summaryrefslogtreecommitdiffstats
path: root/usr/local/www/diag_dump_states.php
diff options
context:
space:
mode:
authorjim-p <jimp@pfsense.org>2013-04-02 14:08:46 -0400
committerjim-p <jimp@pfsense.org>2013-04-02 14:08:46 -0400
commit032d79999ed293ad4e4bc9604bbe5c56a947d709 (patch)
tree433fdcce83fb72f5de24066110f1288c9b9c9159 /usr/local/www/diag_dump_states.php
parent068e6891e2c2c03a427e477d03d309e1f9d47255 (diff)
downloadpfsense-032d79999ed293ad4e4bc9604bbe5c56a947d709.zip
pfsense-032d79999ed293ad4e4bc9604bbe5c56a947d709.tar.gz
Switch states view to use popen to speed it up and use less memory (should be able to view much larger state tables in the GUI without running out of RAM)
Diffstat (limited to 'usr/local/www/diag_dump_states.php')
-rwxr-xr-xusr/local/www/diag_dump_states.php106
1 files changed, 54 insertions, 52 deletions
diff --git a/usr/local/www/diag_dump_states.php b/usr/local/www/diag_dump_states.php
index ef00595..ce48762 100755
--- a/usr/local/www/diag_dump_states.php
+++ b/usr/local/www/diag_dump_states.php
@@ -28,7 +28,7 @@
*/
/*
- pfSense_BUILDER_BINARIES: /sbin/pfctl
+ pfSense_BUILDER_BINARIES: /sbin/pfctl
pfSense_MODULE: filter
*/
@@ -56,22 +56,14 @@ if($_GET['action']) {
if ($_GET['filter'] && ($_GET['killfilter'] == "Kill")) {
if (is_ipaddr($_GET['filter'])) {
- $tokill = $_GET['filter'] . "/32";
+ $tokill = escapeshellarg($_GET['filter'] . "/32");
} elseif (is_subnet($_GET['filter'])) {
- $tokill = $_GET['filter'];
+ $tokill = escapeshellarg($_GET['filter']);
}
$retval = mwexec("/sbin/pfctl -k {$tokill} -k 0/0");
$retval = mwexec("/sbin/pfctl -k 0.0.0.0/0 -k {$tokill}");
}
-/* get our states */
-if($_GET['filter']) {
- exec("/sbin/pfctl -s state | grep " . escapeshellarg(htmlspecialchars($_GET['filter'])), $states);
-}
-else {
- exec("/sbin/pfctl -s state", $states);
-}
-
$pgtitle = array(gettext("Diagnostics"),gettext("Show States"));
include("head.inc");
@@ -141,10 +133,7 @@ include("head.inc");
<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
- <?=gettext("Current state count");?>: <?= $current_statecount ?>
- <?php if (!empty($_GET['filter'])): ?>
- (<?=gettext("Matching filter")?>: <?= count($states) ?>)
- <?php endif; ?>
+ <?=gettext("Current total state count");?>: <?= $current_statecount ?>
</td>
<td style="font-weight:bold;" align="right">
<?=gettext("Filter expression:");?>
@@ -173,50 +162,63 @@ include("head.inc");
<tbody>
<?php
$row = 0;
-if(count($states) > 0) {
- foreach($states as $line) {
- if($row >= 1000)
- break;
-
- $line_split = preg_split("/\s+/", $line);
- $type = array_shift($line_split);
- $proto = array_shift($line_split);
- $state = array_pop($line_split);
- $info = implode(" ", $line_split);
-
- /* break up info and extract $srcip and $dstip */
- $ends = preg_split("/\<?-\>?/", $info);
- $parts = explode(":", $ends[0]);
- $srcip = trim($parts[0]);
- $parts = explode(":", $ends[count($ends) - 1]);
- $dstip = trim($parts[0]);
-
- echo "<tr valign='top' name='r:{$srcip}:{$dstip}'>
- <td class='listlr'>{$proto}</td>
- <td class='listr'>{$info}</td>
- <td class='listr'>{$state}</td>
- <td class='list'>
- <img src='/themes/{$g['theme']}/images/icons/icon_x.gif' height='17' width='17' border='0'
- onclick=\"removeState('{$srcip}', '{$dstip}');\" style='cursor:pointer;'
- name='i:{$srcip}:{$dstip}'
- title='" . gettext("Remove all state entries from") . " {$srcip} " . gettext("to") . " {$dstip}' alt='' />
- </td>
- </tr>";
- $row++;
- }
-}
-else {
- echo "<tr>
- <td class='list' colspan='4' align='center' valign='top'>
- " . gettext("No states were found.") . "
+/* get our states */
+$grepline = ($_GET['filter']) ? "| grep " . escapeshellarg(htmlspecialchars($_GET['filter'])) : "";
+$fd = popen("/sbin/pfctl -s state {$grepline}", "r" );
+while ($line = chop(fgets($fd))) {
+ if($row >= 10000)
+ break;
+
+ $line_split = preg_split("/\s+/", $line);
+ $type = array_shift($line_split);
+ $proto = array_shift($line_split);
+ $state = array_pop($line_split);
+ $info = implode(" ", $line_split);
+
+ /* break up info and extract $srcip and $dstip */
+ $ends = preg_split("/\<?-\>?/", $info);
+ $parts = explode(":", $ends[0]);
+ $srcip = trim($parts[0]);
+ $parts = explode(":", $ends[count($ends) - 1]);
+ $dstip = trim($parts[0]);
+
+?>
+ <tr valign="top" name="r:<?= $srcip ?>:<?= $dstip ?>">
+ <td class="listlr"><?= $proto ?></td>
+ <td class="listr"><?= $info ?></td>
+ <td class="listr"><?= $state ?></td>
+ <td class="list">
+ <img src="/themes/<?= $g['theme'] ?>/images/icons/icon_x.gif" height="17" width="17" border="0"
+ onclick="removeState('<?= $srcip ?>', '<?= $dstip ?>');" style="cursor:pointer;"
+ name="i:<?= $srcip ?>:<?= $dstip ?>"
+ title="<?= gettext('Remove all state entries from') ?> <?= $srcip ?> <?= gettext('to') ?> <?= $dstip ?>" alt="" />
</td>
- </tr>";
+ </tr>
+<?php
+ $row++;
+ ob_flush();
}
+
+if ($row == 0): ?>
+ <tr>
+ <td class="list" colspan="4" align="center" valign="top">
+ <?= gettext("No states were found.") ?>
+ </td>
+ </tr>
+<?php endif;
+pclose($fd);
?>
</tbody>
</table>
</td>
</tr>
+ <tr>
+ <td class="list" colspan="4" align="center" valign="top">
+ <?php if (!empty($_GET['filter'])): ?>
+ <?=gettext("States matching current filter")?>: <?= $row ?>
+ <?php endif; ?>
+ </td>
+ </tr>
</table>
<!-- End of tab content -->
OpenPOWER on IntegriCloud