/** Publish TR data */ public static function publishTraceroute($data) { global $dbconn, $ixmaps_debug_mode; // FIXME: move this to config.php $URI = "https://www.ixmaps.ca/cgi-bin/gather-tr.cgi"; $trSubString = ""; $trString = ""; /*check tr status: does the TR reach its destination?*/ end($data['ip_analysis']['hops']); $lastKey = key($data['ip_analysis']['hops']); $lastIp = $data['ip_analysis']['hops'][$lastKey]['winIp']; //echo "LastIP: ".$lastIp; if ($data['dest_ip'] == $lastIp) { $trStatus = "c"; } else { $trStatus = "i"; } // FIXED! collecting the protocol used in the submission data_type = json foreach ($data['traceroute_submissions'] as $sub_data) { if ($sub_data['data_type'] == "json") { // convert to lowercase before comparison $sub_data['protocol'] = strtolower($sub_data['protocol']); if ($sub_data['protocol'] == "icmp") { $protocol = "i"; } else { if ($sub_data['protocol'] == "udp") { $protocol = "u"; } else { if ($sub_data['protocol'] == "tcp") { $protocol = "t"; } } } } } // TODO: check for null fields // convert timeout to seconds $data['timeout'] = round($data['timeout'] / 1000); $trString = "dest=" . $data['dest'] . "&dest_ip=" . $data['dest_ip'] . "&submitter=" . urlencode($data['submitter']) . "&zip_code=" . urlencode($data['postal_code']) . "&client=" . urlencode($data['traceroute_submissions'][0]['client']) . "&cl_ver=1.0&privacy=8&timeout=" . $data['timeout'] . "&protocol=" . $protocol . "&maxhops=" . $data['maxhops'] . "&attempts=" . $data['queries'] . "&status=" . $trStatus; $hopCount = 0; $foundFirstValidIp = false; // hops foreach ($data['ip_analysis']['hops'] as $key => $hop) { // skip local ips if (!GatherTr::checkIpIsPrivate($hop['winIp']) || $hop['winIp'] == "") { // anonimize first valid ip if (!$foundFirstValidIp && $hop['winIp'] != "") { $foundFirstValidIp = true; //echo "\n First Valid IP: ".$hop['winIp']; $ipQuads = explode('.', $hop['winIp']); $ipAmonim = ""; for ($i = 0; $i < count($ipQuads); $i++) { if ($i == count($ipQuads) - 1) { $ipAmonim .= ".0"; } else { if ($i == 0) { $ipAmonim .= "" . $ipQuads[$i]; } else { $ipAmonim .= "." . $ipQuads[$i]; } } } $hop['winIp'] = $ipAmonim; } $hopCount++; $latencyCount = 0; // latencies foreach ($hop['latencies'] as $key1 => $latency) { $latencyCount++; $rtt_ms = 0; if ($hop['winIp'] == "") { $status = "t"; } else { $status = "r"; } $trString .= "&status_" . $hopCount . "_" . $latencyCount . "=" . $status . "&ip_addr_" . $hopCount . "_" . $latencyCount . "=" . $hop['winIp'] . "&rtt_ms_" . $hopCount . "_" . $latencyCount . "=" . round($latency); } } else { //echo "\n skiping ip: ".$hop['winIp']; } // end skip ip } $totItems = $hopCount * $data['queries']; $trString .= "&n_items=" . $totItems; //echo "\n".$trString.""; // adding exceptions for SSL certificate $arrContextOptions = array("ssl" => array("verify_peer" => false, "verify_peer_name" => false)); // publish data $trResult = file_get_contents($URI . "?" . $trString, false, stream_context_create($arrContextOptions)); //echo "\n\n".$trResult; $search = "new traceroute ID"; //$lines = file('example.txt'); $line_number = false; $tr_id_arr = explode("\n", $trResult); while (list($key, $line) = each($tr_id_arr) and !$line_number) { $line_number = strpos($line, $search) !== FALSE ? $key + 1 : $line_number; } $tr_id_line = explode("=", $tr_id_arr[$line_number - 1]); //echo "\nTR ID: ".$tr_id_line[1]; if (count($tr_id_line) == 2 && $tr_id_line[1] != 0) { return $tr_id_line[1]; } else { return 0; } }
<?php header('Access-Control-Allow-Origin: *'); include '../config.php'; include '../model/GatherTr.php'; // MaxMind Include Files include '../geoip/geoip.inc'; include '../geoip/geoipcity.inc'; include '../geoip/geoipregionvars.php'; $gi1 = geoip_open("../geoip/dat/GeoLiteCity.dat", GEOIP_STANDARD); if (isset($_REQUEST['ip']) && $_REQUEST['ip'] != "") { $ip = $_REQUEST['ip']; } else { $ip = 0; } $ip_data = GatherTr::getHostnames($_REQUEST['ip'], $_REQUEST['t']); echo "TOT: IPs analyzed:" . count($ip_data); echo "<hr/>"; $c = 0; echo "<pre>"; //echo "IP\tixmaps-hostname\tnew-hostname\tStatus"; foreach ($ip_data as $key => $ip) { $c++; // current IXmaps data echo "IXmaps IP: " . $ip['ip_addr']; echo "\n"; print_r($ip); // Checking MaxMind Data $record1 = geoip_record_by_addr($gi1, $ip['ip_addr']); echo "\nMaxMind Data:"; echo "\n";
//header('Access-Control-Allow-Origin: *'); include '../config.php'; include '../model/GatherTr.php'; if (!isset($_REQUEST['ip'])) { echo "You must provide an IP as parameter: <br/>\n http://www.ixmaps.ca/application/controller/ip-to-asn.php?ip=<b>[ip]</b>"; } else { $ip = $_REQUEST['ip']; /* Check ip IP for geolocation purposes */ // dev display $asn_carrier = GatherTr::getIpForAsn($ip); echo "<hr/>getIpForAsn..."; echo "<pre>"; print_r($asn_carrier); echo "</pre>"; echo "<hr/>getHostnameForIp..."; $hostname_new = GatherTr::getHostnameForIp($ip); echo "<pre>"; print_r($hostname_new); echo "</pre>"; echo "<hr/>ipInIXmaps..."; $ixmaps_data = GatherTr::ipInIXmaps($ip); echo "<pre>"; print_r($ixmaps_data); echo "</pre>"; // display /*echo "<br/>netmask: ".$asn_carrier[0]['netmask']; echo "<br/>asn: ".$asn_carrier[0]['asn']; echo "<br/>Carrier: ".$asn_carrier[0]['name'];*/ }
<?php header('Access-Control-Allow-Origin: *'); //ini_set( "display_errors", 0); // use only in production include '../config.php'; include '../model/GatherTr.php'; if (isset($_REQUEST['tr_c_id']) && $_REQUEST['tr_c_id'] != "") { // use only for debugging $c = GatherTr::getTrContribution($_REQUEST['tr_c_id']); //echo "TR Data saved!\n\n"; // fix json return: assume now not order in the contributions for ($i = 0; $i < count($c['traceroute_submissions']); $i++) { if ($c['traceroute_submissions'][$i]['data_type'] == "json") { $c['traceroute_submissions'][$i]['tr_data'] = json_decode($c['traceroute_submissions'][$i]['tr_data']); } } echo json_encode($c); } else { echo 'No tr_c_id sent.'; }
$_POST['privacy'] = 8; $_POST['client'] = ""; $_POST['cl_version'] = ""; //print_r($_POST); /* TODO: add exahustive check for consistency and completness of the TR data Requires discussion with tests on the TrGen client */ if (isset($_POST['dest_ip']) && $_POST['dest_ip'] != "") { //print_r($_POST); $tr_c_id = GatherTr::saveTrContribution($_POST); //echo "\ntr_c_id: ". $tr_c_id."\n"; $b = GatherTr::saveTrContributionData($_POST, $tr_c_id); $trData = GatherTr::getTrContribution($tr_c_id); //print_r($rawTrData); $trByHop = GatherTr::formatTrData($trData); //print_r($d); if ($trByHop == 0) { // analyis of TR failed or not implemented yet } else { $trAnalyzed = GatherTr::analyzeTrData($trByHop); $trData['ip_analysis'] = $trAnalyzed; //print_r($trData); $trId = GatherTr::publishTraceroute($trData); $f = GatherTr::flagContribution($tr_c_id, $trId); $result = array("TRid" => $trId, "tr_c_id" => $tr_c_id); echo json_encode($result); } } else { echo 'No parameters sent.'; }