Commit 21377312 authored by Franco Fichtner's avatar Franco Fichtner

sbin: apply PSR2 style

parent b4845e62
...@@ -4,7 +4,7 @@ require_once("pfsense-utils.inc"); ...@@ -4,7 +4,7 @@ require_once("pfsense-utils.inc");
ini_set("max_execution_time", "0"); ini_set("max_execution_time", "0");
if(empty($argv[1])) { if (empty($argv[1])) {
echo "No modem device given \n"; echo "No modem device given \n";
exit(0); exit(0);
} }
...@@ -19,7 +19,7 @@ $i = 0; ...@@ -19,7 +19,7 @@ $i = 0;
$record = array(); $record = array();
$handle = fopen($device, "r"); $handle = fopen($device, "r");
if(! $handle) { if (! $handle) {
echo "Can not open modem stats device\n"; echo "Can not open modem stats device\n";
exit(1); exit(1);
} }
...@@ -36,7 +36,7 @@ $record['bwdownstream'] = 0; ...@@ -36,7 +36,7 @@ $record['bwdownstream'] = 0;
$record['simstate'] = 0; $record['simstate'] = 0;
$record['service'] = 0; $record['service'] = 0;
while(true) { while (true) {
$string = ""; $string = "";
$string = fgets($handle, 256); $string = fgets($handle, 256);
...@@ -45,7 +45,7 @@ while(true) { ...@@ -45,7 +45,7 @@ while(true) {
$elements[0] = trim($elements[0]); $elements[0] = trim($elements[0]);
$elements[1] = trim($elements[1]); $elements[1] = trim($elements[1]);
switch($elements[0]) { switch ($elements[0]) {
case "^MODE": case "^MODE":
$record['mode'] = $elements[1]; $record['mode'] = $elements[1];
break; break;
...@@ -71,7 +71,7 @@ while(true) { ...@@ -71,7 +71,7 @@ while(true) {
break; break;
} }
if($i > 10) { if ($i > 10) {
$csv = $header; $csv = $header;
$csv .= implode(",", $record); $csv .= implode(",", $record);
$csv .= "\n"; $csv .= "\n";
......
...@@ -52,8 +52,9 @@ $current_user_count = 0; ...@@ -52,8 +52,9 @@ $current_user_count = 0;
/* tmp file to use to store old data (per interface)*/ /* tmp file to use to store old data (per interface)*/
$tmpfile = '/var/db/captiveportal_online_users'; $tmpfile = '/var/db/captiveportal_online_users';
if(empty($type)) if (empty($type)) {
exit; exit;
}
/* echo the rrd required syntax */ /* echo the rrd required syntax */
echo "N:"; echo "N:";
...@@ -70,23 +71,25 @@ if ($type == "loggedin") { ...@@ -70,23 +71,25 @@ if ($type == "loggedin") {
if ($fd) { if ($fd) {
while (!feof($fd)) { while (!feof($fd)) {
$line = trim(fgets($fd)); $line = trim(fgets($fd));
if($line) if ($line) {
$previous_user_timestamp = $line; $previous_user_timestamp = $line;
else } else {
$previous_user_timestamp = 0; $previous_user_timestamp = 0;
} }
}
} else { } else {
$previous_user_timestamp = 0; $previous_user_timestamp = 0;
} }
@fclose($fd); @fclose($fd);
foreach($cpdb as $user) { foreach ($cpdb as $user) {
$user_ip = $user[2]; $user_ip = $user[2];
// Record the timestamp // Record the timestamp
$timestamp = $user[0]; $timestamp = $user[0];
if ($timestamp > $previous_user_timestamp) if ($timestamp > $previous_user_timestamp) {
$current_user_count = $current_user_count + 1; $current_user_count = $current_user_count + 1;
} }
}
// Write out the latest timestamp but not if it is empty // Write out the latest timestamp but not if it is empty
if (!empty($timestamp)) { if (!empty($timestamp)) {
...@@ -100,9 +103,9 @@ if ($type == "loggedin") { ...@@ -100,9 +103,9 @@ if ($type == "loggedin") {
/* If $timestamp is less than or equal to previous_user_timestamp return 0, /* If $timestamp is less than or equal to previous_user_timestamp return 0,
* as we only want the 'X' number of users logged in since last RRD poll. * as we only want the 'X' number of users logged in since last RRD poll.
*/ */
if($timestamp <= $previous_user_timestamp) if ($timestamp <= $previous_user_timestamp) {
$result = 0; $result = 0;
else { } else {
$result = $current_user_count; $result = $current_user_count;
} }
} elseif ($type == "concurrent") } elseif ($type == "concurrent")
......
...@@ -45,8 +45,9 @@ if (file_exists($status_file)) { ...@@ -45,8 +45,9 @@ if (file_exists($status_file)) {
sort($previous_mirror_list); sort($previous_mirror_list);
if (count($previous_mirror_status) > 0) { if (count($previous_mirror_status) > 0) {
// Check list of current mirrors vs old mirrors, notify if one has appeared/disappeared // Check list of current mirrors vs old mirrors, notify if one has appeared/disappeared
if ($mirror_list != $previous_mirror_list) if ($mirror_list != $previous_mirror_list) {
$notices[] = sprintf(gettext("List of mirrors changed. Old: (%s) New: (%s)"), implode(", ", $previous_mirror_list), implode(", ", $mirror_list)); $notices[] = sprintf(gettext("List of mirrors changed. Old: (%s) New: (%s)"), implode(", ", $previous_mirror_list), implode(", ", $mirror_list));
}
// For each mirror, check the mirror status, notify if changed // For each mirror, check the mirror status, notify if changed
foreach ($mirror_list as $mirror) { foreach ($mirror_list as $mirror) {
...@@ -64,11 +65,14 @@ if (file_exists($status_file)) { ...@@ -64,11 +65,14 @@ if (file_exists($status_file)) {
// Check the drive status as it may be different. // Check the drive status as it may be different.
asort($mirror_status[$mirror]['components']); asort($mirror_status[$mirror]['components']);
asort($previous_mirror_status[$mirror]['components']); asort($previous_mirror_status[$mirror]['components']);
if ($mirror_status[$mirror]['components'] != $previous_mirror_status[$mirror]['components']) if ($mirror_status[$mirror]['components'] != $previous_mirror_status[$mirror]['components']) {
$notices[] = sprintf(gettext("Mirror %s drive status changed. Old: (%s) New: (%s)"), $notices[] = sprintf(
gettext("Mirror %s drive status changed. Old: (%s) New: (%s)"),
$mirror, $mirror,
implode(", ", $previous_mirror_status[$mirror]['components']), implode(", ", $previous_mirror_status[$mirror]['components']),
implode(", ", $mirror_status[$mirror]['components'])); implode(", ", $mirror_status[$mirror]['components'])
);
}
} }
} }
} }
...@@ -78,5 +82,6 @@ if (count($notices)) { ...@@ -78,5 +82,6 @@ if (count($notices)) {
file_notice("gmirror", implode("\n ", $notices), "GEOM Mirror Status Change", 1); file_notice("gmirror", implode("\n ", $notices), "GEOM Mirror Status Change", 1);
} }
// Write out current status if changed // Write out current status if changed
if ($mirror_status != $previous_mirror_status) if ($mirror_status != $previous_mirror_status) {
file_put_contents($status_file, serialize($mirror_status)); file_put_contents($status_file, serialize($mirror_status));
}
<?php <?php
$leases_file = "/var/dhcpd/var/db/dhcpd6.leases"; $leases_file = "/var/dhcpd/var/db/dhcpd6.leases";
if(!file_exists($leases_file)) { if (!file_exists($leases_file)) {
exit(1); exit(1);
} }
$duid_arr = array(); $duid_arr = array();
foreach(file($leases_file) as $line) { foreach (file($leases_file) as $line) {
// echo "$line"; // echo "$line";
if(preg_match("/^(ia-[np][ad])[ ]+\"(.*?)\"/i ", $line, $duidmatch)) { if (preg_match("/^(ia-[np][ad])[ ]+\"(.*?)\"/i ", $line, $duidmatch)) {
$type = $duidmatch[1]; $type = $duidmatch[1];
$duid = $duidmatch[2]; $duid = $duidmatch[2];
continue; continue;
} }
/* is it active? otherwise just discard */ /* is it active? otherwise just discard */
if(preg_match("/binding state active/i", $line, $activematch)) { if (preg_match("/binding state active/i", $line, $activematch)) {
$active = true; $active = true;
continue; continue;
} }
if(preg_match("/iaaddr[ ]+([0-9a-f:]+)[ ]+/i", $line, $addressmatch)) { if (preg_match("/iaaddr[ ]+([0-9a-f:]+)[ ]+/i", $line, $addressmatch)) {
$ia_na = $addressmatch[1]; $ia_na = $addressmatch[1];
continue; continue;
} }
if(preg_match("/iaprefix[ ]+([0-9a-f:\/]+)[ ]+/i", $line, $prefixmatch)) { if (preg_match("/iaprefix[ ]+([0-9a-f:\/]+)[ ]+/i", $line, $prefixmatch)) {
$ia_pd = $prefixmatch[1]; $ia_pd = $prefixmatch[1];
continue; continue;
} }
/* closing bracket */ /* closing bracket */
if(preg_match("/^}/i ", $line)) { if (preg_match("/^}/i ", $line)) {
switch($type) { switch ($type) {
case "ia-na": case "ia-na":
$duid_arr[$duid][$type] = $ia_na; $duid_arr[$duid][$type] = $ia_na;
break; break;
...@@ -51,14 +51,14 @@ foreach(file($leases_file) as $line) { ...@@ -51,14 +51,14 @@ foreach(file($leases_file) as $line) {
$routes = array(); $routes = array();
foreach ($duid_arr as $entry) { foreach ($duid_arr as $entry) {
if($entry['ia-pd'] <> "") { if ($entry['ia-pd'] <> "") {
$routes[$entry['ia-na']] = $entry['ia-pd']; $routes[$entry['ia-na']] = $entry['ia-pd'];
} }
array_shift($duid_arr); array_shift($duid_arr);
} }
// echo "add routes\n"; // echo "add routes\n";
if(count($routes) > 0) { if (count($routes) > 0) {
foreach ($routes as $address => $prefix) { foreach ($routes as $address => $prefix) {
echo "/sbin/route change -inet6 {$prefix} {$address}\n"; echo "/sbin/route change -inet6 {$prefix} {$address}\n";
} }
...@@ -67,28 +67,29 @@ if(count($routes) > 0) { ...@@ -67,28 +67,29 @@ if(count($routes) > 0) {
/* get clog from dhcpd */ /* get clog from dhcpd */
$dhcpdlogfile = "/var/log/dhcpd.log"; $dhcpdlogfile = "/var/log/dhcpd.log";
$clog = array(); $clog = array();
if(file_exists($dhcpdlogfile)) if (file_exists($dhcpdlogfile)) {
exec("clog $dhcpdlogfile", $clog, $ret); exec("clog $dhcpdlogfile", $clog, $ret);
}
if($ret > 0) if ($ret > 0) {
$clog = array(); $clog = array();
}
$expires = array(); $expires = array();
foreach($clog as $line) { foreach ($clog as $line) {
if(preg_match("/releases[ ]+prefix[ ]+([0-9a-f:]+\/[0-9]+)/i", $line, $expire)) { if (preg_match("/releases[ ]+prefix[ ]+([0-9a-f:]+\/[0-9]+)/i", $line, $expire)) {
if(in_array($expire[1], $routes)) if (in_array($expire[1], $routes)) {
continue; continue;
}
$expires[$expire[1]] = $expire[1]; $expires[$expire[1]] = $expire[1];
} }
array_shift($clog); array_shift($clog);
} }
// echo "remove routes\n"; // echo "remove routes\n";
if(count($expires) > 0) { if (count($expires) > 0) {
foreach ($expires as $prefix) { foreach ($expires as $prefix) {
echo "/sbin/route delete -inet6 {$prefix['prefix']}\n"; echo "/sbin/route delete -inet6 {$prefix['prefix']}\n";
array_shift($expires); array_shift($expires);
} }
} }
?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment