Project

General

Profile

Download (5.02 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2

    
3
/* $Id$ */
4
/*
5
	diag_sockets.php
6
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
7
	Copyright (C) 2012
8
	All rights reserved.
9

    
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12

    
13
	1. Redistributions of source code must retain the above copyright notice,
14
	this list of conditions and the following disclaimer.
15

    
16
	2. Redistributions in binary form must reproduce the above copyright
17
	notice, this list of conditions and the following disclaimer in the
18
	documentation and/or other materials provided with the distribution.
19

    
20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30

    
31
*/
32

    
33
/*
34
	pfSense_BUILDER_BINARIES:	/usr/bin/sockstat
35
*/
36
##|+PRIV
37
##|*IDENT=page-diagnostics-sockets
38
##|*NAME=Diagnostics: Sockets page
39
##|*DESCR=Allow access to the 'Diagnostics: Sockets' page.
40
##|*MATCH=diag_sockets.php*
41
##|-PRIV
42

    
43
include('guiconfig.inc');
44

    
45
$pgtitle = array(gettext("Diagnostics"),gettext("Sockets"));
46

    
47
include('head.inc');
48

    
49
?>
50

    
51
<?php include("fbegin.inc");
52

    
53
$showAll = isset($_GET['showAll']);
54
$showAllText = $showAll ? "Show only listening sockets" : "Show all socket connections";
55
$showAllOption = $showAll ? "" : "?showAll";
56

    
57
?>
58

    
59
<div class="panel panel-default">
60
	<div class="panel-heading">System socket information for both IPv4 and IPv6</div>
61
	<div class="panel-body">
62

    
63
(Click <a href="#about">here </a>for explanation of the information listed for each socket) <br /><br />
64
<input class="btn btn-info btn-xs" type="button" value="<?=$showAllText?>" onclick="window.location.href='diag_sockets.php<?=$showAllOption?>'"/>
65

    
66

    
67
<?php
68
	if (isset($_GET['showAll']))
69
	{
70
		$internet4 = shell_exec('sockstat -4');
71
		$internet6 = shell_exec('sockstat -6');
72
	} else {
73
		$internet4 = shell_exec('sockstat -4lL');
74
		$internet6 = shell_exec('sockstat -6lL');
75
	}
76
	foreach (array(&$internet4, &$internet6) as $tabindex => $table) {
77
		$elements = ($tabindex == 0 ? 7 : 7);
78
		$name = ($tabindex == 0 ? 'IPv4' : 'IPv6');
79
?>
80
<a name="<?=$name?>"></a>
81
<div class="table table-responsive">
82
<br />
83
<table class="table table-hover table-striped table-condensed summary="results">
84
	<thead>
85
		<tr>
86
			<th>
87
				<?=$name?>
88
			</th>
89
		</tr>
90
	</thead>
91
	<tbody>
92

    
93
<?php
94
		foreach (explode("\n", $table) as $i => $line) {
95
			if ($i == 0)
96
				$class = 'info';
97
			else
98
				$class = '';
99

    
100
			if (trim($line) == "")
101
				continue;
102

    
103
			print("<tr id=\"$name$i\">\n");
104
			$j = 0;
105
			foreach (explode(' ', $line) as $entry) {
106
				if ($entry == '' || $entry == "ADDRESS") continue;
107
				if ($i == 0)
108
					print("<th class=\"$class\">$entry</th>\n");
109
				else
110
					print("<td class=\"$class\">$entry</td>\n");
111
				if ($i > 0)
112
					$class = 'listr';
113
				$j++;
114
			}
115
			print("</tr>\n");
116
		}?>
117
	</tbody>
118
</table>
119

    
120
<?php
121
	}
122
?>
123
</div>
124
</div>
125

    
126
<a name="about"></a>
127
<div class="alert alert-success" role="alert">
128
	<div class="panel panel-default">
129
	<div class="panel-heading">Socket information - explanation</div>
130
		<div class="panel-body">
131

    
132
This page show the output for the commands: "sockstat -4lL" and "sockstat -6lL".<br />
133
Or in case of showing all sockets the output for: "sockstat -4" and "sockstat -6".<br />
134
			<br />
135
The information listed for each socket is:
136
			<br /><br />
137
			<table>
138
				<tr><td class="col-sm-3">USER			  </td><td>The user who owns the socket.</td></tr>
139
				<tr><td class="col-sm-3">COMMAND		  </td><td>The command which holds the socket.</td></tr>
140
				<tr><td class="col-sm-3">PID			  </td><td>The process ID of the command which holds the socket.</td></tr>
141
				<tr><td class="col-sm-3">FD				  </td><td>The file descriptor number of the socket.</td></tr>
142
				<tr><td class="col-sm-3">PROTO			  </td><td>The transport protocol associated with the socket for Internet sockets, or the type of socket (stream or data-gram) for UNIX sockets.</td></tr>
143
				<tr><td class="col-sm-3">ADDRESS		  </td><td>(UNIX sockets only) For bound sockets, this is the file-name of the socket.	For other sockets, it is the name, PID and file descriptor number of the peer, or ``(none)'' if the socket is neither bound nor connected.</td></tr>
144
				<tr><td class="col-sm-3">LOCAL ADDRESS	  </td><td>(Internet sockets only) The address the local end of the socket is bound to (see getsockname(2)).</td></tr>
145
				<tr><td class="col-sm-3">FOREIGN ADDRESS  </td><td>(Internet sockets only) The address the foreign end of the socket is bound to (see getpeername(2)).</td></tr>
146
			</table>
147
		</div>
148
	</div>
149
</div>
150
<?php
151

    
152
include('foot.inc');
153

    
154

    
(47-47/252)