Example #1
0
 function __construct()
 {
     self::$instance = $this;
     $this->options = get_option('hyper-cache', array());
     register_activation_hook('hyper-cache/plugin.php', array($this, 'hook_activate'));
     register_deactivation_hook('hyper-cache/plugin.php', array($this, 'hook_deactivate'));
     add_action('edit_post', array($this, 'hook_edit_post'), 1);
     add_action('save_post', array($this, 'hook_save_post'), 1);
     add_action('comment_post', array($this, 'hook_comment_post'), 1, 2);
     add_action('wp_update_comment_count', array($this, 'hook_wp_update_comment_count'), 1);
     add_action('bbp_new_reply', array($this, 'hook_bbp_new_reply'));
     add_action('bbp_new_topic', array($this, 'hook_bbp_new_topic'));
     add_action('hyper_cache_clean', array($this, 'hook_hyper_cache_clean'));
     if (!is_admin() && !isset($_COOKIE['cache_disable'])) {
         // The function must exists or the advanced-cache.php has been removed
         global $hyper_cache_is_mobile;
         if ($hyper_cache_is_mobile && !empty($this->options['theme'])) {
             add_filter('stylesheet', array($this, 'hook_get_stylesheet'));
             add_filter('template', array($this, 'hook_get_template'));
         }
         add_action('template_redirect', array($this, 'hook_template_redirect'), 0);
     }
     if (is_admin()) {
         add_action('admin_init', array($this, 'hook_admin_init'));
         add_action('admin_head', array($this, 'hook_admin_head'));
         add_action('admin_menu', array($this, 'hook_admin_menu'));
         if (!is_dir(WP_CONTENT_DIR . '/logs')) {
             wp_mkdir_p(WP_CONTENT_DIR . '/logs');
         }
     }
 }
Example #2
0
function HyperCacheMirror($JustID = 0)
{
    $unix = new unix();
    $httrack = $unix->find_program("httrack");
    if (!is_file($httrack)) {
        if ($GLOBALS["VERBOSE"]) {
            echo "httrack no such binary\n";
        }
        return;
    }
    $q = new mysql_squid_builder();
    if (!$q->FIELD_EXISTS("artica_caches_mirror", "ToDelete")) {
        $sql = "ALTER TABLE `artica_caches_mirror` ADD `ToDelete` SMALLINT(1) NOT NULL DEFAULT '0',ADD INDEX(`ToDelete`)";
        $q->QUERY_SQL($sql);
        if (!$q->ok) {
            squid_admin_enforce(1, "Fatal: MySQL error", $q->mysql_error, __FILE__, __LINE__);
            return;
        }
    }
    if (!$q->FIELD_EXISTS("artica_caches_mirror", "RunEvents")) {
        $sql = "ALTER TABLE `artica_caches_mirror` ADD `RunEvents` TEXT";
        $q->QUERY_SQL($sql);
        if (!$q->ok) {
            squid_admin_enforce(1, "Fatal: MySQL error", $q->mysql_error, __FILE__, __LINE__);
            return;
        }
    }
    $nice = EXEC_NICE();
    $sql = "SELECT * FROM artica_caches_mirror WHERE enabled=1 AND `ToDelete`=0";
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        squid_admin_enforce(1, "Fatal: MySQL error", $q->mysql_error, __FILE__, __LINE__);
        return;
    }
    if (!isset($GLOBALS["HyperCacheStoragePath"])) {
        $sock = new sockets();
        $GLOBALS["HyperCacheStoragePath"] = $sock->GET_INFO("HyperCacheStoragePath");
        if ($GLOBALS["HyperCacheStoragePath"] == null) {
            $GLOBALS["HyperCacheStoragePath"] = "/home/artica/proxy-cache";
        }
    }
    $t1 = time();
    $count = 0;
    if (mysql_num_rows($results) == 0) {
        return;
    }
    $proxyport = $unix->squid_internal_port();
    $HyperCache = new HyperCache();
    while ($ligne = mysql_fetch_assoc($results)) {
        if ($JustID > 0) {
            if ($ligne["ID"] != $JustID) {
                events("Scrapping rule ID {$ligne["ID"]} !skipped", 0, 2, __LINE__);
                continue;
            }
        }
        $t = time();
        $count++;
        $sitename = $ligne["sitename"];
        $sitename_path = $HyperCache->HyperCacheUriToHostname($sitename);
        $workingdir = $GLOBALS["HyperCacheStoragePath"] . "/mirror/{$sitename_path}";
        $TimeExec = $ligne["TimeExec"];
        $TimeExecLast = $unix->file_time_min("{$workingdir}/TimeExec");
        if (!$GLOBALS["FORCE"]) {
            events("Scrapping {$sitename} require {$TimeExec}mn, current {$TimeExecLast}Mn", 0, 2, __LINE__);
            if ($TimeExecLast < $TimeExec) {
                continue;
            }
        }
        events("Scrapping rule ID {$ligne["ID"]} for {$sitename}", 0, 2, __LINE__);
        $minrate = $ligne["minrate"];
        $maxfilesize = $ligne["maxfilesize"];
        $maxsitesize = $ligne["maxsitesize"];
        $maxfilesize = $maxfilesize * 1000;
        $maxsitesize = $maxsitesize * 1000;
        $minrate = $minrate * 1000;
        $update = null;
        $resultsCMD = array();
        $pidpath = "{$GLOBALS["HyperCacheStoragePath"]}/mirror/{$sitename_path}/hts-in_progress.lock";
        if (!is_dir($workingdir)) {
            @mkdir($workingdir, 0755, true);
        }
        @chown("{$GLOBALS["HyperCacheStoragePath"]}/mirror", "squid");
        @chgrp("{$GLOBALS["HyperCacheStoragePath"]}/mirror", "squid");
        @chown("{$GLOBALS["HyperCacheStoragePath"]}/mirror/{$sitename_path}", "squid");
        @chgrp("{$GLOBALS["HyperCacheStoragePath"]}/mirror/{$sitename_path}", "squid");
        if (is_file($pidpath)) {
            $PID = HyperCacheMirror_pid($pidpath);
            if ($unix->process_exists($PID)) {
                events("Scrapping rule ID {$ligne["ID"]} for {$sitename} Process {$PID} already running since " . $unix->PROCESS_TIME_INT($PID), 0, 2, __LINE__);
                continue;
            }
        }
        @file_put_contents("{$workingdir}/TimeExec", time());
        if (is_file("{$workingdir}/hts-cache")) {
            $update = " --update";
        }
        $cmdline = array();
        $cmdline[] = "{$httrack} \"{$sitename}\" --quiet{$update} -%U squid --proxy 127.0.0.1:{$proxyport}";
        $cmdline[] = "--stay-on-same-domain -u2 -C1 -I0 -N100 --robots=0 --max-files={$maxfilesize}";
        $cmdline[] = "--max-size={$maxsitesize}";
        $cmdline[] = "-O \"{$workingdir}\" 2>&1";
        squid_admin_enforce(2, "Scrapping {$sitename} using proxy 127.0.0.1:{$proxyport}...", null, __FILE__, __LINE__);
        $cmd = @implode(" ", $cmdline);
        if ($GLOBALS["VERBOSE"]) {
            echo "{$cmd}\n";
        }
        exec($cmd, $resultsCMD);
        if ($GLOBALS["VERBOSE"]) {
            echo @implode("\n", $resultsCMD);
        }
        $dirsize = $unix->DIRSIZE_BYTES($workingdir);
        $took = $unix->distanceOfTimeInWords($t, time(), true);
        $dirsizeText = round($dirsize / 1024 / 1000, 2);
        squid_admin_enforce(2, "Mirror on {$sitename} done took {$took} size={$dirsizeText} MB", null, __FILE__, __LINE__);
        $logs = mysql_escape_string2(@file_get_contents("{$workingdir}/hts-log.txt"));
        $q->QUERY_SQL("UPDATE artica_caches_mirror SET \n\t\t\t\tsize='{$dirsize}',`RunEvents`='{$logs}' WHERE ID={$ligne["ID"]}", "artica_backup");
        if (!$q->ok) {
            squid_admin_enforce(1, "MySQL error", $q->mysql_error, __FILE__, __LINE__);
        }
    }
    $took = $unix->distanceOfTimeInWords($t1, time(), true);
    squid_admin_enforce(2, "{$count} web site(s) scrapped took {$took}", null, __FILE__, __LINE__);
}
Example #3
0
function HyperCacheWhiteUri($URI)
{
    if (count($GLOBALS["HyperCacheRulesWhiteList"]) == 0) {
        return false;
    }
    $HyperCache = new HyperCache();
    $HyperCacheRulesWhiteList = $GLOBALS["HyperCacheRulesWhiteList"];
    while (list($pattern, $line) = each($HyperCacheRulesWhiteList)) {
        if ($HyperCache->HyperCacheRulesMatchPattern($pattern, $URI)) {
            return true;
        }
    }
}
Example #4
0
function apache_config()
{
    $sock = new sockets();
    $unix = new unix();
    $EnablePHPFPM = 0;
    @mkdir("/var/run/squid", 0755, true);
    @mkdir("/var/run/squid", 0755, true);
    $APACHE_SRC_ACCOUNT = "squid";
    $APACHE_SRC_GROUP = "squid";
    $APACHE_MODULES_PATH = $unix->APACHE_MODULES_PATH();
    if (!isset($GLOBALS["HyperCacheStoragePath"])) {
        $sock = new sockets();
        $GLOBALS["HyperCacheStoragePath"] = $sock->GET_INFO("HyperCacheStoragePath");
        if ($GLOBALS["HyperCacheStoragePath"] == null) {
            $GLOBALS["HyperCacheStoragePath"] = "/home/artica/proxy-cache";
        }
    }
    $SquidEnforceRules = intval($sock->GET_INFO("SquidEnforceRules"));
    $HyperCacheHTTPListenPort = $sock->GET_INFO("HyperCacheHTTPListenPort");
    $HyperCacheHTTPListenPortSSL = $sock->GET_INFO("HyperCacheHTTPListenPortSSL");
    $HyperCacheHTTPListenPortSSLEnabled = intval($sock->GET_INFO("HyperCacheHTTPListenPortSSLEnabled"));
    if (!is_numeric($HyperCacheHTTPListenPort)) {
        $HyperCacheHTTPListenPort = 8700;
    }
    if (!is_numeric($HyperCacheHTTPListenPortSSL)) {
        $HyperCacheHTTPListenPortSSL = 8900;
    }
    $HyperCacheListenAddr = $sock->GET_INFO("HyperCacheListenAddr");
    $unix = new unix();
    $NETWORK_ALL_INTERFACES = $unix->NETWORK_ALL_INTERFACES();
    unset($NETWORK_ALL_INTERFACES["lo"]);
    if ($HyperCacheListenAddr == null) {
        $HyperCacheListenAddr = $unix->NETWORK_DEFAULT_LISTEN_ADDR();
        $sock->SET_INFO("HyperCacheListenAddr", $HyperCacheListenAddr);
    }
    if ($unix->NETWORK_IS_LISTEN_ADDR_EXISTS($HyperCacheListenAddr)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} {$HyperCacheListenAddr} doesn't exists...\n";
        }
        $HyperCacheListenAddr = $unix->NETWORK_DEFAULT_LISTEN_ADDR();
        $sock->SET_INFO("HyperCacheListenAddr", $HyperCacheListenAddr);
    }
    $ipaddr = $HyperCacheListenAddr;
    $phpfpm = $unix->APACHE_LOCATE_PHP_FPM();
    $php = $unix->LOCATE_PHP5_BIN();
    $EnableArticaApachePHPFPM = $sock->GET_INFO("EnableArticaApachePHPFPM");
    if (!is_numeric($EnableArticaApachePHPFPM)) {
        $EnableArticaApachePHPFPM = 0;
    }
    if (!is_file($phpfpm)) {
        $EnableArticaApachePHPFPM = 0;
    }
    $unix->chown_func($APACHE_SRC_ACCOUNT, $APACHE_SRC_GROUP, "/var/run/squid");
    $apache_LOCATE_MIME_TYPES = $unix->apache_LOCATE_MIME_TYPES();
    if ($EnableArticaApachePHPFPM == 1) {
        if (!is_file("{$APACHE_MODULES_PATH}/mod_fastcgi.so")) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} mod_fastcgi.so is required to use PHP5-FPM\n";
            }
            $EnableArticaApachePHPFPM = 0;
        }
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Listen address: {$ipaddr}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Run as {$APACHE_SRC_ACCOUNT}:{$APACHE_SRC_GROUP}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} HTTP Port: {$HyperCacheHTTPListenPort} SSL Port: {$HyperCacheHTTPListenPortSSL}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} PHP-FPM: {$EnablePHPFPM}\n";
    }
    $q = new mysql_squid_builder();
    $nice = EXEC_NICE();
    $sql = "SELECT * FROM artica_caches_mirror WHERE enabled=1 AND `ToDelete`=0";
    $results = $q->QUERY_SQL($sql);
    $HyperCache = new HyperCache();
    while ($ligne = mysql_fetch_assoc($results)) {
        $t = time();
        $sitename = $ligne["sitename"];
        $sitename_path = $HyperCache->HyperCacheUriToHostname($sitename);
        $workingdir = $GLOBALS["HyperCacheStoragePath"] . "/mirror/{$sitename_path}";
        if (!is_dir($workingdir)) {
            @mkdir($workingdir, 0755, true);
        }
        @chown("{$GLOBALS["HyperCacheStoragePath"]}/mirror", "squid");
        @chgrp("{$GLOBALS["HyperCacheStoragePath"]}/mirror", "squid");
        @chown("{$GLOBALS["HyperCacheStoragePath"]}/mirror/{$sitename_path}", "squid");
        @chgrp("{$GLOBALS["HyperCacheStoragePath"]}/mirror/{$sitename_path}", "squid");
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} build folder for mirrored {$sitename_path}\n";
        }
        $mirrors[] = "";
        $mirrors_aliases[] = "alias /{$sitename_path} {$workingdir}";
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: alias /{$sitename_path} {$workingdir}\n";
        }
        $mirrors[] = "";
        $mirrors[] = "\t<Directory \"{$workingdir}\">";
        $mirrors[] = "\t\tDirectorySlash On";
        $mirrors[] = "\t\tDirectoryIndex index.html index-2.html";
        $mirrors[] = "\t\tOptions All";
        $mirrors[] = "\t\tOrder deny,allow";
        $mirrors[] = "\t\tAllow from all";
        $mirrors[] = "\t</Directory>";
        $mirrors[] = "";
    }
    $mirrors_conf = @implode("\n", $mirrors);
    $mirrors_aliases_conf = @implode("\n", $mirrors_aliases);
    $f[] = "LockFile /var/run/squid/HyperCacheWebAccept.lock";
    $f[] = "PidFile /var/run/squid/HyperCacheWeb.pid";
    $f[] = "AcceptMutex flock";
    $f[] = "DocumentRoot /usr/share/artica-postfix";
    $f[] = "DirectoryIndex squidcache.php";
    $f[] = "NameVirtualHost {$ipaddr}:{$HyperCacheHTTPListenPort}";
    $f[] = $mirrors_aliases_conf;
    if ($HyperCacheHTTPListenPortSSLEnabled == 1) {
        $f[] = "SSLRandomSeed startup file:/dev/urandom  256";
        $f[] = "SSLRandomSeed connect builtin";
        $f[] = "SSLSessionCache        shmcb:/var/run/squid/HyperCacheWebSSL(512000)";
        $f[] = "SSLSessionCacheTimeout  300";
        $f[] = "SSLSessionCacheTimeout  300";
        $f[] = "NameVirtualHost {$ipaddr}:{$HyperCacheHTTPListenPortSSL}";
        $f[] = "Listen {$ipaddr}:{$HyperCacheHTTPListenPortSSL}";
    }
    $f[] = "Listen {$ipaddr}:{$HyperCacheHTTPListenPort}";
    $f[] = "<VirtualHost {$ipaddr}:{$HyperCacheHTTPListenPort}>";
    $f[] = "\tServerName {$ipaddr}";
    $f[] = "\tLoglevel debug";
    $f[] = "\tLoglevel debug";
    $f[] = "\tErrorLog /var/log/squid/HyperCache-error.log";
    $f[] = "\tLogFormat \"%h %l %u %t \\\"%r\\\" %<s %b\" common";
    $f[] = "\tCustomLog /var/log/squid/HyperCache-access.log common";
    $f[] = "\tErrorDocument 400 /squidcache.php";
    $f[] = "\tErrorDocument 401 /squidcache.php";
    $f[] = "\tErrorDocument 403 /squidcache.php";
    $f[] = "\tErrorDocument 404 /squidcache.php";
    $f[] = "\tErrorDocument 500 /squidcache.php";
    //$f[]="\tFallbackResource /squidcache.php";
    $f[] = $mirrors_aliases_conf;
    $f[] = $mirrors_conf;
    $f[] = "</VirtualHost>";
    if ($HyperCacheHTTPListenPortSSLEnabled == 1) {
        $squid = new squidbee();
        $data = $squid->SaveCertificate($ArticaSplashHotSpotCertificate, false, true, false);
        if (preg_match("#ssl_certificate\\s+(.+?);\\s+ssl_certificate_key\\s+(.+?);#is", $data, $re)) {
            $cert = $re[1];
            $key = $re[2];
        }
        $f[] = "<VirtualHost {$ipaddr}:{$HyperCacheHTTPListenPortSSL}>";
        $f[] = "\tFallbackResource /squidcache.php";
        $f[] = "\tServerName {$ipaddr}";
        $f[] = "\tDocumentRoot /usr/share/artica-postfix";
        $f[] = "\tSSLEngine on";
        $f[] = "\tSSLCertificateFile \"{$cert}\"";
        $f[] = "\tSSLCertificateKeyFile \"{$key}\"";
        $f[] = "\tSSLVerifyClient none";
        $f[] = "\tServerSignature Off";
        $f[] = $mirrors_conf;
        $f[] = "</VirtualHost>";
    }
    $f[] = "<IfModule mpm_prefork_module>";
    $f[] = "</IfModule>";
    $f[] = "<IfModule mpm_worker_module>";
    $f[] = "\tMinSpareThreads      25";
    $f[] = "\tMaxSpareThreads      75 ";
    $f[] = "\tThreadLimit          64";
    $f[] = "\tThreadsPerChild      25";
    $f[] = "</IfModule>";
    $f[] = "<IfModule mpm_event_module>";
    $f[] = "\tMinSpareThreads      25";
    $f[] = "\tMaxSpareThreads      75 ";
    $f[] = "\tThreadLimit          64";
    $f[] = "\tThreadsPerChild      25";
    $f[] = "</IfModule>";
    $f[] = "AccessFileName .htaccess";
    $f[] = "<Files ~ \"^\\.ht\">";
    $f[] = "\tOrder allow,deny";
    $f[] = "\tDeny from all";
    $f[] = "\tSatisfy all";
    $f[] = "</Files>";
    $f[] = "DefaultType text/plain";
    $f[] = "HostnameLookups Off";
    $f[] = "User\t\t\t\t   {$APACHE_SRC_ACCOUNT}";
    $f[] = "Group\t\t\t\t   {$APACHE_SRC_GROUP}";
    $f[] = "Timeout              300";
    $f[] = "KeepAlive            Off";
    $f[] = "KeepAliveTimeout     15";
    $f[] = "StartServers         1";
    $f[] = "MaxClients           50";
    $f[] = "MinSpareServers      2";
    $f[] = "MaxSpareServers      5";
    $f[] = "MaxRequestsPerChild  5000";
    $f[] = "MaxKeepAliveRequests 100";
    $f[] = "ServerName " . $unix->hostname_g();
    if ($HyperCacheHTTPListenPortSSLEnabled == 1) {
        $f[] = "<IfModule mod_ssl.c>";
        $f[] = "\tSSLRandomSeed connect builtin";
        $f[] = "\tSSLRandomSeed connect file:/dev/urandom 512";
        $f[] = "\tAddType application/x-x509-ca-cert .crt";
        $f[] = "\tAddType application/x-pkcs7-crl    .crl";
        $f[] = "\tSSLPassPhraseDialog  builtin";
        $f[] = "\tSSLSessionCache        shmcb:/var/run/squid/ssl_scache-articahtp(512000)";
        $f[] = "\tSSLSessionCacheTimeout  300";
        $f[] = "\tSSLSessionCacheTimeout  300";
        $f[] = "\tSSLMutex  sem";
        $f[] = "\tSSLCipherSuite HIGH:MEDIUM:!ADH";
        $f[] = "\tSSLProtocol all -SSLv2";
        $f[] = "</IfModule>";
        $f[] = "";
    }
    // $f[]="\tFallbackResource /squidcache.php";
    $f[] = "AddType application/x-httpd-php .php";
    $f[] = "php_value error_log \"/var/log/lighttpd/apache-hotspot-php.log\"";
    $f[] = "<IfModule mod_fcgid.c>";
    $f[] = "\tPHP_Fix_Pathinfo_Enable 1";
    $f[] = "</IfModule>";
    $f[] = "<IfModule mod_php5.c>";
    $f[] = "    <FilesMatch \"\\.ph(p3?|tml)\$\">";
    $f[] = "\tSetHandler application/x-httpd-php";
    $f[] = "    </FilesMatch>";
    $f[] = "    <FilesMatch \"\\.phps\$\">";
    $f[] = "\tSetHandler application/x-httpd-php-source";
    $f[] = "    </FilesMatch>";
    $f[] = "    <IfModule mod_userdir.c>";
    $f[] = "        <Directory /home/*/public_html>";
    $f[] = "            php_admin_value engine Off";
    $f[] = "        </Directory>";
    $f[] = "    </IfModule>";
    $f[] = "</IfModule>";
    $f[] = "<IfModule mod_mime.c>";
    $f[] = "\tTypesConfig /etc/mime.types";
    $f[] = "\tAddType application/x-compress .Z";
    $f[] = "\tAddType application/x-gzip .gz .tgz";
    $f[] = "\tAddType application/x-bzip2 .bz2";
    $f[] = "\tAddType application/x-httpd-php .php .phtml";
    $f[] = "\tAddType application/x-httpd-php-source .phps";
    $f[] = "\tAddLanguage ca .ca";
    $f[] = "\tAddLanguage cs .cz .cs";
    $f[] = "\tAddLanguage da .dk";
    $f[] = "\tAddLanguage de .de";
    $f[] = "\tAddLanguage el .el";
    $f[] = "\tAddLanguage en .en";
    $f[] = "\tAddLanguage eo .eo";
    $f[] = "\tRemoveType  es";
    $f[] = "\tAddLanguage es .es";
    $f[] = "\tAddLanguage et .et";
    $f[] = "\tAddLanguage fr .fr";
    $f[] = "\tAddLanguage he .he";
    $f[] = "\tAddLanguage hr .hr";
    $f[] = "\tAddLanguage it .it";
    $f[] = "\tAddLanguage ja .ja";
    $f[] = "\tAddLanguage ko .ko";
    $f[] = "\tAddLanguage ltz .ltz";
    $f[] = "\tAddLanguage nl .nl";
    $f[] = "\tAddLanguage nn .nn";
    $f[] = "\tAddLanguage no .no";
    $f[] = "\tAddLanguage pl .po";
    $f[] = "\tAddLanguage pt .pt";
    $f[] = "\tAddLanguage pt-BR .pt-br";
    $f[] = "\tAddLanguage ru .ru";
    $f[] = "\tAddLanguage sv .sv";
    $f[] = "\tRemoveType  tr";
    $f[] = "\tAddLanguage tr .tr";
    $f[] = "\tAddLanguage zh-CN .zh-cn";
    $f[] = "\tAddLanguage zh-TW .zh-tw";
    $f[] = "\tAddCharset us-ascii    .ascii .us-ascii";
    $f[] = "\tAddCharset ISO-8859-1  .iso8859-1  .latin1";
    $f[] = "\tAddCharset ISO-8859-2  .iso8859-2  .latin2 .cen";
    $f[] = "\tAddCharset ISO-8859-3  .iso8859-3  .latin3";
    $f[] = "\tAddCharset ISO-8859-4  .iso8859-4  .latin4";
    $f[] = "\tAddCharset ISO-8859-5  .iso8859-5  .cyr .iso-ru";
    $f[] = "\tAddCharset ISO-8859-6  .iso8859-6  .arb .arabic";
    $f[] = "\tAddCharset ISO-8859-7  .iso8859-7  .grk .greek";
    $f[] = "\tAddCharset ISO-8859-8  .iso8859-8  .heb .hebrew";
    $f[] = "\tAddCharset ISO-8859-9  .iso8859-9  .latin5 .trk";
    $f[] = "\tAddCharset ISO-8859-10  .iso8859-10  .latin6";
    $f[] = "\tAddCharset ISO-8859-13  .iso8859-13";
    $f[] = "\tAddCharset ISO-8859-14  .iso8859-14  .latin8";
    $f[] = "\tAddCharset ISO-8859-15  .iso8859-15  .latin9";
    $f[] = "\tAddCharset ISO-8859-16  .iso8859-16  .latin10";
    $f[] = "\tAddCharset ISO-2022-JP .iso2022-jp .jis";
    $f[] = "\tAddCharset ISO-2022-KR .iso2022-kr .kis";
    $f[] = "\tAddCharset ISO-2022-CN .iso2022-cn .cis";
    $f[] = "\tAddCharset Big5        .Big5       .big5 .b5";
    $f[] = "\tAddCharset cn-Big5     .cn-big5";
    $f[] = "\t# For russian, more than one charset is used (depends on client, mostly):";
    $f[] = "\tAddCharset WINDOWS-1251 .cp-1251   .win-1251";
    $f[] = "\tAddCharset CP866       .cp866";
    $f[] = "\tAddCharset KOI8      .koi8";
    $f[] = "\tAddCharset KOI8-E      .koi8-e";
    $f[] = "\tAddCharset KOI8-r      .koi8-r .koi8-ru";
    $f[] = "\tAddCharset KOI8-U      .koi8-u";
    $f[] = "\tAddCharset KOI8-ru     .koi8-uk .ua";
    $f[] = "\tAddCharset ISO-10646-UCS-2 .ucs2";
    $f[] = "\tAddCharset ISO-10646-UCS-4 .ucs4";
    $f[] = "\tAddCharset UTF-7       .utf7";
    $f[] = "\tAddCharset UTF-8       .utf8";
    $f[] = "\tAddCharset UTF-16      .utf16";
    $f[] = "\tAddCharset UTF-16BE    .utf16be";
    $f[] = "\tAddCharset UTF-16LE    .utf16le";
    $f[] = "\tAddCharset UTF-32      .utf32";
    $f[] = "\tAddCharset UTF-32BE    .utf32be";
    $f[] = "\tAddCharset UTF-32LE    .utf32le";
    $f[] = "\tAddCharset euc-cn      .euc-cn";
    $f[] = "\tAddCharset euc-gb      .euc-gb";
    $f[] = "\tAddCharset euc-jp      .euc-jp";
    $f[] = "\tAddCharset euc-kr      .euc-kr";
    $f[] = "\tAddCharset EUC-TW      .euc-tw";
    $f[] = "\tAddCharset gb2312      .gb2312 .gb";
    $f[] = "\tAddCharset iso-10646-ucs-2 .ucs-2 .iso-10646-ucs-2";
    $f[] = "\tAddCharset iso-10646-ucs-4 .ucs-4 .iso-10646-ucs-4";
    $f[] = "\tAddCharset shift_jis   .shift_jis .sjis";
    $f[] = "\tAddType text/html .shtml";
    $f[] = "\tAddOutputFilter INCLUDES .shtml";
    $f[] = "</IfModule>";
    $f[] = $mirrors_conf;
    $f[] = "<Directory \"/usr/share/artica-postfix\">";
    $f[] = "FallbackResource /squidcache.php";
    $f[] = "\tDirectorySlash On";
    $f[] = "\tDirectoryIndex squidcache.php";
    $f[] = "\t\t<Files \"squidcache.php\">";
    $f[] = "\t\t\tOrder allow,deny";
    $f[] = "\t\t\tallow from all";
    $f[] = "\t\t</Files>";
    /*	$f[]="\tErrorDocument 400 /hotspot.php";
    	$f[]="\tErrorDocument 401 /hotspot.php";
    	$f[]="\tErrorDocument 403 /hotspot.php";
    	$f[]="\tErrorDocument 404 /hotspot.php";
    	$f[]="\tErrorDocument 500 /hotspot.php";
    */
    $f[] = "\tOptions -Indexes";
    $f[] = ParseArticaDirectory();
    @chmod("/usr/share/artica-postfix/squidcache.php", 0755);
    @chown("/usr/share/artica-postfix/squidcache.php", "squid");
    if ($HyperCacheHTTPListenPortSSLEnabled == 1) {
        $f[] = "\tSSLOptions +StdEnvVars";
    }
    $f[] = "\tAllowOverride All";
    $f[] = "\tOrder allow,deny";
    $f[] = "\tAllow from all";
    $f[] = "</Directory>";
    if ($EnableArticaApachePHPFPM == 1) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Activate PHP5-FPM\n";
        }
        shell_exec("{$php} /usr/share/artica-postfix/exec.initslapd.php --phppfm");
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Restarting PHP5-FPM\n";
        }
        shell_exec("/etc/init.d/php5-fpm restart");
        $f[] = "\tAlias /php5.fastcgi /var/run/squid/php5.fastcgi";
        $f[] = "\tAddHandler php-script .php";
        $f[] = "\tFastCGIExternalServer /var/run/squid/php5.fastcgi -socket /var/run/php-fpm.sock -idle-timeout 610";
        $f[] = "\tAction php-script /php5.fastcgi virtual";
        $f[] = "\t<Directory /var/run/squid>";
        $f[] = "\t\t<Files php5.fastcgi>";
        $f[] = "\t\tOrder deny,allow";
        $f[] = "\t\tAllow from all";
        $f[] = "\t\t</Files>";
        $f[] = "\t</Directory>";
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} PHP5-FPM is disabled\n";
        }
    }
    if ($EnableArticaApachePHPFPM == 0) {
        $array["php5_module"] = "libphp5.so";
    }
    $array["dumpio_module"] = "mod_dumpio.so";
    $array["actions_module"] = "mod_actions.so";
    $array["expires_module"] = "mod_expires.so";
    $array["rewrite_module"] = "mod_rewrite.so";
    $array["dir_module"] = "mod_dir.so";
    $array["mime_module"] = "mod_mime.so";
    $array["alias_module"] = "mod_alias.so";
    $array["auth_basic_module"] = "mod_auth_basic.so";
    $array["authz_host_module"] = "mod_authz_host.so";
    $array["autoindex_module"] = "mod_autoindex.so";
    $array["negotiation_module"] = "mod_negotiation.so";
    if ($HyperCacheHTTPListenPortSSLEnabled == 1) {
        $array["ssl_module"] = "mod_ssl.so";
    }
    $array["headers_module"] = "mod_headers.so";
    //$array["ldap_module"]="mod_ldap.so";
    if ($EnableArticaApachePHPFPM == 1) {
        $array["fastcgi_module"] = "mod_fastcgi.so";
    }
    if (is_dir("/etc/apache2")) {
        if (!is_file("/etc/apache2/mime.types")) {
            if ($apache_LOCATE_MIME_TYPES != "/etc/apache2/mime.types") {
                @copy($apache_LOCATE_MIME_TYPES, "/etc/apache2/mime.types");
            }
        }
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Mime types path.......: {$apache_LOCATE_MIME_TYPES}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Modules path..........: {$APACHE_MODULES_PATH}\n";
    }
    while (list($module, $lib) = each($array)) {
        if (is_file("{$APACHE_MODULES_PATH}/{$lib}")) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} include module \"{$module}\"\n";
            }
            $f[] = "LoadModule {$module} {$APACHE_MODULES_PATH}/{$lib}";
        } else {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} skip module \"{$module}\"\n";
            }
        }
    }
    @file_put_contents("/etc/artica-postfix/HyperCacheHTTPD.conf", @implode("\n", $f));
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} /etc/artica-postfix/HyperCacheHTTPD.conf done\n";
    }
}