Ejemplo n.º 1
0
<?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.';
}
Ejemplo n.º 2
0
 /**
 	Analyze TR data. 
 	This function assumes that the tr data is structured as follows:
 	[tr_data][hop][queries]
 */
 public static function analyzeTrDataOld($tr_c_id)
 {
     global $dbconn;
     $data = GatherTr::getTrContribution($tr_c_id);
     //print_r($data);
     $TR = array();
     // submissions
     foreach ($data['traceroute_submissions'] as $key1 => $submission) {
         // check contribution type
         if ($submission['data_type'] == 'json') {
             $trHops = json_decode($submission['tr_data'], true);
             $totHops = count($trHops);
             //print_r($trHops);
             //hops
             foreach ($trHops as $key2 => $hop) {
                 $hopNum = $key2 + 1;
                 $latencies = array();
                 $ip_rank = array();
                 // queries
                 foreach ($hop as $key3 => $hopPass) {
                     //$hopPass['rtt'] = $hopPass['rtt']*100;
                     $latencies[] = $hopPass['rtt'];
                     $ip_latencies[$hopPass['ip']][] = $hopPass['rtt'];
                     // prevent ip !set
                     if (isset($hopPass['ip'])) {
                         if (!isset($ip_rank[$hopPass['ip']])) {
                             $ip_rank[$hopPass['ip']] = 1;
                         } else {
                             $ip_rank[$hopPass['ip']] += 1;
                         }
                     } else {
                         // error at this hop
                     }
                     //
                 }
                 // end queries
                 sort($latencies);
                 arsort($ip_rank);
                 $keys = array_keys($ip_rank);
                 $winnerIp = $keys[0];
                 //echo "\nWinner IP: ".$winnerIp;
                 $TR['hops'][$hopNum]['latencies'] = $latencies;
                 $TR['hops'][$hopNum]['winIp'] = $winnerIp;
             }
             //end hop
             //print_r($TR);
             $data['ip_analysis'] = $TR;
             return $data;
         } else {
             if ($submission['data_type'] == 'txt') {
                 //echo "\nis txt";
                 //$data = GatherTr::analyzeRawTracerouteTxt();
                 return 0;
                 // TODO:
             } else {
                 return 0;
             }
         }
     }
 }
Ejemplo n.º 3
0
//echo json_encode($_POST);
// TODO: Analysis of Legacy code
$_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 {