Project

General

Profile

Download (4.16 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-2018 Rubicon Communications, LLC (Netgate)
7
 * All rights reserved.
8
 *
9
 * Licensed under the Apache License, Version 2.0 (the "License");
10
 * you may not use this file except in compliance with the License.
11
 * You may obtain a copy of the License at
12
 *
13
 * http://www.apache.org/licenses/LICENSE-2.0
14
 *
15
 * Unless required by applicable law or agreed to in writing, software
16
 * distributed under the License is distributed on an "AS IS" BASIS,
17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
 * See the License for the specific language governing permissions and
19
 * limitations under the License.
20
 */
21

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

    
29
require_once('guiconfig.inc');
30

    
31
$pgtitle = array(gettext("Diagnostics"), gettext("Sockets"));
32

    
33
include('head.inc');
34

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

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

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

    
56

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

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

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

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

    
104
<div>
105
<div class="infoblock">
106
<?php
107
print_info_box(
108
	gettext('Socket Information') .
109
		'<br /><br />' .
110
		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>') .
111
		'<br /><br />' .
112
		gettext('The information listed for each socket is:') .
113
		'<br /><br />' .
114
		'<dl class="dl-horizontal responsive">' .
115
		sprintf(gettext('%1$sUSER%2$s	%3$sThe user who owns the socket.%4$s'), '<dt>', '</dt>', '<dd>', '</dd>') .
116
		sprintf(gettext('%1$sCOMMAND%2$s	%3$sThe command which holds the socket.%4$s'), '<dt>', '</dt>', '<dd>', '</dd>') .
117
		sprintf(gettext('%1$sPID%2$s	%3$sThe process ID of the command which holds the socket.%4$s'), '<dt>', '</dt>', '<dd>', '</dd>') .
118
		sprintf(gettext('%1$sFD%2$s	%3$sThe file descriptor number of the socket.%4$s'), '<dt>', '</dt>', '<dd>', '</dd>') .
119
		sprintf(gettext('%1$sPROTO%2$s	%3$sThe transport protocol associated with the socket.%4$s'), '<dt>', '</dt>', '<dd>', '</dd>') .
120
		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>') .
121
		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>') .
122
		'</dl>',
123
	'info',
124
	false);
125
?>
126
</div>
127
</div>
128
<?php
129

    
130
include('foot.inc');
(29-29/234)