function customappsreg_customdests_edit($old_custom_dest, $custom_dest, $description, $notes) { global $db; if ($old_custom_dest != $custom_dest) { $usage_list = framework_identify_destinations($custom_dest, $module_hash = false); if (!empty($usage_list[$custom_dest])) { echo "<script>javascript:alert('" . _('DUPLICATE Destination: This destination is in use or potentially used by another module') . "')</script>"; return false; } } $sql = "UPDATE custom_destinations SET " . "custom_dest = " . sql_formattext($custom_dest) . ", " . "description = " . sql_formattext($description) . ", " . "notes = " . sql_formattext($notes) . " " . "WHERE custom_dest = " . sql_formattext($old_custom_dest); $result = $db->query($sql); if (DB::IsError($result)) { die_freepbx($result->getMessage() . $sql); } }
/** create a comprehensive list of all destinations that are problematic * @param array an array of destinations to check against * @param bool set to true if custome (unknown) destinations should be reported * @return array an array of the destinations that are empty, orphaned or custom * @description This function will scan the entire system and identify destinations * that are problematic. Either empty, orphaned or an unknow custom * destinations. An orphaned destination is one that should belong * to a module but the object it would have pointed to does not exist * because it was probably deleted. */ function framework_list_problem_destinations($module_hash = false, $ignore_custom = false) { global $active_modules; if (!is_array($module_hash)) { $module_hash = $active_modules; } $my_dest_arr = array(); $problem_dests = array(); $all_dests = framework_check_destination_usage(true, $module_hash); foreach ($all_dests as $dests) { foreach ($dests as $adest) { if (!empty($adest['dest'])) { $my_dest_arr[] = $adest['dest']; } } } $my_dest_arr = array_unique($my_dest_arr); $identities = framework_identify_destinations($my_dest_arr, $module_hash); foreach ($all_dests as $dests) { foreach ($dests as $adest) { if (empty($adest['dest'])) { $problem_dests[] = array('status' => 'EMPTY', 'dest' => $adest['dest'], 'description' => $adest['description'], 'edit_url' => $adest['edit_url']); } else { if ($identities[$adest['dest']] === false) { if ($ignore_custom) { continue; } $problem_dests[] = array('status' => 'CUSTOM', 'dest' => $adest['dest'], 'description' => $adest['description'], 'edit_url' => $adest['edit_url']); } else { if (is_array($identities[$adest['dest']])) { foreach ($identities[$adest['dest']] as $details) { if (empty($details)) { $problem_dests[] = array('status' => 'ORPHAN', 'dest' => $adest['dest'], 'description' => $adest['description'], 'edit_url' => $adest['edit_url']); } break; // there is only one set per array } } else { echo "ERROR?\n"; var_dump($adest); } } } } } return $problem_dests; }
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; }