コード例 #1
0
ファイル: traceroute.php プロジェクト: lonelywoolf/hypervm
 static function initThisList($parent, $class)
 {
     global $gbl, $sgbl, $login, $ghtml;
     $_sysname = "linux";
     $host = $_SERVER['REMOTE_ADDR'];
     if (!$host || $sgbl->isDebug()) {
         $host = "google.com";
     }
     if ($parent->isClass('client')) {
         $server = $parent->websyncserver;
     } else {
         $server = $parent->syncserver;
     }
     $cmd = "traceroute -q 1 -n {$host} ";
     $_result = rl_exec_get(null, "localhost", array("traceroute", "exec_traceroute"), array($cmd));
     if (!is_array($_result)) {
         throw new lxexception("traceroute_failed", '', "");
     }
     if (count($_result) == 0) {
         throw new lxexception("traceroute_failed", '', "");
     }
     $object = new Traceroute(null, null, '__name__');
     return $object->Net_Traceroute_Result($_result, $_sysname);
 }
コード例 #2
0
    /**
     */
    public static function dataTransform($trArr)
    {
        global $savePath, $webUrl;
        /*		echo '<textarea>';
        		print_r($trArr);
        		echo '</textarea>';*/
        $date = md5(date('d-m-o_G-i-s'));
        $myLogFile = $savePath . "/" . "_log_" . $date . ".csv";
        $myLogFileWeb = $webUrl . '/gm-temp/_log_' . $date . ".csv";
        //$fhLog = fopen($myLogFile, 'w') or die("can't open file");
        $dist_from_origin = 0;
        $latOrigin = 0;
        $longOrigin = 0;
        $originAsn = 0;
        $imp_dist = 0;
        $imp_dist_txt = '"Trid";"Hop";"Country";"City";"ASN";"IP";"Latency";"Time SoL";"Distance From Origin (KM)";"gl_override";"Origin Lat";"Origin Long"; "Origin ASN"
';
        //fwrite($fhLog, $imp_dist_txt);
        $time_light_will_do = 0;
        $trData = array();
        // distance speed of light in KM per 1 milsec
        $SL = 200;
        //$SL = 86;
        for ($i = 0; $i < count($trArr); $i++) {
            $dist_from_origin = 0;
            //$latOrigin = 0;
            //$longOrigin = 0;
            $imp_dist = 0;
            $imp_dist_txt = '';
            $time_light_will_do = 0;
            $trId = $trArr[$i]['id'];
            $hop = $trArr[$i]['hop'];
            $ip = $trArr[$i]['ip_addr'];
            /*			$lat = $trArr[$i]['mm_lat'];
            			$long = $trArr[$i]['mm_long'];
            */
            $lat = $trArr[$i]['lat'];
            $long = $trArr[$i]['long'];
            $num = $trArr[$i]['num'];
            $name = $trArr[$i]['name'];
            $rtt_ms = $trArr[$i]['rtt_ms'];
            // calclulate first hop for first hop available: note this is not 100% acurate
            //if($i==0){
            if ($hop == 1) {
                $latOrigin = $lat;
                $longOrigin = $long;
                $originAsn = $num;
            } else {
                // calculate distance from origin
                $dist_from_origin = Traceroute::distance($latOrigin, $longOrigin, $lat, $long, false);
                $time_light_will_do = $dist_from_origin / $SL;
                $time_light_will_do *= 2;
                // is it an imposible time? distance?
                if ($rtt_ms < $time_light_will_do) {
                    $imp_dist = 1;
                    //$imp_dist_txt = '<b>YES!</b>';
                }
            }
            $trData[$trId][] = array($ip, $hop, $lat, $long, $trId, $num, $name, $trArr[$i]['dest'], $trArr[$i]['dest_ip'], $trArr[$i]['submitter'], $trArr[$i]['mm_city'], $trArr[$i]['mm_country'], $trArr[$i]['sub_time'], $trArr[$i]['rtt_ms'], $trArr[$i]['gl_override'], $dist_from_origin, $imp_dist, $time_light_will_do, $latOrigin, $longOrigin);
            // write impossible distances to a file: this method seems to be more secure that jQuery
            if ($imp_dist == 1) {
                $impDistanceLog = '' . $trId . ';' . $hop . ';"' . $trArr[$i]['mm_country'] . '";"' . $trArr[$i]['mm_city'] . '";' . $num . ';"' . $ip . '";' . $trArr[$i]['rtt_ms'] . ';' . $time_light_will_do . ';"' . $dist_from_origin . '";' . $trArr[$i]['gl_override'] . ';"' . $latOrigin . '";"' . $longOrigin . '";"' . $originAsn . '"
';
                //echo '<br/>'.$imp_dist_txt.$impDistanceLog;
                //fwrite($fhLog, $impDistanceLog);
            }
        }
        // end for
        //fclose($fhLog);
        //echo '<br/>Impossible Distances log saved at <a href="'.$myLogFileWeb.'">_log_'.$date.'.csv</a>';
        unset($trArr);
        return $trData;
        //unset($trData);
        /*		echo '<hr/><textarea>';
        		print_r($trData);
        		echo '</textarea>';
        */
    }
コード例 #3
0
ファイル: Traceroute.php プロジェクト: agamba/ixmaps-website
    /**
    	Transform basic tr results array and gather new data for advanced analysis.
    		i.e SoL calculations
    */
    public static function dataTransform($trArr)
    {
        global $savePath, $webUrl;
        /*		echo '<textarea>';
        		print_r($trArr);
        		echo '</textarea>';
        */
        print_r($trArr);
        $date = md5(date('d-m-o_G-i-s'));
        $myLogFile = $savePath . "/" . "_log_" . $date . ".csv";
        $myLogFileWeb = $webUrl . '/gm-temp/_log_' . $date . ".csv";
        //$fhLog = fopen($myLogFile, 'w') or die("can't open file");
        $dist_from_origin = 0;
        $latOrigin = 0;
        $longOrigin = 0;
        $originAsn = 0;
        $imp_dist = 0;
        $imp_dist_txt = '"Trid";"Hop";"Country";"City";"ASN";"IP";"Latency";"Time SoL";"Distance From Origin (KM)";"gl_override";"Origin Lat";"Origin Long"; "Origin ASN"
';
        //fwrite($fhLog, $imp_dist_txt);
        $time_light_will_do = 0;
        $trData = array();
        // distance speed of light in KM per 1 milsec
        $SL = 200;
        //$SL = 86;
        // get tr data for all attempts only once
        $activeTrId = $trArr[0]['id'];
        $trDetailsAllData = Traceroute::getTraceRouteAll($activeTrId);
        // exit funcion if not data is returned
        if (count($trDetailsAllData) == 0) {
            return array();
        }
        /*		echo '<textarea>';
        		print_r($trArr);
        		echo '</textarea>';
        */
        // analyze min latency for origin
        // calculate if the min latency of the following hop is less than the min latency of the origin,
        // if so assign that min latency to orign and this also applies to following hop; where current hop != from origin and != from last hop.
        // origin data
        // last hop data
        // analyze here all the hops in between first and last
        // assess geocorrection. Based on this analysis we could indicate which IP should be used to replace wrong coordinates of any hop, based on the following logic:
        /*
        		a) N-1 and N+1 for currentHop, when currentHop != first and != last hop
        		b) N+1 for currentHop, when currentHop = first hop
        		c) N-1 for currentHop, when currentHop  = last hop
        */
        $totHopsData = count($trDetailsAllData);
        /*FIXME: why is not set?
        		It is not set because the hop has no ip a*/
        //print_r($trDetailsAllData);
        $lastHop = $trDetailsAllData[$totHopsData - 1]['hop'];
        $firstHop = $trDetailsAllData[0]['hop'];
        $latenciesArray = array();
        foreach ($trDetailsAllData as $trDetail => $TrDetailData) {
            $currentHop = $TrDetailData['hop'];
            // collect latencies and exclude values = -1 and = 0
            if ($TrDetailData['rtt_ms'] != -1 && $TrDetailData['rtt_ms'] != 0) {
                // this approach actually works better. Capture all here, then analyze the array.
                $latenciesArray[$TrDetailData['hop']][] = $TrDetailData['rtt_ms'];
                //$latenciesArray[$TrDetailData['hop']][$TrDetailData['rtt_ms']]=0;
            }
        }
        // end for collecting latencies
        //$ar2 = array(1, 3, 2, 4);
        //array_multisort($latenciesArray,$ar2);
        /*
        	This approach to calculate speed impossible distance is put
        	on standby for now.. will come back to it laters ;)
        	It's way to unstable still.
        */
        //////////////////////////
        /*		$minOriginLatency = sort($latenciesArray[1]);
        		$minOriginLatency = $latenciesArray[1][0];
        		$latenciesArrayCalculated = array();
        
        		// sort the latencies in the array and get min latencies
        		foreach ($latenciesArray as $key => $value) {
        			echo 'sorting latencies for TRid: '.$activeTrId.' Hop: '.$key;
        			//ksort($latenciesArray[$key], SORT_DESC);
        			//rsort($latenciesArray[$key]);
        			sort($latenciesArray[$key]);
        			// just remove all the other latencies, and keep the min latency
        			$latenciesArray[$key]=$latenciesArray[$key][0];
        			$minL=$latenciesArray[$key];
        			if($minOriginLatency>$minL && $key>1){
        				$minOriginLatency=$minL;
        			}
        		}*/
        /*
        	loop again and re-asign the min possible latency based on min value in subsequent hops
        	As it works on current Traceroute detail page
        */
        /*		foreach ($latenciesArray as $key => $value) {
        				//echo '<br/>... Checking hop '.$key;
        				$minLofAllNext = Traceroute::checkMinLatency($key, $latenciesArray);
        				$latenciesArrayCalculated[$key]=$minLofAllNext;
        			}
        */
        // log: comparison between actual min and calculated latencies
        /*echo '<textarea>$minOriginLatency: '. $minOriginLatency.'';
        		print_r($latenciesArray);
        		echo '</textarea>';*/
        /*			echo '<textarea>--- Calculated Latencies for each hop trId: ['.$activeTrId.']:';
        			print_r($latenciesArrayCalculated);
        			echo '</textarea>';
        */
        //////////////////////////
        // start loop over tr data array, where $i is an index of joined traceroute and tr_item tables
        for ($i = 0; $i < count($trArr); $i++) {
            //echo '****************************'.$trArr[$i]['hostname'];
            // key data for google display
            $trId = $trArr[$i]['id'];
            $hop = $trArr[$i]['hop'];
            $ip = $trArr[$i]['ip_addr'];
            /*			$lat = $trArr[$i]['mm_lat'];
            			$long = $trArr[$i]['mm_long'];
            */
            $lat = $trArr[$i]['lat'];
            $long = $trArr[$i]['long'];
            $num = $trArr[$i]['num'];
            $nameLen = strlen($trArr[$i]['name']);
            $pattern1 = '/ - /';
            preg_match_all($pattern1, $trArr[$i]['name'], $matches, PREG_SET_ORDER);
            if ($nameLen < 23) {
                $name = $trArr[$i]['name'] . '';
            } else {
                if (count($matches) == 1) {
                    $nameArr = explode(' - ', $trArr[$i]['name']);
                    $nameLen1 = strlen($nameArr[1]);
                    if ($nameLen1 > 23) {
                        $name = substr($nameArr[1], 0, 22) . '...';
                    } else {
                        $name = $nameArr[1] . '';
                    }
                    unset($nameArr);
                } else {
                    //$nameArr = explode(' ', $trArr[$i]['name']);
                    //$name = $nameArr[0].' : 3';
                    $name = substr($trArr[$i]['name'], 0, 22) . '...';
                }
            }
            unset($matches);
            // data needed for impossible distance calculation
            $dist_from_origin = 0;
            $imp_dist = 0;
            $imp_dist_txt = '';
            $time_light_will_do = 0;
            // old approach: use only the first attempt data
            $rtt_ms = $trArr[$i]['rtt_ms'];
            // new approach: use min latency out of the 4 attemps and correct it relative to the min latency of subsequent hops. This seems to be working quite well ;) There seems to be
            // Stil under development, causing a too much processing for Anto standards ;)
            //$rtt_ms = $latenciesArrayCalculated[$hop];
            // calclulate origin assuming it does have a hop number = 1; Note this is not 100% acurate as there might be traceroutes that have missed it and start on a number > 1
            //if($i==0){
            if ($hop == 1) {
                $latOrigin = $lat;
                $longOrigin = $long;
                $originAsn = $num;
            } else {
                // calculate distance from origin
                $dist_from_origin = Traceroute::distance($latOrigin, $longOrigin, $lat, $long, false);
                $time_light_will_do = $dist_from_origin / $SL;
                $time_light_will_do *= 2;
                // is it an imposible time? distance?
                //if($rtt_ms<$time_light_will_do){
                // use $minOriginLatency instead
                if ($rtt_ms < $time_light_will_do) {
                    $imp_dist = 1;
                    //$imp_dist_txt = '<b>YES!</b>';
                }
            }
            $lastHopIp = 0;
            $trData[$trId][] = array($ip, $hop, $lat, $long, $trId, $num, $name, $trArr[$i]['dest'], $trArr[$i]['dest_ip'], $trArr[$i]['submitter'], $trArr[$i]['mm_city'], $trArr[$i]['mm_country'], $trArr[$i]['sub_time'], $trArr[$i]['rtt_ms'], $trArr[$i]['gl_override'], $dist_from_origin, $imp_dist, $time_light_will_do, $latOrigin, $longOrigin, $lastHopIp, $trArr[$i]['flagged'], $trArr[$i]['hostname'], $trArr[$i]['country_code']);
            // write impossible distances to a CSV file: this method seems to be more secure and faster than doing in jQuery: NOTE: this is only for development version. It seems an overhead for production
            if ($imp_dist == 1) {
                $impDistanceLog = '' . $trId . ';' . $hop . ';"' . $trArr[$i]['mm_country'] . '";"' . $trArr[$i]['mm_city'] . '";' . $num . ';"' . $ip . '";' . $trArr[$i]['rtt_ms'] . ';' . $time_light_will_do . ';"' . $dist_from_origin . '";' . $trArr[$i]['gl_override'] . ';"' . $latOrigin . '";"' . $longOrigin . '";"' . $originAsn . '"
';
                //echo '<br/>'.$imp_dist_txt.$impDistanceLog;
                //fwrite($fhLog, $impDistanceLog);
            }
        }
        // end for
        //fclose($fhLog);
        //echo '<br/>Impossible Distances log saved at <a href="'.$myLogFileWeb.'">_log_'.$date.'.csv</a>';
        unset($trArr);
        return $trData;
        //unset($trData);
        /*		echo '<hr/><textarea>';
        		print_r($trData);
        		echo '</textarea>';
        */
    }
コード例 #4
0
    //$data='[{"constraint1":"does","constraint2":"originate","constraint3":"city","constraint4":"Halifax","constraint5":"AND"},{"constraint1":"does","constraint2":"goesVia","constraint3":"city","constraint4":"Toronto","constraint5":"AND"},{"constraint1":"does","constraint2":"terminate","constraint3":"city","constraint4":"Chicago","constraint5":""}]';
    // two
    //$data='[{"constraint1":"does","constraint2":"originate","constraint3":"city","constraint4":"Toronto","constraint5":"AND"},{"constraint1":"does","constraint2":"goesVia","constraint3":"city","constraint4":"Miami","constraint5":"AND"}]';
    $data = json_encode($dataArray);
    // one
    //$data='[{"constraint1":"does","constraint2":"originate","constraint3":"city","constraint4":"Toronto","constraint5":"AND"}]';
    Traceroute::saveSearch($data);
    //Traceroute::testArrays();
    $b = Traceroute::getTraceRoute($data);
    /*	if(count($b)>1000) {
    		echo '<p>The number of traceroutes found is greather than 1000. <br/>Please add new constraints to your query.</p>';
    
    	} else {
    		Traceroute::renderTrSets($b);
    	}*/
    Traceroute::renderTrSets($b);
    //Traceroute::buildWhere($data);
    //$trId = 1813;
    //echo 'TR id: '.$trId.' : Last Hop: '.Traceroute::getLastHop($trId);
    //Traceroute::getHop($trId, 'last');
}
// testing
/*
$c = array_diff($a, $b);
echo '<hr/>Difference: <b>'.count($c).'</b>';
//print_r($c);
Traceroute::renderTrSets($c);

$d = array_intersect($a, $b);
echo '<hr/>Intersects: : <b>'.count($d).'</b>';
//print_r($d);
コード例 #5
0
     $b = Traceroute::processQuickLink($dataArray);
 } else {
     $b = Traceroute::getTraceRoute($dataArray);
 }
 $data = json_encode($dataArray);
 $saveLog = Traceroute::saveSearch($data);
 //Traceroute::saveSearch($data);
 // get IXmaps geographic data and prepare the response into a json format
 //print_r($data);
 if (count($b) != 0) {
     $ixMapsData = Traceroute::getIxMapsData($b);
     //print_r($ixMapsData);
     $ixMapsDataT = Traceroute::dataTransform($ixMapsData);
     //print_r($ixMapsDataT);
     $ixMapsDataStats = Traceroute::generateDataForGoogleMaps($ixMapsDataT);
     $trHtmlTable = Traceroute::renderTrSets($ixMapsDataT);
 }
 // end calculation of execution time
 $mtime = microtime();
 $mtime = explode(" ", $mtime);
 $mtime = $mtime[1] + $mtime[0];
 $endtime = $mtime;
 $totaltime = $endtime - $starttime;
 $totaltime = number_format($totaltime, 2);
 //echo "<hr/>This page was created in <b>".$totaltime."</b> seconds";
 // add db query results/errors
 $ixMapsDataStats['querySummary'] = $dbQuerySummary;
 $ixMapsDataStats['queryLogs'] = $dbQueryHtml;
 //$ixMapsDataStats['queryLogs']=.$dbQueryHtml.'<hr/>'.$saveLog;
 // add excec time
 $ixMapsDataStats['execTime'] = $totaltime;
コード例 #6
0
<?php

include '../config.php';
include '../model/Traceroute.php';
if (!isset($_POST) || count($_POST) == 0) {
    echo '<br/><hr/>No parameters sent.';
} else {
    $sField = $_POST['field'];
    $sKeyword = $_POST['keyword'];
    echo Traceroute::getAutoCompleteData($sField, $sKeyword);
}
コード例 #7
0
 /**
  */
 public static function renderTrSets($data)
 {
     if (count($data) != 0) {
         Traceroute::getLongLat($data);
     }
     $html = '<hr/>';
     foreach ($data as $trId) {
         $html .= ' | <a href="javascript: viewTrDetails(' . $trId . ');">' . $trId . '</a>';
     }
     unset($data);
     echo $html;
 }