Esempio n. 1
0
 /**
 Key Function!
 Get TR data for set of constraints
 */
 public static function getTraceRoute($data)
 {
     global $dbconn, $dbQueryHtml, $dbQuerySummary;
     $result = array();
     $trSets = array();
     $conn = 0;
     $limit1 = 4500;
     $limit2 = 5000;
     $offset = 0;
     $doesNotChk = false;
     // loop constraints
     foreach ($data as $constraint) {
         $dbQuerySummary .= '<br><b>' . $constraint['constraint1'] . ' : ' . $constraint['constraint2'] . ' : ' . $constraint['constraint3'] . ' : ' . $constraint['constraint4'] . ' : ' . $constraint['constraint5'] . '</b>';
         $w = '';
         $wParams = array();
         $sql = "SELECT as_users.num, tr_item.traceroute_id, traceroute.id, ip_addr_info.mm_city, ip_addr_info.ip_addr, ip_addr_info.asnum FROM as_users, tr_item, traceroute, ip_addr_info WHERE (tr_item.traceroute_id=traceroute.id) AND (ip_addr_info.ip_addr=tr_item.ip_addr) AND (as_users.num=ip_addr_info.asnum)";
         $sqlOrder = ' order by tr_item.traceroute_id, tr_item.hop, tr_item.attempt';
         $aa = 0;
         // adding exception for doesnot cases
         if ($constraint['constraint1'] == 'doesNot' && $constraint['constraint2'] != 'originate' && $constraint['constraint2'] != 'terminate') {
             //echo "IF: doesNot && !=originate && terminate";
             $oppositeSet = array();
             $positiveSet = array();
             //$w.=''.Traceroute::buildWhere($constraint);
             $wParams = Traceroute::buildWhere($constraint);
             $sqlTemp = $sql;
             //$sqlTemp.=$w.$sqlOrder;
             $sqlTemp .= $wParams[0] . $sqlOrder;
             $positiveSet = Traceroute::getTrSet($sqlTemp, $wParams[1]);
             // getting oposite set for diff comparison
             /*$sqlOposite = $sql;
             		$sqlOposite .= Traceroute::buildWhere($constraint,$doesNotChk);
             		$sqlOposite .= $sqlOrder;
             		$oppositeSet = Traceroute::getTrSet($sqlOposite);*/
             $doesNotChk = true;
             $sqlOposite = $sql;
             $wParams = Traceroute::buildWhere($constraint, $doesNotChk);
             //$sqlOposite .= Traceroute::buildWhere($constraint,$doesNotChk);
             $sqlOposite .= $wParams[0] . $sqlOrder;
             //$oppositeSet = Traceroute::getTrSet($sqlOposite);
             $oppositeSet = Traceroute::getTrSet($sqlOposite, $wParams[1]);
             //echo '<br/><i>'.$sqlOposite.'</i>';
             //echo '<br/>Opposite Set: '.count($oppositeSet);
             $trSets[$conn] = array_diff($positiveSet, $oppositeSet);
             //echo '<hr/>'.count($trSets[$conn]);
             $doesNotChk = false;
             unset($oppositeSet);
             unset($positiveSet);
             //unset($diff);
             // adding an exception for "terminate": This option is now querying tr_last_hops reference table
         } else {
             if ($constraint['constraint2'] == 'terminate') {
                 //echo "IF: terminate";
                 $tApproach = 1;
                 if ($tApproach == 0) {
                     // old approach: using dest_ip
                     $sql = "SELECT as_users.num, tr_item.traceroute_id, traceroute.id, ip_addr_info.mm_city, ip_addr_info.ip_addr, ip_addr_info.asnum FROM as_users, tr_item, traceroute, ip_addr_info WHERE (tr_item.traceroute_id=traceroute.id) AND (ip_addr_info.ip_addr=tr_item.ip_addr) AND (as_users.num=ip_addr_info.asnum)";
                     $sqlOrder = ' order by tr_item.traceroute_id, tr_item.hop, tr_item.attempt';
                     $w .= " AND (traceroute.dest_ip=ip_addr_info.ip_addr) AND tr_item.attempt = 1 AND tr_item.hop > 1";
                     //$w.=''.Traceroute::buildWhere($constraint);
                     $wParams = Traceroute::buildWhere($constraint);
                     $w .= '' . $wParams[0];
                     //$dbQuerySummary.='<BR/>CASE B:';
                 } else {
                     if ($tApproach == 1) {
                         // new approach: using tr_last_hops
                         $sql = "SELECT as_users.num, tr_last_hops.traceroute_id_lh, tr_last_hops.reached, traceroute.id, ip_addr_info.mm_city, ip_addr_info.ip_addr, ip_addr_info.asnum FROM tr_last_hops, as_users, traceroute, ip_addr_info WHERE (as_users.num=ip_addr_info.asnum) AND (traceroute.id=tr_last_hops.traceroute_id_lh) AND (ip_addr_info.ip_addr=tr_last_hops.ip_addr_lh) ";
                         $sqlOrder = ' order by traceroute.id';
                         // this is doing nothing I believe, as all the sql is not created here
                         //$w.=''.Traceroute::buildWhere($constraint);
                         $wParams = Traceroute::buildWhere($constraint);
                         $w .= '' . $wParams[0];
                         //$dbQuerySummary.='<BR/>CASE A:';
                     }
                 }
                 $sql .= $w . $sqlOrder;
                 //	echo "<hr/>".$sql;
                 $trSets[$conn] = Traceroute::getTrSet($sql, $wParams[1]);
                 $operands[$conn] = $constraint['constraint5'];
             } else {
                 //echo "IF: all the other cases";
                 //$w.=''.Traceroute::buildWhere($constraint);
                 $wParams = Traceroute::buildWhere($constraint);
                 $w .= '' . $wParams[0];
                 $sql .= $w . $sqlOrder;
                 //echo '<br/><i>'.$sql.'</i>';
                 $trSets[$conn] = Traceroute::getTrSet($sql, $wParams[1]);
                 $operands[$conn] = $constraint['constraint5'];
             }
         }
         //echo '<br/><i>'.$sql.'</i>';
         // add SQL to log file
         //$dbQuerySummary.='<br/>'.$sql;
         $conn++;
     }
     // end for each
     $trSetResult = array();
     for ($i = 0; $i < $conn; $i++) {
         $trSetResultTemp = array();
         // only one constraint
         if ($i == 0) {
             //$trSetResult=$trSets[0];
             $trSetResult = array_merge($trSetResult, $trSets[0]);
             // all in between
         } else {
             if ($i > 0) {
                 if ($data[$i - 1]['constraint5'] == 'OR') {
                     $trSetResultTemp = array_merge($trSetResult, $trSets[$i]);
                     //$trSetResultTemp = array_merge($trSets[$i-1],$trSets[$i]);
                     $trSetResultTemp = array_unique($trSetResultTemp);
                     //echo '<br/>ToT trSetResultTemp: '.count($trSetResultTemp);
                     $trSetResult = array_merge($trSetResult, $trSetResultTemp);
                 } else {
                     $trSetResultTemp = array_intersect($trSetResult, $trSets[$i]);
                 }
                 $trSetResult = array();
                 $empty = array();
                 $trSetResult = array_merge($empty, $trSetResultTemp);
             }
         }
         //$dbQuerySummary .='<hr/>'.$sql;
     }
     // end for
     $trSetResultLast = array_unique($trSetResult);
     // FIXME: move this to the client. make this count based on the # of TR resulting in the set
     // It's already done. need to fix UI loading of data
     $dbQuerySummary .= '<br/>Total traceroutes : <b>' . count($trSetResultLast) . "</b><br />";
     //echo '<hr/>getTraceRoute: '.memory_get_usage();
     unset($trSetResult);
     unset($trSetResultTemp);
     unset($trSets);
     //echo '<hr/>getTraceRoute: '.memory_get_usage();
     return $trSetResultLast;
 }
Esempio n. 2
0
 /**
  */
 public static function getTraceRoute($data)
 {
     global $dbconn;
     $result = array();
     $trSets = array();
     $conn = 0;
     $limit1 = 4500;
     $limit2 = 5000;
     $offset = 0;
     $doesNotChk = false;
     // loop constraints
     foreach ($data as $constraint) {
         //if($ixmaps_debug_mode) {
         echo '<br><b>' . $constraint['constraint1'] . ' : ' . $constraint['constraint2'] . ' : ' . $constraint['constraint3'] . ' : ' . $constraint['constraint4'] . ' : ' . $constraint['constraint5'] . '</b>';
         //}
         $w = '';
         $sql = '';
         $sql = "SELECT as_users.num, tr_item.traceroute_id, traceroute.id, ip_addr_info.mm_city, ip_addr_info.ip_addr, ip_addr_info.asnum FROM as_users, tr_item, traceroute, ip_addr_info WHERE (tr_item.traceroute_id=traceroute.id) AND (ip_addr_info.ip_addr=tr_item.ip_addr) AND (as_users.num=ip_addr_info.asnum)";
         $sqlOrder = ' order by tr_item.traceroute_id, tr_item.hop, tr_item.attempt';
         /*
          */
         $aa = 0;
         // adding exception for doesnot cases
         if ($constraint['constraint1'] == 'doesNot' && $constraint['constraint2'] != 'originate' && $constraint['constraint2'] != 'terminate') {
             $oppositeSet = array();
             $positiveSet = array();
             $w .= '' . Traceroute::buildWhere($constraint);
             $sqlTemp = $sql;
             $sqlTemp .= $w . $sqlOrder;
             $positiveSet = Traceroute::getTrSet($sqlTemp);
             /*echo '<br/><i>'.$sqlTemp.'</i>';
             		echo '<br/>positiveSet: '.count($positiveSet);*/
             $doesNotChk = true;
             // getting oposite set for diff comparison
             $sqlOposite = $sql;
             $sqlOposite .= Traceroute::buildWhere($constraint, $doesNotChk);
             $sqlOposite .= $sqlOrder;
             $oppositeSet = Traceroute::getTrSet($sqlOposite);
             //echo '<br/><i>'.$sqlOposite.'</i>';
             //echo '<br/>Opposite Set: '.count($oppositeSet);
             $trSets[$conn] = array_diff($positiveSet, $oppositeSet);
             //echo '<hr/>'.count($trSets[$conn]);
             $doesNotChk = false;
             unset($oppositeSet);
             unset($positiveSet);
             //unset($diff);
         } else {
             $w .= '' . Traceroute::buildWhere($constraint);
             $sql .= $w . $sqlOrder;
             $trSets[$conn] = Traceroute::getTrSet($sql);
             $operands[$conn] = $constraint['constraint5'];
             //echo '<br/><i>'.$sql.'</i>';
         }
         //echo " | Traceroutes: <b>".count($trSets[$conn]).'</b>';
         //echo '<hr>';
         //print_r($constraint);
         //$sql .=$w.' and traceroute.id between '.$limit1.' AND '.$limit2.' order by tr_item.traceroute_id, tr_item.hop, tr_item.attempt';
         //LIMIT '.$limit.' OFFSET '.$offset.''
         //$newTrSet = array(Traceroute::getTrSet($constraint), $operand);
         //print_r($trSets[$conn]);
         //$trSets[$conn]=$newTrSet;
         //$sql.= " ".Traceroute::buildWhere($constraint);
         $conn++;
     }
     // end for each
     $trSetResult = array();
     //echo '<hr/>';
     for ($i = 0; $i < $conn; $i++) {
         $trSetResultTemp = array();
         // only one constraint
         if ($i == 0) {
             //$trSetResult=$trSets[0];
             $trSetResult = array_merge($trSetResult, $trSets[0]);
             // all in between
         } else {
             if ($i > 0) {
                 if ($data[$i - 1]['constraint5'] == 'OR') {
                     /*					echo '<br/>OR case. Merging';
                     					echo '<br/>ToT trSetResult: '.count($trSetResult);
                     					echo '<br/>ToT trSets['.$i.']: '.count($trSets[$i]);
                     */
                     $trSetResultTemp = array_merge($trSetResult, $trSets[$i]);
                     //$trSetResultTemp = array_merge($trSets[$i-1],$trSets[$i]);
                     $trSetResultTemp = array_unique($trSetResultTemp);
                     //echo '<br/>ToT trSetResultTemp: '.count($trSetResultTemp);
                     $trSetResult = array_merge($trSetResult, $trSetResultTemp);
                 } else {
                     /*echo '<br/>AND case. Intersecting';
                     		echo '<br/>ToT trSetResult: '.count($trSetResult);
                     		echo '<br/>ToT trSets['.$i.']: '.count($trSets[$i]);*/
                     //$trSetResultTemp = array_intersect($trSetResult,$trSets[$i]);
                     $trSetResultTemp = array_intersect($trSetResult, $trSets[$i]);
                     //echo '<br/>ToT trSetResultTemp: '.count($trSetResultTemp);
                 }
                 $trSetResult = array();
                 $empty = array();
                 $trSetResult = array_merge($empty, $trSetResultTemp);
                 //$trSetResult =  array_merge($trSetResult, $trSetResultTemp);
             }
         }
         //echo '<br/>--- ToT trSetResult: ['.$i.'] '.count($trSetResult);
     }
     // end for
     $trSetResultLast = array_unique($trSetResult);
     //$trSetResult = array_intersect($trSets[0],$trSets[1],$trSets[2]);
     echo '<br/>Total traceroutes : <b>' . count($trSetResultLast) . "</b>";
     //echo '<hr/>getTraceRoute: '.memory_get_usage();
     unset($trSetResult);
     unset($trSetResultTemp);
     unset($trSets);
     //echo '<hr/>getTraceRoute: '.memory_get_usage();
     return $trSetResultLast;
 }
Esempio n. 3
0
 /**
  */
 public static function getTraceRoute($data)
 {
     global $dbconn;
     $result = array();
     $data_array = json_decode($data, ture);
     $trSets = array();
     $conn = 0;
     $limit1 = 4500;
     $limit2 = 5000;
     $offset = 0;
     // loop constraints
     foreach ($data_array as $constraint) {
         $w = '';
         $sql = '';
         $sql = "SELECT as_users.num, tr_item.traceroute_id, traceroute.id, ip_addr_info.mm_city, ip_addr_info.ip_addr, ip_addr_info.asnum FROM as_users, tr_item, traceroute, ip_addr_info WHERE (tr_item.traceroute_id=traceroute.id) AND (ip_addr_info.ip_addr=tr_item.ip_addr) AND (as_users.num=ip_addr_info.asnum)";
         $w .= '' . Traceroute::buildWhere($constraint);
         //$sql .=$w.' and traceroute.id between '.$limit1.' AND '.$limit2.' order by tr_item.traceroute_id, tr_item.hop, tr_item.attempt';
         $sql .= $w . ' order by tr_item.traceroute_id, tr_item.hop, tr_item.attempt';
         //LIMIT '.$limit.' OFFSET '.$offset.''
         //echo '<br/><i>'.$sql.'</i>';
         //$newTrSet = array(Traceroute::getTrSet($constraint), $operand);
         $trSets[$conn] = Traceroute::getTrSet($sql);
         //print_r($trSets[$conn]);
         //$trSets[$conn]=$newTrSet;
         //$sql.= " ".Traceroute::buildWhere($constraint);
         $conn++;
     }
     // end for each
     $trSetResult = array();
     //echo '<hr/>';
     for ($i = 0; $i < $conn; $i++) {
         $trSetResultTemp = array();
         // only one constraint
         if ($i == 0) {
             //$trSetResult=$trSets[0];
             $trSetResult = array_merge($trSetResult, $trSets[0]);
             // all in between
         } else {
             if ($i > 0) {
                 if ($data_array[$i - 1]['constraint5'] == 'OR') {
                     /*
                     	echo '<br/>OR case. Merging';
                     	echo '<br/>ToT trSetResult: '.count($trSetResult);
                     	echo '<br/>ToT trSets['.$i.']: '.count($trSets[$i]);
                     */
                     $trSetResultTemp = array_merge($trSetResult, $trSets[$i]);
                     //$trSetResultTemp = array_merge($trSets[$i-1],$trSets[$i]);
                     $trSetResultTemp = array_unique($trSetResultTemp);
                     //echo '<br/>ToT trSetResultTemp: '.count($trSetResultTemp);
                     $trSetResult = array_merge($trSetResult, $trSetResultTemp);
                 } else {
                     /*echo '<br/>AND case. Intersecting';
                     		echo '<br/>ToT trSetResult: '.count($trSetResult);
                     		echo '<br/>ToT trSets['.$i.']: '.count($trSets[$i]);*/
                     //$trSetResultTemp = array_intersect($trSetResult,$trSets[$i]);
                     $trSetResultTemp = array_intersect($trSetResult, $trSets[$i]);
                     //echo '<br/>ToT trSetResultTemp: '.count($trSetResultTemp);
                 }
                 $trSetResult = array();
                 $empty = array();
                 $trSetResult = array_merge($empty, $trSetResultTemp);
                 //$trSetResult =  array_merge($trSetResult, $trSetResultTemp);
             }
         }
         //echo '<br/>--- ToT trSetResult: ['.$i.'] '.count($trSetResult);
     }
     // end for
     $trSetResultLast = array_unique($trSetResult);
     //$trSetResult = array_intersect($trSets[0],$trSets[1],$trSets[2]);
     echo '<hr/><a name="tot-trs" id="tot-trs"></a>Total traceroutes : <b>' . count($trSetResultLast) . "</b>";
     //echo '<hr/>getTraceRoute: '.memory_get_usage();
     unset($trSetResult);
     unset($trSetResultTemp);
     unset($trSets);
     //echo '<hr/>getTraceRoute: '.memory_get_usage();
     return $trSetResultLast;
 }