Project

General

Profile

Download (4.25 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * diag_sockets.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8
 * Copyright (c) 2014-2020 Rubicon Communications, LLC (Netgate)
9
 * All rights reserved.
10
 *
11
 * 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
 *
15
 * http://www.apache.org/licenses/LICENSE-2.0
16
 *
17
 * 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
 */
23

    
24
##|+PRIV
25
##|*IDENT=page-diagnostics-sockets
26
##|*NAME=Diagnostics: Sockets
27
##|*DESCR=Allow access to the 'Diagnostics: Sockets' page.
28
##|*MATCH=diag_sockets.php*
29
##|-PRIV
30

    
31
require_once('guiconfig.inc');
32

    
33
$pgtitle = array(gettext("Diagnostics"), gettext("Sockets"));
34

    
35
include('head.inc');
36

    
37
$showAll = isset($_REQUEST['showAll']);
38
$showAllText = $showAll ? gettext("Show only listening sockets") : gettext("Show all socket connections");
39
$showAllOption = $showAll ? "" : "?showAll";
40

    
41
?>
42
<button class="btn btn-info btn-sm" type="button" value="<?=$showAllText?>" onclick="window.location.href='diag_sockets.php<?=$showAllOption?>'">
43
	<i class="fa fa-<?= ($showAll) ? 'minus-circle' : 'plus-circle' ; ?> icon-embed-btn"></i>
44
	<?=$showAllText?>
45
</button>
46
<br />
47
<br />
48

    
49
<?php
50
	if (isset($_REQUEST['showAll'])) {
51
		$internet4 = shell_exec('sockstat -4');
52
		$internet6 = shell_exec('sockstat -6');
53
	} else {
54
		$internet4 = shell_exec('sockstat -4l');
55
		$internet6 = shell_exec('sockstat -6l');
56
	}
57

    
58

    
59
	foreach (array(&$internet4, &$internet6) as $tabindex => $table) {
60
		$elements = ($tabindex == 0 ? 7 : 7);
61
		$name = ($tabindex == 0 ? 'IPv4' : 'IPv6');
62
?>
63
<div class="panel panel-default">
64
	<div class="panel-heading"><h2 class="panel-title"><?=$name?> <?=gettext("System Socket Information")?></h2></div>
65
	<div class="panel-body">
66
		<div class="table table-responsive">
67
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
68
				<thead>
69
<?php
70
					foreach (explode("\n", $table) as $i => $line) {
71
						if (trim($line) == "") {
72
							continue;
73
						}
74

    
75
						$j = 0;
76
						print("<tr>\n");
77
						foreach (explode(' ', $line) as $entry) {
78
							if ($entry == '' || $entry == "ADDRESS") {
79
								continue;
80
							}
81

    
82
							if ($i == 0) {
83
								print("<th class=\"$class\">$entry</th>\n");
84
							} else {
85
								print("<td class=\"$class\">$entry</td>\n");
86
							}
87

    
88
							$j++;
89
						}
90
						print("</tr>\n");
91
						if ($i == 0) {
92
							print("</thead>\n");
93
							print("<tbody>\n");
94
						}
95
					}
96
?>
97
				</tbody>
98
			</table>
99
		</div>
100
	</div>
101
</div>
102
<?php
103
	}
104
?>
105

    
106
<div>
107
<div class="infoblock">
108
<?php
109
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
		'<dl class="dl-horizontal responsive">' .
117
		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
?>
128
</div>
129
</div>
130
<?php
131

    
132
include('foot.inc');
(29-29/229)