status_graph.php 13.1 KB
Newer Older
Ad Schellevis's avatar
Ad Schellevis committed
1
<?php
2

Ad Schellevis's avatar
Ad Schellevis committed
3
/*
4
	Copyright (C) 2014-2015 Deciso B.V.
Ad Schellevis's avatar
Ad Schellevis committed
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
	Copyright (C) 2004 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
	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.
*/

31
require_once("guiconfig.inc");
Ad Schellevis's avatar
Ad Schellevis committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47

if ($_POST['width'])
	$width = $_POST['width'];
else
	$width = "100%";

if ($_POST['height'])
	$height = $_POST['height'];
else
	$height = "200";

// Get configured interface list
$ifdescrs = get_configured_interface_with_descr();
if (isset($config['ipsec']['enable']))
	$ifdescrs['enc0'] = "IPsec";
foreach (array('server', 'client') as $mode) {
48
	if (isset($config['openvpn']["openvpn-{$mode}"])) {
Ad Schellevis's avatar
Ad Schellevis committed
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
		foreach ($config['openvpn']["openvpn-{$mode}"] as $id => $setting) {
			if (!isset($setting['disable'])) {
				$ifdescrs['ovpn' . substr($mode, 0, 1) . $setting['vpnid']] = gettext("OpenVPN") . " ".$mode.": ".htmlspecialchars($setting['description']);
			}
		}
	}
}

if ($_GET['if']) {
	$curif = $_GET['if'];
	$found = false;
	foreach($ifdescrs as $descr => $ifdescr) {
		if ($descr == $curif) {
			$found = true;
			break;
		}
	}
	if ($found === false) {
		header("Location: status_graph.php");
		exit;
	}
} else {
	if (empty($ifdescrs["wan"])) {
		/* Handle the case when WAN has been disabled. Use the first key in ifdescrs. */
		reset($ifdescrs);
		$curif = key($ifdescrs);
	}
	else {
		$curif = "wan";
	}
}
if ($_GET['sort']) {
	$cursort = $_GET['sort'];
} else {
	$cursort = "";
}
if ($_GET['filter']) {
	$curfilter = $_GET['filter'];
} else {
	$curfilter = "";
}
if ($_GET['hostipformat']) {
	$curhostipformat = $_GET['hostipformat'];
} else {
	$curhostipformat = "";
}

96
$pgtitle = array(gettext('Interfaces'), gettext('Traffic Graph'));
Ad Schellevis's avatar
Ad Schellevis committed
97 98 99 100 101

include("head.inc");

?>

102
<body>
Ad Schellevis's avatar
Ad Schellevis committed
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
<?php include("fbegin.inc"); ?>

<script type="text/javascript">
//<![CDATA[
function updateBandwidth(){
    var hostinterface = jQuery("#if").val();
	var sorting = jQuery("#sort").val();
	var filter = jQuery("#filter").val();
	var hostipformat = jQuery("#hostipformat").val();
    bandwidthAjax(hostinterface, sorting, filter, hostipformat);
}

function bandwidthAjax(hostinterface, sorting, filter, hostipformat) {
	uri = "bandwidth_by_ip.php?if=" + hostinterface + "&sort=" + sorting + "&filter=" + filter + "&hostipformat=" + hostipformat;
	var opt = {
	    // Use GET
	    type: 'get',
	    error: function(req) {
	        /* XXX: Leave this for debugging purposes: Handle 404
	        if(req.status == 404)
	            alert('Error 404: location "' + uri + '" was not found.');
		*/
	        /* Handle other errors
	        else
	            alert('Error ' + req.status + ' -- ' + req.statusText + ' -- ' + uri);
		*/
	    },
		success: function(data) {
			updateBandwidthHosts(data);
	    }
	}
	jQuery.ajax(uri, opt);
}

function updateBandwidthHosts(data){
    var hosts_split = data.split("|");
    d = document;
    //parse top ten bandwidth abuser hosts
    for (var y=0; y<10; y++){
        if ((y < hosts_split.length) && (hosts_split[y] != "") && (hosts_split[y] != "no info")) {
			hostinfo = hosts_split[y].split(";");

			//update host ip info
			var HostIpID = "hostip" + y;
			var hostip = d.getElementById(HostIpID);
			hostip.innerHTML = hostinfo[0];

			//update bandwidth inbound to host
			var hostbandwidthInID = "bandwidthin" + y;
			var hostbandwidthin = d.getElementById(hostbandwidthInID);
			hostbandwidthin.innerHTML = hostinfo[1] + " Bits/sec";

			//update bandwidth outbound from host
			var hostbandwidthOutID = "bandwidthout" + y;
			var hostbandwidthOut = d.getElementById(hostbandwidthOutID);
			hostbandwidthOut.innerHTML = hostinfo[2] + " Bits/sec";

			//make the row appear if hidden
			var rowid = "#host" + y;
			if (jQuery(rowid).css('display') == "none"){
				//hide rows that contain no data
				jQuery(rowid).show(1000);
			}
        }
        else
        {
            var rowid = "#host" + y;
            if (jQuery(rowid).css('display') != "none"){
                //hide rows that contain no data
                jQuery(rowid).fadeOut(2000);
            }
        }
    }
176

Ad Schellevis's avatar
Ad Schellevis committed
177 178 179 180 181 182 183 184
    setTimeout('updateBandwidth()', 1000);
}
//]]>
</script>

<?php

/* link the ipsec interface magically */
185
if (isset($config['ipsec']['enable']) || isset($config['ipsec']['client']['enable']))
Ad Schellevis's avatar
Ad Schellevis committed
186 187 188 189
	$ifdescrs['enc0'] = "IPsec";

?>

190 191

	<section class="page-content-main">
192
		<div class="container-fluid">
193
			<div class="row">
194

195
				<?php if (isset($input_errors) && count($input_errors) > 0) print_input_errors($input_errors); ?>
196

197
			    <section class="col-xs-12">
198

199
				    <div class="content-box">
200

201 202 203
						<form name="form1" action="status_graph.php" method="get">
						<div class="table-responsive" >
                            <table class="table table-striped" style="margin-bottom:0;">
204 205 206
					      <thead>
					        <tr>
					          <th><?=gettext("Interface"); ?></th>
207 208 209
                    <th><?= gettext('Sort by') ?></th>
                    <th><?= gettext('Filter') ?></th>
                    <th><?= gettext('Display') ?></th>
210 211 212 213 214
					        </tr>
					      </thead>
					      <tbody>
					        <tr>
					          <td><select id="if" name="if" class="form-control" style="z-index: -10;" onchange="document.form1.submit()">
215 216 217 218 219 220 221 222
						<?php
						foreach ($ifdescrs as $ifn => $ifd) {
							echo "<option value=\"$ifn\"";
							if ($ifn == $curif) echo " selected=\"selected\"";
							echo ">" . htmlspecialchars($ifd) . "</option>\n";
						}
						?>
						</select></td>
223
					          <td><select id="sort" name="sort" class="form-control" style="z-index: -10;" onchange="document.form1.submit()">
224 225
              <option value=""><?= gettext('Bw In') ?></option>
              <option value="out"<?php if ($cursort == "out") echo " selected=\"selected\"";?>><?= gettext('Bw Out') ?></option>
226
						</select></td>
227
					          <td><select id="filter" name="filter" class="form-control" style="z-index: -10;" onchange="document.form1.submit()">
228 229 230
              <option value="local"<?php if ($curfilter == "local") echo " selected=\"selected\"";?>><?= gettext('Local') ?></option>
              <option value="remote"<?php if ($curfilter == "remote") echo " selected=\"selected\"";?>><?= gettext('Remote') ?></option>
              <option value="all"<?php if ($curfilter == "all") echo " selected=\"selected\"";?>><?= gettext('All') ?></option>
231
						</select></td>
232
					          <td><select id="hostipformat" name="hostipformat" class="form-control" style="z-index: -10;" onchange="document.form1.submit()">
233 234 235
              <option value=""><?= gettext('IP Address') ?></option>
              <option value="hostname"<?php if ($curhostipformat == "hostname") echo " selected";?>><?= gettext('Host Name') ?></option>
              <option value="fqdn"<?php if ($curhostipformat == "fqdn") echo " selected=\"selected\"";?>><?= gettext('FQDN') ?></option>
236
						</select></td>
237 238
					        </tr>
					      </tbody>
239 240 241
                            </table>
						</div>
						</form>
242

243 244
				    </div>
			    </section>
245

246
				 <section class="col-xs-12">
247

248
				    <div class="content-box">
249 250


251 252 253 254 255
						<div id="niftyOutter" class="col-xs-12">
						    <div id="col1" style="float: left; width: 46%; padding: 5px; position: relative;">
						        <object	data="graph.php?ifnum=<?=htmlspecialchars($curif);?>&amp;ifname=<?=rawurlencode($ifdescrs[htmlspecialchars($curif)]);?>">
						          <param name="id" value="graph" />
						          <param name="type" value="image/svg+xml" />
256 257
						          <param name="width" value="<?php echo $width; ?>" />
						          <param name="height" value="<?php echo $height; ?>" />
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
						          <param name="pluginspage" value="http://www.adobe.com/svg/viewer/install/auto" />
						        </object>
						    </div>
						    <div id="col2" style="float: right; width: 48%; padding: 5px; position: relative;">
						        <table width="100%" border="0" cellspacing="0" cellpadding="0" summary="status">
						            <tr>
						                <td class="listtopic" valign="top"><?=(($curhostipformat=="") ? gettext("Host IP") : gettext("Host Name or IP")); ?></td>
						                <td class="listtopic" valign="top"><?=gettext("Bandwidth In"); ?></td>
						                <td class="listtopic" valign="top"><?=gettext("Bandwidth Out"); ?></td>
						           </tr>
						           <tr id="host0" style="display:none">
						                <td id="hostip0" class="vncell">
						                </td>
						                <td id="bandwidthin0" class="listr">
						                </td>
						                <td id="bandwidthout0" class="listr">
						                </td>
						           </tr>
						           <tr id="host1" style="display:none">
						                <td id="hostip1" class="vncell">
						                </td>
						                <td id="bandwidthin1" class="listr">
						                </td>
						                <td id="bandwidthout1" class="listr">
						                </td>
						           </tr>
						           <tr id="host2" style="display:none">
						                <td id="hostip2" class="vncell">
						                </td>
						                <td id="bandwidthin2" class="listr">
						                </td>
						                <td id="bandwidthout2" class="listr">
						                </td>
						           </tr>
						           <tr id="host3" style="display:none">
						                <td id="hostip3" class="vncell">
						                </td>
						                <td id="bandwidthin3" class="listr">
						                </td>
						                <td id="bandwidthout3" class="listr">
						                </td>
						           </tr>
						           <tr id="host4" style="display:none">
						                <td id="hostip4" class="vncell">
						                </td>
						                <td id="bandwidthin4" class="listr">
						                </td>
						                <td id="bandwidthout4" class="listr">
						                </td>
						           </tr>
						           <tr id="host5" style="display:none">
						                <td id="hostip5" class="vncell">
						                </td>
						                <td id="bandwidthin5" class="listr">
						                </td>
						                <td id="bandwidthout5" class="listr">
						                </td>
						           </tr>
						           <tr id="host6" style="display:none">
						                <td id="hostip6" class="vncell">
						                </td>
						                <td id="bandwidthin6" class="listr">
						                </td>
						                <td id="bandwidthout6" class="listr">
						                </td>
						           </tr>
						           <tr id="host7" style="display:none">
						                <td id="hostip7" class="vncell">
						                </td>
						                <td id="bandwidthin7" class="listr">
						                </td>
						                <td id="bandwidthout7" class="listr">
						                </td>
						           </tr>
						           <tr id="host8" style="display:none">
						                <td id="hostip8" class="vncell">
						                </td>
						                <td id="bandwidthin8" class="listr">
						                </td>
						                <td id="bandwidthout8" class="listr">
						                </td>
						           </tr>
						           <tr id="host9" style="display:none">
						                <td id="hostip9" class="vncell">
						                </td>
						                <td id="bandwidthin9" class="listr">
						                </td>
						                <td id="bandwidthout9" class="listr">
						                </td>
						           </tr>
						        </table>
							</div>
							<div style="clear: both;"></div>
						</div>
						<div class="col-xs-12">
							<p><span class="text-danger"><strong><?=gettext("Note"); ?>:</strong></span> <?=gettext("the"); ?> <a href="http://www.adobe.com/svg/viewer/install/" target="_blank"><?=gettext("Adobe SVG Viewer"); ?></a>, <?=gettext("Firefox 1.5 or later or other browser supporting SVG is required to view the graph"); ?>.</p>
						</div>
					</div>
				</section>
			</div>
		</div>
	</section>
Ad Schellevis's avatar
Ad Schellevis committed
360 361 362 363 364 365

<script type="text/javascript">
//<![CDATA[
jQuery(document).ready(updateBandwidth);
//]]>
</script>
366
<?php include("foot.inc"); ?>