Ejemplo n.º 1
1
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);
}
Ejemplo n.º 2
0
function UsersSizeByHour()
{
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid";
    $pidtime = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".time";
    $pid = @file_get_contents($pidfile);
    if (systemMaxOverloaded()) {
        events("UsersSizeByHour:: systemMaxOverloaded {$GLOBALS["SYSTEM_INTERNAL_LOAD"]} !!! -> DIE", __LINE__);
        return;
    }
    $unix = new unix();
    $mypid = getmypid();
    if ($unix->process_exists($pid, basename(__FILE__))) {
        if ($pid != $mypid) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            events("Already executed pid {$pid} since {$time}mn-> DIE");
            if ($GLOBALS["VERBOSE"]) {
                echo "Already executed pid {$pid} since {$time}mn\n";
            }
            die;
        }
    }
    events("Starting pid [{$mypid}]...");
    @file_put_contents($pidfile, $mypid);
    $timefile = $unix->file_time_min($pidtime);
    events("Timelock:{$timefile} Mn");
    if (!$GLOBALS["VERBOSE"]) {
        if ($timefile < 10) {
            events("Only each 10mn :current {$timefile}Mn");
            if ($GLOBALS["VERBOSE"]) {
                echo "Only each 10mn\n";
            }
            return;
        }
    }
    @unlink($pidtime);
    @file_put_contents($pidtime, time());
    // VF /var/log/artica-postfix/squid/queues/RTTSize;
    $q = new mysql_squid_builder();
    $q->CreateUserSizeRTTTable();
    $RTTSIZEPATH = "/var/log/artica-postfix/squid-RTTSize/" . date("YmdH");
    if (!is_file($RTTSIZEPATH)) {
        events("{$RTTSIZEPATH} no such file...");
        events("UserSizeRTT_oldfiles()");
        UserSizeRTT_oldfiles();
        events("main_table()");
        main_table();
        return;
    }
    if (!$q->TABLE_EXISTS("UserSizeRTT")) {
        events("Fatal UserSizeRTT no such table, die()");
        ufdbguard_admin_events("Fatal UserSizeRTT no such table, die();", __FUNCTION__, __FILE__, __LINE__, "stats");
        return;
    }
    events("{$RTTSIZEPATH} = " . FormatBytes(@filesize($RTTSIZEPATH) / 1024));
    $RTTSIZEARRAY = unserialize(@file_get_contents($RTTSIZEPATH));
    RTTSizeArray($RTTSIZEARRAY);
    //$prefix="INSERT IGNORE INTO UserSizeRTT (`zMD5`,`uid`,`zdate`,`ipaddr`,`hostname`,`account`,`MAC`,`UserAgent`,`size`) VALUES";
    //if($mac==null){$mac=$this->GetMacFromIP($ip);}
}
Ejemplo n.º 3
0
function ParseLogsDir()
{
    $d = 0;
    $h = 0;
    $sock = new sockets();
    $workingDir = $sock->GET_INFO("SquidOldLogsDefaultDir");
    if (!($handle = opendir($workingDir))) {
        @mkdir($workingDir, 0755, true);
        return;
    }
    $squidtail = new squid_tail();
    while (false !== ($filename = readdir($handle))) {
        if ($filename == ".") {
            continue;
        }
        if ($filename == "..") {
            continue;
        }
        $targetFile = "{$workingDir}/{$filename}";
        if (!is_file($targetFile)) {
            continue;
        }
        $d++;
        $h++;
        $c = 0;
        if ($d > 300) {
            if (systemMaxOverloaded()) {
                $array_load = sys_getloadavg();
                $internal_load = $array_load[0];
                events("ParseSquidLogBrutProcess()::{$workingDir}:: Overloaded: {$internal_load} system, break loop...", __LINE__);
                break;
            }
            $d = 0;
        }
        $handle = @fopen($targetFile, "r");
        if (!$handle) {
            events("Failed to open file", __LINE__);
            continue;
        }
        while (!feof($handle)) {
            $c++;
            $buffer = trim(fgets($handle, 4096));
            if (!$squidtail->parse_tail($buffer, null)) {
                continue;
            }
        }
    }
}
Ejemplo n.º 4
0
    ini_set('error_prepend_string', null);
    ini_set('error_append_string', null);
}
include_once dirname(__FILE__) . '/ressources/class.templates.inc';
include_once dirname(__FILE__) . '/ressources/class.ldap.inc';
include_once dirname(__FILE__) . '/ressources/class.amavis.inc';
include_once dirname(__FILE__) . '/framework/class.unix.inc';
include_once dirname(__FILE__) . '/framework/frame.class.inc';
if (posix_getuid() != 0) {
    die("Cannot be used in web server mode\n\n");
}
if ($argv[1] = "--spamass-milter") {
    CheckSpamassassinMilter();
    die;
}
if (systemMaxOverloaded()) {
    writelogs("This system is too many overloaded, die()", __FUNCTION__, __FILE__, __LINE__);
    die;
}
$sock = new sockets();
$EnablePolicydWeight = $sock->GET_INFO('EnablePolicydWeight');
if ($EnablePolicydWeight != 1) {
    RemovePolicydWeight();
} else {
    EnablePolicyd();
}
CheckSpamassassinMilter();
CheckCLamavMilter();
CheckAmavis();
die;
function EnablePolicyd()
Ejemplo n.º 5
0
function __re_categorize_subtables($oldT1 = 0)
{
    $unix = new unix();
    if (systemMaxOverloaded()) {
        writelogs_squid("Fatal: VERY Overloaded system, die();", __FUNCTION__, __FILE__, __LINE__, "stats");
        return;
    }
    $sock = new sockets();
    $RecategorizeSecondsToWaitOverload = $sock->GET_INFO("RecategorizeSecondsToWaitOverload");
    $RecategorizeMaxExecutionTime = $sock->GET_INFO("RecategorizeSecondsToWaitOverload");
    if (!is_numeric($RecategorizeSecondsToWaitOverload)) {
        $RecategorizeSecondsToWaitOverload = 30;
    }
    if (!is_numeric($RecategorizeMaxExecutionTime)) {
        $RecategorizeMaxExecutionTime = 210;
    }
    if ($oldT1 > 1) {
        $t = $oldT1;
    } else {
        $t = time();
    }
    $tables_days = $GLOBALS["Q"]->LIST_TABLES_DAYS();
    $tables_hours = $GLOBALS["Q"]->LIST_TABLES_HOURS();
    $sql = "SELECT * FROM visited_sites";
    $results = $GLOBALS["Q"]->QUERY_SQL($sql);
    $num_rows = mysql_num_rows($results);
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $website = trim($ligne["sitename"]);
        $category = trim($ligne["category"]);
        if ($website == null) {
            continue;
        }
        if ($category == null) {
            continue;
        }
        reset($tables_days);
        reset($tables_hours);
        while (list($num, $tablename) = each($tables_days)) {
            $category = addslashes($category);
            $GLOBALS["Q"]->QUERY_SQL("UPDATE {$tablename} SET category='{$category}' WHERE sitename='{$website}'");
            if (!$GLOBALS["Q"]->ok) {
                writelogs_squid("Fatal: mysql error on table {$tablename} {$GLOBALS["Q"]->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "stats");
                return;
            }
        }
        while (list($num, $tablename) = each($tables_hours)) {
            $category = addslashes($category);
            $GLOBALS["Q"]->QUERY_SQL("UPDATE {$tablename} SET category='{$category}' WHERE sitename='{$website}'");
            if (!$GLOBALS["Q"]->ok) {
                writelogs_squid("Fatal: mysql error on table {$tablename} {$GLOBALS["Q"]->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "stats");
                return;
            }
        }
        if (system_is_overloaded(__FILE__)) {
            writelogs_squid("Fatal: Overloaded system, sleeping {$RecategorizeSecondsToWaitOverload} secondes...", __FUNCTION__, __FILE__, __LINE__, "stats");
            sleep($RecategorizeSecondsToWaitOverload);
        }
        if (systemMaxOverloaded()) {
            writelogs_squid("Fatal: VERY Overloaded system, die();", __FUNCTION__, __FILE__, __LINE__, "stats");
            return;
        }
        $distanceInSeconds = round(abs(time() - $t));
        $distanceInMinutes = round($distanceInSeconds / 60);
        if ($distanceInMinutes > $RecategorizeMaxExecutionTime) {
            $took = $unix->distanceOfTimeInWords($t, time());
            writelogs_squid("Re-categorized websites task aborted (Max execution time {$RecategorizeMaxExecutionTime}Mn) ({$took})", __FUNCTION__, __FILE__, __LINE__, "stats");
            return;
        }
    }
    $took = $unix->distanceOfTimeInWords($t, time());
    writelogs_squid("{$num_rows} re-categorized  websites updated in " . count($tables_days) . " day tables, " . count($tables_hours) . " hours tables, ({$took})", __FUNCTION__, __FILE__, __LINE__, "stats");
}
function ParseSquidLogMain()
{
    if (systemMaxOverloaded()) {
        return;
    }
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pid = @file_get_contents($pidfile);
    if ($pid < 100) {
        $pid = null;
    }
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        events("ParseSquidLogBrutProcess:: Already executed pid {$pid} since {$time}mn-> DIE", __LINE__);
        if ($GLOBALS["VERBOSE"]) {
            echo "Already executed pid {$pid} since {$time}mn\n";
        }
        die;
    }
    $WORKDIR = "/var/log/artica-postfix/dansguardian-stats2";
    $dirs = $unix->dirdir($WORKDIR);
    $php5 = $unix->LOCATE_PHP5_BIN();
    $nice = EXEC_NICE();
    $nohup = $unix->find_program("nohup");
    while (list($dir, $val) = each($dirs)) {
        $basename = basename($dir);
        if ($basename == "--verbose") {
            continue;
        }
        $pidfile = "/etc/artica-postfix/pids/squidMysqllogs.{$basename}.lock.pid";
        $pid = @file_get_contents($pidfile);
        $filesCount = $unix->COUNT_FILES($dir);
        events_brut("ParseSquidLogMain:: {$filesCount} files, {$basename}: {$pidfile} PID:{$pid} ");
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $MNS = $unix->PROCCESS_TIME_MIN($pid);
            events_brut("ParseSquidLogMain:: {$basename}: {$filesCount} files, Already process running pid: {$pid} since {$MNS}mn");
            continue;
        }
        $Procs = ParseSquidLogMainProcessCount("squid-sql-proc", $basename);
        if ($Procs > 0) {
            $MNS = $unix->PROCCESS_TIME_MIN($pid);
            events_brut("ParseSquidLogMain:: {$Procs} processe(s) already in memory");
            continue;
        }
        $cmd = "{$nohup} {$php5} " . __FILE__ . " --squid-sql-proc {$basename} >/dev/null 2>&1 &";
        events_brut("ParseSquidLogMain:: {$filesCount} files Fork for {$basename} sub-dir", __LINE__);
        shell_exec($cmd);
    }
    $filesCount = $unix->COUNT_FILES($WORKDIR);
    $pidfile = "/etc/artica-postfix/pids/squidMysqllogs.lock.pid";
    $pid = @file_get_contents($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $MNS = $unix->PROCCESS_TIME_MIN($pid);
        events_brut("ParseSquidLogMain:: NULL: {$filesCount} files Already process running pid: {$pid} since {$MNS}mn");
    } else {
        $cmd = "{$nohup} {$php5} " . __FILE__ . " --squid-sql-proc >/dev/null 2>&1 &";
        events_brut("ParseSquidLogMain:: {$filesCount} files, Fork for NULL DIR", __LINE__);
        shell_exec($cmd);
    }
}
Ejemplo n.º 7
0
function launch_all_status($force=false){
	
	xLoadAvg();
	
	$trace=debug_backtrace();if(isset($trace[1])){$called=" called by ". basename($trace[1]["file"])." {$trace[1]["function"]}() line {$trace[1]["line"]}";events("$called",__FUNCTION__,__LINE__);}	

	CheckCallable();
	if(!is_file("/usr/share/artica-postfix/ressources/logs/global.versions.conf")){
		events("-> artica-install --write-version",__FUNCTION__,__LINE__);
		$GLOBALS["CLASS_UNIX"]->THREAD_COMMAND_SET("/usr/share/artica-postfix/bin/artica-install --write-versions");
	}else{
		$filetime=file_time_min("/usr/share/artica-postfix/ressources/logs/global.versions.conf");
		events("global.versions.conf={$filetime}mn ",__FUNCTION__,__LINE__);
		if($filetime>60){
			events("global.versions.conf \"$filetime\"mn",__FUNCTION__,__LINE__);
			@unlink("/usr/share/artica-postfix/ressources/logs/global.versions.conf");
			$GLOBALS["CLASS_UNIX"]->THREAD_COMMAND_SET("/usr/share/artica-postfix/bin/artica-install --write-versions");
		}
	}
	
	@unlink($GLOBALS["MY-POINTER"]);
	@file_put_contents($GLOBALS["MY-POINTER"],time());
	
	$functions=array("squid_master_status","c_icap_master_status","kav4Proxy_status","dansguardian_master_status","wpa_supplicant","fetchmail","milter_greylist",
	"framework","pdns_server","pdns_recursor","cyrus_imap","mysql_server","mysql_mgmt","mysql_replica","openldap","saslauthd","syslogger","squid_tail","amavis",
	"amavis_milter","boa","lighttpd","fcron1","fcron2","clamd","clamscan","clammilter","freshclam","retranslator_httpd","spamassassin_milter","spamassassin",
	"postfix","postfix_logger","mailman","kas3_milter","kas3_ap","smbd","nmbd","winbindd","scanned_only","roundcube","cups","apache-groupware","apache_groupware",
	"gdm","console-kit","xfce","vmtools","hamachi","artica_notifier","dhcpd_server","pure_ftpd","mldonkey","policyd_weight","backuppc","kav4fs","kav4fsavs",
	"apache_ocsweb","web_download","ocs_agent","openssh","gluster","auditd","squidguardweb","opendkim","ufdbguardd","squidguard_logger","milter_dkim","dropbox",
	"artica_policy","virtualbox_webserv","tftpd","dhcpd_server","crossroads","artica_status","artica_executor","artica_background","bandwith",
	 "pptpd","pptp_clients","apt_mirror","squid_clamav_tail","ddclient","cluebringer","apachesrc","zarafa_web","zarafa_ical","zarafa_dagent","zarafa_indexer",
	"zarafa_monitor","zarafa_gateway","zarafa_spooler","zarafa_server","assp","openvpn","vboxguest","sabnzbdplus","SwapWatchdog","artica_meta_scheduler",
	"OpenVPNClientsStatus","stunnel","meta_checks","zarafa_licensed","CheckCurl","ufdbguardd_tail","vnstat","NetAdsWatchdog","munin","autofs","greyhole",
	"dnsmasq","iscsi","watchdog_yorel","postfwd2","vps_servers","smartd","crossroads_multiple","auth_tail","greyhole_watchdog","greensql"
	);
	$data1=$GLOBALS["TIME_CLASS"];
	$data2 = time();
	$difference = ($data2 - $data1); 	 
	$min=round($difference/60);	
	if($min>9){
		events("reloading classes...",__FUNCTION__,__LINE__);
		$GLOBALS["TIME_CLASS"]=time();
		$GLOBALS["CLASS_SOCKETS"]=new sockets();
		$GLOBALS["CLASS_USERS"]=new settings_inc();
		$GLOBALS["CLASS_UNIX"]=new unix();		
	} 
	
	
	
	while (list ($num, $func) = each ($functions) ){
		if(function_exists($func)){
			$mem=round(((memory_get_usage()/1024)/1000),2);
			events("running function \"$func\" {$mem}MB in memory",__FUNCTION__,__LINE__);
			if(!$force){
				if(system_is_overloaded()){
					events("System is overloaded: {$GLOBALS["SYSTEM_INTERNAL_LOAD"]}, pause 2 seconds",__FUNCTION__,__LINE__);
					AmavisWatchdog();
					greyhole_watchdog();
					sleep(2);
					return;
				}else{
					if(systemMaxOverloaded()){
					events("System is very overloaded {$GLOBALS["SYSTEM_INTERNAL_LOAD"]}, pause 5  seconds",__FUNCTION__,__LINE__);
					AmavisWatchdog();
					greyhole_watchdog();
					sleep(5);
					return;
					}
				}
			}
			
			try {
				$results=call_user_func($func);
			} catch (Exception $e) {
				writelogs("Fatal while running function $func ($e)",__FUNCTION__,__FILE__,__LINE__);
			}
			
			if(trim($results)<>null){$conf[]=$results;}
		}
	}
	
@unlink("/usr/share/artica-postfix/ressources/logs/global.status.ini");
file_put_contents("/usr/share/artica-postfix/ressources/logs/global.status.ini",@implode("\n",$conf));
@chmod(770,"/usr/share/artica-postfix/ressources/logs/global.status.ini");
@file_put_contents("/etc/artica-postfix/cache.global.status",@implode("\n",$conf));	
events("creating status done ". count($conf)." lines....",__FUNCTION__,__LINE__);
}
Ejemplo n.º 8
0
function WATCHDOG($APP_NAME, $cmd)
{
    if ($GLOBALS["DISABLE_WATCHDOG"]) {
        return null;
    }
    if (!isset($GLOBALS["ArticaWatchDogList"][$APP_NAME])) {
        $GLOBALS["ArticaWatchDogList"][$APP_NAME] = 1;
    }
    if ($GLOBALS["ArticaWatchDogList"][$APP_NAME] == null) {
        $GLOBALS["ArticaWatchDogList"][$APP_NAME] = 1;
    }
    if (systemMaxOverloaded(basename(__FILE__))) {
        $array_load = sys_getloadavg();
        $internal_load = $array_load[0];
        $GLOBALS["CLASS_UNIX"]->send_email_events("Artica Watchdog start {$APP_NAME} is not performed (load {$internal_load})", "System is very overloaded ({$internal_load}) all watchdog tasks are stopped and waiting a better time!", "system");
        return;
    }
    if ($GLOBALS["ArticaWatchDogList"][$APP_NAME] == 1) {
        $cmd = "{$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} " . dirname(__FILE__) . "/exec.watchdog.php --start-process \"{$APP_NAME}\" \"{$cmd}\" >/dev/null 2>&1 &";
        events("WATCHDOG: running {$APP_NAME} ({$cmd})", basename(__FILE__));
        shell_exec($cmd);
    }
}
Ejemplo n.º 9
0
function status()
{
    if (systemMaxOverloaded()) {
        return;
    }
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pidTime = "/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 "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($pidTime);
        if ($time < 60) {
            return;
        }
    }
    @unlink($pidTime);
    @file_get_contents($pidTime, time());
    $q = new mysql_squid_builder();
    $sql = "SELECT * FROM haarp_caches";
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        return;
    }
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $directory = trim($ligne["directory"]);
        $ID = $ligne["ID"];
        @mkdir("{$directory}", 0755, true);
        if (substr($directory, strlen($directory) - 1, 1) != "/") {
            $directory = $directory . "/";
        }
        $dir[$ID] = $directory;
    }
    if (count($dir) == 0) {
        @mkdir("/home/haarp-1", 0755, true);
        $dir[1] = "/home/haarp-1";
    }
    while (list($ID, $directory) = each($dir)) {
        $size = $unix->dskspace_bytes($directory);
        $q->QUERY_SQL("UPDATE haarp_caches SET `size`='{$size}' WHERE ID={$ID}");
    }
}
Ejemplo n.º 10
0
function squid_running_schedules()
{
    $TimeFile = "/etc/artica-postfix/pids/exec.squid.run.schedules.php.time";
    $pidfile = "/etc/artica-postfix/pids/exec.squid.run.schedules.php.pid";
    $unix = new unix();
    $pid = @file_get_contents($pidfile);
    if ($pid < 100) {
        $pid = null;
    }
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        _statussquid("{$pid} already executed since {$timepid}Mn");
        if ($timepid < 5) {
            return;
        }
        $kill = $unix->find_program("kill");
        unix_system_kill_force($pid);
    }
    @file_put_contents($pidfile, getmypid());
    if (!$GLOBALS["VERBOSE"]) {
        $time = $unix->file_time_min($TimeFile);
        if ($time < 4) {
            _statussquid("Current {$time}Mn need 5Mn");
            return;
        }
    }
    @unlink($TimeFile);
    @file_put_contents($TimeFile, time());
    $BASEDIR = "/usr/share/artica-postfix";
    $SQUIDEnable = $GLOBALS["CLASS_SOCKETS"]->GET_INFO("SQUIDEnable");
    if (!is_numeric($SQUIDEnable)) {
        $SQUIDEnable = 1;
    }
    if (function_exists("systemMaxOverloaded")) {
        if (systemMaxOverloaded()) {
            _statussquid("Overloaded system, aborting...");
            return;
        }
    }
    if ($SQUIDEnable == 0) {
        return;
    }
    _statussquid("squid_running_schedules");
    shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.logfile_daemon-parse.php --tables-primaires >/dev/null 2>&1 &");
    $filetimeF = "/etc/artica-postfix/pids/exec.squid.watchdog.php.start_watchdog.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 5) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.watchdog.php >/dev/null 2>&1 &");
    }
    $filetimeF = "/usr/share/artica-postfix/ressources/logs/web/ufdb.rules_toolbox_left.html";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 5) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/dansguardian2.mainrules.php rules-toolbox-left >/dev/null 2>&1 &");
    }
    $filetimeF = "/usr/share/artica-postfix/ressources/logs/web/squid_mem_status.html";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 5) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.watchdog.php --mem-status >/dev/null 2>&1 &");
    }
    $filetimeF = "/usr/share/artica-postfix/ressources/logs/web/SQUID_MGR_INFO.DB";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 15) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.watchdog.php --info >/dev/null 2>&1 &");
    }
    $filetimeF = "/usr/share/artica-postfix/ressources/logs/web/squid_stores_status.html";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 20) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.watchdog.php --store-status >/dev/null 2>&1 &");
    }
    $filetimeF = '/etc/artica-postfix/pids/Winbindd_privileged_SQUID.time';
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 5) {
        $GLOBALS["CLASS_UNIX"]->Winbindd_privileged_SQUID();
        @unlink($filetimeF);
        @file_put_contents($filetimeF, time());
    }
    $filetimeF = '/etc/artica-postfix/pids/EnableKerbAuth.time';
    $EnableKerbAuth = intval($GLOBALS["CLASS_SOCKETS"]->GET_INFO("EnableKerbAuth"));
    if ($EnableKerbAuth == 1) {
        $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
        _statussquid(basename($filetimeF) . ": {$filetime}Mn");
        if ($filetime > 5) {
            @unlink($filetimeF);
            shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.kerbauth.php --pinglic >/dev/null 2>&1 &");
            @file_put_contents($filetimeF, time());
        }
    }
    $filetimeF = '/etc/artica-postfix/pids/DisableGoogleSSL.time';
    $DisableGoogleSSL = intval($GLOBALS["CLASS_SOCKETS"]->GET_INFO("DisableGoogleSSL"));
    if ($DisableGoogleSSL == 1) {
        $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
        _statussquid(basename($filetimeF) . ": {$filetime}Mn");
        if ($GLOBALS["CLASS_UNIX"]->file_time_min($filetime) > 4320) {
            shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.nosslsearch.google.com.php --run >/dev/null 2>&1 &");
            @unlink($filetimeF);
            @file_put_contents($filetimeF, time());
        }
    }
    $filetimeF = "/etc/artica-postfix/pids/exec.squid.stats.hours.php.RTTZ_WORKSHOURS.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 60) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.stats.hours.php --rtt >/dev/null 2>&1 &");
    }
    $filetimeF = "/etc/artica-postfix/pids/exec.squid.stats.hours.php.tables_hours.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 60) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.stats.hours.php >/dev/null 2>&1 &");
    }
    $filetimeF = "/etc/artica-postfix/pids/exec.squid.php.Defaultschedules.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 120) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.php --defaults-schedules");
    }
    $filetimeF = "/etc/artica-postfix/pids/exec.squid.stats.central.php.import.statistics.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 120) {
        @unlink("/etc/artica-postfix/pids/exec.squid.stats.central.php.import.statistics.time");
        @file_put_contents("/etc/artica-postfix/pids/exec.squid.stats.central.php.import.statistics.time", time());
        stats_admin_events(2, "Launching importation tables task", null, __FILE__, __LINE__);
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.stats.central.php --import");
    }
    $filetimeF = "/etc/artica-postfix/pids/exec.squid.stats.not-categorized.php.not_categorized_scan.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 120) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.stats.not-categorized.php --recategorize >/dev/null 2>&1 &");
    }
    $filetimeF = "/etc/artica-postfix/pids/exec.squid.stats.totals.php.donnees_interface.pid";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 30) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.stats.totals.php --interface >/dev/null 2>&1 &");
    }
    $filetimeF = "/etc/artica-postfix/pids/exec.squid.interface-size.php.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 14) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.interface-size.php >/dev/null 2>&1 &");
    }
    $filetimeF = "/etc/artica-postfix/pids/exec.squid.stats.quota-week.parser.php.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 1880) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.stats.quota-week.parser.php >/dev/null 2>&1 &");
    }
    $filetimeF = "/etc/artica-postfix/pids/exec.squid.stats.mime.parser.php.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 19) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.stats.mime.parser.php >/dev/null 2>&1 &");
    }
    $filetimeF = "/etc/artica-postfix/pids/exec.squid.stats.mime.proto.php.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 19) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.stats.mime.proto.php >/dev/null 2>&1 &");
    }
    $filetimeF = "/etc/artica-postfix/pids/exec.squid.hourly.tables.php.current_access_db.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 9) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.hourly.tables.php --current_access >/dev/null 2>&1 &");
    }
    $filetimeF = "/etc/artica-postfix/pids/exec.squid.hourly.tables.php.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 64) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.hourly.tables.php >/dev/null 2>&1 &");
    }
    $timefile = "/etc/artica-postfix/pids/exec.squid.stats.quotaday.php.start.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 61) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.stats.quotaday.php >/dev/null 2>&1 &");
    }
    $timefile = "/etc/artica-postfix/pids/exec.squid.stats.quotaday.php.quotatemp.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 61) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.stats.quotaday.php --quotatemp >/dev/null 2>&1 &");
    }
    $timefile = "/etc/artica-postfix/pids/exec.squid-searchwords.php.searchwords_hour.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 61) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid-searchwords.php --hour >/dev/null 2>&1 &");
    }
    $timefile = "/etc/artica-postfix/pids/YoutubeByHour.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 61) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.stats.youtube.days.php --youtube-hours >/dev/null 2>&1 &");
    }
    $timefile = "/etc/artica-postfix/pids/exec.squid.stats.notcached-week.php.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 30) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.stats.notcached-week.php >/dev/null 2>&1 &");
    }
    $timefile = "/etc/artica-postfix/pids/exec.squid.stats.protos.php.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 240) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.stats.protos.php >/dev/null 2>&1 &");
    }
    $timefile = "/etc/artica-postfix/pids/exec.squid.php.rotate_logs.pid";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 60) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.php --rotate >/dev/null 2>&1 &");
    }
    $timefile = "/etc/artica-postfix/pids/exec.squid.rotate.php.build.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 120) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.rotate.php >/dev/null 2>&1 &");
    }
    $SquidEnforceRules = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/SquidEnforceRules"));
    if ($SquidEnforceRules == 1) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squidcache.php >/dev/null 2>&1 &");
    }
    $timefile = "/usr/share/artica-postfix/ressources/logs/web/squid_redirectors_status.db";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 10) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.watchdog.php --redirector-array >/dev/null 2>&1 &");
    }
    $timefile = "/etc/artica-postfix/pids/exec.dansguardian.injector.php.ParseAllUfdbs.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 5) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.dansguardian.injector.php --blocked >/dev/null 2>&1 &");
    }
}
Ejemplo n.º 11
0
function Overloaded()
{
    if (!systemMaxOverloaded()) {
        return false;
    }
    $tpl = new templates();
    $title = $tpl->_ENGINE_parse_body("{OVERLOADED_SYSTEM}");
    $link = "<center><a href='#' OnClick=javascript:Loadjs('artica.performances.php'); style='font-weight:bolder;text-decoration:underline;font-size:11px'>{performances_settings}</a></center>";
    $html[] = "\$.jGrowl(\"";
    $html[] = "<table>";
    $html[] = "<tr>";
    $html[] = "<td width=1% valign='top'>";
    $html[] = "<img src=img/database-error-48.png>";
    $html[] = "</td>";
    $html[] = "<td valign=top>";
    $html[] = "<span style=color:red;font-size:16px>{$title}";
    $html[] = "</span><hr>";
    $html[] = $tpl->_ENGINE_parse_body("<span style=font-size:13px>{OVERLOADED_SYSTEM_EXPLAIN}</span><p>{$link}</p>", "");
    $html[] = "\",";
    $html[] = "{header: '{$title}',life:15000});";
    echo implode("", $html) . "\n";
}
Ejemplo n.º 12
0
function launch_all_status()
{
    $functions = array("group5", "group10", "group30s", "group10s", "group0", "group2", "group300", "group120", "group30", "group60mn", "group5h", "group24h", "watchdog_artica_status");
    $system_is_overloaded = system_is_overloaded();
    $systemMaxOverloaded = systemMaxOverloaded();
    FillMemory();
    while (list($num, $func) = each($functions)) {
        if ($system_is_overloaded) {
            events("System is overloaded: ({$GLOBALS["SYSTEM_INTERNAL_LOAD"]}}, pause 10 seconds", __FUNCTION__, __LINE__);
            sleep(10);
            continue;
        } else {
            if ($systemMaxOverloaded) {
                events("System is very overloaded, pause stop", __FUNCTION__, __LINE__);
                return;
                continue;
            }
        }
        sleep(1);
        call_user_func($func);
    }
    $already = array();
    $AlreadyTests = array();
    if (count($GLOBALS["CMDS"]) > 0) {
        events("scheduling " . count($GLOBALS["CMDS"]) . " commands", __FUNCTION__, __LINE__);
        $FileDataCommand = @file_get_contents('/etc/artica-postfix/background');
        $tbl = explode("\n", $FileDataCommand);
        while (list($num, $zcommands) = each($GLOBALS["CMDS"])) {
            if (trim($zcommands) == null) {
                continue;
            }
            if (preg_match("#^(.+?)\\s+#", $zcommands, $re)) {
                if (!$AlreadyTests[$fileTests]) {
                    $fileTests = trim("{$re[1]}");
                    if (!is_file($fileTests)) {
                        events("running {$fileTests} No such file", __FUNCTION__, __LINE__);
                        continue;
                    } else {
                        $AlreadyTests[$fileTests] = true;
                    }
                }
            }
            if (!$already[$zcommands]) {
                $tbl[] = $zcommands;
                $already[$zcommands] = true;
            }
        }
        @file_put_contents('/etc/artica-postfix/background', implode("\n", $tbl));
        unset($GLOBALS["CMDS"]);
        $mem = round(memory_get_usage() / 1024 / 1000, 2);
        if ($GLOBALS["EnableArticaBackground"]) {
            $EnableArticaBackground = "Has daemon mode...";
        } else {
            $EnableArticaBackground = "Has cmdline mode...";
        }
        events("Saving /etc/artica-postfix/background done... Memory of this computer={$GLOBALS["TOTAL_MEMORY_MB"]}M Process memory at the end={$mem} Mb EnableArticaBackground=`{$EnableArticaBackground}`", __FUNCTION__, __LINE__);
    }
    @file_put_contents("/etc/artica-postfix/pids/" . basename(__FILE__) . ".GLOBALS", serialize($GLOBALS["TIME"]));
}
Ejemplo n.º 13
0
function squid_running_schedules()
{
    $TimeFile = "/etc/artica-postfix/pids/exec.squid.run.schedules.php.time";
    $pidfile = "/etc/artica-postfix/pids/exec.squid.run.schedules.php.pid";
    $unix = new unix();
    $pid = @file_get_contents($pidfile);
    if ($pid < 100) {
        $pid = null;
    }
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        _statussquid("{$pid} already executed since {$timepid}Mn");
        if ($timepid < 5) {
            return;
        }
        $kill = $unix->find_program("kill");
        unix_system_kill_force($pid);
    }
    @file_put_contents($pidfile, getmypid());
    if (!$GLOBALS["VERBOSE"]) {
        $time = $unix->file_time_min($TimeFile);
        if ($time < 4) {
            _statussquid("Current {$time}Mn need 5Mn");
            return;
        }
    }
    @unlink($TimeFile);
    @file_put_contents($TimeFile, time());
    $StatsApplianceReceivers = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/StatsApplianceReceivers"));
    $SquidPerformance = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/SquidPerformance"));
    $BASEDIR = "/usr/share/artica-postfix";
    $SQUIDEnable = $GLOBALS["CLASS_SOCKETS"]->GET_INFO("SQUIDEnable");
    if (!is_numeric($SQUIDEnable)) {
        $SQUIDEnable = 1;
    }
    if (function_exists("systemMaxOverloaded")) {
        if (systemMaxOverloaded()) {
            squid_admin_mysql(1, "{$GLOBALS["SYSTEM_INTERNAL_LOAD"]}: System is overloaded, Artica tasks as been aborted", null, __FILE__, __LINE__);
            _statussquid("Overloaded system, aborting...");
            return;
        }
    }
    if ($SQUIDEnable == 0) {
        return;
    }
    $filetimeF = "/etc/artica-postfix/pids/exec.squid.watchdog.php.start_watchdog.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 5) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.watchdog.php >/dev/null 2>&1 &");
    }
    $filetimeF = "/usr/share/artica-postfix/ressources/logs/web/squid_mem_status.html";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 5) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.watchdog.php --mem-status >/dev/null 2>&1 &");
    }
    $filetimeF = "/usr/share/artica-postfix/ressources/logs/web/SQUID_MGR_INFO.DB";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 15) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.watchdog.php --info >/dev/null 2>&1 &");
    }
    $filetimeF = "/usr/share/artica-postfix/ressources/logs/web/squid_stores_status.html";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 20) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.watchdog.php --store-status >/dev/null 2>&1 &");
    }
    $filetimeF = '/etc/artica-postfix/pids/Winbindd_privileged_SQUID.time';
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 5) {
        $GLOBALS["CLASS_UNIX"]->Winbindd_privileged_SQUID();
        @unlink($filetimeF);
        @file_put_contents($filetimeF, time());
    }
    $filetimeF = '/etc/artica-postfix/pids/EnableKerbAuth.time';
    $EnableKerbAuth = intval($GLOBALS["CLASS_SOCKETS"]->GET_INFO("EnableKerbAuth"));
    if ($EnableKerbAuth == 1) {
        $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
        _statussquid(basename($filetimeF) . ": {$filetime}Mn");
        if ($filetime > 5) {
            @unlink($filetimeF);
            shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.kerbauth.php --pinglic >/dev/null 2>&1 &");
            @file_put_contents($filetimeF, time());
        }
    }
    $filetimeF = '/etc/artica-postfix/pids/DisableGoogleSSL.time';
    $EnableGoogleDNS = 1;
    $DisableGoogleSSL = intval($GLOBALS["CLASS_SOCKETS"]->GET_INFO("DisableGoogleSSL"));
    $EnableGoogleSafeSearch = $GLOBALS["CLASS_SOCKETS"]->GET_INFO("EnableGoogleSafeSearch");
    if (!is_numeric($EnableGoogleSafeSearch)) {
        $EnableGoogleSafeSearch = 1;
    }
    if ($DisableGoogleSSL == 0) {
        if ($EnableGoogleSafeSearch == 0) {
            $EnableGoogleDNS = 0;
        }
    }
    if ($EnableGoogleDNS == 1) {
        $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
        _statussquid(basename($filetimeF) . ": {$filetime}Mn");
        if ($GLOBALS["CLASS_UNIX"]->file_time_min($filetime) > 4320) {
            shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.nosslsearch.google.com.php --run >/dev/null 2>&1 &");
            @unlink($filetimeF);
            @file_put_contents($filetimeF, time());
        }
    }
    $filetimeF = "/etc/artica-postfix/pids/exec.squid.php.Defaultschedules.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 120) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.php --defaults-schedules");
    }
    if ($SquidPerformance < 2) {
        $filetimeF = "/etc/artica-postfix/pids/exec.squid.stats.central.php.import.statistics.time";
        $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
        _statussquid(basename($filetimeF) . ": {$filetime}Mn");
        if ($filetime > 120) {
            @unlink("/etc/artica-postfix/pids/exec.squid.stats.central.php.import.statistics.time");
            @file_put_contents("/etc/artica-postfix/pids/exec.squid.stats.central.php.import.statistics.time", time());
            stats_admin_events(2, "Launching importation tables task", null, __FILE__, __LINE__);
            shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.stats.central.php --import");
        }
    }
    if ($SquidPerformance < 2) {
        $filetimeF = "/etc/artica-postfix/pids/exec.squid.stats.not-categorized.php.not_categorized_scan.time";
        $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
        _statussquid(basename($filetimeF) . ": {$filetime}Mn");
        if ($filetime > 120) {
            shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.stats.not-categorized.php --recategorize >/dev/null 2>&1 &");
        }
    }
    if ($SquidPerformance < 2) {
        $filetimeF = "/etc/artica-postfix/pids/exec.squid.stats.totals.php.donnees_interface.pid";
        $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
        _statussquid(basename($filetimeF) . ": {$filetime}Mn");
        if ($filetime > 30) {
            shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.stats.totals.php --interface >/dev/null 2>&1 &");
        }
    }
    if ($SquidPerformance < 2) {
        $filetimeF = "/etc/artica-postfix/pids/exec.squid.stats.quota-week.parser.php.time";
        $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
        _statussquid(basename($filetimeF) . ": {$filetime}Mn");
        if ($filetime > 1880) {
            shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.stats.quota-week.parser.php >/dev/null 2>&1 &");
        }
    }
    if ($SquidPerformance < 2) {
        $filetimeF = "/etc/artica-postfix/pids/exec.squid.stats.mime.proto.php.time";
        $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
        _statussquid(basename($filetimeF) . ": {$filetime}Mn");
        if ($filetime > 19) {
            shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.stats.mime.proto.php >/dev/null 2>&1 &");
        }
    }
    if ($SquidPerformance < 2) {
        $filetimeF = "/etc/artica-postfix/pids/YoutubeByHour.time";
        $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
        _statussquid(basename($filetimeF) . ": {$filetime}Mn");
        if ($filetime > 61) {
            shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.stats.youtube.days.php --youtube-hours >/dev/null 2>&1 &");
        }
    }
    $filetimeF = "/etc/artica-postfix/pids/exec.squid.php.rotate_logs.pid";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 60) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.php --rotate >/dev/null 2>&1 &");
    }
    $filetimeF = "/etc/artica-postfix/pids/exec.squid.rotate.php.build.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 120) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.rotate.php >/dev/null 2>&1 &");
    }
    if ($SquidPerformance < 3) {
        $SquidEnforceRules = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/SquidEnforceRules"));
        if ($SquidEnforceRules == 1) {
            shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squidcache.php >/dev/null 2>&1 &");
        }
    }
    $filetimeF = "/usr/share/artica-postfix/ressources/logs/web/squid_redirectors_status.db";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 10) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.watchdog.php --redirector-array >/dev/null 2>&1 &");
    }
    if ($SquidPerformance < 2) {
        $filetimeF = "/etc/artica-postfix/pids/exec.squid.interface-size.php.CachedOrNot.time";
        $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
        _statussquid(basename($filetimeF) . ": {$filetime}Mn");
        if ($filetime > 4) {
            shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.interface-size.php --cache-or-not >/dev/null 2>&1 &");
        }
    }
    $filetimeF = "/etc/artica-postfix/settings/Daemons/StatsApplianceReceivers";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 4) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.interface-size.php --stats-apps-clients >/dev/null 2>&1 &");
    }
    if ($StatsApplianceReceivers > 0) {
        $filetimeF = "/etc/artica-postfix/pids/exec.stats-appliance-clean.php.start_parse.time";
        $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
        _statussquid(basename($filetimeF) . ": {$filetime}Mn");
        if ($filetime > 59) {
            shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.stats-appliance-clean.php >/dev/null 2>&1 &");
        }
    }
    $filetimeF = "/etc/artica-postfix/pids/exec.clean.varlog.php.varlog.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 15) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.clean.varlog.php >/dev/null 2>&1 &");
    }
    $filetimeF = "/etc/artica-postfix/pids/exec.ufdb.parse-categories.php.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 60) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.ufdb.parse-categories.php >/dev/null 2>&1 &");
    }
    $filetimeF = "/etc/artica-postfix/pids/exec.mysqld.crash.php.check_crashed_squid.time";
    $filetime = $GLOBALS["CLASS_UNIX"]->file_time_min($filetimeF);
    _statussquid(basename($filetimeF) . ": {$filetime}Mn");
    if ($filetime > 120) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.mysqld.crash.php --crashed-squid >/dev/null 2>&1 &");
    }
    squid_tasks();
}
Ejemplo n.º 14
0
function ParseLocalQueue()
{
    if (systemMaxOverloaded()) {
        events("[OVERLOAD]:: running in max overload mode, aborting queue");
        return;
    }
    $EnableArticaBackground = $GLOBALS["CLASS_SOCKETS"]->GET_INFO("EnableArticaBackground");
    if (!is_numeric($EnableArticaBackground)) {
        $EnableArticaBackground = 1;
    }
    if ($EnableArticaBackground == 0) {
        $mef = basename(__FILE__);
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $oldpid = @file_get_contents($pidfile);
        if ($GLOBALS["CLASS_UNIX"]->process_exists($oldpid, $mef)) {
            events("Process Already exist pid {$oldpid} line:" . __LINE__);
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $MemoryInstances = MemoryInstances();
    if ($MemoryInstances > 4) {
        events("Too much php processes in memory, aborting");
        return;
    }
    if (!is_numeric($MemoryInstances)) {
        $MemoryInstances = 0;
    }
    if (is_file("/etc/artica-postfix/orders.queue")) {
        $size = @filesize("/etc/artica-postfix/orders.queue");
        if ($size > 0) {
            events("Loading /etc/artica-postfix/orders.queue {$size} bytes");
            $orders_queue = explode("\n", @file_get_contents("/etc/artica-postfix/orders.queue"));
            if (is_array($orders_queue)) {
                while (list($num, $ligne) = each($orders_queue)) {
                    if (trim($ligne) == null) {
                        continue;
                    }
                    $orders[md5($ligne)] = $ligne;
                }
            }
        }
        @unlink("/etc/artica-postfix/orders.queue");
    }
    if (is_file("/etc/artica-postfix/background")) {
        $size = @filesize("/etc/artica-postfix/background");
        if ($size > 0) {
            events("Loading /etc/artica-postfix/background {$size} bytes");
            $background = explode("\n", @file_get_contents("/etc/artica-postfix/background"));
            if (is_array($background)) {
                while (list($num, $ligne) = each($background)) {
                    if (trim($ligne) == null) {
                        continue;
                    }
                    $orders[md5($ligne)] = $ligne;
                }
            }
        }
        @unlink("/etc/artica-postfix/background");
    }
    if (is_file("/var/log/artica-postfix/executor-daemon.log")) {
        $time_exec = file_time_min("/var/log/artica-postfix/executor-daemon.log");
        events("executor-daemon.log {$time_exec} Min");
        if ($time_exec > 5) {
            events("artica-executor is freeze ({$time_exec} minutes), restart it (see /tmp/watchdog.executor.log)");
            system(trim("/etc/init.d/artica-postfix restart artica-exec >/tmp/watchdog.executor.log 2>&1"));
            events("done...");
        }
    }
    if (is_file("/usr/share/artica-postfix/ressources/logs/global.status.ini")) {
        $time_status = file_time_min("/usr/share/artica-postfix/ressources/logs/global.status.ini");
        events("global.status.ini {$time_exec} Min");
        if ($time_status > 5) {
            events("artica-status is freeze ({$time_status} minutes for /usr/share/artica-postfix/ressources/logs/global.status.ini), restart it (see /tmp/watchdog.status.log)");
            system(trim("/etc/init.d/artica-postfix restart artica-status >/tmp/watchdog.status.log 2>&1"), $results);
            $cmd = trim($nice . $nohup . " " . $GLOBALS["CLASS_UNIX"]->LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.status.php --all >/dev/null 2>&1 &");
            events("{$cmd} done...");
        }
    }
    events("artica-executor: {$time_exec}mn; artica-status: {$time_status}mn ");
    if (count($orders) == 0) {
        events("artica-executor: queue is empty...");
        artica_exec();
        return null;
    }
    //events("[NORMAL]:: NICE={$GLOBALS["NICE"]}");
    $nice = $GLOBALS["NICE"];
    $orders_number = count($orders);
    $count_max = $orders_number;
    if ($count_max > 4) {
        $count_max = 4;
    }
    if ($orders_number > 10) {
        if (!$GLOBALS["OVERLOAD"]) {
            $count_max = 10;
        }
    }
    $count = 0;
    if ($count_max + $MemoryInstances > 10) {
        $count_max = 10 - $MemoryInstances;
    }
    if ($GLOBALS["TOTAL_MEMORY_MB"] < 400) {
        events("Lower config switch to 2 max processes...mem:{$GLOBALS["TOTAL_MEMORY_MB"]}MB");
        $count_max = 2;
    }
    while (list($num, $cmd) = each($orders)) {
        if (trim($cmd) == null) {
            continue;
        }
        if (preg_match("#artica-make#", $cmd)) {
            events("artica-make detected \"{$cmd}\", execute this task first...");
            shell_exec("{$nice}{$cmd}{$devnull}");
            unset($orders[$num]);
        }
    }
    reset($orders);
    events("Orders:{$orders_number} Loaded instances:{$MemoryInstances} Max to order:{$count_max}");
    while (list($num, $cmd) = each($orders)) {
        if (trim($cmd) == null) {
            continue;
        }
        $devnull = " >/dev/null 2>&1";
        if (strpos($cmd, ">") > 0) {
            $devnull = null;
        }
        if (system_is_overloaded(__FILE__)) {
            if ($count >= $count_max) {
                break;
            }
            unset($orders[$num]);
            events("[OVERLOAD]:: running in overload mode {$nice}{$cmd}{$devnull}");
            shell_exec("{$nice}{$cmd}{$devnull}");
            events("[OVERLOAD]:: {$cmd} was successfully executed, parse next");
            $count++;
            continue;
        }
        $count++;
        events("[NORMAL]:: running in normal mode {$nice}{$cmd}{$devnull} &");
        shell_exec("{$nice}{$cmd}{$devnull} &");
        events("[NORMAL]::[{$num}] {$cmd} was successfully executed, parse next");
        unset($orders[$num]);
        if ($count >= $count_max) {
            break;
        }
    }
    events("{$count}/{$orders_number} order(s) executed...end;");
    if (is_array($orders)) {
        if (count($orders) > 0) {
            reset($orders);
            $fh = fopen("/etc/artica-postfix/background", 'w') or die("can't open file");
            while (list($num, $cmd) = each($orders)) {
                $datas = "{$cmd}\n";
                fwrite($fh, $datas);
            }
            fclose($fh);
            events("Queued " . count($orders) . " order(s)");
        }
    }
}
Ejemplo n.º 15
0
function check_databases($bd)
{
    include_once dirname(__FILE__) . "/ressources/class.os.system.inc";
    if (systemMaxOverloaded()) {
        die;
    }
    $q = new mysql();
    $q->checkRoundCubeTables($bd);
}
Ejemplo n.º 16
0
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");
    }
}
Ejemplo n.º 17
0
function launch_all_status()
{
    $functions = array("group5", "group10", "group30s", "group10s", "group0", "group2", "group300", "group120", "group30", "group60mn", "group5h", "group24h", "watchdog_artica_status");
    $system_is_overloaded = system_is_overloaded();
    $systemMaxOverloaded = systemMaxOverloaded();
    FillMemory();
    while (list($num, $func) = each($functions)) {
        if ($system_is_overloaded) {
            events("System is overloaded: ({$GLOBALS["SYSTEM_INTERNAL_LOAD"]}}, pause 10 seconds", __FUNCTION__, __LINE__);
            sleep(10);
            continue;
        } else {
            if ($systemMaxOverloaded) {
                events("System is very overloaded, pause stop", __FUNCTION__, __LINE__);
                return;
                continue;
            }
        }
        usleep(10000);
        call_user_func($func);
    }
    $already = array();
    $AlreadyTests = array();
    if (count($GLOBALS["CMDS"]) > 0) {
        events("scheduling " . count($GLOBALS["CMDS"]) . " commands", __FUNCTION__, __LINE__);
        $FileDataCommand = @file_get_contents('/etc/artica-postfix/background');
        $tbl = explode("\n", $FileDataCommand);
        while (list($num, $zcommands) = each($GLOBALS["CMDS"])) {
            if (trim($zcommands) == null) {
                continue;
            }
            if (preg_match("#^(.+?)\\s+#", $zcommands, $re)) {
                if (!$AlreadyTests[$fileTests]) {
                    $fileTests = trim("{$re[1]}");
                    if (!is_file($fileTests)) {
                        events("running {$fileTests} No such file", __FUNCTION__, __LINE__);
                        continue;
                    } else {
                        $AlreadyTests[$fileTests] = true;
                    }
                }
            }
            if (!$already[$zcommands]) {
                $tbl[] = $zcommands;
                $already[$zcommands] = true;
            }
        }
        @file_put_contents('/etc/artica-postfix/background', implode("\n", $tbl));
        unset($GLOBALS["CMDS"]);
        $mem = round(memory_get_usage() / 1024 / 1000, 2);
        events("{$mem}MB consumed in memory", __FUNCTION__, __LINE__);
        if ($GLOBALS["TOTAL_MEMORY_MB"] < 400) {
            $unix = new unix();
            $cmd = trim($nohup . " {$GLOBALS["EXEC_NICE"]}" . $unix->LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.parse-orders.php >/dev/null 2>&1 &");
            shell_exec($cmd);
        }
    }
    @file_put_contents("/etc/artica-postfix/pids/" . basename(__FILE__) . ".GLOBALS", serialize($GLOBALS["TIME"]));
}
Ejemplo n.º 18
0
function ParseLocalQueue(){
	
$MemoryInstances=MemoryInstances();
if($MemoryInstances>4){events("Too much php processes in memory, aborting");return;}
if(!is_numeric($MemoryInstances)){$MemoryInstances=0;}

if(is_file("/etc/artica-postfix/orders.queue")){
		$size=@filesize("/etc/artica-postfix/orders.queue");
		if($size>0){
			events("Loading /etc/artica-postfix/orders.queue $size bytes");
			$orders_queue=explode("\n",@file_get_contents("/etc/artica-postfix/orders.queue"));
			if(is_array($orders_queue)){
				while (list ($num, $ligne) = each ($orders_queue) ){
					if(trim($ligne)==null){continue;}
					$orders[md5($ligne)]=$ligne;
				}	
			}
		}
		@unlink("/etc/artica-postfix/orders.queue");	
	}


if(is_file("/etc/artica-postfix/background")){
		$size=@filesize("/etc/artica-postfix/background");
		if($size>0){
			events("Loading /etc/artica-postfix/background $size bytes");
			$background=explode("\n",@file_get_contents("/etc/artica-postfix/background"));
			if(is_array($background)){
				while (list ($num, $ligne) = each ($background) ){
					if(trim($ligne)==null){continue;}
					$orders[md5($ligne)]=$ligne;
				}
			}
		}
		@unlink("/etc/artica-postfix/background");
		
}

	if(is_file("/var/log/artica-postfix/executor-daemon.log")){
		$time_exec=file_time_min("/var/log/artica-postfix/executor-daemon.log");
		events("executor-daemon.log $time_exec Min");
		if($time_exec>5){
			events("artica-executor is freeze ($time_exec minutes), restart it (see /tmp/watchdog.executor.log)");
			system(trim("/etc/init.d/artica-postfix restart artica-exec >/tmp/watchdog.executor.log 2>&1"));
			events("done...");
		}
	}
	
	
	if(is_file("/usr/share/artica-postfix/ressources/logs/global.status.ini")){
		$time_status=file_time_min("/usr/share/artica-postfix/ressources/logs/global.status.ini");
		events("global.status.ini $time_exec Min");
		if($time_status>5){
			events("artica-status is freeze ($time_status minutes), restart it (see /tmp/watchdog.status.log");
			system(trim("/etc/init.d/artica-postfix restart artica-status >/tmp/watchdog.status.log 2>&1"),$results);
			events("done...");
		}	
	}
	events("artica-executor: {$time_exec}mn; artica-status: {$time_status}mn ");

	
	if(count($orders)==0){
		events("artica-executor: queue is empty...");
		return null;
	}
	
	
	
	//events("[NORMAL]:: NICE={$GLOBALS["NICE"]}");
	$nice=$GLOBALS["NICE"];
	$orders_number=count($orders);
	$count_max=$orders_number;
	if($count_max>4){$count_max=4;}
	if($orders_number>10){if(!$GLOBALS["OVERLOAD"]){$count_max=10;}}
	$count=0;
	

	
	if($count_max+$MemoryInstances>10){$count_max=10-$MemoryInstances;}
	
	if($GLOBALS["TOTAL_MEMORY_MB"]<400){
		events("Lower config switch to 2 max processes...");
		$count_max=2;
	}	
	
	
	events("Orders:$orders_number Loaded instances:$MemoryInstances Max to order:$count_max");
	
	while (list ($num, $cmd) = each ($orders) ){
		if(trim($cmd)==null){continue;}
		if(systemMaxOverloaded()){events("[OVERLOAD]:: running in max overload mode, aborting queue");break;}
		$devnull=" >/dev/null 2>&1";
		if(strpos($cmd,">")>0){$devnull=null;}

		if(system_is_overloaded(__FILE__)){
			if($count>=$count_max){break;}
			unset($orders[$num]);
			events("[OVERLOAD]:: running in overload mode $nice$cmd$devnull");
			shell_exec("$nice$cmd$devnull");
			events("[OVERLOAD]:: $cmd was successfully executed, parse next");
			$count++;
			continue;
		}
		$count++;
		events("[NORMAL]:: running in normal mode $nice$cmd$devnull &");
		shell_exec("$nice$cmd$devnull &");
		events("[NORMAL]:: $cmd was successfully executed, parse next");
		unset($orders[$num]);
		if($count>=$count_max){break;}
	}
	
	
	events("$count/$orders_number order(s) executed...end;");
	if(is_array($orders)){
		if(count($orders)>0){
			reset($orders);
			$fh = fopen("/etc/artica-postfix/background", 'w') or die("can't open file");
			while (list ($num, $cmd) = each ($orders) ){
				$datas="$cmd\n";
				fwrite($fh, $datas);
				}
			fclose($fh);
			events("Queued ". count($orders)." order(s)");
		}
	}

}