| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
include_once('sipstation.utility.php'); |
|---|
| 10 |
|
|---|
| 11 |
if (! @include_once("common/json.inc.php")) { |
|---|
| 12 |
$quietmode=1; |
|---|
| 13 |
include_once("/var/www/html/admin/common/json.inc.php"); |
|---|
| 14 |
include_once("/var/www/html/admin/functions.inc.php"); |
|---|
| 15 |
$amp_conf = parse_amportal_conf("/etc/amportal.conf"); |
|---|
| 16 |
include_once("/var/www/html/admin/common/db_connect.php"); |
|---|
| 17 |
include_once("/var/www/html/admin/modules/core/functions.inc.php"); |
|---|
| 18 |
if (!isset($active_modules)) { |
|---|
| 19 |
$active_modules = array(); |
|---|
| 20 |
} |
|---|
| 21 |
} |
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
if (!function_exists('core_did_create_update')) { |
|---|
| 28 |
function core_did_create_update($did_vars) { |
|---|
| 29 |
$did_create['extension'] = isset($did_vars['extension']) ? $did_vars['extension'] : ''; |
|---|
| 30 |
$did_create['cidnum'] = isset($did_vars['cidnum']) ? $did_vars['cidnum'] : ''; |
|---|
| 31 |
|
|---|
| 32 |
if (count(core_did_get($did_create['extension'], $did_create['$cidnum']))) { |
|---|
| 33 |
return core_did_edit_properties($did_vars); |
|---|
| 34 |
} else { |
|---|
| 35 |
$did_create['faxexten'] = isset($did_vars['faxexten']) ? $did_vars['faxexten'] : ''; |
|---|
| 36 |
$did_create['faxemail'] = isset($did_vars['faxemail']) ? $did_vars['faxemail'] : ''; |
|---|
| 37 |
$did_create['answer'] = isset($did_vars['answer']) ? $did_vars['answer'] : '0'; |
|---|
| 38 |
$did_create['wait'] = isset($did_vars['wait']) ? $did_vars['wait'] : '0'; |
|---|
| 39 |
$did_create['privacyman'] = isset($did_vars['privacyman']) ? $did_vars['privacyman'] : ''; |
|---|
| 40 |
$did_create['alertinfo'] = isset($did_vars['alertinfo']) ? $did_vars['alertinfo'] : ''; |
|---|
| 41 |
$did_create['ringing'] = isset($did_vars['ringing']) ? $did_vars['ringing'] : ''; |
|---|
| 42 |
$did_create['mohclass'] = isset($did_vars['mohclass']) ? $did_vars['mohclass'] : 'default'; |
|---|
| 43 |
$did_create['description'] = isset($did_vars['description']) ? $did_vars['description'] : ''; |
|---|
| 44 |
$did_create['grppre'] = isset($did_vars['grppre']) ? $did_vars['grppre'] : ''; |
|---|
| 45 |
$did_create['delay_answer']= isset($did_vars['delay_answer'])? $did_vars['delay_answer']: '0'; |
|---|
| 46 |
$did_create['pricid'] = isset($did_vars['pricid']) ? $did_vars['pricid'] : ''; |
|---|
| 47 |
$did_create['channel'] = isset($did_vars['channel']) ? $did_vars['channel'] : ''; |
|---|
| 48 |
|
|---|
| 49 |
$did_dest = isset($did_vars['destination']) ? $did_vars['destination'] : ''; |
|---|
| 50 |
return core_did_add($did_vars, $did_dest); |
|---|
| 51 |
} |
|---|
| 52 |
} |
|---|
| 53 |
} |
|---|
| 54 |
|
|---|
| 55 |
if (!function_exists('core_did_edit_properties')) { |
|---|
| 56 |
function core_did_edit_properties($did_vars) { |
|---|
| 57 |
global $db; |
|---|
| 58 |
|
|---|
| 59 |
if (!is_array($did_vars)) { |
|---|
| 60 |
return false; |
|---|
| 61 |
} |
|---|
| 62 |
$extension = $db->escapeSimple(isset($did_vars['extension']) ? $did_vars['extension'] : ''); |
|---|
| 63 |
$cidnum = $db->escapeSimple(isset($did_vars['cidnum']) ? $did_vars['cidnum'] : ''); |
|---|
| 64 |
$sql = ""; |
|---|
| 65 |
foreach ($did_vars as $key => $value) { |
|---|
| 66 |
switch ($key) { |
|---|
| 67 |
case 'faxexten': |
|---|
| 68 |
case 'faxemail': |
|---|
| 69 |
case 'answer': |
|---|
| 70 |
case 'wait': |
|---|
| 71 |
case 'privacyman': |
|---|
| 72 |
case 'alertinfo': |
|---|
| 73 |
case 'ringing': |
|---|
| 74 |
case 'mohclass': |
|---|
| 75 |
case 'description': |
|---|
| 76 |
case 'grppre': |
|---|
| 77 |
case 'delay_answer': |
|---|
| 78 |
case 'pricid': |
|---|
| 79 |
case 'destination': |
|---|
| 80 |
$sql_value = $db->escapeSimple($value); |
|---|
| 81 |
$sql .= " `$key` = '$sql_value',"; |
|---|
| 82 |
break; |
|---|
| 83 |
default: |
|---|
| 84 |
} |
|---|
| 85 |
} |
|---|
| 86 |
if ($sql == '') { |
|---|
| 87 |
return false; |
|---|
| 88 |
} |
|---|
| 89 |
$sql = substr($sql,0,(strlen($sql)-1)); |
|---|
| 90 |
$sql_update = "UPDATE `incoming` SET"."$sql WHERE `extension` = '$extension' AND `cidnum` = '$cidnum'"; |
|---|
| 91 |
return sql($sql_update); |
|---|
| 92 |
} |
|---|
| 93 |
} |
|---|
| 94 |
|
|---|
| 95 |
function sipstation_set_outboundcid($target, $cid) { |
|---|
| 96 |
global $db; |
|---|
| 97 |
global $astman; |
|---|
| 98 |
$exten = explode(',',$target); |
|---|
| 99 |
$extension = $exten[1]; |
|---|
| 100 |
if ($astman) { |
|---|
| 101 |
$astman->database_put("AMPUSER",$extension."/outboundcid","$cid"); |
|---|
| 102 |
} else { |
|---|
| 103 |
freepbx_debug("could not get to manager"); |
|---|
| 104 |
} |
|---|
| 105 |
$extension = $db->escapeSimple($extension); |
|---|
| 106 |
|
|---|
| 107 |
/* This is really bad practice, but until we can get a decent API that is able |
|---|
| 108 |
to update extensions without extreme pain, this will have to do. |
|---|
| 109 |
*/ |
|---|
| 110 |
sql("UPDATE `users` SET `outboundcid` = '$cid' WHERE `extension` = '$extension'"); |
|---|
| 111 |
} |
|---|
| 112 |
|
|---|
| 113 |
$json_array['status'] = 'success'; |
|---|
| 114 |
$exten_cids = array(); |
|---|
| 115 |
$cnt = 0; |
|---|
| 116 |
if (isset($_POST['dids'])) { |
|---|
| 117 |
|
|---|
| 118 |
$filter = array('dids' => true,); |
|---|
| 119 |
$dids_to_update = array(); |
|---|
| 120 |
$dids_validation_fail = array(); |
|---|
| 121 |
|
|---|
| 122 |
$current_dids = sipstation_get_config("xxx", false, $filter); |
|---|
| 123 |
$dids = unserialize($_POST['dids']); |
|---|
| 124 |
foreach ($dids as $did) { |
|---|
| 125 |
$did_parts = unserialize($did); |
|---|
| 126 |
if (isset($did_parts['did'])) { |
|---|
| 127 |
$update = false; |
|---|
| 128 |
|
|---|
| 129 |
if ($failover && $did_parts['failover'] != $current_dids['dids'][$did_parts['did']]['failover']) { |
|---|
| 130 |
if (preg_match('/^\s*([1]{0,1}[2-9]{1}\d{2}[2-9]{1}\d{6})\s*$/', $did_parts['failover'], $match)) { |
|---|
| 131 |
$dids_to_update[$did_parts['did']] = $match[1]; |
|---|
| 132 |
$update = true; |
|---|
| 133 |
} else { |
|---|
| 134 |
$dids_validation_fail[$did_parts['did']] = $did_parts['failover']; |
|---|
| 135 |
continue; |
|---|
| 136 |
} |
|---|
| 137 |
} |
|---|
| 138 |
if ($did_parts['dest'] != 'blank' && $did_parts['dest'] != 'assigned') { |
|---|
| 139 |
$did_vars['extension'] = $did_parts['did']; |
|---|
| 140 |
$did_vars['destination'] = $did_parts['dest']; |
|---|
| 141 |
$did_vars['description'] = $did_parts['desc']; |
|---|
| 142 |
core_did_create_update($did_vars); |
|---|
| 143 |
if ($did_parts['setcid']) { |
|---|
| 144 |
sipstation_set_outboundcid($did_vars['destination'],$did_vars['extension']); |
|---|
| 145 |
} |
|---|
| 146 |
$update = true; |
|---|
| 147 |
} |
|---|
| 148 |
if ($update) { |
|---|
| 149 |
$cnt++; |
|---|
| 150 |
} |
|---|
| 151 |
} else { |
|---|
| 152 |
$json_array['status'] = _("An error was encountered updating DID destinations");; |
|---|
| 153 |
} |
|---|
| 154 |
} |
|---|
| 155 |
if ($failover) sipstation_put_dids($dids_to_update); |
|---|
| 156 |
} |
|---|
| 157 |
|
|---|
| 158 |
if (empty($dids_validation_fail)) { |
|---|
| 159 |
$json_array['update_count'] = $cnt; |
|---|
| 160 |
$json_array['status_message'] = sprintf(_("Successfully updated or created %s inbound routes for your DIDs"),$cnt); |
|---|
| 161 |
} elseif ($cnt) { |
|---|
| 162 |
$json_array['status'] = 'validation_failures'; |
|---|
| 163 |
$json_array['update_count'] = $cnt; |
|---|
| 164 |
$json_array['validation_failures'] = $dids_validation_fail; |
|---|
| 165 |
$validation_failures = count($dids_validation_fail); |
|---|
| 166 |
$json_array['status_message'] = sprintf(_("There are %s invalid entries, only updated or created %s inbound routes for your DIDs"),$validation_failures, $cnt); |
|---|
| 167 |
} else { |
|---|
| 168 |
$json_array['status'] = 'validation_failures'; |
|---|
| 169 |
$json_array['update_count'] = 0; |
|---|
| 170 |
$json_array['validation_failures'] = $dids_validation_fail; |
|---|
| 171 |
$json_array['status_message'] = sprintf(_("There were %s validation failures on the requested DIDs, no updates performed"),$validation_failures); |
|---|
| 172 |
} |
|---|
| 173 |
|
|---|
| 174 |
|
|---|
| 175 |
|
|---|
| 176 |
|
|---|
| 177 |
if ($cnt) { |
|---|
| 178 |
needreload(); |
|---|
| 179 |
if ($_POST['send_reload'] == 'yes') { |
|---|
| 180 |
ob_start(); |
|---|
| 181 |
if (!@include ('views/freepbx_reloadbar.php')) { |
|---|
| 182 |
@include ('../../views/freepbx_reloadbar.php'); |
|---|
| 183 |
} |
|---|
| 184 |
$json_array['reload_bar'] = ob_get_clean(); |
|---|
| 185 |
ob_start(); |
|---|
| 186 |
if (!@include ('views/freepbx_reload.php')) { |
|---|
| 187 |
@include ('../../views/freepbx_reload.php'); |
|---|
| 188 |
} |
|---|
| 189 |
$json_array['reload_header'] = ob_get_clean(); |
|---|
| 190 |
} |
|---|
| 191 |
$json_array['show_reload'] = 'yes'; |
|---|
| 192 |
} else { |
|---|
| 193 |
$json_array['show_reload'] = 'no'; |
|---|
| 194 |
} |
|---|
| 195 |
|
|---|
| 196 |
$json = new Services_JSON(); |
|---|
| 197 |
$value = $json->decode($_POST); |
|---|
| 198 |
|
|---|
| 199 |
header("Content-type: application/json"); |
|---|
| 200 |
echo $json->encode($json_array); |
|---|
| 201 |
|
|---|