Beispiel #1
0
function get_firmware_version($raw_params)
{
    global $branch;
    // Variables.
    $path_to_files = './xmlrpc/';
    $toreturn = array();
    $working = array();
    $toparse = array();
    $params = array_shift(xmlrpc_params_to_php($raw_params));
    // Branches to track
    $branches = array('stable' => array('stable'), 'beta' => array('stable', 'beta'), 'alpha' => array('stable', 'beta', 'alpha'));
    $platforms = array('pfSense', 'embedded');
    // Version manifest filenames.
    if (!$platforms[$params['platform']]) {
        $params['platform'] = "pfSense";
    }
    $versions = array('firmware' => 'version', 'base' => 'version_base', 'kernel' => 'version_' . $params['platform']);
    // Categories we know about.
    $categories = array('firmware', 'base', 'kernel');
    // Load the version manifests into the versions array and initialize our returned struct.
    foreach ($params as $key => $value) {
        if (isset($versions[$key])) {
            // Filter out other params like "platform"
            $versions[$key] = parse_xml_config($path_to_files . $versions[$key], "pfsenseupdates", $categories);
            $versions[$key] = $versions[$key][$key];
            if (is_array($versions[$key])) {
                // If we successfully parsed the XML, start processing versions
                for ($i = 0; $i < count($versions[$key]); $i++) {
                    if (version_compare($params[$key]['version'], $versions[$key][$i]['version'], "=")) {
                        $toreturn[$key] = array_slice($versions[$key], $i + 1);
                    }
                }
                if (count($toreturn[$key]) < 1) {
                    $toreturn[$key] = $versions[$key];
                }
                // Now that we have the versions we need, find the newest full update.
                $latestfull = 0;
                foreach ($toreturn[$key] as $index => $version) {
                    if (array_key_exists('full', $version)) {
                        $latestfull = $index;
                    }
                }
                $toreturn[$key] = array_slice($toreturn[$key], $latestfull);
                // For the client's convenience toss the latest version of this type into an array.
                $toreturn['latest'][$key] = $toreturn[$key][count($toreturn[$key]) - 1]['version'];
                // Now that we have our base array, process branches.
                $branch = $params['branch'] ? $branches[$params['branch']] : $branches['stable'];
                $toreturn[$key] = array_filter($toreturn[$key], "filter_versions");
                if (count($toreturn[$key]) < 1) {
                    $toreturn[$key] = "latest_in_branch";
                }
            } else {
                $toreturn[$key] = "xml_error";
            }
        }
    }
    $response = XML_RPC_encode($toreturn);
    return new XML_RPC_Response($response);
}
    /* Start in the background so we don't hang up the GUI */
    mwexec_bg("/usr/local/sbin/qstats -p {$g['varrun_path']}/qstats.pid");
    /* Give it a moment to start up */
    sleep(1);
}
$fd = @fsockopen("unix://{$g['varrun_path']}/qstats");
if (!$fd) {
    $error = gettext("Something wrong happened during communication with stat gathering.");
} else {
    $stats = "";
    while (!feof($fd)) {
        $stats .= fread($fd, 4096);
    }
    fclose($fd);
    @file_put_contents("{$g['tmp_path']}/qstats", $stats);
    $altqstats = @parse_xml_config("{$g['tmp_path']}/qstats", array("altqstats"));
    if ($altqstats == -1) {
        $error = gettext("No queue statistics could be read.");
    }
}
if ($_REQUEST['getactivity']) {
    $statistics = array();
    $bigger_stat = 0;
    $stat_type = $_REQUEST['stats'];
    /* build the queue stats. */
    foreach ($altqstats['queue'] as $q) {
        statsQueues($q);
    }
    /* calculate the bigger amount of packets or bandwidth being moved through all queues. */
    if ($stat_type == "0") {
        foreach ($statistics as $q) {
Beispiel #3
0
function grep_log()
{
    global $postfix_dir, $postfix_arg, $config, $g;
    $total_lines = 0;
    $days = array();
    $grep = "\\(MailScanner\\|postfix.cleanup\\|postfix.smtp\\|postfix.error\\|postfix.qmgr\\)";
    $curr_time = time();
    $log_time = strtotime($postfix_arg['time'], $curr_time);
    $m = date('M', strtotime($postfix_arg['time'], $curr_time));
    $j = substr("  " . date('j', strtotime($postfix_arg['time'], $curr_time)), -3);
    # file grep loop
    $maillog_filename = "/var/log/maillog";
    foreach ($postfix_arg['grep'] as $hour) {
        if (!file_exists($maillog_filename) || !is_readable($maillog_filename)) {
            continue;
        }
        print "/usr/bin/grep '^" . $m . $j . " " . $hour . ".*" . $grep . "' {$maillog_filename}\n";
        $lists = array();
        exec("/usr/bin/grep " . escapeshellarg('^' . $m . $j . " " . $hour . ".*" . $grep) . " {$maillog_filename}", $lists);
        foreach ($lists as $line) {
            #check where is first mail record
            if (preg_match("/ delay=(\\d+)/", $line, $delay)) {
                $day = date("Y-m-d", strtotime("-" . $delay[1] . " second", $log_time));
                if (!in_array($day, $days)) {
                    $days[] = $day;
                    create_db($day . ".db");
                    print "Found logs to {$day}.db\n";
                    $stm_queue[$day] = "BEGIN;\n";
                    $stm_noqueue[$day] = "BEGIN;\n";
                }
            } else {
                $day = date("Y-m-d", strtotime($postfix_arg['time'], $curr_time));
                if (!in_array($day, $days)) {
                    $days[] = $day;
                    create_db($day . ".db");
                    print "Found logs to {$day}.db\n";
                    $stm_queue[$day] = "BEGIN;\n";
                    $stm_noqueue[$day] = "BEGIN;\n";
                }
            }
            $status = array();
            $total_lines++;
            #Nov  8 09:31:50 srvch011 postfix/smtpd[43585]: 19C281F59C8: client=pm03-974.auinmem.br[177.70.0.3]
            if (preg_match("/(\\w+\\s+\\d+\\s+[0-9,:]+) (\\w+) postfix.smtpd\\W\\d+\\W+(\\w+): client=(.*)/", $line, $email)) {
                $values = "'" . $email[3] . "','" . $email[1] . "','" . $email[2] . "','" . $email[4] . "'";
                if (${$email[3]} != $email[3]) {
                    $stm_queue[$day] .= 'insert or ignore into mail_from(sid,date,server,client) values (' . $values . ');' . "\n";
                }
                ${$email[3]} = $email[3];
            } else {
                if (preg_match("/(\\w+\\s+\\d+\\s+[0-9,:]+) (\\w+) MailScanner.*Requeue: (\\w+)\\W\\w+ to (\\w+)/", $line, $email)) {
                    $stm_queue[$day] .= "update or ignore mail_from set sid='" . $email[4] . "' where sid='" . $email[3] . "';\n";
                } else {
                    if (preg_match("/(\\w+\\s+\\d+\\s+[0-9,:]+) (\\w+) MailScanner\\W\\d+\\W+\\w+\\s+(\\w+).* is spam, (.*)/", $line, $email)) {
                        $stm_queue[$day] .= "insert or ignore into mail_status (info) values ('spam');\n";
                        print "\n#######################################\nSPAM:" . $email[4] . $email[3] . $email[2] . "\n#######################################\n";
                        $stm_queue[$day] .= "update or ignore mail_to set status=(select id from mail_status where info='spam'), status_info='" . preg_replace("/(\\<|\\>|\\s+|\\'|\")/", " ", $email[4]) . "' where from_id in (select id from mail_from where sid='" . $email[3] . "' and server='" . $email[2] . "');\n";
                    } else {
                        if (preg_match("/(\\w+\\s+\\d+\\s+[0-9,:]+) (\\w+) postfix.\\w+\\W\\d+\\W+(\\w+): to=\\<(.*)\\>, relay=(.*), delay=([0-9,.]+), .* dsn=([0-9,.]+), status=(\\w+) (.*)/", $line, $email)) {
                            $stm_queue[$day] .= "insert or ignore into mail_status (info) values ('" . $email[8] . "');\n";
                            $stm_queue[$day] .= "insert or ignore into mail_to (from_id,too,status,status_info,relay,delay,dsn) values ((select id from mail_from where sid='" . $email[3] . "' and server='" . $email[2] . "'),'" . strtolower($email[4]) . "',(select id from mail_status where info='" . $email[8] . "'),'" . preg_replace("/(\\<|\\>|\\s+|\\'|\")/", " ", $email[9]) . "','" . $email[5] . "','" . $email[6] . "','" . $email[7] . "');\n";
                            $stm_queue[$day] .= "update or ignore mail_to set status=(select id from mail_status where info='" . $email[8] . "'), status_info='" . preg_replace("/(\\<|\\>|\\s+|\\'|\")/", " ", $email[9]) . "', dsn='" . $email[7] . "', delay='" . $email[6] . "', relay='" . $email[5] . "', too='" . strtolower($email[4]) . "' where from_id in (select id from mail_from where sid='" . $email[3] . "' and server='" . $email[2] . "');\n";
                        } else {
                            if (preg_match("/(\\w+\\s+\\d+\\s+[0-9,:]+) (\\w+) postfix.cleanup\\W\\d+\\W+(\\w+): message-id=\\<(.*)\\>/", $line, $email)) {
                                $stm_queue[$day] .= "update mail_from set msgid='" . $email[4] . "' where sid='" . $email[3] . "';\n";
                            } else {
                                if (preg_match("/(\\w+\\s+\\d+\\s+[0-9,:]+) (\\w+) postfix.qmgr\\W\\d+\\W+(\\w+): from=\\<(.*)\\>\\W+size=(\\d+)/", $line, $email)) {
                                    $stm_queue[$day] .= "update mail_from set fromm='" . strtolower($email[4]) . "', size='" . $email[5] . "' where sid='" . $email[3] . "';\n";
                                } else {
                                    if (preg_match("/(\\w+\\s+\\d+\\s+[0-9,:]+) (\\w+) postfix.smtpd\\W\\d+\\W+warning: (\\w+): queue file size limit exceeded/", $line, $email)) {
                                        $stm_queue[$day] .= "insert or ignore into mail_status (info) values ('" . $email[8] . "');\n";
                                        $stm_queue[$day] .= "update mail_to set status=(select id from mail_status where info='reject'), status_info='queue file size limit exceeded' where from_id in (select id from mail_from where sid='" . $email[3] . "' and server='" . $email[2] . "');\n";
                                    } else {
                                        if (preg_match("/(\\w+\\s+\\d+\\s+[0-9,:]+) (\\w+) postfix.cleanup\\W\\d+\\W+(\\w+): (\\w+): (.*) from ([a-z,A-Z,0-9,.,-]+)\\W([0-9,.]+)\\W+from=\\<(.*)\\> to=\\<(.*)\\>.*helo=\\W([a-z,A-Z,0-9,.,-]+)(.*)/", $line, $email)) {
                                            $status['date'] = $email[1];
                                            $status['server'] = $email[2];
                                            $status['sid'] = $email[3];
                                            $status['remote_hostname'] = $email[6];
                                            $status['remote_ip'] = $email[7];
                                            $status['from'] = $email[8];
                                            $status['to'] = $email[9];
                                            $status['helo'] = $email[10];
                                            $status['status'] = $email[4];
                                            $stm_queue[$day] .= "insert or ignore into mail_status (info) values ('" . $email[4] . "');\n";
                                            if ($email[4] == "warning") {
                                                if (${$status['sid']} == 'hold') {
                                                    $status['status'] = 'hold';
                                                } else {
                                                    $status['status'] = 'incoming';
                                                    $stm_queue[$day] .= "insert or ignore into mail_status (info) values ('" . $status['status'] . "');\n";
                                                }
                                                #print "$line\n";
                                                $status['status_info'] = preg_replace("/(\\<|\\>|\\s+|\\'|\")/", " ", $email[11]);
                                                $status['subject'] = preg_replace("/header Subject: /", "", $email[5]);
                                                $status['subject'] = preg_replace("/(\\<|\\>|\\s+|\\'|\")/", " ", $status['subject']);
                                                $stm_queue[$day] .= "update mail_from set subject='" . $status['subject'] . "', fromm='" . strtolower($status['from']) . "',helo='" . $status['helo'] . "' where sid='" . $status['sid'] . "';\n";
                                                $stm_queue[$day] .= "insert or ignore into mail_to (from_id,too,status,status_info) VALUES ((select id from mail_from where sid='" . $email[3] . "' and server='" . $email[2] . "'),'" . strtolower($status['to']) . "',(select id from mail_status where info='" . $status['status'] . "'),'" . $status['status_info'] . "');\n";
                                                $stm_queue[$day] .= "update or ignore mail_to set status=(select id from mail_status where info='" . $status['status'] . "'), status_info='" . $status['status_info'] . "', too='" . strtolower($status['to']) . "' where from_id in (select id from mail_from where sid='" . $status['sid'] . "' and server='" . $email[2] . "');\n";
                                            } else {
                                                ${$status['sid']} = $status['status'];
                                                $stm_queue[$day] .= "update mail_from set fromm='" . strtolower($status['from']) . "',helo='" . $status['helo'] . "' where sid='" . $status['sid'] . "';\n";
                                                $status['status_info'] = preg_replace("/(\\<|\\>|\\s+|\\'|\")/", " ", $email[5] . $email[11]);
                                                $stm_queue[$day] .= "insert or ignore into mail_to (from_id,too,status,status_info) VALUES ((select id from mail_from where sid='" . $email[3] . "' and server='" . $email[2] . "'),'" . strtolower($status['to']) . "',(select id from mail_status where info='" . $email[4] . "'),'" . $status['status_info'] . "');\n";
                                                $stm_queue[$day] .= "update or ignore mail_to set status=(select id from mail_status where info='" . $email[4] . "'), status_info='" . $status['status_info'] . "', too='" . strtolower($status['to']) . "' where from_id in (select id from mail_from where sid='" . $status['sid'] . "' and server='" . $email[2] . "');\n";
                                            }
                                        } else {
                                            if (preg_match("/(\\w+\\s+\\d+\\s+[0-9,:]+) (\\w+) postfix.smtpd\\W\\d+\\W+NOQUEUE:\\s+(\\w+): (.*); from=\\<(.*)\\> to=\\<(.*)\\>.*helo=\\<(.*)\\>/", $line, $email)) {
                                                $status['date'] = $email[1];
                                                $status['server'] = $email[2];
                                                $status['status'] = $email[3];
                                                $status['status_info'] = $email[4];
                                                $status['from'] = $email[5];
                                                $status['to'] = $email[6];
                                                $status['helo'] = $email[7];
                                                $values = "'" . $status['date'] . "','" . $status['status'] . "','" . $status['status_info'] . "','" . strtolower($status['from']) . "','" . strtolower($status['to']) . "','" . $status['helo'] . "','" . $status['server'] . "'";
                                                $stm_noqueue[$day] .= 'insert or ignore into mail_noqueue(date,status,status_info,fromm,too,helo,server) values (' . $values . ');' . "\n";
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if ($total_lines % 1500 == 0) {
                #save log in database
                write_db($stm_noqueue, "noqueue", $days);
                write_db($stm_queue, "from", $days);
                foreach ($days as $d) {
                    $stm_noqueue[$d] = "BEGIN;\n";
                    $stm_queue[$d] = "BEGIN;\n";
                }
            }
            if ($total_lines % 1500 == 0) {
                print "{$line}\n";
            }
        }
        #save log in database
        write_db($stm_noqueue, "noqueue", $days);
        write_db($stm_queue, "from", $days);
        foreach ($days as $d) {
            $stm_noqueue[$d] = "BEGIN;\n";
            $stm_queue[$d] = "BEGIN;\n";
        }
    }
    $config = parse_xml_config("{$g['conf_path']}/config.xml", $g['xml_rootobj']);
    //print count($config['installedpackages']);
    #start db replication if configured
    if ($config['installedpackages']['postfixsync']['config'][0]['rsync']) {
        foreach ($config['installedpackages']['postfixsync']['config'] as $rs) {
            foreach ($rs['row'] as $sh) {
                $sync_to_ip = $sh['ipaddress'];
                $sync_type = $sh['sync_type'];
                $password = $sh['password'];
                print "checking replication to {$sync_to_ip}...";
                if ($password && $sync_to_ip && preg_match("/(both|database)/", $sync_type)) {
                    postfix_do_xmlrpc_sync($sync_to_ip, $password, $sync_type);
                }
                print "ok\n";
            }
        }
    }
}