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();
function sipstation_put_dids($dids) { if (empty($dids)) { return true; } $keycode = sipstation_get_key(); $xml = ' <?xml version="1.0" encoding="UTF-8" standalone="no"?> <xml type="sipstation/xml" version="1.0.0"> <xml_version>1.0.0</xml_version>'; $xml .= "\n<keycode>{$keycode}</keycode>\n<dids>"; foreach ($dids as $did => $failover) { $xml .= "\n<did failover=\"{$failover}\">{$did}</did>"; } $xml .= "\n</dids>\n</xml>\n"; // TODO: different URL for putting just dids $url = "https://store.freepbx.com/store/myaccount.xml"; $user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"; $ch = curl_init(); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_USERAGENT, $user_agent); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // print results to string and not STDOUT curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/cookie.txt'); // IMITATE CLASSIC BROWSER'S BEHAVIOUR curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20); // TODO: deal with timeout! $xml = curl_exec($ch); // curl info back from request $return_status = curl_getinfo($ch); // freepbx_debug($return_status); // TODO: if ($xml === false) { handle it, retry, etc. // TODO: or at least toss in some error xml response curl_close($ch); return $xml; }