--- etc/rtg.php.orig 2003-09-24 20:42:03 UTC +++ etc/rtg.php @@ -1,146 +1,152 @@ \n\n\n"; + print "\n\n\n"; /* Connect to RTG MySQL Database */ - $dbc=@mysql_connect ($host, $user, $pass) or - $dbc=@mysql_connect ("$host:/var/lib/mysql/mysql.sock", $user, $pass) or + $dbc=@mysqli_connect ($host, $user, $pass, $db) or die ("MySQL Connection Failed, Check Configuration."); - mysql_select_db($db,$dbc); - if ($PHP_SELF == "") { + if (!isset($PHP_SELF) || $PHP_SELF == "") { $PHP_SELF = "rtg.php"; - $errors = $_GET['errors']; - $scalex = $_GET['scalex']; - $scaley = $_GET['scaley']; - $aggr = $_GET['aggr']; - $percentile = $_GET['percentile']; - $nth = $_GET['nth']; - $xplot = $_GET['xplot']; - $yplot = $_GET['yplot']; - $borderb = $_GET['borderb']; - $iid = $_GET['iid']; - $rid = $_GET['rid']; - $syear = $_GET['syear']; - $eyear = $_GET['eyear']; - $smonth = $_GET['smonth']; - $emonth = $_GET['emonth']; - $sday = $_GET['sday']; - $eday = $_GET['eday']; - $shour = $_GET['shour']; - $ehour = $_GET['ehour']; - $smin = $_GET['smin']; - $emin = $_GET['emin']; + $errors = isset($_GET['errors'])?$_GET['errors']:""; + $scalex = isset($_GET['scalex'])?$_GET['scalex']:""; + $scaley = isset($_GET['scaley'])?$_GET['scaley']:""; + $aggr = isset($_GET['aggr'])?$_GET['aggr']:""; + $percentile = isset($_GET['percentile'])?$_GET['percentile']:""; + $nth = isset($_GET['nth'])?$_GET['nth']:""; + $xplot = isset($_GET['xplot'])?$_GET['xplot']:""; + $yplot = isset($_GET['yplot'])?$_GET['yplot']:""; + $borderb = isset($_GET['borderb'])?$_GET['borderb']:""; + $iid = isset($_GET['iid'])?$_GET['iid']:""; + $rid = isset($_GET['rid'])?$_GET['rid']:""; + $syear = isset($_GET['syear'])?$_GET['syear']:""; + $eyear = isset($_GET['eyear'])?$_GET['eyear']:""; + $smonth = isset($_GET['smonth'])?$_GET['smonth']:""; + $emonth = isset($_GET['emonth'])?$_GET['emonth']:""; + $sday = isset($_GET['sday'])?$_GET['sday']:""; + $eday = isset($_GET['eday'])?$_GET['eday']:""; + $shour = isset($_GET['shour'])?$_GET['shour']:""; + $ehour = isset($_GET['ehour'])?$_GET['ehour']:""; + $smin = isset($_GET['smin'])?$_GET['smin']:""; + $emin = isset($_GET['emin'])?$_GET['emin']:""; } # Determine router, interface names as necessary - if ($rid && $iid) { - $selectQuery="SELECT a.name, a.description, a.speed, b.name AS router FROM interface a, router b WHERE a.rid=b.rid AND a.rid=$rid AND a.id=$iid[0]"; - $selectResult=mysql_query($selectQuery, $dbc); - $selectRow=mysql_fetch_object($selectResult); - $interfaces = mysql_num_rows($selectResult); + if (($rid != "") && ($iid != "")) { + $selectQuery="SELECT `a`.`name`, `a`.`description`, `a`.`speed`, `b`.`name` " . + "AS `router` FROM `interface` `a`, `router` `b` WHERE `a`.`rid`=`b`.`rid` " . + "AND `a`.`rid`=" . mysqli_real_escape_string($dbc, $rid) . " AND `a`.`id`=" . + mysqli_real_escape_string($dbc, $iid[0]); + $selectResult=mysqli_query($dbc, $selectQuery); + $selectRow=mysqli_fetch_object($selectResult); + $interfaces = mysqli_num_rows($selectResult); $name = $selectRow->name; $description = $selectRow->description; $speed = ($selectRow->speed)/1000000; $router = $selectRow->router; - } else if ($rid && !$iid) { - $selectQuery="SELECT name AS router from router where rid=$rid"; - $selectResult=mysql_query($selectQuery, $dbc); - $selectRow=mysql_fetch_object($selectResult); + } else if (($rid != "") && ($iid == "")) { + $selectQuery="SELECT `name` AS `router` FROM `router` WHERE `rid`=" . + mysqli_real_escape_string($dbc, $rid); + $selectResult=mysqli_query($dbc, $selectQuery); + $selectRow=mysqli_fetch_object($selectResult); $router = $selectRow->router; } # Generate Title - echo "RTG: "; - if ($rid && $iid) echo "$router: $name"; - else if ($rid && !$iid) echo "$router"; - echo "\n"; + echo "RTG: "; + if (($rid != "") && ($iid != "")) echo "$router: $name"; + else if (($rid != "") && ($iid == "")) echo "$router"; + echo "\n"; ?> - - - - - -

+ + + +

\n"; +echo "

\n"; -if (!$rid && !$iid) { - echo "\n"; + $selectQuery="SELECT DISTINCT `name`, `rid` FROM `router` ORDER BY `name`"; + $selectResult=mysqli_query($dbc, $selectQuery); + while ($selectRow=mysqli_fetch_object($selectResult)){ + echo "\n"; } - echo "\n"; + echo "\n"; } -if ($smonth != "" && $iid == "") { - echo "
\n"; +if (($smonth != "") && ($iid == "")) { + echo "
\n"; echo "Please select an interface!\n"; - echo "
\n"; + echo "
\n"; } -if ($rid && !$iid) { - echo "\n"; +if (($rid != "") && ($iid == "")) { + echo "\n"; - echo "\n"; + $selectQuery="SELECT `id`, `name`, `description` FROM `interface` WHERE " . + "`rid`=" . mysqli_real_escape_string($dbc, $rid) . " ORDER BY `name`"; + $selectResult=mysqli_query($dbc, $selectQuery); + while ($selectRow=mysqli_fetch_object($selectResult)){ + echo "\n"; } - echo "\n"; + echo "\n"; - echo "

\n"; - echo ""; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
From: \n"; - echo "\n"; + echo "\n"; + echo ""; + echo "\n"; - echo "\n"; + echo "
From: / \n"; - echo " / \n"; + echo " / \n"; - echo " / \n"; + echo "\n"; - echo ":\n"; - echo "\n"; + echo "\" />\n"; + echo ":\n"; + echo "\n"; + echo "
To: \n"; - echo "To: / \n"; - echo " / \n"; + echo " / \n"; - echo " / \n"; + echo "\n"; - echo ":\n"; - echo "\n"; - echo "
Aggregate Interfaces: \n"; - echo "\n"; - echo "
th Percentile: \n"; - echo "\n"; - echo "
Fit to Data: \n"; - echo "\n"; - echo "
Fit to Speed: \n"; - echo "\n"; - echo "
X Size: \n"; - echo "\n"; - echo "
Y Size: \n"; - echo "\n"; - echo "
BorderB: \n"; - echo "\n"; - echo "
\n"; + echo "\" />\n"; + echo "
:\n"; + echo "\n"; + echo "
Aggregate Interfaces:
th Percentile:
Fit to Data:
Fit to Speed:
X Size:
Y Size:
BorderB:
\n"; } -if (($bt || $smonth) && $iid) { +if (($bt != "" || $smonth != "") && ($iid != "")) { /* Format into GNU date syntax */ if ($bt == "") { @@ -148,67 +154,84 @@ if (($bt || $smonth) && $iid) { $et = strtotime("$eyear-$emonth-$eday $ehour:$emin:59"); } - $range="dtime>FROM_UNIXTIME($bt) AND dtime<=FROM_UNIXTIME($et)"; - $range="$range AND id=$iid[0]"; + $range="`dtime`>FROM_UNIXTIME(" . mysqli_real_escape_string($dbc, $bt) . ") AND " . + "`dtime`<=FROM_UNIXTIME(" . mysqli_real_escape_string($dbc, $et) . ") " . + "AND `id`=" . mysqli_real_escape_string($dbc, $iid[0]); - $selectQuery="SELECT description, name, speed FROM interface WHERE rid=$rid AND id=$iid[0]"; - $selectResult=mysql_query($selectQuery, $dbc); - $selectRow=mysql_fetch_object($selectResult); - echo "\n"; - echo "\n"; - echo "\n"; - printf ("\n", $selectRow->speed / 1000000); - echo "\n"; - print strftime("\n", $et); - echo "
Device:$router ($rid)
Interface:$selectRow->name ($iid[0])
Speed:%2.3f Mbps
Description:$selectRow->description
Period:%m/%d/%Y %H:%M - ", $bt); - print strftime("%m/%d/%Y %H:%M
\n"; - echo "

\n"; + $selectQuery="SELECT `description`, `name`, `speed` FROM `interface` WHERE " . + "`rid`=" . mysqli_real_escape_string($dbc, $rid) . " AND `id`=" . + mysqli_real_escape_string($dbc, $iid[0]); + $selectResult=mysqli_query($dbc, $selectQuery); + $selectRow=mysqli_fetch_object($selectResult); + echo "\n"; + echo "\n"; + echo "\n"; + printf ("\n", $selectRow->speed / 1000000); + echo "\n"; + print strftime("\n", $et); + echo "\n"; + echo "
Device:$router ($rid)
Interface:$selectRow->name ($iid[0])
Speed:%2.3f Mbps
Description:$selectRow->description
Period:%m/%d/%Y %H:%M - ", $bt); + print strftime("%m/%d/%Y %H:%M
\n"; + echo "

\n"; #$selectQuery="SELECT DISTINCT id FROM ifInOctets_$rid WHERE $range"; - #$selectResult=mysql_query($selectQuery, $dbc); - #if (mysql_num_rows($selectResult) <= 0) { + #$selectResult=mysqli_query($dbc, $selectQuery); + #if (mysqli_num_rows($selectResult) <= 0) { # print "
No Data Found on Interface for Given Range.
\n"; #} #else { - $args = "t1=ifInOctets_$rid&t2=ifOutOctets_$rid&begin=$bt&end=$et&units=bits/s&factor=8"; + $args = "t1=ifInOctets_$rid&t2=ifOutOctets_$rid&begin=$bt&"; + $args .= "end=$et&units=bits/s&factor=8"; + $args .= "&title=" . urlencode($selectRow->description); + $args .= "&t1_name=" . urlencode("Input Octets"); + $args .= "&t2_name=" . urlencode("Output Octets"); foreach ($iid as $value) { - $args="$args&iid=$value"; + $args="$args&iid=" . urlencode($value); } - if ($scalex) $args = "$args&scalex=yes"; - if ($scaley) $args = "$args&scaley=yes"; - if ($xplot) $args = "$args&xplot=$xplot"; - if ($yplot) $args = "$args&yplot=$yplot"; - if ($borderb) $args = "$args&borderb=$borderb"; - if ($aggr) $args = "$args&aggr=yes"; - if ($percentile) $args = "$args&percentile=$nth"; - print "
\n"; - $args = "t1=ifInUcastPkts_$rid&t2=ifOutUcastPkts_$rid&begin=$bt&end=$et&units=pkts/s"; + if ($scalex != "") $args = "$args&scalex=yes"; + if ($scaley != "") $args = "$args&scaley=yes"; + if ($xplot != "") $args = "$args&xplot=$xplot"; + if ($yplot != "") $args = "$args&yplot=$yplot"; + if ($borderb != "") $args = "$args&borderb=$borderb"; + if ($aggr != "") $args = "$args&aggr=yes"; + if ($percentile != "") $args = "$args&percentile=$nth"; + print "\"graph\"
\n"; + $args = "t1=ifInUcastPkts_$rid&t2=ifOutUcastPkts_$rid&begin=$bt&"; + $args .= "end=$et&units=pkts/s"; + $args .= "&title=" . urlencode($selectRow->description); + $args .= "&t1_name=" . urlencode("Input Packets"); + $args .= "&t2_name=" . urlencode("Output Packets"); foreach ($iid as $value) { - $args="$args&iid=$value"; + $args="$args&iid=" . urlencode($value); + } + if ($scalex != "") $args = "$args&scalex=yes"; + if ($xplot != "") $args = "$args&xplot=$xplot"; + if ($yplot != "") $args = "$args&yplot=$yplot"; + if ($borderb != "") $args = "$args&borderb=$borderb"; + if ($aggr != "") $args = "$args&aggr=yes"; + if ($percentile != "") $args = "$args&percentile=$nth"; + print "\"graph\"
\n"; + if ($errors != "") + { + print "\"graph\"\n"; } - if ($scalex) $args = "$args&scalex=yes"; - if ($xplot) $args = "$args&xplot=$xplot"; - if ($yplot) $args = "$args&yplot=$yplot"; - if ($borderb) $args = "$args&borderb=$borderb"; - if ($aggr) $args = "$args&aggr=yes"; - if ($percentile) $args = "$args&percentile=$nth"; - print "
\n"; - if ($errors) - print "\n"; # } } -mysql_close($dbc); +mysqli_close($dbc); ?> -

- -

-
-
- +

+ + +
+


+ RTG Version $VERSION"; -?> - - + print "RTG Version $VERSION
"; +?>

+ +