[ previous ] [ next ] [ threads ]
 
 From:  "John ." <jvoigt at gmail dot com>
 To:  "Graeme B. Davis" <graeme dot davis at mci dot com>
 Cc:  Chris Buechler <cbuechler at gmail dot com>, m0n0wall at lists dot m0n0 dot ch
 Subject:  Re: [m0n0wall] Traffic Shaper/MRTG/IP usage question...
 Date:  Wed, 22 Sep 2004 14:50:47 -0400
On Wed, 22 Sep 2004 09:07:00 -0400, Graeme B. Davis
<graeme dot davis at mci dot com> wrote:
> I'm talking about the MRTG-side script that parses/logs into the web
> page to get the info into MRTG...
> 

OK - the following is provided as an example only.  Do not use it! 
You are responsible for anything this does to your system.  Don't
blame me if you break anything.  There is no documentation - this was
just a quick hack I did.  Please don't complain to me about
programming style as I am not a programmer. There is no support.  Use
at your own risk.  Well, that should be enough disclaimers.  Note that
the "i" and "o" numbers in the last script correspond to rule numbers.
 You'll have to inspect your monowall box to find the correct values. 
Hopefully, none of the mail systems involved will mangle any of this.

The following should be added to your config.xml file and uploaded to
your mono box:

                <shellcmd>mkdir /usr/local/www/cgi</shellcmd>
                <shellcmd>echo "#!/usr/local/bin/php" >
/usr/local/www/cgi/dump.php</shellcmd>
                <shellcmd>echo "&lt;?php echo \"&lt;pre>\";" >>
/usr/local/www/cgi/dump.php</shellcmd>
                <shellcmd>echo "\$ph = popen( \"/usr/bin/uptime; /sbin/ipfw
show\", \"r\" );" >> /usr/local/www/cgi/dump.php</shellcmd>
                <shellcmd>echo "while (\$line = fgets( \$ph )) echo \$line;
pclose( \$ph );" >> /usr/local/www/cgi/dump.php</shellcmd>
                <shellcmd>echo "echo \"&lt;/pre>\"; ?>" >>
/usr/local/www/cgi/dump.php</shellcmd>
                <shellcmd>chmod 755 /usr/local/www/cgi/dump.php</shellcmd>

Here's one of the MRTG entries for the machine collecting stats:

Target[Vonage]: `/usr/local/bin/php /root/cgi/monodata.php 1`
MaxBytes[Vonage]: 64000
Title[Vonage]: Traffic Analysis for Vonage
PageTop[Vonage]: <H1>Traffic Analysis for Vonage</H1>
 <TABLE>
 <TR><TD>Service:</TD><TD>Vonage</TD></TR>
 </TABLE>

Here's /root/cgi/monodata.php:

<?php
$save = $argv[1];
$fp = fsockopen ("monowall.local.com", 80, $errno, $errstr, 30);
if (!$fp) {
    echo "$errstr ($errno)<br>\n";
} else {
    fputs ($fp, "GET /cgi/dump.php HTTP/1.0\r\n\r\n");
    $result = "";
    while (!feof($fp)) {
        $result .= fgets ($fp,128);
    }
    fclose ($fp);
$results  = explode("\n", $result);
if ($save == 1) {
   $name = "Vonage";
   $i=9;
   $o=8;
} else if ($save == 2) {
   $name = "RTV";
   $i=11;
   $o=10;
} else {
   $name = "Others";
   $i=13;
   $o=12;
}
$in = strtok($results[$i], " ");
$in = strtok(" ");
$in = strtok(" ");
$out = strtok($results[$o], " ");
$out = strtok(" ");
$out = strtok(" ");
echo "$in\n";
echo "$out\n";
echo $results[5],"\n";
echo "$name\n";
}
?>