Project

General

Profile

Download (5.83 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	diag_sockets.php
4
*/
5
/* ====================================================================
6
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
7
 *
8
 *	Redistribution and use in source and binary forms, with or without modification,
9
 *	are permitted provided that the following conditions are met:
10
 *
11
 *	1. Redistributions of source code must retain the above copyright notice,
12
 *		this list of conditions and the following disclaimer.
13
 *
14
 *	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
 *
19
 *	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
 *
24
 *	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
 *
29
 *	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
 *
33
 *	6. Redistributions of any form whatsoever must retain the following
34
 *		acknowledgment:
35
 *
36
 *	"This product includes software developed by the pfSense Project
37
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
38
 *
39
 *	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
 *
52
 *	====================================================================
53
 *
54
 */
55

    
56
/*
57
	pfSense_BUILDER_BINARIES:	/usr/bin/sockstat
58
*/
59
##|+PRIV
60
##|*IDENT=page-diagnostics-sockets
61
##|*NAME=Diagnostics: Sockets
62
##|*DESCR=Allow access to the 'Diagnostics: Sockets' page.
63
##|*MATCH=diag_sockets.php*
64
##|-PRIV
65

    
66
include('guiconfig.inc');
67

    
68
$pgtitle = array(gettext("Diagnostics"), gettext("Sockets"));
69

    
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
<input class="btn btn-info btn-sm" type="button" value="<?=$showAllText?>" onclick="window.location.href='diag_sockets.php<?=$showAllOption?>'"/>
78
<br />
79
<br />
80

    
81
<?php
82
	if (isset($_GET['showAll'])) {
83
		$internet4 = shell_exec('sockstat -4');
84
		$internet6 = shell_exec('sockstat -6');
85
	} else {
86
		$internet4 = shell_exec('sockstat -4l');
87
		$internet6 = shell_exec('sockstat -6l');
88
	}
89

    
90

    
91
	foreach (array(&$internet4, &$internet6) as $tabindex => $table) {
92
		$elements = ($tabindex == 0 ? 7 : 7);
93
		$name = ($tabindex == 0 ? 'IPv4' : 'IPv6');
94
?>
95
<div class="panel panel-default">
96
	<div class="panel-heading"><h2 class="panel-title"><?=$name?> <?=gettext("system socket information")?></h2></div>
97
	<div class="panel-body">
98
		<div class="table table-responsive">
99
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
100
				<thead>
101
<?php
102
					foreach (explode("\n", $table) as $i => $line) {
103
						if (trim($line) == "")
104
							continue;
105

    
106
						$j = 0;
107
						foreach (explode(' ', $line) as $entry) {
108
							if ($entry == '' || $entry == "ADDRESS")
109
								continue;
110

    
111
							if ($i == 0) {
112
								print("<th class=\"$class\">$entry</th>\n");
113
							}
114
							else {
115
								print("<td class=\"$class\">$entry</td>\n");
116
							}
117

    
118
							$j++;
119
						}
120
						print("</tr>\n");
121
						if($i == 0) {
122
							print("</thead>\n");
123
							print("<tbody>\n");
124
						}
125
					}
126
?>
127
				</tbody>
128
			</table>
129
		</div>
130
	</div>
131
</div>
132
<?php
133
	}
134
?>
135

    
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
</div>
156
<?php
157

    
158
include('foot.inc');
159

    
160

    
(35-35/228)