mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-17 01:54:49 +00:00
(legacy) refactor diag_system_pftop.php
This commit is contained in:
parent
3cc55eafd4
commit
b57f27ccbe
@ -21,3 +21,9 @@ command:/usr/local/opnsense/scripts/filter/list_osfp.py
|
||||
parameters:
|
||||
type:script_output
|
||||
message:request osfp
|
||||
|
||||
[diag.top]
|
||||
command:/usr/local/sbin/pftop
|
||||
parameters: -w 200 -b -o %s -v %s %s
|
||||
type:script_output
|
||||
message:request pftop statistics
|
||||
|
||||
@ -28,178 +28,142 @@
|
||||
|
||||
require_once("guiconfig.inc");
|
||||
|
||||
$pgtitle = gettext("Diagnostics: pfTop");
|
||||
|
||||
$sorttypes = array('age', 'bytes', 'dest', 'dport', 'exp', 'none', 'peak', 'pkt', 'rate', 'size', 'sport', 'src');
|
||||
$viewtypes = array('default', 'label', 'long', 'rules', 'size', 'speed', 'state', 'time');
|
||||
$viewall = array('label', 'rules');
|
||||
$numstates = array('50', '100', '200', '500', '1000', 'all');
|
||||
$numstates = array('50', '100', '200', '500', '1000', '99999999999');
|
||||
|
||||
if($_REQUEST['getactivity']) {
|
||||
if($_REQUEST['sorttype'] && in_array($_REQUEST['sorttype'], $sorttypes)
|
||||
&& $_REQUEST['viewtype'] && in_array($_REQUEST['viewtype'], $viewtypes)
|
||||
&& $_REQUEST['states'] && in_array($_REQUEST['states'], $numstates)) {
|
||||
$viewtype = escapeshellarg($_REQUEST['viewtype']);
|
||||
if (in_array($_REQUEST['viewtype'], $viewall)) {
|
||||
$sorttype = "";
|
||||
$numstate = "-a";
|
||||
} else {
|
||||
$sorttype = "-o " . escapeshellarg($_REQUEST['sorttype']);
|
||||
$numstate = ($_REQUEST['states'] == "all" ? "-a" : escapeshellarg($_REQUEST['states']));
|
||||
}
|
||||
} else {
|
||||
$sorttype = "bytes";
|
||||
$viewtype = "default";
|
||||
$numstate = "100";
|
||||
}
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
// fetch only valid input data (items from above lists)
|
||||
$viewtype = 'default';
|
||||
$numstate = '200';
|
||||
$sorttype ='bytes';
|
||||
if (isset($_POST['viewtype']) && in_array($_POST['viewtype'], $viewtypes)) {
|
||||
$viewtype = $_POST['viewtype'];
|
||||
}
|
||||
if (isset($_POST['states']) && in_array($_POST['states'], $numstates)) {
|
||||
$numstate = $_POST['states'];
|
||||
}
|
||||
if (isset($_POST['sorttype']) && in_array($_POST['sorttype'], $sorttypes)) {
|
||||
$sorttype = $_POST['sorttype'];
|
||||
}
|
||||
|
||||
$text = `pftop -b {$sorttype} -v {$viewtype} {$numstate}`;
|
||||
echo $text;
|
||||
exit;
|
||||
// fetch pftop data
|
||||
echo configd_run("filter diag top {$sorttype} {$viewtype} {$numstate}");
|
||||
exit;
|
||||
}
|
||||
|
||||
$pgtitle = gettext("Diagnostics: pfTop");
|
||||
include("head.inc");
|
||||
|
||||
if($_REQUEST['sorttype'] && in_array($_REQUEST['sorttype'], $sorttypes)
|
||||
&& $_REQUEST['viewtype'] && in_array($_REQUEST['viewtype'], $viewtypes)
|
||||
&& $_REQUEST['states'] && in_array($_REQUEST['states'], $numstates)) {
|
||||
$viewtype = escapeshellarg($_REQUEST['viewtype']);
|
||||
if (in_array($_REQUEST['viewtype'], $viewall)) {
|
||||
$sorttype = "";
|
||||
$numstate = "-a";
|
||||
} else {
|
||||
$sorttype = "-o " . escapeshellarg($_REQUEST['sorttype']);
|
||||
$numstate = ($_REQUEST['states'] == "all" ? "-a" : escapeshellarg($_REQUEST['states']));
|
||||
}
|
||||
} else {
|
||||
$sorttype = "bytes";
|
||||
$viewtype = "default";
|
||||
$numstate = "100";
|
||||
}
|
||||
|
||||
?>
|
||||
<body>
|
||||
<?php include("fbegin.inc"); ?>
|
||||
|
||||
<script type="text/javascript">
|
||||
//<![CDATA[
|
||||
function getpftopactivity() {
|
||||
var url = "/diag_system_pftop.php";
|
||||
var pars = 'getactivity=yes&sorttype=' + jQuery('#sorttype').val() + '&viewtype=' + jQuery('#viewtype').val() + '&states=' + jQuery('#states').val();
|
||||
jQuery.ajax(
|
||||
url,
|
||||
{
|
||||
type: 'post',
|
||||
data: pars,
|
||||
complete: activitycallback
|
||||
});
|
||||
}
|
||||
function activitycallback(transport) {
|
||||
jQuery('#pftopactivitydiv').html('<pre>' + transport.responseText + '<\/pre>');
|
||||
setTimeout('getpftopactivity()', 2500);
|
||||
}
|
||||
setTimeout('getpftopactivity()', 1000);
|
||||
//]]>
|
||||
</script>
|
||||
$( document ).ready(function() {
|
||||
/**
|
||||
* fetch pftop data from backend
|
||||
*/
|
||||
function getpftopactivity() {
|
||||
$.ajax(
|
||||
'/diag_system_pftop.php',
|
||||
{
|
||||
type: 'post',
|
||||
data: {'getactivity':'yes'
|
||||
,'sorttype':$('#sorttype').val()
|
||||
,'viewtype':$('#viewtype').val()
|
||||
,'states':$('#states').val()
|
||||
},
|
||||
complete: function(transport) {
|
||||
$('#pftopactivitydiv').html('<pre>' + transport.responseText + '<\/pre>');
|
||||
setTimeout(getpftopactivity, 2500);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$("#viewtype").change(function() {
|
||||
var selected = $("#viewtype option:selected").val();
|
||||
switch(selected) {
|
||||
case "rules":
|
||||
$(".show_opt").addClass("hidden");
|
||||
break;
|
||||
default:
|
||||
$(".show_opt").removeClass("hidden");
|
||||
}
|
||||
});
|
||||
|
||||
// toggle initial viewtype select
|
||||
$("#viewtype").change();
|
||||
// start initial fetch
|
||||
getpftopactivity();
|
||||
});
|
||||
</script>
|
||||
|
||||
<section class="page-content-main">
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
|
||||
|
||||
|
||||
<div class="table-responsive">
|
||||
|
||||
<form method="post" action="<?=$_SERVER['REQUEST_URI'];?>">
|
||||
<table class="table table-striped __nomb">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?=gettext("View type:"); ?></th>
|
||||
<th><?=gettext("Sort type:"); ?></th>
|
||||
<th><?=gettext("Number of States:"); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><select name='viewtype' id='viewtype' class="form-control">
|
||||
<option value='default' <?php echo ($viewtype == "default") ? "selected=\"selected\"" : ""; ?>><?=gettext("Default");?></option>
|
||||
<option value='label' <?php echo ($viewtype == "label") ? "selected=\"selected\"" : ""; ?>><?=gettext("Label");?></option>
|
||||
<option value='long' <?php echo ($viewtype == "long") ? "selected=\"selected\"" : ""; ?>><?=gettext("Long");?></option>
|
||||
<option value='rules' <?php echo ($viewtype == "rules") ? "selected=\"selected\"" : ""; ?>><?=gettext("Rules");?></option>
|
||||
<option value='size' <?php echo ($viewtype == "size") ? "selected=\"selected\"" : ""; ?>><?=gettext("Size");?></option>
|
||||
<option value='speed' <?php echo ($viewtype == "speed") ? "selected=\"selected\"" : ""; ?>><?=gettext("Speed");?></option>
|
||||
<option value='state' <?php echo ($viewtype == "state") ? "selected=\"selected\"" : ""; ?>><?=gettext("State");?></option>
|
||||
<option value='time' <?php echo ($viewtype == "time") ? "selected=\"selected\"" : ""; ?>><?=gettext("Time");?></option>
|
||||
</select></td>
|
||||
<td><select name='sorttype' id='sorttype' class="form-control">
|
||||
<option value='age' <?php echo ($sorttype == "age") ? "selected=\"selected\"" : ""; ?>><?=gettext("Age");?></option>
|
||||
<option value='bytes' <?php echo ($sorttype == "bytes") ? "selected=\"selected\"" : ""; ?>><?=gettext("Bytes");?></option>
|
||||
<option value='dest' <?php echo ($sorttype == "dest") ? "selected=\"selected\"" : ""; ?>><?=gettext("Destination Address");?></option>
|
||||
<option value='dport' <?php echo ($sorttype == "dport") ? "selected=\"selected\"" : ""; ?>><?=gettext("Destination Port");?></option>
|
||||
<option value='exp' <?php echo ($sorttype == "exp") ? "selected=\"selected\"" : ""; ?>><?=gettext("Expiry");?></option>
|
||||
<option value='none' <?php echo ($sorttype == "none") ? "selected=\"selected\"" : ""; ?>><?=gettext("None");?></option>
|
||||
<option value='peak' <?php echo ($sorttype == "peak") ? "selected=\"selected\"" : ""; ?>><?=gettext("Peak");?></option>
|
||||
<option value='pkt' <?php echo ($sorttype == "pkt") ? "selected=\"selected\"" : ""; ?>><?=gettext("Packet");?></option>
|
||||
<option value='rate' <?php echo ($sorttype == "rate") ? "selected=\"selected\"" : ""; ?>><?=gettext("Rate");?></option>
|
||||
<option value='size' <?php echo ($sorttype == "size") ? "selected=\"selected\"" : ""; ?>><?=gettext("Size");?></option>
|
||||
<option value='sport' <?php echo ($sorttype == "sport") ? "selected=\"selected\"" : ""; ?>><?=gettext("Source Port");?></option>
|
||||
<option value='src' <?php echo ($sorttype == "src") ? "selected=\"selected\"" : ""; ?>><?=gettext("Source Address");?></option>
|
||||
</select></td>
|
||||
<td><select name='states' id='states' class="form-control">
|
||||
<option value='50' <?php echo ($numstate == "50") ? "selected=\"selected\"" : ""; ?>>50</option>
|
||||
<option value='100' <?php echo ($numstate == "100") ? "selected=\"selected\"" : ""; ?>>100</option>
|
||||
<option value='200' <?php echo ($numstate == "200") ? "selected=\"selected\"" : ""; ?>>200</option>
|
||||
<option value='500' <?php echo ($numstate == "500") ? "selected=\"selected\"" : ""; ?>>500</option>
|
||||
<option value='1000' <?php echo ($numstate == "1000") ? "selected=\"selected\"" : ""; ?>>1000</option>
|
||||
<option value='all' <?php echo ($numstate == "all") ? "selected=\"selected\"" : ""; ?>>all</option>
|
||||
</select></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<section class="col-xs-12">
|
||||
|
||||
|
||||
|
||||
<?php
|
||||
if($savemsg) {
|
||||
echo "<div id=\"savemsg\">";
|
||||
print_info_box($savemsg);
|
||||
echo "</div>";
|
||||
}
|
||||
if (isset($input_errors) && count($input_errors) > 0)
|
||||
print_input_errors($input_errors);
|
||||
?>
|
||||
|
||||
<div id="pftopactivitydiv"><?=gettext("Gathering pfTOP activity, please wait...");?></div>
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="table-responsive">
|
||||
<form method="post" action="<?=$_SERVER['REQUEST_URI'];?>">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?=gettext("View type:"); ?></th>
|
||||
<th class="show_opt"><?=gettext("Sort type:"); ?></th>
|
||||
<th class="show_opt"><?=gettext("Number of States:"); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<select name='viewtype' id='viewtype' class="selectpicker" data-width="auto" data-live-search="true">
|
||||
<option value='default' selected="selected"><?=gettext("Default");?></option>
|
||||
<option value='label'><?=gettext("Label");?></option>
|
||||
<option value='long'><?=gettext("Long");?></option>
|
||||
<option value='rules'><?=gettext("Rules");?></option>
|
||||
<option value='size'><?=gettext("Size");?></option>
|
||||
<option value='speed'><?=gettext("Speed");?></option>
|
||||
<option value='state'><?=gettext("State");?></option>
|
||||
<option value='time'><?=gettext("Time");?></option>
|
||||
</select>
|
||||
</td>
|
||||
<td class="show_opt">
|
||||
<div>
|
||||
<select name='sorttype' id='sorttype' class="selectpicker" data-width="auto" data-live-search="true">
|
||||
<option value='age'><?=gettext("Age");?></option>
|
||||
<option value='bytes'><?=gettext("Bytes");?></option>
|
||||
<option value='dest'><?=gettext("Destination Address");?></option>
|
||||
<option value='dport'><?=gettext("Destination Port");?></option>
|
||||
<option value='exp'><?=gettext("Expiry");?></option>
|
||||
<option value='none'><?=gettext("None");?></option>
|
||||
<option value='peak'><?=gettext("Peak");?></option>
|
||||
<option value='pkt'><?=gettext("Packet");?></option>
|
||||
<option value='rate'><?=gettext("Rate");?></option>
|
||||
<option value='size'><?=gettext("Size");?></option>
|
||||
<option value='sport'><?=gettext("Source Port");?></option>
|
||||
<option value='src'><?=gettext("Source Address");?></option>
|
||||
</select>
|
||||
</div>
|
||||
</td>
|
||||
<td class="show_opt">
|
||||
<div id='statesdiv'>
|
||||
<select name='states' id='states' class="selectpicker" data-width="auto" data-live-search="true">
|
||||
<option value='50'>50</option>
|
||||
<option value='100'>100</option>
|
||||
<option value='200' selected="selected">200</option>
|
||||
<option value='500'>500</option>
|
||||
<option value='1000'>1000</option>
|
||||
<option value='9999999999'>all</option>
|
||||
</select>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
<section class="col-xs-12">
|
||||
<div id="pftopactivitydiv"><?=gettext("Gathering pfTOP activity, please wait...");?></div>
|
||||
</section>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
<script type="text/javascript">
|
||||
//<![CDATA[
|
||||
jQuery("#viewtype").change(function() {
|
||||
var selected = jQuery("#viewtype option:selected");
|
||||
switch(selected.val()) {
|
||||
case "label":
|
||||
case "rules":
|
||||
jQuery("#sorttype, #sorttypediv, #statesdiv, #states").hide();
|
||||
break;
|
||||
default:
|
||||
jQuery("#sorttype, #sorttypediv, #statesdiv, #states").show();
|
||||
}
|
||||
});
|
||||
//]]>
|
||||
</script>
|
||||
|
||||
|
||||
<?php include("foot.inc"); ?>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user