. */ /* For testing: if (! @include_once("common/json.inc.php")) { include_once("/var/www/html/admin/common/json.inc.php"); } */ include_once("common/json.inc.php"); global $amp_conf; $output = array(); $fn = "http://mirror.freepbx.org/whatismyip.php"; $json_array['status'] = _('Failed to auto-detect settings'); $json_array['externip'] = ''; /* Fetch the IP address of this system, expects xml formatted as: nnn.nnn.nnn.nnn */ if (!$amp_conf['MODULEADMINWGET']) { $ip_xml = @file_get_contents($fn); } if (empty($ip_xml)) { exec("wget -O - '$fn' 2> /dev/null", $data_arr, $retcode); $ip_xml = implode("\n",$data_arr); } preg_match('|^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$|',$ip_xml,$matches); if (isset($matches[1])) { $json_array['externip'] = $matches[1]; $json_array['status'] = _('Failed to auto-detect local network settings'); // TODO: path to route? // exec('route -nv',$output,$retcode); foreach ($output as $line) { preg_match('/^\s*(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s*(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s*(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/',$line,$matches); if (isset($matches[3]) && $matches[2] == '0.0.0.0' && substr($matches[1],0,4) != '169.') { $localnet[$matches[1]] = $matches[3]; $json_array['status'] = 'success'; } } } else { $json_array['status'] = _('Failed to auto-detect settings'); } $json_array['localnet'] = $localnet; $json = new Services_JSON(); sleep(0); header("Content-type: application/json"); echo $json->encode($json_array);