function SEND_MYSQL($sql)
{
    $bd = @mysql_connect(":/var/run/mysqld/mysqld.sock", "root", null);
    if (!$bd) {
        $des = @mysql_error();
        $errnum = @mysql_errno();
        ToSyslog("MySQL error: {$errnum} {$des}");
        return;
    }
    $ok = @mysql_select_db("postfixlog", $bd);
    if (!$ok) {
        $des = @mysql_error();
        $errnum = @mysql_errno();
        ToSyslog("MySQL error: {$errnum} {$des}");
        @mysql_close($bd);
        return;
    }
    $results = @mysql_query($sql, $bd);
    if (!$results) {
        $des = @mysql_error();
        $errnum = @mysql_errno();
        ToSyslog("MySQL error: {$errnum} {$des}");
    }
    @mysql_close($bd);
}
function parse_realtime_events($nopid = false)
{
    events("parse_realtime_events():: nopid => {$nopid}");
    $unix = new unix();
    $TimePID = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid";
    $TimeExec = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".time";
    if (!$nopid) {
        $pid = @file_get_contents($TimePID);
        if ($unix->process_exists($pid)) {
            $timePid = $unix->PROCCESS_TIME_MIN($pid);
            events("parse_realtime_events():: Already process exists {$pid} since {$timePid}Mn");
            if ($timePid > 10) {
                $kill = $unix->find_program("kill");
                events("parse_realtime_events():: Killing {$pid} running since {$timePid}Mn");
                unix_system_kill_force($pid);
            } else {
                if ($GLOBALS["VERBOSE"]) {
                    echo "Already running PID {$pid} since {$timePid}mn";
                }
                die;
            }
        }
        @file_put_contents($TimePID, getmypid());
    }
    events("parse_realtime_events():: Time File: {$TimeExec}");
    @unlink($TimeExec);
    @file_put_contents($TimeExec, time());
    events("Wakup...");
    Wakeup();
    events("parse_realtime_events():: -> parse_realtime_hash()");
    $GLOBALS["PARSE_SECOND_TIME"] = false;
    parse_realtime_hash();
    if (!$GLOBALS["PARSE_SECOND_TIME"]) {
        return;
    }
    @mkdir("/var/log/squid/mysql-queue", 0755, true);
    if (!($handle = opendir("/var/log/squid/mysql-queue"))) {
        return;
    }
    $q = new mysql_squid_builder();
    $q->check_youtube_hour(date("YmdH"));
    $countDeFiles = 0;
    while (false !== ($filename = readdir($handle))) {
        if ($filename == ".") {
            continue;
        }
        if ($filename == "..") {
            continue;
        }
        $filepath = "/var/log/squid/mysql-queue/{$filename}";
        if (preg_match("#^UserAutDB#", $filename)) {
            $content = unserialize(@file_get_contents($filepath));
            $contentSize = filesize($filepath) / 1024;
            $ArraySize = count($content);
            $sql = "INSERT IGNORE INTO UserAutDB (zmd5,MAC,ipaddr,uid,hostname,UserAgent) VALUES " . @implode(",", $content);
            $q->QUERY_SQL($sql);
            if (!$q->ok) {
                echo $q->mysql_error . "\n";
            } else {
                if ($GLOBALS["VERBOSE"]) {
                    echo $filepath . " ({$contentSize} KB) done with {$ArraySize} elements...\n";
                }
                @unlink($filepath);
            }
            continue;
        }
        if (preg_match("#^macscan#", $filename)) {
            $content = unserialize(@file_get_contents($filepath));
            $contentSize = filesize($filepath) / 1024;
            $ArraySize = count($content);
            $sql = "INSERT IGNORE INTO `macscan` (`MAC`,`ipaddr`) VALUES " . @implode(",", $content);
            $q->QUERY_SQL($sql);
            if (!$q->ok) {
                echo $q->mysql_error . "\n";
            } else {
                if ($GLOBALS["VERBOSE"]) {
                    echo $filepath . " ({$contentSize} KB) done with {$ArraySize} elements...\n";
                }
                @unlink($filepath);
            }
            continue;
        }
        if (preg_match("#^YoutubeRTT#", $filename)) {
            $sql = trim(@file_get_contents($filepath));
            $contentSize = strlen($sql) / 1024;
            if (preg_match("#INSERT IGNORE INTO `(.+?)`#", $sql, $re)) {
                $tablename = $re[1];
                if (!preg_match("#youtubehours_([0-9]+)#", $tablename)) {
                    echo "***** replace {$tablename} to youtubehours_date(YmdH) ****\n";
                    $sql = str_replace($tablename, "youtubehours_" . date("YmdH"), $sql);
                }
            }
            $q->QUERY_SQL($sql);
            if (!$q->ok) {
                ToSyslog("{$q->mysql_error} in line [" . __LINE__ . "]");
                if (preg_match("#Table\\s+'.+?\\.youtubehours_(.+?)'\\s+doesn't exist#", $q->mysql_error, $re)) {
                    ToSyslog("Building youtubehours_{$re[1]} table");
                    $q->check_youtube_hour($re[1]);
                    $q->QUERY_SQL($sql);
                }
            }
            if (!$q->ok) {
                ToSyslog("Failed ->{$filename}");
                continue;
            }
            if ($GLOBALS["VERBOSE"]) {
                echo $filepath . " ({$contentSize} KB) done with 1 element...\n";
            }
            @unlink($filepath);
        }
        if (preg_match("#^sizehour_([0-9]+)\\.#", $filename, $re)) {
            $TableSizeHours = "sizehour_{$re[1]}";
            $content = unserialize(@file_get_contents($filepath));
            $contentSize = filesize($filepath) / 1024;
            $q->check_sizehour($TableSizeHours);
            $sql = "INSERT IGNORE INTO `{$TableSizeHours}` (`zDate`,`size`,`cached`) VALUES " . @implode(",", $content);
            $q->QUERY_SQL($sql);
            if (!$q->ok) {
                echo $q->mysql_error . "\n";
            } else {
                if ($GLOBALS["VERBOSE"]) {
                    echo $filepath . " ({$contentSize} KB) done with " . count($content) . " elements...\n";
                }
                @unlink($filepath);
            }
            continue;
        }
        if (preg_match("#^searchwords_([0-9]+)\\.#", $filename, $re)) {
            $TableSource = "searchwords_{$re[1]}";
            $content = unserialize(@file_get_contents($filepath));
            $contentSize = filesize($filepath) / 1024;
            $q->check_SearchWords_hour(null, $TableSource);
            $sql = "INSERT IGNORE INTO `{$TableSource}`\n\t\t(`zmd5`,`sitename`,`zDate`,`ipaddr`,`hostname`,`uid`,`MAC`,`account`,`familysite`,`words`)\n\t\tVALUES " . @implode(",", $content);
            $q->QUERY_SQL($sql);
            if (!$q->ok) {
                echo $q->mysql_error . "\n";
            } else {
                if ($GLOBALS["VERBOSE"]) {
                    echo $filepath . " ({$contentSize} KB) done with " . count($content) . " elements...\n";
                }
                @unlink($filepath);
            }
            continue;
        }
        if (preg_match("#^quotatemp_([0-9]+)\\.#", $filename, $re)) {
            $TableSource = "quotatemp_{$re[1]}";
            $q->check_quota_hour_tmp($re[1]);
            $q->check_quota_hour($re[1]);
            $content = unserialize(@file_get_contents($filepath));
            $contentSize = filesize($filepath) / 1024;
            $sql = "INSERT IGNORE INTO `{$TableSource}` (`xtime`,`keyr`,`ipaddr`,`familysite`,`servername`,`uid`,`MAC`,`size`) VALUES " . @implode(",", $content);
            $q->QUERY_SQL($sql);
            if (!$q->ok) {
                echo $q->mysql_error . "\n";
            } else {
                if ($GLOBALS["VERBOSE"]) {
                    echo $filepath . " ({$contentSize} KB) done with " . count($content) . " elements...\n";
                }
                @unlink($filepath);
            }
            continue;
        }
    }
    events("{$countDeFiles} Scanned files...");
    $php = $unix->LOCATE_PHP5_BIN();
    $nohup = $unix->find_program("nohup");
    $cmd = "{$nohup} {$php} " . __FILE__ . " --tables-primaires >/dev/null 2>&1 &";
    if ($GLOBALS["VERBOSE"]) {
        echo $cmd . "\n";
    }
    shell_exec($cmd);
}
示例#3
0
if (!isset($GLOBALS["UfdbguardSMTPNotifs"]["BLOCK_NOTIFS"])) {
    $GLOBALS["UfdbguardSMTPNotifs"]["BLOCK_NOTIFS"] = 0;
}
if ($GLOBALS["UfdbguardSMTPNotifs"]["ENABLED"] == 0) {
    $GLOBALS["UfdbguardSMTPNotifs"]["BLOCK_NOTIFS"] = 0;
}
events("SMTP Notification: {$GLOBALS["UfdbguardSMTPNotifs"]["ENABLED"]}");
events("Threats Notifications: {$GLOBALS["UfdbguardSMTPNotifs"]["BLOCK_NOTIFS"]}");
events("SQUID_PERFORMANCE: {$GLOBALS["SQUID_PERFORMANCE"]}");
$GLOBALS["RELOADCMD"] = "{$GLOBALS["nohup"]} {$GLOBALS["PHP5_BIN"]} " . dirname(__FILE__) . "/exec.squidguard.php --reload-ufdb";
if ($argv[1] == '--date') {
    echo date("Y-m-d H:i:s") . "\n";
}
@mkdir("{$GLOBALS["ARTICALOGDIR"]}/squid-stats", 0666, true);
@mkdir("{$GLOBALS["ARTICALOGDIR"]}/pagepeeker", 600, true);
ToSyslog("Watchdog started pid {$pid}");
events("ufdbGenTable = {$GLOBALS["ufdbGenTable"]}");
if (!is_dir("/home/ufdb/relatime-events")) {
    @mkdir("/home/ufdb/relatime-events", 0755, true);
}
shell_exec("{$GLOBALS["chown"]} -R squid:squid /home/ufdb/relatime-events");
$pipe = fopen("php://stdin", "r");
while (!feof($pipe)) {
    $buffer .= fgets($pipe, 4096);
    try {
        Parseline($buffer);
    } catch (Exception $e) {
        ufdbguard_admin_events("Fatal error on {$buffer}: " . $e->getMessage(), "MAIN", __FILE__, __LINE__, "ufdbguard-service");
    }
    $buffer = null;
}
function SwapWatchdog()
{
    $sock = new sockets();
    $unix = new unix();
    $MonitConfig = unserialize(base64_decode($sock->GET_INFO("SquidWatchdogMonitConfig")));
    $MonitConfig = watchdog_config_default($MonitConfig);
    $ps = $unix->find_program("ps");
    if ($GLOBALS["VERBOSE"]) {
        echo "\n******** SWAP *******\n";
    }
    if ($MonitConfig["SWAP_MONITOR"] == 0) {
        return;
    }
    include_once dirname(__FILE__) . "/ressources/class.main_cf.inc";
    $sys = new systeminfos();
    $pourc = round($sys->swap_used / $sys->swap_total * 100);
    $freeMemory = $unix->TOTAL_MEMORY_MB_FREE();
    $SwapMemoryused = $sys->swap_used;
    ToSyslog("SwapWatchdog(): {$sys->swap_used}MB used Current {$pourc}% Free Memory: {$freeMemory}MB, min:{$MonitConfig["SWAP_MIN"]}% MAX:{$MonitConfig["SWAP_MAX"]}%");
    if ($pourc < $MonitConfig["SWAP_MIN"]) {
        return;
    }
    if (!isset($MonitConfig["SWAP_MIN"])) {
        $MonitConfig["SWAP_MIN"] = 5;
    }
    if (!isset($MonitConfig["SWAP_MAX"])) {
        $MonitConfig["SWAP_MAX"] = 55;
    }
    $ps_text[] = "There is not enough memory to clean the swap";
    $ps_text[] = "Current configuration was: Free Swap memory over than {$MonitConfig["SWAP_MAX"]}%";
    $ps_text[] = "Your current Swap file using: {$SwapMemoryused}M - {$pourc}% - {$sys->swap_used}/{$sys->swap_total}";
    $ps_text[] = "Memory free on your system:{$freeMemory}M";
    $ps_text[] = "You will find here a snapshot of current tasks";
    $ps_text[] = ps_mem_report();
    $ps_mail = @implode("\n", $ps_text);
    if ($pourc > $MonitConfig["SWAP_MAX"]) {
        if ($SwapMemoryused < $freeMemory) {
            squid_admin_mysql(0, "[ALERT] REBOOT server!!! Swap exceed rule {$pourc}% max: {$MonitConfig["SWAP_MAX"]}%", $ps_mail, __FILE__, __LINE__);
            FailOverDown("Swap exceed rule - reboot - {$pourc}% max:{$MonitConfig["SWAP_MAX"]}%\n{$ps_mail}");
            shell_exec($unix->find_program("shutdown") . " -rF now");
            die;
        }
        squid_admin_mysql(1, "Cleaning SWAP current: {$pourc}% max:{$MonitConfig["SWAP_MAX"]}%", "clean the swap ({$SwapMemoryused}M/{$freeMemory}M)\n{$ps_mail}", __FILE__, __LINE__);
        SwapWatchdog_FreeSync();
        die;
    }
    squid_admin_mysql(1, "Cleaning SWAP current:{$pourc}% min:{$MonitConfig["SWAP_MIN"]}%", "clean the swap ({$SwapMemoryused}M/{$freeMemory}M)\n{$ps_mail}", __FILE__, __LINE__);
    SwapWatchdog_FreeSync();
}
function gencaches_start()
{
    $unix = new unix();
    $min = 10;
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $timefile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    if ($GLOBALS["VERBOSE"]) {
        echo "Time File: {$timefile}\n";
    }
    $pid = @file_get_contents($pidfile);
    if ($GLOBALS["FORCE"]) {
        ToSyslog("gencaches_start(): Executed in --force mode");
    }
    if (!$GLOBALS["FORCE"]) {
        if ($pid < 100) {
            $pid = null;
        }
        $unix = new unix();
        if ($unix->process_exists($pid, basename(__FILE__))) {
            if ($GLOBALS["VERBOSE"]) {
                echo "Already executed pid {$pid}\n";
            }
            ToSyslog("gencaches_start(): already executed pid {$pid}");
            return;
        }
        $timeexec = $unix->file_time_min($timefile);
        if ($timeexec < $min) {
            return;
        }
        $mypid = getmypid();
        @file_put_contents($pidfile, $mypid);
    }
    @unlink($timefile);
    @file_put_contents($timefile, time());
    gencaches();
    gencache_day();
    gencache_hier();
    gencache_TOP();
}
示例#6
0
function restart_routes()
{
    $unix = new unix();
    $php = $unix->LOCATE_PHP5_BIN();
    $nohup = $unix->find_program("nohup");
    ToSyslog("kernel: [  Artica-Net] Start Network [artica-ifup] (" . basename(__FILE__) . "/" . __LINE__ . ")");
    @file_put_contents("/usr/share/artica-postfix/ressources/logs/web/exec.virtuals-ip.php.html", "\n");
    @chmod("/usr/share/artica-postfix/ressources/logs/web/exec.virtuals-ip.php.html", 0777);
    shell_exec("{$nohup} /etc/init.d/artica-ifup routes >> /usr/share/artica-postfix/ressources/logs/web/exec.virtuals-ip.php.html 2>&1 &");
}
示例#7
0
function wifidog_register_perform()
{
    session_start();
    $page = CurrentPageName();
    $autocreate_confirmed = 0;
    if ($GLOBALS["HOTSPOT_DEBUG"]) {
        ToSyslog("Starting wifidog_register_perform()");
    }
    $sock = new sockets();
    $ArticaHotSpotSMTP = SMTP_SETTINGS();
    $email = trim(strtolower($_POST["email"]));
    $q = new mysql_squid_builder();
    $password2 = trim($_POST["password2"]);
    $password = trim($_POST["password"]);
    if ($password2 != $password) {
        return wifidog_register("{password_mismatch}");
    }
    if ($ArticaHotSpotSMTP["ENABLED_SMTP"] == 1) {
        if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
            return wifidog_register("{error_email_invalid}");
        }
        $tr = explode("@", $email);
        $domain = $tr[1];
        if (!checkdnsrr($domain, 'MX')) {
            return wifidog_register("&laquo;{$domain}&raquo;<br>{error_domain_email_invalid}");
        }
    }
    $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT uid FROM hotspot_members WHERE `uid`='{$email}'"));
    $wifidog_build_uri = wifidog_build_uri();
    $uriext = $wifidog_build_uri[0];
    $HiddenFields = $wifidog_build_uri[1];
    if ($ligne["uid"] != null) {
        if ($ArticaHotSpotSMTP["ENABLED_SMTP"] == 1) {
            $link = "<center><a href=\"{$page}?wifidog-recover=yes&{$uriext}\">{lost_password}</a></center>";
        }
        return wifidog_register("{this_account_already_exists}<hr>{$link}");
    }
    $MAC = $_REQUEST["mac"];
    $REGISTER_MAX_TIME = $ArticaHotSpotSMTP["REGISTER_MAX_TIME"];
    $ArticaSplashHotSpotEndTime = $ArticaHotSpotSMTP["ArticaSplashHotSpotEndTime"];
    $password = md5($password);
    $creationtime = time();
    $autocreate_maxttl = $ArticaHotSpotSMTP["REGISTER_MAX_TIME"];
    $sessionkey = md5($password . $creationtime . $email);
    $gateway_addr = $_REQUEST["gw_address"];
    $gw_port = $_REQUEST["gw_port"];
    $gw_id = $_REQUEST["gw_id"];
    $ARP = $_REQUEST["mac"];
    $url = $_REQUEST["url"];
    $token = $_REQUEST["token"];
    if ($ArticaHotSpotSMTP["ENABLED_SMTP"] == 0) {
        $autocreate_confirmed = 1;
    }
    if ($GLOBALS["HOTSPOT_DEBUG"]) {
        ToSyslog("Create new member {$email},{$password},TTL:{$ArticaSplashHotSpotEndTime} in line:" . __LINE__);
    }
    $sql = "INSERT IGNORE INTO hotspot_members \n\t(uid,ttl,sessiontime,password,enabled,creationtime,autocreate,autocreate_confirmed,autocreate_maxttl,sessionkey,MAC) VALUES\n\t('{$email}','{$ArticaSplashHotSpotEndTime}','','{$password}',1,'{$creationtime}',1,'{$autocreate_confirmed}',{$autocreate_maxttl},'{$sessionkey}','{$MAC}')";
    $q->QUERY_SQL($sql);
    if (!$q->ok) {
        if (strpos(" {$q->mysql_error}", "Unknown column") > 0) {
            if ($GLOBALS["HOTSPOT_DEBUG"]) {
                ToSyslog("check_hotspot_tables in line:" . __LINE__);
            }
            $q->check_hotspot_tables();
            if (!$q->ok) {
                if ($GLOBALS["HOTSPOT_DEBUG"]) {
                    ToSyslog("{$q->mysql_error} in line:" . __LINE__);
                }
            }
            $q->QUERY_SQL($sql);
        }
    }
    if (!$q->ok) {
        ToSyslog("{$q->mysql_error}");
        return wifidog_register($q->mysql_error);
    }
    if ($ArticaHotSpotSMTP["ENABLED_SMTP"] == 0) {
        $array["SERVER_NAME"] = $_SERVER["SERVER_NAME"];
        $array["redirecturi"] = $url;
        $array["LOGIN"] = $email;
        $array["redirecturi"] = $_REQUEST["url"];
        $array["REMOTE_ADDR"] = $_REQUEST["ip"];
        $array["token"] = $token;
        $array["HOST"] = $_REQUEST["ip"];
        UnLock($array);
        ToSyslog("wifidog_auth/" . __FUNCTION__ . ":: SESSION(HOTSPOT_REDIRECT_URL) = {$url}");
        $_SESSION["HOTSPOT_AUTO_REGISTER"] = true;
        $_SESSION["HOTSPOT_REDIRECT_URL"] = $url;
        $redirecturi = "http://{$gateway_addr}:{$gw_port}/wifidog/auth?token={$token}";
        ToSyslog("wifidog_auth/" . __FUNCTION__ . ":: Redirect Token: {$token} to {$redirecturi}");
        header("Location: {$redirecturi}");
        return;
    }
    $proto = "http";
    $myHostname = $_SERVER["HTTP_HOST"];
    $page = CurrentPageName();
    if (isset($_SERVER["HTTPS"])) {
        $proto = "https";
    }
    $URL_REDIRECT = "{$proto}://{$myHostname}/{$page}?wifidog-confirm={$sessionkey}";
    $smtp_sender = $ArticaHotSpotSMTP["smtp_sender"];
    if ($ArticaHotSpotSMTP["REGISTER_MESSAGE"] == null) {
        $ArticaHotSpotSMTP["REGISTER_MESSAGE"] = "Hi, in order to activate your account on the HotSpot system,\nclick on the link below";
    }
    if ($ArticaHotSpotSMTP["RECOVER_MESSAGE"] == null) {
        $ArticaHotSpotSMTP["RECOVER_MESSAGE"] = "Hi, in order to recover your password on the HotSpot system,\nclick on the link below";
    }
    if ($ArticaHotSpotSMTP["CONFIRM_MESSAGE"] == null) {
        $ArticaHotSpotSMTP["CONFIRM_MESSAGE"] = "Success\nA message as been sent to you.\nPlease check your WebMail system in order to confirm your registration";
    }
    if ($ArticaHotSpotSMTP["REGISTER_SUBJECT"] == null) {
        $ArticaHotSpotSMTP["REGISTER_SUBJECT"] = "HotSpot account validation";
    }
    $smtp_senderTR = explode("@", $smtp_sender);
    $instance = $smtp_senderTR[1];
    $random_hash = md5(date('r', time()));
    $boundary = "{$random_hash}/{$instance}";
    $body[] = "Return-Path: <{$smtp_sender}>";
    $body[] = "Date: " . date("D, d M Y H:i:s") . " +0100 (CET)";
    $body[] = "From: {$smtp_sender}";
    $body[] = "Subject: {$ArticaHotSpotSMTP["REGISTER_SUBJECT"]}";
    $body[] = "To: {$email}";
    $body[] = "Auto-Submitted: auto-replied";
    $body[] = "MIME-Version: 1.0";
    $body[] = "Content-Type: multipart/mixed;";
    $body[] = "\tboundary=\"{$boundary}\"";
    $body[] = "Content-Transfer-Encoding: 8bit";
    $body[] = "Message-Id: <{$random_hash}@{$instance}>";
    $body[] = "--{$boundary}";
    $body[] = "Content-Description: Notification";
    $body[] = "Content-Type: text/plain; charset=us-ascii";
    $body[] = "";
    $body[] = $ArticaHotSpotSMTP["REGISTER_MESSAGE"];
    $body[] = $URL_REDIRECT;
    $body[] = "";
    $body[] = "";
    $body[] = "--{$boundary}";
    $finalbody = @implode("\r\n", $body);
    $smtp = new smtp();
    if ($ArticaHotSpotSMTP["smtp_auth_user"] != null) {
        $params["auth"] = true;
        $params["user"] = $ArticaHotSpotSMTP["smtp_auth_user"];
        $params["pass"] = $ArticaHotSpotSMTP["smtp_auth_passwd"];
    }
    $params["host"] = $ArticaHotSpotSMTP["smtp_server_name"];
    $params["port"] = $ArticaHotSpotSMTP["smtp_server_port"];
    if (!$smtp->connect($params)) {
        return wifidog_register("{error_while_sending_message} {error} {$smtp->error_number} {$smtp->error_text}");
    }
    if (!$smtp->send(array("from" => $smtp_sender, "recipients" => $email, "body" => $finalbody, "headers" => null))) {
        $smtp->quit();
        return wifidog_register("{error_while_sending_message} {error} {$smtp->error_number} {$smtp->error_text}");
    }
    if ($GLOBALS["HOTSPOT_DEBUG"]) {
        ToSyslog("From: {$smtp_sender} to {$email} {$ArticaHotSpotSMTP["REGISTER_SUBJECT"]} success");
    }
    $smtp->quit();
    if ($GLOBALS["HOTSPOT_DEBUG"]) {
        ToSyslog("wifidog_auth/" . __FUNCTION__ . ":: Token: {$token} -> UnLock(..");
    }
    $array["LOGIN"] = $email;
    $array["ARP"] = $_REQUEST["mac"];
    $array["token"] = $token;
    $array["redirecturi"] = $_REQUEST["url"];
    $array["REMOTE_ADDR"] = $_REQUEST["ip"];
    $array["REGISTER"] = true;
    if (!UnLock($array)) {
        if ($GLOBALS["HOTSPOT_DEBUG"]) {
            ToSyslog("wifidog_auth/" . __FUNCTION__ . "::failed_to_create_session");
        }
        return wifidog_register("{error} {failed_to_create_session}");
    }
    ToSyslog("wifidog_auth/" . __FUNCTION__ . ":: SESSION(HOTSPOT_REDIRECT_URL) = {$url}");
    $_SESSION["HOTSPOT_AUTO_REGISTER"] = true;
    $_SESSION["HOTSPOT_REDIRECT_URL"] = $url;
    $redirecturi = "http://{$gateway_addr}:{$gw_port}/wifidog/auth?token={$token}";
    ToSyslog("wifidog_auth/" . __FUNCTION__ . ":: Redirect Token: {$token} to {$redirecturi}");
    header("Location: {$redirecturi}");
}
function start()
{
    $unix = new unix();
    $pid = getmypid();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pidTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    if ($GLOBALS["VERBOSE"]) {
        echo "pidTime: {$pidTime}\n";
    }
    $pid = @file_get_contents($pidfile);
    if ($unix->process_exists($pid)) {
        if ($pid != $pid) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($time > 120) {
                ToSyslog("killing {$pid}  (line:  Line: " . __LINE__ . ")");
                unix_system_kill_force($pid);
            } else {
                die;
            }
        }
    }
    @file_put_contents($pidfile, getmypid());
    $pidTimeEx = $unix->file_time_min($pidTime);
    if (!$GLOBALS["FORCE"]) {
        if ($pidTimeEx < 240) {
            ToSyslog("Waiting 240mn minimal - current ({$pidTimeEx}Mn)");
            return;
        }
    }
    @unlink($pidTime);
    @file_put_contents($pidTime, time());
    $ARRAY = array();
    $curlftps = $unix->find_program("curlftpfs");
    $pgrep = $unix->find_program("pgrep");
    exec("{$pgrep} -l -f \"{$curlftps}\" 2>&1", $results);
    while (list($index, $line) = each($results)) {
        $line = trim($line);
        if ($line == null) {
            continue;
        }
        $MOUNTED = null;
        $pidtime = 0;
        $pid = 0;
        if (preg_match("#pgrep#", $line)) {
            continue;
        }
        if (preg_match("#^([0-9]+)\\s+(.+)#", $line, $re)) {
            $pid = $re[1];
            $pidtime = $unix->PROCESS_TTL($pid);
            $cmdline = trim($re[2]);
            $cmdline = str_replace($curlftps, "", $cmdline);
            $cmdline = trim($re[2]);
            if ($GLOBALS["VERBOSE"]) {
                echo "Found {$pid} {$pidtime}Mn [{$cmdline}]\n";
            }
            $ARRAY[$pid]["TIME"] = $pidtime;
            if ($GLOBALS["VERBOSE"]) {
                echo "Explode {$cmdline}\n";
            }
            $TR = explode(" ", $cmdline);
            while (list($index2, $bg) = each($TR)) {
                if ($GLOBALS["VERBOSE"]) {
                    echo "Checks {$bg}\n";
                }
                if (substr($bg, 0, 1) == "/") {
                    $MOUNTED = $bg;
                    if ($GLOBALS["VERBOSE"]) {
                        echo "Found {$pid} {$pidtime}Mn mounted on {$bg}\n";
                    }
                    $ARRAY[$pid]["MOUNTED"] = $MOUNTED;
                    break;
                }
            }
        }
    }
    if (count($ARRAY) == 0) {
        return;
    }
    $umount = $unix->find_program("umount");
    while (list($pid, $ar) = each($ARRAY)) {
        $TIME = $ar["TIME"];
        $MOUNTED = $ar["MOUNTED"];
        if ($TIME < 960) {
            continue;
        }
        ToSyslog("Umounting curlftps process id {$pid} mounted on {$MOUNTED} and running since {$TIME}mn, and exceed 960mn");
        shell_exec("{$umount} -l {$MOUNTED}");
        if ($unix->process_exists($pid)) {
            ToSyslog("Killing curlftps process id {$pid}");
            $unix->KILL_PROCESS($pid, 9);
        }
    }
}
示例#9
0
function caches_infos($aspid = false)
{
    $cacheFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    $cachePID = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    if ($GLOBALS["FORCE"]) {
        ToSyslog("caches_infos(): Executed in force mode");
    }
    $unix = new unix();
    $sock = new sockets();
    if (!$GLOBALS["VERBOSE"]) {
        if (system_is_overloaded(basename(__FILE__))) {
            EventsWatchdog("Overloaded system, aborting task...");
            ToSyslog("caches_infos(): Overloaded system, aborting task");
            writelogs("Overloaded system, aborting task...", __FUNCTION__, __FILE__, __LINE__);
            return;
        }
        if ($aspid) {
            $pid = @file_get_contents($cachePID);
            if ($unix->process_exists($pid)) {
                $timepid = $unix->PROCCESS_TIME_MIN($pid);
                if ($timepid < 15) {
                    ToSyslog("caches_infos(): Already task PID: {$pid} running since {$timepid}Mn");
                }
                $kill = $unix->find_program("{$kill}");
                unix_system_kill_force($pid);
            }
        }
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "init...\n";
    }
    $q = new mysql_squid_builder();
    if (!$GLOBALS["FORCE"]) {
        $CacheTime = $unix->file_time_min($cacheFile);
        if ($CacheTime < 15) {
            EventsWatchdog("Max 15Mn, current={$CacheTime} ({$cacheFile})...");
            if ($GLOBALS["VERBOSE"]) {
                echo "Max 15Mn, current={$CacheTime}\n";
            }
            return;
        }
    }
    $squid_pid = SQUID_PID();
    if (!$unix->process_exists($squid_pid)) {
        $nohup = $unix->find_program("nohup");
        squid_admin_mysql(0, "Squid-Cache is not running..., start it", null, __FILE__, __LINE__);
        ToSyslog("caches_infos(): Squid-Cache is not running..., start it");
        shell_exec("{$nohup} /etc/init.d/squid start >/dev/null 2>&1 &");
        return;
    }
    @unlink($cacheFile);
    @file_put_contents($cacheFile, time());
    $ttl = $unix->PROCCESS_TIME_MIN($squid_pid);
    if ($unix->PROCCESS_TIME_MIN($squid_pid) < 5) {
        ToSyslog("caches_infos(): squid-cache running only since {$ttl}mn, aborting");
        return;
    }
    ToSyslog("caches_infos(): Starting get Squid-cache informations.");
    $array = $unix->squid_get_cache_infos();
    for ($i = 0; $i < 10; $i++) {
        $check = true;
        if (!is_array($array)) {
            if ($GLOBALS["VERBOSE"]) {
                echo "unix->squid_get_cache_infos() Not an array...\n";
            }
            $check = false;
            sleep(1);
            $array = $unix->squid_get_cache_infos();
            continue;
        }
        if (count($array) == 0) {
            if ($GLOBALS["VERBOSE"]) {
                echo "unix->squid_get_cache_infos() O items !!\n";
            }
            $check = false;
            sleep(1);
            $array = $unix->squid_get_cache_infos();
            continue;
        }
        if ($check) {
            break;
        }
    }
    if (!is_array($array)) {
        if ($GLOBALS["VERBOSE"]) {
            echo "unix->squid_get_cache_infos() Not an array...\n";
        }
        return;
    }
    if (count($array) == 0) {
        if ($GLOBALS["VERBOSE"]) {
            echo basename(__FILE__) . "[" . __LINE__ . "] unix->squid_get_cache_infos() O items !!...\n";
        }
        @file_put_contents("/usr/share/artica-postfix/ressources/logs/web/squid_get_cache_infos.db", serialize($array));
        @chmod("/usr/share/artica-postfix/ressources/logs/web/squid_get_cache_infos.db", 0755);
        return;
    }
    @unlink("/usr/share/artica-postfix/ressources/logs/web/squid_get_cache_infos.db");
    @file_put_contents("/usr/share/artica-postfix/ressources/logs/web/squid_get_cache_infos.db", serialize($array));
    @chmod("/usr/share/artica-postfix/ressources/logs/web/squid_get_cache_infos.db", 0755);
    $uuid = $unix->GetUniqueID();
    $profix = "INSERT IGNORE INTO cachestatus(uuid,cachedir,maxsize,currentsize,pourc) VALUES ";
    while (list($directory, $arrayDir) = each($array)) {
        $directory = trim($directory);
        if ($directory == null) {
            continue;
        }
        if ($GLOBALS["VERBOSE"]) {
            echo "('{$uuid}','{$directory}','{$arrayDir["MAX"]}','{$arrayDir["CURRENT"]}','{$arrayDir["POURC"]}')\n";
        }
        $f[] = "('{$uuid}','{$directory}','{$arrayDir["MAX"]}','{$arrayDir["CURRENT"]}','{$arrayDir["POURC"]}')";
    }
    if (count($f) > 0) {
        $q->QUERY_SQL("DELETE FROM cachestatus WHERE uuid='{$uuid}'");
        $q->QUERY_SQL("{$profix}" . @implode(",", $f));
        if (!$q->ok) {
            echo $q->mysql_error . "\n";
        }
    }
}
function PushToRepo($filepath)
{
    $curl = "/usr/bin/curl";
    $unix = new unix();
    $ftpass5 = trim(@file_get_contents("/root/ftp-password5"));
    $uri = "ftp://mirror.articatech.net/www.artica.fr/WebfilterDBS";
    $size = round(filesize($filepath) / 1024);
    $ftpass5 = $unix->shellEscapeChars($ftpass5);
    ToSyslog("Push {$filepath} ( {$size} KB ) to {$uri}\n{$curl} -T {$filepath} {$uri}/ --user {$ftpass5}");
    shell_exec("{$curl} -T {$filepath} {$uri}/ --user {$ftpass5}");
}
function load_stats()
{
    events("************************ SCHEDULE ****************************", __FUNCTION__, __LINE__);
    if (!isset($GLOBALS["CLASS_SOCKETS"])) {
        $GLOBALS["CLASS_SOCKETS"] = new sockets();
    }
    if (!isset($GLOBALS["CLASS_UNIX"])) {
        $unix = new unix();
    } else {
        $unix = $GLOBALS["CLASS_UNIX"];
    }
    $array_load = sys_getloadavg();
    $internal_load = $array_load[0];
    $time = time();
    $BASEDIR = "/usr/share/artica-postfix";
    $hash_mem = array();
    $files = $unix->DirFiles("/usr/share/artica-postfix/bin");
    while (list($filename, $line) = each($files)) {
        @chmod("/usr/share/artica-postfix/bin/{$filename}", 0755);
        @chown("/usr/share/artica-postfix/bin/{$filename}", "root");
    }
    @chmod("/usr/share/artica-postfix/ressources/mem.pl", 0755);
    $datas = shell_exec(dirname(__FILE__) . "/mem.pl");
    if (preg_match('#T=([0-9]+) U=([0-9]+)#', $datas, $re)) {
        $ram_used = $re[2];
    }
    @mkdir("/var/log/artica-postfix/sys_loadavg", 0755, true);
    @mkdir("/var/log/artica-postfix/sys_mem", 0755, true);
    @mkdir("/var/log/artica-postfix/sys_alerts", 0755, true);
    @mkdir("/etc/artica-postfix/croned.1", 0755, true);
    @mkdir("/etc/artica-postfix/pids", 0755, true);
    events("Internal Load: {$internal_load} Ram used: {$ram_used}", __FUNCTION__, __LINE__);
    @file_put_contents("/var/log/artica-postfix/sys_loadavg/{$time}", $internal_load);
    @file_put_contents("/var/log/artica-postfix/sys_mem/{$time}", $ram_used);
    $NtpdateAD = intval($GLOBALS["CLASS_SOCKETS"]->GET_INFO("NtpdateAD"));
    $NTPDClientEnabled = intval($GLOBALS["CLASS_SOCKETS"]->GET_INFO("NTPDClientEnabled"));
    if ($NtpdateAD == 1) {
        $NTPDClientEnabled = 1;
    }
    if (system_is_overloaded(basename(__FILE__))) {
        $date = time();
        if (!is_file("/var/log/artica-postfix/sys_alerts/{$date}")) {
            $ps = $unix->find_program("ps");
            $load = $GLOBALS["SYSTEM_INTERNAL_LOAD"];
            if (!$unix->process_exists($GLOBALS["CLASS_UNIX"]->PIDOF_PATTERN("{$ps}"))) {
                $cmd = trim($GLOBALS["nohup"] . " {$GLOBALS["NICE"]} {$ps} auxww >/var/log/artica-postfix/sys_alerts/{$date}-{$load} 2>&1");
                shell_exec($cmd);
            }
        }
    } else {
        if (is_file("/etc/artica-postfix/WEBSTATS_APPLIANCE")) {
            shell_exec_time("exec.squid.php --ping-clients-proxy", 5);
        }
    }
    // NTP CLIENT *****************************************************************************
    if ($NTPDClientEnabled == 1) {
        $time_file = $GLOBALS["CLASS_UNIX"]->file_time_min("/etc/artica-postfix/pids/exec.squid.watchdog.php.start_watchdog.ntp.time");
        $NTPDClientPool = intval($GLOBALS["CLASS_SOCKETS"]->GET_INFO("NTPDClientPool"));
        if ($NTPDClientPool == 0) {
            $NTPDClientPool = 120;
        }
        if ($time_file > $NTPDClientPool) {
            shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.ntpdate.php >/dev/null 2>&1 &");
        }
    }
    // ****************************************************************************************
    $time_file = $GLOBALS["CLASS_UNIX"]->file_time_min("/etc/artica-postfix/pids/exec.syslog-engine.php.load_stats.time");
    if ($time_file > 5) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.syslog-engine.php --load-stats >/dev/null 2>&1 &");
    }
    $time_file = $GLOBALS["CLASS_UNIX"]->file_time_min("/etc/artica-postfix/pids/exec.mpstat.php.time");
    if ($time_file > 1) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.mpstat.php >/dev/null 2>&1 &");
    }
    $time_file = $GLOBALS["CLASS_UNIX"]->file_time_min("/etc/artica-postfix/pids/exec.philesight.php.scan_directories.time");
    if ($time_file > 60) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.philesight.php --directories >/dev/null 2>&1 &");
    }
    $time_file = $GLOBALS["CLASS_UNIX"]->file_time_min("/etc/artica-postfix/pids/exec.seeker.php.xtart.time");
    events("seeker: {$time_file}mn/30mn");
    $GLOBALS["CLASS_UNIX"]->events("seeker: {$time_file}mn/30mn (/etc/artica-postfix/pids/exec.seeker.php.xtart.time)", "/var/log/seeker.log", false, __FUNCTION__, __LINE__, basename(__FILE__));
    if ($time_file > 5) {
        events("************ Executing seeker... ************");
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.seeker.php >/dev/null 2>&1 &");
    }
    $time_file = $GLOBALS["CLASS_UNIX"]->file_time_min("/etc/artica-postfix/croned.1/cron.notifs.php.time");
    if ($time_file > 5) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/cron.notifs.php >/dev/null 2>&1 &");
    }
    $time_file = $GLOBALS["CLASS_UNIX"]->file_time_min("/etc/artica-postfix/pids/exec.cleanfiles.php.time");
    if ($time_file > 120) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.cleanfiles.php >/dev/null 2>&1 &");
    }
    $timefile = $time_file = $GLOBALS["CLASS_UNIX"]->file_time_min("/etc/artica-postfix/pids/exec.clean.logs.php.CleanLogs.time");
    if ($time_file > 240) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.clean.logs.php --clean-tmp >/dev/null 2>&1 &");
    }
    $time_file = $GLOBALS["CLASS_UNIX"]->file_time_min("/etc/artica-postfix/pids/exec.squid.watchdog.php.CHECK_DNS_SYSTEMS.time");
    events("CHECK_DNS_SYSTEMS: {$time_file}mn", __FUNCTION__, __LINE__);
    if ($time_file > 4) {
        $cmd = "{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.watchdog.php --dns >/dev/null 2>&1 &";
        events($cmd, __FUNCTION__, __LINE__);
        shell_exec2("{$cmd}");
    }
    $time_file = $GLOBALS["CLASS_UNIX"]->file_time_min("/etc/artica-postfix/pids/exec.clean.logs.php.clean_space.time");
    events("clean_space: {$time_file}mn", __FUNCTION__, __LINE__);
    if ($time_file > 240) {
        $cmd = "{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.clean.logs.php --clean-space >/dev/null 2>&1 &";
        events($cmd, __FUNCTION__, __LINE__);
        shell_exec2("{$cmd}");
    }
    $kill = $GLOBALS["CLASS_UNIX"]->find_program("kill");
    $pgrep = $GLOBALS["CLASS_UNIX"]->find_program("pgrep");
    exec("pgrep -l -f \"exec.schedules.php --run\" 2>&1", $results);
    while (list($index, $line) = each($results)) {
        if (preg_match("#pgrep#", $line)) {
            continue;
        }
        if (!preg_match("#^([0-9]+)\\s+#", $line, $re)) {
            continue;
        }
        $pid = $re[1];
        $TTL = $GLOBALS["CLASS_UNIX"]->PROCCESS_TIME_MIN($pid);
        events("{$line} -> {$TTL}Mn");
        if ($TTL < 420) {
            continue;
        }
        ToSyslog("Killing exec.schedules.php PID {$pid}");
        unix_system_kill_force($pid);
    }
    events("************************ SCHEDULE ****************************", __FUNCTION__, __LINE__);
}
示例#12
0
function CheckCallable()
{
    include_once dirname(__FILE__) . "/ressources/class.os.system.tools.inc";
    include_once dirname(__FILE__) . "/ressources/class.influx.inc";
    include_once dirname(__FILE__) . "/ressources/class.status.openldap.inc";
    include_once dirname(__FILE__) . "/framework/class.status.hardware.inc";
    include_once dirname(__FILE__) . "/ressources/class.status.ftp-proxy.inc";
    if (!isset($GLOBALS["CLASS_UNIX"])) {
        $GLOBALS["CLASS_UNIX"] = new unix();
    }
    if (!isset($GLOBALS["CLASS_USERS"])) {
        $GLOBALS["CLASS_USERS"] = new settings_inc();
    }
    if (!isset($GLOBALS["CLASS_SOCKETS"])) {
        $GLOBALS["CLASS_SOCKETS"] = new sockets();
    }
    $methodVariable = array($GLOBALS["CLASS_UNIX"], 'GetVersionOf');
    if (!is_callable($methodVariable, true, $callable_name)) {
        ToSyslog("Loading unix class");
        $GLOBALS["CLASS_UNIX"] = new unix();
    }
    $methodVariable = array($GLOBALS["CLASS_UNIX"], 'find_program');
    if (!is_callable($methodVariable, true, $callable_name)) {
        events("Loading unix class");
        $GLOBALS["CLASS_UNIX"] = new unix();
    }
    $methodVariable = array($GLOBALS["CLASS_SOCKETS"], 'GET_INFO');
    if (!is_callable($methodVariable, true, $callable_name)) {
        ToSyslog("Loading socket class");
        $GLOBALS["CLASS_SOCKETS"] = new sockets();
    }
    $methodVariable = array($GLOBALS["CLASS_USERS"], 'BuildLeftMenus');
    if (!is_callable($methodVariable, true, $callable_name)) {
        ToSyslog("Loading usersMenus class");
        $GLOBALS["CLASS_USERS"] = new settings_inc();
    }
    $GLOBALS["OS_SYSTEM"] = new os_system();
    $GLOBALS["MEMORY_INSTALLED"] = $GLOBALS["OS_SYSTEM"]->memory();
    if (is_file("/etc/artica-postfix/amavis.watchdog.cache")) {
        $GLOBALS["AMAVIS_WATCHDOG"] = unserialize(@file_get_contents("/etc/artica-postfix/amavis.watchdog.cache"));
    }
    $GLOBALS["TIME_CLASS"] = time();
    $GLOBALS["ArticaWatchDogList"] = unserialize(base64_decode($GLOBALS["CLASS_SOCKETS"]->GET_INFO("ArticaWatchDogList")));
}
function ufdbguard_blocks_errors($nopid = false)
{
    $unix = new unix();
    if ($nopid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = @file_get_contents($pidfile);
        if ($unix->process_exists($pid)) {
            writelogs("Already running pid {$pid}", __FUNCTION__, __FILE__, __LINE__);
            return;
        }
        $t = 0;
    }
    if (!is_dir("/var/log/artica-postfix/ufdbguard-blocks-errors")) {
        return;
    }
    if (!($handle = opendir("/var/log/artica-postfix/ufdbguard-blocks-errors"))) {
        events_tail("ufdbguard_blocks_errors:: -> glob failed in Line: /var/log/artica-postfix/ufdbguard-blocks-errors " . __LINE__);
        return;
    }
    $q = new mysql_squid_builder();
    while (false !== ($filename = readdir($handle))) {
        if ($filename == ".") {
            continue;
        }
        if ($filename == "..") {
            continue;
        }
        $targetFile = "/var/log/artica-postfix/ufdbguard-blocks-errors/{$filename}";
        $queries = unserialize(@file_get_contents($targetFile));
        if (!is_array($queries)) {
            events_tail("PaseUdfdbGuard:: {$targetFile}, not an array....");
            @unlink($targetFile);
            continue;
        }
        if (!preg_match("#(.+?)\\.([0-9]+)#", $filename, $re)) {
            events_tail("PaseUdfdbGuard:: {$targetFile}, No compatible file");
            @unlink($targetFile);
            continue;
        }
        $tablename = $re[1];
        $q->CheckTablesBlocked_day(0, $tablename);
        $prefix = "INSERT IGNORE INTO `{$tablename}` (`zmd5`,`client`,`website`,`category`,`rulename`,`public_ip`,`why`,`blocktype`,`hostname`,`uid`,`MAC`,`uri`,`zDate`) VALUES ";
        if (!$q->QUERY_SQL($prefix . @implode(",", $queries))) {
            ToSyslog("Fatal line " . __LINE__ . " " . $q->mysql_error);
            $time = $unix->file_time_min($targetFile);
            if ($time > 5760) {
                @unlink($targetFile);
            }
            continue;
        }
        @unlink($targetFile);
    }
}
function clean_empty_tables()
{
    $unix = new unix();
    ///etc/artica-postfix/pids/exec.squid.stats.hours.php.clean_empty_tables.time
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $timefile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    if ($GLOBALS["VERBOSE"]) {
        echo "Time File: {$timefile}\n";
    }
    $pid = @file_get_contents($pidfile);
    if ($GLOBALS["FORCE"]) {
        ToSyslog("macscan(): Executed in --force mode");
    }
    if (!$GLOBALS["FORCE"]) {
        if ($pid < 100) {
            $pid = null;
        }
        $unix = new unix();
        if ($unix->process_exists($pid, basename(__FILE__))) {
            if ($GLOBALS["VERBOSE"]) {
                echo "Already executed pid {$pid}\n";
            }
            ToSyslog("clean_empty_tables(): already executed pid {$pid}");
            return;
        }
        $timeexec = $unix->file_time_min($timefile);
        if ($timeexec < 30) {
            return;
        }
        $mypid = getmypid();
        @file_put_contents($pidfile, $mypid);
    }
    @unlink($timefile);
    @file_put_contents($timefile, time());
    $q = new mysql_squid_builder();
    $TABLES = $q->LIST_TABLES_HOURS_TEMP();
    $current = "squidhour_" . date("YmdH");
    while (list($tablename, $none) = each($TABLES)) {
        if ($tablename == $current) {
            continue;
        }
        if ($q->COUNT_ROWS($tablename) > 0) {
            continue;
        }
        $q->QUERY_SQL("DROP TABLE `{$tablename}`");
    }
    $TABLES = $q->LIST_TABLES_SIZEHOURS();
    $current = "sizehour_" . date("YmdH");
    while (list($tablename, $none) = each($TABLES)) {
        if ($tablename == $current) {
            continue;
        }
        if ($q->COUNT_ROWS($tablename) > 0) {
            continue;
        }
        $q->QUERY_SQL("DROP TABLE `{$tablename}`");
    }
    $TABLES = $q->LIST_TABLES_dansguardian_events();
    $current = " dansguardian_events_" . date("Ymd");
    while (list($tablename, $none) = each($TABLES)) {
        if ($tablename == $current) {
            continue;
        }
        if ($q->COUNT_ROWS($tablename) > 0) {
            continue;
        }
        $q->QUERY_SQL("DROP TABLE `{$tablename}`");
    }
}
function load_stats()
{
    events("************************ SCHEDULE ****************************", __FUNCTION__, __LINE__);
    if (!isset($GLOBALS["CLASS_SOCKETS"])) {
        $GLOBALS["CLASS_SOCKETS"] = new sockets();
    }
    if (!isset($GLOBALS["CLASS_UNIX"])) {
        $unix = new unix();
    } else {
        $unix = $GLOBALS["CLASS_UNIX"];
    }
    $time = time();
    $BASEDIR = "/usr/share/artica-postfix";
    $hash_mem = array();
    @mkdir("/var/log/artica-postfix/sys_alerts", 0755, true);
    $NtpdateAD = intval($GLOBALS["CLASS_SOCKETS"]->GET_INFO("NtpdateAD"));
    $NTPDClientEnabled = intval($GLOBALS["CLASS_SOCKETS"]->GET_INFO("NTPDClientEnabled"));
    $SquidPerformance = intval($GLOBALS["CLASS_SOCKETS"]->GET_INFO("SquidPerformance"));
    if ($NtpdateAD == 1) {
        $NTPDClientEnabled = 1;
    }
    // NTP CLIENT *****************************************************************************
    if ($NTPDClientEnabled == 1) {
        $time_file = $GLOBALS["CLASS_UNIX"]->file_time_min("/etc/artica-postfix/pids/exec.squid.watchdog.php.start_watchdog.ntp.time");
        $NTPDClientPool = intval($GLOBALS["CLASS_SOCKETS"]->GET_INFO("NTPDClientPool"));
        if ($NTPDClientPool == 0) {
            $NTPDClientPool = 120;
        }
        if ($time_file > $NTPDClientPool) {
            shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.ntpdate.php >/dev/null 2>&1 &");
        }
    }
    // ****************************************************************************************
    $time_file = $GLOBALS["CLASS_UNIX"]->file_time_min("/etc/artica-postfix/pids/exec.syslog-engine.php.load_stats.time");
    events("exec.syslog-engine.php --load-stats = {$time_file}/5mn");
    if ($time_file > 5) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.syslog-engine.php --load-stats >/dev/null 2>&1 &");
    }
    // ****************************************************************************************
    $time_file = $GLOBALS["CLASS_UNIX"]->file_time_min("/etc/artica-postfix/pids/exec.philesight.php.scan_directories.time");
    if ($time_file > 60) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.philesight.php --directories >/dev/null 2>&1 &");
    }
    // ****************************************************************************************
    $time_file = $GLOBALS["CLASS_UNIX"]->file_time_min("/etc/artica-postfix/pids/exec.seeker.php.xtart.time");
    events("seeker: {$time_file}mn/30mn");
    $GLOBALS["CLASS_UNIX"]->events("seeker: {$time_file}mn/30mn (/etc/artica-postfix/pids/exec.seeker.php.xtart.time)", "/var/log/seeker.log", false, __FUNCTION__, __LINE__, basename(__FILE__));
    if ($time_file > 5) {
        events("************ Executing seeker... ************");
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.seeker.php >/dev/null 2>&1 &");
    }
    $time_file = $GLOBALS["CLASS_UNIX"]->file_time_min("/etc/artica-postfix/croned.1/cron.notifs.php.time");
    if ($time_file > 5) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/cron.notifs.php >/dev/null 2>&1 &");
    }
    $time_file = $GLOBALS["CLASS_UNIX"]->file_time_min("/etc/artica-postfix/pids/exec.cleanfiles.php.time");
    if ($time_file > 120) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.cleanfiles.php >/dev/null 2>&1 &");
    }
    $timefile = $time_file = $GLOBALS["CLASS_UNIX"]->file_time_min("/etc/artica-postfix/pids/exec.clean.logs.php.CleanLogs.time");
    if ($time_file > 240) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.clean.logs.php --clean-tmp >/dev/null 2>&1 &");
    }
    $time_file = $GLOBALS["CLASS_UNIX"]->file_time_min("/etc/artica-postfix/pids/exec.squid.watchdog.php.CHECK_DNS_SYSTEMS.time");
    events("CHECK_DNS_SYSTEMS: {$time_file}mn", __FUNCTION__, __LINE__);
    $time_file = $GLOBALS["CLASS_UNIX"]->file_time_min("/etc/artica-postfix/pids/exec.clean.logs.php.clean_space.time");
    events("clean_space: {$time_file}mn", __FUNCTION__, __LINE__);
    if ($time_file > 240) {
        $cmd = "{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.clean.logs.php --clean-space >/dev/null 2>&1 &";
        events($cmd, __FUNCTION__, __LINE__);
        shell_exec2("{$cmd}");
    }
    $kill = $GLOBALS["CLASS_UNIX"]->find_program("kill");
    $pgrep = $GLOBALS["CLASS_UNIX"]->find_program("pgrep");
    exec("pgrep -l -f \"exec.schedules.php --run\" 2>&1", $results);
    while (list($index, $line) = each($results)) {
        if (preg_match("#pgrep#", $line)) {
            continue;
        }
        if (!preg_match("#^([0-9]+)\\s+#", $line, $re)) {
            continue;
        }
        $pid = $re[1];
        $TTL = $GLOBALS["CLASS_UNIX"]->PROCCESS_TIME_MIN($pid);
        events("{$line} -> {$TTL}Mn");
        if ($TTL < 420) {
            continue;
        }
        ToSyslog("Killing exec.schedules.php PID {$pid}");
        unix_system_kill_force($pid);
    }
    events("************************ SCHEDULE ****************************", __FUNCTION__, __LINE__);
}
示例#16
0
function artica_ifup()
{
    $unix = new unix();
    $nohup = $unix->find_program("nohup");
    ToSyslog("kernel: [  Artica-Net] start Network [artica-ifup] (" . basename(__FILE__) . "/" . __LINE__ . ")");
    shell_exec("{$nohup} /etc/init.d/artica-ifup start --script=system.php/artica_ifup >/dev/null 2>&1 &");
}
示例#17
0
function start($aspid = false)
{
    $unix = new unix();
    if (is_file("/etc/artica-postfix/FROM_ISO")) {
        if ($unix->file_time_min("/etc/artica-postfix/FROM_ISO") < 1) {
            return;
        }
    }
    $sock = new sockets();
    if (!$aspid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = $unix->get_pid_from_file($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    if (!is_file("/etc/modprobe.d/blacklist-floppy.conf")) {
        @mkdir("/etc/modprobe.d", 0755, true);
        $rmmod = $unix->find_program("rmmod");
        $update_initframs = $unix->find_program("update-initramfs");
        @file_put_contents("/etc/modprobe.d/blacklist-floppy.conf", "blacklist floppy\n");
        shell_exec("{$rmmod} floppy");
        shell_exec("{$update_initframs} -u >/dev/null 2>&1 &");
    }
    $EnableArticaFrontEndToNGninx = $sock->GET_INFO("EnableArticaFrontEndToNGninx");
    $EnableArticaFrontEndToApache = $sock->GET_INFO("EnableArticaFrontEndToApache");
    if (!is_numeric($EnableArticaFrontEndToNGninx)) {
        $EnableArticaFrontEndToNGninx = 0;
    }
    if (!is_numeric($EnableArticaFrontEndToApache)) {
        $EnableArticaFrontEndToApache = 0;
    }
    $EnableNginx = $sock->GET_INFO("EnableNginx");
    $EnableFreeWeb = $sock->GET_INFO("EnableFreeWeb");
    if (!is_numeric($EnableFreeWeb)) {
        $EnableFreeWeb = 0;
    }
    if (!is_numeric($EnableNginx)) {
        $EnableNginx = 1;
    }
    if ($EnableNginx == 0) {
        $EnableArticaFrontEndToNGninx = 0;
    }
    $unix->CleanOldLibs();
    $chmod = $unix->find_program("chmod");
    @mkdir("/etc/artica-postfix/settings/Daemons", 0755, true);
    shell_exec("{$chmod} -R 0755 /etc/artica-postfix/settings >/dev/null 2>&1");
    $sock = new sockets();
    $DisableForceFCK = intval($sock->GET_INFO("DisableForceFCK"));
    @unlink("/forcefsck");
    if ($DisableForceFCK == 0) {
        @touch("/forcefsck");
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} EnableArticaFrontEndToNGninx:{$EnableArticaFrontEndToNGninx}\n";
    }
    $pid = LIGHTTPD_PID();
    if ($EnableArticaFrontEndToNGninx == 1) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} transfered to Nginx..\n";
        }
        if ($unix->process_exists($pid)) {
            ToSyslog("Stopping artica-webinterface service using lighttpd (transfered to Nginx)...");
            stop(true);
            apache_stop();
        }
        shell_exec("/etc/init.d/nginx start");
        return;
    }
    if ($EnableArticaFrontEndToApache == 1) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Transfered to Apache..\n";
        }
        if ($unix->process_exists($pid)) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Stopping Lighttpd PID {$pid}\n";
            }
            ToSyslog("Stopping artica-webinterface service using lighttpd (transfered to Apache)...");
            stop(true);
        }
        $apachebin = $unix->LOCATE_APACHE_BIN_PATH();
        if (is_file($apachebin)) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Starting Apache Mode...\n";
            }
            apache_start();
        }
        return;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} transfered to lighttpd..\n";
    }
    $GLOBALS["SERVICE_NAME"] = "Artica lighttpd service";
    $pid = LIGHTTPD_PID();
    if ($unix->process_exists($pid)) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} {$GLOBALS["SERVICE_NAME"]} already started {$pid} since {$timepid}Mn...\n";
        }
        return;
    }
    ToSyslog("Starting artica-webinterface service using lighttpd...");
    $nohup = $unix->find_program("nohup");
    $php5 = $unix->LOCATE_PHP5_BIN();
    $rm = $unix->find_program("rm");
    $lighttpd_bin = $unix->find_program("lighttpd");
    $LIGHTTPD_CONF_PATH = LIGHTTPD_CONF_PATH();
    @mkdir("/var/run/lighttpd", 0755, true);
    @mkdir("/var/log/lighttpd", 0755, true);
    $cmd = "{$nohup} {$php5} /usr/share/artica-postfix/exec.web-community-filter.php --register-lic >/dev/null 2>&1 &";
    if ($GLOBALS["VERBOSE"]) {
        echo "{$cmd}\n";
    }
    shell_exec($cmd);
    buildConfig();
    $cmd = "{$lighttpd_bin} -f {$LIGHTTPD_CONF_PATH}";
    if ($GLOBALS["VERBOSE"]) {
        echo "{$cmd}\n";
    }
    shell_exec($cmd);
    for ($i = 0; $i < 8; $i++) {
        $pid = LIGHTTPD_PID();
        if ($unix->process_exists($pid)) {
            break;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} waiting {$i}/8...\n";
        }
        sleep(1);
    }
    $pid = LIGHTTPD_PID();
    if ($unix->process_exists($pid)) {
        ToSyslog("{$GLOBALS["SERVICE_NAME"]} Success service started pid:{$pid}");
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Success service started pid:{$pid}...\n";
        }
        shell_exec("{$php5} /usr/share/artica-postfix/exec.apc.compile.php");
        if (!is_file('/etc/init.d/artica-memcache')) {
            shell_exec("{$php5} /usr/share/artica-postfix/exec.initslapd.php --memcache");
        }
        shell_exec("{$nohup} {$php5} /usr/share/artica-postfix/exec.initslapd.php --phppfm-restart-back >/dev/null 2>&1 &");
        shell_exec("{$nohup} /etc/init.d/artica-memcached start >/dev/null 2>&1 &");
        shell_exec("{$nohup} /etc/init.d/monit restart >/dev/null 2>&1 &");
        $APACHE_SRC_ACCOUNT = $unix->APACHE_SRC_ACCOUNT();
        $APACHE_SRC_GROUP = $unix->APACHE_SRC_GROUP();
        $unix->chown_func($APACHE_SRC_ACCOUNT, $APACHE_SRC_GROUP, "/var/lib/php5/*");
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} failed...\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$cmd}\n";
        }
    }
}
示例#18
0
function reconfigure_restart_network()
{
    $unix = new unix();
    $php = $unix->LOCATE_PHP5_BIN();
    $nohup = $unix->find_program("nohup");
    ToSyslog("kernel: [  Artica-Net] reconfigure Network [artica-ifup] (" . basename(__FILE__) . "/" . __LINE__ . ")");
    $cmd = trim("/etc/init.d/artica-ifup reconfigure");
    shell_exec("{$nohup} /etc/init.d/artica-ifup reconfigure --script=cmd.php/reconfigure_restart_network >/dev/null 2>&1 &");
}
示例#19
0
function stop($aspid = false)
{
    $unix = new unix();
    if (!$aspid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = $unix->get_pid_from_file($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($GLOBALS["OUTPUT"]) {
                echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $pid = PID_NUM();
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service already stopped...\n";
        }
        return;
    }
    $pid = PID_NUM();
    $nohup = $unix->find_program("nohup");
    $php5 = $unix->LOCATE_PHP5_BIN();
    $kill = $unix->find_program("kill");
    if ($GLOBALS["OUTPUT"]) {
        echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service Shutdown pid {$pid}...\n";
    }
    ToSyslog("Shutdown {$GLOBALS["TITLENAME"]} service");
    unix_system_kill($pid);
    for ($i = 0; $i < 5; $i++) {
        Killing();
    }
    $pid = PID_NUM();
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service success...\n";
        }
        return;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service shutdown - force - pid {$pid}...\n";
    }
    unix_system_kill_force($pid);
    if ($unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service failed...\n";
        }
        return;
    }
}
示例#20
0
function pack_error($text, $function, $line)
{
    $logFile = "/var/log/apache2/proxy.pack.error";
    $servername = $_SERVER["SERVER_NAME"];
    $from = $_SERVER["REMOTE_ADDR"];
    $lineToSave = date('H:i:s') . " [{$servername}] {$GLOBALS["IPADDR"]}: {$text} function {$function} line {$line}";
    $LineToSyslog = "[{$servername}] {$GLOBALS["IPADDR"]}: {$text} function {$function} line {$line}";
    if (is_file($logFile)) {
        $size = @filesize($logFile);
        if ($size > 900000) {
            @unlink($logFile);
        }
    }
    $f = @fopen($logFile, 'a');
    if (!$f) {
        ToSyslog($LineToSyslog);
        return;
    }
    @fwrite($f, "{$lineToSave}\n");
    @fclose($f);
}
示例#21
0
function UcarpDown()
{
    if (!$GLOBALS["CORP_LICENSE"]) {
        return;
    }
    if ($GLOBALS["UCARP_MASTER"] == null) {
        return;
    }
    $downfile = "/usr/share/ucarp/vip-{$GLOBALS["UCARP_MASTER"]}-down.sh";
    if (!is_file($downfile)) {
        return;
    }
    ToSyslog("Shutdown VIP {$GLOBALS["UCARP_MASTER"]}");
    shell_exec("{$GLOBALS["nohup"]} {$downfile} >/dev/null 2>&1 &");
}
示例#22
0
function BuildArticaInNginx()
{
    $sock = new sockets();
    $unix = new unix();
    $BuildFrameWorkInNginx = false;
    $EnableArticaFrontEndToNGninx = intval($sock->GET_INFO("EnableArticaFrontEndToNGninx"));
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx, EnableArticaFrontEndToNGninx = {$EnableArticaFrontEndToNGninx}\n";
    }
    if ($EnableArticaFrontEndToNGninx == 0) {
        return;
    }
    $SargOutputDir = $sock->GET_INFO("SargOutputDir");
    if ($SargOutputDir == null) {
        $SargOutputDir = "/var/www/html/squid-reports";
    }
    if (!is_dir($SargOutputDir)) {
        @mkdir($SargOutputDir, 0755, true);
    }
    if (!is_file("{$SargOutputDir}/logo.gif")) {
        @copy("/usr/share/artica-postfix/css/images/logo.gif", "{$SargOutputDir}/logo.gif");
    }
    if (!is_file("{$SargOutputDir}/pattern.png")) {
        @copy("/usr/share/artica-postfix/css/images/pattern.png", "{$SargOutputDir}/pattern.png");
    }
    $phpfpm = $unix->APACHE_LOCATE_PHP_FPM();
    $EnablePHPFPM = $sock->GET_INFO("EnablePHPFPM");
    $EnableArticaApachePHPFPM = $sock->GET_INFO("EnableArticaApachePHPFPM");
    if (!is_numeric($EnableArticaApachePHPFPM)) {
        $EnableArticaApachePHPFPM = 0;
    }
    if ($EnableArticaApachePHPFPM == 0) {
        $EnablePHPFPM = 0;
    }
    $EnableSargGenerator = $sock->GET_INFO("EnableSargGenerator");
    if (!is_numeric($EnableSargGenerator)) {
        $EnableSargGenerator = 1;
    }
    if (!is_numeric($EnablePHPFPM)) {
        $EnablePHPFPM = 0;
    }
    if (!is_file($phpfpm)) {
        $EnablePHPFPM = 0;
    }
    if ($EnablePHPFPM == 1) {
        ToSyslog("Restarting PHP5-FPM");
        shell_exec("/etc/init.d/php5-fpm reload >/dev/null 2>&1");
    }
    $host = new nginx("0.0.0.0:9000");
    $host->set_ssl();
    $host->set_proxy_disabled();
    $host->set_DocumentRoot("/usr/share/artica-postfix");
    $host->set_index_file("admin.index.php");
    $host->build_proxy();
    $lighttpdbin = $unix->find_program("lighttpd");
    if (!is_file($lighttpdbin)) {
        $BuildFrameWorkInNginx = true;
    }
    if (is_file("/etc/artica-postfix/WORDPRESS_APPLIANCE")) {
        $BuildFrameWorkInNginx = true;
    }
    if ($EnableSargGenerator == 1) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx, SARG is enabled...\n";
        }
        $host->SargDir();
        $host->build_proxy();
    }
    if ($BuildFrameWorkInNginx) {
        if (is_file("/etc/php5/fpm/pool.d/framework.conf")) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx, building framework...\n";
            }
            $host = new nginx(47980);
            $host->set_proxy_disabled();
            $host->set_DocumentRoot("/usr/share/artica-postfix/framework");
            $host->set_framework();
            $host->set_listen_ip("127.0.0.1");
            $host->set_servers_aliases(array("127.0.0.1"));
            $host->build_proxy();
        }
    }
}
示例#23
0
function start($aspid = false)
{
    $unix = new unix();
    $sock = new sockets();
    $Masterbin = "/usr/share/artica-postfix/bin/process1";
    if (!is_file($Masterbin)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, process1 not installed\n";
        }
        return;
    }
    if (!$aspid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = $unix->get_pid_from_file($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $pid = PID_NUM();
    if ($unix->process_exists($pid)) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Service already started {$pid} since {$timepid}Mn...\n";
        }
        return;
    }
    $nohup = $unix->find_program("nohup");
    if (is_file("/etc/artica-postfix/artica-as-rebooted")) {
        if (!is_file("/etc/artica-postfix/process1-first-executed")) {
            $cmd = "{$nohup} {$Masterbin} --force --" . time() . " >/dev/null 2>&1 &";
            ToSyslog("Running {$Masterbin} after reboot");
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service\n";
            }
            @touch("/etc/artica-postfix/process1-first-executed");
            return;
        }
    }
    $timeFile = "process1.executed.time";
    $Time = $unix->file_time_get($timeFile);
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} TTL {$Time}Mn\n";
    }
    if ($Time < 2) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Need to wait..\n";
        }
        return;
    }
    $cmd = "{$nohup} {$Masterbin} --force --" . time() . " >/dev/null 2>&1 &";
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service\n";
    }
    ToSyslog("Running {$Masterbin}");
    shell_exec($cmd);
    $unix->file_time_set($timeFile);
    for ($i = 1; $i < 15; $i++) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} waiting {$i}/5\n";
        }
        sleep(5);
        $pid = PID_NUM();
        if (!$unix->process_exists($pid)) {
            break;
        }
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Success\n";
    }
}