Exemplo n.º 1
0
// Last record in DB
$sth = $DB->dbh->prepare("SELECT LogDate, LogTime FROM FmAccessLog ORDER BY LogDate DESC, LogTime DESC LIMIT 1");
$sth->execute();
if ($sth->errorInfo()[1]) {
    printLogAndDie("DB error: " . $sth->errorInfo()[2]);
}
if ($lastRecord = $sth->fetch(PDO::FETCH_ASSOC)) {
    $lastRecDateTime = $lastRecord['LogDate'] . ' ' . $lastRecord['LogTime'];
}
// Prepare list of log files to parse
$log2Parse = array();
// List of log files to parse
$lastDateTime = '';
// Last record in log file (we'll select older record among several log files)
foreach (array('FM_ACCESS_LOG', 'FM_EVENT_LOG') as $log) {
    $myLastDateTime = getDateFromLog(readLastLine($CONFIG[$log]));
    // Read date/time of the last record in log
    if (!$lastDateTime || $lastDateTime > $myLastDateTime) {
        $lastDateTime = $myLastDateTime;
        // Select older record among several log files
    }
    $firstDateTime = getDateFromLog(readFirstLine($CONFIG[$log]));
    // Read date/time of the first record in log
    if ($lastRecDateTime < $firstDateTime && array_key_exists($log . '_ROTATE', $CONFIG) && $CONFIG[$log . '_ROTATE']) {
        $LOG->message("Additionally parse previous log: " . $CONFIG[$log . '_ROTATE']);
        $log2Parse[] = $CONFIG[$log . '_ROTATE'];
    }
    $log2Parse[] = $CONFIG[$log];
}
// Parse log files
foreach ($log2Parse as $logFile) {
Exemplo n.º 2
0
if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] == $_SERVER['PHP_SELF']) {
    header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found', true, 404);
    exit;
}
if (!file_exists("main.php")) {
    return;
}
#Tell main we are calling it
define('Sprinklers', TRUE);
#Source required files
require_once "main.php";
#Update log files
$datetime = Date("Y-m-d H:i:s", time());
$settings = get_settings();
$rainSenseStatus = $settings["rs"];
$rainDelayStatus = $settings["rd"];
$newSprinklerValveSettings = implode("", get_station_status());
$oldSprinklerValveSettings = explode("--", readLastLine($log_file));
if ($newSprinklerValveSettings != $oldSprinklerValveSettings[0] || (!isset($oldSprinklerValveSettings[2]) || $rainSenseStatus != $oldSprinklerValveSettings[2]) || (!isset($oldSprinklerValveSettings[3]) || $rainDelayStatus != $oldSprinklerValveSettings[3])) {
    file_put_contents($log_file, $newSprinklerValveSettings . "--" . $datetime . "--" . $rainSenseStatus . "--" . $rainDelayStatus . "\n", FILE_APPEND);
}
$tz = $settings["tz"] - 48;
$tz = ($tz >= 0 ? "+" : "-") . abs($tz) / 4 * 60 * 60 + (abs($tz) % 4 * 15 / 10 . abs($tz) % 4 * 15 % 10 * 60);
#Automatically turn off manual mode daily, if enabled
if ($auto_mm && date('H', time() + $tz) == "00" && date('i') == "00" && $settings["mm"] == 1 && intval($newSprinklerValveSettings) == 0) {
    send_to_os("/cv?pw=&mm=0");
}
#Automatic rain delay, every hour, if enabled
if ($auto_delay && date('i') == "00") {
    weather_to_delay();
}