Project

General

Profile

Download (5.96 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
##|+PRIV
57
##|*IDENT=page-diagnostics-sockets
58
##|*NAME=Diagnostics: Sockets
59
##|*DESCR=Allow access to the 'Diagnostics: Sockets' page.
60
##|*MATCH=diag_sockets.php*
61
##|-PRIV
62

    
63
include('guiconfig.inc');
64

    
65
$pgtitle = array(gettext("Diagnostics"), gettext("Sockets"));
66

    
67
include('head.inc');
68

    
69
$showAll = isset($_GET['showAll']);
70
$showAllText = $showAll ? gettext("Show only listening sockets") : gettext("Show all socket connections");
71
$showAllOption = $showAll ? "" : "?showAll";
72

    
73
?>
74
<button class="btn btn-info btn-sm" type="button" value="<?=$showAllText?>" onclick="window.location.href='diag_sockets.php<?=$showAllOption?>'">
75
	<i class="fa fa-<?= ($showAll) ? 'minus-circle' : 'plus-circle' ; ?> icon-embed-btn"></i>
76
	<?=$showAllText?>
77
</button>
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

    
107
						$j = 0;
108
						print("<tr>\n");
109
						foreach (explode(' ', $line) as $entry) {
110
							if ($entry == '' || $entry == "ADDRESS") {
111
								continue;
112
							}
113

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

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

    
138
<div>
139
<div class="infoblock">
140
<?php
141
print_info_box(gettext('Socket information - explanation.') . '<br /><br />' .
142
gettext('This page shows the output for the commands: "sockstat -4lL" and "sockstat -6lL".' . '<br />' .
143
		'Or in case of showing all sockets the output for: "sockstat -4" and "sockstat -6".' . '<br />' . '<br />' .
144
'The information listed for each socket is:' . '<br /><br />' .
145
' <dl class="dl-horizontal responsive">' .
146
				'<dt>USER</dt>			<dd>The user who owns the socket.</dd>' .
147
				'<dt>COMMAND</dt>		<dd>The command which holds the socket.</dd>' .
148
				'<dt>PID</dt>			<dd>The process ID of the command which holds the socket.</dd>' .
149
				'<dt>FD</dt>				<dd>The file descriptor number of the socket.</dd>' .
150
				'<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>' .
151
				'<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>' .
152
				'<dt>LOCAL ADDRESS</dt> <dd>(Internet sockets only) The address the local end of the socket is bound to (see getsockname(2)).</dd>' .
153
				'<dt>FOREIGN ADDRESS</dt><dd>(Internet sockets only) The address the foreign end of the socket is bound to (see getpeername(2)).</dd>' .
154
			'</dl>'), 'info', false);
155
?>
156
</div>
157
</div>
158
<?php
159

    
160
include('foot.inc');
161

    
162

    
(28-28/225)