Project

General

Profile

Download (5.83 KB) Statistics
| Branch: | Tag: | Revision:
1 f1e01f7c Erik Fonnesbeck
<?php
2
/*
3
	diag_sockets.php
4
*/
5 fd9ebcd5 Stephen Beaver
/* ====================================================================
6 b9a5448f Stephen Beaver
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
7 fd9ebcd5 Stephen Beaver
 *
8 b9a5448f Stephen Beaver
 *	Redistribution and use in source and binary forms, with or without modification,
9
 *	are permitted provided that the following conditions are met:
10 fd9ebcd5 Stephen Beaver
 *
11 b9a5448f Stephen Beaver
 *	1. Redistributions of source code must retain the above copyright notice,
12
 *		this list of conditions and the following disclaimer.
13 fd9ebcd5 Stephen Beaver
 *
14 b9a5448f Stephen Beaver
 *	2. Redistributions in binary form must reproduce the above copyright
15
 *		notice, this list of conditions and the following disclaimer in
16
 *		the documentation and/or other materials provided with the
17
 *		distribution.
18 fd9ebcd5 Stephen Beaver
 *
19 b9a5448f Stephen Beaver
 *	3. All advertising materials mentioning features or use of this software
20
 *		must display the following acknowledgment:
21
 *		"This product includes software developed by the pfSense Project
22
 *		 for use in the pfSense software distribution. (http://www.pfsense.org/).
23 fd9ebcd5 Stephen Beaver
 *
24 b9a5448f Stephen Beaver
 *	4. The names "pfSense" and "pfSense Project" must not be used to
25
 *		 endorse or promote products derived from this software without
26
 *		 prior written permission. For written permission, please contact
27
 *		 coreteam@pfsense.org.
28 fd9ebcd5 Stephen Beaver
 *
29 b9a5448f Stephen Beaver
 *	5. Products derived from this software may not be called "pfSense"
30
 *		nor may "pfSense" appear in their names without prior written
31
 *		permission of the Electric Sheep Fencing, LLC.
32 fd9ebcd5 Stephen Beaver
 *
33 b9a5448f Stephen Beaver
 *	6. Redistributions of any form whatsoever must retain the following
34
 *		acknowledgment:
35 fd9ebcd5 Stephen Beaver
 *
36 b9a5448f Stephen Beaver
 *	"This product includes software developed by the pfSense Project
37
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
38 0da0d43e Phil Davis
 *
39 b9a5448f Stephen Beaver
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
40
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
43
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
51 fd9ebcd5 Stephen Beaver
 *
52 b9a5448f Stephen Beaver
 *	====================================================================
53 fd9ebcd5 Stephen Beaver
 *
54
 */
55 f1e01f7c Erik Fonnesbeck
56
/*
57 f1dab9ec sbeaver
	pfSense_BUILDER_BINARIES:	/usr/bin/sockstat
58 f1e01f7c Erik Fonnesbeck
*/
59
##|+PRIV
60
##|*IDENT=page-diagnostics-sockets
61
##|*NAME=Diagnostics: Sockets page
62
##|*DESCR=Allow access to the 'Diagnostics: Sockets' page.
63
##|*MATCH=diag_sockets.php*
64
##|-PRIV
65
66
include('guiconfig.inc');
67
68 699737d9 Phil Davis
$pgtitle = array(gettext("Diagnostics"), gettext("Sockets"));
69 f1e01f7c Erik Fonnesbeck
70
include('head.inc');
71
72
$showAll = isset($_GET['showAll']);
73
$showAllText = $showAll ? "Show only listening sockets" : "Show all socket connections";
74
$showAllOption = $showAll ? "" : "?showAll";
75
76
?>
77 b9a5448f Stephen Beaver
<input class="btn btn-info btn-sm" type="button" value="<?=$showAllText?>" onclick="window.location.href='diag_sockets.php<?=$showAllOption?>'"/>
78
<br />
79
<br />
80 f1e01f7c Erik Fonnesbeck
81
<?php
82 5f601060 Phil Davis
	if (isset($_GET['showAll'])) {
83 f1e01f7c Erik Fonnesbeck
		$internet4 = shell_exec('sockstat -4');
84
		$internet6 = shell_exec('sockstat -6');
85
	} else {
86 b965f190 PiBa-NL
		$internet4 = shell_exec('sockstat -4l');
87
		$internet6 = shell_exec('sockstat -6l');
88 f1e01f7c Erik Fonnesbeck
	}
89 b9a5448f Stephen Beaver
90
91 f1e01f7c Erik Fonnesbeck
	foreach (array(&$internet4, &$internet6) as $tabindex => $table) {
92
		$elements = ($tabindex == 0 ? 7 : 7);
93
		$name = ($tabindex == 0 ? 'IPv4' : 'IPv6');
94
?>
95 b9a5448f Stephen Beaver
<div class="panel panel-default">
96 10fe1eb5 Stephen Beaver
	<div class="panel-heading"><h2 class="panel-title"><?=$name?> <?=gettext("system socket information")?></h2></div>
97 b9a5448f Stephen Beaver
	<div class="panel-body">
98 a6ff5ea1 sbeaver
		<div class="table table-responsive">
99 10fe1eb5 Stephen Beaver
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
100 a6ff5ea1 sbeaver
				<thead>
101 f1e01f7c Erik Fonnesbeck
<?php
102 a6ff5ea1 sbeaver
					foreach (explode("\n", $table) as $i => $line) {
103
						if (trim($line) == "")
104
							continue;
105
106
						$j = 0;
107
						foreach (explode(' ', $line) as $entry) {
108 b9a5448f Stephen Beaver
							if ($entry == '' || $entry == "ADDRESS")
109
								continue;
110
111
							if ($i == 0) {
112 a6ff5ea1 sbeaver
								print("<th class=\"$class\">$entry</th>\n");
113 b9a5448f Stephen Beaver
							}
114
							else {
115 a6ff5ea1 sbeaver
								print("<td class=\"$class\">$entry</td>\n");
116 b9a5448f Stephen Beaver
							}
117 a6ff5ea1 sbeaver
118
							$j++;
119
						}
120
						print("</tr>\n");
121 b9a5448f Stephen Beaver
						if($i == 0) {
122
							print("</thead>\n");
123
							print("<tbody>\n");
124
						}
125 a6ff5ea1 sbeaver
					}
126
?>
127
				</tbody>
128
			</table>
129
		</div>
130 b9a5448f Stephen Beaver
	</div>
131
</div>
132 f1e01f7c Erik Fonnesbeck
<?php
133 f1dab9ec sbeaver
	}
134 f1e01f7c Erik Fonnesbeck
?>
135 b9a5448f Stephen Beaver
136
<div>
137
<div id="infoblock">
138
<?php
139
print_info_box(gettext('Socket information - explanation.') . '<br /><br />' .
140
gettext('This page shows the output for the commands: "sockstat -4lL" and "sockstat -6lL".' . '<br />' .
141
		'Or in case of showing all sockets the output for: "sockstat -4" and "sockstat -6".' . '<br />' . '<br />' .
142
'The information listed for each socket is:' . '<br /><br />' .
143
' <dl class="dl-horizontal responsive">' .
144
				'<dt>USER</dt>			<dd>The user who owns the socket.</dd>' .
145
				'<dt>COMMAND</dt>		<dd>The command which holds the socket.</dd>' .
146
				'<dt>PID</dt>			<dd>The process ID of the command which holds the socket.</dd>' .
147
				'<dt>FD</dt>				<dd>The file descriptor number of the socket.</dd>' .
148
				'<dt>PROTO</dt>			<dd>The transport protocol associated with the socket for Internet sockets, or the type of socket (stream or data-gram) for UNIX sockets.</dd>' .
149
				'<dt>ADDRESS</dt>		<dd>(UNIX sockets only) For bound sockets, this is the file-name of the socket. For other sockets, it is the name, PID and file descriptor number of the peer, or "(none)" if the socket is neither bound nor connected.</dd>' .
150
				'<dt>LOCAL ADDRESS</dt> <dd>(Internet sockets only) The address the local end of the socket is bound to (see getsockname(2)).</dd>' .
151
				'<dt>FOREIGN ADDRESS</dt><dd>(Internet sockets only) The address the foreign end of the socket is bound to (see getpeername(2)).</dd>' .
152
			'</dl>'), info);
153
?>
154
</div>
155 f1e01f7c Erik Fonnesbeck
</div>
156
<?php
157 f1dab9ec sbeaver
158
include('foot.inc');
159