include_once "/var/www/html/admin/common/db_connect.php"; include_once "/var/www/html/admin/modules/core/functions.inc.php"; if (!isset($active_modules)) { $active_modules = array(); } } global $db; global $sipstation_xml_version; /* For testing: */ /* include_once("common/json.inc.php"); */ //TODO: mockup, would need to do error checking // $json_array = sipstation_get_config(sipstation_get_key()); /* Check if we have trunks configured with the same credentials and if so, skip the trunk creation mode Note: there are some ugly queries below. We don't like to do that but the APIs are not ideal and very heavy. This turns out to be much more efficient to detect these trunks. */ $trunk_conflict = array(); if ($json_array['query_status'] == 'SUCCESS') { $sip_user = $json_array['sip_username']; $gateways = implode("','", $json_array['gateways']); $sql = "\n SELECT `id` FROM `sip` WHERE `keyword` = 'username' \n AND `data` = '{$sip_user}' AND `id` IN (\n SELECT `id` FROM `sip` WHERE `keyword` = 'host' \n AND `data` IN ('{$gateways}')\n )"; $results = $db->getCol($sql); if (DB::IsError($results)) { $results = array();
} $extension = $db->escapeSimple($extension); // not reall necessary but ... /* This is really bad practice, but until we can get a decent API that is able to update extensions without extreme pain, this will have to do. */ sql("UPDATE `users` SET `outboundcid` = '{$cid}' WHERE `extension` = '{$extension}'"); } $json_array['status'] = 'success'; $exten_cids = array(); $cnt = 0; if (isset($_POST['dids'])) { $filter = array('dids' => true); $dids_to_update = array(); $dids_validation_fail = array(); $current_dids = sipstation_get_config("xxx", false, $filter); $dids = unserialize($_POST['dids']); foreach ($dids as $did) { $did_parts = unserialize($did); if (isset($did_parts['did'])) { $update = false; //TODO: $failover flag tmp here if ($failover && $did_parts['failover'] != $current_dids['dids'][$did_parts['did']]['failover']) { if (preg_match('/^\\s*([1]{0,1}[2-9]{1}\\d{2}[2-9]{1}\\d{6})\\s*$/', $did_parts['failover'], $match)) { $dids_to_update[$did_parts['did']] = $match[1]; $update = true; } else { $dids_validation_fail[$did_parts['did']] = $did_parts['failover']; continue; } }
function sipstation_confirm_key($key) { $xml_array = sipstation_get_config(trim($key)); if ($xml_array['status'] == 'success') { switch ($xml_array['query_status']) { case 'SUCCESS': return 'valid'; case 'TEMPNOTAVAIL': return 'tempnotavail'; case 'BADKEY': sipstation_remove_key(); default: return 'invalid'; } } else { return $xml_array['status']; } }