Example #1
0
function scan_stored_items($nopid = true)
{
    $sock = new sockets();
    $SquidPerformance = intval($sock->GET_INFO("SquidPerformance"));
    if ($SquidPerformance < 3) {
        die;
    }
    $unix = new unix();
    if (system_is_overloaded(basename(__FILE__))) {
        $php = $unix->LOCATE_PHP5_BIN();
        ufdbguard_admin_events("Overloaded system... ask to run this task later...", __FUNCTION__, __FILE__, __LINE__, "proxy");
        $unix->THREAD_COMMAND_SET("{$php} " . __FILE__ . " --scan");
    }
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pidTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    if ($nopid) {
        $pid = @file_get_contents($pidfile);
        $myfile = basename(__FILE__);
        if ($unix->process_exists($pid, $myfile)) {
            ufdbguard_admin_events("Task already running PID: {$pid}, aborting current task", __FUNCTION__, __FILE__, __LINE__, "proxy");
            return;
        }
    }
    $TimePid = $unix->file_time_min($pidTime);
    if ($TimePid < 1440) {
        ufdbguard_admin_events("Task cannot be used less than 14h currently ({$TimePid}Mn)", __FUNCTION__, __FILE__, __LINE__, "proxy");
        return;
    }
    if (ScanPurgeexc()) {
        ufdbguard_admin_events("Already Executed...", __FUNCTION__, __FILE__, __LINE__, "proxy");
        return;
    }
    @unlink($pidTime);
    @file_put_contents($pidTime, time());
    $mypid = getmypid();
    @file_put_contents($pidfile, $mypid);
    $purge = $unix->find_program("purge");
    if (strlen($purge) < 5) {
        ufdbguard_admin_events("purge no such file, aborting task", __FUNCTION__, __FILE__, __LINE__, "proxy");
        return;
    }
    $nice = EXEC_NICE();
    $cmd = "{$nice}{$purge} -c /etc/squid3/squid.conf -e \".\" -P 0 -n >/var/cache/purge.calculated.db 2>&1";
    if ($GLOBALS["VERBOSE"]) {
        echo $cmd . "\n";
    }
    $t1 = time();
    system(trim($cmd));
    $took = $unix->distanceOfTimeInWords($t1, time());
    if ($GLOBALS["VERBOSE"]) {
        echo "done {$took}\n";
    }
    squid_admin_mysql(2, "Stored items: Extracting items information from cache done took:{$took}", null, __FILE__, __LINE__, "proxy");
    inject_stored_items(true);
}
Example #2
0
function parse_logs()
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pidTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    if (!$GLOBALS["VERBOSE"]) {
        if ($unix->file_time_min($pidTime) < 45) {
            return;
        }
    }
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        return;
    }
    @file_put_contents($pidfile, getmypid());
    @unlink($pidTime);
    @file_put_contents($pidTime, time());
    $sock = new sockets();
    $EnableNginxStats = $sock->GET_INFO("EnableNginxStats");
    if (!is_numeric($EnableNginxStats)) {
        $EnableNginxStats = 0;
    }
    if ($EnableNginxStats == 0) {
        return;
    }
    if (system_is_overloaded(basename(__FILE__))) {
        events("Overloaded system: {$GLOBALS["SYSTEM_INTERNAL_LOAD"]} aborting", __FUNCTION__, __LINE__);
        return;
    }
    $nice = EXEC_NICE();
    $sock = new sockets();
    $kill = $unix->find_program("kill");
    $NginxWorkLogsDir = $sock->GET_INFO("NginxWorkLogsDir");
    if ($NginxWorkLogsDir == null) {
        $NginxWorkLogsDir = "/home/nginx/logsWork";
    }
    $sys = new mysql_storelogs();
    $files = $unix->DirFiles($NginxWorkLogsDir, "-([0-9\\-]+)\\.log");
    while (list($filename, $line) = each($files)) {
        if (!preg_match("#^(.+?)-[0-9]+-[0-9]+-[0-9]+-[0-9]+\\.log\$#", $filename, $re)) {
            if ($GLOBALS["VERBOSE"]) {
                echo "{$filename}, skip\n";
            }
            continue;
        }
        $servername = $re[1];
        $fullpath = "{$NginxWorkLogsDir}/{$filename}";
        ParseFile($servername, $fullpath);
    }
    $php = $unix->LOCATE_PHP5_BIN();
    $nohup = $unix->find_program("nohup");
    shell_exec("{$nohup} {$php} " . __FILE__ . " --hosts >/dev/null 2>&1 &");
    shell_exec("{$nohup} {$php} " . dirname(__FILE__) . "/exec.nginx-stats-day.php >/dev/null 2>&1 &");
}
function ScanFile($toScan)
{
    if (!$GLOBALS["SAMBA_INSTALLED"]) {
        return true;
    }
    $localdatabase = "/usr/share/artica-postfix/LocalDatabases";
    $file = @file_get_contents($toScan);
    $ext = Get_extension($file);
    $nice = EXEC_NICE();
    $database = "{$localdatabase}/samba.db";
    if (!is_file($GLOBALS["omindex"])) {
        return true;
    }
    $directory = dirname($file);
    if ($GLOBALS["DIRS"]["{$directory}"]) {
        return true;
    }
    $basename = basename($file);
    $cmd = "{$nice}{$GLOBALS["omindex"]} -l 1 --follow -D {$database} -U \"{$directory}\" \"{$directory}\"";
    $GLOBALS["DIRS"]["{$directory}"] = true;
    exec($cmd, $results);
    ParseLogs($results);
    return true;
}
function Execute()
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $myFile = basename(__FILE__);
    $pid = @file_get_contents($pidfile);
    if ($unix->process_exists($pid, $myFile)) {
        WriteMyLogs("Already executed PID:{$pid}, die()", __FUNCTION__, __FILE__, __LINE__);
        die;
    }
    $cachetime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    $q = new mysql_squid_builder();
    if ($q->COUNT_ROWS("framework_orders") == 0) {
        if ($GLOBALS["VERBOSE"]) {
            echo "Table framework_orders as no row\n";
        }
        die;
    }
    $php5 = $unix->LOCATE_PHP5_BIN();
    $nice = EXEC_NICE();
    $q = new mysql_squid_builder();
    $results = $q->QUERY_SQL("SELECT * FROM framework_orders");
    if (!$q->ok) {
        if (strpos($q->mysql_error, "doesn't exist") > 0) {
            $q->CheckTables();
            $results = $q->QUERY_SQL("SELECT * FROM framework_orders");
        }
    }
    if (!$q->ok) {
        ufdbguard_admin_events("Fatal: {$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "framework");
        die;
    }
    $reconfigure_plugins = false;
    while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) {
        if ($GLOBALS["VERBOSE"]) {
            echo "ORDER: {$ligne["ORDER"]} -> {$ligne["zmd5"]}\n";
        }
        if (preg_match("#COMPILEDB:(.+)#", $ligne["ORDER"], $re)) {
            if (preg_match("#english-(.+)#", $re[1])) {
                $q->QUERY_SQL("DELETE FROM framework_orders WHERE zmd5='{$ligne["zmd5"]}'");
                continue;
            }
            ufdbguard_admin_events("LAUNCH: category {$re[1]} compilation", __FUNCTION__, __FILE__, __LINE__, "framework");
            $re[1] = trim($re[1]);
            $table = "category_" . $q->category_transform_name($re[1]);
            if ($GLOBALS["VERBOSE"]) {
                echo "order to compile database {$re[1]} (table {$table})\n";
            }
            if (!$q->TABLE_EXISTS($table)) {
                ufdbguard_admin_events("Fatal: {$table} no suche table, create it", __FUNCTION__, __FILE__, __LINE__, "framework");
                $q->CreateCategoryTable(null, $table);
            }
            $cmd = "{$nice} {$php5} /usr/share/artica-postfix/exec.squidguard.php --compile-category \"{$re[1]}\"";
            if ($GLOBALS["VERBOSE"]) {
                echo "{$cmd}\n";
            }
            $q->QUERY_SQL("DELETE FROM framework_orders WHERE zmd5='{$ligne["zmd5"]}'");
            if (!$q->ok) {
                ufdbguard_admin_events("Fatal: {$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "framework");
                die;
            }
            shell_exec($cmd);
            $reconfigure_plugins = true;
        }
    }
    if ($reconfigure_plugins) {
        ufdbguard_admin_events("LAUNCH: filters reconfiguration", __FUNCTION__, __FILE__, __LINE__, "framework");
        shell_exec("{$nice} {$php5} /usr/share/artica-postfix/exec.squidguard.php --build");
    }
}
Example #5
0
function homes()
{
    $GLOBALS["INDEXED"] = 0;
    $GLOBALS["SKIPPED"] = 0;
    $GLOBALS["DIRS"] = array();
    $FOLDERS = array();
    $RFOLDERS = array();
    $unix = new unix();
    $GLOBALS["omindex"] = $unix->find_program("omindex");
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid)) {
        system_admin_events("Already instance executed pid:{$olpid}", __FUNCTION__, __FILE__, __LINE__, "xapian");
        die;
    }
    @file_put_contents($pidfile, getmypid());
    $nice = EXEC_NICE();
    $t1 = time();
    if (!is_file($GLOBALS["omindex"])) {
        system_admin_events("omindex no such binary, aborting", __FUNCTION__, __FILE__, __LINE__, "xapian");
        return;
    }
    $ldap = new clladp();
    $attr = array("homeDirectory", "uid", "dn");
    $pattern = "(&(objectclass=sambaSamAccount)(uid=*))";
    $sock = new sockets();
    $sock = new sockets();
    $sr = @ldap_search($ldap->ldap_connection, "dc=organizations," . $ldap->suffix, $pattern, $attr);
    $hash = ldap_get_entries($ldap->ldap_connection, $sr);
    $sock = new sockets();
    for ($i = 0; $i < $hash["count"]; $i++) {
        $uid = $hash[$i]["uid"][0];
        $homeDirectory = $hash[$i][strtolower("homeDirectory")][0];
        if ($uid == null) {
            writelogs("uid is null, SKIP ", __FUNCTION__, __FILE__, __LINE__);
            continue;
        }
        if ($uid == "nobody") {
            writelogs("uid is nobody, SKIP ", __FUNCTION__, __FILE__, __LINE__);
            continue;
        }
        if ($uid == "root") {
            writelogs("uid is root, SKIP ", __FUNCTION__, __FILE__, __LINE__);
            continue;
        }
        if (substr($uid, strlen($uid) - 1, 1) == '$') {
            writelogs("{$uid}:This is a computer, SKIP ", __FUNCTION__, __FILE__, __LINE__);
            continue;
        }
        if ($homeDirectory == null) {
            $homeDirectory = "/home/{$uid}";
        }
        if (!is_dir($homeDirectory)) {
            continue;
        }
        $FOLDERS[$uid] = $homeDirectory;
        $RFOLDERS[$homeDirectory] = true;
    }
    $SambaXapianAuth = unserialize(base64_decode($sock->GET_INFO("SambaXapianAuth")));
    $username = $SambaXapianAuth["username"];
    $password = $SambaXapianAuth["password"];
    $domain = $SambaXapianAuth["domain"];
    $comp = $SambaXapianAuth["ip"];
    if (!isset($SambaXapianAuth["lang"])) {
        $SambaXapianAuth["lang"] == "none";
    }
    $lang = $SambaXapianAuth["lang"];
    if ($lang == null) {
        $lang = "none";
    }
    $t1 = time();
    $dirs = $unix->dirdir("/home");
    $samba = new samba();
    $localdatabase = "/usr/share/artica-postfix/LocalDatabases";
    while (list($dir, $ligne) = each($dirs)) {
        if ($dir == "/home/export") {
            continue;
        }
        if ($dir == "/home/netlogon") {
            continue;
        }
        if ($dir == "/home/artica") {
            continue;
        }
        if ($dir == "/home/logs-backup") {
            continue;
        }
        if (isset($RFOLDERS[$dir])) {
            continue;
        }
        if (isset($samba->main_shared_folders[$dir])) {
            continue;
        }
        $FOLDERS[basename($dir)] = $dir;
    }
    $count = 0;
    while (list($uid, $directory) = each($FOLDERS)) {
        $BaseUrl = $directory;
        $database = "{$localdatabase}/xapian-{$uid}";
        @mkdir($database, 0755, true);
        if (!is_dir($directory)) {
            system_admin_events("{$directory}, no such directory", __FUNCTION__, __FILE__, __LINE__, "xapian");
            continue;
        }
        $t = time();
        $cmd = "{$nice}{$GLOBALS["omindex"]} -l 0 -s {$lang} -E 512 -m 60M --follow -D \"{$database}\" -U \"{$BaseUrl}\" \"{$directory}\" -v 2>&1";
        if ($GLOBALS["VERBOSE"]) {
            echo "{$cmd}\n";
        }
        $results_scan = array();
        exec($cmd, $results_scan);
        $dirRes = ParseLogs($results_scan);
        $took = $unix->distanceOfTimeInWords($t, time(), true);
        $count++;
        system_admin_events("scanned {$directory} took {$took} indexed:{$dirRes[0]} skipped:{$dirRes[1]}", __FUNCTION__, __FILE__, __LINE__, "xapian");
    }
    $took = $unix->distanceOfTimeInWords($t1, time(), true);
    system_admin_events("scanned {$count} directorie(s) took {$took}", __FUNCTION__, __FILE__, __LINE__, "xapian");
}
Example #6
0
function execute_mysql($OnlyID = 0)
{
    $GLOBALS["INDEXED"] = 0;
    $GLOBALS["SKIPPED"] = 0;
    $GLOBALS["DIRS"] = array();
    $unix = new unix();
    $httrack = $unix->find_program("httrack");
    if (!is_file($httrack)) {
        system_admin_events("httrack no such binary", __FUNCTION__, __FILE__, __LINE__, "webcopy");
        return;
    }
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        system_admin_events("Already instance executed pid:{$olpid}", __FUNCTION__, __FILE__, __LINE__, "webcopy");
        return;
    }
    $getmypid = getmypid();
    @file_put_contents($pidfile, $getmypid);
    $q = new mysql();
    $nice = EXEC_NICE();
    $sql = "SELECT * FROM httrack_sites WHERE enabled=1";
    $results = $q->QUERY_SQL($sql, "artica_backup");
    if (!$q->ok) {
        system_admin_events("Fatal: {$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "webcopy");
        return;
    }
    $t1 = time();
    $count = 0;
    if ($OnlyID > 0) {
        $ligne2 = mysql_fetch_array($q->QUERY_SQL("SELECT sitename FROM httrack_sites WHERE ID={$OnlyID}", "artica_backup"));
        $log_exp = " only for [{$ligne2["sitename"]}] ";
    }
    system_admin_events("Starting executing WebCopy task {$log_exp} pid:{$getmypid}", __FUNCTION__, __FILE__, __LINE__, "webcopy");
    while ($ligne = mysql_fetch_assoc($results)) {
        if ($OnlyID > 0) {
            if ($ligne["ID"] != $OnlyID) {
                continue;
            }
        }
        $t = time();
        $count++;
        $workingdir = $ligne["workingdir"];
        $sitename = $ligne["sitename"];
        $maxsize = $ligne["maxsize"];
        $minrate = $ligne["minrate"];
        $maxfilesize = $ligne["maxfilesize"];
        $maxsitesize = $ligne["maxsitesize"];
        $maxfilesize = $maxfilesize * 1000;
        $maxsitesize = $maxsitesize * 1000;
        $minrate = $minrate * 1000;
        $update = null;
        $resultsCMD = array();
        if (!is_dir($workingdir)) {
            @mkdir($workingdir, 0755, true);
        }
        if (is_file("{$workingdir}/hts-cache")) {
            $update = " --update";
        }
        $cmdline = "{$httrack} \"{$sitename}\" --quiet{$update} --max-files={$maxfilesize} --max-size={$maxsitesize} --max-rate={$minrate} -O \"{$workingdir}\" 2>&1";
        if ($GLOBALS["VERBOSE"]) {
            echo "{$cmdline}\n";
        }
        exec($cmdline, $resultsCMD);
        if ($GLOBALS["VERBOSE"]) {
            echo @implode("\n", $resultsCMD);
        }
        $dirsize = $unix->DIRSIZE_BYTES($workingdir);
        $took = $unix->distanceOfTimeInWords($t, time(), true);
        $dirsizeText = round($dirsize / 1024 / 1000, 2);
        system_admin_events("{$sitename} scrapped took {$took} size={$dirsizeText} MB", __FUNCTION__, __FILE__, __LINE__, "webcopy");
        $q->QUERY_SQL("UPDATE httrack_sites SET size='{$dirsize}' WHERE ID={$ligne["ID"]}", "artica_backup");
    }
    $took = $unix->distanceOfTimeInWords($t1, time(), true);
    system_admin_events("{$count} web sites scrapped took {$took}", __FUNCTION__, __FILE__, __LINE__, "webcopy");
}
Example #7
0
function scanarp()
{
    $GLOBALS["CLASS_USERS"] = new usersMenus();
    $GLOBALS["CLASS_SOCKETS"] = new sockets();
    if (!$GLOBALS["CLASS_USERS"]->ARPD_INSTALLED) {
        if ($GLOBALS["VERBOSE"]) {
            echo __FUNCTION__ . " ARPD_INSTALLED = FALSE\n";
        }
        return;
    }
    $EnableArpDaemon = $GLOBALS["CLASS_SOCKETS"]->GET_INFO("EnableArpDaemon");
    if (!is_numeric($EnableArpDaemon)) {
        $EnableArpDaemon = 1;
    }
    if ($EnableArpDaemon == 0) {
        if ($GLOBALS["VERBOSE"]) {
            echo __FUNCTION__ . " EnableArpDaemon = {$EnableArpDaemon}\n";
        }
        return;
    }
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid";
    $unix = new unix();
    $me = basename(__FILE__);
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, $me)) {
        if ($GLOBALS["VERBOSE"]) {
            echo " {$pid} --> Already executed.. aborting the process\n";
        }
        $time = $unix->PROCCESS_TIME_MIN($pid);
        system_admin_events("Already executed pid {$pid} since {$time}Mn.. aborting the process", __FUNCTION__, __FILE__, __LINE__, "system");
        die;
    }
    @file_put_contents($pidfile, getmypid());
    if (!is_file("/var/lib/arpd/arpd.db")) {
        die;
    }
    $GLOBALS["CLASS_UNIX"] = $unix;
    $GLOBALS["nmblookup"] = $unix->find_program("nmblookup");
    $GLOBALS["arpd"] = $unix->find_program("arpd");
    $GLOBALS["arp"] = $unix->find_program("arp");
    $GLOBALS["ARP_DB"] = "/var/lib/arpd/arpd.db";
    $GLOBALS["CACHE_DB"] = "/etc/artica-postfix/arpd.cache";
    $GLOBALS["EnableMacAddressFilter"] = trim(@file_get_contents("/etc/artica-postfix/settings/Daemons/EnableMacAddressFilter"));
    if (!is_numeric($GLOBALS["EnableMacAddressFilter"])) {
        $GLOBALS["EnableMacAddressFilter"] = 1;
    }
    $squidbin = $unix->LOCATE_SQUID_BIN();
    if (is_file($squidbin)) {
        if ($GLOBALS["EnableMacAddressFilter"] == 0) {
            return;
        }
    }
    $ArpdArray = unserialize(base64_decode(@file_get_contents($GLOBALS["CACHE_DB"])));
    if ($GLOBALS["FLUSH"]) {
        $ArpdArray = array();
    }
    if (!is_array($ArpdArray)) {
        $ArpdArray = array();
    }
    if (!isset($ArpdArray["LAST"])) {
        $ArpdArray["LAST"] = 0;
    }
    $last_modified = filemtime($GLOBALS["ARP_DB"]);
    $TimeArpd = $ArpdArray["LAST"];
    if ($TimeArpd == $last_modified) {
        events("{$TimeArpd} -> {$last_modified} No modification time", __FUNCTION__, __LINE__);
        return;
    }
    events("Scanning ARP table....", __FUNCTION__, __LINE__);
    $ArpdArray["LAST"] = $last_modified;
    exec("{$GLOBALS["arpd"]} -l 2>&1", $results);
    events("{$GLOBALS["arpd"]} -l return " . count($results) . " element(s)", __FUNCTION__, __LINE__);
    while (list($num, $ligne) = each($results)) {
        if (preg_match("#unexpected file type or format#", $ligne)) {
            @unlink($GLOBALS["ARP_DB"]);
            @unlink($GLOBALS["CACHE_DB"]);
            shell_exec("/etc/init.d/arpd restart");
            die;
        }
        if (!preg_match("#^[0-9]+\\s+\\s+(.+?)\\s+(.+)#", $ligne, $re)) {
            if ($GLOBALS["VERBOSE"]) {
                echo "line: {$num}, unexpected line..\n";
            }
            continue;
        }
        if (preg_match("#FAILED:#", $re[2])) {
            continue;
        }
        $mac = $re[2];
        $ipaddr = $re[1];
        if ($GLOBALS["VERBOSE"]) {
            echo "line: {$num}, MAC:{$mac} -> {$ipaddr}\n";
        }
        if (isset($ArpdArray["MACS"][$mac])) {
            if ($GLOBALS["VERBOSE"]) {
                echo "MAC:{$mac} Already cached, aborting....\n";
            }
            continue;
        }
        $ArpdArray["MACS"][$mac] = true;
        $cmp = new computers();
        $uid = $cmp->ComputerIDFromMAC($mac);
        if ($GLOBALS["VERBOSE"]) {
            echo "line: {$num}, MAC:{$mac} -> {$uid}\n";
        }
        if ($uid == null) {
            $res2 = array();
            $computer_name = null;
            events("It is time to add {$mac}/{$ipaddr} in database", __FUNCTION__, __LINE__);
            exec("{$GLOBALS["arp"]} -a {$ipaddr} 2>&1", $res2);
            if (preg_match("#^(.+?)\\s+\\(#", trim(@implode("", $res2)), $rz)) {
                $computer_name = $rz[1];
            }
            if (strlen($computer_name) < 3) {
                $computer_name = $ipaddr;
            }
            $cmp->uid = "{$computer_name}\$";
            $cmp->ComputerIP = $ipaddr;
            $cmp->ComputerMacAddress = $mac;
            system_admin_events("adding/editing {$computer_name} with MAC:{$mac}", __FUNCTION__, __FILE__, __LINE__, "network");
            $cmp->Add();
        } else {
            if ($GLOBALS["FLUSH"]) {
                $res2 = array();
                $cmp = new computers($uid);
                $computer_name = null;
                events("It is time to edit {$uid}/{$mac}/{$ipaddr} in database", __FUNCTION__, __LINE__);
                exec("{$GLOBALS["arp"]} -a {$ipaddr} 2>&1", $res2);
                if ($GLOBALS["VERBOSE"]) {
                    echo "{$GLOBALS["arp"]} -a {$ipaddr} 2>&1 = >" . trim(@implode("", $res2));
                }
                if (preg_match("#^(.+?)\\s+\\(#", trim(@implode("", $res2)), $rz)) {
                    $computer_name = $rz[1];
                } else {
                    if ($GLOBALS["VERBOSE"]) {
                        echo "Unable to find computer name\n";
                    }
                }
                if (strlen($computer_name) < 3) {
                    $computer_name = $ipaddr;
                }
                if ($GLOBALS["VERBOSE"]) {
                    echo "line: {$num}, UID:{$mac} -> {$uid}\n";
                }
                if ($GLOBALS["VERBOSE"]) {
                    echo "line: {$num}, NAME:{$computer_name} -> {$uid}\n";
                }
                system_admin_events("adding/editing {$computer_name} with MAC:{$mac}", __FUNCTION__, __FILE__, __LINE__, "network");
                $cmp->ComputerIP = $ipaddr;
                $cmp->ComputerMacAddress = $mac;
                $cmp->Add();
            }
        }
        if (system_is_overloaded(basename(__FILE__))) {
            @file_put_contents($GLOBALS["CACHE_DB"], base64_encode(serialize($ArpdArray)));
            system_admin_events("Overloaded system, aborting the task...", __FUNCTION__, __FILE__, __LINE__, "network");
            return;
        }
        @file_put_contents($GLOBALS["CACHE_DB"], base64_encode(serialize($ArpdArray)));
        $nice = EXEC_NICE();
        $unix = new unix();
        $nohup = $unix->find_program("nohup");
        $php5 = $unix->LOCATE_PHP5_BIN();
        shell_exec("{$nohup} {$nice} {$php5} " . __FILE__ . " --tomysql schedule-id={$GLOBALS["SCHEDULE_ID"]} >/dev/null 2>&1 &");
    }
}
Example #8
0
function DirectorySize()
{
    $unix = new unix();
    $pid_path = "/etc/artica-postfix/pids/" . __FILE__ . "." . __FUNCTION__;
    $oldpid = @file_get_contents($pid_path);
    if ($unix->process_exists($oldpid)) {
        die;
    }
    $childpid = posix_getpid();
    @file_put_contents($pid_path, $childpid);
    $filetim = file_time_min("/etc/artica-postfix/croned.1/" . __FILE__ . "." . __FUNCTION__);
    if ($filetim < 240) {
        die;
    }
    $partition_default = $unix->IMAPD_GET("partition-default");
    artica_mysql_events("Starting calculate - {$partition_default} - disk size", null, __FILE__, "mailbox");
    if (strlen($partition_default) < 3) {
        return;
    }
    if (!is_dir($partition_default)) {
        return;
    }
    $GLOBALS["NICE"] = EXEC_NICE();
    $du_bin = $unix->find_program("du");
    exec("{$GLOBALS["NICE"]}{$du_bin} -h -s {$partition_default} 2>&1", $results);
    $r = implode("", $results);
    if (preg_match("#^(.+?)\\s+#", $r, $re)) {
        $sock = new sockets();
        $sock->SET_INFO("CyrusImapPartitionDefaultSize", $re[1]);
        send_email_events("Mailboxes size on your server: {$re['1']}", "Mailboxes size on your server: {$re['1']}", "mailbox");
        if ($partition_default == "/var/spool/cyrus/mail") {
            $sock->SET_INFO("CyrusImapPartitionDefaultDirSize", $re[1]);
            return;
        }
        unset($results);
        exec("{$GLOBALS["NICE"]}{$du_bin} -h -s /var/spool/cyrus/mail 2>&1", $results);
        $r = implode("", $results);
        if (preg_match("#^(.+?)\\s+#", $r, $re)) {
            $sock->SET_INFO("CyrusImapPartitionDefaultDirSize", $re[1]);
        }
    }
}
Example #9
0
function CheckUserCount()
{
    $unix = new unix();
    $cachefile = "/etc/artica-postfix/UsersNumber";
    $php = $unix->LOCATE_PHP5_BIN();
    $nohup = $unix->find_program("nohup");
    $nice = EXEC_NICE();
    if (!is_file($cachefile)) {
        shell_exec("{$nohup} {$nice} {$php} /usr/share/artica-postfix/exec.samba.php --users >/dev/null 2>&1 &");
        return 0;
    }
    $usersN = @file_get_contents($cachefile);
    if ($unix->file_time_min($cachefile) > 3600) {
        @unlink($cachefile);
        shell_exec("{$nohup} {$nice} {$php} /usr/share/artica-postfix/exec.samba.php --users >/dev/null 2>&1 &");
        return $usersN;
    }
    return $usersN;
}
Example #10
0
function ParseLoadQeues()
{
    $unix = new unix();
    $du = $unix->find_program("du");
    $rm = $unix->find_program("rm");
    $EXEC_NICE = EXEC_NICE();
    exec("{$EXEC_NICE}{$du} -b -s /etc/artica-postfix/loadavg.queue 2>&1", $results);
    $tmp = trim(@implode("", $results));
    if (preg_match("#[0-9]+\\s+#", $tmp, $re)) {
        $size = $re[1] / 1024;
        $size = $size / 1000;
        if ($size > 100) {
            shell_exec("/bin/rm -rf /etc/artica-postfix/loadavg.queue/*");
            return;
        }
    }
    if (!is_dir('/etc/artica-postfix/loadavg.queue')) {
        @mkdir("/etc/artica-postfix/loadavg.queue", true);
    }
    if ($handle = opendir("/etc/artica-postfix/loadavg.queue")) {
        while (false !== ($file = readdir($handle))) {
            if ($file == "." && $file == "..") {
                continue;
            }
            $filename = "/etc/artica-postfix/loadavg.queue/{$file}";
            $filebase = basename($filename);
            if ($GLOBALS["VERBOSE"]) {
                echo "parse {$filename}\n";
            }
            sleep(1);
            if (preg_match("#^([0-9]+)\\.([0-9]+)\\.queue\$#", $filebase, $re)) {
                $filebase = "{$re[1]}.{$re[2]}.0.queue";
            }
            if (preg_match("#([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.queue\$#", $filebase, $re)) {
                if (system_is_overloaded()) {
                    $unix->events(basename(__FILE__) . ": ParseLoadQeues() system is overloaded aborting for {$filename}");
                    return;
                }
                $datas = loadavg_table($filename, $lsof);
                if (is_file("{$filename}.lsof")) {
                    $lsofTEXT = ParseLsof("{$filename}.lsof");
                    @unlink("{$filename}.lsof");
                } else {
                    if ($GLOBALS["VERBOSE"]) {
                        echo "{$filename}.lsof no such file\n";
                    }
                }
                if (is_file("{$filename}.iotop")) {
                    $IoText = ParseIotOp("{$filename}.lsof");
                    @unlink("{$filename}.iotop");
                } else {
                    if ($GLOBALS["VERBOSE"]) {
                        echo "{$filename}.iotop no such file\n";
                    }
                }
                $time = date("Y-m-d H:i:s", $re[1]);
                $load = "{$re[2]},{$re[3]}";
                $q = new mysql();
                $datas = mysql_escape_string2($datas);
                $lsofTEXT = mysql_escape_string2($lsofTEXT);
                $IoText = mysql_escape_string2($IoText);
                $sql = "INSERT IGNORE INTO avgreports (`zDate`,`loadavg`,`psreport`,`lsofreport`,`iotopreport`) VALUES ('{$time}','{$load}','{$datas}','{$lsofTEXT}','{$IoText}')";
                $q->QUERY_SQL($sql, "artica_events");
                if ($GLOBALS["VERBOSE"]) {
                    echo "{$time}: {$load}\n";
                }
                $unix->send_email_events("System Load - {$load} - exceed rule (processes)", $datas, "system", $time);
                if (strlen($lsofTEXT) > 50) {
                    $unix->send_email_events("System Load - {$load} - exceed rule (opened files)", $lsofTEXT, "system", $time);
                }
                if (strlen($IoText) > 50) {
                    $unix->send_email_events("System Load - {$load} - exceed rule (Disk perfs)", $IoText, "system", $time);
                }
                @unlink($filename);
            } else {
                echo "{$filebase} did not match ([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.queue\n";
                @unlink($filename);
            }
        }
    }
}
Example #11
0
function GetUpdates()
{
    if (system_is_overloaded(basename(__FILE__))) {
        system_admin_events("This system is too many overloaded, die()", __FUNCTION__, __FILE__, __LINE__, "system-update");
        die;
    }
    $sock = new sockets();
    $EnableSystemUpdates = $sock->GET_INFO("EnableSystemUpdates");
    if (!is_numeric($EnableSystemUpdates)) {
        $EnableSystemUpdates = 0;
    }
    if ($EnableSystemUpdates == 0) {
        clean_upgrade();
        return;
    }
    @mkdir("/usr/share/artica-postfix/ressources/logs/web", 0755, true);
    @unlink("/usr/share/artica-postfix/ressources/logs/web/debian.update.html");
    $unix = new unix();
    if (is_file("/etc/artica-postfix/FROM_ISO")) {
        $time = $unix->file_time_min("/etc/artica-postfix/FROM_ISO");
        if ($time < 60) {
            return;
        }
    }
    $tmpf = $unix->FILE_TEMP();
    exim_remove();
    CheckSourcesList();
    wsgate_debian();
    $sock = new sockets();
    $ini = new Bs_IniHandler();
    $users = new usersMenus();
    $configDisk = trim($sock->GET_INFO('ArticaAutoUpdateConfig'));
    $ini->loadString($configDisk);
    $AUTOUPDATE = $ini->_params["AUTOUPDATE"];
    $EXEC_NICE = EXEC_NICE();
    $nohup = $unix->find_program("nohup");
    if (trim($AUTOUPDATE["auto_apt"]) == null) {
        $AUTOUPDATE["auto_apt"] = "no";
    }
    $q = new mysql();
    php_fpm();
    if ($GLOBALS["VERBOSE"]) {
        system_admin_events("Running apt-check", __FUNCTION__, __FILE__, __LINE__, "system-update");
    }
    exec("{$_GET["APT-GET"]} check 2>&1", $results);
    if ($GLOBALS["VERBOSE"]) {
        system_admin_events("Running apt-check -> " . count($results) . " items", __FUNCTION__, __FILE__, __LINE__, "update");
    }
    while (list($num, $line) = each($results)) {
        if ($GLOBALS["VERBOSE"]) {
            system_admin_events("apt-check: {$line}", __FUNCTION__, __FILE__, __LINE__, "update");
        }
        if (preg_match("#dpkg --configure -a#", $line)) {
            $cmd = "DEBIAN_FRONTEND=noninteractive dpkg --configure -a --force-confold 2>&1";
            if ($GLOBALS["VERBOSE"]) {
                system_admin_events("apt-check: Executing {$cmd}", __FUNCTION__, __FILE__, __LINE__, "update");
            }
            exec("{$cmd}", $results1);
            while (list($num1, $line1) = each($results1)) {
                if (preg_match("#hardlink between a file in.+?backuppc#", $line1)) {
                    if ($GLOBALS["VERBOSE"]) {
                        system_admin_events("apt-check: remove backuppc", __FUNCTION__, __FILE__, __LINE__, "update");
                    }
                    shell_exec("{$_GET["APT-GET"]} -y remove backuppc --force-yes ");
                }
            }
            system_admin_events("dpkg was interrupted\nReconfigure has been performed\n" . @implode("\n", $results1), __FUNCTION__, __FILE__, __LINE__, "update", "update");
            if ($GLOBALS["VERBOSE"]) {
                system_admin_events("apt-check: reconfigure:\n" . @implode("\n", $results1), __FUNCTION__, __FILE__, __LINE__, "update");
            }
            return;
        }
    }
    exec("{$_GET["APT-GET"]} update 2>&1", $results);
    while (list($num, $line) = each($results)) {
        if ($GLOBALS["VERBOSE"]) {
            system_admin_events("update: {$line}", __FUNCTION__, __FILE__, __LINE__, "system-update");
        }
    }
    $results = array();
    exec("{$_GET["APT-GET"]} -f install --force-yes 2>&1", $results);
    while (list($num, $line) = each($results)) {
        if (preg_match("#hardlink between a file in.+?backuppc#", $line)) {
            if ($GLOBALS["VERBOSE"]) {
                system_admin_events("apt-check: remove backuppc \"{$_GET["APT-GET"]} remove backuppc --force-yes\"", __FUNCTION__, __FILE__, __LINE__, "system-update");
            }
            shell_exec("{$_GET["APT-GET"]} -y remove backuppc --force-yes ");
        }
        if ($GLOBALS["VERBOSE"]) {
            system_admin_events("-f install: {$line}", __FUNCTION__, __FILE__, __LINE__, "system-update");
        }
    }
    if (COUNT_REPOS() == 0) {
        if ($GLOBALS["VERBOSE"]) {
            system_admin_events(" -> INSERT_DEB_PACKAGES()", __FUNCTION__, __FILE__, __LINE__, "system-update");
        }
        INSERT_DEB_PACKAGES();
    }
    shell_exec("{$_GET["APT-GET"]} -f install --force-yes >/dev/null 2>&1");
    shell_exec("{$_GET["APT-GET"]} upgrade -s >{$tmpf} 2>&1");
    $datas = @file_get_contents($tmpf);
    $tbl = explode("\n", $datas);
    system_admin_events("Found " . strlen($datas) . " bytes for apt", __FUNCTION__, __FILE__, __LINE__, "system-update");
    @unlink($tmpf);
    $q->QUERY_SQL("TRUNCATE TABLE syspackages_updt", "artica_backup");
    while (list($num, $val) = each($tbl)) {
        if ($val == null) {
            continue;
        }
        if (preg_match("#^Inst\\s+(.+?)\\s+#", $val, $re)) {
            $packages[] = $re[1];
            if (preg_match("#libclamav#", $re[1])) {
                if ($users->KASPERSKY_WEB_APPLIANCE) {
                    shell_exec("{$EXEC_NICE}{$_GET["APT-GET"]} remove -y -q libclamav* clamav* --purge");
                    continue;
                }
            }
            system_admin_events("Found {$re[1]} new package", __FUNCTION__, __FILE__, __LINE__, "system-update");
            $q->QUERY_SQL("INSERT IGNORE INTO syspackages_updt (package) VALUES('" . addslashes(trim($re[1])) . "')", "artica_backup");
            if (!$q->ok) {
                echo "{$q->mysql_error}\n";
            }
            if (!$q->ok) {
                if (preg_match("#doesn't exist#", $q->mysql_error)) {
                    $q->BuildTables();
                    $q->QUERY_SQL("INSERT IGNORE INTO syspackages_updt (package) VALUES('" . trim($re[1]) . "')", "artica_backup");
                }
            }
        } else {
            if (preg_match("#dpkg was interrupted.+?dpkg --configure -a#", $val)) {
                send_email_events("dpkg was interrupted", "{reconfigure} all will be performed\n{$val}", "update");
                shell_exec("DEBIAN_FRONTEND=noninteractive dpkg --configure -a --force-confold >/dev/null");
                return;
            }
            if (preg_match("#dpkg --configure -a#", $val)) {
                send_email_events("dpkg was interrupted", "{reconfigure} all will be performed\n{$val}", "update");
                shell_exec("DEBIAN_FRONTEND=noninteractive dpkg --configure -a --force-confold >/dev/null");
                return;
            }
            system_admin_events("Garbage \"{$val}\"", __FUNCTION__, __FILE__, __LINE__, "system-update");
        }
    }
    $count = count($packages);
    if ($count > 0) {
        @file_put_contents("/etc/artica-postfix/apt.upgrade.cache", implode("\n", $packages));
        $text = "You can perform upgrade of linux packages for\n" . @file_get_contents("/etc/artica-postfix/apt.upgrade.cache");
        system_admin_events("New upgrade {$count} packages(s) ready {$text}", __FUNCTION__, __FILE__, __LINE__, "update");
        send_email_events("new upgrade {$count} packages(s) ready", $text, "update");
        $paragraph = ParagrapheTEXT('32-infos.png', "{$count} {system_packages}", "{$count} {system_packages_can_be_upgraded}", "javascript:Loadjs('artica.update.php');\n\t\t", "{system_packages_can_be_upgraded}", 300, 80);
        @file_put_contents("/usr/share/artica-postfix/ressources/logs/web/debian.update.html", $paragraph);
        shell_exec("/bin/chmod 777 /usr/share/artica-postfix/ressources/logs/web/debian.update.html");
        if ($AUTOUPDATE["auto_apt"] == "yes") {
            UPGRADE(true);
        }
    } else {
        system_admin_events("No new packages...", __FUNCTION__, __FILE__, __LINE__, "update");
        @unlink("/etc/artica-postfix/apt.upgrade.cache");
    }
    exec("/usr/share/artica-postfix/bin/setup-ubuntu --check-base-system 2>&1", $results2);
    system_admin_events("Checks Artica required packages done\n" . @implode("\n", $results2), __FUNCTION__, __FILE__, __LINE__, "update");
}
Example #12
0
function artica_parse($filename)
{
    echo "Parsing {$filename}\n";
    if (preg_match("#^(.+?)\\.[0-9]+\\.aws\$#", basename($filename), $re)) {
        $instancename = $re[1];
    }
    $f = explode("\n", @file_get_contents($filename));
    $prefixsql = "INSERT IGNORE INTO `mails_stats`(`zmd5`,`zDate`,`instance`,`sender`,`sender_domain`,`recipient`,`recipient_domain`,\n\t`sender_ip`,`recipient_ip`,`smtpcode`,`mailsize`,`artica_meta`) VALUES\n\t";
    $events_number = 0;
    while (list($num, $ligne) = each($f)) {
        if (trim($ligne) == null) {
            continue;
        }
        if (preg_match("#([0-9\\-]+)\\s+([0-9\\:]+)\\s+(.*?)\\s+(.*?)\\s+(.*?)\\s+(.*?)\\s+SMTP\\s+-\\s+([0-9]+)\\s+([0-9\\?]+)#", $ligne, $re)) {
            $day = $re[1];
            $time = $re[2];
            $from = strtolower($re[3]);
            $to = strtolower($re[4]);
            $ipfrom = $re[5];
            $ipto = $re[6];
            $smtpcode = $re[7];
            $size = $re[8];
            if (!is_numeric($size)) {
                $size = 0;
            }
            $zdate = "{$day} {$time}";
            $domainfrom = "";
            $domainto = "";
            if ($from == "<>") {
                $from = "Unknown";
            }
            if ($to == "<>") {
                $to = "Unknown";
            }
            if (preg_match("#(.+?)@(.+)#", $from, $re)) {
                $domainfrom = $re[2];
            }
            if (preg_match("#(.+?)@(.+)#", $to, $re)) {
                $domainto = $re[2];
            }
            if ($domainfrom == null) {
                $domainfrom = "Unknown";
            }
            if ($domainto == null) {
                $domainto = "Unknown";
            }
            $md5 = md5("{$instancename}{$day}{$time}{$from}{$to}{$size}");
            $sq[] = "('{$md5}','{$zdate}','{$instancename}','{$from}','{$domainfrom}','{$to}','{$domainto}','{$ipfrom}','{$ipto}','{$smtpcode}','{$size}',0)";
            $events_number++;
        } else {
            echo $ligne . "FAILED\n";
        }
    }
    if (is_array($sq)) {
        $sql = "{$prefixsql}" . @implode(",", $sq);
    }
    $q = new mysql();
    $unix = new unix();
    $q->QUERY_SQL($sql, "artica_events");
    if (!$q->ok) {
        echo "Mysql error:{$q->msql_error}\n";
        return;
    }
    $unix = new unix();
    $awstats = $unix->LOCATE_AWSTATS_BIN();
    $GLOBALS["perl"] = $unix->find_program("perl");
    $GLOBALS["nice"] = EXEC_NICE();
    $awstats_buildstaticpages = $unix->LOCATE_AWSTATS_BUILDSTATICPAGES_BIN();
    $awstats_conf[] = "LogFile={$filename}";
    $awstats_conf[] = "LogType=M";
    $awstats_conf[] = "LogFormat=\"%time2 %email %email_r %host %host_r %method %url %code %bytesd\"";
    $awstats_conf[] = "LevelForBrowsersDetection=0";
    $awstats_conf[] = "LevelForOSDetection=0";
    $awstats_conf[] = "LevelForRefererAnalyze=0";
    $awstats_conf[] = "LevelForRobotsDetection=0";
    $awstats_conf[] = "LevelForWormsDetection=0";
    $awstats_conf[] = "LevelForSearchEnginesDetection=0";
    $awstats_conf[] = "LevelForFileTypesDetection=0";
    $awstats_conf[] = "ShowMenu=1";
    $awstats_conf[] = "ShowSummary=HB";
    $awstats_conf[] = "ShowMonthStats=HB";
    $awstats_conf[] = "ShowDaysOfMonthStats=HB";
    $awstats_conf[] = "ShowDaysOfWeekStats=HB";
    $awstats_conf[] = "ShowHoursStats=HB";
    $awstats_conf[] = "ShowDomainsStats=0";
    $awstats_conf[] = "ShowHostsStats=HBL";
    $awstats_conf[] = "ShowAuthenticatedUsers=0";
    $awstats_conf[] = "ShowRobotsStats=0";
    $awstats_conf[] = "ShowEMailSenders=HBML";
    $awstats_conf[] = "ShowEMailReceivers=HBML";
    $awstats_conf[] = "ShowSessionsStats=0";
    $awstats_conf[] = "ShowPagesStats=0";
    $awstats_conf[] = "ShowFileTypesStats=0";
    $awstats_conf[] = "ShowFileSizesStats=0";
    $awstats_conf[] = "ShowBrowsersStats=0";
    $awstats_conf[] = "ShowOSStats=0";
    $awstats_conf[] = "ShowOriginStats=0";
    $awstats_conf[] = "ShowKeyphrasesStats=0";
    $awstats_conf[] = "ShowKeywordsStats=0";
    $awstats_conf[] = "ShowMiscStats=0";
    $awstats_conf[] = "ShowHTTPErrorsStats=0";
    $awstats_conf[] = "ShowSMTPErrorsStats=1";
    @file_put_contents("/etc/awstats/awstats.{$instancename}.conf", @implode("\n", $awstats_conf));
    @chmod("/etc/awstats/awstats.{$instancename}.conf", 644);
    $t1 = time();
    @mkdir("/var/tmp/awstats/{$instancename}", 0666, true);
    $cmd = "{$GLOBALS["nice"]}{$GLOBALS["perl"]} {$awstats_buildstaticpages} -config={$instancename} -update -lang=auto -awstatsprog={$awstats} -dir=/var/tmp/awstats/{$instancename} 2>&1";
    if ($GLOBALS["VERBOSE"]) {
        echo $cmd . "\n";
    }
    exec($cmd, $results);
    if ($GLOBALS["VERBOSE"]) {
        echo @implode("\n", $results) . "\n";
    }
    awstats_import_sql($instancename, $GLOBALS["ARTICAMETA"]);
    $t2 = time();
    @unlink($filename);
}
Example #13
0
function ParseLocalQueue()
{
    if (is_file("/etc/artica-postfix/orders.queue")) {
        $size = @filesize("/etc/artica-postfix/orders.queue");
        if ($size > 0) {
            events("Loading /etc/artica-postfix/orders.queue {$size} bytes");
            $orders_queue = explode("\n", @file_get_contents("/etc/artica-postfix/orders.queue"));
            if (is_array($orders_queue)) {
                while (list($num, $ligne) = each($orders_queue)) {
                    if (trim($ligne) == null) {
                        continue;
                    }
                    $orders[md5($ligne)] = $ligne;
                }
            }
        }
        @unlink("/etc/artica-postfix/orders.queue");
    }
    if (is_file("/etc/artica-postfix/background")) {
        $size = @filesize("/etc/artica-postfix/background");
        if ($size > 0) {
            events("Loading /etc/artica-postfix/background {$size} bytes");
            $background = explode("\n", @file_get_contents("/etc/artica-postfix/background"));
            if (is_array($background)) {
                while (list($num, $ligne) = each($background)) {
                    if (trim($ligne) == null) {
                        continue;
                    }
                    $orders[md5($ligne)] = $ligne;
                }
            }
        }
        @unlink("/etc/artica-postfix/background");
    }
    if (count($orders) == 0) {
        return null;
    }
    $nice = EXEC_NICE();
    shell_exec('export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11');
    $nohup = LOCATE_NOHUP() . " ";
    $orders_number = count($orders);
    $count_max = $orders_number;
    if ($count_max > 2) {
        $count_max = 2;
    }
    if ($orders_number > 10) {
        if (!$GLOBALS["OVERLOAD"]) {
            $count_max = 10;
        }
    }
    while (list($num, $cmd) = each($orders)) {
        $count = $count + 1;
        $devnull = " >/dev/null 2>&1";
        if (strpos($cmd, ">") > 0) {
            $devnull = null;
        }
        if ($GLOBALS["OVERLOAD"]) {
            if ($count >= $count_max) {
                break;
            }
            unset($orders[$num]);
            events("[OVERLOAD]:: running in overload mode {$cmd}");
            shell_exec("{$nohup}{$nice}{$cmd}{$devnull}");
            continue;
        }
        events("[NORMAL]:: running in normal mode {$cmd}");
        shell_exec("{$nohup}{$nice}{$cmd}{$devnull} &");
        unset($orders[$num]);
        if ($count >= $count_max) {
            break;
        }
    }
    events("{$count}/{$orders_number} order(s) executed...end;");
    if (is_array($orders)) {
        if (count($orders) > 0) {
            reset($orders);
            $fh = fopen("/etc/artica-postfix/background", 'w') or die("can't open file");
            while (list($num, $cmd) = each($orders)) {
                $datas = "{$cmd}\n";
                fwrite($fh, $datas);
            }
            fclose($fh);
            events("Queued " . count($orders) . " order(s)");
        }
    }
}
function ParseGzSqlFile($filepath){
	
	
	if($GLOBALS["MYSQLCOMMAND"]==null){
		$unix=new unix();
		$mysql=$unix->find_program("mysql");
		$q=new mysql();
		if($q->mysql_password<>null){
			$password="******";
		}
		$nice=EXEC_NICE();
		$cmd="$nice$mysql --batch --user=$q->mysql_admin $password --port=$q->mysql_port";
		$cmd=$cmd." --host=$q->mysql_server --database=artica_backup";
		$cmd=$cmd." --max_allowed_packet=500M";
		$GLOBALS["MYSQLCOMMAND"]=$cmd;
	}else{
		$cmd=$GLOBALS["MYSQLCOMMAND"];
	}
	
	//echo $cmd." <$filepath\n";
	echo "Starting......: [ParseGzSqlFile]:: Artica database community running importation (". basename($filepath).")\n";
	exec("$cmd <$filepath 2>&1",$results);
	
	
	
	if(count($results)>0){
		while (list ($num, $ligne) = each ($results) ){
			if(!preg_match("#Duplicate entry#",$ligne)){
				echo "Starting......: Artica database community $ligne\n";
				if(preg_match("#ERROR\s+[0-9]+#",$ligne)){
					echo "Starting......: Artica database community error detected\n";
					$GLOBALS["NEWFILES"][]=$ligne;
					$unix->send_email_events("Web community mysql error", "Unable to import data file $filepath\n$ligne","proxy");
					return false;
				}
			}
		}
	}
	return true;
	@unlink($filepath);
	
}
Example #15
0
function BuildJgrowl()
{
    events("starting", __FUNCTION__, __FILE__, __LINE__);
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $oldpid = @file_get_contents($pidfile);
    if ($unix->process_exists($oldpid)) {
        events("Already running pid {$oldpid}", __FUNCTION__, __FILE__, __LINE__);
        die;
    }
    $size = $unix->file_size("/etc/artica-postfix/smtpnotif.conf");
    if ($size > 200000) {
        events("/etc/artica-postfix/smtpnotif.conf => cleaning -> size={$size}", "MAIN", __FUNCTION__, __FILE__, __LINE__);
        $tbl = explode("\n", @file_get_contents("/etc/artica-postfix/smtpnotif.conf"));
        events("/etc/artica-postfix/smtpnotif.conf => cleaning -> " . count($tbl) . " rows", "MAIN", __FUNCTION__, __FILE__, __LINE__);
        while (list($index, $val) = each($tbl)) {
            if (trim($val) == null) {
                continue;
            }
            $new[] = $val;
        }
        @file_put_contents("/etc/artica-postfix/smtpnotif.conf", @implode("\n", $new));
        events("/etc/artica-postfix/smtpnotif.conf => cleaning -> " . count($new) . " rows", "MAIN", __FUNCTION__, __FILE__, __LINE__);
    }
    @file_put_contents($pidfile, getmypid());
    $nice = EXEC_NICE();
    if (is_file("/usr/share/artica-postfix/ressources/logs/web/jgrowl.txt")) {
        events("/usr/share/artica-postfix/ressources/logs/web/jgrowl.txt exists, aborting", __FUNCTION__, __FILE__, __LINE__);
        die;
    }
    $cmd = $nice . LOCATE_PHP5_BIN2() . " " . __FILE__ . " >/usr/share/artica-postfix/ressources/logs/web/jgrowl.txt 2>&1";
    events("Executing {$cmd}", __FUNCTION__, __FILE__, __LINE__);
    shell_exec($cmd);
    events("chmod...", __FUNCTION__, __FILE__, __LINE__);
    @chmod("/usr/share/artica-postfix/ressources/logs/web/jgrowl.txt", 0777);
    events("success, die", __FUNCTION__, __FILE__, __LINE__);
    die;
}
Example #16
0
function apache_config()
{
    $sock = new sockets();
    $unix = new unix();
    $EnablePHPFPM = 0;
    @mkdir("/var/run/squid", 0755, true);
    @mkdir("/var/run/squid", 0755, true);
    $APACHE_SRC_ACCOUNT = "squid";
    $APACHE_SRC_GROUP = "squid";
    $APACHE_MODULES_PATH = $unix->APACHE_MODULES_PATH();
    if (!isset($GLOBALS["HyperCacheStoragePath"])) {
        $sock = new sockets();
        $GLOBALS["HyperCacheStoragePath"] = $sock->GET_INFO("HyperCacheStoragePath");
        if ($GLOBALS["HyperCacheStoragePath"] == null) {
            $GLOBALS["HyperCacheStoragePath"] = "/home/artica/proxy-cache";
        }
    }
    $SquidEnforceRules = intval($sock->GET_INFO("SquidEnforceRules"));
    $HyperCacheHTTPListenPort = $sock->GET_INFO("HyperCacheHTTPListenPort");
    $HyperCacheHTTPListenPortSSL = $sock->GET_INFO("HyperCacheHTTPListenPortSSL");
    $HyperCacheHTTPListenPortSSLEnabled = intval($sock->GET_INFO("HyperCacheHTTPListenPortSSLEnabled"));
    if (!is_numeric($HyperCacheHTTPListenPort)) {
        $HyperCacheHTTPListenPort = 8700;
    }
    if (!is_numeric($HyperCacheHTTPListenPortSSL)) {
        $HyperCacheHTTPListenPortSSL = 8900;
    }
    $HyperCacheListenAddr = $sock->GET_INFO("HyperCacheListenAddr");
    $unix = new unix();
    $NETWORK_ALL_INTERFACES = $unix->NETWORK_ALL_INTERFACES();
    unset($NETWORK_ALL_INTERFACES["lo"]);
    if ($HyperCacheListenAddr == null) {
        $HyperCacheListenAddr = $unix->NETWORK_DEFAULT_LISTEN_ADDR();
        $sock->SET_INFO("HyperCacheListenAddr", $HyperCacheListenAddr);
    }
    if ($unix->NETWORK_IS_LISTEN_ADDR_EXISTS($HyperCacheListenAddr)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} {$HyperCacheListenAddr} doesn't exists...\n";
        }
        $HyperCacheListenAddr = $unix->NETWORK_DEFAULT_LISTEN_ADDR();
        $sock->SET_INFO("HyperCacheListenAddr", $HyperCacheListenAddr);
    }
    $ipaddr = $HyperCacheListenAddr;
    $phpfpm = $unix->APACHE_LOCATE_PHP_FPM();
    $php = $unix->LOCATE_PHP5_BIN();
    $EnableArticaApachePHPFPM = $sock->GET_INFO("EnableArticaApachePHPFPM");
    if (!is_numeric($EnableArticaApachePHPFPM)) {
        $EnableArticaApachePHPFPM = 0;
    }
    if (!is_file($phpfpm)) {
        $EnableArticaApachePHPFPM = 0;
    }
    $unix->chown_func($APACHE_SRC_ACCOUNT, $APACHE_SRC_GROUP, "/var/run/squid");
    $apache_LOCATE_MIME_TYPES = $unix->apache_LOCATE_MIME_TYPES();
    if ($EnableArticaApachePHPFPM == 1) {
        if (!is_file("{$APACHE_MODULES_PATH}/mod_fastcgi.so")) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} mod_fastcgi.so is required to use PHP5-FPM\n";
            }
            $EnableArticaApachePHPFPM = 0;
        }
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Listen address: {$ipaddr}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Run as {$APACHE_SRC_ACCOUNT}:{$APACHE_SRC_GROUP}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} HTTP Port: {$HyperCacheHTTPListenPort} SSL Port: {$HyperCacheHTTPListenPortSSL}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} PHP-FPM: {$EnablePHPFPM}\n";
    }
    $q = new mysql_squid_builder();
    $nice = EXEC_NICE();
    $sql = "SELECT * FROM artica_caches_mirror WHERE enabled=1 AND `ToDelete`=0";
    $results = $q->QUERY_SQL($sql);
    $HyperCache = new HyperCache();
    while ($ligne = mysql_fetch_assoc($results)) {
        $t = time();
        $sitename = $ligne["sitename"];
        $sitename_path = $HyperCache->HyperCacheUriToHostname($sitename);
        $workingdir = $GLOBALS["HyperCacheStoragePath"] . "/mirror/{$sitename_path}";
        if (!is_dir($workingdir)) {
            @mkdir($workingdir, 0755, true);
        }
        @chown("{$GLOBALS["HyperCacheStoragePath"]}/mirror", "squid");
        @chgrp("{$GLOBALS["HyperCacheStoragePath"]}/mirror", "squid");
        @chown("{$GLOBALS["HyperCacheStoragePath"]}/mirror/{$sitename_path}", "squid");
        @chgrp("{$GLOBALS["HyperCacheStoragePath"]}/mirror/{$sitename_path}", "squid");
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} build folder for mirrored {$sitename_path}\n";
        }
        $mirrors[] = "";
        $mirrors_aliases[] = "alias /{$sitename_path} {$workingdir}";
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: alias /{$sitename_path} {$workingdir}\n";
        }
        $mirrors[] = "";
        $mirrors[] = "\t<Directory \"{$workingdir}\">";
        $mirrors[] = "\t\tDirectorySlash On";
        $mirrors[] = "\t\tDirectoryIndex index.html index-2.html";
        $mirrors[] = "\t\tOptions All";
        $mirrors[] = "\t\tOrder deny,allow";
        $mirrors[] = "\t\tAllow from all";
        $mirrors[] = "\t</Directory>";
        $mirrors[] = "";
    }
    $mirrors_conf = @implode("\n", $mirrors);
    $mirrors_aliases_conf = @implode("\n", $mirrors_aliases);
    $f[] = "LockFile /var/run/squid/HyperCacheWebAccept.lock";
    $f[] = "PidFile /var/run/squid/HyperCacheWeb.pid";
    $f[] = "AcceptMutex flock";
    $f[] = "DocumentRoot /usr/share/artica-postfix";
    $f[] = "DirectoryIndex squidcache.php";
    $f[] = "NameVirtualHost {$ipaddr}:{$HyperCacheHTTPListenPort}";
    $f[] = $mirrors_aliases_conf;
    if ($HyperCacheHTTPListenPortSSLEnabled == 1) {
        $f[] = "SSLRandomSeed startup file:/dev/urandom  256";
        $f[] = "SSLRandomSeed connect builtin";
        $f[] = "SSLSessionCache        shmcb:/var/run/squid/HyperCacheWebSSL(512000)";
        $f[] = "SSLSessionCacheTimeout  300";
        $f[] = "SSLSessionCacheTimeout  300";
        $f[] = "NameVirtualHost {$ipaddr}:{$HyperCacheHTTPListenPortSSL}";
        $f[] = "Listen {$ipaddr}:{$HyperCacheHTTPListenPortSSL}";
    }
    $f[] = "Listen {$ipaddr}:{$HyperCacheHTTPListenPort}";
    $f[] = "<VirtualHost {$ipaddr}:{$HyperCacheHTTPListenPort}>";
    $f[] = "\tServerName {$ipaddr}";
    $f[] = "\tLoglevel debug";
    $f[] = "\tLoglevel debug";
    $f[] = "\tErrorLog /var/log/squid/HyperCache-error.log";
    $f[] = "\tLogFormat \"%h %l %u %t \\\"%r\\\" %<s %b\" common";
    $f[] = "\tCustomLog /var/log/squid/HyperCache-access.log common";
    $f[] = "\tErrorDocument 400 /squidcache.php";
    $f[] = "\tErrorDocument 401 /squidcache.php";
    $f[] = "\tErrorDocument 403 /squidcache.php";
    $f[] = "\tErrorDocument 404 /squidcache.php";
    $f[] = "\tErrorDocument 500 /squidcache.php";
    //$f[]="\tFallbackResource /squidcache.php";
    $f[] = $mirrors_aliases_conf;
    $f[] = $mirrors_conf;
    $f[] = "</VirtualHost>";
    if ($HyperCacheHTTPListenPortSSLEnabled == 1) {
        $squid = new squidbee();
        $data = $squid->SaveCertificate($ArticaSplashHotSpotCertificate, false, true, false);
        if (preg_match("#ssl_certificate\\s+(.+?);\\s+ssl_certificate_key\\s+(.+?);#is", $data, $re)) {
            $cert = $re[1];
            $key = $re[2];
        }
        $f[] = "<VirtualHost {$ipaddr}:{$HyperCacheHTTPListenPortSSL}>";
        $f[] = "\tFallbackResource /squidcache.php";
        $f[] = "\tServerName {$ipaddr}";
        $f[] = "\tDocumentRoot /usr/share/artica-postfix";
        $f[] = "\tSSLEngine on";
        $f[] = "\tSSLCertificateFile \"{$cert}\"";
        $f[] = "\tSSLCertificateKeyFile \"{$key}\"";
        $f[] = "\tSSLVerifyClient none";
        $f[] = "\tServerSignature Off";
        $f[] = $mirrors_conf;
        $f[] = "</VirtualHost>";
    }
    $f[] = "<IfModule mpm_prefork_module>";
    $f[] = "</IfModule>";
    $f[] = "<IfModule mpm_worker_module>";
    $f[] = "\tMinSpareThreads      25";
    $f[] = "\tMaxSpareThreads      75 ";
    $f[] = "\tThreadLimit          64";
    $f[] = "\tThreadsPerChild      25";
    $f[] = "</IfModule>";
    $f[] = "<IfModule mpm_event_module>";
    $f[] = "\tMinSpareThreads      25";
    $f[] = "\tMaxSpareThreads      75 ";
    $f[] = "\tThreadLimit          64";
    $f[] = "\tThreadsPerChild      25";
    $f[] = "</IfModule>";
    $f[] = "AccessFileName .htaccess";
    $f[] = "<Files ~ \"^\\.ht\">";
    $f[] = "\tOrder allow,deny";
    $f[] = "\tDeny from all";
    $f[] = "\tSatisfy all";
    $f[] = "</Files>";
    $f[] = "DefaultType text/plain";
    $f[] = "HostnameLookups Off";
    $f[] = "User\t\t\t\t   {$APACHE_SRC_ACCOUNT}";
    $f[] = "Group\t\t\t\t   {$APACHE_SRC_GROUP}";
    $f[] = "Timeout              300";
    $f[] = "KeepAlive            Off";
    $f[] = "KeepAliveTimeout     15";
    $f[] = "StartServers         1";
    $f[] = "MaxClients           50";
    $f[] = "MinSpareServers      2";
    $f[] = "MaxSpareServers      5";
    $f[] = "MaxRequestsPerChild  5000";
    $f[] = "MaxKeepAliveRequests 100";
    $f[] = "ServerName " . $unix->hostname_g();
    if ($HyperCacheHTTPListenPortSSLEnabled == 1) {
        $f[] = "<IfModule mod_ssl.c>";
        $f[] = "\tSSLRandomSeed connect builtin";
        $f[] = "\tSSLRandomSeed connect file:/dev/urandom 512";
        $f[] = "\tAddType application/x-x509-ca-cert .crt";
        $f[] = "\tAddType application/x-pkcs7-crl    .crl";
        $f[] = "\tSSLPassPhraseDialog  builtin";
        $f[] = "\tSSLSessionCache        shmcb:/var/run/squid/ssl_scache-articahtp(512000)";
        $f[] = "\tSSLSessionCacheTimeout  300";
        $f[] = "\tSSLSessionCacheTimeout  300";
        $f[] = "\tSSLMutex  sem";
        $f[] = "\tSSLCipherSuite HIGH:MEDIUM:!ADH";
        $f[] = "\tSSLProtocol all -SSLv2";
        $f[] = "</IfModule>";
        $f[] = "";
    }
    // $f[]="\tFallbackResource /squidcache.php";
    $f[] = "AddType application/x-httpd-php .php";
    $f[] = "php_value error_log \"/var/log/lighttpd/apache-hotspot-php.log\"";
    $f[] = "<IfModule mod_fcgid.c>";
    $f[] = "\tPHP_Fix_Pathinfo_Enable 1";
    $f[] = "</IfModule>";
    $f[] = "<IfModule mod_php5.c>";
    $f[] = "    <FilesMatch \"\\.ph(p3?|tml)\$\">";
    $f[] = "\tSetHandler application/x-httpd-php";
    $f[] = "    </FilesMatch>";
    $f[] = "    <FilesMatch \"\\.phps\$\">";
    $f[] = "\tSetHandler application/x-httpd-php-source";
    $f[] = "    </FilesMatch>";
    $f[] = "    <IfModule mod_userdir.c>";
    $f[] = "        <Directory /home/*/public_html>";
    $f[] = "            php_admin_value engine Off";
    $f[] = "        </Directory>";
    $f[] = "    </IfModule>";
    $f[] = "</IfModule>";
    $f[] = "<IfModule mod_mime.c>";
    $f[] = "\tTypesConfig /etc/mime.types";
    $f[] = "\tAddType application/x-compress .Z";
    $f[] = "\tAddType application/x-gzip .gz .tgz";
    $f[] = "\tAddType application/x-bzip2 .bz2";
    $f[] = "\tAddType application/x-httpd-php .php .phtml";
    $f[] = "\tAddType application/x-httpd-php-source .phps";
    $f[] = "\tAddLanguage ca .ca";
    $f[] = "\tAddLanguage cs .cz .cs";
    $f[] = "\tAddLanguage da .dk";
    $f[] = "\tAddLanguage de .de";
    $f[] = "\tAddLanguage el .el";
    $f[] = "\tAddLanguage en .en";
    $f[] = "\tAddLanguage eo .eo";
    $f[] = "\tRemoveType  es";
    $f[] = "\tAddLanguage es .es";
    $f[] = "\tAddLanguage et .et";
    $f[] = "\tAddLanguage fr .fr";
    $f[] = "\tAddLanguage he .he";
    $f[] = "\tAddLanguage hr .hr";
    $f[] = "\tAddLanguage it .it";
    $f[] = "\tAddLanguage ja .ja";
    $f[] = "\tAddLanguage ko .ko";
    $f[] = "\tAddLanguage ltz .ltz";
    $f[] = "\tAddLanguage nl .nl";
    $f[] = "\tAddLanguage nn .nn";
    $f[] = "\tAddLanguage no .no";
    $f[] = "\tAddLanguage pl .po";
    $f[] = "\tAddLanguage pt .pt";
    $f[] = "\tAddLanguage pt-BR .pt-br";
    $f[] = "\tAddLanguage ru .ru";
    $f[] = "\tAddLanguage sv .sv";
    $f[] = "\tRemoveType  tr";
    $f[] = "\tAddLanguage tr .tr";
    $f[] = "\tAddLanguage zh-CN .zh-cn";
    $f[] = "\tAddLanguage zh-TW .zh-tw";
    $f[] = "\tAddCharset us-ascii    .ascii .us-ascii";
    $f[] = "\tAddCharset ISO-8859-1  .iso8859-1  .latin1";
    $f[] = "\tAddCharset ISO-8859-2  .iso8859-2  .latin2 .cen";
    $f[] = "\tAddCharset ISO-8859-3  .iso8859-3  .latin3";
    $f[] = "\tAddCharset ISO-8859-4  .iso8859-4  .latin4";
    $f[] = "\tAddCharset ISO-8859-5  .iso8859-5  .cyr .iso-ru";
    $f[] = "\tAddCharset ISO-8859-6  .iso8859-6  .arb .arabic";
    $f[] = "\tAddCharset ISO-8859-7  .iso8859-7  .grk .greek";
    $f[] = "\tAddCharset ISO-8859-8  .iso8859-8  .heb .hebrew";
    $f[] = "\tAddCharset ISO-8859-9  .iso8859-9  .latin5 .trk";
    $f[] = "\tAddCharset ISO-8859-10  .iso8859-10  .latin6";
    $f[] = "\tAddCharset ISO-8859-13  .iso8859-13";
    $f[] = "\tAddCharset ISO-8859-14  .iso8859-14  .latin8";
    $f[] = "\tAddCharset ISO-8859-15  .iso8859-15  .latin9";
    $f[] = "\tAddCharset ISO-8859-16  .iso8859-16  .latin10";
    $f[] = "\tAddCharset ISO-2022-JP .iso2022-jp .jis";
    $f[] = "\tAddCharset ISO-2022-KR .iso2022-kr .kis";
    $f[] = "\tAddCharset ISO-2022-CN .iso2022-cn .cis";
    $f[] = "\tAddCharset Big5        .Big5       .big5 .b5";
    $f[] = "\tAddCharset cn-Big5     .cn-big5";
    $f[] = "\t# For russian, more than one charset is used (depends on client, mostly):";
    $f[] = "\tAddCharset WINDOWS-1251 .cp-1251   .win-1251";
    $f[] = "\tAddCharset CP866       .cp866";
    $f[] = "\tAddCharset KOI8      .koi8";
    $f[] = "\tAddCharset KOI8-E      .koi8-e";
    $f[] = "\tAddCharset KOI8-r      .koi8-r .koi8-ru";
    $f[] = "\tAddCharset KOI8-U      .koi8-u";
    $f[] = "\tAddCharset KOI8-ru     .koi8-uk .ua";
    $f[] = "\tAddCharset ISO-10646-UCS-2 .ucs2";
    $f[] = "\tAddCharset ISO-10646-UCS-4 .ucs4";
    $f[] = "\tAddCharset UTF-7       .utf7";
    $f[] = "\tAddCharset UTF-8       .utf8";
    $f[] = "\tAddCharset UTF-16      .utf16";
    $f[] = "\tAddCharset UTF-16BE    .utf16be";
    $f[] = "\tAddCharset UTF-16LE    .utf16le";
    $f[] = "\tAddCharset UTF-32      .utf32";
    $f[] = "\tAddCharset UTF-32BE    .utf32be";
    $f[] = "\tAddCharset UTF-32LE    .utf32le";
    $f[] = "\tAddCharset euc-cn      .euc-cn";
    $f[] = "\tAddCharset euc-gb      .euc-gb";
    $f[] = "\tAddCharset euc-jp      .euc-jp";
    $f[] = "\tAddCharset euc-kr      .euc-kr";
    $f[] = "\tAddCharset EUC-TW      .euc-tw";
    $f[] = "\tAddCharset gb2312      .gb2312 .gb";
    $f[] = "\tAddCharset iso-10646-ucs-2 .ucs-2 .iso-10646-ucs-2";
    $f[] = "\tAddCharset iso-10646-ucs-4 .ucs-4 .iso-10646-ucs-4";
    $f[] = "\tAddCharset shift_jis   .shift_jis .sjis";
    $f[] = "\tAddType text/html .shtml";
    $f[] = "\tAddOutputFilter INCLUDES .shtml";
    $f[] = "</IfModule>";
    $f[] = $mirrors_conf;
    $f[] = "<Directory \"/usr/share/artica-postfix\">";
    $f[] = "FallbackResource /squidcache.php";
    $f[] = "\tDirectorySlash On";
    $f[] = "\tDirectoryIndex squidcache.php";
    $f[] = "\t\t<Files \"squidcache.php\">";
    $f[] = "\t\t\tOrder allow,deny";
    $f[] = "\t\t\tallow from all";
    $f[] = "\t\t</Files>";
    /*	$f[]="\tErrorDocument 400 /hotspot.php";
    	$f[]="\tErrorDocument 401 /hotspot.php";
    	$f[]="\tErrorDocument 403 /hotspot.php";
    	$f[]="\tErrorDocument 404 /hotspot.php";
    	$f[]="\tErrorDocument 500 /hotspot.php";
    */
    $f[] = "\tOptions -Indexes";
    $f[] = ParseArticaDirectory();
    @chmod("/usr/share/artica-postfix/squidcache.php", 0755);
    @chown("/usr/share/artica-postfix/squidcache.php", "squid");
    if ($HyperCacheHTTPListenPortSSLEnabled == 1) {
        $f[] = "\tSSLOptions +StdEnvVars";
    }
    $f[] = "\tAllowOverride All";
    $f[] = "\tOrder allow,deny";
    $f[] = "\tAllow from all";
    $f[] = "</Directory>";
    if ($EnableArticaApachePHPFPM == 1) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Activate PHP5-FPM\n";
        }
        shell_exec("{$php} /usr/share/artica-postfix/exec.initslapd.php --phppfm");
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Restarting PHP5-FPM\n";
        }
        shell_exec("/etc/init.d/php5-fpm restart");
        $f[] = "\tAlias /php5.fastcgi /var/run/squid/php5.fastcgi";
        $f[] = "\tAddHandler php-script .php";
        $f[] = "\tFastCGIExternalServer /var/run/squid/php5.fastcgi -socket /var/run/php-fpm.sock -idle-timeout 610";
        $f[] = "\tAction php-script /php5.fastcgi virtual";
        $f[] = "\t<Directory /var/run/squid>";
        $f[] = "\t\t<Files php5.fastcgi>";
        $f[] = "\t\tOrder deny,allow";
        $f[] = "\t\tAllow from all";
        $f[] = "\t\t</Files>";
        $f[] = "\t</Directory>";
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} PHP5-FPM is disabled\n";
        }
    }
    if ($EnableArticaApachePHPFPM == 0) {
        $array["php5_module"] = "libphp5.so";
    }
    $array["dumpio_module"] = "mod_dumpio.so";
    $array["actions_module"] = "mod_actions.so";
    $array["expires_module"] = "mod_expires.so";
    $array["rewrite_module"] = "mod_rewrite.so";
    $array["dir_module"] = "mod_dir.so";
    $array["mime_module"] = "mod_mime.so";
    $array["alias_module"] = "mod_alias.so";
    $array["auth_basic_module"] = "mod_auth_basic.so";
    $array["authz_host_module"] = "mod_authz_host.so";
    $array["autoindex_module"] = "mod_autoindex.so";
    $array["negotiation_module"] = "mod_negotiation.so";
    if ($HyperCacheHTTPListenPortSSLEnabled == 1) {
        $array["ssl_module"] = "mod_ssl.so";
    }
    $array["headers_module"] = "mod_headers.so";
    //$array["ldap_module"]="mod_ldap.so";
    if ($EnableArticaApachePHPFPM == 1) {
        $array["fastcgi_module"] = "mod_fastcgi.so";
    }
    if (is_dir("/etc/apache2")) {
        if (!is_file("/etc/apache2/mime.types")) {
            if ($apache_LOCATE_MIME_TYPES != "/etc/apache2/mime.types") {
                @copy($apache_LOCATE_MIME_TYPES, "/etc/apache2/mime.types");
            }
        }
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Mime types path.......: {$apache_LOCATE_MIME_TYPES}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Modules path..........: {$APACHE_MODULES_PATH}\n";
    }
    while (list($module, $lib) = each($array)) {
        if (is_file("{$APACHE_MODULES_PATH}/{$lib}")) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} include module \"{$module}\"\n";
            }
            $f[] = "LoadModule {$module} {$APACHE_MODULES_PATH}/{$lib}";
        } else {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} skip module \"{$module}\"\n";
            }
        }
    }
    @file_put_contents("/etc/artica-postfix/HyperCacheHTTPD.conf", @implode("\n", $f));
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} /etc/artica-postfix/HyperCacheHTTPD.conf done\n";
    }
}
Example #17
0
    echo "/etc/artica-postfix/settings/Daemons/CyrusAVConfig no such file...\n";
    die;
}
@mkdir("/etc/artica-postfix/pids");
$pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid";
$unix = new unix();
if ($unix->process_exists(@file_get_contents($pidfile))) {
    echo "Process already exists...\n";
    die;
}
@file_put_contents($pidfile, getmypid());
$t1 = time();
$time = date('Y-m-d') . "_" . date('h:i');
$ini = new Bs_IniHandler();
$ini->loadFile("/etc/artica-postfix/settings/Daemons/CyrusAVConfig");
$nice = EXEC_NICE();
$clamscan = $unix->find_program("clamscan");
if (!is_file($clamscan)) {
    die;
}
$partition_default = $unix->IMAPD_GET("partition-default");
if (!is_dir($partition_default)) {
    send_email_events("Mailboxes antivirus scanning failed", "partition-default: \"{$partition_default}\"\nno such directory", "mailbox");
    echo "partition-default: no such directory\n";
    die;
}
@mkdir("/var/log/artica-postfix/antivirus/cyrus-imap", 0755, true);
$time = date('Y-m-d') . "_" . date('h:I');
$cmd = "{$nice} /usr/bin/clamscan --recursive=yes --infected ";
$cmd = $cmd . "--max-filesize=10M --max-scansize=10M --max-recursion=5 --max-dir-recursion=10 ";
$cmd = $cmd . "--log=/log/artica-postfix/antivirus/cyrus-imap/{$time}.scan {$partition_default}";
Example #18
0
function UFDBGUARD_COMPILE_SINGLE_DB($path)
{
    $timeStart = time();
    $OriginalDirename = dirname($path);
    $unix = new unix();
    $path = str_replace(".ufdb", "", $path);
    $pidpath = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . md5($path) . ".pid";
    $pid = @file_get_contents($pidpath);
    if ($unix->process_exists($pid)) {
        events_ufdb_tail("Check \"{$path}\"... Already process PID \"{$pid}\" running task has been aborted");
        return;
    }
    $category = null;
    $ufdbGenTable = $unix->find_program("ufdbGenTable");
    if (!is_file($ufdbGenTable)) {
        writelogs("ufdbGenTable no such binary", __FUNCTION__, __FILE__, __LINE__);
        return;
    }
    events_ufdb_tail("Check \"{$path}\"...", __LINE__);
    if (preg_match("#\\/var\\/lib\\/squidguard\\/(.+?)\\/(.+?)/(.+?)\$#", $path, $re)) {
        $category = $re[2];
        $domain_path = "/var/lib/squidguard/{$re[1]}/{$re[2]}/domains";
    }
    if ($category == null) {
        if (preg_match("#\\/var\\/lib\\/squidguard\\/(.+?)\\/domains#", $path, $re)) {
            $category = $re[1];
            $domain_path = "/var/lib/squidguard/{$re[1]}/domains";
        }
    }
    if (preg_match("#web-filter-plus\\/BL\\/(.+?)\\/domains#", $path, $re)) {
        $category = $re[1];
        $domain_path = "/var/lib/squidguard/web-filter-plus/BL/{$category}/domains";
    }
    if (preg_match("#blacklist-artica\\/(.+?)\\/(.+?)\\/domains#", $path, $re)) {
        events_ufdb_tail("find double category \"{$re[1]}-{$re[2]}\"...", __LINE__);
        $category = "{$re[1]}-{$re[2]}";
        $domain_path = "/var/lib/squidguard/blacklist-artica/{$re[1]}/{$re[2]}/domains";
    }
    if (preg_match("#blacklist-artica\\/sex\\/(.+?)\\/domains#", $path, $re)) {
        $category = $re[1];
        $domain_path = "/var/lib/squidguard/blacklist-artica/sex/{$category}/domains";
    }
    if ($category == null) {
        events_ufdb_tail("exec.squidguard.php:: \"{$path}\" cannot understand...");
    }
    events_ufdb_tail("exec.squidguard.php:: Found category \"{$category}\"", __LINE__);
    if (!is_file($path)) {
        events_ufdb_tail("exec.squidguard.php:{$category}: \"{$path}\" no such file, build it", __LINE__);
        @file_put_contents($domain_path, " ");
    }
    $category_compile = substr($category, 0, 15);
    if (strlen($category_compile) > 15) {
        $category_compile = str_replace("recreation_", "recre_", $category_compile);
        $category_compile = str_replace("automobile_", "auto_", $category_compile);
        $category_compile = str_replace("finance_", "fin_", $category_compile);
        if (strlen($category_compile) > 15) {
            $category_compile = str_replace("_", "", $category_compile);
            if (strlen($category_compile) > 15) {
                $category_compile = substr($category_compile, strlen($category_compile) - 15, 15);
            }
        }
    }
    events_ufdb_tail("exec.squidguard.php:: category \"{$category}\" retranslated to \"{$category_compile}\"", __LINE__);
    if (is_file("{$domain_path}.ufdb")) {
        events_ufdb_tail("exec.squidguard.php:: removing \"{$domain_path}.ufdb\" ...");
        @unlink("{$domain_path}.ufdb");
    }
    if (!is_file($domain_path)) {
        events_ufdb_tail("exec.squidguard.php:: {$domain_path} no such file, create an empty one", __LINE__);
        @mkdir(dirname($domain_path), 0755, true);
        @file_put_contents($domain_path, "#");
    }
    $urlcmd = null;
    $d = " -d {$domain_path}";
    if (is_file("{$OriginalDirename}/urls")) {
        $urlssize = @filesize("{$OriginalDirename}/urls");
        events_ufdb_tail("exec.squidguard.php:: {$OriginalDirename}/urls {$urlssize} bytes...", __LINE__);
        if ($urlssize > 50) {
            $urlcmd = " -u {$OriginalDirename}/urls";
        }
    }
    $NICE = EXEC_NICE();
    $cmd = "{$NICE}{$ufdbGenTable} -n -D -W -t {$category_compile}{$d}{$urlcmd} 2>&1";
    events_ufdb_tail("exec.squidguard.php:{$category}:{$cmd}");
    $time = time();
    exec($cmd, $results);
    exec($cmd, $results);
    while (list($a, $b) = each($results)) {
        if (strpos($b, "is not added because it was already matched")) {
            continue;
        }
        if (strpos($b, "has optimised subdomains")) {
            continue;
        }
        events_ufdb_tail("exec.squidguard.php:{$category}:{$b}");
    }
    $tookrecompile = $unix->distanceOfTimeInWords($time, time());
    events_ufdb_tail("exec.squidguard.php:{$category_compile}: execution {$tookrecompile}", __LINE__);
    events_ufdb_tail("exec.squidguard.php:{$category}:done..");
    $user = GetSquidUser();
    $chown = $unix->find_program("chown");
    if (is_file($chown)) {
        events_ufdb_tail("exec.squidguard.php:{$category}:{$chown} -R {$user} {$OriginalDirename}");
        shell_exec("{$chown} -R {$user} {$OriginalDirename}/*");
        shell_exec("{$chown} -R {$user} /var/log/squid/*");
    }
    $sock = new sockets();
    $took = $unix->distanceOfTimeInWords($timeStart, time());
    $sock->TOP_NOTIFY("{$OriginalDirename} webfiltering database ({$category}) was recompiled took {$took} hard compilation took: {$tookrecompile}", "info");
}
function DNS_DEL_ENTRY($value)
{
    $hostname = base64_decode($value);
    $EXEC_NICE = EXEC_NICE();
    if (is_file("/usr/bin/nohup")) {
        $nohup = "/usr/bin/nohup ";
    }
    $reload_datas = $nohup . $EXEC_NICE . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --export-all-dns >/dev/null 2>&1 &";
    include_once dirname(__FILE__) . "/ressources/class.pdns.inc";
    $ldap = new clladp();
    $upd = array();
    $tbl = explode(".", $hostname);
    $dc = "dc=" . @implode(",dc=", $tbl);
    if ($ldap->ExistsDN("{$dc},ou=dns,{$ldap->suffix}")) {
        if ($ldap->ldap_delete("{$dc},ou=dns,{$ldap->suffix}", true)) {
            send_email_events("Success deleting DNS entry {$hostname}", "DN removed was : {$dc},ou=dns,{$ldap->suffix}", "CLOUD");
            return true;
        }
    } else {
        events("unable to stat {$dc},ou=dns,{$ldap->suffix}", __FUNCTION__, __FILE__, __LINE__);
    }
    $suffix = "ou=dns,{$ldap->suffix}";
    $pattern = "(&(objectclass=*)(associatedDomain={$hostname}))";
    $sr = @ldap_search($ldap->ldap_connection, $suffix, "{$pattern}", array());
    if ($sr) {
        $hash = ldap_get_entries($ldap->ldap_connection, $sr);
        for ($i = 0; $i < $hash["count"]; $i++) {
            $dn = $hash[$i]["dn"];
            if (strlen($dn) > 0) {
                $dns[] = $dn;
                events("removing  associateddomain={$hostname} in {$dn}", __FUNCTION__, __FILE__, __LINE__);
                $upd["associateddomain"] = $hostname;
                if (!$ldap->Ldap_del_mod($dn, $upd)) {
                    $dns[] = $ldap->ldap_last_error;
                }
            }
        }
        send_email_events("Success executing remove DNS entry {$hostname}", @implode("\n", $dns), "CLOUD");
        return true;
    }
    events("Failed -> notify", __FUNCTION__, __FILE__, __LINE__);
    send_email_events("Failed remove DNS entry {$hostname} does not exists", null, "CLOUD");
    shell_exec($reload_datas);
    return true;
}
Example #20
0
function execute()
{
    $nice = EXEC_NICE();
    if (is_file(dirname(__FILE__) . "/exec.sarg.gilou.php")) {
        shell_exec($nice . LOCATE_PHP5_BIN2() . " " . dirname(__FILE__) . "/exec.sarg.gilou.php --exec");
        return;
    }
    $nice = EXEC_NICE();
    $unix = new unix();
    $today = date("d/m/Y");
    $sarg_bin = $unix->find_program("sarg");
    if (!is_file($sarg_bin)) {
        echo "Sarg not installed";
        return;
    }
    buildconf();
    $usersauth = false;
    $squid = new squidbee();
    if ($squid->LDAP_AUTH == 1) {
        $usersauth = true;
    }
    if ($squid->LDAP_EXTERNAL_AUTH == 1) {
        $usersauth = true;
    }
    if (!is_file("/etc/squid/exclude_codes")) {
        @file_put_contents("/etc/squid/exclude_codes", "\nNONE/400\n");
    }
    @mkdir("/usr/share/artica-postfix/squid", 755, true);
    if ($usersauth) {
        echo "Starting......: Sarg, user authentification enabled\n";
        $u = " -i ";
    } else {
        echo "Starting......: Sarg, user authentification disabled\n";
    }
    $cmd = "{$nice}{$sarg_bin} -d {$today}-{$today} {$u}-f /etc/squid3/sarg.conf -l /var/log/squid/sarg.log -o /usr/share/artica-postfix/squid -x -z 2>&1";
    $t1 = time();
    echo "Starting......: Sarg, {$cmd}\n";
    exec($cmd, $results);
    while (list($index, $line) = each($results)) {
        if (preg_match("#SARG: No records found#", $line)) {
            $subject_add = "(No records found)";
        }
        if (preg_match("#SARG:\\s+.+?mixed records format#", $line)) {
            send_email_events("SARG: Error, squid was reloaded", "It seems that there is a mixed log file format detected in squid\n\t\t\tThis reason is Artica change squid log format from orginial to http access mode.\n\t\t\tIn this case, the log will be moved and squid will be reloaded \n\t\t\tin order to build a full log file with only one log format.\n\t\t\t\n" . @implode("\n", $results), "proxy");
            shell_exec(LOCATE_PHP5_BIN2() . " " . dirname(__FILE__) . "/exec.squid.php --reconfigure");
            shell_exec($unix->LOCATE_SQUID_BIN() . " -k rotate");
            shell_exec("/etc/init.d/artica-postfix restart squid-tail");
            return;
        }
        if (preg_match("#SARG:\\s+.+?enregistrements de plusieurs formats#", $line)) {
            send_email_events("SARG: Error, squid was reloaded", "It seems that there is a mixed log file format detected in squid\n\t\t\tThis reason is Artica change squid log format from orginial to http access mode.\n\t\t\tIn this case, the log will be moved and squid will be reloaded \n\t\t\tin order to build a full log file with only one log format.\n\t\t\t\n" . @implode("\n", $results), "proxy");
            shell_exec(LOCATE_PHP5_BIN2() . " " . dirname(__FILE__) . "/exec.squid.php --reconfigure");
            shell_exec($unix->LOCATE_SQUID_BIN() . " -k rotate");
            shell_exec("/etc/init.d/artica-postfix restart squid-tail");
            return;
        }
        if (preg_match("#SARG.+?Unknown input log file format#", $line)) {
            send_email_events("SARG: \"Unknown input log file format\", squid was reloaded", "It seems that there is a input log file format log file format detected in squid\n\t\t\tThis reason is Artica change squid log format from orginial to log_fqn on, this will be disabled\n\t\t\tIn this case, the log will be moved and squid will be reloaded \n\t\t\tin order to build a full log file with only one log format.\n\t\t\t\n" . @implode("\n", $results), "proxy");
            shell_exec(LOCATE_PHP5_BIN2() . " " . dirname(__FILE__) . "/exec.squid.php --reconfigure");
            shell_exec($unix->LOCATE_SQUID_BIN() . " -k rotate");
            shell_exec("/etc/init.d/artica-postfix restart squid-tail");
            return;
        }
    }
    $unix = new unix();
    $lighttpd_user = $unix->LIGHTTPD_USER();
    echo "Starting......: Sarg, lighttpd user: {$lighttpd_user}\n";
    $chown = $unix->find_program("chown");
    echo "Starting......: Sarg,{$chown} -R {$lighttpd_user}:{$lighttpd_user} /usr/share/artica-postfix/squid/*\n";
    exec("{$chown} -R {$lighttpd_user}:{$lighttpd_user} /usr/share/artica-postfix/squid/* >/dev/null 2>&1", $results2);
    echo "Starting......: Sarg,\n" . @implode("\n" . $results2) . "\n";
    $t2 = time();
    $distanceOfTimeInWords = distanceOfTimeInWords($t1, $t2);
    echo "Starting......: Sarg, {$distanceOfTimeInWords}\n";
    if ($GLOBALS["VERBOSE"]) {
        echo "SARG: Statistics generated ({$distanceOfTimeInWords})\n\n";
        echo @implode("\n", $results) . "\n";
    }
    send_email_events("SARG: Statistics generated ({$distanceOfTimeInWords}) {$subject_add}", "Command line:\n-----------\n{$cmd}\n" . @implode("\n", $results), "proxy");
}
function ParseSquidLogMain()
{
    if (systemMaxOverloaded()) {
        return;
    }
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pid = @file_get_contents($pidfile);
    if ($pid < 100) {
        $pid = null;
    }
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        events("ParseSquidLogBrutProcess:: Already executed pid {$pid} since {$time}mn-> DIE", __LINE__);
        if ($GLOBALS["VERBOSE"]) {
            echo "Already executed pid {$pid} since {$time}mn\n";
        }
        die;
    }
    $WORKDIR = "/var/log/artica-postfix/dansguardian-stats2";
    $dirs = $unix->dirdir($WORKDIR);
    $php5 = $unix->LOCATE_PHP5_BIN();
    $nice = EXEC_NICE();
    $nohup = $unix->find_program("nohup");
    while (list($dir, $val) = each($dirs)) {
        $basename = basename($dir);
        if ($basename == "--verbose") {
            continue;
        }
        $pidfile = "/etc/artica-postfix/pids/squidMysqllogs.{$basename}.lock.pid";
        $pid = @file_get_contents($pidfile);
        $filesCount = $unix->COUNT_FILES($dir);
        events_brut("ParseSquidLogMain:: {$filesCount} files, {$basename}: {$pidfile} PID:{$pid} ");
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $MNS = $unix->PROCCESS_TIME_MIN($pid);
            events_brut("ParseSquidLogMain:: {$basename}: {$filesCount} files, Already process running pid: {$pid} since {$MNS}mn");
            continue;
        }
        $Procs = ParseSquidLogMainProcessCount("squid-sql-proc", $basename);
        if ($Procs > 0) {
            $MNS = $unix->PROCCESS_TIME_MIN($pid);
            events_brut("ParseSquidLogMain:: {$Procs} processe(s) already in memory");
            continue;
        }
        $cmd = "{$nohup} {$php5} " . __FILE__ . " --squid-sql-proc {$basename} >/dev/null 2>&1 &";
        events_brut("ParseSquidLogMain:: {$filesCount} files Fork for {$basename} sub-dir", __LINE__);
        shell_exec($cmd);
    }
    $filesCount = $unix->COUNT_FILES($WORKDIR);
    $pidfile = "/etc/artica-postfix/pids/squidMysqllogs.lock.pid";
    $pid = @file_get_contents($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $MNS = $unix->PROCCESS_TIME_MIN($pid);
        events_brut("ParseSquidLogMain:: NULL: {$filesCount} files Already process running pid: {$pid} since {$MNS}mn");
    } else {
        $cmd = "{$nohup} {$php5} " . __FILE__ . " --squid-sql-proc >/dev/null 2>&1 &";
        events_brut("ParseSquidLogMain:: {$filesCount} files, Fork for NULL DIR", __LINE__);
        shell_exec($cmd);
    }
}
Example #22
0
if (GET_INFO_DAEMON("cpuLimitEnabled") == 1) {
    $GLOBALS["cpuLimitEnabled"] = true;
} else {
    $GLOBALS["cpuLimitEnabled"] = false;
}
$GLOBALS["OVERLOADED"] = system_is_overloaded();
if ($GLOBALS["OVERLOADED"]) {
    writelogs("This system is overloaded", __FUNCTION__, __FILE__, __LINE__);
    if ($GLOBALS["cpuLimitEnabled"]) {
        if (GET_INFO_DAEMON("cpulimit") > 0) {
            shell_exec("/usr/share/artica-postfix/bin/process1 --cpulimit");
        }
    }
}
$dirname = dirname(__FILE__);
$_GET["NICE"] = EXEC_NICE();
$_GET["PHP5"] = LOCATE_PHP5_BIN();
$users = new usersMenus();
$sock = new sockets();
$GLOBALS["SQUID_INSTALLED"] = $users->SQUID_INSTALLED;
$GLOBALS["POSTFIX_INSTALLED"] = $users->POSTFIX_INSTALLED;
$GLOBALS["SAMBA_INSTALLED"] = $users->SAMBA_INSTALLED;
$_GET["MIME_DEFANGINSTALLED"] = $users->MIMEDEFANG_INSTALLED;
$GLOBALS["DANSGUARDIAN_INSTALLED"] = $users->DANSGUARDIAN_INSTALLED;
$GLOBALS["KAS_INSTALLED"] = $users->kas_installed;
if ($GLOBALS["VERBOSE"]) {
    writelogs("DANSGUARDIAN_INSTALLED={$GLOBALS["DANSGUARDIAN_INSTALLED"]}", "MAIN", __FILE__, __LINE__);
}
$GLOBALS["EnableArticaWatchDog"] = GET_INFO_DAEMON("EnableArticaWatchDog");
if ($GLOBALS["VERBOSE"]) {
    if ($GLOBALS["POSTFIX_INSTALLED"]) {
Example #23
0
function HyperCacheMirror($JustID = 0)
{
    $unix = new unix();
    $httrack = $unix->find_program("httrack");
    if (!is_file($httrack)) {
        if ($GLOBALS["VERBOSE"]) {
            echo "httrack no such binary\n";
        }
        return;
    }
    $q = new mysql_squid_builder();
    if (!$q->FIELD_EXISTS("artica_caches_mirror", "ToDelete")) {
        $sql = "ALTER TABLE `artica_caches_mirror` ADD `ToDelete` SMALLINT(1) NOT NULL DEFAULT '0',ADD INDEX(`ToDelete`)";
        $q->QUERY_SQL($sql);
        if (!$q->ok) {
            squid_admin_enforce(1, "Fatal: MySQL error", $q->mysql_error, __FILE__, __LINE__);
            return;
        }
    }
    if (!$q->FIELD_EXISTS("artica_caches_mirror", "RunEvents")) {
        $sql = "ALTER TABLE `artica_caches_mirror` ADD `RunEvents` TEXT";
        $q->QUERY_SQL($sql);
        if (!$q->ok) {
            squid_admin_enforce(1, "Fatal: MySQL error", $q->mysql_error, __FILE__, __LINE__);
            return;
        }
    }
    $nice = EXEC_NICE();
    $sql = "SELECT * FROM artica_caches_mirror WHERE enabled=1 AND `ToDelete`=0";
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        squid_admin_enforce(1, "Fatal: MySQL error", $q->mysql_error, __FILE__, __LINE__);
        return;
    }
    if (!isset($GLOBALS["HyperCacheStoragePath"])) {
        $sock = new sockets();
        $GLOBALS["HyperCacheStoragePath"] = $sock->GET_INFO("HyperCacheStoragePath");
        if ($GLOBALS["HyperCacheStoragePath"] == null) {
            $GLOBALS["HyperCacheStoragePath"] = "/home/artica/proxy-cache";
        }
    }
    $t1 = time();
    $count = 0;
    if (mysql_num_rows($results) == 0) {
        return;
    }
    $proxyport = $unix->squid_internal_port();
    $HyperCache = new HyperCache();
    while ($ligne = mysql_fetch_assoc($results)) {
        if ($JustID > 0) {
            if ($ligne["ID"] != $JustID) {
                events("Scrapping rule ID {$ligne["ID"]} !skipped", 0, 2, __LINE__);
                continue;
            }
        }
        $t = time();
        $count++;
        $sitename = $ligne["sitename"];
        $sitename_path = $HyperCache->HyperCacheUriToHostname($sitename);
        $workingdir = $GLOBALS["HyperCacheStoragePath"] . "/mirror/{$sitename_path}";
        $TimeExec = $ligne["TimeExec"];
        $TimeExecLast = $unix->file_time_min("{$workingdir}/TimeExec");
        if (!$GLOBALS["FORCE"]) {
            events("Scrapping {$sitename} require {$TimeExec}mn, current {$TimeExecLast}Mn", 0, 2, __LINE__);
            if ($TimeExecLast < $TimeExec) {
                continue;
            }
        }
        events("Scrapping rule ID {$ligne["ID"]} for {$sitename}", 0, 2, __LINE__);
        $minrate = $ligne["minrate"];
        $maxfilesize = $ligne["maxfilesize"];
        $maxsitesize = $ligne["maxsitesize"];
        $maxfilesize = $maxfilesize * 1000;
        $maxsitesize = $maxsitesize * 1000;
        $minrate = $minrate * 1000;
        $update = null;
        $resultsCMD = array();
        $pidpath = "{$GLOBALS["HyperCacheStoragePath"]}/mirror/{$sitename_path}/hts-in_progress.lock";
        if (!is_dir($workingdir)) {
            @mkdir($workingdir, 0755, true);
        }
        @chown("{$GLOBALS["HyperCacheStoragePath"]}/mirror", "squid");
        @chgrp("{$GLOBALS["HyperCacheStoragePath"]}/mirror", "squid");
        @chown("{$GLOBALS["HyperCacheStoragePath"]}/mirror/{$sitename_path}", "squid");
        @chgrp("{$GLOBALS["HyperCacheStoragePath"]}/mirror/{$sitename_path}", "squid");
        if (is_file($pidpath)) {
            $PID = HyperCacheMirror_pid($pidpath);
            if ($unix->process_exists($PID)) {
                events("Scrapping rule ID {$ligne["ID"]} for {$sitename} Process {$PID} already running since " . $unix->PROCESS_TIME_INT($PID), 0, 2, __LINE__);
                continue;
            }
        }
        @file_put_contents("{$workingdir}/TimeExec", time());
        if (is_file("{$workingdir}/hts-cache")) {
            $update = " --update";
        }
        $cmdline = array();
        $cmdline[] = "{$httrack} \"{$sitename}\" --quiet{$update} -%U squid --proxy 127.0.0.1:{$proxyport}";
        $cmdline[] = "--stay-on-same-domain -u2 -C1 -I0 -N100 --robots=0 --max-files={$maxfilesize}";
        $cmdline[] = "--max-size={$maxsitesize}";
        $cmdline[] = "-O \"{$workingdir}\" 2>&1";
        squid_admin_enforce(2, "Scrapping {$sitename} using proxy 127.0.0.1:{$proxyport}...", null, __FILE__, __LINE__);
        $cmd = @implode(" ", $cmdline);
        if ($GLOBALS["VERBOSE"]) {
            echo "{$cmd}\n";
        }
        exec($cmd, $resultsCMD);
        if ($GLOBALS["VERBOSE"]) {
            echo @implode("\n", $resultsCMD);
        }
        $dirsize = $unix->DIRSIZE_BYTES($workingdir);
        $took = $unix->distanceOfTimeInWords($t, time(), true);
        $dirsizeText = round($dirsize / 1024 / 1000, 2);
        squid_admin_enforce(2, "Mirror on {$sitename} done took {$took} size={$dirsizeText} MB", null, __FILE__, __LINE__);
        $logs = mysql_escape_string2(@file_get_contents("{$workingdir}/hts-log.txt"));
        $q->QUERY_SQL("UPDATE artica_caches_mirror SET \n\t\t\t\tsize='{$dirsize}',`RunEvents`='{$logs}' WHERE ID={$ligne["ID"]}", "artica_backup");
        if (!$q->ok) {
            squid_admin_enforce(1, "MySQL error", $q->mysql_error, __FILE__, __LINE__);
        }
    }
    $took = $unix->distanceOfTimeInWords($t1, time(), true);
    squid_admin_enforce(2, "{$count} web site(s) scrapped took {$took}", null, __FILE__, __LINE__);
}
Example #24
0
function StartUpdate()
{
    $updaterbin = "/opt/kaspersky/kav4proxy/bin/kav4proxy-keepup2date";
    if (!is_file($updaterbin)) {
        return;
    }
    $t = time();
    ufdbguard_admin_events("Starting updating Kaspersky For Proxy server", __FUNCTION__, __FILE__, __LINE__, "update");
    $unix = new unix();
    $sock = new sockets();
    @mkdir("{$GLOBALS["RUN_DIR"]}", 0777, true);
    $chmod = $unix->find_program("chmod");
    shell_exec("{$chmod} 777 {$GLOBALS["RUN_DIR"]}");
    $pidFile = "{$GLOBALS["RUN_DIR"]}/keepup2date.pid";
    $pid = $unix->get_pid_from_file($pidFile);
    if ($unix->process_exists($pid)) {
        ufdbguard_admin_events("Other instance {$pid} running, aborting task", __FUNCTION__, __FILE__, __LINE__, "update");
        return;
    }
    $Kav4ProxyDatabasePath = $sock->GET_INFO("Kav4ProxyDatabasePath");
    if ($Kav4ProxyDatabasePath == null) {
        $Kav4ProxyDatabasePath = "/home/artica/squid/kav4proxy/bases";
    }
    $php5 = $unix->LOCATE_PHP5_BIN();
    shell_exec("{$php5} /usr/share/artica-postfix/exec.kav4proxy.php --build");
    @mkdir("/opt/tmp", 0755, true);
    @mkdir("{$Kav4ProxyDatabasePath}", 0755, true);
    @mkdir("/var/log/artica-postfix/kaspersky/kav4proxy", 0755, true);
    shell_exec("{$chmod} 777 /opt/tmp");
    shell_exec("{$chmod} 777 {$Kav4ProxyDatabasePath}");
    buildConf();
    $logfile = "/var/log/artica-postfix/kaspersky/kav4proxy/" . date("Y-m-d_H-i-s");
    $tmpFileName = "/etc/artica-postfix/kav4proxy-keepup2date.conf";
    $nice = EXEC_NICE();
    $cmd = "{$nice}{$updaterbin} -d {$pidFile} -c {$tmpFileName} -l {$logfile} 2>&1";
    ufdbguard_admin_events("{$cmd}", __FUNCTION__, __FILE__, __LINE__, "update");
    shell_exec($cmd);
    $t2 = time();
    $timehuman = $unix->distanceOfTimeInWords($t, $t2);
    ufdbguard_admin_events("Updating Kaspersky For Proxy server finish took {$timehuman}", __FUNCTION__, __FILE__, __LINE__, "update");
    ufdbguard_admin_events(@file_get_contents($logfile), __FUNCTION__, __FILE__, __LINE__, "update");
    $t = file($logfile);
    while (list($index, $line) = each($t)) {
        if (preg_match("#^\\[.*?F\\]\\s+(.+)#", $line, $re)) {
            ufdbguard_admin_events("Failed: {$re[1]}", __FUNCTION__, __FILE__, __LINE__, "update");
        }
    }
    if ($GLOBALS["VERBOSE"]) {
        $verb = " --verbose";
    }
    shell_exec("/opt/kaspersky/kav4proxy/bin/kav4proxy-licensemanager -i >/etc/artica-postfix/kav4proxy-licensemanager-i");
    shell_exec($unix->LOCATE_PHP5_BIN() . " /usr/share/artica-postfix/exec.kaspersky-update-logs.php --force{$verb}");
    Kav4ProxyDatabasePathSatus();
}
Example #25
0
function backup()
{
    $sock = new sockets();
    $unix = new unix();
    $pidTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    $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);
        echo "Starting......: " . date("H:i:s") . " [INIT]: nginx Already Artica task running PID {$pid} since {$time}mn\n";
        return;
    }
    $time = $unix->file_time_min($pidTime);
    if ($time < 60) {
        return;
    }
    @file_put_contents($pidfile, getmypid());
    @unlink($pidTime);
    @file_put_contents($pidTime, getmypid());
    $SargOutputDir = $sock->GET_INFO("SargOutputDir");
    if ($SargOutputDir == null) {
        $SargOutputDir = "/var/www/html/squid-reports";
    }
    $BackupSargUseNas = $sock->GET_INFO("BackupSargUseNas");
    if (!is_numeric($BackupSargUseNas)) {
        $BackupSargUseNas = 0;
    }
    $nice = EXEC_NICE();
    $mount = new mount("/var/log/sarg-exec.log");
    if ($BackupSargUseNas == 0) {
        return;
    }
    $BackupSargNASIpaddr = $sock->GET_INFO("BackupSargNASIpaddr");
    $BackupSargNASFolder = $sock->GET_INFO("BackupSargNASFolder");
    $BackupSargNASUser = $sock->GET_INFO("BackupSargNASUser");
    $BackupSargNASPassword = $sock->GET_INFO("BackupSargNASPassword");
    $mountPoint = "/mnt/BackupSargUseNas";
    if (!$mount->smb_mount($mountPoint, $BackupSargNASIpaddr, $BackupSargNASUser, $BackupSargNASPassword, $BackupSargNASFolder)) {
        sarg_admin_events("SARG: Unable to connect to NAS storage system: {$BackupSargNASUser}@{$BackupSargNASIpaddr}", __FUNCTION__, __FILE__, __LINE__, "sarg");
        return;
    }
    $BackupDir = "{$mountPoint}/sarg";
    @mkdir("{$BackupDir}", 0755);
    if (!is_dir($BackupDir)) {
        if ($GLOBALS["VERBOSE"]) {
            echo "Fatal {$BackupDir} permission denied\n";
        }
        sarg_admin_events("Fatal {$BackupDir} permission denied", __FUNCTION__, __FILE__, __LINE__, "sarg");
        $mount->umount($mountPoint);
        return false;
    }
    $t = time();
    @file_put_contents("{$BackupDir}/{$t}", time());
    if (!is_file("{$BackupDir}/{$t}")) {
        sarg_admin_events("Fatal {$BackupDir} permission denied", __FUNCTION__, __FILE__, __LINE__, "sarg");
        $mount->umount($mountPoint);
        return false;
    }
    @unlink("{$BackupDir}/{$t}");
    $cp = $unix->find_program("cp");
    shell_exec(trim("{$nice} {$cp} -dpR {$SargOutputDir}/* {$BackupDir}/"));
    $mount->umount($mountPoint);
    sarg_admin_events("Copy to {$BackupSargNASIpaddr}/{$BackupSargNASFolder} done", __FUNCTION__, __FILE__, __LINE__, "sarg");
}
function scan()
{
    $q = new mysql();
    $unix = new unix();
    $postconf = $unix->find_program("postconf");
    if (!is_file($postconf)) {
        return;
    }
    $nice = EXEC_NICE();
    $kill = $unix->find_program("kill");
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $SendMailCache = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".mail";
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        if ($time > 10) {
            unix_system_kill_force($pid);
        } else {
            return;
        }
    }
    $results = array();
    $sock = new sockets();
    $PostfixSMTPNotifs = unserialize(base64_decode($sock->GET_INFO("PostfixSMTPNotifs")));
    if (!isset($PostfixSMTPNotifs["ENABLED_WATCHDOG"])) {
        $PostfixSMTPNotifs["ENABLED_WATCHDOG"] = 0;
    }
    $sql = "CREATE TABLE  IF NOT EXISTS `artica_events`.`postqueuep` (\n\t`zDate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,\n\t`servername` VARCHAR( 255 ) NOT NULL ,\n\t`queuesize` bigint(255) unsigned NOT NULL ,\n\t`queuenum` bigint(255) unsigned NOT NULL ,\n\tINDEX ( `zDate` , `queuesize` , `queuenum`),\n\tKEY `servername` (`servername`)\n\t) ENGINE=MyISAM;\n\t";
    $q->QUERY_SQL($sql, "artica_events");
    if (!$q->ok) {
        echo $q->mysql_error;
    }
    $hostname = $unix->hostname_g();
    $max_messages = $PostfixSMTPNotifs["max_messages"];
    $postqueue = $unix->find_program("postqueue");
    if ($GLOBALS["VERBOSE"]) {
        echo "{$nice} {$postqueue} -p|grep -E \"[0-9]+\\s+Requests\" 2>&1\n";
    }
    exec(trim("{$nice} {$postqueue} -p|grep -E \"[0-9]+\\s+Requests\" 2>&1"), $results);
    if ($GLOBALS["VERBOSE"]) {
        echo "found " . count($results) . " lines.\n";
    }
    while (list($num, $ligne) = each($results)) {
        if (!preg_match("#([0-9]+)\\s+(.*?)\\s+in\\s+([0-9]+)\\s+Requests#", $ligne, $re)) {
            if ($GLOBALS["VERBOSE"]) {
                echo "{$ligne} no match\n";
            }
            continue;
        }
        if ($re[2] != "Kbytes") {
            system_admin_events("{$re[2]} Unable to understand this format", __FUNCTION__, __FILE__, __LINE__);
        }
        $size = $re[1];
        $kbytes = $re[2];
        $requests = $re[3];
        $time = date("Y-m-d H:i:s");
        if ($GLOBALS["VERBOSE"]) {
            echo "{$requests} requests/{$max_messages}\n";
        }
        if ($requests >= $max_messages) {
            if ($PostfixSMTPNotifs["ENABLED_WATCHDOG"] == 1) {
                $time = $unix->file_time_min($SendMailCache);
                if ($time > 15) {
                    if ($GLOBALS["VERBOSE"]) {
                        echo "Queue exceed {$requests}/{$max_messages} -> Send Mail\n";
                    }
                    $unix->SendEmailConfigured($PostfixSMTPNotifs, "Queue exceed {$requests}/{$max_messages}", "Your server reach the max messages in it's queue, come on!");
                }
            }
        }
        $sql = "INSERT IGNORE INTO postqueuep (zDate,servername,queuesize,queuenum) VALUES ('{$time}','{$hostname}','{$size}','{$requests}')";
        $q->QUERY_SQL($sql, "artica_events");
        if (!$q->ok) {
            @mkdir("/var/log/artica-postfix/postqueuep_error", 0755, true);
            @file_put_contents("/var/log/artica-postfix/postqueuep_error/" . md5($sql), $sql);
        }
    }
}
Example #27
0
function VirtualBoxList()
{
    if ($GLOBALS["VERBOSE"]) {
        echo "starting analyze VirtualBox machines...\n";
    }
    $users = new usersMenus();
    if (!$users->VIRTUALBOX_INSTALLED) {
        events("Virtualbox not installed...", __FUNCTION__, __FILE__, __LINE__);
        if ($GLOBALS["VERBOSE"]) {
            echo "terminated... (" . __LINE__ . ")\n";
        }
        return null;
    }
    $sock = new sockets();
    $array = unserialize(base64_decode($sock->getFrameWork("cmd.php?virtualbox-list-vms=yes")));
    if (!is_array($array)) {
        events("Not an array", __FUNCTION__, __FILE__, __LINE__);
        if ($GLOBALS["VERBOSE"]) {
            echo "terminated... (" . __LINE__ . ")\n";
        }
        return;
    }
    while (list($vboxname, $vboxArray) = each($array)) {
        if ($GLOBALS["VERBOSE"]) {
            echo "check {$vboxname} (" . __LINE__ . ")\n";
        }
        $CPUSTATS = unserialize(base64_decode($sock->getFrameWork("cmd.php?virtualbox-showcpustats=yes&virtual-machine=" . base64_encode($vboxname))));
        $array[$vboxname]["METRICS"] = $CPUSTATS;
    }
    reset($array);
    $EXEC_NICE = EXEC_NICE();
    if (is_file("/usr/bin/nohup")) {
        $nohup = "/usr/bin/nohup ";
    }
    $cmd = $nohup . $EXEC_NICE . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --export-virtualbox-logs >/dev/null 2>&1 &";
    shell_exec($cmd);
    return base64_encode(serialize($array));
}
Example #28
0
function postqueue_master($instance = "MASTER")
{
    $unix = new unix();
    $NICE = EXEC_NICE();
    if ($GLOBALS["VERBOSE"]) {
        echo __FUNCTION__ . ":: {$instance}:: analyze {$instance}\n";
    }
    $instance_name = $instance;
    if ($instance == "MASTER") {
        $instance_text = "master";
        $instance = null;
    } else {
        $instance = "-{$instance}";
        $instance_text = $instance;
    }
    $postqueue = $unix->find_program("postqueue");
    if ($GLOBALS["VERBOSE"]) {
        echo __FUNCTION__ . ":: {$instance}:: {$postqueue} -c /etc/postfix{$instance} -p\n";
    }
    exec("{$NICE}{$postqueue} -c /etc/postfix{$instance} -p", $results);
    $count = count($results);
    $array["COUNT"] = postqueue_master_count($instance, $results);
    if ($GLOBALS["VERBOSE"]) {
        echo __FUNCTION__ . ":: {$instance}:: {$array["COUNT"]} message(s)\n";
    }
    $MSGID = null;
    for ($i = 0; $i <= $count; $i++) {
        $line = $results[$i];
        $active = false;
        if (preg_match("#([A-Z0-9\\*]+)\\s+([0-9]+)\\s+(.+?)\\s+([0-9]+)\\s+([0-9:]+)\\s+(.+?)\$#", $line, $re)) {
            $MSGID = $re[1];
            if (strpos($MSGID, "*") > 0) {
                $active = true;
            }
            $MSGID = str_replace("*", "", $MSGID);
            $size = $re[2];
            $day = $re[3];
            $dayNum = $re[4];
            $time = $re[5];
            $from = $re[6];
            $timestamp = strtotime("{$day} {$dayNum} {$time}");
            $date = date('Y-m-d H:i:s', $timestamp);
            $array["LIST"][$instance_text][$MSGID]["DATE"] = "{$day} {$dayNum} {$time}";
            $array["LIST"][$instance_text][$MSGID]["timestamp"] = $date;
            $array["LIST"][$instance_text][$MSGID]["FROM"] = "{$from}";
            $array["LIST"][$instance_text][$MSGID]["msgsize"] = $size;
            if ($active) {
                $array["LIST"][$instance_text][$MSGID]["ACTIVE"] = "YES";
            }
            if (preg_match("#(.+?)@(.+)#", $array["LIST"][$instance_text][$MSGID]["FROM"], $re)) {
                $array["LIST"][$MSGID]["FROM_DOMAIN"] = $re[2];
            }
            continue;
        }
        if (preg_match("#^\\((.+?)\\)\$#", trim($line), $re)) {
            $array["LIST"][$instance_text][$MSGID]["STATUS"] = $re[1];
            continue;
        }
        if (preg_match("#^\\s+\\s+\\s+(.+?)\$#", $line, $re)) {
            $array["LIST"][$instance_text][$MSGID]["TO"][] = trim($re[1]);
            continue;
        }
    }
    $content = serialize($array);
    $filename = md5($content);
    if (!is_dir("/var/log/artica-postfix/postqueue")) {
        @mkdir("/var/log/artica-postfix/postqueue", 755, true);
    }
    @file_put_contents("/var/log/artica-postfix/postqueue/{$filename}.array", $content);
}
Example #29
0
function awstats()
{
    $sock = new sockets();
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pidTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    if ($unix->file_time_min($pidTime) < 60) {
        return;
    }
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        return;
    }
    @file_put_contents($pidfile, getmypid());
    @unlink($pidTime);
    @file_put_contents($pidTime, time());
    $sock = new sockets();
    $EnableNginxStats = $sock->GET_INFO("EnableNginxStats");
    if (!is_numeric($EnableNginxStats)) {
        $EnableNginxStats = 0;
    }
    if ($EnableNginxStats == 1) {
        return;
    }
    include_once dirname(__FILE__) . "/ressources/class.awstats.inc";
    include_once dirname(__FILE__) . "/ressources/class.mysql.syslogs.inc";
    $awstats_bin = $unix->LOCATE_AWSTATS_BIN();
    $nice = EXEC_NICE();
    $perl = $unix->find_program("perl");
    $awstats_buildstaticpages = $unix->LOCATE_AWSTATS_BUILDSTATICPAGES_BIN();
    if ($GLOBALS["VERBOSE"]) {
        echo "awstats......: {$awstats_bin}\n";
        echo "statics Pages: {$awstats_buildstaticpages}\n";
        echo "Nice.........: {$nice}\n";
        echo "perl.........: {$perl}\n";
    }
    if (!is_file($awstats_buildstaticpages)) {
        echo "buildstaticpages no such binary...\n";
        return;
    }
    $sock = new sockets();
    $kill = $unix->find_program("kill");
    $NginxWorkLogsDir = $sock->GET_INFO("NginxWorkLogsDir");
    if ($NginxWorkLogsDir == null) {
        $NginxWorkLogsDir = "/home/nginx/logsWork";
    }
    $sys = new mysql_storelogs();
    $files = $unix->DirFiles($NginxWorkLogsDir, "-([0-9\\-]+)\\.log");
    while (list($filename, $line) = each($files)) {
        if (!preg_match("#^(.+?)-[0-9]+-[0-9]+-[0-9]+-[0-9]+\\.log\$#", $filename, $re)) {
            if ($GLOBALS["VERBOSE"]) {
                echo "{$filename}, skip\n";
            }
            continue;
        }
        if ($GLOBALS["VERBOSE"]) {
            echo "{$filename}, domain:{$re[1]}\n";
        }
        $servername = $re[1];
        $GLOBALS["nice"] = $nice;
        $aw = new awstats($servername);
        $aw->set_LogFile("{$NginxWorkLogsDir}/{$filename}");
        $aw->set_LogType("W");
        $aw->set_LogFormat(1);
        $config = $aw->buildconf();
        $SOURCE_FILE_PATH = "{$NginxWorkLogsDir}/{$filename}";
        $configlength = strlen($config);
        if ($configlength < 10) {
            if ($GLOBALS["VERBOSE"]) {
                echo "configuration file lenght failed {$configlength} bytes, aborting {$servername}\n";
            }
            return;
        }
        @file_put_contents("/etc/awstats/awstats.{$servername}.conf", $config);
        @chmod("/etc/awstats/awstats.{$servername}.conf", 644);
        $Lang = $aw->GET("Lang");
        if ($Lang == null) {
            $Lang = "auto";
        }
        @mkdir("/var/tmp/awstats/{$servername}", 666, true);
        $t1 = time();
        $cmd = "{$nice}{$perl} {$awstats_buildstaticpages} -config={$servername} -update -lang={$Lang} -awstatsprog={$awstats_bin} -dir=/var/tmp/awstats/{$servername} -LogFile=\"{$SOURCE_FILE_PATH}\" 2>&1";
        if ($GLOBALS["VERBOSE"]) {
            echo $cmd . "\n";
        }
        shell_exec($cmd);
        $filedate = date('Y-m-d H:i:s', filemtime($SOURCE_FILE_PATH));
        if (!awstats_import_sql($servername)) {
            continue;
        }
        $sys->ROTATE_TOMYSQL($SOURCE_FILE_PATH, $filedate);
    }
}
Example #30
0
function squid_events_purge()
{
    $q = new mysql();
    $t1 = time();
    $sock = new sockets();
    $nice = EXEC_NICE();
    $squidMaxTableDays = $sock->GET_INFO("squidMaxTableDays");
    $squidMaxTableDaysBackup = $sock->GET_INFO("squidMaxTableDaysBackup");
    $squidMaxTableDaysBackupPath = $sock->GET_INFO("squidMaxTableDaysBackupPath");
    if ($squidMaxTableDays == null) {
        $squidMaxTableDays = 730;
    }
    if ($squidMaxTableDaysBackup == null) {
        $squidMaxTableDaysBackup = 1;
    }
    if ($squidMaxTableDaysBackupPath == null) {
        $squidMaxTableDaysBackupPath = "/home/squid-mysql-bck";
    }
    $sql = "SELECT COUNT( ID ) as tcount FROM `dansguardian_events` WHERE `zDate` < DATE_SUB( NOW( ) , INTERVAL {$squidMaxTableDays} DAY )";
    $ligne = @mysql_fetch_array($q->QUERY_SQL($sql, 'artica_events'));
    $events_number = $ligne["tcount"];
    if ($events_number == 0) {
        return;
    }
    if ($events_number < 0) {
        return;
    }
    if (!is_numeric($events_number)) {
        return;
    }
    $unix = new unix();
    $mysqldump = $unix->find_program("mysqldump");
    $gzip_bin = $unix->find_program("gzip");
    $stat_bin = $unix->find_program("stat");
    if ($squidMaxTableDaysBackup == 1) {
        if (!is_file($mysqldump)) {
            send_email_events("PURGE: unable to stat mysqldump the backup cannot be performed", "task aborted, uncheck the backup feature if you want to purge without backup", "proxy");
            return;
        }
        if (strlen($squidMaxTableDaysBackupPath) == 0) {
            send_email_events("PURGE: backup path was not set", "task aborted, uncheck the backup feature if you want to purge without backup", "proxy");
            return;
        }
        @mkdir($squidMaxTableDaysBackupPath, 600, true);
        $targeted_path = "{$squidMaxTableDaysBackupPath}/" . date("Y-m-d") . "." . time() . ".sql";
        $dumpcmd = "{$nice}{$mysqldump} -u {$q->mysql_admin} -p{$q->mysql_password} -h {$q->mysql_server} artica_events dansguardian_events";
        $dumpcmd = $dumpcmd . " -w \"zDate < DATE_SUB( NOW( ) , INTERVAL {$squidMaxTableDays} DAY )\" >{$targeted_path}";
        exec($dumpcmd, $results);
        $text_results = @implode("\n", $results);
        if (!is_file("{$targeted_path}")) {
            send_email_events("PURGE: failed dump table", "task aborted,{$targeted_path} no such file\n{$text_results}\n uncheck the backup feature if you want to purge without backup\n{$dumpcmd}", "proxy");
            return;
        }
        if (is_file($gzip_bin)) {
            $targeted_path_gz = $targeted_path . ".gz";
            shell_exec("{$nice}{$gzip_bin} {$targeted_path} -c >{$targeted_path_gz} 2>&1");
            if (is_file($targeted_path_gz)) {
                @unlink($targeted_path);
                $targeted_path = $targeted_path_gz;
            }
        }
        unset($results);
        exec("{$stat_bin} -c %s {$targeted_path}", $results);
        $filesize = trim(@implode("", $results));
        $filesize = $filesize / 1024;
        $filesize = FormatBytes($filesize);
        $filesize = str_replace("&nbsp;", " ", $filesize);
    }
    $sql = "DELETE FROM `dansguardian_events` WHERE `zDate` < DATE_SUB( NOW( ) , INTERVAL {$squidMaxTableDays} DAY )";
    $q = new mysql();
    $q->QUERY_SQL($sql, "artica_events");
    if (!$q->ok) {
        send_email_events("PURGE: failed removing {$events_number} elements", "task aborted,unable to delete {$events_number} elements,\nError:{$q->mysql_error}\n{$sql}", "proxy");
        return;
    }
    $t2 = time();
    $distanceOfTimeInWords = distanceOfTimeInWords($t1, $t2);
    if ($squidMaxTableDaysBackup == 1) {
        $backuptext = "\nRemoved elements are backuped on your specified folder:{$squidMaxTableDaysBackupPath}\nBackuped datas file:{$targeted_path} ({$filesize})";
    }
    send_email_events("PURGE: success removing {$events_number} elements", "task successfully executed.\nExecution time:{$distanceOfTimeInWords}\nBackuped datas:{$targeted_path}", "proxy");
}