function dump()
{
    $unix = new unix();
    if (!$unix->is_socket("/var/run/syslogdb.sock")) {
        return false;
    }
    $bd = @mysql_connect(":/var/run/syslogdb.sock", "root");
    if (!$bd) {
        return;
    }
    $ok = @mysql_select_db("syslogs", $bd);
    $results = QUERY_SQLZ("SELECT storeid,filename FROM accesslogs");
    if (!$results) {
        return false;
    }
    while ($ligne = mysql_fetch_assoc($results)) {
        $storeid = $ligne["storeid"];
        $filename = $ligne["filename"];
        if (!export_storeid_access($storeid, $filename)) {
            continue;
        }
    }
}
    $GLOBALS["VERBOSE"] = true;
    ini_set('display_errors', 1);
    ini_set('error_reporting', E_ALL);
    ini_set('error_prepend_string', null);
    ini_set('error_append_string', null);
}
include_once "{$dirname}/ressources/class.templates.inc";
include_once "{$dirname}/ressources/class.users.menus.inc";
include_once "{$dirname}/ressources/class.squid.inc";
include_once "{$dirname}/ressources/class.status.inc";
include_once "{$dirname}/ressources/class.artica.graphs.inc";
include_once "{$dirname}/ressources/class.mysql.syslogs.inc";
if ($GLOBALS["AS_ROOT"]) {
    include_once "/usr/share/artica-postfix/framework/class.unix.inc";
    $unix = new unix();
    if (!$unix->is_socket("/var/run/mysqld/articadb.sock")) {
        die;
    }
}
if (!$GLOBALS["AS_ROOT"]) {
    $users = new usersMenus();
    if (!$users->AsWebStatisticsAdministrator) {
        die("Permission denied");
    }
}
if ($argv[1] == "squid-status-stats") {
    squid_status_stats();
    exit;
}
if (isset($_GET["status"])) {
    status();
示例#3
0
function RestoreFromBackup($backuppath)
{
    $unix = new unix();
    $PidRestore = "/etc/artica-postfix/pids/zarafaRestore.pid";
    $rm = $unix->find_program("rm");
    $pid = $unix->get_pid_from_file($PidRestore);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Restore Task Already running PID {$pid} since {$time}mn\n";
        }
        return;
    }
    $pid = $unix->PIDOF_PATTERN("exec.zarafa-db.php --restorefrom");
    if ($pid != getmypid()) {
        if ($unix->process_exists($pid)) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: Restore Task Already running PID {$pid} since {$time}mn\n";
            }
            return;
        }
    }
    $mysql = $unix->find_program("mysql");
    $pid = $unix->PIDOF_PATTERN("{$mysql}\\s+.*?--socket=/var/run/mysqld/zarafa-db.sock.*?database=zarafa");
    if ($unix->process_exists($pid)) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Restore Task Already running PID {$pid} since {$time}mn\n";
        }
        return;
    }
    @file_put_contents($PidRestore, getmypid());
    $sock = new sockets();
    $SourceDir = dirname($backuppath);
    $WORKDIR = $sock->GET_INFO("ZarafaDedicateMySQLWorkDir");
    if ($WORKDIR == null) {
        $WORKDIR = "/home/zarafa-db";
    }
    if (is_file("{$SourceDir}/ldap.ldif")) {
        RestoreFromBackup_progress("{restore_ldap_database}", 10);
        RestoreFromBackup_ldap("{$SourceDir}/ldap.ldif");
    }
    $unix = new unix();
    if (!is_file($backuppath)) {
        echo "Action: `{$backuppath}` no such file: ABORT!\n";
        RestoreFromBackup_progress("{failed}", 100);
        return;
    }
    echo "Action: Removing Zarafa Database MySQL client `{$mysql}`....\n";
    RestoreFromBackup_progress("Removing Zarafa Database", 30);
    $cmd = "{$mysql} --socket=/var/run/mysqld/zarafa-db.sock --protocol=socket --user=root --batch --debug-info --database=zarafa --execute=\"DROP DATABASE zarafa\" 2>&1";
    $results = array();
    exec("{$cmd}", $results);
    while (list($num, $ligne) = each($results)) {
        echo "MySQL: (Delete Database) {$ligne}\n";
    }
    RestoreFromBackup_progress("Removing all content", 32);
    if (is_dir("{$WORKDIR}/data/zarafa")) {
        recursive_remove_directory("{$WORKDIR}");
    }
    RestoreFromBackup_progress("Restarting MySQL service (recovery)", 40);
    echo "Action: Restarting MySQL service...\n";
    echo "Action: Stopping MySQL service...\n";
    stop(true);
    echo "Action: Starting MySQL service (InnoDB recovery mode)...\n";
    start(true, true);
    while (list($num, $ligne) = each($results)) {
        echo "Service: {$ligne}\n";
    }
    sleep(5);
    $ZARAFADB_PID = ZARAFADB_PID();
    if (!$unix->process_exists($ZARAFADB_PID)) {
        RestoreFromBackup_progress("Failed to restart dedicated MySQL", 100);
        return;
    }
    RestoreFromBackup_progress("Stopping Zarafa server", 43);
    @unlink("/tmp/zarafa-upgrade-lock");
    shell_exec("/etc/init.d/zarafa-server stop --force");
    $pid = XZARAFA_SERVER_PID();
    if ($unix->process_exists($pid)) {
        $kill = $unix->find_program("kill");
        unix_system_kill_force($pid);
    }
    RestoreFromBackup_progress("Restarting MySQL service (normal)", 45);
    echo "Action: Restarting MySQL service...\n";
    echo "Action: Stopping MySQL service...\n";
    stop(true);
    echo "Action: Starting MySQL service (InnoDB normal mode)...\n";
    start(true, false);
    while (list($num, $ligne) = each($results)) {
        echo "Service: {$ligne}\n";
    }
    sleep(2);
    $ZARAFADB_PID = ZARAFADB_PID();
    if (!$unix->process_exists($ZARAFADB_PID)) {
        RestoreFromBackup_progress("Failed to restart dedicated MySQL", 100);
        return;
    }
    if (!$unix->is_socket("/var/run/mysqld/zarafa-db.sock")) {
        echo "Action: /var/run/mysqld/zarafa-db.sock waiting socket\n";
        for ($i = 0; $i < 5; $i++) {
            if ($unix->is_socket("/var/run/mysqld/zarafa-db.sock")) {
                break;
            }
            echo "Action: Waiting zarafa-db.sock {$i}/4\n";
            sleep(1);
        }
    }
    if (!$unix->is_socket("/var/run/mysqld/zarafa-db.sock")) {
        echo "Action: /var/run/mysqld/zarafa-db.sock no such socket\n";
        RestoreFromBackup_progress("zarafa-db.sock no such socket", 100);
        return;
    }
    echo "Action: /var/run/mysqld/zarafa-db.sock OK\n";
    echo "Action: create a freshed Zarafa database\n";
    $ZarafaIndexPath = $sock->GET_INFO("ZarafaIndexPath");
    if ($ZarafaIndexPath == null) {
        $ZarafaIndexPath = "/var/lib/zarafa/index";
    }
    RestoreFromBackup_progress("Cleaning/Stopping Zarafa search DBs", 50);
    if (is_dir($ZarafaIndexPath)) {
        recursive_remove_directory("{$ZarafaIndexPath}");
        shell_exec("/etc/init.d/zarafa-search stop");
    }
    RestoreFromBackup_progress("Create a freshed Zarafa database", 50);
    $results = array();
    $cmd = "{$mysql} --socket=/var/run/mysqld/zarafa-db.sock --protocol=socket --user=root --batch --debug-info --execute=\"CREATE DATABASE zarafa\" 2>&1";
    $results = array();
    exec("{$cmd}", $results);
    while (list($num, $ligne) = each($results)) {
        echo "MySQL: (Create Database) {$ligne}\n";
    }
    RestoreFromBackup_progress("Testing Database...", 51);
    if (!is_dir("{$WORKDIR}/data/zarafa")) {
        echo "Action: FAILED TO create a freshed Zarafa database: ABORT!!\n";
        echo "Action: {$WORKDIR}/data/zarafa no such directory\n";
        RestoreFromBackup_progress("FAILED to create a freshed Zarafa database", 100);
        return;
    }
    RestoreFromBackup_progress("Checks Database size", 53);
    databasesize(true);
    $gunzip = $unix->find_program("gunzip");
    $SourceFileBase = basename($backuppath);
    $file_ext = $unix->file_ext($SourceFileBase);
    $tStart = time();
    $nohup = $unix->find_program("nohup");
    $backuppath1 = $unix->shellEscapeChars($backuppath);
    $cmd = "{$nohup} {$mysql} --show-warnings --socket=/var/run/mysqld/zarafa-db.sock --protocol=socket --user=root --batch --debug-info --database=zarafa < {$backuppath1} >/root/mysqllog.txt 2>&1 &";
    echo "Action: {$SourceFileBase} extension {$file_ext}\n";
    echo "Action: Restoring From {$backuppath1}\n";
    if ($file_ext == "gz") {
        echo "Action: Restoring From {$backuppath1} with uncompress..\n";
        $cmd = "{$nohup} {$gunzip} -c {$backuppath1} |{$mysql} --show-warnings --socket=/var/run/mysqld/zarafa-db.sock --protocol=socket --user=root --batch --debug-info --database=zarafa >/root/mysqllog.txt 2>&1 &";
    }
    $size = @filesize($backuppath);
    $size = FormatBytes($size / 1024);
    echo "Action: Please wait, it should take time...\nAction: Do not shutdown the computer or restart the MySQL service!\n";
    $results = array();
    RestoreFromBackup_progress("{restoring_data} {$size} {please_wait} !", 70);
    $lastmd5 = null;
    $continue = true;
    shell_exec($cmd);
    $ALRDLO = array();
    while ($continue) {
        $fileMD5 = @md5_file("/root/mysqllog.txt");
        if ($fileMD5 != $lastmd5) {
            $LOGS = explode("\n", @file_get_contents("/root/mysqllog.txt"));
            while (list($num, $ligne) = each($LOGS)) {
                if (trim($ligne) == null) {
                    continue;
                }
                if (isset($ALRDLO[md5($ligne)])) {
                    continue;
                }
                $ALRDLO[md5($ligne)] = true;
                if (preg_match("#ERROR\\s+([0-9]+)\\s+\\(#", $ligne, $re)) {
                    echo date("Y-m-d H:i:s") . " MySQL: FAILED !!! {$ligne}\n";
                    RestoreFromBackup_progress("{failed} {error} {$re[1]} ", 100);
                    return;
                }
                echo date("Y-m-d H:i:s") . " MySQL: {$ligne}\n";
            }
            $lastmd5 = $fileMD5;
        }
        $pid = $unix->PIDOF_PATTERN("{$mysql}\\s+.*?--socket=/var/run/mysqld/zarafa-db.sock.*?database=zarafa");
        echo "Action: PID: {$pid}\n";
        if (!$unix->process_exists($pid)) {
            echo "Action: injection stopped running since " . $unix->distanceOfTimeInWords($tStart, time(), true) . "\n";
            $continue = false;
            break;
        }
        echo "Action: PID {$pid} running since " . $unix->distanceOfTimeInWords($tStart, time(), true) . ", please wait...\n";
        RestoreFromBackup_progress($unix->distanceOfTimeInWords($tStart, time(), true) . " {please_wait} !", 71);
        $continue = true;
        sleep(30);
        continue;
    }
    echo "Action: Done, took: " . $unix->distanceOfTimeInWords($tStart, time(), true) . "\n";
    echo "Action: Please wait, Checks Database size\n";
    RestoreFromBackup_progress("Checks Database size", 75);
    databasesize(true);
    RestoreFromBackup_progress("{restoring_data} {success}", 80);
    echo "Action: restart_services\n";
    RestoreFromBackup_progress("{restart_services}", 90);
    $unix->THREAD_COMMAND_SET("/etc/init.d/zarafa-server restart");
    echo "Action: Restore task done...\n";
    echo "Action: You can close the windows now...\n";
    RestoreFromBackup_progress("{done}", 100);
    die;
}
示例#4
0
function start($aspid = false)
{
    $unix = new unix();
    $sock = new sockets();
    $Masterbin = $unix->CYRUS_DAEMON_BIN_PATH();
    $zarafaBin = $unix->find_program("zarafa-server");
    if (!is_file($Masterbin)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, arpd not installed\n";
        }
        return;
    }
    if (!$aspid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = $unix->get_pid_from_file($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    if ($unix->process_exists($unix->get_pid_from_file("/etc/artica-postfix/artica-backup.pid"))) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} A backup task currently is in use\n";
        }
        return;
    }
    $pid = PID_NUM();
    if ($unix->process_exists($pid)) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Service already started {$pid} since {$timepid}Mn...\n";
        }
        return;
    }
    if (is_file("/etc/artica-postfix/stop.cyrus.imapd")) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} LOCKED !\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Remove /etc/artica-postfix/stop.cyrus.imapd !\n";
        }
        return;
    }
    if (is_file("/etc/artica-postfix/cyrus-stop")) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} LOCKED !\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Remove /etc/artica-postfix/cyrus-stop !\n";
        }
        return;
    }
    $unix->CreateUnixUser("postfix", "postfix");
    $php5 = $unix->LOCATE_PHP5_BIN();
    $EnableCyrusImap = $sock->GET_INFO("EnableCyrusImap");
    if (!is_numeric($EnableCyrusImap)) {
        $EnableCyrusImap = 1;
    }
    $DisableMessaging = intval($sock->GET_INFO("DisableMessaging"));
    $DisableIMAPVerif = intval($sock->GET_INFO("DisableIMAPVerif"));
    if ($DisableIMAPVerif == 0) {
        if (is_file("{$zarafaBin}")) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Zarafa is installed, aborting\n";
            }
            stop(true);
            return;
        }
    }
    if ($EnableCyrusImap == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service disabled (see EnableCyrusImap)\n";
        }
        return;
    }
    if ($DisableMessaging == 1) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service disabled (see DisableMessaging)\n";
        }
        return;
    }
    if (!is_file('/usr/bin/cyradm')) {
        $cyradm = $unix->CYRADM_PATH();
        if (is_file($cyradm)) {
            shell_exec("/bin/ln -s {$cyradm} /usr/bin/cyradm");
        }
    }
    if (is_file('/usr/share/artica-postfix/exec.imapd.conf.php')) {
        shell_exec("{$php5} /usr/share/artica-postfix/exec.imapd.conf.php >/dev/null 2>&1");
    }
    if (!is_file('/etc/artica-postfix/cyrus.check.time')) {
        shell_exec("/usr/share/artica-postfix/bin/artica-install --cyrus-rights >/dev/null 2>&1");
    }
    shell_exec("{$php5} /usr/share/artica-postfix/exec.check-cyrus-account.php --check-adms");
    $sysctl = $unix->find_program("sysctl");
    $echo = $unix->find_program("echo");
    $nohup = $unix->find_program("nohup");
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Check permissions\n";
    }
    CheckPermissions();
    BuildConfig();
    $params[] = "{$nohup} {$Masterbin}";
    $params[] = "-M /etc/cyrus.conf";
    $params[] = "-C /etc/imapd.conf";
    $params[] = "-p /var/run/cyrmaster.pid -d >/dev/null 2>&1 &";
    $cmd = @implode(" ", $params);
    shell_exec($cmd);
    for ($i = 1; $i < 5; $i++) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Waiting {$i}/5\n";
        }
        sleep(1);
        $pid = PID_NUM();
        if ($unix->process_exists($pid)) {
            break;
        }
    }
    $pid = PID_NUM();
    if ($unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Success PID {$pid}\n";
        }
        $lmtpsocket = "/var/spool/postfix/var/run/cyrus/socket/lmtp";
        for ($i = 1; $i < 5; $i++) {
            if ($unix->is_socket($lmtpsocket)) {
                if ($GLOBALS["OUTPUT"]) {
                    echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Waiting socket success..\n";
                }
                $unix->chown_func("postfix", "postfix", "/var/spool/postfix/var/run");
                $unix->chown_func("postfix", "postfix", "{$lmtpsocket}");
                break;
            }
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Waiting socket {$i}/5\n";
            }
            sleep(1);
        }
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Failed\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} {$cmd}\n";
        }
    }
}
示例#5
0
function FreeMem($aspid = false, $SwapOffOn = array())
{
    $unix = new unix();
    if (!$aspid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = @file_get_contents($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            if ($GLOBALS["VERBOSE"]) {
                echo "Already executed pid {$pid}\n";
            }
            return;
        }
    }
    if (count($SwapOffOn) == 0) {
        $sock = new sockets();
        $SwapOffOn = unserialize(base64_decode($sock->GET_INFO("SwapOffOn")));
        if (!is_numeric($SwapOffOn["AutoMemWatchdog"])) {
            $SwapOffOn["AutoMemWatchdog"] = 1;
        }
        if (!is_numeric($SwapOffOn["AutoMemPerc"])) {
            $SwapOffOn["AutoMemPerc"] = 90;
        }
        if (!is_numeric($SwapOffOn["AutoMemInterval"])) {
            $SwapOffOn["AutoMemInterval"] = 180;
        }
    }
    $text[] = "Configuration was:";
    $text[] = "--------------------------------------";
    $text[] = "Free memory when Swap exceed {$SwapOffOn["AutoMemPerc"]}%";
    $text[] = "Watchdog scanning interval: each {$SwapOffOn["AutoMemInterval"]}mn";
    if (isset($SwapOffOn["CURRENT"])) {
        $text[] = $SwapOffOn["CURRENT"];
    }
    $text[] = $unix->ps_mem_report();
    $TOTAL_MEMORY_MB_FREE = $unix->TOTAL_MEMORY_MB_FREE();
    $text[] = "{$TOTAL_MEMORY_MB_FREE}MB before operation";
    $sync = $unix->find_program("sync");
    $sysctl = $unix->find_program("sysctl");
    $squid = $unix->LOCATE_SQUID_BIN();
    shell_exec($sync);
    shell_exec("{$sysctl} -w vm.drop_caches=3");
    shell_exec($sync);
    shell_exec("/etc/init.d/apache2 restart");
    if (is_file("/etc/init.d/ssh")) {
        shell_exec("/etc/init.d/ssh restart");
    }
    if ($unix->is_socket("/var/run/mysqld/mysqld.sock")) {
        $q = new mysql();
        $q->EXECUTE_SQL("RESET QUERY CACHE;");
    }
    if ($unix->is_socket("/var/run/mysqld/squid-db.sock")) {
        $q = new mysql_squid_builder();
        $q->EXECUTE_SQL("RESET QUERY CACHE;");
    }
    $TOTAL_MEMORY_MB_FREE2 = $unix->TOTAL_MEMORY_MB_FREE();
    $text[] = "{$TOTAL_MEMORY_MB_FREE2}MB After operation";
    $TOTAL_MEMORY_MB = $TOTAL_MEMORY_MB_FREE2 - $TOTAL_MEMORY_MB_FREE;
    $text[] = "{$TOTAL_MEMORY_MB}MB restored";
    $FINAL_TEXT = @implode("\n", $text);
    system_admin_events("Free memory operation has been executed - {$TOTAL_MEMORY_MB}MB restored\n{$FINAL_TEXT}", __FUNCTION__, __FILE__, __LINE__);
    if (is_file($squid)) {
        squid_admin_mysql(1, "Swap exceed rule: Free memory operation has been executed - {$TOTAL_MEMORY_MB}MB restored", $FINAL_TEXT, __FILE__, __LINE__);
    }
}
示例#6
0
function start($aspid = false)
{
    $unix = new unix();
    $sock = new sockets();
    $Masterbin = $unix->find_program("clamd");
    if (!is_file($Masterbin)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, clamd not installed\n";
        }
        return;
    }
    if (!$aspid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = $unix->get_pid_from_file($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $pid = PID_NUM();
    if ($unix->process_exists($pid)) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Service already started {$pid} since {$timepid}Mn...\n";
        }
        return;
    }
    $EnableClamavDaemon = $sock->EnableClamavDaemon();
    if ($EnableClamavDaemon == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service disabled (see sock->EnableClamavDaemon)\n";
        }
        return;
    }
    $php5 = $unix->LOCATE_PHP5_BIN();
    $nohup = $unix->find_program("nohup");
    $aa_complain = $unix->find_program('aa-complain');
    if (is_file($aa_complain)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} add clamd Profile to AppArmor..\n";
        }
        shell_exec("{$aa_complain} {$Masterbin} >/dev/null 2>&1");
    }
    @mkdir("/var/clamav", 0755, true);
    @mkdir("/var/run/clamav", 0755, true);
    @mkdir("/var/lib/clamav", 0755, true);
    @mkdir("/var/log/clamav", 0755, true);
    $unix->chown_func("clamav", "clamav", "/var/clamav");
    $unix->chown_func("clamav", "clamav", "/var/run/clamav");
    $unix->chown_func("clamav", "clamav", "/var/lib/clamav");
    $unix->chown_func("clamav", "clamav", "/var/log/clamav");
    $clamd_version = clamd_version();
    $cmd = "{$nohup} {$Masterbin} --config-file=/etc/clamav/clamd.conf >/dev/null 2>&1 &";
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service version {$clamd_version}\n";
    }
    shell_exec($cmd);
    for ($i = 1; $i < 5; $i++) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} waiting {$i}/5\n";
        }
        sleep(1);
        $pid = PID_NUM();
        if ($unix->process_exists($pid)) {
            break;
        }
    }
    $pid = PID_NUM();
    if ($unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Success PID {$pid}\n";
        }
        sleep(1);
        for ($i = 1; $i < 5; $i++) {
            if ($unix->is_socket("/var/run/clamav/clamav.sock")) {
                if ($GLOBALS["OUTPUT"]) {
                    echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Apply permissions on clamav.sock\n";
                }
                @chmod("/var/run/clamav/clamav.sock", 0777);
                break;
            } else {
                if ($GLOBALS["OUTPUT"]) {
                    echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} waiting for socket... {$i}/4\n";
                }
                sleep(1);
            }
        }
        if ($unix->is_socket("/var/run/clamav/clamav.sock")) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Apply permissions on clamav.sock\n";
            }
            @chmod("/var/run/clamav/clamav.sock", 0777);
        } else {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} socket failed\n";
            }
        }
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Failed\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} {$cmd}\n";
        }
    }
    $pid = PID_NUM();
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Failed..\n";
        }
    }
    if (!$unix->is_socket("/var/run/clamav/clamav.sock")) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} socket Failed..\n";
        }
    }
}
示例#7
0
function SERVICE_START($nochecks = false, $nopid = false)
{
    $unix = new unix();
    $sock = new sockets();
    $kill = $unix->find_program("kill");
    if (!$nopid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = @file_get_contents($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            echo "Starting......: " . date("H:i:s") . " MySQL this script is already executed PID: {$pid} since {$time}Mn\n";
            if ($time < 5) {
                if (!$GLOBALS["FORCE"]) {
                    return;
                }
            }
            unix_system_kill_force($pid);
        }
        @file_put_contents($pidfile, getmypid());
    }
    if (is_file("/etc/artica-postfix/mysql.stop")) {
        echo "Starting......: " . date("H:i:s") . " MySQL locked, exiting\n";
        return;
    }
    $PID_NUM = PID_NUM();
    if ($unix->process_exists($PID_NUM)) {
        $timemin = $unix->PROCCESS_TIME_MIN($PID_NUM);
        echo "Starting......: " . date("H:i:s") . " MySQL already running PID \"{$PID_NUM}\" since {$timemin}Mn\n";
        return;
    }
    $mysql_install_db = $unix->find_program('mysql_install_db');
    $mysqlbin = $unix->LOCATE_mysqld_bin();
    $php5 = $unix->LOCATE_PHP5_BIN();
    $nohup = $unix->find_program("nohup");
    if (!is_file($mysqlbin)) {
        echo "Starting......: " . date("H:i:s") . " MySQL is not installed, abort\n";
        return;
    }
    $EnableMysqlFeatures = $sock->GET_INFO('EnableMysqlFeatures');
    $MysqlBinAllAdresses = $sock->GET_INFO('MysqlBinAllAdresses');
    $MySQLTMPMEMSIZE = $sock->GET_INFO('MySQLTMPMEMSIZE');
    $MysqlTooManyConnections = $sock->GET_INFO("MysqlTooManyConnections");
    $MysqlRemoveidbLogs = $sock->GET_INFO("MysqlRemoveidbLogs");
    $innodb_force_recovery = $sock->GET_INFO("innodb_force_recovery");
    if (!is_numeric($innodb_force_recovery)) {
        $innodb_force_recovery = 0;
    }
    if (!is_numeric($MysqlRemoveidbLogs)) {
        $MysqlRemoveidbLogs = 0;
    }
    if (!is_numeric($MysqlBinAllAdresses)) {
        $MysqlBinAllAdresses = 0;
    }
    if (!is_numeric($MySQLTMPMEMSIZE)) {
        $MySQLTMPMEMSIZE = 0;
    }
    if (!is_numeric($MysqlTooManyConnections)) {
        $MysqlTooManyConnections = 0;
    }
    if (!is_numeric($EnableMysqlFeatures)) {
        $EnableMysqlFeatures = 1;
    }
    $MySqlTmpDir = $sock->GET_INFO('MySQLTMPDIR');
    $MySQLLOgErrorPath = $sock->GET_INFO('MySQLLOgErrorPath');
    $datadir = $unix->MYSQL_DATA_DIR();
    $EnableMysqlLog = $sock->GET_INFO("EnableMysqlLog");
    if (!is_numeric($EnableMysqlLog)) {
        $EnableMysqlLog = 0;
    }
    if ($datadir == null) {
        $datadir = '/var/lib/mysql';
    }
    if ($MySqlTmpDir == '/tmp') {
        $MySqlTmpDir = null;
    }
    if ($MySQLLOgErrorPath == null) {
        $MySQLLOgErrorPath = $datadir . '/mysqld.err';
    }
    if ($MysqlTooManyConnections == 1) {
        echo "Starting......: " . date("H:i:s") . " MySQL MysqlTooManyConnections=1, abort\n";
        return;
    }
    if (isset($GLOBALS["RECOVERY"])) {
        $innodb_force_recovery = $GLOBALS["RECOVERY"];
    }
    if (strlen($MySqlTmpDir) > 3) {
        echo "Starting......: " . date("H:i:s") . " MySQL tempdir : {$MySqlTmpDir}\n";
        shell_exec("{$php5} /usr/share/artica-postfix/exec.mysql.build.php --tmpfs");
        $MySqlTmpDir = str_replace("//", "/", $MySqlTmpDir);
        if (!is_dir($MySqlTmpDir)) {
            @mkdir($MySqlTmpDir, 0755, true);
            $unix->chown_func("mysql", "mysql", $MySqlTmpDir);
        }
        $MySqlTmpDirCMD = " --tmpdir={$MySqlTmpDir}";
    }
    if ($EnableMysqlFeatures == 0) {
        echo "Starting......: " . date("H:i:s") . " MySQL is disabled by \"EnableMysqlFeatures\"...\n";
        return;
    }
    $pid_file = "/var/run/mysqld/mysqld.pid";
    $socket = "/var/run/mysqld/mysqld.sock";
    $mysql_user = "******";
    @mkdir("/var/run/mysqld", 0755, true);
    @mkdir("/var/log/mysql", 0755, true);
    @mkdir($datadir, 0755, true);
    $dirs = $unix->dirdir("/var/lib/mysql");
    while (list($num, $directory) = each($dirs)) {
        echo "Starting......: " . date("H:i:s") . " MySQL, apply permissions on " . basename($directory) . "\n";
        $unix->chown_func("mysql", "mysql", "{$directory}/*");
    }
    $bind_address = ' --bind-address=127.0.0.1';
    $bind_address2 = "127.0.0.1";
    if ($MysqlBinAllAdresses == 1) {
        $bind_address2 = 'All (0.0.0.0)';
        $bind_address = ' --bind-address=0.0.0.0';
    }
    echo "Starting......: " . date("H:i:s") . " MySQL Pid path.......:{$pid_file}\n";
    echo "Starting......: " . date("H:i:s") . " datadir..............:{$datadir}\n";
    echo "Starting......: " . date("H:i:s") . " Log error............:{$MySQLLOgErrorPath}\n";
    echo "Starting......: " . date("H:i:s") . " socket...............:{$socket}\n";
    echo "Starting......: " . date("H:i:s") . " user.................:{$mysql_user}\n";
    echo "Starting......: " . date("H:i:s") . " LOGS ENABLED.........:{$EnableMysqlLog}\n";
    echo "Starting......: " . date("H:i:s") . " Daemon...............:{$mysqlbin}\n";
    echo "Starting......: " . date("H:i:s") . " Bind address.........:{$bind_address2}\n";
    echo "Starting......: " . date("H:i:s") . " Temp Dir.............:{$MySqlTmpDir}\n";
    echo "Starting......: " . date("H:i:s") . " innodb_force_recovery:{$innodb_force_recovery}\n";
    mysql_admin_mysql(1, "Starting MySQL service...", null, __FILE__, __LINE__);
    echo "Starting......: " . date("H:i:s") . " Settings permissions..\n";
    @mkdir("/var/run/mysqld", 0755, true);
    $unix->chown_func($mysql_user, $mysql_user, "/var/run/mysqld");
    $unix->chown_func($mysql_user, $mysql_user, "/var/log/mysql");
    $unix->chown_func($mysql_user, $mysql_user, $datadir);
    $unix->chown_func($mysql_user, $mysql_user, "{$datadir}/*");
    if ($unix->is_socket("/var/run/mysqld/mysqld.sock")) {
        @unlink("/var/run/mysqld/mysqld.sock");
    }
    if (is_file('/var/run/mysqld/mysqld.err')) {
        @unlink('/var/run/mysqld/mysqld.err');
    }
    if (is_file("/var/run/mysqld/mysqld.pid")) {
        $unix->chown_func($mysql_user, $mysql_user, "/var/run/mysqld/mysqld.pid");
    }
    if ($MysqlRemoveidbLogs == 1) {
        shell_exec('/bin/mv /var/lib/mysql/ib_logfile* /tmp/');
        $sock->SET_INFO('MysqlRemoveidbLogs', '0');
    }
    $logpathstring = " --log-error={$MySQLLOgErrorPath}";
    if ($EnableMysqlLog == 1) {
        $logpathstring = " --log=/var/log/mysql.log --log-slow-queries=/var/log/mysql-slow-queries.log --log-error={$MySQLLOgErrorPath} --log-warnings";
    }
    $toTouch[] = "/var/log/mysql-slow-queries.log";
    $toTouch[] = "/var/log/mysql.error";
    $toTouch[] = "/var/log/mysql.log";
    $toTouch[] = "/var/log/mysql.warn";
    while (list($num, $filename) = each($toTouch)) {
        if (!is_file($filename)) {
            @file_put_contents($filename, "#\n");
        }
        $unix->chown_func($mysql_user, $mysql_user, $filename);
    }
    echo "Starting......: " . date("H:i:s") . " MySQL Checking : {$datadir}/mysql/host.frm\n";
    if (!is_file("{$datadir}/mysql/host.frm")) {
        if (is_file($mysql_install_db)) {
            echo "Starting......: " . date("H:i:s") . " MySQL Installing default databases\n";
            shell_exec("{$mysql_install_db} --datadir=\"{$datadir}\"");
        }
    } else {
        echo "Starting......: " . date("H:i:s") . " MySQL Checking : {$datadir}/mysql/host.frm OK\n";
    }
    $cmd2 = array();
    $MEMORY = $unix->MEM_TOTAL_INSTALLEE();
    $AsCategoriesAppliance = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/AsCategoriesAppliance"));
    if ($AsCategoriesAppliance == 1) {
        $MEMORY = 620288;
    }
    if ($MEMORY < 624288) {
        $GetStartedValues = GetStartedValues();
        echo "Starting......: " . date("H:i:s") . " MySQL Warning memory did not respond to pre-requesites, tuning to lower memory\n";
        if ($GetStartedValues["--key-buffer-size"]) {
            $cmd2[] = "--key-buffer-size=8M";
        }
        if ($GetStartedValues["--max-allowed-packet"]) {
            $cmd2[] = "--max-allowed-packet=4M";
        }
        if ($GetStartedValues["--table-cache"]) {
            $cmd2[] = "--table-cache=4";
        }
        if ($GetStartedValues["--sort-buffer-size"]) {
            $cmd2[] = "--sort-buffer-size=64k";
        }
        if ($GetStartedValues["--read-buffer-size"]) {
            $cmd2[] = "--read-buffer-size=256k";
        }
        if ($GetStartedValues["--read-rnd-buffer-size"]) {
            $cmd2[] = "--read-rnd-buffer-size=128k";
        }
        if ($GetStartedValues["--net-buffer-length"]) {
            $cmd2[] = "--net-buffer-length=2k";
        }
        if ($GetStartedValues["--thread-stack"]) {
            $cmd2[] = "--thread-stack=192k";
        }
        if ($GetStartedValues["--thread-cache-size"]) {
            $cmd2[] = "--thread-cache-size=128";
        }
        if ($GetStartedValues["--thread-concurrency"]) {
            $cmd2[] = "--thread-concurrency=10";
        }
        if ($GetStartedValues["--default-storage-engine"]) {
            $cmd2[] = "--default-storage-engine=MyISAM";
        }
        if ($GetStartedValues["--default-tmp-storage-engine"]) {
            $cmd2[] = "--default-tmp-storage-engine=MyISAM";
        }
        if ($GetStartedValues["--tmp-table-size"]) {
            $cmd2[] = "--tmp-table-size=16M";
        }
        if ($GetStartedValues["--table-cache"]) {
            $cmd2[] = "--table-cache=64";
        }
        if ($GetStartedValues["--query-cache-limit"]) {
            $cmd2[] = "--query-cache-limit=4M";
        }
        if ($GetStartedValues["--query-cache-size"]) {
            $cmd2[] = "--query-cache-size=32M";
        }
        if ($GetStartedValues["--max-connections"]) {
            $cmd2[] = "--max-connections=50";
        }
        if (is_file("/etc/artica-postfix/WORDPRESS_APPLIANCE")) {
            $cmd2[] = "--innodb=OFF";
        }
        echo "Starting......: " . date("H:i:s") . " MySQL " . count($cmd2) . " forced option(s)\n";
    }
    if (is_file($MySQLLOgErrorPath)) {
        @unlink($MySQLLOgErrorPath);
    }
    $cmds[] = $mysqlbin;
    if ($MEMORY < 624288) {
        $cmds[] = "--no-defaults --user=mysql";
    }
    $cmds[] = "--pid-file=/var/run/mysqld/mysqld.pid";
    $cmds[] = trim($logpathstring);
    $cmds[] = trim($MySqlTmpDirCMD);
    $cmds[] = "--socket={$socket}";
    $cmds[] = "--datadir=\"{$datadir}\"";
    if (count($cmd2) == 0) {
        if ($innodb_force_recovery > 0) {
            $cmds[] = "--innodb-force-recovery={$innodb_force_recovery}";
        }
    }
    if (count($cmd2) > 0) {
        $cmds[] = @implode(" ", $cmd2);
    }
    $cmds[] = ">/dev/null 2>&1 &";
    if (is_file('/usr/sbin/aa-complain')) {
        echo "Starting......: " . date("H:i:s") . " Mysql Adding mysql in apparamor complain mode...\n";
        shell_exec("/usr/sbin/aa-complain {$mysqlbin} >/dev/null 2>&1");
    }
    $cmd = @implode(" ", $cmds);
    while (list($num, $ligne) = each($cmds)) {
        echo "Starting......: " . date("H:i:s") . " MySQL Option: {$ligne}\n";
    }
    echo "Starting......: " . date("H:i:s") . " MySQL Starting daemon, please wait\n";
    writelogs("Starting MySQL {$cmd}", __FUNCTION__, __FILE__, __LINE__);
    shell_exec($cmd);
    $count = 0;
    sleep(2);
    for ($i = 0; $i < 6; $i++) {
        $pid = PID_NUM();
        if ($unix->process_exists($pid, $mysqlbin)) {
            echo "Starting......: " . date("H:i:s") . " MySQL Checks daemon running...\n";
            break;
        }
        echo "Starting......: " . date("H:i:s") . " MySQL Checks daemon, please wait ({$i}/6)\n";
        sleep(1);
    }
    $pid = PID_NUM();
    if (!$unix->process_exists($pid)) {
        echo "Starting......: " . date("H:i:s") . " MySQL failed\n";
        echo "Starting......: " . date("H:i:s") . " {$cmd}\n";
        system_admin_events("Failed to start MySQL server", __FUNCTION__, __FILE__, __LINE__, "services");
        $php5 = $unix->LOCATE_PHP5_BIN();
        shell_exec("{$nohup} {$php5} /usr/share/artica-postfix/exec.mysql.build.php >/dev/null 2>&1 &");
    } else {
        for ($i = 0; $i < 4; $i++) {
            echo "Starting......: " . date("H:i:s") . " MySQL Checks mysqld.sock waiting {$i}/3\n";
            if ($unix->is_socket("/var/run/mysqld/mysqld.sock")) {
                break;
            }
            sleep(1);
        }
        if (!$unix->is_socket("/var/run/mysqld/mysqld.sock")) {
            mysql_admin_mysql(0, "Failed to start MySQL Server /var/run/mysqld/mysqld.sock no such socket after 4 seconds", null, __FILE__, __LINE__);
            echo "Starting......: " . date("H:i:s") . " MySQL Checks mysqld.sock failed...\n";
        }
        mysql_admin_mysql(1, "Success to start MySQL Server with new pid {$pid}", null, __FILE__, __LINE__);
        echo "Starting......: " . date("H:i:s") . " MySQL Success pid {$pid}\n";
        $q = new mysql_squid_builder();
        $q->MEMORY_TABLES_RESTORE();
    }
}
示例#8
0
function restore_squidlogs($sourceDir)
{
    if (!($handle = opendir("{$sourceDir}/squidlogs"))) {
        echo "Failed open {$sourceDir}/squidlogs\n";
        return;
    }
    $password = null;
    $unix = new unix();
    if (!$unix->is_socket("/var/run/mysqld/squid-db.sock")) {
        system_admin_events("Error,/var/run/mysqld/squid-db.sock no such socket", __FUNCTION__, __FILE__, __LINE__);
        return false;
    }
    $sock = new sockets();
    $gunzip = $unix->find_program("gunzip");
    $mysql = $unix->find_program("mysql");
    $BLACKLIST = array();
    $nice = $unix->EXEC_NICE();
    $q = new mysql_squid_builder();
    $sock = new sockets();
    $BackupArticaRestoreNetwork = intval($sock->GET_INFO("BackupArticaRestoreNetwork"));
    if ($GLOBALS["NOT_RESTORE_NETWORK"]) {
        $BackupArticaRestoreNetwork = 0;
    }
    if ($BackupArticaRestoreNetwork == 0) {
        $BLACKLIST["dns_servers.gz"] = true;
        $BLACKLIST["dnsmasq_records.gz"] = true;
    }
    if ($q->mysql_password != null) {
        $password = "******" . $unix->shellEscapeChars($q->mysql_password);
    }
    $prefix = trim("{$mysql} --force -S /var/run/mysqld/squid-db.sock -u {$q->mysql_admin}{$password} squidlogs");
    while (false !== ($filename = readdir($handle))) {
        if ($filename == ".") {
            continue;
        }
        if ($filename == "..") {
            continue;
        }
        if (isset($BLACKLIST[$filename])) {
            continue;
        }
        $SourceFile = "{$sourceDir}/squidlogs/{$filename}";
        if (is_dir($SourceFile)) {
            continue;
        }
        echo "Restoring Proxy database/{$filename}\n";
        $cmd = trim("{$nice} {$gunzip} -c {$SourceFile} |{$prefix}");
        system($cmd);
    }
}
示例#9
0
function Checks()
{
    $GLOBALS["NORELOAD"] = true;
    $unix = new unix();
    if (!is_file("/usr/lib/x86_64-linux-gnu/autofs/lookup_ldap.so")) {
        build_progress_rs("{install} autofs-ldap", 15);
        $unix->DEBIAN_INSTALL_PACKAGE("autofs-ldap");
    }
    if (!is_file("/usr/lib/x86_64-linux-gnu/autofs/lookup_ldap.so")) {
        build_progress_rs("{install} autofs-ldap {failed}", 110);
        return;
    }
    if (!$unix->is_socket("/var/run/slapd/slapd.sock")) {
        build_progress_rs("{restarting_service} OpenLDAP", 15);
        system("/etc/init.d/slapd restart");
    } else {
        if ($GLOBALS["PROGRESS"]) {
            build_progress_rs("{restarting_service} OpenLDAP", 15);
            system("/etc/init.d/slapd restart");
        }
    }
    $curlftpfs = $unix->find_program("curlftpfs");
    $fusermount = $unix->find_program("fusermount");
    if (is_file($curlftpfs)) {
        if (!is_file("/sbin/mount.curl")) {
            build_progress_rs("/sbin/mount.curl", 15);
            $curlftpfsZ[] = "#! /bin/sh";
            $curlftpfsZ[] = "{$curlftpfs} \$1 \$2 -o \$5,disable_eprt";
            $curlftpfsZ[] = "";
            @file_put_contents("/sbin/mount.curl", @implode("\n", $curlftpfsZ));
            @chmod("/sbin/mount.curl", 0755);
        }
        if (!is_file("/sbin/umount.curl")) {
            build_progress_rs("/sbin/umount.curl", 15);
            $curlftpfsZ = array();
            $curlftpfsZ[] = "#! /bin/sh";
            $curlftpfsZ[] = "{$fusermount} -u \$1";
            $curlftpfsZ[] = "";
            @file_put_contents("/sbin/umount.curl", @implode("\n", $curlftpfsZ));
            @chmod("/sbin/umount.curl", 0755);
        }
    }
    $ldap = new clladp();
    $data = "<?xml version=\"1.0\" ?>\n         <autofs_ldap_sasl_conf\n                 usetls=\"no\"\n                 tlsrequired=\"no\"\n                 authrequired=\"yes\"\n                 authtype=\"PLAIN\"\n                 user=\"{$ldap->ldap_admin}\"\n                 secret=\"{$ldap->ldap_password}\"\n         />";
    @file_put_contents("/etc/autofs_ldap_auth.conf", $data);
    if (is_file("/etc/autofs_ldap_auth.conf")) {
        @chmod("/etc/autofs_ldap_auth.conf", 0600);
        @chown("/etc/autofs_ldap_auth.conf", "root");
        @chgrp("/etc/autofs_ldap_auth.conf", "root");
    }
    build_progress_rs("{checking_configuration}", 15);
    $auto = new autofs();
    build_progress_rs("{checking_configuration}", 20);
    autofs_default();
    build_progress_rs("{checking_configuration}", 25);
    Autocount();
    build_progress_rs("{checking_configuration}", 30);
    davfs();
}
示例#10
0
function start($aspid = false)
{
    $unix = new unix();
    $sock = new sockets();
    $nginx = $unix->find_program("nginx");
    if (!is_file($nginx)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx, not installed\n";
        }
        return;
    }
    if (!$aspid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = $unix->get_pid_from_file($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $MEMORY = $unix->MEM_TOTAL_INSTALLEE();
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx {$MEMORY}K\n";
    }
    $pid = PID_NUM();
    if ($unix->process_exists($pid)) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx Service already started {$pid} since {$timepid}Mn...\n";
        }
        return;
    }
    $php = $unix->LOCATE_PHP5_BIN();
    $EnableNginx = $sock->GET_INFO("EnableNginx");
    if (is_file("/etc/artica-postfix/WORDPRESS_APPLIANCE")) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx, is Wordpress Appliance\n";
        }
        $sock->SET_INFO("EnableNginx", 1);
        if (!is_dir("/usr/share/wordpress-src")) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx, Installing Wordpress\n";
            }
            shell_exec("{$php} /usr/share/artica-postfix/exec.wordpress.download.php");
        }
        $EnableNginx = 1;
    }
    if (!is_numeric($EnableNginx)) {
        $EnableNginx = 1;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx service \"EnableNginx\" = {$EnableNginx}\n";
    }
    if ($EnableNginx == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx service disabled\n";
        }
        return;
    }
    GHOSTS_PID();
    @mkdir("/var/log/nginx", 0755, true);
    $nohup = $unix->find_program("nohup");
    $fuser = $unix->find_program("fuser");
    $kill = $unix->find_program("kill");
    $results = array();
    $FUSERS = array();
    exec("{$fuser} 80/tcp 2>&1", $results);
    while (list($key, $line) = each($results)) {
        if ($GLOBALS["VERBOSE"]) {
            echo "fuser: ->\"{$line}\"\n";
        }
        if (preg_match("#tcp:\\s+(.+)#", $line, $re)) {
            $FUSERS = explode(" ", $re[1]);
        }
    }
    if (count($FUSERS) > 0) {
        while (list($key, $pid) = each($FUSERS)) {
            $pid = trim($pid);
            if (!is_numeric($pid)) {
                continue;
            }
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: killing {$pid} PID that listens 80\n";
            }
            unix_system_kill_force($pid);
        }
    }
    exec("{$fuser} 443/tcp 2>&1", $results);
    while (list($key, $line) = each($results)) {
        if ($GLOBALS["VERBOSE"]) {
            echo "fuser: ->\"{$line}\"\n";
        }
        if (preg_match("#tcp:\\s+(.+)#", $line, $re)) {
            $FUSERS = explode(" ", $re[1]);
        }
    }
    if (count($FUSERS) > 0) {
        while (list($key, $pid) = each($FUSERS)) {
            $pid = trim($pid);
            if (!is_numeric($pid)) {
                continue;
            }
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: killing {$pid} PID that listens 443\n";
            }
            unix_system_kill_force($pid);
        }
    }
    $php5 = $unix->LOCATE_PHP5_BIN();
    if ($unix->is_socket("/var/run/nginx-authenticator.sock")) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Remove authenticator socket\n";
        }
        @unlink("/var/run/nginx-authenticator.sock");
    }
    if (is_file("/var/run/nginx-authenticator.sock")) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Remove authenticator socket\n";
        }
        @unlink("/var/run/nginx-authenticator.sock");
    }
    nginx_mime_types();
    $EnableArticaInNGINX = $sock->GET_INFO("EnableArticaInNGINX");
    if (!is_numeric($EnableArticaInNGINX)) {
        $EnableArticaInNGINX = 0;
    }
    @unlink("/etc/nginx/conf.d/default.conf");
    if ($EnableArticaInNGINX == 1) {
        build_default_asArtica();
    }
    $cmd = "{$nginx} -c /etc/nginx/nginx.conf";
    if ($GLOBALS["VERBOSE"]) {
        echo "{$cmd}\n";
    }
    shell_exec($cmd);
    for ($i = 0; $i < 6; $i++) {
        $pid = PID_NUM();
        if ($unix->process_exists($pid)) {
            break;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx service waiting {$i}/6...\n";
        }
        sleep(1);
    }
    $pid = PID_NUM();
    if ($unix->process_exists($pid)) {
        nginx_admin_mysql(2, "Nginx Web service success to start [action=info]", null, __FILE__, __LINE__);
        @unlink($GLOBALS["pidStampReload"]);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx service Success service started pid:{$pid}...\n";
        }
        $php5 = $unix->LOCATE_PHP5_BIN();
        shell_exec("{$nohup} {$php5} /usr/share/artica-postfix/exec.php-fpm.php --start >/dev/null 2>&1 &");
        shell_exec("{$nohup} {$php} /usr/share/artica-postfix/exec.nginx.wizard.php --avail-status --force >/dev/null 2>&1 &");
        return;
    }
    nginx_admin_mysql(0, "Nginx Web service failed to start [action=info]", null, __FILE__, __LINE__);
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx service failed...\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$cmd}\n";
    }
    $cmd = "{$nohup} {$php5} /usr/share/artica-postfix/exec.web-community-filter.php --register-lic >/dev/null 2>&1 &";
    if ($GLOBALS["VERBOSE"]) {
        echo "{$cmd}\n";
    }
}
示例#11
0
function IS_APP_SQUIDDB_INSTALLED()
{
    $unix = new unix();
    if ($unix->is_socket("/var/run/mysqld/squid-db.sock")) {
        writelogs_framework("/var/run/mysqld/squid-db.sock socket OK", __FUNCTION__, __FILE__, __LINE__);
        echo "<articadatascgi>TRUE</articadatascgi>";
        return;
    }
    writelogs_framework("/var/run/mysqld/squid-db.sock socket FALSE", __FUNCTION__, __FILE__, __LINE__);
    if (is_dir("/opt/squidsql/data/squidlogs")) {
        writelogs_framework("/opt/squidsql/data/squidlogs OK", __FUNCTION__, __FILE__, __LINE__);
        echo "<articadatascgi>TRUE</articadatascgi>";
        return;
    }
    writelogs_framework("/opt/squidsql/data/squidlogs no such dir", __FUNCTION__, __FILE__, __LINE__);
    echo "<articadatascgi>FALSE</articadatascgi>";
}
示例#12
0
function build_phpmyadmin()
{
    if (!is_dir("/usr/share/phpmyadmin/themes")) {
        echo "[INFO] phpmyadmin not detected\n";
    }
    $unix = new unix();
    $hostname = $unix->hostname_g();
    $blowfish_secret = md5($hostname);
    echo "[INFO] Starting building phpmyadmin\n";
    $f[] = "<?php";
    $f[] = "/* vim: set expandtab sw=4 ts=4 sts=4: */";
    $f[] = "/**";
    $f[] = " * phpMyAdmin sample configuration, you can use it as base for";
    $f[] = " * manual configuration. For easier setup you can use setup/";
    $f[] = " *";
    $f[] = " * All directives are explained in documentation in the doc/ folder";
    $f[] = " * or at <http://docs.phpmyadmin.net/>.";
    $f[] = " *";
    $f[] = " * @package PhpMyAdmin";
    $f[] = " */";
    $f[] = "";
    $f[] = "/*";
    $f[] = " * This is needed for cookie based authentication to encrypt password in";
    $f[] = " * cookie";
    $f[] = " */";
    $f[] = "\$cfg['blowfish_secret'] = '{$blowfish_secret}'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */";
    $f[] = "";
    $f[] = "/*";
    $f[] = " * Servers configuration";
    $f[] = " */";
    $f[] = "\$i = 0;";
    $f[] = "";
    $f[] = "/*";
    $f[] = " * First server";
    $f[] = " */";
    $f[] = "/* Authentication type */";
    $f[] = "/* Server parameters */";
    $f[] = "\$i++;";
    $f[] = "\$cfg['Servers'][\$i]['auth_type'] = 'cookie';";
    $f[] = "\$cfg['Servers'][\$i]['verbose'] = 'Local MySQL';";
    $f[] = "\$cfg['Servers'][\$i]['socket'] = '/var/run/mysqld/mysqld.sock';";
    $f[] = "\$cfg['Servers'][\$i]['host'] = 'localhost';";
    $f[] = "\$cfg['Servers'][\$i]['connect_type'] = 'socket';";
    $f[] = "\$cfg['Servers'][\$i]['compress'] = false;";
    $f[] = "\$cfg['Servers'][\$i]['AllowNoPassword'] = true;";
    $f[] = "\$cfg['Servers'][\$i]['nopassword'] = true;";
    $f[] = "\$cfg['Servers'][\$i]['AllowRoot'] = true;";
    $f[] = "\$cfg['Servers'][\$i]['AllowNoPasswordRoot'] = true;";
    if ($unix->is_socket("/var/run/mysqld/squid-db.sock")) {
        $f[] = "\$i++;";
        $f[] = "\$cfg['Servers'][\$i]['auth_type'] = 'cookie';";
        $f[] = "\$cfg['Servers'][\$i]['verbose'] = 'Proxy MySQL Statistics';";
        $f[] = "\$cfg['Servers'][\$i]['socket'] = '/var/run/mysqld/squid-db.sock';";
        $f[] = "\$cfg['Servers'][\$i]['host'] = 'localhost';";
        $f[] = "\$cfg['Servers'][\$i]['connect_type'] = 'socket';";
        $f[] = "\$cfg['Servers'][\$i]['compress'] = false;";
        $f[] = "\$cfg['Servers'][\$i]['AllowNoPassword'] = true;";
        $f[] = "\$cfg['Servers'][\$i]['nopassword'] = true;";
        $f[] = "\$cfg['Servers'][\$i]['AllowRoot'] = true;";
        $f[] = "\$cfg['Servers'][\$i]['AllowNoPasswordRoot'] = true;";
    }
    $f[] = "";
    $f[] = "/*";
    $f[] = " * phpMyAdmin configuration storage settings.";
    $f[] = " */";
    $f[] = "";
    $f[] = "\$i++;";
    $f[] = "/* User used to manipulate with storage */";
    $f[] = "// \$cfg['Servers'][\$i]['controlhost'] = '';";
    $f[] = "// \$cfg['Servers'][\$i]['controlport'] = '';";
    $f[] = "// \$cfg['Servers'][\$i]['controluser'] = '******';";
    $f[] = "// \$cfg['Servers'][\$i]['controlpass'] = '******';";
    $f[] = "";
    $f[] = "/* Storage database and tables */";
    $f[] = "\$cfg['Servers'][\$i]['pmadb'] = 'phpmyadmin';";
    $f[] = "\$cfg['Servers'][\$i]['bookmarktable'] = 'pma__bookmark';";
    $f[] = "\$cfg['Servers'][\$i]['relation'] = 'pma__relation';";
    $f[] = "\$cfg['Servers'][\$i]['table_info'] = 'pma__table_info';";
    $f[] = "\$cfg['Servers'][\$i]['table_coords'] = 'pma__table_coords';";
    $f[] = "\$cfg['Servers'][\$i]['pdf_pages'] = 'pma__pdf_pages';";
    $f[] = "\$cfg['Servers'][\$i]['column_info'] = 'pma__column_info';";
    $f[] = "\$cfg['Servers'][\$i]['history'] = 'pma__history';";
    $f[] = "\$cfg['Servers'][\$i]['table_uiprefs'] = 'pma__table_uiprefs';";
    $f[] = "\$cfg['Servers'][\$i]['tracking'] = 'pma__tracking';";
    $f[] = "\$cfg['Servers'][\$i]['designer_coords'] = 'pma__designer_coords';";
    $f[] = "\$cfg['Servers'][\$i]['userconfig'] = 'pma__userconfig';";
    $f[] = "\$cfg['Servers'][\$i]['recent'] = 'pma__recent';";
    $f[] = "\$cfg['Servers'][\$i]['favorite'] = 'pma__favorite';";
    $f[] = "\$cfg['Servers'][\$i]['users'] = 'pma__users';";
    $f[] = "\$cfg['Servers'][\$i]['usergroups'] = 'pma__usergroups';";
    $f[] = "\$cfg['Servers'][\$i]['navigationhiding'] = 'pma__navigationhiding';";
    $f[] = "\$cfg['Servers'][\$i]['savedsearches'] = 'pma__savedsearches';";
    $f[] = "/* Contrib / Swekey authentication */";
    $f[] = "// \$cfg['Servers'][\$i]['auth_swekey_config'] = '/etc/swekey-pma.conf';";
    $f[] = "";
    $f[] = "/*";
    $f[] = " * End of servers configuration";
    $f[] = " */";
    $f[] = "";
    $f[] = "/*";
    $f[] = " * Directories for saving/loading files from server";
    $f[] = " */";
    $f[] = "\$cfg['UploadDir'] = '';";
    $f[] = "\$cfg['SaveDir'] = '';";
    $f[] = "";
    $f[] = "/**";
    $f[] = " * Whether to display icons or text or both icons and text in table row";
    $f[] = " * action segment. Value can be either of 'icons', 'text' or 'both'.";
    $f[] = " */";
    $f[] = "//\$cfg['RowActionType'] = 'both';";
    $f[] = "";
    $f[] = "/**";
    $f[] = " * Defines whether a user should be displayed a \"show all (records)\"";
    $f[] = " * button in browse mode or not.";
    $f[] = " * default = false";
    $f[] = " */";
    $f[] = "//\$cfg['ShowAll'] = true;";
    $f[] = "";
    $f[] = "/**";
    $f[] = " * Number of rows displayed when browsing a result set. If the result";
    $f[] = " * set contains more rows, \"Previous\" and \"Next\".";
    $f[] = " * default = 30";
    $f[] = " */";
    $f[] = "//\$cfg['MaxRows'] = 50;";
    $f[] = "";
    $f[] = "/**";
    $f[] = " * disallow editing of binary fields";
    $f[] = " * valid values are:";
    $f[] = " *   false    allow editing";
    $f[] = " *   'blob'   allow editing except for BLOB fields";
    $f[] = " *   'noblob' disallow editing except for BLOB fields";
    $f[] = " *   'all'    disallow editing";
    $f[] = " * default = blob";
    $f[] = " */";
    $f[] = "//\$cfg['ProtectBinary'] = 'false';";
    $f[] = "";
    $f[] = "/**";
    $f[] = " * Default language to use, if not browser-defined or user-defined";
    $f[] = " * (you find all languages in the locale folder)";
    $f[] = " * uncomment the desired line:";
    $f[] = " * default = 'en'";
    $f[] = " */";
    $f[] = "//\$cfg['DefaultLang'] = 'en';";
    $f[] = "//\$cfg['DefaultLang'] = 'de';";
    $f[] = "//\$cfg['DefaultLang'] = 'fr';";
    $f[] = "";
    $f[] = "/**";
    $f[] = " * default display direction (horizontal|vertical|horizontalflipped)";
    $f[] = " */";
    $f[] = "//\$cfg['DefaultDisplay'] = 'vertical';";
    $f[] = "";
    $f[] = "";
    $f[] = "/**";
    $f[] = " * How many columns should be used for table display of a database?";
    $f[] = " * (a value larger than 1 results in some information being hidden)";
    $f[] = " * default = 1";
    $f[] = " */";
    $f[] = "//\$cfg['PropertiesNumColumns'] = 2;";
    $f[] = "";
    $f[] = "/**";
    $f[] = " * Set to true if you want DB-based query history.If false, this utilizes";
    $f[] = " * JS-routines to display query history (lost by window close)";
    $f[] = " *";
    $f[] = " * This requires configuration storage enabled, see above.";
    $f[] = " * default = false";
    $f[] = " */";
    $f[] = "//\$cfg['QueryHistoryDB'] = true;";
    $f[] = "";
    $f[] = "/**";
    $f[] = " * When using DB-based query history, how many entries should be kept?";
    $f[] = " *";
    $f[] = " * default = 25";
    $f[] = " */";
    $f[] = "//\$cfg['QueryHistoryMax'] = 100;";
    $f[] = "";
    $f[] = "/**";
    $f[] = " * Should error reporting be enabled for JavaScript errors";
    $f[] = " *";
    $f[] = " * default = 'ask'";
    $f[] = " */";
    $f[] = "//\$cfg['SendErrorReports'] = 'ask';";
    $f[] = "";
    $f[] = "/*";
    $f[] = " * You can find more configuration options in the documentation";
    $f[] = " * in the doc/ folder or at <http://docs.phpmyadmin.net/>.";
    $f[] = " */";
    $f[] = "?>";
    echo "slapd: [INFO] phpmyadmin success\n";
    @file_put_contents("/usr/share/phpmyadmin/config.inc.php", @implode("\n", $f));
    @chmod("/usr/share/phpmyadmin/config.inc.php", 0705);
    $q = new mysql();
    if (!$q->DATABASE_EXISTS("phpmyadmin")) {
        $q->CREATE_DATABASE("phpmyadmin");
    }
    $q->QUERY_SQL("CREATE TABLE IF NOT EXISTS `pma__bookmark` (\n`id` int(11) NOT NULL auto_increment,\n`dbase` varchar(255) NOT NULL default '',\n`user` varchar(255) NOT NULL default '',\n`label` varchar(255) COLLATE utf8_general_ci NOT NULL default '',\n`query` text NOT NULL,\nPRIMARY KEY  (`id`)\n)\nCOMMENT='Bookmarks'\nDEFAULT CHARACTER SET utf8 COLLATE utf8_bin;", "phpmyadmin");
    $q->QUERY_SQL("CREATE TABLE IF NOT EXISTS `pma__column_info` (\n\t\t`id` int(5) unsigned NOT NULL auto_increment,\n\t\t`db_name` varchar(64) NOT NULL default '',\n\t\t`table_name` varchar(64) NOT NULL default '',\n\t\t`column_name` varchar(64) NOT NULL default '',\n\t\t`comment` varchar(255) COLLATE utf8_general_ci NOT NULL default '',\n\t\t`mimetype` varchar(255) COLLATE utf8_general_ci NOT NULL default '',\n\t\t`transformation` varchar(255) NOT NULL default '',\n\t\t`transformation_options` varchar(255) NOT NULL default '',\n\t\tPRIMARY KEY  (`id`),\n\t\tUNIQUE KEY `db_name` (`db_name`,`table_name`,`column_name`)\n)\nCOMMENT='Column information for phpMyAdmin'\n\t\tDEFAULT CHARACTER SET utf8 COLLATE utf8_bin;", "phpmyadmin");
    $q->QUERY_SQL("CREATE TABLE IF NOT EXISTS `pma__history` (\n\t\t`id` bigint(20) unsigned NOT NULL auto_increment,\n\t\t`username` varchar(64) NOT NULL default '',\n\t\t`db` varchar(64) NOT NULL default '',\n\t\t`table` varchar(64) NOT NULL default '',\n\t\t`timevalue` timestamp NOT NULL,\n\t\t`sqlquery` text NOT NULL,\n\t\tPRIMARY KEY  (`id`),\n\t\tKEY `username` (`username`,`db`,`table`,`timevalue`)\n)\nCOMMENT='SQL history for phpMyAdmin'\n\t\tDEFAULT CHARACTER SET utf8 COLLATE utf8_bin;", "phpmyadmin");
    $q->QUERY_SQL("CREATE TABLE IF NOT EXISTS `pma__pdf_pages` (\n\t\t`db_name` varchar(64) NOT NULL default '',\n\t\t`page_nr` int(10) unsigned NOT NULL auto_increment,\n\t\t`page_descr` varchar(50) COLLATE utf8_general_ci NOT NULL default '',\n\t\tPRIMARY KEY  (`page_nr`),\n\t\tKEY `db_name` (`db_name`)\n)\nCOMMENT='PDF relation pages for phpMyAdmin'\n\t\tDEFAULT CHARACTER SET utf8 COLLATE utf8_bin;", "phpmyadmin");
    $q->QUERY_SQL("CREATE TABLE IF NOT EXISTS `pma__recent` (\n\t\t`username` varchar(64) NOT NULL,\n\t\t`tables` text NOT NULL,\n\t\tPRIMARY KEY (`username`)\n)\nCOMMENT='Recently accessed tables'\n\t\tDEFAULT CHARACTER SET utf8 COLLATE utf8_bin;", "phpmyadmin");
    $q->QUERY_SQL("CREATE TABLE IF NOT EXISTS `pma__favorite` (\n\t\t`username` varchar(64) NOT NULL,\n\t\t`tables` text NOT NULL,\n\t\tPRIMARY KEY (`username`)\n)\nCOMMENT='Favorite tables'\n\t\tDEFAULT CHARACTER SET utf8 COLLATE utf8_bin;", "phpmyadmin");
    $q->QUERY_SQL("CREATE TABLE IF NOT EXISTS `pma__table_uiprefs` (\n\t\t`username` varchar(64) NOT NULL,\n\t\t`db_name` varchar(64) NOT NULL,\n\t\t`table_name` varchar(64) NOT NULL,\n\t\t`prefs` text NOT NULL,\n\t\t`last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n\t\tPRIMARY KEY (`username`,`db_name`,`table_name`)\n)\nCOMMENT='Tables'' UI preferences'\n\t\tDEFAULT CHARACTER SET utf8 COLLATE utf8_bin;", "phpmyadmin");
    $q->QUERY_SQL("CREATE TABLE IF NOT EXISTS `pma__relation` (\n\t\t`master_db` varchar(64) NOT NULL default '',\n\t\t`master_table` varchar(64) NOT NULL default '',\n\t\t`master_field` varchar(64) NOT NULL default '',\n\t\t`foreign_db` varchar(64) NOT NULL default '',\n\t\t`foreign_table` varchar(64) NOT NULL default '',\n\t\t`foreign_field` varchar(64) NOT NULL default '',\n\t\tPRIMARY KEY  (`master_db`,`master_table`,`master_field`),\n\t\tKEY `foreign_field` (`foreign_db`,`foreign_table`)\n)\nCOMMENT='Relation table'\n\t\tDEFAULT CHARACTER SET utf8 COLLATE utf8_bin;", "phpmyadmin");
    $q->QUERY_SQL("CREATE TABLE IF NOT EXISTS `pma__table_coords` (\n\t\t`db_name` varchar(64) NOT NULL default '',\n\t\t`table_name` varchar(64) NOT NULL default '',\n\t\t`pdf_page_number` int(11) NOT NULL default '0',\n\t\t`x` float unsigned NOT NULL default '0',\n\t\t`y` float unsigned NOT NULL default '0',\n\t\tPRIMARY KEY  (`db_name`,`table_name`,`pdf_page_number`)\n)\nCOMMENT='Table coordinates for phpMyAdmin PDF output'\n\t\tDEFAULT CHARACTER SET utf8 COLLATE utf8_bin;", "phpmyadmin");
    $q->QUERY_SQL("CREATE TABLE IF NOT EXISTS `pma__table_info` (\n\t\t`db_name` varchar(64) NOT NULL default '',\n\t\t`table_name` varchar(64) NOT NULL default '',\n\t\t`display_field` varchar(64) NOT NULL default '',\n\t\tPRIMARY KEY  (`db_name`,`table_name`)\n)\nCOMMENT='Table information for phpMyAdmin'\n\t\tDEFAULT CHARACTER SET utf8 COLLATE utf8_bin;", "phpmyadmin");
    $q->QUERY_SQL("CREATE TABLE IF NOT EXISTS `pma__designer_coords` (\n\t\t`db_name` varchar(64) NOT NULL default '',\n\t\t`table_name` varchar(64) NOT NULL default '',\n\t\t`x` INT,\n\t\t`y` INT,\n\t\t`v` TINYINT,\n\t\t`h` TINYINT,\n\t\tPRIMARY KEY (`db_name`,`table_name`)\n)\nCOMMENT='Table coordinates for Designer'\n\t\tDEFAULT CHARACTER SET utf8 COLLATE utf8_bin;", "phpmyadmin");
    $q->QUERY_SQL("CREATE TABLE IF NOT EXISTS `pma__tracking` (\n\t\t`db_name` varchar(64) NOT NULL,\n\t\t`table_name` varchar(64) NOT NULL,\n\t\t`version` int(10) unsigned NOT NULL,\n\t\t`date_created` datetime NOT NULL,\n\t\t`date_updated` datetime NOT NULL,\n\t\t`schema_snapshot` text NOT NULL,\n\t\t`schema_sql` text,\n\t\t`data_sql` longtext,\n\t\t`tracking` set('UPDATE','REPLACE','INSERT','DELETE','TRUNCATE','CREATE DATABASE','ALTER DATABASE','DROP DATABASE','CREATE TABLE','ALTER TABLE','RENAME TABLE','DROP TABLE','CREATE INDEX','DROP INDEX','CREATE VIEW','ALTER VIEW','DROP VIEW') default NULL,\n\t\t`tracking_active` int(1) unsigned NOT NULL default '1',\n\t\tPRIMARY KEY  (`db_name`,`table_name`,`version`)\n)\nCOMMENT='Database changes tracking for phpMyAdmin'\n\t\tDEFAULT CHARACTER SET utf8 COLLATE utf8_bin;", "phpmyadmin");
    $q->QUERY_SQL("CREATE TABLE IF NOT EXISTS `pma__userconfig` (\n\t\t`username` varchar(64) NOT NULL,\n\t\t`timevalue` timestamp NOT NULL,\n\t\t`config_data` text NOT NULL,\n\t\tPRIMARY KEY  (`username`)\n)\nCOMMENT='User preferences storage for phpMyAdmin'\n\t\tDEFAULT CHARACTER SET utf8 COLLATE utf8_bin;", "phpmyadmin");
    $q->QUERY_SQL("CREATE TABLE IF NOT EXISTS `pma__users` (\n\t\t`username` varchar(64) NOT NULL,\n\t\t`usergroup` varchar(64) NOT NULL,\n\t\tPRIMARY KEY (`username`,`usergroup`)\n)\nCOMMENT='Users and their assignments to user groups'\n\t\tDEFAULT CHARACTER SET utf8 COLLATE utf8_bin;", "phpmyadmin");
    $q->QUERY_SQL("CREATE TABLE IF NOT EXISTS `pma__usergroups` (\n\t\t`usergroup` varchar(64) NOT NULL,\n\t\t`tab` varchar(64) NOT NULL,\n\t\t`allowed` enum('Y','N') NOT NULL DEFAULT 'N',\n\t\tPRIMARY KEY (`usergroup`,`tab`,`allowed`)\n)\nCOMMENT='User groups with configured menu items'\n\t\tDEFAULT CHARACTER SET utf8 COLLATE utf8_bin;", "phpmyadmin");
    $q->QUERY_SQL("CREATE TABLE IF NOT EXISTS `pma__navigationhiding` (\n\t\t`username` varchar(64) NOT NULL,\n\t\t`item_name` varchar(64) NOT NULL,\n\t\t`item_type` varchar(64) NOT NULL,\n\t\t`db_name` varchar(64) NOT NULL,\n\t\t`table_name` varchar(64) NOT NULL,\n\t\tPRIMARY KEY (`username`,`item_name`,`item_type`,`db_name`,`table_name`)\n)\nCOMMENT='Hidden items of navigation tree'\n\t\tDEFAULT CHARACTER SET utf8 COLLATE utf8_bin;", "phpmyadmin");
    $q->QUERY_SQL("CREATE TABLE IF NOT EXISTS `pma__savedsearches` (\n\t\t`id` int(5) unsigned NOT NULL auto_increment,\n\t\t`username` varchar(64) NOT NULL default '',\n\t\t`db_name` varchar(64) NOT NULL default '',\n\t\t`search_name` varchar(64) NOT NULL default '',\n\t\t`search_data` text NOT NULL,\n\t\tPRIMARY KEY  (`id`),\n\t\tUNIQUE KEY `u_savedsearches_username_dbname` (`username`,`db_name`,`search_name`)\n)", "phpmyadmin");
}
示例#13
0
function start($aspid = false)
{
    $unix = new unix();
    $scriptlog = null;
    if ($GLOBALS["BYSCRIPT"]) {
        $scriptlog = " by init.d script";
    }
    if (is_file("/etc/artica-postfix/FROM_ISO")) {
        if ($unix->file_time_min("/etc/artica-postfix/FROM_ISO") < 1) {
            return;
        }
    }
    if (!$aspid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = $unix->get_pid_from_file($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $pid = LIGHTTPD_PID();
    @mkdir("/usr/share/artica-postfix/ressources/web", 0755, true);
    if (!is_dir("/usr/share/artica-postfix/ressources/web")) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: Framework service Warning !!! /usr/share/artica-postfix/ressources/web (permission denied !)\n";
    }
    if ($unix->process_exists($pid)) {
        if (!$unix->is_socket("/usr/share/artica-postfix/ressources/web/framework.sock")) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: Framework service framework.sock no such socket, stop framework\n";
            }
            stop(true);
        } else {
            $timepid = $unix->PROCCESS_TIME_MIN($pid);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: Framework Service already started {$pid} since {$timepid}Mn...\n";
            }
            return;
        }
    }
    $nohup = $unix->find_program("nohup");
    $php5 = $unix->LOCATE_PHP5_BIN();
    $lighttpd_bin = $unix->find_program("lighttpd");
    if (!is_file($lighttpd_bin)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Framework service lighttpd not found..\n";
        }
        return;
    }
    @mkdir("/var/run/lighttpd", 0755, true);
    $cmd = "{$nohup} {$php5} /usr/share/artica-postfix/exec.web-community-filter.php --register-lic >/dev/null 2>&1 &";
    if ($GLOBALS["VERBOSE"]) {
        echo "{$cmd}\n";
    }
    shell_exec($cmd);
    buildConfig();
    $cmd = "{$lighttpd_bin} -f /etc/artica-postfix/framework.conf";
    if ($GLOBALS["VERBOSE"]) {
        echo "{$cmd}\n";
    }
    shell_exec($cmd);
    for ($i = 0; $i < 6; $i++) {
        $pid = LIGHTTPD_PID();
        if ($unix->process_exists($pid)) {
            if (!$unix->is_socket("/usr/share/artica-postfix/ressources/web/framework.sock")) {
                if ($GLOBALS["OUTPUT"]) {
                    echo "Starting......: " . date("H:i:s") . " [INIT]: Framework service waiting framework.sock\n";
                }
            } else {
                break;
            }
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Framework service waiting {$i}/6...\n";
        }
        sleep(1);
    }
    $pid = LIGHTTPD_PID();
    if ($unix->process_exists($pid)) {
        FrmToSyslog("Success service started pid:{$pid}{$scriptlog}");
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Framework service apply permissions on framework.sock\n";
        }
        @chmod("/usr/share/artica-postfix/ressources/web/framework.sock", 0777);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Framework service apply permissions on Settings direcotry\n";
        }
        $unix->chmod_alldirs(0755, "/etc/artica-postfix/settings/Daemons/*");
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Framework Success service started pid:{$pid}...\n";
        }
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Framework service failed...\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$cmd}\n";
        }
    }
}
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"]);
}
示例#15
0
function start($aspid = false)
{
    $sock = new sockets();
    $unix = new unix();
    $GLOBALS["CLASS_UNIX"] = $unix;
    if (!$aspid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = $unix->get_pid_from_file($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: Already task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $MailArchiverEnabled = $sock->GET_INFO("MailArchiverEnabled");
    $MailArchiverToMySQL = $sock->GET_INFO("MailArchiverToMySQL");
    $MailArchiverToMailBox = $sock->GET_INFO("MailArchiverToMailBox");
    $MailArchiverMailBox = $sock->GET_INFO("MailArchiverMailBox");
    $MailArchiverUsePerl = $sock->GET_INFO("MailArchiverUsePerl");
    if (!is_numeric($MailArchiverEnabled)) {
        $MailArchiverEnabled = 0;
    }
    if (!is_numeric($MailArchiverToMySQL)) {
        $MailArchiverToMySQL = 1;
    }
    if (!is_numeric($MailArchiverUsePerl)) {
        $MailArchiverUsePerl = 1;
    }
    if ($GLOBALS["VERBOSE"]) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: VERBOSE MODE\n";
        }
    }
    if ($MailArchiverEnabled == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Mail Archiver is disabled...\n";
        }
        return;
    }
    if ($MailArchiverUsePerl == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Mail Archiver (Perl method) is disabled...\n";
        }
        return;
    }
    $pid = mailarchive_pid();
    if ($unix->process_exists($pid)) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Mail Archiver (Perl method) already running pid {$pid} since {$time}mn...\n";
        }
        return;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: Mail Archiver (Perl method)...\n";
    }
    $usersMenus = new usersMenus();
    $OS = $usersMenus->LinuxDistriCode;
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: Mail Archiver (Perl method) on {$OS}...\n";
    }
    if ($OS == "DEBIAN" or $OS == "UBUNTU") {
        CheckPerlDebian();
    }
    $mhonarc = $unix->find_program("mhonarc");
    if (!is_file($mhonarc)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Mail Archiver (Perl method) failed mhonarc not such binary !!!\n";
        }
        return;
    }
    $nohup = $unix->find_program("nohup");
    @mkdir("/var/spool/mail-rtt-backup", 0755, true);
    @mkdir("/var/run/maildump", 0777, true);
    @unlink("/var/run/maildump/maildump.socket");
    $cmd = "{$nohup} /usr/share/artica-postfix/bin/milter_archiver.pl >/dev/null 2>&1 &";
    shell_exec($cmd);
    for ($i = 0; $i < 5; $i++) {
        sleep(1);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Mail Archiver (Perl method) waiting {$i}/5...\n";
        }
        $pid = mailarchive_pid();
        if ($unix->process_exists($pid)) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: Mail Archiver (Perl method) Success running with pid {$pid}...\n";
            }
            break;
        }
    }
    $pid = mailarchive_pid();
    if ($unix->process_exists($pid)) {
        for ($i = 0; $i < 5; $i++) {
            if ($unix->is_socket("/var/run/maildump/maildump.socket")) {
                if ($GLOBALS["OUTPUT"]) {
                    echo "Starting......: " . date("H:i:s") . " [INIT]: Mail Archiver permission on maildump.socket done\n";
                }
                @chmod("/var/run/maildump/maildump.socket", 0777);
                break;
            }
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: Mail Archiver waiting socket {$i}/5...\n";
            }
            sleep(1);
        }
        $unix->THREAD_COMMAND_SET("/etc/init.d/artica-status restart --force");
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Mail Archiver (Perl method) failed to start..\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$cmd}\n";
        }
    }
}
示例#16
0
function build()
{
    $unix = new unix();
    $users = new usersMenus();
    $q = new mysql();
    $nohup = $unix->find_program("nohup");
    $hostname_bin = $unix->find_program("hostname");
    $php5 = $unix->LOCATE_PHP5_BIN();
    $sock = new sockets();
    $Myhostname = $sock->GET_INFO("myhostname");
    $oom_kill_allocating_task = $sock->GET_INFO("oom_kill_allocating_task");
    if (!is_numeric($oom_kill_allocating_task)) {
        $oom_kill_allocating_task = 1;
    }
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid";
    $pid = @file_get_contents($pidfile);
    $sysctl = $unix->find_program("sysctl");
    $ifconfig = $unix->find_program("ifconfig");
    $GLOBALS["ipbin"] = $unix->find_program("ip");
    $GLOBALS["SCRIPTS_DOWN"] = array();
    if ($unix->process_exists($pid, basename(__FILE__))) {
        event("Building networks already executed PID: {$pid}", __FUNCTION__, __LINE__);
        echo "Starting......: " . date("H:i:s") . " Building networks already executed PID: {$pid}\n";
        die;
    }
    $fqdn = @file_get_contents("/etc/artica-postfix/FULL_HOSTNAME");
    if (is_file("/etc/init.d/hostname.sh")) {
        if (is_file("/usr/sbin/update-rc.d")) {
            shell_exec("/usr/sbin/update-rc.d -f hostname remove >/dev/null 2>&1");
            @unlink("/etc/init.d/hostname.sh");
        }
    }
    if ($oom_kill_allocating_task == 1) {
        echo "Starting......: " . date("H:i:s") . " Kernel oom_kill_allocating_task is enabled\n";
        shell_exec("{$sysctl} -w \"vm.oom_dump_tasks=1\" >/dev/null 2>&1");
        shell_exec("{$sysctl} -w \"vm.oom_kill_allocating_task=1\" >/dev/null 2>&1");
    } else {
        echo "Starting......: " . date("H:i:s") . " Kernel oom_kill_allocating_task is disabled\n";
        shell_exec("{$sysctl} -w \"vm.oom_dump_tasks=0\" >/dev/null 2>&1");
        shell_exec("{$sysctl} -w \"vm.oom_kill_allocating_task=0\" >/dev/null 2>&1");
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "Line:" . __LINE__ . " persistent_net_rules()\n";
    }
    persistent_net_rules();
    if ($GLOBALS["VERBOSE"]) {
        echo "Line:" . __LINE__ . " dev_shm()\n";
    }
    dev_shm();
    $ip = $unix->find_program("ip");
    $echobin = $unix->find_program("echo");
    $logger = $unix->find_program("logger");
    $IPROUTEFOUND = false;
    exec("{$ip} route", $results);
    events("IP route -> " . count($results) . " lines", __FUNCTION__, __LINE__);
    while (list($index, $line) = each($results)) {
        events("IP route -> {$line}", __FUNCTION__, __LINE__);
        if (preg_match("#default via#", $line)) {
            events("IP route found default via -> {$line}", __FUNCTION__, __LINE__);
            $IPROUTEFOUND = true;
        }
    }
    if (!$IPROUTEFOUND) {
        @unlink("/etc/artica-postfix/MEM_INTERFACES");
    }
    if (is_file("/etc/artica-postfix/MEM_INTERFACES")) {
        $MEM_INTERFACES = unserialize(@file_get_contents("/etc/artica-postfix/MEM_INTERFACES"));
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "Line:" . __LINE__ . " MEM_INTERFACES()\n";
    }
    $EXECUTE_CMDS = true;
    if (is_array($MEM_INTERFACES)) {
        $EXECUTE_CMDS = false;
        if ($GLOBALS["VERBOSE"]) {
            echo "Line:" . __LINE__ . " NETWORK_ALL_INTERFACES()\n";
        }
        $array = $unix->NETWORK_ALL_INTERFACES();
        while (list($Interface, $ipaddr) = each($MEM_INTERFACES)) {
            if ($ipaddr == null) {
                continue;
            }
            if ($GLOBALS["VERBOSE"]) {
                echo "Line:" . __LINE__ . " {$Interface} Must be {$ipaddr} -> {$array[$Interface]["IPADDR"]}\n";
            }
            events("{$Interface} Must be {$ipaddr} -> {$array[$Interface]["IPADDR"]}", __FUNCTION__, __LINE__);
            if ($ipaddr != $array[$Interface]["IPADDR"]) {
                events("Must rebuilded....", __FUNCTION__, __LINE__);
                $EXECUTE_CMDS = true;
                break;
            }
        }
    }
    if ($q->mysql_server == "127.0.0.1") {
        if (!$unix->is_socket("/var/run/mysqld/mysqld.sock")) {
            event("/var/run/mysqld/mysqld.sock no such socket", __FUNCTION__, __LINE__);
            echo "Starting......: " . date("H:i:s") . " Building networks MySQL database not available starting MySQL service...\n";
            shell_exec("{$nohup} {$php5} /usr/share/artica-postfix/exec.initd-mysql.php >/dev/null 2>&1 &");
            shell_exec("{$nohup} /etc/init.d/mysql start >/dev/null 2>&1 &");
            sleep(1);
            for ($i = 0; $i < 5; $i++) {
                $q = new mysql();
                if (!is_file("/var/run/mysqld/mysqld.sock")) {
                    echo "Starting......: " . date("H:i:s") . " Building networks waiting MySQL database to start...{$i}/4\n";
                    sleep(1);
                } else {
                    break;
                }
            }
            if (!$unix->is_socket("/var/run/mysqld/mysqld.sock")) {
                event("/var/run/mysqld/mysqld.sock no such socket", __FUNCTION__, __LINE__);
                echo "Starting......: " . date("H:i:s") . " Building networks MySQL database not available...\n";
                die;
            }
        }
    }
    shell_exec("{$nohup} {$php5} /usr/share/artica-postfix/exec.initd-mysql.php >/dev/null 2>&1 &");
    if (!$q->BD_CONNECT()) {
        sleep(1);
        event("Building networks MySQL database not available starting MySQL service", __FUNCTION__, __LINE__);
        echo "Starting......: " . date("H:i:s") . " Building networks MySQL database not available starting MySQL service...\n";
        shell_exec("{$nohup} /etc/init.d/mysql start >/dev/null 2>&1 &");
        for ($i = 0; $i < 5; $i++) {
            $q = new mysql();
            if (!$q->BD_CONNECT()) {
                echo "Starting......: " . date("H:i:s") . " Building networks waiting MySQL database to start...{$i}/4\n";
                sleep(1);
            } else {
                break;
            }
        }
        $q = new mysql();
        if (!$q->BD_CONNECT()) {
            event("Building networks MySQL database not available...", __FUNCTION__, __LINE__);
            echo "Starting......: " . date("H:i:s") . " Building networks MySQL database not available...\n";
            die;
        }
    }
    if (!$q->TABLE_EXISTS("nics", "artica_backup", true)) {
        echo "Starting......: " . date("H:i:s") . " Building networks MySQL table is not yet builded..\n";
        die;
    }
    $GLOBALS["SAVED_INTERFACES"] = array();
    Checkipv6();
    @file_put_contents($pidfile, getmypid());
    echo "Starting......: " . date("H:i:s") . " Building networks checking bridge\n";
    bridges_build();
    echo "Starting......: " . date("H:i:s") . " Building networks checking IPV6\n";
    Checkipv6();
    $nic = new system_nic();
    $datas = $nic->root_build_debian_config();
    echo "Starting......: " . date("H:i:s") . " Building networks Reloading " . count($GLOBALS["SAVED_INTERFACES"]) . " interface(s)\n";
    if (count($GLOBALS["SAVED_INTERFACES"]) == 0) {
        echo "Starting......: " . date("H:i:s") . " Building networks Building Ipv6 virtuals IP...\n";
        Checkipv6Virts();
    }
    $EXECUTE_CMDS = false;
    if (is_file("/etc/init.d/hostname.sh")) {
        if (is_file("/usr/sbin/update-rc.d")) {
            shell_exec("/usr/sbin/update-rc.d -f hostname remove >/dev/null 2>&1");
            @unlink("/etc/init.d/hostname.sh");
        }
    }
    LoadProcNetDev();
    $GLOBALS["SCRIPTS_TOP"][] = "# [" . __LINE__ . "]";
    $GLOBALS["SCRIPTS_TOP"][] = "# [" . __LINE__ . "] *******************************";
    $GLOBALS["SCRIPTS_TOP"][] = "# [" . __LINE__ . "] **** SETTINGS for LOOP BACK ***";
    $GLOBALS["SCRIPTS_TOP"][] = "# [" . __LINE__ . "] *******************************";
    $GLOBALS["SCRIPTS_TOP"][] = "# [" . __LINE__ . "]";
    $ModeProbeAlx = intval($sock->GET_INFO("ModeProbeAlx"));
    $GLOBALS["SCRIPTS_TOP"][] = "# [" . __LINE__ . "] ALX driver: {$ModeProbeAlx}";
    if ($ModeProbeAlx == 1) {
        $modprobe = $unix->find_program("modprobe");
        $GLOBALS["SCRIPTS_TOP"][] = "{$modprobe} alx";
    }
    $GLOBALS["SCRIPTS_TOP"][] = "{$ifconfig} lo 127.0.0.1 up";
    if ($Myhostname != null) {
        $GLOBALS["SCRIPTS_TOP"][] = "{$hostname_bin} \"{$Myhostname}\"";
    }
    $GLOBALS["SCRIPTS_TOP"][] = "# [" . __LINE__ . "]";
    $datas = $nic->networks_disabled();
    $sh = array();
    $sh[] = "#!/bin/sh -e";
    $sh[] = "### BEGIN INIT INFO";
    $sh[] = "# Builded on " . date("Y-m-d H:i:s");
    $sh[] = "# Provides:          artica-ifup";
    $sh[] = "# Required-Start:    mountkernfs \$local_fs";
    $sh[] = "# Required-Stop:     \$local_fs";
    $sh[] = "# Should-Start:\t\tifupdown";
    $sh[] = "# Should-Stop:\t\tifupdown";
    $sh[] = "# Default-Start:     S";
    $sh[] = "# Default-Stop:      0 6";
    $sh[] = "# Short-Description: start and stop the network";
    $sh[] = "# Description:       Artica ifup service Raise network interfaces";
    $sh[] = "### END INIT INFO";
    $sh[] = "case \"\$1\" in";
    $sh[] = "start)";
    $sh[] = "{$logger} \"kernel: [  Artica-Net] Artica network Script executed (start)\" || true";
    $mkdir = $unix->find_program("mkdir");
    $sh[] = "mkdir -p /run/network >/dev/null 2>&1";
    $sh[] = "{$php5} /usr/share/artica-postfix/exec.virtuals-ip-notify.php --start \$2 \$3 || true";
    etc_hosts();
    routes_main();
    ucarp_build(true);
    bridges_build();
    IPTABLES_NETWORK_BRIDGES();
    $sh[] = "{$echobin} \"\" > /var/log/net-start.log";
    $sh[] = "{$echobin} \"  **** Apply Network configuration, please wait... ****\"";
    while (list($index, $line) = each($GLOBALS["SCRIPTS_TOP"])) {
        $line = trim($line);
        if ($line == null) {
            continue;
        }
        if (substr($line, 0, 1) == "#") {
            $sh[] = ScriptInfo($line);
            continue;
        }
        $md = md5($line);
        if (isset($AL[$md])) {
            echo "Starting......: " . date("H:i:s") . " SKIPING `{$line}`\n";
            continue;
        }
        $AL[$md] = true;
        echo "Starting......: " . date("H:i:s") . " `{$line}`\n";
        if (strpos($line, "/etc/hosts") > 0) {
            $sh[] = "{$line}";
            continue;
        }
        if (preg_match("#ifconfig\\s+(.+?)\\s+(.+?)netmask(.+?)\\s+#", $line, $re)) {
            $sh[] = "{$echobin} \"adding {$re[2]}/{$re[3]} in {$re[1]} interface\"";
        }
        $sh[] = "{$echobin} \"{$line}\" >>/var/log/net-start.log 2>&1";
        $sh[] = "{$line} >>/var/log/net-start.log 2>&1 || true";
    }
    while (list($index, $line) = each($GLOBALS["SCRIPTS"])) {
        $line = trim($line);
        if ($line == null) {
            continue;
        }
        if (substr($line, 0, 1) == "#") {
            $sh[] = ScriptInfo($line);
            continue;
        }
        if (preg_match("#^OUTPUT\\s+(.+)#", $line, $re)) {
            $line = str_replace('"', "'", $line);
            $sh[] = "{$echobin} \"{$re[1]}\"";
            continue;
        }
        $md = md5($line);
        if (isset($AL[$md])) {
            echo "Starting......: " . date("H:i:s") . " SKIPING `{$line}`\n";
            continue;
        }
        $AL[$md] = true;
        echo "Starting......: " . date("H:i:s") . " `{$line}`\n";
        if (strpos($line, "/etc/hosts") > 0) {
            $sh[] = "{$line}";
            continue;
        }
        if (preg_match("#ifconfig\\s+(.+?)\\s+(.+?)netmask(.+?)\\s+#", $line, $re)) {
            $sh[] = "{$echobin} \"adding {$re[2]}/{$re[3]} in {$re[1]} interface\"";
        }
        if (strpos('echo "', $line) == 0) {
            $sh[] = "{$echobin} \"{$line}\" >>/var/log/net-start.log 2>&1";
        }
        $sh[] = "{$line} >>/var/log/net-start.log 2>&1 || true";
    }
    if (count($GLOBALS["SCRIPTS_ROUTES"]) > 0) {
        $GLOBALS["START_ROUTES"][] = "{$echobin} \"Apply network routes, please wait...\"";
        $sh[] = "";
        $sh[] = "# [" . __LINE__ . "]";
        $sh[] = "# [" . __LINE__ . "] *******************************";
        $sh[] = "# [" . __LINE__ . "] ****     NETWORK ROUTES    ****";
        $sh[] = "# [" . __LINE__ . "] *******************************";
        $sh[] = "# [" . __LINE__ . "]";
        while (list($index, $line) = each($GLOBALS["SCRIPTS_ROUTES"])) {
            $line = trim($line);
            if ($line == null) {
                continue;
            }
            if (substr($line, 0, 1) == "#") {
                $ScriptInfo = ScriptInfo($line);
                $sh[] = $ScriptInfo;
                $GLOBALS["START_ROUTES"][] = $ScriptInfo;
                continue;
            }
            $md = md5($line);
            if (isset($AL[$md])) {
                if (!preg_match("#^force#", $line)) {
                    echo "Starting......: " . date("H:i:s") . " SKIPING `{$line}`\n";
                    continue;
                }
            }
            if (preg_match("#^force:(.+)#", $line, $re)) {
                $line = $re[1];
                $md = md5($line);
            }
            $AL[$md] = true;
            if (preg_match("#ip route add (.+?)\\s+.*?src\\s+(.+)#", $line, $re)) {
                $GLOBALS["START_ROUTES"][] = "{$echobin} \"Create route for network {$re[1]} for local address {$re[2]}\"";
                $sh[] = "{$echobin} \"Create route for network {$re[1]} for local address {$re[2]}\"";
            }
            if (preg_match("#ip route add (.+?)\\s+via(.+?)\\s+src\\s+([0-9\\.]+)#", $line, $re)) {
                $GLOBALS["START_ROUTES"][] = "{$echobin} \"Create route for network {$re[1]} using gateway {$re[2]} for local address {$re[3]}\"";
                $sh[] = "{$echobin} \"Create route for network {$re[1]} using gateway {$re[2]} for local address {$re[3]}\"";
            }
            $GLOBALS["START_ROUTES"][] = "{$echobin} \"{$line}\" >>/var/log/net-start.log 2>&1";
            $sh[] = "{$echobin} \"{$line}\" >>/var/log/net-start.log 2>&1";
            if (preg_match("#\\/echo\\s+#", $line)) {
                $sh[] = $line;
                continue;
            }
            $sh[] = "{$line} >>/var/log/net-start.log 2>&1 || true";
            $GLOBALS["START_ROUTES"][] = "{$line} >>/var/log/net-start.log 2>&1 || true";
        }
    }
    $sh[] = "if [ -x /etc/init.d/artica-ifup-content.sh ] ; then";
    $sh[] = "\t/etc/init.d/artica-ifup-content.sh || true";
    $sh[] = "fi";
    $sh[] = nics_vde_build();
    $EnablePDNS = $sock->GET_INFO("EnablePDNS");
    if (!is_numeric($EnablePDNS)) {
        $EnablePDNS = 0;
    }
    $unix = new unix();
    $squid = $unix->LOCATE_SQUID_BIN();
    $ip = $unix->find_program("ip");
    $echo = $unix->find_program("echo");
    $nohup = $unix->find_program("nohup");
    $monit = $unix->find_program("monit");
    $ifconfig = $unix->find_program("ifconfig");
    $php = $unix->LOCATE_PHP5_BIN();
    if (is_file($squid)) {
        $sh[] = "# [" . __LINE__ . "] Reloading squid";
        $sh[] = "{$echo} \"Reloading squid ( if exists )\"";
        $sh[] = "{$nohup} {$php} /usr/share/artica-postfix/exec.squid.php --kreconfigure 2>&1 >>/var/log/net-start.log 2>&1 &";
    }
    $sh[] = "# [" . __LINE__ . "] Flushing ARP cache";
    $sh[] = "{$echo} \"Flushing ARP cache...\"";
    $sh[] = "ip -s -s neigh flush all >>/var/log/net-start.log 2>&1 || true";
    $sh[] = "# [" . __LINE__ . "] Tune the kernel";
    $sh[] = "{$echo} \"Tuning the kernel...\"";
    $sh[] = "{$php5} /usr/share/artica-postfix/exec.sysctl.php --build >>/var/log/net-start.log 2>&1 || true";
    $sh[] = "if [ -x /bin/artica-firewall.sh ] ; then";
    $sh[] = "\t/bin/artica-firewall.sh || true";
    $sh[] = "fi";
    if (is_file("/etc/init.d/ssh")) {
        $sh[] = "# [" . __LINE__ . "] Starting sshd";
        $sh[] = "{$echo} \"Starting sshd\"";
        $sh[] = "/etc/init.d/ssh start 2>&1 || true";
    }
    $sh[] = "# [" . __LINE__ . "] Starting FrameWork";
    $sh[] = "{$echo} \"Starting FrameWork\"";
    $sh[] = "{$nohup} {$php5} /usr/share/artica-postfix/exec.framework.php --start >/dev/null 2>&1 &";
    $sh[] = "# [" . __LINE__ . "] Starting Meta Server Client";
    $sh[] = "{$echo} \"Starting FrameWork\"";
    $sh[] = "{$nohup} {$php5} /usr/share/artica-postfix/exec.artica-meta-client.php --ping --force >/dev/null 2>&1 &";
    if ($EnablePDNS == 1) {
        $sh[] = "# [" . __LINE__ . "] Reloading PowerDNS...";
        $sh[] = "{$echo} \"Reloading PowerDNS\"";
        $sh[] = "{$php5} /usr/share/artica-postfix/exec.pdns.php --reload 2>&1 || true";
    }
    if (is_file($monit)) {
        $sh[] = "# [" . __LINE__ . "] Starting Monit in background";
        $sh[] = "{$echo} \"Starting Monit in background\"";
        $sh[] = "{$nohup} {$monit} -c /etc/monit/monitrc -p /var/run/monit/monit.pid -s /var/run/monit/monit.state >/dev/null 2>&1 &";
    }
    $mount = $unix->find_program("mount");
    if (is_file($mount)) {
        $sh[] = "# [" . __LINE__ . "] Mount all system after network set";
        $sh[] = "{$echo} \"Starting mount in background\"";
        $sh[] = "{$nohup} {$mount} -a >/dev/null 2>&1 &";
    }
    $sh[] = "# [" . __LINE__ . "] Reloading DHCPD (if exists)";
    $sh[] = "{$echo} \"Reloading DHCP server ( if exists )\"";
    $sh[] = "{$php5} /usr/share/artica-postfix/exec.dhcpd.compile.php --reload-if-run 2>&1 || true";
    $sh[] = "{$echo} \"  ****      Apply Network configuration, done      ****\"";
    $sh[] = ";;";
    $sh[] = "  stop)";
    $sh[] = "{$logger} \"* * * * * * * * * * * * * * SUSPECTED STOPPED SERVER !!! * * * * * * * * * * * * * *\" || true";
    $sh[] = "{$logger} \"kernel: [  Artica-Net] Artica network Script executed (stop)\" || true";
    if (is_array($GLOBALS["SCRIPTS_DOWN"])) {
        while (list($index, $line) = each($GLOBALS["SCRIPTS_DOWN"])) {
            if (substr($line, 0, 1) == "#") {
                $sh[] = ScriptInfo($line);
                continue;
            }
            $sh[] = "{$line} >>/var/log/net-stop.log 2>&1 || true";
        }
    }
    $php = $unix->LOCATE_PHP5_BIN();
    $sh[] = ";;";
    $sh[] = "reconfigure)";
    $sh[] = "{$logger} \"kernel: [  Artica-Net] Artica network Script Executed (reconfigure)\" || true";
    $sh[] = "{$php} " . __FILE__ . " --build --force \$2 \$3";
    $sh[] = "/etc/init.d/artica-ifup start";
    $sh[] = ";;";
    $sh[] = "routes)";
    $sh[] = "{$logger} \"kernel: [  Artica-Net] Artica network Script Executed (routes)\" || true";
    $sh[] = "# Array of " . count($GLOBALS["START_ROUTES"]);
    $sh[] = "{$echobin} \"Flushing routes tables...\"";
    $sh[] = "{$GLOBALS["ipbin"]} route flush table all";
    $sh[] = "{$echobin} \"{$ifconfig} lo 127.0.0.1 down\"";
    $sh[] = "{$ifconfig} lo 127.0.0.1 down || true";
    $sh[] = "{$echobin} \"{$ifconfig} lo 127.0.0.1 up\"";
    $sh[] = "{$ifconfig} lo 127.0.0.1 up || true";
    $sh[] = "{$echobin} \"Apply routes to the system\"";
    $sh[] = "{$echobin} \"Running routes\" > /var/log/net-start.log 2>&1";
    $sh[] = @implode("\n", $GLOBALS["START_ROUTES"]);
    $sh[] = "{$echobin} \"Routes applied to the system\"";
    $sh[] = ";;";
    $sh[] = "*)";
    $sh[] = "{$logger} \"kernel: [  Artica-Net] Artica network Script executed (unknown)\" || true";
    $sh[] = " echo \"Usage: \$0 {start or reconfigure only}\"";
    $sh[] = "exit 1";
    $sh[] = ";;";
    $sh[] = "esac";
    $sh[] = "exit 0\n";
    @file_put_contents("/etc/init.d/artica-ifup", @implode("\n", $sh));
    @chmod("/etc/init.d/artica-ifup", 0755);
    if (is_file('/usr/sbin/update-rc.d')) {
        shell_exec("/usr/sbin/update-rc.d -f artica-ifup defaults >/dev/null 2>&1");
        if (is_file('/etc/init.d/networking')) {
            shell_exec("/usr/sbin/update-rc.d -f networking disable  >/dev/null 2>&1");
            @copy("/etc/init.d/networking", "/etc/init.d/networking.back");
            @unlink("/etc/init.d/networking");
        }
    }
    if (is_file('/sbin/chkconfig')) {
        shell_exec("/sbin/chkconfig --add artica-ifup >/dev/null 2>&1");
        shell_exec("/sbin/chkconfig --level 1234 artica-ifup on >/dev/null 2>&1");
    }
    $inter[] = "# This file describes the network interfaces available on your system";
    $inter[] = "## and how to activate them. For more information, see interfaces(5).";
    $inter[] = "";
    $inter[] = "## The loopback network interface";
    $inter[] = "auto lo";
    $inter[] = "iface lo inet loopback";
    $inter[] = "";
    $inter[] = "";
    if (is_file("/etc/network/interfaces")) {
        @file_put_contents("/etc/network/interfaces", @implode("\n", $inter));
    }
    squid_admin_mysql(1, "Network script was rebuilded", null, __FILE__, __LINE__);
    echo "Starting......: " . date("H:i:s") . " Building FireWall rules.\n";
    system("{$php5} /usr/share/artica-postfix/exec.firehol.php --build");
    echo "Starting......: " . date("H:i:s") . " done...\n";
}
示例#17
0
function start($aspid = false, $verifdbs = false)
{
    $unix = new unix();
    $sock = new sockets();
    $Masterbin = "/opt/ufdbcat/bin/ufdbcatdd";
    if (!is_file($Masterbin)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, ufdbguardd not installed\n";
        }
        return;
    }
    if (!$aspid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = $unix->get_pid_from_file($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $pid = PID_NUM();
    if ($unix->process_exists($pid)) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Service already started {$pid} since {$timepid}Mn...\n";
        }
        if ($GLOBALS["MONIT"]) {
            @file_put_contents($GLOBALS["PID_PATH"], $pid);
        }
        return;
    }
    $DisableUfdbCat = $sock->DisableUfdbCat();
    if ($DisableUfdbCat == 1) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service disabled (see DisableUfdbCat)\n";
        }
        stop();
        return;
    }
    $php5 = $unix->LOCATE_PHP5_BIN();
    $sysctl = $unix->find_program("sysctl");
    $echo = $unix->find_program("echo");
    $nohup = $unix->find_program("nohup");
    $kill = $unix->find_program("kill");
    $cp = $unix->find_program("cp");
    @mkdir("/etc/ufdbcat", 0755, true);
    @mkdir("/var/log/ufdbcat", 0755, true);
    @mkdir(dirname($GLOBALS["PID_PATH"]), 0755, true);
    @chmod($GLOBALS["PID_PATH"], 0755);
    @chmod($Masterbin, 0755);
    build_progress("{starting_service}", 10);
    CheckDirectories($verifdbs);
    if (is_file("/var/log/ufdbcat/ufdbguardd.log")) {
        @unlink("/var/log/ufdbcat/ufdbguardd.log");
    }
    if (is_file("/var/run/ufdbcat-03977")) {
        @unlink("/var/run/ufdbcat-03977");
    }
    if ($unix->is_socket("/var/run/ufdbcat-03977")) {
        @unlink("/var/run/ufdbcat-03977");
    }
    $AsCategoriesAppliance = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/AsCategoriesAppliance"));
    $Threads = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/UfdbCatThreads"));
    if ($Threads == 0) {
        $Threads = 4;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} pid path: {$GLOBALS["PID_PATH"]}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Threads:{$Threads}\n";
    }
    if (is_file("/opt/ufdbcat/bin/ufdbhttpd")) {
        @unlink("/opt/ufdbcat/bin/ufdbhttpd");
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} ** Categories Appliance Mode ***\n";
    }
    $isRemoteSockets = isRemoteSockets();
    if ($isRemoteSockets) {
        if (!is_file("{$Masterbin}.sock")) {
            @copy($Masterbin, "{$Masterbin}.sock");
        }
        $ufdbguardd = $unix->find_program("ufdbguardd");
        if (!is_file($ufdbguardd)) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Fatal ufdbguardd no such binary!!!\n";
            }
            return false;
        }
        @unlink($Masterbin);
        @copy($ufdbguardd, $Masterbin);
    }
    if (!$isRemoteSockets) {
        if (is_file("{$Masterbin}.sock")) {
            @copy("{$Masterbin}.sock", $Masterbin);
            @unlink("{$Masterbin}.sock");
        }
    }
    @unlink($GLOBALS["PID_PATH"]);
    @chmod($Masterbin, 0755);
    $cmd = "{$Masterbin} -c /etc/ufdbcat/ufdbGuard.conf -U root -w {$Threads} -N >/dev/null 2>&1 &";
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service\n";
    }
    build_progress("{starting_service}", 96);
    squid_admin_mysql(2, "Starting Categories Service", "nothing", __FILE__, __LINE__);
    buildconfig();
    shell_exec($cmd);
    for ($i = 1; $i < 5; $i++) {
        build_progress("{starting_service} {$i}/5", 98);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} waiting {$i}/5\n";
        }
        sleep(1);
        $pid = PID_NUM();
        if ($unix->process_exists($pid)) {
            break;
        }
    }
    $pid = PID_NUM();
    if ($unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Success PID {$pid}\n";
        }
        if (!$isRemoteSockets) {
            for ($i = 1; $i < 10; $i++) {
                if ($GLOBALS["OUTPUT"]) {
                    echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Checking socket {$i}/5...\n";
                }
                sleep(1);
                if ($unix->is_socket("/var/run/ufdbcat-03977")) {
                    if ($GLOBALS["OUTPUT"]) {
                        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Checking socket success...\n";
                    }
                    @chmod("/var/run/ufdbcat-03977", 0777);
                    break;
                }
            }
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Success\n";
        }
        build_progress("{success}", 100);
        return true;
    }
    squid_admin_mysql(0, "Failed to start Categories Service", "nothing", __FILE__, __LINE__);
    build_progress("{failed}", 110);
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Failed\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} {$cmd}\n";
    }
}
示例#18
0
function CheckMySQL()
{
    $unix = new unix();
    $sock = new sockets();
    $EnableSquidRemoteMySQL = $sock->GET_INFO("EnableSquidRemoteMySQL");
    $ProxyUseArticaDB = $sock->GET_INFO("ProxyUseArticaDB");
    $squidEnableRemoteStatistics = $sock->GET_INFO("squidEnableRemoteStatistics");
    if (!is_numeric($squidEnableRemoteStatistics)) {
        $squidEnableRemoteStatistics = 0;
    }
    if (!is_numeric($ProxyUseArticaDB)) {
        $ProxyUseArticaDB = 0;
    }
    if ($EnableSquidRemoteMySQL == 1) {
        return true;
    }
    if ($squidEnableRemoteStatistics == 1) {
        return true;
    }
    if ($ProxyUseArticaDB == 0) {
        return true;
    }
    $filetime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    $time = $unix->file_time_min($filetime);
    $WORKDIR = $sock->GET_INFO("SquidStatsDatabasePath");
    if ($WORKDIR == null) {
        $WORKDIR = "/opt/squidsql";
    }
    if (is_link($WORKDIR)) {
        $WORKDIR = readlink($WORKDIR);
    }
    if (!is_dir("{$WORKDIR}/data")) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " MySQL database not prepared\n";
        }
        shell_exec("/etc/init.d/squid-db start");
        shell_exec("/etc/init.d/artica-status start");
        if (!is_dir("{$WORKDIR}/data")) {
            return;
        }
    }
    if (!is_dir("{$WORKDIR}/data/squidlogs")) {
        if ($unix->is_socket("/var/run/mysqld/squid-db.sock")) {
            include_once dirname(__FILE__) . "/ressources/class.mysql.squid.builder.php";
            $q = new mysql_squid_builder();
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " Creating database squidlogs\n";
            }
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " Use DB: {$q->ProxyUseArticaDB}\n";
            }
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " Socket: {$q->SocketPath}\n";
            }
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " Server: {$q->mysql_server}\n";
            }
            $q->CREATE_DATABASE("squidlogs");
            if (!$q->ok) {
                if ($GLOBALS["OUTPUT"]) {
                    echo "Starting......: " . date("H:i:s") . " {$q->mysql_error}";
                }
                return;
            }
            if (is_dir("{$WORKDIR}/data/squidlogs")) {
                return true;
            }
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " MySQL database not prepared\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " {$WORKDIR}/data/squidlogs no such directory\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " Starting MySQL database\n";
        }
        shell_exec("/etc/init.d/squid-db start");
        shell_exec("/etc/init.d/artica-status start");
    }
    if (!is_dir("{$WORKDIR}/data/squidlogs")) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " MySQL database not prepared\n";
        }
        return;
    }
    return true;
}
示例#19
0
function start($aspid = false)
{
    $unix = new unix();
    $sock = new sockets();
    $Masterbin = $unix->find_program("clamav-milter");
    if (!is_file($Masterbin)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, clamav-milter not installed\n";
        }
        return;
    }
    if (!$aspid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = $unix->get_pid_from_file($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return false;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $pid = PID_NUM();
    if ($unix->process_exists($pid)) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Service already started {$pid} since {$timepid}Mn...\n";
        }
        return true;
    }
    $ClamavMilterEnabled = intval($sock->GET_INFO("ClamavMilterEnabled"));
    $MimeDefangClamav = intval($sock->GET_INFO("MimeDefangClamav"));
    $MimeDefangEnabled = intval($sock->GET_INFO("MimeDefangEnabled"));
    if ($MimeDefangEnabled == 0) {
        $MimeDefangClamav = 0;
    }
    if ($MimeDefangClamav == 1) {
        $ClamavMilterEnabled = 0;
    }
    if ($ClamavMilterEnabled == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service disabled (see ClamavMilterEnabled/MimeDefangEnabled/MimeDefangClamav)\n";
        }
        return false;
    }
    $php5 = $unix->LOCATE_PHP5_BIN();
    $nohup = $unix->find_program("nohup");
    build_progress_restart("{starting_service}", 31);
    $aa_complain = $unix->find_program('aa-complain');
    if (is_file($aa_complain)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} add clamd Profile to AppArmor..\n";
        }
        shell_exec("{$aa_complain} {$Masterbin} >/dev/null 2>&1");
    }
    @mkdir("/var/clamav", 0755, true);
    @mkdir("/var/run/clamav", 0755, true);
    @mkdir("/var/lib/clamav", 0755, true);
    @mkdir("/var/log/clamav", 0755, true);
    $ClamUser = "******";
    $squidbin = $unix->LOCATE_SQUID_BIN();
    if (is_file($squidbin)) {
        $ClamUser = "******";
    }
    $unix->chown_func("{$ClamUser}", "{$ClamUser}", "/var/clamav");
    $unix->chown_func("{$ClamUser}", "{$ClamUser}", "/var/run/clamav");
    $unix->chown_func("{$ClamUser}", "{$ClamUser}", "/var/lib/clamav");
    $unix->chown_func("{$ClamUser}", "{$ClamUser}", "/var/log/clamav");
    build_progress_restart("{starting_service}", 32);
    $clamd_version = clamd_version();
    build();
    $cmd = "{$nohup} {$Masterbin} --config-file=/etc/clamav/clamav-milter.conf >/dev/null 2>&1 &";
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service version {$clamd_version}\n";
    }
    build_progress_restart("{starting_service} (clamd) ", 33);
    system("/etc/init.d/clamav-daemon start");
    shell_exec($cmd);
    for ($i = 1; $i < 5; $i++) {
        build_progress_restart("{starting_service}", 35);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} waiting {$i}/5\n";
        }
        sleep(1);
        $pid = PID_NUM();
        if ($unix->process_exists($pid)) {
            break;
        }
    }
    $pid = PID_NUM();
    if ($unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Success PID {$pid}\n";
        }
        sleep(1);
        for ($i = 1; $i < 11; $i++) {
            build_progress_restart("{starting_service}", 40);
            if ($unix->is_socket("/var/spool/postfix/var/run/clamav/clamav-milter.ctl")) {
                if ($GLOBALS["OUTPUT"]) {
                    echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Apply permissions on clamav-milter.ctl\n";
                }
                @chmod("/var/spool/postfix/var/run/clamav/clamav-milter.ctl", 0777);
                break;
            } else {
                if ($GLOBALS["OUTPUT"]) {
                    echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} waiting for socket... {$i}/10 clamav-milter.ctl\n";
                }
                sleep(1);
            }
        }
        if ($unix->is_socket("/var/spool/postfix/var/run/clamav/clamav-milter.ctl")) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Apply permissions on clamav-milter.ctl\n";
            }
            @chmod("/var/spool/postfix/var/run/clamav/clamav-milter.ctl", 0777);
        } else {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} socket failed\n";
            }
        }
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Failed\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} {$cmd}\n";
        }
        build_progress_restart("{starting_service} {failed}", 40);
        return;
    }
    $pid = PID_NUM();
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Failed..\n";
        }
        build_progress_restart("{starting_service} {failed}", 40);
        return;
    }
    if (!$unix->is_socket("/var/spool/postfix/var/run/clamav/clamav-milter.ctl")) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} socket Failed..\n";
        }
    }
    return true;
}
示例#20
0
function GetUnixSocketPath()
{
    $path = null;
    $unix = new unix();
    if ($path == null) {
        if ($unix->is_socket("/var/run/ufdbcat-03978")) {
            $path = "/var/run/ufdbcat-03978";
        }
    }
    if ($path == null) {
        if ($unix->is_socket("/var/run/ufdbcat-03977")) {
            $path = "/var/run/ufdbcat-03977";
        }
    }
    return $path;
}
示例#21
0
function SingleInstance_start($nopid = false)
{
    $sock = new sockets();
    $unix = new unix();
    if (!$nopid) {
        $unix = new unix();
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . "pid";
        $pid = @file_get_contents($pidfile);
        if ($unix->process_exists($pid)) {
            echo "{$GLOBALS["deflog_start"]} already Artica Starting process exists {$pid}\n";
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $miltergreybin = $unix->find_program("milter-greylist");
    $MilterGreyListEnabled = $sock->GET_INFO("MilterGreyListEnabled");
    if (!is_numeric($MilterGreyListEnabled)) {
        $MilterGreyListEnabled = 0;
    }
    $pid = SingleInstance_pid();
    if ($unix->process_exists($pid)) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "{$GLOBALS["deflog_start"]} Service already started {$pid} since {$timepid}Mn...\n";
        }
        return;
    }
    if ($MilterGreyListEnabled == 0) {
        echo "{$GLOBALS["deflog_start"]} is not enabled ( see MilterGreyListEnabled)\n";
        return;
    }
    $dirs[] = "/var/run/milter-greylist";
    $dirs[] = "/var/spool/postfix/var/run/milter-greylist";
    $dirs[] = "/var/milter-greylist";
    $dirs[] = "/var/lib/milter-greylist";
    $dirs[] = "/usr/local/var/milter-greylist/";
    while (list($num, $directory) = each($dirs)) {
        @mkdir($directory, 0755, true);
        @chown($directory, "postfix");
        @chgrp($directory, "postfix");
        @chmod($directory, 0755);
    }
    $FullSocketPath = "/var/run/milter-greylist/milter-greylist.sock";
    $pidpath = "/var/run/milter-greylist/milter-greylist.pid";
    $dbpath = "/var/milter-greylist/greylist.db";
    $confpath = SingleInstanceConfPath();
    $files[] = "/var/milter-greylist/greylist.db";
    $files[] = "/usr/local/var/milter-greylist/greylist.db";
    while (list($num, $filename) = each($files)) {
        if (!is_file($filename)) {
            @touch($filename);
        }
        @chown($filename, "postfix");
        @chgrp($filename, "postfix");
    }
    $MilterGreyListUseTCPPort = $sock->GET_INFO("MilterGreyListUseTCPPort");
    $MilterGeryListTCPPort = $sock->GET_INFO("MilterGeryListTCPPort");
    if (!is_numeric($MilterGeryListTCPPort)) {
        $MilterGeryListTCPPort = 0;
    }
    if (!is_numeric($MilterGreyListUseTCPPort)) {
        $MilterGreyListUseTCPPort = 0;
    }
    if ($MilterGeryListTCPPort == 0) {
        $MilterGreyListUseTCPPort = 0;
    }
    if (!is_file($confpath)) {
        SingleInstance();
    }
    if (!is_file($dbpath)) {
        @touch($dbpath);
    }
    @chown($dbpath, "postfix");
    @chgrp($dbpath, "postfix");
    if ($MilterGreyListUseTCPPort == 1) {
        $FullSocketPath = "inet:{$MilterGeryListTCPPort}";
    }
    $tmpfile = $unix->FILE_TEMP();
    $nohup = $unix->find_program("nohup");
    if ($GLOBALS["OUTPUT"]) {
        echo "{$GLOBALS["deflog_start"]} running daemon {$miltergreybin}\n";
    }
    $cmd = "{$nohup} {$miltergreybin} -u postfix -P {$pidpath} -p {$FullSocketPath} -f {$confpath} -d {$dbpath} >{$tmpfile} 2>&1 &";
    if ($GLOBALS["VERBOSE"]) {
        echo "**** \n {$cmd} \n ************\n";
    }
    shell_exec($cmd);
    $f = explode("\n", @file_get_contents("{$tmpfile}"));
    while (list($num, $ligne) = each($f)) {
        $ligne = trim($ligne);
        if ($ligne == null) {
            continue;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "{$GLOBALS["deflog_start"]} {$ligne}\n";
        }
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "{$GLOBALS["deflog_start"]} waiting 5s\n";
    }
    for ($i = 1; $i < 6; $i++) {
        if ($GLOBALS["OUTPUT"]) {
            echo "{$GLOBALS["deflog_start"]} waiting {$i}/5\n";
        }
        sleep(1);
        $pid = SingleInstance_pid();
        if ($unix->process_exists($pid)) {
            break;
        }
    }
    $pid = SingleInstance_pid();
    if ($unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "{$GLOBALS["deflog_start"]} Success PID {$pid}\n";
        }
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "{$GLOBALS["deflog_start"]} Failed\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "{$cmd}\n";
        }
        return;
    }
    for ($i = 1; $i < 15; $i++) {
        if (!$unix->is_socket($FullSocketPath)) {
            $socketname = basename($FullSocketPath);
            if ($GLOBALS["OUTPUT"]) {
                echo "{$GLOBALS["deflog_start"]} Waiting {$socketname} socket {$i}/5...\n";
            }
            sleep(1);
            continue;
        }
        break;
    }
    if ($unix->is_socket($FullSocketPath)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "{$GLOBALS["deflog_start"]} {$FullSocketPath} OK\n";
        }
        @chown("{$FullSocketPath}", "postfix");
        @chgrp($FullSocketPath, "postfix");
        @chmod($FullSocketPath, 0777);
    }
}
示例#22
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";
        }
    }
}
示例#23
0
function CleanAllindDir($DirPath, $maxtime = 180)
{
    if (!is_dir($DirPath)) {
        return;
    }
    $unix = new unix();
    if (!($handle = opendir($DirPath))) {
        return;
    }
    while (false !== ($file = readdir($handle))) {
        if ($file == ".") {
            continue;
        }
        if ($file == "..") {
            continue;
        }
        if (is_dir($DirPath)) {
            continue;
        }
        $path = "{$DirPath}/{$file}";
        if (preg_match("#_[0-9]+_tmp#", $file)) {
            @unlink($path);
            continue;
        }
        if ($unix->is_socket($path)) {
            continue;
        }
        $time = $unix->file_time_min($path);
        if ($time < $maxtime) {
            continue;
        }
        $size = @filesize($path) / 1024;
        $GLOBALS["DELETED_SIZE"] = $GLOBALS["DELETED_SIZE"] + $size;
        $GLOBALS["DELETED_FILES"] = $GLOBALS["DELETED_FILES"] + 1;
        if ($GLOBALS["VERBOSE"]) {
            echo "{$path} - > DELETE\n";
        }
        @unlink($path);
    }
}
示例#24
0
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";
    }
}
示例#25
0
function start($aspid = false)
{
    $unix = new unix();
    $sock = new sockets();
    $nginx = $unix->find_program("nginx");
    if (!is_file($nginx)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx, not installed\n";
        }
        return;
    }
    if (!$aspid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = $unix->get_pid_from_file($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $MEMORY = $unix->MEM_TOTAL_INSTALLEE();
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx {$MEMORY}K\n";
    }
    $pid = PID_NUM();
    if ($unix->process_exists($pid)) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx Service already started {$pid} since {$timepid}Mn...\n";
        }
        return;
    }
    $php = $unix->LOCATE_PHP5_BIN();
    $EnableNginx = intval($sock->GET_INFO("EnableNginx"));
    $SquidAllow80Port = intval($sock->GET_INFO("SquidAllow80Port"));
    if (is_file("/etc/artica-postfix/WORDPRESS_APPLIANCE")) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx, is Wordpress Appliance\n";
        }
        $sock->SET_INFO("EnableNginx", 1);
        if (!is_dir("/usr/share/wordpress-src")) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx, Installing Wordpress\n";
            }
            shell_exec("{$php} /usr/share/artica-postfix/exec.wordpress.download.php");
        }
        $EnableNginx = 1;
    }
    if (!is_numeric($EnableNginx)) {
        $EnableNginx = 1;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx service \"EnableNginx\" = {$EnableNginx}\n";
    }
    if ($SquidAllow80Port == 1) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx service disabled (SquidAllow80Port)\n";
        }
        return;
    }
    if ($EnableNginx == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx service disabled\n";
        }
        return;
    }
    GHOSTS_PID();
    @mkdir("/home/nginx/tmp", 0755, true);
    @mkdir("/var/log/nginx", 0755, true);
    $nohup = $unix->find_program("nohup");
    $fuser = $unix->find_program("fuser");
    $kill = $unix->find_program("kill");
    $results = array();
    $FUSERS = array();
    $unix->KILL_PROCESSES_BY_PORT(80);
    $unix->KILL_PROCESSES_BY_PORT(443);
    $php5 = $unix->LOCATE_PHP5_BIN();
    if ($unix->is_socket("/var/run/nginx-authenticator.sock")) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Remove authenticator socket\n";
        }
        @unlink("/var/run/nginx-authenticator.sock");
    }
    if (is_file("/var/run/nginx-authenticator.sock")) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Remove authenticator socket\n";
        }
        @unlink("/var/run/nginx-authenticator.sock");
    }
    nginx_mime_types();
    @unlink("/etc/nginx/conf.d/default.conf");
    $cmd = "{$nginx} -c /etc/nginx/nginx.conf";
    if ($GLOBALS["VERBOSE"]) {
        echo "{$cmd}\n";
    }
    shell_exec($cmd);
    for ($i = 0; $i < 6; $i++) {
        $pid = PID_NUM();
        if ($unix->process_exists($pid)) {
            break;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx service waiting {$i}/6...\n";
        }
        sleep(1);
    }
    $pid = PID_NUM();
    if ($unix->process_exists($pid)) {
        nginx_admin_mysql(2, "Nginx Web service success to start [action=info]", null, __FILE__, __LINE__);
        @unlink($GLOBALS["pidStampReload"]);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx service Success service started pid:{$pid}...\n";
        }
        $php5 = $unix->LOCATE_PHP5_BIN();
        shell_exec("{$nohup} {$php5} /usr/share/artica-postfix/exec.php-fpm.php --start >/dev/null 2>&1 &");
        shell_exec("{$nohup} {$php} /usr/share/artica-postfix/exec.nginx.wizard.php --avail-status --force >/dev/null 2>&1 &");
        return;
    }
    nginx_admin_mysql(0, "Nginx Web service failed to start [action=info]", null, __FILE__, __LINE__);
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx service failed...\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$cmd}\n";
    }
    $cmd = "{$nohup} {$php5} /usr/share/artica-postfix/exec.web-community-filter.php --register-lic >/dev/null 2>&1 &";
    if ($GLOBALS["VERBOSE"]) {
        echo "{$cmd}\n";
    }
}
示例#26
0
function purge($aspid = false)
{
    $unix = new unix();
    $sock = new sockets();
    $workdir = "/var/lib/c_icap/temporary";
    if (is_link($workdir)) {
        $workdir = readlink($workdir);
    }
    if (!is_dir($workdir)) {
        return;
    }
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pidTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    $rm = $unix->find_program("rm");
    if ($GLOBALS["VERBOSE"]) {
        echo "pidfile: {$pidfile}\n";
        echo "pidTime: {$pidTime}\n";
    }
    if (!$aspid) {
        $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]: c-icap service Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
    }
    if (!$GLOBALS["FORCE"]) {
        if (isset($GLOBALS["SCHEDULE"])) {
            $Time = $unix->file_time_min($pidTime);
            if ($GLOBALS["VERBOSE"]) {
                echo "Time:{$Time}Mn\n";
            }
            if ($Time < 20) {
                if ($GLOBALS["VERBOSE"]) {
                    echo "Time:{$Time}Mn < 20 -> Die();\n";
                }
                return;
            }
        }
    }
    if ($GLOBALS["FORCE"]) {
        $Time = $unix->file_time_min($pidTime);
        if ($Time < 1) {
            if ($GLOBALS["VERBOSE"]) {
                echo "Time:{$Time}Mn < 1 -> Die();\n";
            }
            return;
        }
    }
    @unlink($pidTime);
    @file_put_contents($pidTime, time());
    $MaxCICAPWorkTimeMin = $sock->GET_INFO("MaxCICAPWorkTimeMin");
    $MaxCICAPWorkSize = $sock->GET_INFO("MaxCICAPWorkSize");
    if (!is_numeric($MaxCICAPWorkTimeMin)) {
        $MaxCICAPWorkTimeMin = 1440;
    }
    if (!is_numeric($MaxCICAPWorkSize)) {
        $MaxCICAPWorkSize = 5000;
    }
    $size = round($unix->DIRSIZE_KO($workdir) / 1024, 2);
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: c-icap service `{$workdir}` {$size}MB/{$MaxCICAPWorkSize}\n";
    }
    @file_put_contents($pidfile, getmypid());
    $squidbin = $unix->LOCATE_SQUID_BIN();
    $sync = $unix->find_program("sync");
    if ($size > $MaxCICAPWorkSize) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: c-icap service {$size}MB exceed size!\n";
        }
        squid_admin_mysql(0, "C-ICAP: `{$workdir}` {$size}MB exceed size!", "Artica will remove all files..\n", __FILE__, __LINE__);
        shell_exec("{$rm} {$workdir}/*");
        shell_exec($sync);
        stop(true);
        start(true);
        squid_admin_mysql(2, "Reconfiguring proxy service\n", __FILE__, __LINE__);
        shell_exec("/etc/init.d/squid reload --script=" . basename(__FILE__));
        return;
    }
    if ($GLOBALS["ALL"]) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: c-icap service {$size}MB exceed size!\n";
        }
        squid_admin_mysql(0, "C-ICAP: `{$workdir}` {$size}MB exceed size!", "Artica will remove all files..\n", __FILE__, __LINE__);
        shell_exec("{$rm} {$workdir}/*");
        shell_exec($sync);
        stop(true);
        start(true);
        squid_admin_mysql(2, "Reconfiguring proxy service\n", __FILE__, __LINE__);
        shell_exec("/etc/init.d/squid reload --script=" . basename(__FILE__));
        return;
    }
    if (!($handle = opendir($workdir))) {
        return;
    }
    while (false !== ($file = readdir($handle))) {
        if ($file == ".") {
            continue;
        }
        if ($file == "..") {
            continue;
        }
        if (is_dir($workdir)) {
            continue;
        }
        $path = "{$workdir}/{$file}";
        $size = @filesize($path);
        $size = $size / 1024;
        $size = $size / 1024;
        if ($unix->is_socket($path)) {
            continue;
        }
        $time = $unix->file_time_min($path);
        if ($GLOBALS["ALL"]) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: c-icap service removing `{$path}` ( {$size}M )\n";
            }
            @unlink($path);
            continue;
        }
        if ($time > $MaxCICAPWorkTimeMin) {
            squid_admin_mysql(1, "C-ICAP: Removing temporary file {$path} ( {$time}Mn/{$size}M )", "It exceed rule of {$MaxCICAPWorkTimeMin}Mn ( {$time}Mn )", __FILE__, __LINE__);
            @unlink($path);
            continue;
        }
    }
    $REMOVED = false;
    $workdir = "/var/clamav/tmp";
    if (is_dir($workdir)) {
        if (!($handle = opendir($workdir))) {
            return;
        }
        while (false !== ($file = readdir($handle))) {
            if ($file == ".") {
                continue;
            }
            if ($file == "..") {
                continue;
            }
            if (is_dir($workdir)) {
                continue;
            }
            $path = "{$workdir}/{$file}";
            $size = @filesize($path);
            $size = $size / 1024;
            $size = $size / 1024;
            if ($unix->is_socket($path)) {
                continue;
            }
            $time = $unix->file_time_min($path);
            if ($GLOBALS["ALL"]) {
                if ($GLOBALS["OUTPUT"]) {
                    echo "Starting......: " . date("H:i:s") . " [INIT]: c-icap service removing `{$path}` ( {$size}M )\n";
                }
                $REMOVED = true;
                @unlink($path);
                continue;
            }
            if ($time > $MaxCICAPWorkTimeMin) {
                squid_admin_mysql(1, "C-ICAP: Removing temporary file {$path} ( {$time}Mn/{$size}M )", "It exceed rule of {$MaxCICAPWorkTimeMin}Mn ( {$time}Mn )", __FILE__, __LINE__);
                $REMOVED = true;
                @unlink($path);
                continue;
            }
        }
    }
    if ($REMOVED) {
        shell_exec($sync);
    }
}