Project

General

Profile

Download (5.45 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-2016 Rubicon Communications, LLC (Netgate)
7
 * All rights reserved.
8
 *
9
 * Redistribution and use in source and binary forms, with or without
10
 * modification, are permitted provided that the following conditions are met:
11
 *
12
 * 1. Redistributions of source code must retain the above copyright notice,
13
 *    this list of conditions and the following disclaimer.
14
 *
15
 * 2. Redistributions in binary form must reproduce the above copyright
16
 *    notice, this list of conditions and the following disclaimer in
17
 *    the documentation and/or other materials provided with the
18
 *    distribution.
19
 *
20
 * 3. All advertising materials mentioning features or use of this software
21
 *    must display the following acknowledgment:
22
 *    "This product includes software developed by the pfSense Project
23
 *    for use in the pfSense® software distribution. (http://www.pfsense.org/).
24
 *
25
 * 4. The names "pfSense" and "pfSense Project" must not be used to
26
 *    endorse or promote products derived from this software without
27
 *    prior written permission. For written permission, please contact
28
 *    coreteam@pfsense.org.
29
 *
30
 * 5. Products derived from this software may not be called "pfSense"
31
 *    nor may "pfSense" appear in their names without prior written
32
 *    permission of the Electric Sheep Fencing, LLC.
33
 *
34
 * 6. Redistributions of any form whatsoever must retain the following
35
 *    acknowledgment:
36
 *
37
 * "This product includes software developed by the pfSense Project
38
 * for use in the pfSense software distribution (http://www.pfsense.org/).
39
 *
40
 * THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
41
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
44
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51
 * OF THE POSSIBILITY OF SUCH DAMAGE.
52
 */
53

    
54
##|+PRIV
55
##|*IDENT=page-diagnostics-sockets
56
##|*NAME=Diagnostics: Sockets
57
##|*DESCR=Allow access to the 'Diagnostics: Sockets' page.
58
##|*MATCH=diag_sockets.php*
59
##|-PRIV
60

    
61
require_once('guiconfig.inc');
62

    
63
$pgtitle = array(gettext("Diagnostics"), gettext("Sockets"));
64

    
65
include('head.inc');
66

    
67
$showAll = isset($_GET['showAll']);
68
$showAllText = $showAll ? gettext("Show only listening sockets") : gettext("Show all socket connections");
69
$showAllOption = $showAll ? "" : "?showAll";
70

    
71
?>
72
<button class="btn btn-info btn-sm" type="button" value="<?=$showAllText?>" onclick="window.location.href='diag_sockets.php<?=$showAllOption?>'">
73
	<i class="fa fa-<?= ($showAll) ? 'minus-circle' : 'plus-circle' ; ?> icon-embed-btn"></i>
74
	<?=$showAllText?>
75
</button>
76
<br />
77
<br />
78

    
79
<?php
80
	if (isset($_GET['showAll'])) {
81
		$internet4 = shell_exec('sockstat -4');
82
		$internet6 = shell_exec('sockstat -6');
83
	} else {
84
		$internet4 = shell_exec('sockstat -4l');
85
		$internet6 = shell_exec('sockstat -6l');
86
	}
87

    
88

    
89
	foreach (array(&$internet4, &$internet6) as $tabindex => $table) {
90
		$elements = ($tabindex == 0 ? 7 : 7);
91
		$name = ($tabindex == 0 ? 'IPv4' : 'IPv6');
92
?>
93
<div class="panel panel-default">
94
	<div class="panel-heading"><h2 class="panel-title"><?=$name?> <?=gettext("System Socket Information")?></h2></div>
95
	<div class="panel-body">
96
		<div class="table table-responsive">
97
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
98
				<thead>
99
<?php
100
					foreach (explode("\n", $table) as $i => $line) {
101
						if (trim($line) == "") {
102
							continue;
103
						}
104

    
105
						$j = 0;
106
						print("<tr>\n");
107
						foreach (explode(' ', $line) as $entry) {
108
							if ($entry == '' || $entry == "ADDRESS") {
109
								continue;
110
							}
111

    
112
							if ($i == 0) {
113
								print("<th class=\"$class\">$entry</th>\n");
114
							} else {
115
								print("<td class=\"$class\">$entry</td>\n");
116
							}
117

    
118
							$j++;
119
						}
120
						print("</tr>\n");
121
						if ($i == 0) {
122
							print("</thead>\n");
123
							print("<tbody>\n");
124
						}
125
					}
126
?>
127
				</tbody>
128
			</table>
129
		</div>
130
	</div>
131
</div>
132
<?php
133
	}
134
?>
135

    
136
<div>
137
<div class="infoblock">
138
<?php
139
print_info_box(gettext('Socket Information') . '<br /><br />' .
140
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 />' .
141
		'The information listed for each socket is:' . '<br /><br />' .
142
		'<dl class="dl-horizontal responsive">' .
143
			'<dt>USER</dt>			<dd>The user who owns the socket.</dd>' .
144
			'<dt>COMMAND</dt>		<dd>The command which holds the socket.</dd>' .
145
			'<dt>PID</dt>			<dd>The process ID of the command which holds the socket.</dd>' .
146
			'<dt>FD</dt>			<dd>The file descriptor number of the socket.</dd>' .
147
			'<dt>PROTO</dt>			<dd>The transport protocol associated with the socket.</dd>' .
148
			'<dt>LOCAL ADDRESS</dt>		<dd>The address the local end of the socket is bound to.</dd>' .
149
			'<dt>FOREIGN ADDRESS</dt>	<dd>The address the foreign end of the socket is bound to.</dd>' .
150
		'</dl>'), 'info', false);
151
?>
152
</div>
153
</div>
154
<?php
155

    
156
include('foot.inc');
157

    
158

    
(27-27/227)