1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
<?php
/*
* diag_sockets.php
*
* part of pfSense (https://www.pfsense.org)
* Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
##|+PRIV
##|*IDENT=page-diagnostics-sockets
##|*NAME=Diagnostics: Sockets
##|*DESCR=Allow access to the 'Diagnostics: Sockets' page.
##|*MATCH=diag_sockets.php*
##|-PRIV
require_once('guiconfig.inc');
$pgtitle = array(gettext("Diagnostics"), gettext("Sockets"));
include('head.inc');
$showAll = isset($_GET['showAll']);
$showAllText = $showAll ? gettext("Show only listening sockets") : gettext("Show all socket connections");
$showAllOption = $showAll ? "" : "?showAll";
?>
<button class="btn btn-info btn-sm" type="button" value="<?=$showAllText?>" onclick="window.location.href='diag_sockets.php<?=$showAllOption?>'">
<i class="fa fa-<?= ($showAll) ? 'minus-circle' : 'plus-circle' ; ?> icon-embed-btn"></i>
<?=$showAllText?>
</button>
<br />
<br />
<?php
if (isset($_GET['showAll'])) {
$internet4 = shell_exec('sockstat -4');
$internet6 = shell_exec('sockstat -6');
} else {
$internet4 = shell_exec('sockstat -4l');
$internet6 = shell_exec('sockstat -6l');
}
foreach (array(&$internet4, &$internet6) as $tabindex => $table) {
$elements = ($tabindex == 0 ? 7 : 7);
$name = ($tabindex == 0 ? 'IPv4' : 'IPv6');
?>
<div class="panel panel-default">
<div class="panel-heading"><h2 class="panel-title"><?=$name?> <?=gettext("System Socket Information")?></h2></div>
<div class="panel-body">
<div class="table table-responsive">
<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
<thead>
<?php
foreach (explode("\n", $table) as $i => $line) {
if (trim($line) == "") {
continue;
}
$j = 0;
print("<tr>\n");
foreach (explode(' ', $line) as $entry) {
if ($entry == '' || $entry == "ADDRESS") {
continue;
}
if ($i == 0) {
print("<th class=\"$class\">$entry</th>\n");
} else {
print("<td class=\"$class\">$entry</td>\n");
}
$j++;
}
print("</tr>\n");
if ($i == 0) {
print("</thead>\n");
print("<tbody>\n");
}
}
?>
</tbody>
</table>
</div>
</div>
</div>
<?php
}
?>
<div>
<div class="infoblock">
<?php
print_info_box(gettext('Socket Information') . '<br /><br />' .
gettext('This page shows all listening sockets by default, and shows both listening and outbound connection sockets when <strong>Show all socket connections</strong> is clicked.<br /><br />' .
'The information listed for each socket is:' . '<br /><br />' .
'<dl class="dl-horizontal responsive">' .
'<dt>USER</dt> <dd>The user who owns the socket.</dd>' .
'<dt>COMMAND</dt> <dd>The command which holds the socket.</dd>' .
'<dt>PID</dt> <dd>The process ID of the command which holds the socket.</dd>' .
'<dt>FD</dt> <dd>The file descriptor number of the socket.</dd>' .
'<dt>PROTO</dt> <dd>The transport protocol associated with the socket.</dd>' .
'<dt>LOCAL ADDRESS</dt> <dd>The address the local end of the socket is bound to.</dd>' .
'<dt>FOREIGN ADDRESS</dt> <dd>The address the foreign end of the socket is bound to.</dd>' .
'</dl>'), 'info', false);
?>
</div>
</div>
<?php
include('foot.inc');
|