status_rrd_graph_settings.php 7.41 KB
Newer Older
Ad Schellevis's avatar
Ad Schellevis committed
1 2
<?php
/*
3
	Copyright (C) 2014-2015 Deciso B.V.
Ad Schellevis's avatar
Ad Schellevis committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
	Copyright (C) 2007 Seth Mos <seth.mos@dds.nl>
	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.
*/

require("guiconfig.inc");
require_once("filter.inc");
require("shaper.inc");
require_once("rrd.inc");

$pconfig['enable'] = isset($config['rrd']['enable']);
$pconfig['category'] = $config['rrd']['category'];
$pconfig['style'] = $config['rrd']['style'];
$pconfig['period'] = $config['rrd']['period'];

$curcat = "settings";
$categories = array('system' => gettext("System"),
		'traffic' => gettext("Traffic"),
		'packets' => gettext("Packets"),
		'quality' => gettext("Quality"),
		'queues' => gettext("Queues"),
		'captiveportal' => gettext("Captive Portal"));

if(isset($config['ntpd']['statsgraph'])) {
	$categories['ntpd'] = gettext("NTP");
}

$styles = array('inverse' => gettext("Inverse"),
		'absolute' => gettext("Absolute"));
$periods = array("absolute" => gettext("Absolute Timespans"),
		"current" => gettext("Current Period"),
		"previous" => gettext("Previous Period"));

if ($_POST['ResetRRD']) {
	mwexec('/bin/rm /var/db/rrd/*');
	enable_rrd_graphing();
	setup_gateways_monitor();
	$savemsg = "RRD data has been cleared. New RRD files have been generated.";
} elseif ($_POST) {
	unset($input_errors);
	$pconfig = $_POST;

	/* input validation */
	/* none */

        if (!$input_errors) {
                $config['rrd']['enable'] = $_POST['enable'] ? true : false;
                $config['rrd']['category'] = $_POST['category'];
                $config['rrd']['style'] = $_POST['style'];
                $config['rrd']['period'] = $_POST['period'];
                write_config();

                $retval = 0;
                $retval = enable_rrd_graphing();
                $savemsg = get_std_save_message($retval);
	}
}



$rrddbpath = "/var/db/rrd/";
chdir($rrddbpath);
$databases = glob("*.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;
	}
	if(stristr($database, "captiveportal-") && is_array($config['captiveportal'])) {
		$captiveportal = true;
	}
}

$pgtitle = array(gettext("Status"),gettext("RRD Graphs"));
include("head.inc");

?>
110 111 112

<body>

Ad Schellevis's avatar
Ad Schellevis committed
113
<?php include("fbegin.inc"); ?>
114 115

	<section class="page-content-main">
116
		<div class="container-fluid">
117
			<div class="row">
118

119 120
				<?php if ($input_errors) print_input_errors($input_errors); ?>
				<?php if ($savemsg) print_info_box($savemsg); ?>
121

122
			    <section class="col-xs-12">
123 124 125 126 127

				<? include("status_rrd_graph_tabs.php"); ?>

					<div class="tab-content content-box col-xs-12">

128 129

							<form action="status_rrd_graph_settings.php" method="post" name="iform" id="iform">
130 131


132 133

							<div class="table-responsive">
134
								<table class="table table-striped __nomb">
135 136 137 138 139 140 141 142 143 144
									<tr>
										<td width="22%" valign="top" class="vtable"><?=gettext("RRD Graphs");?></td>
										<td width="78%" class="vtable">
											<label>
												<input name="enable" type="checkbox" id="enable" value="yes" <?php if ($pconfig['enable']) echo "checked=\"checked\"" ?> onclick="enable_change(false)" />
												&nbsp;<?=gettext("Enables the RRD graphing backend.");?>
											</label>
										</td>
									</tr>
									<tr>
145
							<td width="22%" valign="top" class="vtable"><?=gettext("Default category");?></td>
146 147 148 149 150 151 152 153 154 155 156 157 158 159
				                        <td width="78%" class="vtable">
											<select name="category" id="category" class="form-control" style="z-index: -10;" >
											<?php
											foreach ($categories as $category => $categoryd) {
												echo "<option value=\"$category\"";
												if ($category == $pconfig['category']) echo " selected=\"selected\"";
												echo ">" . htmlspecialchars($categoryd) . "</option>\n";
											}
											?>
											</select>
											<p class="text-muted"><em><small><?=gettext("This selects default category.");?></small></em></p>
										</td>
									</tr>
									<tr>
160
							<td width="22%" valign="top" class="vtable"><?=gettext("Default style");?></td>
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
				                        <td width="78%" class="vtable">
											<select name="style" class="form-control" style="z-index: -10;" >
											<?php
											foreach ($styles as $style => $styled) {
												echo "<option value=\"$style\"";
												if ($style == $pconfig['style']) echo " selected=\"selected\"";
												echo ">" . htmlspecialchars($styled) . "</option>\n";
											}
											?>
											</select>
											<p class="text-muted"><em><small><?=gettext("This selects the default style.");?></small></em></p>
										</td>
									</tr>
									<tr>
										<td width="22%" valign="top" class="vtable"><?=gettext("Default period");?></td>
										<td width="78%" class="vtable">
											<select name="period" class="form-control" style="z-index: -10;" >
											<?php
											foreach ($periods as $period => $periodd) {
												echo "<option value=\"$period\"";
												if ($period == $pconfig['period']) echo " selected=\"selected\"";
												echo ">" . htmlspecialchars($periodd) . "</option>\n";
											}
											?>
											</select>
											<p class="text-muted"><em><small><?=gettext("This selects the default period.");?></small></em></p>
										</td>
									</tr>
									<tr>
										<td width="22%" valign="top">&nbsp;</td>
										<td width="78%">
											<input name="Submit" type="submit" class="btn btn-primary" value="<?=gettext("Save");?>" onclick="enable_change(true)" />
											<input name="ResetRRD" type="submit" class="btn btn-default" value="<?=gettext("Reset RRD Data");?>" onclick="return confirm('<?=gettext('Do you really want to reset the RRD graphs? This will erase all graph data.');?>')" />
										</td>
									</tr>
								</table>
							 </div>
198
							 <div class="container-fluid">
199 200 201
							 <p><strong><span class="text-danger"><?=gettext("Note:");?></span></strong><br />
											<?=gettext("Graphs will not be allowed to be recreated within a 1 minute interval, please " .
											"take this into account after changing the style.");?>
202

203 204 205
							 </p>
						</div>
				    </div>
206
			</section>
207
			</div>
Ad Schellevis's avatar
Ad Schellevis committed
208
		</div>
209
	</section>
210 211

<?php include("foot.inc"); ?>