<?
$srcfile = $_GET['srcfile'];
if ($srcfile == "stats" OR $srcfile == "rate" OR $srcfile == "normal") {
global $meta;
$meta = "<meta http-equiv=\"refresh\" content=\"10;url=reports.php?srcfile=$srcfile\">";
}
// reportts.php : All code hear is to view the status of the ipvsadm table
// It needs to display both required AND acctual status ?
// Copyright Loadbalancer.org Limited all source code protected by the GPL with NO WARRANTY.
// function warn_no_results($arrtext) Quick function to avoid duplication
include ("../inc/header.inc");
include ("../inc/functions.inc");
# This code opens a file, reads it into an array and then writes it back to a file.
If ($srcfile=="pickup") { // Just dump the connection table to screen.
$output = `sudo cat /etc/scop/pickup.txt`;
echo "<pre>$output</pre>";
}
If ($srcfile=="route") { // Just dump the connection table to screen.
exec ("sudo /sbin/route -vn > /var/www/html/scop/stats/route.html");
$output = `sudo /sbin/route -vn`;
echo "<pre>$output</pre>";
}
If ($srcfile=="connection") { // Just dump the connection table to screen.
$output = `sudo /sbin/ipvsadm -Lcn`;
echo "<pre>$output</pre>";
}
If ($srcfile=="connectionwithlookup") { // Same again but with a DNS lookup
$output = `sudo /sbin/ipvsadm -Lc`;
echo "<pre>$output</pre>";
}
If ($srcfile=="ifconfig") { // Dump the status of the NICs too the screen
$output = `sudo ifconfig`;
echo "<pre>$output</pre>";
}
If ($srcfile=="clear") { // Re-set the packet counters to zero
exec ("sudo ipvsadm -Z");
echo "<p>The packet counters have now been cleared.</p>";
SCOP_log("Reports : Packet counters cleared.");
}
If ($srcfile=="ldirectordlog") { // View the ldirectord log file (Highlighting would be nice ?)
if (filesize("/var/log/ldirectord.log")==0) {
echo "The ldirectord log has been archived and is currently empty<br>";
echo "You can use SCP to access the archived logs if required<br>";
} else {
$output = `sudo cat /var/log/ldirectord.log`;
echo "<pre>$output</pre>";
}
// Show refresh button
echo "</br><FORM method=\"post\" action=\"reports.php?srcfile=ldirectordlog&t=$t\"> <INPUT type=\"submit\" value=\"Check Status\" name=\"go\" ></form>";
SCOP_log("Reports : Ldirectord log viewed.");
}
If ($srcfile=="heartbeatlog") { // View the Heartbeat log file
if (filesize("/var/log/ha-log")==0) {
echo "The Heartbeat log has been archived and is currently empty<br>";
echo "You can use SCP to access the archived logs if required<br>";
} else {
$output = `sudo cat /var/log/ha-log`;
echo "<pre>$output</pre>";
}
// Show refresh button
echo "</br><FORM method=\"post\" action=\"reports.php?srcfile=heartbeatlog&t=$t\"> <INPUT type=\"submit\" value=\"Check Status\" name=\"go\" ></form>";
SCOP_log("Reports : Heartbeat log viewed.");
}
If ($srcfile=="SCOPlog") { // View the Heartbeat log file
if (filesize("/var/log/scop-log")==0) {
echo "The SCOP log has been archived and is currently empty<br>";
echo "You can use SCP to access the archived logs if required<br>";
} else {
$output = `sudo cat /var/log/scop-log`;
echo "<pre>$output</pre>";
}
// Show refresh button
echo "</br><FORM method=\"post\" action=\"reports.php?srcfile=SCOPlog&t=$t\"> <INPUT type=\"submit\" value=\"Check Status\" name=\"go\" ></form>";
}
If ($srcfile=="haresources") { // View the hareasources file i.e what VIPs we are using
$output = `sudo cat /etc/ha.d/haresources`;
echo "<pre>$output</pre>";
}
If ($srcfile=="firewall") {
$output = `sudo /usr/sbin/iptables -L -t nat`;
echo "<pre>$output</pre>";
}
If ($srcfile=="stats") { // The main status report showing active and inactive connecctions
parse_config_file(); // Read the file and setup the global variables
exec ("sudo /sbin/ipvsadm -Ln --stats > /var/www/html/scop/stats/stats.html");
exec ("sudo chmod 777 /var/www/html/scop/stats/stats.html");
if ($arrtext = file("/var/www/html/scop/stats/stats.html")) {
} else {
echo "<font color='#010000'> The file <b>/var/www/html/scop/stats/stats.html</b> does not have the correct permissions.</br>";
}
warn_no_results($arrtext); //Check we got a response from ipvsadm
// Show refresh button
echo "<FORM method=\"post\" action=\"reports.php?srcfile=stats&t=$t\"> <INPUT type=\"submit\" value=\"Check Status\" name=\"go\" ></form>";
$item=0;
for ( $i=3; $i<count($arrtext); $i++) {
# If the line is not a remark then tokenise on newline or tab
$tok = strtok(ltrim($arrtext[$i])," \n\t");
while ($tok) {
$value0[$item]=$tok;
#echo "</br>attribute = " . $Attribute[$item];
$tok = strtok(" \n\t");
$value1[$item]=$tok;
#echo "</br>value1 = " . $value1[$item];
$tok = strtok(" \n\t");
$value2[$item]=$tok;
#echo "</br>value2 = " . $value2[$item];
$tok = strtok(" \n\t");
$value3[$item]=$tok;
#echo "</br>value3 = " . $value3[$item];
$tok = strtok(" \n\t");
$value4[$item]=$tok;
#echo "</br>value4 = " . $value4[$item];
$tok = strtok(" \n\t");
$value5[$item]=$tok;
#echo "</br>value5 = " . $value5[$item];
$tok = strtok(" \n\t");
$value6[$item]=$tok;
#echo "</br>value6 = " . $value6[$item];
# first word is attribute
# Second word is value
$tok = strtok(" \n\t");
$item=$item+1;
}
}
echo "</hr>";
$VIP=0;
for ( $b=0; $b<$item; $b++) {
If ($value0[$b]=="TCP" OR $value0[$b]=="FWM" OR $value0[$b]=="UDP") {
#VIP line
if ($VIP<>0) {echo "</table>";}
$RIP=0;
$VIP=$VIP+1;
$vipip = $value1[$b];
$viplabel = Get_vip_label($vipip);
echo "</br><b>Virtual Server " . $VIP . " -> <i>$viplabel</i></b></br> ";
echo $value1[$b] . "</br>";
echo "<table width=\"60%\"><th>Real IP Address:Port</th><th>Label</th><th>Connections</th><th>Incomming Packets</th><th>Outgoing Packets</th><th>Incoming Bytes</th><th>Outgoing Bytes</th> ";
} else {
$riplabel = Get_rip_label($vipip,$value1[$b]);
echo "<tr><td> $value1[$b] </td><td><i> $riplabel </i></td><td>$value2[$b]</td><td>$value3[$b]</td><td>$value4[$b]</td><td>$value5[$b]</td><td>$value6[$b]</td></tr>";
}
}
echo "</table>";
SCOP_log("Reports : Stats viewed.");
}
If ($srcfile=="rate") {
parse_config_file(); // Read the file and setup the global variables
exec ("sudo /sbin/ipvsadm -Ln --rate > /var/www/html/scop/stats/rate.html");
exec ("sudo chmod 777 /var/www/html/scop/stats/rate.html");
if ($arrtext = file("/var/www/html/scop/stats/rate.html")) {
} else {
echo "<font color='#010000'> The file <b>/var/www/html/scop/stats/rate.html</b> does not have the correct permissions.</br>";
}
warn_no_results($arrtext); //Check we got a response from ipvsadm
// Show refresh button
echo "<FORM method=\"post\" action=\"reports.php?srcfile=rate&t=$t\"> <INPUT type=\"submit\" value=\"Check Status\" name=\"go\" ></form>";
$item=0;
for ( $i=3; $i<count($arrtext); $i++) {
# If the line is not a remark then tokenise on newline or tab
$tok = strtok(ltrim($arrtext[$i])," \n\t");
while ($tok) {
$value0[$item]=$tok;
#echo "</br>attribute = " . $Attribute[$item];
$tok = strtok(" \n\t");
$value1[$item]=$tok;
#echo "</br>value1 = " . $value1[$item];
$tok = strtok(" \n\t");
$value2[$item]=$tok;
#echo "</br>value2 = " . $value2[$item];
$tok = strtok(" \n\t");
$value3[$item]=$tok;
#echo "</br>value3 = " . $value3[$item];
$tok = strtok(" \n\t");
$value4[$item]=$tok;
#echo "</br>value4 = " . $value4[$item];
$tok = strtok(" \n\t");
$value5[$item]=$tok;
#echo "</br>value5 = " . $value5[$item];
$tok = strtok(" \n\t");
$value6[$item]=$tok;
#echo "</br>value6 = " . $value6[$item];
# first word is attribute
# Second word is value
$tok = strtok(" \n\t");
$item=$item+1;
}
}
echo "</hr>";
$VIP=0;
for ( $b=0; $b<$item; $b++) {
If ($value0[$b]=="TCP" OR $value0[$b]=="FWM" OR $value0[$b]=="UDP") {
#VIP line
if ($VIP<>0) {echo "</table>";}
$RIP=0;
$VIP=$VIP+1;
$vipip = $value1[$b];
$viplabel = Get_vip_label($vipip);
echo "</br><b>Virtual Server " . $VIP . "<i>-> $viplabel</i></b></br> ";
echo $value1[$b] . "</br>";
echo "<table width=\"60%\"><th>Real IP Address:Port</th><th>label</th><th>Connections /Sec</th><th>Incomming Packets /Sec</th><th>Outgoing Packets /Sec</th><th>Incoming Bytes /Sec</th><th>Outgoing Bytes /Sec</th> ";
} else {
$riplabel = Get_rip_label($vipip,$value1[$b]);
echo "<tr></tr><td> $value1[$b] </td><td> <i>$riplabel</i> </td><td>$value2[$b]</td><td>$value3[$b]</td><td>$value4[$b]</td><td>$value5[$b]</td><td>$value6[$b]</td></tr>";
}
}
echo "</table>";
SCOP_log("Reports : Connection rates viewed.");
}
If ($srcfile=="normal") {
parse_config_file(); // Read the file and setup the global variables
exec ("sudo /sbin/ipvsadm -Ln > /var/www/html/scop/stats/normal.html");
exec ("sudo chmod 777 /var/www/html/scop/stats/normal.html");
if ($arrtext = file("/var/www/html/scop/stats/normal.html")) {
} else {
echo "<font color='#010000'> The file <b>/var/www/html/scop/stats/normal.html</b> does not have the correct permissions.</br>";
}
warn_no_results($arrtext); //Check we got a response from ipvsadm
// Show refresh button
echo "<FORM method=\"post\" action=\"reports.php?srcfile=normal&t=$t\"> <INPUT type=\"submit\" value=\"Check Status\" name=\"go\" ></form>";
$item=0;
for ( $i=3; $i<count($arrtext); $i++) {
# If the line is not a remark then tokenise on newline or tab
$tok = strtok(ltrim($arrtext[$i])," \n\t");
while ($tok) {
$value0[$item]=$tok;
#echo "</br>attribute = " . $Attribute[$item];
$tok = strtok(" \n\t");
$value1[$item]=$tok;
#echo "</br>value1 = " . $value1[$item];
$tok = strtok(" \n\t");
$value2[$item]=$tok;
#echo "</br>value2 = " . $value2[$item];
$tok = strtok(" \n\t");
$value3[$item]=$tok;
#echo "</br>value3 = " . $value3[$item];
$tok = strtok(" \n\t");
$value4[$item]=$tok;
#echo "</br>value4 = " . $value4[$item];
$tok = strtok(" \n\t");
$value5[$item]=$tok;
#echo "</br>value5 = " . $value5[$item];
$tok = strtok(" \n\t");
$value6[$item]=$tok;
#echo "</br>value6 = " . $value6[$item];
# first word is attribute
# Second word is value
$tok = strtok(" \n\t");
$item=$item+1;
}
}
echo "</hr>";
$VIP=0;
echo "<table>";
for ( $b=0; $b<$item; $b++) {
If ($value0[$b]=="TCP" OR $value0[$b]=="FWM" OR $value0[$b]=="UDP") {
#VIP line
if ($VIP<>0) {echo "</table>";}
$RIP=0;
$VIP=$VIP+1;
$vipip = $value1[$b];
$viplabel = Get_vip_label($vipip);
echo "</br><b>Virtual Server " . $VIP . "-> <i>$viplabel</i> </b></br> ";
echo $value1[$b] . " " . $value2[$b] . " " . $value3[$b] ." " . $value4[$b] . "</br>";
echo "<table width=\"60%\"><th>Real IP Address:Port</th><th>Label</th><th>Connection Type</th><th>Weight</th><th>Active Connections</th><th>Inactive Connections</th>";
} else {
$riplabel = Get_rip_label($vipip,$value1[$b]);
echo "<tr><td> $value1[$b] </td><td> <i>$riplabel</i> </td><td>$value2[$b]</td><td>$value3[$b]</td><td>$value4[$b]</td><td>$value5[$b]</td></tr>";
}
}
echo "</table>";
SCOP_log("Reports : Connections viewed.");
}
include ("../inc/footer.inc");
function warn_no_results($arrtext) {
// Quick function to avoid duplication
if (count($arrtext)==3) {
echo "<h3>Error : No results returned from ipvsadm ? </h3>";
echo "<h3>Warning : The system may still be booting or you may have a configuration error.</h3>";
}
}
?>