<?
$srcfile = $_GET['srcfile'];
$l = $_GET['l'];
if ($srcfile == "stats" OR $srcfile == "rate" OR $srcfile == "normal") {
global $meta;
$meta = "<meta http-equiv=\"refresh\" content=\"10;url=reports.php?srcfile=$srcfile&l=$l\">";
}
// 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");
$trans="5";
$a5 = "${$l.$trans}";
$trans="14a";
$a14a = "${$l.$trans}";
$trans="14b";
$a14b = "${$l.$trans}";
$trans="14c";
$a14c = "${$l.$trans}";
$trans="14d";
$a14d = "${$l.$trans}";
$trans="14e";
$a14e = "${$l.$trans}";
$trans="14f";
$a14f = "${$l.$trans}";
# 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.
echo "<table width=\"60%\" align=\"center\"><tr><td>";
if ($arrtext = file("/etc/scop/pickup.txt")) {
} else {
echo "<font color='#010000'> The file <b>/etc/scop/pickup.txt</b> does not have the correct permissions.</br>";
}
for ( $i=0; $i<count($arrtext); $i++) {
echo "$arrtext[$i]</br>";
}
echo "</td></tr></table>";
}
If ($srcfile=="route") { // Just dump the connection table to screen.
$trans="2";
$a2 = "${$l.$trans}";
$trans="13d";
$a14e = "${$l.$trans}";
?>
<div id="contentArea">
<h1><a href="/scop/index.php?menu=viewconf&l=<?=$l?>"><?=$a2?></a> > <?=$a14e?></h1>
<div class="border">
<?
echo "<table width=\"60%\" align=\"center\"><tr><td>";
exec ("sudo /sbin/route -vn > /var/www/html/scop/stats/route.html");
exec ("sudo chmod 777 /var/www/html/scop/stats/route.html");
if ($arrtext = file("/var/www/html/scop/stats/route.html")) {
} else {
echo "<font color='#010000'> The file <b>/var/www/html/scop/stats/route.html</b> does not have the correct permissions.</br>";
}
for ( $i=0; $i<count($arrtext); $i++) {
echo "<pre>";
echo "$arrtext[$i]";
echo "</pre>";
}
echo "</td></tr></table>";
}
If ($srcfile=="connection") { // Just dump the connection table to screen.
?>
<div id="contentArea">
<h1><a href="/scop/index.php?menu=reports&l=<?=$l?>"><?=$a5?></a> > <?=$a14d?></h1>
<div class="border">
<?
echo "<table width=\"60%\" align=\"center\"><tr><td>";
#exec ("sudo /sbin/ipvsadm -Lcn > /var/www/html/scop/stats/connection.html");
echo "<PRE>";
echo `sudo /sbin/ipvsadm -Lcn`;
echo "</PRE>";
#exec ("sudo chmod 777 /var/www/html/scop/stats/connection.html");
#if ($arrtext = file("/var/www/html/scop/stats/connection.html")) {
#} else {
# echo "<font color='#010000'> The file <b>/var/www/html/scop/stats/connection.html</b> does not have the correct permissions.</br>";
#}
#for ( $i=2; $i<count($arrtext); $i++) {
#echo "$arrtext[$i]</br>";
#}
echo "</td></tr></table>";
}
If ($srcfile=="connectionwithlookup") { // Same again but with a DNS lookup
?>
<div id="contentArea">
<h1><a href="/scop/index.php?menu=reports&l=<?=$l?>"><?=$a5?></a> > <?=$a14e?></h1>
<div class="border">
<?
echo "<table width=\"60%\" align=\"center\"><tr><td>";
echo "<PRE>";
echo `sudo /sbin/ipvsadm -Lc`;
echo "</PRE>";
#exec ("sudo /sbin/ipvsadm -Lc > /var/www/html/scop/stats/connection.html");
#exec ("sudo chmod 777 /var/www/html/scop/stats/connection.html");
#if ($arrtext = file("/var/www/html/scop/stats/connection.html")) {
#} else {
# echo "<font color='#010000'> The file <b>/var/www/html/scop/stats/connection.html</b> does not #have the correct permissions.</br>";
# }
# for ( $i=2; $i<count($arrtext); $i++) {
# echo "$arrtext[$i]</br>";
# }
echo "</td></tr></table>";
}
If ($srcfile=="ifconfig") { // Dump the status of the NICs too the screen
$trans="2";
$a2 = "${$l.$trans}";
$trans="13b";
$a13b = "${$l.$trans}";
?>
<div id="contentArea">
<h1><a href="/scop/index.php?menu=viewconf&l=<?=$l?>"><?=$a2?></a> > <?=$a13b?></h1>
<div class="border">
<?
echo "<table width=\"60%\" align=\"center\"><tr><td>";
$output = `sudo ifconfig`;
echo "<pre>$output</pre>";
echo "</td></tr></table>";
}
If ($srcfile=="pound") { // Pound configuration file
$trans="2";
$a2 = "${$l.$trans}";
$trans="13a";
$a13a = "${$l.$trans}";
$trans="108";
$t108 = "${$l.$trans}";
?>
<div id="contentArea">
<h1><a href="/scop/index.php?menu=viewconf&l=<?=$l?>"><?=$a2?></a> > <? echo "$a13a $t108"; ?></h1>
<div class="border">
<?
echo "<table width=\"60%\" align=\"center\"><tr><td>";
$output = `cat /usr/local/etc/pound.cfg`;
echo "<pre>$output</pre>";
echo "</td></tr></table>";
}
If ($srcfile=="haproxy") { // HAProxy configuration file
$trans="2";
$a2 = "${$l.$trans}";
$trans="13a";
$a13a = "${$l.$trans}";
$trans="107";
$t107 = "${$l.$trans}";
?>
<div id="contentArea">
<h1><a href="/scop/index.php?menu=viewconf&l=<?=$l?>"><?=$a2?></a> > <? echo "$a13a $t107"; ?></h1>
<div class="border">
<?
echo "<table width=\"60%\" align=\"center\"><tr><td>";
$output = `cat /etc/haproxy/haproxy.cfg`;
echo "<pre>$output</pre>";
echo "</td></tr></table>";
}
If ($srcfile=="clear") { // Re-set the packet counters to zero
$trans="6";
$a6 = "${$l.$trans}";
$trans="15a";
$a15a = "${$l.$trans}";
?>
<div id="contentArea">
<h1><a href="/scop/index.php?menu=logs&l=<?=$l?>"><?=$a6?></a> > <?=$a15a?></h1>
<div class="border">
<?
$trans="103";
$a103 = "${$l.$trans}";
exec ("sudo ipvsadm -Z");
echo "<p><center>$a103</center></p>";
SCOP_log("Reports : Packet counters cleared.");
}
If ($srcfile=="ldirectordlog") { // View the ldirectord log file (Highlighting would be nice ?)
$trans="6";
$a6 = "${$l.$trans}";
?>
<div id="contentArea">
<h1><a href="/scop/index.php?menu=logs&l=<?=$l?>"><? echo"$a6";?></a> > Ldirectord</h1>
<div class="border">
<?
echo "<table width=\"60%\" align=\"center\"><tr><td>";
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.");
echo "</td></tr></table>";
}
If ($srcfile=="heartbeatlog") { // View the Heartbeat log file
$trans="6";
$a6 = "${$l.$trans}";
?>
<div id="contentArea">
<h1><a href="/scop/index.php?menu=logs&l=<?=$l?>"><?=$a6?></a> > Heartbeat</h1>
<div class="border">
<?
echo "<table width=\"60%\" align=\"center\"><tr><td>";
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.");
echo "</td></tr></table>";
}
If ($srcfile=="SCOPlog") { // View the Heartbeat log file
$trans="6";
$a6 = "${$l.$trans}";
?>
<div id="contentArea">
<h1><a href="/scop/index.php?menu=logs&l=<?=$l?>"><?=$a6?></a> > SCOP</h1>
<div class="border">
<?
echo "<table width=\"60%\" align=\"center\"><tr><td>";
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>";
echo "</td></tr></table>";
}
If ($srcfile=="haresources") { // View the hareasources file i.e what VIPs we are using
$trans="2";
$a2 = "${$l.$trans}";
$trans="13c";
$a13c = "${$l.$trans}";
?>
<div id="contentArea">
<h1><a href="/scop/index.php?menu=viewconf&l=<?=$l?>"><?=$a2?></a> > <?=$a13c?></h1>
<div class="border">
<?
echo "<table width=\"60%\" align=\"center\"><tr><td>";
$output = `sudo cat /etc/ha.d/haresources`;
echo "<pre>$output</pre>";
echo "</td></tr></table>";
}
If ($srcfile=="firewall") {
$trans="2";
$a2 = "${$l.$trans}";
$trans="13e";
$a13e = "${$l.$trans}";
?>
<div id="contentArea">
<h1><a href="/scop/index.php?menu=viewconf&l=<?=$l?>"><?=$a2?></a> > <?=$a13e?></h1>
<div class="border">
<?
echo "<table width=\"60%\" align=\"center\"><tr><td>";
$output = `sudo /usr/sbin/iptables -L -n`;
echo "<pre>$output</pre>";
$output = `sudo /usr/sbin/iptables -L -t nat -n`;
echo "<pre>$output</pre>";
echo "</td></tr></table>";
}
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
?>
<div id="contentArea">
<h1><a href="/scop/index.php?menu=reports&l=<?=$l?>"><?=$a5?></a> > <?=$a14c?></h1>
<div class="border">
<?
// Show refresh button
echo "<center><FORM method=\"post\" action=\"reports.php?srcfile=stats&t=$t\"> <INPUT type=\"submit\" value=\"Check Status\" name=\"go\" ></form><br />";
$item=0;
echo "<table border=\"0\" class=\"datagrid\" align=\"center\"><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> ";
?><tr><td colspan="7" class="sep2"></td></tr><?
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 "<th colspan=\"6\" style=\"text-align:left;\">VIP " . $VIP . " <i>$viplabel</i> ";
echo $value1[$b] . "</th></tr>";
} 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>";
?><tr><td colspan="7" class="sep1"></td></tr><?
}
}
echo "</table></center>";
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
?>
<div id="contentArea">
<h1><a href="/scop/index.php?menu=reports&l=<?=$l?>"><?=$a5?></a> > <?=$a14b?></h1>
<div class="border">
<?
// Show refresh button
echo "<center><FORM method=\"post\" action=\"reports.php?srcfile=rate&t=$t\"> <INPUT type=\"submit\" value=\"Check Status\" name=\"go\" ></form><br />";
$item=0;
echo "<table border=\"0\" class=\"datagrid\" align=\"center\"><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> ";
?><tr><td colspan="7" class="sep2"></td></tr><?
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;
}
}
$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 "<tr><th colspan=\"6\" style=\"text-align:left;\">VIP " . $VIP . "<i> $viplabel</i> ";
echo $value1[$b] . "</th></tr>";
} else {
$riplabel = Get_rip_label($vipip,$value1[$b]);
echo "<tr></tr><td><center>$value1[$b]</center></td><td><i><center>$riplabel</i></center> </td><td><center>$value2[$b]</center></td><td><center>$value3[$b]</center></td><td><center>$value4[$b]</center></td><td><center>$value5[$b]</center></td><td><center>$value6[$b]</center></td></tr>";
?><tr><td colspan="7" class="sep1"></td></tr><?
}
}
?></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
?>
<div id="contentArea">
<h1><a href="/scop/index.php?menu=reports&l=<?=$l?>"><?=$a5?></a> > <?=$a14a?></h1>
<div class="border">
<?
// Show refresh button
echo "<center><FORM method=\"post\" action=\"reports.php?srcfile=normal&t=$t\"> <INPUT type=\"submit\" value=\"Check Status\" name=\"go\" ></form><br />";
$item=0;
echo "<table border=\"0\" class=\"datagrid\" align=\"center\">";
echo "<th>Real IP Address:Port</th><th>Label</th><th>Connection Type</th><th>Weight</th><th>Active Connections</th><th>Inactive Connections</th>";
?><tr><td colspan="7" class="sep2"></td></tr><?
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;
}
}
$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 "<tr><th colspan=\"6\" style=\"text-align:left;\">VIP " . $VIP . " <i>$viplabel</i> ";
echo $value1[$b] . " " . $value2[$b] . " " . $value3[$b] ." " . $value4[$b] . "</th></tr>";
} 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>";
?><tr><td colspan="7" class="sep1"></td></tr><?
}
}
echo "</table>";
SCOP_log("Reports : Connections viewed.");
}
//echo "</td></tr></table>";
?>
</div>
<div class="bottom"><span>-----</span></div>
</div>
<?
include ("../inc/footer.inc");
?>