From 7d906758d5033a54b77ab61cd0e0a72120eb4f52 Mon Sep 17 00:00:00 2001 From: smos Date: Thu, 15 Jul 2010 17:20:49 +0200 Subject: Improve the RRD graph display --- usr/local/www/status_rrd_graph.php | 88 +++++++++++- usr/local/www/status_rrd_graph_img.php | 245 +++++++++++++++++++++------------ 2 files changed, 235 insertions(+), 98 deletions(-) (limited to 'usr/local') diff --git a/usr/local/www/status_rrd_graph.php b/usr/local/www/status_rrd_graph.php index f7b5b25..cefbbb2 100755 --- a/usr/local/www/status_rrd_graph.php +++ b/usr/local/www/status_rrd_graph.php @@ -63,6 +63,12 @@ if ($_GET['cat']) { } } +if ($_GET['period']) { + $curperiod = $_GET['period']; +} else { + $curperiod = "current"; +} + if ($_GET['option']) { $curoption = $_GET['option']; } else { @@ -150,11 +156,61 @@ $ui_databases = array_merge($dbheader, $databases); $styles = array('inverse' => 'Inverse', 'absolute' => 'Absolute'); -$periods = array("4h", "16h", "48h", "32d", "6m", "1y", "4y"); +$graphs = array("day", "week", "month", "quarter", "year", "4year"); +$periods = array("current" => "Current Period", "previous" => "Previous Period"); $pgtitle = array("Status","RRD Graphs"); include("head.inc"); +function get_dates($curperiod, $graph) { + $now = time(); + $end = $now; + $curyear = date('Y', $now); + $curmonth = date('m', $now); + $curweek = date('W', $now); + $curweekday = date('w', $now); + $curday = date('d', $now); + + switch($curperiod) { + case "previous": + $offset = -1; + break; + default: + $offset = 0; + } + switch($graph) { + case "day": + $start = mktime(0, 0, 0, $curmonth, ($curday - $offset), $curyear); + $end = mktime(0, 0, 0, $curmonth, (($curday - $offset) + 1), $curyear); + break; + case "week": + $start = mktime(0, 0, 0, $curmonth, (($curday - $curweekday) - $offset), $curyear); + $end = mktime(0, 0, 0, $curmonth, (($curday - $curweekday) + 7), $curyear); + break; + case "month": + $start = mktime(0, 0, 0, ($curmonth - $offset), 0, $curyear); + $end = mktime(0, 0, 0, (($curmonth - $offset) + 1), 0, $curyear); + break; + case "quarter": + $start = mktime(0, 0, 0, (($curmonth -2) - $offset), 0, $curyear); + $end = mktime(0, 0, 0, (($curmonth - $offset) + 1), 0, $curyear); + break; + case "year": + $start = mktime(0, 0, 0, 1, 0, ($curyear - $offset)); + $end = mktime(0, 0, 0, 1, 0, (($curyear - $offset) +1)); + break; + case "4year": + $start = mktime(0, 0, 0, 1, 0, (($curyear - 3) - $offset)); + $end = mktime(0, 0, 0, 1, 0, (($curyear - $offset) +1)); + break; + } + $dates = array(); + $dates['start'] = $start; + $dates['end'] = $end; + return $dates; +} + + ?> @@ -249,12 +305,24 @@ include("head.inc"); echo ">" . htmlspecialchars($styled) . "\n"; } ?> + + + + $interval) { + // echo "year $curyear, month $curmonth, week $curweek, day $curday, weekday $curweekday
"; + foreach($graphs as $graph) { /* check which databases are valid for our category */ foreach($ui_databases as $curdatabase) { if(! preg_match("/($curcat)/i", $curdatabase)) { @@ -289,10 +357,13 @@ include("head.inc"); } } if(in_array($curdatabase, $databases)) { + $dates = get_dates($curperiod, $graph); + $start = $dates['start']; + $end = $dates['end']; echo "\n"; - echo "\"$prettydb\n"; + echo "\"$prettydb\n"; echo "


\n"; echo "\n"; } @@ -308,7 +379,7 @@ include("head.inc"); //alert('updating'); var randomid = Math.floor(Math.random()*11); $interval) { + foreach($graphs as $graph) { /* check which databases are valid for our category */ foreach($databases as $curdatabase) { if(! stristr($curdatabase, $curcat)) { @@ -338,9 +409,12 @@ include("head.inc"); continue 2; } } + $dates = get_dates($curperiod, $graph); + $start = $dates['start']; + $end = $dates['end']; /* generate update events utilizing prototype $('') feature */ echo "\n"; - echo "\t\t\$('{$interval}-{$curoption}-{$curdatabase}').src='status_rrd_graph_img.php?interval={$interval}&database={$curdatabase}&style={$curstyle}&tmp=' + randomid;\n"; + echo "\t\t\$('{$graph}-{$curoption}-{$curdatabase}').src='status_rrd_graph_img.php?start={$start}&end={$end}&graph={$graph}&database={$curdatabase}&style={$curstyle}&tmp=' + randomid;\n"; } } ?> diff --git a/usr/local/www/status_rrd_graph_img.php b/usr/local/www/status_rrd_graph_img.php index 63657d0..ffaea00 100644 --- a/usr/local/www/status_rrd_graph_img.php +++ b/usr/local/www/status_rrd_graph_img.php @@ -51,12 +51,79 @@ if ($_GET['style']) { $curstyle = "inverse"; } -if ($_GET['interval']) { - $interval = $_GET['interval']; +/* this is used for temp name */ +if ($_GET['graph']) { + $curgraph = $_GET['graph']; } else { - $interval = "4h"; + $curgraph = "custom"; } +$now = time(); + +if (is_numeric($_GET['start'])) { + if($start < ($now - (3600 * 24 * 365 * 5))) { + $start = $now - (4 * 3600); + } + $start = $_GET['start']; +} else { + $start = $now - (4 * 3600); +} + +if (is_numeric($_GET['end'])) { + $end = $_GET['end']; +} else { + $end = $now; +} + +/* this should never happen */ +if($end < $start) { + $end = $now; +} + +$seconds = $end - $start; + +$scales = array(); +$scales[14400] = "MINUTE:5:MINUTE:10:MINUTE:30:0:%H%:%M"; +$scales[57600] = "MINUTE:30:HOUR:1:HOUR:1:0:%H"; +$scales[172800] = "HOUR:1:HOUR:6:HOUR:2:0:%H"; +$scales[691200] = "HOUR:2:HOUR:12:DAY:1:0:%D %d"; +$scales[2764800] = "DAY:1:WEEK:1:WEEK:1:0:Week %W"; +$scales[16070400] = "WEEK:1:MONTH:1:MONTH:1:0:%b"; +$scales[42854400] = "MONTH:1:MONTH:1:MONTH:1:0:%b"; + +$archives = array(); +$archives[1] = 1000; +$archives[5] = 1000; +$archives[60] = 1000; +$archives[720] = 1000; + +$defOptions = array( + 'to' => 1, + 'parts' => 1, + 'precision' => 'minute', + 'distance' => FALSE, + 'separator' => ', ' +); + +/* always set the average to the highest value as a fallback */ +$average = 720 * 60; +foreach($archives as $rra => $value) { + $archivestart = $end - ($rra * 60 * $value); + if($archivestart <= $start) { + $average = $rra * 60; + break; + } +} + +foreach($scales as $scalelength => $value) { + if($scalelength >= $seconds) { + $scale = $value; + break; + } +} + +log_error("start $start, end $end, archivestart $archivestart, average $average, scale $scale, seconds $seconds"); + /* Deduce a interface if possible and use the description */ $curif = split("-", $curdatabase); $curif = "$curif[0]"; @@ -68,41 +135,6 @@ $search = array("-", ".rrd", $curif); $replace = array(" :: ", "", $friendly); $prettydb = ucwords(str_replace($search, $replace, $curdatabase)); -$periods = array("4h", "16h", "48h", "32d", "6m", "1y", "4y"); - -$found = 0; -foreach($periods as $period) if($period == $interval) $found = 1; -if($found == 0) { - PRINT "Graph interval $interval is not valid
\n"; - exit(); -} - -$graphs['4h']['seconds'] = 14400; -$graphs['4h']['average'] = 60; -$graphs['4h']['scale'] = "MINUTE:5:MINUTE:10:MINUTE:30:0:%H%:%M"; -$graphs['16h']['seconds'] = 57600; -$graphs['16h']['average'] = 60; -$graphs['16h']['scale'] = "MINUTE:30:HOUR:1:HOUR:1:0:%H"; -$graphs['48h']['seconds'] = 172800; -$graphs['48h']['average'] = 300; -$graphs['48h']['scale'] = "HOUR:1:HOUR:6:HOUR:2:0:%H"; -$graphs['32d']['seconds'] = 2764800; -$graphs['32d']['average'] = 3600; -$graphs['32d']['scale'] = "DAY:1:WEEK:1:WEEK:1:0:Week %W"; -$graphs['6m']['seconds'] = 16070400; -$graphs['6m']['average'] = 43200; -$graphs['6m']['scale'] = "WEEK:1:MONTH:1:MONTH:1:0:%b"; -$graphs['1y']['seconds'] = 31622400; -$graphs['1y']['average'] = 43200; -$graphs['1y']['scale'] = "MONTH:1:MONTH:3:MONTH:1:0:%b"; -$graphs['4y']['seconds'] = 126489600; -$graphs['4y']['average'] = 86400; -$graphs['4y']['scale'] = "MONTH:1:YEAR:1:MONTH:3:0:%b"; - -/* generate the graphs when we request the page. */ -$seconds = $graphs[$interval]['seconds']; -$average = $graphs[$interval]['average']; -$scale = $graphs[$interval]['scale']; $rrddbpath = "/var/db/rrd/"; $rrdtmppath = "/tmp/"; @@ -110,8 +142,8 @@ $rrdtool = "/usr/bin/nice -n20 /usr/local/bin/rrdtool"; $uptime = "/usr/bin/uptime"; $sed = "/usr/bin/sed"; -$havg = humantime($average); -$hperiod = humantime($seconds); +$havg = timeDiff($average, $defOptions); +$hperiod = timeDiff($seconds, $defOptions); $data = true; /* XXX: (billm) do we have an exec() type function that does this type of thing? */ @@ -186,28 +218,59 @@ default: break; } -function humantime($timestamp){ - $difference = $timestamp; - $periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade"); - $lengths = array("60","60","24","7","4.35","12","10"); - for($j = 0; $difference >= $lengths[$j]; $j++) { - $difference /= $lengths[$j]; - $difference = round($difference); - } - if($difference != 1) { - $periods[$j].= "s"; - } - $text = "$difference $periods[$j]"; - return $text; +function timeDiff($time, $opt = array()) { + // The default values + $defOptions = array( + 'to' => 0, + 'parts' => 1, + 'precision' => 'second', + 'distance' => TRUE, + 'separator' => ', ' + ); + $opt = array_merge($defOptions, $opt); + // Default to current time if no to point is given + (!$opt['to']) && ($opt['to'] = time()); + // Init an empty string + $str = ''; + // To or From computation + $diff = ($opt['to'] >= $time) ? $opt['to']-$time : $time-$opt['to']; + // An array of label => periods of seconds; + $periods = array( + 'decade' => 315569260, + 'year' => 31556926, + 'month' => 2629744, + 'week' => 604800, + 'day' => 86400, + 'hour' => 3600, + 'minute' => 60, + 'second' => 1 + ); + // Round to precision + if ($opt['precision'] != 'second') + $diff = round(($diff/$periods[$opt['precision']])) * $periods[$opt['precision']]; + // Report the value is 'less than 1 ' precision period away + (0 == $diff) && ($str = 'less than 1 '.$opt['precision']); + // Loop over each period + foreach ($periods as $label => $value) { + // Stitch together the time difference string + (($x=floor($diff/$value))&&$opt['parts']--) && $str.=($str?$opt['separator']:'').($x.' '.$label.($x > 1?'s':'')); + // Stop processing if no more parts are going to be reported. + if ($opt['parts'] == 0 || $label == $opt['precision']) break; + // Get ready for the next pass + $diff -= $x*$value; + } + $opt['distance'] && $str.=($str&&$opt['to'] >= $time)?' ago':' away'; + return $str; } + if((strstr($curdatabase, "-traffic.rrd")) && (file_exists("$rrddbpath$curdatabase"))) { /* define graphcmd for traffic stats */ - $graphcmd = "$rrdtool graph $rrdtmppath$curdatabase-$interval.png "; - $graphcmd .= "--start -$seconds -e -$average --vertical-label \"bits/sec\" "; + $graphcmd = "$rrdtool graph $rrdtmppath$curdatabase-$curgraph.png "; + $graphcmd .= "--start $start --end $end --vertical-label \"bits/sec\" "; $graphcmd .= "--color SHADEA#eeeeee --color SHADEB#eeeeee "; $graphcmd .= "--title \"`hostname` - {$prettydb} - {$hperiod} - {$havg} average\" "; - $graphcmd .= "--height 200 --width 620 -x \"{$scale}\" "; + $graphcmd .= "--height 200 --width 620 "; $graphcmd .= "DEF:$curif-in_bytes_pass=$rrddbpath$curdatabase:inpass:AVERAGE "; $graphcmd .= "DEF:$curif-out_bytes_pass=$rrddbpath$curdatabase:outpass:AVERAGE "; $graphcmd .= "DEF:$curif-in_bytes_block=$rrddbpath$curdatabase:inblock:AVERAGE "; @@ -279,12 +342,12 @@ if((strstr($curdatabase, "-traffic.rrd")) && (file_exists("$rrddbpath$curdatabas elseif(strstr($curdatabase, "-throughput.rrd")) { /* define graphcmd for throughput stats */ /* this gathers all interface statistics, the database does not actually exist */ - $graphcmd = "$rrdtool graph $rrdtmppath$curdatabase-$interval.png "; - $graphcmd .= "--start -$seconds -e -$average "; + $graphcmd = "$rrdtool graph $rrdtmppath$curdatabase-$curgraph.png "; + $graphcmd .= "--start $start --end $end "; $graphcmd .= "--vertical-label \"bits/sec\" "; $graphcmd .= "--color SHADEA#eeeeee --color SHADEB#eeeeee "; $graphcmd .= "--title \"`hostname` - {$prettydb} - {$hperiod} - {$havg} average\" "; - $graphcmd .= "--height 200 --width 620 -x \"{$scale}\" "; + $graphcmd .= "--height 200 --width 620 "; $iflist = get_configured_interface_list(); $g = 0; @@ -406,12 +469,12 @@ elseif(strstr($curdatabase, "-throughput.rrd")) { } elseif((strstr($curdatabase, "-packets.rrd")) && (file_exists("$rrddbpath$curdatabase"))) { /* define graphcmd for packets stats */ - $graphcmd = "$rrdtool graph $rrdtmppath$curdatabase-$interval.png "; - $graphcmd .= "--start -$seconds -e -$average "; + $graphcmd = "$rrdtool graph $rrdtmppath$curdatabase-$curgraph.png "; + $graphcmd .= "--start $start --end $end "; $graphcmd .= "--vertical-label \"packets/sec\" "; $graphcmd .= "--color SHADEA#eeeeee --color SHADEB#eeeeee "; $graphcmd .= "--title \"`hostname` - {$prettydb} - {$hperiod} - {$havg} average\" "; - $graphcmd .= "--height 200 --width 620 -x \"$scale\" "; + $graphcmd .= "--height 200 --width 620 "; $graphcmd .= "DEF:\"$curif-in_pps_pass=$rrddbpath$curdatabase:inpass:AVERAGE\" "; $graphcmd .= "DEF:\"$curif-out_pps_pass=$rrddbpath$curdatabase:outpass:AVERAGE\" "; $graphcmd .= "DEF:\"$curif-in_pps_block=$rrddbpath$curdatabase:inblock:AVERAGE\" "; @@ -475,12 +538,12 @@ elseif((strstr($curdatabase, "-packets.rrd")) && (file_exists("$rrddbpath$curdat } elseif((strstr($curdatabase, "-wireless.rrd")) && (file_exists("$rrddbpath$curdatabase"))) { /* define graphcmd for packets stats */ - $graphcmd = "$rrdtool graph $rrdtmppath$curdatabase-$interval.png "; - $graphcmd .= "--start -$seconds -e -$average "; + $graphcmd = "$rrdtool graph $rrdtmppath$curdatabase-$curgraph.png "; + $graphcmd .= "--start $start --end $end "; $graphcmd .= "--vertical-label \"snr/channel/rate\" "; $graphcmd .= "--color SHADEA#eeeeee --color SHADEB#eeeeee "; $graphcmd .= "--title \"`hostname` - {$prettydb} - {$hperiod} - {$havg} average\" "; - $graphcmd .= "--height 200 --width 620 -x \"$scale\" "; + $graphcmd .= "--height 200 --width 620 "; $graphcmd .= "DEF:\"$curif-snr=$rrddbpath$curdatabase:snr:AVERAGE\" "; $graphcmd .= "DEF:\"$curif-rate=$rrddbpath$curdatabase:rate:AVERAGE\" "; $graphcmd .= "DEF:\"$curif-channel=$rrddbpath$curdatabase:channel:AVERAGE\" "; @@ -508,12 +571,12 @@ elseif((strstr($curdatabase, "-wireless.rrd")) && (file_exists("$rrddbpath$curda } elseif((strstr($curdatabase, "-states.rrd")) && (file_exists("$rrddbpath$curdatabase"))) { /* define graphcmd for states stats */ - $graphcmd = "$rrdtool graph $rrdtmppath$curdatabase-$interval.png "; + $graphcmd = "$rrdtool graph $rrdtmppath$curdatabase-$curgraph.png "; $graphcmd .= "--start -$seconds -e -$average "; $graphcmd .= "--vertical-label \"states, ip\" "; $graphcmd .= "--color SHADEA#eeeeee --color SHADEB#eeeeee "; $graphcmd .= "--title \"`hostname` - {$prettydb} - {$hperiod} - {$havg} average\" "; - $graphcmd .= "--height 200 --width 620 -x \"$scale\" "; + $graphcmd .= "--height 200 --width 620 "; $graphcmd .= "DEF:\"$curif-pfrate=$rrddbpath$curdatabase:pfrate:AVERAGE\" "; $graphcmd .= "DEF:\"$curif-pfstates=$rrddbpath$curdatabase:pfstates:AVERAGE\" "; $graphcmd .= "DEF:\"$curif-pfnat=$rrddbpath$curdatabase:pfnat:AVERAGE\" "; @@ -562,12 +625,12 @@ elseif((strstr($curdatabase, "-states.rrd")) && (file_exists("$rrddbpath$curdata } elseif((strstr($curdatabase, "-processor.rrd")) && (file_exists("$rrddbpath$curdatabase"))) { /* define graphcmd for processor stats */ - $graphcmd = "$rrdtool graph $rrdtmppath$curdatabase-$interval.png "; - $graphcmd .= "--start -$seconds -e -$average "; + $graphcmd = "$rrdtool graph $rrdtmppath$curdatabase-$curgraph.png "; + $graphcmd .= "--start $start --end $end "; $graphcmd .= "--vertical-label \"utilization, number\" "; $graphcmd .= "--color SHADEA#eeeeee --color SHADEB#eeeeee "; $graphcmd .= "--title \"`hostname` - {$prettydb} - {$hperiod} - {$havg} average\" "; - $graphcmd .= "--height 200 --width 620 -x \"$scale\" "; + $graphcmd .= "--height 200 --width 620 "; $graphcmd .= "DEF:\"user=$rrddbpath$curdatabase:user:AVERAGE\" "; $graphcmd .= "DEF:\"nice=$rrddbpath$curdatabase:nice:AVERAGE\" "; $graphcmd .= "DEF:\"system=$rrddbpath$curdatabase:system:AVERAGE\" "; @@ -614,12 +677,12 @@ elseif((strstr($curdatabase, "-processor.rrd")) && (file_exists("$rrddbpath$curd } elseif((strstr($curdatabase, "-memory.rrd")) && (file_exists("$rrddbpath$curdatabase"))) { /* define graphcmd for memory usage stats */ - $graphcmd = "$rrdtool graph $rrdtmppath$curdatabase-$interval.png "; - $graphcmd .= "--start -$seconds -e -$average "; + $graphcmd = "$rrdtool graph $rrdtmppath$curdatabase-$curgraph.png "; + $graphcmd .= "--start $start --end $end "; $graphcmd .= "--vertical-label \"utilization, percent\" "; $graphcmd .= "--color SHADEA#eeeeee --color SHADEB#eeeeee "; $graphcmd .= "--title \"`hostname` - {$prettydb} - {$hperiod} - {$havg} average\" "; - $graphcmd .= "--height 200 --width 620 -x \"$scale\" "; + $graphcmd .= "--height 200 --width 620 "; $graphcmd .= "DEF:\"active=$rrddbpath$curdatabase:active:AVERAGE\" "; $graphcmd .= "DEF:\"inactive=$rrddbpath$curdatabase:inactive:AVERAGE\" "; $graphcmd .= "DEF:\"free=$rrddbpath$curdatabase:free:AVERAGE\" "; @@ -666,12 +729,12 @@ elseif((strstr($curdatabase, "-memory.rrd")) && (file_exists("$rrddbpath$curdata } elseif((strstr($curdatabase, "-queues.rrd")) && (file_exists("$rrddbpath$curdatabase"))) { /* define graphcmd for queue stats */ - $graphcmd = "$rrdtool graph $rrdtmppath$curdatabase-$interval.png "; - $graphcmd .= "--start -$seconds -e -$average "; + $graphcmd = "$rrdtool graph $rrdtmppath$curdatabase-$curgraph.png "; + $graphcmd .= "--start $start --end $end "; $graphcmd .= "--vertical-label \"bits/sec\" "; $graphcmd .= "--color SHADEA#eeeeee --color SHADEB#eeeeee "; $graphcmd .= "--title \"`hostname` - {$prettydb} - {$hperiod} - {$havg} average\" "; - $graphcmd .= "--height 200 --width 620 -x \"$scale\" "; + $graphcmd .= "--height 200 --width 620 "; if ($altq) { $a_queues =& $altq->get_queue_list(); $t = 0; @@ -695,12 +758,12 @@ elseif((strstr($curdatabase, "-queues.rrd")) && (file_exists("$rrddbpath$curdata } elseif((strstr($curdatabase, "-queuedrops.rrd")) && (file_exists("$rrddbpath$curdatabase"))) { /* define graphcmd for queuedrop stats */ - $graphcmd = "$rrdtool graph $rrdtmppath$curdatabase-$interval.png "; - $graphcmd .= "--start -$seconds -e -$average "; + $graphcmd = "$rrdtool graph $rrdtmppath$curdatabase-$curgraph.png "; + $graphcmd .= "--start $start --end $end "; $graphcmd .= "--vertical-label \"drops / sec\" "; $graphcmd .= "--color SHADEA#eeeeee --color SHADEB#eeeeee "; $graphcmd .= "--title \"`hostname` - {$prettydb} - {$hperiod} - {$havg} average\" "; - $graphcmd .= "--height 200 --width 620 -x \"$scale\" "; + $graphcmd .= "--height 200 --width 620 "; if ($altq) { $a_queues =& $altq->get_queue_list(); $t = 0; @@ -725,13 +788,13 @@ elseif((strstr($curdatabase, "-queuedrops.rrd")) && (file_exists("$rrddbpath$cur } elseif((strstr($curdatabase, "-quality.rrd")) && (file_exists("$rrddbpath$curdatabase"))) { /* make a link quality graphcmd, we only have WAN for now, others too follow */ - $graphcmd = "$rrdtool graph $rrdtmppath$curdatabase-$interval.png \\ - --start -$seconds -e -$average \\ + $graphcmd = "$rrdtool graph $rrdtmppath$curdatabase-$curgraph.png \\ + --start $start --end $end \\ --title \"`hostname` - {$prettydb} - {$hperiod} - {$havg} average\" \\ --color SHADEA#eeeeee --color SHADEB#eeeeee \\ --vertical-label \"ms / %\" \\ --height 200 --width 620 \\ - -x \"$scale\" --lower-limit 0 \\ + --lower-limit 0 \\ DEF:delayraw=$rrddbpath$curdatabase:delay:AVERAGE \\ DEF:loss=$rrddbpath$curdatabase:loss:AVERAGE \\ \"CDEF:delay=delayraw,1000,*\" \\ @@ -761,13 +824,13 @@ elseif((strstr($curdatabase, "-quality.rrd")) && (file_exists("$rrddbpath$curdat } elseif((strstr($curdatabase, "spamd.rrd")) && (file_exists("$rrddbpath$curdatabase"))) { /* graph a spamd statistics graph */ - $graphcmd = "$rrdtool graph $rrdtmppath$curdatabase-$interval.png "; - $graphcmd .= "--start -$seconds -e -$average "; + $graphcmd = "$rrdtool graph $rrdtmppath$curdatabase-$curgraph.png "; + $graphcmd .= "--start $start --end $end "; $graphcmd .= "--title \"`hostname` - {$prettydb} - {$hperiod} - {$havg} average\" "; $graphcmd .= "--color SHADEA#eeeeee --color SHADEB#eeeeee "; $graphcmd .= "--vertical-label=\"Conn / Time, sec.\" "; $graphcmd .= "--height 200 --width 620 --no-gridfit "; - $graphcmd .= "-x \"$scale\" --lower-limit 0 "; + $graphcmd .= "--lower-limit 0 "; $graphcmd .= "DEF:\"consmin=$rrddbpath$curdatabase:conn:MIN\" "; $graphcmd .= "DEF:\"consavg=$rrddbpath$curdatabase:conn:AVERAGE\" "; $graphcmd .= "DEF:\"consmax=$rrddbpath$curdatabase:conn:MAX\" "; @@ -799,12 +862,12 @@ elseif((strstr($curdatabase, "spamd.rrd")) && (file_exists("$rrddbpath$curdataba $graphcmd .= "COMMENT:\"\t\t\t\t\t\t\t\t\t\t\t\t\t`date +\"%b %d %H\:%M\:%S %Y\"`\" "; } elseif((strstr($curdatabase, "-cellular.rrd")) && (file_exists("$rrddbpath$curdatabase"))) { - $graphcmd = "$rrdtool graph $rrdtmppath$curdatabase-$interval.png "; - $graphcmd .= "--start -$seconds -e -$average "; + $graphcmd = "$rrdtool graph $rrdtmppath$curdatabase-$curgraph.png "; + $graphcmd .= "--start $start --end $end "; $graphcmd .= "--vertical-label \"signal\" "; $graphcmd .= "--color SHADEA#eeeeee --color SHADEB#eeeeee "; $graphcmd .= "--title \"`hostname` - {$prettydb} - {$hperiod} - {$havg} average\" "; - $graphcmd .= "--height 200 --width 620 -x \"$scale\" "; + $graphcmd .= "--height 200 --width 620 "; $graphcmd .= "DEF:\"$curif-signal1=$rrddbpath$curdatabase:signal1:AVERAGE\" "; $graphcmd .= "DEF:\"$curif-signal2=$rrddbpath$curdatabase:signal2:AVERAGE\" "; $graphcmd .= "LINE2:\"$curif-signal1#{$colorwireless[0]}:$curif-signal1\" "; @@ -829,8 +892,8 @@ else { } /* check modification time to see if we need to generate image */ -if (file_exists("$rrdtmppath$curdatabase-$interval.png")) { - if((time() - filemtime("$rrdtmppath$curdatabase-$interval.png")) >= 55 ) { +if (file_exists("$rrdtmppath$curdatabase-$curgraph.png")) { + if((time() - filemtime("$rrdtmppath$curdatabase-$curgraph.png")) >= 55 ) { if($data) exec("$graphcmd 2>&1", $graphcmdoutput, $graphcmdreturn); $graphcmdoutput = implode(" ", $graphcmdoutput) . $graphcmd; @@ -869,7 +932,7 @@ if(($graphcmdreturn <> 0) || (! $data)) { $file= "/usr/local/www/themes/{$g['theme']}/images/misc/rrd_error.png"; readfile($file); } else { - $file = "$rrdtmppath$curdatabase-$interval.png"; + $file = "$rrdtmppath$curdatabase-$curgraph.png"; if(file_exists("$file")) { header("Content-type: image/png"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); -- cgit v1.1 From 2e12b76c9002d3f05e400523ab0c7558daa4dd2e Mon Sep 17 00:00:00 2001 From: jim-p Date: Thu, 15 Jul 2010 13:06:07 -0400 Subject: Pull in RADIUS reply messages for logout page. --- usr/local/captiveportal/index.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'usr/local') diff --git a/usr/local/captiveportal/index.php b/usr/local/captiveportal/index.php index 32c8853..7d432e2 100755 --- a/usr/local/captiveportal/index.php +++ b/usr/local/captiveportal/index.php @@ -477,6 +477,11 @@ function portal_allow($clientip,$clientmac,$username,$password = null, $attribut $logouturl = "http://{$ourhostname}/"; } + if (isset($attributes['reply_message'])) + $message = $attributes['reply_message']; + else + $message = 0; + include("{$g['varetc_path']}/captiveportal-logout.html"); } else { -- cgit v1.1 From 161cd05c63acb5c200adf65572cad2db2a259a61 Mon Sep 17 00:00:00 2001 From: smos Date: Thu, 15 Jul 2010 20:01:05 +0200 Subject: Remove debugging line Improve the scale so that it matches up the length of the period. Style fixes --- usr/local/www/status_rrd_graph.php | 4 ++-- usr/local/www/status_rrd_graph_img.php | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) (limited to 'usr/local') diff --git a/usr/local/www/status_rrd_graph.php b/usr/local/www/status_rrd_graph.php index cefbbb2..441aa3a 100755 --- a/usr/local/www/status_rrd_graph.php +++ b/usr/local/www/status_rrd_graph.php @@ -197,11 +197,11 @@ function get_dates($curperiod, $graph) { break; case "year": $start = mktime(0, 0, 0, 1, 0, ($curyear - $offset)); - $end = mktime(0, 0, 0, 1, 0, (($curyear - $offset) +1)); + $end = mktime(0, 0, 0, 1, 1, (($curyear - $offset) +1)); break; case "4year": $start = mktime(0, 0, 0, 1, 0, (($curyear - 3) - $offset)); - $end = mktime(0, 0, 0, 1, 0, (($curyear - $offset) +1)); + $end = mktime(0, 0, 0, 1, 1, (($curyear - $offset) +1)); break; } $dates = array(); diff --git a/usr/local/www/status_rrd_graph_img.php b/usr/local/www/status_rrd_graph_img.php index ffaea00..5000b5d 100644 --- a/usr/local/www/status_rrd_graph_img.php +++ b/usr/local/www/status_rrd_graph_img.php @@ -95,7 +95,7 @@ $archives = array(); $archives[1] = 1000; $archives[5] = 1000; $archives[60] = 1000; -$archives[720] = 1000; +$archives[720] = 3000; $defOptions = array( 'to' => 1, @@ -122,7 +122,7 @@ foreach($scales as $scalelength => $value) { } } -log_error("start $start, end $end, archivestart $archivestart, average $average, scale $scale, seconds $seconds"); +// log_error("start $start, end $end, archivestart $archivestart, average $average, scale $scale, seconds $seconds"); /* Deduce a interface if possible and use the description */ $curif = split("-", $curdatabase); @@ -233,11 +233,11 @@ function timeDiff($time, $opt = array()) { // Init an empty string $str = ''; // To or From computation - $diff = ($opt['to'] >= $time) ? $opt['to']-$time : $time-$opt['to']; + $diff = ($opt['to'] >= $time) ? $opt['to'] - $time : $time - $opt['to']; // An array of label => periods of seconds; $periods = array( 'decade' => 315569260, - 'year' => 31556926, + 'year' => 31539600, 'month' => 2629744, 'week' => 604800, 'day' => 86400, @@ -245,21 +245,22 @@ function timeDiff($time, $opt = array()) { 'minute' => 60, 'second' => 1 ); + // 31539600, 31556926, 31622400 // Round to precision if ($opt['precision'] != 'second') - $diff = round(($diff/$periods[$opt['precision']])) * $periods[$opt['precision']]; + $diff = round(($diff / $periods[$opt['precision']])) * $periods[$opt['precision']]; // Report the value is 'less than 1 ' precision period away - (0 == $diff) && ($str = 'less than 1 '.$opt['precision']); + (0 == $diff) && ($str = 'less than 1 ' .$opt['precision']); // Loop over each period foreach ($periods as $label => $value) { // Stitch together the time difference string - (($x=floor($diff/$value))&&$opt['parts']--) && $str.=($str?$opt['separator']:'').($x.' '.$label.($x > 1?'s':'')); + (($x = floor($diff / $value)) && $opt['parts']--) && $str .= ($str ? $opt['separator'] : '') . ($x .' '. $label. ($x > 1 ? 's' : '')); // Stop processing if no more parts are going to be reported. if ($opt['parts'] == 0 || $label == $opt['precision']) break; // Get ready for the next pass - $diff -= $x*$value; + $diff -= $x * $value; } - $opt['distance'] && $str.=($str&&$opt['to'] >= $time)?' ago':' away'; + $opt['distance'] && $str .= ($str && $opt['to'] >= $time) ? ' ago' : ' away'; return $str; } -- cgit v1.1 From 6a8cf738d6fc852773a9049c6728453ad5dbca9f Mon Sep 17 00:00:00 2001 From: smos Date: Thu, 15 Jul 2010 20:33:02 +0200 Subject: Fix the calculus so the date goes backwards --- usr/local/www/status_rrd_graph.php | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'usr/local') diff --git a/usr/local/www/status_rrd_graph.php b/usr/local/www/status_rrd_graph.php index 441aa3a..b467d8a 100755 --- a/usr/local/www/status_rrd_graph.php +++ b/usr/local/www/status_rrd_graph.php @@ -180,30 +180,31 @@ function get_dates($curperiod, $graph) { } switch($graph) { case "day": - $start = mktime(0, 0, 0, $curmonth, ($curday - $offset), $curyear); - $end = mktime(0, 0, 0, $curmonth, (($curday - $offset) + 1), $curyear); + $start = mktime(0, 0, 0, $curmonth, ($curday + $offset), $curyear); + $end = mktime(0, 0, 0, $curmonth, (($curday + $offset) + 1), $curyear); break; case "week": - $start = mktime(0, 0, 0, $curmonth, (($curday - $curweekday) - $offset), $curyear); - $end = mktime(0, 0, 0, $curmonth, (($curday - $curweekday) + 7), $curyear); + $start = mktime(0, 0, 0, $curmonth, (($curday + $curweekday) - $offset), $curyear); + $end = mktime(0, 0, 0, $curmonth, (($curday + $curweekday) + 7), $curyear); break; case "month": - $start = mktime(0, 0, 0, ($curmonth - $offset), 0, $curyear); - $end = mktime(0, 0, 0, (($curmonth - $offset) + 1), 0, $curyear); + $start = mktime(0, 0, 0, ($curmonth + $offset), 0, $curyear); + $end = mktime(0, 0, 0, (($curmonth + $offset) + 1), 0, $curyear); break; case "quarter": - $start = mktime(0, 0, 0, (($curmonth -2) - $offset), 0, $curyear); - $end = mktime(0, 0, 0, (($curmonth - $offset) + 1), 0, $curyear); + $start = mktime(0, 0, 0, (($curmonth - 2) + $offset), 0, $curyear); + $end = mktime(0, 0, 0, (($curmonth + $offset) + 1), 0, $curyear); break; case "year": - $start = mktime(0, 0, 0, 1, 0, ($curyear - $offset)); - $end = mktime(0, 0, 0, 1, 1, (($curyear - $offset) +1)); + $start = mktime(0, 0, 0, 1, 0, ($curyear + $offset)); + $end = mktime(0, 0, 0, 1, 1, (($curyear + $offset) +1)); break; - case "4year": - $start = mktime(0, 0, 0, 1, 0, (($curyear - 3) - $offset)); - $end = mktime(0, 0, 0, 1, 1, (($curyear - $offset) +1)); + case "4year": + $start = mktime(0, 0, 0, 1, 0, (($curyear - 3) + $offset)); + $end = mktime(0, 0, 0, 1, 1, (($curyear + $offset) +1)); break; } + // echo "start $start ". date('l jS \of F Y h:i:s A', $start) .", end $end ". date('l jS \of F Y h:i:s A', $end) ."
"; $dates = array(); $dates['start'] = $start; $dates['end'] = $end; -- cgit v1.1 From 0423bf2c65f75ff73d6a2b0007e949dc6f49ac66 Mon Sep 17 00:00:00 2001 From: smos Date: Thu, 15 Jul 2010 20:43:49 +0200 Subject: round the date calculation result so that it results in 1 month instead of 4 weeks which looks strange. --- usr/local/www/status_rrd_graph.php | 4 ++-- usr/local/www/status_rrd_graph_img.php | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'usr/local') diff --git a/usr/local/www/status_rrd_graph.php b/usr/local/www/status_rrd_graph.php index b467d8a..115d12c 100755 --- a/usr/local/www/status_rrd_graph.php +++ b/usr/local/www/status_rrd_graph.php @@ -197,11 +197,11 @@ function get_dates($curperiod, $graph) { break; case "year": $start = mktime(0, 0, 0, 1, 0, ($curyear + $offset)); - $end = mktime(0, 0, 0, 1, 1, (($curyear + $offset) +1)); + $end = mktime(0, 0, 0, 1, 0, (($curyear + $offset) +1)); break; case "4year": $start = mktime(0, 0, 0, 1, 0, (($curyear - 3) + $offset)); - $end = mktime(0, 0, 0, 1, 1, (($curyear + $offset) +1)); + $end = mktime(0, 0, 0, 1, 0, (($curyear + $offset) +1)); break; } // echo "start $start ". date('l jS \of F Y h:i:s A', $start) .", end $end ". date('l jS \of F Y h:i:s A', $end) ."
"; diff --git a/usr/local/www/status_rrd_graph_img.php b/usr/local/www/status_rrd_graph_img.php index 5000b5d..567d272 100644 --- a/usr/local/www/status_rrd_graph_img.php +++ b/usr/local/www/status_rrd_graph_img.php @@ -233,7 +233,7 @@ function timeDiff($time, $opt = array()) { // Init an empty string $str = ''; // To or From computation - $diff = ($opt['to'] >= $time) ? $opt['to'] - $time : $time - $opt['to']; + $diff = ($opt['to'] > $time) ? $opt['to'] - $time : $time - $opt['to']; // An array of label => periods of seconds; $periods = array( 'decade' => 315569260, @@ -250,11 +250,11 @@ function timeDiff($time, $opt = array()) { if ($opt['precision'] != 'second') $diff = round(($diff / $periods[$opt['precision']])) * $periods[$opt['precision']]; // Report the value is 'less than 1 ' precision period away - (0 == $diff) && ($str = 'less than 1 ' .$opt['precision']); + (0 == $diff) && ($str = 'less than 1 ' . $opt['precision']); // Loop over each period foreach ($periods as $label => $value) { // Stitch together the time difference string - (($x = floor($diff / $value)) && $opt['parts']--) && $str .= ($str ? $opt['separator'] : '') . ($x .' '. $label. ($x > 1 ? 's' : '')); + (($x = round($diff / $value)) && $opt['parts']--) && $str .= ($str ? $opt['separator'] : '') . ($x .' '. $label. ($x > 1 ? 's' : '')); // Stop processing if no more parts are going to be reported. if ($opt['parts'] == 0 || $label == $opt['precision']) break; // Get ready for the next pass @@ -894,7 +894,7 @@ else { /* check modification time to see if we need to generate image */ if (file_exists("$rrdtmppath$curdatabase-$curgraph.png")) { - if((time() - filemtime("$rrdtmppath$curdatabase-$curgraph.png")) >= 55 ) { + if((time() - filemtime("$rrdtmppath$curdatabase-$curgraph.png")) >= 5 ) { if($data) exec("$graphcmd 2>&1", $graphcmdoutput, $graphcmdreturn); $graphcmdoutput = implode(" ", $graphcmdoutput) . $graphcmd; -- cgit v1.1 From 1f6f0076316417a10827c9771a65b324b62a9a56 Mon Sep 17 00:00:00 2001 From: jim-p Date: Thu, 15 Jul 2010 14:48:47 -0400 Subject: Do not allow "0" for PPTP users. Default to 16 clients. --- usr/local/www/vpn_pptp.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'usr/local') diff --git a/usr/local/www/vpn_pptp.php b/usr/local/www/vpn_pptp.php index 1c88670..9a7b108 100755 --- a/usr/local/www/vpn_pptp.php +++ b/usr/local/www/vpn_pptp.php @@ -328,8 +328,9 @@ function enable_change(enable_over) {