diff options
author | SjonHortensius <sjon@hortensius.net> | 2015-04-25 12:56:42 +0200 |
---|---|---|
committer | SjonHortensius <sjon@hortensius.net> | 2015-04-25 12:56:42 +0200 |
commit | 6393afea13de54fb78b2844ebcbe6e4f8c45ff8d (patch) | |
tree | 2f5f68729ce458a2dc36190c057b7d31444bc8d8 /usr | |
parent | 2445bf60f056aa6c5fa80d82a4c1235ed3d60ec5 (diff) | |
parent | 45b99bb69ab85692cb2e29cb4f25cda311cc2da3 (diff) | |
download | pfsense-6393afea13de54fb78b2844ebcbe6e4f8c45ff8d.zip pfsense-6393afea13de54fb78b2844ebcbe6e4f8c45ff8d.tar.gz |
Merge pull request #87 from sbeaver-netgate/diag_tables
Converted diag_tables.php
Diffstat (limited to 'usr')
-rw-r--r-- | usr/local/www/diag_tables.php | 201 |
1 files changed, 128 insertions, 73 deletions
diff --git a/usr/local/www/diag_tables.php b/usr/local/www/diag_tables.php index 09237e3..9b7787a 100644 --- a/usr/local/www/diag_tables.php +++ b/usr/local/www/diag_tables.php @@ -32,7 +32,7 @@ /* pfSense_BUILDER_BINARIES: /sbin/pfctl - pfSense_MODULE: filter + pfSense_MODULE: filter */ ##|+PRIV @@ -49,6 +49,7 @@ require_once("guiconfig.inc"); // Set default table $tablename = "sshlockout"; +$bogons = false; if($_REQUEST['type']) $tablename = $_REQUEST['type']; @@ -61,7 +62,7 @@ if($_REQUEST['delete']) { exit; } -if($_REQUEST['deleteall']) { +if($_POST['deleteall']) { exec("/sbin/pfctl -t " . escapeshellarg($tablename) . " -T show", $entries); if(is_array($entries)) { foreach($entries as $entryA) { @@ -71,33 +72,56 @@ if($_REQUEST['deleteall']) { } } -if((($tablename == "bogons") || ($tablename == "bogonsv6")) && ($_POST['Download'])) { - mwexec_bg("/etc/rc.update_bogons.sh now"); - $maxtimetowait = 0; - $loading = true; - while($loading == true) { - $isrunning = `/bin/ps awwwux | /usr/bin/grep -v grep | /usr/bin/grep bogons`; - if($isrunning == "") - $loading = false; - $maxtimetowait++; - if($maxtimetowait > 89) - $loading = false; - sleep(1); +if(($tablename == "bogons") || ($tablename == "bogonsv6")) { + $bogons = true; + + if($_POST['Download']) { + mwexec_bg("/etc/rc.update_bogons.sh now"); + $maxtimetowait = 0; + $loading = true; + while($loading == true) { + $isrunning = `/bin/ps awwwux | /usr/bin/grep -v grep | /usr/bin/grep bogons`; + if($isrunning == "") + $loading = false; + $maxtimetowait++; + if($maxtimetowait > 89) + $loading = false; + sleep(1); + } + if($maxtimetowait < 90) + $savemsg = gettext("The bogons database has been updated."); } - if($maxtimetowait < 90) - $savemsg = gettext("The bogons database has been updated."); } exec("/sbin/pfctl -t " . escapeshellarg($tablename) . " -T show", $entries); exec("/sbin/pfctl -sT", $tables); include("head.inc"); -?> -<body> -<?php include("fbegin.inc"); ?> -<?php if ($savemsg) print_info_box($savemsg); ?> -<form method="post" action="diag_tables.php"> +if ($savemsg) + print_info_box($savemsg); + +require('classes/Form.class.php'); +$form = new Form(false); +$form->addGlobal(new Form_Input( + 'showtables', + null, + 'hidden', + 'yes' +)); + +$section = new Form_Section('Table to display'); + +$section->addInput(new Form_Select( + 'type', + 'Table', + $tablename, + array_combine($tables, $tables) +)); + +$form->add($section); +print $form; +?> <script type="text/javascript"> //<![CDATA[ @@ -105,7 +129,7 @@ include("head.inc"); window.location='diag_tables.php?type=' + entrytype; } function del_entry(entry) { - jQuery.ajax("diag_tables.php?type=<?php echo htmlspecialchars($tablename);?>&delete=" + entry, { + jQuery.ajax("diag_tables.php?type=<?=htmlspecialchars($tablename)?>&delete=" + entry, { complete: function(response) { if (200 == response.status) { // Escape all dots to not confuse jQuery selectors @@ -119,59 +143,90 @@ include("head.inc"); //]]> </script> -<?=gettext("Table:");?> -<select id="type" onchange="method_change(jQuery('#type').val());" name="type"> - <?php foreach ($tables as $table) { - echo "<option value=\"{$table}\""; - if ($tablename == $table) - echo " selected=\"selected\""; - echo ">{$table}</option>\n"; - } - ?> -</select> - -<br/><br/> - -<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0" summary="tables"> - <tr> - <td class="listhdrr"><?=gettext("IP Address");?></td> - </tr> -<?php $count = 0; foreach($entries as $entryA): ?> - <?php $entry = trim($entryA); ?> - <tr id="<?=$entry?>"> - <td> - <?php echo $entry; ?> - </td> - <td> - <?php if ( ($tablename != "bogons") && ($tablename != "bogonsv6") ) { ?> - <a onclick="del_entry('<?=htmlspecialchars($entry)?>');"> - <img src="/themes/<?=$g['theme'];?>/images/icons/icon_x.gif" alt="delete" /> - </a> - <?php } ?> - </td> - </tr> -<?php $count++; endforeach; ?> +<div class="table-responsive"> + <table class="table table-striped table-hover table-condensed"> + <thead> + <tr id="tblheader"> + <th> + <?=gettext("IP Address")?> + </th> + </tr> + </thead> + <tbody> <?php - if($count == 0) - if( ($tablename == "bogons") || ($tablename == "bogonsv6") ) - echo "<tr><td>" . gettext("No entries exist in this table.") . " " . "<input name=\"Download\" type=\"submit\" class=\"formbtn\" value=\"" . gettext("Download") . "\" /> " . gettext(" the latest bogon data."); - else - echo "<tr><td>" . gettext("No entries exist in this table."); -?> + + $count = 0; + foreach($entries as $entryA): + $entry = trim($entryA); +?> + <tr id="<?=$entry?>"> + <td> + <?=$entry; ?> + </td> + <td> + <?php if (!$bogons) { ?> + <a class="btn btn-xs btn-default" onclick="del_entry('<?=htmlspecialchars($entry)?>');">Remove</a> + <?php } ?> + </td> + </tr> <?php - if($count > 0) - if( ($tablename == "bogons") || ($tablename == "bogonsv6") ) { - $last_updated = exec('/usr/bin/grep -i -m 1 -E "^# last updated" /etc/' . escapeshellarg($tablename)); - echo "<tr><td> <b>$count</b> " . gettext("entries in this table.") . " " . "<input name=\"Download\" type=\"submit\" class=\"formbtn\" value=\"" . gettext("Download") . "\" /> " . gettext(" the latest bogon data.") . "<br />" . "$last_updated"; - } - else - echo "<tr><td>" . gettext("Delete") . " <a href=\"diag_tables.php?deleteall=true&type=" . htmlspecialchars($tablename) . "\">" . gettext("all") . "</a> " . "<b>$count</b> " . gettext("entries in this table."); + $count++; + endforeach; ?> -</td></tr> -</table> -</form> + </tbody> + </table> +</div> +<?php + if($count == 0) { +?> + <div class="alert alert-warning" role="alert">No entries exist in this table</div> +<?php } + +if($bogons || ($count > 0)) { + $form2 = new Form(false); + + $form2->addGlobal(new Form_Input( + 'cleartables', + null, + 'hidden', + $tablename + )); + + $section2 = new Form_Section('Table Data'); + + if($bogons) { + $last_updated = exec('/usr/bin/grep -i -m 1 -E "^# last updated" /etc/' . escapeshellarg($tablename) . '|cut -d"(" -f2|tr -d ")" '); + + $section2->addInput(new Form_StaticText( + 'Last update', + $last_updated + )); + + $section2->addInput(new Form_Button( + 'Download', + 'Download' + ))->setHelp('Download the latest bogon data')->removeClass('btn -primary')->addClass('btn-warning btn-sm'); + } else if($count > 0) { + $section2->addInput(new Form_Button( + 'deleteall', + 'Clear Table' + ))->setHelp('Clear all of the entries in this table')->removeClass('btn-primary')->addClass('btn-danger'); + } + + $form2->add($section2); + print $form2; +} +?> + +<script> +events.push(function(){ + $('#type').on('change', function(){ + $('#tblheader').html('<th class="warning">Fetching table data</th>') + method_change(jQuery('#type').val()); + }); +}); +</script> + +<?php include("foot.inc"); ?> -<?php include("fend.inc"); ?> -</body> -</html> |