| 1 |
f1e01f7c
|
Erik Fonnesbeck
|
<?php
|
| 2 |
|
|
|
| 3 |
|
|
/* $Id$ */
|
| 4 |
|
|
/*
|
| 5 |
|
|
diag_sockets.php
|
| 6 |
|
|
*/
|
| 7 |
fd9ebcd5
|
Stephen Beaver
|
/* ====================================================================
|
| 8 |
|
|
* Copyright (c) 2004-2015 Electric Sheep Fencing, LLC. All rights reserved.
|
| 9 |
|
|
*
|
| 10 |
|
|
* Redistribution and use in source and binary forms, with or without modification,
|
| 11 |
|
|
* 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
|
| 18 |
|
|
* the documentation and/or other materials provided with the
|
| 19 |
|
|
* distribution.
|
| 20 |
|
|
*
|
| 21 |
|
|
* 3. All advertising materials mentioning features or use of this software
|
| 22 |
|
|
* must display the following acknowledgment:
|
| 23 |
|
|
* "This product includes software developed by the pfSense Project
|
| 24 |
|
|
* for use in the pfSense software distribution. (http://www.pfsense.org/).
|
| 25 |
|
|
*
|
| 26 |
|
|
* 4. The names "pfSense" and "pfSense Project" must not be used to
|
| 27 |
|
|
* endorse or promote products derived from this software without
|
| 28 |
|
|
* prior written permission. For written permission, please contact
|
| 29 |
|
|
* coreteam@pfsense.org.
|
| 30 |
|
|
*
|
| 31 |
|
|
* 5. Products derived from this software may not be called "pfSense"
|
| 32 |
|
|
* nor may "pfSense" appear in their names without prior written
|
| 33 |
|
|
* permission of the Electric Sheep Fencing, LLC.
|
| 34 |
|
|
*
|
| 35 |
|
|
* 6. Redistributions of any form whatsoever must retain the following
|
| 36 |
|
|
* acknowledgment:
|
| 37 |
|
|
*
|
| 38 |
|
|
* "This product includes software developed by the pfSense Project
|
| 39 |
|
|
* for use in the pfSense software distribution (http://www.pfsense.org/).
|
| 40 |
|
|
*
|
| 41 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
|
| 42 |
|
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 43 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
| 44 |
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
|
| 45 |
|
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 46 |
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
| 47 |
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 48 |
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
| 49 |
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
| 50 |
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
| 51 |
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
| 52 |
|
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 53 |
|
|
*
|
| 54 |
|
|
* ====================================================================
|
| 55 |
|
|
*
|
| 56 |
|
|
*/
|
| 57 |
f1e01f7c
|
Erik Fonnesbeck
|
|
| 58 |
|
|
/*
|
| 59 |
f1dab9ec
|
sbeaver
|
pfSense_BUILDER_BINARIES: /usr/bin/sockstat
|
| 60 |
f1e01f7c
|
Erik Fonnesbeck
|
*/
|
| 61 |
|
|
##|+PRIV
|
| 62 |
|
|
##|*IDENT=page-diagnostics-sockets
|
| 63 |
|
|
##|*NAME=Diagnostics: Sockets page
|
| 64 |
|
|
##|*DESCR=Allow access to the 'Diagnostics: Sockets' page.
|
| 65 |
|
|
##|*MATCH=diag_sockets.php*
|
| 66 |
|
|
##|-PRIV
|
| 67 |
|
|
|
| 68 |
|
|
include('guiconfig.inc');
|
| 69 |
|
|
|
| 70 |
699737d9
|
Phil Davis
|
$pgtitle = array(gettext("Diagnostics"), gettext("Sockets"));
|
| 71 |
f1e01f7c
|
Erik Fonnesbeck
|
|
| 72 |
|
|
include('head.inc');
|
| 73 |
|
|
|
| 74 |
|
|
?>
|
| 75 |
f1dab9ec
|
sbeaver
|
|
| 76 |
f1e01f7c
|
Erik Fonnesbeck
|
<?php include("fbegin.inc");
|
| 77 |
|
|
|
| 78 |
|
|
$showAll = isset($_GET['showAll']);
|
| 79 |
|
|
$showAllText = $showAll ? "Show only listening sockets" : "Show all socket connections";
|
| 80 |
|
|
$showAllOption = $showAll ? "" : "?showAll";
|
| 81 |
|
|
|
| 82 |
|
|
?>
|
| 83 |
f1dab9ec
|
sbeaver
|
|
| 84 |
|
|
<div class="panel panel-default">
|
| 85 |
f17594c7
|
Sjon Hortensius
|
<div class="panel-heading"><h2 class="panel-title">System socket information for both IPv4 and IPv6</h2></div>
|
| 86 |
f1dab9ec
|
sbeaver
|
<div class="panel-body">
|
| 87 |
|
|
|
| 88 |
|
|
(Click <a href="#about">here </a>for explanation of the information listed for each socket) <br /><br />
|
| 89 |
|
|
<input class="btn btn-info btn-xs" type="button" value="<?=$showAllText?>" onclick="window.location.href='diag_sockets.php<?=$showAllOption?>'"/>
|
| 90 |
|
|
|
| 91 |
f1e01f7c
|
Erik Fonnesbeck
|
|
| 92 |
|
|
<?php
|
| 93 |
5f601060
|
Phil Davis
|
if (isset($_GET['showAll'])) {
|
| 94 |
f1e01f7c
|
Erik Fonnesbeck
|
$internet4 = shell_exec('sockstat -4');
|
| 95 |
|
|
$internet6 = shell_exec('sockstat -6');
|
| 96 |
|
|
} else {
|
| 97 |
b965f190
|
PiBa-NL
|
$internet4 = shell_exec('sockstat -4l');
|
| 98 |
|
|
$internet6 = shell_exec('sockstat -6l');
|
| 99 |
f1e01f7c
|
Erik Fonnesbeck
|
}
|
| 100 |
|
|
foreach (array(&$internet4, &$internet6) as $tabindex => $table) {
|
| 101 |
|
|
$elements = ($tabindex == 0 ? 7 : 7);
|
| 102 |
|
|
$name = ($tabindex == 0 ? 'IPv4' : 'IPv6');
|
| 103 |
|
|
?>
|
| 104 |
a6ff5ea1
|
sbeaver
|
<div class="table table-responsive">
|
| 105 |
88627531
|
sbeaver
|
<table class="table table-hover table-striped table-condensed">
|
| 106 |
a6ff5ea1
|
sbeaver
|
<thead>
|
| 107 |
|
|
<tr>
|
| 108 |
|
|
<th>
|
| 109 |
|
|
<?=$name?>
|
| 110 |
|
|
</th>
|
| 111 |
|
|
</tr>
|
| 112 |
|
|
</thead>
|
| 113 |
|
|
<tbody>
|
| 114 |
f1dab9ec
|
sbeaver
|
|
| 115 |
f1e01f7c
|
Erik Fonnesbeck
|
<?php
|
| 116 |
a6ff5ea1
|
sbeaver
|
foreach (explode("\n", $table) as $i => $line) {
|
| 117 |
|
|
if ($i == 0)
|
| 118 |
|
|
$class = 'info';
|
| 119 |
|
|
else
|
| 120 |
|
|
$class = '';
|
| 121 |
|
|
|
| 122 |
|
|
if (trim($line) == "")
|
| 123 |
|
|
continue;
|
| 124 |
|
|
|
| 125 |
88627531
|
sbeaver
|
print("<tr>\n");
|
| 126 |
a6ff5ea1
|
sbeaver
|
$j = 0;
|
| 127 |
|
|
foreach (explode(' ', $line) as $entry) {
|
| 128 |
|
|
if ($entry == '' || $entry == "ADDRESS") continue;
|
| 129 |
|
|
if ($i == 0)
|
| 130 |
|
|
print("<th class=\"$class\">$entry</th>\n");
|
| 131 |
|
|
else
|
| 132 |
|
|
print("<td class=\"$class\">$entry</td>\n");
|
| 133 |
|
|
|
| 134 |
|
|
$j++;
|
| 135 |
|
|
}
|
| 136 |
|
|
print("</tr>\n");
|
| 137 |
|
|
}
|
| 138 |
|
|
?>
|
| 139 |
|
|
</tbody>
|
| 140 |
|
|
</table>
|
| 141 |
|
|
</div>
|
| 142 |
f1e01f7c
|
Erik Fonnesbeck
|
<?php
|
| 143 |
f1dab9ec
|
sbeaver
|
}
|
| 144 |
f1e01f7c
|
Erik Fonnesbeck
|
?>
|
| 145 |
a6ff5ea1
|
sbeaver
|
</div>
|
| 146 |
88627531
|
sbeaver
|
<a name="about"></a>
|
| 147 |
|
|
<div class="alert alert-success" role="alert">
|
| 148 |
|
|
<div class="panel panel-default">
|
| 149 |
f17594c7
|
Sjon Hortensius
|
<div class="panel-heading"><h2 class="panel-title">Socket information - explanation</h2></div>
|
| 150 |
88627531
|
sbeaver
|
<div class="panel-body">
|
| 151 |
288a2a0f
|
Phil Davis
|
This page shows the output for the commands: "sockstat -4lL" and "sockstat -6lL".<br />
|
| 152 |
88627531
|
sbeaver
|
Or in case of showing all sockets the output for: "sockstat -4" and "sockstat -6".<br />
|
| 153 |
|
|
<br />
|
| 154 |
|
|
The information listed for each socket is:
|
| 155 |
|
|
<br /><br />
|
| 156 |
|
|
<dl class="dl-horizontal responsive">
|
| 157 |
|
|
<dt>USER</dt> <dd>The user who owns the socket.</dd>
|
| 158 |
|
|
<dt>COMMAND</dt> <dd>The command which holds the socket.</dd>
|
| 159 |
|
|
<dt>PID</dt> <dd>The process ID of the command which holds the socket.</dd>
|
| 160 |
|
|
<dt>FD</dt> <dd>The file descriptor number of the socket.</dd>
|
| 161 |
|
|
<dt>PROTO</dt> <dd>The transport protocol associated with the socket for Internet sockets, or the type of socket (stream or data-gram) for UNIX sockets.</dd>
|
| 162 |
|
|
<dt>ADDRESS</dt> <dd>(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.</dd>
|
| 163 |
|
|
<dt>LOCAL ADDRESS</dt> <dd>(Internet sockets only) The address the local end of the socket is bound to (see getsockname(2)).</dd>
|
| 164 |
|
|
<dt>FOREIGN ADDRESS</dt><dd>(Internet sockets only) The address the foreign end of the socket is bound to (see getpeername(2)).</dd>
|
| 165 |
|
|
</dl>
|
| 166 |
|
|
</div>
|
| 167 |
f1dab9ec
|
sbeaver
|
</div>
|
| 168 |
|
|
</div>
|
| 169 |
f1e01f7c
|
Erik Fonnesbeck
|
</div>
|
| 170 |
|
|
<?php
|
| 171 |
f1dab9ec
|
sbeaver
|
|
| 172 |
|
|
include('foot.inc');
|
| 173 |
|
|
|