Project

General

Profile

Download (4.31 KB) Statistics
| Branch: | Tag: | Revision:
1 f1e01f7c Erik Fonnesbeck
<?php
2
/*
3 c5d81585 Renato Botelho
 * diag_sockets.php
4 fd9ebcd5 Stephen Beaver
 *
5 c5d81585 Renato Botelho
 * part of pfSense (https://www.pfsense.org)
6 38809d47 Renato Botelho do Couto
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8 a68f7a3d Luiz Otavio O Souza
 * Copyright (c) 2014-2024 Rubicon Communications, LLC (Netgate)
9 c5d81585 Renato Botelho
 * All rights reserved.
10 fd9ebcd5 Stephen Beaver
 *
11 b12ea3fb Renato Botelho
 * Licensed under the Apache License, Version 2.0 (the "License");
12
 * you may not use this file except in compliance with the License.
13
 * You may obtain a copy of the License at
14 fd9ebcd5 Stephen Beaver
 *
15 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
16 fd9ebcd5 Stephen Beaver
 *
17 b12ea3fb Renato Botelho
 * Unless required by applicable law or agreed to in writing, software
18
 * distributed under the License is distributed on an "AS IS" BASIS,
19
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
 * See the License for the specific language governing permissions and
21
 * limitations under the License.
22 fd9ebcd5 Stephen Beaver
 */
23 f1e01f7c Erik Fonnesbeck
24
##|+PRIV
25
##|*IDENT=page-diagnostics-sockets
26 5230f468 jim-p
##|*NAME=Diagnostics: Sockets
27 f1e01f7c Erik Fonnesbeck
##|*DESCR=Allow access to the 'Diagnostics: Sockets' page.
28
##|*MATCH=diag_sockets.php*
29
##|-PRIV
30
31 86573bb9 Phil Davis
require_once('guiconfig.inc');
32 f1e01f7c Erik Fonnesbeck
33 699737d9 Phil Davis
$pgtitle = array(gettext("Diagnostics"), gettext("Sockets"));
34 f1e01f7c Erik Fonnesbeck
35
include('head.inc');
36
37 7f4268b6 Steve Beaver
$showAll = isset($_REQUEST['showAll']);
38 185b4365 Phil Davis
$showAllText = $showAll ? gettext("Show only listening sockets") : gettext("Show all socket connections");
39 f1e01f7c Erik Fonnesbeck
$showAllOption = $showAll ? "" : "?showAll";
40
41
?>
42 37676f4e jim-p
<button class="btn btn-info btn-sm" type="button" value="<?=$showAllText?>" onclick="window.location.href='diag_sockets.php<?=$showAllOption?>'">
43 d365c2c7 Marcos Mendoza
	<i class="<?= ($showAll) ? 'fa-solid fa-minus-circle' : 'fa-solid fa-plus-circle' ; ?> icon-embed-btn"></i>
44 37676f4e jim-p
	<?=$showAllText?>
45
</button>
46 b9a5448f Stephen Beaver
<br />
47
<br />
48 f1e01f7c Erik Fonnesbeck
49
<?php
50 cbb82e6b Steve Beaver
	if (isset($_REQUEST['showAll'])) {
51 8cd6e269 Viktor G
		$internet4 = shell_exec('/usr/bin/sockstat -4');
52
		$internet6 = shell_exec('/usr/bin/sockstat -6');
53 f1e01f7c Erik Fonnesbeck
	} else {
54 8cd6e269 Viktor G
		$internet4 = shell_exec('/usr/bin/sockstat -4l');
55
		$internet6 = shell_exec('/usr/bin/sockstat -6l');
56 f1e01f7c Erik Fonnesbeck
	}
57 b9a5448f Stephen Beaver
58
59 f1e01f7c Erik Fonnesbeck
	foreach (array(&$internet4, &$internet6) as $tabindex => $table) {
60
		$elements = ($tabindex == 0 ? 7 : 7);
61
		$name = ($tabindex == 0 ? 'IPv4' : 'IPv6');
62
?>
63 b9a5448f Stephen Beaver
<div class="panel panel-default">
64 3d7a8696 k-paulius
	<div class="panel-heading"><h2 class="panel-title"><?=$name?> <?=gettext("System Socket Information")?></h2></div>
65 b9a5448f Stephen Beaver
	<div class="panel-body">
66 a6ff5ea1 sbeaver
		<div class="table table-responsive">
67 10fe1eb5 Stephen Beaver
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
68 a6ff5ea1 sbeaver
				<thead>
69 f1e01f7c Erik Fonnesbeck
<?php
70 a6ff5ea1 sbeaver
					foreach (explode("\n", $table) as $i => $line) {
71 947141fd Phil Davis
						if (trim($line) == "") {
72 a6ff5ea1 sbeaver
							continue;
73 947141fd Phil Davis
						}
74 a6ff5ea1 sbeaver
75
						$j = 0;
76 63ff711e Colin Fleming
						print("<tr>\n");
77 a6ff5ea1 sbeaver
						foreach (explode(' ', $line) as $entry) {
78 947141fd Phil Davis
							if ($entry == '' || $entry == "ADDRESS") {
79 b9a5448f Stephen Beaver
								continue;
80 947141fd Phil Davis
							}
81 b9a5448f Stephen Beaver
82
							if ($i == 0) {
83 a6ff5ea1 sbeaver
								print("<th class=\"$class\">$entry</th>\n");
84 947141fd Phil Davis
							} else {
85 a6ff5ea1 sbeaver
								print("<td class=\"$class\">$entry</td>\n");
86 b9a5448f Stephen Beaver
							}
87 a6ff5ea1 sbeaver
88
							$j++;
89
						}
90
						print("</tr>\n");
91 947141fd Phil Davis
						if ($i == 0) {
92 b9a5448f Stephen Beaver
							print("</thead>\n");
93
							print("<tbody>\n");
94
						}
95 a6ff5ea1 sbeaver
					}
96
?>
97
				</tbody>
98
			</table>
99
		</div>
100 b9a5448f Stephen Beaver
	</div>
101
</div>
102 f1e01f7c Erik Fonnesbeck
<?php
103 f1dab9ec sbeaver
	}
104 f1e01f7c Erik Fonnesbeck
?>
105 b9a5448f Stephen Beaver
106
<div>
107 35681930 Stephen Beaver
<div class="infoblock">
108 b9a5448f Stephen Beaver
<?php
109 5db70796 Phil Davis
print_info_box(
110
	gettext('Socket Information') .
111
		'<br /><br />' .
112
		sprintf(gettext('This page shows all listening sockets by default, and shows both listening and outbound connection sockets when %1$sShow all socket connections%2$s is clicked.'), '<strong>', '</strong>') .
113
		'<br /><br />' .
114
		gettext('The information listed for each socket is:') .
115
		'<br /><br />' .
116 1121b4a7 jim-p
		'<dl class="dl-horizontal responsive">' .
117 5db70796 Phil Davis
		sprintf(gettext('%1$sUSER%2$s	%3$sThe user who owns the socket.%4$s'), '<dt>', '</dt>', '<dd>', '</dd>') .
118
		sprintf(gettext('%1$sCOMMAND%2$s	%3$sThe command which holds the socket.%4$s'), '<dt>', '</dt>', '<dd>', '</dd>') .
119
		sprintf(gettext('%1$sPID%2$s	%3$sThe process ID of the command which holds the socket.%4$s'), '<dt>', '</dt>', '<dd>', '</dd>') .
120
		sprintf(gettext('%1$sFD%2$s	%3$sThe file descriptor number of the socket.%4$s'), '<dt>', '</dt>', '<dd>', '</dd>') .
121
		sprintf(gettext('%1$sPROTO%2$s	%3$sThe transport protocol associated with the socket.%4$s'), '<dt>', '</dt>', '<dd>', '</dd>') .
122
		sprintf(gettext('%1$sLOCAL ADDRESS%2$s	%3$sThe address the local end of the socket is bound to.%4$s'), '<dt>', '</dt>', '<dd>', '</dd>') .
123
		sprintf(gettext('%1$sFOREIGN ADDRESS%2$s	%3$sThe address the foreign end of the socket is bound to.%4$s'), '<dt>', '</dt>', '<dd>', '</dd>') .
124
		'</dl>',
125
	'info',
126
	false);
127 b9a5448f Stephen Beaver
?>
128
</div>
129 f1e01f7c Erik Fonnesbeck
</div>
130
<?php
131 f1dab9ec sbeaver
132
include('foot.inc');