コード例 #1
0
function start()
{
    $sock = new sockets();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $unix = new unix();
    $me = basename(__FILE__);
    if ($unix->process_exists(@file_get_contents($pidfile), $me)) {
        if ($GLOBALS["VERBOSE"]) {
            echo " --> Already executed.. " . @file_get_contents($pidfile) . " aborting the process\n";
        }
        system_admin_events("--> Already executed.. " . @file_get_contents($pidfile) . " aborting the process", __FUNCTION__, __FILE__, __LINE__, "zarafa");
        die;
    }
    @file_put_contents($pidfile, getmypid());
    $WordpressBackupParams = unserialize(base64_decode($sock->GET_INFO("WordpressBackupParams")));
    if (!isset($WordpressBackupParams["FTP_ENABLE"])) {
        $WordpressBackupParams["FTP_ENABLE"] = 0;
    }
    if (!isset($WordpressBackupParams["DEST"])) {
        $WordpressBackupParams["DEST"] = "/home/wordpress-backup";
    }
    if ($WordpressBackupParams["DEST"] == null) {
        $WordpressBackupParams["DEST"] = "/home/wordpress-backup";
    }
    ScanFreeWebs($WordpressBackupParams);
    $t = time();
    build_progress_fullback("{backup} FTP ?", 95);
    ftp_backup($WordpressBackupParams);
    sizes_backup();
    build_progress_fullback("{done}", 100);
}
コード例 #2
0
function restart_lighttpd()
{
    $t = time();
    exec("/etc/init.d/artica-webinterface restart 2>&1", $results);
    $unix = new unix();
    $took = $unix->distanceOfTimeInWords($t, time());
    system_admin_events("Restart Web interface service done took:{$took}\n" . @implode("\n", $results), __FUNCTION__, __FILE__, __LINE__, "system");
}
コード例 #3
0
function ScanFoldders()
{
    $sock = new sockets();
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $timefile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    $pid = file_get_contents("{$pidfile}");
    if ($GLOBALS["VERBOSE"]) {
        echo "{$timefile}\n";
    }
    if (system_is_overloaded(basename(__FILE__))) {
        die;
    }
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $timeMin = $unix->PROCCESS_TIME_MIN($pid);
        if ($timeMin > 240) {
            system_admin_events("Too many TTL, {$pid} will be killed", __FUNCTION__, __FILE__, __LINE__, "logrotate");
            $kill = $unix->find_program("kill");
            unix_system_kill_force($pid);
        } else {
            die;
        }
    }
    if (!$GLOBALS["FORCE"]) {
        $TimeExec = $unix->file_time_min($timefile);
        if ($TimeExec < 240) {
            return;
        }
    }
    @unlink($timefile);
    @file_put_contents($timefile, time());
    $LogRotatePath = $sock->GET_INFO("LogRotatePath");
    $SystemLogsPath = $sock->GET_INFO("SystemLogsPath");
    $BackupMaxDaysDir = $sock->GET_INFO("BackupMaxDaysDir");
    $maillogStoragePath = trim(@file_get_contents("/etc/artica-postfix/settings/Daemons/maillogStoragePath"));
    if ($GLOBALS["VERBOSE"]) {
        echo "Starting Main\n";
    }
    $q = new mysql();
    $q->QUERY_SQL("DROP TABLE `sysstorestatus`", "artica_events");
    $sql = "CREATE TABLE IF NOT EXISTS `sysstorestatus` (\n\t\t\t  `filepath` VARCHAR(255) NOT NULL,\n\t\t\t  `filesize`  BIGINT UNSIGNED NOT NULL,\n\t\t\t  `zDate` DATETIME,\n\t\t\t  PRIMARY KEY (`filepath`),\n\t\t\t  KEY `zDate` (`zDate`),\n\t\t\t  KEY `filesize` (`filesize`)\n\t\t\n\t\t\t)";
    $q->QUERY_SQL($sql, "artica_events");
    if (!$q->ok) {
        echo $q->mysql_error;
        return;
    }
    ScanThis("/home/postfix/maillog");
    ScanThis("/home/logrotate");
    ScanThis("/home/logrotate_backup");
    ScanThis("/home/logs-backup");
    ScanThis("/home/backup/postfix");
    ScanThis($LogRotatePath);
    ScanThis($SystemLogsPath);
    ScanThis($maillogStoragePath);
}
コード例 #4
0
ファイル: exec.hdparm.php プロジェクト: BillTheBest/1.6.x
function launch_tests()
{
    $unix = new unix();
    $php = $unix->LOCATE_PHP5_BIN();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        return;
    }
    if (system_is_overloaded(basename(__FILE__))) {
        system_admin_events("Overloaded, aborting task...", __FUNCTION__, __FILE__, __LINE__, "system");
        $unix->THREAD_COMMAND_SET("{$php} " . __FILE__);
        return;
    }
    @file_put_contents($pidfile, getmypid());
    $datafile = "/etc/artica-postfix/settings/Daemons/HdparmInfos";
    writelogs("Testing hard drives ({$datafile})", __FUNCTION__, __FILE__, __LINE__);
    $timenum = file_time_min($datafile);
    if (is_file($datafile)) {
        if (file_time_min($datafile) < 61) {
            writelogs("{$timenum}Mn executed, waiting 60Mn", __FUNCTION__, __FILE__, __LINE__);
            die;
        }
    }
    if ($GLOBALS["FIND_HDPARM"] == null) {
        writelogs("Unable to stat 'hdparm'", __FUNCTION__, __FILE__, __LINE__);
        die;
    }
    $disks = GetDisks();
    if (!is_array($disks)) {
        return null;
    }
    while (list($index, $line) = each($disks)) {
        unset($results);
        exec("{$GLOBALS["FIND_HDPARM"]} -t {$index}", $results);
        while (list($num, $line_result) = each($results)) {
            if (preg_match("#=\\s+([0-9\\.]+)\\s+MB\\/sec\$#", $line_result, $re)) {
                if (preg_match("#.+?\\/(.+)\$#", $index, $ri)) {
                    system_admin_events("{$ri[1]}:{$re[1]}MB/sec", __FUNCTION__, __FILE__, __LINE__, "system");
                    writelogs("testing disk {$ri[1]}:{$re[1]}MB/sec...", __FUNCTION__, __FILE__, __LINE__);
                    $array[$ri[1]] = $re[1];
                }
            }
        }
    }
    @unlink($datafile);
    @file_put_contents($datafile, base64_encode(serialize($array)));
    if (!is_file($datafile)) {
        writelogs("{$datafile} no such file or directory", __FUNCTION__, __FILE__, __LINE__);
    }
}
コード例 #5
0
 function DELETE_TABLE($table)
 {
     if (!function_exists("mysql_connect")) {
         return 0;
     }
     if (function_exists("system_admin_events")) {
         $trace = @debug_backtrace();
         if (isset($trace[1])) {
             $called = "called by " . basename($trace[1]["file"]) . " {$trace[1]["function"]}() line {$trace[1]["line"]}";
         }
         system_admin_events("MySQL table {$this->database}/{$table} was deleted {$called}", __FUNCTION__, __FILE__, __LINE__, "mysql-delete");
     }
     $this->QUERY_SQL("DROP TABLE `{$table}`", $this->database);
 }
コード例 #6
0
function start()
{
    $sock = new sockets();
    $unix = new unix();
    if (!$GLOBALS["VERBOSE"]) {
        $pidtime = "/etc/artica-postfix/pids/exec.mimedefang.quarantine.php.start.time";
        if ($unix->file_time_min($pidtime) < 5) {
            return;
        }
        @unlink($pidtime);
        @file_put_contents($pidtime, time());
    }
    $postgres = new postgres_sql();
    $postgres->SMTP_TABLES();
    $storage_path = "/var/spool/MD-Quarantine";
    $unix = new unix();
    $pidpath = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pid = @file_get_contents($pidpath);
    if ($unix->process_exists($pid)) {
        system_admin_events("Already process {$pid} running.. Aborting", __FUNCTION__, __FILE__, __LINE__, "postfix");
        return;
    }
    @file_put_contents($pidpath, getmypid());
    $c = 0;
    $q = new postgres_sql();
    $q->SMTP_TABLES();
    if ($handle = opendir($storage_path)) {
        while (false !== ($file = readdir($handle))) {
            if ($file == "." && $file == "..") {
                continue;
            }
            if (substr($file, 0, 1) == '.') {
                continue;
            }
            if (!preg_match("#^qdir-#", $file)) {
                continue;
            }
            $path = "{$storage_path}/{$file}";
            if (!is_file("{$path}/ENTIRE_MESSAGE")) {
                continue;
            }
            import_quarantine($path);
        }
    }
    CleanDatabase();
}
コード例 #7
0
function parseQueue()
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pid = $unix->get_pid_from_file($pidfile);
    $sock = new sockets();
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $pidTime = $unix->PROCCESS_TIME_MIN($pid);
        events("Already process PID: {$pid} running since {$pidTime} minutes", __FUNCTION__, __FILE__, __LINE__, "postfix-stats");
        return;
    }
    @file_put_contents($pidfile, getmypid());
    if (system_is_overloaded(basename(__FILE__))) {
        events("Overloaded system, aborting", __FUNCTION__, __FILE__, __LINE__, "postfix-stats");
        return;
    }
    $EnableArticaSMTPStatistics = $sock->GET_INFO("EnableArticaSMTPStatistics");
    if (!is_numeric($EnableArticaSMTPStatistics)) {
        $EnableArticaSMTPStatistics = 0;
    }
    $directory = "/var/log/artica-mail";
    if (!is_dir($directory)) {
        return;
    }
    if (!($handle = @opendir($directory))) {
        return;
    }
    $q = new mysql_postfix_builder();
    $q->CheckTables();
    events("open {$directory}");
    while (false !== ($filename = readdir($handle))) {
        if ($EnableArticaSMTPStatistics == 0) {
            @unlink("{$directory}/{$filename}");
            continue;
        }
        if (!preg_match("#(.+?)\\.[0-9]+\\.aws#", $filename, $re)) {
            continue;
        }
        $instancename = $re[1];
        ParseFile("{$directory}/{$filename}");
        if (system_is_overloaded(basename(__FILE__))) {
            system_admin_events("Overloaded system, aborting", __FUNCTION__, __FILE__, __LINE__, "postfix-stats");
            return;
        }
    }
}
コード例 #8
0
function mailboxes_ou_lang($ou)
{
    $unix = new unix();
    $sock = new sockets();
    $t = time();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $unix = new unix();
    $me = basename(__FILE__);
    if ($unix->process_exists(@file_get_contents($pidfile), $me)) {
        if ($GLOBALS["VERBOSE"]) {
            echo " --> Already executed.. " . @file_get_contents($pidfile) . " aborting the process\n";
        }
        system_admin_events("--> Already executed.. " . @file_get_contents($pidfile) . " aborting the process", __FUNCTION__, __FILE__, __LINE__, "zarafa");
        die;
    }
    @file_put_contents($pidfile, getmypid());
    $oumd5 = md5(strtolower(trim($ou)));
    $OuDefaultLang = $sock->GET_INFO("zarafaMBXLang{$oumd5}");
    if ($OuDefaultLang == null) {
        system_admin_events("`{$ou}` no such default language, aborting", __FUNCTION__, __FILE__, __LINE__, "zarafa");
        return;
    }
    $ldap = new clladp();
    $members = $ldap->hash_users_ou($ou);
    $CountMembers = count($members);
    system_admin_events("{$ou} {$CountMembers} to change to {$OuDefaultLang}", __FUNCTION__, __FILE__, __LINE__, "zarafa");
    $c = 0;
    while (list($uid, $name) = each($members)) {
        $ct = new user($uid);
        if ($ct->zarafaMbxLang == null) {
            $ct->SaveZarafaMbxLang($OuDefaultLang);
            $c++;
            $sock->getFrameWork("cmd.php?zarafa-admin=yes");
            $sock->getFrameWork("zarafa.php?zarafa-user-create-store={$uid}&lang={$OuDefaultLang}");
            $sock->getFrameWork("zarafa.php?foldersnames=yes&uid={$uid}&lang={$OuDefaultLang}");
        }
    }
    $took = $unix->distanceOfTimeInWords($t, time(), true);
    system_admin_events("{$ou} {$c}/{$CountMembers} changed to {$OuDefaultLang} done took: {$took}", __FUNCTION__, __FILE__, __LINE__, "zarafa");
}
コード例 #9
0
ファイル: exec.arpscan.php プロジェクト: brucewu16899/1.6.x
function scanarp_mysql()
{
    $unix = new unix();
    $t = time();
    if (systemMaxOverloaded()) {
        return;
    }
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $unix = new unix();
    $me = basename(__FILE__);
    $pid = @file_get_contents($pidfile);
    if ($unix->process_exists($pid, $me)) {
        if ($GLOBALS["VERBOSE"]) {
            echo " --> Already executed.. {$pid} aborting the process\n";
        }
        system_admin_events("--> Already executed.. {$pid} aborting the process", __FUNCTION__, __FILE__, __LINE__, "network");
        die;
    }
    $sock = new sockets();
    $EnableArpDaemon = $sock->GET_INFO("EnableArpDaemon");
    $ArpdKernelLevel = $sock->GET_INFO("ArpdKernelLevel");
    if (!is_numeric($EnableArpDaemon)) {
        $EnableArpDaemon = 1;
    }
    $articastatus_pidfile = "/etc/artica-postfix/exec.status.php.pid";
    $pid = $unix->get_pid_from_file($articastatus_pidfile);
    if (!$unix->process_exists($pid)) {
        syslog_status("artica status doesn't run, start it, old pid was: {$pid}");
        shell_exec("/etc/init.d/artica-status start");
    }
    $list = $unix->PIDOF_PATTERN_ALL($me);
    if (count($list) > 2) {
        system_admin_events("--> Already executed.." . count($list) . " Processes executed");
        die;
    }
    @file_put_contents($pidfile, getmypid());
    $arpbin = $unix->find_program("arp");
    $arpdbin = $unix->find_program("arpd");
    if (!is_file($arpbin)) {
        echo "arp, no such binary...\n";
        return;
    }
    exec("{$arpbin} -a 2>&1", $results);
    if ($GLOBALS["VERBOSE"]) {
        echo "{$arpbin} -a 2>&1\n";
    }
    $prefix = "INSERT INTO arpcache (`mac`,`ipaddr`,`hostname`,`HWtype`,`iface`) VALUES ";
    while (list($num, $ligne) = each($results)) {
        if (preg_match("#^(.+?)\\s+\\((.+?)\\)\\s+.+?\\s+(.+?)\\s+\\[(.+?)\\]\\s+.+?\\s+(.+)#", $ligne, $re)) {
            $mac = trim($re[3]);
            $hostname = trim($re[1]);
            $ipaddr = trim($re[2]);
            $HWtype = trim($re[4]);
            $iface = trim($re[5]);
            if ($GLOBALS["VERBOSE"]) {
                echo "MATCH `{$ligne}` '{$mac}','{$ipaddr}','{$hostname}','{$HWtype}','{$iface}'\n";
            }
            $f[] = "('{$mac}','{$ipaddr}','{$hostname}','{$HWtype}','{$iface}')";
            continue;
        }
        if (preg_match("#^([a-z0-9\\.\\-\\_\\?]+)\\s+\\((.+?)\\).+?incomplete.+?[a-z]+\\s+(.+)\$#", $ligne, $re)) {
            $mac = null;
            $hostname = trim($re[1]);
            $ipaddr = trim($re[2]);
            $HWtype = null;
            $iface = trim($re[3]);
            if ($GLOBALS["VERBOSE"]) {
                echo "MATCH `{$ligne}` '{$mac}','{$ipaddr}','{$hostname}','{$HWtype}','{$iface}'\n";
            }
            $f[] = "('{$mac}','{$ipaddr}','{$hostname}','{$HWtype}','{$iface}')";
            continue;
        }
        if ($GLOBALS["VERBOSE"]) {
            echo "No match `{$ligne}`\n";
        }
    }
    if (is_file($arpdbin)) {
        $results = array();
        exec("{$arpdbin} -l 2>&1", $results);
        while (list($num, $ligne) = each($results)) {
            if (preg_match("#^[0-9]+\\s+([0-9\\.]+)\\s+(.+)#", $ligne, $re)) {
                $mac = trim($re[2]);
                if (preg_match("#FAILED:#", $mac)) {
                    $mac = null;
                }
                $hostname = null;
                $ipaddr = trim($re[1]);
                $HWtype = null;
                $iface = "arpd";
                $f[] = "('{$mac}','{$ipaddr}','{$hostname}','{$HWtype}','{$iface}')";
                continue;
            }
        }
    }
    if (count($f) > 0) {
        $q = new mysql();
        $q->QUERY_SQL("TRUNCATE TABLE `arpcache`", "artica_backup");
        if ($GLOBALS["VERBOSE"]) {
            echo count($f) . " entries\n";
        }
        $sql = $prefix . @implode(",", $f);
        $q->QUERY_SQL($sql, "artica_backup");
        if (!$q->ok) {
            system_admin_events("Fatal, {$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "network");
            return;
        }
        $took = $unix->distanceOfTimeInWords($t, time(), true);
        system_admin_events(count($f) . " ARP entries added into MySQL server", __FUNCTION__, __FILE__, __LINE__, "network");
    }
}
コード例 #10
0
function logrotatelogs($nopid = false)
{
    $unix = new unix();
    $sock = new sockets();
    if ($nopid) {
        $pidpath = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = @file_get_contents($pidpath);
        if ($unix->process_exists($pid)) {
            $pidtime = $unix->PROCCESS_TIME_MIN($pid);
            system_admin_events(basename(__FILE__) . ":: " . __FUNCTION__ . " Already process {$pid} running since {$pidtime} Mn.. Aborting", __FUNCTION__, __FILE__, __LINE__);
            return;
        }
        @file_put_contents($pidpath, getmypid());
    }
    $echo = $unix->find_program("echo");
    $LogsRotateDeleteSize = $sock->GET_INFO("LogsRotateDeleteSize");
    if (!is_numeric($LogsRotateDeleteSize)) {
        $LogsRotateDeleteSize = 5000;
    }
    include_once dirname(__FILE__) . "/ressources/class.mysql.syslog.inc";
    if ($GLOBALS["VERBOSE"]) {
        echo __FUNCTION__ . " line:" . __LINE__ . "\n";
    }
    $q = new mysql_syslog();
    if ($q->COUNT_ROWS("logrotate") == 0) {
        $q->CheckDefaults();
    }
    $sql = "SELECT RotateFiles FROM logrotate WHERE enabled=1";
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        echo $q->mysql_error;
    }
    while ($ligne = mysql_fetch_assoc($results)) {
        $filepath = $ligne["RotateFiles"];
        if (strpos($filepath, "*") > 0) {
            if ($GLOBALS["VERBOSE"]) {
                echo __FUNCTION__ . ":: Scanning {$filepath} line:" . __LINE__ . "\n";
            }
            foreach (glob($filepath) as $filename) {
                $size = $unix->file_size($filename);
                $size = $size / 1024;
                $size = round($size / 1000, 2);
                $ARRAY[$filename] = $size;
            }
        } else {
            if (is_file($filepath)) {
                $size = $unix->file_size($filepath);
                $size = $size / 1024;
                $size = round($size / 1000, 2);
                $ARRAY[$filepath] = $size;
            }
            if (is_dir($filepath)) {
                while (list($num, $filename) = each($f)) {
                    $filepath = "/var/log/{$filename}";
                    $f = $unix->DirFiles("{$filepath}");
                    $size = $unix->file_size($filepath);
                    $size = $size / 1024;
                    $size = round($size / 1000, 2);
                    $ARRAY[$filepath] = $size;
                }
            }
        }
    }
    $f = $unix->DirFiles("/var/log");
    while (list($num, $filename) = each($f)) {
        $filepath = "/var/log/{$filename}";
        $size = $unix->file_size($filepath);
        $size = $size / 1024;
        $size = round($size / 1000, 2);
        $ARRAY[$filepath] = $size;
    }
    $f = $unix->DirFiles("/var/log/artica-postfix");
    while (list($num, $filename) = each($f)) {
        $filepath = "/var/log/artica-postfix/{$filename}";
        $size = $unix->file_size($filepath);
        $size = $size / 1024;
        $size = round($size / 1000, 2);
        $ARRAY[$filepath] = $size;
    }
    $restart = false;
    while (list($filepath, $sizeM) = each($ARRAY)) {
        if ($sizeM > $LogsRotateDeleteSize) {
            shell_exec("{$echo} \"\" >{$filepath}");
            $restart = true;
            $unix->send_email_events("{$filepath} was cleaned ({$sizeM}M)", "It exceed maximal size {$LogsRotateDeleteSize}M", "system");
        }
    }
    if ($restart) {
        shell_exec("/etc/init.d/syslog restart");
        shell_exec("/etc/init.d/artica-syslog restart");
        shell_exec("/etc/init.d/auth-tail restart");
        shell_exec("/etc/init.d/postfix-logger restart");
    }
}
コード例 #11
0
function repair_action($database, $tablename, $expl)
{
    $unix = new unix();
    $q = new mysql();
    if (preg_match("#Can.*?t find file#", $expl)) {
        system_admin_events("{$tablename} is destroyed, remove it..", __FUNCTION__, __FILE__, __LINE__);
        echo "Removing table {$database}/{$tablename}\n";
        $q->DELETE_TABLE($tablename, $database);
        return;
    }
    if (preg_match("#is marked as crashed#", $expl)) {
        $results = array();
        $t = time();
        if (is_file("/var/lib/mysql/{$database}/{$tablename}.TMD")) {
            @copy("/var/lib/mysql/{$database}/{$tablename}.TMD", "/var/lib/mysql/{$database}/{$tablename}.TMD-" . time());
            @unlink("/var/lib/mysql/{$database}/{$tablename}.TMD");
        }
        $myisamchk = $unix->find_program("myisamchk");
        $cmd = "{$myisamchk} -r /var/lib/mysql/{$database}/{$tablename}.MYI";
        if ($GLOBALS["VERBOSE"]) {
            echo "{$cmd}\n";
        }
        exec($cmd, $results);
        $took = $unix->distanceOfTimeInWords($t, time());
        system_admin_events("{$tablename} repaired took: {$took}", @implode("\r\n", $results), __FUNCTION__, __FILE__, __LINE__);
        return;
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "{$tablename} nothing to do...\n";
    }
}
コード例 #12
0
ファイル: exec.httptrack.php プロジェクト: BillTheBest/1.6.x
function execute_mysql($OnlyID = 0)
{
    $GLOBALS["INDEXED"] = 0;
    $GLOBALS["SKIPPED"] = 0;
    $GLOBALS["DIRS"] = array();
    $unix = new unix();
    $httrack = $unix->find_program("httrack");
    if (!is_file($httrack)) {
        system_admin_events("httrack no such binary", __FUNCTION__, __FILE__, __LINE__, "webcopy");
        return;
    }
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        system_admin_events("Already instance executed pid:{$olpid}", __FUNCTION__, __FILE__, __LINE__, "webcopy");
        return;
    }
    $getmypid = getmypid();
    @file_put_contents($pidfile, $getmypid);
    $q = new mysql();
    $nice = EXEC_NICE();
    $sql = "SELECT * FROM httrack_sites WHERE enabled=1";
    $results = $q->QUERY_SQL($sql, "artica_backup");
    if (!$q->ok) {
        system_admin_events("Fatal: {$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "webcopy");
        return;
    }
    $t1 = time();
    $count = 0;
    if ($OnlyID > 0) {
        $ligne2 = mysql_fetch_array($q->QUERY_SQL("SELECT sitename FROM httrack_sites WHERE ID={$OnlyID}", "artica_backup"));
        $log_exp = " only for [{$ligne2["sitename"]}] ";
    }
    system_admin_events("Starting executing WebCopy task {$log_exp} pid:{$getmypid}", __FUNCTION__, __FILE__, __LINE__, "webcopy");
    while ($ligne = mysql_fetch_assoc($results)) {
        if ($OnlyID > 0) {
            if ($ligne["ID"] != $OnlyID) {
                continue;
            }
        }
        $t = time();
        $count++;
        $workingdir = $ligne["workingdir"];
        $sitename = $ligne["sitename"];
        $maxsize = $ligne["maxsize"];
        $minrate = $ligne["minrate"];
        $maxfilesize = $ligne["maxfilesize"];
        $maxsitesize = $ligne["maxsitesize"];
        $maxfilesize = $maxfilesize * 1000;
        $maxsitesize = $maxsitesize * 1000;
        $minrate = $minrate * 1000;
        $update = null;
        $resultsCMD = array();
        if (!is_dir($workingdir)) {
            @mkdir($workingdir, 0755, true);
        }
        if (is_file("{$workingdir}/hts-cache")) {
            $update = " --update";
        }
        $cmdline = "{$httrack} \"{$sitename}\" --quiet{$update} --max-files={$maxfilesize} --max-size={$maxsitesize} --max-rate={$minrate} -O \"{$workingdir}\" 2>&1";
        if ($GLOBALS["VERBOSE"]) {
            echo "{$cmdline}\n";
        }
        exec($cmdline, $resultsCMD);
        if ($GLOBALS["VERBOSE"]) {
            echo @implode("\n", $resultsCMD);
        }
        $dirsize = $unix->DIRSIZE_BYTES($workingdir);
        $took = $unix->distanceOfTimeInWords($t, time(), true);
        $dirsizeText = round($dirsize / 1024 / 1000, 2);
        system_admin_events("{$sitename} scrapped took {$took} size={$dirsizeText} MB", __FUNCTION__, __FILE__, __LINE__, "webcopy");
        $q->QUERY_SQL("UPDATE httrack_sites SET size='{$dirsize}' WHERE ID={$ligne["ID"]}", "artica_backup");
    }
    $took = $unix->distanceOfTimeInWords($t1, time(), true);
    system_admin_events("{$count} web sites scrapped took {$took}", __FUNCTION__, __FILE__, __LINE__, "webcopy");
}
コード例 #13
0
ファイル: exec.nightly.php プロジェクト: brucewu16899/1.6.x
function install_package($filename, $expected = null)
{
    $unix = new unix();
    $sock = new sockets();
    $php = $unix->LOCATE_PHP5_BIN();
    $nohup = $unix->find_program("nohup");
    $rm = $unix->find_program("rm");
    $RebootAfterArticaUpgrade = $sock->GET_INFO("RebootAfterArticaUpgrade");
    if (!is_numeric($RebootAfterArticaUpgrade)) {
        $RebootAfterArticaUpgrade = 0;
    }
    events("Starting......: " . date("H:i:s") . " install_package() Extracting package {$filename}, please wait... ");
    echo "Starting......: " . date("H:i:s") . " install_package() Extracting package {$filename}, please wait... \n";
    $tarbin = $unix->find_program("tar");
    $killall = $unix->find_program("killall");
    echo "Starting......: " . date("H:i:s") . " tar: {$tarbin}\n";
    echo "Starting......: " . date("H:i:s") . " killall: {$killall}\n";
    @file_put_contents("/usr/share/artica-postfix/download_progress", 10);
    events("Starting......: " . date("H:i:s") . " install_package() Testing Package");
    echo "Starting......: " . date("H:i:s") . " Testing Package " . basename($filename) . "\n";
    if (!$unix->TARGZ_TEST_CONTAINER($filename)) {
        echo "Starting......: " . date("H:i:s") . " Testing Package " . basename($filename) . " failed\n";
        _artica_update_event(0, "Compressed package seems corrupted", null, __FILE__, __LINE__);
        events("Fatal, Compressed package seems corrupted");
        events($GLOBALS["TARGZ_TEST_CONTAINER_ERROR"]);
        @unlink($filename);
        @file_put_contents("/usr/share/artica-postfix/download_progress", 100);
        return false;
    }
    events("Starting......: " . date("H:i:s") . " Purge directories...");
    @file_put_contents("/usr/share/artica-postfix/download_progress", 40);
    system("{$rm} -f /usr/share/artica-postfix/ressources/logs/*");
    system("{$rm} -f /usr/share/artica-postfix/ressources/logs/web/*");
    if (is_dir("/usr/share/artica-postfix/ressources/conf/upload")) {
        system("{$rm} -f /usr/share/artica-postfix/ressources/conf/upload/*");
    }
    if (is_dir("/usr/share/artica-postfix/ressources/conf/meta/hosts/uploaded")) {
        system("{$rm} -f /usr/share/artica-postfix/ressources/conf/meta/hosts/uploaded/*");
    }
    events("Starting......: " . date("H:i:s") . " Extracting...");
    exec("{$tarbin} xf {$filename} -C /usr/share/ 2>&1", $results);
    if (is_file("{$killall}")) {
        shell_exec("{$killall} artica-install >/dev/null 2>&1");
    }
    @unlink($filename);
    shell_exec("{$nohup} {$php} " . dirname(__FILE__) . "/exec.checkfolder-permissions.php --force >/dev/null 2>&1 &");
    $MyCurrentVersion = GetCurrentVersionString();
    if ($expected != null) {
        if ($MyCurrentVersion != $expected) {
            _artica_update_event(1, "install_package(): Expected version:{$expected} does not match {$MyCurrentVersion}", $results, __FILE__, __LINE__);
            return;
        }
    }
    _artica_update_event(2, "install_package(): Success updating to a new version v{$MyCurrentVersion}", $results, __FILE__, __LINE__);
    if ($RebootAfterArticaUpgrade == 1) {
        @file_put_contents("/usr/share/artica-postfix/download_progress", 100);
        _artica_update_event(1, "install_package() Reboot the server in 10s...", null, __FILE__, __LINE__);
        events("Reboot the server in 10s...");
        system_admin_events("Warning: Reboot the server in 10s...", __FUNCTION__, __FILE__, __LINE__, "artica-update");
        $shutdown = $unix->find_program("shutdown");
        shell_exec("shutdown -r -t 10");
        return true;
    }
    _artica_update_event(2, "install_package(): restart dedicated services...", null, __FILE__, __LINE__);
    system_admin_events("Warning: Restart Artica dedicated services after an upgrade...", __FUNCTION__, __FILE__, __LINE__, "artica-update");
    RestartDedicatedServices();
    _artica_update_event(2, "install_package(): finish", null, __FILE__, __LINE__);
    return true;
}
コード例 #14
0
        @unlink($squid3);
    }
    echo "Removing squid last install\n";
    remove_squid();
    echo "Make install\n";
    shell_exec("echo \"**************************************\" >>/root/squid-{$v}-configure.log 2>&1");
    shell_exec("echo \"\" >>/root/squid-{$v}-configure.log 2>&1");
    if ($GLOBALS["VERBOSE"]) {
        system("make install");
    }
    if (!$GLOBALS["VERBOSE"]) {
        shell_exec("make install >>/root/squid-{$v}-configure.log 2>&1");
    }
}
if (!is_file("/usr/sbin/squid")) {
    system_admin_events("Installing the new squid-cache {$v} failed", __FUNCTION__, __FILE__, __LINE__, "software");
    echo "Failed\n";
}
if (!$GLOBALS["NO_COMPILE"]) {
    shell_exec("/bin/rm -rf /usr/share/squid3/errors/templates/*");
}
shell_exec("/bin/chown -R squid:squid /usr/share/squid3");
echo "Compiling ufdbcat....\n";
compile_ufdbcat();
echo "Creating package....\n";
create_package_squid($t);
function DebianVersion()
{
    $ver = trim(@file_get_contents("/etc/debian_version"));
    preg_match("#^([0-9]+)\\.#", $ver, $re);
    if (preg_match("#squeeze\\/sid#", $ver)) {
コード例 #15
0
function NoIp()
{
    $sock = new sockets();
    $EnableNoIpService = $sock->GET_INFO("EnableNoIpService");
    if (!is_numeric($EnableNoIpService)) {
        $EnableNoIpService = 0;
    }
    if ($EnableNoIpService == 0) {
        return;
    }
    $Config = unserialize(base64_decode($sock->GET_INFO("NoipConf")));
    $curl = new ccurl("http://dynupdate.no-ip.com/nic/update?hostname={$Config["NoIPHostname"]}");
    $curl->authname = $Config["NoIPUsername"];
    $curl->authpass = $Config["NoIPPassword"];
    $curl->NoHTTP_POST = true;
    if (!$curl->get()) {
        system_admin_events("Fatal {$curl->error} !!", __FUNCTION__, __FILE__, __LINE__, "system");
        return;
    }
    $results = explode("\n", $curl->data);
    while (list($num, $line) = each($results)) {
        $line = trim($line);
        if ($line == null) {
            continue;
        }
        if (preg_match("#good\\s+([0-9\\.]+)#", $line, $re)) {
            system_admin_events("OK For {$re[1]}", __FUNCTION__, __FILE__, __LINE__, "system");
            writelogs("OK for {$re[1]}", __FUNCTION__, __FILE__);
            $myip = $re[1];
            break;
        }
        if (preg_match("#nochg\\s+([0-9\\.]+)#", $line, $re)) {
            writelogs("OK no changes {$re[1]}", __FUNCTION__, __FILE__);
            $myip = $re[1];
            break;
        }
        if (preg_match("#nochg\\s+([0-9\\.]+)#", $line, $re)) {
            writelogs("OK no changes {$re[1]}", __FUNCTION__, __FILE__);
            $myip = $re[1];
            break;
        }
        if (preg_match("#abuse\\s+(.+)#", $line, $re)) {
            writelogs("Fatal: Abuse!!!! {$re[1]}", __FUNCTION__, __FILE__);
            break;
        }
    }
    if ($myip != null) {
        @file_put_contents("/usr/share/artica-postfix/ressources/logs/web/myIP.conf", $myip);
        @chmod("/usr/share/artica-postfix/ressources/logs/web/myIP.conf", 775);
        $sock->SET_INFO("PublicIPAddress", $myip);
    }
}
コード例 #16
0
 public function QUERY_SQL($sql, $database = null, $called = null, $unbuffered = false)
 {
     $TableDropped_blacklist["ufdb_smtp"] = true;
     $database = trim($database);
     if ($database == "artica_backup") {
         $database = $this->database;
     }
     if ($database == "artica_events") {
         $database = $this->database;
     }
     if ($database == "ocsweb") {
         $database = $this->database;
     }
     if ($database == "postfixlog") {
         $database = $this->database;
     }
     if ($database == "powerdns") {
         $database = $this->database;
     }
     if ($database == "zarafa") {
         $database = $this->database;
     }
     if ($database == "syslogstore") {
         $database = $this->database;
     }
     if ($database == "metaclient") {
         $database = $this->database;
     }
     if ($database == null) {
         $database = $this->database;
     }
     $this->last_id = 0;
     $this->sql = $sql;
     $CLASS = __CLASS__;
     $FUNCTION = __FUNCTION__;
     $FILENAME = basename(__FILE__);
     $LOGPRF = "{$FILENAME}::{$CLASS}/{$FUNCTION}";
     $this->ok = false;
     if (isset($GLOBALS["HOTSPOT_DEBUG"])) {
         if ($GLOBALS["HOTSPOT_DEBUG"]) {
             if (function_exists("wifidog_logs")) {
                 wifidog_logs("{$sql}", __FUNCTION__, __LINE__);
             }
         }
     }
     $sql = trim($sql);
     if ($called == null) {
         if (function_exists("debug_backtrace")) {
             $trace = @debug_backtrace();
             if (isset($trace[1])) {
                 $called = "called by " . basename($trace[1]["file"]) . " {$trace[1]["function"]}() line {$trace[1]["line"]}";
             }
         }
     }
     if (preg_match("#delete.*?webfilter_members#i", $sql)) {
         $this->ToSyslog("FATAL!! CHATEAU-THIERRY {$sql} {$called}");
     }
     if ($GLOBALS["DEBUG_SQL"]) {
         echo "this->BD_CONNECT\n";
     }
     @mysql_close($this->mysql_connection);
     if (!$this->BD_CONNECT(false, $called)) {
         if ($GLOBALS["VERBOSE"]) {
             echo "Unable to BD_CONNECT class mysql/QUERY_SQL\n";
         }
         if (function_exists("system_admin_events")) {
             $trace = @debug_backtrace();
             if (isset($trace[1])) {
                 $called = "called by " . basename($trace[1]["file"]) . " {$trace[1]["function"]}() line {$trace[1]["line"]}";
             }
             system_admin_events("MySQL error DB:\"{$database}\" Error, unable to connect to MySQL server, request failed\n{$called}", __FUNCTION__, __FILE__, __LINE__, "mysql-error");
         }
         $this->writeLogs("QUERY_SQL:" . __LINE__ . ": DB:\"{$database}\" Error, unable to connect to MySQL server, request failed", __CLASS__ . '/' . __FUNCTION__, __LINE__);
         $this->ok = false;
         $this->mysql_error = $this->BD_CONNECT_ERROR . " Error, unable to connect to MySQL server";
         $this->ToSyslog($this->mysql_error);
         return false;
     }
     if (preg_match("#DROP TABLE\\s+(.+)\$#i", $sql, $re)) {
         $TableDropped = $re[1];
         if (!isset($TableDropped_blacklist[$TableDropped])) {
             if (function_exists("system_admin_events")) {
                 $trace = @debug_backtrace();
                 if (isset($trace[1])) {
                     $called = "called by " . basename($trace[1]["file"]) . " {$trace[1]["function"]}() line {$trace[1]["line"]}";
                 }
                 system_admin_events("MySQL table {$database}/{$TableDropped} was deleted {$called}", __FUNCTION__, __FILE__, __LINE__, "mysql-delete");
             }
         }
     }
     if ($GLOBALS["DEBUG_SQL"]) {
         echo "mysql_select_db()\n";
     }
     if ($GLOBALS['VERBOSE']) {
         $ok = mysql_select_db($database, $this->mysql_connection);
     } else {
         $ok = @mysql_select_db($database, $this->mysql_connection);
     }
     if (!$ok) {
         $errnum = @mysql_errno($this->mysql_connection);
         $des = @mysql_error($this->mysql_connection);
         if (!is_numeric($errnum)) {
             if ($GLOBALS["VERBOSE"]) {
                 echo "{$LOGPRF} mysql_select_db/{$this->database}/" . __LINE__ . "  [FAILED] error {$errnum} {$des} -> RESTART !!\n";
             }
             @mysql_close($this->mysql_connection);
             $this->mysql_connection = false;
             $this->BD_CONNECT(false, $called);
             $ok = @mysql_select_db($this->database, $this->mysql_connection);
             if (!$ok) {
                 if ($GLOBALS["VERBOSE"]) {
                     echo "{$LOGPRF} mysql_select_db/{$this->database}/" . __LINE__ . " [FAILED] -> SECOND TIME !!\n";
                 }
                 if (function_exists("mysql_admin_mysql")) {
                     mysql_admin_mysql(0, "FATAL MySQL error Connection failed to MySQL database", $sql . "\n{$this->mysql_error}", __FILE__, __LINE__);
                 }
                 $this->ok = false;
                 return false;
             }
         }
     }
     if (!$ok) {
         $errnum = @mysql_errno($this->mysql_connection);
         $des = @mysql_error($this->mysql_connection);
         if ($GLOBALS["VERBOSE"]) {
             echo "{$LOGPRF} mysql_select_db/{$this->database}/" . __LINE__ . " [FAILED] N.{$errnum} DESC:{$des} mysql/QUERY_SQL\n";
         }
         if ($GLOBALS["VERBOSE"]) {
             echo "mysql -u {$this->mysql_admin} -p{$this->mysql_password} -h {$this->mysql_server} -P {$this->mysql_port} -A {$this->database}\n";
         }
         $this->mysql_errornum = $errnum;
         $this->mysql_error = $des;
         $time = date('h:i:s');
         $this->writeLogs("{$LOGPRF} Line:" . __LINE__ . ":mysql_select_db DB:\"{$database}\" Error Number ({$errnum}) ({$des}) config:{$this->mysql_server}:{$this->mysql_port}@{$this->mysql_admin} ({$called})", __CLASS__ . '/' . __FUNCTION__, __LINE__);
         $this->mysql_error = "{$LOGPRF} Line:" . __LINE__ . ": mysql_select_db:: Error {$errnum} ({$des}) config:{$this->mysql_server}:{$this->mysql_port}@{$this->mysql_admin} line:" . __LINE__;
         $this->ok = false;
         $this->ToSyslog($this->mysql_error);
         $this->ToSyslog($sql);
         @mysql_close($this->mysql_connection);
         $this->mysql_connection = false;
         if (function_exists("mysql_admin_mysql")) {
             mysql_admin_mysql(0, "FATAL MySQL error Error Number ({$errnum}) ({$des})", $sql . "\n{$this->mysql_error}", __FILE__, __LINE__);
         }
         return null;
     }
     $mysql_unbuffered_query_log = null;
     if (preg_match("#^(UPDATE|DELETE)#i", $sql)) {
         $mysql_unbuffered_query_log = "mysql_unbuffered_query";
         if ($GLOBALS["DEBUG_SQL"]) {
             echo "mysql_unbuffered_query()\n";
         }
         $results = @mysql_unbuffered_query($sql, $this->mysql_connection);
     } else {
         if ($unbuffered) {
             $mysql_unbuffered_query_log = "mysql_unbuffered_query";
             if ($GLOBALS["DEBUG_SQL"]) {
                 echo "mysql_unbuffered_query()\n";
             }
             $results = @mysql_unbuffered_query($sql, $this->mysql_connection);
         } else {
             $mysql_unbuffered_query_log = "mysql_query";
             if ($GLOBALS["DEBUG_SQL"]) {
                 echo "mysql_query()\n";
             }
             $results = @mysql_query($sql, $this->mysql_connection);
             $this->last_id = @mysql_insert_id($this->mysql_connection);
         }
     }
     if (!$results) {
         $errnum = @mysql_errno($this->mysql_connection);
         $des = @mysql_error($this->mysql_connection);
         if (preg_match('#Duplicate entry#', $des)) {
             $this->writeLogs("QUERY_SQL:" . __LINE__ . ": DB:\"{$database}\" Error {$errnum} {$des} line:" . __LINE__, __CLASS__ . '/' . __FUNCTION__, __FILE__, __LINE__);
             $this->writeLogs("QUERY_SQL:" . __LINE__ . ": DB:\"{$database}\" " . substr($sql, 0, 255) . "...line:" . __LINE__, __CLASS__ . '/' . __FUNCTION__, __FILE__, __LINE__);
             $this->writelogs($sql, __CLASS__ . '/' . __FUNCTION__, __FILE__);
             $this->ok = true;
             @mysql_close($this->mysql_connection);
             $this->mysql_connection = false;
             return true;
         }
         $this->mysql_errornum = $errnum;
         $this->mysql_error = "QUERY_SQL:" . __LINE__ . ": {$mysql_unbuffered_query_log}:: {$called} Error {$errnum} ({$des}) config:{$this->mysql_server}:{$this->mysql_port}@{$this->mysql_admin} line:" . __LINE__;
         if (isset($GLOBALS["HOTSPOT_DEBUG"])) {
             if ($GLOBALS["HOTSPOT_DEBUG"]) {
                 if (function_exists("wifidog_logs")) {
                     wifidog_logs("{$this->mysql_error}", __FUNCTION__, __LINE__);
                 }
             }
         }
         $this->ToSyslog($this->mysql_error);
         $sql = str_replace("\n", " ", $sql);
         $sql = str_replace("\t", " ", $sql);
         $sql = str_replace("  ", " ", $sql);
         $this->ToSyslog($sql);
         if (preg_match("#Table\\s+'(.+?)'.*?is marked as crashed#", $des, $re)) {
             if (class_exists("sockets")) {
                 $sock = new sockets();
                 $ARRAY["DB"] = $database;
                 $ARRAY["TABLE"] = $re[1];
                 $data = urlencode(base64_encode(serialize($ARRAY)));
                 $sock->getFrameWork("squid.php?mysql-crash={$data}");
             }
         }
         if ($GLOBALS["VERBOSE"]) {
             echo "{$LOGPRF} {$mysql_unbuffered_query_log}/" . __LINE__ . " [FAILED] N.{$errnum} DESC:{$des} {$called}\n";
         }
         if ($GLOBALS["VERBOSE"]) {
             echo "{$LOGPRF} {$mysql_unbuffered_query_log}" . __LINE__ . " [FAILED] {$sql}\n";
         }
         if (function_exists("mysql_admin_mysql")) {
             mysql_admin_mysql(0, "FATAL MySQL error Error Number ({$errnum}) ({$des})", $sql . "\n{$this->mysql_error}", __FILE__, __LINE__);
         }
         @mysql_free_result($this->mysql_connection);
         @mysql_close($this->mysql_connection);
         $this->mysql_connection = false;
         $this->ok = false;
         return null;
     }
     if ($GLOBALS["DEBUG_SQL"]) {
         echo "SUCCESS\n";
     }
     $this->ok = true;
     if ($this->last_id == 0) {
         $this->last_id = @mysql_insert_id($this->mysql_connection);
     }
     $result_return = $results;
     @mysql_free_result($this->mysql_connection);
     @mysql_close($this->mysql_connection);
     $this->mysql_connection = false;
     return $result_return;
 }
コード例 #17
0
ファイル: exec.wordpress.php プロジェクト: brucewu16899/1.6.x
function config($servername)
{
    $GLOBALS["SERVICE_NAME"] = "Wordpress {$servername}";
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".{$servername}.pid";
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        build_progress("{$servername} Already executed", 110);
        die;
    }
    @file_put_contents($pidfile, getmypid());
    $q = new mysql();
    $cp = $unix->find_program("cp");
    $sock = new sockets();
    $Salts = null;
    $DB_HOST = $q->mysql_server;
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$servername}: MySQL host: {$DB_HOST}\n";
    }
    if ($q->mysql_server == "127.0.0.1" or $q->mysql_server == "localhost" or $q->mysql_server == "localhost:") {
        if ($q->SocketPath == null) {
            $q->SocketPath = "/var/run/mysqld/mysqld.sock";
        }
        $DB_HOST = "localhost:{$q->SocketPath}";
    }
    if (!is_file("/usr/share/artica-postfix/bin/wp-cli.phar")) {
        build_progress("wp-cli.phar: no such binary", 110);
        return;
    }
    @chmod("/usr/share/artica-postfix/bin/wp-cli.phar", 0755);
    build_progress("{$servername}: {testing_configuration}", 40);
    $free = new freeweb($servername);
    $WORKING_DIRECTORY = $free->www_dir;
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$servername}: Directory: {$WORKING_DIRECTORY}\n";
    }
    @unlink("{$WORKING_DIRECTORY}/wp-config.php");
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$servername}: Duplicate: {$free->groupware_duplicate}\n";
    }
    if ($free->groupware_duplicate != null) {
        build_progress("{$servername}: {duplicate} {from} {$free->groupware_duplicate}", 40);
        if (!duplicate_wordpress($servername)) {
            build_progress("{$servername}: {installing} {failed}...", 110);
            apache_admin_mysql(0, "Failed to duplicate {$servername} from {$free->groupware_duplicate}", null, __FILE__, __LINE__);
            return;
        }
        apache_admin_mysql(2, "Success duplicate {$servername} from {$free->groupware_duplicate}", null, __FILE__, __LINE__);
        $free = new freeweb($servername);
    } else {
        if (!scan($WORKING_DIRECTORY)) {
            build_progress("{$servername}: {installing}...", 42);
            @mkdir($WORKING_DIRECTORY);
            shell_exec("{$cp} -rf /usr/share/wordpress-src/* {$WORKING_DIRECTORY}/");
            if (!scan($WORKING_DIRECTORY)) {
                apache_admin_mysql(0, "Failed to install {$servername} from /usr/share/wordpress-src", null, __FILE__, __LINE__);
                build_progress("{$servername}: {installing} {failed}...", 110);
                return;
            }
            apache_admin_mysql(2, "Success to install {$servername} from /usr/share/wordpress-src", null, __FILE__, __LINE__);
        }
    }
    $wordpressDB = $free->mysql_database;
    if ($wordpressDB == null) {
        $wordpressDB = $free->CreateDatabaseName();
        $free->mysql_database = $wordpressDB;
        $free->CreateSite(true);
    }
    $WordPressDBPass = $free->mysql_password;
    $DB_USER = $free->mysql_username;
    if ($DB_USER == "wordpress") {
        $DB_USER = null;
    }
    if ($DB_USER == null) {
        $DB_USER = "******" . time();
        $free->mysql_username = $DB_USER;
        $free->CreateSite(true);
    }
    if ($WordPressDBPass == null) {
        $WordPressDBPass = md5(time());
        $free->mysql_password = $WordPressDBPass;
        $free->CreateSite(true);
    }
    $DB_PASSWORD = $WordPressDBPass;
    if (is_file("{$WORKING_DIRECTORY}/salts.php")) {
        $Salts = @file_get_contents("{$WORKING_DIRECTORY}/salts.php");
    }
    if ($Salts == null) {
        $TMP = $unix->FILE_TEMP();
        build_progress("{$servername}: Acquiring Salts...", 44);
        $curl = new ccurl("https://api.wordpress.org/secret-key/1.1/salt/");
        if (!$curl->GetFile("{$TMP}")) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$servername}: Unable to download salts !!\n";
            }
            build_progress("{$servername}: Acquiring Salts {failed}...", 110);
            return;
        }
        $ASASLT = false;
        $fa = explode("\n", @file_get_contents($TMP));
        @unlink($TMP);
        while (list($num, $ligne) = each($fa)) {
            if (preg_match("#define\\(#", $ligne)) {
                $ASASLT = true;
                break;
            }
        }
        if (!$ASASLT) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$servername}: Unable to download salts !!\n";
            }
            build_progress("{$servername}: Acquiring Salts {failed}...", 110);
            return;
        }
        @file_put_contents("{$WORKING_DIRECTORY}/salts.php", @implode("\n", $fa));
    }
    build_progress("{$servername}: checking...", 48);
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$servername}: MySQL host...........: \"{$DB_HOST}\"\n";
    }
    if (!$q->DATABASE_EXISTS($wordpressDB)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$servername}: Create MySQL database: \"{$wordpressDB}\"\n";
        }
        $q->CREATE_DATABASE($wordpressDB);
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$servername}: MySQL database.......: \"{$wordpressDB}\"\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$servername}: MySQL user...........: \"{$DB_USER}\"\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$servername}: MySQL Password.......: \"{$DB_PASSWORD}\"\n";
    }
    $q->PRIVILEGES($DB_USER, $WordPressDBPass, $wordpressDB);
    $f[] = "<?php";
    $f[] = $Salts;
    $f[] = "/**";
    $f[] = " * The base configurations of the WordPress.";
    $f[] = " *";
    $f[] = " * This file has the following configurations: MySQL settings, Table Prefix,";
    $f[] = " * Secret Keys, WordPress Language, and ABSPATH. You can find more information";
    $f[] = " * by visiting {@link http://codex.wordpress.org/Editing_wp-config.php Editing";
    $f[] = " * wp-config.php} Codex page. You can get the MySQL settings from your web host.";
    $f[] = " *";
    $f[] = " * This file is used by the wp-config.php creation script during the";
    $f[] = " * installation. You don't have to use the web site, you can just copy this file";
    $f[] = " * to \"wp-config.php\" and fill in the values.";
    $f[] = " *";
    $f[] = " * @package WordPress";
    $f[] = " */";
    $f[] = "";
    $f[] = "// ** MySQL settings - You can get this info from your web host ** //";
    $f[] = "/** The name of the database for WordPress */";
    $f[] = "define('DB_NAME', '{$wordpressDB}');";
    $f[] = "";
    $f[] = "/** MySQL database username */";
    $f[] = "define('DB_USER', '{$DB_USER}');";
    $f[] = "";
    $f[] = "/** MySQL database password */";
    $f[] = "define('DB_PASSWORD', '{$DB_PASSWORD}');";
    $f[] = "";
    $f[] = "/** MySQL hostname */";
    $f[] = "define('DB_HOST', '{$DB_HOST}');";
    $f[] = "";
    $f[] = "/** Database Charset to use in creating database tables. */";
    $f[] = "define('DB_CHARSET', 'utf8');";
    $f[] = "";
    $f[] = "/** The Database Collate type. Don't change this if in doubt. */";
    $f[] = "define('DB_COLLATE', '');";
    $f[] = "";
    $f[] = "/**#@+";
    $f[] = " * Authentication Unique Keys and Salts.";
    $f[] = " *";
    $f[] = " * Change these to different unique phrases!";
    $f[] = " * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}";
    $f[] = " * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.";
    $f[] = " *";
    $f[] = " * @since 2.6.0";
    $f[] = " */";
    $f[] = "";
    $f[] = "/**#@-*/";
    $f[] = "";
    $f[] = "/**";
    $f[] = " * WordPress Database Table prefix.";
    $f[] = " *";
    $f[] = " * You can have multiple installations in one database if you give each a unique";
    $f[] = " * prefix. Only numbers, letters, and underscores please!";
    $f[] = " */";
    $f[] = "\$table_prefix  = 'wp_';";
    $f[] = "";
    $f[] = "/**";
    $f[] = " * WordPress Localized Language, defaults to English.";
    $f[] = " *";
    $f[] = " * Change this to localize WordPress. A corresponding MO file for the chosen";
    $f[] = " * language must be installed to wp-content/languages. For example, install";
    $f[] = " * de_DE.mo to wp-content/languages and set WPLANG to 'de_DE' to enable German";
    $f[] = " * language support.";
    $f[] = " */";
    $f[] = "define('WPLANG', '');";
    $f[] = "";
    $f[] = "/**";
    $f[] = " * For developers: WordPress debugging mode.";
    $f[] = " *";
    $f[] = " * Change this to true to enable the display of notices during development.";
    $f[] = " * It is strongly recommended that plugin and theme developers use WP_DEBUG";
    $f[] = " * in their development environments.";
    $f[] = " */";
    $f[] = "define('WP_DEBUG', false);";
    $f[] = "";
    $f[] = "/* That's all, stop editing! Happy blogging. */";
    $f[] = "";
    $f[] = "/** Absolute path to the WordPress directory. */";
    $f[] = "if ( !defined('ABSPATH') )";
    $f[] = "\tdefine('ABSPATH', dirname(__FILE__) . '/');";
    $f[] = "";
    $f[] = "/** Sets up WordPress vars and included files. */";
    $f[] = "require_once(ABSPATH . 'wp-settings.php');";
    $f[] = "?>";
    @file_put_contents("{$WORKING_DIRECTORY}/wp-config.php", @implode("\n", $f));
    build_progress("{$servername}: wp-config.php {done}...", 50);
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$servername}: {$WORKING_DIRECTORY}/wp-config.php done...\n";
    }
    $f = array();
    $f[] = "<?php";
    $f[] = "/*";
    $f[] = "WP-Cache Config Sample File";
    $f[] = "";
    $f[] = "See wp-cache.php for author details.";
    $f[] = "*/";
    $f[] = "";
    $f[] = "if ( ! defined('WPCACHEHOME') )";
    $f[] = "\tdefine( 'WPCACHEHOME', WP_PLUGIN_DIR . '/wp-super-cache/' );";
    $f[] = "";
    $f[] = "\$cache_compression = 0; // Super cache compression";
    $f[] = "\$cache_enabled = false;";
    $f[] = "\$super_cache_enabled = false;";
    $f[] = "\$cache_max_time = 3600; //in seconds";
    $f[] = "//\$use_flock = true; // Set it true or false if you know what to use";
    $f[] = "\$cache_path = WP_CONTENT_DIR . '/cache/';";
    $f[] = "\$file_prefix = 'wp-cache-';";
    $f[] = "\$ossdlcdn = 0;";
    $f[] = "";
    $f[] = "// Array of files that have 'wp-' but should still be cached";
    $f[] = "\$cache_acceptable_files = array( 'wp-comments-popup.php', 'wp-links-opml.php', 'wp-locations.php' );";
    $f[] = "";
    $f[] = "\$cache_rejected_uri = array('wp-.*\\.php', 'index\\.php');";
    $f[] = "\$cache_rejected_user_agent = array ( 0 => 'bot', 1 => 'ia_archive', 2 => 'slurp', 3 => 'crawl', 4 => 'spider', 5 => 'Yandex' );";
    $f[] = "";
    $f[] = "\$cache_rebuild_files = 1;";
    $f[] = "";
    $f[] = "// Disable the file locking system.";
    $f[] = "// If you are experiencing problems with clearing or creating cache files";
    $f[] = "// uncommenting this may help.";
    $f[] = "\$wp_cache_mutex_disabled = 1;";
    $f[] = "";
    $f[] = "// Just modify it if you have conflicts with semaphores";
    $f[] = "\$sem_id = 5419;";
    $f[] = "";
    $f[] = "if ( '/' != substr(\$cache_path, -1)) {";
    $f[] = "\t\$cache_path .= '/';";
    $f[] = "}";
    $f[] = "";
    $f[] = "\$wp_cache_mobile = 0;";
    $f[] = "\$wp_cache_mobile_whitelist = 'Stand Alone/QNws';";
    $f[] = "\$wp_cache_mobile_browsers = 'Android, 2.0 MMP, 240x320, AvantGo, BlackBerry, Blazer, Cellphone, Danger, DoCoMo, Elaine/3.0, EudoraWeb, hiptop, IEMobile, iPhone, iPod, KYOCERA/WX310K, LG/U990, MIDP-2.0, MMEF20, MOT-V, NetFront, Newt, Nintendo Wii, Nitro, Nokia, Opera Mini, Palm, Playstation Portable, portalmmm, Proxinet, ProxiNet, SHARP-TQ-GX10, Small, SonyEricsson, Symbian OS, SymbianOS, TS21i-10, UP.Browser, UP.Link, Windows CE, WinWAP';";
    $f[] = "";
    $f[] = "// change to relocate the supercache plugins directory";
    $f[] = "\$wp_cache_plugins_dir = WPCACHEHOME . 'plugins';";
    $f[] = "// set to 1 to do garbage collection during normal process shutdown instead of wp-cron";
    $f[] = "\$wp_cache_shutdown_gc = 0;";
    $f[] = "\$wp_super_cache_late_init = 0;";
    $f[] = "";
    $f[] = "// uncomment the next line to enable advanced debugging features";
    $f[] = "\$wp_super_cache_advanced_debug = 0;";
    $f[] = "\$wp_super_cache_front_page_text = '';";
    $f[] = "\$wp_super_cache_front_page_clear = 0;";
    $f[] = "\$wp_super_cache_front_page_check = 0;";
    $f[] = "\$wp_super_cache_front_page_notification = '0';";
    $f[] = "";
    $f[] = "\$wp_cache_object_cache = 0;";
    $f[] = "\$wp_cache_anon_only = 0;";
    $f[] = "\$wp_supercache_cache_list = 0;";
    $f[] = "\$wp_cache_debug_to_file = 0;";
    $f[] = "\$wp_super_cache_debug = 0;";
    $f[] = "\$wp_cache_debug_level = 5;";
    $f[] = "\$wp_cache_debug_ip = '';";
    $f[] = "\$wp_cache_debug_log = '';";
    $f[] = "\$wp_cache_debug_email = '';";
    $f[] = "\$wp_cache_pages[ \"search\" ] = 0;";
    $f[] = "\$wp_cache_pages[ \"feed\" ] = 0;";
    $f[] = "\$wp_cache_pages[ \"category\" ] = 0;";
    $f[] = "\$wp_cache_pages[ \"home\" ] = 0;";
    $f[] = "\$wp_cache_pages[ \"frontpage\" ] = 0;";
    $f[] = "\$wp_cache_pages[ \"tag\" ] = 0;";
    $f[] = "\$wp_cache_pages[ \"archives\" ] = 0;";
    $f[] = "\$wp_cache_pages[ \"pages\" ] = 0;";
    $f[] = "\$wp_cache_pages[ \"single\" ] = 0;";
    $f[] = "\$wp_cache_pages[ \"author\" ] = 0;";
    $f[] = "\$wp_cache_hide_donation = 0;";
    $f[] = "\$wp_cache_not_logged_in = 0;";
    $f[] = "\$wp_cache_clear_on_post_edit = 0;";
    $f[] = "\$wp_cache_hello_world = 0;";
    $f[] = "\$wp_cache_mobile_enabled = 0;";
    $f[] = "\$wp_cache_cron_check = 0;";
    $f[] = "?>";
    if (is_file("{$WORKING_DIRECTORY}/wp-content/plugins/wp-super-cache/wp-cache-config-sample.php")) {
        @file_put_contents("{$WORKING_DIRECTORY}/wp-content/plugins/wp-super-cache/wp-cache-config.php", @implode("\n", $f));
    }
    @file_put_contents("{$WORKING_DIRECTORY}/wp-config.php", @implode("\n", $f));
    build_progress("{$servername}: wp-config.php {done}...", 50);
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$servername}: {$WORKING_DIRECTORY}/wp-config.php done...\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$servername}: Testing configuration...\n";
    }
    if ($free->groupware_admin == null) {
        $ldap = new clladp();
        $free->groupware_admin = $ldap->ldap_admin;
        $free->groupware_password = $ldap->ldap_password;
    }
    $admin = $unix->shellEscapeChars($free->groupware_admin);
    $password = $unix->shellEscapeChars($free->groupware_password);
    $WORKING_DIRECTORY_CMDLINE = $unix->shellEscapeChars($WORKING_DIRECTORY);
    $cmd = array();
    $cmd[] = "/usr/share/artica-postfix/bin/wp-cli.phar core install";
    $cmd[] = "--url=\"{$servername}\"";
    $cmd[] = "--title=\"{$servername}\"";
    $cmd[] = "--admin_user={$admin}";
    $cmd[] = "--admin_password={$password}";
    $cmd[] = "--admin_email={$admin}@{$servername}";
    $cmd[] = "--path={$WORKING_DIRECTORY_CMDLINE}";
    $cmd[] = "--allow-root --debug --no-color 2>&1";
    $cmdline = @implode(" ", $cmd);
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$servername}: {$cmdline}\n";
    }
    build_progress("{$servername}: {install_wordpress} {please_wait} !...", 51);
    exec($cmdline, $results1);
    while (list($num, $ligne) = each($results1)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$servername}: {$ligne}\n";
        }
    }
    build_progress("{$servername}: {enforce_security}", 52);
    secure_wp($WORKING_DIRECTORY);
    build_progress("{$servername}: {directory_size}", 53);
    $size = $unix->DIRSIZE_BYTES($free->WORKING_DIRECTORY);
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$servername}: {$free->WORKING_DIRECTORY} {$size}Bytes\n";
    }
    $q->QUERY_SQL("UPDATE freeweb SET DirectorySize={$size} WHERE servername='{$servername}'", "artica_backup");
    if (!$q->ok) {
        system_admin_events("{$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "freewebs");
    }
}
コード例 #18
0
ファイル: exec.kerbauth.php プロジェクト: BillTheBest/1.6.x
function sync_time($aspid = false)
{
    if (isset($GLOBALS[__FUNCTION__])) {
        return;
    }
    $unix = new unix();
    $sock = new sockets();
    $NtpdateAD = intval($sock->GET_INFO("NtpdateAD"));
    if ($NtpdateAD == 0) {
        return;
    }
    $function = __FUNCTION__;
    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__))) {
            $timeExec = intval($unix->PROCCESS_TIME_MIN($pid));
            writelogs("Process {$pid} already exists since {$timeExec}Mn", __FUNCTION__, __FILE__, __LINE__);
            if ($timeExec > 5) {
                $kill = $unix->find_program("kill");
                system_admin_events("killing old pid {$pid} (already exists since {$timeExec}Mn)", __FUNCTION__, __FILE__, __LINE__);
                unix_system_kill_force($pid);
            } else {
                return;
            }
        }
        @file_put_contents($pidfile, getmypid());
    }
    $array = unserialize(base64_decode($sock->GET_INFO("KerbAuthInfos")));
    $hostname = strtolower(trim($array["WINDOWS_SERVER_NETBIOSNAME"])) . "." . strtolower(trim($array["WINDOWS_DNS_SUFFIX"]));
    $ipaddr = trim($array["ADNETIPADDR"]);
    $ntpdate = $unix->find_program("ntpdate");
    $hwclock = $unix->find_program("hwclock");
    if (!is_file($ntpdate)) {
        progress_logs(20, "{sync_time_ad}", "{$function}, ntpdate no such binary Line:" . __LINE__ . "");
        return;
    }
    progress_logs(20, "{sync_time_ad}", "{$function}, sync the time with the Active Directory {$hostname} [{$ipaddr}]...");
    if ($ipaddr != null) {
        $cmd = "{$ntpdate} -u {$ipaddr}";
    } else {
        $cmd = "{$ntpdate} -u {$hostname}";
    }
    if ($GLOBALS["VERBOSE"]) {
        progress_logs(20, "{sync_time_ad}", "{$cmd} line:" . __LINE__ . "");
    }
    exec($cmd . " 2>&1", $results);
    while (list($num, $a) = each($results)) {
        $unix->ToSyslog($a, false, "ntpd");
        progress_logs(20, "{sync_time_ad}", "{$function}, {$a} Line:" . __LINE__ . "");
    }
    if (is_file($hwclock)) {
        progress_logs(20, "{sync_time_ad}", "{$function}, sync the Hardware time with {$hwclock}");
        shell_exec("{$hwclock} --systohc");
    }
    $GLOBALS[__FUNCTION__] = true;
}
コード例 #19
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();
    }
}
コード例 #20
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);
    }
}
コード例 #21
0
ファイル: exec.seeker.php プロジェクト: articatech/artica
function xtart()
{
    if (!isset($GLOBALS["ARTICALOGDIR"])) {
        $GLOBALS["ARTICALOGDIR"] = @file_get_contents("/etc/artica-postfix/settings/Daemons/ArticaLogDir");
        if ($GLOBALS["ARTICALOGDIR"] == null) {
            $GLOBALS["ARTICALOGDIR"] = "/var/log/artica-postfix";
        }
    }
    $unix = new unix();
    $binfile = "/usr/share/artica-postfix/bin/seeker";
    if (!is_file($binfile)) {
        build_progress("{failed}", 110);
        events("Unable to stat {$binfile}");
        return;
    }
    $php = $unix->LOCATE_PHP5_BIN();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pidTime = "/etc/artica-postfix/pids/exec.seeker.php.xtart.time";
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        events("Already process executed pid {$pid}");
        return;
    }
    if (system_is_overloaded(basename(__FILE__))) {
        events("Overloaded system, schedule it later", __LINE__);
        $unix->THREAD_COMMAND_SET("{$php} " . __FILE__);
        build_progress("{failed} Overloaded", 110);
        return;
    }
    @file_put_contents($pidfile, getmypid());
    $timefile = $unix->file_time_min($pidTime);
    $DisksBenchs = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/DisksBenchs"));
    $DisksBenchs = $DisksBenchs * 60;
    if (!$GLOBALS["FORCE"]) {
        if ($timefile < $DisksBenchs) {
            events("{$timefile}mn, require at least {$DisksBenchs}mn", __LINE__);
            return;
        }
    }
    @unlink($pidTime);
    @file_put_contents($pidTime, time());
    build_progress("{scanning} {disks}", 10);
    $fdisk = $unix->find_program("fdisk");
    exec("{$fdisk} -l 2>&1", $results);
    $DISKS = array();
    while (list($index, $line) = each($results)) {
        $line = trim($line);
        if ($line == null) {
            continue;
        }
        if (preg_match("#^(Disque|Disk)\\s+\\/([a-zA-Z0-9\\-\\_\\/\\.]+).*?:\\s+[0-9]+.*?(bytes|octets)#", $line, $re)) {
            $DISKS["/" . $re[2]] = true;
        }
    }
    if (count($DISKS) == 0) {
        build_progress("{scanning} {disks} {failed}", 110);
        events("Unable to detect disks");
        $unix->ToSyslog("Unable to detect disks");
        system_admin_events("Unable to detect disks\n" . @implode("\n", $results), __FUNCTION__, __FILE__, __LINE__, "system");
        return;
    }
    $RUN = false;
    while (list($disk, $line) = each($DISKS)) {
        $results = array();
        @chmod("{$binfile}", 0755);
        $cmd = "{$binfile} \"" . trim($disk) . "\" 2>&1";
        build_progress("{scanning} {$disk}", 60);
        events("{$cmd}");
        exec($cmd, $results);
        while (list($index, $line) = each($results)) {
            $line = trim($line);
            echo "***: {$line}\n";
            $md5 = md5("{$disk}" . time());
            if ($line == null) {
                continue;
            }
            if (!preg_match("#^Results:\\s+([0-9]+)\\s+seeks.*?,\\s+([0-9\\.]+)\\s+ms#", $line, $re)) {
                continue;
            }
            $seeks = $re[1];
            $ms = $re[2];
            events("{$disk} {$seeks} seeks, {$ms} ms", __LINE__);
            $array = array();
            @mkdir("{$GLOBALS["ARTICALOGDIR"]}/seeker-queue", 0755, true);
            $array["SEEKS"] = $seeks;
            $array["DISK"] = $disk;
            $array["MS"] = $ms;
            $array["time"] = time();
            $unix->ToSyslog("Bench disk {$disk} {$ms} ms for {$seeks} seeks");
            events("{$GLOBALS["ARTICALOGDIR"]}/seeker-queue/{$md5}.ay", __LINE__);
            @file_put_contents("{$GLOBALS["ARTICALOGDIR"]}/seeker-queue/{$md5}.ay", serialize($array));
            $RUN = true;
            break;
        }
    }
    if ($RUN) {
        $php = $unix->LOCATE_PHP5_BIN();
        $nohup = $unix->find_program("nohup");
        build_progress("{analyze}", 90);
        $cmd = "{$php} " . dirname(__FILE__) . "/exec.syslog-engine.php --seeker";
        events($cmd);
        system($cmd);
    }
    build_progress("{done}", 100);
}
コード例 #22
0
ファイル: exec.acls.php プロジェクト: BillTheBest/1.6.x
function ApplySingleAcls($directory)
{
    if ($directory == "/tmp") {
        echo "Starting......: " . date("H:i:s") . " acls {$directory} is denied\n";
        return;
    }
    $unix = new unix();
    $chmod_bin = $unix->find_program("chmod");
    $setfacl_bin = $unix->find_program("setfacl");
    $recursive = null;
    $chmod = null;
    $q = new mysql();
    $dir = $unix->shellEscapeChars($directory);
    if (!is_dir($directory)) {
        system_admin_events("INFO,acls {$directory} no such directory delete it from database", __FUNCTION__, __FILE__, __LINE__, "acls");
        echo "Starting......: " . date("H:i:s") . " acls {$directory} no such directory\n";
        $q->QUERY_SQL("DELETE FROM acl_directories WHERE `directory`='{$directory}'");
        if (!$q->ok) {
            system_admin_events("Fatal,{$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "acls");
            echo $q->mysql_error . "\n";
        }
        return;
    }
    $acls = new aclsdirs($directory);
    echo "Starting......: " . date("H:i:s") . " acls \"{$dir}\" directory\n";
    if (!is_numeric($acls->chmod_octal)) {
        $events[] = "octal is not a numeric value...";
    }
    if (is_numeric($acls->chmod_octal)) {
        $events[] = "octal \"{$acls->chmod_octal}\"";
        if (chmod_recursive == 1) {
            $events[] = "Recursive mode";
            $recursive = " -R ";
        }
        $chmod = " " . $acls->chmod_octal;
    }
    if ($chmod != null) {
        $cmd = "{$chmod_bin}{$recursive}{$chmod} {$dir}";
        $events[] = "{$cmd}";
        exec("{$chmod_bin}{$recursive}{$chmod} {$dir} 2>&1", $events);
    }
    if (strlen($setfacl_bin) < 3) {
        $events[] = "ERROR: setfacl no such binary file";
        $events_text = @implode("\n", $events);
        if ($GLOBALS["VERBOSE"]) {
            echo $events_text . "\n";
        }
        $sql = "UPDATE acl_directories SET events='" . addslashes($events_text) . "' WHERE `md5`='{$acls->md5}'";
        if ($GLOBALS["VERBOSE"]) {
            echo $sql . "\n";
        }
        $q->QUERY_SQL($sql, "artica_backup");
        if (!$q->ok) {
            echo "{$q->mysql_error}\n";
        }
        return;
    }
    $cmd = "{$setfacl_bin} -b {$dir} 2>&1";
    $events[] = $cmd;
    exec("{$cmd}", $events);
    if ($GLOBALS["VERBOSE"]) {
        if (!is_array($acls->acls_array)) {
            echo "acls_array not an Array\n";
        }
    }
    print_r($acls->acls_array);
    $gp = new groups();
    if (is_array($acls->acls_array["GROUPS"])) {
        while (list($groupname, $array) = each($acls->acls_array["GROUPS"])) {
            $perms = array();
            $perms_strings = null;
            $recurs = null;
            if ($array["r"] == 1) {
                $perms[] = "r";
            }
            if ($array["w"] == 1) {
                $perms[] = "w";
            }
            if ($array["x"] == 1) {
                $perms[] = "x";
            }
            $perms_strings = @implode("", $perms);
            if ($perms_strings == null) {
                $events[] = "No permissions set for {$groupname}";
                continue;
            }
            if ($acls->acls_array["recursive"] == 1) {
                $recurs = "-R ";
            }
            $gpid = $gp->GroupIDFromGetEnt($groupname);
            $groupname = utf8_encode($groupname);
            if ($GLOBALS["VERBOSE"]) {
                echo "`{$groupname}` as gidNumber `{$gpid}`\n";
            }
            if (is_numeric($gpid)) {
                if ($gpid > 0) {
                    $groupname = $gpid;
                }
            }
            $cmd = "{$setfacl_bin} {$recurs}-m g:\"{$groupname}\":{$perms_strings} {$dir} 2>&1";
            $events[] = $cmd;
            exec("{$cmd}", $events);
            if ($acls->acls_array["default"] == 1) {
                $groupname = utf8_encode($groupname);
                $cmd = "{$setfacl_bin} {$recurs}-m d:g:\"{$groupname}\":{$perms_strings} {$dir} 2>&1";
                $events[] = $cmd;
                exec("{$cmd}", $events);
            }
        }
    } else {
        $events[] = "Groups: No acls\n";
    }
    if (is_array($acls->acls_array["MEMBERS"])) {
        while (list($member, $array) = each($acls->acls_array["MEMBERS"])) {
            $perms = array();
            $perms_strings = null;
            $recurs = null;
            if ($array["r"] == 1) {
                $perms[] = "r";
            }
            if ($array["w"] == 1) {
                $perms[] = "w";
            }
            if ($array["x"] == 1) {
                $perms[] = "x";
            }
            $perms_strings = @implode("", $perms);
            if ($perms_strings == null) {
                $events[] = "No permissions set for {$member}";
                continue;
            }
            if ($acls->acls_array["recursive"] == 1) {
                $recurs = "-R";
            }
            $member = utf8_encode($member);
            $cmd = "{$setfacl_bin} {$recurs} -m u:\"{$member}\":{$perms_strings} {$dir} 2>&1";
            $events[] = $cmd;
            exec("{$cmd}", $events);
            if ($acls->acls_array["default"] == 1) {
                $member = utf8_encode($member);
                $cmd = "{$setfacl_bin} {$recurs} -m d:u:\"{$member}\":{$perms_strings} {$dir} 2>&1";
                $events[] = $cmd;
                exec("{$cmd}", $events);
            }
        }
    } else {
        $events[] = "Members: No acls\n";
    }
    $events_text = @implode("\n", $events);
    if ($GLOBALS["VERBOSE"]) {
        echo $events_text . "\n";
    }
    system_admin_events("INFO,{$directory},\n{$events_text}", __FUNCTION__, __FILE__, __LINE__, "acls");
    $sql = "UPDATE acl_directories SET events='" . addslashes($events_text) . "' WHERE `md5`='{$acls->md5}'";
    $q->QUERY_SQL($sql, "artica_backup");
}
コード例 #23
0
function inject_contacts($uid, $contacts)
{
    while (list($index, $array) = each($contacts)) {
        $emailAddress_str = $array["email1address"];
        $emailAddress_str = trim(strtolower($emailAddress_str));
        if ($emailAddress_str == null) {
            continue;
        }
        if (!ValidateMail($emailAddress_str)) {
            if ($GLOBALS["VERBOSE"]) {
                echo "inject_contacts({$uid},...) -> ValidateMail({$emailAddress_str}) -> `FALSE`\n";
            }
            continue;
        }
        $md5 = md5("{$emailAddress_str}{$uid}");
        $f[] = "('{$emailAddress_str}','{$uid}','{$md5}','1')";
        $emailAddress_str = $array["email2address"];
        $emailAddress_str = trim(strtolower($emailAddress_str));
        if ($emailAddress_str == null) {
            continue;
        }
        if (!ValidateMail($emailAddress_str)) {
            if ($GLOBALS["VERBOSE"]) {
                echo "inject_contacts({$uid},...) -> ValidateMail({$emailAddress_str}) -> `FALSE`\n";
            }
            continue;
        }
        $md5 = md5("{$emailAddress_str}{$uid}");
        $f[] = "('{$emailAddress_str}','{$uid}','{$md5}','1')";
        $emailAddress_str = $array["email3address"];
        $emailAddress_str = trim(strtolower($emailAddress_str));
        if ($emailAddress_str == null) {
            continue;
        }
        if (!ValidateMail($emailAddress_str)) {
            if ($GLOBALS["VERBOSE"]) {
                echo "inject_contacts({$uid},...) -> ValidateMail({$emailAddress_str}) -> `FALSE`\n";
            }
            continue;
        }
        $md5 = md5("{$emailAddress_str}{$uid}");
        $f[] = "('{$emailAddress_str}','{$uid}','{$md5}','1')";
    }
    if (count($f) > 0) {
        $sql = "DELETE FROM `contacts_whitelist` WHERE uid='{$uid}' AND manual=0 AND enabled=1";
        $q = new mysql();
        $q->QUERY_SQL($sql, "artica_backup");
        system_user_events($uid, count($f) . " are added to the whitelist database..", __FUNCTION__, __FILE__, __LINE__, "whitelist");
        $sql = "INSERT IGNORE INTO contacts_whitelist (`sender`,`uid`,`md5`,`enabled`) VALUES " . @implode(",", $f);
        $q->QUERY_SQL($sql, "artica_backup");
        if (!$q->ok) {
            system_admin_events("Fatal: {$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "zarafa");
            return;
        }
        $GLOBALS["ITEMSC"] = $GLOBALS["ITEMSC"] + count($f);
    }
}
コード例 #24
0
function transaction_find($msgid, $id)
{
    $unix = new unix();
    $results = array();
    $users = new usersMenus();
    $maillog = $users->maillog_path;
    $grep = $unix->find_program("grep");
    if (!is_file($maillog)) {
        $results[] = "{$maillog} no such file";
    }
    exec("{$grep} {$msgid} {$maillog} 2>&1", $results);
    $q = new mysql();
    if (count($results) == 0) {
        $sql = "SELECT time_stamp\tFROM smtp_logs WHERE id={$id}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_events"));
        $time = strtotime($ligne["time_stamp"]);
        $pp = date("H:i", $time);
        $d = date("d", $time);
        $results[] = "Find '{$d}\\s+{$pp}.*?postfix'";
        exec("{$grep} -E '{$d}\\s+{$pp}.*?postfix' {$maillog} 2>&1", $results);
    }
    if (count($results) == 0) {
        $results[] = "{$msgid} no such transaction";
    }
    $sql = "UPDATE smtp_logs SET `transaction`='" . base64_encode(@implode("\n", $results)) . "' WHERE id='{$id}'";
    $q->QUERY_SQL($sql, "artica_events");
    if (!$q->ok) {
        system_admin_events("Fatal, search transaction {$msgid} failed {$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "postfix");
    }
}
コード例 #25
0
ファイル: exec.testspeed.php プロジェクト: BillTheBest/1.6.x
function install_argparse()
{
    $unix = new unix();
    $run = false;
    $aptget = $unix->find_program("apt-get");
    if (is_file($aptget)) {
        if ($GLOBALS["VERBOSE"]) {
            echo "Installing python-argparse\n";
        }
        exec("DEBIAN_FRONTEND=noninteractive /usr/bin/apt-get -o Dpkg::Options::=\"--force-confnew\" --force-yes -fuy install python-argparse 2>&1", $results);
        system_admin_events("python-lxml (apt): " . @implode("\n", $results), __FUNCTION__, __FILE__, __LINE__, "testspeed");
        $run = true;
    }
    $yum = $unix->find_program("yum");
    if (is_file($yum)) {
        $run = false;
    }
    if ($run) {
        runProc(true);
    }
}
コード例 #26
0
ファイル: exec.apt-get.php プロジェクト: BillTheBest/1.6.x
function wsgate_debian()
{
    if ($GLOBALS["VERBOSE"]) {
        echo "Load unix class...\n";
    }
    $unix = new unix();
    if ($GLOBALS["VERBOSE"]) {
        echo "Load unix class done..\n";
    }
    if (!is_dir("/etc/apt/sources.list.d")) {
        if ($GLOBALS["VERBOSE"]) {
            echo "/etc/apt/sources.list.d, no such directory\n";
        }
        return;
    }
    if (is_file("/etc/apt/sources.list.d/freerdp.list")) {
        @unlink("/etc/apt/sources.list.d/freerdp.list");
    }
    if (is_file("/etc/apt/sources.list.d/freerdp1.list")) {
        if ($GLOBALS["VERBOSE"]) {
            echo "/etc/apt/sources.list.d/freerdp1.list already set\n";
        }
        return;
    }
    $sourcelist = null;
    $LINUX_CODE_NAME = $unix->LINUX_CODE_NAME();
    $LINUXVER = $unix->LINUX_VERS();
    if ($GLOBALS["VERBOSE"]) {
        echo "{$LINUX_CODE_NAME} {$LINUXVER[0]}.{$LINUXVER[1]}\n";
    }
    if ($LINUX_CODE_NAME == "DEBIAN") {
        if ($LINUXVER[0] > 5) {
            $sourcelist = "deb http://download.opensuse.org/repositories/home:/felfert/Debian_6.0 ./";
        }
    }
    if ($LINUX_CODE_NAME == "UBUNTU") {
        if ($LINUXVER[0] > 9) {
            if ($LINUXVER[1] > 9) {
                $sourcelist = "deb http://download.opensuse.org/repositories/home:/felfert/xUbuntu_10.10 ./";
            }
        }
        if ($LINUXVER[0] > 10) {
            if ($LINUXVER[1] > 9) {
                $sourcelist = "deb http://download.opensuse.org/repositories/home:/felfert/xUbuntu_11.10 ./";
            }
        }
        if ($LINUXVER[0] > 11) {
            if ($LINUXVER[1] > 3) {
                $sourcelist = "deb http://download.opensuse.org/repositories/home:/felfert/xUbuntu_12.04 ./";
            }
        }
    }
    if ($sourcelist == null) {
        if ($GLOBALS["VERBOSE"]) {
            echo "sourcelist is null\n";
        }
        return;
    }
    $wget = $unix->find_program("wget");
    $aptkey = $unix->find_program("apt-key");
    $aptget = $unix->find_program("apt-get");
    $cmd = "{$wget} -O - http://download.opensuse.org/repositories/home:/felfert/Debian_6.0/Release.key | {$aptkey} add -";
    shell_exec($cmd);
    @file_put_contents("/etc/apt/sources.list.d/freerdp1.list", $sourcelist);
    $cmd = "DEBIAN_FRONTEND=noninteractive {$aptget} -o Dpkg::Options::=\"--force-confnew\" --force-yes -y update 2>&1";
    exec($cmd, $results);
    system_admin_events($cmd . "\n" . @implode("\n", $results), __FUNCTION__, __FILE__, __LINE__, "system-update");
    shell_exec($cmd);
    $cmd = "DEBIAN_FRONTEND=noninteractive {$aptget} -o Dpkg::Options::=\"--force-confnew\" --force-yes -y install wsgate 2>&1";
    exec($cmd, $results);
    system_admin_events($cmd . "\n" . @implode("\n", $results), __FUNCTION__, __FILE__, __LINE__, "system-update");
    shell_exec($cmd);
}
コード例 #27
0
function FreeMem($aspid = false, $SwapOffOn = array())
{
    $unix = new unix();
    if (!$aspid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = @file_get_contents($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            if ($GLOBALS["VERBOSE"]) {
                echo "Already executed pid {$pid}\n";
            }
            return;
        }
    }
    if (count($SwapOffOn) == 0) {
        $sock = new sockets();
        $SwapOffOn = unserialize(base64_decode($sock->GET_INFO("SwapOffOn")));
        if (!is_numeric($SwapOffOn["AutoMemWatchdog"])) {
            $SwapOffOn["AutoMemWatchdog"] = 1;
        }
        if (!is_numeric($SwapOffOn["AutoMemPerc"])) {
            $SwapOffOn["AutoMemPerc"] = 90;
        }
        if (!is_numeric($SwapOffOn["AutoMemInterval"])) {
            $SwapOffOn["AutoMemInterval"] = 180;
        }
    }
    $text[] = "Configuration was:";
    $text[] = "--------------------------------------";
    $text[] = "Free memory when Swap exceed {$SwapOffOn["AutoMemPerc"]}%";
    $text[] = "Watchdog scanning interval: each {$SwapOffOn["AutoMemInterval"]}mn";
    if (isset($SwapOffOn["CURRENT"])) {
        $text[] = $SwapOffOn["CURRENT"];
    }
    $text[] = $unix->ps_mem_report();
    $TOTAL_MEMORY_MB_FREE = $unix->TOTAL_MEMORY_MB_FREE();
    $text[] = "{$TOTAL_MEMORY_MB_FREE}MB before operation";
    $sync = $unix->find_program("sync");
    $sysctl = $unix->find_program("sysctl");
    $squid = $unix->LOCATE_SQUID_BIN();
    shell_exec($sync);
    shell_exec("{$sysctl} -w vm.drop_caches=3");
    shell_exec($sync);
    shell_exec("/etc/init.d/apache2 restart");
    if (is_file("/etc/init.d/ssh")) {
        shell_exec("/etc/init.d/ssh restart");
    }
    if ($unix->is_socket("/var/run/mysqld/mysqld.sock")) {
        $q = new mysql();
        $q->EXECUTE_SQL("RESET QUERY CACHE;");
    }
    if ($unix->is_socket("/var/run/mysqld/squid-db.sock")) {
        $q = new mysql_squid_builder();
        $q->EXECUTE_SQL("RESET QUERY CACHE;");
    }
    $TOTAL_MEMORY_MB_FREE2 = $unix->TOTAL_MEMORY_MB_FREE();
    $text[] = "{$TOTAL_MEMORY_MB_FREE2}MB After operation";
    $TOTAL_MEMORY_MB = $TOTAL_MEMORY_MB_FREE2 - $TOTAL_MEMORY_MB_FREE;
    $text[] = "{$TOTAL_MEMORY_MB}MB restored";
    $FINAL_TEXT = @implode("\n", $text);
    system_admin_events("Free memory operation has been executed - {$TOTAL_MEMORY_MB}MB restored\n{$FINAL_TEXT}", __FUNCTION__, __FILE__, __LINE__);
    if (is_file($squid)) {
        squid_admin_mysql(1, "Swap exceed rule: Free memory operation has been executed - {$TOTAL_MEMORY_MB}MB restored", $FINAL_TEXT, __FILE__, __LINE__);
    }
}
コード例 #28
0
ファイル: exec.scamp.php プロジェクト: BillTheBest/1.6.x
function Zexec()
{
    $sock = new sockets();
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid";
    if (!$GLOBALS["FORCE"]) {
        $pid = $unix->get_pid_from_file($pidfile);
        if ($unix->process_exists($pid)) {
            $timeTTL = $unix->PROCCESS_TIME_MIN($pid);
            system_admin_events("Already running PID {$pid} since {$timeTTL}Mn", __FUNCTION__, __FILE__, __LINE__, "antivirus");
            return;
        }
        $rm = $unix->find_program("rm");
        $timepid = $unix->file_time_min($pidfile);
        if ($timepid < 120) {
            system_admin_events("Require 120Mn minimal (current: {$timepid})", __FUNCTION__, __FILE__, __LINE__, "antivirus");
            return;
        }
    }
    @unlink($pidfile);
    @file_put_contents($pidfile, getmypid());
    $curlcmdline = null;
    $puser = null;
    $ini = new Bs_IniHandler();
    $datas = $sock->GET_INFO("ArticaProxySettings");
    if (trim($datas) != null) {
        $ini->loadString($datas);
        $ArticaProxyServerEnabled = $ini->_params["PROXY"]["ArticaProxyServerEnabled"];
        $ArticaProxyServerName = $ini->_params["PROXY"]["ArticaProxyServerName"];
        $ArticaProxyServerPort = $ini->_params["PROXY"]["ArticaProxyServerPort"];
        $ArticaProxyServerUsername = trim($ini->_params["PROXY"]["ArticaProxyServerUsername"]);
        $ArticaProxyServerUserPassword = $ini->_params["PROXY"]["ArticaProxyServerUserPassword"];
        if ($ArticaProxyServerEnabled == "yes") {
            if ($ArticaProxyServerUserPassword != null) {
                $puser = "******";
            }
            $curlcmdline = " --proxy {$ArticaProxyServerName}:{$ArticaProxyServerPort}{$puser}";
        }
    }
    $f[] = "# This is the /etc/scamp/default file.";
    $f[] = "# Created " . date('F') . " " . date('d') . ", " . date('Y') . " @ " . date('H:i:s') . "";
    $f[] = "";
    $f[] = "SCAMP_VERSION=5.3b";
    $f[] = "CLAMAV_DB=/var/lib/clamav";
    $f[] = "T_DIR=/var/lib/clamav/tmp";
    $f[] = "C_GROUP=clamav";
    $f[] = "C_PID=/var/run/clamav/clamd.pid";
    $f[] = "C_USER=clamav";
    $f[] = "GET_LDB=1";
    $f[] = "GET_MALWARE=1";
    $f[] = "GET_MSRBL=0";
    $f[] = "GET_SANE=1";
    $f[] = "GET_SECURITE=4";
    $f[] = "GET_WINNOW=1";
    $f[] = "gpg_key_url=http://www.sanesecurity.net/publickey.gpg";
    $f[] = "L_TYPE=0";
    $f[] = "MK_LOG=1";
    $f[] = "MSRBL=rsync://rsync.mirror.msrbl.com/msrbl/";
    $f[] = "msrbl_Images=MSRBL-Images.hdb";
    $f[] = "msrbl_SPAM=MSRBL-SPAM.ndb";
    $f[] = "msrbl_SPAM_CR=MSRBL-SPAM-CR.ndb";
    $f[] = "MSR_DIR=/var/lib/clamav/tmp/msr";
    $f[] = "MW_DIR=/var/lib/clamav/tmp/malware";
    $f[] = "MW_FILE=mbl.ndb";
    $f[] = "MW_URL=http://www.malwarepatrol.com.br/cgi/submit?action=list_clamav_ext";
    $f[] = "RELOAD=0";
    $f[] = "REST=1";
    $f[] = "SANE=rsync://rsync.sanesecurity.net/sanesecurity";
    $f[] = "SANE_DB=/var/lib/clamav/tmp/sane";
    $f[] = "SI_DIR=/var/lib/clamav/tmp/securite";
    $f[] = "SYS_LOG=1";
    $f[] = "WPC=3";
    $f[] = "W_SUM=0";
    if (!is_dir("/etc/scamp")) {
        @mkdir("/etc/scamp", 0755, true);
    }
    if (!is_dir("/var/lib/clamav")) {
        @mkdir("/var/lib/clamav", 0755, true);
    }
    @file_put_contents("/etc/scamp/default", @implode("\n", $f));
    $t = time();
    $l = explode("\n", @file_get_contents("/usr/share/artica-postfix/bin/scamp.sh"));
    while (list($num, $line) = each($l)) {
        if (preg_match("#^CURL_PROXY_CMD#", $line)) {
            $l[$num] = "CURL_PROXY_CMD=\"{$curlcmdline}\"";
        }
    }
    @file_put_contents("/usr/share/artica-postfix/bin/scamp.sh", @implode("\n", $l));
    exec("/usr/share/artica-postfix/bin/scamp.sh -L -q -R");
    $took = $unix->distanceOfTimeInWords($t, time());
    $content = @file_get_contents("/var/log/scamp.log");
    system_admin_events("Update done, took {$took}\n{$content}", __FUNCTION__, __FILE__, __LINE__, "antivirus");
    @unlink("/var/log/scamp.log");
    if (is_file("/var/run/c-icap/c-icap.ctl")) {
        shell_exec("echo -n \"srv_clamav:dbreload\" > /var/run/c-icap/c-icap.ctl");
        shell_exec("echo -n \"virus_scan:dbreload\" > /var/run/c-icap/c-icap.ctl");
    }
}
コード例 #29
0
ファイル: compile-squid32.php プロジェクト: BillTheBest/1.6.x
function create_package($t)
{
    $unix = new unix();
    $wget = $unix->find_program("wget");
    $tar = $unix->find_program("tar");
    $rm = $unix->find_program("rm");
    $cp = $unix->find_program("cp");
    $Architecture = Architecture();
    $version = squid_version();
    shell_exec("wget http://www.articatech.net/download/anthony-icons.tar.gz -O /tmp/anthony-icons.tar.gz");
    @mkdir("/usr/share/squid3/icons", 0755, true);
    shell_exec("tar -xf /tmp/anthony-icons.tar.gz -C /usr/share/squid3/icons/");
    shell_exec("/bin/chown -R squid:squid /usr/share/squid3/icons/");
    mkdir("/root/squid-builder/usr/share/squid3", 0755, true);
    mkdir("/root/squid-builder/etc/squid3", 0755, true);
    mkdir("/root/squid-builder/lib/squid3", 0755, true);
    mkdir("/root/squid-builder/usr/sbin", 0755, true);
    mkdir("/root/squid-builder/usr/bin", 0755, true);
    mkdir("/root/squid-builder/usr/share/squid-langpack", 0755, true);
    shell_exec("{$cp} -rf /usr/share/squid3/* /root/squid-builder/usr/share/squid3/");
    shell_exec("{$cp} -rf /etc/squid3/* /root/squid-builder/etc/squid3/");
    shell_exec("{$cp} -rf /lib/squid3/* /root/squid-builder/lib/squid3/");
    shell_exec("{$cp} -rf /usr/share/squid-langpack/* /root/squid-builder/usr/share/squid-langpack/");
    shell_exec("{$cp} -rf /usr/sbin/squid /root/squid-builder/usr/sbin/squid");
    shell_exec("{$cp} -rf /usr/bin/purge /root/squid-builder/usr/bin/purge");
    shell_exec("{$cp} -rf /usr/bin/squidclient /root/squid-builder/usr/bin/squidclient");
    shell_exec("{$cp} -rf /usr/bin/mysar /root/squid-builder/usr/bin/mysar");
    echo "Compile SARG....\n";
    compile_sarg();
    if ($Architecture == 64) {
        $Architecture = "x64";
    }
    if ($Architecture == 32) {
        $Architecture = "i386";
    }
    echo "Compile Arch {$Architecture} v:{$version}\n";
    chdir("/root/squid-builder");
    $version = squid_version();
    echo "Compressing....\n";
    shell_exec("{$tar} -czf squid32-{$Architecture}-{$version}.tar.gz *");
    system_admin_events("/root/squid-builder/squid32-{$Architecture}-{$version}.tar.gz  ready...", __FUNCTION__, __FILE__, __LINE__);
    if (is_file("/root/ftp-password")) {
        echo "/root/squid-builder/squid32-{$Architecture}-{$version}.tar.gz is now ready to be uploaded\n";
        shell_exec("curl -T /root/squid-builder/squid32-{$Architecture}-{$version}.tar.gz ftp://www.articatech.net/download/ --user " . @file_get_contents("/root/ftp-password"));
        system_admin_events("Uploading squid32-{$Architecture}-{$version}.tar.gz done.", __FUNCTION__, __FILE__, __LINE__);
        if (is_file("/root/rebuild-artica")) {
            shell_exec("{$wget} \"" . @file_get_contents("/root/rebuild-artica") . "\" -O /tmp/rebuild.html");
        }
    }
    shell_exec("/etc/init.d/artica-postfix restart squid-cache");
    $took = $unix->distanceOfTimeInWords($t, time(), true);
    system_admin_events("Installing the new squid-cache {$version} success took:{$took}", __FUNCTION__, __FILE__, __LINE__, "software");
}
コード例 #30
0
function update()
{
    $unix = new unix();
    $sock = new sockets();
    $filetime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    if ($GLOBALS["VERBOSE"]) {
        echo "filetime = {$filetime}\n";
        echo "pidfile = {$pidfile}\n";
    }
    $EnableSpamhausDROPList = $sock->GET_INFO("EnableSpamhausDROPList");
    if (!is_numeric($EnableSpamhausDROPList)) {
        $EnableSpamhausDROPList = 0;
    }
    if (!$GLOBALS["FORCE"]) {
        if (!$GLOBALS["VERBOSE"]) {
            $pid = $unix->get_pid_from_file($pidfile);
            if ($unix->process_exists($pid)) {
                if ($GLOBALS["VERBOSE"]) {
                    echo "{$pid} already running !!!\n";
                }
                return;
            }
        }
    }
    @file_put_contents($pidfile, getmypid());
    if (!$GLOBALS["FORCE"]) {
        $time = $unix->file_time_min($filetime);
        if ($time < 1440) {
            if ($GLOBALS["VERBOSE"]) {
                echo "{$time}Mn !!!\n";
            }
            return;
        }
        @unlink($filetime);
        @file_put_contents($filetime, time());
    }
    $iptables = new iptables_chains();
    $curl = new ccurl("http://www.spamhaus.org/drop/drop.lasso");
    $curl->NoHTTP_POST = true;
    $tmpdir = $unix->TEMP_DIR();
    $destination = "{$tmpdir}/drop.lasso";
    if (!$curl->get()) {
        system_admin_events("Spamhaus DROP List failed {$curl->error}");
        return;
    }
    $drop = explode("\n", $curl->data);
    foreach ($drop as $line) {
        $line = trim($line);
        if (!empty($line) && substr($line, 0, 1) !== ';') {
            list($cidr, $sbl) = explode(" ; ", $line);
            $cidr = trim($cidr);
            $sbl = trim($sbl);
            //echo "iptables -A input -s $cidr -d 0/0 -j REJECT\n";
            //echo "iptables -A output -s 0/0 -d $cidr -j REJECT\n";
            $array[$cidr] = $sbl;
        }
    }
    $q = new mysql();
    $prefix = "INSERT IGNORE INTO iptables(\n\tservice,\n\tservername,\n\tserverip,\n\tlocal_port,\n\tdisable,\n\tevents_number,\n\trule_string,\n\trulemd5,\n\tflux,\n\tevents_block,\n\tdate_created,\n\tmultiples_ports,allow ) VALUES ";
    $date = date("Y-m-d H:i:s");
    while (list($cidr, $sbl) = each($array)) {
        $rulemd5 = md5("{$cidr}{$sbl}");
        $f[] = "('SpamHaus',\n\t\t'{$cidr}',\n\t\t'{$cidr}',\n\t\t'0',\n\t\t'0',\n\t\t'0',\n\t\t'iptables -A input -s {$cidr} -d 0/0 -j REJECT',\n\t\t'{$rulemd5}','INPUT',\n\t\t'Spamhaus DROP List',\n\t\t'{$date}',\n\t\t'0',0)";
    }
    if (count($f) > 0) {
        echo count($f) . " rules added";
        $q->QUERY_SQL("DELETE FROM iptables WHERE `service`='SpamHaus' AND `allow`=0", "artica_backup");
        $q->QUERY_SQL($prefix . @implode($f, ","), "artica_backup");
    }
    $php = $unix->LOCATE_PHP5_BIN();
    $nohup = $unix->find_program("nohup");
    $cmd = "{$nohup} {$php} /usr/share/artica-postfix/exec.postfix.iptables.php --spamhaus >/dev/null 2>&1 &";
    echo $cmd . "\n";
    shell_exec($cmd);
}