function UFDBGUARD_COMPILE_CATEGORY($category) { $sock = new sockets(); $EnableRemoteStatisticsAppliance = $sock->GET_INFO("EnableRemoteStatisticsAppliance"); if (!is_numeric($EnableRemoteStatisticsAppliance)) { $EnableRemoteStatisticsAppliance = 0; } $UseRemoteUfdbguardService = $sock->GET_INFO("UseRemoteUfdbguardService"); if (!is_numeric($UseRemoteUfdbguardService)) { $UseRemoteUfdbguardService = 0; } if ($EnableRemoteStatisticsAppliance == 1) { UFDBGUARD_COMPILE_CATEGORY_PROGRESS("{failed} Stat Appliance enabled", 110); return; } if ($UseRemoteUfdbguardService == 1) { UFDBGUARD_COMPILE_CATEGORY_PROGRESS("{failed} Use remote service", 110); return; } $unix = new unix(); if ($GLOBALS["VERBOSE"]) { $ufdbguardd = $unix->find_program("ufdbguardd"); system("{$ufdbguardd} -v"); } $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); UFDBGUARD_COMPILE_CATEGORY_PROGRESS("{failed} {$category} category aborting,task pid {$pid} running since {$time}Mn", 110); ufdbguard_admin_events("Compile {$category} category aborting,task pid {$pid} running since {$time}Mn", __FUNCTION__, __FILE__, __LINE__, "compile"); return; } @file_put_contents($pidfile, getmypid()); $t = time(); echo "Starting......: " . date("H:i:s") . " Compiling category {$category}\n"; UFDBGUARD_COMPILE_CATEGORY_PROGRESS("{compiling} Compiling category {$category}", 2); $ufdb = new compile_ufdbguard(); $ufdb->compile_category($category); $sock = new sockets(); $EnableWebProxyStatsAppliance = $sock->GET_INFO("EnableWebProxyStatsAppliance"); if (!is_numeric($EnableWebProxyStatsAppliance)) { $EnableWebProxyStatsAppliance = 0; } if ($EnableWebProxyStatsAppliance == 1) { echo "Starting......: " . date("H:i:s") . " This server is a Squid Appliance, compress databases and notify proxies\n"; CompressCategories(); notify_remote_proxys(); } }
function TemplatesInMysql($aspid = false) { $unix = new unix(); $pidpath = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pidtime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time"; if (!$aspid) { $pid = $unix->get_pid_from_file($pidpath); if ($unix->process_exists($pid)) { return; } } @file_put_contents($pidpath, getmypid()); EventsWatchdog("writing /etc/artica-postfix/SQUID_TEMPLATE_DONE"); @file_put_contents("/etc/artica-postfix/SQUID_TEMPLATE_DONE", time()); @file_put_contents("/etc/artica-postfix/SQUID_TEMPLATE_DONEv2", time()); $sock = new sockets(); $SquidTemplateSimple = $sock->GET_INFO("SquidTemplateSimple"); if (!is_numeric($SquidTemplateSimple)) { $SquidTemplateSimple = 1; } if ($SquidTemplateSimple == 1) { $unix = new unix(); $php = $unix->LOCATE_PHP5_BIN(); $nohup = $unix->find_program("nohup"); $by = "--FUNC-" . __FUNCTION__ . "-L-" . __LINE__; shell_exec("{$nohup} {$php} /usr/share/artica-postfix/exec.squid.templates.php {$by} >/dev/null 2>&1 &"); return; } $TimeExec = $unix->file_time_min($pidtime); if (!$GLOBALS["FORCE"]) { if ($TimeExec < 240) { return; } } $users = new usersMenus(); $sock = new sockets(); $EnableRemoteStatisticsAppliance = $sock->GET_INFO("EnableRemoteStatisticsAppliance"); $EnableWebProxyStatsAppliance = $sock->GET_INFO("EnableWebProxyStatsAppliance"); if (!is_numeric($EnableWebProxyStatsAppliance)) { $EnableWebProxyStatsAppliance = 0; } if (!is_numeric($EnableRemoteStatisticsAppliance)) { $EnableRemoteStatisticsAppliance = 0; } $UnlockWebStats = $sock->GET_INFO("UnlockWebStats"); if (!is_numeric($UnlockWebStats)) { $UnlockWebStats = 0; } if ($UnlockWebStats == 1) { $EnableRemoteStatisticsAppliance = 0; } if ($EnableRemoteStatisticsAppliance == 1) { if (!$users->CORP_LICENSE) { if (!is_file("/etc/artica-postfix/SQUID_TEMPLATE_DONE")) { DefaultTemplatesInArtica(); return; } } EventsWatchdog("Using the Web statistics appliance to get template files"); if ($GLOBALS["VERBOSE"]) { echo "Use the Web statistics appliance to get template files...\n"; } TemplatesInMysql_remote(); return; } @mkdir("/etc/artica-postfix", 0755, true); $base = "/usr/share/squid-langpack"; @mkdir($base, 0755, true); if (!is_dir("{$base}/templates")) { @mkdir("{$base}/templates", 0755, true); } $headerTemp = @file_get_contents(dirname(__FILE__) . "/ressources/databases/squid.default.header.db"); $q = new mysql_squid_builder(); if (!$q->BD_CONNECT(true)) { squid_admin_mysql(2, "Error, unable to connect to MySQL", __FILE__, __LINE__); if (!$users->CORP_LICENSE) { DefaultTemplatesInArtica(); } return; } $sql = "CREATE TABLE IF NOT EXISTS `squidtpls` (\n\t\t\t `zmd5` CHAR(32) NOT NULL,\n\t\t\t `template_name` varchar(128) NOT NULL,\n\t\t\t `template_body` LONGTEXT NOT NULL,\n\t\t\t `template_header` LONGTEXT NOT NULL,\n\t\t\t `template_title` varchar(255) NOT NULL,\n\t\t\t `template_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n\t\t\t `template_link` smallint(1) NOT NULL,\n\t\t\t `template_uri` varchar(255) NOT NULL,\n\t\t\t `lang` varchar(5) NOT NULL,\n\t\t\t PRIMARY KEY (`zmd5`),\n\t\t\t KEY `template_name` (`template_name`,`lang`),\n\t\t\t KEY `template_title` (`template_title`),\n\t\t\t KEY `template_time` (`template_time`),\n\t\t\t KEY `template_link` (`template_link`),\n\t\t\t FULLTEXT KEY `template_body` (`template_body`)\n\t\t\t) ENGINE = MYISAM;"; $q->QUERY_SQL($sql); if ($q->COUNT_ROWS("squidtpls") == 0) { if (!is_file("/etc/artica-postfix/SQUID_TEMPLATE_DONE")) { squid_admin_mysql(2, "Ask to build default templates squidtpls=0", null, __FILE__, __LINE__); DefaultTemplatesInArtica(); } } if (!$users->CORP_LICENSE) { if (!is_file("/etc/artica-postfix/SQUID_TEMPLATE_DONE")) { squid_admin_mysql(2, "Ask to build default templates - no license -", null, __FILE__, __LINE__); DefaultTemplatesInArtica(); return; } } $sql = "SELECT * FROM squidtpls"; $results = $q->QUERY_SQL($sql); if (!$q->ok) { squid_admin_mysql(1, "MySQL Error on templates", $q->mysql_error, __FILE__, __LINE__); ufdbguard_admin_events("Fatal,{$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "proxy"); return; } $c = 0; while ($ligne = mysql_fetch_assoc($results)) { $ligne["template_header"] = stripslashes($ligne["template_header"]); $ligne["template_title"] = stripslashes($ligne["template_title"]); $ligne["template_body"] = stripslashes($ligne["template_body"]); $template_name = $ligne["template_name"]; if ($ligne["template_link"] == 1) { continue; } $header = trim($ligne["template_header"]); if ($header == null) { $header = $headerTemp; } if ($GLOBALS["VERBOSE"]) { echo "Template: `{$template_name}`: {$ligne["template_title"]}\n"; } if (!preg_match("#^ERR_.+#", $ligne["template_name"])) { $ligne["template_name"] = "ERR_" . $ligne["template_name"]; } $filename2 = null; $ligne["template_body"] = utf8_encode($ligne["template_body"]); $ligne["template_title"] = utf8_encode($ligne["template_title"]); $filename = "{$base}/{$ligne["lang"]}/{$ligne["template_name"]}"; if ($ligne["lang"] == "en") { $filename2 = "/usr/share/squid-langpack/templates/{$ligne["template_name"]}"; } $newheader = str_replace("{TITLE}", $ligne["template_title"], $header); $templateDatas = "{$newheader}{$ligne["template_body"]}</body></html>"; if ($GLOBALS["VERBOSE"]) { echo "Template: `{$template_name}`: Path `{$filename}`\n"; } if ($ligne["emptytpl"] == 1) { $templateDatas = "<html><head></head><body></body></html>"; } if ($GLOBALS["VERBOSE"]) { echo "Template: `{$template_name}`: {$ligne["lang"]}\n"; } if (is_numeric($ligne["lang"])) { $ligne["lang"] = "en"; } @mkdir(dirname($filename), 0755, true); @file_put_contents($filename, $templateDatas); if ($filename2 != null) { @file_put_contents($filename2, $templateDatas); $unix->chown_func("squid", "squid", "{$filename2}"); } @file_put_contents("{$base}/{$ligne["lang"]}/{$ligne["template_name"]}", $templateDatas); $unix->chown_func("squid", "squid", "{$base}/{$ligne["lang"]}/{$ligne["template_name"]}"); $unix->chown_func("squid", "squid", "{$filename}"); $c++; if ($ligne["lang"] == "en") { if ($GLOBALS["VERBOSE"]) { echo "Writing {$base}/{$ligne["template_name"]}\n"; } @file_put_contents("{$base}/{$ligne["template_name"]}", $templateDatas); $unix->chown_func("squid:squid", null, "{$base}/templates/{$ligne["template_name"]}"); } else { if (!IfTemplateExistsinEn($template_name)) { @mkdir("{$base}/en", 0755, true); @file_put_contents("{$base}/en/{$ligne["template_name"]}", $templateDatas); $unix->chown_func("squid:squid", null, "{$base}/en/{$ligne["template_name"]}"); } } } $sql = "SELECT * FROM squidtpls WHERE emptytpl=1"; $results = $q->QUERY_SQL($sql); while ($ligne = mysql_fetch_assoc($results)) { if (is_numeric($ligne["lang"])) { $ligne["lang"] = "en"; } if (!preg_match("#^ERR_.+#", $ligne["template_name"])) { $ligne["template_name"] = "ERR_" . $ligne["template_name"]; } $filename = "{$base}/{$ligne["lang"]}/{$ligne["template_name"]}"; $templateDatas = "<html><head></head><body></body></html>"; @mkdir(dirname($filename), 0755, true); @file_put_contents($filename, $templateDatas); @file_put_contents("{$base}/{$ligne["lang"]}/{$ligne["template_name"]}", $templateDatas); $unix->chown_func("squid", "squid", "{$base}/{$ligne["lang"]}/{$ligne["template_name"]}"); $unix->chown_func("squid", "squid", "{$filename}"); } $unix = new unix(); $tar = $unix->find_program("tar"); $unix->chown_func("squid", "squid", "{$base}/*"); chdir($base); shell_exec("{$tar} -czf " . dirname(__FILE__) . "/ressources/databases/squid-lang-pack.tgz *"); if ($EnableWebProxyStatsAppliance == 1) { if ($GLOBALS["VERBOSE"]) { echo "-> notify_remote_proxys()\n"; } notify_remote_proxys("SQUID_LANG_PACK"); if ($GLOBALS["VERBOSE"]) { echo "This is a statistics appliance, aborting next step\n"; } return; } squid_admin_mysql(2, "{$c} web pages templates saved", "no information", __FILE__, __LINE__); Reload_Squid(); }