All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* pfSense_MODULE: system */ ##|+PRIV ##|*IDENT=page-status-rrdgraphs ##|*NAME=Status: RRD Graphs page ##|*DESCR=Allow access to the 'Status: RRD Graphs' page. ##|*MATCH=status_rrd_graph.php* ##|-PRIV require("guiconfig.inc"); require_once("filter.inc"); require("shaper.inc"); require_once("rrd.inc"); /* if the rrd graphs are not enabled redirect to settings page */ if(! isset($config['rrd']['enable'])) { header("Location: status_rrd_graph_settings.php"); } $rrddbpath = "/var/db/rrd/"; chdir($rrddbpath); $databases = glob("*.rrd"); if ($_GET['cat']) { $curcat = $_GET['cat']; } else { if(! empty($config['rrd']['category'])) { $curcat = $config['rrd']['category']; } else { $curcat = "system"; } } if ($_GET['period']) { $curperiod = $_GET['period']; } else { $curperiod = "current"; } if ($_GET['option']) { $curoption = $_GET['option']; } else { switch($curcat) { case "system": $curoption = "processor"; break; case "queues": $curoption = "queues"; break; case "queuedrops": $curoption = "queuedrops"; break; case "quality": foreach($databases as $database) { if(preg_match("/[-]quality\.rrd/i", $database)) { /* pick off the 1st database we find that matches the quality graph */ $name = explode("-", $database); $curoption = "$name[0]"; continue 2; } } case "wireless": foreach($databases as $database) { if(preg_match("/[-]wireless\.rrd/i", $database)) { /* pick off the 1st database we find that matches the wireless graph */ $name = explode("-", $database); $curoption = "$name[0]"; continue 2; } } case "cellular": foreach($databases as $database) { if(preg_match("/[-]cellular\.rrd/i", $database)) { /* pick off the 1st database we find that matches the celullar graph */ $name = explode("-", $database); $curoption = "$name[0]"; continue 2; } } case "vpnusers": foreach($databases as $database) { if(preg_match("/[-]vpnusers\.rrd/i", $database)) { /* pick off the 1st database we find that matches the VPN graphs */ $name = explode("-", $database); $curoption = "$name[0]"; continue 2; } } default: $curoption = "wan"; break; } } $now = time(); if($curcat == "custom") { 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; if ($_GET['style']) { $curstyle = $_GET['style']; } else { if(! empty($config['rrd']['style'])) { $curstyle = $config['rrd']['style']; } else { $curstyle = "inverse"; } } /* sort names reverse so WAN comes first */ rsort($databases); /* these boilerplate databases are required for the other menu choices */ $dbheader = array("allgraphs-traffic.rrd", "allgraphs-quality.rrd", "allgraphs-wireless.rrd", "allgraphs-cellular.rrd", "allgraphs-vpnusers.rrd", "allgraphs-packets.rrd", "system-allgraphs.rrd", "system-throughput.rrd", "outbound-quality.rrd", "outbound-packets.rrd", "outbound-traffic.rrd"); /* additional menu choices for the custom tab */ $dbheader_custom = array("system-throughput.rrd"); foreach($databases as $database) { if(stristr($database, "-wireless")) { $wireless = true; } if(stristr($database, "-queues")) { $queues = true; } if(stristr($database, "-cellular") && !empty($config['ppps'])) { $cellular = true; } if(stristr($database, "-vpnusers")) { $vpnusers = true; } } /* append the existing array to the header */ $ui_databases = array_merge($dbheader, $databases); $custom_databases = array_merge($dbheader_custom, $databases); $styles = array('inverse' => gettext('Inverse'), 'absolute' => gettext('Absolute')); $graphs = array("day", "week", "month", "quarter", "year", "4year"); $periods = array("current" => gettext("Current Period"), "previous" => gettext("Previous Period")); $pgtitle = array(gettext("Status"),gettext("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('N', $now) - 1; // We want to start on monday $curday = date('d', $now); switch($curperiod) { case "previous": $offset = -1; break; default: $offset = 0; } switch($graph) { case "12hour": switch($offset) { case 0; $houroffset = 0; break; default: $houroffset = ($offset * 12) - 12; break; } $start = mktime((8 + $houroffset), 0, 0, $curmonth, $curday, $curyear); if(($offset != 0) || (($end - ($start + (12 * 3600)) ) > 0) ) { $end = mktime((8 + $houroffset) + 12, 0, 0, $curmonth, $curday, $curyear); } break; case "day": $start = mktime(0, 0, 0, $curmonth, ($curday + $offset), $curyear); if($offset != 0) $end = mktime(0, 0, 0, $curmonth, (($curday + $offset) + 1), $curyear); break; case "week": switch($offset) { case 0; $weekoffset = 0; break; default: $weekoffset = ($offset * 7) - 7; break; } $start = mktime(0, 0, 0, $curmonth, (($curday - $curweekday) + $weekoffset), $curyear); if($offset != 0) $end = mktime(0, 0, 0, $curmonth, (($curday - $curweekday) + $weekoffset + 7), $curyear); break; case "month": $start = mktime(0, 0, 0, ($curmonth + $offset), 0, $curyear); if($offset != 0) $end = mktime(0, 0, 0, (($curmonth + $offset) + 1), 0, $curyear); break; case "quarter": $start = mktime(0, 0, 0, (($curmonth - 2) + $offset), 0, $curyear); if($offset != 0) $end = mktime(0, 0, 0, (($curmonth + $offset) + 1), 0, $curyear); break; case "year": $start = mktime(0, 0, 0, 1, 0, ($curyear + $offset)); if($offset != 0) $end = mktime(0, 0, 0, 1, 0, (($curyear + $offset) +1)); break; case "4year": $start = mktime(0, 0, 0, 1, 0, (($curyear - 3) + $offset)); if($offset != 0) $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) ."
"; $dates = array(); $dates['start'] = $start; $dates['end'] = $end; return $dates; } ?>
">
\n"; } } else { foreach($graphs as $graph) { /* check which databases are valid for our category */ foreach($ui_databases as $curdatabase) { if(! preg_match("/($curcat)/i", $curdatabase)) { continue; } $optionc = split("-", $curdatabase); $search = array("-", ".rrd", $optionc); $replace = array(" :: ", "", $friendly); switch($curoption) { case "outbound": /* make sure we do not show the placeholder databases in the outbound view */ if((stristr($curdatabase, "outbound")) || (stristr($curdatabase, "allgraphs"))) { continue 2; } /* only show interfaces with a gateway */ $optionc = "$optionc[0]"; if(!interface_has_gateway($optionc)) { if(!isset($gateways_arr)) { if(preg_match("/quality/i", $curdatabase)) $gateways_arr = return_gateways_array(); else $gateways_arr = array(); } $found_gateway = false; foreach ($gateways_arr as $gw) { if ($gw['name'] == $optionc) { $found_gateway = true; break; } } if(!$found_gateway) { continue 2; } } if(! preg_match("/(^$optionc-|-$optionc\\.)/i", $curdatabase)) { continue 2; } break; case "allgraphs": /* make sure we do not show the placeholder databases in the all view */ if((stristr($curdatabase, "outbound")) || (stristr($curdatabase, "allgraphs"))) { continue 2; } break; default: /* just use the name here */ if(! preg_match("/(^$curoption-|-$curoption\\.)/i", $curdatabase)) { continue 2; } } if(in_array($curdatabase, $ui_databases)) { $dates = get_dates($curperiod, $graph); $start = $dates['start']; $end = $dates['end']; echo "\n"; } } } } ?>

"custom") { ?> "> \n"; echo "\"$prettydb\n"; echo "


\n"; echo "
\n"; echo "\"$prettydb\n"; echo "


\n"; echo "