コード例 #1
0
ファイル: exec.itchart.php プロジェクト: BillTheBest/1.6.x
function build_rules()
{
    $q = new mysql_squid_builder();
    $unix = new unix();
    $SQUID_BIN = $unix->LOCATE_SQUID_BIN();
    build_progress("{IT_charter}", 25);
    $sql = "SELECT ID,title FROM itcharters WHERE enabled=1";
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        build_progress("{IT_charter} {mysql_error}", 110);
        echo $q->mysql_error;
        return;
    }
    if (mysql_num_rows($results) == 0) {
        @unlink("/etc/squid3/itCharts.enabled.db");
        squid_admin_mysql(1, "Reloading Proxy service (itCharts)", null, __FILE__, __LINE__);
        build_progress("{IT_charter} {reload_proxy_service}", 90);
        system("{$SQUID_BIN} -f /etc/squid3/squid.conf -k reconfigure");
        build_progress("{IT_charter} {done} 0 {item}", 100);
        return;
    }
    while ($ligne = mysql_fetch_assoc($results)) {
        build_progress("{$ligne["title"]}", 50);
        echo "{$ligne["ID"]}: {$ligne["title"]}\n";
        $MAIN[$ligne["ID"]] = $ligne["title"];
    }
    @file_put_contents("/etc/squid3/itCharts.enabled.db", serialize($MAIN));
    squid_admin_mysql(1, "Reloading Proxy service (itCharts)", null, __FILE__, __LINE__);
    build_progress("{IT_charter} {reload_proxy_service}", 90);
    system("{$SQUID_BIN} -f /etc/squid3/squid.conf -k reconfigure");
    build_progress("{IT_charter} {done} " . count($MAIN) . " {items}", 100);
}
コード例 #2
0
function xstart()
{
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid";
    $pidtime = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".time";
    $pid = @file_get_contents($pidfile);
    if ($GLOBALS["VERBOSE"]) {
        echo "{$pidtime}\n";
    }
    $unix = new unix();
    $squid = $unix->LOCATE_SQUID_BIN();
    if (!$GLOBALS["FORCE"]) {
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($GLOBALS["VERBOSE"]) {
                echo "Already executed pid {$pid} since {$time}mn\n";
            }
            die;
        }
    }
    $mypid = getmypid();
    @file_put_contents($pidfile, $mypid);
    $timefile = $unix->file_time_min($pidtime);
    if ($GLOBALS["VERBOSE"]) {
        echo "Timelock:{$pidtime} {$timefile} Mn\n";
    }
    if (!$GLOBALS["FORCE"]) {
        if ($timefile < 5) {
            if ($GLOBALS["VERBOSE"]) {
                echo "{$timefile}mn require 5mn\n";
            }
            return;
        }
    }
    @unlink($pidtime);
    @file_put_contents($pidtime, time());
    if (!is_file("/home/ufdb/smtp-events/ACCESS_LOG")) {
        if ($GLOBALS["VERBOSE"]) {
            echo "/home/ufdb/smtp-events/ACCESS_LOG no such file\n";
        }
    }
    $array = explode("\n", @file_get_contents("/home/ufdb/smtp-events/ACCESS_LOG"));
    @unlink("/home/ufdb/smtp-events/ACCESS_LOG");
    $body = array();
    $mmstp = new ufdb_msmtp();
    $Subject = count($array) . " Web filtering blocked event(s)";
    $body[] = "Return-Path: <{$mmstp->smtp_sender}>";
    $body[] = "Date: " . date("D, d M Y H:i:s") . " +0100 (CET)";
    $body[] = "From: {$mmstp->smtp_sender}";
    $body[] = "Subject: {$Subject}";
    $body[] = "To: {$mmstp->recipient}";
    $body[] = "";
    $body[] = "";
    $body[] = @implode("\r\n", $array);
    $body[] = "";
    $body[] = "";
    $finalbody = @implode("\r\n", $body);
    if (!$mmstp->Send($finalbody)) {
        squid_admin_mysql(0, "Unable to send notification {$Subject} to {$mmstp->recipient}", "{$Subject} to {$mmstp->recipient}\n------------------\n" . @implode("\n", $array) . "\n\t\tThe following error encountered\n" . $mmstp->logs . "\n", __FILE__, __LINE__);
    }
}
コード例 #3
0
function start_parse()
{
    if ($GLOBALS["VERBOSE"]) {
        "echo Loading...\n";
    }
    $unix = new unix();
    if ($GLOBALS["VERBOSE"]) {
        "echo Loading done...\n";
    }
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $timefile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    $pid = @file_get_contents($pidfile);
    if (!$GLOBALS["FORCE"]) {
        if ($pid < 100) {
            $pid = null;
        }
        $unix = new unix();
        if ($unix->process_exists($pid, basename(__FILE__))) {
            if ($GLOBALS["VERBOSE"]) {
                echo "Already executed pid {$pid}\n";
            }
            return;
        }
        $timeexec = $unix->file_time_min($timefile);
        if ($timeexec < 10) {
            return;
        }
        $mypid = getmypid();
        @file_put_contents($pidfile, $mypid);
    }
    @unlink($timefile);
    @file_put_contents($timefile, time());
    $ldap = new clladp();
    if (!$ldap->IsKerbAuth()) {
        return;
    }
    $q = new mysql_squid_builder();
    $sql = "SELECT ID,GroupName FROM webfilters_sqgroups WHERE `enabled`=1 AND `GroupType`='proxy_auth_statad'";
    $results = $q->QUERY_SQL($sql);
    $REFRESH = false;
    $Count = mysql_num_rows($results);
    $UPDATED = array();
    while ($ligne = mysql_fetch_assoc($results)) {
        if (parse_object($ligne["ID"], $ligne["GroupName"])) {
            $UPDATED[] = $ligne["GroupName"];
            $REFRESH = true;
        }
    }
    if ($REFRESH) {
        squid_admin_mysql(1, "Reloading proxy service after updating " . count($UPDATED) . " Active Directory group(s)", @implode("\n", $UPDATED), __FILE__, __LINE__);
        $squid = $unix->LOCATE_SQUID_BIN();
        system("/etc/init.d/squid reload --force --script=exec.squid.static.ad.groups.php/" . __LINE__);
        $sock = new sockets();
        $EnableTransparent27 = intval($sock->GET_INFO("EnableTransparent27"));
        if ($EnableTransparent27 == 1) {
            system("/etc/init.d/squid-nat reload --script=" . basename(__FILE__));
        }
    }
}
コード例 #4
0
function x_squid_version()
{
    $unix = new unix();
    $squidbin = $unix->LOCATE_SQUID_BIN();
    exec("{$squidbin} -v 2>&1", $results);
    while (list($num, $val) = each($results)) {
        if (preg_match("#Squid Cache: Version.*?([0-9\\.\\-a-z]+)#", $val, $re)) {
            return trim($re[1]);
        }
    }
}
コード例 #5
0
function build($uri)
{
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $unix = new unix();
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        die;
    }
    @file_put_contents($pidfile, getmypid());
    $echo = $unix->find_program("echo");
    $curl = $unix->find_program("curl");
    $squidbin = $unix->LOCATE_SQUID_BIN();
    $curl = $unix->find_program("curl");
    @unlink("/var/log/squid/request.debug");
    $DirFinal = "/usr/share/artica-postfix/ressources/support/" . time();
    @mkdir($DirFinal, 0755, true);
    $SquidMgrListenPort = trim(@file_get_contents("/etc/artica-postfix/settings/Daemons/SquidMgrListenPort"));
    shell_exec("{$echo} \"Proxy address 127.0.0.1:{$SquidMgrListenPort}\" > /var/log/squid/request.debug 2>&1");
    shell_exec("{$echo} \"Url to test: {$uri} \" >> /var/log/squid/request.debug 2>&1");
    progress("{rotate_logs_files}", 30);
    shell_exec("{$echo} \"Rotate & turn to debug... \" >> /var/log/squid/request.debug 2>&1");
    @copy("/var/log/squid/access.log", "/var/log/squid/access.log." . time());
    shell_exec("{$squidbin} -k rotate >> /var/log/squid/request.debug 2>&1");
    progress("{turn_to_debug}", 35);
    shell_exec("{$squidbin} -k debug >/dev/null 2>&1");
    sleep(4);
    progress("{send_query}", 40);
    $cmd = "{$curl} --head --verbose --trace-time --proxy http://127.0.0.1:{$SquidMgrListenPort} --url {$uri} >> /var/log/squid/request.debug 2>&1";
    shell_exec("{$echo} \"{$cmd}\" >> /var/log/squid/request.debug 2>&1");
    shell_exec($cmd);
    sleep(4);
    progress("{return_back_to_normal}", 40);
    LogsThisDebug("************************************************************");
    squid_admin_mysql(1, "Reconfiguring proxy service", null, __FILE__, __LINE__);
    shell_exec("/etc/init.d/squid reload --script=" . basename(__FILE__) . "  >> /var/log/squid/request.debug 2>&1");
    LogsThisDebug("************************************************************");
    sleep(1);
    @copy("/var/log/squid/cache.log", "{$DirFinal}/cache.log");
    progress("{compressing_package}", 90);
    $tar = $unix->find_program("tar");
    $rm = $unix->find_program("rm");
    $filename = "request.tar.gz";
    @unlink("/usr/share/artica-postfix/ressources/support/{$filename}");
    @copy("/var/log/squid/request.debug", "{$DirFinal}/request.debug");
    @unlink("/var/log/squid/request.debug");
    chdir($DirFinal);
    $cmd = "{$tar} -cvzf /usr/share/artica-postfix/ressources/support/{$filename} * 2>&1";
    exec($cmd, $results);
    @chmod("/usr/share/artica-postfix/ressources/support/{$filename}", 0755);
    shell_exec("{$rm} -rf {$DirFinal}");
    LogsThisDebug("*********************************************************");
    $c = 0;
    progress("{success}", 100);
}
コード例 #6
0
function build_whitelist()
{
    build_progress_wb("{compiling}", 30);
    urlrewriteaccessdeny();
    build_progress_wb("{compiling}", 35);
    urlrewriteaccessdeny_squid();
    build_progress_wb("{compiling}", 40);
    build_blacklists();
    $unix = new unix();
    $php5 = $unix->LOCATE_PHP5_BIN();
    $squidbin = $unix->LOCATE_SQUID_BIN();
    squid_admin_mysql(2, "Reloading proxy service for whitelist domains", null, __FILE__, __LINE__);
    build_progress_wb("{reloading}", 90);
    system("{$squidbin} -k reconfigure");
    build_progress_wb("{done}", 100);
}
コード例 #7
0
function tests_port($port_id)
{
    $unix = new unix();
    $squid = new squidbee();
    $q = new mysql_squid_builder();
    $ligne = @mysql_fetch_array($q->QUERY_SQL("SELECT * FROM proxy_ports WHERE ID={$port_id}"));
    $ssl_bump_line = $squid->ssl_bump_line($ligne["sslcertificate"]);
    $randport = rand(63500, 65535);
    build_progress("{testing_ssl_certificate} ID:{$port_id} {$ligne["sslcertificate"]}", 15);
    $t = time();
    $pid_filename = "/var/run/squid/{$t}.pid";
    $cache_log = "/var/log/squid/cache.{$t}.log";
    $f[] = "coredump_dir\t/var/squid/cache";
    $f[] = "cache_log\t/var/log/squid/cache.log";
    $f[] = "pid_filename\t/var/run/squid/squid.pid";
    $f[] = "cache_effective_user squid";
    $f[] = "http_port 127.0.0.1:{$randport} {$ssl_bump_line}";
    echo " ***********************************************************************\n";
    echo "Using HTTPS port {$ssl_bump_line} Certificate {$ligne["sslcertificate"]}\n";
    echo " ***********************************************************************\n";
    $f[] = "";
    $tmpfile = $unix->FILE_TEMP();
    $squidbin = $unix->LOCATE_SQUID_BIN();
    build_progress("{testing_ssl_certificate} {$ligne["sslcertificate"]}", 20);
    echo "Conf  : {$tmpfile}\n";
    echo "Binary: {$squidbin}\n";
    @file_put_contents($tmpfile, @implode("\n", $f));
    exec("{$squidbin} -f {$tmpfile} -k check 2>&1", $results);
    @unlink($tmpfile);
    while (list($num, $line) = each($results)) {
        echo "Check  : {$line}\n";
        if (preg_match("#FATAL: No valid signing SSL#", $line)) {
            build_progress("{testing_ssl_certificate_failed} {$ligne["sslcertificate"]}", 110);
            $sql = "UPDATE proxy_ports SET sslcertificate='' WHERE ID='{$port_id}'";
            $q->QUERY_SQL($sql);
            return;
        }
    }
    build_progress("{testing_ssl_certificate} {success}", 100);
    // FATAL: No valid signing SSL certificate
}
コード例 #8
0
function squid_reconfigure_exe()
{
    $unix = new unix();
    $squidbin = $unix->LOCATE_SQUID_BIN();
    build_progress("Reloading Proxy service...", 10);
    $pid = SQUID_PID();
    if ($unix->process_exists($pid)) {
        build_progress("Reloading Proxy service...", 50);
        system("/etc/init.d/squid reload --force --script=exec.squid.reconfigure.php/" . __LINE__);
        sleep(2);
        $sock = new sockets();
        $EnableTransparent27 = intval($sock->GET_INFO("EnableTransparent27"));
        if ($EnableTransparent27 == 1) {
            build_progress("Reloading Proxy NAT service...", 60);
            system("/etc/init.d/squid-nat reload --script=" . basename(__FILE__));
        }
        build_progress("Reloading Proxy service...{done}", 100);
        return;
    }
    echo "Not running !\n";
    build_progress("Reloading Proxy service {failed}...", 110);
}
コード例 #9
0
function build_whitelist()
{
    $sock = new sockets();
    $EnableTransparent27 = intval($sock->GET_INFO("EnableTransparent27"));
    $PrivoxyEnabled = intval($sock->GET_INFO("PrivoxyEnabled"));
    build_progress_wb("{compiling}", 30);
    urlrewriteaccessdeny();
    build_progress_wb("{compiling}", 35);
    urlrewriteaccessdeny_squid();
    build_progress_wb("{compiling}", 40);
    @unlink("/var/log/squid/ufdbgclient.black.db");
    @file_put_contents("/etc/squid3/ip-blacklists.db", "#");
    @file_put_contents("/etc/squid3/www-blacklists.db", "#");
    build_blacklists(true);
    build_progress_wb("{compiling}", 50);
    $unix = new unix();
    if ($PrivoxyEnabled == 1) {
        build_progress_wb("{compiling} {APP_PRIVOXY}", 55);
        shell_exec("/etc/init.d/privoxy restart");
        build_progress_wb("{compiling} {APP_PRIVOXY} {done}", 60);
    }
    build_progress_wb("{reloading}", 65);
    system("/etc/init.d/squid reload --script=" . basename(__FILE__));
    $sock = new sockets();
    $EnableTransparent27 = intval($sock->GET_INFO("EnableTransparent27"));
    $PrivoxyEnabled = intval($sock->GET_INFO("PrivoxyEnabled"));
    if ($EnableTransparent27 == 1) {
        build_progress_wb("{reloading} NAT", 70);
        system("/etc/init.d/squid-nat reload --script=" . basename(__FILE__));
    }
    $php5 = $unix->LOCATE_PHP5_BIN();
    $squidbin = $unix->LOCATE_SQUID_BIN();
    squid_admin_mysql(2, "Reloading proxy service for whitelist domains", null, __FILE__, __LINE__);
    build_progress_wb("{reloading}", 90);
    system("{$squidbin} -k reconfigure");
    build_progress_wb("{done}", 100);
}
コード例 #10
0
ファイル: exec.sysctl.php プロジェクト: BillTheBest/1.6.x
function build()
{
    $unix = new unix();
    $sock = new sockets();
    $Isagetway = false;
    $INSTALL_SERVICE = false;
    $KernelSendRedirects = $sock->GET_INFO("KernelSendRedirects");
    if (!is_numeric($KernelSendRedirects)) {
        $KernelSendRedirects = 1;
    }
    $conntrack = $unix->find_program("conntrack");
    $EnableChilli = $sock->GET_INFO("EnableChilli");
    $EnableArticaAsGateway = $sock->GET_INFO("EnableArticaAsGateway");
    if (!is_numeric($EnableChilli)) {
        $EnableChilli = 0;
    }
    $hasProxyTransparent = $sock->GET_INFO("hasProxyTransparent");
    if (!is_numeric($hasProxyTransparent)) {
        $hasProxyTransparent = 0;
    }
    $hostname = trim(@file_get_contents("/etc/artica-postfix/FULL_HOSTNAME"));
    if ($EnableChilli == 1) {
        $Isagetway = true;
    }
    if ($EnableArticaAsGateway == 1) {
        $Isagetway = true;
    }
    if ($hasProxyTransparent == 1) {
        $Isagetway = true;
    }
    if (is_file("/etc/artica-postfix/IPTABLES_BR_BRIDGE")) {
        $Isagetway = true;
    }
    if (is_file("/etc/artica-postfix/IPTABLES_BRIDGE")) {
        $Isagetway = true;
    }
    $EnableipV6 = $sock->GET_INFO("EnableipV6");
    if (!is_numeric($EnableipV6)) {
        $EnableipV6 = 0;
    }
    $ARRAY = unserialize(base64_decode($sock->GET_INFO("kernel_values")));
    $swappiness = intval($ARRAY["swappiness"]);
    if ($swappiness == 0) {
        $swappiness = 10;
    }
    $tcp_max_syn_backlog = $ARRAY["tcp_max_syn_backlog"];
    if (!is_numeric($tcp_max_syn_backlog)) {
        $tcp_max_syn_backlog = 1024;
    }
    $EnableTCPOptimize = $sock->GET_INFO("EnableTCPOptimize");
    $DisableConntrack = intval($sock->GET_INFO("DisableConntrack"));
    if (!is_numeric($EnableTCPOptimize)) {
        $EnableTCPOptimize = 1;
    }
    $DisableTCPOptimizations = $sock->GET_INFO("DisableTCPOptimizations");
    if ($DisableTCPOptimizations == 1) {
        $EnableTCPOptimize = 0;
    }
    $echo = $unix->find_program("echo");
    $modprobe = $unix->find_program("modprobe");
    $DisableTCPEn = intval(trim(@file_get_contents("/etc/artica-postfix/settings/Daemons/DisableTCPEn")));
    $DisableTCPWindowScaling = intval(trim(@file_get_contents("/etc/artica-postfix/settings/Daemons/DisableTCPWindowScaling")));
    $EnableSystemOptimize = intval(trim(@file_get_contents("/etc/artica-postfix/settings/Daemons/EnableSystemOptimize")));
    $tcp_ecn = 2;
    $tcp_window_scaling = 1;
    if ($DisableTCPWindowScaling == 1) {
        $tcp_window_scaling = 0;
    }
    if ($DisableTCPEn == 1) {
        $tcp_ecn = 0;
    }
    $sysctl = $unix->find_program("sysctl");
    $f[] = "#";
    $f[] = "# /etc/sysctl.conf - Configuration file for setting system variables";
    $f[] = "# See /etc/sysctl.d/ for additonal system variables";
    $f[] = "# See sysctl.conf (5) for information.";
    $f[] = "#";
    $f[] = "";
    $f[] = "#kernel.domainname = example.com";
    $f[] = "";
    $f[] = "# Uncomment the following to stop low-level messages on console";
    $f[] = "#kernel.printk = 3 4 1 3";
    $f[] = "";
    $f[] = "##############################################################";
    // /proc/sys/vm/dirty_ratio defaults to 20% of RAM
    // /proc/sys/vm/dirty_background_ratio defaults to 10%of RAM
    $memory = $unix->MEM_TOTAL_INSTALLEE() * 1024;
    $dirty_ratio = round($memory * 0.8);
    if ($EnableSystemOptimize == 0) {
        shell_exec("{$echo} 33554432 >/proc/sys/vm/dirty_background_bytes");
        shell_exec("{$echo} {$dirty_ratio} >/proc/sys/vm/dirty_bytes");
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Memory: {$memory} bytes\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} dirty_ratio = {$dirty_ratio} bytes \n";
        }
    } else {
        $swappiness = 0;
        shell_exec("{$echo} 1024 > /sys/block/sda/queue/nr_requests");
    }
    $squidbin = $unix->LOCATE_SQUID_BIN();
    $t = explode(".", $hostname);
    if (count($t) > 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} `hostname` = '{$hostname}'\n";
        }
        $f[] = "kernel.hostname={$t[0]}";
        unset($t[0]);
        $f[] = "kernel.domainname=" . @implode(".", $t);
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} `swappiness` = '{$swappiness}%'\n";
    }
    $f[] = "vm.swappiness = {$swappiness}";
    $f[] = "net.ipv4.icmp_ignore_bogus_error_responses = 1";
    $f[] = "net.ipv4.tcp_window_scaling = {$tcp_window_scaling}";
    $f[] = "net.ipv4.tcp_ecn = {$tcp_ecn}";
    $f[] = "net.ipv4.tcp_sack = 1";
    $f[] = "net.ipv4.tcp_fack = 1";
    $f[] = "net.ipv4.tcp_timestamps = 1";
    $f[] = "net.ipv4.icmp_echo_ignore_broadcasts = 1";
    $f[] = "";
    if ($EnableSystemOptimize == 1) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} set dirty pages\n";
        }
        $f[] = "vm.dirty_background_ratio = 4";
        $f[] = "vm.dirty_background_bytes = 33554432";
        $f[] = "vm.dirty_ratio = 64";
        shell_exec("{$echo} \"100663296\" > /proc/sys/vm/dirty_bytes");
        shell_exec("{$echo} \"33554432\" > /proc/sys/vm/dirty_background_bytes");
        if (is_file($squidbin)) {
            if (is_file("/proc/sys/net/local/dgram/recvspace")) {
                $f[] = "net.local.dgram.recvspace=262144";
            }
            if (is_file("/proc/sys/net/local/dgram/maxdgram")) {
                $f[] = "net.local.dgram.maxdgram=16384";
            }
        }
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} revert dirty pages to default\n";
        }
        $f[] = "vm.dirty_background_ratio = 10";
        $f[] = "vm.dirty_ratio = 20";
        $f[] = "vm.dirty_background_bytes = 0";
        $f[] = "vm.dirty_bytes = 0";
    }
    if (is_file($conntrack)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} conntrack installed\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} conntrack DisableConntrack = {$DisableConntrack}\n";
        }
        if ($DisableConntrack == 1) {
            $f[] = "net.ipv4.netfilter.ip_conntrack_generic_timeout = 600";
            $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_timeout_syn_sent = 120";
            $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_timeout_syn_sent2 = 120";
            $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_timeout_syn_recv = 60";
            $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_timeout_established = 432000";
            $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_timeout_fin_wait = 120";
            $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_timeout_close_wait = 60";
            $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_timeout_last_ack = 30";
            $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_timeout_time_wait = 120";
            $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_timeout_close = 10";
            $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_timeout_max_retrans = 300";
            $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_loose = 1";
            $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_be_liberal = 0";
            $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_max_retrans = 3";
            $f[] = "net.ipv4.netfilter.ip_conntrack_udp_timeout = 30";
            $f[] = "net.ipv4.netfilter.ip_conntrack_udp_timeout_stream = 180";
            $f[] = "net.ipv4.netfilter.ip_conntrack_icmp_timeout = 30";
            $f[] = "net.ipv4.netfilter.ip_conntrack_max = 32088";
            $f[] = "net.ipv4.netfilter.ip_conntrack_log_invalid = 0";
            $f[] = "net.netfilter.nf_conntrack_acct = 0";
            shell_exec("{$echo} 8022 >/sys/module/nf_conntrack/parameters/hashsize >/dev/null 2>&1");
        } else {
            shell_exec("{$modprobe} nf_conntrack >/dev/null 2>&1");
            shell_exec("{$modprobe} nf_conntrack_ipv4 >/dev/null 2>&1");
            $nf_conntrack_max = 196608;
            $ip_conntrack_tcp_timeout_established = 86400;
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} conntrack MAX....: {$nf_conntrack_max}\n";
            }
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} conntrack Timeout: {$ip_conntrack_tcp_timeout_established}\n";
            }
            if (is_file("/proc/sys/net/netfilter/nf_conntrack_acct")) {
                $f[] = "net.netfilter.nf_conntrack_acct = 1";
                $f[] = "net.netfilter.nf_conntrack_checksum = 0";
                $f[] = "net.netfilter.nf_conntrack_max = {$nf_conntrack_max}";
                $f[] = "net.netfilter.nf_conntrack_tcp_timeout_established = {$ip_conntrack_tcp_timeout_established}";
                $f[] = "net.netfilter.nf_conntrack_udp_timeout = 60";
                $f[] = "net.netfilter.nf_conntrack_udp_timeout_stream = 180";
                $f[] = "net.ipv4.netfilter.ip_conntrack_generic_timeout = 600";
                $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_timeout_syn_sent = 120";
                $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_timeout_syn_sent2 = 120";
                $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_timeout_syn_recv = 60";
                $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_timeout_established = {$ip_conntrack_tcp_timeout_established}";
                $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_timeout_fin_wait = 120";
                $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_timeout_close_wait = 60";
                $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_timeout_last_ack = 30";
                $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_timeout_time_wait = 120";
                $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_timeout_close = 10";
                $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_timeout_max_retrans = 300";
                $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_loose = 1";
                $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_be_liberal = 0";
                $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_max_retrans = 3";
                $f[] = "net.ipv4.netfilter.ip_conntrack_udp_timeout = 30";
                $f[] = "net.ipv4.netfilter.ip_conntrack_udp_timeout_stream = 180";
                $f[] = "net.ipv4.netfilter.ip_conntrack_icmp_timeout = 30";
                $f[] = "net.ipv4.netfilter.ip_conntrack_max = {$nf_conntrack_max}";
                $f[] = "net.ipv4.netfilter.ip_conntrack_checksum = 1";
                $f[] = "net.ipv4.netfilter.ip_conntrack_log_invalid = 0";
                shell_exec("{$echo} " . round($nf_conntrack_max / 8) . " > /sys/module/nf_conntrack/parameters/hashsize >/dev/null 2>&1");
            }
        }
    }
    if ($EnableTCPOptimize) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Optimize TCP stack\n";
        }
        $f[] = "net.ipv4.tcp_rfc1337 = 1";
        $f[] = "net.ipv4.tcp_syn_retries = 3";
        $f[] = "net.ipv4.tcp_synack_retries = 2";
        if ($tcp_max_syn_backlog < 1025) {
            $tcp_max_syn_backlog = 10240;
        }
        $wmem_max = trim(intval(@file_get_contents("/proc/sys/net/core/wmem_max")));
        $f[] = "net.ipv4.tcp_max_syn_backlog = {$tcp_max_syn_backlog}";
        $f[] = "net.ipv4.tcp_timestamps = 0";
        $f[] = "net.ipv4.tcp_fin_timeout = 15";
        $f[] = "net.ipv4.tcp_keepalive_time = 1800";
        $f[] = "net.ipv4.tcp_reordering = 5";
        $f[] = "net.ipv4.tcp_synack_retries = 3";
        $f[] = "net.ipv4.tcp_max_tw_buckets = 360000";
        $f[] = "net.core.netdev_max_backlog = 4000";
        $f[] = "net.core.rmem_default = 262144";
        $f[] = "net.core.rmem_max = 262144";
        $f[] = "net.core.wmem_max = 262144";
        $f[] = "net.ipv4.tcp_rmem=10240 87380 {$wmem_max}";
        $f[] = "net.ipv4.tcp_wmem=10240 87380 {$wmem_max}";
        $f[] = "net.ipv4.tcp_mem = {$wmem_max} {$wmem_max} {$wmem_max}";
        $f[] = "net.ipv4.conf.all.log_martians=0";
        $f[] = "net.ipv4.ip_local_port_range = 1024 65000";
        $f[] = "net.ipv4.tcp_window_scaling = {$tcp_window_scaling}";
        $f[] = "net.ipv4.tcp_ecn = {$tcp_ecn}";
        $f[] = "net.ipv4.tcp_low_latency =1 ";
        $f[] = "net.ipv4.tcp_timestamps=1";
        $f[] = "net.ipv4.tcp_sack=1";
        $f[] = "net.ipv4.tcp_no_metrics_save=1";
        $f[] = "net.core.netdev_max_backlog=16384";
        $f[] = "net.core.rmem_max=12582912";
        $f[] = "net.core.wmem_max = 12582912";
        $f[] = "net.core.wmem_default = 65535";
        $f[] = "net.core.optmem_max = 40960";
        $f[] = "net.ipv6.conf.all.accept_redirects = 1";
        $f[] = "net.ipv6.conf.all.accept_source_route = 0";
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} TCP stack set to default\n";
        }
        $f[] = "net.ipv4.tcp_rfc1337 = 0";
        $f[] = "net.ipv4.tcp_low_latency = 0 ";
        $f[] = "net.ipv4.tcp_syn_retries = 5";
        $f[] = "net.ipv4.tcp_synack_retries = 5";
        $f[] = "net.ipv4.tcp_max_syn_backlog = 512";
        $f[] = "net.ipv4.tcp_timestamps = 1";
        $f[] = "net.ipv4.tcp_fin_timeout = 60";
        $f[] = "net.ipv4.tcp_keepalive_time = 7200";
        $f[] = "net.ipv4.tcp_reordering = 3";
        $f[] = "net.ipv4.tcp_max_tw_buckets = 65536";
        $f[] = "net.ipv4.ip_local_port_range = 32768\t61000";
        $f[] = "net.core.rmem_default = 229376";
        $f[] = "net.core.netdev_max_backlog = 1000";
        $f[] = "net.core.rmem_max = 131071";
        $f[] = "net.core.wmem_max = 131071";
        $f[] = "net.ipv4.tcp_rmem = 4096\t87380\t1033696";
        $f[] = "net.ipv4.tcp_wmem = 4096\t16384\t1033696";
        $f[] = "net.ipv4.tcp_mem = 24225\t32303\t48450";
        $f[] = "net.ipv4.tcp_window_scaling = {$tcp_window_scaling}";
        $f[] = "net.ipv4.tcp_ecn = {$tcp_ecn}";
        $f[] = "net.ipv4.tcp_sack = 1";
        $f[] = "net.ipv4.tcp_no_metrics_save = 0";
        $f[] = "net.core.netdev_max_backlog = 1000";
        $f[] = "net.core.rmem_max = 131071";
        $f[] = "net.core.wmem_max = 131071";
        $f[] = "net.core.wmem_default = 229376";
        $f[] = "net.core.optmem_max = 20480";
        $f[] = "net.ipv4.icmp_echo_ignore_broadcasts = 1";
        $f[] = "net.ipv4.conf.all.send_redirects = 1";
        $f[] = "net.ipv4.conf.all.secure_redirects = 1";
        $f[] = "net.ipv4.conf.all.accept_redirects = 1";
        $f[] = "net.ipv4.conf.all.accept_source_route = 0";
        $f[] = "net.ipv4.conf.all.arp_accept = 0";
        $f[] = "net.ipv4.conf.all.arp_ignore = 0";
        $f[] = "net.ipv4.conf.all.arp_announce = 0";
        $f[] = "net.ipv4.conf.all.arp_filter = 0";
        $f[] = "net.ipv4.conf.all.arp_notify = 0";
        $f[] = "net.ipv4.ip_nonlocal_bind = 0";
        $f[] = "net.ipv4.conf.all.log_martians=0";
        $f[] = "net.ipv4.tcp_max_syn_backlog = 512";
    }
    if ($Isagetway) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Set as gateway...\n";
        }
        $f[] = "net.ipv4.ip_forward=1";
        if ($EnableipV6 == 1) {
            $f[] = "net.ipv6.conf.all.send_redirects = {$KernelSendRedirects}";
            $f[] = "net.ipv6.conf.all.forwarding=1";
            $f[] = "net.ipv6.conf.all.accept_redirects = 1";
            $f[] = "net.ipv6.conf.all.accept_source_route = 1";
            $f[] = "net.ipv6.conf.all.arp_accept=0";
            $f[] = "net.ipv6.conf.all.arp_ignore=1";
            $f[] = "net.ipv6.conf.all.arp_announce=2";
            $f[] = "net.ipv6.conf.all.arp_filter=1";
            $f[] = "net.ipv6.conf.all.arp_notify=1";
        }
    }
    if ($EnableipV6 == 1) {
        $f[] = "net.ipv6.conf.all.disable_ipv6 = 0";
        $f[] = "net.ipv6.conf.default.disable_ipv6 = 0";
        $f[] = "net.ipv6.conf.lo.disable_ipv6 = 0";
    } else {
        $f[] = "net.ipv6.conf.all.disable_ipv6 = 1";
        $f[] = "net.ipv6.conf.default.disable_ipv6 = 1";
        $f[] = "net.ipv6.conf.lo.disable_ipv6 = 1";
    }
    $SCRIPT[] = "#!/bin/sh";
    $SCRIPT[] = "### BEGIN INIT INFO";
    $SCRIPT[] = "# Provides:         artica-optimize";
    $SCRIPT[] = "# Required-Start:    \$local_fs";
    $SCRIPT[] = "# Required-Stop:     \$local_fs";
    $SCRIPT[] = "# Should-Start:";
    $SCRIPT[] = "# Should-Stop:";
    $SCRIPT[] = "# Default-Start:     2 3 4 5";
    $SCRIPT[] = "# Default-Stop:      0 1 6";
    $SCRIPT[] = "# Short-Description: artica-optimize";
    $SCRIPT[] = "# chkconfig: - 80 75";
    $SCRIPT[] = "# description: artica-optimize";
    $SCRIPT[] = "### END INIT INFO";
    $SCRIPT[] = "case \"\$1\" in";
    $SCRIPT[] = " start)";
    $SCRIPT[] = "echo \"Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}\"";
    $echo = $unix->find_program("echo");
    while (list($index, $line) = each($f)) {
        if (!preg_match("#(.+?)=(.+)#", $line, $re)) {
            continue;
        }
        $SCRIPT[] = "{$sysctl} -w \"" . trim($re[1]) . "=" . trim($re[2]) . "\" >/dev/null 2>&1 || true";
    }
    $SCRIPT[] = "echo \"Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}\" done.";
    $SCRIPT[] = ";;";
    $SCRIPT[] = "*)";
    $SCRIPT[] = "echo \"Usage: \$0 start\"";
    $SCRIPT[] = "exit 1";
    $SCRIPT[] = ";;";
    $SCRIPT[] = "esac";
    $SCRIPT[] = "exit 0";
    $SCRIPT[] = "";
    if (!is_file("/etc/init.d/artica-optimize")) {
        $INSTALL_SERVICE = true;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} /etc/init.d/artica-optimize done\n";
    }
    @file_put_contents("/etc/init.d/artica-optimize", @implode("\n", $SCRIPT));
    @chmod("/etc/init.d/artica-optimize", 0755);
    $f[] = "";
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Installing init service\n";
    }
    @file_put_contents("/etc/sysctl.conf", @implode("\n", $f));
    if (is_file('/usr/sbin/update-rc.d')) {
        shell_exec("/usr/sbin/update-rc.d -f artica-optimize defaults >/dev/null 2>&1");
    }
    if (is_file('/sbin/chkconfig')) {
        shell_exec("/sbin/chkconfig --add artica-optimize >/dev/null 2>&1");
        shell_exec("/sbin/chkconfig --level 345 artica-optimize on >/dev/null 2>&1");
    }
    shell_exec("/etc/init.d/artica-optimize start");
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} /etc/sysctl.conf done\n";
    }
    if ($GLOBALS["REBOOT"]) {
        $reboot = $unix->find_program("reboot");
        shell_exec("{$reboot}");
    }
    start(true);
}
コード例 #11
0
function start($aspid = false)
{
    $unix = new unix();
    if (!$aspid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = $unix->get_pid_from_file($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $sock = new sockets();
    $iptables = $unix->find_program("iptables");
    $sysctl = $unix->find_program("sysctl");
    $ips = $unix->ifconfig_interfaces_list();
    $KernelSendRedirects = $sock->GET_INFO("KernelSendRedirects");
    if (!is_numeric($KernelSendRedirects)) {
        $KernelSendRedirects = 1;
    }
    $modprobe = $unix->find_program("modprobe");
    $EnableArticaHotSpot = $sock->GET_INFO("EnableArticaHotSpot");
    if (!is_numeric($EnableArticaHotSpot)) {
        $EnableArticaHotSpot = 0;
    }
    if ($EnableArticaHotSpot == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} disabled ( see EnableArticaHotSpot )\n";
        }
        remove_sessions();
        remove_temp_sessions();
        return;
    }
    $squid = $unix->LOCATE_SQUID_BIN();
    if (!is_file($squid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Squid-cache not installed\n";
        }
        return;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} loading ip_conntrack module\n";
    }
    shell_exec("{$modprobe} ip_conntrack");
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} building firewall\n";
    }
    if (!is_file("/etc/artica-postfix/hotspot.conf")) {
        build();
    }
    $f = explode("\n", @file_get_contents("/etc/artica-postfix/hotspot.conf"));
    while (list($num, $ligne) = each($f)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} `{$ligne}`\n";
        }
        shell_exec($ligne);
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Patching kernel\n";
    }
    shell_exec("{$sysctl} -w net.ipv4.ip_forward=1 2>&1");
    shell_exec("{$sysctl} -w net.ipv4.conf.default.send_redirects={$KernelSendRedirects} 2>&1");
    shell_exec("{$sysctl} -w net.ipv4.conf.all.send_redirects={$KernelSendRedirects} 2>&1");
    shell_exec("{$sysctl} -w net.ipv4.conf.eth0.send_redirects={$KernelSendRedirects} 2>&1");
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Delete session..\n";
    }
    untrack();
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Success started PID 0\n";
    }
}
コード例 #12
0
ファイル: exec.sarg.php プロジェクト: brucewu16899/1.6.x
function execute()
{
    $nice = EXEC_NICE();
    if (is_file(dirname(__FILE__) . "/exec.sarg.gilou.php")) {
        events("Executing exec.sarg.gilou.php instead...");
        shell_exec($nice . LOCATE_PHP5_BIN2() . " " . dirname(__FILE__) . "/exec.sarg.gilou.php --exec");
        return;
    }
    $sock = new sockets();
    $SargOutputDir = $sock->GET_INFO("SargOutputDir");
    if ($SargOutputDir == null) {
        $SargOutputDir = "/var/www/html/squid-reports";
    }
    $nice = EXEC_NICE();
    $unix = new unix();
    $today = date("d/m/Y");
    $sarg_bin = $unix->find_program("sarg");
    if (!is_file($sarg_bin)) {
        sarg_admin_events("Fatal, unable to locate sarg binary, aborting...", __FUNCTION__, __FILE__, __LINE__, "sarg");
        return;
    }
    events("Building settings..");
    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("{$SargOutputDir}", 0755, true);
    $u = " -i ";
    $cmd = "{$nice}{$sarg_bin} -d {$today}-{$today} {$u}-f /etc/squid3/sarg.conf -l /var/log/squid/access.log -o \"{$SargOutputDir}\" -x -z 2>&1";
    $t1 = time();
    echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, {$cmd}\n";
    sargevents("execute(): {$cmd}");
    exec($cmd, $results);
    while (list($index, $line) = each($results)) {
        if (preg_match("#SARG: No records found#", $line)) {
            events("No records found");
            $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/auth-tail restart >/dev/null 2>&1");
            shell_exec("/etc/init.d/cache-tail restart >/dev/null 2>&1");
            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/auth-tail restart >/dev/null 2>&1");
            shell_exec("/etc/init.d/cache-tail restart >/dev/null 2>&1");
            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/auth-tail restart >/dev/null 2>&1");
            shell_exec("/etc/init.d/cache-tail restart >/dev/null 2>&1");
            return;
        }
    }
    $NICE = EXEC_NICE();
    $unix = new unix();
    $lighttpd_user = $unix->APACHE_SRC_ACCOUNT();
    $php = $unix->LOCATE_PHP5_BIN();
    $nohup = $unix->find_program("nohup");
    echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, lighttpd user: {$lighttpd_user}\n";
    $chown = $unix->find_program("chown");
    echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]},{$chown} -R {$lighttpd_user}:{$lighttpd_user} {$SargOutputDir}/*\n";
    exec("{$chown} -R {$lighttpd_user}:{$lighttpd_user} {$SargOutputDir}/* >/dev/null 2>&1", $results2);
    echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]},\n" . @implode("\n" . $results2) . "\n";
    shell_exec("{$nohup} {$php} " . __FILE__ . " --backup >/dev/null 2>&1 &");
    $t2 = time();
    $distanceOfTimeInWords = distanceOfTimeInWords($t1, $t2);
    echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, {$distanceOfTimeInWords}\n";
    events("Statistics generated ({$distanceOfTimeInWords})");
    if ($GLOBALS["VERBOSE"]) {
        echo "SARG: Statistics generated ({$distanceOfTimeInWords})\n\n";
        echo @implode("\n", $results) . "\n";
    }
    status(true);
    sarg_admin_events("SARG: Statistics generated ({$distanceOfTimeInWords}) {$subject_add}", "Command line:\n-----------\n{$cmd}\n" . @implode("\n", $results), __FUNCTION__, __FILE__, __LINE__, "sarg");
}
コード例 #13
0
function Parseline($buffer)
{
    $buffer = trim($buffer);
    if ($buffer == null) {
        return null;
    }
    if (dustbin($buffer)) {
        return null;
    }
    if (!isset($GLOBALS["CHMOD"])) {
        $unix = new unix();
        $GLOBALS["CHMOD"] = $unix->find_program("chmod");
    }
    if ($GLOBALS["VERBOSE"]) {
        events(" - > " . __LINE__);
    }
    if (count($GLOBALS["DNSISSUES"]) > 1) {
        $curdate = date("YmdHi");
        $curcount = count($GLOBALS["DNSISSUES"][$curdate]);
        unset($GLOBALS["DNSISSUES"]);
        $GLOBALS["DNSISSUES"][$curdate] = $curcount;
    }
    $GLOBALS["COUNTLINES"]++;
    if ($GLOBALS["COUNTLINES"] > 20) {
        @unlink("/etc/artica-postfix/pids/squid-cache-logs.time");
        @file_put_contents("/etc/artica-postfix/pids/squid-cache-logs.time", time());
        $GLOBALS["COUNTLINES"] = 0;
    }
    if (preg_match("#FD [0-9]+ Closing HTTP connection#", $buffer)) {
        return;
    }
    if (preg_match("#temporary disabling.*?digest from#", $buffer)) {
        return;
    }
    if (preg_match("#kid[0-9]+\\| .*?\\/[0-9]+ exists#", $buffer)) {
        return;
    }
    //*******************************************************************************************************************
    if (preg_match("#logfileHandleWrite:.*?error(.+)#", $buffer, $re)) {
        squid_admin_mysql(1, "Artica logger issue {$re[1]} [action=warn]", $buffer, __FILE__, __LINE__);
        return;
    }
    //*******************************************************************************************************************
    if (preg_match("#FATAL: Cannot open SNMP receiving Port#", $buffer, $re)) {
        squid_admin_mysql(0, "SNMP option issue! [action=disable SNMP]", $buffer, __FILE__, __LINE__);
        shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.watchdog.php --disable-snmp >/dev/null 2>&1");
        return;
    }
    //*******************************************************************************************************************
    if (preg_match("#FATAL: The\\s+(.*?)\\s+helpers are crashing too rapidly, need help#", $buffer, $re)) {
        squid_admin_mysql(0, "Herlpers [{$re[1]}] issue! [action=emergency!]", "The proxy claims about an helper that crashing, Artica pass your proxy service into emergency mode!\n{$buffer}", __FILE__, __LINE__);
        @file_put_contents("/etc/artica-postfix/settings/Daemons/SquidUrgency", 1);
        shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.php --build --force >/dev/null 2>&1 &");
    }
    //*******************************************************************************************************************
    if (preg_match("#FATAL: I don't handle this error well#", $buffer, $re)) {
        $file = "/etc/artica-postfix/pids/squid.did.handle.error.well";
        $timefile = file_time_min($file);
        if ($timefile > 10) {
            squid_admin_mysql(0, "Error that proxy did not handle very well! [action=restart-forced]", $buffer, __FILE__, __LINE__);
            shell_exec("{$GLOBALS["NOHUP"]} /etc/init.d/squid restart --force --cache-logs >/dev/null 2>&1 &");
            @unlink($file);
            @file_put_contents($file, time());
        }
        return;
    }
    //*******************************************************************************************************************
    if (preg_match("#WARNING: All [0-9]+\\/([0-9]+)\\s+BasicFakeAuth processes are busy#", $buffer, $re)) {
        $file = "/etc/artica-postfix/pids/squid.external.BasicFakeAuth.queue.overload";
        $timefile = file_time_min($file);
        if ($timefile > 3) {
            $SquidClientParams = unserialize(base64_decode($GLOBALS["CLASS_SOCKETS"]->GET_INFO("SquidClientParams")));
            if (!is_numeric($SquidClientParams["external_acl_children"])) {
                $SquidClientParams["external_acl_children"] = 5;
            }
            if (!is_numeric($SquidClientParams["external_acl_startup"])) {
                $SquidClientParams["external_acl_startup"] = 1;
            }
            if (!is_numeric($SquidClientParams["external_acl_idle"])) {
                $SquidClientParams["external_acl_idle"] = 1;
            }
            $SquidClientParams["external_acl_children"] = $SquidClientParams["external_acl_children"] + 2;
            $SquidClientParams["external_acl_startup"] = $SquidClientParams["external_acl_startup"] + 2;
            $SquidClientParams["external_acl_idle"] = $SquidClientParams["external_acl_idle"] + 2;
            $GLOBALS["CLASS_SOCKETS"]->SaveConfigFile(base64_encode(serialize($SquidClientParams)), "SquidClientParams");
            shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.php --build --force >/dev/null 2>&1 &");
            $text = "{$buffer}\n\t\t\tNew parameters has been set and the proxy service was reconfigurer with:\n\t\t\texternal_acl_children = {$SquidClientParams["external_acl_children"]}\n\t\t\texternal_acl_startup  = {$SquidClientParams["external_acl_startup"]}\n\t\t\texternal_acl_idle     = {$SquidClientParams["external_acl_idle"]}\n\t\t\t";
            squid_admin_mysql(1, "BasicFakeAuth ACL queue overloaded increase it", "{$text}");
            @unlink($file);
            @file_put_contents($file, time());
            return;
        }
        return;
    }
    //*******************************************************************************************************************
    if (preg_match("#\\/swap\\.state:.*?Read-only file system#", $buffer, $re)) {
        if (TimeStampTTL(__LINE__, 2)) {
            squid_admin_mysql(0, "{$re[1]} File system in read-only! suggest to reboot the server !", $buffer, __FILE__, __LINE__);
        }
        return;
    }
    //*******************************************************************************************************************
    if (preg_match("#Open FD READ\\/WRITE\\s+[0-9]+\\s+(.+?)\\s+#", $buffer, $re)) {
        if (preg_match("#DNS\\s+#", $buffer)) {
            return;
        }
        if (preg_match("#ufdbgclient#", $re[1])) {
            return;
        }
        if (preg_match("#Idle server#", $re[1])) {
            return;
        }
        if (preg_match("#Idle client#", $re[1])) {
            return;
        }
        if (preg_match("#DNS#", $re[1])) {
            return;
        }
        if (preg_match("#ntlm_auth#", $re[1])) {
            return;
        }
        if (TimeStampTTL(__LINE__, 2)) {
            squid_admin_mysql(0, "`{$re[1]}` File descriptors issue, you should increase file descriptors [action: None]", $buffer, __FILE__, __LINE__);
        }
        return;
    }
    //*******************************************************************************************************************
    if (preg_match("#FATAL: Unable to open HTTP Socket#", $buffer, $re)) {
        if (TimeStampTTL(__LINE__, 5)) {
            squid_admin_mysql(0, "Port conflicts ! [action: force-restart]", null, __FILE__, __LINE__);
            shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.watchdog.php --restart --force --kill-all >/dev/null 2>&1 &");
            return;
        }
        squid_admin_mysql(0, "Port conflicts ! [action: none - Timed out]", null, __FILE__, __LINE__);
    }
    //*******************************************************************************************************************
    if (preg_match("#FATAL: UFSSwapDir::openLog: Failed to open swap log#", $buffer, $re)) {
        squid_admin_mysql(0, "UFSSwapDir Proxy cannot open it's cache !! [action: None]", null, __FILE__, __LINE__);
        return;
    }
    //*******************************************************************************************************************
    if (preg_match("#Ipc::Mem::Segment::open failed to shm_open.*?No such file or directory#", $buffer, $re)) {
        squid_admin_mysql(0, "SMP Proxy cannot be linked to the system !! [action: None]", null, __FILE__, __LINE__);
        return;
    }
    //*******************************************************************************************************************
    if (preg_match("#kid([0-9]+).*?Preparing for shutdown after\\s+([0-9]+)\\s+requests#", $buffer, $re)) {
        if (TimeStampTTL(__LINE__, 2)) {
            squid_admin_mysql(2, "Process CPU.{$re[1]} is stopping [action: None]", null, __FILE__, __LINE__);
        }
        return;
    }
    //*******************************************************************************************************************
    if (preg_match("#kid([0-9]+).*?Squid Cache.*?: Exiting normally#", $buffer, $re)) {
        if (TimeStampTTL(__LINE__, 2)) {
            squid_admin_mysql(0, "Process CPU.{$re[1]} was stopped [action: None]", null, __FILE__, __LINE__);
        }
        return;
    }
    //*******************************************************************************************************************
    if (preg_match("#kid([0-9]+).*?Process Roles:\\s+(.+?)#", $buffer, $re)) {
        if (TimeStampTTL(__LINE__, 2)) {
            squid_admin_mysql(2, "Process CPU.{$re[1]} was started in {$re[2]} mode [action: None]", null, __FILE__, __LINE__);
        }
        return;
    }
    //*******************************************************************************************************************
    if (preg_match("#ERROR: NTLM Authentication validating user\\. Error returned 'BH NT_STATUS_ACCESS_DENIED'#", $buffer, $re)) {
        if (TimeStampTTL(__LINE__, 10)) {
            squid_admin_mysql(0, "Active directory link failed NT_STATUS_ACCESS_DENIED [action: Relink]", $buffer, __FILE__, __LINE__);
            shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.kerbauth.php --join --force >/dev/null 2>&1 &");
        }
        return;
    }
    //*******************************************************************************************************************
    if (preg_match("#Detected DEAD Parent: Peer([0-9]+)#", $buffer, $re)) {
        if (TimeStampTTL(__LINE__, 2)) {
            squid_admin_mysql(0, "Parent proxy number {$re[1]} is dead [action: None]", null, __FILE__, __LINE__);
            shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.watchdog.php --peer-status --force >/dev/null 2>&1 &");
            shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.watchdog.php --dead-parent \"{$re[1]}\" >/dev/null 2>&1 &");
        }
        return;
    }
    //*******************************************************************************************************************
    if (preg_match("#TCP connection to (.+?)\\/([0-9]+)\\s+failed#", $buffer, $re)) {
        if (TimeStampTTL(__LINE__, 2)) {
            squid_admin_mysql(1, "Connecting to Peer {$re[1]}:{$re[2]} failed [action: None]", null, __FILE__, __LINE__);
            shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.watchdog.php --peer-status --force >/dev/null 2>&1 &");
        }
        return;
    }
    //*******************************************************************************************************************
    if (preg_match("#commBind: Cannot bind socket FD [0-9]+ to ([0-9\\.]+):.*?Cannot assign requested address#", $buffer, $re)) {
        if (TimeStampTTL(__LINE__, 5)) {
            squid_admin_mysql(0, "Proxy service Unable to hook {$re[1]} network address [action: Reconfigure]", "Proxy claim\n{$buffer}\nArtica will reconfigure the service\nPlease follow this issue, newt check will be in 5mn", __FILE__, __LINE__);
            shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.php --build --force >/dev/null 2>&1 &");
        }
        return;
    }
    //*******************************************************************************************************************
    if (preg_match("#Squid Cache.*?:\\s+Exiting normally#", $buffer, $re)) {
        if (TimeStampTTL(__LINE__, 1)) {
            squid_admin_mysql(2, "Proxy service was normally stopped", "Proxy claim\n{$buffer}\n", __FILE__, __LINE__);
        }
        return;
    }
    //*******************************************************************************************************************
    if (preg_match("#FATAL: Received Bus Error...dying#", $buffer, $re)) {
        if (TimeStampTTL(__LINE__, 5)) {
            squid_admin_mysql(0, "Bus Error !", "Proxy claim\n{$buffer}\nThis caused by an hardware issue or a proxy bug ( please contact our support team)\nArtica will try to start Proxy if it is not running", __FILE__, __LINE__);
            shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.watchdog.php --start {$GLOBALS["SCRIPT_SUFFIX"]} >/dev/null 2>&1 &");
        }
        return;
    }
    //*******************************************************************************************************************
    if (preg_match("#FATAL: Unable to open HTTPS Socket#", $buffer, $re)) {
        if (TimeStampTTL(__LINE__, 5)) {
            squid_admin_mysql(0, "Port conflict issue on HTTPS socket -> Restart proxy service", "{$buffer}\n", __FILE__, __LINE__);
            shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.watchdog.php --restart --force {$GLOBALS["SCRIPT_SUFFIX"]} >/dev/null 2>&1 &");
        }
        return;
    }
    //*******************************************************************************************************************
    if (preg_match("#FATAL: The basicauthenticator helpers are crashing too rapidly, need help#", $buffer, $re)) {
        if (TimeStampTTL(__LINE__, 2)) {
            $text[] = $buffer;
            $f = explode("\n", @file_get_contents("/etc/squid3/squid.conf"));
            while (list($num, $line) = each($f)) {
                if (preg_match("#auth_param basic program#", $line)) {
                    $text[] = "basicauthenticator: {$line}";
                }
            }
            squid_admin_mysql(0, "basicauthenticator extension is crashing", @implode("\n", $text), __FILE__, __LINE__);
        }
        return;
    }
    //*******************************************************************************************************************
    if (preg_match("#ERROR: URL-rewrite produces invalid request:#", $buffer, $re)) {
        if (TimeStampTTL(__LINE__, 5)) {
            squid_admin_mysql(0, "Redirector Web filter miss-configured, reconfigure Web filter", "{$buffer}\n", __FILE__, __LINE__);
            shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squidguard.php --build --force --restart {$GLOBALS["SCRIPT_SUFFIX"]} >/dev/null 2>&1 &");
        }
        return;
    }
    //*******************************************************************************************************************
    if (preg_match("#assertion failed: mem\\.cc:([0-9]+):\\s+\"(.+?)\"#", $buffer, $re)) {
        if (TimeStampTTL(__LINE__, 1)) {
            squid_admin_mysql(1, "Memory assertion failed mem.cc Line {$re[1]} - {$re[2]}", "{$buffer}\n", __FILE__, __LINE__);
        }
        return;
    }
    //*******************************************************************************************************************
    if (preg_match("#optional ICAP service is down after an options fetch failure:\\s+icap:\\/\\/(.+?):([0-9]+)\\/(.+?)\\s+#", $buffer, $re)) {
        if (TimeStampTTL(__LINE__, 2)) {
            squid_admin_mysql(1, "ICAP service {$re[3]} down {$re[1]}:{$re[2]}", "{$buffer}\n", __FILE__, __LINE__);
        }
        return;
    }
    //*******************************************************************************************************************
    if (preg_match("#logfileHandleWrite: daemon:: error writing\\s+(.*)#", $buffer, $re)) {
        squid_admin_mysql(2, "Error writing to Artica statistics dameon", "{$buffer}\n", __FILE__, __LINE__);
        return;
    }
    //*******************************************************************************************************************
    if (preg_match("#kid([0-9]+)\\|\\s+Reconfiguring Squid Cache#", $buffer, $re)) {
        events("CPU.{$re[1]} Reconfiguring Proxy service", __LINE__);
        squid_admin_mysql(2, "CPU.{$re[1]} Reconfiguring Proxy service", "{$buffer}\n", __FILE__, __LINE__);
    }
    //*******************************************************************************************************************
    if (preg_match("#WARNING: Unexpected change of authentication scheme.*?client\\s+(.*?)\\)#", $buffer, $re)) {
        events("{$re[1]} Unexpected change of authentication scheme", __LINE__);
        squid_admin_mysql(1, "Computer {$re[1]} Unexpected change of authentication scheme", "{$buffer}\n", __FILE__, __LINE__);
        return;
    }
    //*******************************************************************************************************************
    if (preg_match("#WARNING: All [0-9]+\\/([0-9]+) redirector processes are busy#", $buffer, $re)) {
        events("{$re[1]} Process reached for Web filtering daemon, Artica will increase the value...", __LINE__);
        squid_admin_mysql(2, "{$re[1]} Process reached for Web filtering daemon, Artica will increase the value", "{$buffer}\n", __FILE__, __LINE__);
        shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.watchdog.php --redirectors-more >/dev/null 2>&1 &");
        return;
    }
    //*******************************************************************************************************************
    if (preg_match("#\\| WARNING: HTTP header contains NULL characters \\{Host:\\s+(.+)#i", $buffer, $re)) {
        events("{$re[1]} seems to crash", __LINE__);
        squid_admin_mysql(0, "Webserver \"{$re[1]}\" seems to crashing", "script of this source server seems broken\n{$buffer}\n", __FILE__, __LINE__);
        return;
    }
    // *******************************************************************************************************************
    if (preg_match("#squidaio_queue_request: WARNING - Queue congestion#i", $buffer)) {
        events("squidaio_queue_request error issue ->`{$buffer}`", __LINE__);
        if (TimeStampTTL(__LINE__, 2)) {
            squid_admin_mysql(2, "Queue congestion", "{$buffer}\n" . @file_get_contents("/usr/share/artica-postfix/ressources/databases/SQUID_ERROR_QUEUE_CONGESTION.db"), __FILE__, __LINE__);
        }
        return;
    }
    // *******************************************************************************************************************
    if (preg_match("#WARNING: Consider increasing the number of ads_group processes in your config file#i", $buffer)) {
        events("ads_group error issue ->`{$buffer}`", __LINE__);
        if (TimeStampTTL(125, 2)) {
            squid_admin_mysql(0, "Queue overload on external ACL ads_group add more.", "{$buffer}\n", __FILE__, __LINE__);
            shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.watchdog.php --external-acl-children-more >/dev/null 2>&1 &");
        }
        return;
    }
    // *******************************************************************************************************************
    if (preg_match("#WARNING: external ACL 'ads_group' queue overload. Using stale result#i", $buffer)) {
        events("ads_group error issue ->`{$buffer}`", __LINE__);
        if (TimeStampTTL(125, 2)) {
            squid_admin_mysql(0, "Queue overload on external ACL ads_group add more.", "{$buffer}\n", __FILE__, __LINE__);
            shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.watchdog.php --external-acl-children-more >/dev/null 2>&1 &");
        }
    }
    // *******************************************************************************************************************
    if (preg_match("#PHP Startup: Unable to load dynamic library#i", $buffer)) {
        shell_exec("/usr/share/artica-postfix/bin/artica-install --php-include");
        shell_exec("{$GLOBALS["NOHUP"]} /etc/init.d/squid reload --cache-logs >/dev/null 2>&1");
    }
    // *******************************************************************************************************************
    if (preg_match("#errorTryLoadText:\\s+'(.+?)':.*?Permission denied#", $buffer, $re)) {
        @chown($re[1], "squid");
        return;
    }
    // *******************************************************************************************************************
    if (preg_match("#PHP Warning.*?Unable to load dynamic library '(.+?)'.*?undefined symbol#", $buffer, $re)) {
        if (is_file($re[1])) {
            @copy($re[1], $re[1] . "." . time() . ".bak");
            @unlink($re[1]);
            shell_exec("{$GLOBALS["NOHUP"]} /etc/init.d/artica-webconsole restart >/dev/null 2>&1");
        }
        return;
    }
    // *******************************************************************************************************************
    if (preg_match("#FATAL: Rock cache_dir at\\s+(.+?)\\s+failed to open db file#", $buffer, $re)) {
        events("disk write error issue ->`{$buffer}`", __LINE__);
        if (TimeStampTTL(__LINE__, 10)) {
            squid_admin_mysql(0, "Rock cache_dir issue", "{$buffer}\nrun cache -Z", __FILE__, __LINE__);
            shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.smp.php --squid-z-fly >/dev/null 2>&1 &");
        }
        return;
    }
    // *******************************************************************************************************************
    if (preg_match("#basic_ldap_auth: WARNING, could not bind to binddn.*?Can.*?contact LDAP server#", $buffer, $re)) {
        events("basic_ldap_auth error issue ->`{$buffer}`", __LINE__);
        if (TimeStampTTL(__LINE__, 2)) {
            squid_admin_mysql(0, "Remote LDAP server issue unable to contact specified LDAP Port", "{$buffer}\n", __FILE__, __LINE__);
        }
        return;
    }
    // *******************************************************************************************************************
    if (preg_match("#diskHandleWrite:\\s+FD\\s+.*?disk write error:.*?No space left on device#", $buffer, $re)) {
        events("disk write error issue ->`{$buffer}`", __LINE__);
        if (TimeStampTTL(__LINE__, 10)) {
            squid_admin_mysql(0, "No space left on device, rebuild all caches", "{$buffer}\nIt seems the one of caches or all caches handle your disk space.\nReconstruct caches procedure as been executed.", __FILE__, __LINE__);
            shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.rebuild.caches.php >/dev/null 2>&1 &");
        }
        return;
    }
    // *******************************************************************************************************************
    if (preg_match("#commBind:\\s+Cannot bind socket FD\\s+[0-9]+\\s+to.*?(::1|127\\.0\\.0\\.1)\\]:.*?Cannot assign requested address#", $buffer, $re)) {
        if (TimeStampTTL(__LINE__, 1)) {
            events("127.0.0.1 issue", __LINE__);
            squid_admin_mysql(0, "Loopback interface issue - {$re[1]}", "{$buffer}\nArtica will reconfigure loopback");
            shell_exec("{$GLOBALS["IFCONFIG"]} lo 127.0.0.1 netmask 255.255.255.0 up >/dev/null 2>&1");
            shell_exec("/etc/init.d/squid reload {$GLOBALS["SCRIPT_SUFFIX"]}");
            return;
        }
    }
    // *******************************************************************************************************************
    if (preg_match("#Uninitialized SSL certificate database directory:\\s+(.+?)\\.#", $buffer, $re)) {
        if (TimeStampTTL(__LINE__, 1)) {
            $Directory = $re[1];
            events("SSL issue on `{$Directory}`", __LINE__);
            squid_admin_mysql(0, "Uninitialized SSL certificate database directory", "{$buffer}\nArtica will initalize `{$Directory}` with `{$GLOBALS["sslcrtd_program"]}`");
            shell_exec("{$GLOBALS["RM"]} -rf {$Directory} >/dev/null 2>&1");
            shell_exec("{$GLOBALS["sslcrtd_program"]} -c -s {$Directory} >/dev/null 2>&1");
            shell_exec("{$GLOBALS["CHOWN"]} -R squid:squid {$Directory} >/dev/null 2>&1");
            shell_exec("{$GLOBALS["NOHUP"]} /etc/init.d/squid start --cache-logs >/dev/null 2>&1 &");
            return;
        }
    }
    // *******************************************************************************************************************
    if (preg_match("#FATAL: Ipc::Mem::Segment::open failed to shm_open.*?squid-squid-page-pool\\.shm.*?No such file or directory#", $buffer)) {
        if (TimeStampTTL(__LINE__, 1)) {
            events("Ipc::Mem::Segment:: issue on squid-squid-page-pool.shm -> restart" . __LINE__);
            squid_admin_mysql(0, "SMP Memory issue", "{$buffer}\nThe proxy service will be restarted");
            squid_admin_notifs("Warning, SMP Memory issue.\n{$buffer}\nThe proxy service will be restarted", __FUNCTION__, __FILE__, __LINE__, "watchdog");
            shell_exec("{$GLOBALS["NOHUP"]} /etc/init.d/squid restart --cache-logs >/dev/null 2>&1 &");
        }
        events("Ipc::Mem::Segment:: issue on squid-squid-page-pool.shm need to wait 1mn" . __LINE__);
    }
    // *******************************************************************************************************************
    if (preg_match("#TCP connection to\\s+127\\.0\\.0\\.1\\/{$GLOBALS["HAARP_PORT"]}\\s+failed#", $buffer)) {
        events("HTTP connection failed to Haarp cache system times Line:" . __LINE__);
        if (TimeStampTTL(__LINE__, 3)) {
            @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableHaarp", 0);
            shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.php --build >/dev/null 2>&1 &");
            squid_admin_mysql(0, "Haarp issues", "Proxy service have issues with haarp,disable it\n{$buffer}\n the Haarp service will be restarted");
            squid_admin_notifs("Warning, Haarp issues.\nProxy service have issues with haarp,\n{$buffer}\n the Haarp service will be restarted");
            shell_exec("{$GLOBALS["NOHUP"]} /etc/init.d/haarp restart >/dev/null 2>&1 &");
        }
        return;
    }
    // *******************************************************************************************************************
    if (preg_match("#Detected DEAD Parent.*?HaarpPeer#", $buffer)) {
        events("HTTP connection failed to Haarp cache system times Line:" . __LINE__);
        if (TimeStampTTL(__LINE__, 3)) {
            @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableHaarp", 0);
            shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.php --build >/dev/null 2>&1 &");
            squid_admin_mysql(0, "Haarp issues", "Proxy service have issues with haarp,service will be disabled\n{$buffer}\n the Haarp service will be restarted");
            squid_admin_notifs("Warning, Haarp issues.\nProxy service have issues with haarp,\n{$buffer}\n the service will be restarted");
            shell_exec("{$GLOBALS["NOHUP"]} /etc/init.d/haarp restart >/dev/null 2>&1 &");
        }
        return;
    }
    // *******************************************************************************************************************
    if (preg_match("#cannot connect to ufdbguardd daemon socket#", $buffer, $re)) {
        if ($GLOBALS["MonitConfig"]["watchdog"] == 0) {
            squid_admin_mysql(1, "Web filtering issue -> ufdbguardd daemon socket [action=none]", "{$buffer}\nWeb filtering will be disabled when reach 4", __FILE__, __LINE__);
            return;
        }
        if ($GLOBALS["MonitConfig"]["DisableWebFilteringNetFailed"] == 0) {
            squid_admin_mysql(1, "Web filtering issue -> ufdbguardd daemon socket [action=none]", "{$buffer}\nWeb filtering will be disabled when reach 4", __FILE__, __LINE__);
            return;
        }
        if (TimeStampTTL(__LINE__, 5)) {
            $GLOBALS["WEBFISSUE"]++;
            squid_admin_mysql(0, "Web filtering issue {$GLOBALS["WEBFISSUE"]}/4", "{$buffer}\nWeb filtering will be disabled when reach 2 times each 5mn", __FILE__, __LINE__);
            if ($GLOBALS["WEBFISSUE"] > 2) {
                squid_admin_mysql(0, "Web filtering issue MAX reached [action=remove]", "{$buffer}\nWeb filtering will be disabled", __FILE__, __LINE__);
                shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.php --disableUFDB >/dev/null 2>&1 &");
                $GLOBALS["WEBFISSUE"] = 0;
            }
        }
        return;
    }
    // *******************************************************************************************************************
    if (preg_match("#ERROR: URL-rewrite produces invalid request#", $buffer, $re)) {
        if ($GLOBALS["MonitConfig"]["watchdog"] == 0) {
            return;
        }
        if ($GLOBALS["MonitConfig"]["DisableWebFilteringNetFailed"] == 0) {
            return;
        }
        if (TimeStampTTL(__LINE__, 5)) {
            squid_admin_mysql(0, "Web filtering compatiblity issue", "Proxy claim:\n{$buffer}\nWeb filtering will be disabled for compatibilities issues\nreturn back to 3.3x versions\nWe currently investigate on the compatibility");
            shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.php --disableUFDB >/dev/null 2>&1 &");
        }
        return;
    }
    // *******************************************************************************************************************
    if (preg_match("#TCP connection to (.+?)\\/([0-9]+)\\s+failed#", $buffer, $re)) {
        if (!isset($GLOBALS["CNXFAILED"][$re[1]])) {
            $GLOBALS["CNXFAILED"][$re[1]] = 0;
        }
        $GLOBALS["CNXFAILED"][$re[1]] = $GLOBALS["CNXFAILED"][$re[1]] + 1;
        events("{$re[1]} HTTP connection failed ({$GLOBALS["CNXFAILED"][$re[1]]}) times Line:" . __LINE__);
    }
    // *******************************************************************************************************************
    if (preg_match("#ipcacheParse: No Address records in response to '(.+?)'#", $buffer, $re)) {
        if ($GLOBALS["MonitConfig"]["NotifyDNSIssues"] == 0) {
            reset($GLOBAL["DNSISSUES"]);
            return;
        }
        $curdate = date("YmdHi");
        $GLOBALS["DNSISSUES"][$curdate][$re[1]] = true;
        if (count($GLOBALS["DNSISSUES"][$curdate] + 1) > $GLOBALS["MonitConfig"]["DNSIssuesMAX"]) {
            while (list($num, $ligne) = each($GLOBALS["DNSISSUES"][$curdate])) {
                $t[] = $num;
            }
            reset($GLOBALS["DNSISSUES"]);
            $report = NETWORK_REPORT();
            squid_admin_mysql(1, "DNS issues", "Proxy service have issues to Resolve these websites::\n" . @implode("\n", $t) . "\n{$report}");
            squid_admin_notifs("Warning, " . count($t) . " DNS issues.\nProxy service have issues to Resolve these websites::\n" . @implode("\n", $t) . "\n{$report}", __FUNCTION__, __FILE__, __LINE__, "watchdog");
        }
        return;
    }
    // *******************************************************************************************************************
    if (preg_match("#commBind: Cannot bind socket FD.*?Address already in use#", $buffer)) {
        if (TimeStampTTL(__LINE__, 5)) {
            squid_admin_mysql(0, "Bind Socket issue", "{$buffer}\nProxy service have issues to bind port\n{$buffer}\nArtica will restart the proxy service");
            squid_admin_notifs("Warning, Bind Socket issue.\n{$buffer}\nProxy service have issues to bind port\n{$buffer}\nArtica will restart the proxy service", __FUNCTION__, __FILE__, __LINE__, "watchdog");
            shell_exec("{$GLOBALS["NOHUP"]} /etc/init.d/squid start --crashed >/dev/null 2>&1 &");
        }
        return;
    }
    // *******************************************************************************************************************
    if (preg_match("#FATAL: kid[0-9]+ registration timed out#", $buffer)) {
        @mkdir("/var/run/squid", 0755, true);
        shell_exec("{$GLOBALS["CHOWN"]} -R squid:squid /var/run/squid");
        $GLOBALS["WEBPROCISSUE"]++;
        squid_admin_mysql(0, "Warning, Processor issue count:{$GLOBALS["WEBPROCISSUE"]} (max {$GLOBALS["MonitConfig"]["WEBPROCISSUE"]} times)", $buffer, __FILE__, __LINE__);
        if (TimeStampTTL(__LINE__, 2)) {
            squid_admin_mysql(0, "Processor issue!!: SMP is disabled, you should consider return back to 1 CPU", "The detected error was:\n{$buffer}\n", __FILE__, __LINE__);
        }
        return;
    }
    // *******************************************************************************************************************
    if (preg_match("#abandoning local=(.*?):.*?remote=(.*?):#", $buffer, $re)) {
        $client = $re[2];
        $hostname = gethostbyaddr($re[2]);
        events("{$client} [{$hostname}] KeepAlive session was disconnected from this user Line:" . __LINE__);
        return;
    }
    //*******************************************************************************************************************
    if (preg_match("#ERROR:\\s+(.+?)\\/00: \\(2\\) No such file or directory#", $buffer, $re)) {
        if (TimeStampTTL(__LINE__, 2)) {
            $dirname = trim($re[1]);
            events("{$dirname} -> no cache created -> squid-z Line:" . __LINE__);
            shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.smp.php --squid-z-fly >/dev/null 2>&1 &");
            return;
        }
    }
    // *******************************************************************************************************************
    if (preg_match("#FATAL:\\s+Failed to make swap directory\\s+(.+?):.*?13.*?Permission denied#", $buffer, $re)) {
        $dirname = trim($re[1]);
        $basename = basename($dirname);
        if (is_numeric($basename)) {
            $dirname = dirname($dirname);
        }
        events("{$dirname} -> squid:squid {$re[1]}/0755 Permisssions... Line:" . __LINE__);
        @chown($dirname, "squid");
        @chgrp($dirname, "squid");
        @chmod($re[1], 0755);
        events("{$dirname} ({$basename}) Permisssions denied... Line:" . __LINE__);
        return;
    }
    // *******************************************************************************************************************
    if (preg_match("#\\/home\\/squid\\/cache\\/MemBooster([0-9]+)\\/.*?No space left on device#", $buffer, $re)) {
        events("No space left on Memory Booster MemBooster{$re[1]}: line:" . __LINE__);
        if (TimeStampTTL(__LINE__ . $re[1], 3)) {
            squid_admin_mysql(1, "Memory cache full", "The cache memory MemBooster({$re[1]}) will be flushed to 0 and the proxy service will be restarted");
            squid_admin_notifs("Warning, Memory cache, full\nThe cache memory MemBooster({$re[1]}) will be flushed to 0 and the proxy service will be restarted", __FUNCTION__, __FILE__, __LINE__, "watchdog");
            shell_exec("{$GLOBALS["UMOUNT"]} -l /home/squid/cache/MemBooster{$re[1]}");
            shell_exec("{$GLOBALS["NOHUP"]} /etc/init.d/squid restart --force --cache-logs 2>&1");
        }
        return;
    }
    // *******************************************************************************************************************
    if (preg_match("#FATAL: Write failure.*?check your disk space#", $buffer)) {
        events("Fatal: Write failure: Disk space over limit (cannot determine which path) Line:" . __LINE__);
        if (TimeStampTTL(__LINE__, 10)) {
            exec("{$GLOBALS["DF"]} -h 2>&1", $defres);
            squid_admin_mysql(0, "Write failure - disk space issue", "check your disk space for Proxy cache service.\nHere the status of your storage system:" . @implode("\n", $defres));
            squid_admin_notifs("Warning, check your disk space for Proxy cache service.\nHere the status of your storage system:" . @implode("\n", $defres), __FUNCTION__, __FILE__, __LINE__, "watchdog");
        }
        return;
    }
    // *******************************************************************************************************************
    if (preg_match("#WARNING: Disk space over limit#", $buffer)) {
        if (TimeStampTTL(__LINE__, 5)) {
            squid_admin_mysql(1, "Disk space over limit", "{$buffer}\nswapstate will be executed");
            events("Disk space over limit Line: refresh swap.state" . __LINE__);
            shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.watchdog.php --swapstate >/dev/null 2>&1 &");
        }
        return;
    }
    // *******************************************************************************************************************
    if (preg_match("#errorTryLoadText: '(.+?)':\\s+\\(13\\) Permission denied#i", $buffer, $re)) {
        if (!is_file($re[1])) {
            @file_put_contents($re[1], "\n");
        }
        @chmod($re[1], 0777);
        @chown($re[1], "squid");
        @chown(dirname($re[1]), "squid");
        return;
    }
    // *******************************************************************************************************************
    if (preg_match("#Squid Cache.*?Terminated abnormally#", $buffer)) {
        if ($GLOBALS["MonitConfig"]["RestartWhenCrashes"] == 0) {
            exec("{$GLOBALS["TAIL"]} -n 50 /var/log/squid/cache.log 2>&1", $results);
            squid_admin_mysql(0, "Squid Cache Terminated Abnormally", "squid-cache claim\r\n{$buffer}\r\nThis just a notification, Artica will checks your settings and determine what is the issue...\n" . @implode("\n", $results), __FILE__, __LINE__);
            squid_admin_notifs("Squid Cache Terminated Abnormally.\r\nsquid-cache claim\r\n{$buffer}\r\nThis just a notification, Artica will checks your settings and determine what is the issue...", __FUNCTION__, __FILE__, __LINE__, "proxy");
            return;
        }
        if (TimeStampTTL(__LINE__, 5)) {
            exec("{$GLOBALS["TAIL"]} -n 50 /var/log/squid/cache.log 2>&1", $results);
            squid_admin_mysql(1, "Squid Cache Terminated Abnormally", "squid-cache claim\r\n{$buffer}\r\nArtica will restart the proxy service.\nPiece of logs:" . @implode("\n", $results));
            squid_admin_notifs("Squid Cache Terminated abnormally.\n{$buffer}\nProxy service have issues\n{$buffer}\nArtica will start the proxy service\nPiece of logs:" . @implode("\n", $results), __FUNCTION__, __FILE__, __LINE__, "watchdog");
            shell_exec("{$GLOBALS["NOHUP"]} /etc/init.d/squid start --crashed >/dev/null 2>&1 &");
        }
        return;
    }
    // *******************************************************************************************************************
    if (preg_match("#WARNING: external ACL.*?queue overload. Request rejected#i", $buffer, $re)) {
        $file = "/etc/artica-postfix/pids/squid.external.ACL.queue.overload";
        $timefile = file_time_min($file);
        if ($timefile > 3) {
            $SquidClientParams = unserialize(base64_decode($GLOBALS["CLASS_SOCKETS"]->GET_INFO("SquidClientParams")));
            if (!is_numeric($SquidClientParams["external_acl_children"])) {
                $SquidClientParams["external_acl_children"] = 5;
            }
            if (!is_numeric($SquidClientParams["external_acl_startup"])) {
                $SquidClientParams["external_acl_startup"] = 1;
            }
            if (!is_numeric($SquidClientParams["external_acl_idle"])) {
                $SquidClientParams["external_acl_idle"] = 1;
            }
            $SquidClientParams["external_acl_children"] = $SquidClientParams["external_acl_children"] + 1;
            $SquidClientParams["external_acl_startup"] = $SquidClientParams["external_acl_startup"] + 1;
            $SquidClientParams["external_acl_idle"] = $SquidClientParams["external_acl_idle"] + 1;
            $GLOBALS["CLASS_SOCKETS"]->SaveConfigFile(base64_encode(serialize($SquidClientParams)), "SquidClientParams");
            shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.php --build --force >/dev/null 2>&1 &");
            events("external ACL (queue overload) Increase: external_acl_children:{$SquidClientParams["external_acl_children"]},external_acl_startup:{$SquidClientParams["external_acl_startup"]}, external_acl_idle:{$SquidClientParams["external_acl_idle"]} Line:" . __LINE__);
            $text = "{$buffer}\n\t\t\tNew parameters has been set and the proxy service was reconfigurer with:\n\t\t\texternal_acl_children = {$SquidClientParams["external_acl_children"]}\n\t\t\texternal_acl_startup  = {$SquidClientParams["external_acl_startup"]}\n\t\t\texternal_acl_idle     = {$SquidClientParams["external_acl_idle"]}\n\t\t\t";
            squid_admin_notifs($text, __FUNCTION__, __FILE__, __LINE__, "watchdog");
            squid_admin_mysql(1, "external ACL queue overload", "{$text}");
            @unlink($file);
            @file_put_contents($file, time());
            return;
        }
        events("external ACL (queue overload) timeout ({$timefile}mn) line:" . __LINE__);
        return;
    }
    // *******************************************************************************************************************
    if (preg_match("#kid[0-9]+.*?ERROR opening swap log\\s+(.+?)\\/swap\\.state: \\(13\\) Permission denied#", $buffer, $re)) {
        $dirname = $re[1];
        $file = "/etc/artica-postfix/pids/opening.swap.state." . md5($dirname);
        events("{$dirname} ERROR opening swap log... Line:" . __LINE__);
        $timefile = file_time_min($file);
        if ($timefile > 3) {
            swapstate($dirname);
            if (!isset($GLOBALS["CHMOD"])) {
                $unix = new unix();
                $GLOBALS["CHMOD"] = $unix->find_program("chmod");
            }
            if (!isset($GLOBALS["CHOWN"])) {
                $unix = new unix();
                $GLOBALS["CHOWN"] = $unix->find_program("chown");
            }
            if (!isset($GLOBALS["SQUIDBIN"])) {
                $unix = new unix();
                $GLOBALS["SQUIDBIN"] = $unix->LOCATE_SQUID_BIN();
            }
            $cmd = "{$GLOBALS["NOHUP"]} {$GLOBALS["CHMOD"]} -R 0755 {$dirname} >/dev/null 2>&1 &";
            shell_exec($cmd);
            events("{$cmd}" . __LINE__);
            squid_admin_mysql(1, "Permission denied: Reconfiguring squid-cache", "Permission as been set to {$dirname}");
            squid_admin_mysql(1, "Reconfiguring proxy service", null, __FILE__, __LINE__);
            $cmd = "{$GLOBALS["NOHUP"]} {$GLOBALS["CHOWN"]} -R squid:squid {$dirname} >/dev/null 2>&1 &";
            shell_exec("/etc/init.d/squid reload {$GLOBALS["SCRIPT_SUFFIX"]}");
            events("{$cmd}" . __LINE__);
            shell_exec($cmd);
            @unlink($file);
            @file_put_contents($file, time());
        } else {
            events("{$dirname} Timeout {$timefile}Mn need to wait 3mn Line chown just swap.state :" . __LINE__);
            swapstate($dirname);
            if (!isset($GLOBALS["SQUIDBIN"])) {
                $unix = new unix();
                $GLOBALS["SQUIDBIN"] = $unix->LOCATE_SQUID_BIN();
            }
            squid_admin_mysql(1, "Permission denied: Reconfiguring squid-cache", "Permission as been set to {$dirname}");
            squid_admin_mysql(1, "Reconfiguring proxy service", null, __FILE__, __LINE__);
            $cmd = "/etc/init.d/squid reload {$GLOBALS["SCRIPT_SUFFIX"]} >/dev/null 2>&1 &";
            events("{$cmd}" . __LINE__);
            shell_exec($cmd);
        }
        return;
    }
    // *******************************************************************************************************************
    if (preg_match("#ERROR opening swap log (.+?)\\/swap\\.state: \\(13\\) Permission denied#", $buffer, $re)) {
        $dirname = $re[1];
        $file = "/etc/artica-postfix/pids/opening.swap.state." . md5($dirname);
        events("{$dirname} ERROR opening swap log... Line:" . __LINE__);
        $timefile = file_time_min($file);
        if ($timefile > 3) {
            swapstate($dirname);
            if (!isset($GLOBALS["CHMOD"])) {
                $unix = new unix();
                $GLOBALS["CHMOD"] = $unix->find_program("chmod");
            }
            if (!isset($GLOBALS["CHOWN"])) {
                $unix = new unix();
                $GLOBALS["CHOWN"] = $unix->find_program("chown");
            }
            if (!isset($GLOBALS["SQUIDBIN"])) {
                $unix = new unix();
                $GLOBALS["SQUIDBIN"] = $unix->LOCATE_SQUID_BIN();
            }
            $cmd = "{$GLOBALS["NOHUP"]} {$GLOBALS["CHMOD"]} -R 0775 {$dirname} >/dev/null 2>&1 &";
            shell_exec($cmd);
            events("{$cmd}" . __LINE__);
            squid_admin_mysql(1, "Permission denied: Reconfiguring squid-cache", "Permission as been set to {$dirname}");
            $cmd = "{$GLOBALS["NOHUP"]} {$GLOBALS["CHOWN"]} -R squid:squid {$dirname} && /etc/init.d/squid reload {$GLOBALS["SCRIPT_SUFFIX"]} >/dev/null 2>&1 &";
            events("{$cmd}" . __LINE__);
            shell_exec($cmd);
            @unlink($file);
            @file_put_contents($file, time());
        } else {
            events("{$dirname} Timeout {$timefile}Mn need to wait 3mn Line:" . __LINE__);
            swapstate($dirname);
        }
        return;
    }
    // *******************************************************************************************************************
    if (preg_match("#Detected DEAD Parent:\\s+(.+)#", $buffer, $re)) {
        events("DEAD Parent {$re[1]} -> exec.squid.watchdog.php --dead-parent {$re[1]}" . __LINE__);
        shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.watchdog.php --dead-parent \"{$re[1]}\" >/dev/null 2>&1 &");
        return;
    }
    // *******************************************************************************************************************
    if (preg_match("#kid[0-9]+.*?ERROR:\\s+(.+):\\s+\\(2\\)\\s+No such file or directory#i", $buffer, $re)) {
        if (TimeStampTTL(__LINE__, 5)) {
            squid_admin_mysql(2, "Missing object {$dirname} [action: None]", "squid-cache claim\r\n{$buffer}\r\nArtica have automatically created this directory....");
        }
        return;
    }
    // *******************************************************************************************************************
    if (preg_match("#Preparing for shutdown after\\s+([0-9]+)\\s+requests#", $buffer, $re)) {
        squid_admin_mysql(2, "Proxy will be stopped after {$re[1]} requests", "{$buffer}");
        return;
    }
    // *******************************************************************************************************************
    if (preg_match("#Store rebuilding is\\s+([0-9\\.,]+)#", $buffer, $re)) {
        if ($re[1] == "0.00") {
            return;
        }
        squid_admin_mysql(2, "Store rebuilding {$re[1]}%", "{$buffer}");
        $intval = intval($re[1]);
        if ($intval > 100) {
            $file = "/etc/artica-postfix/pids/Squid.Store.rebuilding";
            $timefile = file_time_min($file);
            if ($timefile > 10) {
                squid_admin_mysql(0, "Store rebuilding task {$re[1]}% is over 100% - Reset caches", "{$buffer}");
                shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.rebuild.caches.php --reindex >/dev/null 2>&1 &");
                @unlink($file);
                @file_put_contents($file, time());
                return;
            }
        }
        events("Store rebuilding is: {$re[1]}% = {$intval} swap.state [do nothing] line:" . __LINE__);
        return;
    }
    // *******************************************************************************************************************
    if (preg_match("#commBind: Cannot bind socket FD [0-9]+ to\\s+(.*?)\\s+\\([0-9]+\\) No such file or directory#", $buffer, $re)) {
        if (TimeStampTTL(__LINE__, 2)) {
            squid_admin_mysql(1, "Cannot bind socket to {$re[1]}", "{$buffer}", __FILE__, __LINE__);
        }
        return;
    }
    // *******************************************************************************************************************
    if (preg_match("#\\|\\s+(.+?):\\s+\\(2\\)\\s+No such file or directory#", $buffer, $re)) {
        if (preg_match("#\\/usr\\/share\\/squid3#i", $buffer)) {
            return;
        }
        if (TimeStampTTL(__LINE__, 2)) {
            squid_admin_mysql(1, "{$re[1]} No such file or directory", "{$buffer}", __FILE__, __LINE__);
        }
        return;
    }
    // *******************************************************************************************************************
    if (preg_match("#kid[0-9]+\\|\\s+\\/(.+?)\\/[0-9]+\\/[0-9A-Z]+\$#", $buffer)) {
        return;
    }
    // *******************************************************************************************************************
    if (preg_match("#storeDirClean:\\s+(.+?):\\s+\\(2\\)\\s+No such file or directory#", $buffer, $re)) {
        $file = "/etc/artica-postfix/pids/" . md5("storeDirCleanNo::NoSuchFileOrDirectory");
        $fileMail = "/etc/artica-postfix/pids/squid.miss_dir";
        $timefile = file_time_min($file);
        $dirname = trim($re[1]);
        events("{$dirname} No such file or directory... Line:" . __LINE__);
        @mkdir("{$dirname}", 0755);
        @chown($dirname, "squid");
        @chgrp($dirname, "squid");
        if ($timefile > 5) {
            $timefile = file_time_min($fileMail);
            if ($timefile > 10) {
                squid_admin_mysql(1, "Suspicious removed object {$dirname}", "Suspicious removed object {$dirname}\r\nsquid-cache claim\r\n{$buffer}\r\nIt seems that this cache directory was removed after the started service\r\nChecks that your have created your caches \"outside\" /var/cache/squid*\r\n");
                squid_admin_notifs("Suspicious removed object {$dirname}\r\nsquid-cache claim\r\n{$buffer}\r\nIt seems that this cache directory was removed after the started service\r\nChecks that your have created your caches \"outside\" /var/cache/squid*\r\n", __FUNCTION__, __FILE__, __LINE__, "proxy");
                @unlink($fileMail);
                @file_put_contents($file, time());
            }
            @unlink($file);
            @file_put_contents($file, time());
        }
        return;
    }
    // *******************************************************************************************************************
    if (preg_match("#DiskThreadsDiskFile::openDone:.*?No such file or directory#", $buffer, $re)) {
        $file = "/etc/artica-postfix/pids/" . md5("DiskThreadsDiskFile::openDone:NoSuchFileOrDirectory");
        $timefile = file_time_min($file);
        $fileMail = "/etc/artica-postfix/pids/squid.miss_dir";
        events("DiskThreadsDiskFile:: \"{$buffer}\" [do nothing]");
        if ($timefile < 15) {
            return;
        }
        squid_admin_mysql(1, "Cache object issue on disk", "squid-cache claim\r\n{$buffer}\r\nIt seems that some caches objects was removed after the started service\r\nJust an information, nothing will be done.");
        $timefile = file_time_min($fileMail);
        @unlink($file);
        @file_put_contents($file, time());
        return;
    }
    // *******************************************************************************************************************
    if (preg_match("#Failed to verify one of the swap directories#", $buffer, $re)) {
        $file = "/etc/artica-postfix/pids/" . md5("Failed to verify one of the swap directories");
        $timefile = file_time_min($file);
        $fileMail = "/etc/artica-postfix/pids/squid.miss_dir";
        events("Failed to verify one of the swap directories [ - squid -z ?]");
        if ($timefile < 5) {
            return;
        }
        $timefile = file_time_min($fileMail);
        if ($timefile > 10) {
            squid_admin_mysql(0, "Missing Caches !!", "squid-cache claim\r\n{$buffer}\r\nIt seems that caches directory was removed after the started service\r\nArtica start the procedure to verify caches..\r\n");
            squid_admin_notifs("Missing Caches !!\r\nsquid-cache claim\r\n{$buffer}\r\nIt seems that caches directory was removed after the started service\r\nArtica start the procedure to verify caches..\r\nr", __FUNCTION__, __FILE__, __LINE__, "proxy");
            @unlink($file);
            @file_put_contents($file, time());
        }
        @unlink($file);
        @file_put_contents($file, time());
        shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.smp.php --squid-z-fly >/dev/null 2>&1 &");
        return;
    }
    // *******************************************************************************************************************
    if (preg_match("#kid[0-9]+\\|\\s+\\/home\\/squid\\/cache\\/MemBooster[0-9]+\\/#", $buffer, $re)) {
        $file = "/etc/artica-postfix/pids/" . md5("MemBoosterFailed");
        $timefile = file_time_min($file);
        if ($timefile < 15) {
            return;
        }
        squid_admin_mysql(1, "Cache object issue MemBoosters", "squid-cache claim\r\n{$buffer}\r\nIt seems that some caches objects was removed after the started service\r\nJust an information, nothing will be done.");
        @unlink($file);
        @file_put_contents($file, time());
        //shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.watchdog.php --CleanMemBoosters >/dev/null 2>&1");
    }
    // *******************************************************************************************************************
    if (strpos($buffer, "Old swap file detected") > 0) {
        events("Old swap file detected..." . __LINE__);
        //squid_admin_notifs("Missing some caches directories\r\nsquid-cache claim\r\n$buffer\r\nArtica will reset all caches", __FUNCTION__, __FILE__, __LINE__, "proxy");
        //shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.rebuild.caches.php");
        return;
    }
    // *******************************************************************************************************************
    if (strpos($buffer, "Run 'squid -z' to create swap directories")) {
        $file = "/etc/artica-postfix/pids/" . md5("Run 'squid -z' to create swap directories");
        $timefile = file_time_min($file);
        if ($timefile > 5) {
            events("SQUID -Z !!!... Line:" . __LINE__);
            squid_admin_mysql(0, "Missing Caches !!", "squid-cache claim\r\n{$buffer}\r\nArtica will launch the directory creation");
            squid_admin_notifs("Missing some caches directories\r\nsquid-cache claim\r\n{$buffer}\r\nArtica will launch the directory creation", __FUNCTION__, __FILE__, __LINE__, "proxy");
            shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.smp.php --squid-z-fly >/dev/null 2>&1 &");
            @unlink($file);
            @file_put_contents($file, time());
        } else {
            events("SQUID -Z !!!... TIMEOUT Line:" . __LINE__);
        }
        return;
    }
    // *******************************************************************************************************************
    if (strpos($buffer, "| Reconfiguring Squid Cache") > 0) {
        $file = "/etc/artica-postfix/pids/" . md5("Reconfiguring Squid Cache");
        $timefile = file_time_min($file);
        if ($timefile > 1) {
            events("Reconfiguring Squid Cache Line:" . __LINE__);
            @unlink($file);
            @file_put_contents($file, time());
        }
        return;
    }
    // *******************************************************************************************************************
    if (strpos($buffer, "Fatal: Bungled squid.conf line")) {
        events("Bad configuration file!" . __LINE__);
        squid_admin_mysql(0, "Bad configuration file", "squid-cache claim\r\n{$buffer}\r\nTry to run the configuration compilation on Artica or contact our support team...");
        squid_admin_notifs("Bad configuration file!\r\nsquid-cache claim\r\n{$buffer}\r\nTry to run the configuration compilation on Artica or contact our support team...", __FUNCTION__, __FILE__, __LINE__, "proxy");
        return;
    }
    // *******************************************************************************************************************
    if (preg_match("#FATAL ERROR: cannot connect to ufdbguardd daemon socket: Connection timed out#", $buffer)) {
        $file = "/etc/artica-postfix/pids/" . md5("Fatal:ufdbguardd daemon socket: Connection timed out");
        $timefile = file_time_min($file);
        if ($timefile > 5) {
            events("Fatal: ufdbguardd daemon socket:timed out " . __LINE__);
            squid_admin_mysql(0, "Issue on Webfiltering Daemon!", "squid-cache claim\r\n{$buffer}\r\nThe Webfiltering Dameon will disconnected from proxy service will be reloaded");
            squid_admin_notifs("Issue on Webfiltering Daemon!\r\nsquid-cache claim\r\n{$buffer}\r\nThe Webfiltering Dameon will disconnected from proxy service will be reloaded", __FUNCTION__, __FILE__, __LINE__, "proxy");
            @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableUfdbGuard", 0);
            shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.php --build --force >/dev/null 2>&1 &");
            shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/bin/artica-make APP_UFDBGUARD >/dev/null 2>&1 &");
            @unlink($file);
            @file_put_contents($file, time());
            return;
        }
        events("Fatal: ufdbguardd daemon socket:timed out " . __LINE__);
        return;
    }
    // *******************************************************************************************************************
    if (preg_match("#:\\s+(.+?):\\s+\\(13\\)\\s+Permission denied#", $buffer, $re)) {
        @chown($re[1], "squid");
        @chgrp($re[1], "squid");
        events("Add squid:squid permission on `{$re[1]}` " . __LINE__);
        if (preg_match("#pinger\$#", $re[1])) {
            events("Add chmod 04755 on `{$re[1]}` " . __LINE__);
            shell_exec("{$GLOBALS["CHOWN"]} root {$re[1]}");
            shell_exec("{$GLOBALS["CHMOD"]} 4755 {$re[1]}");
        }
        return;
    }
    // *******************************************************************************************************************
    if (preg_match("#FATAL: Received Segment Violation\\.\\.\\.dying#", $buffer)) {
        $file = "/etc/artica-postfix/pids/" . md5("Fatal: Received Segment Violation");
        $timefile = file_time_min($file);
        events("Fatal: Received Segment Violation " . __LINE__);
        if ($GLOBALS["MonitConfig"]["RestartWhenCrashes"] == 0) {
            squid_admin_mysql(1, "Received Segment Violation", "squid-cache claim\r\n{$buffer}");
            squid_admin_notifs("Received Segment Violation\r\nsquid-cache claim\r\n{$buffer}\r\nThis just a notification, Artica will checks your settings and determine what is the issue...", __FUNCTION__, __FILE__, __LINE__, "proxy");
            return;
        }
    }
    if (preg_match("#optional ICAP service is down after an options fetch failure:\\s+icap:.*?1344\\/av\\/reqmod#", $buffer)) {
        $file = "/etc/artica-postfix/pids/" . md5("KasperskyIcapDown");
        $timefile = file_time_min($file);
        if ($timefile > 2) {
            squid_admin_mysql(1, "ICAP service is down, reloading squid-cache service", "{$buffer}");
            port1344_notavailable();
            @unlink($file);
            @file_put_contents($file, time());
            shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.watchdog.php --reload --force --exec-status=" . __LINE__ . " >/dev/null 2>&1 &");
            return;
        }
        events("ICAP service is down after an options (1344) -> timeout Line:" . __LINE__);
        return;
    }
    if (strpos($buffer, "Terminated abnormally")) {
        if ($GLOBALS["MonitConfig"]["RestartWhenCrashes"] == 0) {
            squid_admin_mysql(1, "Squid Terminated abnormally", "{$buffer}");
            squid_admin_notifs("Squid Terminated abnormally\r\nsquid-cache claim\r\n{$buffer}\r\nThis just a notification, Artica will checks your settings and determine what is the issue...", __FUNCTION__, __FILE__, __LINE__, "proxy");
            return;
        }
        $file = "/etc/artica-postfix/pids/" . md5("Terminated abnormally");
        $timefile = file_time_min($file);
        if ($timefile > 1) {
            events("Terminated abnormally " . __LINE__);
            squid_admin_mysql(0, "Squid Terminated abnormally", "{$buffer}\nProxy will be restarted");
            squid_admin_notifs("Squid Terminated abnormally\r\nsquid-cache claim\r\n{$buffer}\r\nThis just a notification, Artica will checks your settings and determine what is the issue...", __FUNCTION__, __FILE__, __LINE__, "proxy");
            @unlink($file);
            @file_put_contents($file, time());
        }
        return;
    }
    events("Not Filtered \"{$buffer}\" Line:" . __LINE__);
}
コード例 #14
0
ファイル: exec.nightly.php プロジェクト: brucewu16899/1.6.x
function RestartDedicatedServices($aspid = false)
{
    $unix = new unix();
    if ($aspid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = @file_get_contents($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            echo "Starting......: " . date("H:i:s") . " RestartDedicatedServices already executed PID: {$pid} since {$time}Mn\n";
            if ($time < 120) {
                if (!$GLOBALS["FORCE"]) {
                    die;
                }
            }
            unix_system_kill_force($pid);
        }
        @file_put_contents($pidfile, getmypid());
    }
    $nohup = $unix->find_program("nohup");
    $php = $unix->LOCATE_PHP5_BIN();
    $squidbin = $unix->LOCATE_SQUID_BIN();
    $unix->THREAD_COMMAND_SET("{$php} /usr/share/artica-postfix/exec.web-community-filter.php --register");
    events("Starting artica");
    echo "Starting......: " . date("H:i:s") . " nightly builds starting artica...\n";
    @file_put_contents("/usr/share/artica-postfix/download_progress", 45);
    system("/etc/init.d/artica-postfix start");
    echo "Starting......: " . date("H:i:s") . " nightly builds building init scripts\n";
    @file_put_contents("/usr/share/artica-postfix/download_progress", 50);
    system("{$php} /usr/share/artica-postfix/exec.initslapd.php --force >/dev/null 2>&1");
    echo "Starting......: " . date("H:i:s") . " nightly builds updating network\n";
    @file_put_contents("/usr/share/artica-postfix/download_progress", 55);
    system("{$php} /usr/share/artica-postfix/exec.virtuals-ip.php >/dev/null 2>&1");
    system("{$php} /usr/share/artica-postfix/exec.monit.php --build >/dev/null 2>&1");
    echo "Starting......: " . date("H:i:s") . " nightly builds purge and clean....\n";
    @file_put_contents("/usr/share/artica-postfix/download_progress", 60);
    shell_exec("{$nohup} /etc/init.d/slapd start >/dev/null 2>&1 &");
    shell_exec("{$nohup} /etc/init.d/artica-webconsole start >/dev/null 2>&1 &");
    if (is_file("/etc/init.d/nginx")) {
        shell_exec("{$nohup} /etc/init.d/nginx reload >/dev/null 2>&1 &");
    }
    shell_exec("{$nohup} /etc/init.d/auth-tail restart >/dev/null 2>&1 &");
    shell_exec("{$nohup} /etc/init.d/artica-framework restart >/dev/null 2>&1 &");
    shell_exec("{$nohup} /usr/share/artica-postfix/bin/process1 -perm >/dev/null 2>&1 &");
    shell_exec("{$nohup} /usr/share/artica-postfix/bin/artica-make --empty-cache >/dev/null 2>&1 &");
    shell_exec("{$nohup} /etc/init.d/monit restart >/dev/null 2>&1 &");
    shell_exec("{$nohup} /etc/init.d/artica-status restart --force >/dev/null 2>&1 &");
    shell_exec("{$nohup} {$php} /usr/share/artica-postfix/exec.squid.php --build-schedules >/dev/null 2>&1 &");
    shell_exec("{$nohup} {$php} /usr/share/artica-postfix/exec.schedules.php --defaults >/dev/null 2>&1 &");
    if (is_file($squidbin)) {
        squid_admin_mysql(1, "Reconfiguring proxy service", null, __FILE__, __LINE__);
        $cmd = "/etc/init.d/squid reload --script=" . basename(__FILE__) . " >/dev/null 2>&1 &";
        shell_exec($cmd);
    }
    events("done");
    @file_put_contents("/usr/share/artica-postfix/download_progress", 100);
    echo "Starting......: " . date("H:i:s") . " Done you can close the screen....\n";
    _artica_update_event(2, "RestartDedicatedServices(): finish", null, __FILE__, __LINE__);
}
コード例 #15
0
function start($port_id)
{
    $unix = new unix();
    $squid = new squidbee();
    $q = new mysql_squid_builder();
    $INCLUDE = false;
    $f = explode("\n", @file_get_contents("/etc/squid3/squid.conf"));
    build_progress_bandwidth("{limit_rate} {analyze}", 20);
    while (list($www, $line) = each($f)) {
        if (!preg_match("#acls_bandwidth\\.conf#", $line)) {
            continue;
        }
        echo "Include OK\n";
        $INCLUDE = TRUE;
        break;
    }
    if (!$INCLUDE) {
        echo "Include False, reconfigure\n";
        build_progress_bandwidth("{limit_rate} {reconfigure}", 80);
        $php = $unix->LOCATE_PHP5_BIN();
        system("{$php} /usr/share/artica-postfix/exec.squid.php --build --force");
        build_progress_bandwidth("{limit_rate} {done}", 100);
        return;
    }
    $md51 = md5_file("/etc/squid3/acls_bandwidth.conf");
    build_progress_bandwidth("{limit_rate} {reconfigure}", 50);
    $band = new squid_bandwith_builder();
    if (!$band->compile()) {
        build_progress_bandwidth("{limit_rate} {failed}", 110);
        return;
    }
    $md52 = md5_file("/etc/squid3/acls_bandwidth.conf");
    if ($md51 == $md52) {
        build_progress_bandwidth("{limit_rate} {done} {unmodified}", 100);
        return;
    }
    $squidbin = $unix->LOCATE_SQUID_BIN();
    build_progress_bandwidth("{limit_rate} {reloading}", 97);
    system("{$squidbin} -k reconfigure");
    build_progress_bandwidth("{limit_rate} {done} OK", 100);
    // FATAL: No valid signing SSL certificate
}
コード例 #16
0
function start($aspid = false)
{
    $unix = new unix();
    $sock = new sockets();
    $Masterbin = $unix->find_program("clamav-milter");
    if (!is_file($Masterbin)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, clamav-milter not installed\n";
        }
        return;
    }
    if (!$aspid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = $unix->get_pid_from_file($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return false;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $pid = PID_NUM();
    if ($unix->process_exists($pid)) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Service already started {$pid} since {$timepid}Mn...\n";
        }
        return true;
    }
    $ClamavMilterEnabled = intval($sock->GET_INFO("ClamavMilterEnabled"));
    $MimeDefangClamav = intval($sock->GET_INFO("MimeDefangClamav"));
    $MimeDefangEnabled = intval($sock->GET_INFO("MimeDefangEnabled"));
    if ($MimeDefangEnabled == 0) {
        $MimeDefangClamav = 0;
    }
    if ($MimeDefangClamav == 1) {
        $ClamavMilterEnabled = 0;
    }
    if ($ClamavMilterEnabled == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service disabled (see ClamavMilterEnabled/MimeDefangEnabled/MimeDefangClamav)\n";
        }
        return false;
    }
    $php5 = $unix->LOCATE_PHP5_BIN();
    $nohup = $unix->find_program("nohup");
    build_progress_restart("{starting_service}", 31);
    $aa_complain = $unix->find_program('aa-complain');
    if (is_file($aa_complain)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} add clamd Profile to AppArmor..\n";
        }
        shell_exec("{$aa_complain} {$Masterbin} >/dev/null 2>&1");
    }
    @mkdir("/var/clamav", 0755, true);
    @mkdir("/var/run/clamav", 0755, true);
    @mkdir("/var/lib/clamav", 0755, true);
    @mkdir("/var/log/clamav", 0755, true);
    $ClamUser = "******";
    $squidbin = $unix->LOCATE_SQUID_BIN();
    if (is_file($squidbin)) {
        $ClamUser = "******";
    }
    $unix->chown_func("{$ClamUser}", "{$ClamUser}", "/var/clamav");
    $unix->chown_func("{$ClamUser}", "{$ClamUser}", "/var/run/clamav");
    $unix->chown_func("{$ClamUser}", "{$ClamUser}", "/var/lib/clamav");
    $unix->chown_func("{$ClamUser}", "{$ClamUser}", "/var/log/clamav");
    build_progress_restart("{starting_service}", 32);
    $clamd_version = clamd_version();
    build();
    $cmd = "{$nohup} {$Masterbin} --config-file=/etc/clamav/clamav-milter.conf >/dev/null 2>&1 &";
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service version {$clamd_version}\n";
    }
    build_progress_restart("{starting_service} (clamd) ", 33);
    system("/etc/init.d/clamav-daemon start");
    shell_exec($cmd);
    for ($i = 1; $i < 5; $i++) {
        build_progress_restart("{starting_service}", 35);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} waiting {$i}/5\n";
        }
        sleep(1);
        $pid = PID_NUM();
        if ($unix->process_exists($pid)) {
            break;
        }
    }
    $pid = PID_NUM();
    if ($unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Success PID {$pid}\n";
        }
        sleep(1);
        for ($i = 1; $i < 11; $i++) {
            build_progress_restart("{starting_service}", 40);
            if ($unix->is_socket("/var/spool/postfix/var/run/clamav/clamav-milter.ctl")) {
                if ($GLOBALS["OUTPUT"]) {
                    echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Apply permissions on clamav-milter.ctl\n";
                }
                @chmod("/var/spool/postfix/var/run/clamav/clamav-milter.ctl", 0777);
                break;
            } else {
                if ($GLOBALS["OUTPUT"]) {
                    echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} waiting for socket... {$i}/10 clamav-milter.ctl\n";
                }
                sleep(1);
            }
        }
        if ($unix->is_socket("/var/spool/postfix/var/run/clamav/clamav-milter.ctl")) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Apply permissions on clamav-milter.ctl\n";
            }
            @chmod("/var/spool/postfix/var/run/clamav/clamav-milter.ctl", 0777);
        } else {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} socket failed\n";
            }
        }
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Failed\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} {$cmd}\n";
        }
        build_progress_restart("{starting_service} {failed}", 40);
        return;
    }
    $pid = PID_NUM();
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Failed..\n";
        }
        build_progress_restart("{starting_service} {failed}", 40);
        return;
    }
    if (!$unix->is_socket("/var/spool/postfix/var/run/clamav/clamav-milter.ctl")) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} socket Failed..\n";
        }
    }
    return true;
}
コード例 #17
0
ファイル: exec.squidguard.php プロジェクト: BillTheBest/1.6.x
function build_ufdbguard_HUP()
{
    if (isset($GLOBALS["build_ufdbguard_HUP_EXECUTED"])) {
        return;
    }
    $GLOBALS["build_ufdbguard_HUP_EXECUTED"] = true;
    $unix = new unix();
    $sock = new sockets();
    $forceTXT = null;
    $ufdbguardReloadTTL = intval($sock->GET_INFO("ufdbguardReloadTTL"));
    if ($ufdbguardReloadTTL < 1) {
        $ufdbguardReloadTTL = 10;
    }
    $php5 = $unix->LOCATE_PHP5_BIN();
    $rm = $unix->find_program("rm");
    shell_exec("{$php5} /usr/share/artica-postfix/exec.ufdbclient.reload.php");
    shell_exec("{$rm} /home/squid/error_page_cache/*");
    if (function_exists("debug_backtrace")) {
        $trace = @debug_backtrace();
        if (isset($trace[1])) {
            $called = "called by " . basename($trace[1]["file"]) . " {$trace[1]["function"]}() line {$trace[1]["line"]}";
        }
    }
    $trace = debug_backtrace();
    if (isset($trace[1])) {
        $called = " called by " . basename($trace[1]["file"]) . " {$trace[1]["function"]}() line {$trace[1]["line"]}";
    }
    $timeFile = "/etc/artica-postfix/pids/UfdbGuardReload.time";
    $TimeReload = $unix->file_time_min($timeFile);
    if (!$GLOBALS["FORCE"]) {
        if ($TimeReload < $ufdbguardReloadTTL) {
            build_progress("{reloading_service} {failed}", 110);
            $unix->_syslog("Webfiltering service Aborting reload, last reload since {$TimeReload}Mn, need at least {$ufdbguardReloadTTL}Mn", basename(__FILE__));
            echo "Starting......: " . date("H:i:s") . " Webfiltering service Aborting reload, last reload since {$TimeReload}Mn, need at least {$ufdbguardReloadTTL}Mn\n";
            return;
        }
    } else {
        echo "Starting......: " . date("H:i:s") . " --- FORCED --- ufdbGuard last reload was {$TimeReload}mn\n";
    }
    @unlink($timeFile);
    @file_put_contents($timeFile, time());
    $pid = ufdbguard_pid();
    build_progress("{reloading_service} {$pid}", 71);
    $squidbin = $unix->LOCATE_SQUID_BIN();
    $ufdbguardd = $unix->find_program("ufdbguardd");
    if (strlen($ufdbguardd) < 5) {
        WriteToSyslogMail("ufdbguardd no such binary", basename(__FILE__));
        return;
    }
    $kill = $unix->find_program("kill");
    if ($unix->process_exists($pid)) {
        $processTTL = intval($unix->PROCCESS_TIME_MIN($pid));
        $LastTime = intval($unix->file_time_min($timeFile));
        build_progress("{reloading_service} {$pid} {$processTTL}Mn", 72);
        echo "Starting......: " . date("H:i:s") . " Webfiltering service Reloading service TTL {$processTTL}Mn\n";
        echo "Starting......: " . date("H:i:s") . " Webfiltering service Reloading service Last config since {$LastTime}Mn\n";
        echo "Starting......: " . date("H:i:s") . " Webfiltering service Reloading Max reload {$ufdbguardReloadTTL}Mn\n";
        if (!$GLOBALS["FORCE"]) {
            echo "Starting......: " . date("H:i:s") . " Webfiltering service Reloading force is disabled\n";
            if ($LastTime < $ufdbguardReloadTTL) {
                squid_admin_mysql(2, "Reloading Web Filtering PID: {$pid} [Aborted] last reload {$LastTime}Mn, need {$ufdbguardReloadTTL}mn", null, __FILE__, __LINE__);
                echo "Starting......: " . date("H:i:s") . " Webfiltering service Reloading service Aborting... minimal time was {$ufdbguardReloadTTL}mn - Current {$LastTime}mn\n{$called}\n";
                return;
            }
            if ($processTTL < $ufdbguardReloadTTL) {
                squid_admin_mysql(2, "Reloading Web Filtering PID: {$pid} [Aborted] {$processTTL}Mn, need {$ufdbguardReloadTTL}mn", null, __FILE__, __LINE__);
                echo "Starting......: " . date("H:i:s") . " Webfiltering service PID: {$pid}  Reloading service Aborting... minimal time was {$ufdbguardReloadTTL}mn\n{$called}\n";
                return;
            }
        }
        if ($GLOBALS["FORCE"]) {
            $forceTXT = " with option FORCE enabled";
            $prefix = "[FORCED]:";
        }
        @unlink($timeFile);
        @file_put_contents($timeFile, time());
        echo "Starting......: " . date("H:i:s") . " Webfiltering service Reloading service PID:{$pid} {$processTTL}mn\n";
        squid_admin_mysql(1, "{$prefix}Reloading Web Filtering service PID: {$pid} TTL {$processTTL}Mn", "{$forceTXT}\n{$called}\n{$GLOBALS["CMDLINEXEC"]}");
        build_progress("{reloading_service} HUP {$pid}", 75);
        unix_system_HUP($pid);
        build_progress("{reloading_proxy_service}", 76);
        shell_exec("{$php5} /usr/share/artica-postfix/exec.ufdbclient.reload.php");
        $squidbin = $unix->LOCATE_SQUID_BIN();
        squid_admin_mysql(1, "{$prefix}Reloading Proxy service", null, __FILE__, __LINE__);
        system("{$squidbin} -k reconfigure");
        return true;
    }
    squid_admin_mysql(1, "Warning, Reloading Web Filtering but not running [action=start]", "{$forceTXT}\n{$called}\n{$GLOBALS["CMDLINEXEC"]}");
    echo "Starting......: " . date("H:i:s") . " Webfiltering service reloading service no pid is found, Starting service...\n";
    @unlink($timeFile);
    @file_put_contents($timeFile, time());
    build_progress("{starting_service}", 76);
    if (!ufdbguard_start()) {
        return;
    }
    echo "Starting......: " . date("H:i:s") . " Webfiltering Service restarting ufdb-tail process\n";
    shell_exec("/etc/init.d/ufdb-tail restart");
    shell_exec("{$php5} /usr/share/artica-postfix/exec.ufdbclient.reload.php");
    squid_admin_mysql(1, "{$prefix}Reloading Proxy service", null, __FILE__, __LINE__);
    system("{$squidbin} -k reconfigure");
    build_progress("{starting_service} {done}", 77);
    return true;
}
コード例 #18
0
function LogRotateTimeAndSize($BaseWorkDir)
{
    if (!is_dir($BaseWorkDir)) {
        return;
    }
    $unix = new unix();
    $sock = new sockets();
    $php5 = $unix->LOCATE_PHP5_BIN();
    $squidbin = $unix->LOCATE_SQUID_BIN();
    $echo = $unix->find_program("echo");
    $syslog = new mysql_storelogs();
    $LogsRotateDefaultSizeRotation = $sock->GET_INFO("LogsRotateDefaultSizeRotation");
    $SquidRotateOnlySchedule = intval($sock->GET_INFO("SquidRotateOnlySchedule"));
    if (!is_numeric($LogsRotateDefaultSizeRotation)) {
        $LogsRotateDefaultSizeRotation = 100;
    }
    $LogsRotateDeleteSize = intval($sock->GET_INFO("LogsRotateDeleteSize"));
    if ($LogsRotateDeleteSize == 0) {
        $LogsRotateDeleteSize = 5000;
    }
    $syslog = new mysql_storelogs();
    if ($BaseWorkDir == "/var/log/squid") {
        return;
    }
    if (!($handle = opendir($BaseWorkDir))) {
        return;
    }
    while (false !== ($fileZ = readdir($handle))) {
        if ($fileZ == ".") {
            continue;
        }
        if ($fileZ == "..") {
            continue;
        }
        $filename = "{$BaseWorkDir}/{$fileZ}";
        if (is_dir($filename)) {
            continue;
        }
        $size = $unix->file_size($filename);
        $sizePHP = round(unix_file_size($filename) / 1024);
        $size = round($size / 1024 / 1000, 2);
        if ($size >= $LogsRotateDeleteSize) {
            $syslog->events("{$filename} -> set to 0bytes {$size} >{$LogsRotateDeleteSize}", __FUNCTION__, __LINE__);
            shell_exec("{$echo} \" \" > \"{$filename}\"");
            $GLOBALS["DELETED_SIZE"] = $GLOBALS["DELETED_SIZE"] + $sizePHP;
            $GLOBALS["DELETED_FILES"]++;
            $GLOBALS["DELETED_FILES"][] = "{$filename}";
            continue;
        }
        if ($GLOBALS["VERBOSE"]) {
            echo "Found file: {$filename} {$size}M !== {$LogsRotateDefaultSizeRotation}M\n";
        }
        if ($fileZ == "cache.log") {
            if ($size > $LogsRotateDefaultSizeRotation) {
                if ($SquidRotateOnlySchedule == 0) {
                    exec("{$php5} /usr/share/artica-postfix/exec.squid.php --rotate --force 2>&1", $results);
                    squid_admin_mysql(2, "{$fileZ} {$size}M Exceed {$LogsRotateDefaultSizeRotation}M", "Artica flush a log rotation\n" . @implode("\n", $results));
                    return;
                } else {
                    if ($size > $LogsRotateDeleteSize) {
                        $warnfile = "/etc/artica-postfix/pids/squid.rotate.cache.warn";
                        if ($unix->file_time_min($warnfile) > 30) {
                            squid_admin_mysql(1, "Warning {$fileZ} {$size}M Exceed {$LogsRotateDeleteSize}M", null, __FILE__, __LINE__);
                            @unlink($warnfile);
                            @file_put_contents($warnfile, time());
                        }
                    }
                }
            }
            continue;
        }
        if ($fileZ == "external-acl.log") {
            continue;
        }
        if ($fileZ == "ufdbguardd.log") {
            continue;
        }
        if ($fileZ == "access.log") {
            if ($size > $LogsRotateDefaultSizeRotation) {
                if ($SquidRotateOnlySchedule == 0) {
                    $syslog->events("{$php5} /usr/share/artica-postfix/exec.squid.php --rotate --smooth", __FUNCTION__, __LINE__);
                    exec("{$php5} /usr/share/artica-postfix/exec.squid.php --rotate --smooth 2>&1", $results);
                    rotate_admin_events("{$fileZ} {$size}M Exceed {$LogsRotateDefaultSizeRotation}M perform a Proxy log rotation", __FUNCTION__, __FILE__, __LINE__, "proxy", $GLOBALS["SCHEDULE_ID"]);
                    squid_admin_mysql(2, "{$fileZ} {$size}M Exceed {$LogsRotateDefaultSizeRotation}M", "Artica flush a log rotation\n" . @implode("\n", $results));
                    return;
                } else {
                    if ($size > $LogsRotateDeleteSize) {
                        $warnfile = "/etc/artica-postfix/pids/squid.rotate.access.warn";
                        if ($unix->file_time_min($warnfile) > 30) {
                            $syslog->events("Warning {$fileZ} {$size}M Exceed {$LogsRotateDeleteSize}M", __FUNCTION__, __LINE__);
                            rotate_admin_events(1, "Warning {$fileZ} {$size}M Exceed {$LogsRotateDeleteSize}M", null, __FILE__, __LINE__);
                            squid_admin_mysql(1, "Warning {$fileZ} {$size}M Exceed {$LogsRotateDeleteSize}M", null, __FILE__, __LINE__);
                            @unlink($warnfile);
                            @file_put_contents($warnfile, time());
                        }
                    }
                }
            }
        }
        if ($fileZ == "netdb.state") {
            continue;
        }
        $time = $unix->file_time_min($filename);
        $filedate = date('Y-m-d H:i:s', filemtime($filename));
        if (preg_match("#access\\.log[0-9]+\$#", $filename)) {
            continue;
        }
        if (preg_match("#access\\.log\\.[0-9]+\$#", $filename)) {
            continue;
        }
        if (preg_match("#sarg\\.log\\.[0-9]+\$#", $filename)) {
            @mkdir("/home/squid/sarg_logs");
            $syslog->events("copy {$filename} -> /home/squid/sarg_logs/" . basename($filename) . "." . filemtime($filename), __FUNCTION__, __LINE__);
            if (@copy($filename, "/home/squid/sarg_logs/" . basename($filename) . "." . filemtime($filename))) {
                @unlink($filename);
            }
            continue;
        }
        $extension = pathinfo($filename, PATHINFO_EXTENSION);
        if ($GLOBALS["VERBOSE"]) {
            echo "Analyze {$filename} ({$extension}) {$filedate}\n";
        }
        if (is_numeric($extension)) {
            $syslog->events("ROTATE_TOMYSQL {$filename}", __FUNCTION__, __LINE__);
            $syslog->ROTATE_TOMYSQL($filename, $filedate);
            continue;
        }
        if ($extension == "gz") {
            $syslog->events("ROTATE_TOMYSQL {$filename}", __FUNCTION__, __LINE__);
            $syslog->ROTATE_TOMYSQL($filename, $filedate);
            continue;
        }
        if ($extension == "state") {
            continue;
        }
        if ($extension == "bz2") {
            $syslog->events("ROTATE_TOMYSQL {$filename}", __FUNCTION__, __LINE__);
            $syslog->ROTATE_TOMYSQL($filename, $filedate);
            continue;
        }
        $time = $unix->file_time_min($filename);
        echo "{$filename} {$time}Mn\n";
        $syslog->events("ROTATE_TOMYSQL {$filename}", __FUNCTION__, __LINE__);
        $syslog->ROTATE_TOMYSQL($filename, $filedate);
    }
}
コード例 #19
0
ファイル: exec.arpscan.php プロジェクト: brucewu16899/1.6.x
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 &");
    }
}
コード例 #20
0
ファイル: exec.freshclam.php プロジェクト: articatech/artica
function build()
{
    $sock = new sockets();
    $unix = new unix();
    $clamdscan = $unix->find_program("clamdscan");
    $FreshClamCheckDay = intval($sock->GET_INFO("FreshClamCheckDay"));
    $FreshClamMaxAttempts = intval($sock->GET_INFO("FreshClamMaxAttempts"));
    if ($FreshClamCheckDay == 0) {
        $FreshClamCheckDay = 16;
    }
    if ($FreshClamMaxAttempts == 0) {
        $FreshClamMaxAttempts = 16;
    }
    $ClamUser = $unix->ClamUser();
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} clamdscan = {$clamdscan}\n";
    }
    $f[] = "DatabaseOwner {$ClamUser}";
    $f[] = "UpdateLogFile /var/log/clamav/freshclam.log";
    $f[] = "LogVerbose false";
    $f[] = "LogSyslog true";
    $f[] = "LogFacility LOG_LOCAL6";
    $f[] = "LogFileMaxSize 0";
    $f[] = "LogTime true";
    $f[] = "Foreground false";
    $f[] = "Debug false";
    $f[] = "MaxAttempts {$FreshClamMaxAttempts}";
    $f[] = "DatabaseDirectory /var/lib/clamav";
    $f[] = "AllowSupplementaryGroups true";
    $f[] = "NotifyClamd /etc/clamav/clamd.conf";
    $f[] = "PidFile /var/run/clamav/freshclam.pid";
    $f[] = "ConnectTimeout 30";
    $f[] = "ReceiveTimeout 30";
    $f[] = "TestDatabases yes";
    $f[] = "ScriptedUpdates yes";
    $f[] = "CompressLocalDatabase no";
    $f[] = "Bytecode true";
    $f[] = "# Check for new database {$FreshClamCheckDay} times a day";
    $f[] = "Checks {$FreshClamCheckDay}";
    $f[] = "DNSDatabaseInfo current.cvd.clamav.net";
    $f[] = "DatabaseMirror db.local.clamav.net";
    $f[] = "DatabaseMirror database.clamav.net";
    $f[] = "OnUpdateExecute " . __FILE__ . " --updated";
    $HTTPProxyServer = $unix->GET_HTTP_PROXY_STRING();
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Proxy:{$HTTPProxyServer}\n";
    }
    if ($HTTPProxyServer != null) {
        if (preg_match("#\\/\\/(.+?):([0-9]+)#", $HTTPProxyServer, $re)) {
            $f[] = "HTTPProxyServer {$re[1]}";
            $f[] = "HTTPProxyPort {$re[2]}";
        } else {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Proxy:{$HTTPProxyServer} no match\n";
            }
        }
    }
    @mkdir("/etc/clamav", 0755, true);
    $SecuriteInfoCode = $sock->GET_INFO("SecuriteInfoCode");
    $EnableClamavUnofficial = intval($sock->GET_INFO("EnableClamavUnofficial"));
    if ($SecuriteInfoCode != null) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Enabled: securiteinfo\n";
        }
        $f[] = "DatabaseCustomURL http://www.securiteinfo.com/get/signatures/{$SecuriteInfoCode}/securiteinfo.hdb";
        $f[] = "DatabaseCustomURL http://www.securiteinfo.com/get/signatures/{$SecuriteInfoCode}/securiteinfo.ign2";
        $f[] = "DatabaseCustomURL http://www.securiteinfo.com/get/signatures/{$SecuriteInfoCode}/javascript.ndb";
        $f[] = "DatabaseCustomURL http://www.securiteinfo.com/get/signatures/{$SecuriteInfoCode}/spam_marketing.ndb";
        $f[] = "DatabaseCustomURL http://www.securiteinfo.com/get/signatures/{$SecuriteInfoCode}/securiteinfohtml.hdb";
        $f[] = "DatabaseCustomURL http://www.securiteinfo.com/get/signatures/{$SecuriteInfoCode}/securiteinfoascii.hdb";
    }
    $f[] = "";
    $f[] = "";
    @file_put_contents("/etc/clamav/freshclam.conf", @implode("\n", $f));
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Unofficial databases:{$EnableClamavUnofficial}\n";
    }
    if ($EnableClamavUnofficial == 1) {
        if (!is_file("/etc/cron.d/clamav-unofficial-sigs-cron")) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Building /etc/cron.d/clamav-unofficial-sigs-cron\n";
            }
            $CRON[] = "MAILTO=\"\"";
            $CRON[] = "45 * * * * root /usr/share/artica-postfix/bin/clamav-unofficial-sigs.sh -c /etc/clamav-unofficial-sigs.conf >/dev/null 2>&1";
            $CRON[] = "";
            file_put_contents("/etc/cron.d/clamav-unofficial-sigs-cron", @implode("\n", $CRON));
            $CRON = array();
            chmod("/etc/cron.d/clamav-unofficial-sigs-cron", 0640);
            chown("/etc/cron.d/clamav-unofficial-sigs-cron", "root");
            system("/etc/init.d/cron reload");
        }
    } else {
        if (is_file("/etc/cron.d/clamav-unofficial-sigs-cron")) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Removing /etc/cron.d/clamav-unofficial-sigs-cron\n";
            }
            @unlink("/etc/cron.d/clamav-unofficial-sigs-cron");
            system("/etc/init.d/cron reload");
        }
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} freshclam.conf done\n";
    }
    $unix = new unix();
    $sock = new sockets();
    $CurlProxy = null;
    $squidbin = $unix->LOCATE_SQUID_BIN();
    if (is_file($squidbin)) {
        $SQUIDEnable = $sock->GET_INFO("SQUIDEnable");
        if (!is_numeric($SQUIDEnable)) {
            $SQUIDEnable = 1;
        }
        if ($SQUIDEnable == 1) {
            $port = $unix->squid_internal_port();
            $CurlProxy = "-x 127.0.0.1:{$port}";
        }
    }
    if ($CurlProxy == null) {
        $ini = new Bs_IniHandler();
        $sock = new sockets();
        $datas = $sock->GET_INFO("ArticaProxySettings");
        if (trim($datas) != null) {
            $ini->loadString($datas);
            $ArticaProxyServerEnabled = $ini->_params["PROXY"]["ArticaProxyServerEnabled"];
            $ArticaProxyServerName = $ini->_params["PROXY"]["ArticaProxyServerName"];
            $ArticaProxyServerPort = $ini->_params["PROXY"]["ArticaProxyServerPort"];
            $ArticaProxyServerUsername = trim($ini->_params["PROXY"]["ArticaProxyServerUsername"]);
            $ArticaProxyServerUserPassword = $ini->_params["PROXY"]["ArticaProxyServerUserPassword"];
            if ($ArticaProxyServerEnabled == 1) {
                $ArticaProxyServerEnabled = "yes";
            }
        }
        if ($ArticaProxyServerEnabled == "yes") {
            $CurlProxy = "-x {$ArticaProxyServerName}:{$ArticaProxyServerPort}";
            if ($ArticaProxyServerUsername != null) {
                $ArticaProxyServerUserPassword = $unix->shellEscapeChars($ArticaProxyServerUserPassword);
                $CurlProxy = $CurlProxy . " -U {$ArticaProxyServerUsername}:{$ArticaProxyServerUserPassword}";
            }
        }
    }
    @mkdir("/var/log/clamav-unofficial-sigs", 0755, true);
    @chmod("/usr/share/artica-postfix/exec.freshclam.updated.php", 0755);
    @chmod("/usr/share/artica-postfix/exec.freshclam.sansecurity.updated.php", 0755);
    @chmod("/usr/share/artica-postfix/bin/clamav-unofficial-sigs.sh", 0755);
    $SecuriteInfoCode = $sock->GET_INFO("SecuriteInfoCode");
    $MalwarePatrolCode = $sock->GET_INFO("MalwarePatrolCode");
    $f = array();
    $f[] = "# This file contains user configuration settings for clamav-unofficial-sigs.sh";
    $f[] = "###################";
    $f[] = "# This is property of eXtremeSHOK.com";
    $f[] = "# You are free to use, modify and distribute, however you may not remove this notice.";
    $f[] = "# Copyright (c) Adrian Jon Kriel :: admin@extremeshok.com";
    $f[] = "##################";
    $f[] = "#";
    $f[] = "# Script updates can be found at: https://github.com/extremeshok/clamav-unofficial-sigs";
    $f[] = "# ";
    $f[] = "# Originially based on: ";
    $f[] = "# Script provide by Bill Landry (unofficialsigs@gmail.com).";
    $f[] = "#";
    $f[] = "# License: BSD (Berkeley Software Distribution)";
    $f[] = "#";
    $f[] = "##################";
    $f[] = "#";
    $f[] = "# NOT COMPATIBLE WITH VERSION 3.XX CONFIG ";
    $f[] = "#";
    $f[] = "################################################################################";
    $f[] = "";
    $f[] = "# Edit the quoted variables below to meet your own particular needs";
    $f[] = "# and requirements, but do not remove the \"quote\" marks.";
    $f[] = "";
    $f[] = "# Set the appropriate ClamD user and group accounts for your system.";
    $f[] = "# If you do not want the script to set user and group permissions on";
    $f[] = "# files and directories, comment the next two variables.";
    $f[] = "clam_user=\"{$ClamUser}\"";
    $f[] = "clam_group=\"{$ClamUser}\"";
    $f[] = "clam_dbs=\"/var/lib/clamav\"";
    $f[] = "clamd_pid=\"/var/run/clamav/clamd.pid\"";
    $f[] = "#reload_dbs=\"yes\"";
    $f[] = "#reload_opt=\"{$clamdscan} --reload\"  # Default";
    $f[] = "# owner: read, write";
    $f[] = "# group: read";
    $f[] = "# world: read";
    $f[] = "#";
    $f[] = "# as defined in the \"clam_dbs\" path variable below, then set the following";
    $f[] = "# \"setmode\" variable to \"no\".";
    $f[] = "setmode=\"yes\"";
    $f[] = "";
    $f[] = "# Set path to ClamAV database files location.  If unsure, check";
    $f[] = "# your clamd.conf file for the \"DatabaseDirectory\" path setting.";
    $f[] = "clam_dbs=\"/var/lib/clamav\"";
    $f[] = "";
    $f[] = "# Set path to clamd.pid file (see clamd.conf for path location).";
    $f[] = "clamd_pid=\"/var/run/clamav/clamd.pid\"";
    $f[] = "#clamd_pid=\"/var/run/clamd.pid\"";
    $f[] = "";
    $f[] = "# To enable \"ham\" (non-spam) directory scanning and removal of";
    $f[] = "# signatures that trigger on ham messages, uncomment the following";
    $f[] = "# variable and set it to the appropriate ham message directory.";
    $f[] = "#ham_dir=\"/var/lib/clamav-unofficial-sigs/ham-test\"";
    $f[] = "";
    $f[] = "# If you would like to reload the clamd databases after an update,";
    $f[] = "# change the following variable to \"yes\".";
    $f[] = "reload_dbs=\"yes\"";
    $f[] = "";
    $f[] = "# Top level working directory, script will attempt to create them.";
    $f[] = "work_dir=\"/var/lib/clamav-unofficial-sigs\"   #Top level working directory";
    $f[] = "";
    $f[] = "# Log update information to '\$log_file_path/\$log_file_name'.";
    $f[] = "enable_logging=\"yes\"";
    $f[] = "log_file_path=\"/var/log/clamav-unofficial-sigs\"";
    $f[] = "log_file_name=\"clamav-unofficial-sigs.log\"";
    $f[] = "";
    $f[] = "";
    $f[] = "# =========================";
    $f[] = "# MalwarePatrol : https://www.malwarepatrol.net";
    $f[] = "# MalwarePatrol 2015 free clamav signatures";
    $f[] = "#";
    $f[] = "# 1. Sign up for a free account : https://www.malwarepatrol.net/signup-free.shtml";
    $f[] = "# 2. You will recieve an email containing your password/receipt number";
    $f[] = "# 3. Enter the receipt number into the config: replacing YOUR-RECEIPT-NUMBER with your receipt number from the email";
    $f[] = "";
    $f[] = "malwarepatrol_receipt_code=\"{$MalwarePatrolCode}\"";
    $f[] = "# Set to no to enable the commercial subscription url.";
    $f[] = "malwarepatrol_free=\"yes\"";
    $f[] = "";
    $f[] = "# =========================";
    $f[] = "# SecuriteInfo : https://www.SecuriteInfo.com";
    $f[] = "# SecuriteInfo 2015 free clamav signatures";
    $f[] = "#";
    $f[] = "#Usage of SecuriteInfo 2015 free clamav signatures : https://www.securiteinfo.com";
    $f[] = "# - 1. Sign up for a free account : https://www.securiteinfo.com/clients/customers/signup";
    $f[] = "# - 2. You will recieve an email to activate your account and then a followup email with your login name";
    $f[] = "# - 3. Login and navigate to your customer account : https://www.securiteinfo.com/clients/customers/account";
    $f[] = "# - 4. Click on the Setup tab";
    $f[] = "# - 5. You will need to get your unique identifier from one of the download links, they are individual for every user";
    $f[] = "# - 5.1. The 128 character string is after the http://www.securiteinfo.com/get/signatures/ ";
    $f[] = "# - 5.2. Example https://www.securiteinfo.com/get/signatures/your_unique_and_very_long_random_string_of_characters/securiteinfo.hdb";
    $f[] = "#   Your 128 character authorisation signature would be : your_unique_and_very_long_random_string_of_characters";
    $f[] = "# - 6. Enter the authorisation signature into the config securiteinfo_authorisation_signature: replacing YOUR-SIGNATURE-NUMBER with your authorisation signature from the link";
    $f[] = "";
    $f[] = "securiteinfo_authorisation_signature=\"{$SecuriteInfoCode}\"";
    $f[] = "";
    $f[] = "# ========================";
    $f[] = "# Database provider update time";
    $f[] = "# ========================";
    $f[] = "# Since the database files are dynamically created, non default values can cause banning, change with caution";
    $f[] = "";
    $f[] = "securiteinfo_update_hours=\"4\"   # Default is 4 hours (6 downloads daily).";
    $f[] = "linuxmalwaredetect_update_hours=\"6\"   # Default is 6 hours (4 downloads daily).";
    $f[] = "malwarepatrol_update_hours=\"24\"   # Default is 24 hours (1 downloads daily).";
    $f[] = "yararules_update_hours=\"24\"   # Default is 24 hours (1 downloads daily).";
    $f[] = "";
    $f[] = "# ========================";
    $f[] = "# Enabled Databases";
    $f[] = "# ========================";
    $f[] = "# Set to no to disable an entire database.";
    if ($SecuriteInfoCode != null) {
        $f[] = "securiteinfo_enabled=\"yes\"   # SecuriteInfo ";
    } else {
        $f[] = "securiteinfo_enabled=\"no\"   # SecuriteInfo ";
    }
    $f[] = "sanesecurity_enabled=\"yes\"   # Sanesecurity";
    $f[] = "linuxmalwaredetect_enabled=\"yes\"   # Linux Malware Detect";
    if ($MalwarePatrolCode != null) {
        $f[] = "malwarepatrol_enabled=\"yes\"   # Malware Patrol";
    } else {
        $f[] = "malwarepatrol_enabled=\"no\"   # Malware Patrol";
    }
    $f[] = "yararules_enabled=\"no\"   # Yara-Rule Project, requires clamAV 0.99+";
    $f[] = "";
    $f[] = "# ========================";
    $f[] = "# Sanesecurity Database(s)";
    $f[] = "# ========================";
    $f[] = "# Add or remove database file names between quote marks as needed.  To";
    $f[] = "# disable usage of any of the Sanesecurity distributed database files";
    $f[] = "# shown, remove the database file name from the quoted section below.";
    $f[] = "# Only databases defined as \"low\" risk have been enabled by default ";
    $f[] = "# for additional information about the database ratings, see: ";
    $f[] = "# http://www.sanesecurity.com/clamav/databases.htm";
    $f[] = "# Only add signature databases here that are \"distributed\" by Sanesecuirty";
    $f[] = "# as defined at the URL shown above.  Database distributed by others sources";
    $f[] = "# (e.g., SecuriteInfo & MalewarePatrol, can be added to other sections of";
    $f[] = "# this config file below).  Finally, make sure that the database names are";
    $f[] = "# spelled correctly or you will experience issues when the script runs";
    $f[] = "# (hint: all rsync servers will fail to download signature updates).";
    $f[] = "";
    $f[] = "sanesecurity_dbs=\" # BEGIN SANESECURITY DATABASE";
    $f[] = "### SANESECURITY http://sanesecurity.com/usage/signatures/";
    $f[] = "## REQUIRED, Do NOT disable";
    $f[] = "sanesecurity.ftm  #REQUIRED Message file types, for best performance";
    $f[] = "sigwhitelist.ign2 #REQUIRED Fast update file to whitelist any problem signatures";
    $f[] = "## LOW";
    $f[] = "junk.ndb  #LOW  General high hitting junk, containing spam/phishing/lottery/jobs/419s etc ";
    $f[] = "jurlbl.ndb #LOW Junk Url based";
    $f[] = "phish.ndb #LOW Phishing";
    $f[] = "rogue.hdb  #LOW Malware, Rogue anti-virus software and Fake codecs etc.  Updated hourly to cover the latest malware threats  ";
    $f[] = "scam.ndb #LOW Spam/scams  ";
    $f[] = "spamimg.hdb #LOW Spam images ";
    $f[] = "spamattach.hdb #LOW Spam Spammed attachments such as pdf/doc/rtf/zip ";
    $f[] = "blurl.ndb  #LOW Blacklisted full urls over the last 7 days, covering malware/spam/phishing. URLs added only when main signatures have failed to detect but are known to be \"bad\"  ";
    $f[] = "## MED";
    $f[] = "spear.ndb  #MED Spear phishing email addresses (autogenerated from data here)";
    $f[] = "lott.ndb  #MED Lottery  ";
    $f[] = "spam.ldb  #MED Spam detected using the new Logical Signature type";
    $f[] = "spearl.ndb  #MED Spear phishing urls (autogenerated from data here)   ";
    $f[] = "jurlbla.ndb #MED Junk Url based autogenerated from various feeds";
    $f[] = "badmacro.ndb #MED Detect dangerous macros";
    $f[] = "";
    $f[] = "### FOXHOLE http://sanesecurity.com/foxhole-databases/";
    $f[] = "## LOW";
    $f[] = "malwarehash.hsb  #LOW Malware hashes without known Size";
    $f[] = "## MED";
    $f[] = "#foxhole_generic.cdb #MED See Foxhole page for more details";
    $f[] = "#foxhole_filename.cdb #MED See Foxhole page for more details";
    $f[] = "## HIGH";
    $f[] = "#foxhole_all.cdb  #HIGH See Foxhole page for more details  ";
    $f[] = "";
    $f[] = "### OITC http://www.oitc.com/winnow/clamsigs/index.html";
    $f[] = "### Note: the two databases winnow_phish_complete.ndb and winnow_phish_complete_url.ndb should NOT be used together.  ";
    $f[] = "# LOW";
    $f[] = "winnow.attachments.hdb  #LOW Spammed attachments such as pdf/doc/rtf/zip";
    $f[] = "winnow_malware.hdb  #LOW Current virus, trojan and other malware not yet detected by ClamAV.";
    $f[] = "winnow_malware_links.ndb #LOW Links to malware";
    $f[] = "winnow_extended_malware.hdb  #LOW contain hand generated signatures for malware ";
    $f[] = "winnow_bad_cw.hdb #LOW md5 hashes of malware attachments acquired directly from a group of botnets";
    $f[] = "# MED";
    $f[] = "#winnow_phish_complete_url.ndb #Med Similar to winnow_phish_complete.ndb except that entire urls are used  ";
    $f[] = "#winnow.complex.patterns.ldb  #MED contain hand generated signatures for malware and some egregious fraud  ";
    $f[] = "#winnow_extended_malware_links.ndb #MED contain hand generated signatures for malware links ";
    $f[] = "#winnow_spam_complete.ndb  #MED Signatures to detect fraud and other malicious spam";
    $f[] = "# HIGH";
    $f[] = "#winnow_phish_complete.ndb #HIGH Phishing and other malicious urls and compromised hosts **DO NOT USE WITH winnow_phish_complete_url**";
    $f[] = "";
    $f[] = "### SCAMNAILER http://www.scamnailer.info/";
    $f[] = "# MED";
    $f[] = "#scamnailer.ndb  #MED Spear phishing and other phishing emails";
    $f[] = "";
    $f[] = "### BOFHLAND http://clamav.bofhland.org/";
    $f[] = "# LOW";
    $f[] = "bofhland_cracked_URL.ndb  #LOW Spam URLs  ";
    $f[] = "bofhland_malware_URL.ndb  #LOW Malware URLs ";
    $f[] = "bofhland_phishing_URL.ndb #LOW Phishing URLs";
    $f[] = "bofhland_malware_attach.hdb #LOW Malware Hashes";
    $f[] = "";
    $f[] = "###  RockSecurity http://rooksecurity.com/";
    $f[] = "#LOW";
    $f[] = "hackingteam.hsb #LOW Hacking Team hashes";
    $f[] = "";
    $f[] = "### CRDF https://threatcenter.crdf.fr/";
    $f[] = "# LOW";
    $f[] = "crdfam.clamav.hdb #LOW List of new threats detected by CRDF Anti Malware  ";
    $f[] = "";
    $f[] = "### Porcupine";
    $f[] = "# LOW";
    $f[] = "porcupine.ndb  #LOW Brazilian e-mail phishing and malware signatures ";
    $f[] = "phishtank.ndb  #LOW Online and valid phishing urls from phishtank.com data feed ";
    $f[] = "";
    $f[] = "### Sanesecurity YARA Format rules";
    $f[] = "### Note: Yara signatures require ClamAV 0.99 or newer to work";
    $f[] = "#Sanesecurity_sigtest.yara #LOW Sanesecurity test signatures ";
    $f[] = "#Sanesecurity_spam.yara #LOW detect spam ";
    $f[] = "";
    $f[] = "\" # END SANESECURITY DATABASES";
    $f[] = "";
    $f[] = "# ========================";
    $f[] = "# SecuriteInfo Database(s)";
    $f[] = "# ========================";
    $f[] = "# Only active when you set your securiteinfo_authorisation_signature";
    $f[] = "# Add or remove database file names between quote marks as needed.  To";
    $f[] = "# disable any SecuriteInfo database downloads, remove the appropriate";
    $f[] = "# lines below.";
    $f[] = "securiteinfo_dbs=\"";
    $f[] = "### Securiteinfo https://www.securiteinfo.com/services/improve-detection-rate-of-zero-day-malwares-for-clamav.shtml";
    $f[] = "## REQUIRED, Do NOT disable";
    $f[] = "securiteinfo.ign2";
    $f[] = "# LOW";
    $f[] = "securiteinfo.hdb #LOW Malwares in the Wild";
    $f[] = "javascript.ndb  #LOW Malwares Javascript ";
    $f[] = "securiteinfohtml.hdb  #LOW Malwares HTML ";
    $f[] = "securiteinfoascii.hdb  #LOW Text file malwares (Perl or shell scripts, bat files, exploits, ...)";
    $f[] = "securiteinfopdf.hdb #LOW Malwares PDF ";
    $f[] = "# HIGH";
    $f[] = "#spam_marketing.ndb #HIGH Spam Marketing /  spammer blacklist";
    $f[] = "\" #END SECURITEINFO DATABASES";
    $f[] = "";
    $f[] = "# ========================";
    $f[] = "# Linux Malware Detect Database(s)";
    $f[] = "# ========================";
    $f[] = "# Add or remove database file names between quote marks as needed.  To";
    $f[] = "# disable any SecuriteInfo database downloads, remove the appropriate";
    $f[] = "# lines below.";
    $f[] = "linuxmalwaredetect_dbs=\"";
    $f[] = "### Linux Malware Detect https://www.rfxn.com/projects/linux-malware-detect/";
    $f[] = "# LOW";
    $f[] = "rfxn.ndb #LOW HEX Malware detection signatures";
    $f[] = "rfxn.hdb  #LOW MD5 malware detection signatures";
    $f[] = "\" #END LINUXMALWAREDETECT DATABASES";
    $f[] = "";
    $f[] = "# =========================";
    $f[] = "# MalwarePatrol Database ";
    $f[] = "# =========================";
    $f[] = "# Only active when you set your malwarepatrol_receipt_code";
    $f[] = "## REQUIRED, Do NOT disable";
    $f[] = "malwarepatrol_db=\"malwarepatrol.db\" #LOW URLs containing of Viruses, Trojans, Worms, or Malware  ";
    $f[] = "";
    $f[] = "# ========================";
    $f[] = "# Yara Rules Project Database(s)";
    $f[] = "# ========================";
    $f[] = "# Add or remove database file names between quote marks as needed.  To";
    $f[] = "# disable any Yara Rule database downloads, remove the appropriate";
    $f[] = "# lines below.";
    $f[] = "yararules_dbs=\"";
    $f[] = "### Yara Rules https://github.com/Yara-Rules/rules";
    $f[] = "# LOW";
    $f[] = "antidebug.yar #LOW anti debug and anti virtualization techniques used by malware ";
    $f[] = "malicious_document.yar #LOW documents with malicious code";
    $f[] = "# MED";
    $f[] = "#packer.yar #MED well-known sofware packers";
    $f[] = "# HIGH";
    $f[] = "#crypto.yar #HIGH detect the existence of cryptographic algoritms";
    $f[] = "\" #END YARARULES DATABASES";
    $f[] = "";
    $f[] = "";
    $f[] = "# =========================";
    $f[] = "# Additional signature databases";
    $f[] = "# =========================";
    $f[] = "# Additional signature databases can be specified here in the following";
    $f[] = "# format: PROTOCOL://URL-or-IP/PATH/TO/FILE-NAME (use a trailing \"/\" in";
    $f[] = "# place of the \"FILE-NAME\" to download all files from specified location,";
    $f[] = "# but this *ONLY* works for files downloaded via rsync).  For non-rsync";
    $f[] = "# downloads, curl is used.  For download protocols supported by curl, see";
    $f[] = "# \"man curl\".  This also works well for locations that have many ClamAV";
    $f[] = "# servers that use 3rd party signature databases, as only one server need";
    $f[] = "# download the remote databases, and all others can update from the local";
    $f[] = "# mirrors copy.  See format examples below.  To use, remove the comments";
    $f[] = "# and examples shown and add your own sites between the quote marks.";
    $f[] = "#add_dbs=\"";
    $f[] = "#   rsync://192.168.1.50/new-db/sigs.hdb";
    $f[] = "#   rsync://rsync.example.com/all-dbs/";
    $f[] = "#   ftp://ftp.example.net/pub/sigs.ndb";
    $f[] = "#   http://www.example.org/sigs.ldb";
    $f[] = "#\" #END ADDITIONAL DATABASES";
    $f[] = "";
    $f[] = "";
    $f[] = "";
    $f[] = "";
    $f[] = "# ==================================================";
    $f[] = "# ==================================================";
    $f[] = "# A D V A N C E D   O P T I O N S";
    $f[] = "# ==================================================";
    $f[] = "# ==================================================";
    $f[] = "";
    $f[] = "# Enable or disable download time randomization.  This allows the script to";
    $f[] = "# be executed via cron, but the actual database file checking will pause";
    $f[] = "# for a random number of seconds between the \"min\" and \"max\" time settings";
    $f[] = "# specified below.  This helps to more evenly distribute load on the host";
    $f[] = "# download sites.  To disable, set the following variable to \"no\".";
    $f[] = "enable_random=\"yes\"";
    $f[] = "";
    $f[] = "# If download time randomization is enabled above (enable_random=\"yes\"),";
    $f[] = "# then set the min and max radomization time intervals (in seconds).";
    $f[] = "min_sleep_time=\"60\"    # Default minimum is 60 seconds (1 minute).";
    $f[] = "max_sleep_time=\"600\"   # Default maximum is 600 seconds (10 minutes).";
    $f[] = "";
    $f[] = "# Set the clamd_restart_opt if the \"reload_dbs\" variable above is set";
    $f[] = "# Command to do a full clamd service stop/start";
    $f[] = "clamd_restart_opt=\"/etc/init.d/clamd restart\"";
    $f[] = "";
    $f[] = "# If running clamd in \"LocalSocket\" mode (*NOT* in TCP/IP mode), and";
    $f[] = "# either \"SOcket Cat\" (socat) or the \"IO::Socket::UNIX\" perl module";
    $f[] = "# are installed on the system, and you want to report whether clamd";
    $f[] = "# is running or not, uncomment the \"clamd_socket\" variable below (you";
    $f[] = "# will be warned if neither socat nor IO::Socket::UNIX are found, but";
    $f[] = "# the script will still run).  You will also need to set the correct";
    $f[] = "# path to your clamd socket file (if unsure of the path, check the";
    $f[] = "# \"LocalSocket\" setting in your clamd.conf file for socket location).";
    $f[] = "#clamd_socket=\"/tmp/clamd.socket\"";
    $f[] = "#clamd_socket=\"/var/run/clamd.socket\"";
    $f[] = "";
    $f[] = "# If you would like to attempt to restart ClamD if detected not running,";
    $f[] = "# uncomment the next 2 lines.  Enter the clamd service stop and  start command";
    $f[] = "# for your particular distro for the \"start_clamd\" \"stop_clamd\" variables";
    $f[] = "# (the sample start command shown below should work for most linux distros).";
    $f[] = "# NOTE: these 2 variables are dependant on the \"clamd_socket\" variable";
    $f[] = "# shown above - if not enabled, then the following 2 variables will be";
    $f[] = "# ignored, whether enabled or not.";
    $f[] = "#clamd_start=\"service clamd start\"";
    $f[] = "#clamd_stop=\"service clamd stop\"";
    $f[] = "";
    $f[] = "# Set rsync connection and data transfer timeout limits in seconds.";
    $f[] = "# The defaults settings here are reasonable, only change if you are";
    $f[] = "# experiencing timeout issues.";
    $f[] = "rsync_connect_timeout=\"30\"";
    $f[] = "rsync_max_time=\"90\"";
    $f[] = "";
    $f[] = "# Set curl connection and data transfer timeout limits in seconds.";
    $f[] = "# The defaults settings here are reasonable, only change if you are";
    $f[] = "# experiencing timeout issues.";
    $f[] = "curl_connect_timeout=\"30\"";
    $f[] = "curl_max_time=\"90\"";
    $f[] = "";
    $f[] = "# Set working directory paths (edit to meet your own needs). If these";
    $f[] = "# directories do not exist, the script will attempt to create them.";
    $f[] = "# Sub-directory names:";
    $f[] = "sanesecurity_dir=\"\$work_dir/dbs-ss\"        # Sanesecurity sub-directory";
    $f[] = "securiteinfo_dir=\"\$work_dir/dbs-si\"        # SecuriteInfo sub-directory ";
    $f[] = "linuxmalwaredetect_dir=\"\$work_dir/dbs-lmd\"      # Linux Malware Detect sub-directory ";
    $f[] = "malwarepatrol_dir=\"\$work_dir/dbs-mbl\"      # MalwarePatrol sub-directory ";
    $f[] = "yararules_dir=\"\$work_dir/dbs-yara\"      # Yara-Rules sub-directory ";
    $f[] = "config_dir=\"\$work_dir/configs\"   # Script configs sub-directory";
    $f[] = "gpg_dir=\"\$work_dir/gpg-key\"      # Sanesecurity GPG Key sub-directory";
    $f[] = "add_dir=\"\$work_dir/dbs-add\"      # User defined databases sub-directory";
    $f[] = "";
    $f[] = "# If you would like to make a backup copy of the current running database";
    $f[] = "# file before updating, leave the following variable set to \"yes\" and a";
    $f[] = "# backup copy of the file will be created in the production directory";
    $f[] = "# with -bak appended to the file name.";
    $f[] = "keep_db_backup=\"no\"";
    $f[] = "";
    $f[] = "# If you want to silence the information reported by curl, rsync, gpg";
    $f[] = "# or the general script comments, change the following variables to";
    $f[] = "# \"yes\".  If all variables are set to \"yes\", the script will output";
    $f[] = "# nothing except error conditions.";
    $f[] = "silence_ssl=\"yes\" # Default is \"yes\" ignore ssl errors and warnings";
    $f[] = "curl_silence=\"no\"      # Default is \"no\" to report curl statistics";
    $f[] = "rsync_silence=\"no\"     # Default is \"no\" to report rsync statistics";
    $f[] = "gpg_silence=\"no\"       # Default is \"no\" to report gpg signature status";
    $f[] = "comment_silence=\"no\"   # Default is \"no\" to report script comments";
    $f[] = "";
    $f[] = "# If necessary to proxy database downloads, define the rsync and/or curl";
    $f[] = "# proxy settings here.  For rsync, the proxy must support connections to";
    $f[] = "# port 873.  Both curl and rsync proxy setting need to be defined in the";
    $f[] = "# format of \"hostname:port\".  For curl, also note the -x and -U flags,";
    $f[] = "# which must be set as \"-x hostname:port\" and \"-U username:password\".";
    $f[] = "rsync_proxy=\"\"";
    $f[] = "curl_proxy=\"{$CurlProxy}\"";
    $f[] = "user_configuration_complete=\"yes\"";
    $f[] = "";
    $f[] = "# ========================";
    $f[] = "# Database provider URLs, do not edit.";
    $f[] = "sanesecurity_url=\"rsync.sanesecurity.net\"";
    $f[] = "sanesecurity_gpg_url=\"http://www.sanesecurity.net/publickey.gpg\"";
    $f[] = "securiteinfo_url=\"https://www.securiteinfo.com/get/signatures/\"";
    $f[] = "linuxmalwaredetect_url=\"http://cdn.rfxn.com/downloads/\"";
    $f[] = "malwarepatrol_free_url=\"https://lists.malwarepatrol.net/cgi/getfile?product=8&list=clamav_basic\"";
    $f[] = "malwarepatrol_subscription_url=\"https://lists.malwarepatrol.net/cgi/getfile?product=15&list=clamav_basic\"";
    $f[] = "yararules_url=\"https://raw.githubusercontent.com/Yara-Rules/rules/master/\"";
    $f[] = "";
    $f[] = "# ========================";
    $f[] = "# do not edit";
    $f[] = "config_version=\"53\"";
    $f[] = "";
    @file_put_contents("/etc/clamav-unofficial-sigs.conf", @implode("\n", $f));
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} clamav-unofficial-sigs.conf done\n";
    }
    $f = array();
}
コード例 #21
0
function xstart()
{
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid";
    $pidtime = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".time";
    $dbfile = "/var/log/squid/ufdbgclient.unlock.db";
    $pid = @file_get_contents($pidfile);
    if ($GLOBALS["VERBOSE"]) {
        echo "{$pidtime}\n";
    }
    $unix = new unix();
    $squid = $unix->LOCATE_SQUID_BIN();
    if (!$GLOBALS["FORCE"]) {
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            unlock_events("Already executed pid {$pid} since {$time}mn-> DIE");
            if ($GLOBALS["VERBOSE"]) {
                echo "Already executed pid {$pid} since {$time}mn\n";
            }
            die;
        }
    }
    $mypid = getmypid();
    @file_put_contents($pidfile, $mypid);
    $timefile = $unix->file_time_min($pidtime);
    if ($GLOBALS["VERBOSE"]) {
        echo "Timelock:{$pidtime} {$timefile} Mn\n";
    }
    if (!$GLOBALS["FORCE"]) {
        if ($timefile < 5) {
            if ($GLOBALS["VERBOSE"]) {
                echo "{$timefile}mn require 5mn\n";
            }
            unlock_events("{$timefile}mn require 5mn");
            return;
        }
    }
    @unlink($pidtime);
    @file_put_contents($pidtime, time());
    $q = new mysql_squid_builder();
    $sock = new sockets();
    $EnableUfdbGuardArtica = $sock->EnableUfdbGuardArtica();
    unlock_events("EnableUfdbGuardArtica={$EnableUfdbGuardArtica}");
    $Count = $q->COUNT_ROWS("ufdbunlock");
    if ($Count == 0) {
        if ($GLOBALS["VERBOSE"]) {
            echo "ufdbunlock = 0 rows\n";
        }
        unlock_events("ufdbunlock = 0 rows");
        if (is_file($dbfile)) {
            @unlink($dbfile);
            if ($EnableUfdbGuardArtica == 0) {
                if ($GLOBALS["FORCE"]) {
                    squid_admin_mysql(2, "Reconfigure Proxy service in order to release blocked {$_GET["reconfigure-unlock"]} website(s)", null, __FILE__, __LINE__);
                    unlock_events("/etc/init.d/squid reload --script=exec.ufdb.queue.release.php");
                    system("/etc/init.d/squid reload --script=exec.ufdb.queue.release.php/" . __LINE__);
                    return;
                }
            }
            unlock_ufdbguard_artica();
            return;
        }
        die;
    }
    if ($EnableUfdbGuardArtica == 1) {
        unlock_ufdbguard_artica();
        return;
    }
    $q->QUERY_SQL("DELETE FROM ufdbunlock WHERE finaltime <" . time());
    $Count2 = $q->COUNT_ROWS("ufdbunlock");
    if ($Count == $Count2) {
        if ($Count2 == 0) {
            @unlink($dbfile);
        }
        if ($GLOBALS["VERBOSE"]) {
            echo "***** NOTHING ******\n";
        }
        if ($GLOBALS["FORCE"]) {
            squid_admin_mysql(2, "Reconfigure Proxy service in order to release blocked {$_GET["reconfigure-unlock"]} website(s)", null, __FILE__, __LINE__);
            system("/etc/init.d/squid reload --script=exec.ufdb.queue.release.php/" . __LINE__);
        }
        return;
    }
    $count3 = $Count - $Count2;
    $unix = new unix();
    $squid = $unix->LOCATE_SQUID_BIN();
    squid_admin_mysql(2, "Reconfigure Proxy service in order to re-block blocked {$count3} websites", null, __FILE__, __LINE__);
    system("/etc/init.d/squid reload --script=exec.ufdb.queue.release.php/" . __LINE__);
    $sock = new sockets();
    $EnableTransparent27 = intval($sock->GET_INFO("EnableTransparent27"));
    if ($EnableTransparent27 == 1) {
        system("/etc/init.d/squid-nat reload --script=" . basename(__FILE__));
    }
}
コード例 #22
0
ファイル: exec.snmpd.php プロジェクト: articatech/artica
function build()
{
    $unix = new unix();
    $sock = new sockets();
    $EnableSNMPD = $sock->GET_INFO("EnableSNMPD");
    $SNMPDNetwork = $sock->GET_INFO("SNMPDNetwork");
    if ($SNMPDNetwork == null) {
        $SNMPDNetwork = "default";
    }
    if (!is_numeric($EnableSNMPD)) {
        $EnableSNMPD = 0;
    }
    $SNMPDCommunity = $sock->GET_INFO("SNMPDCommunity");
    if ($SNMPDCommunity == null) {
        $SNMPDCommunity = "public";
    }
    $EnableProxyInSNMPD = intval($sock->GET_INFO("EnableProxyInSNMPD"));
    $WizardSavedSettings = unserialize(base64_decode($sock->GET_INFO("WizardSavedSettings")));
    $organization = $WizardSavedSettings["organization"];
    $mail = $WizardSavedSettings["mail"];
    $f[] = "agentAddress 161";
    $f[] = "view   systemonly  included   .1.3.6.1.2.1.1";
    $f[] = "view   systemonly  included   .1.3.6.1.2.1.25.1";
    $f[] = "rwcommunity {$SNMPDCommunity}  {$SNMPDNetwork}";
    $f[] = "rouser   authOnlyUser";
    $f[] = "#rwuser   authPrivUser   priv";
    $f[] = "sysLocation    {$organization}";
    $f[] = "sysContact     Manager <{$mail}>";
    $f[] = "sysServices    72";
    $f[] = "proc  mountd";
    $f[] = "proc  ntalkd";
    $apache = $unix->LOCATE_APACHE_BIN_PATH();
    if ($apache != null) {
        $f[] = "proc  {$apache}";
    }
    $ufdbguardd = $unix->find_program("ufdbguardd");
    if ($ufdbguardd != null) {
        $f[] = "proc  {$ufdbguardd}";
    }
    $f[] = "proc  " . $unix->LOCATE_PHP5_BIN();
    $mysqld = $unix->find_program("mysqld");
    if ($mysqld != null) {
        $f[] = "proc  {$mysqld}";
    }
    $lighttpd = $unix->find_program("lighttpd");
    if ($lighttpd != null) {
        $f[] = "proc  {$lighttpd}";
    }
    $clamd = $unix->find_program("clamd");
    if ($clamd != null) {
        $f[] = "proc  {$clamd}";
    }
    $f[] = "disk       /     10000";
    $f[] = "disk       /var  5%";
    $f[] = "includeAllDisks  10%";
    $f[] = "load   12 10 5";
    $f[] = "iquerySecName   internalUser       ";
    $f[] = "rouser          internalUser";
    $f[] = "defaultMonitors          yes";
    $unix = new unix();
    if ($EnableProxyInSNMPD == 1) {
        $squid = $unix->LOCATE_SQUID_BIN();
        if ($squid != null) {
            $f[] = "proc  {$squid}";
            $SquidSNMPPort = intval($sock->GET_INFO("SquidSNMPPort"));
            $SquidSNMPComunity = $sock->GET_INFO("SquidSNMPComunity");
            if ($SquidSNMPPort == 0) {
                $SquidSNMPPort = intval($squid->snmp_port);
            }
            if ($SquidSNMPPort == 0) {
                $SquidSNMPPort = 3401;
            }
            if ($SquidSNMPComunity == null) {
                $SquidSNMPComunity = $squid->snmp_community;
            }
            if ($SquidSNMPComunity == null) {
                $SquidSNMPComunity = "public";
            }
            if (is_file("/usr/share/squid3/mib.txt")) {
                $moib = " -m /usr/share/squid3/mib.txt";
            }
            $f[] = "proxy{$moib} -v 1 -c {$SquidSNMPComunity} 127.0.0.1:{$SquidSNMPPort} .1.3.6.1.4.1.3495.1";
        }
    }
    $f[] = "master          agentx";
    $f[] = "#agentXSocket    tcp:localhost:705";
    @mkdir("/etc/snmp", 0755, true);
    @file_put_contents("/etc/snmp/snmpd.conf", @implode("\n", $f));
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} /etc/snmp/snmpd.conf done\n";
    }
}
コード例 #23
0
ファイル: exec.squid.smp.php プロジェクト: BillTheBest/1.6.x
function caches_squid_z()
{
    $unix = new unix();
    $squidbin = $unix->LOCATE_SQUID_BIN();
    if (!is_file($squidbin)) {
        events_squid_caches("Starting......: " . date("H:i:s") . " [SMP] squid no such binary", __FUNCTION__, __LINE__);
        return;
    }
    $pidffile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pidTfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    $pid = $unix->get_pid_from_file($pidffile);
    if ($unix->process_exists($pid)) {
        events_squid_caches("Starting......: " . date("H:i:s") . " [SMP] Aready running pid {$pid}", __FUNCTION__, __LINE__);
        return;
    }
    @file_put_contents($pidffile, getmypid());
    if ($unix->file_time_min($pidTfile) < 5) {
        return;
    }
    @unlink($pidTfile);
    @file_put_contents($pidTfile, time());
    $stopstart = false;
    $GetLocalCaches = $unix->SQUID_CACHE_FROM_SQUIDCONF_FULL();
    $conffile = "/tmp/squid-" . time() . ".conf";
    $f[] = "cache_effective_user squid";
    $f[] = "pid_filename\t/var/run/squid-temp.pid";
    $f[] = "http_port 127.0.0.1:65478";
    while (list($cache_dir, $line) = each($GetLocalCaches)) {
        if (!is_dir($cache_dir)) {
            events_squid_caches("Starting......: " . date("H:i:s") . " [SMP] creating {$cache_dir}", __FUNCTION__, __LINE__);
            $stopstart = true;
            @mkdir($cache_dir, 0755, true);
        }
        @chown($cache_dir, "squid");
        @chgrp($cache_dir, "squid");
        $f[] = $line;
    }
    $su = $unix->find_program("su");
    echo "Starting......: " . date("H:i:s") . " [SMP] Writing config {$conffile}\n";
    @file_put_contents($conffile, @implode("\n", $f));
    $cmd = "{$su} -c \"{$squidbin} -f {$conffile} -z\" squid 2>&1";
    events_squid_caches("Starting......: " . date("H:i:s") . " [SMP] Launch {$cmd}", __FUNCTION__, __LINE__);
    exec("{$cmd}", $results);
    while (list($a, $b) = each($results)) {
        events_squid_caches("Starting......: " . date("H:i:s") . " [SMP] {$b}", __FUNCTION__, __LINE__);
    }
    if (!$GLOBALS["NORESTART"]) {
        echo "Starting......: " . date("H:i:s") . " [SMP] Writing restarting squid-cache\n";
        exec("/etc/init.d/squid restart --script=" . basename(__FILE__) . " 2>&1", $results);
        while (list($a, $b) = each($results)) {
            events_squid_caches("Starting......: " . date("H:i:s") . " [SMP] {$b}", __FUNCTION__, __LINE__);
        }
    }
}
コード例 #24
0
function restore()
{
    $sock = new sockets();
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    if ($GLOBALS["VERBOSE"]) {
        echo "PID: {$pidfile}\n";
    }
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid)) {
        $TTL = $unix->PROCESS_TTL($pid);
        if ($TTL < 240) {
            return;
        }
        $kill = $unix->find_program("kill");
        unix_system_kill_force($pid);
    }
    @file_put_contents($pidfile, getmypid());
    $hostname = $unix->hostname_g();
    progress(10, "{mounting}");
    if (!restore_TestNas()) {
        system_admin_events("Mounting NAS filesystem report false", __FUNCTION__, __FILE__, __LINE__);
        progress(100, "{failed}");
        return;
    }
    $BackupArticaRestoreNASIpaddr = $sock->GET_INFO("BackupArticaRestoreNASIpaddr");
    $BackupArticaRestoreNASFolder = $sock->GET_INFO("BackupArticaRestoreNASFolder");
    $BackupArticaRestoreNASUser = $sock->GET_INFO("BackupArticaRestoreNASUser");
    $BackupArticaRestoreNASPassword = $sock->GET_INFO("BackupArticaRestoreNASPassword");
    $BackupArticaRestoreNASFolderSource = $sock->GET_INFO("BackupArticaRestoreNASFolderSource");
    $BackupArticaRestoreNetwork = $sock->GET_INFO("BackupArticaRestoreNetwork");
    $mountPoint = "/mnt/BackupArticaRestoreNAS";
    $BackupArticaRestoreNASFolderSource = str_replace("\\", "/", $BackupArticaRestoreNASFolderSource);
    $sourceDir = "{$mountPoint}/{$BackupArticaRestoreNASFolderSource}";
    $sourceDir = str_replace("//", "/", $sourceDir);
    if (!is_file("{$sourceDir}/BKVERSION.txt")) {
        progress(100, "{failed} BKVERSION.txt no such file");
        $mount = new mount("/var/log/artica-postfix/backup.debug");
        if ($mount->ismounted($mountPoint)) {
            $mount->umount($mountPoint);
        }
        return;
    }
    $time = trim(@file_get_contents("{$sourceDir}/BKVERSION.txt"));
    progress(15, "{backup} " . date("Y-m-d H:i:s"));
    progress(20, "{restoring_ldap_database}, {please_wait}...");
    Restore_ldap($sourceDir);
    progress(40, "{restoring_artica_settings}, {please_wait}...");
    restore_artica_settings($sourceDir);
    progress(50, "{restoring_artica_databases}, {please_wait}...");
    restore_artica_backup($sourceDir);
    progress(60, "{restoring_artica_databases}, {please_wait}...");
    restore_ocsweb($sourceDir);
    progress(80, "{restoring_artica_databases}, {please_wait}...");
    restore_squidlogs($sourceDir);
    progress(82, "{restoring} PowerDNS, {please_wait}...");
    restore_powerdns($sourceDir);
    progress(90, "{reconfigure_server}, {please_wait}...");
    $squidbin = $unix->LOCATE_SQUID_BIN();
    $php = $unix->LOCATE_PHP5_BIN();
    if (is_file($squidbin)) {
        shell_exec("{$php} /usr/share/artica-postfix/exec.squid.php --build --force");
    }
    progress(100, "{success}");
    $mount = new mount("/var/log/artica-postfix/backup.debug");
    if ($mount->ismounted($mountPoint)) {
        $mount->umount($mountPoint);
    }
    if ($BackupArticaRestoreNetwork == 1) {
        $unix->THREAD_COMMAND_SET("{$php} /usr/share/artica-postfix/exec.virtuals-ip.php --build");
    }
    return;
}
コード例 #25
0
function freewebs()
{
    $unix = new unix();
    $squidbin = $unix->LOCATE_SQUID_BIN();
    if (!is_file($squidbin)) {
        return;
    }
    $q = new squid_freewebs();
    exec("{$squidbin} -k reconfigure 2>&1", $results);
    squid_admin_mysql(1, "Reconfigure proxy service ( FreeWebs acls builder)", @implode("\n", $results), __FILE__, __LINE__);
}
コード例 #26
0
function ReloadMacHelpers($output = false)
{
    $unix = new unix();
    @mkdir("/var/log/squid/reload", 0755, true);
    @chown("/var/log/squid/reload", "squid");
    @chgrp("/var/log/squid/reload", "squid");
    $unix = new unix();
    $pgrep = $unix->find_program("pgrep");
    $rm = $unix->find_program("rm");
    shell_exec("{$rm} /var/log/squid/reload/*.MACTOUID >/dev/null 2>&1");
    exec("{$pgrep} -l -f \"external_acl_usersMacs.php\" 2>&1", $results);
    while (list($index, $ligne) = each($results)) {
        if (preg_match("#pgrep#", $ligne)) {
            continue;
        }
        if (!preg_match("#^([0-9]+)\\s+#", $ligne, $re)) {
            continue;
        }
        if ($output) {
            echo "Reload PID {$re[1]}\n";
        }
        @touch("/var/log/squid/reload/{$re[1]}.MACTOUID");
        @chown("/var/log/squid/reload/{$re[1]}.MACTOUID", "squid");
        @chgrp("/var/log/squid/reload/{$re[1]}.MACTOUID", "squid");
    }
    $squidbin = $unix->LOCATE_SQUID_BIN();
    shell_exec("{$squidbin} -f /etc/squid3/squid.conf -k reconfigure >/dev/null 2>&1");
}
コード例 #27
0
function FreeMem($aspid = false, $SwapOffOn = array())
{
    $unix = new unix();
    if (!$aspid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = @file_get_contents($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            if ($GLOBALS["VERBOSE"]) {
                echo "Already executed pid {$pid}\n";
            }
            return;
        }
    }
    if (count($SwapOffOn) == 0) {
        $sock = new sockets();
        $SwapOffOn = unserialize(base64_decode($sock->GET_INFO("SwapOffOn")));
        if (!is_numeric($SwapOffOn["AutoMemWatchdog"])) {
            $SwapOffOn["AutoMemWatchdog"] = 1;
        }
        if (!is_numeric($SwapOffOn["AutoMemPerc"])) {
            $SwapOffOn["AutoMemPerc"] = 90;
        }
        if (!is_numeric($SwapOffOn["AutoMemInterval"])) {
            $SwapOffOn["AutoMemInterval"] = 180;
        }
    }
    $text[] = "Configuration was:";
    $text[] = "--------------------------------------";
    $text[] = "Free memory when Swap exceed {$SwapOffOn["AutoMemPerc"]}%";
    $text[] = "Watchdog scanning interval: each {$SwapOffOn["AutoMemInterval"]}mn";
    if (isset($SwapOffOn["CURRENT"])) {
        $text[] = $SwapOffOn["CURRENT"];
    }
    $text[] = $unix->ps_mem_report();
    $TOTAL_MEMORY_MB_FREE = $unix->TOTAL_MEMORY_MB_FREE();
    $text[] = "{$TOTAL_MEMORY_MB_FREE}MB before operation";
    $sync = $unix->find_program("sync");
    $sysctl = $unix->find_program("sysctl");
    $squid = $unix->LOCATE_SQUID_BIN();
    shell_exec($sync);
    shell_exec("{$sysctl} -w vm.drop_caches=3");
    shell_exec($sync);
    shell_exec("/etc/init.d/apache2 restart");
    if (is_file("/etc/init.d/ssh")) {
        shell_exec("/etc/init.d/ssh restart");
    }
    if ($unix->is_socket("/var/run/mysqld/mysqld.sock")) {
        $q = new mysql();
        $q->EXECUTE_SQL("RESET QUERY CACHE;");
    }
    if ($unix->is_socket("/var/run/mysqld/squid-db.sock")) {
        $q = new mysql_squid_builder();
        $q->EXECUTE_SQL("RESET QUERY CACHE;");
    }
    $TOTAL_MEMORY_MB_FREE2 = $unix->TOTAL_MEMORY_MB_FREE();
    $text[] = "{$TOTAL_MEMORY_MB_FREE2}MB After operation";
    $TOTAL_MEMORY_MB = $TOTAL_MEMORY_MB_FREE2 - $TOTAL_MEMORY_MB_FREE;
    $text[] = "{$TOTAL_MEMORY_MB}MB restored";
    $FINAL_TEXT = @implode("\n", $text);
    system_admin_events("Free memory operation has been executed - {$TOTAL_MEMORY_MB}MB restored\n{$FINAL_TEXT}", __FUNCTION__, __FILE__, __LINE__);
    if (is_file($squid)) {
        squid_admin_mysql(1, "Swap exceed rule: Free memory operation has been executed - {$TOTAL_MEMORY_MB}MB restored", $FINAL_TEXT, __FILE__, __LINE__);
    }
}
コード例 #28
0
ファイル: exec.abuse-ch.php プロジェクト: articatech/artica
function xstart()
{
    $curl = new ccurl();
    $unix = new unix();
    $Pidfile = "/etc/artica-postfix/pids/exec.abuse-ch.pid";
    $PidTime = "/etc/artica-postfix/pids/exec.abuse-ch.time";
    $pid = $unix->get_pid_from_file($Pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        if ($GLOBALS["VERBOSE"]) {
            echo "Aborting Task already running pid {$pid} " . __FUNCTION__ . "()\n";
        }
        return;
    }
    @file_put_contents($Pidfile, getmypid());
    if (!$GLOBALS["VERBOSE"]) {
        $time = $unix->file_time_min($PidTime);
        if ($time < 10) {
            echo "Only each 10mn\n";
            die;
        }
        @unlink($PidTime);
        @file_put_contents($PidTime, time());
    }
    $curl = new ccurl("http://articatech.net/WebfilterDBS/ransomwaretracker.txt");
    $tmpfile = $unix->TEMP_DIR();
    if (!$curl->GetFile("{$tmpfile}/ransomwaretracker.txt")) {
        squid_admin_mysql(0, "ransomwaretracker.txt unable to get index file", $curl->error, __FILE__, __LINE__);
        return;
    }
    $array = unserialize(@file_get_contents("{$tmpfile}/ransomwaretracker.txt"));
    $TIME = $array["TIME"];
    if (!isset($array["MD5"])) {
        squid_admin_mysql(0, "ransomwaretracker.txt corrupted file", $curl->error, __FILE__, __LINE__);
        return;
    }
    @unlink("{$tmpfile}/ransomwaretracker.txt");
    $CurrentMD5 = @file_get_contents("/etc/artica-postfix/settings/Daemons/ransomwaretrackerMD5");
    if ($CurrentMD5 == $array["MD5"]) {
        return;
    }
    $curl = new ccurl("http://articatech.net/WebfilterDBS/ransomwaretracker.gz");
    if (!$curl->GetFile("{$tmpfile}/ransomwaretracker.gz")) {
        squid_admin_mysql(0, "ransomwaretracker.gz unable to get pattern file", $curl->error, __FILE__, __LINE__);
        return;
    }
    if (!$unix->uncompress("{$tmpfile}/ransomwaretracker.gz", "{$tmpfile}/ransomwaretracker.db")) {
        squid_admin_mysql(0, "ransomwaretracker.gz unable to extract file", $curl->error, __FILE__, __LINE__);
        return;
    }
    $ARRAY = unserialize(@file_get_contents("{$tmpfile}/ransomwaretracker.db"));
    if (!isset($ARRAY["URIS"])) {
        squid_admin_mysql(0, "ransomwaretracker.db corrupted database", $curl->error, __FILE__, __LINE__);
        return;
    }
    if (is_file("/etc/squid3/ransomwaretracker.db")) {
        @unlink("/etc/squid3/ransomwaretracker.db");
    }
    @copy("{$tmpfile}/ransomwaretracker.db", "/etc/squid3/ransomwaretracker.db");
    if (!is_file("/etc/artica-postfix/settings/Daemons/RansomwareReloaded")) {
        squid_admin_mysql(1, "Reloading Proxy service for updating Ranswomware function", null, __FILE__, __LINE__);
        $squid = $unix->LOCATE_SQUID_BIN();
        shell_exec("{$squid} -f /etc/squid3/squid.conf -k reconfigure");
        @touch("/etc/artica-postfix/settings/Daemons/RansomwareReloaded");
    }
    squid_admin_mysql(2, "Success updating ranswomware database v{$TIME}", null, __FILE__, __LINE__);
}
コード例 #29
0
function support_step2()
{
    $files[] = "/var/log/squid/cache.log";
    $files[] = "/var/log/syslog";
    $files[] = "/var/log/messages";
    $files[] = "/var/log/auth.log";
    $files[] = "/var/log/squid/access.log";
    $files[] = "/var/log/squid/external-acl.log";
    $files[] = "/var/log/squid/logfile_daemon.debug";
    $files[] = "/var/log/php.log";
    $files[] = "/var/log/mail.log";
    $files[] = "/var/log/squid.watchdog.log";
    $files[] = "/var/log/squid/ufdbguardd.log";
    $files[] = "/var/log/samba/log.winbindd";
    $files[] = "/etc/samba/smb.conf";
    $files[] = "/var/log/samba/log.nmbd";
    $files[] = "/var/log/samba/log.smbd";
    $files[] = "/var/run/mysqld/mysqld.err";
    $files[] = "/etc/init.d/artica-ifup";
    $files[] = "/var/log/net-start.log";
    $files[] = "/var/log/artica-ufdb.log";
    $files[] = "/var/log/artica-meta.log";
    $files[] = "/var/log/webfiltering-update.log";
    $files[] = "{$GLOBALS["ARTICALOGDIR"]}/ufdbguard-tail.debug";
    $unix = new unix();
    $cp = $unix->find_program("cp");
    $dmesg = $unix->find_program("dmesg");
    @mkdir("/usr/share/artica-postfix/ressources/support", 0755, true);
    shell_exec("{$dmesg} >/usr/share/artica-postfix/ressources/support/dmesg.txt");
    progress("{get_all_logs}", 45);
    if (is_dir("/etc/squid3")) {
        @mkdir("/usr/share/artica-postfix/ressources/support/etc-squid3", 0755, true);
        $cmd = "/bin/cp -rf /etc/squid3/* /usr/share/artica-postfix/ressources/support/etc-squid3/";
        shell_exec("{$cmd}");
    }
    $squidbin = $unix->LOCATE_SQUID_BIN();
    progress("{get_all_logs}", 46);
    if (is_file("/tmp/squid.conf")) {
        if (is_file($squidbin)) {
            shell_exec("{$squidbin} -f /tmp/squid.conf -k parse >/etc-squid3/tmp.squid.conf.log 2>&1");
        }
        @copy("/tmp/squid.conf", "/usr/share/artica-postfix/ressources/support/etc-squid3/tmp.squid.conf");
    }
    progress("{get_all_logs}", 47);
    if (is_dir("/etc/postfix")) {
        @mkdir("/usr/share/artica-postfix/ressources/support/etc-postfix", 0755, true);
        $cmd = "/bin/cp -rf /etc/postfix/* /usr/share/artica-postfix/ressources/support/etc-postfix/";
        shell_exec("{$cmd}");
    }
    progress("{get_all_logs}", 48);
    while (list($a, $b) = each($files)) {
        if (is_file($b)) {
            progress("{get_all_logs}:" . basename($b), 48);
            $destfile = basename("{$b}.gz");
            $unix->compress($b, "/usr/share/artica-postfix/ressources/support/{$destfile}");
        }
    }
    progress("{get_all_logs} lshw", 49);
    $lshw = $unix->find_program("lshw");
    exec("{$lshw} -class network 2>&1", $results);
    progress("{get_all_logs} ifconfig", 50);
    $ifconfig = $unix->find_program("ifconfig");
    exec("{$ifconfig} -a 2>&1", $results);
    $results[] = "\n\t***************\n";
    progress("{get_all_logs} IP", 50);
    $ip = $unix->find_program("ip");
    exec("{$ip} link show 2>&1", $results);
    $results[] = "\n\t***************\n";
    progress("{get_all_logs} Route", 50);
    exec("{$ip} route 2>&1", $results);
    $results[] = "\n\t***************\n";
    $f = explode("\n", @file_get_contents("/etc/iproute2/rt_tables"));
    while (list($a, $line) = each($f)) {
        if (!preg_match("#^([0-9]+)\\s+(.+)#", $line, $re)) {
            continue;
        }
        $table_num = $re[1];
        $tablename = $re[2];
        if ($table_num == 0) {
            continue;
        }
        if ($table_num > 252) {
            continue;
        }
        $results[] = "\n\t***** Table route {$table_num} named {$tablename} *****\n";
        exec("{$ip} route show table {$table_num} 2>&1", $results);
        $results[] = "\n\t***************\n";
    }
    progress("{get_all_logs} uname", 51);
    $unix = new unix();
    $uname = $unix->find_program("uname");
    $results[] = "{$uname} -a:";
    exec("{$uname} -a 2>&1", $results);
    $results[] = "\n";
    $results[] = "/bin/bash --version:";
    exec("/bin/bash --version 2>&1", $results);
    $results[] = "\n";
    progress("{get_all_logs} gdb", 52);
    $gdb = $unix->find_program("gdb");
    if (is_file($gdb)) {
        $results[] = "{$gdb} --version:";
        exec("{$gdb} --version 2>&1", $results);
    } else {
        $results[] = "gdb no such binary....";
    }
    $results[] = "\n";
    $smbd = $unix->find_program("smbd");
    if (is_file($smbd)) {
        $results[] = "{$smbd} -V:";
        exec("{$smbd} -V 2>&1", $results);
    } else {
        $results[] = "smbd no such binary....";
    }
    $results[] = "\n";
    progress("{get_all_logs} {$squidbin}", 53);
    if (is_file($squidbin)) {
        $results[] = "{$squidbin} -v:";
        exec("{$squidbin} -v 2>&1", $results);
        squid_watchdog_events("Reconfiguring Proxy parameters...");
        exec("/etc/init.d/squid reload --script=" . basename(__FILE__) . " 2>&1", $results);
        squid_admin_mysql(2, "Framework executed to reconfigure squid-cache", @implode("\n", $results));
    } else {
        $results[] = "squid no such binary....";
    }
    $results[] = "\n";
    progress("{get_all_logs}", 54);
    if (is_file($squidbin)) {
        $results[] = "{$squidbin} -v:";
        exec("{$squidbin} -v 2>&1", $results);
        squid_watchdog_events("Reconfiguring Proxy parameters...");
        exec("/etc/init.d/squid reload --script=" . basename(__FILE__) . " 2>&1", $results);
        squid_admin_mysql(2, "Framework executed to reconfigure squid-cache", @implode("\n", $results));
        shell_exec("{$squidbin} -f /etc/squid3/squid.conf -k check -X >/usr/share/artica-postfix/ressources/support/squid-conf-check.txt");
        if (is_file("/tmp/squid.conf")) {
            shell_exec("{$squidbin} -f /tmp/squid.conf -k check -X >/usr/share/artica-postfix/ressources/support/squid-temp-check.txt");
        }
    } else {
        $results[] = "squid3 no such binary....";
    }
    progress("{get_all_logs} DF", 55);
    $results[] = "\n";
    $df = $unix->find_program("df");
    if (is_file($df)) {
        $results[] = "{$df} -h:";
        exec("{$df} -h 2>&1", $results);
    } else {
        $results[] = "{$df} no such binary....";
    }
    progress("{get_all_logs}", 56);
    @file_put_contents("/usr/share/artica-postfix/ressources/support/generated.versions.txt", @implode("\n", $results));
}
コード例 #30
0
function install($filename)
{
    $GLOBALS["PROGRESS_FILE"] = "/usr/share/artica-postfix/ressources/logs/artica.install.progress";
    $GLOBALS["LOG_FILE"] = "/usr/share/artica-postfix/ressources/logs/web/artica.install.progress.txt";
    $unix = new unix();
    $LINUX_CODE_NAME = $unix->LINUX_CODE_NAME();
    $LINUX_DISTRIBUTION = $unix->LINUX_DISTRIBUTION();
    $LINUX_VERS = $unix->LINUX_VERS();
    $LINUX_ARCHITECTURE = $unix->LINUX_ARCHITECTURE();
    $APACHEUSER = $unix->APACHE_SRC_ACCOUNT();
    $DebianVer = "debian{$LINUX_VERS[0]}";
    $TMP_DIR = $unix->TEMP_DIR();
    $ORGV = @file_get_contents("/usr/share/artica-postfix/VERSION");
    $PATCH_VER = null;
    $tarballs_file = "/usr/share/artica-postfix/ressources/conf/upload/{$filename}";
    echo "Package {$tarballs_file}\n";
    $size = filesize($tarballs_file);
    ArticaMeta_release($tarballs_file);
    if (preg_match('#([0-9\\.]+)_([0-9\\.]+)-([0-9]+).tgz$#i', $filename, $r)) {
        $CUR_BRANCH = @file_get_contents("/usr/share/artica-postfix/MAIN_RELEASE");
        $CUR_BRANCH = trim($CUR_BRANCH);
        echo "Patch....................: {$r[3]}\n";
        echo "From.....................: {$r[1]}\n";
        echo "To.......................: {$r[2]}\n";
        echo "Current Branch..........: {$CUR_BRANCH}\n";
        if ($CUR_BRANCH != $r[1]) {
            echo "{$CUR_BRANCH} != {$r[1]}\n";
            build_progress("{not_for_current_branch} {requested} {$r[1]}", 110);
            return;
        }
        $PATCH_VER = $r[2] . " :";
        $ASPATCH = true;
    }
    echo "Size....................: " . FormatBytes($size / 1024) . "\n";
    echo "Current version.........: {$ORGV}\n";
    build_progress("{analyze}...", 10);
    echo "Current system..........: {$LINUX_CODE_NAME} {$LINUX_DISTRIBUTION} {$LINUX_VERS[0]}/{$LINUX_VERS[1]} {$LINUX_ARCHITECTURE}\n";
    echo "Package.................: {$filename}\n";
    echo "Temp dir................: {$TMP_DIR}\n";
    echo "Apache User.............: {$APACHEUSER}\n";
    if (!is_file($tarballs_file)) {
        echo "{$tarballs_file} no such file...\n";
        build_progress("No such file...", 110);
        return;
    }
    echo "Uncompressing {$tarballs_file}...\n";
    build_progress("{extracting} {$filename}...", 20);
    $chown = $unix->find_program("chown");
    $chmod = $unix->find_program("chmod");
    $tar = $unix->find_program("tar");
    $rm = $unix->find_program("rm");
    $nohup = $unix->find_program("nohup");
    $php = $unix->LOCATE_PHP5_BIN();
    $squid = $unix->LOCATE_SQUID_BIN();
    build_progress("{extracting} {$filename}...", 50);
    system("{$tar} xpf {$tarballs_file} -C /usr/share/");
    echo "Removing {$tarballs_file}...\n";
    @unlink($tarballs_file);
    shell_exec("{$rm} -rf /usr/share/artica-postfix/ressources/conf/upload/*");
    build_progress("{apply_permissions}...", 55);
    echo "{$APACHEUSER} -> /usr/share/artica-postfix\n";
    shell_exec("{$chown} -R {$APACHEUSER} /usr/share/artica-postfix");
    echo "0755 -> /usr/share/artica-postfix\n";
    shell_exec("{$chmod} -R 0755 /usr/share/artica-postfix");
    $ORGD = @file_get_contents("/usr/share/artica-postfix/VERSION");
    echo "Old version.............: {$ORGV}\n";
    if ($ASPATCH) {
        $patched = " (patched)";
    }
    echo "Current version.........: {$ORGD}{$patched}\n";
    sleep(2);
    if ($ORGV == $ORGD) {
        build_progress("{operation_failed} Same version {$PATCH_VER}{$filename}...", 110);
        return;
    }
    build_progress("{restarting} Artica...", 60);
    $unix->THREAD_COMMAND_SET("{$php} /usr/share/artica-postfix/exec.web-community-filter.php --register");
    build_progress("{restarting} Artica...", 65);
    build_progress("{building_init_scripts}...", 70);
    system("{$php} /usr/share/artica-postfix/exec.initslapd.php");
    build_progress("{updating_network}...", 75);
    system("{$php} /usr/share/artica-postfix/exec.virtuals-ip.php");
    system("{$php} /usr/share/artica-postfix/exec.monit.php --build");
    echo "Starting......: " . date("H:i:s") . " Purge and clean....\n";
    build_progress("{restarting} Artica...", 80);
    if (is_file("/etc/init.d/nginx")) {
        shell_exec("{$nohup} /etc/init.d/nginx reload >/dev/null 2>&1 &");
    }
    build_progress("{restarting} Artica...", 81);
    shell_exec("{$nohup} /etc/init.d/auth-tail restart");
    build_progress("{restarting} Artica...", 82);
    shell_exec("{$nohup} /etc/init.d/artica-framework");
    build_progress("{restarting} Artica...", 83);
    shell_exec("{$nohup} /usr/share/artica-postfix/bin/process1 --force --verbose " . time() . "");
    build_progress("{restarting} Artica...", 84);
    shell_exec("{$nohup} /usr/share/artica-postfix/bin/artica-make --empty-cache >/dev/null 2>&1 &");
    build_progress("{restarting} Artica...", 85);
    shell_exec("{$nohup} /etc/init.d/monit restart >/dev/null 2>&1 &");
    build_progress("{restarting} Artica...", 86);
    shell_exec("{$nohup} /etc/init.d/artica-status restart --force >/dev/null 2>&1 &");
    build_progress("{restarting} Artica...", 87);
    shell_exec("{$nohup} {$php} /usr/share/artica-postfix/exec.squid.php --build-schedules >/dev/null 2>&1 &");
    build_progress("{restarting} Artica...", 88);
    shell_exec("{$nohup} {$php} /usr/share/artica-postfix/exec.schedules.php --defaults >/dev/null 2>&1 &");
    build_progress("{restarting} Artica...", 90);
    build_progress("{restarting} Artica...", 100);
    echo "Starting......: " . date("H:i:s") . " Done you can close the screen....\n";
}