#!/usr/bin/perl # get the traffic data and parse it my (@traffic_data) = `/sbin/ipfstat -noia`; for( $i = 0; $i < @traffic_data; $i++ ) { ($traffic_data[ $i ]) = split ' ', $traffic_data[ $i ]; } # header and fancy-catch-the-eye-stuff print "Content-type: text/html\n\n"; print "\n"; print "Traffic Statistics\n"; print "\n"; print "

\nTraffic for " . `hostname` . "

\n"; print "

This is a live page listing the current amount of traffic caused on this network.

\n"; print "
\n"; # process'em for( $i = 0; $i < ( @traffic_data / 2 ); $i++ ) { # display stats. the colour is based on a 5000MB quota. You definitely want to change # that. print "

Statistics for Rule #" . ( $i + 1 ) . ":

\n"; print '\n"; # ..and the total traffic $total = sprintf( "%.2f", ( $traffic_data[ $i * 2 + 1 ] + $traffic_data[ $i ] ) / ( 1024 * 1024 ) ); if( $total < 2500 ) { $color = "#00FF00"; } elsif( $total < 4000 ) { $color = "#FF9900"; } else { $color ="#FF0000"; } print "

Total: $total (Mb)

\n"; } print "
\n"; $host = `hostname -s`; chop( $host ); print "

Back to main site

\n"; print "\n"; print "\n";