function sipstation_set_outboundcid($target, $cid) { global $db; global $astman; $exten = explode(',', $target); $extension = $exten[1]; if ($astman) { $astman->database_put("AMPUSER", $extension . "/outboundcid", "{$cid}"); } else { freepbx_debug("could not get to manager"); } $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}'"); }
function sipstation_get_config($account_key, $online = true, $filter_sections = array()) { global $db; global $ast_codec_hash; global $codec_array; if (!empty($account_key)) { $json_array = array(); $xml_parser = sipstation_get_settings($account_key, $online); if (!empty($xml_parser->data)) { foreach ($xml_parser->data['xml'] as $key => $value) { switch ($key) { case 'xml_version': case 'query_status': case 'query_status_message': case 'sip_username': case 'sip_password': case 'num_trunks': case 'monthly_cost': case 'cid_format': case 'nat_troubleshooting': if (!empty($filter_sections) && (!isset($filter_sections[$key]) || !$filter_sections[$key])) { continue; } $json_array[$key] = trim("{$value}"); break; case 'gateways': case 'e911_address': case 'registered_status': if (!empty($filter_sections) && (!isset($filter_sections[$key]) || !$filter_sections[$key])) { continue; } foreach ($value as $key2 => $value2) { if (is_array($value2)) { foreach ($value2 as $gw => $value3) { $json_array[$key][$key2][$gw] = $value3 ? trim($value3) : ''; } } else { $json_array[$key][$key2] = $value2 ? trim($value2) : ''; } } if ($key == 'registered_status') { foreach ($value as $key2 => $value2) { if (is_array($value2)) { if ($value2['contact_ip'] == $value2['network_ip']) { $json_array[$key][$key2]['ips_match'] = 'yes'; } else { $json_array[$key][$key2]['ips_match'] = is_private_ip($value2['contact_ip']) ? 'private' : 'no'; } } else { if ($key2 != 'registered') { continue; } if ($json_array[$key]['contact_ip'] == $json_array[$key]['network_ip'] && $value2 == 'yes') { $json_array[$key]['ips_match'] = 'yes'; } else { $json_array[$key]['ips_match'] = 'no'; $json_array[$key]['ips_match'] = is_private_ip($json_array[$key]['contact_ip']) ? 'private' : 'no'; } } } } break; case 'dids': if (!empty($filter_sections) && (!isset($filter_sections[$key]) || !$filter_sections[$key])) { continue; } if (!empty($value['did']) && !is_array($value['did'])) { $tmp = $value['did']; unset($value['did']); $value['did'][] = $tmp; $single = true; } else { $single = false; } $idx = 0; foreach ($value['did'] as $did) { $path = $single ? "/xml/dids/did" : "/xml/dids/did/{$idx}"; $idx++; $failover = $xml_parser->attributes[$path]['failover']; $did = trim($did); $exten = core_did_get($did); if (empty($exten)) { $json_array[$key][$did] = array('destination' => 'blank', 'desc' => _("Not Set"), 'description' => '', 'failover' => "{$failover}"); } else { $dest_results = framework_identify_destinations($exten['destination']); if (is_array($dest_results[$exten['destination']])) { /* This is really bad but the calls to core_users get are so heavy and core_users_list don't give details that we will do this for now and deal with it later. */ $user_cid_hash = array(); $sql = "SELECT `extension`, `outboundcid` FROM `users`"; $user_cids = $db->getAll($sql, DB_FETCHMODE_ASSOC); if (DB::IsError($user_cids)) { freepbx_debug("Failed trying to get user cids"); freepbx_debug($user_cids->getMessage()); $user_cids = array(); } foreach ($user_cids as $item) { $user_cid_hash[$item['extension']] = $item['outboundcid']; } foreach ($dest_results[$exten['destination']] as $mod => $info) { //$destination = (substr($exten['destination'],0,15) == 'from-did-direct' ? $exten['destination'] : 'assigned'); $is_checked = 0; if (substr($exten['destination'], 0, 15) == 'from-did-direct') { $destination = $exten['destination']; $exten_arr = explode(',', $destination); if (isset($exten_arr[1]) && isset($user_cid_hash[$exten_arr[1]])) { $is_checked = preg_match('/^\\s*[<]?(' . $did . ')[>]?\\s*$|^\\s*"[^"]*"\\s*<(' . $did . ')>\\s*$/', $user_cid_hash[$exten_arr[1]]); } else { $is_checked = 0; } } else { $destination = 'assigned'; } $json_array[$key][$did] = array('destination' => $destination, 'desc' => $info['description'], 'description' => $exten['description'], 'outboundcid' => $is_checked, 'failover' => "{$failover}"); break; } } else { $json_array[$key][$did] = array('destination' => 'blank', 'desc' => _("Not Set"), 'description' => '', 'failover' => "{$failover}"); } } } break; case 'asterisk_settings': if (!empty($filter_sections) && (!isset($filter_sections[$key]) || !$filter_sections[$key])) { continue; } $json_array['asterisk_settings']['peer'] = $value['peer']['setting']; break; case 'codecs': if (!empty($filter_sections) && (!isset($filter_sections[$key]) || !$filter_sections[$key])) { continue; } $codec_array = $value['codec']; /* filter the Asterisk codec hash to only those that we are told are supported */ $ast_codec_hash = array_filter(array_map('sipstation_supported_codecs', $ast_codec_hash)); break; default: } $json_array['status'] = 'success'; } } else { $json_array['status'] = 'noserver'; } } else { $json_array['status'] = 'nokey'; } return $json_array; }