Commit 21377312 authored by Franco Fichtner's avatar Franco Fichtner

sbin: apply PSR2 style

parent b4845e62
......@@ -4,9 +4,9 @@ require_once("pfsense-utils.inc");
ini_set("max_execution_time", "0");
if(empty($argv[1])) {
echo "No modem device given \n";
exit(0);
if (empty($argv[1])) {
echo "No modem device given \n";
exit(0);
}
/* Huawei example */
......@@ -19,9 +19,9 @@ $i = 0;
$record = array();
$handle = fopen($device, "r");
if(! $handle) {
echo "Can not open modem stats device\n";
exit(1);
if (! $handle) {
echo "Can not open modem stats device\n";
exit(1);
}
$record['time'] = 0;
......@@ -36,49 +36,49 @@ $record['bwdownstream'] = 0;
$record['simstate'] = 0;
$record['service'] = 0;
while(true) {
$string = "";
$string = fgets($handle, 256);
while (true) {
$string = "";
$string = fgets($handle, 256);
$elements = array();
$elements = split(":", $string);
$elements[0] = trim($elements[0]);
$elements[1] = trim($elements[1]);
$elements = array();
$elements = split(":", $string);
$elements[0] = trim($elements[0]);
$elements[1] = trim($elements[1]);
switch($elements[0]) {
case "^MODE":
$record['mode'] = $elements[1];
break;
case "^SRVST":
$record['service'] = $elements[1];
break;
case "^SIMST":
$record['simstate'] = $elements[1];
break;
case "^RSSI":
$record['rssi'] = $elements[1];
break;
case "^DSFLOWRPT":
$items = array();
$items = split(",", $elements[1]);
$record['time'] = hexdec($items[0]);
$record['upstream'] = round((floatval(hexdec($items[1])) * 8) /1024);
$record['downstream'] = round((floatval(hexdec($items[2])) * 8) /1024);
$record['sent'] = hexdec($items[3]);
$record['received'] = hexdec($items[4]);
$record['bwupstream'] = round((floatval(hexdec($items[5])) * 8) /1024);
$record['bwdownstream'] = round((floatval(hexdec($items[6])) * 8) /1024);
break;
}
switch ($elements[0]) {
case "^MODE":
$record['mode'] = $elements[1];
break;
case "^SRVST":
$record['service'] = $elements[1];
break;
case "^SIMST":
$record['simstate'] = $elements[1];
break;
case "^RSSI":
$record['rssi'] = $elements[1];
break;
case "^DSFLOWRPT":
$items = array();
$items = split(",", $elements[1]);
$record['time'] = hexdec($items[0]);
$record['upstream'] = round((floatval(hexdec($items[1])) * 8) /1024);
$record['downstream'] = round((floatval(hexdec($items[2])) * 8) /1024);
$record['sent'] = hexdec($items[3]);
$record['received'] = hexdec($items[4]);
$record['bwupstream'] = round((floatval(hexdec($items[5])) * 8) /1024);
$record['bwdownstream'] = round((floatval(hexdec($items[6])) * 8) /1024);
break;
}
if($i > 10) {
$csv = $header;
$csv .= implode(",", $record);
$csv .= "\n";
file_put_contents($statfile, $csv);
$i = 0;
}
$i++;
if ($i > 10) {
$csv = $header;
$csv .= implode(",", $record);
$csv .= "\n";
file_put_contents($statfile, $csv);
$i = 0;
}
$i++;
}
fclose($handle);
?>
......@@ -52,60 +52,63 @@ $current_user_count = 0;
/* tmp file to use to store old data (per interface)*/
$tmpfile = '/var/db/captiveportal_online_users';
if(empty($type))
exit;
if (empty($type)) {
exit;
}
/* echo the rrd required syntax */
echo "N:";
$result = "NaN";
if ($type == "loggedin") {
$timestamp = 0;
$timestamp = 0;
/* Find out the previous user timestamp
/* Find out the previous user timestamp
* so we can determine the difference between the current
* and previous user count. If the file is empty return a 0.
*/
$fd = @fopen($tmpfile, "r");
if ($fd) {
while (!feof($fd)) {
$line = trim(fgets($fd));
if($line)
$previous_user_timestamp = $line;
else
$previous_user_timestamp = 0;
}
} else {
$previous_user_timestamp = 0;
}
@fclose($fd);
foreach($cpdb as $user) {
$user_ip = $user[2];
// Record the timestamp
$timestamp = $user[0];
if ($timestamp > $previous_user_timestamp)
$current_user_count = $current_user_count + 1;
}
// Write out the latest timestamp but not if it is empty
if (!empty($timestamp)) {
$fd = @fopen($tmpfile, "w");
if ($fd) {
fwrite($fd, $timestamp);
}
@fclose($fd);
}
/* If $timestamp is less than or equal to previous_user_timestamp return 0,
$fd = @fopen($tmpfile, "r");
if ($fd) {
while (!feof($fd)) {
$line = trim(fgets($fd));
if ($line) {
$previous_user_timestamp = $line;
} else {
$previous_user_timestamp = 0;
}
}
} else {
$previous_user_timestamp = 0;
}
@fclose($fd);
foreach ($cpdb as $user) {
$user_ip = $user[2];
// Record the timestamp
$timestamp = $user[0];
if ($timestamp > $previous_user_timestamp) {
$current_user_count = $current_user_count + 1;
}
}
// Write out the latest timestamp but not if it is empty
if (!empty($timestamp)) {
$fd = @fopen($tmpfile, "w");
if ($fd) {
fwrite($fd, $timestamp);
}
@fclose($fd);
}
/* 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.
*/
if($timestamp <= $previous_user_timestamp)
$result = 0;
else {
$result = $current_user_count;
}
if ($timestamp <= $previous_user_timestamp) {
$result = 0;
} else {
$result = $current_user_count;
}
} elseif ($type == "concurrent")
$result = $no_users;
$result = $no_users;
echo "$result";
......@@ -39,44 +39,49 @@ $notices = array();
// Check for gmirror.status
if (file_exists($status_file)) {
// If it exists, read status in
$previous_mirror_status = unserialize(file_get_contents($status_file));
$previous_mirror_list = array_keys($previous_mirror_status);
sort($previous_mirror_list);
if (count($previous_mirror_status) > 0) {
// Check list of current mirrors vs old mirrors, notify if one has appeared/disappeared
if ($mirror_list != $previous_mirror_list)
$notices[] = sprintf(gettext("List of mirrors changed. Old: (%s) New: (%s)"), implode(", ", $previous_mirror_list), implode(", ", $mirror_list));
// If it exists, read status in
$previous_mirror_status = unserialize(file_get_contents($status_file));
$previous_mirror_list = array_keys($previous_mirror_status);
sort($previous_mirror_list);
if (count($previous_mirror_status) > 0) {
// Check list of current mirrors vs old mirrors, notify if one has appeared/disappeared
if ($mirror_list != $previous_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
foreach ($mirror_list as $mirror) {
if (is_array($previous_mirror_status[$mirror])) {
// Notify if the status changed
if ($mirror_status[$mirror]['status'] != $previous_mirror_status[$mirror]['status']) {
$notices[] = sprintf(gettext("Mirror %s status changed from %s to %s."), $mirror, $previous_mirror_status[$mirror]['status'], $mirror_status[$mirror]['status']);
}
// Notify if the drive count changed
if (count($mirror_status[$mirror]['components']) != count($previous_mirror_status[$mirror]['components'])) {
// Notify if the consumer count changed.
$notices[] = sprintf(gettext("Mirror %s consumer count changed from %d to %d."), $mirror, count($previous_mirror_status[$mirror]['components']), count($mirror_status[$mirror]['components']));
}
if (strtoupper($mirror_status[$mirror]['status']) == "DEGRADED") {
// Check the drive status as it may be different.
asort($mirror_status[$mirror]['components']);
asort($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)"),
$mirror,
implode(", ", $previous_mirror_status[$mirror]['components']),
implode(", ", $mirror_status[$mirror]['components']));
}
}
}
}
// For each mirror, check the mirror status, notify if changed
foreach ($mirror_list as $mirror) {
if (is_array($previous_mirror_status[$mirror])) {
// Notify if the status changed
if ($mirror_status[$mirror]['status'] != $previous_mirror_status[$mirror]['status']) {
$notices[] = sprintf(gettext("Mirror %s status changed from %s to %s."), $mirror, $previous_mirror_status[$mirror]['status'], $mirror_status[$mirror]['status']);
}
// Notify if the drive count changed
if (count($mirror_status[$mirror]['components']) != count($previous_mirror_status[$mirror]['components'])) {
// Notify if the consumer count changed.
$notices[] = sprintf(gettext("Mirror %s consumer count changed from %d to %d."), $mirror, count($previous_mirror_status[$mirror]['components']), count($mirror_status[$mirror]['components']));
}
if (strtoupper($mirror_status[$mirror]['status']) == "DEGRADED") {
// Check the drive status as it may be different.
asort($mirror_status[$mirror]['components']);
asort($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)"),
$mirror,
implode(", ", $previous_mirror_status[$mirror]['components']),
implode(", ", $mirror_status[$mirror]['components'])
);
}
}
}
}
}
}
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
if ($mirror_status != $previous_mirror_status)
file_put_contents($status_file, serialize($mirror_status));
if ($mirror_status != $previous_mirror_status) {
file_put_contents($status_file, serialize($mirror_status));
}
<?php
$leases_file = "/var/dhcpd/var/db/dhcpd6.leases";
if(!file_exists($leases_file)) {
exit(1);
if (!file_exists($leases_file)) {
exit(1);
}
$duid_arr = array();
foreach(file($leases_file) as $line) {
// echo "$line";
if(preg_match("/^(ia-[np][ad])[ ]+\"(.*?)\"/i ", $line, $duidmatch)) {
$type = $duidmatch[1];
$duid = $duidmatch[2];
continue;
}
foreach (file($leases_file) as $line) {
// echo "$line";
if (preg_match("/^(ia-[np][ad])[ ]+\"(.*?)\"/i ", $line, $duidmatch)) {
$type = $duidmatch[1];
$duid = $duidmatch[2];
continue;
}
/* is it active? otherwise just discard */
if(preg_match("/binding state active/i", $line, $activematch)) {
$active = true;
continue;
}
/* is it active? otherwise just discard */
if (preg_match("/binding state active/i", $line, $activematch)) {
$active = true;
continue;
}
if(preg_match("/iaaddr[ ]+([0-9a-f:]+)[ ]+/i", $line, $addressmatch)) {
$ia_na = $addressmatch[1];
continue;
}
if (preg_match("/iaaddr[ ]+([0-9a-f:]+)[ ]+/i", $line, $addressmatch)) {
$ia_na = $addressmatch[1];
continue;
}
if(preg_match("/iaprefix[ ]+([0-9a-f:\/]+)[ ]+/i", $line, $prefixmatch)) {
$ia_pd = $prefixmatch[1];
continue;
}
if (preg_match("/iaprefix[ ]+([0-9a-f:\/]+)[ ]+/i", $line, $prefixmatch)) {
$ia_pd = $prefixmatch[1];
continue;
}
/* closing bracket */
if(preg_match("/^}/i ", $line)) {
switch($type) {
case "ia-na":
$duid_arr[$duid][$type] = $ia_na;
break;
case "ia-pd":
$duid_arr[$duid][$type] = $ia_pd;
break;
}
unset($type);
unset($duid);
unset($active);
unset($ia_na);
unset($ia_pd);
continue;
}
/* closing bracket */
if (preg_match("/^}/i ", $line)) {
switch ($type) {
case "ia-na":
$duid_arr[$duid][$type] = $ia_na;
break;
case "ia-pd":
$duid_arr[$duid][$type] = $ia_pd;
break;
}
unset($type);
unset($duid);
unset($active);
unset($ia_na);
unset($ia_pd);
continue;
}
}
$routes = array();
foreach ($duid_arr as $entry) {
if($entry['ia-pd'] <> "") {
$routes[$entry['ia-na']] = $entry['ia-pd'];
}
array_shift($duid_arr);
if ($entry['ia-pd'] <> "") {
$routes[$entry['ia-na']] = $entry['ia-pd'];
}
array_shift($duid_arr);
}
// echo "add routes\n";
if(count($routes) > 0) {
foreach ($routes as $address => $prefix) {
echo "/sbin/route change -inet6 {$prefix} {$address}\n";
}
if (count($routes) > 0) {
foreach ($routes as $address => $prefix) {
echo "/sbin/route change -inet6 {$prefix} {$address}\n";
}
}
/* get clog from dhcpd */
$dhcpdlogfile = "/var/log/dhcpd.log";
$clog = array();
if(file_exists($dhcpdlogfile))
exec("clog $dhcpdlogfile", $clog, $ret);
if (file_exists($dhcpdlogfile)) {
exec("clog $dhcpdlogfile", $clog, $ret);
}
if($ret > 0)
$clog = array();
if ($ret > 0) {
$clog = array();
}
$expires = array();
foreach($clog as $line) {
if(preg_match("/releases[ ]+prefix[ ]+([0-9a-f:]+\/[0-9]+)/i", $line, $expire)) {
if(in_array($expire[1], $routes))
continue;
$expires[$expire[1]] = $expire[1];
}
array_shift($clog);
foreach ($clog as $line) {
if (preg_match("/releases[ ]+prefix[ ]+([0-9a-f:]+\/[0-9]+)/i", $line, $expire)) {
if (in_array($expire[1], $routes)) {
continue;
}
$expires[$expire[1]] = $expire[1];
}
array_shift($clog);
}
// echo "remove routes\n";
if(count($expires) > 0) {
foreach ($expires as $prefix) {
echo "/sbin/route delete -inet6 {$prefix['prefix']}\n";
array_shift($expires);
}
if (count($expires) > 0) {
foreach ($expires as $prefix) {
echo "/sbin/route delete -inet6 {$prefix['prefix']}\n";
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