function install()
{
    $unix = new unix();
    $DISTRICODE = $unix->LINUX_CODE_NAME();
    $arch = $unix->LINUX_ARCHITECTURE();
    $VERS = $unix->LINUX_VERS();
    $dpkg = $unix->find_program("dpkg");
    echo "DISTRICODE:{$DISTRICODE} \n";
    if (!python_verify_modules("MySQLdb")) {
        $unix->DEBIAN_INSTALL_PACKAGE("python-mysqldb");
    }
    if (!python_verify_modules("ldap")) {
        echo "Installing python-ldap\n";
        if ($DISTRICODE == "DEBIAN") {
            if ($arch == 64) {
                if ($VERS[0] == 6) {
                    if (is_file("/usr/share/artica-postfix/bin/install/postfix/python-6-ldap-amd64.deb")) {
                        shell_exec("{$dpkg} -i --force-all /usr/share/artica-postfix/bin/install/postfix/python-6-ldap-amd64.deb");
                    }
                }
                if ($VERS[0] == 7) {
                    if (is_file("/usr/share/artica-postfix/bin/install/postfix/python-7-ldap-amd64.deb")) {
                        shell_exec("{$dpkg} -i --force-all /usr/share/artica-postfix/bin/install/postfix/python-7-ldap-amd64.deb");
                    }
                }
            }
        }
    }
    if (!python_verify_modules("ldap")) {
        $unix->DEBIAN_INSTALL_PACKAGE("python-ldap");
    }
    if (!python_verify_modules("ldap")) {
        echo "Warning, ldap/python-ldap not installed...\n";
        return;
    }
    if (!python_verify_modules("MySQLdb")) {
        echo "Warning, MySQLdb/python-mysqldb not installed...\n";
        return;
    }
    echo "MySQLdb / python-mysqldb OK\n";
    echo "LDAP / python-ldap OK\n";
    $tmpdir = $unix->TEMP_DIR() . "/iredmail";
    $tar = $unix->find_program("tar");
    $rm = $unix->find_program("rm");
    if (!is_file("/usr/share/artica-postfix/bin/install/postfix/iredapd.tar.gz")) {
        return;
    }
    @mkdir($tmpdir, 0755, true);
    shell_exec("{$tar} xf /usr/share/artica-postfix/bin/install/postfix/iredapd.tar.gz -C /");
    if (!is_file("/opt/iRedAPD/iredapd.py")) {
        return;
    }
    @chmod("/opt/iRedAPD/iredapd.py", 0755);
}
Esempio n. 2
0
function installapt()
{
    @unlink($GLOBALS["LOGFILE"]);
    $unix = new unix();
    $mount = $unix->find_program("mount");
    $umount = $unix->find_program("umount");
    $tar = $unix->find_program("tar");
    $rm = $unix->find_program("rm");
    echo "Please wait...\n";
    build_progress("{update_debian_repository}", 5);
    $aptget = $unix->find_program("apt-get");
    build_progress("{updating_repository}", 15);
    echo "Please wait, running apt-get install\n";
    $cmd = "DEBIAN_FRONTEND=noninteractive {$aptget} --force-yes update";
    system($cmd);
    build_progress("{INSTALL_VMWARE_TOOLS}", 50);
    $unix->DEBIAN_INSTALL_PACKAGE("open-vm-tools");
    if (!is_file("/usr/bin/vmware-toolbox-cmd")) {
        build_progress("{INSTALL_VMWARE_TOOLS} {failed_to_install}", 110);
        return;
    }
    build_progress("{INSTALL_VMWARE_TOOLS} {success}", 90);
    build_progress("{removing_caches}", 95);
    $unix->REMOVE_INTERFACE_CACHE();
    build_progress("{success}", 100);
}
Esempio n. 3
0
function Checks()
{
    $GLOBALS["NORELOAD"] = true;
    $unix = new unix();
    if (!is_file("/usr/lib/x86_64-linux-gnu/autofs/lookup_ldap.so")) {
        build_progress_rs("{install} autofs-ldap", 15);
        $unix->DEBIAN_INSTALL_PACKAGE("autofs-ldap");
    }
    if (!is_file("/usr/lib/x86_64-linux-gnu/autofs/lookup_ldap.so")) {
        build_progress_rs("{install} autofs-ldap {failed}", 110);
        return;
    }
    if (!$unix->is_socket("/var/run/slapd/slapd.sock")) {
        build_progress_rs("{restarting_service} OpenLDAP", 15);
        system("/etc/init.d/slapd restart");
    } else {
        if ($GLOBALS["PROGRESS"]) {
            build_progress_rs("{restarting_service} OpenLDAP", 15);
            system("/etc/init.d/slapd restart");
        }
    }
    $curlftpfs = $unix->find_program("curlftpfs");
    $fusermount = $unix->find_program("fusermount");
    if (is_file($curlftpfs)) {
        if (!is_file("/sbin/mount.curl")) {
            build_progress_rs("/sbin/mount.curl", 15);
            $curlftpfsZ[] = "#! /bin/sh";
            $curlftpfsZ[] = "{$curlftpfs} \$1 \$2 -o \$5,disable_eprt";
            $curlftpfsZ[] = "";
            @file_put_contents("/sbin/mount.curl", @implode("\n", $curlftpfsZ));
            @chmod("/sbin/mount.curl", 0755);
        }
        if (!is_file("/sbin/umount.curl")) {
            build_progress_rs("/sbin/umount.curl", 15);
            $curlftpfsZ = array();
            $curlftpfsZ[] = "#! /bin/sh";
            $curlftpfsZ[] = "{$fusermount} -u \$1";
            $curlftpfsZ[] = "";
            @file_put_contents("/sbin/umount.curl", @implode("\n", $curlftpfsZ));
            @chmod("/sbin/umount.curl", 0755);
        }
    }
    $ldap = new clladp();
    $data = "<?xml version=\"1.0\" ?>\n         <autofs_ldap_sasl_conf\n                 usetls=\"no\"\n                 tlsrequired=\"no\"\n                 authrequired=\"yes\"\n                 authtype=\"PLAIN\"\n                 user=\"{$ldap->ldap_admin}\"\n                 secret=\"{$ldap->ldap_password}\"\n         />";
    @file_put_contents("/etc/autofs_ldap_auth.conf", $data);
    if (is_file("/etc/autofs_ldap_auth.conf")) {
        @chmod("/etc/autofs_ldap_auth.conf", 0600);
        @chown("/etc/autofs_ldap_auth.conf", "root");
        @chgrp("/etc/autofs_ldap_auth.conf", "root");
    }
    build_progress_rs("{checking_configuration}", 15);
    $auto = new autofs();
    build_progress_rs("{checking_configuration}", 20);
    autofs_default();
    build_progress_rs("{checking_configuration}", 25);
    Autocount();
    build_progress_rs("{checking_configuration}", 30);
    davfs();
}
Esempio n. 4
0
function install()
{
    $unix = new unix();
    $unix->DEBIAN_INSTALL_PACKAGE("console-setup");
    if (is_file("/bin/setupcon")) {
        echo "* * * * * SUCCESS * * * * *\n";
        return;
    }
    echo "* * * * * FAILED * * * * *\n";
}
Esempio n. 5
0
function install()
{
    if (extension_loaded('snmp')) {
        return;
    }
    $unix = new unix();
    $FileTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".time";
    if ($unix->file_time_min($FileTime) < 15) {
        return;
    }
    @unlink($FileTime);
    @file_put_contents($FileTime, time());
    $unix->DEBIAN_INSTALL_PACKAGE("php5-snmp");
    system("/etc/init.d/artica-webconsole restart");
    system("/etc/init.d/artica-status restart");
}
Esempio n. 6
0
function pgsql()
{
    if (extension_loaded('pgsql')) {
        return;
    }
    $unix = new unix();
    $FileTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".time";
    if ($unix->file_time_min($FileTime) < 15) {
        return;
    }
    @unlink($FileTime);
    @file_put_contents($FileTime, time());
    squid_admin_mysql(1, "Installing missing package php5-pgsql", null, __FILE__, __LINE__);
    $unix->DEBIAN_INSTALL_PACKAGE("php5-pgsql");
    system("/usr/share/artica-postfix/exec.php.ini.php");
    system("/etc/init.d/artica-webconsole restart");
    system("/etc/init.d/artica-status restart");
}
Esempio n. 7
0
function install()
{
    $unix = new unix();
    $timefile = "/etc/artica-postfix/pids/" . __FILE__ . ".time";
    if ($unix->file_time_min($timefile) < 240) {
        return;
    }
    @unlink($timefile);
    @file_put_contents($timefile, time());
    $bin = $unix->find_program("fail2ban-server");
    if (!is_file($bin)) {
        $unix->DEBIAN_INSTALL_PACKAGE("fail2ban");
    }
    $bin = $unix->find_program("fail2ban-server");
    $fail2ban = new fail2ban();
    if (is_file($bin)) {
        $fail2ban->buildinit();
        build();
    }
}
Esempio n. 8
0
function arp_scanner($net, $insert = false)
{
    if (!is_file("/usr/bin/arp-scan")) {
        if (!isset($GLOBALS["DEBIAN_INSTALL_PACKAGE_ARP_SCAN"])) {
            $unix = new unix();
            $unix->DEBIAN_INSTALL_PACKAGE("arp-scan");
            $GLOBALS["DEBIAN_INSTALL_PACKAGE_ARP_SCAN"] = true;
        }
        if (!is_file("/usr/bin/arp-scan")) {
            return array();
        }
    }
    exec("/usr/bin/arp-scan --quiet --retry=1 {$net} 2>&1", $results);
    $MAIN = array();
    while (list($num, $line) = each($results)) {
        $line = trim($line);
        if ($line == null) {
            continue;
        }
        if (!preg_match("#^([0-9]+).([0-9]+).([0-9]+).([0-9]+)\\s+(.+?)\\s+(.+)#", $line, $re)) {
            continue;
        }
        $ipaddr = "{$re[1]}.{$re[2]}.{$re[3]}.{$re[4]}";
        $mac = $re[5];
        $vendor = $re[6];
        echo "Found {$ipaddr} -> {$mac} ( {$vendor} )\n";
        $date = date("Y-m-d H:i:s");
        $GLOBALS[$mac]["IP"] = $ipaddr;
        $GLOBALS[$mac]["MACHINE_TYPE"] = $vendor;
        $MAIN[] = "('{$ipaddr}','{$mac}','{$vendor}','{$date}')";
    }
    if (!$insert) {
        return $MAIN;
    }
    if (count($MAIN) == 0) {
        return;
    }
    while (list($mac, $array) = each($MAIN)) {
        $cmp = new computers();
        $uid = $cmp->ComputerIDFromMAC($mac);
        $array["HOSTNAME"] = gethostbyname($array["IP"]);
        $ipaddr = $array["IP"];
        if (preg_match("#^[0-9\\.]+\$#", $array["HOSTNAME"])) {
            $array["HOSTNAME"] = null;
        }
        if ($uid != null) {
            if ($GLOBALS["VERBOSE"]) {
                echo "{$mac} = {$uid}\n";
            }
            $cmp = new computers($uid);
            $ldap_ipaddr = $cmp->ComputerIP;
            $ComputerRealName = $cmp->ComputerRealName;
            if ($GLOBALS["VERBOSE"]) {
                echo "{$mac} = {$uid}\nLDAP:{$ldap_ipaddr}<>NMAP:{$ipaddr}\nLDAP CMP:{$ComputerRealName}<>NMAP:{$array["HOSTNAME"]}";
            }
            if ($array["HOSTNAME"] != null) {
                $EXPECTED_UID = strtoupper($array["HOSTNAME"]) . "\$";
                if ($EXPECTED_UID != $uid) {
                    $RAISON[] = "UID: {$uid} is different from {$EXPECTED_UID}";
                    nmap_logs("EDIT UID: {$mac}:[{$array["HOSTNAME"]}] ({$ipaddr})", @implode("\n", $array) . "\n" . @implode("\n", $RAISON), $uid);
                    $cmp->update_uid($EXPECTED_UID);
                }
            }
            if ($ldap_ipaddr != $ipaddr) {
                writelogs("Change {$ldap_ipaddr} -> to {$ipaddr} for  {$cmp->uid}", __FUNCTION__, __FILE__, __LINE__);
                $RAISON[] = "LDAP IP ADDR: {$ldap_ipaddr} is different from {$ipaddr}";
                $RAISON[] = "DN: {$cmp->dn}";
                $RAISON[] = "UID: {$cmp->uid}";
                $RAISON[] = "MAC: {$cmp->ComputerMacAddress}";
                if (!$cmp->update_ipaddr($ipaddr)) {
                    $RAISON[] = "ERROR:{$cmp->ldap_last_error}";
                }
                nmap_logs("EDIT IP: {$mac}:[{$array["HOSTNAME"]}] ({$ipaddr})", @implode("\n", $array) . "\n" . @implode("\n", $RAISON), $uid);
            }
            continue;
        }
        if ($array["HOSTNAME"] != null) {
            $uid = "{$array["HOSTNAME"]}\$";
        } else {
            continue;
        }
        nmap_logs("ADD NEW: {$mac}:[{$array["HOSTNAME"]}] ({$ipaddr})", @implode("\n", $array) . "\n" . @implode("\n", $RAISON), "{$uid}");
        $cmp = new computers();
        $cmp->ComputerIP = $ipaddr;
        $cmp->ComputerMacAddress = $mac;
        $cmp->uid = "{$uid}";
        $cmp->ComputerRunning = 1;
        $cmp->ComputerMachineType = $array["MACHINE_TYPE"];
        $cmp->Add();
    }
}
Esempio n. 9
0
function php_snmp()
{
    $unix = new unix();
    php_snmp_progress("{checking_php_snmp}", 20);
    $unix->DEBIAN_INSTALL_PACKAGE("php5-snmp");
    $nohup = $unix->find_program("nohup");
    if (is_file("/usr/lib/php5/20090626/snmp.so")) {
        php_snmp_progress("{checking_php_snmp} {success}", 100);
        sleep(5);
        system("{$nohup} /etc/init.d/artica-webconsole restart >/dev/null 2>&1 &");
        system("{$nohup} /etc/init.d/artica-status restart >/dev/null 2>&1 &");
    }
    if (is_file("/usr/lib/php5/20100525/snmp.so")) {
        php_snmp_progress("{checking_php_snmp} {success}", 100);
        sleep(5);
        system("{$nohup} /etc/init.d/artica-webconsole restart >/dev/null 2>&1 &");
        system("{$nohup} /etc/init.d/artica-status restart >/dev/null 2>&1 &");
    }
    php_snmp_progress("{checking_php_snmp} {failed}", 110);
    //php5-snmp
}
Esempio n. 10
0
function install()
{
    $unix = new unix();
    $rm = $unix->find_program("rm");
    $cgrulesengd = $unix->find_program("cgrulesengd");
    echo "cgrulesengd = {$cgrulesengd}\n";
    if (is_file($cgrulesengd)) {
        build_progress_install("{success}", 100);
        return;
    }
    $GLOBALS["OUTPUT"] = true;
    build_progress_install("{installing} {please_wait}", 15);
    $unix = new unix();
    $cgrulesengd = null;
    $unix->DEBIAN_INSTALL_PACKAGE("cgroup-bin", true);
    if (is_file("/usr/sbin/cgrulesengd")) {
        $cgrulesengd = "/usr/sbin/cgrulesengd";
    }
    if ($cgrulesengd == null) {
        $cgrulesengd = $unix->find_program("cgrulesengd", true);
    }
    if (is_file($cgrulesengd)) {
        build_progress_install("{learning_artica}", 80);
        system("/usr/share/artica-postfix/bin/process1 --force --verbose --" . time());
        build_progress_install("{removing_caches}", 90);
        $unix->REMOVE_INTERFACE_CACHE();
        start();
        build_progress_install("{success}", 100);
        return;
    }
    build_progress_install("{failed_to_install}", 110);
}
Esempio n. 11
0
function start($aspid = false)
{
    $unix = new unix();
    $sock = new sockets();
    $users = new usersMenus();
    $Masterbin = "/usr/local/ArticaStats/bin/postgres";
    if (!is_file($Masterbin)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, arpd not installed\n";
        }
        return;
    }
    if (!$aspid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = $unix->get_pid_from_file($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $pid = PID_NUM();
    if ($unix->MEM_TOTAL_INSTALLEE() < 624288) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} not enough memory\n";
        }
        if ($unix->process_exists($pid)) {
            stop();
        }
        build_progress_restart("{starting} {failed} no memory", 110);
        return;
    }
    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";
        }
        build_progress_restart("{starting} {success}", 30);
        return true;
    }
    $php5 = $unix->LOCATE_PHP5_BIN();
    $sysctl = $unix->find_program("sysctl");
    $echo = $unix->find_program("echo");
    $nohup = $unix->find_program("nohup");
    $su = $unix->find_program("su");
    $rm = $unix->find_program("rm");
    $SquidPerformance = intval($sock->GET_INFO("SquidPerformance"));
    $EnableInfluxDB = intval($sock->GET_INFO("EnableInfluxDB"));
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} EnableInfluxDB: {$EnableInfluxDB}\n";
    }
    $InfluxUseRemote = intval($sock->GET_INFO("InfluxUseRemote"));
    if ($users->POSTFIX_INSTALLED) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Postfix installed: True\n";
        }
    }
    if ($InfluxUseRemote == 1) {
        $EnableInfluxDB = 0;
    }
    $FreeZePostGres = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/FreeZePostGres"));
    if ($FreeZePostGres == 1) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Freeze !!! Aborting...\n";
        }
        return;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Use Remote statistics.: {$InfluxUseRemote}\n";
    }
    if (!$users->POSTFIX_INSTALLED) {
        $EnableIntelCeleron = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/EnableIntelCeleron"));
        if ($EnableIntelCeleron == 1) {
            $EnableInfluxDB = 0;
        }
    }
    if (is_file("/etc/artica-postfix/STATS_APPLIANCE")) {
        $EnableInfluxDB = 1;
        $SquidPerformance = 0;
        $EnableIntelCeleron = 0;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Use Statistics DB.....: {$EnableInfluxDB}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Use Intel Celeron mode: {$EnableIntelCeleron}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Use Performance.......: {$SquidPerformance}\n";
    }
    if ($EnableInfluxDB == 0) {
        build_progress_restart("{starting} {failed} {disabled}", 110);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service disabled (see EnableInflux)\n";
        }
        return;
    }
    if (!function_exists("pg_connect")) {
        build_progress_restart("{starting} installing php5-pgsql", 35);
        $unix->DEBIAN_INSTALL_PACKAGE("php5-pgsql");
        system("/usr/share/artica-postfix/exec.php.ini.php");
        if (!function_exists("pg_connect")) {
            build_progress_restart("{starting} installing php5-pgsql {failed}", 110);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} pg_connect no such function\n";
            }
            return;
        }
        system("/etc/init.d/artica-webconsole restart");
    }
    build_progress_restart("{starting}", 40);
    if (!$unix->UnixUserExists("ArticaStats")) {
        $unix->CreateUnixUser("ArticaStats", "ArticaStats");
    }
    @mkdir("/var/run/ArticaStats", 0755, true);
    @mkdir("/home/ArticaStatsDB", 0700, true);
    @mkdir("/var/log/ArticaStatsDB", 0755, true);
    @chown("/home/ArticaStatsDB", "ArticaStats");
    @chgrp("/home/ArticaStatsDB", "ArticaStats");
    @chown("/var/run/ArticaStats", "ArticaStats");
    @chgrp("/var/run/ArticaStats", "ArticaStats");
    @chown("/var/log/ArticaStatsDB", "ArticaStats");
    @chgrp("/var/log/ArticaStatsDB", "ArticaStats");
    if (is_file("/var/log/ArticaStatsDB/ArticaStatsDB.log")) {
        @unlink("/var/log/ArticaStatsDB/ArticaStatsDB.log");
        @touch("/var/log/ArticaStatsDB/ArticaStatsDB.log");
    }
    @chown("/var/log/ArticaStatsDB/ArticaStatsDB.log", "ArticaStats");
    @chgrp("/var/log/ArticaStatsDB/ArticaStatsDB.log", "ArticaStats");
    if (is_file("/var/run/ArticaStats/.s.PGSQL.8086")) {
        @unlink("/var/run/ArticaStats/.s.PGSQL.8086");
    }
    $php = $unix->LOCATE_PHP5_BIN();
    if (!is_file("/etc/artica-postfix/locales.gen")) {
        squid_admin_mysql(1, "Generating languages for the PostGreSQL compatibility", null, __FILE__, __LINE__);
        build_progress_restart("{generating_langs}", 42);
        system("{$php} /usr/share/artica-postfix/exec.locale.gen.php");
    }
    if (!is_dir("/home/ArticaStatsDB/base/1")) {
        squid_admin_mysql(0, "Creating a new PostgreSQL database in ArticaStatsDB", null, __FILE__, __LINE__);
        build_progress_restart("{starting}", 45);
        $rm = $unix->find_program("rm");
        shell_exec("{$rm} -rf /home/ArticaStatsDB/*");
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} initialize database...\n";
        }
        system("{$su} -c \"/usr/local/ArticaStats/bin/initdb --username=ArticaStats /home/ArticaStatsDB --no-locale -E UTF8\" ArticaStats");
    }
    if (!is_dir("/home/ArticaStatsDB/base/1")) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} initialize database failed...\n";
        }
        $rm = $unix->find_program("rm");
        shell_exec("{$rm} -rf /home/ArticaStatsDB/*");
        return;
    }
    build_progress_restart("{starting}", 50);
    xbuild();
    fuser_port();
    build_progress_restart("{starting} {permissions}", 55);
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Apply permissions on /home/ArticaStatsDB\n";
    }
    $chown = $unix->find_program("chown");
    $chmod = $unix->find_program("chmod");
    shell_exec("{$chown} -R ArticaStats:ArticaStats /home/ArticaStatsDB");
    shell_exec("{$chmod} 0700 /home/ArticaStatsDB");
    if (is_file("/home/ArticaStatsDB/postmaster.pid")) {
        @unlink("/home/ArticaStatsDB/postmaster.pid");
    }
    $f[] = "su -l ArticaStats -c '";
    $f[] = "/usr/local/ArticaStats/bin/pg_ctl -o \"-k /tmp,/var/run/ArticaStats\"  -D /home/ArticaStatsDB -l /var/log/ArticaStatsDB/ArticaStatsDB.log start'";
    $cmd = @implode(" ", $f) . " >/dev/null 2>&1 &";
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service\n";
    }
    shell_exec($cmd);
    for ($i = 1; $i < 5; $i++) {
        build_progress_restart("{starting} {wait} {$i}/5", 70);
        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)) {
        build_progress_restart("{starting} {success}", 75);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Success PID {$pid}\n";
        }
        $pg = new postgres_sql();
        $pg->CREATE_TABLES();
        return true;
    } else {
        build_progress_restart("{starting} {failed}", 110);
        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";
        }
    }
}
Esempio n. 12
0
function varlog()
{
    $unix = new unix();
    $rsync = $unix->find_program("rsync");
    $rm = $unix->find_program("rm");
    if (!is_file($rsync)) {
        $unix->DEBIAN_INSTALL_PACKAGE("rsync");
    }
    //$GLOBALS["ArticaMaxLogsSize"]=$ArticaMaxLogsSize;
    //$GLOBALS["logs_cleaning"]=$sock->GET_NOTIFS("logs_cleaning");
    //$GLOBALS["MaxTempLogFilesDay"]=$sock->GET_INFO("MaxTempLogFilesDay");
    //if($GLOBALS["MaxTempLogFilesDay"]==null){$GLOBALS["MaxTempLogFilesDay"]=5;}
    if (!is_numeric($GLOBALS["ArticaMaxLogsSize"])) {
        init();
    }
    $sock = new sockets();
    $LogsRotateDefaultSizeRotation = $sock->GET_INFO("LogsRotateDefaultSizeRotation");
    if (!is_numeric($LogsRotateDefaultSizeRotation)) {
        $LogsRotateDefaultSizeRotation = 100;
    }
    $LogsDirectoryStorage = $sock->GET_INFO("LogsDirectoryStorage");
    if (trim($LogsDirectoryStorage) == null) {
        $LogsDirectoryStorage = "/home/logs-backup";
    }
    $echo = $unix->find_program("echo");
    $LogRotatePath = $sock->GET_INFO("LogRotatePath");
    if ($LogRotatePath == null) {
        $LogRotatePath = "/home/logrotate";
    }
    $SQUIDEnable = $sock->GET_INFO("SQUIDEnable");
    if (!is_numeric($SQUIDEnable)) {
        $SQUIDEnable = 1;
    }
    $REMOVE_PHP_SCRIPTS[] = "/usr/share/artica-postfix/miniadm.logon.php";
    $REMOVE_PHP_SCRIPTS[] = "/usr/share/artica-postfix/miniadm.index.php";
    $REMOVE_PHP_SCRIPTS[] = "/usr/share/artica-postfix/miniadm.logoff.php";
    while (list($index, $filepath) = each($REMOVE_PHP_SCRIPTS)) {
        if (is_file($filepath)) {
            @unlink($filepath);
        }
    }
    $RESTART_SQUID = false;
    $syslog[] = "/var/log/syslog";
    $syslog[] = "/var/log/messages";
    $syslog[] = "/var/log/daemon.log";
    $syslog[] = "/var/log/auth.log";
    $syslog[] = "/var/log/kern.log";
    $syslog[] = "/var/log/user.log";
    $other[] = "/var/log/php.log";
    $other[] = "/var/log/artica-postfix/framework.log";
    $other[] = "/usr/share/artica-postfix/ressources/logs/php.log";
    $other[] = "/var/log/artica-postfix/logrotate.debug";
    $other[] = "/var/log/ArticaProc.log";
    $other[] = "/var/log/clamav/clamav.log";
    $other[] = "/var/log/clamav/clamd.log";
    $other[] = "/var/log/clamav/freshclam.log";
    $other[] = "/var/log/lighttpd/access.log";
    $other[] = "/var/log/lighttpd/apache-access.log";
    $other[] = "/var/log/apt/history.log";
    $other[] = "/var/log/apt/term.log";
    $other[] = "/var/log/redis/redis-server.log";
    $other[] = "/var/log/clamav-unofficial-sigs.log";
    $other[] = "/var/log/influxdb/influxdb.startup";
    $other[] = "/var/log/influxdb/influxd.log";
    $other[] = "/var/log/influxdb/influxd.service.log";
    if (is_dir("/usr/share/artica-postfix/ressources/ressources")) {
        shell_exec("{$rm} -rf /usr/share/artica-postfix/ressources/ressources");
    }
    if (is_file("/var/log/artica-postfix/squid-logger-start.log")) {
        shell_exec("{$echo} \"\">/var/log/artica-postfix/squid-logger-start.log");
    }
    if (is_file("/var/log/artica-postfix/exec.syslog-engine.php.log")) {
        shell_exec("{$echo} \"\">/var/log/artica-postfix/exec.syslog-engine.php.log");
    }
    if (is_file("/var/log/squid/squidtail.log")) {
        $size = @filesize("/var/log/squid/squidtail.log") / 1024 / 1000;
        if ($size > $LogsRotateDefaultSizeRotation) {
            if (@copy("/var/log/squid/squidtail.log", "{$LogRotatePath}/squidtail.log." . time())) {
                shell_exec("{$echo} \"\">/var/log/squid/squidtail.log");
                $RESTART_SYSLOG = true;
                $RESTART_SQUID = true;
            }
        }
    }
    if (is_file("/var/log/squid/logfile_daemon.debug")) {
        $size = @filesize("/var/log/squid/logfile_daemon.debug") / 1024 / 1000;
        if ($size > $LogsRotateDefaultSizeRotation) {
            shell_exec("{$echo} \"\">/var/log/squid/logfile_daemon.debug");
            $RESTART_SYSLOG = true;
        }
    }
    if (is_file("/var/log/squid/ext_time_quota_acl.log")) {
        $size = @filesize("/var/log/squid/ext_time_quota_acl.log") / 1024 / 1000;
        if ($size > $LogsRotateDefaultSizeRotation) {
            shell_exec("{$echo} \"\">/var/log/squid/ext_time_quota_acl.log");
        }
    }
    $RESTART_SYSLOG = false;
    $checks = array();
    while (list($index, $filepath) = each($syslog)) {
        $size = @filesize($filepath) / 1024 / 1000;
        echo "{$filepath} {$size}MB <> {$LogsRotateDefaultSizeRotation}M\n";
        if ($size > $LogsRotateDefaultSizeRotation) {
            $nextfile = "{$LogsDirectoryStorage}/" . basename($filepath) . "-" . time();
            if (!@copy($filepath, $nextfile)) {
                @unlink($nextfile);
                continue;
            }
            $checks[] = $nextfile;
            shell_exec("{$echo} \"\" >{$filepath}");
            $RESTART_SYSLOG = true;
        }
    }
    if ($RESTART_SQUID) {
        $squidbin = $unix->LOCATE_SQUID_BIN();
        if (is_file($squidbin)) {
            if ($SQUIDEnable == 1) {
                $restart_squid_stamp = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __LINE__;
                if ($unix->file_time_min($restart_squid_stamp) > 240) {
                    system_admin_mysql(1, "Ask to rotate logs after cleaning log files", null, __FILE__, __LINE__);
                    shell_exec("{$squidbin} -f /etc/squid3/squid.conf -k reconfigure");
                    shell_exec("{$squidbin} -f /etc/squid3/squid.conf -k rotate");
                    @unlink($restart_squid_stamp);
                    @file_put_contents($restart_squid_stamp, time());
                }
            }
        }
    }
    if ($RESTART_SYSLOG) {
        squid_admin_mysql(1, "Restarting Syslog after a rotation", null, __FILE__, __LINE__);
        $unix->RESTART_SYSLOG();
    }
    while (list($index, $filepath) = each($other)) {
        $size = @filesize($filepath) / 1024 / 1000;
        echo "{$filepath} {$size}MB <> {$LogsRotateDefaultSizeRotation}M\n";
        if ($size > 50) {
            shell_exec("{$echo} \"\" >{$filepath}");
        }
    }
    $q = new mysql_storelogs();
    if ($handle = opendir($LogsDirectoryStorage)) {
        while (false !== ($fileZ = readdir($handle))) {
            if ($fileZ == ".") {
                continue;
            }
            if ($fileZ == "..") {
                continue;
            }
            $filename = "{$LogsDirectoryStorage}/{$fileZ}";
            $q->events("Injecting {$filename}", __FUNCTION__, __LINE__);
            $q->InjectFile($filename, null);
        }
    }
    if ($handle = opendir("/var/log")) {
        while (false !== ($fileZ = readdir($handle))) {
            if ($fileZ == ".") {
                continue;
            }
            if ($fileZ == "..") {
                continue;
            }
            $path = "/var/log/{$filename}";
            if (is_dir($path)) {
                continue;
            }
            if (!preg_match("#artica-status\\.log\\.[0-9]+\$#", $fileZ)) {
                continue;
            }
            if ($unix->file_time_min($path) > 1440) {
                @unlink($path);
            }
        }
    }
    if ($handle = opendir("/var/log/influxdb")) {
        while (false !== ($fileZ = readdir($handle))) {
            if ($fileZ == ".") {
                continue;
            }
            if ($fileZ == "..") {
                continue;
            }
            $path = "/var/log/influxdb/{$filename}";
            if (is_dir($path)) {
                continue;
            }
            if (preg_match("#\\.log\\.[0-9]+\$#", $fileZ)) {
                @unlink($path);
                continue;
            }
        }
    }
    if ($handle = opendir("/var/log/squid")) {
        while (false !== ($fileZ = readdir($handle))) {
            if ($fileZ == ".") {
                continue;
            }
            if ($fileZ == "..") {
                continue;
            }
            $path = "/var/log/squid/{$filename}";
            if (is_dir($path)) {
                continue;
            }
            if (preg_match("#ufdbguardd\\.log\\.[0-9]+\$#", $fileZ)) {
                @unlink($path);
                continue;
            }
        }
    }
    $BackupMaxDays = $sock->GET_INFO("BackupMaxDays");
    $BackupMaxDaysDir = $sock->GET_INFO("BackupMaxDaysDir");
    $BackupMaxDaysAccess = $sock->GET_INFO("BackupMaxDaysAccess");
    if (!is_numeric($BackupMaxDaysAccess)) {
        $BackupMaxDaysAccess = 365;
    }
    $LogRotatePath = $sock->GET_INFO("LogRotatePath");
    if (!is_numeric($BackupMaxDays)) {
        $BackupMaxDays = 30;
    }
    $BackupMaxHours = $BackupMaxDays * 24;
    $BackupMaxMins = $BackupMaxHours * 60;
    $BackupMaxDaysAccess = $BackupMaxDaysAccess * 24;
    $BackupMaxDaysAccess = $BackupMaxDaysAccess * 60;
    if ($BackupMaxDaysDir == null) {
        $BackupMaxDaysDir = "/home/logrotate_backup";
    }
    if ($LogRotatePath == null) {
        $LogRotatePath = "/home/logrotate";
    }
    if (is_dir($BackupMaxDaysDir)) {
        if ($handle = opendir($BackupMaxDaysDir)) {
            while (false !== ($fileZ = readdir($handle))) {
                if ($fileZ == ".") {
                    continue;
                }
                if ($fileZ == "..") {
                    continue;
                }
                $filename = "{$BackupMaxDaysDir}/{$fileZ}";
                $mins = $unix->file_time_min($filename);
                if (preg_match("#^access\\.#", $filename)) {
                    if ($mins >= $BackupMaxDaysAccess) {
                        $q->events("Removing {$filename} {$mins}>=BackupMaxDaysAccess:{$BackupMaxDaysAccess}", __FUNCTION__, __LINE__);
                        echo "Removing {$filename}\n";
                        @unlink($filename);
                    }
                    continue;
                }
                if ($GLOBALS["VERBOSE"]) {
                    echo "{$filename} = {$mins}Mn\n";
                }
                if ($mins >= $BackupMaxMins) {
                    $q->events("Removing {$filename} {$mins}>=BackupMaxMins:{$BackupMaxMins}", __FUNCTION__, __LINE__);
                    echo "Removing {$filename}\n";
                    @unlink($filename);
                }
                $q->events("Injecting {$filename}", __FUNCTION__, __LINE__);
                $q->InjectFile($filename);
            }
        }
    }
    if (is_dir($LogRotatePath)) {
        if ($handle = opendir($LogRotatePath)) {
            while (false !== ($fileZ = readdir($handle))) {
                if ($fileZ == ".") {
                    continue;
                }
                if ($fileZ == "..") {
                    continue;
                }
                $filename = "{$LogRotatePath}/{$fileZ}";
                $mins = $unix->file_time_min($filename);
                if ($GLOBALS["VERBOSE"]) {
                    echo "{$filename} = {$mins}Mn\n";
                }
                if ($mins >= $BackupMaxMins) {
                    $q->events("Removing {$filename} {$mins}>=BackupMaxMins:{$BackupMaxMins}", __FUNCTION__, __LINE__);
                    echo "Removing {$filename}\n";
                    @unlink($filename);
                }
                $q->events("Injecting {$filename}", __FUNCTION__, __LINE__);
                $q->InjectFile($filename);
            }
        }
    }
    $LogRotatePath = $LogRotatePath . "/work";
    if (is_dir($LogRotatePath)) {
        if ($handle = opendir($LogRotatePath)) {
            while (false !== ($fileZ = readdir($handle))) {
                if ($fileZ == ".") {
                    continue;
                }
                if ($fileZ == "..") {
                    continue;
                }
                $filename = "{$LogRotatePath}/{$fileZ}";
                $filemd5 = md5_file($filename);
                if (isset($ARRAYMD[$filemd5])) {
                    @unlink($filename);
                    continue;
                }
                $ARRAYMD[$filemd5] = $filename;
            }
        }
        if ($handle = opendir($LogRotatePath)) {
            while (false !== ($fileZ = readdir($handle))) {
                if ($fileZ == ".") {
                    continue;
                }
                if ($fileZ == "..") {
                    continue;
                }
                $filename = "{$LogRotatePath}/{$fileZ}";
                $mins = $unix->file_time_min($filename);
                if ($GLOBALS["VERBOSE"]) {
                    echo "{$filename} = {$mins}Mn\n";
                }
                if (preg_match("#^access\\.#", $filename)) {
                    if ($mins >= $BackupMaxDaysAccess) {
                        echo "Removing {$filename}\n";
                        $q->events("Removing {$filename} {$mins}>=BackupMaxDaysAccess:{$BackupMaxDaysAccess}", __FUNCTION__, __LINE__);
                        @unlink($filename);
                        continue;
                    }
                    $q->events("Injecting {$filename}", __FUNCTION__, __LINE__);
                    $q->InjectFile($filename);
                    continue;
                }
                if ($mins >= $BackupMaxMins) {
                    $q->events("Removing {$filename} {$mins}>=BackupMaxMins:{$BackupMaxMins}", __FUNCTION__, __LINE__);
                    echo "Removing {$filename}\n";
                    @unlink($filename);
                }
                $q->events("Injecting {$filename}", __FUNCTION__, __LINE__);
                $q->InjectFile($filename);
            }
        }
    }
}
Esempio n. 13
0
function start_prepare()
{
    if ($GLOBALS["CRASHED"]) {
        return;
    }
    buil_init_squid_cache_log();
    initd_squid();
    $reconfigure = false;
    $unix = new unix();
    $sock = new sockets();
    $NtpdateAD = $sock->GET_INFO("NtpdateAD");
    $php = $unix->LOCATE_PHP5_BIN();
    $nohup = $unix->find_program("nohup");
    if (!is_file("/etc/squid3/malwares.acl")) {
        @file_put_contents("/etc/squid3/malwares.acl", "\n");
    }
    if (!is_file("/etc/squid3/squid-block.acl")) {
        @file_put_contents("/etc/squid3/squid-block.acl", "\n");
    }
    $EXPLODED = explode("\n", @file_get_contents("/etc/squid3/squid.conf"));
    while (list($index, $val) = each($EXPLODED)) {
        if (preg_match("#INSERT YOUR OWN RULE#", $val)) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Preparing.....: " . date("H:i:s") . " squid must be reconfigured...\n";
            }
            $reconfigure = true;
        }
    }
    if ($reconfigure) {
        if ($GLOBALS["OUTPUT"]) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " Rebuild configuration\n";
            }
            system("{$php} /usr/share/artica-postfix/exec.squid.php --build --withoutloading");
        } else {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " Rebuild configuration\n";
            }
            exec("{$php} /usr/share/artica-postfix/exec.squid.php --build --withoutloading 2>&1", $GLOBALS["LOGS"]);
        }
    }
    if ($NtpdateAD == 1) {
        shell_exec("{$nohup} {$php} /usr/share/artica-postfix/exec.kerbauth.php --ntpdate >/dev/null 2>&1 &");
    }
    $unix->CreateUnixUser("squid", "squid");
    if (!is_file("/etc/squid3/squid.conf")) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Preparing.....: " . date("H:i:s") . " Warning /etc/squid3/squid.conf no such file\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Preparing.....: " . date("H:i:s") . " Ask to build it and die\n";
        }
        shell_exec("{$php} /usr/share/artica-postfix/exec.squid.php --build --force --withoutloading");
        die;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " initd-squid\n";
    }
    shell_exec("{$php} /usr/share/artica-postfix/exec.initd-squid.php >/dev/null 2>&1");
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " Watchdog config\n";
    }
    shell_exec("{$php} /usr/share/artica-postfix/exec.squid.php --watchdog-config >/dev/null 2>&1");
    exec("{$php} /usr/share/artica-postfix/exec.squid.transparent.php", $GLOBALS["LOGS"]);
    if (!is_file("/etc/init.d/tproxy start")) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " Building transparent method\n";
        }
        exec("{$php} /usr/share/artica-postfix/exec.squid.transparent.php", $GLOBALS["LOGS"]);
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " Starting transparent method\n";
        }
        exec("/etc/init.d/tproxy start", $GLOBALS["LOGS"]);
    }
    $directories_squid[] = "/var/squid";
    $directories_squid[] = "/var/squid/cache";
    $directories_squid[] = "/usr/share/squid3/icons";
    $directories_squid[] = "/var/log/squid";
    $directories_squid[] = "/etc/squid3";
    $directories_squid[] = "/var/lib/squidguard";
    $directories_squid[] = "/var/run/squid";
    $directories_squid[] = "/lib/squid3";
    $directories_chmod[] = "/var/logs";
    $directories_chmod[] = "/var/log";
    $directories_chmod[] = "/var";
    $directories_chmod_owned[] = "/home/squid";
    $filesOblig[] = "/etc/squid3/url_rewrite_program.deny.db";
    $filesOblig[] = "/var/run/squid/squid.pid";
    while (list($num, $directory) = each($directories_squid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Preparing.....: " . date("H:i:s") . " {$directory}\n";
        }
        if (!is_dir($directory)) {
            @mkdir($directory, 0755, true);
        }
        @chmod($directory, 0755);
        $unix->chmod_func(0755, "{$directory}/*");
        $unix->chown_func("squid", "squid", "{$directory}/*");
    }
    while (list($num, $directory) = each($directories_chmod)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Preparing.....: " . date("H:i:s") . " {$directory}\n";
        }
        if (!is_dir($directory)) {
            @mkdir($directory, 0755, true);
        }
        @chmod($directory, 0755);
    }
    while (list($num, $directory) = each($directories_chmod)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Preparing.....: " . date("H:i:s") . " {$directory}\n";
        }
        if (!is_dir($directory)) {
            @mkdir($directory, 0755, true);
        }
        $unix->chmod_func(0755, "{$directory}");
        $unix->chown_func("squid", "squid", "{$directory}");
    }
    while (list($num, $filepath) = each($filesOblig)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Preparing.....: " . date("H:i:s") . " {$filepath}\n";
        }
        if (!is_file($filepath)) {
            @touch("{$filepath}");
        }
        @chmod($filepath, 0755);
        @chown($filepath, "squid");
        @chgrp($filepath, "squid");
    }
    $articafiles[] = "exec.logfile_daemon.php";
    $articafiles[] = "external_acl_squid_ldap.php";
    $articafiles[] = "external_acl_dynamic.php";
    $articafiles[] = "external_acl_quota.php";
    $articafiles[] = "external_acl_basic_auth.php";
    $articafiles[] = "external_acl_squid.php";
    while (list($num, $filename) = each($articafiles)) {
        $filepath = "/usr/share/artica-postfix/{$filename}";
        if ($GLOBALS["OUTPUT"]) {
            echo "Preparing.....: " . date("H:i:s") . " {$filepath}\n";
        }
        @chmod($filepath, 0755);
        @chown($filepath, "squid");
        @chgrp($filepath, "squid");
    }
    $squid_locate_pinger = $unix->squid_locate_pinger();
    $setcap = $unix->find_program("setcap");
    if (is_file($squid_locate_pinger)) {
        @chmod($squid_locate_pinger, 0755);
        @chown($squid_locate_pinger, "squid");
        @chgrp($squid_locate_pinger, "squid");
        if (is_file("{$setcap}")) {
            shell_exec("{$setcap} cap_net_raw=pe {$squid_locate_pinger}");
        } else {
            if ($GLOBALS["OUTPUT"]) {
                echo "Preparing.....: " . date("H:i:s") . " WARNING! setcap, no such binary!!\n";
            }
            $unix->DEBIAN_INSTALL_PACKAGE("libcap2-bin");
        }
    }
}
Esempio n. 14
0
function start($nopid = false)
{
    $unix = new unix();
    $sock = new sockets();
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    if (!$nopid) {
        $pid = $unix->get_pid_from_file($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
    }
    $pid = redis_pid();
    if ($unix->process_exists($pid)) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Already running since {$time}Mn...\n";
        }
        return;
    }
    $Enablentopng = $sock->GET_INFO("Enablentopng");
    if (!is_numeric($Enablentopng)) {
        $Enablentopng = 0;
    }
    $SquidPerformance = intval($sock->GET_INFO("SquidPerformance"));
    if ($SquidPerformance > 2) {
        $Enablentopng = 0;
    }
    if ($Enablentopng == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Disabled ( see Enablentopng )...\n";
        }
        return;
    }
    $masterbin = $unix->find_program("redis-server");
    $masterbin = $unix->find_program("redis-server");
    if (!is_file($masterbin)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} installing redis-server\n";
        }
        $unix->DEBIAN_INSTALL_PACKAGE("redis-server");
        $masterbin = $unix->find_program("redis-server");
    }
    if (!is_file($masterbin)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Not installed...\n";
        }
        return;
    }
    CheckFilesAndSecurity();
    $version = redis_version();
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Starting service v{$version}\n";
    }
    $cmd = "{$masterbin} /etc/redis/redis.conf";
    shell_exec($cmd);
    $c = 1;
    for ($i = 0; $i < 10; $i++) {
        sleep(1);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Starting service waiting {$c}/10\n";
        }
        $pid = redis_pid();
        if ($unix->process_exists($pid)) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Success PID {$pid}\n";
            }
            break;
        }
        $c++;
    }
    $pid = redis_pid();
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Failed\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} {$cmd}\n";
        }
    }
}
Esempio n. 15
0
function install()
{
    $unix = new unix();
    build_progress("{installing_firewall_service}", 10);
    $src_package = "/usr/share/artica-postfix/bin/install/firehol-debian7-64.tar.gz";
    if (!is_file($src_package)) {
        build_progress("{source_package_not_found}", 110);
        return;
    }
    $tar = $unix->find_program("tar");
    $php = $unix->LOCATE_PHP5_BIN();
    build_progress("{uncompress}", 20);
    shell_exec("{$tar} xvf /usr/share/artica-postfix/bin/install/firehol-debian7-64.tar.gz -C /");
    build_progress("{installing_service}", 30);
    $ipset = $unix->find_program("ipset");
    if (!is_file($ipset)) {
        build_progress("{installing_service} - IPSET -", 35);
        $unix->DEBIAN_INSTALL_PACKAGE("ipset");
    }
    build_init(true);
    build_progress("{refresh_settings}", 60);
    system("/usr/share/artica-postfix/bin/process1 --force --verbose --" . time());
    build_progress("{restart_status_service}", 70);
    system("/etc/init.d/artica-status restart --force");
    build_progress("{done}", 100);
}
Esempio n. 16
0
function ebtables_rules()
{
    $unix = new unix();
    $sock = new sockets();
    $ebtables = $unix->find_program("ebtables");
    $aptget = $unix->find_program("apt-get");
    if ($GLOBALS["VERBOSE"]) {
        echo "EBTABLES: [" . __LINE__ . "] ebtables = {$ebtables}\n";
    }
    $NETWORK_ALL_INTERFACES = $unix->NETWORK_ALL_INTERFACES();
    $squid = new squidbee();
    $SSL_BUMP = $squid->SSL_BUMP;
    if ($GLOBALS["VERBOSE"]) {
        echo "EBTABLES: [" . __LINE__ . "] SSL_BUMP = {$SSL_BUMP}\n";
    }
    if (!is_file($ebtables)) {
        if ($GLOBALS["VERBOSE"]) {
            echo "EBTABLES: [" . __LINE__ . "] NO BINARY apt-get = \"{$aptget}\"\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " ebtables no such binary...\n";
        }
        $unix->DEBIAN_INSTALL_PACKAGE("ebtables");
    }
    $conntrack = $unix->find_program("conntrack");
    if (!is_file($conntrack)) {
        $unix->DEBIAN_INSTALL_PACKAGE("conntrack");
    }
    $ebtables = $unix->find_program("ebtables");
    if (!is_file($ebtables)) {
        return "# ebtables, no such binary";
    }
    $q = new mysql();
    $sql = "SELECT `Interface` FROM `nics` WHERE `Bridged`=1";
    if ($GLOBALS["VERBOSE"]) {
        echo "[" . __LINE__ . "] {$sql}\n";
    }
    $results = $q->QUERY_SQL($sql, "artica_backup");
    if (!$q->ok) {
        echo "{$q->mysql_error}\n";
    }
    $count = mysql_num_rows($results);
    if ($count == 0) {
        $sock->SET_INFO("HotSpotAsBridge", 0);
        return "# ebtables, no bridge defined...";
    }
    $sock->SET_INFO("HotSpotAsBridge", 1);
    $GLOBALS["EBTABLES"] = true;
    if ($GLOBALS["VERBOSE"]) {
        echo "[" . __LINE__ . "] EBTABLES = TRUE\n";
    }
    //iptables -t nat -A PREROUTING -i br0 -p tcp --dport 80 -j REDIRECT --to-port 3128
    $f[] = "# ebtables, {$count} Interfaces SSL_BUMP = {$SSL_BUMP}";
    $f[] = "{$ebtables} -t broute -A BROUTING -p IPv4 --ip-protocol 6 --ip-destination-port 80 -j redirect --redirect-target ACCEPT";
    if ($SSL_BUMP == 1) {
        $f[] = "{$ebtables} -t broute -A BROUTING -p IPv4 --ip-protocol 6 --ip-destination-port 443 -j redirect --redirect-target ACCEPT";
    }
    return @implode("\n", $f);
}
Esempio n. 17
0
function installapt()
{
    if (!is_file("/etc/artica-postfix/settings/Daemons/SQUIDEnable")) {
        @file_put_contents("/etc/artica-postfix/settings/Daemons/SQUIDEnable", 1);
    }
    $GLOBALS["OUTPUT"] = true;
    @unlink($GLOBALS["LOGFILE"]);
    $unix = new unix();
    $mount = $unix->find_program("mount");
    $umount = $unix->find_program("umount");
    $tar = $unix->find_program("tar");
    $rm = $unix->find_program("rm");
    $git_proxy = null;
    $gem_proxy = null;
    $curl_proxy = null;
    $squidbin = $unix->LOCATE_SQUID_BIN();
    $SQUIDEnable = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/SQUIDEnable"));
    if ($SQUIDEnable == 1) {
        $SquidMgrListenPort = trim(@file_get_contents("/etc/artica-postfix/settings/Daemons/SquidMgrListenPort"));
        echo "* * * Force git to use http.proxy http://127.0.0.1:{$SquidMgrListenPort} * * *\n";
        $gem_proxy = "--http-proxy 127.0.0.1:{$SquidMgrListenPort}";
        $curl_proxy = "--proxy http://127.0.0.1:{$SquidMgrListenPort}";
        $git_proxy = "--global http.proxy http://127.0.0.1:{$SquidMgrListenPort}";
    }
    $prc = 20;
    echo "Please wait...\n";
    //-------------------------------------------------------------------------------------------------
    $prc++;
    if (!is_file("/usr/lib/x86_64-linux-gnu/libyaml.so")) {
        build_progress("{install_package} libyaml", $prc);
        build_progress_reconfigure("{install_package} libyaml", 46);
        $unix->DEBIAN_INSTALL_PACKAGE("libyaml-dev");
        if (!is_file("/usr/lib/x86_64-linux-gnu/libyaml.so")) {
            build_progress("{install_package} libyaml {failed_to_install}", 110);
            return;
        } else {
            echo "libyaml..........: OK\n";
        }
    }
    //-------------------------------------------------------------------------------------------------
    //-------------------------------------------------------------------------------------------------
    $prc++;
    if (!is_file("/usr/lib/perl5/Crypt/SSLeay.pm")) {
        build_progress("{install_package} libcrypt-ssleay-perl", $prc);
        build_progress_reconfigure("{install_package} libcrypt-ssleay-perl", 46);
        $unix->DEBIAN_INSTALL_PACKAGE("libcrypt-ssleay-perl");
        if (!is_file("/usr/lib/perl5/Crypt/SSLeay.pm")) {
            build_progress("{install_package} libcrypt-ssleay-perl {failed_to_install}", 110);
            return;
        } else {
            echo "libcrypt-ssleay-perl OK\n";
        }
    }
    //-------------------------------------------------------------------------------------------------
    $prc++;
    if (!is_file("/usr/lib/x86_64-linux-gnu/libpng.so")) {
        build_progress("{install_package} libpng12-dev", $prc);
        build_progress_reconfigure("{install_package} libpng12-dev", 46);
        $unix->DEBIAN_INSTALL_PACKAGE("libpng12-dev");
        if (!is_file("/usr/lib/x86_64-linux-gnu/libpng.so")) {
            build_progress("{install_package} libpng12-dev {failed_to_install}", 110);
            return;
        } else {
            echo "libpng12-dev.....: OK\n";
        }
    }
    $prc++;
    if (!is_file("/usr/lib/x86_64-linux-gnu/libgd.so")) {
        build_progress("{install_package} libgd2-xpm-dev", $prc);
        build_progress_reconfigure("{install_package} libgd2-xpm-dev", 46);
        $unix->DEBIAN_INSTALL_PACKAGE("libgd2-xpm-dev");
        if (!is_file("/usr/lib/x86_64-linux-gnu/libgd.so")) {
            build_progress("{install_package} libgd2-xpm-dev {failed_to_install}", 110);
            return;
        } else {
            echo "libgd2-xpm-dev.: OK\n";
        }
    }
    $prc++;
    if (!is_file("/usr/lib/x86_64-linux-gnu/libjansson.so.4")) {
        build_progress("{install_package} libjansson4", $prc);
        build_progress_reconfigure("{install_package} libjansson4", 47);
        $unix->DEBIAN_INSTALL_PACKAGE("libjansson4");
        if (!is_file("/usr/lib/x86_64-linux-gnu/libjansson.so.4")) {
            build_progress("{install_package} libjansson {failed_to_install}", 110);
            return;
        } else {
            echo "libjansson4......: OK\n";
        }
    }
    $prc++;
    if (!is_file("/usr/lib/x86_64-linux-gnu/libnss3.so")) {
        build_progress("{install_package} libnss3", $prc);
        build_progress_reconfigure("{install_package} libnss3", 47);
        $unix->DEBIAN_INSTALL_PACKAGE("libnss3");
        if (!is_file("/usr/lib/x86_64-linux-gnu/libnss3.so")) {
            build_progress("{install_package} libnss3 {failed_to_install}", 110);
            return;
        } else {
            echo "libnss3..........: OK\n";
        }
    }
    $prc++;
    if (!is_file("/usr/share/pyshared/yaml/__init__.py")) {
        build_progress("{install_package} python-yaml", $prc);
        build_progress_reconfigure("{install_package} python-yaml", 47);
        $unix->DEBIAN_INSTALL_PACKAGE("python-yaml");
        if (!is_file("/usr/share/pyshared/yaml/__init__.py")) {
            build_progress("{install_package} python-yaml {failed_to_install}", 110);
            return;
        } else {
            echo "python-yaml......: OK\n";
        }
    }
    $prc++;
    if (!is_file("/usr/share/pyshared/MySQLdb/__init__.py")) {
        build_progress("{install_package} python-mysqldb", $prc);
        build_progress_reconfigure("{install_package} python-mysqldb", 47);
        $unix->DEBIAN_INSTALL_PACKAGE("python-mysqldb");
        if (!is_file("/usr/share/pyshared/MySQLdb/__init__.py")) {
            build_progress("{install_package} python-mysqldb {failed_to_install}", 110);
            return;
        } else {
            echo "python-mysqldb...: OK\n";
        }
    }
    $prc++;
    if (!is_file("/usr/share/pyshared/psycopg2/__init__.py")) {
        build_progress("{install_package} python-psycopg2", $prc);
        build_progress_reconfigure("{install_package} python-psycopg2", 47);
        $unix->DEBIAN_INSTALL_PACKAGE("python-psycopg2");
        if (!is_file("/usr/share/pyshared/psycopg2/__init__.py")) {
            build_progress("{install_package} python-psycopg2 {failed_to_install}", 110);
            return;
        } else {
            echo "python-psycopg2..: OK\n";
        }
    }
    $prc++;
    if (!is_file("/usr/sbin/oinkmaster")) {
        build_progress_reconfigure("{install_package} oinkmaster", 48);
        build_progress("{install_package} oinkmaster", $prc);
        $unix->DEBIAN_INSTALL_PACKAGE("oinkmaster");
        if (!is_file("/usr/sbin/oinkmaster")) {
            build_progress("{install_package} oinkmaster {failed_to_install}", 110);
            return;
        } else {
            echo "oinkmaster.......: OK\n";
        }
    }
    //-------------------------------------------------------------------------------------------------
    return true;
}
Esempio n. 18
0
function start($aspid = false)
{
    $unix = new unix();
    $sock = new sockets();
    $Masterbin = $unix->find_program("pdns_server");
    $PowerDNSLogLevel = $sock->GET_INFO("PowerDNSLogLevel");
    $PowerDNSDNSSEC = $sock->GET_INFO("PowerDNSDNSSEC");
    $PowerDNSLogsQueries = $sock->GET_INFO("PowerDNSLogsQueries");
    if (!is_numeric($PowerDNSLogLevel)) {
        $PowerDNSLogLevel = 0;
    }
    if (!is_numeric($PowerDNSDNSSEC)) {
        $PowerDNSDNSSEC = 0;
    }
    if (!is_numeric($PowerDNSLogsQueries)) {
        $PowerDNSLogsQueries = 0;
    }
    if (!is_file($Masterbin)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, not installed\n";
        }
        return;
    }
    if (!$aspid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = $unix->get_pid_from_file($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $pid = PID_NUM();
    $EnablePDNS = $sock->GET_INFO("EnablePDNS");
    if (!is_numeric($EnablePDNS)) {
        $EnablePDNS = 0;
    }
    if ($EnablePDNS == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service disabled (see EnablePDNS)\n";
        }
        stop(true);
        return;
    }
    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;
    }
    if (!is_file("/usr/lib/libboost_serialization.so.1.49.0")) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}: Please wait, installing libboost-serialization1.49.0\n";
        }
        $unix->DEBIAN_INSTALL_PACKAGE("libboost-serialization1.49.0");
    }
    $php5 = $unix->LOCATE_PHP5_BIN();
    $sysctl = $unix->find_program("sysctl");
    $echo = $unix->find_program("echo");
    $nohup = $unix->find_program("nohup");
    $dnsmasq_bin = $unix->find_program("dnsmasq");
    $kill = $unix->find_program("kill");
    if (is_file($dnsmasq_bin)) {
        $dnsmasq_pid = $unix->PIDOF($dnsmasq_bin);
        if ($unix->process_exists($dnsmasq_pid)) {
            unix_system_kill_force($dnsmasq_pid);
        }
    }
    @mkdir("/var/run/pdns", 0755, true);
    $t = explode("\n", @file_get_contents("/etc/powerdns/pdns.conf"));
    while (list($index, $ligne) = each($t)) {
        if (preg_match("#^recursor=(.+)\$#", $ligne, $re)) {
            $recursor = trim($re[1]);
            break;
        }
    }
    $PowerDNSPerfs = unserialize(base64_encode($sock->GET_INFO("PowerDNSPerfs")));
    if (!isset($PowerDNSPerfs["cache-ttl"])) {
        $PowerDNSPerfs["cache-ttl"] = 3600;
    }
    if (!isset($PowerDNSPerfs["negquery-cache-ttl"])) {
        $PowerDNSPerfs["negquery-cache-ttl"] = 7200;
    }
    if (!isset($PowerDNSPerfs["query-cache-ttl"])) {
        $PowerDNSPerfs["query-cache-ttl"] = 300;
    }
    if (!isset($PowerDNSPerfs["recursive-cache-ttl"])) {
        $PowerDNSPerfs["recursive-cache-ttl"] = 7200;
    }
    if (!is_numeric($PowerDNSPerfs["negquery-cache-ttl"])) {
        $PowerDNSPerfs["negquery-cache-ttl"] = 7200;
    }
    if (!is_numeric($PowerDNSPerfs["query-cache-ttl"])) {
        $PowerDNSPerfs["query-cache-ttl"] = 300;
    }
    if (!is_numeric($PowerDNSPerfs["recursive-cache-ttl"])) {
        $PowerDNSPerfs["recursive-cache-ttl"] = 7200;
    }
    if (!is_numeric($PowerDNSPerfs["cache-ttl"])) {
        $PowerDNSPerfs["cache-ttl"] = 3600;
    }
    $cmds[] = $Masterbin;
    $cmds[] = "--daemon --guardian=yes";
    $cmds[] = "--recursor={$recursor}";
    $cmds[] = "--config-dir=/etc/powerdns";
    $cmds[] = "--cache-ttl={$PowerDNSPerfs["cache-ttl"]}";
    $cmds[] = "--negquery-cache-ttl={$PowerDNSPerfs["negquery-cache-ttl"]}";
    $cmds[] = "--query-cache-ttl={$PowerDNSPerfs["query-cache-ttl"]}";
    $cmds[] = "--recursive-cache-ttl={$PowerDNSPerfs["recursive-cache-ttl"]}";
    if ($PowerDNSLogLevel > 8) {
        $cmds[] = "--log-dns-details --loglevel={$PowerDNSLogLevel}";
    } else {
        if ($PowerDNSLogsQueries == 1) {
            $cmds[] = "--log-dns-details";
        }
        if ($PowerDNSLogLevel > 0) {
            $cmds[] = "--loglevel={$PowerDNSLogLevel}";
        }
    }
    $cmd = @implode(" ", $cmds);
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service\n";
    }
    shell_exec($cmd);
    for ($i = 1; $i < 11; $i++) {
        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";
        }
        if ($PowerDNSDNSSEC == 1) {
            shell_exec("{$php5} /usr/share/artica-postfix/exec.pdns.php --dnssec");
        }
    } 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";
        }
    }
}
Esempio n. 19
0
function CheckFilesAndSecurity()
{
    if (isset($GLOBALS[__FUNCTION__ . "_EXECUTED"])) {
        return;
    }
    $GLOBALS[__FUNCTION__ . "_EXECUTED"] = true;
    $squid_user = SquidUser();
    $unix = new unix();
    $chown = $unix->find_program("chown");
    $chmod = $unix->find_program("chmod");
    $squid_user = SquidUser();
    $ln = $unix->find_program("ln");
    $rm = $unix->find_program("rm");
    if (!is_dir("/var/logs")) {
        @mkdir("/var/logs", 0755, true);
    }
    $squidlogdir = "/var/log/squid";
    if (is_link($squidlogdir)) {
        $squidlogdir = @readlink($squidlogdir);
    }
    $baselogdir = dirname($squidlogdir);
    @chmod($baselogdir, 0755);
    @mkdir("/var/lib/squid/session", 0755, true);
    @mkdir("/usr/local/share/artica", 0755, true);
    @mkdir("/var/squid/cache", 0755, true);
    @mkdir("/var/lib/ssl_db", 0755, true);
    @mkdir("/var/log/squid/nudity", 0755, true);
    if (!is_dir("/var/run/squid")) {
        @mkdir("/var/run/squid", 0755, true);
    }
    @mkdir("/var/log/squid/squid", 0755, true);
    if (!is_file("/var/logs/cache.log")) {
        @file_put_contents("/var/logs/cache.log", "\n");
    }
    if (!is_dir("/usr/share/squid-langpack/templates/lb-lu")) {
        shell_exec("{$ln} -sf /usr/share/squid-langpack/templates/en-us /usr/share/squid-langpack/templates/lb-lu");
    }
    if (!is_file("/etc/squid3/squid-block.acl")) {
        @touch("/etc/squid3/squid-block.acl", "");
    }
    if (!is_file("/etc/squid3/clients_ftp.acl")) {
        @touch("/etc/squid3/clients_ftp.acl", "");
    }
    if (!is_file("/etc/squid3/allowed-user-agents.acl")) {
        @touch("/etc/squid3/allowed-user-agents.acl", "");
    }
    $unix->chmod_func(0755, "/etc/artica-postfix/settings/Daemons");
    $unix->chmod_func(0755, "/etc/artica-postfix/settings/Daemons/*");
    //helpers
    @chmod("/usr/share/artica-postfix/ufdbgclient.php", 0755);
    @chown("/usr/share/artica-postfix/ufdbgclient.php", "squid");
    @chgrp("/usr/share/artica-postfix/ufdbgclient.php", "squid");
    $GLOBALS["LogFileDeamonLogDir"] = @file_get_contents("/etc/artica-postfix/settings/Daemons/LogFileDeamonLogDir");
    if ($GLOBALS["LogFileDeamonLogDir"] == null) {
        $GLOBALS["LogFileDeamonLogDir"] = "/home/artica/squid/realtime-events";
    }
    @mkdir($GLOBALS["LogFileDeamonLogDir"], 0755, true);
    @chmod($GLOBALS["LogFileDeamonLogDir"], 0755);
    @chown($GLOBALS["LogFileDeamonLogDir"], "squid");
    @chgrp($GLOBALS["LogFileDeamonLogDir"], "squid");
    $items[] = "/etc/squid3/SquidNudityScanParams";
    $items[] = "/var/squid/cache";
    $items[] = "/var/lib/squid/session";
    $items[] = "/etc/squid3/*";
    $items[] = "{$squidlogdir}";
    $items[] = "{$squidlogdir}/*";
    $items[] = "{$squidlogdir}/nudity";
    $items[] = "/var/logs";
    $items[] = "/var/lib/ssl_db";
    $items[] = "/var/logs/cache.log";
    $items[] = "/home/squid/cache";
    $items[] = "/home/squid";
    $items[] = "/var/run/squid/*";
    $items[] = "/usr/local/share/artica";
    while (list($none, $path) = each($items)) {
        echo "Starting......: " . date("H:i:s") . " [SYS]: permissions on \"{$path}\"\n";
        $unix->chown_func($squid_user, $squid_user, $path);
        $unix->chmod_func(0755, $path);
    }
    $squid_locate_pinger = $unix->squid_locate_pinger();
    $setcap = $unix->find_program("setcap");
    if (is_file($squid_locate_pinger)) {
        shell_exec("{$chmod} 0755 {$squid_locate_pinger}");
        @chown($squid_locate_pinger, "squid");
        @chgrp($squid_locate_pinger, "squid");
        if (is_file("{$setcap}")) {
            shell_exec("{$setcap} cap_net_raw=pe {$squid_locate_pinger}");
        } else {
            $unix->DEBIAN_INSTALL_PACKAGE("libcap2-bin");
        }
    }
    $unix->THREAD_COMMAND_SET("{$chown} -R squid:squid /var/lib/squid/session");
    $GetCachesInsquidConf = $unix->SQUID_CACHE_FROM_SQUIDCONF();
    while (list($CacheDirectory, $type) = each($GetCachesInsquidConf)) {
        if (trim($CacheDirectory) == null) {
            continue;
        }
        if (!is_dir($CacheDirectory)) {
            continue;
        }
        $unix->chown_func("squid", "squid", $CacheDirectory);
        $unix->THREAD_COMMAND_SET("{$chown} -R squid:squid {$CacheDirectory}");
        $unix->THREAD_COMMAND_SET("{$chmod} -R 0755 {$CacheDirectory}");
        @chmod($CacheDirectory, 0755);
    }
    if (is_dir("/usr/share/squid-langpack")) {
        $unix->chown_func($squid_user, $squid_user, "/usr/share/squid-langpack");
    }
    if (!is_file("{$squidlogdir}/squidGuard.log")) {
        @file_put_contents("/var/log/squid/squidGuard.log", "#");
    }
    $unix->Winbindd_privileged_SQUID();
    $tpls["ERR_CONFLICT_HOST"] = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\"> <html><head> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> <title>ERROR: The requested URL could not be retrieved</title> <style type=\"text/css\"><!--   %l  body :lang(fa) { direction: rtl; font-size: 100%; font-family: Tahoma, Roya, sans-serif; float: right; } :lang(he) { direction: rtl; }  --></style> </head><body id=%c> <div id=\"titles\"> <h1>ERROR</h1> <h2>The requested URL could not be retrieved</h2> </div> <hr>  <div id=\"content\"> <p>The following error was encountered while trying to retrieve the URL: <a href=\"%U\">%U</a></p>  <blockquote id=\"data\"> <pre>URI Host Conflict</pre> </blockquote>  <p>This means the domain name you are trying to access apparently no longer exists on the machine you are requesting it from.</p>  <p>Some possible problems are:</p> <ul> <li>The domain may have moved very recently. Trying again will resolve that.</li> <li>The website may require you to use a local country-based version. Using your ISP provided DNS server(s) should resolve that.</li> </ul>  <p>Your cache administrator is <a href=\"mailto:%w%W\">%w</a>.</p> <br> </div>  <hr> <div id=\"footer\"> <p>Generated %T by %h (%s)</p> <!-- %c --> </div> </body></html>";
    $tpls["MGR_INDEX"] = "\n";
    while (list($file, $lined) = each($tpls)) {
        if (!is_file("/usr/share/squid-langpack/en/{$file}")) {
            @file_put_contents("/usr/share/squid-langpack/en/{$file}", $lined);
        }
        if (!is_file("/usr/share/squid-langpack/templates/{$file}")) {
            @file_put_contents("/usr/share/squid-langpack/templates/{$file}", $lined);
        }
    }
    $ssl_crtd = locate_ssl_crtd();
    if (!is_file("/var/lib/ssl_db/index.txt")) {
        if (is_file($ssl_crtd)) {
            if (is_dir("/var/lib/ssl_db")) {
                shell_exec("{$rm} -rf /var/lib/ssl_db");
            }
            shell_exec("{$ssl_crtd} -c -s /var/lib/ssl_db");
            $unix->chown_func($squid_user, $squid_user, "/var/lib/ssl_db/*");
        } else {
            echo "Starting......: " . date("H:i:s") . " unable to stat ssl_crtd to fill `/var/lib/ssl_db`\n";
        }
    }
}
Esempio n. 20
0
function xrun()
{
    $unix = new unix();
    $siege = $unix->find_program("siege");
    $sock = new sockets();
    $ARRAY = unserialize(base64_decode($sock->GET_INFO("SquidSiegeConfig")));
    if (!is_numeric($ARRAY["GRAB_URLS"])) {
        $ARRAY["GRAB_URLS"] = 0;
    }
    if (!is_numeric($ARRAY["USE_LOCAL_PROXY"])) {
        $ARRAY["USE_LOCAL_PROXY"] = 1;
    }
    if (!is_numeric($ARRAY["SESSIONS"])) {
        $ARRAY["SESSIONS"] = 150;
    }
    if (!is_numeric($ARRAY["MAX_TIME"])) {
        $ARRAY["MAX_TIME"] = 30;
    }
    build_progress_disconnect("{starting}", 5);
    if (!is_file($siege)) {
        build_progress_disconnect("{please_wait} {installing} SIEGE", 50);
        $unix->DEBIAN_INSTALL_PACKAGE("siege");
        $siege = $unix->find_program("siege");
        if (!is_file($siege)) {
            build_progress_disconnect("{installing} SIEGE {failed}", 110);
        }
    }
    $f[] = "internet = true";
    if ($ARRAY["USE_LOCAL_PROXY"] == 1) {
        $squid = new squidbee();
        if ($squid->hasProxyTransparent == 1) {
            $port = $squid->second_listen_port;
        } else {
            $port = $squid->listen_port;
        }
        $addr = "127.0.0.1";
    } else {
        $addr = $ARRAY["REMOTE_PROXY"];
        $port = intval($ARRAY["REMOTE_PROXY_PORT"]);
    }
    if ($addr == null) {
        build_progress_disconnect("{failed} No proxy address", 110);
        return;
    }
    if ($port == 0) {
        build_progress_disconnect("{failed} No proxy port", 110);
        return;
    }
    if ($ARRAY["SESSIONS"] == 0) {
        build_progress_disconnect("{failed} {simulate} 0 sessions", 110);
        return;
    }
    $f[] = "proxy-host ={$addr}";
    $f[] = "proxy-port = {$port}";
    $f[] = "user-agent = Mozilla/5.0 (compatible; IE 11.0; Win32; Trident/7.0)";
    $f[] = "file = /etc/siege/urls.txt";
    $f[] = "concurrent = {$ARRAY["SESSIONS"]}";
    $f[] = "time = {$ARRAY["MAX_TIME"]}S";
    $f[] = "timeout = 5";
    $f[] = "logfile = /var/log/siege.log";
    if (trim($ARRAY["USERNAME"]) != null) {
        $f[] = "username = {$ARRAY["USERNAME"]}";
        $f[] = "password = {$ARRAY["PASSWORD"]}";
    }
    @file_put_contents("/root/.siegerc", @implode("\n", $f));
    $filetemp = $unix->FILE_TEMP();
    $nohup = $unix->find_program("nohup");
    $URLS_NUMBER = $unix->COUNT_LINES_OF_FILE("/etc/siege/urls.txt");
    if ($URLS_NUMBER < 20) {
        @unlink("/etc/siege/urls.txt");
        if ($ARRAY["GRAB_URLS"] == 1) {
            import_urls();
        } else {
            @copy("/usr/share/artica-postfix/bin/install/squid/urls.txt", "/etc/siege/urls.txt");
        }
        $URLS_NUMBER = $unix->COUNT_LINES_OF_FILE("/etc/siege/urls.txt");
    }
    $FINAL["urls"] = $URLS_NUMBER;
    $FINAL["START_TIME"] = time();
    $ss[] = "{$nohup} {$siege} --concurrent={$ARRAY["SESSIONS"]}";
    $ss[] = "--internet --file=/etc/siege/urls.txt --time={$ARRAY["MAX_TIME"]}S";
    $ss[] = "--benchmark --rc=/root/.siegerc >{$filetemp} 2>&1 &";
    $cmd = @implode(" ", $ss);
    echo "{$cmd}\n";
    build_progress_disconnect("{executing}", 50);
    system($cmd);
    sleep(2);
    $pid = $unix->PIDOF($siege);
    while ($unix->process_exists($pid)) {
        $array_mem = getSystemMemInfo();
        $MemFree = $array_mem["MemFree"];
        $array_load = sys_getloadavg();
        $internal_load = $array_load[0];
        echo "Memory Free: " . round($MemFree / 1024) . " MB\n";
        echo "Load: {$internal_load}\n";
        build_progress_disconnect("{please_wait} Load:{$internal_load}", 50);
        sleep(2);
        $pid = $unix->PIDOF($siege);
    }
    build_progress_disconnect("{please_wait} {analyze}...", 90);
    $array = explode("\n", @file_get_contents($filetemp));
    @unlink($filetemp);
    while (list($num, $val) = each($array)) {
        echo "{$val}\n";
        if (preg_match("#alert#", $val)) {
            continue;
        }
        if (preg_match("#ERROR#", $val)) {
            continue;
        }
        if (preg_match("#(.+?):\\s+(.+)#", $val, $re)) {
            $FINAL[trim($re[1])] = trim($re[2]);
        }
    }
    $FINAL["STOP_TIME"] = time();
    build_progress_disconnect("{done}...", 99);
    sleep(5);
    build_progress_disconnect("{done}...", 100);
    @file_put_contents("/usr/share/artica-postfix/ressources/logs/web/siege.report.txt", serialize($FINAL));
    @chmod("/usr/share/artica-postfix/ressources/logs/web/siege.report.txt", 0755);
}
Esempio n. 21
0
function scan_directories()
{
    $UPDATED = false;
    if ($GLOBALS["VERBOSE"]) {
        $GLOBALS["FORCE"] = true;
    }
    if ($GLOBALS["FORCE"]) {
        $UPDATED = true;
        ini_set('html_errors', 0);
        ini_set('display_errors', 1);
        ini_set('error_reporting', E_ALL);
    }
    $unix = new unix();
    $pidFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $TimeFile = "/etc/artica-postfix/pids/exec.philesight.php.scan_directories.time";
    $pid = $unix->get_pid_from_file($pidFile);
    if ($unix->process_exists($pid)) {
        return;
    }
    if (!$GLOBALS["FORCE"]) {
        $time = $unix->file_time_min($TimeFile);
        if ($time < 120) {
            return;
        }
        if (system_is_overloaded(__FILE__)) {
            return;
        }
    }
    @unlink($TimeFile);
    @file_put_contents($TimeFile, time());
    if (!is_file("/usr/bin/ruby1.8")) {
        build_progress("{please_wait}, /usr/bin/ruby1.8 no such binary [installing]...", 5);
        $unix->DEBIAN_INSTALL_PACKAGE("ruby1.8");
    }
    if (!is_file("/usr/bin/ruby1.8")) {
        build_progress("{failed}, /usr/bin/ruby1.8 no such binary...", 110);
        system_admin_events("/usr/bin/ruby1.8 no such binary, philesight cannot be used!", __FUNCTION__, __FILE__, __LINE__);
    }
    $sock = new sockets();
    $EnableArticaMetaClient = intval($sock->GET_INFO("EnableArticaMetaClient"));
    if ($EnableArticaMetaClient == 1) {
        meta_events("Meta Client Enabled", __FUNCTION__, __LINE__);
    }
    $q = new mysql();
    $results = $q->QUERY_SQL("SELECT * FROM philesight WHERE enabled=1", "artica_backup");
    @mkdir("/usr/share/artica-postfix/img/philesight", 0755, true);
    @mkdir("/home/artica/philesight", 0755, true);
    $NICE = $unix->EXEC_NICE();
    build_progress("{please_wait}, {scaning_directories}...", 10);
    $pr = 10;
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $directory = $ligne["directory"];
        $partition = $ligne["partition"];
        $md5 = md5($directory);
        $maxtime = $ligne["maxtime"];
        if ($maxtime == 0) {
            continue;
        }
        $lastscan = $ligne["lastscan"];
        if ($lastscan == 0) {
            $lastscan = 1000000;
        }
        $sql_time_min = sql_time_min($lastscan);
        $partition = $unix->DIRPART_OF($directory);
        $hd = $unix->DIRDISK_OF($directory);
        $ARRAY = $unix->DF_SATUS_K($directory);
        $USED = $ARRAY["POURC"];
        $FREEMB = round($ARRAY["AIVA"] / 1024);
        $ARRAY_META[$directory]["MD5"] = $md5;
        $ARRAY_META[$directory]["lastscan"] = $lastscan;
        $ARRAY_META[$directory]["HD"] = $hd;
        $ARRAY_META[$directory]["PARTITION"] = $partition;
        $ARRAY_META[$directory]["USED"] = $USED;
        $ARRAY_META[$directory]["FREEMB"] = $FREEMB;
        $directoryXXX = mysql_escape_string2($directory);
        $sql = "UPDATE `philesight` SET `hd`='{$hd}',\n\t\tpartition='{$partition}',\n\t\thd='{$hd}',\n\t\tUSED='{$USED}',\n\t\tFREEMB='{$FREEMB}'\n\t\tWHERE `directory`='{$directoryXXX}'";
        $q->QUERY_SQL($sql, 'artica_backup');
        if (is_file("/home/artica/philesight/{$md5}.db")) {
            if (!$GLOBALS["FORCE"]) {
                if ($sql_time_min < $maxtime) {
                    continue;
                }
            }
        }
        $pr++;
        if ($GLOBALS["FORCE"]) {
            echo "Partition............: {$partition}\n";
        }
        if ($GLOBALS["FORCE"]) {
            echo "Hard disk............: {$hd}\n";
        }
        if ($GLOBALS["FORCE"]) {
            echo "Used.................: {$USED}%\n";
        }
        if ($GLOBALS["FORCE"]) {
            echo "Free.................: {$FREEMB}MB\n";
        }
        build_progress("{please_wait}, {scaning_directory} {$directory}...", $pr);
        $UPDATED = true;
        $cmd = "{$NICE} /usr/share/artica-postfix/bin/philesight --db /home/artica/philesight/{$md5}.db --only-dirs --index \"{$directory}\" 2>&1";
        if ($GLOBALS["FORCE"]) {
            echo "{$cmd}\n";
        }
        system($cmd);
        if (!is_file("/home/artica/philesight/{$md5}.db")) {
            if ($GLOBALS["FORCE"]) {
                echo "/home/artica/philesight/{$md5}.db no such file.\n";
            }
        }
        build_progress("{please_wait}, Generating report on {$directory}...", $pr);
        $cmd = "{$NICE} /usr/share/artica-postfix/bin/philesight --db /home/artica/philesight/{$md5}.db --path \"{$directory}\" --draw /usr/share/artica-postfix/img/philesight/{$md5}.png";
        if ($GLOBALS["FORCE"]) {
            echo "{$cmd}\n";
        }
        system($cmd);
        $directory = mysql_escape_string2($directory);
        $sql = "UPDATE `philesight` SET `hd`='{$hd}',\n\t\tpartition='{$partition}',\n\t\tlastscan=" . time() . ",\n\t\thd='{$hd}',\n\t\tUSED='{$USED}',\n\t\tFREEMB='{$FREEMB}'\n\t\tWHERE `directory`='{$directory}'";
        $q->QUERY_SQL($sql, 'artica_backup');
        if (!$q->ok) {
            echo $q->mysql_error . "\n";
            build_progress("{failed}, MySQL error", 110);
            return;
        }
    }
    build_progress("{success}", 100);
    if ($EnableArticaMetaClient) {
        meta_events("UPDATED={$UPDATED}", __FUNCTION__, __LINE__);
    }
    if ($UPDATED) {
        $sock = new sockets();
        $EnableArticaMetaClient = intval($sock->GET_INFO("EnableArticaMetaClient"));
        if ($EnableArticaMetaClient == 1) {
            $cp = $unix->find_program("cp");
            $tar = $unix->find_program("tar");
            $rm = $unix->find_program("rm");
            @mkdir("/home/artica/metaclient/upload/philesight", true, 0755);
            @file_put_contents("/home/artica/metaclient/upload/philesight/dump.db", serialize($ARRAY_META));
            shell_exec("{$cp} -f /usr/share/artica-postfix/img/philesight/* /home/artica/metaclient/upload/philesight/");
            @chdir("/home/artica/metaclient/upload/philesight");
            system("cd /home/artica/metaclient/upload/philesight");
            if (is_file("/home/artica/metaclient/upload/philesight.tgz")) {
                @unlink("/home/artica/metaclient/upload/philesight.tgz");
            }
            shell_exec("{$tar} -cf /home/artica/metaclient/upload/philesight.tgz *");
            shell_exec("{$rm} -rf /home/artica/metaclient/upload/philesight/*");
        }
    }
    if ($GLOBALS["META_PING"]) {
        if (is_file("/home/artica/metaclient/upload/philesight.tgz")) {
            $php = $unix->LOCATE_PHP5_BIN();
            system("{$php} /usr/share/artica-postfix/exec.artica-meta-client.php --ping --force >/dev/null 2>&1 &");
        }
    }
}
Esempio n. 22
0
function start($aspid = false)
{
    $unix = new unix();
    $sock = new sockets();
    $Masterbin = $unix->find_program("dnsmasq");
    $ipClass = new IP();
    if (!is_file($Masterbin)) {
        $unix->DEBIAN_INSTALL_PACKAGE("dnmasq");
    }
    if (!is_file($Masterbin)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, dnsmasq not installed\n";
        }
        return;
    }
    if (!$aspid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = $unix->get_pid_from_file($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $pid = PID_NUM();
    if ($unix->process_exists($pid)) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Service already started {$pid} since {$timepid}Mn...\n";
        }
        return;
    }
    $sock = new sockets();
    $EnableLocalDNSMASQ = $sock->GET_INFO('EnableLocalDNSMASQ');
    $EnableDNSMASQ = intval($sock->GET_INFO("EnableDNSMASQ"));
    $EnableLocalDNSMASQ = $sock->GET_INFO("EnableLocalDNSMASQ");
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} EnableDNSMASQ={$EnableDNSMASQ}\n";
    }
    if ($EnableLocalDNSMASQ == 1) {
        $EnableDNSMASQ = 1;
    }
    $EnableDNSMASQ = $sock->dnsmasq_enabled();
    if ($EnableDNSMASQ == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} EnableLocalDNSMASQ ({$EnableLocalDNSMASQ})\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} EnableDNSMASQ ({$EnableDNSMASQ})\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service disabled (see EnableDNSMASQ)\n";
        }
        return;
    }
    $php5 = $unix->LOCATE_PHP5_BIN();
    $echo = $unix->find_program("echo");
    $nohup = $unix->find_program("nohup");
    if (!is_file("/etc/dnsmasq.cmdlines.array")) {
        build(true);
    }
    $G = unserialize(@file_get_contents("/etc/dnsmasq.cmdlines.array"));
    $cmdline = @implode(" ", $G);
    echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} " . count($G) . " token(s)\n";
    while (list($num, $val) = each($G)) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} token: {$val}\n";
    }
    if (!is_file("/etc/dnsmasq.conf.empty")) {
        @file_put_contents("/etc/dnsmasq.conf.empty", "\n");
    }
    fuser_port();
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service {" . __LINE__ . "}\n";
    }
    shell_exec($cmdline);
    for ($i = 1; $i < 5; $i++) {
        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)) {
        shell_exec("{$nohup} /etc/init.d/monit reconfigure >/dev/null 2>&1 &");
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Success PID {$pid}\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"]} {$cmdline}\n";
        }
    }
}
Esempio n. 23
0
function runProc($norestart = false)
{
    $unix = new unix();
    $sock = new sockets();
    $t = time();
    $timeFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".time";
    $timePID = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid";
    $EnableBandwithCalculation = $sock->GET_INFO("EnableBandwithCalculation");
    if (!is_numeric($EnableBandwithCalculation)) {
        $EnableBandwithCalculation = 1;
    }
    $GetInstances = GetInstances();
    if ($GetInstances > 0) {
        system_admin_events("{$GetInstances} instance(s) already running.. aborting...", __FUNCTION__, __FILE__, __LINE__, "testspeed");
        return;
    }
    if ($EnableBandwithCalculation == 0) {
        system_admin_events("Feature disabled trough the Interface (EnableBandwithCalculation) you have to disable the schedule too...", __FUNCTION__, __FILE__, __LINE__, "testspeed");
        return;
    }
    if (!$GLOBALS["FORCE"]) {
        $pid = $unix->get_pid_from_file($timePID);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $timexec = $unix->PROCCESS_TIME_MIN($pid);
            if ($timexec < 30) {
                system_admin_events("Already instance executed pid {$pid} since {$timexec}Mn", __FUNCTION__, __FILE__, __LINE__, "testspeed");
                return;
            } else {
                $kill = $unix->find_program("kill");
                unix_system_kill_force($pid);
                system_admin_events("Instance pid {$pid} since {$timexec}Mn was killed", __FUNCTION__, __FILE__, __LINE__, "testspeed");
            }
        }
        $ExecTimefile = $unix->file_time_min($timeFile);
        if ($ExecTimefile < 30) {
            system_admin_events("Must run minimal 30mn ({$ExecTimefile}Mn), aborting", __FUNCTION__, __FILE__, __LINE__, "testspeed");
            return;
        }
        @unlink($timeFile);
        @file_put_contents($timeFile, time());
        @file_put_contents($timePID, getmypid());
    }
    $python = $unix->find_program("python");
    if (!is_file($python)) {
        system_admin_events("python, no such binary", __FUNCTION__, __FILE__, __LINE__, "testspeed");
        return;
    }
    $speedDNum = 0;
    $speedYNum = 0;
    $IP = null;
    $ISP = null;
    if (!is_file("/usr/lib/pyshared/python2.7/lxml/etree.so")) {
        $unix->DEBIAN_INSTALL_PACKAGE("python-lxml");
    }
    @chdir("/usr/share/artica-postfix/bin");
    exec("{$python} /usr/share/artica-postfix/bin/tespeed.py -dt 1 -ut 1 2>&1", $results);
    @chdir("/root");
    while (list($index, $line) = each($results)) {
        if ($GLOBALS["VERBOSE"]) {
            echo "{$line}\n";
        }
        if (preg_match("#IP:\\s+(.+?);.*?ISP:\\s+(.+?)\$#", $line, $re)) {
            $IP = trim($re[1]);
            $ISP = trim($re[2]);
        }
        if (preg_match("#No module named lxml#", $line)) {
            system_admin_events("Error,{$line}", __FUNCTION__, __FILE__, __LINE__, "testspeed");
            if (!$norestart) {
                install_lxml();
            }
            return;
        }
        if (preg_match("#No module named argparse#", $line)) {
            system_admin_events("Error,{$line}", __FUNCTION__, __FILE__, __LINE__, "testspeed");
            if (!$norestart) {
                install_argparse();
            }
            return;
        }
        if (preg_match("#Download speed:\\s+([0-9\\.]+)\\s+Mbit#", $line, $re)) {
            $speedDNum = $re[1];
            $speedDNum = $speedDNum * 1024;
        }
        if (preg_match("#Upload speed:\\s+([0-9\\.]+)\\s+Mbit#", $line, $re)) {
            $speedUNum = $re[1];
            $speedYNum = $speedUNum * 1024;
        }
    }
    $took = $unix->distanceOfTimeInWords($t, time(), true);
    if ($GLOBALS["VERBOSE"]) {
        echo "ISP:{$ISP} , IP:{$IP} Download: {$speedDNum} Kbi/s upload {$speedYNum} Kbi/s\n";
    }
    if ($speedDNum == 0) {
        return;
    }
    if ($speedYNum == 0) {
        return;
    }
    system_admin_events("ISP:{$ISP} , IP:{$IP} Download: {$speedDNum} Kbi/s upload {$speedYNum} Kbi/s took {$took}", __FUNCTION__, __FILE__, __LINE__, "testspeed");
    $array["ISP"] = $ISP;
    $array["PUBLIC_IP"] = $IP;
    $array["DOWNLOAD"] = $speedDNum;
    $array["UPLOAD"] = $speedYNum;
    $array["DATE"] = time();
    @mkdir("/usr/share/artica-postfix/ressources/web/cache1", 0777, true);
    @file_put_contents("/usr/share/artica-postfix/ressources/web/cache1/bandwith.stats", serialize($array));
    if (strlen($speedDNum) > 2) {
        $q = new mysql();
        $q->BuildTables();
        $q->QUERY_SQL("INSERT INTO speedtests (zDate,ISP,download,upload) VALUES (NOW(),'{$ISP}','{$speedDNum}','{$speedYNum}')", "artica_events");
        if (!$q->ok) {
            system_admin_events("Fatal error, {$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "testspeed");
        }
    }
    $q->QUERY_SQL("DELETE FROM speedtests WHERE zDate<DATE_SUB(NOW(),INTERVAL 35 DAY)", "artica_events");
}
Esempio n. 24
0
function importcomputersFromList()
{
    $unix = new unix();
    if (!is_file("/usr/bin/arp-scan")) {
        $unix->DEBIAN_INSTALL_PACKAGE("arp-scan");
    }
    $sock = new sockets();
    $ipClass = new IP();
    $tbl = explode("\n", $sock->GET_INFO("ComputerListToImport"));
    $CountOfLines = count($tbl);
    build_progress("{$CountOfLines} {computers}", 10);
    echo "[" . __LINE__ . "] {$CountOfLines} lines\n";
    $i = 0;
    $z = 0;
    $max = $CountOfLines;
    $FAILED = 0;
    $SUCCESS = 0;
    while (list($num, $line) = each($tbl)) {
        $z++;
        $prc = $z / $CountOfLines * 100;
        $prc = round($prc);
        if ($prc < 10) {
            $prc = 10;
        }
        if ($prc > 90) {
            $prc = 90;
        }
        $proxy_alias = null;
        $computername = null;
        $IPADDR = null;
        $MAC = null;
        //pc001,192.168.1.5,d8:9e:3f:34:2d:8d,jhon_pc[br]
        $EXPLODED = explode(",", $line);
        $computername = $EXPLODED[0];
        $IPADDR = $EXPLODED[1];
        $MAC = $EXPLODED[2];
        $MAC = str_replace("-", ":", $MAC);
        $MAC = strtolower($MAC);
        if (isset($EXPLODED[3])) {
            $proxy_alias = trim(strtolower($EXPLODED[3]));
        }
        if ($proxy_alias != null) {
            proxy_alias_add($IPADDR, $MAC, $proxy_alias);
        }
        $computername = trim($computername);
        if ($MAC == null) {
            $MAC = arp_scan_IpToMac($IPADDR);
        }
        if ($computername == null) {
            echo "[" . __LINE__ . "] Computer Name is null, aborting\n";
            $FAILED++;
            continue;
        }
        if (!$ipClass->isValid($IPADDR)) {
            $IPADDR = null;
        }
        if (!$ipClass->IsvalidMAC($MAC)) {
            $MAC = null;
        }
        build_progress("{$computername} {$IPADDR}/{$MAC}/{$proxy_alias}", $prc);
        $cmp = new computers();
        if ($MAC != null) {
            $uid = $cmp->ComputerIDFromMAC($MAC);
        } else {
            $uid = "{$computername}\$";
        }
        if ($uid == null) {
            $uid = "{$computername}\$";
        }
        if ($IPADDR == null) {
            echo "Try to resolve {$computername}\n";
            $IPADDR = @gethostbyname($computername);
            if (!$ipClass->isValid($IPADDR)) {
                $IPADDR = null;
            }
        }
        $cmp = new computers($uid);
        if ($IPADDR != null) {
            $cmp->ComputerIP = $IPADDR;
        }
        if ($MAC != null) {
            $cmp->ComputerMacAddress = $MAC;
        }
        $cmp->ComputerRealName = $computername;
        if (!$cmp->Add()) {
            echo "{$computername}: {$cmp->ldap_error}\n";
            $FAILED++;
        } else {
            $SUCCESS++;
        }
        $i = $i + 1;
    }
    echo "Success: {$SUCCESS}\n";
    echo "Failed : {$FAILED}\n";
    build_progress("{$SUCCESS} {added_computers}", 95);
    sleep(10);
    build_progress("{done}", 100);
}
Esempio n. 25
0
function start($aspid = false, $restart = false)
{
    $unix = new unix();
    $sock = new sockets();
    $Masterbin = $unix->find_program("dnsmasq");
    $ipClass = new IP();
    if (!is_file($Masterbin)) {
        $unix->DEBIAN_INSTALL_PACKAGE("dnmasq");
    }
    if (!is_file($Masterbin)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, dnsmasq not installed\n";
        }
        return;
    }
    if (!$aspid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = $unix->get_pid_from_file($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    if ($restart) {
        stop(true);
    }
    $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 false;
    }
    $sock = new sockets();
    $EnableLocalDNSMASQ = $sock->GET_INFO('EnableLocalDNSMASQ');
    $EnableDNSMASQ = intval($sock->GET_INFO("EnableDNSMASQ"));
    $EnableLocalDNSMASQ = $sock->GET_INFO("EnableLocalDNSMASQ");
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} EnableDNSMASQ={$EnableDNSMASQ}\n";
    }
    if ($EnableLocalDNSMASQ == 1) {
        $EnableDNSMASQ = 1;
    }
    $EnableDNSMASQ = $sock->dnsmasq_enabled();
    if ($EnableDNSMASQ == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} EnableLocalDNSMASQ ({$EnableLocalDNSMASQ})\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} EnableDNSMASQ ({$EnableDNSMASQ})\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service disabled (see EnableDNSMASQ)\n";
        }
        return false;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Build.....\n";
    }
    build(true);
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Starting service\n";
    }
    if ($restart) {
        stop(true);
    }
    shell_exec("/etc/init.d/dnsmasq start");
    return true;
}
Esempio n. 26
0
function install_dialog()
{
    $TimeFile = "/etc/artica-postfix/install.dialog.time";
    $unix = new unix();
    if (!$GLOBALS["FORCE"]) {
        $TimeEx = $unix->file_time_min($TimeFile);
        if ($TimeEx < 15) {
            return;
        }
    }
    @unlink($TimeFile);
    @file_put_contents($TimeFile, time());
    $dialog = $unix->find_program("dialog");
    if (is_file($dialog)) {
        return;
    }
    $unix->DEBIAN_INSTALL_PACKAGE("dialog");
}