diag_routes.php 7.65 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 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 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
	Copyright (C) 2006 Fernando Lamos
	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.

*/

include('guiconfig.inc');

if (isset($_REQUEST['isAjax'])) {
	$netstat = "/usr/bin/netstat -rW";
	if (isset($_REQUEST['IPv6'])) {
		$netstat .= " -f inet6";
		echo "IPv6\n";
	} else {
		$netstat .= " -f inet";
		echo "IPv4\n";
	}
	if (!isset($_REQUEST['resolve']))
		$netstat .= " -n";

	if (!empty($_REQUEST['filter']))
		$netstat .= " | /usr/bin/sed -e '1,3d; 5,\$ { /" . escapeshellarg(htmlspecialchars($_REQUEST['filter'])) . "/!d; };'";
	else
		$netstat .= " | /usr/bin/sed -e '1,3d'";

	if (is_numeric($_REQUEST['limit']) && $_REQUEST['limit'] > 0)
		$netstat .= " | /usr/bin/head -n {$_REQUEST['limit']}";

	echo htmlspecialchars_decode(shell_exec($netstat));

	exit;
}

58
$pgtitle = array(gettext('System'), gettext('Routes'), gettext('Status'));
Ad Schellevis's avatar
Ad Schellevis committed
59 60 61 62 63
$shortcut_section = "routing";

include('head.inc');

?>
64
<body>
Ad Schellevis's avatar
Ad Schellevis committed
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79

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

<script type="text/javascript">
//<![CDATA[

	function update_routes(section) {
		var url = "diag_routes.php";
		var limit = jQuery('#limit option:selected').text();
		var filter = jQuery('#filter').val();
		var params = "isAjax=true&limit=" + limit + "&filter=" + filter;
		if (jQuery('#resolve').is(':checked'))
			params += "&resolve=true";
		if (section == "IPv6")
			params += "&IPv6=true";
80
		var myAjax =  $.ajax(
81

Ad Schellevis's avatar
Ad Schellevis committed
82
			{
83 84 85 86
				url:url,
				type: 'post',
				data: params,
				success: update_routes_callback
Ad Schellevis's avatar
Ad Schellevis committed
87 88 89
			});
	}

90
	function update_routes_callback(data, textStatus, transport) {
Ad Schellevis's avatar
Ad Schellevis committed
91 92 93 94 95 96 97 98
		// First line contains section
		var responseTextArr = transport.responseText.split("\n");
		var section = responseTextArr.shift();
		var tbody = '';
		var field = '';
		var elements = 8;
		var tr_class = '';

99
		var thead = '';
Ad Schellevis's avatar
Ad Schellevis committed
100 101 102 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
		for (var i = 0; i < responseTextArr.length; i++) {
			if (responseTextArr[i] == "")
				continue;
			var tmp = '';
			if (i == 0) {
				tr_class = 'listhdrr';
				tmp += '<tr class="sortableHeaderRowIdentifier">' + "\n";
			} else {
				tr_class = 'listlr';
				tmp += '<tr>' + "\n";
			}
			var j = 0;
			var entry = responseTextArr[i].split(" ");
			for (var k = 0; k < entry.length; k++) {
				if (entry[k] == "")
					continue;
				if (i == 0 && j == (elements - 1))
					tr_class = 'listhdr';
				tmp += '<td class="' + tr_class + '">' + entry[k] + '<\/td>' + "\n";
				if (i > 0)
					tr_class = 'listr';
				j++;
			}
			// The 'Expire' field might be blank
			if (j == (elements - 1))
				tmp += '<td class="listr">&nbsp;<\/td>' + "\n";
			tmp += '<\/tr>' + "\n";
			if (i == 0)
				thead += tmp;
			else
				tbody += tmp;
		}
		jQuery('#' + section + ' > thead').html(thead);
		jQuery('#' + section + ' > tbody').html(tbody);
	}

	function update_all_routes() {
		update_routes("IPv4");
		update_routes("IPv6");
	}

141
	jQuery(document).ready(function(){setTimeout('update_all_routes()', 3000);});
Ad Schellevis's avatar
Ad Schellevis committed
142 143 144 145 146 147

//]]>
</script>



148 149 150 151



<section class="page-content-main">
152
	<div class="container-fluid">
153
		<div class="row">
154

155
			<section class="col-xs-12">
156

157
				<?php if (isset($input_errors) && count($input_errors) > 0) print_input_errors($input_errors); ?>
158

159 160
                <div class="content-box">

Ad Schellevis's avatar
Ad Schellevis committed
161
                    <header class="content-box-head container-fluid">
162 163
				        <h3><?=gettext("Routing tables"); ?></h3>
				    </header>
164

Ad Schellevis's avatar
Ad Schellevis committed
165
				    <div class="content-box-main">
166 167 168

						<form action="<?=$_SERVER['REQUEST_URI'];?>" method="post" name="iform" id="iform">
					    <div class="table-responsive">
169 170 171 172 173 174
				        <table class="table table-striped __nomb">
					        <tbody>
						        <tr>
						          <td><?=gettext("Name resolution");?></td>
						          <td><input type="checkbox" class="formfld" id="resolve" name="resolve" value="yes" <?php if ($_POST['resolve'] == 'yes') echo "checked=\"checked\""; ?> />&nbsp;<?=gettext("Enable");?>
										<p class="text-muted"><em><small><?=gettext("Enable this to attempt to resolve names when displaying the tables.");?></small></em></p>
175
									  </td>
176 177 178 179
						        </tr>
						        <tr>
						          <td><?=gettext("Number of rows");?></td>
						          <td><select id="limit" name="limit" class="form-control">
180 181 182 183 184 185 186 187
										<?php
											foreach (array("10", "50", "100", "200", "500", "1000", gettext("all")) as $item) {
												echo "<option value=\"{$item}\" " . ($item == "100" ? "selected=\"selected\"" : "") . ">{$item}</option>\n";
											}
										?>
										</select>
										<p class="text-muted"><em><small><?=gettext("Select how many rows to display.");?></small></em></p>
									 </td>
188 189 190 191 192 193 194 195 196 197 198 199
						        </tr>
						        <tr>
						          <td><?=gettext("Filter expression");?></td>
						          <td>
							          <input type="text" class="form-control search" name="filter" id="filter" />
										  <p class="text-muted"><em><small><?=gettext("Use a regular expression to filter IP address or hostnames.");?></small></em></p>
						          </td>
						        </tr>
						        <tr>
						          <td>&nbsp;</td>
						          <td>
							          <input type="button" class="btn btn-primary" name="update" onclick="update_all_routes();" value="<?=gettext("Update"); ?>" />
200
										  <p class="text-muted"><em><small><span class="text-danger"><strong><?=gettext("Note:")?></strong></span> <?=gettext("By enabling name resolution, the query should take a bit longer. You can stop it at any time by clicking the Stop button in your browser.");?></small></em></p>
201 202 203 204
							      </td>
						        </tr>
					        </tbody>
					    </table>
205 206 207
					    </div>
					    </form>
				    </div>
208

209 210 211
				</div>
			</section>

212 213 214
			<section class="col-xs-12">

                <div class="content-box">
215

Ad Schellevis's avatar
Ad Schellevis committed
216
                    <header class="content-box-head container-fluid">
217 218
				        <h3>IPv4</h3>
				    </header>
219 220
				     <table class="table table-striped table-sort sortable __nomb" id="IPv4" summary="IPv4 routes">
						<thead></thead>
221 222 223 224 225 226 227
						<tbody>
							<tr><td class="listhdrr"><?=gettext("Gathering data, please wait...");?></td></tr>
						</tbody>
					</table>
                </div>
			</section>

228 229 230 231
			<section class="col-xs-12">

                <div class="content-box">

Ad Schellevis's avatar
Ad Schellevis committed
232
                    <header class="content-box-head container-fluid">
233 234
				        <h3>IPv6</h3>
				    </header>
Ad Schellevis's avatar
Ad Schellevis committed
235
					<table class="table table-striped table-sort sortable __nomb" id="IPv6" summary="IPv6 routes">
236
						<thead></thead>
237 238 239 240 241 242 243 244 245 246 247 248 249
						<tbody>
							<tr><td class="listhdrr"><?=gettext("Gathering data, please wait...");?></td></tr>
						</tbody>
					</table>
                </div>
			</section>
		</div>
	</div>
</section>


<?php
include('foot.inc');
250
?>