Пример #1
0
chdir('..');
require_once 'init.inc.php';
$stations = $DB->getAll("SELECT id,name,external_id FROM stations");
foreach ($stations as $station) {
    $prices = fetchStationPrices($station['external_id']);
    if (empty($prices) || !array_key_exists('super', $prices)) {
        continue;
    }
    foreach ($prices as $fuel => $price) {
        //echo "$fuel $price {$station['name']}\n";
        $fuel_id = $DB->getOne("SELECT id FROM fuels WHERE name='" . es($fuel) . "' LIMIT 1");
        if (empty($fuel_id)) {
            $fuel_id = dbInsert('fuels', array('name' => es($fuel)));
        }
        $DB->query("UPDATE prices SET is_latest=0 WHERE fuel_id='" . ei($fuel_id) . "' AND station_id=" . ei($station['id']));
        dbInsert('prices', array('station_id' => ei($station['id']), 'fuel_id' => ei($fuel_id), 'price' => ef($price), 'is_latest' => 1));
        $t = intval(time() / 900) * 900;
        rammsteinUpdateRRD($station['id'], $fuel_id, $price, $t);
    }
}
function fetchStationPrices($station_id)
{
    $url = 'http://www.oeamtc.at/spritapp/ShowGasStation.do?spritaction=show&gsid=' . intval($station_id);
    $html = fetchHtml($url);
    #file_put_contents('dump/'.$station_id.'_'.time().'.html', $html);
    $html = preg_replace("/[\r\n\t ]+/", " ", $html);
    if (!preg_match('#pricesBox.*<tr>.*?Super.*?</tr>.*</div>#', $html, $m)) {
        return false;
    }
    if (!preg_match('#<table class="infoTable stationDetailsInfoTable">.*?</table>#', $m[0], $m)) {
        return false;
Пример #2
0
function parseMaillogLine($line)
{
    global $INCOMING, $DB;
    // date		hostname	service		pid		message
    if (!preg_match('/([a-zA-Z]{3}[ ]+\\d{1,2} \\d{2}:\\d{2}:\\d{2}) ([^ ]*) ([^\\[]*)\\[(\\d*)\\]: (.*)$/', $line, $m)) {
        return false;
    }
    $date = strtotime($m[1]);
    $service = $m[3];
    $msg = $m[5];
    switch ($service) {
        case 'postfix/smtpd':
            if (preg_match('/^([^:]*): client=([^ ]*)/', $msg, $m)) {
                $INCOMINT[$m[1]] = array();
                $INCOMING[$m[1]]['message_id'] = $m[1];
                $INCOMING[$m[1]]['connect'] = $m[2];
                $INCOMING[$m[1]]['arrived'] = $date;
                $INCOMING[$m[1]]['state'] = 'incoming';
            }
            break;
        case 'postfix/cleanup':
            if (preg_match('/^([^:]*): message-id=<([^>]*)>/', $msg, $m)) {
                // vytvorime si v db zaznam o tejto sprave
                try {
                    $mail =& $INCOMING[$m[1]];
                    dbInsert('messages', array('message_id' => es($m[2]), 'processing_id' => es($m[1]), 'state' => 'amavis', 'received' => es($mail['arrived'])));
                } catch (Exception $e) {
                    //echo "$e\n\n";
                    // spravu uz mame v zozname, takze bud niekto spoofuje idcka a my
                    // sa len tak nechame alebo je to druha cast prvej spravy (vysledok z amavisu)
                    $INCOMING[$m[1]]['clone'] = 1;
                }
            }
            // z Cc Bcc a To headerov vykradneme cielove adresy (to_addr)
            if (preg_match('/([^:]*): warning: header (Cc|Bcc|To): ([^\\[]*)\\[/', $msg, $m)) {
                $mail =& $INCOMING[$m[1]];
                if (!preg_match_all('/<[^>]*>/', $m[3], $addrs)) {
                    continue;
                }
                foreach ($addrs as $addr) {
                    $mail['to_addr'] .= $addr[0] . ',';
                }
            }
            break;
        case 'postfix/qmgr':
            // precitame zo spravy pocet prijmatelov, odosielatela a jej velkost
            if (preg_match('/^([^:]*):.*from=<[^>]*>/', $msg, $m)) {
                $id = $m[1];
                // ak je to klonik (nieco co vypadlo z amavisu) tak to nechame tak...
                $mail =& $INCOMING[$id];
                if ($mail['clone']) {
                    continue;
                }
                if (preg_match('/from=([^, ]*)[, ]/', $msg, $m)) {
                    $mail['from_addr'] = $m[1];
                }
                if (preg_match('/size=([\\-\\d]*)/', $msg, $m)) {
                    $mail['size'] = $m[1];
                }
                if (preg_match('/nrcpt=([\\d]*)/', $msg, $m)) {
                    $mail['nrcpt'] = $m[1];
                }
                $DB->query("UPDATE messages SET \n\t\t\t\t\tsize='" . ei($mail['size']) . "', \n\t\t\t\t\tfrom_addr='" . es($mail['from_addr']) . "', \n\t\t\t\t\tto_addr='" . es($mail['to_addr']) . "' \n\t\t\t\tWHERE processing_id='" . es($id) . "'");
            }
            // sprava bola odstranena z queue... odstranime si ju z nasich zoznamov
            // INCOMING a referenciu v DB
            if (preg_match('/^([^:]*): removed/', $msg, $m)) {
                $DB->query("UPDATE messages SET processing_id = NULL WHERE processing_id='" . es($m[1]) . "'");
                unset($INCOMING[$m[1]]);
            }
            break;
        case 'postfix/smtp':
            if (preg_match('/^([^:]*):/', $msg, $m)) {
                $id = $m[1];
                $mail =& $INCOMING[$id];
                // ak sme nepozreli este vsetkych prijimatelov tak nas stale trapia
                /*		if ($mail['nrcpt'] > 0) {
                				if (preg_match('/to=(<[^>]*>)/', $msg, $m))
                					$mail['to_proc'] .= $m[1].',';
                				if (--$mail['nrcpt'] == 0)
                					$DB->query("UPDATE messages SET to_proc='".es($mail['to_proc'])."' WHERE processing_id='".es($id)."'");
                	}*/
                // ak je to lokalny relay (amavis) tak odignorujeme co sa stalo
                if (preg_match('/relay=127.0.0.1/', $msg)) {
                    continue;
                }
                //TODO: inac by sme mali zobrat status=(status) (status_msg)
                if (preg_match('/status=([^ ]*) \\((.*)\\)/', $msg, $m)) {
                    $DB->query("UPDATE messages SET status='" . es($m[1]) . "', status_msg='" . es($m[2]) . "' WHERE processing_id='" . es($id) . "'");
                }
            }
            break;
        case 'amavis':
            if (preg_match('/\\([^\\)]*\\) (Blocked|Passed) ([^,]*).*Message-ID: <([^>]*)>/', $msg, $m)) {
                $action = $m[1];
                $status = $m[2];
                $message_id = $m[3];
                if ($action == 'Blocked') {
                    $state = 'done';
                    $quarantine = '';
                    if (preg_match('/quarantine: ([^ ,]*)[, ]/', $msg, $m)) {
                        $quarantine = $m[1];
                    }
                } else {
                    $state = 'scanned';
                    $queued_as = '';
                    if (preg_match('/queued_as: ([^ ,]*)[, ]/', $msg, $m)) {
                        $queued_as = $m[1];
                    }
                }
                $DB->query("UPDATE messages SET \n\t\t\t\t\tamavis_action='" . es($action) . "', \n\t\t\t\t\tamavis_status='" . es($status) . "', \n\t\t\t\t\tstate='" . es($state) . "',\n\t\t\t\t\tquarantine='" . es($quarantine) . "',\n\t\t\t\t\tprocessing_id='" . es($queued_as) . "'\n\t\t\t\tWHERE message_id='" . es($message_id) . "'");
            }
            break;
    }
    //echo "$line\n";
}
Пример #3
0
#!/usr/bin/env php
<?php 
// fix path
chdir(realpath(dirname(__FILE__)));
chdir('..');
require_once 'init.inc.php';
$fuels = $DB->getAll("SELECT * FROM fuels ORDER BY name ASC");
$stations = $DB->getAll("SELECT * FROM stations ORDER BY name ASC");
foreach ($fuels as $fuel) {
    foreach ($stations as &$station) {
        $prices = $DB->getAll("SELECT * FROM prices WHERE station_id=" . ei($station['id']) . " AND fuel_id=" . ei($fuel['id']) . " ORDER BY ts ASC");
        $start_t = strtotime($prices[0]['ts']) - 450;
        $end_t = strtotime($prices[sizeof($prices) - 1]['ts']);
        echo "start {$start_t}\n";
        rammsteinCreateRRD($station['id'], $fuel['id'], $start_t);
        foreach ($prices as $price) {
            $t = strtotime($price['ts']);
            $t = intval($t / 900) * 900;
            rammsteinUpdateRRD($station['id'], $fuel['id'], $price['price'], $t);
        }
    }
}
Пример #4
0
$fuels = $DB->getAll("SELECT * FROM fuels ORDER BY name ASC");
echo <<<EOT
<br/>
<ul id="navi" class="nav nav-tabs">
EOT;
foreach ($fuels as $fuel) {
    echo '<li role="presentation"><a href="#' . $fuel['name'] . '" aria-controls="' . $fuel['name'] . '" role="tab" data-toggle="tab">' . ucfirst($fuel['name']) . '</a></li>';
}
echo <<<EOT
</ul>
<div class="tab-content">
EOT;
$prev_fuel = '';
$table_opened = false;
foreach ($fuels as $fuel) {
    $prices = $DB->getAll("\n\t\tSELECT ts,price,s.name AS station_name,s.address\n\t\tFROM prices p \n\t\tLEFT JOIN stations s ON p.station_id=s.id\n\t\tWHERE is_latest=1 AND fuel_id=" . ei($fuel['id']) . "\n\t\tORDER BY fuel_id, station_name ASC");
    echo <<<EOT
<div role="tabpanel" class="tab-pane" id="{$fuel['name']}">
<table class="table table-hover">
<thead>
<tr>
<th>Station</th>
<th>EUR/l</th>
<th>Last update</th>
</tr>
</thead>
EOT;
    $lowest = 10;
    foreach ($prices as $price) {
        if ($price['price'] < $lowest) {
            $lowest = $price['price'];