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");
        }
    }
}
Beispiel #2
0
function start($aspid = false)
{
    $unix = new unix();
    $sock = new sockets();
    if (!$aspid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = $unix->get_pid_from_file($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $spawn_fcgi = $unix->find_program("spawn-fcgi");
    if (!is_file($spawn_fcgi)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} not installed\n";
        }
        return;
    }
    $pid = DEFAULT_PID();
    if ($unix->process_exists($pid)) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} already started {$pid} since {$timepid}Mn...\n";
        }
        return;
    }
    $nohup = $unix->find_program("nohup");
    $php5 = $unix->LOCATE_PHP5_BIN();
    $phpcgi = $unix->LIGHTTPD_PHP5_CGI_BIN_PATH();
    $EnablePHPFPM = intval($sock->GET_INFO("EnablePHPFPM"));
    $EnablePHPFPMFrameWork = $sock->GET_INFO("EnablePHPFPMFrameWork");
    $EnableArticaApachePHPFPM = $sock->GET_INFO("EnableArticaApachePHPFPM");
    $EnablePHPFPMFreeWeb = $sock->GET_INFO("EnablePHPFPMFreeWeb");
    $EnableFreeWeb = $sock->GET_INFO("EnableFreeWeb");
    if (!is_numeric($EnablePHPFPMFrameWork)) {
        $EnablePHPFPMFrameWork = 0;
    }
    if (!is_numeric($EnableArticaApachePHPFPM)) {
        $EnableArticaApachePHPFPM = 0;
    }
    if (!is_numeric($EnablePHPFPMFreeWeb)) {
        $EnablePHPFPMFreeWeb = 0;
    }
    if (!is_numeric($EnableFreeWeb)) {
        $EnableFreeWeb = 0;
    }
    if ($EnableFreeWeb == 0) {
        $EnablePHPFPMFreeWeb = 1;
    }
    $enabled = 1;
    if ($EnablePHPFPM == 1) {
        if ($EnablePHPFPMFrameWork == 1) {
            if ($EnableArticaApachePHPFPM == 1) {
                if ($EnablePHPFPMFreeWeb == 1) {
                    $enabled = 0;
                }
            }
        }
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} EnablePHPFPM............: {$EnablePHPFPM}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} EnablePHPFPMFrameWork...: {$EnablePHPFPMFrameWork}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} EnableArticaApachePHPFPM: {$EnableArticaApachePHPFPM}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} EnablePHPFPMFreeWeb.....: {$EnablePHPFPMFreeWeb}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Enabled.................: {$enabled}\n";
    }
    if ($enabled == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} is disabled...\n";
        }
        stop();
    }
    if (!is_file($phpcgi)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} FATAL no php-cgi can be enabled !\n";
        }
        return false;
    }
    $unix->chmod_func(0777, "/var/run");
    if ($unix->is_socket("/var/run/php-fcgi.sock")) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} remove old socket /var/run/php-fcgi.sock\n";
        }
        @unlink("/var/run/php-fcgi.sock");
    }
    $params = LOAD_CMDLINES();
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} version {$params["VERSION"]}\n";
    }
    $PROCESSES = 3;
    $CHILDREN = 5;
    $MEMORY = $unix->MEM_TOTAL_INSTALLEE();
    if ($MEMORY < 624288) {
        $PROCESSES = 1;
        $CHILDREN = 2;
    }
    $pid = $unix->get_pid_from_file("/var/run/spawn-fcgi.pid");
    $f[] = $spawn_fcgi;
    $f[] = "-s /var/run/php-fcgi.sock";
    if (isset($params["C"])) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} {$PROCESSES} Processes\n";
        }
        $f[] = "-C {$PROCESSES}";
    }
    if (isset($params["F"])) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} {$CHILDREN} Children\n";
        }
        $f[] = "-F {$CHILDREN}";
    }
    $f[] = "-u www-data -g www-data";
    $f[] = "-f {$phpcgi}";
    $f[] = "-P /var/run/spawn-fcgi.pid";
    $cmd = @implode(" ", $f);
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} {$cmd}\n";
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "{$cmd}\n";
    }
    shell_exec($cmd);
    for ($i = 0; $i < 4; $i++) {
        $pid = DEFAULT_PID();
        if ($unix->process_exists($pid)) {
            break;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} waiting {$i}/4...\n";
        }
        sleep(1);
    }
    $pid = DEFAULT_PID();
    if ($unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Success service started pid:{$pid}...\n";
        }
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} failed...\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$cmd}\n";
        }
    }
}
Beispiel #3
0
function start_ldap($aspid = false)
{
    $sock = new sockets();
    $ldaps = array();
    $unix = new unix();
    $kill = $unix->find_program("kill");
    if (!$GLOBALS["FORCE"]) {
        $pid = $unix->get_pid_from_file('/etc/artica-postfix/pids/exec.backup.artica.php.restore.pid');
        if ($unix->process_exists($pid)) {
            $pidtime = $unix->PROCCESS_TIME_MIN($pid);
            if ($pidtime < 15) {
                echo "slapd: [INFO] Artica restore task already running pid {$pid} since {$pidtime}mn\n";
                restart_ldap_progress("{success}", 100);
                return;
            }
        }
    }
    $MYPID_FILE = "/etc/artica-postfix/pids/start_ldap.pid";
    if (!$aspid) {
        $pid = $unix->get_pid_from_file($MYPID_FILE);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $pidtime = $unix->PROCCESS_TIME_MIN($pid);
            $unix->ToSyslog("Artica task already running pid {$pid} since {$pidtime}mn", false, basename(__FILE__));
            echo "slapd: [INFO] Artica task already running pid {$pid} since {$pidtime}mn\n";
            if ($pidtime > 10) {
                echo "slapd: [INFO] Killing this Artica task...\n";
                unix_system_kill_force($pid);
            } else {
                die;
            }
        }
        $MYPID_FILE_TIME = $unix->file_time_min($MYPID_FILE);
        if (!$GLOBALS["FORCE"]) {
            if ($MYPID_FILE_TIME < 1) {
                echo "slapd: [INFO] Task must be executed only each 1mn (use --force to by pass)\n";
                die;
            }
        }
        @unlink($MYPID_FILE);
        @file_put_contents($MYPID_FILE, getmypid());
    }
    $slapd = $unix->find_program("slapd");
    $SLAPD_PID_FILE = $unix->SLAPD_PID_PATH();
    $pid = $unix->get_pid_from_file($SLAPD_PID_FILE);
    if ($unix->process_exists($pid)) {
        $pidtime = $unix->PROCCESS_TIME_MIN($pid);
        restart_ldap_progress("{success}", 100);
        echo "slapd: [INFO] slapd already running pid {$pid} since {$pidtime}mn\n";
        @file_put_contents($SLAPD_PID_FILE, $pid);
        return;
    }
    $pid = $unix->PIDOF_PATTERN($slapd);
    echo "slapd: [INFO] detecting presence of `{$slapd}`:{$pid}...\n";
    if ($unix->process_exists($pid)) {
        $pidtime = $unix->PROCCESS_TIME_MIN($pid);
        restart_ldap_progress("{success}", 100);
        echo "slapd: [INFO] slapd already running pid {$pid} since {$pidtime}mn\n";
        @file_put_contents($SLAPD_PID_FILE, $pid);
        return;
    }
    echo "slapd: [INFO] slapd loading required values...\n";
    if (!is_file($slapd)) {
        if (is_file('/usr/lib/openldap/slapd')) {
            $slapd = '/usr/lib/openldap/slapd';
        }
    }
    $OpenLDAPLogLevel = $sock->GET_INFO("OpenLDAPLogLevel");
    $OpenLDAPDisableSSL = $sock->GET_INFO("OpenLDAPDisableSSL");
    $EnableNonEncryptedLdapSession = $sock->GET_INFO("EnableNonEncryptedLdapSession");
    $EnableipV6 = $sock->GET_INFO("EnableipV6");
    if (!is_numeric($EnableipV6)) {
        $EnableipV6 = 0;
    }
    if (!is_numeric($EnableNonEncryptedLdapSession)) {
        $EnableNonEncryptedLdapSession = 1;
    }
    $phpldapadmin = null;
    if (!is_numeric($OpenLDAPDisableSSL)) {
        $OpenLDAPDisableSSL = 0;
    }
    $ZARAFA_INSTALLED = 0;
    if ($GLOBALS["VERBOSE"]) {
        echo "users=new usersMenus();\n";
    }
    $users = new usersMenus();
    if ($GLOBALS["VERBOSE"]) {
        echo "users=new usersMenus() done...;\n";
    }
    if (!is_dir("/var/lib/ldap")) {
        @mkdir("/var/lib/ldap", 0755, true);
    }
    if (!is_dir("/var/run/slapd")) {
        @mkdir("/var/run/slapd", 0755, true);
    }
    if (!is_numeric($OpenLDAPLogLevel)) {
        $OpenLDAPLogLevel = 0;
    }
    if ($OpenLDAPLogLevel != 0) {
        $OpenLDAPLogLevelCmdline = " -d {$OpenLDAPLogLevel}";
    }
    $ifconfig = $unix->find_program("ifconfig");
    echo "slapd: [INFO] start looback address...\n";
    shell_exec("{$ifconfig} lo 127.0.0.1 netmask 255.255.255.0 up >/dev/null 2>&1");
    $ldap[] = "ldapi://" . urlencode("/var/run/slapd/slapd.sock");
    $ldap[] = "ldap://127.0.0.1:389/";
    if (is_file("/etc/artica-postfix/settings/Daemons/LdapListenIPAddr")) {
        $LdapListenIPAddr = explode("\n", @file_get_contents("/etc/artica-postfix/settings/Daemons/LdapListenIPAddr"));
        while (list($num, $ipaddr) = each($LdapListenIPAddr)) {
            $ipaddr = trim($ipaddr);
            if ($ipaddr == null) {
                continue;
            }
            echo "slapd: [INFO] slapd listen `{$ipaddr}`\n";
            if (!$unix->IS_IPADDR_EXISTS($ipaddr)) {
                echo "slapd: [INFO] slapd `{$ipaddr}` does not exists\n";
                continue;
            }
            if ($EnableNonEncryptedLdapSession == 0) {
                $ldaps[] = "ldaps://{$ipaddr}/";
            }
            $ldap[] = "ldap://{$ipaddr}:389/";
        }
    }
    if (count($ldaps) > 0) {
        $SLAPD_SERVICESSSL = " " . @implode(" ", $ldaps);
    }
    $SLAPD_SERVICES = @implode(" ", $ldap) . $SLAPD_SERVICESSSL;
    if ($users->ZARAFA_INSTALLED) {
        $ZARAFA_INSTALLED = 1;
    }
    $DB_RECOVER_BIN = $unix->LOCATE_DB_RECOVER();
    $DB_ARCHIVE_BIN = $unix->LOCATE_DB_ARCHIVE();
    $LDAP_SCHEMA_PATH = $unix->LDAP_SCHEMA_PATH();
    $rm = $unix->find_program("rm");
    $SLAPD_CONF = $unix->SLAPD_CONF_PATH();
    $php5 = $unix->LOCATE_PHP5_BIN();
    $tar = $unix->find_program("tar");
    $pidofbin = $unix->find_program("pidof");
    $ulimit = $unix->find_program("ulimit");
    $nohup = $unix->find_program("nohup");
    $mebin = __FILE__;
    $suffix = @trim(@file_get_contents("/etc/artica-postfix/ldap_settings/suffix"));
    shell_exec("{$nohup} /usr/share/artica-postfix/exec.virtuals-ip.php --resolvconf >/dev/null 2>&1 &");
    echo "slapd: [INFO] slapd `{$slapd}`\n";
    echo "slapd: [INFO] db_recover `{$DB_RECOVER_BIN}`\n";
    echo "slapd: [INFO] db_archive `{$DB_ARCHIVE_BIN}`\n";
    echo "slapd: [INFO] config `{$SLAPD_CONF}`\n";
    echo "slapd: [INFO] pid `{$SLAPD_PID_FILE}`\n";
    echo "slapd: [INFO] services `{$SLAPD_SERVICES}`\n";
    echo "slapd: [INFO] pidof `{$pidofbin}`\n";
    if ($EnableipV6 == 0) {
        echo "slapd: [INFO] ipv4 only...\n";
        $v4 = " -4";
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "-> ARRAY;\n";
    }
    $shemas[] = "core.schema";
    $shemas[] = "cosine.schema";
    $shemas[] = "mod_vhost_ldap.schema";
    $shemas[] = "nis.schema";
    $shemas[] = "inetorgperson.schema";
    $shemas[] = "evolutionperson.schema";
    $shemas[] = "postfix.schema";
    $shemas[] = "dhcp.schema";
    $shemas[] = "samba.schema";
    $shemas[] = "ISPEnv.schema";
    $shemas[] = "mozilla-thunderbird.schema";
    $shemas[] = "officeperson.schema";
    $shemas[] = "pureftpd.schema";
    $shemas[] = "joomla.schema";
    $shemas[] = "autofs.schema";
    $shemas[] = "dnsdomain2.schema";
    $shemas[] = "zarafa.schema";
    restart_ldap_progress("{starting_service}", 50);
    while (list($num, $file) = each($shemas)) {
        if (is_file("/usr/share/artica-postfix/bin/install/{$file}")) {
            if (is_file("{$LDAP_SCHEMA_PATH}/{$file}")) {
                @unlink("{$LDAP_SCHEMA_PATH}/{$file}");
            }
            @copy("/usr/share/artica-postfix/bin/install/{$file}", "{$LDAP_SCHEMA_PATH}/{$file}");
            echo "slapd: [INFO] installing `{$file}` schema\n";
            $unix->chmod_func(0777, "{$LDAP_SCHEMA_PATH}/{$file}");
        }
    }
    if (file_exists($ulimit)) {
        shell_exec("{$ulimit} -HSd unlimited");
    }
    restart_ldap_progress("{starting_service}", 60);
    if (is_dir("/usr/share/phpldapadmin/config")) {
        $phpldapadmin = "{$php5} " . dirname(__FILE__) . "/exec.phpldapadmin.php --build >/dev/null 2>&1";
        echo "slapd: [INFO] please wait, configuring PHPLdapAdminservice... \n";
        shell_exec($phpldapadmin);
    }
    echo "slapd: [INFO] please wait, configuring the daemon...\n";
    if ($unix->MEM_TOTAL_INSTALLEE() < 624288) {
        $sock = new sockets();
        $sock->SET_INFO("SlapdThreads", 2);
    }
    restart_ldap_progress("{starting_service}", 70);
    @chmod("/usr/share/artica-postfix/bin/artica-install", 0755);
    shell_exec("/usr/share/artica-postfix/bin/artica-install --slapdconf");
    echo "slapd: [INFO] please wait, building the start script...\n";
    buildscript();
    $unix->ToSyslog("Launching the OpenLDAP daemon ", false, basename(__FILE__));
    echo "slapd: [INFO] please wait, Launching the daemon...\n";
    if (!$unix->NETWORK_INTERFACE_OK("lo")) {
        $ifconfig = $unix->find_program("ifconfig");
        shell_exec("{$ifconfig} lo 127.0.0.1 netmask 255.255.255.0 up >/dev/null 2>&1");
    }
    restart_ldap_progress("{starting_service}", 80);
    $cdmline = "{$nohup} {$slapd}{$v4} -h \"{$SLAPD_SERVICES}\" -f {$SLAPD_CONF} -u root -g root -l local4{$OpenLDAPLogLevelCmdline} >/dev/null 2>&1 &";
    shell_exec($cdmline);
    sleep(1);
    for ($i = 0; $i < 5; $i++) {
        $pid = $unix->get_pid_from_file($SLAPD_PID_FILE);
        if ($unix->process_exists($pid)) {
            $pidtime = $unix->PROCCESS_TIME_MIN($pid);
            echo "slapd: [INFO] slapd success Running pid {$pid}\n";
            restart_ldap_progress("{success}", 100);
            if ($users->ZARAFA_INSTALLED) {
                start_zarafa();
            }
            return;
        }
        $pid = $unix->PIDOF($slapd);
        if ($unix->process_exists($pid)) {
            $pidtime = $unix->PROCCESS_TIME_MIN($pid);
            echo "slapd: [INFO] slapd success Running pid {$pid}\n";
            if ($users->ZARAFA_INSTALLED) {
                start_zarafa();
            }
            restart_ldap_progress("{success}", 100);
            return;
        }
        echo "slapd: [INFO] please wait, waiting service to start...\n";
        sleep(1);
    }
    restart_ldap_progress("{failed}", 110);
    echo "slapd: [ERR ] Failed to start the service with `{$cdmline}`\n";
}
Beispiel #4
0
function monit()
{
    $monit = new monit_unix();
    $monit->WAKEUP();
    $unix = new unix();
    $unix->chmod_func(0755, "/etc/artica-postfix/settings/Daemons/*");
}
Beispiel #5
0
function CheckPermissions()
{
    $unix = new unix();
    $unix->SystemCreateUser("mail", "mail");
    $unix->SystemCreateUser("postfix", "mail");
    $unix->SystemCreateUser("cyrus", "cyrus");
    $POSTFIX_QUEUE_DIRECTORY = $unix->POSTCONF_GET("queue_directory");
    $dirs[] = "/var/lib/cyrus";
    $dirs[] = "/var/lib/cyrus/db";
    $dirs[] = "/var/lib/cyrus/socket";
    $dirs[] = "/var/lib/cyrus/proc";
    $dirs[] = "/var/run/cyrus/socket";
    $dirs[] = "/var/spool/postfix/var/run/cyrus/socket";
    $ln = $unix->find_program("ln");
    $dirs[] = "{$POSTFIX_QUEUE_DIRECTORY}/var/run/cyrus";
    while (list($num, $directory) = each($dirs)) {
        if (!is_dir($directory)) {
            @mkdir($directory, 0755, true);
        }
        $unix->chmod_func(0755, "{$directory}");
        $unix->chown_func("cyrus", "mail", "{$directory}");
    }
    $unix->chown_func("cyrus", "cyrus", "/var/lib/cyrus");
    if (!is_file("/var/lib/cyrus/user_deny.db")) {
        @touch("/var/lib/cyrus/user_deny.db");
        $unix->chown_func("cyrus", "mail", "/var/lib/cyrus/user_deny.db");
    }
}
Beispiel #6
0
function copytocache()
{
    $unix = new unix();
    $path = $_GET["copytocache"];
    if (!is_file($path)) {
        echo "<articadatascgi>No such file</articadatascgi>";
        writelogs("{$path} -> No such file");
        return;
    }
    $basename = basename($path);
    writelogs("COPY {$path} -> /usr/share/artica-postfix/ressources/logs/{$basename}");
    if (is_file("/usr/share/artica-postfix/ressources/logs/{$basename}")) {
        @unlink("/usr/share/artica-postfix/ressources/logs/{$basename}");
    }
    if (!copy($path, "/usr/share/artica-postfix/ressources/logs/{$basename}")) {
        echo "<articadatascgi>Copy failed</articadatascgi>";
        return;
    }
    $APACHE = $unix->APACHE_SRC_ACCOUNT();
    $APACHE_GROUP = $unix->APACHE_SRC_GROUP();
    $unix->chown_func($APACHE, $APACHE_GROUP, "/usr/share/artica-postfix/ressources/logs/{$basename}");
    $unix->chmod_func(0755, "/usr/share/artica-postfix/ressources/logs/{$basename}");
}
Beispiel #7
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";
        }
    }
}
function BuildDHCP($nopid = false)
{
    $LOGBIN = "DHCP Server";
    $timefile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    $unix = new unix();
    if (!$nopid) {
        if (!$GLOBALS["FORCE"]) {
            if ($unix->file_time_min($timefile) < 2) {
                if ($GLOBALS["VERBOSE"]) {
                    echo "{$timefile} -> is less than 2mn\n";
                }
                return;
            }
        }
    }
    build_progress("{starting_service}", 65);
    $dhcpd = new dhcpd();
    $conf = $dhcpd->BuildConf();
    $confpath = dhcp3Config();
    $unix = new unix();
    @mkdir(dirname($confpath), null, true);
    @file_put_contents($confpath, $conf);
    echo "Starting......: " . date("H:i:s") . " [INIT]: {$LOGBIN} saving \"{$confpath}\" (" . strlen($conf) . " bytes) done\n";
    if (!$unix->UnixUserExists("dhcpd")) {
        $unix->CreateUnixUser("dhcpd", "dhcpd");
    }
    if (!is_dir("/var/lib/dhcp3")) {
        @mkdir("/var/lib/dhcp3", 0755, true);
    }
    $unix->chown_func("dhcpd", "dhcpd", "/var/lib/dhcp3/*");
    $unix->chmod_func(0755, "/var/lib/dhcp3");
    $complain = $unix->find_program("aa-complain");
    if (is_file($complain)) {
        $dhcpd3 = $unix->DHCPD_BIN_PATH();
        if (is_file($dhcpd3)) {
            shell_exec("{$complain} {$dhcpd3} >/dev/null 2>&1");
        }
    }
    @unlink($timefile);
    @file_put_contents($timefile, time());
    if ($GLOBALS["PROGRESS"]) {
        build_progress("{starting_service}", 70);
        $sock = new sockets();
        $sock->getFrameWork("dnsmasq.php?restart=yes");
        $sock->getFrameWork("services.php?restart-monit=yes");
        $sock->getFrameWork("cmd.php?restart-artica-status=yes");
    }
}
Beispiel #9
0
function apache_config()
{
    $sock = new sockets();
    $unix = new unix();
    $EnablePHPFPM = 0;
    @mkdir("/var/run/apache2", 0755, true);
    @mkdir("/var/run/artica-roundcube", 0755, true);
    @mkdir("/var/run/roundcube-apache", 0755, true);
    @mkdir("/var/log/apache2", 0755, true);
    $APACHE_SRC_ACCOUNT = $unix->APACHE_SRC_ACCOUNT();
    $APACHE_SRC_GROUP = $unix->APACHE_SRC_GROUP();
    $APACHE_MODULES_PATH = $unix->APACHE_MODULES_PATH();
    $pydio_installed = false;
    if (is_file(" /etc/php5/cli/conf.d/ming.ini")) {
        @unlink(" /etc/php5/cli/conf.d/ming.ini");
    }
    @unlink("/var/log/apache2/roundcube-error.log");
    @touch("/var/log/apache2/roundcube-error.log");
    @chmod("/var/log/apache2/roundcube-error.log", 0755);
    $unix->chown_func($APACHE_SRC_ACCOUNT, $APACHE_SRC_GROUP, "/var/log/apache2/*");
    $unix->chown_func($APACHE_SRC_ACCOUNT, $APACHE_SRC_GROUP, "/usr/share/artica-postfix/ressources/logs/*");
    $RoundCubeHTTPPort = 8888;
    $RoundCubeHTTPSPort = 449;
    $NoLDAPInLighttpdd = 0;
    $RoundCubeHTTPSPort = intval($sock->GET_INFO("RoundCubeHTTPSPort"));
    $RoundCubeHTTPPort = intval($sock->GET_INFO("RoundCubeHTTPPort"));
    $RoundCubeUseSSL = intval($sock->GET_INFO("RoundCubeUseSSL"));
    $RoundCubeUploadMaxFilesize = intval($sock->GET_INFO("RoundCubeUploadMaxFilesize"));
    if ($RoundCubeUploadMaxFilesize == 0) {
        $RoundCubeUploadMaxFilesize = 128;
    }
    if ($RoundCubeHTTPSPort == 0) {
        $RoundCubeHTTPSPort = 449;
    }
    if ($RoundCubeHTTPPort == 0) {
        $RoundCubeHTTPPort = 8888;
    }
    $RoundCubeListenIP = $sock->GET_INFO("RoundCubeListenIP");
    $phpfpm = $unix->APACHE_LOCATE_PHP_FPM();
    $php = $unix->LOCATE_PHP5_BIN();
    $EnableArticaApachePHPFPM = $sock->GET_INFO("EnableArticaApachePHPFPM");
    if (!is_numeric($EnableArticaApachePHPFPM)) {
        $EnableArticaApachePHPFPM = 0;
    }
    if (!is_file($phpfpm)) {
        $EnableArticaApachePHPFPM = 0;
    }
    $EnablePHPFPM = intval($sock->GET_INFO("EnablePHPFPM"));
    if (!is_numeric($EnablePHPFPM)) {
        $EnablePHPFPM = 0;
    }
    if ($EnablePHPFPM == 0) {
        $EnableArticaApachePHPFPM = 0;
    }
    $unix->chown_func($APACHE_SRC_ACCOUNT, $APACHE_SRC_GROUP, "/var/run/artica-roundcube");
    $apache_LOCATE_MIME_TYPES = $unix->apache_LOCATE_MIME_TYPES();
    if ($EnableArticaApachePHPFPM == 1) {
        if (!is_file("{$APACHE_MODULES_PATH}/mod_fastcgi.so")) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} mod_fastcgi.so is required to use PHP5-FPM\n";
            }
            $EnableArticaApachePHPFPM = 0;
        }
    }
    if ($APACHE_SRC_ACCOUNT == null) {
        $APACHE_SRC_ACCOUNT = "www-data";
        $APACHE_SRC_GROUP = "www-data";
        $unix->CreateUnixUser($APACHE_SRC_ACCOUNT, $APACHE_SRC_GROUP, "Apache username");
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Run as {$APACHE_SRC_ACCOUNT}:{$APACHE_SRC_GROUP}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} PHP-FPM: {$EnablePHPFPM}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} PHP-FPM Enabled: {$EnableArticaApachePHPFPM}\n";
    }
    $open_basedir[] = "/usr/share/artica-postfix";
    $open_basedir[] = "/etc/artica-postfix";
    $open_basedir[] = "/etc/artica-postfix/settings";
    $open_basedir[] = "/var/log";
    $open_basedir[] = "/var/run/mysqld";
    $open_basedir[] = "/usr/share/php";
    $open_basedir[] = "/usr/share/php5";
    $open_basedir[] = "/var/lib/php5";
    $open_basedir[] = "/var/lighttpd/upload";
    $open_basedir[] = "/usr/share/artica-postfix/ressources";
    $open_basedir[] = "/usr/share/artica-postfix/framework";
    $open_basedir[] = "/etc/ssl/certs/mysql-client-download";
    $open_basedir[] = "/var/run";
    $open_basedir[] = "/bin";
    $open_basedir[] = "/tmp";
    $open_basedir[] = "/usr/sbin";
    $open_basedir[] = "/home";
    $f[] = "<Directory \"/usr/share/roundcube\">";
    $f[] = "\tOptions Indexes FollowSymLinks";
    $f[] = "\tphp_value open_basedir \"/usr/share/roundcube\"";
    $f[] = "\tphp_admin_value upload_tmp_dir \"/usr/share/roundcube/uploads\"";
    $f[] = "\tphp_flag register_globals off";
    $f[] = "\tphp_flag magic_quotes_gpc off";
    $f[] = "\tphp_flag magic_quotes_runtime off";
    $f[] = "\tphp_value post_max_size {$RoundCubeUploadMaxFilesize}M";
    $f[] = "\tphp_value upload_max_filesize {$RoundCubeUploadMaxFilesize}M";
    $f[] = "\tphp_flag short_open_tag on";
    $f[] = "\tphp_flag safe_mode off";
    $f[] = "\tDirectoryIndex index.php";
    $f[] = "\tSSLOptions +StdEnvVars";
    $f[] = "\tOptions Indexes FollowSymLinks";
    $f[] = "\tAllowOverride None";
    $f[] = "</Directory>";
    $MyDirectory = @implode("\n", $f);
    $f = array();
    //$f[]="php_value open_basedir \"".@implode(":", $open_basedir)."\"";
    //$f[]="php_value output_buffering Off";
    //$f[]="php_flag magic_quotes_gpc Off";
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Listen Port: {$RoundCubeHTTPSPort}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Listen IP: {$RoundCubeListenIP}\n";
    }
    if ($RoundCubeListenIP != null) {
        $unix = new unix();
        $IPS = $unix->NETWORK_ALL_INTERFACES(true);
        if (!isset($IPS[$RoundCubeListenIP])) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} ERROR! Listen IP: {$RoundCubeListenIP} -> FALSE !!\n";
            }
            $RoundCubeListenIP = null;
        }
    }
    if ($RoundCubeListenIP == null) {
        $RoundCubeListenIP = "*";
    }
    if ($RoundCubeListenIP != null) {
        $RoundCubeHTTPSPort = "{$RoundCubeListenIP}:{$RoundCubeHTTPSPort}";
    }
    $f[] = "";
    $f[] = "LockFile /var/run/apache2/artica-accept.lock";
    $f[] = "PidFile /var/run/roundcube-apache/apache.pid";
    $f[] = "DocumentRoot /usr/share/roundcube";
    $f[] = "Listen {$RoundCubeListenIP}:{$RoundCubeHTTPPort}";
    $f[] = "NameVirtualHost {$RoundCubeListenIP}:{$RoundCubeHTTPPort}";
    if ($RoundCubeUseSSL == 1) {
        $f[] = "Listen {$RoundCubeHTTPSPort}";
        $f[] = "NameVirtualHost {$RoundCubeHTTPSPort}";
    }
    $MaxClients = 20;
    $f[] = "<IfModule mpm_prefork_module>";
    $f[] = "\tStartServers 1";
    $f[] = "\tMinSpareServers 2";
    $f[] = "\tMaxSpareServers 3";
    $f[] = "\tMaxClients {$MaxClients}";
    $f[] = "\tServerLimit {$MaxClients}";
    $f[] = "\tMaxRequestsPerChild 100";
    $f[] = "</IfModule>";
    $f[] = "<IfModule mpm_worker_module>";
    $f[] = "\tMinSpareThreads      25";
    $f[] = "\tMaxSpareThreads      75 ";
    $f[] = "\tThreadLimit          64";
    $f[] = "\tThreadsPerChild      25";
    $f[] = "</IfModule>";
    $f[] = "<IfModule mpm_event_module>";
    $f[] = "\tMinSpareThreads      25";
    $f[] = "\tMaxSpareThreads      75 ";
    $f[] = "\tThreadLimit          64";
    $f[] = "\tThreadsPerChild      25";
    $f[] = "</IfModule>";
    $f[] = "AccessFileName .htaccess";
    $f[] = "DefaultType text/plain";
    $f[] = "HostnameLookups Off";
    $f[] = "User\t\t\t\t   {$APACHE_SRC_ACCOUNT}";
    $f[] = "Group\t\t\t\t   {$APACHE_SRC_GROUP}";
    $f[] = "Timeout              300";
    $f[] = "KeepAlive            Off";
    $f[] = "KeepAliveTimeout     15";
    $f[] = "StartServers         1";
    $f[] = "MaxClients           {$MaxClients}";
    $f[] = "MinSpareServers      2";
    $f[] = "MaxSpareServers      3";
    $f[] = "MaxRequestsPerChild  100";
    $f[] = "MaxKeepAliveRequests 100";
    $ServerName = $unix->hostname_g();
    if ($ServerName == null) {
        $ServerName = "localhost.localdomain";
    }
    $f[] = "ServerName {$ServerName}";
    $f[] = "AddType application/x-httpd-php .php";
    if ($EnableArticaApachePHPFPM == 0) {
        $f[] = "php_value error_log \"/var/log/php.log\"";
    }
    @chown("/var/log/php.log", $APACHE_SRC_ACCOUNT);
    $f[] = "<IfModule mod_fcgid.c>";
    $f[] = "\tPHP_Fix_Pathinfo_Enable 1";
    $f[] = "</IfModule>";
    $f[] = "<IfModule mod_php5.c>";
    $f[] = "    <FilesMatch \"\\.ph(p3?|tml)\$\">";
    $f[] = "\tSetHandler application/x-httpd-php";
    $f[] = "    </FilesMatch>";
    $f[] = "    <FilesMatch \"\\.phps\$\">";
    $f[] = "\tSetHandler application/x-httpd-php-source";
    $f[] = "    </FilesMatch>";
    $f[] = "</IfModule>";
    $f[] = "<IfModule mod_mime.c>";
    $f[] = "\tTypesConfig /etc/mime.types";
    $f[] = "\tAddType application/x-compress .Z";
    $f[] = "\tAddType application/x-gzip .gz .tgz";
    $f[] = "\tAddType application/x-bzip2 .bz2";
    $f[] = "\tAddType application/x-httpd-php .php .phtml";
    $f[] = "\tAddType application/x-httpd-php-source .phps";
    $f[] = "\tAddLanguage ca .ca";
    $f[] = "\tAddLanguage cs .cz .cs";
    $f[] = "\tAddLanguage da .dk";
    $f[] = "\tAddLanguage de .de";
    $f[] = "\tAddLanguage el .el";
    $f[] = "\tAddLanguage en .en";
    $f[] = "\tAddLanguage eo .eo";
    $f[] = "\tRemoveType  es";
    $f[] = "\tAddLanguage es .es";
    $f[] = "\tAddLanguage et .et";
    $f[] = "\tAddLanguage fr .fr";
    $f[] = "\tAddLanguage he .he";
    $f[] = "\tAddLanguage hr .hr";
    $f[] = "\tAddLanguage it .it";
    $f[] = "\tAddLanguage ja .ja";
    $f[] = "\tAddLanguage ko .ko";
    $f[] = "\tAddLanguage ltz .ltz";
    $f[] = "\tAddLanguage nl .nl";
    $f[] = "\tAddLanguage nn .nn";
    $f[] = "\tAddLanguage no .no";
    $f[] = "\tAddLanguage pl .po";
    $f[] = "\tAddLanguage pt .pt";
    $f[] = "\tAddLanguage pt-BR .pt-br";
    $f[] = "\tAddLanguage ru .ru";
    $f[] = "\tAddLanguage sv .sv";
    $f[] = "\tRemoveType  tr";
    $f[] = "\tAddLanguage tr .tr";
    $f[] = "\tAddLanguage zh-CN .zh-cn";
    $f[] = "\tAddLanguage zh-TW .zh-tw";
    $f[] = "\tAddCharset us-ascii    .ascii .us-ascii";
    $f[] = "\tAddCharset ISO-8859-1  .iso8859-1  .latin1";
    $f[] = "\tAddCharset ISO-8859-2  .iso8859-2  .latin2 .cen";
    $f[] = "\tAddCharset ISO-8859-3  .iso8859-3  .latin3";
    $f[] = "\tAddCharset ISO-8859-4  .iso8859-4  .latin4";
    $f[] = "\tAddCharset ISO-8859-5  .iso8859-5  .cyr .iso-ru";
    $f[] = "\tAddCharset ISO-8859-6  .iso8859-6  .arb .arabic";
    $f[] = "\tAddCharset ISO-8859-7  .iso8859-7  .grk .greek";
    $f[] = "\tAddCharset ISO-8859-8  .iso8859-8  .heb .hebrew";
    $f[] = "\tAddCharset ISO-8859-9  .iso8859-9  .latin5 .trk";
    $f[] = "\tAddCharset ISO-8859-10  .iso8859-10  .latin6";
    $f[] = "\tAddCharset ISO-8859-13  .iso8859-13";
    $f[] = "\tAddCharset ISO-8859-14  .iso8859-14  .latin8";
    $f[] = "\tAddCharset ISO-8859-15  .iso8859-15  .latin9";
    $f[] = "\tAddCharset ISO-8859-16  .iso8859-16  .latin10";
    $f[] = "\tAddCharset ISO-2022-JP .iso2022-jp .jis";
    $f[] = "\tAddCharset ISO-2022-KR .iso2022-kr .kis";
    $f[] = "\tAddCharset ISO-2022-CN .iso2022-cn .cis";
    $f[] = "\tAddCharset Big5        .Big5       .big5 .b5";
    $f[] = "\tAddCharset cn-Big5     .cn-big5";
    $f[] = "\t# For russian, more than one charset is used (depends on client, mostly):";
    $f[] = "\tAddCharset WINDOWS-1251 .cp-1251   .win-1251";
    $f[] = "\tAddCharset CP866       .cp866";
    $f[] = "\tAddCharset KOI8      .koi8";
    $f[] = "\tAddCharset KOI8-E      .koi8-e";
    $f[] = "\tAddCharset KOI8-r      .koi8-r .koi8-ru";
    $f[] = "\tAddCharset KOI8-U      .koi8-u";
    $f[] = "\tAddCharset KOI8-ru     .koi8-uk .ua";
    $f[] = "\tAddCharset ISO-10646-UCS-2 .ucs2";
    $f[] = "\tAddCharset ISO-10646-UCS-4 .ucs4";
    $f[] = "\tAddCharset UTF-7       .utf7";
    $f[] = "\tAddCharset UTF-8       .utf8";
    $f[] = "\tAddCharset UTF-16      .utf16";
    $f[] = "\tAddCharset UTF-16BE    .utf16be";
    $f[] = "\tAddCharset UTF-16LE    .utf16le";
    $f[] = "\tAddCharset UTF-32      .utf32";
    $f[] = "\tAddCharset UTF-32BE    .utf32be";
    $f[] = "\tAddCharset UTF-32LE    .utf32le";
    $f[] = "\tAddCharset euc-cn      .euc-cn";
    $f[] = "\tAddCharset euc-gb      .euc-gb";
    $f[] = "\tAddCharset euc-jp      .euc-jp";
    $f[] = "\tAddCharset euc-kr      .euc-kr";
    $f[] = "\tAddCharset EUC-TW      .euc-tw";
    $f[] = "\tAddCharset gb2312      .gb2312 .gb";
    $f[] = "\tAddCharset iso-10646-ucs-2 .ucs-2 .iso-10646-ucs-2";
    $f[] = "\tAddCharset iso-10646-ucs-4 .ucs-4 .iso-10646-ucs-4";
    $f[] = "\tAddCharset shift_jis   .shift_jis .sjis";
    $f[] = "\tAddType text/html .shtml";
    $f[] = "\tAddOutputFilter INCLUDES .shtml";
    $f[] = "</IfModule>";
    $f[] = "<VirtualHost {$RoundCubeListenIP}:{$RoundCubeHTTPPort}>";
    $f[] = "ServerAdmin webmaster@none.tld";
    $f[] = "DocumentRoot /usr/share/roundcube";
    $f[] = "{$MyDirectory}";
    $f[] = "</VirtualHost>";
    if ($RoundCubeUseSSL == 1) {
        $f[] = "AcceptMutex flock";
        $f[] = "SSLCertificateFile \"/etc/ssl/certs/apache/server.crt\"";
        $f[] = "SSLCertificateKeyFile \"/etc/ssl/certs/apache/server.key\"";
        $f[] = "SSLVerifyClient none";
        $f[] = "ServerSignature Off";
        $f[] = "SSLRandomSeed startup file:/dev/urandom  256";
        $f[] = "SSLRandomSeed connect builtin";
        $f[] = "\tSSLRandomSeed connect builtin";
        $f[] = "\tSSLRandomSeed connect file:/dev/urandom 256";
        $f[] = "\tAddType application/x-x509-ca-cert .crt";
        $f[] = "\tAddType application/x-pkcs7-crl    .crl";
        $f[] = "\tSSLPassPhraseDialog  builtin";
        $f[] = "\tSSLSessionCache        shmcb:/var/run/apache2/ssl_scache-artica(512000)";
        $f[] = "\tSSLSessionCacheTimeout  300";
        $f[] = "\tSSLSessionCacheTimeout  300";
        $f[] = "\tSSLCipherSuite HIGH:MEDIUM:!ADH";
        $f[] = "\tSSLProtocol all -SSLv2";
        $f[] = "<VirtualHost {$RoundCubeHTTPSPort}>";
        $f[] = "ServerAdmin webmaster@none.tld";
        $f[] = "DocumentRoot /usr/share/roundcube";
        $f[] = "{$MyDirectory}";
        $mknod = $unix->find_program("mknod");
        shell_exec("{$mknod} /dev/random c 1 9 >/dev/null 2>&1");
        $f[] = "SSLEngine on";
        $f[] = "</VirtualHost>";
        $f[] = "";
    }
    if (!is_file("/etc/ssl/certs/apache/server.crt")) {
        shell_exec("/usr/share/artica-postfix/bin/artica-install --apache-ssl-cert");
    }
    if ($EnableArticaApachePHPFPM == 1) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Activate PHP5-FPM\n";
        }
        shell_exec("{$php} /usr/share/artica-postfix/exec.initslapd.php --phppfm");
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Restarting PHP5-FPM\n";
        }
        shell_exec("/etc/init.d/php5-fpm restart");
        $f[] = "\tAlias /php5.fastcgi /var/run/artica-roundcube/php5.fastcgi";
        $f[] = "\tAddHandler php-script .php";
        $f[] = "\tFastCGIExternalServer /var/run/artica-roundcube/php5.fastcgi -socket /var/run/php-fpm.sock -idle-timeout 610";
        $f[] = "\tAction php-script /php5.fastcgi virtual";
        $f[] = "\t<Directory /var/run/artica-roundcube>";
        $f[] = "\t\t<Files php5.fastcgi>";
        //$f[]="\t\tOrder deny,allow";
        //$f[]="\t\tAllow from all";
        $f[] = "\t\t</Files>";
        $f[] = "\t</Directory>";
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} PHP5-FPM is disabled\n";
        }
    }
    $f[] = "Loglevel info";
    $f[] = "ErrorLog /var/log/apache2/roundcube-error.log";
    $f[] = "LogFormat \"%h %l %u %t \\\"%r\\\" %<s %b\" common";
    $f[] = "CustomLog /var/log/apache2/roundcube-access.log common";
    if ($EnableArticaApachePHPFPM == 0) {
        $array["php5_module"] = "libphp5.so";
    }
    $array["actions_module"] = "mod_actions.so";
    $array["expires_module"] = "mod_expires.so";
    $array["rewrite_module"] = "mod_rewrite.so";
    $array["dir_module"] = "mod_dir.so";
    $array["mime_module"] = "mod_mime.so";
    $array["alias_module"] = "mod_alias.so";
    $array["auth_basic_module"] = "mod_auth_basic.so";
    $array["authn_file_module"] = "mod_authn_file.so";
    //$array["authz_host_module"]="mod_authz_host.so";
    $array["autoindex_module"] = "mod_autoindex.so";
    $array["negotiation_module"] = "mod_negotiation.so";
    $array["ssl_module"] = "mod_ssl.so";
    $array["headers_module"] = "mod_headers.so";
    $array["ldap_module"] = "mod_ldap.so";
    if ($EnableArticaApachePHPFPM == 1) {
        $array["fastcgi_module"] = "mod_fastcgi.so";
    }
    if (is_dir("/etc/apache2")) {
        if (!is_file("/etc/apache2/mime.types")) {
            if ($apache_LOCATE_MIME_TYPES != "/etc/apache2/mime.types") {
                @copy($apache_LOCATE_MIME_TYPES, "/etc/apache2/mime.types");
            }
        }
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Mime types path.......: {$apache_LOCATE_MIME_TYPES}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Modules path..........: {$APACHE_MODULES_PATH}\n";
    }
    while (list($module, $lib) = each($array)) {
        if (is_file("{$APACHE_MODULES_PATH}/{$lib}")) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} include module \"{$module}\"\n";
            }
            $f[] = "LoadModule {$module} {$APACHE_MODULES_PATH}/{$lib}";
        } else {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} skip module \"{$module}\"\n";
            }
        }
    }
    $f[] = "\n\n";
    @file_put_contents("/etc/artica-postfix/apache-roundcube.conf", @implode("\n", $f));
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} /etc/artica-postfix/apache-roundcube.conf done\n";
    }
    $apachename = $unix->APACHE_SRC_ACCOUNT();
    $apachegroup = $unix->APACHE_SRC_GROUP();
    @mkdir("/usr/share/roundcube/uploads", 0755, true);
    $dirs = $unix->dirdir("/usr/share/roundcube");
    while (list($dirname, $lib) = each($dirs)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Privileges on {$dirname}\n";
        }
        $unix->chown_func($APACHE_SRC_ACCOUNT, $APACHE_SRC_GROUP, $dirname);
        $unix->chmod_func(0755, $dirname);
    }
}
function compile()
{
    $unix = new unix();
    $MAIN_CACHE = unserialize(@file_get_contents("/root/UFDB_COMPILE_DATABASES"));
    $q = new mysql_squid_builder();
    $DB_LISTES = TransArray();
    $ufdbGenTable = $unix->find_program("ufdbGenTable");
    $WORKDIR = "/home/artica/ufdbv10";
    $OUTPUTDIR = "/home/artica/ufdbv10Export";
    @mkdir($OUTPUTDIR, 0755, true);
    $UPDATED = 0;
    while (list($category_table, $category) = each($DB_LISTES)) {
        echo "Starting Cleaning {$category_table}\n";
        Clean_table($category_table);
        $CountCategoryTableRows = $q->COUNT_ROWS("{$category_table}");
        echo "{$category_table}: {$CountCategoryTableRows} rows\n";
        if ($CountCategoryTableRows == 0) {
            sendEmail("ALERT! {$category_table} NO ROW!");
            continue;
        }
        if (intval($MAIN_CACHE[$category_table]["ROWS"]) == $CountCategoryTableRows) {
            ToSyslog($category_table . " [SKIPPED] {$MAIN_CACHE[$category_table]["ROWS"]} == {$CountCategoryTableRows}");
            echo "{$category_table}: SKIPPED\n";
            continue;
        }
        $workingtempdir = "{$WORKDIR}/{$category_table}";
        $workingtempFile = "{$workingtempdir}/domains";
        @mkdir($workingtempdir, 0777, true);
        $unix->chmod_func(0777, $workingtempdir);
        if (is_file($workingtempFile)) {
            @unlink($workingtempFile);
        }
        $sql = "SELECT pattern FROM {$category_table} ORDER BY pattern INTO OUTFILE '{$workingtempFile}' LINES TERMINATED BY '\n';";
        $q = new mysql_squid_builder();
        $q->QUERY_SQL($sql);
        if (!$q->ok) {
            sendEmail("ALERT! {$category_table} MySQL error", $q->mysql_error);
            die;
        }
        @file_put_contents("{$workingtempdir}/urls", "\n");
        @file_put_contents("{$workingtempdir}/expressions", "\n");
        @unlink("{$workingtempdir}/domains.ufdb");
        $categoryKey = compile_databases_categoryKey($category);
        $u = " -u {$workingtempdir}/urls";
        $d = " -d {$workingtempdir}/domains";
        $cmd = "{$ufdbGenTable} -n -q -W -t {$categoryKey}{$d}{$u} >/dev/null 2>&1";
        echo "[{$category_table}]::{$category} {$cmd}\n";
        $UPDATED++;
        $t = time();
        $resultsCMD[] = $cmd;
        ToSyslog("[FINISH]:: Compiling {$category_table}...");
        exec($cmd, $resultsCMD);
        if (!is_file("{$workingtempdir}/domains.ufdb")) {
            sendEmail("ALERT! {$category_table} domains.ufdb no such file!");
            continue;
        }
        @mkdir("/home/artica/backuped_categories", 0755);
        $unix->compress($workingtempFile, "/home/artica/backuped_categories/{$category_table}.gz");
        echo "[{$category_table}]::{$category} Compressing to {$OUTPUTDIR}/{$category_table}.gz\n";
        if (!$unix->compress("{$workingtempdir}/domains.ufdb", "{$OUTPUTDIR}/{$category_table}.gz")) {
            sendEmail("ALERT! unable to compress {$workingtempdir}/domains.ufdb");
            die;
        }
        @unlink("/home/ufdbcat/{$category_table}/domains.ufdb");
        @copy("{$workingtempdir}/domains.ufdb", "/var/lib/ufdbartica/{$category_table}/domains.ufdb");
        echo "[{$category_table}]::{$category} Indexing....\n";
        $md5file = md5_file("{$workingtempdir}/domains.ufdb");
        $md5zip = md5_file("{$OUTPUTDIR}/{$category_table}.gz");
        ToSyslog("{$OUTPUTDIR}/{$category_table}.gz [UPDATED]");
        $UPDATED_DBS[] = "{$category_table} ({$CountCategoryTableRows})";
        $MAIN_CACHE[$category_table]["ROWS"] = $CountCategoryTableRows;
        $MAIN_CACHE[$category_table]["TIME"] = time();
        $MAIN_CACHE[$category_table]["MD5SRC"] = $md5file;
        $MAIN_CACHE[$category_table]["MD5GZ"] = $md5zip;
    }
    ToSyslog("[FINISH]:: Building indexes {$UPDATED} updated...");
    @file_put_contents("/root/UFDB_COMPILE_DATABASES", serialize($MAIN_CACHE));
    @file_put_contents("{$OUTPUTDIR}/index.txt", base64_encode(serialize($MAIN_CACHE)));
    if ($UPDATED > 0) {
        ToSyslog("[FINISH]:: PushToRepo_alls()");
        PushToRepo_alls();
        sendEmail("{$UPDATED} Official Webfiltering databases updated", @implode("\n", $UPDATED_DBS));
    }
}
$unix = new unix();
$php5 = $unix->LOCATE_PHP5_BIN();
if ($GLOBALS["VERBOSE"]) {
    echo "lighttpd user: {$username}:{$groupname}\n";
}
if (is_dir("/etc/resolvconf")) {
    shell_exec("{$php5} " . basename(__FILE__) . "/exec.virtuals-ip.php --resolvconf >/dev/null 2>&1 &");
    if (!is_dir("/etc/resolvconf/run/interface")) {
        @mkdir("/etc/resolvconf/run/interface", 0755, true);
    }
}
if (!is_dir("/var/log/btmp")) {
    @mkdir("/var/log/btmp", 0755, true);
}
@chmod("/etc/artica-postfix/settings/Daemons", 0755);
$unix->chmod_func(0755, "/etc/artica-postfix/settings/Daemons/*");
writeprogress(5, "/etc/artica-postfix/settings/Daemons");
$sock = new sockets();
$f[] = 'ressources';
$f[] = 'ressources/sessions';
$f[] = 'ressources/web';
$f[] = 'ressources/web/logs';
$f[] = 'ressources/logs/web/queue/sessions';
$f[] = 'framework';
$f[] = 'ressources/userdb';
$f[] = 'ressources/conf';
$f[] = 'ressources/conf/kasDatas';
$f[] = 'ressources/logs';
$f[] = 'ressources/profiles';
$f[] = 'ressources/profiles/icons';
$f[] = 'ressources/sessions/SessionData';
function start()
{
    $unix = new unix();
    $pidfile = "/var/run/squid-stats-central.pid";
    $timefile = $GLOBALS["TIMEFILE"];
    $sock = new sockets();
    if (!$unix->is_socket("/var/run/mysqld/squid-db.sock")) {
        stats_admin_events(0, "MySQL server not ready, delay task...", null, __FILE__, __LINE__);
        $unix->THREAD_COMMAND_SET($unix->LOCATE_PHP5_BIN() . " " . __FILE__);
        die;
    }
    $WizardStatsApplianceDisconnected = intval($sock->GET_INFO("WizardStatsApplianceDisconnected"));
    if ($WizardStatsApplianceDisconnected == 1) {
        $export_stamp = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".EXPORT.time";
        $export_time = $unix->file_time_min($export_stamp);
        if ($export_time > 60) {
            start_export();
            export_push();
            @unlink($export_stamp);
            @file_put_contents($export_stamp, time());
        }
        die;
    }
    if (!$GLOBALS["NOTIME"]) {
        @unlink($timefile);
        @file_put_contents($timefile, time());
    }
    stats_admin_events(2, " **** STARTING Statistics Engine ****", null, __FILE__, __LINE__);
    percentage("**** STARTING Statistics Engine ****", 0);
    percentage("**** Importing tables ****", 2);
    start_import(true);
    $sock->SQUID_DISABLE_STATS_DIE();
    $pid = @file_get_contents($pidfile);
    if (!$GLOBALS["FORCE"]) {
        if ($pid < 100) {
            $pid = null;
        }
        $unix = new unix();
        if ($unix->process_exists($pid, basename(__FILE__))) {
            if ($GLOBALS["VERBOSE"]) {
                echo "Already executed pid {$pid}\n";
            }
            return;
        }
        $mypid = getmypid();
        @file_put_contents($pidfile, $mypid);
    }
    $DisableArticaProxyStatistics = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/DisableArticaProxyStatistics"));
    if ($DisableArticaProxyStatistics == 1) {
        percentage("{disabled}", 100);
        stats_admin_events(1, "100%) Statistics are disabled");
        StampDone(1000, "Statistics are disabled");
        return;
    }
    @unlink("/var/run/squid-stats-central.stop");
    if (!$GLOBALS["NOTIME"]) {
        @unlink($timefile);
        @file_put_contents($timefile, time());
    }
    $tSource = time();
    $php5 = $unix->LOCATE_PHP5_BIN();
    $nohup = $unix->find_program("nohup");
    $EXEC_NICE = $unix->EXEC_NICE();
    $Prefix = "/usr/share/artica-postfix";
    $q = new mysql_squid_builder();
    $GLOBALS["Q"] = $q;
    @mkdir("/home/artica/categories_databases", 0755, true);
    $unix->chmod_func(0755, "/home/artica/categories_databases/*");
    $unix->chmod_func(0755, "/home/artica/categories_perso/*");
    if (!StampOK(5)) {
        percentage("Reloading categories Daemon...", 2);
        shell_exec("/etc/init.d/ufdbcat reload");
    }
    $t = time();
    if (!StampOK(10)) {
        percentage("Purge old days", 1);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squidlogs.purge.php"));
        stats_admin_events(2, "1%) Purge days took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(10, "Purge old days");
    }
    if (!StampOK(20)) {
        percentage("Compile personal tables...", 2);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.compile_category_perso.php"));
        Step2();
        StampDone(20, "Compile personal tables");
    }
    $t = time();
    if (!StampOK(30)) {
        percentage("Running Quota day", 2);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.quotaday.php"));
        stats_admin_events(2, "2%) Quota day executed took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(30, "Running Quota day");
    }
    if (SquidStatisticsTasksOverTime()) {
        stats_admin_events(1, "Statistics overtime... Aborting", null, __FILE__, __LINE__);
        return;
    }
    if (!StampOK(40)) {
        percentage("Running Youtube Hours", 2);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.youtube.days.php --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "2%) Youtube Hours executed took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(40, "Running Youtube Hours");
    }
    shell_exec("{$nohup} {$php5} /usr/share/artica-postfix/exec.squid.stats.php --thumbs-parse >/dev/null 2>&1 &");
    if (!StampOK(50)) {
        percentage("table_days()", 2);
        table_days();
        StampDone(50, "table days");
    }
    if (!StampOK(60)) {
        percentage("Repair Members tables", 2);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.members.hours.php --repair --byschedule --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        StampDone(60, "Repair Members tables");
    }
    if (!StampOK(70)) {
        percentage("Repair Sum tables", 2);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.totals.php --repair --byschedule --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.repair.php --coherences-tables --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        StampDone(70, "Repair Sum tables");
    }
    if (!StampOK(80)) {
        percentage("WeekDaysNums()", 2);
        WeekDaysNums();
        stats_admin_events(2, "2%) Fix tables executed took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(80, "WeekDaysNums");
    }
    if (!StampOK(90)) {
        $t = time();
        percentage("Scanning nodes", 3);
        nodes_scan();
        stats_admin_events(2, "3%) Scanning nodes executed took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(90, "Scanning nodes");
    }
    if (!StampOK(100)) {
        $t = time();
        percentage("Scanning Active Directory", 4);
        shell_exec(trim("{$nohup} {$EXEC_NICE} {$php5} {$Prefix}/exec.clientad.php >/dev/null 2>&1 &"));
        stats_admin_events(2, "4%) Scanning Active Directory executed took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(100, "Scanning Active Directory");
    }
    if (!StampOK(110)) {
        $t = time();
        percentage("Running Active directory translation", 7);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.ad.ous.php"));
        stats_admin_events(2, "7%) Active directory translation took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(110, "Running Active directory translation");
    }
    if (!StampOK(120)) {
        $t = time();
        percentage("Running Search Words hourly", 8);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid-searchwords.php --hour"));
        stats_admin_events(2, "8%) Running Search Words hourly took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(120, "Running Search Words hourly");
    }
    if (!StampOK(130)) {
        $t = time();
        percentage("Repair tables", 9);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.hours.php --repair --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "9%) Running Search Words hourly took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(130, "Repair tables");
    }
    if (!StampOK(140)) {
        $t = time();
        percentage("Running Clients Hourly (clients_hours())", 10);
        clients_hours();
        stats_admin_events(2, "10%) Running Clients Hourly took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(130, "Running Clients Hourly (clients_hours())");
    }
    if (!StampOK(150)) {
        $t = time();
        percentage("Search Words Hourly", 10);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}//usr/share/artica-postfix/exec.squid-searchwords.php --hour --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "10%)  Search Words Hourly:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(150, "Search Words Hourly");
    }
    if (!StampOK(160)) {
        $t = time();
        percentage("Running Members hour", 11);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.php --members --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "11%) Running Members hour took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(160, "Running Members hour");
    }
    if (!StampOK(170)) {
        $t = time();
        percentage("Repair UserSizeD", 11);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.php --UserSizeD --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "11%) Repair UserSizeD took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(170, "Repair UserSizeD");
    }
    if (!StampOK(180)) {
        $t = time();
        percentage("UserAuthDaysGrouped", 11);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.php --members-central-grouped --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "11%) Repair UserAuthDaysGrouped took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(180, "UserAuthDaysGrouped");
    }
    if (!StampOK(190)) {
        $t = time();
        percentage("quotaday (quotamonth)...", 11);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.quotaday.php --quotamonth --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "33%)  Months tables.... took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(190, "quotaday (quotamonth)");
    }
    if (!StampOK(200)) {
        $t = time();
        percentage("Repair Youtube Ids", 11);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.repair.php --youtube --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "12%) Repair Youtube Ids took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(200, "Repair Youtube Ids");
    }
    if (!StampOK(210)) {
        $t = time();
        percentage("Running Youtube statistics", 11);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.youtube.days.php --youtube-dayz --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "12%) Running Search Words hourly took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(210, "Running Youtube statistics");
    }
    if (!StampOK(220)) {
        $t = time();
        percentage("Summarize days", 12);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.php --summarize-days --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "11%) Summarize days took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(220, "Summarize days");
    }
    if (!StampOK(230)) {
        $t = time();
        percentage("Running Blocked threats day", 13);
        stats_admin_events(2, "13%) Blocked threats day:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(230, "Running Blocked threats day");
    }
    if (!StampOK(240)) {
        $t = time();
        percentage("Running Visited day", 15);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.php --visited-days --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "15%) Visited day took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(240, "Running Visited day");
    }
    if (!StampOK(245)) {
        $t = time();
        percentage("Running Global Family sites", 16);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.familyday.php --scheduled"));
        stats_admin_events(2, "10%) Running exec.squid.stats.familyday.php took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(245, "Running Global Family sites ok");
    }
    if (!StampOK(246)) {
        $t = time();
        percentage("Running Global Users", 17);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.usersday.php --scheduled"));
        stats_admin_events(2, "10%) Running exec.squid.stats.usersday.php took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(246, "Running Global Users ok");
    }
    if (!StampOK(250)) {
        $t = time();
        percentage("Running Days Websites", 20);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.days.websites.php --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "20%)  Days Websites took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(250, "Running Days Websites");
    }
    if (!StampOK(260)) {
        $t = time();
        percentage("Week tables...", 21);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.php --week --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "29%)  Week tables... took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(260, "Week tables...");
    }
    if (!StampOK(270)) {
        $t = time();
        percentage("Repair tables", 26);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.totals.php --repair --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "26%)  Repair tables took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(270, "Repair tables");
    }
    if (!StampOK(280)) {
        percentage("Youtube All", 26);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.youtube_uid.php --all --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "26%)  Youtube All took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(280, "Youtube All");
    }
    if (!StampOK(290)) {
        $t = time();
        percentage("Cache performances", 27);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.php --webcacheperfs --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "27%)  Cache performances took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(290, "Cache performances");
    }
    if (!StampOK(300)) {
        $t = time();
        percentage("Interface elements", 28);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.totals.php --interface --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "28%)  Interface elements took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(300, "Interface elements");
    }
    if (!StampOK(310)) {
        $t = time();
        percentage("Members central...", 29);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.php --members-central --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "29%)  Members central... took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(310, "Members central...");
    }
    if (!StampOK(320)) {
        $t = time();
        percentage("Search Words Weekly", 29);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}//usr/share/artica-postfix/exec.squid-searchwords.php --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "29%)  Search Words Weekly... took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(320, "Search Words Weekly");
    }
    if (!StampOK(330)) {
        $t = time();
        percentage("Week tables ( blocked )...", 30);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.blocked.week.php --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "30%)  Week tables ( blocked ).... took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(330, "Week tables ( blocked )...");
    }
    if (!StampOK(340)) {
        $t = time();
        percentage("Months tables (1) ...", 31);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.php --scan-months --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "31%)  Months tables.... took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(340, "Months tables (1)");
    }
    if (!StampOK(350)) {
        $t = time();
        percentage("Months tables (2) ...", 32);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.month.php --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "32%)  Months tables.... took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(350, "Months tables (2)");
    }
    if (!StampOK(360)) {
        $t = time();
        percentage("Categorize Month tables (3) ...", 32);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.not-categorized.php --months --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "31%)  Months tables.... took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(360, "Categorize last 7 days");
    }
    if (!StampOK(370)) {
        $t = time();
        percentage("Months tables by users (4)...", 35);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.uid-month.php --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "35%)  Months tables.... took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(370, "Months tables by users (4");
    }
    if (!StampOK(380)) {
        $t = time();
        percentage("Repair categories", 40);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.php --repair-categories --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "40%)  Repair categories.... took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(370, "Repair categories");
    }
    if (!StampOK(390)) {
        $t = time();
        percentage("Categorize last days", 45);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.categorize-table.php --last-days --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "45%)  Categorize last days.... took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(390, "Categorize last days");
    }
    if (!StampOK(400)) {
        $t = time();
        percentage("Visited Websites", 46);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.php --visited-sites2 --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "25%)  Visited Websites took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(400, "Visited Websites");
    }
    if (!StampOK(410)) {
        $t = time();
        percentage("Dangerous elements", 46);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.dangerous.php --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "28%)  Interface elements took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(410, "Dangerous elements");
    }
    if (!StampOK(420)) {
        $t = time();
        percentage("Categorize all tables", 46);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.categorize-table.php --all --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "46%)  Categorize all tables.... took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(420, "Categorize all tables");
    }
    if (!StampOK(430)) {
        $t = time();
        percentage("Scanning Not categorized", 47);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.not-categorized.php --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "47%)  Categorize all tables.... took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(430, "Scanning Not categorized");
    }
    if (!StampOK(440)) {
        $t = time();
        percentage("Recategorize", 48);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.recategorize.php --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "48%) Recategorize.... took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(440, "Recategorize");
    }
    if (!StampOK(450)) {
        $t = time();
        percentage("Sync categories", 49);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.php --sync-categories --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "49%) Recategorize.... took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(450, "Sync categories");
    }
    if (!StampOK(460)) {
        $t = time();
        percentage("Global categories", 50);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.global.categories.php --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "50%) Global categories.... took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(460, "Global categories");
    }
    if (!StampOK(470)) {
        $t = time();
        percentage("Parse thumbs", 55);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.php --thumbs-parse --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "50%) Parse thumbs.... took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(470, "Parse thumbs");
    }
    if (!StampOK(480)) {
        percentage("Repair not categorized", 55);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.recategorize.missed.php --repair --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        StampDone(480, "Repair not categorized");
    }
    if (!StampOK(490)) {
        percentage("Not categorized - last 7 days", 55);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.stats.recategorize.missed.php --last7-days --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "5%) Parse thumbs.... took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(490, "Not categorized - last 7 days");
    }
    if (!StampOK(500)) {
        $t = time();
        percentage("Reports", 60);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.reports.php --all --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "60%) Reports.... took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(500, "Reports");
    }
    if (!StampOK(510)) {
        $t = time();
        percentage("Statistics by User", 70);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.members_uid.php --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "70%) Statistics by user took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(510, "Statistics by User");
    }
    if (!StampOK(520)) {
        $t = time();
        percentage("Statistics by Users/Websites", 71);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.websites_uid.php --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "71%) Statistics by user/Websites took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(520, "Statistics by Users/Websites");
    }
    if (!StampOK(530)) {
        $t = time();
        percentage("Statistics by Users/MAC", 73);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.members_mac.php  --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "73%) Statistics by user/mac took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(530, "Statistics by Users/MAC");
    }
    if (!StampOK(540)) {
        $t = time();
        percentage("Statistics by Users/MAC/IP", 73);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.members_macip.php  --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "73%) Statistics by user/mac/ip took:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(530, "Statistics by Users/MAC/IP");
    }
    if (!StampOK(550)) {
        $t = time();
        percentage("Statistics by Users/Blocked", 74);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.blocked_uid.php  --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "74%) Statistics by user/blocked:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(550, "Statistics by Users/Blocked");
    }
    if (!StampOK(560)) {
        $t = time();
        percentage("Statistics by Users/Blocked", 75);
        shell_exec(trim("{$EXEC_NICE} {$php5} {$Prefix}/exec.squid.youtube_uid.php  --schedule-id={$GLOBALS["SCHEDULE_ID"]}"));
        stats_admin_events(2, "74%) Statistics by user/youtube:" . $unix->distanceOfTimeInWords($t, time()), null, __FILE__, __LINE__);
        StampDone(550, "Statistics by Users/Blocked");
    }
    percentage("{finish}:" . date("Y-m-d H:i:s"), 100);
    StampDone(1000, "{done}");
    @unlink($GLOBALS["TIMEFILE"]);
}
Beispiel #13
0
function squidlogs_status($nopid = false)
{
    $sock = new sockets();
    $unix = new unix();
    $cachefile = "/usr/share/artica-postfix/ressources/logs/web/squidlogs.stats";
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $q = new mysql_squid_builder();
    if (!$nopid) {
        $pid = @file_get_contents($pidfile);
        if ($unix->process_exists($pid)) {
            echo "Starting......: " . date("H:i:s") . " cache manager, " . __FUNCTION__ . "() already running PID:{$pid}\n";
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    if ($GLOBALS["FORCE"]) {
        @unlink($cachefile);
    }
    if (is_file($cachefile)) {
        $time = $unix->file_time_min($cachefile);
        if ($time < 20) {
            if ($GLOBALS["VERBOSE"]) {
                echo "{$time}mn require 20mn\n";
            }
            return;
        }
    }
    $df = $unix->find_program("df");
    $sock = new sockets();
    $MYSQL_DATA_DIR = $q->MYSQL_DATA_DIR;
    if (is_dir("/opt/squidsql")) {
        $MYSQL_DATA_DIR = "/opt/squidsql";
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "MYSQL_DATA_DIR = {$MYSQL_DATA_DIR}\n";
    }
    if (!is_link("{$MYSQL_DATA_DIR}/{$q->database}")) {
        $realFolder = "{$MYSQL_DATA_DIR}";
    } else {
        $realFolder = readlink("{$MYSQL_DATA_DIR}");
    }
    $EXEC_NICE = $unix->EXEC_NICE();
    $cmdline = "{$EXEC_NICE}{$df} -h {$realFolder} 2>&1";
    if ($GLOBALS["VERBOSE"]) {
        echo __LINE__ . " {$cmdline}\n";
    }
    exec("{$df} -h {$realFolder} 2>&1", $results);
    $foldersize = $unix->DIRSIZE_BYTES($realFolder);
    while (list($num, $line) = each($results)) {
        if (!preg_match("#(.+?)\\s+([0-9A-Z\\.]+)\\s+([0-9A-Z\\.]+)\\s+([0-9A-Z\\.]+)\\s+([0-9\\.]+)%#", $line, $re)) {
            if ($GLOBALS["VERBOSE"]) {
                echo "{$line}, no match\n";
            }
            continue;
        }
        $array["squidlogs"]["DEV"] = $re[1];
        $array["squidlogs"]["SIZE"] = $re[2];
        $array["squidlogs"]["OC"] = $re[3];
        $array["squidlogs"]["DISP"] = $re[4];
        $array["squidlogs"]["POURC"] = $re[5];
        $array["squidlogs"]["REALPATH"] = $realFolder;
        $array["squidlogs"]["PATHSIZE"] = $foldersize;
        $array["squidlogs"]["TIME"] = time();
    }
    $TuningParameters = unserialize(base64_decode($sock->GET_INFO("MySQLSyslogParams")));
    $MySQLSyslogWorkDir = $sock->GET_INFO("MySQLSyslogWorkDir");
    if ($MySQLSyslogWorkDir == null) {
        $MySQLSyslogWorkDir = "/home/syslogsdb";
    }
    $q = new mysql_storelogs();
    $MYSQL_DATA_DIR = $MySQLSyslogWorkDir;
    if (!is_link("{$MYSQL_DATA_DIR}")) {
        $realFolder = "{$MYSQL_DATA_DIR}";
    } else {
        $realFolder = readlink("{$MYSQL_DATA_DIR}");
    }
    exec("{$df} -h {$realFolder} 2>&1", $results);
    if ($GLOBALS["VERBOSE"]) {
        echo __LINE__ . " {$cmdline}\n";
    }
    $foldersize = $unix->DIRSIZE_BYTES($realFolder);
    while (list($num, $line) = each($results)) {
        if (!preg_match("#(.+?)\\s+([0-9A-Z\\.]+)\\s+([0-9A-Z\\.]+)\\s+([0-9A-Z\\.]+)\\s+([0-9\\.]+)%#", $line, $re)) {
            continue;
        }
        $array["syslogstore"]["DEV"] = $re[1];
        $array["syslogstore"]["SIZE"] = $re[2];
        $array["syslogstore"]["OC"] = $re[3];
        $array["syslogstore"]["DISP"] = $re[4];
        $array["syslogstore"]["POURC"] = $re[5];
        $array["syslogstore"]["REALPATH"] = $realFolder;
        $array["syslogstore"]["PATHSIZE"] = $foldersize;
        $array["syslogstore"]["TIME"] = time();
    }
    print_r($array);
    @unlink($cachefile);
    @file_put_contents($cachefile, serialize($array));
    $unix->chmod_func(0777, $cachefile);
    if ($GLOBALS["VERBOSE"]) {
        echo __LINE__ . " " . __FUNCTION__ . " finish OK\n";
    }
}
function build()
{
    $unix = new unix();
    $sock = new sockets();
    $users = new usersMenus();
    $APACHE_MODULES_PATH = $users->APACHE_MODULES_PATH;
    if ($GLOBALS["OUTPUT"]) {
        echo "Configuring...: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Apache modules in \"{$APACHE_MODULES_PATH}\"\n";
    }
    $ZarafaApachePort = $sock->GET_INFO("ZarafaApachePort");
    $ZarafaApacheSSL = $sock->GET_INFO("ZarafaApacheSSL");
    $LighttpdArticaDisableSSLv2 = $sock->GET_INFO("LighttpdArticaDisableSSLv2");
    $ZarafaWebNTLM = $sock->GET_INFO("ZarafaWebNTLM");
    $ZarafaApacheServerName = $sock->GET_INFO("ZarafaApacheServerName");
    if (!is_numeric($ZarafaWebNTLM)) {
        $ZarafaWebNTLM = 0;
    }
    if (!is_numeric($LighttpdArticaDisableSSLv2)) {
        $LighttpdArticaDisableSSLv2 = 0;
    }
    if (!is_numeric($ZarafaApacheSSL)) {
        $ZarafaApacheSSL = 0;
    }
    if (!is_numeric($ZarafaApachePort)) {
        $ZarafaApachePort = 9010;
    }
    $ZarafaApachePHPFPMEnable = $sock->GET_INFO("ZarafaApachePHPFPMEnable");
    if (!is_numeric($ZarafaApachePHPFPMEnable)) {
        $ZarafaApachePHPFPMEnable = 0;
    }
    if ($ZarafaApacheServerName == null) {
        $ZarafaApacheServerName = $unix->hostname_g();
    }
    if (!is_dir('/usr/share/php/mapi')) {
        if (is_dir('/usr/local/share/php/mapi')) {
            @mkdir("/usr/share/php", 0755, true);
            shell_exec('/bin/ln -s /usr/local/share/php/mapi /usr/share/php/mapi');
        }
    }
    $username = $unix->APACHE_SRC_ACCOUNT();
    $group = $unix->APACHE_SRC_GROUP();
    if ($GLOBALS["OUTPUT"]) {
        echo "Configuring...: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} logs access: /var/log/apache-zarafa/access.log\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Configuring...: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} logs error : /var/log/apache-zarafa/error.log\n";
    }
    @unlink("/var/log/apache-zarafa/access.log");
    @unlink("/var/log/apache-zarafa/error.log");
    @touch("/var/log/apache-zarafa/access.log");
    @touch("/var/log/apache-zarafa/access.log");
    @mkdir("/var/run/apache2", 0755, true);
    @mkdir("/var/run/artica-apache", 0755, true);
    @mkdir('/var/run/zarafa-web', 0755, true);
    @mkdir('/var/log/apache-zarafa', 0755, true);
    @mkdir('/var/lib/zarafa-webaccess/tmp', 0755, true);
    $unix->chown_func($username, $group, "/var/log/apache-zarafa/access.log");
    $unix->chown_func($username, $group, "/var/log/apache-zarafa/error.log");
    $unix->chown_func($username, $group, "/var/run/apache2");
    $unix->chown_func($username, $group, "/var/run/artica-apache");
    $unix->chown_func($username, $group, "/var/run/zarafa-web");
    $unix->chown_func($username, $group, "/var/log/apache-zarafa");
    $unix->chown_func($username, $group, "/var/lib/zarafa-webaccess");
    $unix->chmod_func(0777, "/var/lib/zarafa-webaccess/tmp");
    $unix->chown_func($username, $group, "/usr/share/zarafa-webaccess/plugins/*");
    if ($ZarafaApacheSSL == 1) {
        if (is_file("{$APACHE_MODULES_PATH}/mod_ssl.so")) {
            if (!is_file("/etc/ssl/certs/zarafa/apache.crt.nopass.cert")) {
                shell_exec("/usr/share/artica-postfix/bin/artica-install --zarafa-apache-certificates");
            }
            $f[] = "LoadModule ssl_module /usr/lib/apache2/modules/mod_ssl.so";
            $f[] = "SSLEngine on";
            $f[] = "SSLCertificateFile /etc/ssl/certs/zarafa/apache.crt.nopass.cert";
            $f[] = "SSLCertificateKeyFile /etc/ssl/certs/zarafa/apache-ca.key.nopass.key";
            if ($LighttpdArticaDisableSSLv2 == 1) {
                $f[] = "SSLProtocol -ALL +SSLv3 +TLSv1";
                $f[] = "SSLCipherSuite ALL:!aNULL:!ADH:!eNULL:!LOW:!EXP:RC4+RSA:+HIGH:+MEDIUM";
            }
            $f[] = "SSLRandomSeed connect builtin";
            $f[] = "SSLRandomSeed startup file:/dev/urandom  256";
            $f[] = "SSLRandomSeed connect file:/dev/urandom 256";
            $f[] = "AddType application/x-x509-ca-cert .crt";
            $f[] = "AddType application/x-pkcs7-crl    .crl";
            $f[] = "SSLPassPhraseDialog  builtin";
            $f[] = "SSLSessionCache        shmcb:/var/run/apache2/ssl_scache-zarafa(512000)";
            $f[] = "SSLSessionCacheTimeout  300";
            $f[] = "SSLVerifyClient none";
            $f[] = "ServerSignature Off";
        }
    }
    $SET_MODULES = SET_MODULES();
    $FreeWebPerformances = unserialize(base64_decode($sock->GET_INFO("ZarafaApachePerformances")));
    if (!is_numeric($FreeWebPerformances["Timeout"])) {
        $FreeWebPerformances["Timeout"] = 300;
    }
    if (!is_numeric($FreeWebPerformances["KeepAlive"])) {
        $FreeWebPerformances["KeepAlive"] = 0;
    }
    if (!is_numeric($FreeWebPerformances["MaxKeepAliveRequests"])) {
        $FreeWebPerformances["MaxKeepAliveRequests"] = 100;
    }
    if (!is_numeric($FreeWebPerformances["KeepAliveTimeout"])) {
        $FreeWebPerformances["KeepAliveTimeout"] = 15;
    }
    if (!is_numeric($FreeWebPerformances["MinSpareServers"])) {
        $FreeWebPerformances["MinSpareServers"] = 5;
    }
    if (!is_numeric($FreeWebPerformances["MaxSpareServers"])) {
        $FreeWebPerformances["MaxSpareServers"] = 10;
    }
    if (!is_numeric($FreeWebPerformances["StartServers"])) {
        $FreeWebPerformances["StartServers"] = 5;
    }
    if (!is_numeric($FreeWebPerformances["MaxClients"])) {
        $FreeWebPerformances["MaxClients"] = 50;
    }
    if (!is_numeric($FreeWebPerformances["MaxRequestsPerChild"])) {
        $FreeWebPerformances["MaxRequestsPerChild"] = 10000;
    }
    $f[] = "Timeout              {$FreeWebPerformances["Timeout"]}";
    $f[] = "KeepAlive            {$FreeWebPerformances["KeepAlive"]}";
    $f[] = "KeepAliveTimeout     {$FreeWebPerformances["KeepAliveTimeout"]}";
    $f[] = "StartServers         {$FreeWebPerformances["StartServers"]}";
    $f[] = "MaxClients           {$FreeWebPerformances["MaxClients"]}";
    $f[] = "MinSpareServers      {$FreeWebPerformances["MinSpareServers"]}";
    $f[] = "MaxSpareServers      {$FreeWebPerformances["MaxSpareServers"]}";
    $f[] = "MaxRequestsPerChild  {$FreeWebPerformances["MaxRequestsPerChild"]}";
    $f[] = "MaxKeepAliveRequests {$FreeWebPerformances["MaxKeepAliveRequests"]}";
    $f[] = "ServerLimit\t\t   {$FreeWebPerformances["MaxClients"]}";
    $f[] = "AcceptMutex \t\t  flock";
    $ZarafaApacheWebMailType = $sock->GET_INFO("ZarafaApacheWebMailType");
    //$ZarafaApacheWebMailTypeA["APP_ZARAFA"]="{APP_ZARAFA}";
    //$ZarafaApacheWebMailTypeA["APP_ZARAFA_WEBAPP"]="{APP_ZARAFA_WEBAPP}";
    if ($ZarafaApacheWebMailType == null) {
        $ZarafaApacheWebMailType = "APP_ZARAFA";
    }
    $f[] = $SET_MODULES;
    $f[] = "<IfModule !mpm_netware_module>";
    $f[] = "          <IfModule !mpm_winnt_module>";
    $f[] = "             User {$username}";
    $f[] = "             Group {$group}";
    $f[] = "          </IfModule>";
    $f[] = "</IfModule>";
    $f[] = "ServerAdmin you@example.com";
    $f[] = "ServerName {$ZarafaApacheServerName}";
    if ($ZarafaApacheWebMailType == "APP_ZARAFA_WEBAPP") {
        if (!is_dir("/usr/share/zarafa-webapp")) {
            $ZarafaApacheWebMailType = "APP_ZARAFA";
        }
    }
    if ($ZarafaApacheWebMailType == "APP_ZARAFA") {
        $DocumentRoot = "/usr/share/zarafa-webaccess";
    }
    if ($ZarafaApacheWebMailType == "APP_ZARAFA_WEBAPP") {
        $free = new freeweb();
        $free->InstallZarafaConfigWebAPP("/usr/share/zarafa-webapp");
        $DocumentRoot = "/usr/share/zarafa-webapp";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Configuring...: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} WebMail \"{$ZarafaApacheWebMailType}\"\n";
    }
    $f[] = "ServerRoot \"{$DocumentRoot}\"";
    $f[] = "Listen {$ZarafaApachePort}";
    $f[] = "User {$username}";
    $f[] = "Group {$group}";
    $f[] = "PidFile /var/run/zarafa-web/httpd.pid";
    $f[] = "DocumentRoot \"{$DocumentRoot}\"";
    $f[] = "<Directory {$DocumentRoot}/>";
    if ($ZarafaWebNTLM == 1) {
        $ldap = new clladp();
        $f[] = "    AuthName \"Zarafa logon..\"";
        $f[] = "    AuthType Basic";
        $f[] = "    AuthLDAPURL ldap://{$ldap->ldap_host}:{$ldap->ldap_port}/dc=organizations,{$ldap->suffix}?uid";
        $f[] = "    AuthLDAPBindDN cn={$ldap->ldap_admin},{$ldap->suffix}";
        $f[] = "    AuthLDAPBindPassword {$ldap->ldap_password}";
        $f[] = "    AuthLDAPGroupAttribute memberUid";
        $f[] = "    AuthBasicProvider ldap";
        $f[] = "    AuthzLDAPAuthoritative off";
        $f[] = "    require valid-user";
    }
    if ($ZarafaApachePHPFPMEnable == 0) {
        $f[] = "    php_value magic_quotes_gpc 0";
        $f[] = "    php_value register_globals 0";
        $f[] = "    php_value magic_quotes_runtime 0";
        $f[] = "    php_value post_max_size 31M";
        $f[] = "    php_value include_path  \".:/usr/share/php:/usr/share/php5:/usr/local/share/php\"";
        $f[] = "    php_value upload_max_filesize 30M";
        $f[] = "    php_value short_open_tag 1";
        $f[] = "    php_flag log_errors on";
        $f[] = "    php_value safe_mode 0";
        $f[] = "    php_flag log_errors on";
        $f[] = "    php_value  error_log  \"/var/log/apache-zarafa/php.log\"";
    }
    $f[] = "    DirectoryIndex index.php";
    $f[] = "    Options -Indexes +FollowSymLinks";
    $f[] = "    AllowOverride Options";
    $f[] = "    Order allow,deny";
    $f[] = "    Allow from all";
    $f[] = "</Directory>";
    if ($ZarafaApachePHPFPMEnable == 1) {
        $php = $unix->LOCATE_PHP5_BIN();
        if (!$unix->is_socket("/var/run/php-fpm-zarafa.sock")) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: /var/run/php-fpm-zarafa.sock no such socket\n";
            }
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Activate PHP5-FPM\n";
            }
            shell_exec("{$php} /usr/share/artica-postfix/exec.initslapd.php --phppfm");
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Restarting PHP5-FPM\n";
            }
            shell_exec("/etc/init.d/php5-fpm restart");
        }
        $f[] = "\tAlias /php5.fastcgi /var/run/artica-apache/php5.fastcgi";
        $f[] = "\tAddHandler php-script .php";
        $f[] = "\tFastCGIExternalServer /var/run/artica-apache/php5.fastcgi -socket /var/run/php-fpm-zarafa.sock -idle-timeout 610";
        $f[] = "\tAction php-script /php5.fastcgi virtual";
        $f[] = "\t<Directory /var/run/artica-apache>";
        $f[] = "\t\t<Files php5.fastcgi>";
        $f[] = "\t\tOrder deny,allow";
        $f[] = "\t\tAllow from all";
        $f[] = "\t\t</Files>";
        $f[] = "\t</Directory>";
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Configuring...: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} PHP5-FPM is disabled\n";
        }
    }
    $f[] = "<IfModule dir_module>";
    $f[] = "    DirectoryIndex index.php";
    $f[] = "</IfModule>";
    $f[] = "";
    $f[] = "";
    $f[] = "<FilesMatch \"^\\.ht\">";
    $f[] = "    Order allow,deny";
    $f[] = "    Deny from all";
    $f[] = "    Satisfy All";
    $f[] = "</FilesMatch>";
    $f[] = "<IfModule mod_php5.c>";
    $f[] = "    <FilesMatch \"\\.ph(p3?|tml)\$\">";
    $f[] = "\tSetHandler application/x-httpd-php";
    $f[] = "    </FilesMatch>";
    $f[] = "    <FilesMatch \"\\.phps\$\">";
    $f[] = "\tSetHandler application/x-httpd-php-source";
    $f[] = "    </FilesMatch>";
    $f[] = "    # To re-enable php in user directories comment the following lines";
    $f[] = "    # (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it";
    $f[] = "    # prevents .htaccess files from disabling it.";
    $f[] = "    <IfModule mod_userdir.c>";
    $f[] = "        <Directory /home/*/public_html>";
    $f[] = "            php_admin_value engine Off";
    $f[] = "        </Directory>";
    $f[] = "    </IfModule>";
    $f[] = "</IfModule>";
    $f[] = "";
    $f[] = "";
    $f[] = "ErrorLog \"/var/log/apache-zarafa/error.log\"";
    $f[] = "LogLevel warn";
    $f[] = "";
    $f[] = "<IfModule log_config_module>";
    $f[] = "    LogFormat \"%h %l %u %t \\\"%r\\\" %>s %b \\\"%{Referer}i\\\" \\\"%{User-Agent}i\\\" %V\\\" combinedv";
    $f[] = "    LogFormat \"%h %l %u %t \\\"%r\\\" %>s %b\" common";
    $f[] = "";
    $f[] = "    <IfModule logio_module>";
    $f[] = "      LogFormat \"%h %l %u %t \\\"%r\\\" %>s %b \\\"%{Referer}i\\\" \\\"%{User-Agent}i\\\" %I %O\" combinedio";
    $f[] = "    </IfModule>";
    $f[] = "";
    $f[] = "    CustomLog \"/var/log/apache-zarafa/access.log\" combinedv";
    $f[] = "</IfModule>";
    $f[] = "";
    $f[] = "<IfModule alias_module>";
    $f[] = "    ScriptAlias /cgi-bin/ \"/usr/local/apache-groupware/data/cgi-bin/\"";
    $f[] = "    Alias /images /usr/share/obm2/resources";
    $f[] = "";
    $f[] = "</IfModule>";
    $f[] = "";
    $f[] = "<IfModule cgid_module>";
    $f[] = "";
    $f[] = "</IfModule>";
    $f[] = "";
    $f[] = "";
    $f[] = "<Directory \"/usr/local/apache-groupware/data/cgi-bin\">";
    $f[] = "    AllowOverride None";
    $f[] = "    Options None";
    $f[] = "    Order allow,deny";
    $f[] = "    Allow from all";
    $f[] = "</Directory>";
    $f[] = "";
    $f[] = "";
    $f[] = "DefaultType text/plain";
    $f[] = "";
    $f[] = "<IfModule mime_module>";
    $f[] = "   ";
    $f[] = "    TypesConfig /etc/mime.types";
    $f[] = "    #AddType application/x-gzip .tgz";
    $f[] = "    AddType application/x-compress .Z";
    $f[] = "    AddType application/x-gzip .gz .tgz";
    $f[] = "    AddType application/x-httpd-php .php .phtml";
    $f[] = "    #AddHandler cgi-script .cgi";
    $f[] = "    #AddHandler type-map var";
    $f[] = "    #AddType text/html .shtml";
    $f[] = "    #AddOutputFilter INCLUDES .shtml";
    $f[] = "</IfModule>";
    @file_put_contents('/etc/zarafa/httpd.conf', @implode("\n", $f) . "\n");
    if ($GLOBALS["OUTPUT"]) {
        echo "Configuring...: " . date("H:i:s") . " /etc/zarafa/httpd.conf done\n";
    }
}
Beispiel #15
0
function TestingApacheConfigurationFile()
{
    CheckLibraries();
    $unix = new unix();
    $prefixOutput = "Starting......: " . date("H:i:s") . " [INIT]: Apache Check";
    $httpdconf = $GLOBALS["CLASS_UNIX"]->LOCATE_APACHE_CONF_PATH();
    $apache2ctl = $GLOBALS["CLASS_UNIX"]->LOCATE_APACHE_CTL();
    $unix->chmod_func(0755, "/etc/apache2/sites-enabled/*");
    if (!is_file($apache2ctl)) {
        return true;
    }
    exec("{$apache2ctl} -f {$httpdconf} -S 2>&1", $results);
    echo "{$prefixOutput} [" . __LINE__ . "] verify configuration...\n";
    while (list($index, $line) = each($results)) {
        echo "{$prefixOutput} [" . __LINE__ . "] `{$line}`\n";
        if (preg_match("#Syntax error on line ([0-9]+) of (.+?):#", $line, $re)) {
            @copy($re[2], "/root/" . basename($re[2]));
            echo "{$prefixOutput} [" . __LINE__ . "] `" . basename($re[2]) . "` as been copied in /root...\n";
        }
        if (preg_match("#Syntax OK#i", $line)) {
            echo "{$prefixOutput} [" . __LINE__ . "] Syntax OK...\n";
            return true;
        }
    }
    echo "{$prefixOutput} [" . __LINE__ . "] Syntax Failed !!!...\n";
    @file_put_contents("/etc/artica-postfix/settings/Daemons/ApacheLastError", @implode("\n", $results));
}
function CheckArticaFolderSecurity($username, $groupname)
{
    $unix = new unix();
    $artica_path = "/usr/share/artica-postfix";
    $GLOBALS["LogFileDeamonLogDir"] = @file_get_contents("/etc/artica-postfix/settings/Daemons/LogFileDeamonLogDir");
    if ($GLOBALS["LogFileDeamonLogDir"] == null) {
        $GLOBALS["LogFileDeamonLogDir"] = "/home/artica/squid/realtime-events";
    }
    if (is_file("/usr/local/ArticaStats/bin/postgres")) {
        $GLOBALS["LogFileDeamonLogDir"] = @file_get_contents("/etc/artica-postfix/settings/Daemons/LogFileDeamonLogPostGresDir");
        if ($GLOBALS["LogFileDeamonLogDir"] == null) {
            $GLOBALS["LogFileDeamonLogDir"] = "/home/artica/squid-postgres/realtime-events";
        }
    }
    $fSquidDirs[] = "/var/log/squid/squid_admin_mysql";
    $fSquidDirs[] = "/usr/share/squid3";
    $fSquidDirs[] = $GLOBALS["LogFileDeamonLogDir"];
    while (list($num, $directory) = each($fSquidDirs)) {
        if (!is_dir($directory)) {
            @mkdir($directory, 0755, true);
        }
        @chown($directory, "squid");
        @chgrp($directory, "squid");
    }
    $squidfiles = $unix->SquidPHPFiles();
    $files = $unix->DirFiles($artica_path);
    while (list($filename, $line) = each($files)) {
        if (is_numeric($filename)) {
            @unlink("{$artica_path}/{$filename}");
            continue;
        }
        if (isset($squidfiles[$filename])) {
            @chmod("{$artica_path}/{$filename}", 0755);
            @chgrp("{$artica_path}/{$filename}", "squid");
            @chown("{$artica_path}/{$filename}", "squid");
            continue;
        }
        $unix->chown_func($username, $groupname, "{$artica_path}/{$filename}");
        $unix->chmod_func(0755, "{$artica_path}/{$filename}");
    }
    $unix->chmod_func(0755, "/var/log/squid/access.log");
    $unix->chmod_func(0777, "/var/log/squid/QUOTADB.db");
}
Beispiel #17
0
function squid_k_reconfigure()
{
    $unix = new unix();
    $squid = $unix->LOCATE_SQUID_BIN();
    $force = null;
    if (isset($_GET["force"])) {
        $force = " --force";
    }
    squid_watchdog_events("Reconfiguring Proxy parameters...");
    SQUID_REFRESH_PANEL_STATUS();
    $statusfile = $GLOBALS["SQUID_REFRESH_PANEL_STATUS"];
    $unix->chmod_func(0755, "/etc/artica-postfix/settings/Daemons/*");
    if (isset($_GET["ApplyConfToo"])) {
        $php5 = $unix->LOCATE_PHP5_BIN();
        $nohup = $unix->find_program("nohup");
        $cmd = "{$nohup} {$php5} /usr/share/artica-postfix/exec.squid.php --build{$force} >> {$GLOBALS["SQUID_REFRESH_PANEL_STATUS"]} 2>&1 &";
        squid_admin_mysql(2, "Framework executed to reconfigure squid-cache", @file_get_contents($statusfile));
        writelogs_framework("{$cmd}", __FUNCTION__, __FILE__, __LINE__);
        shell_exec($cmd);
        return;
    }
    shell_exec("{$nohup} {$php5} /usr/share/artica-postfix/exec.squid.php --kreconfigure >> {$GLOBALS["SQUID_REFRESH_PANEL_STATUS"]} 2>&1");
    squid_admin_mysql(2, "Framework executed to reconfigure squid-cache", @file_get_contents($statusfile));
    sleep(2);
    $tail = $unix->find_program("tail");
    shell_exec("{$tail} -n 100 /var/log/squid/cache.log >> {$statusfile} 2>&1");
}
Beispiel #18
0
function chown_medir()
{
    $dir = base64_decode($_GET["chown-medir"]);
    $unix = new unix();
    $APACHE = $unix->APACHE_SRC_ACCOUNT();
    $APACHE_GROUP = $unix->APACHE_SRC_GROUP();
    @mkdir("/etc/artica-postfix/settings/Daemons", 0755, true);
    @mkdir("/usr/share/artica-postfix/ressources/logs", 0755, true);
    $f[] = "/etc/artica-postfix/settings/Daemons";
    $f[] = "/usr/share/artica-postfix/ressources/logs";
    if ($dir != null) {
        $f[] = $dir;
    }
    while (list($key, $directory) = each($f)) {
        writelogs_framework("Permissions on `{$directory}` for {$APACHE}:{$APACHE_GROUP}", __FUNCTION__, __FILE__, __LINE__);
        @mkdir($directory, 0755, true);
        $unix->chown_func($APACHE, null, $directory);
        $unix->chown_func($APACHE, null, "{$directory}/*");
        $unix->chmod_func(0755, "{$directory}");
        $unix->chmod_func(0755, "{$directory}/*");
    }
    if ($dir == null) {
        return;
    }
    @chown($dir, $APACHE);
    @chgrp($dir, $APACHE_GROUP);
}
Beispiel #19
0
function webdbs()
{
    $unix = new unix();
    @touch("/temp/toot");
    $unix->chmod_func(0777, "/temp/toot");
    $unix->chmod_func(0640, "/temp/toot");
    $cicap = new cicap_squidguard();
    $cicap->Construct_personal_categories();
    reload(true);
}