1
|
<?php
|
2
|
|
3
|
/* $Id$ */
|
4
|
/*
|
5
|
diag_sockets.php
|
6
|
Copyright (C) 2013-2015 Electric Sheep Fencing, LP
|
7
|
Copyright (C) 2012
|
8
|
All rights reserved.
|
9
|
|
10
|
Redistribution and use in source and binary forms, with or without
|
11
|
modification, are permitted provided that the following conditions are met:
|
12
|
|
13
|
1. Redistributions of source code must retain the above copyright notice,
|
14
|
this list of conditions and the following disclaimer.
|
15
|
|
16
|
2. Redistributions in binary form must reproduce the above copyright
|
17
|
notice, this list of conditions and the following disclaimer in the
|
18
|
documentation and/or other materials provided with the distribution.
|
19
|
|
20
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
21
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
22
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
23
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
24
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
25
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
26
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
27
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
28
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
29
|
POSSIBILITY OF SUCH DAMAGE.
|
30
|
|
31
|
*/
|
32
|
|
33
|
/*
|
34
|
pfSense_BUILDER_BINARIES: /usr/bin/sockstat
|
35
|
*/
|
36
|
##|+PRIV
|
37
|
##|*IDENT=page-diagnostics-sockets
|
38
|
##|*NAME=Diagnostics: Sockets page
|
39
|
##|*DESCR=Allow access to the 'Diagnostics: Sockets' page.
|
40
|
##|*MATCH=diag_sockets.php*
|
41
|
##|-PRIV
|
42
|
|
43
|
include('guiconfig.inc');
|
44
|
|
45
|
$pgtitle = array(gettext("Diagnostics"),gettext("Sockets"));
|
46
|
|
47
|
include('head.inc');
|
48
|
|
49
|
?>
|
50
|
|
51
|
<?php include("fbegin.inc");
|
52
|
|
53
|
$showAll = isset($_GET['showAll']);
|
54
|
$showAllText = $showAll ? "Show only listening sockets" : "Show all socket connections";
|
55
|
$showAllOption = $showAll ? "" : "?showAll";
|
56
|
|
57
|
?>
|
58
|
|
59
|
<div class="panel panel-default">
|
60
|
<div class="panel-heading">System socket information for both IPv4 and IPv6</div>
|
61
|
<div class="panel-body">
|
62
|
|
63
|
(Click <a href="#about">here </a>for explanation of the information listed for each socket) <br /><br />
|
64
|
<input class="btn btn-info btn-xs" type="button" value="<?=$showAllText?>" onclick="window.location.href='diag_sockets.php<?=$showAllOption?>'"/>
|
65
|
|
66
|
|
67
|
<?php
|
68
|
if (isset($_GET['showAll']))
|
69
|
{
|
70
|
$internet4 = shell_exec('sockstat -4');
|
71
|
$internet6 = shell_exec('sockstat -6');
|
72
|
} else {
|
73
|
$internet4 = shell_exec('sockstat -4lL');
|
74
|
$internet6 = shell_exec('sockstat -6lL');
|
75
|
}
|
76
|
foreach (array(&$internet4, &$internet6) as $tabindex => $table) {
|
77
|
$elements = ($tabindex == 0 ? 7 : 7);
|
78
|
$name = ($tabindex == 0 ? 'IPv4' : 'IPv6');
|
79
|
?>
|
80
|
<div class="table table-responsive">
|
81
|
<table class="table table-hover table-striped table-condensed">
|
82
|
<thead>
|
83
|
<tr>
|
84
|
<th>
|
85
|
<?=$name?>
|
86
|
</th>
|
87
|
</tr>
|
88
|
</thead>
|
89
|
<tbody>
|
90
|
|
91
|
<?php
|
92
|
foreach (explode("\n", $table) as $i => $line) {
|
93
|
if ($i == 0)
|
94
|
$class = 'info';
|
95
|
else
|
96
|
$class = '';
|
97
|
|
98
|
if (trim($line) == "")
|
99
|
continue;
|
100
|
|
101
|
print("<tr>\n");
|
102
|
$j = 0;
|
103
|
foreach (explode(' ', $line) as $entry) {
|
104
|
if ($entry == '' || $entry == "ADDRESS") continue;
|
105
|
if ($i == 0)
|
106
|
print("<th class=\"$class\">$entry</th>\n");
|
107
|
else
|
108
|
print("<td class=\"$class\">$entry</td>\n");
|
109
|
|
110
|
$j++;
|
111
|
}
|
112
|
print("</tr>\n");
|
113
|
}
|
114
|
?>
|
115
|
</tbody>
|
116
|
</table>
|
117
|
</div>
|
118
|
<?php
|
119
|
}
|
120
|
?>
|
121
|
</div>
|
122
|
<a name="about"></a>
|
123
|
<div class="alert alert-success" role="alert">
|
124
|
<div class="panel panel-default">
|
125
|
<div class="panel-heading">Socket information - explanation</div>
|
126
|
<div class="panel-body">
|
127
|
This page show the output for the commands: "sockstat -4lL" and "sockstat -6lL".<br />
|
128
|
Or in case of showing all sockets the output for: "sockstat -4" and "sockstat -6".<br />
|
129
|
<br />
|
130
|
The information listed for each socket is:
|
131
|
<br /><br />
|
132
|
<dl class="dl-horizontal responsive">
|
133
|
<dt>USER</dt> <dd>The user who owns the socket.</dd>
|
134
|
<dt>COMMAND</dt> <dd>The command which holds the socket.</dd>
|
135
|
<dt>PID</dt> <dd>The process ID of the command which holds the socket.</dd>
|
136
|
<dt>FD</dt> <dd>The file descriptor number of the socket.</dd>
|
137
|
<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>
|
138
|
<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>
|
139
|
<dt>LOCAL ADDRESS</dt> <dd>(Internet sockets only) The address the local end of the socket is bound to (see getsockname(2)).</dd>
|
140
|
<dt>FOREIGN ADDRESS</dt><dd>(Internet sockets only) The address the foreign end of the socket is bound to (see getpeername(2)).</dd>
|
141
|
</dl>
|
142
|
</div>
|
143
|
</div>
|
144
|
</div>
|
145
|
</div>
|
146
|
<?php
|
147
|
|
148
|
include('foot.inc');
|
149
|
|
150
|
|