function start($aspid = false) { $unix = new unix(); $sock = new sockets(); $Masterbin = $unix->find_program("clamd"); if (!is_file($Masterbin)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, clamd not installed\n"; } return; } 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]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); } $pid = PID_NUM(); if ($unix->process_exists($pid)) { $timepid = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Service already started {$pid} since {$timepid}Mn...\n"; } return; } $EnableClamavDaemon = $sock->EnableClamavDaemon(); if ($EnableClamavDaemon == 0) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service disabled (see sock->EnableClamavDaemon)\n"; } return; } $php5 = $unix->LOCATE_PHP5_BIN(); $nohup = $unix->find_program("nohup"); $aa_complain = $unix->find_program('aa-complain'); if (is_file($aa_complain)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} add clamd Profile to AppArmor..\n"; } shell_exec("{$aa_complain} {$Masterbin} >/dev/null 2>&1"); } @mkdir("/var/clamav", 0755, true); @mkdir("/var/run/clamav", 0755, true); @mkdir("/var/lib/clamav", 0755, true); @mkdir("/var/log/clamav", 0755, true); $unix->chown_func("clamav", "clamav", "/var/clamav"); $unix->chown_func("clamav", "clamav", "/var/run/clamav"); $unix->chown_func("clamav", "clamav", "/var/lib/clamav"); $unix->chown_func("clamav", "clamav", "/var/log/clamav"); $clamd_version = clamd_version(); $cmd = "{$nohup} {$Masterbin} --config-file=/etc/clamav/clamd.conf >/dev/null 2>&1 &"; if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service version {$clamd_version}\n"; } shell_exec($cmd); for ($i = 1; $i < 5; $i++) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} waiting {$i}/5\n"; } sleep(1); $pid = PID_NUM(); if ($unix->process_exists($pid)) { break; } } $pid = PID_NUM(); if ($unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Success PID {$pid}\n"; } sleep(1); for ($i = 1; $i < 5; $i++) { if ($unix->is_socket("/var/run/clamav/clamav.sock")) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Apply permissions on clamav.sock\n"; } @chmod("/var/run/clamav/clamav.sock", 0777); break; } else { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} waiting for socket... {$i}/4\n"; } sleep(1); } } if ($unix->is_socket("/var/run/clamav/clamav.sock")) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Apply permissions on clamav.sock\n"; } @chmod("/var/run/clamav/clamav.sock", 0777); } else { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} socket failed\n"; } } } else { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Failed\n"; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} {$cmd}\n"; } } $pid = PID_NUM(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Failed..\n"; } } if (!$unix->is_socket("/var/run/clamav/clamav.sock")) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} socket Failed..\n"; } } }
function freshclam() { $bin_path = $GLOBALS["CLASS_UNIX"]->find_program("freshclam"); $EnableFreshClam = $GLOBALS["CLASS_SOCKETS"]->GET_INFO("EnableFreshClam"); $EnableClamavDaemon = $GLOBALS["CLASS_UNIX"]->EnableClamavDaemon(); if ($bin_path == null) { return null; } $pid_path = GetVersionOf("freshclam-pid"); $master_pid = freshclam_pid(); if (!is_numeric($EnableFreshClam)) { $EnableFreshClam = 0; } if (!$GLOBALS["CLASS_UNIX"]->process_exists($master_pid)) { $master_pid = $GLOBALS["CLASS_UNIX"]->PIDOF_PATTERN("{$bin_path}.*?--on-update-execute="); } $l[] = "[FRESHCLAM]"; $l[] = "service_name=APP_FRESHCLAM"; $l[] = "master_version=" . clamd_version(); $l[] = "service_cmd=/etc/init.d/clamav-freshclam"; $l[] = "service_disabled={$EnableFreshClam}"; $l[] = "pid_path={$pid_path}"; $l[] = "family=system"; $l[] = "watchdog_features=1"; $l[] = ""; if ($EnableFreshClam == 0) { if ($GLOBALS["CLASS_UNIX"]->process_exists($master_pid)) { if (!$GLOBALS["DISABLE_WATCHDOG"]) { if ($GLOBALS["CLASS_UNIX"]->PROCCESS_TIME_MIN($master_pid) > 120) { squid_admin_mysql(1, "Stopping Clamav Daemon Updater (not enabled)", null, __FILE__, __LINE__); $cmd = trim("{$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} " . dirname(__FILE__) . "/exec.freshclam.php --stop >/dev/null 2>&1 &"); shell_exec2($cmd); } } } } if (!$GLOBALS["CLASS_UNIX"]->process_exists($master_pid)) { if ($GLOBALS["CLASS_UNIX"]->process_exists($master_pid)) { if (!$GLOBALS["DISABLE_WATCHDOG"]) { squid_admin_mysql(0, "Clamav Daemon Updater stopped [action=start]", null, __FILE__, __LINE__); $cmd = trim("{$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} " . dirname(__FILE__) . "/exec.freshclam.php --start >/dev/null 2>&1 &"); shell_exec2($cmd); } } $l[] = ""; return implode("\n", $l); } $l[] = GetMemoriesOf($master_pid); $l[] = ""; return implode("\n", $l); return; }
function start($aspid = false) { $unix = new unix(); $sock = new sockets(); $Masterbin = $unix->find_program("clamav-milter"); if (!is_file($Masterbin)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, clamav-milter not installed\n"; } return; } 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]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n"; } return false; } @file_put_contents($pidfile, getmypid()); } $pid = PID_NUM(); if ($unix->process_exists($pid)) { $timepid = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Service already started {$pid} since {$timepid}Mn...\n"; } return true; } $ClamavMilterEnabled = intval($sock->GET_INFO("ClamavMilterEnabled")); $MimeDefangClamav = intval($sock->GET_INFO("MimeDefangClamav")); $MimeDefangEnabled = intval($sock->GET_INFO("MimeDefangEnabled")); if ($MimeDefangEnabled == 0) { $MimeDefangClamav = 0; } if ($MimeDefangClamav == 1) { $ClamavMilterEnabled = 0; } if ($ClamavMilterEnabled == 0) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service disabled (see ClamavMilterEnabled/MimeDefangEnabled/MimeDefangClamav)\n"; } return false; } $php5 = $unix->LOCATE_PHP5_BIN(); $nohup = $unix->find_program("nohup"); build_progress_restart("{starting_service}", 31); $aa_complain = $unix->find_program('aa-complain'); if (is_file($aa_complain)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} add clamd Profile to AppArmor..\n"; } shell_exec("{$aa_complain} {$Masterbin} >/dev/null 2>&1"); } @mkdir("/var/clamav", 0755, true); @mkdir("/var/run/clamav", 0755, true); @mkdir("/var/lib/clamav", 0755, true); @mkdir("/var/log/clamav", 0755, true); $ClamUser = "******"; $squidbin = $unix->LOCATE_SQUID_BIN(); if (is_file($squidbin)) { $ClamUser = "******"; } $unix->chown_func("{$ClamUser}", "{$ClamUser}", "/var/clamav"); $unix->chown_func("{$ClamUser}", "{$ClamUser}", "/var/run/clamav"); $unix->chown_func("{$ClamUser}", "{$ClamUser}", "/var/lib/clamav"); $unix->chown_func("{$ClamUser}", "{$ClamUser}", "/var/log/clamav"); build_progress_restart("{starting_service}", 32); $clamd_version = clamd_version(); build(); $cmd = "{$nohup} {$Masterbin} --config-file=/etc/clamav/clamav-milter.conf >/dev/null 2>&1 &"; if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service version {$clamd_version}\n"; } build_progress_restart("{starting_service} (clamd) ", 33); system("/etc/init.d/clamav-daemon start"); shell_exec($cmd); for ($i = 1; $i < 5; $i++) { build_progress_restart("{starting_service}", 35); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} waiting {$i}/5\n"; } sleep(1); $pid = PID_NUM(); if ($unix->process_exists($pid)) { break; } } $pid = PID_NUM(); if ($unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Success PID {$pid}\n"; } sleep(1); for ($i = 1; $i < 11; $i++) { build_progress_restart("{starting_service}", 40); if ($unix->is_socket("/var/spool/postfix/var/run/clamav/clamav-milter.ctl")) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Apply permissions on clamav-milter.ctl\n"; } @chmod("/var/spool/postfix/var/run/clamav/clamav-milter.ctl", 0777); break; } else { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} waiting for socket... {$i}/10 clamav-milter.ctl\n"; } sleep(1); } } if ($unix->is_socket("/var/spool/postfix/var/run/clamav/clamav-milter.ctl")) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Apply permissions on clamav-milter.ctl\n"; } @chmod("/var/spool/postfix/var/run/clamav/clamav-milter.ctl", 0777); } else { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} socket failed\n"; } } } else { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Failed\n"; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} {$cmd}\n"; } build_progress_restart("{starting_service} {failed}", 40); return; } $pid = PID_NUM(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Failed..\n"; } build_progress_restart("{starting_service} {failed}", 40); return; } if (!$unix->is_socket("/var/spool/postfix/var/run/clamav/clamav-milter.ctl")) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} socket Failed..\n"; } } return true; }
function freshclam() { $bin_path = $GLOBALS["CLASS_UNIX"]->find_program("freshclam"); $EnableFreshClam = $GLOBALS["CLASS_SOCKETS"]->GET_INFO("EnableFreshClam"); $EnableClamavDaemon = $GLOBALS["CLASS_UNIX"]->EnableClamavDaemon(); if ($bin_path == null) { return null; } $pid_path = GetVersionOf("freshclam-pid"); $master_pid = trim(@file_get_contents($pid_path)); $EnableClamavDaemon = $GLOBALS["CLASS_SOCKETS"]->EnableClamavDaemon(); if (!is_numeric($EnableClamavDaemon)) { $EnableClamavDaemon = 0; } if (!is_numeric($EnableFreshClam)) { $EnableFreshClam = 0; } if ($GLOBALS["VERBOSE"]) { echo "EnableClamavDaemon = {$EnableClamavDaemon}\n"; echo "EnableFreshClam = {$EnableFreshClam}\n"; } if (!$GLOBALS["CLASS_UNIX"]->process_exists($master_pid)) { $master_pid = $GLOBALS["CLASS_UNIX"]->PIDOF($bin_path); } $l[] = "[FRESHCLAM]"; $l[] = "service_name=APP_FRESHCLAM"; $l[] = "master_version=" . clamd_version(); $l[] = "service_cmd=freshclam"; $l[] = "service_disabled={$EnableFreshClam}"; $l[] = "pid_path={$pid_path}"; $l[] = "family=system"; $l[] = "watchdog_features=1"; $l[] = ""; if ($EnableClamavDaemon == 0) { if ($GLOBALS["CLASS_UNIX"]->process_exists($master_pid)) { if (!$GLOBALS["DISABLE_WATCHDOG"]) { $cmd = trim("{$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} " . dirname(__FILE__) . "/exec.freshclam.php --stop >/dev/null 2>&1 &"); shell_exec2($cmd); } } } if ($EnableClamavDaemon == 1) { if ($GLOBALS["CLASS_UNIX"]->process_exists($master_pid)) { $l[] = GetMemoriesOf($master_pid); $l[] = ""; return implode("\n", $l); } if (!system_is_overloaded(basename(__FILE__))) { $TimeEx = $GLOBALS["CLASS_UNIX"]->file_time_min("/var/run/clamav/scheduled.time"); if ($TimeEx > 120) { $cmd = trim("{$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} " . dirname(__FILE__) . "/exec.freshclam.php --exec >/dev/null 2>&1 &"); shell_exec2($cmd); } } return implode("\n", $l); } if (!$GLOBALS["CLASS_UNIX"]->process_exists($master_pid)) { if ($GLOBALS["CLASS_UNIX"]->process_exists($master_pid)) { if (!$GLOBALS["DISABLE_WATCHDOG"]) { $cmd = trim("{$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} " . dirname(__FILE__) . "/exec.freshclam.php --start >/dev/null 2>&1 &"); shell_exec2($cmd); } } $l[] = ""; return implode("\n", $l); } $l[] = GetMemoriesOf($master_pid); $l[] = ""; return implode("\n", $l); return; }