Project

General

Profile

Download (3.78 KB) Statistics
| Branch: | Tag: | Revision:
1 f1e01f7c Erik Fonnesbeck
<?php
2
/*
3 c5d81585 Renato Botelho
 * diag_sockets.php
4 fd9ebcd5 Stephen Beaver
 *
5 c5d81585 Renato Botelho
 * part of pfSense (https://www.pfsense.org)
6 81299b5c Renato Botelho
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
7 c5d81585 Renato Botelho
 * All rights reserved.
8 fd9ebcd5 Stephen Beaver
 *
9 b12ea3fb Renato Botelho
 * Licensed under the Apache License, Version 2.0 (the "License");
10
 * you may not use this file except in compliance with the License.
11
 * You may obtain a copy of the License at
12 fd9ebcd5 Stephen Beaver
 *
13 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
14 fd9ebcd5 Stephen Beaver
 *
15 b12ea3fb Renato Botelho
 * Unless required by applicable law or agreed to in writing, software
16
 * distributed under the License is distributed on an "AS IS" BASIS,
17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
 * See the License for the specific language governing permissions and
19
 * limitations under the License.
20 fd9ebcd5 Stephen Beaver
 */
21 f1e01f7c Erik Fonnesbeck
22
##|+PRIV
23
##|*IDENT=page-diagnostics-sockets
24 5230f468 jim-p
##|*NAME=Diagnostics: Sockets
25 f1e01f7c Erik Fonnesbeck
##|*DESCR=Allow access to the 'Diagnostics: Sockets' page.
26
##|*MATCH=diag_sockets.php*
27
##|-PRIV
28
29 86573bb9 Phil Davis
require_once('guiconfig.inc');
30 f1e01f7c Erik Fonnesbeck
31 699737d9 Phil Davis
$pgtitle = array(gettext("Diagnostics"), gettext("Sockets"));
32 f1e01f7c Erik Fonnesbeck
33
include('head.inc');
34
35
$showAll = isset($_GET['showAll']);
36 185b4365 Phil Davis
$showAllText = $showAll ? gettext("Show only listening sockets") : gettext("Show all socket connections");
37 f1e01f7c Erik Fonnesbeck
$showAllOption = $showAll ? "" : "?showAll";
38
39
?>
40 37676f4e jim-p
<button class="btn btn-info btn-sm" type="button" value="<?=$showAllText?>" onclick="window.location.href='diag_sockets.php<?=$showAllOption?>'">
41
	<i class="fa fa-<?= ($showAll) ? 'minus-circle' : 'plus-circle' ; ?> icon-embed-btn"></i>
42
	<?=$showAllText?>
43
</button>
44 b9a5448f Stephen Beaver
<br />
45
<br />
46 f1e01f7c Erik Fonnesbeck
47
<?php
48 5f601060 Phil Davis
	if (isset($_GET['showAll'])) {
49 f1e01f7c Erik Fonnesbeck
		$internet4 = shell_exec('sockstat -4');
50
		$internet6 = shell_exec('sockstat -6');
51
	} else {
52 b965f190 PiBa-NL
		$internet4 = shell_exec('sockstat -4l');
53
		$internet6 = shell_exec('sockstat -6l');
54 f1e01f7c Erik Fonnesbeck
	}
55 b9a5448f Stephen Beaver
56
57 f1e01f7c Erik Fonnesbeck
	foreach (array(&$internet4, &$internet6) as $tabindex => $table) {
58
		$elements = ($tabindex == 0 ? 7 : 7);
59
		$name = ($tabindex == 0 ? 'IPv4' : 'IPv6');
60
?>
61 b9a5448f Stephen Beaver
<div class="panel panel-default">
62 3d7a8696 k-paulius
	<div class="panel-heading"><h2 class="panel-title"><?=$name?> <?=gettext("System Socket Information")?></h2></div>
63 b9a5448f Stephen Beaver
	<div class="panel-body">
64 a6ff5ea1 sbeaver
		<div class="table table-responsive">
65 10fe1eb5 Stephen Beaver
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
66 a6ff5ea1 sbeaver
				<thead>
67 f1e01f7c Erik Fonnesbeck
<?php
68 a6ff5ea1 sbeaver
					foreach (explode("\n", $table) as $i => $line) {
69 947141fd Phil Davis
						if (trim($line) == "") {
70 a6ff5ea1 sbeaver
							continue;
71 947141fd Phil Davis
						}
72 a6ff5ea1 sbeaver
73
						$j = 0;
74 63ff711e Colin Fleming
						print("<tr>\n");
75 a6ff5ea1 sbeaver
						foreach (explode(' ', $line) as $entry) {
76 947141fd Phil Davis
							if ($entry == '' || $entry == "ADDRESS") {
77 b9a5448f Stephen Beaver
								continue;
78 947141fd Phil Davis
							}
79 b9a5448f Stephen Beaver
80
							if ($i == 0) {
81 a6ff5ea1 sbeaver
								print("<th class=\"$class\">$entry</th>\n");
82 947141fd Phil Davis
							} else {
83 a6ff5ea1 sbeaver
								print("<td class=\"$class\">$entry</td>\n");
84 b9a5448f Stephen Beaver
							}
85 a6ff5ea1 sbeaver
86
							$j++;
87
						}
88
						print("</tr>\n");
89 947141fd Phil Davis
						if ($i == 0) {
90 b9a5448f Stephen Beaver
							print("</thead>\n");
91
							print("<tbody>\n");
92
						}
93 a6ff5ea1 sbeaver
					}
94
?>
95
				</tbody>
96
			</table>
97
		</div>
98 b9a5448f Stephen Beaver
	</div>
99
</div>
100 f1e01f7c Erik Fonnesbeck
<?php
101 f1dab9ec sbeaver
	}
102 f1e01f7c Erik Fonnesbeck
?>
103 b9a5448f Stephen Beaver
104
<div>
105 35681930 Stephen Beaver
<div class="infoblock">
106 b9a5448f Stephen Beaver
<?php
107 1121b4a7 jim-p
print_info_box(gettext('Socket Information') . '<br /><br />' .
108
gettext('This page shows all listening sockets by default, and shows both listening and outbound connection sockets when <strong>Show all socket connections</strong> is clicked.<br /><br />' .
109
		'The information listed for each socket is:' . '<br /><br />' .
110
		'<dl class="dl-horizontal responsive">' .
111
			'<dt>USER</dt>			<dd>The user who owns the socket.</dd>' .
112
			'<dt>COMMAND</dt>		<dd>The command which holds the socket.</dd>' .
113
			'<dt>PID</dt>			<dd>The process ID of the command which holds the socket.</dd>' .
114
			'<dt>FD</dt>			<dd>The file descriptor number of the socket.</dd>' .
115
			'<dt>PROTO</dt>			<dd>The transport protocol associated with the socket.</dd>' .
116
			'<dt>LOCAL ADDRESS</dt>		<dd>The address the local end of the socket is bound to.</dd>' .
117
			'<dt>FOREIGN ADDRESS</dt>	<dd>The address the foreign end of the socket is bound to.</dd>' .
118
		'</dl>'), 'info', false);
119 b9a5448f Stephen Beaver
?>
120
</div>
121 f1e01f7c Erik Fonnesbeck
</div>
122
<?php
123 f1dab9ec sbeaver
124
include('foot.inc');
125