function amavis_reload(){ SPAMASSASSIN_V320(); PhishTag(); HitFreqsRuleTiming(); if(!is_file("/usr/local/sbin/amavisd")){return null;} if(!is_file("/usr/local/etc/amavisd.conf")){return null;} $amavis=new amavis(); $amavis->CheckDKIM(); $conf=$amavis->buildconf(); @file_put_contents("/usr/local/etc/amavisd.conf",$conf); $unix=new unix(); $unix->THREAD_COMMAND_SET("/usr/share/artica-postfix/bin/artica-make APP_SPAMASSASSIN_RQ"); CheckSecuritiesFolders(); $unix->send_email_events("Amavis will be reloaded", "exec.spamassassin, ordered to reload amavis {$GLOBALS["CMDLINES"]}", "postfix"); $unix->THREAD_COMMAND_SET("/usr/local/sbin/amavisd -c /usr/local/etc/amavisd.conf reload"); }
function launch_tests() { $unix = new unix(); $php = $unix->LOCATE_PHP5_BIN(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { return; } if (system_is_overloaded(basename(__FILE__))) { system_admin_events("Overloaded, aborting task...", __FUNCTION__, __FILE__, __LINE__, "system"); $unix->THREAD_COMMAND_SET("{$php} " . __FILE__); return; } @file_put_contents($pidfile, getmypid()); $datafile = "/etc/artica-postfix/settings/Daemons/HdparmInfos"; writelogs("Testing hard drives ({$datafile})", __FUNCTION__, __FILE__, __LINE__); $timenum = file_time_min($datafile); if (is_file($datafile)) { if (file_time_min($datafile) < 61) { writelogs("{$timenum}Mn executed, waiting 60Mn", __FUNCTION__, __FILE__, __LINE__); die; } } if ($GLOBALS["FIND_HDPARM"] == null) { writelogs("Unable to stat 'hdparm'", __FUNCTION__, __FILE__, __LINE__); die; } $disks = GetDisks(); if (!is_array($disks)) { return null; } while (list($index, $line) = each($disks)) { unset($results); exec("{$GLOBALS["FIND_HDPARM"]} -t {$index}", $results); while (list($num, $line_result) = each($results)) { if (preg_match("#=\\s+([0-9\\.]+)\\s+MB\\/sec\$#", $line_result, $re)) { if (preg_match("#.+?\\/(.+)\$#", $index, $ri)) { system_admin_events("{$ri[1]}:{$re[1]}MB/sec", __FUNCTION__, __FILE__, __LINE__, "system"); writelogs("testing disk {$ri[1]}:{$re[1]}MB/sec...", __FUNCTION__, __FILE__, __LINE__); $array[$ri[1]] = $re[1]; } } } } @unlink($datafile); @file_put_contents($datafile, base64_encode(serialize($array))); if (!is_file($datafile)) { writelogs("{$datafile} no such file or directory", __FUNCTION__, __FILE__, __LINE__); } }
function export_rules(){ $unix=new unix(); if(!is_dir("/var/log/artica-postfix/iptaccount")){@mkdir("/var/log/artica-postfix/iptaccount",0644,true);} $iptaccount=$unix->find_program("iptaccount"); if(!is_file($iptaccount)){ if($GLOBALS["VERBOSE"]){echo "iptaccount, no such file\n";} return; } exec("$iptaccount -a 2>&1",$results); while (list ($num, $ligne) = each ($results) ){ if(preg_match("#Found table.+?rule_([0-9]+)#",$ligne,$re)){ $time=time(); $rule=$re[1]; if($GLOBALS["VERBOSE"]){echo "Rule [{$re[1]}] ($time)\n";} $filename="/var/log/artica-postfix/iptaccount/$time.$rule"; $cmd="$iptaccount -s -l rule_$rule -f >$filename 2>&1"; if($GLOBALS["VERBOSE"]){echo "$cmd\n";} shell_exec($cmd); } } $unix->THREAD_COMMAND_SET($unix->LOCATE_PHP5_BIN()." ".__FILE__." --import"); }
function savenic($NIC) { $unix = new unix(); $ipClass = new IP(); $ETH_IP = trim(@file_get_contents("/etc/artica-postfix/WIZARDIP_{$NIC}")); $NETMASK = trim(@file_get_contents("/etc/artica-postfix/WIZARDMASK_{$NIC}")); $GATEWAY = trim(@file_get_contents("/etc/artica-postfix/WIZARDGATEWAY_{$NIC}")); if (!$ipClass->isIPAddress($ETH_IP)) { echo "* * * * {$ETH_IP} * * * * WRONG !!!!\n"; @file_put_contents("/etc/artica-postfix/WIZARDRESULT_{$NIC}", 0); return; } if (!$ipClass->isIPAddress($GATEWAY)) { echo "* * * * {$GATEWAY} * * * * WRONG !!!!\n"; @file_put_contents("/etc/artica-postfix/WIZARDRESULT_{$NIC}", 0); return; } $nics = new system_nic($NIC); $nics->eth = $NIC; $nics->IPADDR = $ETH_IP; $nics->NETMASK = $NETMASK; $nics->GATEWAY = $GATEWAY; $nics->dhcp = 0; $nics->metric = 1; $nics->defaultroute = 1; $nics->enabled = 1; if (!$nics->SaveNic()) { echo "* * * * MYSQL ERROR !!! * * * * WRONG !!!!\n"; @file_put_contents("/etc/artica-postfix/WIZARDRESULT_{$NIC}", 0); return; } $php = $unix->LOCATE_PHP5_BIN(); $nohup = $unix->find_program("nohup"); $php5 = $php; system("{$php5} " . dirname(__FILE__) . " /exec.virtuals-ip.php --build --force >/dev/null 2>&1"); echo "20%] Please Wait, apply network configuration....\n"; system("/etc/init.d/artica-ifup start"); echo "30%] Please Wait, restarting services....\n"; $unix->THREAD_COMMAND_SET("{$php5} /usr/share/artica-postfix/exec.postfix.maincf.php --reconfigure"); $unix->THREAD_COMMAND_SET("/usr/share/artica-postfix/bin/artica-install --reconfigure-cyrus"); system("{$nohup} /etc/init.d/artica-status reload >/dev/null 2>&1 &"); system("{$nohup} /etc/init.d/nginx restart >/dev/null 2>&1 &"); system("{$nohup} /etc/init.d/monit restart >/dev/null 2>&1 &"); echo "30%] Please Wait, Changing IP address to {$NIC}....\n"; $ifconfig = $unix->find_program("ifconfig"); system("{$ifconfig} {$NIC} down"); system("{$ifconfig} {$NIC} {$ETH_IP} netmask {$NETMASK} up"); system("/bin/ip route add 127.0.0.1 dev lo"); if ($GATEWAY != "0.0.0.0") { echo "31%] Please Wait, Define default gateway to {$GATEWAY}....\n"; system("/sbin/route add {$GATEWAY} dev {$NIC}"); $route = $unix->find_program("route"); shell_exec("{$route} add -net 0.0.0.0 gw {$GATEWAY} dev {$NIC} metric 1"); } echo "95%] Restarting Web Console\n"; system("/etc/init.d/artica-webconsole restart"); echo "100%] Configuration done.\n"; @file_put_contents("/etc/artica-postfix/WIZARDRESULT_{$NIC}", 1); echo "###################################################\n"; echo "############ #############\n"; echo "############ SUCCESS #############\n"; echo "############ #############\n"; echo "###################################################\n\n\n\n"; }
function repair_tables() { $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $timefile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time"; $pid = @file_get_contents($pidfile); $unix = new unix(); if ($unix->process_exists($pid, basename(__FILE__))) { events_tail("Already executed pid {$pid}"); if ($GLOBALS["VERBOSE"]) { echo "Already executed pid {$pid}\n"; } return; } $files = $unix->DirFiles("/usr/share/artica-postfix/ressources/logs/categorize-tables"); $php5 = $unix->LOCATE_PHP5_BIN(); while (list($none, $tablename) = each($files)) { $filePath = "/usr/share/artica-postfix/ressources/logs/categorize-tables/{$tablename}"; if (!is_file($filePath)) { @unlink($filePath); continue; } $ARRAY = unserialize(@file_get_contents($filePath)); if (!is_array($ARRAY)) { @unlink($filePath); continue; } $PID = $ARRAY["PID"]; $CUR = $ARRAY["CURRENT"]; $MAX = $ARRAY["MAX"]; if ($CUR == $MAX) { @unlink($filePath); continue; } if ($unix->process_exists($PID)) { continue; } categorize_tables_events("Ask to schedule table Current:{$CUR}/{$MAX}", null, $tablename, 1); $unix->THREAD_COMMAND_SET("{$php5} " . __FILE__ . " --table {$tablename}"); } }
function restart_monit() { $unix = new unix(); $unix->THREAD_COMMAND_SET("/etc/init.d/artica-postfix restart monit"); writelogs_framework("{$cmd}", __FUNCTION__, __FILE__, __LINE__); }
function xtart() { if (!isset($GLOBALS["ARTICALOGDIR"])) { $GLOBALS["ARTICALOGDIR"] = @file_get_contents("/etc/artica-postfix/settings/Daemons/ArticaLogDir"); if ($GLOBALS["ARTICALOGDIR"] == null) { $GLOBALS["ARTICALOGDIR"] = "/var/log/artica-postfix"; } } $unix = new unix(); $binfile = "/usr/share/artica-postfix/bin/seeker"; if (!is_file($binfile)) { build_progress("{failed}", 110); events("Unable to stat {$binfile}"); return; } $php = $unix->LOCATE_PHP5_BIN(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pidTime = "/etc/artica-postfix/pids/exec.seeker.php.xtart.time"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { events("Already process executed pid {$pid}"); return; } if (system_is_overloaded(basename(__FILE__))) { events("Overloaded system, schedule it later", __LINE__); $unix->THREAD_COMMAND_SET("{$php} " . __FILE__); build_progress("{failed} Overloaded", 110); return; } @file_put_contents($pidfile, getmypid()); $timefile = $unix->file_time_min($pidTime); $DisksBenchs = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/DisksBenchs")); $DisksBenchs = $DisksBenchs * 60; if (!$GLOBALS["FORCE"]) { if ($timefile < $DisksBenchs) { events("{$timefile}mn, require at least {$DisksBenchs}mn", __LINE__); return; } } @unlink($pidTime); @file_put_contents($pidTime, time()); build_progress("{scanning} {disks}", 10); $fdisk = $unix->find_program("fdisk"); exec("{$fdisk} -l 2>&1", $results); $DISKS = array(); while (list($index, $line) = each($results)) { $line = trim($line); if ($line == null) { continue; } if (preg_match("#^(Disque|Disk)\\s+\\/([a-zA-Z0-9\\-\\_\\/\\.]+).*?:\\s+[0-9]+.*?(bytes|octets)#", $line, $re)) { $DISKS["/" . $re[2]] = true; } } if (count($DISKS) == 0) { build_progress("{scanning} {disks} {failed}", 110); events("Unable to detect disks"); $unix->ToSyslog("Unable to detect disks"); system_admin_events("Unable to detect disks\n" . @implode("\n", $results), __FUNCTION__, __FILE__, __LINE__, "system"); return; } $RUN = false; while (list($disk, $line) = each($DISKS)) { $results = array(); @chmod("{$binfile}", 0755); $cmd = "{$binfile} \"" . trim($disk) . "\" 2>&1"; build_progress("{scanning} {$disk}", 60); events("{$cmd}"); exec($cmd, $results); while (list($index, $line) = each($results)) { $line = trim($line); echo "***: {$line}\n"; $md5 = md5("{$disk}" . time()); if ($line == null) { continue; } if (!preg_match("#^Results:\\s+([0-9]+)\\s+seeks.*?,\\s+([0-9\\.]+)\\s+ms#", $line, $re)) { continue; } $seeks = $re[1]; $ms = $re[2]; events("{$disk} {$seeks} seeks, {$ms} ms", __LINE__); $array = array(); @mkdir("{$GLOBALS["ARTICALOGDIR"]}/seeker-queue", 0755, true); $array["SEEKS"] = $seeks; $array["DISK"] = $disk; $array["MS"] = $ms; $array["time"] = time(); $unix->ToSyslog("Bench disk {$disk} {$ms} ms for {$seeks} seeks"); events("{$GLOBALS["ARTICALOGDIR"]}/seeker-queue/{$md5}.ay", __LINE__); @file_put_contents("{$GLOBALS["ARTICALOGDIR"]}/seeker-queue/{$md5}.ay", serialize($array)); $RUN = true; break; } } if ($RUN) { $php = $unix->LOCATE_PHP5_BIN(); $nohup = $unix->find_program("nohup"); build_progress("{analyze}", 90); $cmd = "{$php} " . dirname(__FILE__) . "/exec.syslog-engine.php --seeker"; events($cmd); system($cmd); } build_progress("{done}", 100); }
function RestartDedicatedServices($aspid = false) { $unix = new unix(); if ($aspid) { $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = @file_get_contents($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); echo "Starting......: " . date("H:i:s") . " RestartDedicatedServices already executed PID: {$pid} since {$time}Mn\n"; if ($time < 120) { if (!$GLOBALS["FORCE"]) { die; } } unix_system_kill_force($pid); } @file_put_contents($pidfile, getmypid()); } $nohup = $unix->find_program("nohup"); $php = $unix->LOCATE_PHP5_BIN(); $squidbin = $unix->LOCATE_SQUID_BIN(); $unix->THREAD_COMMAND_SET("{$php} /usr/share/artica-postfix/exec.web-community-filter.php --register"); events("Starting artica"); echo "Starting......: " . date("H:i:s") . " nightly builds starting artica...\n"; @file_put_contents("/usr/share/artica-postfix/download_progress", 45); system("/etc/init.d/artica-postfix start"); echo "Starting......: " . date("H:i:s") . " nightly builds building init scripts\n"; @file_put_contents("/usr/share/artica-postfix/download_progress", 50); system("{$php} /usr/share/artica-postfix/exec.initslapd.php --force >/dev/null 2>&1"); echo "Starting......: " . date("H:i:s") . " nightly builds updating network\n"; @file_put_contents("/usr/share/artica-postfix/download_progress", 55); system("{$php} /usr/share/artica-postfix/exec.virtuals-ip.php >/dev/null 2>&1"); system("{$php} /usr/share/artica-postfix/exec.monit.php --build >/dev/null 2>&1"); echo "Starting......: " . date("H:i:s") . " nightly builds purge and clean....\n"; @file_put_contents("/usr/share/artica-postfix/download_progress", 60); shell_exec("{$nohup} /etc/init.d/slapd start >/dev/null 2>&1 &"); shell_exec("{$nohup} /etc/init.d/artica-webconsole start >/dev/null 2>&1 &"); if (is_file("/etc/init.d/nginx")) { shell_exec("{$nohup} /etc/init.d/nginx reload >/dev/null 2>&1 &"); } shell_exec("{$nohup} /etc/init.d/auth-tail restart >/dev/null 2>&1 &"); shell_exec("{$nohup} /etc/init.d/artica-framework restart >/dev/null 2>&1 &"); shell_exec("{$nohup} /usr/share/artica-postfix/bin/process1 -perm >/dev/null 2>&1 &"); shell_exec("{$nohup} /usr/share/artica-postfix/bin/artica-make --empty-cache >/dev/null 2>&1 &"); shell_exec("{$nohup} /etc/init.d/monit restart >/dev/null 2>&1 &"); shell_exec("{$nohup} /etc/init.d/artica-status restart --force >/dev/null 2>&1 &"); shell_exec("{$nohup} {$php} /usr/share/artica-postfix/exec.squid.php --build-schedules >/dev/null 2>&1 &"); shell_exec("{$nohup} {$php} /usr/share/artica-postfix/exec.schedules.php --defaults >/dev/null 2>&1 &"); if (is_file($squidbin)) { squid_admin_mysql(1, "Reconfiguring proxy service", null, __FILE__, __LINE__); $cmd = "/etc/init.d/squid reload --script=" . basename(__FILE__) . " >/dev/null 2>&1 &"; shell_exec($cmd); } events("done"); @file_put_contents("/usr/share/artica-postfix/download_progress", 100); echo "Starting......: " . date("H:i:s") . " Done you can close the screen....\n"; _artica_update_event(2, "RestartDedicatedServices(): finish", null, __FILE__, __LINE__); }
function build() { $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = @file_get_contents($pidfile); $unix = new unix(); if ($unix->process_exists($pid)) { echo "Starting......: " . date("H:i:s") . " Already process exists pid {$pid}\n"; return; } @file_put_contents($pidfile, getmypid()); $php = $unix->LOCATE_PHP5_BIN(); if (system_is_overloaded()) { $unix->THREAD_COMMAND_SET("{$php} " . __FILE__ . " --build"); return; } patch_grub_default(); $sock = new sockets(); $q = new mysql(); $sql = "SELECT * FROM users_containers WHERE created=0 AND onerror=0"; $results = $q->QUERY_SQL($sql, "artica_backup"); $count = mysql_num_rows($results); if (!$q->ok) { echo "Starting......: " . date("H:i:s") . " users_containers {$q->mysql_error}\n"; return; } echo "Starting......: " . date("H:i:s") . " {$count} containers to build\n"; if ($count > 0) { while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { $directory = trim($ligne["directory"]); $ID = $ligne["container_id"]; if ($directory == null) { users_containers_error($ID, "No specified main directory..."); continue; } $directory_size_avai = $unix->DIRECTORY_FREEM($directory); if ($directory_size_avai == 0) { users_containers_error($ID, "no space left on specified directory"); continue; } @mkdir($directory, 0755, true); if (!is_dir($directory)) { users_containers_error($ID, "Permission denied on specified directory"); continue; } $ContainerFullPath = $directory . "/{$ID}.disk"; $size = $ligne["container_size"]; if ($size > $directory_size_avai) { users_containers_error($ID, "{$size}MB will exceed space on main storage"); continue; } $label = "{$ID}_disk"; echo "Starting......: " . date("H:i:s") . " Verify {$ContainerFullPath} with a size of {$size}MB\n"; if (!stat_system($ContainerFullPath)) { echo "Starting......: " . date("H:i:s") . " buil_dd {$ContainerFullPath} {$size}MB\n"; if (!build_dd($ContainerFullPath, $size)) { users_containers_error($ID, "Unable to build the virtual disk (ERR." . __LINE__ . ")"); continue; } } $GetLoops = GetLoops(); if (!stat_system($ContainerFullPath)) { users_containers_error($ID, "Unable to build the virtual disk (ERR." . __LINE__ . ")"); continue; } if ($GetLoops[$ContainerFullPath] == null) { echo "Starting......: " . date("H:i:s") . " {$ContainerFullPath} no such loop\n"; if (!build_loop($ContainerFullPath)) { echo "`{$ContainerFullPath}` unable to create loop\n"; echo "Starting......: " . date("H:i:s") . " Re-check the loop list...\n"; $GetLoops = GetLoops(); if ($GetLoops[$ContainerFullPath] == null) { users_containers_error($ID, "Loop error (ERR." . __LINE__ . ")"); continue; } } } echo "Starting......: " . date("H:i:s") . " {$ContainerFullPath} loop={$GetLoops[$ContainerFullPath]}\n"; $sql = "UPDATE users_containers SET loop_dev='{$GetLoops[$ContainerFullPath]}' WHERE `container_id`='{$ID}'"; $q->QUERY_SQL($sql, 'artica_backup'); if (!$q->ok) { echo "{$q->mysql_error}\n"; continue; } $dev = $GetLoops[$ContainerFullPath]; echo "Starting......: " . date("H:i:s") . " {$ContainerFullPath} is {$dev}\n"; if (!ifFileSystem($dev)) { if (!mke2fs($dev, $label)) { users_containers_error($ID, "mke2fs error (ERR." . __LINE__ . ")"); continue; } } $uuid = Getuuid($dev); echo "Starting......: " . date("H:i:s") . " {$dev} uuid={$uuid}\n"; $q->QUERY_SQL("UPDATE users_containers SET uuid='{$uuid}' WHERE `container_id`='{$ID}'", 'artica_backup'); if ($uuid == null) { continue; } $q->QUERY_SQL("UPDATE users_containers SET created='1' WHERE `container_id`='{$ID}'", 'artica_backup'); } } @mkdir("/media/artica_containers/membersdisks", 0755, true); $q = new mysql(); $sql = "SELECT * FROM users_containers WHERE created=1 AND onerror=0"; $results = $q->QUERY_SQL($sql, "artica_backup"); $count = mysql_num_rows($results); $mount = $unix->find_program("mount"); $umount = $unix->find_program("umount"); while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { $directory = trim($ligne["directory"]); $mkfs_ext4 = $unix->find_program("mkfs.ext4"); $typ = "ext4"; if (!is_file($mkfs_ext4)) { $typ = "ext3"; } $ID = $ligne["container_id"]; $ContainerFullPath = $directory . "/{$ID}.disk"; if (!is_file($ContainerFullPath)) { echo "Starting......: " . date("H:i:s") . " {$ContainerFullPath} no such file\n"; } $autofs[] = "disk{$ID}\t-fstype={$typ},loop\t:{$ContainerFullPath}"; } echo "Starting......: " . date("H:i:s") . " Saving /etc/auto.members\n"; @file_put_contents("/etc/auto.members", implode("\n", $autofs) . "\n"); @unlink("/etc/init.d/artica-containers"); patch_auto_master(); shell_exec("/etc/init.d/autofs reload"); $unix = new unix(); $php5 = $unix->LOCATE_PHP5_BIN(); $SquidPerformance = intval($sock->GET_INFO("SquidPerformance")); shell_exec("{$php5} /usr/share/artica-postfix/exec.initslapd.php --iscsi"); if (is_file("/etc/init.d/iscsitarget")) { $unix->THREAD_COMMAND_SET("/etc/init.d/iscsitarget restart"); } Checks(true); }
function ipblocks(){ if(system_is_overloaded()){return;} include_once(dirname(__FILE__) . '/ressources/class.mysql.inc'); $unix=new unix(); $php=$unix->LOCATE_PHP5_BIN(); $nogup=$unix->find_program("nohup"); $pidfile="/etc/artica-postfix/pids/".basename(__FILE__).".".__FUNCTION__.".pid"; $pidtime="/etc/artica-postfix/pids/".basename(__FILE__).".".__FUNCTION__.".time"; $pid=@file_get_contents($pidfile); if($unix->process_exists($pid)){echo "Already running pid $pid\n";return;} $q=new mysql(); if(!$q->TABLE_EXISTS('ipblocks_db','artica_backup')){$q->BuildTables();} if(!is_file($pidtime)){ $count=$q->COUNT_ROWS("ipblocks_db", "artica_backup"); if($count==0){shell_exec(trim("$nogup /usr/share/artica-postfix/bin/artica-update --ipblocks >/dev/null 2>&1 &"));} sleep(5); @file_put_contents($pidtime, time()); } if($unix->file_time_min($pidtime)>480){ shell_exec(trim("$nogup /usr/share/artica-postfix/bin/artica-update --ipblocks >/dev/null 2>&1 &")); sleep(5); @unlink($pidtime); @file_put_contents($pidtime, time()); $unix->THREAD_COMMAND_SET("$php /usr/share/artica-postfix/exec.postfix.iptables.php --ipdeny"); } @file_put_contents($pidfile, getmypid()); foreach (glob("/var/log/artica-postfix/ipblocks/*.zone") as $filename) { $basename=basename($filename); if(!preg_match("#(.+?)\.zone#", $basename,$re)){continue;} $country=$re[1]; $datas=explode("\n", @file_get_contents($filename)); $f=true; while (list ($index, $line) = each ($datas) ){ $line=trim($line);if($line==null){continue;}if($country==null){continue;} $sql="INSERT IGNORE INTO ipblocks_db (cdir,country) VALUES('$line','$country')"; $q->QUERY_SQL($sql,"artica_backup"); if(!$q->ok){events("ipblocks:: $q->mysql_error line:".__LINE__);$f=false;break;} } if(!$f){continue;} @unlink($filename); } $file_time="/etc/artica-postfix/pids/". basename(__FILE__).".".__FUNCTION__.".time"; if($unix->file_time_min($file_time)>300){ $sql="DELETE FROM loadavg WHERE stime < DATE_SUB( NOW( ) , INTERVAL 7 DAY )"; $q->QUERY_SQL($sql,"artica_events"); @unlink($file_time); @file_put_contents($file_time, time()); } }
function restore() { $sock = new sockets(); $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; if ($GLOBALS["VERBOSE"]) { echo "PID: {$pidfile}\n"; } $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid)) { $TTL = $unix->PROCESS_TTL($pid); if ($TTL < 240) { return; } $kill = $unix->find_program("kill"); unix_system_kill_force($pid); } @file_put_contents($pidfile, getmypid()); $hostname = $unix->hostname_g(); progress(10, "{mounting}"); if (!restore_TestNas()) { system_admin_events("Mounting NAS filesystem report false", __FUNCTION__, __FILE__, __LINE__); progress(100, "{failed}"); return; } $BackupArticaRestoreNASIpaddr = $sock->GET_INFO("BackupArticaRestoreNASIpaddr"); $BackupArticaRestoreNASFolder = $sock->GET_INFO("BackupArticaRestoreNASFolder"); $BackupArticaRestoreNASUser = $sock->GET_INFO("BackupArticaRestoreNASUser"); $BackupArticaRestoreNASPassword = $sock->GET_INFO("BackupArticaRestoreNASPassword"); $BackupArticaRestoreNASFolderSource = $sock->GET_INFO("BackupArticaRestoreNASFolderSource"); $BackupArticaRestoreNetwork = $sock->GET_INFO("BackupArticaRestoreNetwork"); $mountPoint = "/mnt/BackupArticaRestoreNAS"; $BackupArticaRestoreNASFolderSource = str_replace("\\", "/", $BackupArticaRestoreNASFolderSource); $sourceDir = "{$mountPoint}/{$BackupArticaRestoreNASFolderSource}"; $sourceDir = str_replace("//", "/", $sourceDir); if (!is_file("{$sourceDir}/BKVERSION.txt")) { progress(100, "{failed} BKVERSION.txt no such file"); $mount = new mount("/var/log/artica-postfix/backup.debug"); if ($mount->ismounted($mountPoint)) { $mount->umount($mountPoint); } return; } $time = trim(@file_get_contents("{$sourceDir}/BKVERSION.txt")); progress(15, "{backup} " . date("Y-m-d H:i:s")); progress(20, "{restoring_ldap_database}, {please_wait}..."); Restore_ldap($sourceDir); progress(40, "{restoring_artica_settings}, {please_wait}..."); restore_artica_settings($sourceDir); progress(50, "{restoring_artica_databases}, {please_wait}..."); restore_artica_backup($sourceDir); progress(60, "{restoring_artica_databases}, {please_wait}..."); restore_ocsweb($sourceDir); progress(80, "{restoring_artica_databases}, {please_wait}..."); restore_squidlogs($sourceDir); progress(82, "{restoring} PowerDNS, {please_wait}..."); restore_powerdns($sourceDir); progress(90, "{reconfigure_server}, {please_wait}..."); $squidbin = $unix->LOCATE_SQUID_BIN(); $php = $unix->LOCATE_PHP5_BIN(); if (is_file($squidbin)) { shell_exec("{$php} /usr/share/artica-postfix/exec.squid.php --build --force"); } progress(100, "{success}"); $mount = new mount("/var/log/artica-postfix/backup.debug"); if ($mount->ismounted($mountPoint)) { $mount->umount($mountPoint); } if ($BackupArticaRestoreNetwork == 1) { $unix->THREAD_COMMAND_SET("{$php} /usr/share/artica-postfix/exec.virtuals-ip.php --build"); } return; }
function changemysqldir($dir) { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/squiddbstart.pid"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Already task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); initd(); $dirCMD = $unix->shellEscapeChars($dir); if ($dir == "/opt/squidsql/data") { return; } @mkdir($dir, 0755, true); echo "Stopping Squid-db"; shell_exec("/etc/init.d/squid-db stop"); $Size = $unix->DIRSIZE_BYTES("/opt/squidsql/data"); echo "Copy /home/zarafa-db content to next dir size={$Size}"; $cp = $unix->find_program("cp"); $rm = $unix->find_program("rm"); $ln = $unix->find_program("ln"); shell_exec("{$cp} -rf /opt/squidsql/data/* {$dirCMD}/"); $Size2 = $unix->DIRSIZE_BYTES($dir); if ($Size2 < $Size) { echo "Copy error {$Size2} is less than original size ({$Size})\n"; } echo "Removing old data\n"; shell_exec("{$rm} -rf /opt/squidsql/data"); echo "Create a new symbolic link...\n"; shell_exec("{$ln} -s {$dirCMD} /opt/squidsql/data"); echo "Starting MySQL database engine...\n"; shell_exec("/etc/init.d/squid-db start"); $unix->THREAD_COMMAND_SET($unix->LOCATE_PHP5_BIN() . " " . __FILE__ . " --databasesize"); }
function clients() { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . "pid"; $pid = @file_get_contents($pidfile); if ($unix->process_exists($pid)) { echo "Already process exists {$pid}\n"; return; } $iscsiadm = $unix->find_program("iscsiadm"); if (!is_file($iscsiadm)) { if ($GLOBALS["VERBOSE"]) { echo "{$GLOBALS["deflog_start"]} iscsiadm no such file\n"; } return; } @file_put_contents($pidfile, getmypid()); $f[] = "node.startup = automatic"; $f[] = "#node.session.auth.authmethod = CHAP"; $f[] = "#node.session.auth.username = username"; $f[] = "#node.session.auth.password = password"; $f[] = "#node.session.auth.username_in = username_in"; $f[] = "#node.session.auth.password_in = password_in"; $f[] = "#discovery.sendtargets.auth.authmethod = CHAP"; $f[] = "#discovery.sendtargets.auth.username = username"; $f[] = "#discovery.sendtargets.auth.password = password"; $f[] = "#discovery.sendtargets.auth.username_in = username_in"; $f[] = "#discovery.sendtargets.auth.password_in = password_in"; $f[] = "node.session.timeo.replacement_timeout = 120"; $f[] = "node.conn[0].timeo.login_timeout = 15"; $f[] = "node.conn[0].timeo.logout_timeout = 15"; $f[] = "node.conn[0].timeo.noop_out_interval = 10"; $f[] = "node.conn[0].timeo.noop_out_timeout = 15"; $f[] = "node.session.initial_login_retry_max = 4"; $f[] = "#node.session.iscsi.InitialR2T = Yes"; $f[] = "node.session.iscsi.InitialR2T = No"; $f[] = "#node.session.iscsi.ImmediateData = No"; $f[] = "node.session.iscsi.ImmediateData = Yes"; $f[] = "node.session.iscsi.FirstBurstLength = 262144"; $f[] = "node.session.iscsi.MaxBurstLength = 16776192"; $f[] = "node.conn[0].iscsi.MaxRecvDataSegmentLength = 131072"; $f[] = "discovery.sendtargets.iscsi.MaxRecvDataSegmentLength = 32768"; $f[] = "#node.conn[0].iscsi.HeaderDigest = CRC32C,None"; $f[] = "#node.conn[0].iscsi.DataDigest = CRC32C,None"; $f[] = "#node.conn[0].iscsi.HeaderDigest = None,CRC32C"; $f[] = "#node.conn[0].iscsi.DataDigest = None,CRC32C"; $f[] = "#node.conn[0].iscsi.HeaderDigest = CRC32C"; $f[] = "#node.conn[0].iscsi.DataDigest = CRC32C"; $f[] = "#node.conn[0].iscsi.HeaderDigest = None"; $f[] = "#node.conn[0].iscsi.DataDigest = None"; $f[] = ""; @file_put_contents("/etc/iscsi/iscsid.conf", @implode("\n", $f)); $sql = "SELECT * FROM iscsi_client"; if ($GLOBALS["VERBOSE"]) { echo "{$GLOBALS["deflog_start"]} iscsiadm {$sql}\n"; } $q = new mysql(); $results = $q->QUERY_SQL($sql, 'artica_backup'); if (!$q->ok) { echo "{$GLOBALS["deflog_start"]} iscsiadm {$q->mysql_error}\n"; return; } if (mysql_num_rows($results) == 0) { echo "{$GLOBALS["deflog_start"]} iscsiadm no iSCSI disk connection scheduled\n"; return; } if (!$q->ok) { if ($GLOBALS["VERBOSE"]) { echo "{$GLOBALS["deflog_start"]} {$q->mysql_error}\n"; } return; } while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) { $subarray2 = unserialize(base64_decode($ligne["Params"])); $iqn = "{$subarray2["ISCSI"]}:{$subarray2["FOLDER"]}"; $port = $subarray2["PORT"]; $ip = $subarray2["IP"]; echo "{$GLOBALS["deflog_start"]} {$iqn} -> {$ip}:{$port} Auth:{$ligne["EnableAuth"]} Persistane:{$ligne["Persistante"]}\n"; if ($ligne["EnableAuth"] == 1) { $cmds[] = "{$iscsiadm} -m node --targetname {$iqn} -p {$ip}:{$port} -o update -n node.session.auth.username -v \"{$ligne["username"]}\" 2>&1"; $cmds[] = "{$iscsiadm} -m node --targetname {$iqn} -p {$ip}:{$port} -o update -n node.session.auth.password -v \"{$ligne["password"]}\" 2>&1"; } else { $cmds[] = "{$iscsiadm} -m node --targetname {$iqn} -p {$ip}:{$port} --login 2>&1"; } if ($ligne["Persistante"] == 1) { $cmds[] = "{$iscsiadm} -m node --targetname {$iqn} -p {$ip}:{$port} -o update -n node.startup -v automatic 2>&1"; } else { $cmds[] = "{$iscsiadm} -m node --targetname {$iqn} -p {$ip}:{$port} -o update -n node.startup -v manual 2>&1"; } $cmds[] = "{$iscsiadm} -m node --logoutall all 2>&1"; } if (is_array($cmds)) { while (list($num, $line) = each($cmds)) { if ($GLOBALS["VERBOSE"]) { echo "--------------------------\n{$line}\n"; } $results = array(); exec($line, $results); if ($GLOBALS["VERBOSE"]) { @implode("\n", $results); } } } if ($GLOBALS["VERBOSE"]) { echo "--------------------------\n{$iscsiadm} -m node --loginall all\n"; } shell_exec("{$iscsiadm} -m node --loginall all"); $unix->THREAD_COMMAND_SET("/usr/share/artica-postfix/bin/artica-install --usb-scan-write"); }
function reconfigure(){ if($GLOBALS["VERBOSE"]){writelogs("starting reconfigure()",__FUNCTION__,__FILE__,__LINE__);} $unix=new unix(); $sock=new sockets(); if($GLOBALS["VERBOSE"]){writelogs("->clladp()",__FUNCTION__,__FILE__,__LINE__);} $ldap=new clladp(); $smbpasswd=$unix->find_program("smbpasswd"); if($GLOBALS["VERBOSE"]){writelogs("smbpasswd=$smbpasswd -->samba()",__FUNCTION__,__FILE__,__LINE__);} $samba=new samba(); $net=$unix->LOCATE_NET_BIN_PATH(); $ldap_passwd=$ldap->ldap_password; $EnableSambaActiveDirectory=$sock->GET_INFO("EnableSambaActiveDirectory"); $EnableSambaRemoteLDAP=$sock->GET_INFO("EnableSambaRemoteLDAP"); if($EnableSambaRemoteLDAP==1){ $SambaRemoteLDAPInfos=unserialize(base64_decode($sock->GET_INFO("SambaRemoteLDAPInfos"))); $ldap_passwd=$SambaRemoteLDAPInfos["user_dn_password"]; } if($EnableSambaActiveDirectory==1){activedirectory();} CheckFilesAndDirectories(); FixsambaDomainName(); echo "Starting......: Samba building main configuration...\n"; @file_put_contents("/etc/samba/smb.conf",$samba->BuildConfig()); shell_exec("$smbpasswd -w $ldap_passwd"); SambaAudit(); fixEtcHosts(); $master_password=$samba->GetAdminPassword("administrator"); $SambaEnableEditPosixExtension=$sock->GET_INFO("SambaEnableEditPosixExtension"); if($SambaEnableEditPosixExtension==1){ $cmd="$net idmap secret {$samba->main_array["global"]["workgroup"]} \"$ldap_passwd\" >/dev/null 2>&1 &"; shell_exec($cmd); $cmd="$net idmap secret alloc \"$ldap_passwd\" >/dev/null 2>&1 &"; shell_exec($cmd); } if($EnableSambaActiveDirectory==1){kinit();} $unix->THREAD_COMMAND_SET(LOCATE_PHP5_BIN2()." ".__FILE__." --check-dirs"); $unix->THREAD_COMMAND_SET("/usr/share/artica-postfix/bin/artica-install --samba-reconfigure"); reload(); }
function start($aspid = false) { $sock = new sockets(); $unix = new unix(); $GLOBALS["CLASS_UNIX"] = $unix; if (!$aspid) { $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Already task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); } $MailArchiverEnabled = $sock->GET_INFO("MailArchiverEnabled"); $MailArchiverToMySQL = $sock->GET_INFO("MailArchiverToMySQL"); $MailArchiverToMailBox = $sock->GET_INFO("MailArchiverToMailBox"); $MailArchiverMailBox = $sock->GET_INFO("MailArchiverMailBox"); $MailArchiverUsePerl = $sock->GET_INFO("MailArchiverUsePerl"); if (!is_numeric($MailArchiverEnabled)) { $MailArchiverEnabled = 0; } if (!is_numeric($MailArchiverToMySQL)) { $MailArchiverToMySQL = 1; } if (!is_numeric($MailArchiverUsePerl)) { $MailArchiverUsePerl = 1; } if ($GLOBALS["VERBOSE"]) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: VERBOSE MODE\n"; } } if ($MailArchiverEnabled == 0) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Mail Archiver is disabled...\n"; } return; } if ($MailArchiverUsePerl == 0) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Mail Archiver (Perl method) is disabled...\n"; } return; } $pid = mailarchive_pid(); if ($unix->process_exists($pid)) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Mail Archiver (Perl method) already running pid {$pid} since {$time}mn...\n"; } return; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Mail Archiver (Perl method)...\n"; } $usersMenus = new usersMenus(); $OS = $usersMenus->LinuxDistriCode; if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Mail Archiver (Perl method) on {$OS}...\n"; } if ($OS == "DEBIAN" or $OS == "UBUNTU") { CheckPerlDebian(); } $mhonarc = $unix->find_program("mhonarc"); if (!is_file($mhonarc)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Mail Archiver (Perl method) failed mhonarc not such binary !!!\n"; } return; } $nohup = $unix->find_program("nohup"); @mkdir("/var/spool/mail-rtt-backup", 0755, true); @mkdir("/var/run/maildump", 0777, true); @unlink("/var/run/maildump/maildump.socket"); $cmd = "{$nohup} /usr/share/artica-postfix/bin/milter_archiver.pl >/dev/null 2>&1 &"; shell_exec($cmd); for ($i = 0; $i < 5; $i++) { sleep(1); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Mail Archiver (Perl method) waiting {$i}/5...\n"; } $pid = mailarchive_pid(); if ($unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Mail Archiver (Perl method) Success running with pid {$pid}...\n"; } break; } } $pid = mailarchive_pid(); if ($unix->process_exists($pid)) { for ($i = 0; $i < 5; $i++) { if ($unix->is_socket("/var/run/maildump/maildump.socket")) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Mail Archiver permission on maildump.socket done\n"; } @chmod("/var/run/maildump/maildump.socket", 0777); break; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Mail Archiver waiting socket {$i}/5...\n"; } sleep(1); } $unix->THREAD_COMMAND_SET("/etc/init.d/artica-status restart --force"); } else { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Mail Archiver (Perl method) failed to start..\n"; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$cmd}\n"; } } }
function install($filename) { $GLOBALS["PROGRESS_FILE"] = "/usr/share/artica-postfix/ressources/logs/artica.install.progress"; $GLOBALS["LOG_FILE"] = "/usr/share/artica-postfix/ressources/logs/web/artica.install.progress.txt"; $unix = new unix(); $LINUX_CODE_NAME = $unix->LINUX_CODE_NAME(); $LINUX_DISTRIBUTION = $unix->LINUX_DISTRIBUTION(); $LINUX_VERS = $unix->LINUX_VERS(); $LINUX_ARCHITECTURE = $unix->LINUX_ARCHITECTURE(); $APACHEUSER = $unix->APACHE_SRC_ACCOUNT(); $DebianVer = "debian{$LINUX_VERS[0]}"; $TMP_DIR = $unix->TEMP_DIR(); $ORGV = @file_get_contents("/usr/share/artica-postfix/VERSION"); $PATCH_VER = null; $tarballs_file = "/usr/share/artica-postfix/ressources/conf/upload/{$filename}"; echo "Package {$tarballs_file}\n"; $size = filesize($tarballs_file); ArticaMeta_release($tarballs_file); if (preg_match('#([0-9\\.]+)_([0-9\\.]+)-([0-9]+).tgz$#i', $filename, $r)) { $CUR_BRANCH = @file_get_contents("/usr/share/artica-postfix/MAIN_RELEASE"); $CUR_BRANCH = trim($CUR_BRANCH); echo "Patch....................: {$r[3]}\n"; echo "From.....................: {$r[1]}\n"; echo "To.......................: {$r[2]}\n"; echo "Current Branch..........: {$CUR_BRANCH}\n"; if ($CUR_BRANCH != $r[1]) { echo "{$CUR_BRANCH} != {$r[1]}\n"; build_progress("{not_for_current_branch} {requested} {$r[1]}", 110); return; } $PATCH_VER = $r[2] . " :"; $ASPATCH = true; } echo "Size....................: " . FormatBytes($size / 1024) . "\n"; echo "Current version.........: {$ORGV}\n"; build_progress("{analyze}...", 10); echo "Current system..........: {$LINUX_CODE_NAME} {$LINUX_DISTRIBUTION} {$LINUX_VERS[0]}/{$LINUX_VERS[1]} {$LINUX_ARCHITECTURE}\n"; echo "Package.................: {$filename}\n"; echo "Temp dir................: {$TMP_DIR}\n"; echo "Apache User.............: {$APACHEUSER}\n"; if (!is_file($tarballs_file)) { echo "{$tarballs_file} no such file...\n"; build_progress("No such file...", 110); return; } echo "Uncompressing {$tarballs_file}...\n"; build_progress("{extracting} {$filename}...", 20); $chown = $unix->find_program("chown"); $chmod = $unix->find_program("chmod"); $tar = $unix->find_program("tar"); $rm = $unix->find_program("rm"); $nohup = $unix->find_program("nohup"); $php = $unix->LOCATE_PHP5_BIN(); $squid = $unix->LOCATE_SQUID_BIN(); build_progress("{extracting} {$filename}...", 50); system("{$tar} xpf {$tarballs_file} -C /usr/share/"); echo "Removing {$tarballs_file}...\n"; @unlink($tarballs_file); shell_exec("{$rm} -rf /usr/share/artica-postfix/ressources/conf/upload/*"); build_progress("{apply_permissions}...", 55); echo "{$APACHEUSER} -> /usr/share/artica-postfix\n"; shell_exec("{$chown} -R {$APACHEUSER} /usr/share/artica-postfix"); echo "0755 -> /usr/share/artica-postfix\n"; shell_exec("{$chmod} -R 0755 /usr/share/artica-postfix"); $ORGD = @file_get_contents("/usr/share/artica-postfix/VERSION"); echo "Old version.............: {$ORGV}\n"; if ($ASPATCH) { $patched = " (patched)"; } echo "Current version.........: {$ORGD}{$patched}\n"; sleep(2); if ($ORGV == $ORGD) { build_progress("{operation_failed} Same version {$PATCH_VER}{$filename}...", 110); return; } build_progress("{restarting} Artica...", 60); $unix->THREAD_COMMAND_SET("{$php} /usr/share/artica-postfix/exec.web-community-filter.php --register"); build_progress("{restarting} Artica...", 65); build_progress("{building_init_scripts}...", 70); system("{$php} /usr/share/artica-postfix/exec.initslapd.php"); build_progress("{updating_network}...", 75); system("{$php} /usr/share/artica-postfix/exec.virtuals-ip.php"); system("{$php} /usr/share/artica-postfix/exec.monit.php --build"); echo "Starting......: " . date("H:i:s") . " Purge and clean....\n"; build_progress("{restarting} Artica...", 80); if (is_file("/etc/init.d/nginx")) { shell_exec("{$nohup} /etc/init.d/nginx reload >/dev/null 2>&1 &"); } build_progress("{restarting} Artica...", 81); shell_exec("{$nohup} /etc/init.d/auth-tail restart"); build_progress("{restarting} Artica...", 82); shell_exec("{$nohup} /etc/init.d/artica-framework"); build_progress("{restarting} Artica...", 83); shell_exec("{$nohup} /usr/share/artica-postfix/bin/process1 --force --verbose " . time() . ""); build_progress("{restarting} Artica...", 84); shell_exec("{$nohup} /usr/share/artica-postfix/bin/artica-make --empty-cache >/dev/null 2>&1 &"); build_progress("{restarting} Artica...", 85); shell_exec("{$nohup} /etc/init.d/monit restart >/dev/null 2>&1 &"); build_progress("{restarting} Artica...", 86); shell_exec("{$nohup} /etc/init.d/artica-status restart --force >/dev/null 2>&1 &"); build_progress("{restarting} Artica...", 87); shell_exec("{$nohup} {$php} /usr/share/artica-postfix/exec.squid.php --build-schedules >/dev/null 2>&1 &"); build_progress("{restarting} Artica...", 88); shell_exec("{$nohup} {$php} /usr/share/artica-postfix/exec.schedules.php --defaults >/dev/null 2>&1 &"); build_progress("{restarting} Artica...", 90); build_progress("{restarting} Artica...", 100); echo "Starting......: " . date("H:i:s") . " Done you can close the screen....\n"; }
function DisksStatus($aspid = false) { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pidTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time"; if (!$aspid) { $pid = @file_get_contents("{$pidfile}"); if ($unix->process_exists($pid, basename(__FILE__))) { return; } $pidTime = $unix->file_time_min($pidTime); if ($pidTime < 5) { return; } } @unlink($pidTime); @file_put_contents($pidTime, getmypid()); @file_put_contents($pidfile, getmypid()); if (system_is_overloaded()) { $php5 = $unix->LOCATE_PHP5_BIN(); $unix->THREAD_COMMAND_SET("{$php5} " . __FILE__ . " --disks"); return; } $q = new mysql_squid_builder(); if (!$q->TABLE_EXISTS('webfilters_dbstats')) { $sql = "CREATE TABLE IF NOT EXISTS `webfilters_dbstats` (\n\t\t\t\t `category` varchar(128) NOT NULL PRIMARY KEY,\n\t\t\t\t `articasize` BIGINT UNSIGNED NOT NULL,\n\t\t\t\t `unitoulouse` BIGINT UNSIGNED NOT NULL,\n\t\t\t\t `persosize` BIGINT UNSIGNED NOT NULL,\n\t\t\t\t KEY `articasize` (`articasize`),KEY `unitoulouse` (`unitoulouse`), KEY `persosize` (`persosize`) ) ENGINE = MYISAM;"; $q->QUERY_SQL($sql); } $unix = new unix(); if ($GLOBALS["VERBOSE"]) { echo "-> /var/lib/ftpunivtlse1fr\n"; } $dirs = $unix->dirdir("/var/lib/ftpunivtlse1fr"); while (list($a, $dir) = each($dirs)) { if (!is_file("{$dir}/domains.ufdb")) { continue; } $size = filesize("{$dir}/domains.ufdb"); $category = basename($dir); $category = $q->filaname_tocat($category); $array[$category]["UNIV"] = $size; } $dirs = $unix->dirdir("/var/lib/squidguard"); while (list($a, $dir) = each($dirs)) { if (!is_file("{$dir}/domains.ufdb")) { continue; } $size = filesize("{$dir}/domains.ufdb"); $category = basename($dir); $category = $q->filaname_tocat($category); $array[$category]["PERSO"] = $size; } $dirs = $unix->dirdir("/var/lib/ufdbartica"); while (list($a, $dir) = each($dirs)) { if (!is_file("{$dir}/domains.ufdb")) { continue; } $size = filesize("{$dir}/domains.ufdb"); $category = basename($dir); $category = $q->filaname_tocat($category); $array[$category]["ARTICA"] = $size; } while (list($category, $sizes) = each($array)) { if (!isset($sizes["UNIV"])) { $sizes["UNIV"] = 0; } if (!isset($sizes["ARTICA"])) { $sizes["ARTICA"] = 0; } if (!isset($sizes["PERSO"])) { $sizes["PERSO"] = 0; } $f[] = "('{$category}','{$sizes["ARTICA"]}','{$sizes["UNIV"]}','{$sizes["PERSO"]}')"; } if (count($f) > 0) { $q->QUERY_SQL("TRUNCATE TABLE webfilters_dbstats"); $q->QUERY_SQL("INSERT IGNORE INTO webfilters_dbstats (category,articasize,unitoulouse,persosize) VALUES " . @implode(",", $f)); } }
function restart_lighttpd() { $unix = new unix(); $unix->THREAD_COMMAND_SET("/etc/init.d/artica-postfix restart apache"); }
function instance_delete() { $instance_id = $_GET["instance_id"]; $pidfile = "/var/run/mysqld/mysqld{$instance_id}.pid"; $ini = new iniFrameWork("/etc/mysql-multi.cnf"); $database_path = $ini->get("mysqld{$instance_id}", "datadir"); $unix = new unix(); if (is_file("/usr/sbin/mysqlmulti-start{$instance_id}")) { @unlink("/usr/sbin/mysqlmulti-start{$instance_id}"); } if (is_file("/usr/sbin/mysqlmulti-stop{$instance_id}")) { @unlink("/usr/sbin/mysqlmulti-stop{$instance_id}"); } if (is_file("/etc/monit/conf.d/mysqlmulti{$instance_id}.monitrc")) { @unlink("/etc/monit/conf.d/mysqlmulti{$instance_id}.monitrc"); } $unix->THREAD_COMMAND_SET("/usr/share/artica-postfix/bin/artica-install --monit-check"); $rm = $unix->find_program("rm"); $kill = $unix->find_program("kill"); $php5 = $unix->LOCATE_PHP5_BIN(); $pid = $unix->get_pid_from_file($pidfile); writelogs_framework("{$pidfile} -> {$pid}", __FUNCTION__, __FILE__, __LINE__); if ($unix->process_exists($pid)) { $cmd = "{$kill} -9 {$pid}"; writelogs_framework("{$cmd}", __FUNCTION__, __FILE__, __LINE__); shell_exec($cmd); } writelogs_framework("database path -> '{$database_path}'", __FUNCTION__, __FILE__, __LINE__); if (is_dir($database_path)) { $cmd = "{$rm} -rf \"{$database_path}\" 2>&1"; writelogs_framework("{$cmd}", __FUNCTION__, __FILE__, __LINE__); shell_exec($cmd); } $cmd = "{$php5} /usr/share/artica-postfix/exec.mysql.build.php --multi"; writelogs_framework("{$cmd}", __FUNCTION__, __FILE__, __LINE__); shell_exec($cmd); }
function Execute() { build_progress("Executing", 5); if (!ifMustBeExecuted()) { if ($GLOBALS["VERBOSE"]) { echo "No make sense to execute this script...\n"; } while (list($filename, $line) = each($GLOBALS["ifMustBeExecuted"])) { ufdbevents("ifMustBeExecuted:: {$line}"); } build_progress("No make sense to execute this script", 110); die; } $timeFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time"; $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $unix = new unix(); $StandardTime = 240; $sock = new sockets(); $kill = $unix->find_program("kill"); $pid = @file_get_contents($pidfile); if ($unix->process_exists($pid, __FILE__)) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($time > 240) { unix_system_kill_force($pid); } } if ($unix->process_exists($pid, __FILE__)) { return; } @file_put_contents($pidfile, getmypid()); $CategoriesDatabasesByCron = $sock->GET_INFO("CategoriesDatabaseByCron"); if (!is_numeric($CategoriesDatabasesByCron)) { $CategoriesDatabasesByCron = 1; } if (!$GLOBALS["FORCE"]) { if ($CategoriesDatabasesByCron == 1) { if ($GLOBALS["VERBOSE"]) { echo "Execute():: Only bycron, aborting...\n"; } if (!$GLOBALS["BYCRON"]) { build_progress("Not executed by CRON.. Aborting", 110); return; } } } if (!$GLOBALS["FORCE"]) { if (!$GLOBALS["BYCRON"]) { $timeFile = $unix->file_time_min($timeFile); if ($timeFile < $StandardTime) { build_progress("{$timeFile}mn < {$StandardTime}Mn, aborting...use --force ", 110); if ($GLOBALS["VERBOSE"]) { echo "Execute():: {$timeFile}mn < {$StandardTime}Mn, aborting...use --force to bypass\n"; } return; } } } @unlink($timeFile); @file_put_contents($timeFile, time()); $sock = new sockets(); $EnableArticaMetaClient = intval($sock->GET_INFO("EnableArticaMetaClient")); if ($EnableArticaMetaClient == 1) { build_progress("Using Artica Meta server", 10); return artica_meta_client(); } $BASE_URI = "ftp://ftp.univ-tlse1.fr/pub/reseau/cache/squidguard_contrib"; $myFile = basename(__FILE__); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $cachetime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".{$GLOBALS["SCHEDULE_ID"]}.time"; $unix = new unix(); $ufdbGenTable = $unix->find_program("ufdbGenTable"); $kill = $unix->find_program("kill"); $pid = @file_get_contents($pidfile); $getmypid = $GLOBALS["MYPID"]; if (!$GLOBALS["FORCE"]) { if ($unix->process_exists($pid, $myFile)) { $timePid = $unix->PROCCESS_TIME_MIN($pid); if ($timePid < 60) { build_progress("Already running PID {$pid}", 110); die; } else { unix_system_kill_force($pid); } } } @file_put_contents($pidfile, $getmypid); if ($GLOBALS["VERBOSE"]) { echo "Executed pid {$getmypid}\n"; } if ($GLOBALS["VERBOSE"]) { echo "ufdbGenTable:{$ufdbGenTable}\n"; } $sock = new sockets(); $SquidDatabasesUtlseEnable = $sock->GET_INFO("SquidDatabasesUtlseEnable"); if (!is_numeric($SquidDatabasesUtlseEnable)) { $SquidDatabasesUtlseEnable = 1; } if ($SquidDatabasesUtlseEnable == 0) { build_progress("{database_disabled}", 110); update_progress(100, "{database_disabled}"); echo "Toulouse university is disabled\n"; artica_update_event(2, "Toulouse university is disabled, aborting", null, __FILE__, __LINE__); } if (!$GLOBALS["FORCE"]) { $time = $unix->file_time_min($cachetime); if ($time < 120) { $q = new mysql_squid_builder(); if ($q->COUNT_ROWS("univtlse1fr") == 0) { BuildDatabaseStatus(); } ufdbevents("{$cachetime}: {$time}Mn need 120Mn"); echo "{$cachetime}: {$time}Mn need 120Mn\n"; die; } } @unlink($cachetime); @file_put_contents($cachetime, time()); $q = new mysql_squid_builder(); $results = $q->QUERY_SQL("SELECT * FROM ftpunivtlse1fr"); if (!$q->ok) { if (strpos($q->mysql_error, "doesn't exist") > 0) { $q->CheckTables(); $results = $q->QUERY_SQL("SELECT * FROM ftpunivtlse1fr"); } } if (!$q->ok) { ufdbevents("Fatal: {$q->mysql_error}"); ufdbguard_admin_events("Fatal: {$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "Toulouse DB"); } while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) { $ARRAYSUM_LOCALE[$ligne["filename"]] = $ligne["zmd5"]; } $STATUS = unserialize(@file_get_contents("/etc/artica-postfix/TLSE_LAST_DOWNLOAD")); $STATUS["LAST_CHECK"] = time(); @file_put_contents("/etc/artica-postfix/TLSE_LAST_DOWNLOAD", serialize($STATUS)); if (!isset($GLOBALS["UFDB_COUNT_OF_DOWNLOADED"])) { $GLOBALS["UFDB_COUNT_OF_DOWNLOADED"] = 0; } build_progress("Check MD5", 10); $ARRAYSUM_REMOTE = GET_MD5S_REMOTE(); $TOT = count($ARRAYSUM_REMOTE); $c = 0; $start = 15; while (list($filename, $md5) = each($ARRAYSUM_REMOTE)) { $c++; $prc = round($c / $TOT * 100); update_progress($c, $filename); if (!isset($ARRAYSUM_LOCALE[$filename])) { $ARRAYSUM_LOCALE[$filename] = null; } if ($ARRAYSUM_LOCALE[$filename] != $md5) { $size = FormatBytes($GLOBALS["UFDB_SIZE"] / 1024); if ($prc < 15) { build_progress("Downloading {$filename} ({$size})", 15); $prclog = 15; } if ($prc > 15) { if ($prc < 80) { build_progress("Downloading {$filename} ({$size})", $prc); $prclog = $prc; } if ($prc > 79) { build_progress("Downloading {$filename} ({$size})", 79); $prclog = 79; } } update_remote_file($BASE_URI, $filename, $md5, $prclog); } } if (count($GLOBALS["squid_admin_mysql"])) { $UFDB_SIZE = FormatBytes($GLOBALS["UFDB_SIZE"] / 1024); build_progress(count($GLOBALS["squid_admin_mysql"]) . " downloaded items - {$UFDB_SIZE}", 80); artica_update_event(2, count($GLOBALS["squid_admin_mysql"]) . " downloaded items - {$UFDB_SIZE} - Webfiltering Toulouse Databases updated", @implode("\n", $GLOBALS["squid_admin_mysql"]), __FILE__, __LINE__); unset($GLOBALS["squid_admin_mysql"]); } build_progress("{done}", 85); update_progress(100, "{done}"); build_progress("CoherenceOffiels()", 85); CoherenceOffiels(); build_progress("CoherenceRepertoiresUfdb()", 90); CoherenceRepertoiresUfdb(); build_progress("BuildDatabaseStatus()", 95); BuildDatabaseStatus(); build_progress("remove_bad_files()", 98); remove_bad_files(); build_progress("{finish}", 100); if ($GLOBALS["UFDB_COUNT_OF_DOWNLOADED"] > 0) { artica_meta_server(true); } else { artica_meta_server(); } $php5 = $unix->LOCATE_PHP5_BIN(); $ufdbConvertDB = $unix->find_program("ufdbConvertDB"); if (is_file($ufdbConvertDB)) { shell_exec("{$ufdbConvertDB} /var/lib/ftpunivtlse1fr"); } if (is_dir("/var/lib/ftpunivtlse1fr")) { $chown = $unix->find_program("chown"); shell_exec("{$chown} squid:squid /var/lib/ftpunivtlse1fr"); shell_exec("{$chown} -R squid:squid /var/lib/ftpunivtlse1fr/"); } $unix->THREAD_COMMAND_SET("{$php5} /usr/share/artica-postfix/exec.squidguard.php --disks"); }
function ufdbguard_compile_schedule() { $unix = new unix(); $cmd = LOCATE_PHP5_BIN2() . " /usr/share/artica-postfix/exec.squidguard.php --ufdbguard-schedule"; writelogs_framework("{$cmd}", __FUNCTION__, __FILE__, __LINE__); $unix->THREAD_COMMAND_SET($cmd); }
function changemysqldir($dir) { $sock = new sockets(); $unix = new unix(); $pidfile = $GLOBALS["MYPID"]; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Already task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); if (substr($dir, strlen($dir) - 1, 1) == "/") { $dir = substr($dir, 0, strlen($dir) - 1); } $ArticaDBPath = $sock->GET_INFO("ArticaDBPath"); if ($ArticaDBPath == null) { $ArticaDBPath = "/opt/articatech"; } $dirCMD = $unix->shellEscapeChars($dir); if ($dir == $ArticaDBPath) { return; } @mkdir($dir, 0755, true); $sock->SET_INFO("ArticaDBPath", $dir); $Size = $unix->DIRSIZE_BYTES($ArticaDBPath); echo "Moving......: [INIT]: Copy {$ArticaDBPath} content to next dir size=`{$Size}`\nPlease wait...\n"; $cp = $unix->find_program("cp"); $rm = $unix->find_program("rm"); $nohup = $unix->find_program("nohup"); system("{$cp} -rfv {$ArticaDBPath}/* {$dirCMD}/"); $Size2 = $unix->DIRSIZE_BYTES($dir); if ($Size2 < $Size) { echo "Moving......: [INIT]: Copy error {$Size2} is less than original size ({$Size})\n"; } echo "Moving......: [INIT]: Stamp DB to {$dir}\n"; @file_put_contents("/etc/artica-postfix/settings/Daemons/ArticaDBPath", $dir); echo "Moving......: [INIT]: Restarting MySQL database engine...\n"; system("/etc/init.d/categories-db restart"); echo "Moving......: [INIT]: Removing old data\n"; shell_exec("{$nohup} {$rm} -rf {$ArticaDBPath}/* >/dev/null 2>&1 &"); $unix->THREAD_COMMAND_SET($unix->LOCATE_PHP5_BIN() . " " . __FILE__ . " --databasesize --force"); shell_exec("{$nohup} /etc/init.d/artica-status reload >/dev/null 2>&1 &"); echo "Moving......: [INIT]: DONE\n"; }
function ScanPostfixID($q) { $q = new mysql(); $unix = new unix(); $super = 0; $path = "{$GLOBALS["ARTICALOGDIR"]}/RTM"; $timefile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time"; $timesched = $unix->file_time_min($timefile); if ($timesched <= $GLOBALS["ArticaSMTPStatsTimeFrame"]) { if ($GLOBALS["VERBOSE"]) { echo "{$timesched}/{$GLOBALS["ArticaSMTPStatsTimeFrame"]} aborting\n"; } return; } if ($GLOBALS["VERBOSE"]) { echo "Scanning {$path}...\n"; } $startedAT = date("Y-m-d H:i:s"); $count = 0; if (!($handle = opendir($path))) { @mkdir($path, 0755, true); return; } $countDeFiles = 0; $KILL_THIS_QUEUE = false; while (false !== ($file = readdir($handle))) { if ($file == ".") { continue; } if ($file == "..") { continue; } $targetFile = "{$path}/{$file}"; $countDeFiles++; if ($countDeFiles > $GLOBALS["ArticaSMTPStatsMaxFiles"]) { break; } $count++; $super++; if (preg_match("#\\.id-message\$#", $file)) { $amavis[] = $file; continue; } events("ScanPostfixID():: ({$count}/{$GLOBALS["ArticaSMTPStatsMaxFiles"]})"); events("ScanPostfixID():: \"{$path}/{$file}\""); if (!preg_match("#\\.msg\$#", $file)) { continue; } if ($file == "NOQUEUE.msg") { events("ScanPostfixID():: Delete /{$path}/{$file}"); @unlink("{$path}/{$file}"); continue; } if ($KILL_THIS_QUEUE) { @unlink("/{$path}/{$file}"); continue; } if ($GLOBALS["VERBOSE"]) { echo "ArticaStatusUsleep:{$GLOBALS["ArticaStatusUsleep"]}ms\n"; } usleep($GLOBALS["ArticaStatusUsleep"]); if ($count > $GLOBALS["ArticaSMTPStatsMaxFiles"]) { events("ScanPostfixID():: Break..."); break; } if ($GLOBALS["VERBOSE"]) { echo "PostfixFullProcess -> {$targetFile}\n"; } $t1 = time(); if (!PostfixFullProcess($targetFile, $q)) { continue; } $t2 = time(); $distanceInSeconds = round(abs($t2 - $t1)); if ($GLOBALS["VERBOSE"]) { echo "PostfixFullProcess -> {$distanceInSeconds} seconds\n"; } if ($distanceInSeconds > 3) { send_email_events("Too many time parsing {$GLOBALS["ARTICALOGDIR"]}/RTM", "Processing file take more than 3s ({$distanceInSeconds}s) the realtime monitor will be kept for this queue..", "postfix"); $KILL_THIS_QUEUE = true; } SetStatus("Postfix", $GLOBALS["ArticaSMTPStatsMaxFiles"], $count, $startedAT); events("ScanPostfixID():: ({$count}/{$GLOBALS["ArticaSMTPStatsMaxFiles"]}) with a sleep of {$GLOBALS["ArticaStatusUsleep"]} microseconds line " . __LINE__); } if (is_array($amavis)) { reset($amavis); $max = count($amavis); $count = 0; while (list($num, $file) = each($amavis)) { $count = $count + 1; $super++; if (!preg_match("#\\.id-message\$#", $file)) { continue; } events("ScanPostfixID():amavis_logger(): parsing /{$path}/{$file} {$count}/{$max}"); SetStatus("amavis", $max, $count, $startedAT); amavis_logger("{$path}/{$file}"); } } $path = "/tmp/savemail-infos"; if (!($handle = opendir($path))) { @mkdir($path, 0755, true); return; } $max = $GLOBALS["ArticaSMTPStatsMaxFiles"]; $count = 0; while (false !== ($file = readdir($handle))) { if ($file == ".") { continue; } if ($file == "..") { continue; } $targetFile = "{$path}/{$file}"; $super++; events("ScanPostfixID():amavis_logger(): parsing /tmp/savemail-infos/{$file} {$count}/{$max}"); amavis_logger("/tmp/savemail-infos/{$file}"); } if ($super++ > 0) { $unix->THREAD_COMMAND_SET($unix->LOCATE_PHP5_BIN() . " /usr/share/artica-postfix/exec.postfix.vip.php"); write_syslog("Success inserting {$super} mails events in mysql database...", __FILE__); } }
function SysSyncPaquages() { $unix = new unix(); $unix->THREAD_COMMAND_SET(LOCATE_PHP5_BIN2() . " /usr/share/artica-postfix/exec.system.php --sys-paquages"); $unix->THREAD_COMMAND_SET(LOCATE_PHP5_BIN2() . " /usr/share/artica-postfix/exec.setup-center.php --force"); }
function CleanQueues() { $unix = new unix(); if (!$GLOBALS["FORCE"]) { $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $oldpid = @file_get_contents($pidfile); if ($unix->process_exists($oldpid)) { echo "CleanQueues() already executed pid {$oldpid}\n"; return; } @file_put_contents($pidfile, getmypid()); } $sql = "SELECT * FROM postqueue ORDER BY zDate"; $q = new mysql(); $results = $q->QUERY_SQL($sql, "artica_events"); if (!$q->ok) { echo $q->mysql_error . "\n"; return; } $count = mysql_num_rows($results); if ($count == 0) { if ($GLOBALS["VERBOSE"]) { echo "No line\n"; } return; } $postcat = $unix->find_program("postcat"); $c = ''; while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { $hostname = $ligne["instance"]; if ($hostname != "master") { $c = " -c /etc/postfix-{$hostname}"; } $msgid = $ligne["msgid"]; $results2 = array(); if ($GLOBALS["VERBOSE"]) { echo "Check \"{$msgid}\"\n"; } exec("{$postcat} -qh {$msgid} {$c} 2>&1", $results2); if (preg_match("#No such file#", $results2[0])) { if ($GLOBALS["VERBOSE"]) { echo "{$msgid} DIE\n"; } $sql = "DELETE FROM postqueue WHERE msgid='{$msgid}'"; $q->QUERY_SQL($sql, "artica_events"); if (!$q->ok) { if ($GLOBALS["VERBOSE"]) { echo "Error \"{$q->mysql_error}\"\n"; } } continue; } if ($GLOBALS["VERBOSE"]) { echo "{$msgid} LIVE\n"; } } $unix->THREAD_COMMAND_SET(LOCATE_PHP5_BIN2() . " /usr/share/artica-postfix/exec.postfix.vip.php --queue"); }
function UPGRADE_FROM_INTERFACE() { $unix = new unix(); $php5 = $unix->LOCATE_PHP5_BIN(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $timefile = $unix->file_time_min($pidfile); //$text,$function,$file,$line,$category,$taskid=0 system_admin_events(basename(__FILE__) . ": Already executed pid {$pid} since {$timefile} minutes.. aborting the process", __FUNCTION__, __FILE__, __LINE__, "update"); die; } //if(system_is_overloaded(basename(__FILE__))){system_admin_events("Overloaded system... aborting task...",__FUNCTION__,__FILE__,__LINE__,"system-update");die();} $aptitude = $unix->find_program("aptitude"); if (!is_file($aptitude)) { return; } //if(system_is_overloaded()){$unix->events(basename(__FILE__).": UPGRADE_FROM_INTERFACE() system is overloaded aborting");return;} $q = new mysql(); $sql = "SELECT * FROM syspackages_updt WHERE upgrade=1 AND progress<90"; $results = $q->QUERY_SQL($sql, "artica_backup"); if (mysql_num_rows($results) == 0) { return; } if (!$q->ok) { echo "<H2>{$q->mysql_error}</H2>"; } while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) { if ($ligne["package"] == null) { $q->QUERY_SQL("DELETE FROM syspackages_updt WHERE package=''"); continue; } $q->QUERY_SQL("UPDATE syspackages_updt SET progress=50 WHERE package='{$ligne["package"]}'", "artica_backup"); $results2 = array(); $cmd = "{$aptitude} --safe-resolver --allow-untrusted --allow-new-upgrades -q -y full-upgrade {$ligne["package"]} 2>&1"; exec($cmd, $results2); update_events("Results on upgrade {$ligne["package"]}\n\n" . @implode("\n", $results2), __FUNCTION__, __FILE__, __LINE__, "system-update", "system_update"); $q->QUERY_SQL("UPDATE syspackages_updt SET progress=100 WHERE package='{$ligne["package"]}'", "artica_backup"); if ($GLOBALS["VERBOSE"]) { echo "{$cmd}\n" . @implode("\n", $results2); } if (system_is_overloaded()) { $unix->events(basename(__FILE__) . ": UPGRADE_FROM_INTERFACE() system is overloaded aborting"); $unix->THREAD_COMMAND_SET("{$php5} " . __FILE__ . " --pkg-upgrade"); return; } } if (!is_file("/etc/cron.d/pkg-upgrade")) { @unlink("/etc/cron.d/pkg-upgrade"); } GetUpdates(); }
function build() { $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = @file_get_contents($pidfile); $unix = new unix(); if ($unix->process_exists($pid)) { writelogs("Already process exists pid {$pid}", __FUNCTION__, __FILE__, __LINE__); echo "Already process exists pid {$pid}\n"; return; } $mysqld = $unix->find_program("mysqld"); if (!is_file($mysqld)) { return; } @file_put_contents($pidfile, getmypid()); $q = new mysql(); $sql = "SELECT * FROM loop_disks ORDER BY `size` DESC"; $results = $q->QUERY_SQL($sql, "artica_backup"); if (!$q->ok) { echo "Starting......: " . date("H:i:s") . " Loop disks {$q->mysql_error}\n"; $unix->THREAD_COMMAND_SET($unix->LOCATE_PHP5_BIN() . " " . __FILE__); return; } while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { $path = trim($ligne["path"]); if (is_dir($path)) { $oldpath = $path; $path = $path . "/" . time() . ".disk"; $sql = "UPDATE loop_disks SET path='{$path}' WHERE `path`='{$oldpath}'"; $q->QUERY_SQL($sql, 'artica_backup'); } $size = $ligne["size"]; $maxfds = $ligne["maxfds"]; $label = $ligne["disk_name"]; writelogs("check {$path} ({$size})", __FUNCTION__, __FILE__, __LINE__); if (!stat_system($path)) { writelogs("buil_dd {$path} ({$size})", __FUNCTION__, __FILE__, __LINE__); if (!build_dd($path, $size)) { continue; } } $GetLoops = GetLoops(); if (!stat_system($path)) { writelogs("{$path} no such file", __FUNCTION__, __FILE__, __LINE__); continue; } if ($GetLoops[$path] == null) { writelogs("{$path} no such loop", __FUNCTION__, __FILE__, __LINE__); if (!build_loop($path)) { writelogs("`{$path}` unable to create loop", __FUNCTION__, __FILE__, __LINE__); continue; } writelogs("Re-check the loop list...", __FUNCTION__, __FILE__, __LINE__); $GetLoops = GetLoops(); if ($GetLoops[$path] == null) { writelogs("{$path} no such loop", __FUNCTION__, __FILE__, __LINE__); continue; } } writelogs("{$path} loop={$GetLoops[$path]}", __FUNCTION__, __FILE__, __LINE__); $sql = "UPDATE loop_disks SET loop_dev='{$GetLoops[$path]}' WHERE `path`='{$path}'"; $q->QUERY_SQL($sql, 'artica_backup'); if (!$q->ok) { echo "{$q->mysql_error}\n"; continue; } $dev = $GetLoops[$path]; echo "Starting......: " . date("H:i:s") . " {$path} is {$dev}\n"; if (!ifFileSystem($dev)) { if (!mke2fs($dev, $label, $maxfds)) { continue; } } $uuid = Getuuid($dev); echo "Starting......: " . date("H:i:s") . " {$dev} uuid={$uuid}\n"; if ($uuid == null) { continue; } $autofs = new autofs(); $autofs->uuid = $uuid; $autofs->by_uuid_addmedia($ligne["disk_name"], "auto"); $nohup = $unix->find_program("nohup"); shell_exec("{$nohup} /etc/init.d/artica-postfix autofs restart >/dev/null 2>&1 &"); } }
function orphan_delete() { $unix = new unix(); $nohup = $unix->find_program("nohup"); $zarafa_admin = $unix->find_program("zarafa-admin"); $cmd = "{$zarafa_admin} --remove-store {$_GET["zarafa-orphan-kill"]}"; writelogs_framework($cmd, __FUNCTION__, __FILE__, __LINE__); shell_exec($cmd); $php5 = $unix->LOCATE_PHP5_BIN(); $cmd = "{$php5} /usr/share/artica-postfix/exec.zarafa.build.stores.php --exoprhs --nomail"; $unix->THREAD_COMMAND_SET($cmd); }
function amavis_reload() { $sock = new sockets(); $unix = new unix(); $EnableAmavisDaemon = intval($sock->GET_INFO("EnableAmavisDaemon")); $SpamAssMilterEnabled = intval($sock->GET_INFO("SpamAssMilterEnabled")); $PHP = $unix->LOCATE_PHP5_BIN(); SPAMASSASSIN_V320(); PhishTag(); HitFreqsRuleTiming(); if ($EnableAmavisDaemon == 1) { if (!is_file("/usr/local/sbin/amavisd")) { return null; } if (!is_file("/usr/local/etc/amavisd.conf")) { return null; } $amavis = new amavis(); $amavis->CheckDKIM(); $conf = $amavis->buildconf(); @file_put_contents("/usr/local/etc/amavisd.conf", $conf); $unix->THREAD_COMMAND_SET("/usr/share/artica-postfix/bin/artica-make APP_SPAMASSASSIN_RQ"); CheckSecuritiesFolders(); $unix->send_email_events("Amavis will be reloaded", "exec.spamassassin, ordered to reload amavis {$GLOBALS["CMDLINES"]}", "postfix"); $unix->THREAD_COMMAND_SET("/usr/local/sbin/amavisd -c /usr/local/etc/amavisd.conf reload"); } if ($SpamAssMilterEnabled == 1) { echo "Starting......: " . date("H:i:s") . " Restarting SpamAssassin milter edition\n"; shell_exec("{$PHP} /usr/share/artica-postfix/exec.initslapd.php --spamass-milter"); shell_exec("/etc/init.d/spamass-milter restart"); } }
function inject_stored_items($nopid = false) { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; if (system_is_overloaded(basename(__FILE__))) { $php = $unix->LOCATE_PHP5_BIN(); ufdbguard_admin_events("Overloaded system... ask to run this task later...", __FUNCTION__, __FILE__, __LINE__, "proxy"); $unix->THREAD_COMMAND_SET("{$php} " . __FILE__ . " --inject"); } if (!$nopid) { $pid = @file_get_contents($pidfile); $myfile = basename(__FILE__); if ($unix->process_exists($pid, $myfile)) { ufdbguard_admin_events("Task already running PID: {$pid}, aborting current task", __FUNCTION__, __FILE__, __LINE__, "proxy"); return; } } $mypid = getmypid(); @file_put_contents($pidfile, $mypid); $t1 = time(); $file = "/var/cache/purge.calculated.db"; if (!is_file($file)) { echo "{$file} no such file\n"; return; } $q = new mysql_blackbox(); if (!$q->TABLE_EXISTS("cacheitems_localhost")) { $q->build_cached_items_table("localhost"); } $BIGARRAY = inject_stored_array(); $prefix = "INSERT IGNORE INTO cacheitems_localhost(sitename,familysite,size,items) VALUES "; $q->QUERY_SQL("TRUNCATE TABLE cacheitems_localhost"); $f = array(); $c = 0; while (list($sitename, $array) = each($BIGARRAY)) { $c++; $f[] = "('{$sitename}','{$array["FAMILY"]}','{$array["SIZE"]}','{$array["ITEMS"]}')"; if (count($f) > 500) { $q->QUERY_SQL($prefix . @implode(",", $f)); if (!$q->ok) { squid_admin_mysql(0, "MySQL error!", $q->mysql_error, __FILE__, __LINE__); return; } } } if (count($f) > 0) { $q->QUERY_SQL($prefix . @implode(",", $f)); if (!$q->ok) { squid_admin_mysql(0, "MySQL error!", $q->mysql_error, __FILE__, __LINE__); return; } } $took = $unix->distanceOfTimeInWords($t1, time()); if ($c > 0) { squid_admin_mysql(2, "Sucess adding {$c} cached websites took:{$took}", null, __FILE__, __LINE__); } @unlink($file); }