function BuildRules() { $unix = new unix(); $sock = new sockets(); if (system_is_overloaded(basename(__FILE__))) { system_admin_events("Overloaded system, aborting...", __FUNCTION__, __FILE__, __LINE__, "fetchmail"); die; } $EnableFetchmailScheduler = $sock->GET_INFO("EnableFetchmailScheduler"); $EnablePostfixMultiInstance = $sock->GET_INFO("EnablePostfixMultiInstance"); if (!is_numeric($EnableFetchmailScheduler)) { $EnableFetchmailScheduler = 0; } if (!is_numeric($EnablePostfixMultiInstance)) { $EnablePostfixMultiInstance = 0; } $DenyFetchMailWriteConf = $sock->GET_INFO("DenyFetchMailWriteConf"); if (!is_numeric($DenyFetchMailWriteConf)) { $DenyFetchMailWriteConf = 0; } if (!isset($GLOBALS["FetchMailGLobalDropDelivered"])) { $sock = new sockets(); $GLOBALS["FetchMailGLobalDropDelivered"] = $sock->GET_INFO("FetchMailGLobalDropDelivered"); if (!is_numeric($GLOBALS["FetchMailGLobalDropDelivered"])) { $GLOBALS["FetchMailGLobalDropDelivered"] = 0; } } if ($DenyFetchMailWriteConf == 1) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} saving configuration denied (DenyFetchMailWriteConf)\n"; return true; } @file_put_contents("/proc/sys/net/ipv4/tcp_timestamps", "0"); if ($EnableFetchmailScheduler == 1) { BuildRules_schedule(); return; } foreach (glob("/etc/cron.d/fetchmail*") as $filename) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} removing {$filename}..\n"; @unlink($filename); } $fetch = new fetchmail(); $l[] = "set logfile /var/log/fetchmail.log"; $l[] = "set daemon {$fetch->FetchmailPoolingTime}"; $l[] = "set postmaster \"{$fetch->FetchmailDaemonPostmaster}\""; $l[] = "set idfile \"/var/log/fetchmail.id\""; $l[] = ""; $sql = "SELECT * FROM fetchmail_rules WHERE enabled=1"; $q = new mysql(); $results = $q->QUERY_SQL($sql, "artica_backup"); if (!$q->ok) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} saving configuration file FAILED\n"; return false; } echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} building " . mysql_num_rows($results) . " rules...\n"; $array = array(); while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { $ID = $ligne["ID"]; $pattern = build_line($ligne); $l[] = $pattern; $GLOBALS["FETCHMAIL_RULES_ID"][$ID] = $pattern; } if ($GLOBALS["SINGLE_DEBUG"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} single-debug, aborting nex step\n"; return; } if ($EnablePostfixMultiInstance == 1) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} postfix multiple instances enabled (" . count($GLOBALS["multi_smtp"]) . ") hostnames\n"; @unlink("/etc/artica-postfix/fetchmail.schedules"); if (is_array($GLOBALS["multi_smtp"])) { if ($GLOBALS["DEBUG"]) { print_r($GLOBALS["multi_smtp"]); } while (list($hostname, $rules) = each($GLOBALS["multi_smtp"])) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} {$hostname} save rules...\n"; @file_put_contents("/etc/postfix-{$hostname}/fetchmail.rc", @implode("\n", $rules)); @chmod("/etc/postfix-{$hostname}/fetchmail.rc", 0600); $schedule[] = multi_build_schedule($hostname); if (!is_fetchmailset($hostname)) { $restart = true; } else { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} {$hostname} already scheduled...\n"; } } if ($restart) { @file_put_contents("/etc/artica-postfix/fetchmail.schedules", @implode("\n", $schedule)); system("/etc/init.d/artica-postfix restart fcron"); } } return; } if (is_file("/etc/fetchmail.perso")) { $l[] = "# fetchmail.perso content"; $l[] = "# Save a configuration file in /etc/fetchmail.perso"; $l[] = @file_get_contents("/etc/fetchmail.perso"); } if (is_array($l)) { $conf = implode("\n", $l); echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} building /etc/fetchmailrc " . count($l) . " lines\n"; } else { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} building /etc/fetchmailrc 0 lines\n"; $conf = null; } @file_put_contents("/etc/fetchmailrc", $conf); shell_exec("/bin/chmod 600 /etc/fetchmailrc"); echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} saving /etc/fetchmailrc configuration file done\n"; build_monit(); if ($GLOBALS["RELOAD"]) { if ($EnablePostfixMultiInstance == 0) { reload(); } } }
reconfigure_all_updateutility(); die; exit; } if ($argv[1] == "--reconfigure-wpad") { reconfigure_all_wpad(); die; exit; } if ($argv[1] == "--rouncube-plugins") { roundcube_plugins($argv[2]); die; exit; } if ($argv[1] == "--monit") { build_monit(); die; exit; } if ($argv[1] == "--watchdog") { watchdog($argv[2]); die; exit; } if ($argv[1] == "--start") { startApache(); die; exit; } if ($argv[1] == "--stop") { StopApache();