diag_routes.php 7.57 KB
Newer Older
Ad Schellevis's avatar
Ad Schellevis committed
1 2
<?php
/*
3
	Copyritgh (C) 2014 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
	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;
}

$pgtitle = array(gettext("Diagnostics"),gettext("Routing tables"));
$shortcut_section = "routing";

include('head.inc');

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

<?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";
79
		var myAjax =  $.ajax(
80

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

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

98
		var thead = '';
Ad Schellevis's avatar
Ad Schellevis committed
99 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
		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");
	}

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

//]]>
</script>



147 148 149 150



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

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

156 157
				<?php if ($input_errors) print_input_errors($input_errors); ?>

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

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

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

						<form action="<?=$_SERVER['REQUEST_URI'];?>" method="post" name="iform" id="iform">
					    <div class="table-responsive">
168 169 170 171 172 173
				        <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>
174
									  </td>
175 176 177 178
						        </tr>
						        <tr>
						          <td><?=gettext("Number of rows");?></td>
						          <td><select id="limit" name="limit" class="form-control">
179 180 181 182 183 184 185 186
										<?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>
187 188 189 190 191 192 193 194 195 196 197 198
						        </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"); ?>" />
199
										  <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>
200 201 202 203
							      </td>
						        </tr>
					        </tbody>
					    </table>
204 205 206
					    </div>
					    </form>
				    </div>
207

208 209 210
				</div>
			</section>

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

                <div class="content-box">
214

Ad Schellevis's avatar
Ad Schellevis committed
215
                    <header class="content-box-head container-fluid">
216 217
				        <h3>IPv4</h3>
				    </header>
218

Ad Schellevis's avatar
Ad Schellevis committed
219
				     <table class="table table-striped table-sort sortable __nomb" id="IPv4" summary="ipv4 routes">
220 221 222 223 224 225 226
						<tbody>
							<tr><td class="listhdrr"><?=gettext("Gathering data, please wait...");?></td></tr>
						</tbody>
					</table>
                </div>
			</section>

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

                <div class="content-box">

Ad Schellevis's avatar
Ad Schellevis committed
231
                    <header class="content-box-head container-fluid">
232 233
				        <h3>IPv6</h3>
				    </header>
Ad Schellevis's avatar
Ad Schellevis committed
234
					<table class="table table-striped table-sort sortable __nomb" id="IPv6" summary="IPv6 routes">
235

236 237 238 239 240 241 242 243 244 245 246 247 248
						<tbody>
							<tr><td class="listhdrr"><?=gettext("Gathering data, please wait...");?></td></tr>
						</tbody>
					</table>
                </div>
			</section>
		</div>
	</div>
</section>


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