reporting: a bit of style in previous

* Init and use $cmd_args before going into the switch
* Use exec_safe() where we return dynamic output
* PSR 12 style
This commit is contained in:
Franco Fichtner 2020-08-24 08:18:56 +02:00
parent 2a7a3a97e0
commit c56d332f07

View File

@ -87,22 +87,20 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$real_interface = get_real_interface($pconfig['if']);
$intsubnet = find_interface_network($real_interface);
if (is_subnetv4($intsubnet)) {
$cmd_args = $pconfig['sort'] == 'out' ? ' -T' : ' -R';
switch ( $pconfig['filter'] ) {
switch ($pconfig['filter']) {
case 'local':
$cmd_args = " -c " . $intsubnet . " ";
$cmd_args .= exec_safe(' -c %s', $intsubnet);
break;
case 'private':
$cmd_args = " -c 172.16.0.0/12 -c 192.168.0.0/16 -c 10.0.0.0/8 ";
$cmd_args .= ' -c 172.16.0.0/12 -c 192.168.0.0/16 -c 10.0.0.0/8';
break;
default:
$cmd_args = " -lc 0.0.0.0/0 ";
$cmd_args .= ' -lc 0.0.0.0/0';
break;
}
$cmd_args .= $pconfig['sort'] == "out" ? " -T " : " -R ";
$cmd_action = "/usr/local/bin/rate -v -i {$real_interface} -nlq 1 -Aba 20 {$cmd_args} | tr \"|\" \" \" | awk '{ printf \"%s:%s:%s:%s:%s\\n\", $1, $2, $4, $6, $8 }'";
exec($cmd_action, $listedIPs);
for ($idx = 2 ; $idx < count($listedIPs) ; ++$idx) {