Project

General

Profile

Download (6.13 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 page
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
?>
73

    
74
<?php include("fbegin.inc");
75

    
76
$showAll = isset($_GET['showAll']);
77
$showAllText = $showAll ? "Show only listening sockets" : "Show all socket connections";
78
$showAllOption = $showAll ? "" : "?showAll";
79

    
80
?>
81

    
82
<div class="panel panel-default">
83
	<div class="panel-heading"><h2 class="panel-title">System socket information for both IPv4 and IPv6</h2></div>
84
	<div class="panel-body">
85

    
86
(Click <a href="#about">here </a>for explanation of the information listed for each socket) <br /><br />
87
<input class="btn btn-info btn-xs" type="button" value="<?=$showAllText?>" onclick="window.location.href='diag_sockets.php<?=$showAllOption?>'"/>
88

    
89

    
90
<?php
91
	if (isset($_GET['showAll'])) {
92
		$internet4 = shell_exec('sockstat -4');
93
		$internet6 = shell_exec('sockstat -6');
94
	} else {
95
		$internet4 = shell_exec('sockstat -4l');
96
		$internet6 = shell_exec('sockstat -6l');
97
	}
98
	foreach (array(&$internet4, &$internet6) as $tabindex => $table) {
99
		$elements = ($tabindex == 0 ? 7 : 7);
100
		$name = ($tabindex == 0 ? 'IPv4' : 'IPv6');
101
?>
102
		<div class="table table-responsive">
103
			<table class="table table-hover table-striped table-condensed">
104
				<thead>
105
					<tr>
106
						<th>
107
							<?=$name?>
108
						</th>
109
					</tr>
110
				</thead>
111
				<tbody>
112

    
113
<?php
114
					foreach (explode("\n", $table) as $i => $line) {
115
						if ($i == 0)
116
							$class = 'info';
117
						else
118
							$class = '';
119

    
120
						if (trim($line) == "")
121
							continue;
122

    
123
						print("<tr>\n");
124
						$j = 0;
125
						foreach (explode(' ', $line) as $entry) {
126
							if ($entry == '' || $entry == "ADDRESS") continue;
127
							if ($i == 0)
128
								print("<th class=\"$class\">$entry</th>\n");
129
							else
130
								print("<td class=\"$class\">$entry</td>\n");
131

    
132
							$j++;
133
						}
134
						print("</tr>\n");
135
					}
136
?>
137
				</tbody>
138
			</table>
139
		</div>
140
<?php
141
	}
142
?>
143
	</div>
144
	<a name="about"></a>
145
	<div class="alert alert-success" role="alert">
146
		<div class="panel panel-default">
147
		<div class="panel-heading"><h2 class="panel-title">Socket information - explanation</h2></div>
148
			<div class="panel-body">
149
	This page shows the output for the commands: "sockstat -4lL" and "sockstat -6lL".<br />
150
	Or in case of showing all sockets the output for: "sockstat -4" and "sockstat -6".<br />
151
				<br />
152
	The information listed for each socket is:
153
				<br /><br />
154
				<dl class="dl-horizontal responsive">
155
					<dt>USER</dt>			<dd>The user who owns the socket.</dd>
156
					<dt>COMMAND</dt>		<dd>The command which holds the socket.</dd>
157
					<dt>PID</dt>			<dd>The process ID of the command which holds the socket.</dd>
158
					<dt>FD</dt>				<dd>The file descriptor number of the socket.</dd>
159
					<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>
160
					<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>
161
					<dt>LOCAL ADDRESS</dt>	<dd>(Internet sockets only) The address the local end of the socket is bound to (see getsockname(2)).</dd>
162
					<dt>FOREIGN ADDRESS</dt><dd>(Internet sockets only) The address the foreign end of the socket is bound to (see getpeername(2)).</dd>
163
				</dl>
164
			</div>
165
		</div>
166
	</div>
167
</div>
168
<?php
169

    
170
include('foot.inc');
171

    
172

    
(36-36/234)