function dyndnsCheckIP($int) { $ip_address = get_interface_ip($int); if (is_private_ip($ip_address)) { $hosttocheck = "checkip.dyndns.org"; $checkip = gethostbyname($hosttocheck); $ip_ch = curl_init("http://{$checkip}"); curl_setopt($ip_ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ip_ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ip_ch, CURLOPT_INTERFACE, $ip_address); $ip_result_page = curl_exec($ip_ch); curl_close($ip_ch); $ip_result_decoded = urldecode($ip_result_page); preg_match('=Current IP Address: (.*)</body>=siU', $ip_result_decoded, $matches); $ip_address = trim($matches[1]); } return $ip_address; }
$duplicate_peer = TRUE; } else { // Neither IP nor Domain exist $duplicate_peer = FALSE; } } else { $duplicate_peer = TRUE; } } else { // Using IP only, is there a duplicate if (empty($duplicate_check1) == TRUE) { if ($my_server_domain == $peer_domain || empty($duplicate_check2) == FALSE) { $duplicate_peer = TRUE; } else { // Check for non-private IP range if (is_private_ip($peer_IP, $allow_lan_peers) == FALSE) { // Neither IP nor Domain exist $duplicate_peer = FALSE; } else { $duplicate_peer = TRUE; } } } else { $duplicate_peer = TRUE; } } } if ($duplicate_peer == FALSE) { // Save only domain name if both IP and Domain exist if (empty($peer_domain) == FALSE) { $peer_IP = NULL;
function is_domain_valid($domain) { $result = TRUE; if (empty($domain) == TRUE) { $result = FALSE; } if (filter_var($domain, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) == TRUE) { $result = FALSE; } if (filter_var($domain, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) == TRUE) { $result = FALSE; } if (is_private_ip($domain) == FALSE) { $result = FALSE; } if (strtolower($domain) == "localhost") { $result = FALSE; } return $result; }
$domain_fail = FALSE; // Reset Variable if (empty($peer_domain) == FALSE) { // Check if the hostname and IP fields actually match // and not made up or unrelated. $dns_ip = gethostbyname($peer_domain); if ($dns_ip != $peer_ip) { // No match between Domain IP and Encoded IP $domain_fail = TRUE; } else { $domain_fail = FALSE; } } // Does the public key half match what is encrypted in the 3rd crypt field from // the same peer? if ($arr1[0] == $gen_key_crypt && empty($peer_ip) == FALSE && empty($IP_exist1) == TRUE && $domain_fail == FALSE && is_private_ip($peer_ip) == FALSE) { if ($delete_request == "DELETE_IP") { // Delete my IP and any public key linked to it as it belongs to a previous unknown owner mysql_query("DELETE FROM `generating_peer_list` WHERE `generating_peer_list`.`IP_Address` = '{$peer_ip}' LIMIT 1"); write_log("DELETE IP Request ({$peer_ip}) was allowed for Public Key: " . base64_encode($public_key), "GP"); } else { // My server has moved to another IP, update the list mysql_query("UPDATE `generating_peer_list` SET `IP_Address` = '{$peer_ip}' WHERE `generating_peer_list`.`public_key` = '{$public_key}' LIMIT 1"); write_log("New Generation Peer IP Address ({$peer_ip}) was updated for Public Key: " . base64_encode($public_key), "GP"); } } else { if (my_public_key() == $public_key) { if (election_cycle(1) == TRUE) { if (empty($IP_exist1) == TRUE) { mysql_query("UPDATE `generating_peer_list` SET `IP_Address` = '{$peer_ip}' WHERE `generating_peer_list`.`public_key` = '{$public_key}' LIMIT 1"); write_log("Generation Peer List was updated with My New IP Address ({$peer_ip})", "GP");
$iponly = $remoteip; } function is_private_ip($ip) { if (empty($ip) or !ip2long($ip)) { return NULL; } $private_ips = array(array('10.0.0.0', '10.255.255.255'), array('172.16.0.0', '172.31.255.255'), array('192.168.0.0', '192.168.255.255')); $ip = ip2long($ip); foreach ($private_ips as $ipr) { $min = ip2long($ipr[0]); $max = ip2long($ipr[1]); if ($ip >= $min && $ip <= $max) { return true; } } return false; } if (is_private_ip($iponly) || $iponly == "0.0.0.0") { $ip = $remoteip . $port; } $remoteip = $remoteip . $port; // $querystring="SELECT * FROM serverinfo WHERE ip LIKE '$ip' AND timestamp > NOW() - INTERVAL 10 MINUTE"; // $result=OCmysql_query($querystring); // $rowsreturned=mysql_num_rows($result); // if($rowsreturned==0){ OCmysql_query("INSERT INTO serverinfo SET ip='{$ip}', timestamp_firstseen=NOW() ON DUPLICATE KEY UPDATE timestamp=NOW(), remoteip='{$remoteip}' , hostname='{$hostname}',version='{$version}',game='{$game}',map='{$map}',players='{$players}',maxplayers='{$maxplayers}',\tfromext='1' , postdataext='" . mysql_real_escape_string("HEADER:::: " . json_encode(getallheaders()) . " \$_REQUEST::serverinfoext.php:: " . json_encode($_REQUEST)) . "'"); // } //aggregate players is in funcaggregateplayrecount.php echo "success serverinfoext"; echo json_encode($_REQUEST) . "INSERT INTO serverinfo SET ip='{$ip}', timestamp_firstseen=NOW() ON DUPLICATE KEY UPDATE timestamp=NOW(), remoteip='{$remoteip}' , hostname='{$hostname}',version='{$version}',game='{$game}',map='{$map}',players='{$players}',maxplayers='{$maxplayers}',\tfromext='1' ";
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; }
$natent['interface'] = $if2; $natent['destination']['any'] = true; $natent['natport'] = ""; $a_out[] = $natent; $natent = array(); $natent['source']['network'] = "127.0.0.0/8"; $natent['dstport'] = ""; $natent['descr'] = sprintf(gettext('Auto created rule for localhost to %1$s'), $ifdesc2); $natent['target'] = ""; $natent['interface'] = $if2; $natent['destination']['any'] = true; $natent['staticnatport'] = false; $natent['natport'] = "1024:65535"; $a_out[] = $natent; /* PPTP subnet */ if ($config['pptpd']['mode'] == "server" && is_private_ip($config['pptpd']['remoteip'])) { $pptptopip = $config['pptpd']['n_pptp_units'] - 1; $pptp_subnets = ip_range_to_subnet_array($config['pptpd']['remoteip'], long2ip32(ip2long($config['pptpd']['remoteip']) + $pptptopip)); foreach ($pptp_subnets as $pptpsn) { $natent = array(); $natent['source']['network'] = $pptpsn; $natent['sourceport'] = ""; $natent['descr'] = gettext("Auto created rule for PPTP server"); $natent['target'] = ""; $natent['interface'] = $if2; $natent['destination']['any'] = true; $natent['natport'] = ""; $a_out[] = $natent; } } /* PPPoE subnet */