function install_key($keyfile) { $path = "/usr/share/artica-postfix/ressources/conf/upload/{$keyfile}"; $license_bin = "/opt/kaspersky/kav4proxy/bin/kav4proxy-licensemanager"; $time = time(); $unix = new unix(); $pidFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = $unix->get_pid_from_file($pidFile); if ($unix->process_exists($pid)) { if ($unix->PROCCESS_TIME_MIN($pid, 10) < 2) { progress("{failed} Already running", 110); echo "Already runinng PID {$pid}\n"; return; } } echo "License....: {$path}\n"; echo "Binary File: {$license_bin}\n"; if (!is_file($path)) { echo "{$path} No such file..\n"; progress("{failed} {$keyfile} No such file", 110); die; } if (!is_file($license_bin)) { echo "{$path} No such file..\n"; progress("{failed} " . basename($license_bin) . " No such binary", 110); @unlink($path); die; } $sock = new sockets(); $nohup = $unix->find_program("nohup"); $sock->SET_INFO("kavicapserverEnabled", 1); @unlink("/etc/artica-postfix/kav4proxy-licensemanager"); @unlink("/etc/artica-postfix/kav4proxy-licensemanager-i"); progress("{removing_old_licenses}", 20); system("/opt/kaspersky/kav4proxy/bin/kav4proxy-licensemanager -d a"); progress("{installing} {$keyfile}", 30); $cmd = "/opt/kaspersky/kav4proxy/bin/kav4proxy-licensemanager -c /etc/opt/kaspersky/kav4proxy.conf -a {$path}"; system($cmd); @unlink($path); progress("{analyze_license} {$keyfile}", 50); shell_exec("/opt/kaspersky/kav4proxy/bin/kav4proxy-licensemanager -i >/etc/artica-postfix/kav4proxy-licensemanager-i 2>&1"); progress("{stopping_service}", 60); echo "/etc/init.d/kav4proxy stop\n"; system("/etc/init.d/kav4proxy stop"); progress("{starting_service}", 60); echo "/etc/init.d/kav4proxy start\n"; system("{$nohup} /etc/init.d/kav4proxy start >/dev/null 2>&1 &"); system("{$nohup} /etc/init.d/artica-status restart --force >/dev/null 2>&1 &"); progress("{launch_updates}", 70); $nohup = $unix->find_program("nohup"); $php = $unix - LOCATE_PHP5_BIN(); sleep(2); progress("{launch_updates}", 80); shell_exec("{$nohup} /usr/share/artica-postfix/exec.keepup2date.php --update --force >/dev/null 2>&1 &"); sleep(3); progress("{success}", 100); }
function SaveGlobal() { $samba = new samba(); $shared_name = $_GET["ShareName"]; $php5 = LOCATE_PHP5_BIN(); $folder_name = $samba->GetShareName("/media/{$_GET["uuid"]}"); if ($folder_name == null) { $samba->main_array["{$shared_name}"]["path"] = "/media/{$_GET["uuid"]}"; $samba->main_array["{$shared_name}"]["create mask"] = "0777"; $samba->main_array["{$shared_name}"]["directory mask"] = "0777"; $samba->main_array["{$shared_name}"]["root preexec"] = "{$php5} /usr/share/artica-postfix/exec.samba.php --usb-mount {$_GET["uuid"]} %u"; $samba->main_array["{$shared_name}"]["root postexec"] = "{$php5} /usr/share/artica-postfix/exec.samba.php --usb-umount {$_GET["uuid"]} %u"; $samba->main_array["{$shared_name}"]["root preexec close"] = "yes"; $samba->SaveToLdap(); } else { $samba->main_array["{$folder_name}"]["path"] = "/media/{$_GET["uuid"]}"; $samba->main_array["{$folder_name}"]["create mask"] = "0777"; $samba->main_array["{$folder_name}"]["directory mask"] = "0777"; $samba->main_array["{$folder_name}"]["root preexec"] = "{$php5} /usr/share/artica-postfix/exec.samba.php --usb-mount {$_GET["uuid"]} %u"; $samba->main_array["{$folder_name}"]["root postexec"] = "{$php5} /usr/share/artica-postfix/exec.samba.php --usb-umount {$_GET["uuid"]} %u"; $samba->main_array["{$folder_name}"]["root preexec close"] = "yes"; $samba->SaveToLdap(); } }
function VirtualBoxList() { if ($GLOBALS["VERBOSE"]) { echo "starting analyze VirtualBox machines...\n"; } $users = new usersMenus(); if (!$users->VIRTUALBOX_INSTALLED) { events("Virtualbox not installed...", __FUNCTION__, __FILE__, __LINE__); if ($GLOBALS["VERBOSE"]) { echo "terminated... (" . __LINE__ . ")\n"; } return null; } $sock = new sockets(); $array = unserialize(base64_decode($sock->getFrameWork("cmd.php?virtualbox-list-vms=yes"))); if (!is_array($array)) { events("Not an array", __FUNCTION__, __FILE__, __LINE__); if ($GLOBALS["VERBOSE"]) { echo "terminated... (" . __LINE__ . ")\n"; } return; } while (list($vboxname, $vboxArray) = each($array)) { if ($GLOBALS["VERBOSE"]) { echo "check {$vboxname} (" . __LINE__ . ")\n"; } $CPUSTATS = unserialize(base64_decode($sock->getFrameWork("cmd.php?virtualbox-showcpustats=yes&virtual-machine=" . base64_encode($vboxname)))); $array[$vboxname]["METRICS"] = $CPUSTATS; } reset($array); $EXEC_NICE = EXEC_NICE(); if (is_file("/usr/bin/nohup")) { $nohup = "/usr/bin/nohup "; } $cmd = $nohup . $EXEC_NICE . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --export-virtualbox-logs >/dev/null 2>&1 &"; shell_exec($cmd); return base64_encode(serialize($array)); }
function buildcron() { $unix = new unix(); $path = "/etc/cron.d"; $sql = "SELECT * FROM backup_schedules ORDER BY ID DESC"; $q = new mysql(); $results = $q->QUERY_SQL($sql, "artica_backup"); if (!$q->ok) { return null; } $files = $unix->DirFiles("/etc/cron.d"); while (list($num, $filename) = each($files)) { if (preg_match("#artica-backup-([0-9]+)\$#", $filename)) { echo "Starting......: " . date("H:i:s") . " Backup remove {$filename}\n"; @unlink("{$path}/{$filename}"); } } while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { $schedule = $ligne["schedule"]; echo "Starting......: " . date("H:i:s") . " Backup {$schedule}\n"; $f[] = "{$schedule} " . LOCATE_PHP5_BIN() . " " . __FILE__ . " {$ligne["ID"]} >/dev/null 2>&1"; } @file_put_contents("/etc/artica-postfix/backup.tasks", @implode("\n", $f)); if (!$GLOBALS["NO_RELOAD"]) { system("/etc/init.d/artica-postfix restart daemon"); } }
function DNS_DEL_ENTRY($value) { $hostname = base64_decode($value); $EXEC_NICE = EXEC_NICE(); if (is_file("/usr/bin/nohup")) { $nohup = "/usr/bin/nohup "; } $reload_datas = $nohup . $EXEC_NICE . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --export-all-dns >/dev/null 2>&1 &"; include_once dirname(__FILE__) . "/ressources/class.pdns.inc"; $ldap = new clladp(); $upd = array(); $tbl = explode(".", $hostname); $dc = "dc=" . @implode(",dc=", $tbl); if ($ldap->ExistsDN("{$dc},ou=dns,{$ldap->suffix}")) { if ($ldap->ldap_delete("{$dc},ou=dns,{$ldap->suffix}", true)) { send_email_events("Success deleting DNS entry {$hostname}", "DN removed was : {$dc},ou=dns,{$ldap->suffix}", "CLOUD"); return true; } } else { events("unable to stat {$dc},ou=dns,{$ldap->suffix}", __FUNCTION__, __FILE__, __LINE__); } $suffix = "ou=dns,{$ldap->suffix}"; $pattern = "(&(objectclass=*)(associatedDomain={$hostname}))"; $sr = @ldap_search($ldap->ldap_connection, $suffix, "{$pattern}", array()); if ($sr) { $hash = ldap_get_entries($ldap->ldap_connection, $sr); for ($i = 0; $i < $hash["count"]; $i++) { $dn = $hash[$i]["dn"]; if (strlen($dn) > 0) { $dns[] = $dn; events("removing associateddomain={$hostname} in {$dn}", __FUNCTION__, __FILE__, __LINE__); $upd["associateddomain"] = $hostname; if (!$ldap->Ldap_del_mod($dn, $upd)) { $dns[] = $ldap->ldap_last_error; } } } send_email_events("Success executing remove DNS entry {$hostname}", @implode("\n", $dns), "CLOUD"); return true; } events("Failed -> notify", __FUNCTION__, __FILE__, __LINE__); send_email_events("Failed remove DNS entry {$hostname} does not exists", null, "CLOUD"); shell_exec($reload_datas); return true; }
function set_computer_schedules(){ writelogs("set_computer_schedules:: starting",__FUNCTION__,__FILE__,__LINE__); $ldap=new clladp(); $pattern="(&(objectClass=ArticaComputerInfos)(ComputerScanSchedule=*))"; $attr=array("cn","ComputerScanSchedule","uid"); $sr =@ldap_search($ldap->ldap_connection,$ldap->suffix,$pattern,$attr); if(!$sr){ events("set_computer_schedules():: $ldap->ldap_last_error line: ".__LINE__); return false; } $hash=ldap_get_entries($ldap->ldap_connection,$sr); for($i=0;$i<$hash["count"];$i++){ $uid=$hash[$i]["uid"][0]; $computerscanschedule=$hash[$i]["computerscanschedule"][0]; $filename="$uid"; $filename=str_replace('.','',$filename); $filename=str_replace('$','',$filename); $filename=str_replace(' ','',$filename); $filename=str_replace('-','',$filename); $filename=str_replace('_','',$filename); sys_CRON_CREATE_SCHEDULE($computerscanschedule,LOCATE_PHP5_BIN()." ".__FILE__." $uid","artica-av-$filename"); } }
function set_computer_schedules() { if (is_file("/etc/artica-postfix/KASPERSKY_WEB_APPLIANCE")) { die; } $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = @file_get_contents($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { writelogs("set_computer_schedules:: already {$pid} running, die", __FUNCTION__, __FILE__, __LINE__); die; } writelogs("set_computer_schedules:: starting", __FUNCTION__, __FILE__, __LINE__); $ldap = new clladp(); $pattern = "(&(objectClass=ArticaComputerInfos)(ComputerScanSchedule=*))"; $attr = array("cn", "ComputerScanSchedule", "uid"); $sr = @ldap_search($ldap->ldap_connection, $ldap->suffix, $pattern, $attr); if (!$sr) { events("set_computer_schedules():: {$ldap->ldap_last_error} line: " . __LINE__); return false; } $hash = ldap_get_entries($ldap->ldap_connection, $sr); for ($i = 0; $i < $hash["count"]; $i++) { $uid = $hash[$i]["uid"][0]; $computerscanschedule = $hash[$i]["computerscanschedule"][0]; $filename = "{$uid}"; $filename = str_replace('.', '', $filename); $filename = str_replace('$', '', $filename); $filename = str_replace(' ', '', $filename); $filename = str_replace('-', '', $filename); $filename = str_replace('_', '', $filename); sys_CRON_CREATE_SCHEDULE($computerscanschedule, LOCATE_PHP5_BIN() . " " . __FILE__ . " {$uid}", "artica-av-{$filename}"); } }
$GLOBALS["cpuLimitEnabled"] = true; } else { $GLOBALS["cpuLimitEnabled"] = false; } $GLOBALS["OVERLOADED"] = system_is_overloaded(); if ($GLOBALS["OVERLOADED"]) { writelogs("This system is overloaded", __FUNCTION__, __FILE__, __LINE__); if ($GLOBALS["cpuLimitEnabled"]) { if (GET_INFO_DAEMON("cpulimit") > 0) { shell_exec("/usr/share/artica-postfix/bin/process1 --cpulimit"); } } } $dirname = dirname(__FILE__); $_GET["NICE"] = EXEC_NICE(); $_GET["PHP5"] = LOCATE_PHP5_BIN(); $users = new usersMenus(); $sock = new sockets(); $GLOBALS["SQUID_INSTALLED"] = $users->SQUID_INSTALLED; $GLOBALS["POSTFIX_INSTALLED"] = $users->POSTFIX_INSTALLED; $GLOBALS["SAMBA_INSTALLED"] = $users->SAMBA_INSTALLED; $_GET["MIME_DEFANGINSTALLED"] = $users->MIMEDEFANG_INSTALLED; $GLOBALS["DANSGUARDIAN_INSTALLED"] = $users->DANSGUARDIAN_INSTALLED; $GLOBALS["KAS_INSTALLED"] = $users->kas_installed; if ($GLOBALS["VERBOSE"]) { writelogs("DANSGUARDIAN_INSTALLED={$GLOBALS["DANSGUARDIAN_INSTALLED"]}", "MAIN", __FILE__, __LINE__); } $GLOBALS["EnableArticaWatchDog"] = GET_INFO_DAEMON("EnableArticaWatchDog"); if ($GLOBALS["VERBOSE"]) { if ($GLOBALS["POSTFIX_INSTALLED"]) { events("Postfix is installed...");
function ParseEvents() { ParseReboot(); $unix = new unix(); $path = "/var/log/artica-postfix/events"; $f = new filesClasses(); $hash = $f->DirListTable($path); if (!is_array($hash)) { return null; } $users = new usersMenus(); $sock = new sockets(); $ArticaMetaEnabled = $sock->GET_INFO("ArticaMetaEnabled"); echo date('Y-m-d h:i:s') . " " . count($hash) . " file(s) notifications...\n"; events(count($hash) . " file(s) notifications..."); if (count($hash) == 0) { return; } if ($ArticaMetaEnabled == 1) { $meta = new artica_meta(); $datasToSend = base64_encode(serialize($meta->GLOBAL_ARRAY)); $ArticaMetaHostname = $meta->ArticaMetaHostname; events("ArticaMetaEnabled: \"{$ArticaMetaEnabled}\" -> ({$ArticaMetaHostname})"); } $mysql = new mysql(); while (list($num, $file) = each($hash)) { $text = null; $processname = null; $date = null; $context = null; $subject = null; $recipient = null; $FULL_PATH = "{$path}/{$file}"; if ($unix->file_time_min($FULL_PATH) > 480) { @unlink($FULL_PATH); continue; } $bigtext = @file_get_contents($FULL_PATH); echo date('Y-m-d h:i:s') . " Parsing {$file} " . strlen($bigtext) . " bytes text\n"; $ini = new Bs_IniHandler(); if (preg_match("#<text>(.+?)</text>#is", $bigtext, $re)) { $text = $re[1]; $bigtext = str_replace($re[0], '', $bigtext); $bigtext = str_replace("'", "`", $bigtext); } if (preg_match("#<attachedfiles>(.+?)</attachedfiles>#is", $bigtext, $re)) { $bigtext = str_replace($re[0], '', $bigtext); $files_text = addslashes($re[1]); } $ini->loadString($bigtext); $processname = $ini->_params["LOG"]["processname"]; $date = $ini->_params["LOG"]["date"]; $context = $ini->_params["LOG"]["context"]; if ($context == "YTowOnt9") { $context = "system"; } $subject = $ini->_params["LOG"]["subject"]; $recipient = $ini->_params["LOG"]["recipient"]; if (strlen($text) < 2) { $text = $ini->_params["LOG"]["text"]; } $arrayToSend["context"] = $context; $arrayToSend["subject"] = $subject; $arrayToSend["text"] = $text; $arrayToSend["date"] = $date; echo date('Y-m-d h:i:s') . " Parsing subject {$subject} " . strlen($text) . " bytes text\n"; writelogs("New notification: {$subject} (" . strlen($text) . " bytes) {$date}", __FUNCTION__, __FILE__, __LINE__); $event_id = time(); //$text=addslashes($text); $text = str_replace("'", "`", $text); $subject = str_replace("'", "`", $subject); $text = addslashes($text); $subject = addslashes($subject); if ($subject == null) { if (strlen($text) > 5) { if (strpos($text, "\n") == 0) { $subject = $text; } else { $subject = substr($text, 0, 75) . "..."; } } } if (strlen($subject) < 5) { writelogs("Warning New notification: Subject seems to be empty ! \"{$text}\" removing {$path}/{$file}", __FUNCTION__, __FILE__, __LINE__); @unlink("{$path}/{$file}"); continue; } if (strpos($users->hostname, ".") > 0) { $ty = explode($users->hostname, "."); $users->hostname = $ty[0]; } if (strlen($text) < 5) { $text = "No content body as been added for this notification"; } $sql = "INSERT IGNORE INTO events (zDate,hostname,process,text,context,content,attached_files,recipient,event_id) VALUES(\n \t'{$date}',\n \t'{$users->hostname}',\n \t'{$processname}',\n \t'{$subject}',\n \t'{$context}','{$text}','{$files_text}','{$recipient}','{$event_id}')"; if (!$mysql->UseMysql) { $sql = "INSERT IGNORE INTO events (id,zDate,hostname,\n \tprocess,text,context,content,attached_files,recipient,event_id) VALUES(\n \t'{$event_id}','{$date}',\n \t'{$users->hostname}',\n \t'{$processname}',\n \t'{$subject}',\n \t'{$context}','{$text}','{$files_text}','{$recipient}','{$event_id}')"; } events(date('Y-m-d h:i:s') . " run mysql query -> {$subject}"); if (!$mysql->QUERY_SQL($sql, 'artica_events')) { events("Mysql error keep {$path}/{$file};"); events("Fatal: {$mysql->mysql_error}", __FUNCTION__, __FILE__, __LINE__); if (preg_match("#Access denied for user.+?using password:#", $mysql->mysql_error)) { events("Access denied for user password: {$mysql->mysql_server}@{$mysql->mysql_admin}:{$mysql->mysql_password} detected"); if ($mysql->mysql_server == "127.0.0.1" or $mysql->mysql_server == "localhost") { $ldap = new clladp(); $unix = new unix(); $ldap->ldap_password = $unix->shellEscapeChars($ldap->ldap_password); writelogs("Try to change the mysql password: /usr/share/artica-postfix/bin/artica-install --change-mysqlroot --inline root \"secret\"", __FUNCTION__, __FILE__, __LINE__); exec("/usr/share/artica-postfix/bin/artica-install --change-mysqlroot --inline root \"secret\" 2>&1", $chroot); writelogs("Chaning password="******"\n", $chroot), __FUNCTION__, __FILE__, __LINE__); die; } } if (preg_match("#Unknown column#", $mysql->mysql_error)) { events("->BuildTables()"); $mysql->BuildTables(); } if (preg_match("#Unknown database#", $mysql->mysql_error)) { events("->BuildTables()"); $mysql->BuildTables(); } if (preg_match("#connect to local MySQL server through socket#", $mysql->mysql_error)) { shell_exec("/etc/init.d/artica-postfix start mysql &"); } writelogs("{$sql}", __FUNCTION__, __FILE__, __LINE__); break; } unlink($path . '/' . $file); if ($ArticaMetaEnabled == 1) { $pidfile = "/etc/artica-postfix/pids/exec.artica.meta.php.SendStatus.pid"; $sock = new sockets(); $ArticaMetaPoolTimeMin = $sock->GET_INFO("ArticaMetaPoolTimeMin"); if (!is_numeric($ArticaMetaPoolTimeMin)) { $ArticaMetaPoolTimeMin = 15; } if ($ArticaMetaPoolTimeMin < 2) { $ArticaMetaPoolTimeMin = 15; } $minutes = file_time_min($pidfile); if ($minutes < round($ArticaMetaPoolTimeMin / 2.5)) { $meta->events(basename($pidfile) . ":{$minutes}<" . round($ArticaMetaPoolTimeMin / 2.5) . "Mn, aborting", __FUNCTION__, __FILE__, __LINE__); return; } $http = new httpget(); $meta->events("Send notification \"{$arrayToSend["subject"]}\" to Meta Server", __FUNCTION__, __FILE__, __LINE__); $metaconsole = $http->send("{$ArticaMetaHostname}/lic.status.notifs.php", "post", array("DATAS" => $datasToSend, "NOTIF" => base64_encode(serialize($arrayToSend)))); events("META CONSOLE: {$metaconsole} aborting notifications"); if ($metaconsole == "FAILED_CONNECT") { $meta->events("Result:\"{$metaconsole}\"", __FUNCTION__, __FILE__, __LINE__); return; } if (!is_file("/etc/artica-postfix/artica-meta.tasks")) { if (preg_match("#<TASKS>(.+?)</TASKS>#is", $metaconsole, $re)) { $meta->events("Save tasks to /etc/artica-postfix/artica-meta.tasks", __FUNCTION__, __FILE__, __LINE__); @file_put_contents("/etc/artica-postfix/artica-meta.tasks", $re[1]); $cmd = LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.tasks.php >/dev/null 2>&1 &"; $meta->events("TASKS ->{$cmd}", __FUNCTION__, __FILE__, __LINE__); shell_exec($cmd); } } } $text = addslashes($text); $context = addslashes($context); $subject = addslashes($subject); } if (count($hash) > 0) { events(count($hash) . " events queue parsed..."); } if ($ArticaMetaEnabled == 1) { if (is_file("/etc/artica-postfix/artica-meta.tasks")) { $NICE = EXEC_NICE(); shell_exec($NICE . LOCATE_PHP5_BIN2() . " " . dirname(__FILE__) . "/exec.artica.meta.tasks.php &"); } } }
function UPGRADE() { $unix = new unix(); $tmpf = $unix->FILE_TEMP(); $txt = "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin\n"; $txt = $txt . "echo \$PATH >{$tmpf} 2>&1\n"; $txt = $txt . "rm -f {$tmpf}\n"; $tmpf = $unix->FILE_TEMP(); @file_put_contents($tmpf, $txt); @chmod($tmpf, '0777'); shell_exec($tmpf); $tmpf = $unix->FILE_TEMP(); $cmd = "DEBIAN_FRONTEND=noninteractive {$_GET["APT-GET"]} -o Dpkg::Options::=\"--force-confnew\" --force-yes update >{$tmpf} 2>&1"; writelogs($cmd, __FUNCTION__, __FILE__, __LINE__); shell_exec($cmd); $cmd = "DEBIAN_FRONTEND=noninteractive {$_GET["APT-GET"]} -o Dpkg::Options::=\"--force-confnew\" --force-yes --yes install -f >{$tmpf} 2>&1"; writelogs($cmd, __FUNCTION__, __FILE__, __LINE__); shell_exec($cmd); $cmd = "DEBIAN_FRONTEND=noninteractive {$_GET["APT-GET"]} -o Dpkg::Options::=\"--force-confnew\" --force-yes --yes upgrade >>{$tmpf} 2>&1"; writelogs($cmd, __FUNCTION__, __FILE__, __LINE__); shell_exec($cmd); $datas = @file_get_contents($tmpf); $datassql = addslashes($datas); $q = new mysql(); $sql = "INSERT INTO debian_packages_logs(zDate,package_name,events,install_type) VALUES(NOW(),'artica-upgrade','{$datassql}','upgrade');"; $q->QUERY_SQL($sql, "artica_backup"); @unlink('/etc/artica-postfix/apt.upgrade.cache'); send_email_events("Debian/Ubuntu System upgrade operation", $datas, "system"); INSERT_DEB_PACKAGES(); THREAD_COMMAND_SET(LOCATE_PHP5_BIN() . " /usr/share/artica-postfix/exec.admin.status.postfix.flow.php --services"); }
function build(){ CheckHttpdConf(); RemoveAllSites(); create_cron_task(); $sock=new sockets(); $unix=new unix(); $varWwwPerms=$sock->GET_INFO("varWwwPerms"); if($varWwwPerms==null){$varWwwPerms=755;} remove_files(); $sql="SELECT * FROM freeweb ORDER BY servername"; $httpdconf=$unix->LOCATE_APACHE_CONF_PATH(); $apacheusername=$unix->APACHE_SRC_ACCOUNT(); $GLOBALS["apacheusername"]=$apacheusername; $DAEMON_PATH=$unix->getmodpathfromconf($httpdconf); $q=new mysql(); $results=$q->QUERY_SQL($sql,'artica_backup'); if(!$q->ok){if($GLOBALS["VERBOSE"]){echo $q->mysql_error."\n";return;}} $d_path=$unix->APACHE_DIR_SITES_ENABLED(); $mods_enabled=$DAEMON_PATH."/mods-enabled"; echo "Starting......: Apache daemon path: $d_path\n"; echo "Starting......: Apache mods path..: $mods_enabled\n"; if(!is_dir($d_path)){@mkdir($d_path,666,true);} if(!is_dir($mods_enabled)){@mkdir($mods_enabled,666,true);} $count=mysql_num_rows($results); echo "Starting......: Apache checking virtual web sites count:$count\n"; if($count==0){ $users=new usersMenus(); echo "Starting......: Apache building default $users->hostname...\n"; buildHost($unix->LIGHTTPD_USER(),$users->hostname,0,$d_path); } while($ligne=mysql_fetch_array($results,MYSQL_ASSOC)){ $uid=$ligne["uid"]; $hostname=$ligne["servername"]; $ssl=$ligne["useSSL"]; echo "Starting......: Apache \"$hostname\" starting \n"; buildHost($uid,$hostname,$ssl,$d_path); } $users=$GLOBALS["CLASS_USERS_MENUS"]; $APACHE_MOD_AUTHNZ_LDAP=$users->APACHE_MOD_AUTHNZ_LDAP; if(is_file($GLOBALS["a2enmod"])){ if($APACHE_MOD_AUTHNZ_LDAP){ if($GLOBALS["VERBOSE"]){echo "Starting......: Apache {$GLOBALS["a2enmod"]} authnz_ldap\n";} shell_exec("{$GLOBALS["a2enmod"]} authnz_ldap >/dev/null 2>&1"); } } $sock=$GLOBALS["CLASS_SOCKETS"]; if($sock->GET_INFO("ArticaMetaEnabled")==1){ sys_THREAD_COMMAND_SET(LOCATE_PHP5_BIN()." ".dirname(__FILE__)."/exec.artica.meta.users.php --export-freewebs"); } }
function memory() { $unix = new unix(); $sock = new sockets(); if ($GLOBALS["VERBOSE"]) { $cmd_verbose = " --verbose"; } $PostFixEnableQueueInMemory = $sock->GET_INFO("PostFixEnableQueueInMemory"); $PostFixQueueInMemory = $sock->GET_INFO("PostFixQueueInMemory"); $directory = "/var/spool/postfix"; if ($PostFixEnableQueueInMemory == 1) { echo "Starting......: Postfix Queue in memory is enabled for {$PostFixQueueInMemory}M\n"; echo "Starting......: Postfix executing exec.postfix-multi.php\n"; shell_exec(LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.postfix-multi.php --instance-memory master {$PostFixQueueInMemory}{$cmd_verbose}"); return; } else { $MOUNTED_TMPFS_MEM = $unix->MOUNTED_TMPFS_MEM($directory); if ($MOUNTED_TMPFS_MEM > 0) { shell_exec(LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.postfix-multi.php --instance-memory-kill master{$cmd_verbose}"); return; } echo "Starting......: Postfix Queue in memory is not enabled\n"; } }
function awstats_mail() { $users = new usersMenus(); if (!$users->POSTFIX_INSTALLED) { return; } $unix = new unix(); $sock = new sockets(); $ArticaMetaEnabled = trim($sock->GET_INFO("ArticaMetaEnabled")); if (!is_numeric($ArticaMetaEnabled)) { $ArticaMetaEnabled = 0; } $EnableArticaSMTPStatistics = $sock->GET_INFO("EnableArticaSMTPStatistics"); if (!is_numeric($EnableArticaSMTPStatistics)) { $EnableArticaSMTPStatistics = 1; } $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pidTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time"; if ($EnableArticaSMTPStatistics == 0) { return; } $pid = $unix->get_pid_from_file($pidfile); if (!$GLOBALS["VERBOSE"]) { if ($unix->process_exists($pid, basename(__FILE__))) { $pidTime = $unix->PROCCESS_TIME_MIN($pid); events("Already process PID: {$pid} running since {$pidTime} minutes", __FUNCTION__, __FILE__, __LINE__, "postfix-stats"); return; } $time = $unix->file_time_min("{$pidTime}"); if ($time < 120) { events("Current {$time}mn, need 60mn"); return; } if (system_is_overloaded(basename(__FILE__))) { system_admin_events("Overloaded system, aborting", __FUNCTION__, __FILE__, __LINE__, "postfix-stats"); return; } @unlink($pidTime); @file_put_contents($pidTime, time()); @file_put_contents($pidfile, getmypid()); } $tt1 = time(); $nohup = $unix->find_program("nohup"); if (!$users->awstats_installed) { events("awstats is not installed, artica will install it itself", __FUNCTION__, __FILE__, __LINE__, "postfix-stats"); events("{$nohup} /usr/share/artica-postfix/bin/artica-make APP_AWSTATS >/dev/null &"); shell_exec(trim("{$nohup} /usr/share/artica-postfix/bin/artica-make APP_AWSTATS >/dev/null &")); return; } $sock = new sockets(); $GLOBALS["EnablePostfixMultiInstance"] = $sock->GET_INFO("EnablePostfixMultiInstance"); $GLOBALS["maillogconvert"] = $unix->LOCATE_maillogconvert(); $GLOBALS["zcat"] = $unix->find_program("zcat"); $GLOBALS["perl"] = $unix->find_program("perl"); $GLOBALS["nice"] = EXEC_NICE(); $GLOBALS["sed"] = $unix->find_program("sed"); $GLOBALS["mv"] = $unix->find_program("mv"); $GLOBALS["cp"] = $unix->find_program("cp"); $GLOBALS["touch"] = $unix->find_program("touch"); $GLOBALS["echo"] = $unix->find_program("echo"); $GLOBALS["postfix"] = $unix->find_program("postfix"); if ($GLOBALS["VERBOSE"]) { echo "maillogconvert..........:{$GLOBALS["maillogconvert"]}\n"; echo "zcat....................:{$GLOBALS["zcat"]}\n"; echo "perl....................:{$GLOBALS["perl"]}\n"; echo "nice....................:{$GLOBALS["nice"]}\n"; echo "sed.....................:{$GLOBALS["sed"]}\n"; } if (strlen($GLOBALS["maillogconvert"]) == null) { events("maillogconvert.pl, no such file", __FUNCTION__, __FILE__, __LINE__, "postfix-stats"); return; } @mkdir("/var/log/mail-backup", 666, true); foreach (glob("/var/log/mail.log.*.gz") as $filename) { events("{$GLOBALS["nice"]}{$GLOBALS["zcat"]} {$filename} >/tmp/mail.log"); shell_exec("{$GLOBALS["nice"]}{$GLOBALS["zcat"]} {$filename} >/tmp/mail.log"); $t1 = time(); prepflog("/tmp/mail.log"); $distanceOfTimeInWords = distanceOfTimeInWords($t1, time()); shell_exec("/bin/mv {$filename} /var/log/mail-backup/"); events("/bin/mv {$filename} /var/log/mail-backup/", __FUNCTION__, __FILE__, __LINE__, "postfix-stats"); events(basename($filename) . " {$distanceOfTimeInWords}"); $ev[] = basename($filename) . " " . $distanceOfTimeInWords; @unlink("/tmp/mail.log"); } foreach (glob("/var/log/mail.log.*") as $filename) { if (!preg_match("#\\.[0-9]+\$#", basename($filename))) { if ($GLOBALS["VERBOSE"]) { echo basename($filename) . " SKIP\n"; } continue; } $t1 = time(); prepflog($filename); $distanceOfTimeInWords = distanceOfTimeInWords($t1, time()); if ($GLOBALS["VERBOSE"]) { echo basename($filename) . " {$distanceOfTimeInWords}\n"; } $ev[] = basename($filename) . " " . $distanceOfTimeInWords; shell_exec("/bin/mv {$filename} /var/log/mail-backup/"); } $t1 = time(); if (is_file("/var/log/mail.log")) { $nextFile = "/var/log/mail.log." . time(); shell_exec("{$GLOBALS["cp"]} /var/log/mail.log {$nextFile}"); shell_exec("{$GLOBALS["echo"]} \"\" > /var/log/mail.log"); events("Restarting Syslogs..."); $syslog_init = $unix->RESTART_SYSLOG_FORMAIL(); prepflog($nextFile); $storelogs = new mysql_storelogs(); events("Injecting {$nextFile} to MySQL store logs"); $storelogs->InjectFile($nextFile); artica_parse(); events("reloading postfix"); shell_exec("{$GLOBALS["postfix"]} reload"); } $distanceOfTimeInWords = distanceOfTimeInWords($t1, time()); $ev[] = basename("/var/log/mail.log") . " " . $distanceOfTimeInWords; if ($GLOBALS["VERBOSE"]) { echo basename("/var/log/mail.log") . " {$distanceOfTimeInWords}\n"; } //$cmd="$nice$perl /usr/share/artica-postfix/bin/prepflog.pl </tmp/mail.log|$nice$perl $maillogconvert standard >>/var/log/artica-postfix/awstats-postfix.stats"; foreach (glob("/var/log/artica-mail/*.stats") as $filename) { if (preg_match("#(.+?)\\.([0-9]+)\\.stats#", basename($filename), $re)) { $instance = $re[1]; $time = $re[2]; $cmd = "{$GLOBALS["nice"]}{$GLOBALS["perl"]} {$GLOBALS["maillogconvert"]} standard< {$filename} >/var/log/artica-mail/{$instance}.{$time}.aws"; events($cmd); shell_exec($cmd); @unlink($filename); if (system_is_overloaded(basename(__FILE__))) { system_admin_events("Overloaded system, aborting", __FUNCTION__, __FILE__, __LINE__, "postfix-stats"); return; } } } $filecount = 0; foreach (glob("/var/log/artica-mail/*.aws") as $filename) { artica_parse($filename); $filecount++; $filecountl[] = $filename; } $distanceOfTimeInWords = distanceOfTimeInWords($tt1, time()); if ($filecount > 0) { system_admin_events("Success generating {$filecount} stats files ({$distanceOfTimeInWords})\n" . @implode("\n", $filename), __FUNCTION__, __FILE__, __LINE__, "postfix-stats"); if ($ArticaMetaEnabled == 1) { $cmd = "{$GLOBALS["nice"]}" . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --export-postfix-events >/dev/null 2>&1 &"; shell_exec($cmd); } } }
function build() { $unix = new unix(); if (is_file("/etc/artica-postfix/FROM_ISO")) { if ($unix->file_time_min("/etc/artica-postfix/FROM_ISO") < 1) { return; } } $mef = basename(__FILE__); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = @file_get_contents($pidfile); if ($unix->process_exists($pid, $mef)) { echo "Starting......: " . date("H:i:s") . " [INIT]: Apache building : Process Already exist pid {$pid} line:" . __LINE__ . "\n"; return; } @file_put_contents($pidfile, getmypid()); if ($GLOBALS["VERBOSE"]) { echo "Starting......: " . date("H:i:s") . " [DEBUG]: Apache -> CheckHttpdConf();\n"; } CheckHttpdConf(); if ($GLOBALS["VERBOSE"]) { echo "Starting......: " . date("H:i:s") . " [DEBUG]: Apache -> RemoveAllSites();\n"; } RemoveAllSites(); if ($GLOBALS["VERBOSE"]) { echo "Starting......: " . date("H:i:s") . " [DEBUG]: Apache -> create_cron_task();\n"; } create_cron_task(); sync_squid(); $sock = new sockets(); $FreeWebDisableSSL = intval(trim($sock->GET_INFO("FreeWebDisableSSL"))); $php5 = $unix->LOCATE_PHP5_BIN(); $varWwwPerms = $sock->GET_INFO("varWwwPerms"); if ($varWwwPerms == null) { $varWwwPerms = 755; } if ($GLOBALS["VERBOSE"]) { echo "Starting......: " . date("H:i:s") . " [DEBUG]: Apache -> remove_files();\n"; } remove_files(); $sql = "SELECT * FROM freeweb ORDER BY servername"; $httpdconf = $unix->LOCATE_APACHE_CONF_PATH(); $apacheusername = $unix->APACHE_SRC_ACCOUNT(); $GLOBALS["apacheusername"] = $apacheusername; $DAEMON_PATH = $unix->getmodpathfromconf($httpdconf); if ($GLOBALS["VERBOSE"]) { echo "Starting......: " . date("H:i:s") . " [DEBUG]: Apache -> sql();\n"; } $q = new mysql(); $results = $q->QUERY_SQL($sql, 'artica_backup'); if (!$q->ok) { if ($GLOBALS["VERBOSE"]) { echo "Starting......: " . date("H:i:s") . " [DEBUG]: Apache {$q->mysql_error}\n"; return; } } $d_path = $unix->APACHE_DIR_SITES_ENABLED(); $mods_enabled = $DAEMON_PATH . "/mods-enabled"; if ($FreeWebDisableSSL == 0) { SSL_DEFAULT_VIRTUAL_HOST(); } echo "Starting......: " . date("H:i:s") . " [INIT]: Apache daemon path: {$d_path}\n"; echo "Starting......: " . date("H:i:s") . " [INIT]: Apache mods path..: {$mods_enabled}\n"; if (!is_dir($d_path)) { @mkdir($d_path, 666, true); } if (!is_dir($mods_enabled)) { @mkdir($mods_enabled, 666, true); } $count = mysql_num_rows($results); echo "Starting......: " . date("H:i:s") . " [INIT]: Apache checking virtual web sites count:{$count}\n"; if ($count == 0) { $users = new usersMenus(); echo "Starting......: " . date("H:i:s") . " [INIT]: Apache building default {$users->hostname}...\n"; buildHost($unix->LIGHTTPD_USER(), $users->hostname, 0, $d_path); } if ($GLOBALS["VERBOSE"]) { $add_plus = " --verbose"; } while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) { $uid = $ligne["uid"]; $hostname = $ligne["servername"]; $ssl = $ligne["useSSL"]; if ($FreeWebDisableSSL == 1) { $ssl = 0; } echo "Starting......: " . date("H:i:s") . " [INIT]: Apache \"{$hostname}\" starting\n"; $cmd = "{$php5} " . __FILE__ . " --sitename \"{$hostname}\" --no-httpd-conf --noreload{$add_plus}"; if ($GLOBALS["VERBOSE"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Apache \"{$cmd}\"\n"; } shell_exec($cmd); } $users = $GLOBALS["CLASS_USERS_MENUS"]; $APACHE_MOD_AUTHNZ_LDAP = $users->APACHE_MOD_AUTHNZ_LDAP; if (is_file($GLOBALS["a2enmod"])) { if ($APACHE_MOD_AUTHNZ_LDAP) { if ($GLOBALS["VERBOSE"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Apache {$GLOBALS["a2enmod"]} authnz_ldap\n"; } shell_exec("{$GLOBALS["a2enmod"]} authnz_ldap >/dev/null 2>&1"); } } $sock = $GLOBALS["CLASS_SOCKETS"]; if ($sock->GET_INFO("ArticaMetaEnabled") == 1) { sys_THREAD_COMMAND_SET(LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --export-freewebs"); } sys_THREAD_COMMAND_SET(LOCATE_PHP5_BIN() . " " . __FILE__ . " --monit"); }
if ($GLOBALS["VERBOSE"]) { echo "-> ScanPostFixConnectionsErr()\n"; } ScanPostFixConnectionsErr(); if ($GLOBALS["VERBOSE"]) { echo "-> ScanVirusQueue()\n"; } ScanVirusQueue($q); CheckPostfixLogs(); ScanPostFixMysqlErr(); smtp_logs_day_users(); postqueue(); CleanQueues(); amavis_event_hour(); THREAD_COMMAND_SET(LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.last.100.mails.php"); THREAD_COMMAND_SET(LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.admin.smtp.flow.status.php"); optimizetable(); function OnlyPOstfix() { $pid = getmypid(); $pidefile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".onlypostfix.pid"; if (is_file($pidefile)) { $currentpid = trim(file_get_contents($pidefile)); if ($currentpid != $pid) { if (is_dir('/proc/' . $currentpid)) { write_syslog("Already instance executed aborting...", __FILE__); die; } } } $unix = new unix();
function awstats_mail() { $users = new usersMenus(); if (!$users->POSTFIX_INSTALLED) { return; } $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $oldpid = @file_get_contents($pidfile); if ($unix->process_exists($oldpid, basename(__FILE__))) { echo "{$oldpid} is already in memory\n"; return; } $pid = posix_getpid(); echo "running {$pid} PID\n"; @file_put_contents($pidfile, $pid); $tt1 = time(); $nohup = $unix->find_program("nohup"); if (!$users->awstats_installed) { $unix->send_email_events("awstats is not installed, artica will install it itself", $q->mysql_error, "postfix"); shell_exec(trim("{$nohup} /usr/share/artica-postfix/bin/artica-make APP_AWSTATS >/dev/null &")); return; } $sock = new sockets(); $GLOBALS["EnablePostfixMultiInstance"] = $sock->GET_INFO("EnablePostfixMultiInstance"); $GLOBALS["maillogconvert"] = $unix->LOCATE_maillogconvert(); $GLOBALS["zcat"] = $unix->find_program("zcat"); $GLOBALS["perl"] = $unix->find_program("perl"); $GLOBALS["nice"] = EXEC_NICE(); $GLOBALS["sed"] = $unix->find_program("sed"); if ($GLOBALS["VERBOSE"]) { echo "maillogconvert..........:{$GLOBALS["maillogconvert"]}\n"; echo "zcat....................:{$GLOBALS["zcat"]}\n"; echo "perl....................:{$GLOBALS["perl"]}\n"; echo "nice....................:{$GLOBALS["nice"]}\n"; echo "sed.....................:{$GLOBALS["sed"]}\n"; } if (strlen($GLOBALS["maillogconvert"]) == null) { echo "maillogconvert.pl, no such file\n"; return; } @mkdir("/var/log/mail-backup", 666, true); foreach (glob("/var/log/mail.log.*.gz") as $filename) { shell_exec("{$GLOBALS["nice"]}{$GLOBALS["zcat"]} {$filename} >/tmp/mail.log"); $t1 = time(); prepflog("/tmp/mail.log"); $distanceOfTimeInWords = distanceOfTimeInWords($t1, time()); shell_exec("/bin/mv {$filename} /var/log/mail-backup/"); if ($GLOBALS["VERBOSE"]) { echo basename($filename) . " {$distanceOfTimeInWords}\n"; } $ev[] = basename($filename) . " " . $distanceOfTimeInWords; @unlink("/tmp/mail.log"); } foreach (glob("/var/log/mail.log.*") as $filename) { if (!preg_match("#\\.[0-9]+\$#", basename($filename))) { if ($GLOBALS["VERBOSE"]) { echo basename($filename) . " SKIP\n"; } continue; } $t1 = time(); prepflog($filename); $distanceOfTimeInWords = distanceOfTimeInWords($t1, time()); if ($GLOBALS["VERBOSE"]) { echo basename($filename) . " {$distanceOfTimeInWords}\n"; } $ev[] = basename($filename) . " " . $distanceOfTimeInWords; shell_exec("/bin/mv {$filename} /var/log/mail-backup/"); } $t1 = time(); prepflog("/var/log/mail.log"); $distanceOfTimeInWords = distanceOfTimeInWords($t1, time()); $ev[] = basename("/var/log/mail.log") . " " . $distanceOfTimeInWords; if ($GLOBALS["VERBOSE"]) { echo basename("/var/log/mail.log") . " {$distanceOfTimeInWords}\n"; } //$cmd="$nice$perl /usr/share/artica-postfix/bin/prepflog.pl </tmp/mail.log|$nice$perl $maillogconvert standard >>/var/log/artica-postfix/awstats-postfix.stats"; foreach (glob("/var/log/artica-mail/*.stats") as $filename) { if (preg_match("#(.+?)\\.([0-9]+)\\.stats#", basename($filename), $re)) { $instance = $re[1]; $time = $re[2]; $cmd = "{$GLOBALS["nice"]}{$GLOBALS["perl"]} {$GLOBALS["maillogconvert"]} standard< {$filename} >/var/log/artica-mail/{$instance}.{$time}.aws"; if ($GLOBALS["VERBOSE"]) { echo "{$cmd}\n"; } shell_exec($cmd); @unlink($filename); } } $filecount = 0; foreach (glob("/var/log/artica-mail/*.aws") as $filename) { artica_parse($filename); $filecount++; $filecountl[] = $filename; } $distanceOfTimeInWords = distanceOfTimeInWords($tt1, time()); if ($filecount > 0) { $unix->send_email_events("AWSTATS:: Success generating {$filecount} stats files ({$distanceOfTimeInWords})", @implode("\n", $filename), "postfix"); $cmd = "{$GLOBALS["nice"]}" . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --export-postfix-events >/dev/null 2>&1 &"; shell_exec($cmd); } clean_maillogs(); }
function zarafa_store_error($buffer) { $file = "/etc/artica-postfix/cron.1/" . __FUNCTION__ . ".store.error"; if (file_time_min($file) < 3600) { return null; } @unlink($file); $cmd = LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.zarafa.build.stores.php"; events("{$cmd}"); $GLOBALS["CLASS_UNIX"]->THREAD_COMMAND_SET($cmd); email_events("Zarafa mailbox server store error", "Zarafa claim \"{$buffer}\" Artica will try to reactivate stores and accounts", 'mailbox'); @file_put_contents($file, "#"); }
die("Cannot be used in web server mode\n\n"); } if (!Build_pid_func(__FILE__, "MAIN")) { events(basename(__FILE__) . " Already executed.. aborting the process"); die; } $pid = getmypid(); $pidfile = "/etc/artica-postfix/" . basename(__FILE__) . ".pid"; @mkdir("/var/log/artica-postfix/xapian", 0755, true); @mkdir("/var/log/artica-postfix/infected-queue", 0755, true); events("running {$pid} "); file_put_contents($pidfile, $pid); include_once dirname(__FILE__) . '/ressources/class.ini.inc'; include_once dirname(__FILE__) . '/ressources/class.users.menus.inc'; $GLOBALS["RSYNC_RECEIVE"] = array(); $GLOBALS["LOCATE_PHP5_BIN"] = LOCATE_PHP5_BIN(); $users = new usersMenus(); $_GET["server"] = $users->hostname; $pipe = fopen("php://stdin", "r"); while (!feof($pipe)) { $buffer .= fgets($pipe, 4096); try { Parseline($buffer); } catch (Exception $e) { events("fatal error:" . $e->getMessage()); } $buffer = null; } fclose($pipe); events("Shutdown..."); die;