echo "Starting......: " . date("H:i:s") . " Checking blocked sites\n"; build_progress("{reconfigure} {building} NET ADS", 45); shell_exec("{$NOHUP} {$PHP} " . basename(__FILE__) . "/exec.squid.netads.php >/dev/null 2>&1 &"); echo "Starting......: " . date("H:i:s") . " Building master configuration\n"; $squid->ASROOT = true; build_progress("{reconfigure} Building main configuration", 75); if (!ApplyConfig()) { build_progress("Apply configuration failed", 110); echo "Starting......: " . date("H:i:s") . " Apply configuration failed....\n"; return; } echo "Starting......: " . date("H:i:s") . " Checking Watchdog\n"; build_progress("{reconfigure} checking Watchdog settings", 80); watchdog_config(); build_progress("{reconfigure} build errors", 85); errors_details_txt(); build_progress("{reconfigure} Checking caches", 86); BuildCaches(true); build_progress("{reconfigure} Check files and security", 87); CheckFilesAndSecurity(); build_progress("{reconfigure} Building schedules", 88); build_schedules(true); build_progress("{reconfigure} Building SSL passwords", 89); build_sslpasswords(); build_progress("{reconfigure} Building blacklists", 90); build_blacklists(); build_progress("{reconfigure} Building No caches list", 91); build_denycaches(); build_progress("{reconfigure}", 95); $GLOBALS["OUTPUT"] = true; if ($GLOBALS["NOAPPLY"]) {
function SQUID_TEMPLATES() { if (system_is_overloaded(__FILE__)) { return null; } $unix = new unix(); $EXEC_PID_FILE = "/etc/artica-postfix/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; if ($unix->process_exists(@file_get_contents($EXEC_PID_FILE))) { print "Starting......: Checking squid Already executed pid " . @file_get_contents($EXEC_PID_FILE) . "...\n"; die; } $childpid = posix_getpid(); @file_put_contents($EXEC_PID_FILE, $childpid); if ($GLOBALS["VERBOSE"]) { echo "Search DataDir from compiled environments\n"; } $document_root = $unix->SQUID_GET_DATADIR(); echo "Starting......: squid DataDir: {$document_root}\n"; if (!is_dir("{$document_root}/errors/English")) { echo "Starting......: squid DataDir: {$document_root}/errors/English no such directory\n"; return; } $q = new mysql(); $q->CheckTable_dansguardian(); foreach (glob("{$document_root}/errors/English/*") as $filename) { $file = basename($filename); $sql = "SELECT TEMPLATE_DATA,TEMPLATE_DATA_SOURCE FROM squid_templates WHERE TEMPLATE_NAME='{$file}'"; $ligne = @mysql_fetch_array($q->QUERY_SQL($sql, 'artica_backup')); if ($ligne["TEMPLATE_DATA_SOURCE"] == null) { echo "Starting......: squid importing template {$file}\n"; $datas = addslashes(@file_get_contents($filename)); $sql = "INSERT INTO squid_templates (`TEMPLATE_DATA`,`TEMPLATE_DATA_SOURCE`,`TEMPLATE_NAME`) \n\t\t\tVALUES ('{$datas}','{$datas}','{$file}')"; $q->QUERY_SQL($sql, "artica_backup"); if (!$q->ok) { echo "Starting......: squid failed {$q->mysql_error}\n"; } $TEMPLATES[$file]["MODIFIED"] = $datas; $TEMPLATES[$file]["SRC"] = $datas; } else { $TEMPLATES[$file]["MODIFIED"] = $ligne["TEMPLATE_DATA"]; $TEMPLATES[$file]["SRC"] = $ligne["TEMPLATE_DATA_SOURCE"]; } } if (!is_array($TEMPLATES)) { echo "Starting......: squid no templates found...\n"; return; } $langsDirs = array('Armenian', 'Azerbaijani', 'Bulgarian', 'Catalan', 'Danish', 'Dutch', 'English', 'Estonian', 'Finnish', 'French', 'German', 'Greek', 'Hebrew', 'Hungarian', 'Italian', 'Japanese', 'Korean', 'Lithuanian', 'Portuguese', 'Romanian', 'Russian-1251', 'Russian-koi8-r', 'Serbian', 'Simplify_Chinese', 'Slovak', 'Spanish', 'Swedish', 'Traditional_Chinese', 'Turkish', 'Ukrainian-1251', 'Ukrainian-koi8-u', 'Ukrainian-utf8', 'af', 'ar', 'ar-ae', 'ar-bh', 'ar-dz', 'ar-eg', 'ar-iq', 'ar-jo', 'ar-kw', 'ar-lb', 'ar-ly', 'ar-ma', 'ar-om', 'ar-qa', 'ar-sa', 'ar-sy', 'ar-tn', 'ar-ye', 'az', 'az-az', 'bg', 'bg-bg', 'ca', 'cs', 'cs-cz', 'da', 'da-dk', 'de', 'de-at', 'de-ch', 'de-de', 'de-li', 'de-lu', 'el', 'el-gr', 'en', 'en-au', 'en-bz', 'en-ca', 'en-gb', 'en-ie', 'en-in', 'en-jm', 'en-nz', 'en-ph', 'en-sg', 'en-tt', 'en-uk', 'en-us', 'en-za', 'en-zw', 'es', 'es-ar', 'es-bo', 'es-cl', 'es-co', 'es-cr', 'es-do', 'es-ec', 'es-es', 'es-gt', 'es-hn', 'es-mx', 'es-ni', 'es-pa', 'es-pe', 'es-pr', 'es-py', 'es-sv', 'es-uy', 'es-ve', 'et', 'et-ee', 'fa', 'fa-fa', 'fa-ir', 'fi', 'fi-fi', 'fr', 'fr-be', 'fr-ca', 'fr-ch', 'fr-fr', 'fr-lu', 'fr-mc', 'he', 'he-il', 'hu', 'hu-hu', 'hy', 'hy-am', 'id', 'id-id', 'it', 'it-ch', 'it-it', 'ja', 'ja-jp', 'ko', 'ko-kp', 'ko-kr', 'lt', 'lt-lt', 'lv', 'lv-lv', 'ms', 'ms-my', 'nl', 'nl-nl', 'pl', 'pl-pl', 'pt', 'pt-br', 'pt-pt', 'ro', 'ro-md', 'ro-ro', 'ru', 'ru-ru', 'sk', 'sk-sk', 'sr', 'sr-latn', 'sr-latn-cs', 'sr-sp', 'sv', 'sv-fi', 'sv-se', 'templates', 'th', 'th-th', 'tr', 'tr-tr', 'uk', 'uk-ua', 'uz', 'zh-cn', 'zh-hk', 'zh-mo', 'zh-sg', 'zh-tw'); $css = SQUID_TEMPLATES_COMPILING_CSS(); while (list($template_name, $content) = each($TEMPLATES)) { if (preg_match("#<title>(.+?)</title>#is", $content["SRC"], $re)) { $title = $re[1]; } if (preg_match("#<body>(.+?)</body>#is", $content["MODIFIED"], $re)) { $body = $re[1]; } else { $body = $content["MODIFIED"]; } $html = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n\t\t<html>\n\t\t<head>\n\t\t<title>{$title}</title>\n\t\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> \n\t\t<style type=\"text/css\">\n\t\t<!--\n\t\t{$css}\n\t\t-->\n\t\t</style>\n\t\t</head>\n\t\t<body>\n\t\t\t{$body}\n\t\t</body>\n\t\t</html>\n\t\t"; $TEMPLATES_NEW[$template_name] = $html; } reset($langsDirs); echo "Starting......: squid building templates...\n"; while (list($index, $subdir) = each($langsDirs)) { reset($TEMPLATES_NEW); @mkdir("{$document_root}/errors/{$subdir}", 0755, true); while (list($template_name, $template_data) = each($TEMPLATES_NEW)) { if ($template_name == "error-details.txt") { continue; } if (!@file_put_contents("{$document_root}/errors/{$subdir}/{$template_name}", $template_data)) { echo "Starting......: squid {$document_root}/errors/{$subdir}/{$template_name} permission denied\n"; } } } errors_details_txt(); echo "Starting......: squid replace " . count($TEMPLATES) . " templates in " . count($langsDirs) . " languages done..\n"; }
function build() { build_progress("{reconfigure} (1)", 2); if ($GLOBALS["VERBOSE"]) { echo "Running build...\n"; } $unix = new unix(); $sock = new sockets(); $users = new usersMenus(); $forceCMD = null; $argv = null; $PHP = $unix->LOCATE_PHP5_BIN(); $mypid = getmypid(); if (isset($argv[1])) { $argv = $argv[1]; } $pids = $unix->PIDOF_PATTERN_ALL(basename(__FILE__) . ".*?{$argv}"); if (count($pids) > 1) { build_progress("{already_process_exists_try_later}", 110); while (list($num, $ligne) = each($pids)) { $cmdline = @file_get_contents("/proc/{$num}/cmdline"); echo "Starting......: " . date("H:i:s") . " [SERV]: [{$mypid}] Already process PID {$num} {$cmdline} exists..\n"; echo "Starting......: " . date("H:i:s") . " [SERV]: [{$mypid}] Running " . @file_get_contents("/proc/{$num}/cmdline") . "\n"; } die; } $EnableKerbAuth = $sock->GET_INFO("EnableKerbAuth"); if (!is_numeric($EnableKerbAuth)) { $EnableKerbAuth = 0; } $EnableWebProxyStatsAppliance = $sock->GET_INFO("EnableWebProxyStatsAppliance"); $EnableRemoteStatisticsAppliance = $sock->GET_INFO("EnableRemoteStatisticsAppliance"); if (!is_numeric($EnableRemoteStatisticsAppliance)) { $EnableRemoteStatisticsAppliance = 0; } if (!is_numeric($EnableWebProxyStatsAppliance)) { $EnableWebProxyStatsAppliance = 0; } $UnlockWebStats = $sock->GET_INFO("UnlockWebStats"); if (!is_numeric($UnlockWebStats)) { $UnlockWebStats = 0; } $ServiceFTPEnabled = intval($sock->GET_INFO("ServiceFTPEnabled")); if ($users->WEBSTATS_APPLIANCE) { $EnableWebProxyStatsAppliance = 1; $sock->SET_INFO("{$EnableWebProxyStatsAppliance}", 1); } if ($EnableWebProxyStatsAppliance == 1) { notify_remote_proxys(); } if ($UnlockWebStats == 1) { $EnableRemoteStatisticsAppliance = 0; } //Vérifie le compte utilisateur. //------------------------------------------------------------------------------------------------------------------------------------------------------------ $unix->CreateUnixUser("squid", "squid", "Squid Cache Service"); $MustHave[] = "/etc/squid3/artica-meta/whitelist-nets.db"; $MustHave[] = "/var/logs/cache.log"; $MustHave[] = "/etc/squid3/squid-block.acl"; $MustHave[] = "/etc/squid3/allowed-user-agents.acl"; $MustHave[] = "/etc/squid3/GlobalAccessManager_auth.conf"; $MustHave[] = "/etc/squid3/icap.conf"; $MustHave[] = "/etc/squid3/GlobalAccessManager_url_rewrite.conf"; $MustHave[] = "/etc/squid3/GlobalAccessManager_deny_cache.conf"; $MustHave[] = "/etc/squid3/GlobalAccessManager_deny.conf"; $MustHave[] = "/etc/squid3/squid-block.acl"; $MustHave[] = "/etc/squid3/clients_ftp.acl"; $MustHave[] = "/etc/squid3/allowed-user-agents.acl"; $MustHave[] = "/etc/squid3/whitelisted-computers-by-mac.acl"; while (list($none, $path) = each($MustHave)) { echo "Starting......: " . date("H:i:s") . " [SYS]: checking {$path}\n"; if (!is_file($path)) { @touch($path); } @chown($path, "squid"); @chgrp($path, "squid"); } if ($GLOBALS["FORCE"]) { $forceCMD = " --force"; } $squidbin = $unix->LOCATE_SQUID_BIN(); if (!is_file($squidbin)) { build_progress("{squid_binary_not_found}", 110); echo "Starting......: " . date("H:i:s") . " [SERV]: Unable to stat squid binary, aborting..\n"; die; } $EXEC_TIME_FILE = "/etc/artica-postfix/" . basename(__FILE__) . ".build.time"; if (!$GLOBALS["FORCE"]) { $time = $unix->file_time_min($EXEC_TIME_FILE); if ($time == 0) { build_progress("Failed! Only one config per minute !!!", 110); echo "Starting......: " . date("H:i:s") . " [SERV]: Only one config per minute...\n"; die; } } @unlink($EXEC_TIME_FILE); @file_put_contents($EXEC_TIME_FILE, time()); if ($GLOBALS["EMERGENCY"]) { squid_admin_mysql(0, "Reconfiguring Proxy service after Emergency enabled", null, __FILE__, __LINE__); } $TimeStart = time(); $EXEC_PID_FILE = "/etc/artica-postfix/" . basename(__FILE__) . ".build.pid"; $kill = $unix->find_program("kill"); $pid = @file_get_contents($EXEC_PID_FILE); if ($unix->process_exists($pid, basename(__FILE__))) { $TimePid = $unix->PROCCESS_TIME_MIN($pid); if ($TimePid > 30) { posix_kill(intval($pid), 9); } else { if (!$GLOBALS["FORCE"]) { print "Starting......: " . date("H:i:s") . " Checking (L." . __LINE__ . ") Squid Already executed pid {$pid} since {$TimePid}mn ...\n"; die; } } } echo "Starting......: " . date("H:i:s") . " [SERV]: is connected to remote appliance ? `{$EnableRemoteStatisticsAppliance}`\n"; if ($EnableRemoteStatisticsAppliance == 1) { $r = new squid_stats_appliance(); echo "Starting......: " . date("H:i:s") . " [SERV]: ################################\n"; echo "Starting......: " . date("H:i:s") . " [SERV]: # This server is connected to: #\n"; echo "Starting......: " . date("H:i:s") . " [SERV]: # {$r->URI} #\n"; echo "Starting......: " . date("H:i:s") . " [SERV]: ################################\n"; remote_appliance_restore_tables(); } build_progress("{reconfigure} (1)", 5); if (!PortsConversion()) { build_progress("{reconfigure} {failed} !PortsConversion", 110); return; } squid_reconfigure_build_tool(); build_progress("{reconfigure}", 10); squid_pactester(); build_progress("{reconfigure}", 15); $childpid = posix_getpid(); $sock = new sockets(); $squid_user = SquidUser(); $SQUID_CONFIG_PATH = $unix->SQUID_CONFIG_PATH(); $PHP = LOCATE_PHP5_BIN2(); $NOHUP = $unix->find_program("nohup"); build_progress("{reconfigure}", 20); @file_put_contents($EXEC_PID_FILE, $childpid); if (is_file("/etc/squid3/mime.conf")) { shell_exec("/bin/chown squid:squid /etc/squid3/mime.conf"); } $EnableKerbAuth = $sock->GET_INFO("EnableKerbAuth"); if (!is_numeric("{$EnableKerbAuth}")) { $EnableKerbAuth = 0; } if (!is_dir("/usr/share/squid-langpack")) { TemplatesInMysql(true); exit; } echo "Starting......: " . date("H:i:s") . " Checking squid kerberos authentification is set to {$EnableKerbAuth}\n"; echo "Starting......: " . date("H:i:s") . " Checking squid certificate\n"; build_progress("{reconfigure} Check database", 25); checkdatabase(); build_progress("{reconfigure} certificates", 30); certificate_generate(); build_progress("{reconfigure}", 35); remote_appliance_restore_tables(); build_progress("{reconfigure}", 40); echo "Starting......: " . date("H:i:s") . " Instanciate squid library..\n"; $squid = new squidbee(); $squidbin = $unix->find_program("squid3"); echo "Starting......: " . date("H:i:s") . " checking squid binaries..\n"; if (!is_file($squidbin)) { $squidbin = $unix->find_program("squid"); } echo "Starting......: " . date("H:i:s") . " Binary: {$squidbin}\n"; echo "Starting......: " . date("H:i:s") . " Config: {$SQUID_CONFIG_PATH}\n"; echo "Starting......: " . date("H:i:s") . " User..: {$squid_user}\n"; echo "Starting......: " . date("H:i:s") . " Checking blocked sites\n"; build_progress("{reconfigure} {building} NET ADS", 45); shell_exec("{$NOHUP} {$PHP} " . basename(__FILE__) . "/exec.squid.netads.php >/dev/null 2>&1 &"); echo "Starting......: " . date("H:i:s") . " Building master configuration\n"; $squid->ASROOT = true; echo "Starting......: " . date("H:i:s") . " Checking Watchdog\n"; build_progress("{reconfigure} checking Watchdog settings", 46); watchdog_config(); build_progress("{reconfigure} build errors", 47); errors_details_txt(); build_progress("{reconfigure} Checking caches", 48); BuildCaches(true); build_progress("{reconfigure} Check files and security", 49); CheckFilesAndSecurity(); build_progress("{reconfigure} Building schedules", 50); build_schedules(true); build_progress("{reconfigure} Building SSL passwords", 89); build_sslpasswords(); build_progress("{reconfigure} Building blacklists", 90); build_blacklists(); build_progress("{reconfigure} Building No caches list", 91); build_denycaches(); build_progress("{reconfigure} Building {GLOBAL_ACCESS_CENTER}", 93); system("{$PHP} /usr/share/artica-postfix/exec.squid.global.access.php --nochek"); build_progress("{reconfigure} Building main configuration", 94); if (!ApplyConfig()) { build_progress("Apply configuration failed", 110); echo "Starting......: " . date("H:i:s") . " Apply configuration failed....\n"; return; } build_progress("{reconfigure} FTP Proxy service", 95); system("{$NOHUP} {$PHP} /usr/share/artica-postfix/exec.ftpproxy-multi.php --build >/dev/null 2>&1 &"); build_progress("{reconfigure} Wan Compressor Proxy service", 95); system("{$NOHUP} {$PHP} /usr/share/artica-postfix/exec.wanproxy.php --build-squid >/dev/null 2>&1 &"); build_progress("{checking_transparent_mode}", 95); if ($unix->IS_FIREHOLE_ACTIVE()) { build_progress("{restarting_firewall}", 95); system("{$PHP} /usr/share/artica-postfix/exec.firehol.php"); system("/etc/init.d/firehol restart"); } else { system("{$PHP} /usr/share/artica-postfix/exec.squid.transparent.php"); system("{$PHP} /usr/share/artica-postfix/exec.secure.gateway.php"); if (is_file("/etc/init.d/iptables-transparent")) { build_progress("{restarting_firewall}", 95); system("/etc/init.d/iptables-transparent restart"); } if (is_file("/bin/iptables-parents.sh")) { build_progress("{restarting_firewall} (parent)", 95); system("/bin/iptables-parents.sh"); } if (is_file("/bin/artica-secure-gateway.sh")) { build_progress("{restarting_firewall} (Secure gateway)", 95); shell_exec("/bin/artica-secure-gateway.sh"); } } build_progress("{checking_wccp_mode}", 95); system("{$PHP} /usr/share/artica-postfix/exec.squid.wccp.php --reconfigure"); build_progress("{checking_mikrotik_mode}", 95); system("{$PHP} /usr/share/artica-postfix/exec.mikrotik.php"); build_progress("{reconfigure}", 96); $GLOBALS["OUTPUT"] = true; if ($GLOBALS["NOAPPLY"]) { build_progress("{reconfiguring_proxy_service} {success}", 100); return; } if (!$GLOBALS["RESTART"]) { build_progress("{reloading_service}", 91); if (!$GLOBALS["NORELOAD"]) { Reload_Squid(); } } if ($GLOBALS["RESTART"]) { if (!$GLOBALS["NORELOAD"]) { build_progress("{stopping_service}", 91); system("{$PHP} /usr/share/artica-postfix/exec.squid.watchdog.php --stop {$forceCMD} --byForceReconfigure"); build_progress("{starting_service}", 93); system("{$PHP} /usr/share/artica-postfix/exec.squid.watchdog.php --start {$forceCMD} --byForceReconfigure"); build_progress("{starting_service}", 95); } } build_progress("{building} Cached Web frontend pages", 97); shell_exec("{$NOHUP} {$PHP} " . basename(__FILE__) . "/exec.cache.pages.php --force >/dev/null 2>&1 &"); $BuildAllTemplatesDone = $sock->GET_INFO("BuildAllTemplatesDone"); if (!is_numeric($BuildAllTemplatesDone)) { $BuildAllTemplatesDone = 0; } if ($BuildAllTemplatesDone == 0) { build_progress("{building} Templates schedules", 97); echo "Starting......: " . date("H:i:s") . " scheduling Building templates\n"; sys_THREAD_COMMAND_SET("{$PHP} " . __FILE__ . " --tpl-save"); $sock->SET_INFO("BuildAllTemplatesDone", 1); } build_progress("{building} Templates", 98); sys_THREAD_COMMAND_SET("{$PHP} " . __FILE__ . " --mysql-tpl"); build_progress("{reconfiguring_proxy_service} {success}", 100); echo "Starting......: " . date("H:i:s") . " Done (Took: " . $unix->distanceOfTimeInWords($TimeStart, time()) . ")\n"; die; }