function user_status_table() { if (isset($GLOBALS["user_status_table_executed"])) { if ($GLOBALS["VERBOSE"]) { $trace = debug_backtrace(); if (isset($trace[1])) { $called = " called by " . basename($trace[1]["file"]) . " {$trace[1]["function"]}() line {$trace[1]["line"]}"; echo "user_status_table Already executed {$called}\n"; } } return; } $GLOBALS["user_status_table_executed"] = true; $unix = new unix(); $sock = new sockets(); $timefile = "/usr/share/artica-postfix/ressources/databases/ZARAFA_DB_STATUS.db"; $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $mns = $unix->file_time_min($timefile); if ($GLOBALS["VERBOSE"]) { echo "{$timefile} = {$mns}Mn\n"; } if (!$GLOBALS["FORCE"]) { if (system_is_overloaded(basename(__FILE__))) { system_admin_events("Overload system, aborting", __FUNCTION__, __FILE__, __LINE__, "zarafa"); return; } if ($mns < 180) { return; } $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $timeProcess = $unix->PROCCESS_TIME_MIN($pid); system_admin_events("{$pid}, task is already executed (since {$timeProcess}Mn}), aborting", __FUNCTION__, __FILE__, __LINE__, "zarafa"); if ($timeProcess < 15) { return; } $kill = $unix->find_program("kill"); unix_system_kill_force($pid); system_admin_events("{$pid}, killed (since {$timeProcess}Mn}), aborting", __FUNCTION__, __FILE__, __LINE__, "zarafa"); } } @file_put_contents($pidfile, getmypid()); @unlink($timefile); @file_put_contents($timefile, time()); $ZarafaIndexPath = $sock->GET_INFO("ZarafaIndexPath"); $ZarafaStoreOutsidePath = $sock->GET_INFO("ZarafaStoreOutsidePath"); $ZarafaMySQLServiceType = $sock->GET_INFO("ZarafaMySQLServiceType"); if (!is_numeric($ZarafaMySQLServiceType)) { $ZarafaMySQLServiceType = 1; } // $ZarafaMySQLServiceType =1 ou 2 /var/lib/mysql // $ZarafaMySQLServiceType =3 --> dedicated instance if ($ZarafaIndexPath == null) { $ZarafaIndexPath = "/var/lib/zarafa/index"; } if ($ZarafaStoreOutsidePath == null) { $ZarafaStoreOutsidePath = "/var/lib/zarafa"; } $ARRAY["ZARAFA_INDEX"] = $unix->DIRSIZE_BYTES($ZarafaIndexPath); if ($ZarafaMySQLServiceType == 1 or $ZarafaMySQLServiceType == 2) { $ARRAY["ZARAFA_DB"] = $unix->DIRSIZE_BYTES("/var/lib/mysql"); } if ($ZarafaMySQLServiceType == 3) { $WORKDIR = $sock->GET_INFO("ZarafaDedicateMySQLWorkDir"); if ($WORKDIR == null) { $WORKDIR = "/home/zarafa-db"; } $ARRAY["ZARAFA_DB"] = $unix->DIRSIZE_BYTES($WORKDIR); } $ARRAY["ATTACHS"] = $unix->DIRSIZE_BYTES($ZarafaStoreOutsidePath); @file_put_contents($timefile, serialize($ARRAY)); @chmod($timefile, 0750); unset($ARRAY); $zarafaadmin = $unix->find_program("zarafa-admin"); $kill = $unix->find_program("kill"); $pids = $unix->PIDOF_PATTERN_ALL("zarafa-admin -l"); if (count($pids) > 0) { while (list($pid, $line) = each($pids)) { $time = $unix->PROCESS_TTL($pid); if ($time > 15) { $unix->_syslog("killing zarafa-admin -l pid {$pid} ({$time}mn)", basename(__FILE__)); unix_system_kill_force($pid); } } } $pid = $unix->PIDOF_PATTERN("zarafa-admin -l"); if ($unix->process_exists($pid)) { $unix->_syslog("zarafa-admin -l pid {$pid} still running", basename(__FILE__)); } if ($GLOBALS["VERBOSE"]) { echo "{$zarafaadmin} -l 2>&1\n--------------------------------------------------------------------\n"; } exec("{$zarafaadmin} -l 2>&1", $results); while (list($num, $line) = each($results)) { $line = trim($line); if ($GLOBALS["VERBOSE"]) { echo "\"{$line}\"\n"; } if (preg_match("#User list for\\s+(.+?)\\(#i", $line, $re)) { $ou = $re[1]; continue; } if (preg_match("#Username#", $line)) { continue; } if (preg_match("#SYSTEM#", $line)) { continue; } if (preg_match("#^(.+?)\\s+.+?#", $line, $re)) { if ($GLOBALS["VERBOSE"]) { echo "\"{$ou}\" -> \"{$re[1]}\" -> \"_user_status_table_info({$re[1]},{$zarafaadmin})\"\n"; } $array[$ou][$re[1]] = _user_status_table_info($re[1], $zarafaadmin); } } $q = new mysql(); if (!$q->TABLE_EXISTS('zarafauserss', 'artica_events')) { $sql = "CREATE TABLE IF NOT EXISTS `zarafauserss` (\n\t\t\t `zmd5` varchar(90) NOT NULL PRIMARY KEY,\n\t\t\t `uid` varchar(128) NOT NULL,\n\t\t\t `ou` varchar(128) NOT NULL,\n\t\t\t `mail` varchar(255) NOT NULL,\n\t\t\t `license` smallint(1) NOT NULL,\n\t\t\t `NONACTIVETYPE` varchar(60) NOT NULL,\n\t\t\t `storesize` BINT(100) UNSIGNED NOT NULL,\n\t\t\t KEY `uid` (`uid`),\n\t\t\t KEY `ou` (`ou`),\n\t\t\t KEY `mail` (`mail`),\n\t\t\t KEY `license` (`license`),\n\t\t\t KEY `NONACTIVETYPE` (`NONACTIVETYPE`),\n\t\t\t KEY `storesize` (`storesize`)\n\t\t\t) "; $q->QUERY_SQL($sql, 'artica_events'); if (!$q->ok) { echo $q->mysql_error . "\n"; return; } } $prefix = "INSERT IGNORE INTO zarafauserss (zmd5,uid,ou,mail,license,NONACTIVETYPE,storesize) VALUES "; while (list($ou, $members) = each($array)) { while (list($uid, $main) = each($members)) { $md5 = md5("{$uid}{$ou}"); if (!isset($main["NONACTIVETYPE"])) { $main["NONACTIVETYPE"] = ''; } if ($GLOBALS["VERBOSE"]) { echo "\"('{$md5}','{$uid}','{$ou}','{$main["MAIL"]}','{$main["ACTIVE"]}','{$main["NONACTIVETYPE"]}','{$main["STORE_SIZE"]}')\n"; } $f[] = "('{$md5}','{$uid}','{$ou}','{$main["MAIL"]}','{$main["ACTIVE"]}','{$main["NONACTIVETYPE"]}','{$main["STORE_SIZE"]}')"; } } if (count($f) == 0) { return; } $q->QUERY_SQL("TRUNCATE TABLE zarafauserss", "artica_events"); $q->QUERY_SQL($prefix . @implode(",", $f), "artica_events"); if (!$q->ok) { echo $q->mysql_error . "\n"; } if ($GLOBALS["VERBOSE"]) { echo "FINISH\n--------------------------------------------------------------------\n"; } }
function C_ICAP_TABLES($nopid = false) { $unix = new unix(); $size = $unix->DIRSIZE_BYTES("/home/artica/categories_databases"); if ($size > 2000) { $rm = $unix->find_program("rm"); shell_exec("{$rm} -rf /home/artica/categories_databases/*"); } return; }
function get_status() { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $TimeFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Restarting....: " . date("H:i:s") . " [INIT]: Already Artica task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); if ($GLOBALS["VERBOSE"]) { echo "TimeFile: {$TimeFile}\n"; } if (!$GLOBALS["VERBOSE"]) { $zTime = $unix->file_time_min($TimeFile); if ($zTime < 10) { return; } } @unlink($TimeFile); @file_put_contents($TimeFile, time()); $sock = new sockets(); $StreamCacheCache = $sock->GET_INFO("StreamCacheCache"); $StreamCacheMainCache = $sock->GET_INFO("StreamCacheMainCache"); if ($StreamCacheCache == null) { $StreamCacheCache = "/home/squid/videocache"; } if ($StreamCacheMainCache == null) { $StreamCacheMainCache = "/home/squid/streamcache"; } $dir = $StreamCacheCache; if (is_link($dir)) { $dir = readlink($dir); } $Partition = $unix->DIRPART_INFO($dir); $SIZE = $unix->DIRSIZE_BYTES($dir); $array["VIDEOCACHE"]["SIZE"] = $SIZE; $array["VIDEOCACHE"]["PART"] = $Partition; $dir = $StreamCacheMainCache; if (is_link($dir)) { $dir = readlink($dir); } $Partition = $unix->DIRPART_INFO($dir); $SIZE = $unix->DIRSIZE_BYTES($dir); $array["SQUID"]["SIZE"] = $SIZE; $array["SQUID"]["PART"] = $Partition; @file_put_contents("/usr/share/artica-postfix/ressources/logs/web/videocache.dirs.status.db", @serialize($array)); @chmod("/usr/share/artica-postfix/ressources/logs/web/videocache.dirs.status.db", 0755); }
function status_all_mysql_engines() { $unix = new unix(); if (systemMaxOverloaded()) { return; } $cachefile = "/usr/share/artica-postfix/ressources/logs/web/MYSQLDB_STATUS"; $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); if (!$GLOBALS["VERBOSE"]) { $time = $unix->file_time_min($cachefile); if ($time < 60) { return; } } $sock = new sockets(); $datadir = $unix->MYSQL_DATA_DIR(); $ArticaDBPath = $sock->GET_INFO("ArticaDBPath"); if ($ArticaDBPath == null) { $ArticaDBPath = "/opt/articatech"; } $SquidStatsDatabasePath = $sock->GET_INFO("SquidStatsDatabasePath"); if ($SquidStatsDatabasePath == null) { $SquidStatsDatabasePath = "/opt/squidsql"; } $array["APP_MYSQL_ARTICA"]["size"] = $unix->DIRSIZE_BYTES($datadir); $array["APP_MYSQL_ARTICA"]["INFO"] = $unix->DIRPART_INFO($datadir); if (is_dir("{$ArticaDBPath}/mysql")) { $array["APP_ARTICADB"]["size"] = $unix->DIRSIZE_BYTES("{$ArticaDBPath}"); $array["APP_ARTICADB"]["INFO"] = $unix->DIRPART_INFO("{$ArticaDBPath}"); } if (is_dir("{$SquidStatsDatabasePath}/data")) { $array["APP_SQUID_DB"]["size"] = $unix->DIRSIZE_BYTES("{$SquidStatsDatabasePath}"); $array["APP_SQUID_DB"]["INFO"] = $unix->DIRPART_INFO("{$SquidStatsDatabasePath}"); } $MySQLSyslogWorkDir = $sock->GET_INFO("MySQLSyslogWorkDir"); if ($MySQLSyslogWorkDir == null) { $MySQLSyslogWorkDir = "/home/syslogsdb"; } if (is_dir($MySQLSyslogWorkDir)) { $array["MYSQL_SYSLOG"]["size"] = $unix->DIRSIZE_BYTES($MySQLSyslogWorkDir); $array["MYSQL_SYSLOG"]["INFO"] = $unix->DIRPART_INFO($MySQLSyslogWorkDir); } if ($GLOBALS["VERBOSE"]) { print_r($array); } @unlink($cachefile); @file_put_contents($cachefile, base64_encode(serialize($array))); @chmod($cachefile, 0777); }
function databasesize($force = false) { $sock = new sockets(); $unix = new unix(); $arrayfile = $GLOBALS["DBCACHE_PATH"]; if (!$force) { $pidfile = $GLOBALS["DATABASE_STATS_PID"]; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); return; } @file_put_contents($pidfile, getmypid()); $time = $unix->file_time_min($arrayfile); if ($time < 20) { return; } } $WORKDIR = $sock->GET_INFO($GLOBALS["WORK_DIR_TOKEN"]); if ($WORKDIR == null) { $WORKDIR = $GLOBALS["WORK_DIR_DEFAULT"]; } $dir = $WORKDIR; if (is_link($dir)) { $dir = readlink($dir); } $unix = new unix(); $sizbytes = $unix->DIRSIZE_BYTES($dir); $dir = $unix->shellEscapeChars($dir); $df = $unix->find_program("df"); $array["DBSIZE"] = $sizbytes / 1024; exec("{$df} -B K {$dir} 2>&1", $results); while (list($num, $ligne) = each($results)) { if (preg_match("#^.*?\\s+([0-9A-Z\\.]+)K\\s+([0-9A-Z\\.]+)K\\s+([0-9A-Z\\.]+)K\\s+([0-9\\.]+)%\\s+(.+)#", $ligne, $re)) { $array["SIZE"] = $re[1]; $array["USED"] = $re[2]; $array["AIVA"] = $re[3]; $array["POURC"] = $re[4]; $array["MOUNTED"] = $re[5]; break; } } $results = array(); exec("{$df} -i {$dir} 2>&1", $results); while (list($num, $ligne) = each($results)) { if (preg_match("#^.*?\\s+([0-9A-Z\\.]+)\\s+([0-9A-Z\\.]+)\\s+([0-9A-Z\\.]+)\\s+([0-9\\.]+)%\\s+(.+)#", $ligne, $re)) { $array["ISIZE"] = $re[1]; $array["IUSED"] = $re[2]; $array["IAIVA"] = $re[3]; $array["IPOURC"] = $re[4]; break; } } if ($GLOBALS["VERBOSE"]) { print_r($array); } @unlink($arrayfile); @file_put_contents($arrayfile, serialize($array)); if ($GLOBALS["VERBOSE"]) { echo "Saving {$arrayfile}...\n"; } @chmod($arrayfile, 0755); }
function squidlogs_status($nopid = false) { $sock = new sockets(); $unix = new unix(); $cachefile = "/usr/share/artica-postfix/ressources/logs/web/squidlogs.stats"; $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $q = new mysql_squid_builder(); if (!$nopid) { $pid = @file_get_contents($pidfile); if ($unix->process_exists($pid)) { echo "Starting......: " . date("H:i:s") . " cache manager, " . __FUNCTION__ . "() already running PID:{$pid}\n"; return; } @file_put_contents($pidfile, getmypid()); } if ($GLOBALS["FORCE"]) { @unlink($cachefile); } if (is_file($cachefile)) { $time = $unix->file_time_min($cachefile); if ($time < 20) { if ($GLOBALS["VERBOSE"]) { echo "{$time}mn require 20mn\n"; } return; } } $df = $unix->find_program("df"); $sock = new sockets(); $MYSQL_DATA_DIR = $q->MYSQL_DATA_DIR; if (is_dir("/opt/squidsql")) { $MYSQL_DATA_DIR = "/opt/squidsql"; } if ($GLOBALS["VERBOSE"]) { echo "MYSQL_DATA_DIR = {$MYSQL_DATA_DIR}\n"; } if (!is_link("{$MYSQL_DATA_DIR}/{$q->database}")) { $realFolder = "{$MYSQL_DATA_DIR}"; } else { $realFolder = readlink("{$MYSQL_DATA_DIR}"); } $EXEC_NICE = $unix->EXEC_NICE(); $cmdline = "{$EXEC_NICE}{$df} -h {$realFolder} 2>&1"; if ($GLOBALS["VERBOSE"]) { echo __LINE__ . " {$cmdline}\n"; } exec("{$df} -h {$realFolder} 2>&1", $results); $foldersize = $unix->DIRSIZE_BYTES($realFolder); while (list($num, $line) = each($results)) { if (!preg_match("#(.+?)\\s+([0-9A-Z\\.]+)\\s+([0-9A-Z\\.]+)\\s+([0-9A-Z\\.]+)\\s+([0-9\\.]+)%#", $line, $re)) { if ($GLOBALS["VERBOSE"]) { echo "{$line}, no match\n"; } continue; } $array["squidlogs"]["DEV"] = $re[1]; $array["squidlogs"]["SIZE"] = $re[2]; $array["squidlogs"]["OC"] = $re[3]; $array["squidlogs"]["DISP"] = $re[4]; $array["squidlogs"]["POURC"] = $re[5]; $array["squidlogs"]["REALPATH"] = $realFolder; $array["squidlogs"]["PATHSIZE"] = $foldersize; $array["squidlogs"]["TIME"] = time(); } $TuningParameters = unserialize(base64_decode($sock->GET_INFO("MySQLSyslogParams"))); $MySQLSyslogWorkDir = $sock->GET_INFO("MySQLSyslogWorkDir"); if ($MySQLSyslogWorkDir == null) { $MySQLSyslogWorkDir = "/home/syslogsdb"; } $q = new mysql_storelogs(); $MYSQL_DATA_DIR = $MySQLSyslogWorkDir; if (!is_link("{$MYSQL_DATA_DIR}")) { $realFolder = "{$MYSQL_DATA_DIR}"; } else { $realFolder = readlink("{$MYSQL_DATA_DIR}"); } exec("{$df} -h {$realFolder} 2>&1", $results); if ($GLOBALS["VERBOSE"]) { echo __LINE__ . " {$cmdline}\n"; } $foldersize = $unix->DIRSIZE_BYTES($realFolder); while (list($num, $line) = each($results)) { if (!preg_match("#(.+?)\\s+([0-9A-Z\\.]+)\\s+([0-9A-Z\\.]+)\\s+([0-9A-Z\\.]+)\\s+([0-9\\.]+)%#", $line, $re)) { continue; } $array["syslogstore"]["DEV"] = $re[1]; $array["syslogstore"]["SIZE"] = $re[2]; $array["syslogstore"]["OC"] = $re[3]; $array["syslogstore"]["DISP"] = $re[4]; $array["syslogstore"]["POURC"] = $re[5]; $array["syslogstore"]["REALPATH"] = $realFolder; $array["syslogstore"]["PATHSIZE"] = $foldersize; $array["syslogstore"]["TIME"] = time(); } print_r($array); @unlink($cachefile); @file_put_contents($cachefile, serialize($array)); $unix->chmod_func(0777, $cachefile); if ($GLOBALS["VERBOSE"]) { echo __LINE__ . " " . __FUNCTION__ . " finish OK\n"; } }
function cache_center_status($aspid = false) { $unix = new unix(); if ($GLOBALS["VERBOSE"]) { echo "Running cache_center_status()\n"; $aspid = true; } if (!$aspid) { $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . "Already `task` running PID {$pid} since {$time}mn\n"; } system_admin_events("stop_squid::Already task running PID {$pid} since {$time}mn", __FUNCTION__, __FILE__, __LINE__, "proxy"); return; } @file_put_contents($pidfile, getmypid()); } $TimeFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time"; if ($GLOBALS["VERBOSE"]) { echo "TimeFile={$TimeFile}\n"; } $Time = $unix->file_time_min($TimeFile); if (!$GLOBALS["VERBOSE"]) { if ($Time < 5) { return; } } @unlink($TimeFile); @file_put_contents($TimeFile, time()); $ARRAY = unserialize(base64_decode(squid_get_storage_info())); $q = new mysql(); while (list($directory, $arrayStore) = each($ARRAY)) { $arrayStore["USED"] = intval($arrayStore["USED"]); $arrayStore["PERC"] = intval($arrayStore["PERC"]); if ($arrayStore["USED"] == 0 && $arrayStore["PERC"] > 0) { $arrayStore["USED"] = $unix->DIRSIZE_BYTES($directory); } if ($GLOBALS["VERBOSE"]) { echo "{$directory} USED {$arrayStore["USED"]} PERC:{$arrayStore["PERC"]}\n"; } if ($directory == "MEM") { continue; } if ($arrayStore["USED"] == 0) { continue; } $PERC = $arrayStore["PERC"]; $USED = $arrayStore["USED"]; if (preg_match("#\\/home\\/squid\\/cache\\/MemBooster([0-9]+)#", $directory, $re)) { $q->QUERY_SQL("UPDATE squid_caches_center SET percentcache='{$PERC}',percenttext='{$PERC}', \n\t\t\t\t\t`usedcache`='{$USED}' WHERE ID={$re[1]}", "artica_backup"); continue; } if ($GLOBALS["VERBOSE"]) { echo "{$directory} -> {$USED} / {$PERC}%\n"; } $q->QUERY_SQL("UPDATE squid_caches_center SET \n\t\t\t\tpercentcache='{$PERC}',percenttext='{$PERC}', `usedcache`='{$USED}' WHERE \n\t\t\t\t`cache_dir`='{$directory}'", "artica_backup"); } }
function rebuildcaches() { $logFile = "/usr/share/artica-postfix/ressources/logs/web/rebuild-cache.txt"; $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = @file_get_contents($pidfile); if ($pid < 100) { $pid = null; } $unix = new unix(); $sock = new sockets(); if ($unix->process_exists($pid, basename(__FILE__))) { ouputz("Already process exists {$pid}, aborting", __LINE__); build_progress("Already process exists {$pid}, aborting", 110); die; } $mypid = getmypid(); @file_put_contents($pidfile, $mypid); @unlink($logFile); build_progress("Listing caches....", 10); ouputz("Please wait, rebuild caches....", __LINE__); $t = time(); ouputz("Listing caches....", __LINE__); $array = ListCaches(); $mv = $unix->find_program("mv"); $rm = $unix->find_program("rm"); $php5 = $unix->LOCATE_PHP5_BIN(); build_progress(count($array) . " Caches to delete...", 15); ouputz(count($array) . " caches to delete...", __LINE__); if (count($array) == 0) { build_progress("Fatal, unable to list available caches.", 110); ouputz("Fatal, unable to list available caches...", __LINE__); squid_admin_mysql(0, "Fatal, unable to list available caches", null, __FILE__, __LINE__); @unlink("/etc/artica-postfix/squid.lock"); die; } $t = time(); @unlink("/etc/artica-postfix/squid.lock"); @file_put_contents("/etc/artica-postfix/squid.lock", time()); $squidbin = $unix->LOCATE_SQUID_BIN(); if (!is_file($squidbin)) { ouputz("squid, no such binary file", __LINE__); @unlink("/etc/artica-postfix/squid.lock"); return; } build_progress("{stopping_proxy_service}", 20); squid_admin_mysql(1, "Stopping Proxy service in order to rebuild caches", null, __FILE__, __LINE__); ouputz("Stopping squid, please wait...", __LINE__); if (function_exists("debug_backtrace")) { $trace = debug_backtrace(); if (isset($trace[1])) { $sourcefunction = $trace[1]["function"]; $sourceline = $trace[1]["line"]; $executed = "Executed by {$sourcefunction}() line {$sourceline}\nusing argv:{$GLOBALS["ARGVS"]}\n"; } } shell_exec("/etc/init.d/squid stop --force --script=" . basename(__FILE__)); if ($GLOBALS["REPORT"]) { while (list($cache_dir, $ligne) = each($array)) { $DIRARRAY = $unix->DIR_STATUS($cache_dir); $size = $array["SIZE"]; $used = $array["USED"]; $pourc = $array["POURC"]; $mounted = $array["MOUNTED"]; $logs[] = "{$cache_dir} size: {$size}, used:{$used} {$pourc}% mounted on {$mounted}"; } squid_admin_mysql(2, "Report on caches status", @implode("\n", $logs), __FILE__, __LINE__); } reset($array); while (list($cache_dir, $ligne) = each($array)) { build_progress("Checking {$cache_dir}", 30); if (preg_match("#MemBooster#", $cache_dir)) { squid_admin_mysql(1, "Removing cache {$cache_dir}", null, __FILE__, __LINE__); ouputz("Removing {$cache_dir} content...", __LINE__); squid_admin_mysql(2, "Removing cache {$cache_dir} done", null, __FILE__, __LINE__); shell_exec("{$rm} -rf {$cache_dir}/*"); continue; } $DISK_STATUS = $unix->DF_SATUS_K($cache_dir); $DIRECTORY_SIZE = $unix->DIRSIZE_BYTES($cache_dir) / 1024 / 1024; $AIVA = $DISK_STATUS["AIVA"] * 1024; ouputz("Removing {$cache_dir} '{$DIRECTORY_SIZE}'M Available {$AIVA}M", __LINE__); shell_exec("{$rm} -rf {$cache_dir}"); ouputz("re-create {$cache_dir}", __LINE__); squid_admin_mysql(2, "Re-create {$cache_dir}", null, __FILE__, __LINE__); @mkdir($cache_dir, 0755, true); @chown($cache_dir, "squid"); @chgrp($cache_dir, "squid"); } $su = $unix->find_program("su"); $results = array(); build_progress("Create {$cache_dir}", 30); ouputz("Building new caches {$su} -c \"{$squidbin} -z\" squid", __LINE__); exec("{$su} -c \"{$squidbin} -z\" squid 2>&1", $results); while (list($num, $ligne) = each($results)) { ouputz("{$ligne}", __LINE__); } ouputz("Remove lock file...", __LINE__); @unlink("/etc/artica-postfix/squid.lock"); ouputz("Starting squid, please wait...", __LINE__); build_progress("{starting_proxy_service}", 35); if (function_exists("debug_backtrace")) { $trace = debug_backtrace(); if (isset($trace[1])) { $sourcefunction = $trace[1]["function"]; $sourceline = $trace[1]["line"]; $executed = "Executed by {$sourcefunction}() line {$sourceline}\nusing argv:{$GLOBALS["ARGVS"]}\n"; } } squid_admin_mysql(2, "Starting Proxy Service after rebuilding caches", null, __FILE__, __LINE__); shell_exec("{$php5} /usr/share/artica-postfix/exec.squid.watchdog.php --start --script=" . basename(__FILE__)); for ($i = 0; $i < 60; $i++) { $array = $unix->squid_get_cache_infos(); if (count($array) > 0) { break; } ouputz("Waiting {$i}s/60 cache is not ready...", __LINE__); sleep(1); } ouputz("Done... Squid-cache seems to be ready...", __LINE__); $NICE = $unix->EXEC_NICE(); $nohup = $unix->find_program("nohup"); build_progress("Refresh caches infos...", 50); ouputz("Refresh caches information, please wait...", __LINE__); shell_exec("{$php5} /usr/share/artica-postfix/exec.squid.php --cache-infos --force"); if (is_array($cachesRename)) { reset($cachesRename); while (list($index, $cache_dir) = each($cachesRename)) { build_progress("Removing old {$cache_dir}", 60); $cmd = "{$NICE} {$rm} -rf {$cache_dir} >/dev/null 2>&1 &"; squid_admin_mysql(2, "Ask to delete old cache dir {$cache_dir} done", "{$called}", __FILE__, __LINE__); ouputz("Deleting {$cache_dir} {$cmd}", __LINE__); shell_exec($cmd); } } build_progress("{done}", 100); $took = $unix->distanceOfTimeInWords($t, time()); squid_admin_mysql(2, "All Proxy caches was rebuilded took: {$took}", "{$called}", __FILE__, __LINE__); }
function BackupLogsMaxStoragePercent_info() { $BackupMaxDaysDir = trim(@file_get_contents("/etc/artica-postfix/settings/Daemons/BackupMaxDaysDir")); if ($BackupMaxDaysDir == null) { $BackupMaxDaysDir = "/home/logrotate_backup"; } if (!is_dir("{$BackupMaxDaysDir}")) { @mkdir("{$BackupMaxDaysDir}", true); } $unix = new unix(); $DIRPART_INFO = $unix->DIRPART_INFO($BackupMaxDaysDir); $DIRSIZE = $unix->DIRSIZE_BYTES($BackupMaxDaysDir); $DIRPART_INFO["CURSIZE"] = $DIRSIZE; echo "<articadatascgi>" . base64_encode(serialize($DIRPART_INFO)) . "</articadatascgi>"; }
function CACHES_AVG() { $unix = new unix(); $cache_manager = new cache_manager(); $data = $cache_manager->makeQuery("storedir", true); $StoreDir = null; foreach ($data as $ligne) { if (preg_match("#Current Capacity.*?:\\s+(.+?)% used#", $ligne, $re)) { @file_put_contents("{$GLOBALS["BASEDIR"]}/CACHES_AVG", $re[1]); @chmod("{$GLOBALS["BASEDIR"]}/CACHES_AVG", 0777); } if (preg_match("#Store Directory.*?:(.+)#", $ligne, $re)) { $StoreDir = trim($re[1]); continue; } if (preg_match("#Percent Used:\\s+([0-9\\.]+)%#", $ligne, $re)) { if ($StoreDir == null) { continue; } $dats[$StoreDir]["PERC"] = $re[1]; continue; } if (preg_match("#Maximum Size:\\s+([0-9\\.]+)#", $ligne, $re)) { if ($StoreDir == null) { continue; } $dats[$StoreDir]["SIZE"] = $re[1]; continue; } if (preg_match("#Current Size:\\s+([0-9\\.]+)#", $ligne, $re)) { if (isset($dats[$StoreDir]["USED"])) { continue; } if ($GLOBALS["OUTPUT"]) { echo "* * * * * * * * *\nDISK \"{$ligne}\"\nDISK {$StoreDir} Current Size: {$re[1]}\n* * * * * * * * *\n"; } $dats[$StoreDir]["USED"] = $re[1]; continue; } if (preg_match("#Current entries:\\s+([0-9\\.]+)\\s+([0-9\\.]+)%#", $ligne, $re)) { if ($GLOBALS["OUTPUT"]) { echo "* * * * * * * * *\nDISK \"{$ligne}\"\nDISK {$StoreDir} Current entries:{$re[1]} {$re[2]}%\n* * * * * * * * *\n"; } if ($StoreDir == null) { continue; } $dats[$StoreDir]["ENTRIES"] = $re[1]; $dats[$StoreDir]["PERC"] = $re[2]; continue; } if (preg_match("#Filesystem Space in use:\\s+([0-9]+)\\/#", $ligne, $re)) { if ($StoreDir == null) { continue; } if (isset($dats[$StoreDir]["USED"])) { continue; } if ($GLOBALS["OUTPUT"]) { echo "* * * * * * * * *\nDISK \"{$ligne}\"\nDISK (2) {$StoreDir} Current Size: {$re[1]}\n* * * * * * * * *\n"; } $dats[$StoreDir]["USED"] = $re[1]; } } $q = new mysql(); while (list($directory, $arrayStore) = each($dats)) { $arrayStore["USED"] = intval($arrayStore["USED"]); $arrayStore["PERC"] = intval($arrayStore["PERC"]); if ($arrayStore["USED"] == 0 && $arrayStore["PERC"] > 0) { $arrayStore["USED"] = $unix->DIRSIZE_BYTES($directory); } if ($directory == "MEM") { continue; } if ($arrayStore["USED"] == 0) { continue; } $PERC = $arrayStore["PERC"]; $USED = $arrayStore["USED"]; if (preg_match("#\\/home\\/squid\\/cache\\/MemBooster([0-9]+)#", $directory, $re)) { $sql = "UPDATE squid_caches_center SET percentcache='{$PERC}',percenttext='{$PERC}', `usedcache`='{$USED}' WHERE ID={$re[1]}"; echo $sql . "\n"; $q->QUERY_SQL($sql, "artica_backup"); continue; } if ($GLOBALS["VERBOSE"]) { echo "{$directory} -> {$USED} / {$PERC}%\n"; } $sql = "UPDATE squid_caches_center SET percentcache='{$PERC}',percenttext='{$PERC}', `usedcache`='{$USED}' WHERE `cache_dir`='{$directory}'"; echo $sql . "\n"; $q->QUERY_SQL($sql, "artica_backup"); } }
function CleanPercent($BackupMaxDaysDir, $TOTAL_AVAILABLE) { $unix = new unix(); $q = new mysql_storelogs(); $ARRAY = array(); $DIRSIZE = $unix->DIRSIZE_BYTES($BackupMaxDaysDir); $q->events("Remove files in {$BackupMaxDaysDir} " . FormatBytes($DIRSIZE / 1024) . "/" . FormatBytes($TOTAL_AVAILABLE / 1024), __FUNCTION__, __LINE__); $q2 = new mysql(); $results = $q2->QUERY_SQL("SELECT * FROM backuped_logs ORDER BY zDate LIMIT 0,50", "artica_backup"); if (!$q2->ok) { squid_admin_mysql(0, "MySQL error", $q2->mysql_error, __FILE__, __LINE__); return; } while ($ligne = mysql_fetch_assoc($results)) { if (preg_match("#^\\/mnt\\/", $ligne["path"])) { continue; } $filepath = $ligne["path"]; if (!is_file($filepath)) { continue; } $sizeBytes = @filesize($filepath); @unlink($filepath); $DIRSIZE = $DIRSIZE - $sizeBytes; $q->events("Remove {$filepath} (" . FormatBytes($sizeBytes / 1024) . ") New DIR SIZE=" . FormatBytes($DIRSIZE / 1024) . "/" . FormatBytes($TOTAL_AVAILABLE / 1024), __FUNCTION__, __LINE__); if ($DIRSIZE < $TOTAL_AVAILABLE) { break; } } }
function ScanSize() { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $timefile = "/etc/artica-postfix/pids/tests." . __FUNCTION__ . ".time"; $pid = @file_get_contents("{$pidfile}"); if ($unix->process_exists($pid, basename(__FILE__))) { system_admin_events("Already executed PID {$pid}", __FUNCTION__, __FILE__, __LINE__, "freewebs"); die; } @file_put_contents($pidfile, getmypid()); $time = $unix->file_time_min($timefile); if ($time < 15) { system_admin_events("No less than 15mn or delete {$timefile} file", __FUNCTION__, __FILE__, __LINE__, "freewebs"); die; } @unlink($timefile); @file_put_contents($timefile, time()); $t = time(); $q = new mysql(); $sql = "SELECT servername FROM freeweb"; $results = $q->QUERY_SQL($sql, 'artica_backup'); $GLobalSize = 0; if (mysql_num_rows($results) == 0) { return; } $sitesNumber = mysql_num_rows($results); while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) { $free = new freeweb($ligne["servername"]); if ($free->IsGroupWareFromArtica()) { $q->QUERY_SQL("UPDATE freeweb SET DirectorySize=0 WHERE servername='{$ligne["servername"]}'", "artica_backup"); continue; } $free->CheckWorkingDirectory(); if (is_link($free->WORKING_DIRECTORY)) { $free->WORKING_DIRECTORY = @readlink($free->WORKING_DIRECTORY); } if (!is_dir($free->WORKING_DIRECTORY)) { $q->QUERY_SQL("UPDATE freeweb SET DirectorySize=0 WHERE servername='{$ligne["servername"]}'", "artica_backup"); if (!$q->ok) { system_admin_events("{$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "freewebs"); } continue; } $size = $unix->DIRSIZE_BYTES($free->WORKING_DIRECTORY); $GLobalSize = $GLobalSize + $size; if ($GLOBALS["VERBOSE"]) { echo "{$ligne["servername"]} {$size} Bytes\n"; } $q->QUERY_SQL("UPDATE freeweb SET DirectorySize={$size} WHERE servername='{$ligne["servername"]}'", "artica_backup"); if (!$q->ok) { system_admin_events("{$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "freewebs"); } } if ($GLobalSize > 0) { $took = $unix->distanceOfTimeInWords($t, time(), true); $GLobalSize = round($GLobalSize / 1024, 2); $GLobalSize = $GLobalSize / 1000; system_admin_events("{$sitesNumber} web site(s) scanned {$GLobalSize}M took:{$took}", __FUNCTION__, __FILE__, __LINE__, "freewebs"); } }
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)) { apache_admin_mysql(0, "httrack no such binary", null, __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__))) { apache_admin_mysql(1, "Already instance executed", null, __FILE__, __LINE__, "webcopy"); return; } $ini = new Bs_IniHandler(); $sock = new sockets(); $datas = $sock->GET_INFO("ArticaProxySettings"); if (trim($datas) != null) { $ini->loadString($datas); if (!isset($ini->_params["PROXY"]["ArticaProxyServerEnabled"])) { $ini->_params["PROXY"]["ArticaProxyServerEnabled"] = "no"; } $ArticaProxyServerEnabled = $ini->_params["PROXY"]["ArticaProxyServerEnabled"]; $ArticaProxyServerName = $ini->_params["PROXY"]["ArticaProxyServerName"]; $ArticaProxyServerPort = $ini->_params["PROXY"]["ArticaProxyServerPort"]; $ArticaProxyServerUsername = trim($ini->_params["PROXY"]["ArticaProxyServerUsername"]); $ArticaProxyServerUserPassword = $ini->_params["PROXY"]["ArticaProxyServerUserPassword"]; if ($ArticaProxyServerEnabled == 1) { $ArticaProxyServerEnabled = "yes"; } } $PPRoxy = null; $userPP = null; if ($ArticaProxyServerEnabled == "yes") { if ($ArticaProxyServerUsername != null) { $userPP = "{$ArticaProxyServerUsername}:{$ArticaProxyServerUserPassword}@"; } $PPRoxy = " --proxy {$userPP}@{$ArticaProxyServerName}:{$ArticaProxyServerPort}"; } else { $squidbin = $unix->LOCATE_SQUID_BIN(); if (is_file($squidbin)) { $SQUIDEnable = $sock->GET_INFO("SQUIDEnable"); if (!is_numeric($SQUIDEnable)) { $SQUIDEnable = 1; } $SquidMgrListenPort = intval($sock->GET_INFO("SquidMgrListenPort")); $PPRoxy = " --proxy 127.0.0.1:{$SquidMgrListenPort}"; } } $getmypid = getmypid(); @file_put_contents($pidfile, $getmypid); $php = $unix->LOCATE_PHP5_BIN(); $APACHE_USERNAME = $unix->APACHE_SRC_ACCOUNT(); $APACHE_SRC_GROUP = $unix->APACHE_SRC_GROUP(); $q = new mysql(); $nice = EXEC_NICE(); $sql = "SELECT * FROM httrack_sites WHERE enabled=1"; $results = $q->QUERY_SQL($sql, "artica_backup"); if (!$q->ok) { apache_admin_mysql(0, "Fatal: {$q->mysql_error}", null, __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"]}] "; } apache_admin_mysql(2, "Starting executing WebCopy task {$log_exp} pid:{$getmypid}", null, __FILE__, __LINE__, "webcopy"); $dirsizeG = 0; while ($ligne = mysql_fetch_assoc($results)) { if ($OnlyID > 0) { if ($ligne["ID"] != $OnlyID) { continue; } } $t = time(); $count++; $workingdir = $ligne["workingdir"]; $sitename = $ligne["sitename"]; $minrate = $ligne["minrate"]; $maxfilesize = $ligne["maxfilesize"]; $maxsitesize = $ligne["maxsitesize"]; $size = $ligne["size"]; $sizeKB = $size / 1024; $sizeMB = round($sizeKB / 1024, 2); $maxworkingdir = intval($ligne["maxworkingdir"]); if ($maxworkingdir == 0) { $maxworkingdir = 20; } $maxsitesizeMB = $maxsitesize / 1000; if ($maxsitesizeMB > $maxworkingdir) { $maxsitesize = $maxworkingdir * 1000; } if ($sizeMB > $maxworkingdir) { apache_admin_mysql(1, "Skip downloading content of {$sitename} Directory: {$sizeMB}MB reach limit of {$maxworkingdir}MB", null, __FILE__, __LINE__, "webcopy"); continue; } if ($GLOBALS["VERBOSE"]) { echo "Dir: Current size:{$sizeMB}\n"; echo "Dir: Max size:{$maxworkingdir}\n"; } $ResteMB = $maxworkingdir - $sizeMB; $ResteKB = $ResteMB * 1000; if ($maxsitesize > $ResteKB) { $maxsitesize = $ResteKB; } echo "Dir: Max Downloads:{$maxsitesize} KB\n"; $maxfilesize = $maxfilesize * 1000; $maxsitesize = $maxsitesize * 1000; $minrate = $minrate * 1000; $update = null; $resultsCMD = array(); echo "Dir: Max Downloads:{$maxsitesize} Bytes\n"; if (!is_dir($workingdir)) { @mkdir($workingdir, 0755, true); } if (is_file("{$workingdir}/hts-cache")) { $update = " --update"; } apache_admin_mysql(2, "Starting downloading content of {$sitename}/{$minrate}/" . FormatBytes($maxsitesize / 1000), null, __FILE__, __LINE__, "webcopy"); $cmdline = "{$httrack} \"{$sitename}\" --quiet{$update}{$PPRoxy} --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); $dirsizeG = $dirsizeG + $dirsize; $took = $unix->distanceOfTimeInWords($t, time(), true); $dirsizeText = round($dirsize / 1024 / 1000, 2); if ($GLOBALS["VERBOSE"]) { echo "Dir: Current size:{$sizeMB}\n"; echo "Dir: New size....:{$dirsizeText}MB\n"; } apache_admin_mysql(2, "{$sitename} scrapped took {$took} size={$dirsizeText} MB", @implode("\n", $resultsCMD), __FILE__, __LINE__, "webcopy"); $q->QUERY_SQL("UPDATE httrack_sites SET size='{$dirsize}' WHERE ID={$ligne["ID"]}", "artica_backup"); } $took = $unix->distanceOfTimeInWords($t1, time(), true); @chmod($workingdir, 0755); @chmod(dirname($workingdir), 0755); $chown = $unix->find_program("chown"); shell_exec("{$chown} -R {$APACHE_USERNAME}:{$APACHE_SRC_GROUP} {$workingdir}"); @file_put_contents("/etc/artica-postfix/settings/Daemons/HTTRackSize", $dirsizeG); if ($count > 0) { apache_admin_mysql(2, "{$count} web sites scrapped took {$took}", null, __FILE__, __LINE__, "webcopy"); } system("{$php} /usr/share/artica-postfix/exec.syslog-engine.php --apache"); }
function InsertToMysql() { $unix = new unix(); $date_start = $GLOBALS["DATE_START"]; $size = $unix->DIRSIZE_BYTES("{$GLOBALS["MOUNTED_PATH_FINAL"]}"); $date_end = time(); $calculate = $unix->distanceOfTimeInWords($date_start, time()); $zDate = date("Y-m-d H:i:s"); $hostname = $unix->hostname_g(); $sql = "CREATE TABLE IF NOT EXISTS `artica_events`.`cyrus_backup` (\n\t\t\t\t`ID` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY ,\n\t\t\t\t`zDate` DATETIME NOT NULL ,\n\t\t\t\t`hostname` VARCHAR( 128 ) NOT NULL ,\n\t\t\t\t`duration` VARCHAR( 256 ) NOT NULL ,\n\t\t\t\t`directory` BIGINT UNSIGNED,\n\t\t\t\t`size` BIGINT UNSIGNED ,\n\t\t\t\tINDEX ( `zDate` , `directory` , `size` ,`hostname`)\n\t\t\t\t);"; $q->QUERY_SQL($sql, 'artica_events'); $q->QUERY_SQL("INSERT IGNORE INTO `cyrus_backup` (`zDate`,`hostname`,`duration`,`directory`,`size`) VALUES('{$zDate}','{$hostname}','{$calculate}','{$GLOBALS["DIRBYTES"]}','{$size}')", "artica_events"); if (!$q->ok) { cyrus_admin_mysql(0, "{$q->mysql_error}", __FILE__, __LINE__); } $size = $size / 1024; $size = $size / 1024; cyrus_admin_mysql(2, "Cyrus backup: Success {$calculate} in {$GLOBALS["MOUNTED_PATH_FINAL"]}", null, __FILE__, __LINE__); }
function GetTotalSize($aspid = false) { $filecache = "/etc/artica-postfix/settings/Daemons/SystemTotalSize"; $unix = new unix(); if (!$aspid) { $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting Already Artica task running PID {$pid} since {$time}mn\n"; } return; } } $time = $unix->file_time_min($filecache); if (!$GLOBALS["FORCE"]) { if ($time < 1440) { return; } } $sync = $unix->find_program("sync"); shell_exec($sync); $fullsize = 0; reset($GLOBALS["SYSDIRS"]); $GLOBALS["SYSDIRS"]["/opt/articatech"] = true; $GLOBALS["SYSDIRS"]["/opt/squidsql/data"] = true; while (list($directory, $val) = each($GLOBALS["SYSDIRS"])) { if (is_link($directory)) { $directory = readlink($directory); } if (!is_dir($directory)) { continue; } $size = $unix->DIRSIZE_BYTES($directory); $fullsize = $fullsize + $size; } @unlink($filecache); @file_put_contents($filecache, $fullsize); }
function caches_status() { $unix = new unix(); $q = new mysql_squid_builder(); $sql = "SELECT directory,ID FROM nginx_caches"; if (!$q->FIELD_EXISTS("nginx_caches", "CurrentSize")) { $q->QUERY_SQL("ALTER TABLE `nginx_caches` ADD `CurrentSize` BIGINT UNSIGNED DEFAULT '0', ADD INDEX ( `CurrentSize` )"); } $results = $q->QUERY_SQL($sql, 'artica_backup'); if (!$q->ok) { echo $q->mysql_error . "\n------------------------\n{$sql}\n------------------------\n"; build_progress_caches("MySQL error !", 110); return; } $Sum = mysql_num_rows($results); if ($GLOBALS["OUTPUT"]) { echo "{$Sum} caches..\n"; } $c = 0; while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) { $c++; $directorySize = $unix->DIRSIZE_BYTES($ligne["directory"]); $prc = $c / $Sum; $prc = $prc * 100; if ($prc > 90) { $prc = 90; } if ($GLOBALS["OUTPUT"]) { echo "{$ligne["directory"]} {$directorySize}..\n"; } build_progress_caches("{$ligne["directory"]} {$directorySize}", $prc); $q->QUERY_SQL("UPDATE nginx_caches SET CurrentSize='{$directorySize}' WHERE ID='{$ligne["ID"]}'"); if (!$q->ok) { echo $q->mysql_error . "\n"; build_progress_caches("MySQL error !", 110); return; } } build_progress_caches("{done}", 100); }
function DirectorySize() { $unix = new unix(); $pid_path = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__; $timePath = "/etc/artica-postfix/croned.1/" . basename(__FILE__) . "." . __FUNCTION__ . ".time"; $pid = @file_get_contents($pid_path); if (!$GLOBALS["FORCE"]) { if ($unix->process_exists($pid)) { die; } $childpid = posix_getpid(); @file_put_contents($pid_path, $childpid); if (system_is_overloaded()) { if ($GLOBALS["VERBOSE"]) { echo "Overloaded system.\n"; } return; } } $filetim = $unix->file_time_min($timePath); if ($GLOBALS["VERBOSE"]) { echo "Time File: {$timePath} ({$filetim}Mn)\n"; } if (!$GLOBALS["FORCE"]) { if ($filetim < 240) { return; } } $partition_default = $unix->IMAPD_GET("partition-default"); if (is_link($partition_default)) { $partition_default = readlink($partition_default); } @file_put_contents($timePath, time()); if ($GLOBALS["VERBOSE"]) { echo "partition_default = {$partition_default}\n"; } artica_mysql_events("Starting calculate - {$partition_default} - disk size", null, __FILE__, "mailbox"); if (strlen($partition_default) < 3) { return; } if (!is_dir($partition_default)) { return; } $currentsize = $unix->DIRSIZE_BYTES($partition_default) / 1024 / 1024; $PartInfo = $unix->DIRPART_INFO($partition_default); $totalMB = $PartInfo["TOT"]; $totalMB = round($totalMB / 1048576); if ($GLOBALS["VERBOSE"]) { echo "partition_default = {$currentsize}MB/{$totalMB}MB\n"; } $sock = new sockets(); $currentsize = round($currentsize); $sock->SET_INFO("CyrusImapPartitionDefaultSize", $currentsize); $sock->SET_INFO("CyrusImapPartitionDefaultSizeTime", time()); $sock->SET_INFO("CyrusImapPartitionDiskSize", $totalMB); send_email_events("Mailboxes size on your server: {$currentsize} MB", "Mailboxes size on your server: {$currentsize} MB", "mailbox"); if ($partition_default == "/var/spool/cyrus/mail") { $sock->SET_INFO("CyrusImapPartitionDefaultDirSize", $currentsize); return; } $currentsize = $unix->DIRSIZE_BYTES("/var/spool/cyrus/mail") / 1024 / 1024; $sock->SET_INFO("CyrusImapPartitionDefaultDirSize", $currentsize); }
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"); }
function DirectoriesSize() { include_once dirname(__FILE__) . '/ressources/class.mysql.inc'; $f[] = "/var"; $f[] = "/var/log"; $f[] = "/var/log/artica-postfix"; $f[] = "/var/lib"; $f[] = "/var/www"; $f[] = "/usr/share"; $f[] = "/opt"; $unix = new unix(); $q = new mysql(); $q->QUERY_SQL("TRUNCATE TABLE `DirectorySizes`", "artica_events"); $prefix = "INSERT IGNORE INTO DirectorySizes (zmd5,path,size) VALUES "; if ($GLOBALS["OUTPUT"]) { echo "Checking special directories size....Please wait...\n"; } $du = $unix->find_program($du); while (list($num, $directory) = each($f)) { $size = $unix->DIRSIZE_BYTES($directory); $tt = round($size / 1024 / 1000); $md = md5($directory); $sql[] = "('{$md}','{$directory}','{$size}')"; echo "{$directory}... {$tt} MB\n"; $dirs = array(); $dirs = $unix->dirdir($directory); while (list($a, $b) = each($dirs)) { $size = $unix->DIRSIZE_BYTES($a); $tt = round($size / 1024 / 1000); if ($tt > 1) { echo "\t{$a} -> " . round($size / 1024 / 1000) . " MB\n"; } $md = md5($a); $sql[] = "('{$md}','{$a}','{$size}')"; if (count($sql) > 100) { $q->QUERY_SQL($prefix . @implode(",", $sql), "artica_events"); $sql = array(); } } } if (count($sql) > 0) { if ($GLOBALS["OUTPUT"]) { echo "Checking special directories done.. injecting into DirectorySizes table...\n"; } $q->QUERY_SQL($prefix . @implode(",", $sql), "artica_events"); } }
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"); } }
function HyperCacheMirror($JustID = 0) { $unix = new unix(); $httrack = $unix->find_program("httrack"); if (!is_file($httrack)) { if ($GLOBALS["VERBOSE"]) { echo "httrack no such binary\n"; } return; } $q = new mysql_squid_builder(); if (!$q->FIELD_EXISTS("artica_caches_mirror", "ToDelete")) { $sql = "ALTER TABLE `artica_caches_mirror` ADD `ToDelete` SMALLINT(1) NOT NULL DEFAULT '0',ADD INDEX(`ToDelete`)"; $q->QUERY_SQL($sql); if (!$q->ok) { squid_admin_enforce(1, "Fatal: MySQL error", $q->mysql_error, __FILE__, __LINE__); return; } } if (!$q->FIELD_EXISTS("artica_caches_mirror", "RunEvents")) { $sql = "ALTER TABLE `artica_caches_mirror` ADD `RunEvents` TEXT"; $q->QUERY_SQL($sql); if (!$q->ok) { squid_admin_enforce(1, "Fatal: MySQL error", $q->mysql_error, __FILE__, __LINE__); return; } } $nice = EXEC_NICE(); $sql = "SELECT * FROM artica_caches_mirror WHERE enabled=1 AND `ToDelete`=0"; $results = $q->QUERY_SQL($sql); if (!$q->ok) { squid_admin_enforce(1, "Fatal: MySQL error", $q->mysql_error, __FILE__, __LINE__); return; } if (!isset($GLOBALS["HyperCacheStoragePath"])) { $sock = new sockets(); $GLOBALS["HyperCacheStoragePath"] = $sock->GET_INFO("HyperCacheStoragePath"); if ($GLOBALS["HyperCacheStoragePath"] == null) { $GLOBALS["HyperCacheStoragePath"] = "/home/artica/proxy-cache"; } } $t1 = time(); $count = 0; if (mysql_num_rows($results) == 0) { return; } $proxyport = $unix->squid_internal_port(); $HyperCache = new HyperCache(); while ($ligne = mysql_fetch_assoc($results)) { if ($JustID > 0) { if ($ligne["ID"] != $JustID) { events("Scrapping rule ID {$ligne["ID"]} !skipped", 0, 2, __LINE__); continue; } } $t = time(); $count++; $sitename = $ligne["sitename"]; $sitename_path = $HyperCache->HyperCacheUriToHostname($sitename); $workingdir = $GLOBALS["HyperCacheStoragePath"] . "/mirror/{$sitename_path}"; $TimeExec = $ligne["TimeExec"]; $TimeExecLast = $unix->file_time_min("{$workingdir}/TimeExec"); if (!$GLOBALS["FORCE"]) { events("Scrapping {$sitename} require {$TimeExec}mn, current {$TimeExecLast}Mn", 0, 2, __LINE__); if ($TimeExecLast < $TimeExec) { continue; } } events("Scrapping rule ID {$ligne["ID"]} for {$sitename}", 0, 2, __LINE__); $minrate = $ligne["minrate"]; $maxfilesize = $ligne["maxfilesize"]; $maxsitesize = $ligne["maxsitesize"]; $maxfilesize = $maxfilesize * 1000; $maxsitesize = $maxsitesize * 1000; $minrate = $minrate * 1000; $update = null; $resultsCMD = array(); $pidpath = "{$GLOBALS["HyperCacheStoragePath"]}/mirror/{$sitename_path}/hts-in_progress.lock"; if (!is_dir($workingdir)) { @mkdir($workingdir, 0755, true); } @chown("{$GLOBALS["HyperCacheStoragePath"]}/mirror", "squid"); @chgrp("{$GLOBALS["HyperCacheStoragePath"]}/mirror", "squid"); @chown("{$GLOBALS["HyperCacheStoragePath"]}/mirror/{$sitename_path}", "squid"); @chgrp("{$GLOBALS["HyperCacheStoragePath"]}/mirror/{$sitename_path}", "squid"); if (is_file($pidpath)) { $PID = HyperCacheMirror_pid($pidpath); if ($unix->process_exists($PID)) { events("Scrapping rule ID {$ligne["ID"]} for {$sitename} Process {$PID} already running since " . $unix->PROCESS_TIME_INT($PID), 0, 2, __LINE__); continue; } } @file_put_contents("{$workingdir}/TimeExec", time()); if (is_file("{$workingdir}/hts-cache")) { $update = " --update"; } $cmdline = array(); $cmdline[] = "{$httrack} \"{$sitename}\" --quiet{$update} -%U squid --proxy 127.0.0.1:{$proxyport}"; $cmdline[] = "--stay-on-same-domain -u2 -C1 -I0 -N100 --robots=0 --max-files={$maxfilesize}"; $cmdline[] = "--max-size={$maxsitesize}"; $cmdline[] = "-O \"{$workingdir}\" 2>&1"; squid_admin_enforce(2, "Scrapping {$sitename} using proxy 127.0.0.1:{$proxyport}...", null, __FILE__, __LINE__); $cmd = @implode(" ", $cmdline); if ($GLOBALS["VERBOSE"]) { echo "{$cmd}\n"; } exec($cmd, $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); squid_admin_enforce(2, "Mirror on {$sitename} done took {$took} size={$dirsizeText} MB", null, __FILE__, __LINE__); $logs = mysql_escape_string2(@file_get_contents("{$workingdir}/hts-log.txt")); $q->QUERY_SQL("UPDATE artica_caches_mirror SET \n\t\t\t\tsize='{$dirsize}',`RunEvents`='{$logs}' WHERE ID={$ligne["ID"]}", "artica_backup"); if (!$q->ok) { squid_admin_enforce(1, "MySQL error", $q->mysql_error, __FILE__, __LINE__); } } $took = $unix->distanceOfTimeInWords($t1, time(), true); squid_admin_enforce(2, "{$count} web site(s) scrapped took {$took}", null, __FILE__, __LINE__); }
function databasesize($force = false) { $unix = new unix(); $sock = new sockets(); $arrayfile = "/usr/share/artica-postfix/ressources/logs/web/{$GLOBALS["SERV_NAME"]}.size.db"; $pidfile = "/etc/artica-postfix/pids/{$GLOBALS["SERV_NAME"]}-databasesize.pid"; if (!$force) { $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); return; } @file_put_contents($pidfile, getmypid()); $time = $unix->file_time_min($arrayfile); if ($time < 20) { return; } } $ArticaDBPath = "/home/artica/categories_databases"; $GLOBALS["WORKDIR"] = $ArticaDBPath; $dir = $GLOBALS["WORKDIR"]; if (is_link($dir)) { $dir = readlink($dir); } $unix = new unix(); $sizbytes = $unix->DIRSIZE_BYTES($dir); $dir = $unix->shellEscapeChars($dir); $df = $unix->find_program("df"); $array["DBSIZE"] = $sizbytes / 1024; exec("{$df} -B K {$dir} 2>&1", $results); while (list($num, $ligne) = each($results)) { if (preg_match("#^.*?\\s+([0-9A-Z\\.]+)K\\s+([0-9A-Z\\.]+)K\\s+([0-9A-Z\\.]+)K\\s+([0-9\\.]+)%\\s+(.+)#", $ligne, $re)) { $array["SIZE"] = $re[1]; $array["USED"] = $re[2]; $array["AIVA"] = $re[3]; $array["POURC"] = $re[4]; $array["MOUNTED"] = $re[5]; break; } } $results = array(); exec("{$df} -i {$dir} 2>&1", $results); while (list($num, $ligne) = each($results)) { if (preg_match("#^.*?\\s+([0-9A-Z\\.]+)\\s+([0-9A-Z\\.]+)\\s+([0-9A-Z\\.]+)\\s+([0-9\\.]+)%\\s+(.+)#", $ligne, $re)) { $array["ISIZE"] = $re[1]; $array["IUSED"] = $re[2]; $array["IAIVA"] = $re[3]; $array["IPOURC"] = $re[4]; break; } } if ($GLOBALS["VERBOSE"]) { print_r($array); } @unlink($arrayfile); @file_put_contents($arrayfile, serialize($array)); if ($GLOBALS["VERBOSE"]) { echo "Saving {$arrayfile}...\n"; } @chmod($arrayfile, 0755); }
function databasesize($force = false) { $unix = new unix(); $arrayfile = "/usr/share/artica-postfix/ressources/logs/web/squiddb.size.db"; if (!$force) { $pidfile = "/etc/artica-postfix/pids/squid-databasesize.pid"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); return; } @file_put_contents($pidfile, getmypid()); $time = $unix->file_time_min($arrayfile); if ($time < 20) { return; } } $sock = new sockets(); $WORKDIR = $sock->GET_INFO("SquidStatsDatabasePath"); if ($WORKDIR == null) { $WORKDIR = "/opt/squidsql"; } if (!is_dir($WORKDIR)) { @mkdir($WORKDIR, 0755, true); } $dir = $WORKDIR; if (is_link($dir)) { $dir = readlink($dir); } $unix = new unix(); $sizbytes = $unix->DIRSIZE_BYTES($dir); $dir = $unix->shellEscapeChars($dir); $df = $unix->find_program("df"); $array["DBSIZE"] = $sizbytes / 1024; exec("{$df} -B K {$dir} 2>&1", $results); while (list($num, $ligne) = each($results)) { if (preg_match("#^.*?\\s+([0-9A-Z\\.]+)K\\s+([0-9A-Z\\.]+)K\\s+([0-9A-Z\\.]+)K\\s+([0-9\\.]+)%\\s+(.+)#", $ligne, $re)) { $array["SIZE"] = $re[1]; $array["USED"] = $re[2]; $array["AIVA"] = $re[3]; $array["POURC"] = $re[4]; $array["MOUNTED"] = $re[5]; break; } } $results = array(); exec("{$df} -i {$dir} 2>&1", $results); while (list($num, $ligne) = each($results)) { if (preg_match("#^.*?\\s+([0-9A-Z\\.]+)\\s+([0-9A-Z\\.]+)\\s+([0-9A-Z\\.]+)\\s+([0-9\\.]+)%\\s+(.+)#", $ligne, $re)) { $array["ISIZE"] = $re[1]; $array["IUSED"] = $re[2]; $array["IAIVA"] = $re[3]; $array["IPOURC"] = $re[4]; break; } } if ($GLOBALS["VERBOSE"]) { print_r($array); } @unlink($arrayfile); $q = new mysql_squid_builder(); $TABLES_NUMBER = $q->COUNT_ALL_TABLES(); $array["TABLES_NUMBER"] = $TABLES_NUMBER; @file_put_contents($arrayfile, serialize($array)); if ($GLOBALS["VERBOSE"]) { echo "Saving {$arrayfile}...\n"; } @chmod($arrayfile, 0755); }
function ufdguard_artica_db_status() { $unix = new unix(); $mainpath = "/var/lib/ufdbartica"; $mainpath_size = $unix->DIRSIZE_BYTES($mainpath); $array["SIZE"] = $mainpath_size; if (is_file("{$mainpath}/category_porn/domains.ufdb")) { $date = filemtime("{$mainpath}/category_porn/domains.ufdb"); $array["DATE"] = $date; } else { $array["DATE"] = 0; } @file_put_contents("/etc/artica-postfix/ARTICA_WEBFILTER_DB_STATUS", serialize($array)); }
function UpdateUtilitySize($force = false) { $unix = new unix(); $arrayfile = "/usr/share/artica-postfix/ressources/logs/web/UpdateUtilitySize.size.db"; $pidfile = "/etc/artica-postfix/pids/UpdateUtilitySize.pid"; if (!$force) { $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); return; } @file_put_contents($pidfile, getmypid()); $time = $unix->file_time_min($arrayfile); if ($time < 20) { return; } } $sock = new sockets(); $dir = $sock->GET_INFO("UpdateUtilityStorePath"); if ($dir == null) { $dir = "/home/kaspersky/UpdateUtility"; } $UpdateUtilityUseLoop = $sock->GET_INFO("UpdateUtilityUseLoop"); if (!is_numeric($UpdateUtilityUseLoop)) { $UpdateUtilityUseLoop = 0; } if ($UpdateUtilityUseLoop == 1) { $dir = "/automounts/UpdateUtility"; } if (is_link($dir)) { $dir = readlink($dir); } $unix = new unix(); $sizbytes = $unix->DIRSIZE_BYTES($dir); $dir = $unix->shellEscapeChars($dir); $df = $unix->find_program("df"); $array["DBSIZE"] = $sizbytes / 1024; exec("{$df} -B K {$dir} 2>&1", $results); while (list($num, $ligne) = each($results)) { if (preg_match("#^.*?\\s+([0-9A-Z\\.]+)K\\s+([0-9A-Z\\.]+)K\\s+([0-9A-Z\\.]+)K\\s+([0-9\\.]+)%\\s+(.+)#", $ligne, $re)) { $array["SIZE"] = $re[1]; $array["USED"] = $re[2]; $array["AIVA"] = $re[3]; $array["POURC"] = $re[4]; $array["MOUNTED"] = $re[5]; break; } } $results = array(); exec("{$df} -i {$dir} 2>&1", $results); while (list($num, $ligne) = each($results)) { if (preg_match("#^.*?\\s+([0-9A-Z\\.]+)\\s+([0-9A-Z\\.]+)\\s+([0-9A-Z\\.]+)\\s+([0-9\\.]+)%\\s+(.+)#", $ligne, $re)) { $array["ISIZE"] = $re[1]; $array["IUSED"] = $re[2]; $array["IAIVA"] = $re[3]; $array["IPOURC"] = $re[4]; break; } } if ($GLOBALS["VERBOSE"]) { print_r($array); } @unlink($arrayfile); @file_put_contents($arrayfile, serialize($array)); if ($GLOBALS["VERBOSE"]) { echo "Saving {$arrayfile}...\n"; } @chmod($arrayfile, 0755); }
function Scan_mysql_dirs() { $GLOBALS["INDEXED"] = 0; $GLOBALS["SKIPPED"] = 0; $GLOBALS["DIRS"] = array(); $unix = new unix(); $GLOBALS["omindex"] = $unix->find_program("omindex"); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid)) { system_admin_events("Already instance executed pid:{$olpid}", __FUNCTION__, __FILE__, __LINE__, "xapian"); die; } @file_put_contents($pidfile, getmypid()); $q = new mysql(); $q->check_storage_table(true); $localdatabase = "/usr/share/artica-postfix/LocalDatabases"; $nice = EXEC_NICE(); $sql = "SELECT * FROM xapian_folders"; $results = $q->QUERY_SQL($sql, "artica_backup"); if (!$q->ok) { system_admin_events("{$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "xapian"); return; } $t1 = time(); if (!is_file($GLOBALS["omindex"])) { system_admin_events("omindex no such binary, aborting", __FUNCTION__, __FILE__, __LINE__, "xapian"); return; } $autofs = new autofs(); $autofs->automounts_Browse(); $count = 0; while ($ligne = mysql_fetch_assoc($results)) { $directory = $ligne["directory"]; $database = "{$localdatabase}/samba." . md5($directory) . ".db"; $depth = $ligne["depth"]; $maxsize = $ligne["maxsize"]; $samplsize = $ligne["sample-size"]; $lang = $ligne["lang"]; $WebCopyID = $ligne["WebCopyID"]; $autmountdn = $ligne["autmountdn"]; if ($lang == null) { $lang = "english"; } $indexed = $ligne["indexed"]; if (!is_numeric($samplsize)) { $samplsize = 512; } if (!is_numeric($maxsize)) { $maxsize = 60; } if (!is_numeric($depth)) { $depth = 0; } $BaseUrl = $directory; if ($WebCopyID > 0) { $directory = WebCopyIDDirectory($WebCopyID); $BaseUrl = WebCopyIDAddresses($WebCopyID) . "/"; } if ($autmountdn != null) { if (!isset($autofs->hash_by_dn[$autmountdn])) { system_admin_events("Fatal.. {$autmountdn} no such connection", __FUNCTION__, __FILE__, __LINE__, "xapian"); continue; } $autmountdn_array = $autofs->hash_by_dn[$autmountdn]; $directory = "/automounts/{$autmountdn_array["FOLDER"]}"; $autmountdn_infos = $autmountdn_array["INFOS"]; if (!isset($autmountdn_infos["BROWSER_URI"])) { system_admin_events("Fatal.. {$autmountdn} external protocol error", __FUNCTION__, __FILE__, __LINE__, "xapian"); continue; } $BaseUrl = $autmountdn_infos["BROWSER_URI"]; } if (!is_dir($database)) { @mkdir($database, 0755, true); } if (!is_dir($directory)) { system_admin_events("{$directory}, no such directory", __FUNCTION__, __FILE__, __LINE__, "xapian"); continue; } $t = time(); $cmd = "{$nice}{$GLOBALS["omindex"]} -l {$depth} -s {$lang} -E {$samplsize} -m {$maxsize}M --follow -D \"{$database}\" -U \"{$BaseUrl}\" \"{$directory}\" 2>&1"; if ($GLOBALS["VERBOSE"]) { echo "{$cmd}\n"; } $GLOBALS["DIRS"]["{$directory}"] = true; $results_scan = array(); exec($cmd, $results_scan); $dirRes = ParseLogs($results_scan); $took = $unix->distanceOfTimeInWords($t, time(), true); $DatabaseSize = $unix->DIRSIZE_BYTES($database); $count++; $indexed = $indexed + $dirRes[0]; system_admin_events("scanned {$directory} took {$took} indexed:{$indexed} skipped:{$dirRes[1]}", __FUNCTION__, __FILE__, __LINE__, "xapian"); $q->QUERY_SQL("UPDATE xapian_folders SET ScannedTime=NOW(),indexed={$indexed},DatabasePath='{$database}',DatabaseSize='{$DatabaseSize}'\n\t\n\t\tWHERE ID={$ligne["ID"]}", "artica_backup"); if (!$q->ok) { system_admin_events("{$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "xapian"); } } $took = $unix->distanceOfTimeInWords($t1, time(), true); system_admin_events("scanned {$count} directorie(s) took {$took}", __FUNCTION__, __FILE__, __LINE__, "xapian"); }