Exemple #1
0
function CheckHttpdConf()
{
    EnableMods();
    apache_user();
    $sock = $GLOBALS["CLASS_SOCKETS"];
    $unix = new unix();
    $users = new usersMenus();
    $GLOBALS["ToRestore"] = array();
    $freeweb = new freeweb();
    $chmod = $unix->find_program("chmod");
    $php5 = $unix->LOCATE_PHP5_BIN();
    $httpdconf = $unix->LOCATE_APACHE_CONF_PATH();
    if (!is_file($httpdconf)) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: Apache unable to stat configuration file\n";
        return;
    }
    $d_path = $unix->APACHE_DIR_SITES_ENABLED();
    $DAEMON_PATH = $unix->getmodpathfromconf($httpdconf);
    $APACHE_SRC_ACCOUNT = $unix->APACHE_SRC_ACCOUNT();
    $APACHE_SRC_GROUP = $unix->APACHE_SRC_GROUP();
    if (is_file("/etc/apache2/sites-available/default-ssl")) {
        @unlink("/etc/apache2/sites-available/default-ssl");
    }
    if (is_link("/etc/apache2/sites-enabled/000-default")) {
        @unlink("/etc/apache2/sites-enabled/000-default");
    }
    echo "Starting......: " . date("H:i:s") . " [INIT]: Apache daemon path: \"{$DAEMON_PATH}\" run has \"{$APACHE_SRC_ACCOUNT}:{$APACHE_SRC_GROUP}\"\n";
    if ($APACHE_SRC_ACCOUNT == null) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: Apache daemon unable to determine user that will run apache\n";
        die;
    }
    if (!is_dir("/var/log/apache2")) {
        @mkdir("/var/log/apache2", 0755, true);
    }
    if (!is_dir("/usr/share/GeoIP")) {
        @mkdir("/usr/share/GeoIP", 0755, true);
    }
    shell_exec("{$chmod} 755 /usr/share/GeoIP >/dev/null 2>&1");
    $ApacheDisableModDavFS = intval($sock->GET_INFO("ApacheDisableModDavFS"));
    $ApacheDisableModStatus = intval($sock->GET_INFO("ApacheDisableModStatus"));
    $FreeWebListenPort = $sock->GET_INFO("FreeWebListenPort");
    $FreeWebListenSSLPort = $sock->GET_INFO("FreeWebListenSSLPort");
    $FreeWebEnableModSUPhp = $sock->GET_INFO("FreeWebEnableModSUPhp");
    $FreeWebsEnableModSecurity = $sock->GET_INFO("FreeWebsEnableModSecurity");
    $FreeWebsEnableModEvasive = $sock->GET_INFO("FreeWebsEnableModEvasive");
    $FreeWebsEnableModQOS = $sock->GET_INFO("FreeWebsEnableModQOS");
    $FreeWebsEnableOpenVPNProxy = $sock->GET_INFO("FreeWebsEnableOpenVPNProxy");
    $FreeWebsOpenVPNRemotPort = trim($sock->GET_INFO("FreeWebsOpenVPNRemotPort"));
    $FreeWebDisableSSL = trim($sock->GET_INFO("FreeWebDisableSSL"));
    $FreeWebEnableSQLLog = trim($sock->GET_INFO("FreeWebEnableSQLLog"));
    $ApacheServerTokens = $sock->GET_INFO("ApacheServerTokens");
    if ($ApacheServerTokens == null) {
        $ApacheServerTokens = "Full";
    }
    $hostname = $sock->GET_INFO("ApacheServerName");
    if ($hostname == null) {
        $hostname = $sock->getFrameWork("system.php?hostname-g=yes");
        $sock->SET_INFO($hostname, "ApacheServerName");
    }
    $ZarafaWebAccessInFrontEnd = $sock->GET_INFO("ZarafaWebAccessInFrontEnd");
    if (!is_numeric($ZarafaWebAccessInFrontEnd)) {
        $ZarafaWebAccessInFrontEnd = 1;
    }
    $TomcatEnable = $sock->GET_INFO("TomcatEnable");
    if (!is_numeric($FreeWebDisableSSL)) {
        $FreeWebDisableSSL = 0;
    }
    if (!is_numeric($FreeWebListenSSLPort)) {
        $FreeWebListenSSLPort = 443;
    }
    if (!is_numeric($FreeWebListenPort)) {
        $FreeWebListenPort = 80;
    }
    if (!is_numeric($FreeWebsEnableModSecurity)) {
        $FreeWebsEnableModSecurity = 0;
    }
    if (!is_numeric($FreeWebsEnableModEvasive)) {
        $FreeWebsEnableModEvasive = 0;
    }
    if (!is_numeric($FreeWebsEnableModQOS)) {
        $FreeWebsEnableModQOS = 0;
    }
    if (!is_numeric($FreeWebsEnableOpenVPNProxy)) {
        $FreeWebsEnableOpenVPNProxy = 0;
    }
    if (!is_numeric($TomcatEnable)) {
        $TomcatEnable = 1;
    }
    if (!is_numeric($FreeWebEnableSQLLog)) {
        $FreeWebEnableSQLLog = 0;
    }
    if (!is_numeric($FreeWebEnableModSUPhp)) {
        $FreeWebEnableModSUPhp = 0;
    }
    if ($unix->isNGnx()) {
        $FreeWebListenSSLPort = 447;
        $FreeWebListenPort = 82;
    }
    if ($unix->IsSquidReverse()) {
        $FreeWebListenSSLPort = 447;
        $FreeWebListenPort = 82;
    }
    $APACHE_MODULES_PATH = $unix->APACHE_MODULES_PATH();
    $toremove[] = "mod-status.init";
    $toremove[] = "status.conf";
    $toremove[] = "fcgid.load";
    $toremove[] = "fcgid.conf";
    $toremove[] = "fastcgi.conf";
    $toremove[] = "fastcgi.load";
    $toremove[] = "fastcgi.conf";
    $toremove[] = "log_sql.load";
    $toremove[] = "log_sql_mysql.load";
    $toremove[] = "geoip.conf";
    $toremove[] = "bw.load";
    $toremove[] = "geoip_module.load";
    $toremove[] = "log_sql_module.conf";
    $toremove[] = "log_sql_module.load";
    $toremove[] = "log_sql_mysql_module.load";
    $toremove[] = "log_sql_ssl.load";
    $toremove[] = "unique_id.load";
    $toremove[] = "mime.conf";
    $toremove[] = "mime.load";
    $toremove[] = "php5.conf";
    $toremove[] = "php5.load";
    $toremove[] = "fcgid_module.load";
    $toremove[] = "php5-fpm.load";
    $toremove[] = "fastcgi.load";
    $toremove[] = "php5-fpm.conf";
    $toremove[] = "bw.load";
    $toremove[] = "status_module.load";
    $toremove[] = "autoindex.load";
    $toremove[] = "ldap.load";
    if (is_file("/etc/apache2/sites-enabled/000-default")) {
        $ToDeleteDefault = true;
        $q = new mysql();
        $ligne = @mysql_fetch_array($q->QUERY_SQL("SELECT servername,enabled FROM freeweb WHERE servername='_default_'", 'artica_backup'));
        if ($q->ok) {
            if ($ligne["servername"] == "_default_") {
                if ($ligne["enabled"] == 1) {
                    $ToDeleteDefault = false;
                }
            }
        } else {
            $ToDeleteDefault = false;
        }
        if ($ZarafaWebAccessInFrontEnd == 1) {
            $ToDeleteDefault = false;
        }
        if ($ToDeleteDefault) {
            @unlink("/etc/apache2/sites-enabled/000-default");
        }
    }
    if (is_file("/etc/apache2/conf.d/other-vhosts-access-log")) {
        @unlink("/etc/apache2/conf.d/other-vhosts-access-log");
    }
    @mkdir("/etc/apache2/htdocs", 0755, true);
    if (is_file("/etc/apache2/sites-enabled/default-www")) {
        @unlink("/etc/apache2/sites-enabled/default-www");
    }
    if (is_file("/etc/apache2/sites-available/default")) {
        @unlink("/etc/apache2/sites-available/default");
    }
    if (is_file("/etc/apache2/conf.d/zarafa-webaccess.conf")) {
        @unlink("/etc/apache2/conf.d/zarafa-webaccess.conf");
    }
    if (is_file("/etc/apache2/conf.d/zarafa-webaccess-mobile.conf")) {
        @unlink("/etc/apache2/conf.d/zarafa-webaccess-mobile.conf");
    }
    if (is_file("/etc/httpd/conf/extra/httpd-info.conf")) {
        @unlink("/etc/httpd/conf/extra/httpd-info.conf");
    }
    if (is_file("/etc/apache2/mods-enabled/ssl.conf")) {
        @unlink("/etc/apache2/mods-enabled/ssl.conf");
    }
    $FreeWebListen = $unix->APACHE_ListenDefaultAddress();
    while (list($num, $file) = each($toremove)) {
        if (is_file("{$DAEMON_PATH}/mods-enabled/{$file}")) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Apache remove mods-enabled/{$file}\n";
            shell_exec("/bin/rm -f {$DAEMON_PATH}/mods-enabled/{$file} >/dev/null 2>&1");
        }
        if (is_file("{$DAEMON_PATH}/mods-enabled/{$file}")) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Apache remove mods-available/{$file}\n";
            shell_exec("/bin/rm -f {$DAEMON_PATH}/mods-available/{$file} >/dev/null 2>&1");
        }
    }
    php5_conf($DAEMON_PATH);
    if ($FreeWebDisableSSL == 1) {
        $FreeWebListenSSLPort = 0;
    }
    $VirtualHostsIPAddresses = VirtualHostsIPAddresses($FreeWebListenPort, $FreeWebListen, $FreeWebListenSSLPort);
    if (count($VirtualHostsIPAddresses[0]) > 0) {
        $conf[] = @implode("\n", $VirtualHostsIPAddresses[0]);
    }
    if (count($VirtualHostsIPAddresses[1]) > 0) {
        $conf[] = @implode("\n", $VirtualHostsIPAddresses[1]);
    }
    if ($FreeWebDisableSSL == 0) {
        $conf[] = "<IfModule mod_ssl.c>";
        //$conf[]="\tListen $FreeWebListenSSLPort";
        $conf[] = "\tNameVirtualHost {$FreeWebListen}:{$FreeWebListenSSLPort}";
        if ($VirtualHostsIPAddresses[2] > 0) {
            $conf[] = @implode("\n", $VirtualHostsIPAddresses[2]);
        }
        $conf[] = "\tSSLPassPhraseDialog exec:/etc/apache2/ssl-tools/sslpass.sh";
        shell_exec("{$php5} /usr/share/artica-postfix/exec.openssl.php --pass");
        $conf[] = "</IfModule>";
        $conf[] = "";
        $conf[] = "<IfModule mod_gnutls.c>";
        $conf[] = "\tNameVirtualHost {$FreeWebListen}:{$FreeWebListenSSLPort}";
        if ($VirtualHostsIPAddresses[2] > 0) {
            $conf[] = @implode("\n", $VirtualHostsIPAddresses[2]);
        }
        //$conf[]="\tListen $FreeWebListenSSLPort";
        $conf[] = "</IfModule>";
    }
    $conf[] = "<IfModule mod_fcgid.c>";
    $conf[] = "\tPHP_Fix_Pathinfo_Enable 1";
    $conf[] = "</IfModule>";
    $conf[] = "<IfModule mod_fastcgi.c>";
    $conf[] = "\tAddHandler fastcgi-script .fcgi";
    $conf[] = "#FastCgiWrapper /usr/lib/apache2/suexec";
    $conf[] = "\tFastCgiIpcDir /var/lib/apache2/fastcgi";
    $conf[] = "</IfModule>";
    if (is_file("/usr/lib/apache2/modules/mod_cband.so")) {
        $conf[] = "<IfModule mod_cband.c>";
        $conf[] = "\tCBandScoreFlushPeriod 1";
        $conf[] = "\tCBandRandomPulse On";
        $conf[] = "</IfModule>";
    }
    $conf[] = "";
    if (!is_dir("{$DAEMON_PATH}/sites-available")) {
        @mkdir("{$DAEMON_PATH}/sites-available", 666, true);
    }
    if (!is_dir("{$DAEMON_PATH}/BackupConf")) {
        @mkdir("{$DAEMON_PATH}/BackupConf", 666, true);
    }
    if (is_file("{$DAEMON_PATH}/ports.conf")) {
        @unlink("{$DAEMON_PATH}/BackupConf/ports.conf");
        @copy("{$DAEMON_PATH}/ports.conf", "{$DAEMON_PATH}/BackupConf/ports.conf");
        $GLOBALS["ToRestore"][] = "{$DAEMON_PATH}/BackupConf/ports.conf";
    }
    @file_put_contents("{$DAEMON_PATH}/ports.conf", @implode("\n", $conf));
    echo "Starting......: " . date("H:i:s") . " [INIT]: Apache {$DAEMON_PATH}/ports.conf for NameVirtualHost {$FreeWebListen}:{$FreeWebListenPort} done\n";
    mod_security();
    if ($FreeWebsEnableModEvasive == 1) {
        $Params = unserialize(base64_decode($sock->GET_INFO("modEvasiveDefault")));
        if (!is_numeric($Params["DOSHashTableSize"])) {
            $Params["DOSHashTableSize"] = 1024;
        }
        if (!is_numeric($Params["DOSPageCount"])) {
            $Params["DOSPageCount"] = 10;
        }
        if (!is_numeric($Params["DOSSiteCount"])) {
            $Params["DOSSiteCount"] = 150;
        }
        if (!is_numeric($Params["DOSPageInterval"])) {
            $Params["DOSPageInterval"] = 1.5;
        }
        if (!is_numeric($Params["DOSSiteInterval"])) {
            $Params["DOSSiteInterval"] = 1.5;
        }
        if (!is_numeric($Params["DOSBlockingPeriod"])) {
            $Params["DOSBlockingPeriod"] = 10.7;
        }
        $f[] = "   LoadModule evasive20_module modules/mod_evasive20.so";
        $f[] = "   ExtendedStatus On";
        $f[] = "   DOSHashTableSize {$Params["DOSHashTableSize"]}";
        $f[] = "   DOSPageCount {$Params["DOSPageCount"]}";
        $f[] = "   DOSSiteCount {$Params["DOSSiteCount"]}";
        $f[] = "   DOSPageInterval {$Params["DOSPageInterval"]}";
        $f[] = "   DOSSiteInterval {$Params["DOSSiteInterval"]}";
        $f[] = "   DOSBlockingPeriod {$Params["DOSBlockingPeriod"]}";
        $f[] = "   DOSLogDir  \"/var/log/apache2/mod_evasive.log\"";
        $f[] = "   DOSSystemCommand \"/bin/echo `date '+%F %T'` apache2  %s >> /var/log/apache2/dos_evasive_attacks.log\"";
        $f[] = "";
        echo "Starting......: " . date("H:i:s") . " [INIT]: Apache {$DAEMON_PATH}/mod_evasive.conf\n";
        if (is_file("{$DAEMON_PATH}/mod_evasive.conf")) {
            @unlink("{$DAEMON_PATH}/BackupConf/mod_evasive.conf");
            @copy("{$DAEMON_PATH}/ports.conf", "{$DAEMON_PATH}/BackupConf/mod_evasive.conf");
            $GLOBALS["ToRestore"][] = "{$DAEMON_PATH}/BackupConf/mod_evasive.conf";
        }
        @file_put_contents("{$DAEMON_PATH}/mod_evasive.conf", @implode("\n", $f));
        unset($f);
    }
    @mkdir("/var/run/apache2", 0775, true);
    if (is_file("{$DAEMON_PATH}/ssl.conf")) {
        @unlink("{$DAEMON_PATH}/BackupConf/ssl.conf");
        @copy("{$DAEMON_PATH}/ports.conf", "{$DAEMON_PATH}/BackupConf/ssl.conf");
        $GLOBALS["ToRestore"][] = "{$DAEMON_PATH}/BackupConf/ssl.conf";
    }
    @unlink("{$DAEMON_PATH}/ssl.conf");
    if ($FreeWebDisableSSL == 0) {
        $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/apache2/ssl_scache(512000)";
        $f[] = "\tSSLSessionCacheTimeout  300";
        $f[] = "\tSSLSessionCacheTimeout  300";
        $f[] = "\tSSLMutex  sem";
        //$f[]="	SSLMutex  file:/var/run/apache2/ssl_mutex";
        $f[] = "\tSSLCipherSuite HIGH:MEDIUM:!ADH";
        $f[] = "\tSSLProtocol all -SSLv2";
        $f[] = "</IfModule>";
        $f[] = "";
        @file_put_contents("{$DAEMON_PATH}/ssl.conf", @implode("\n", $f));
        unset($f);
    }
    apache_security($DAEMON_PATH);
    $httpdconf_data = @file_get_contents($httpdconf);
    $httpdconf_basename = basename($httpdconf);
    if (is_file($httpdconf)) {
        @unlink("{$DAEMON_PATH}/BackupConf/{$httpdconf_basename}");
        @copy("{$DAEMON_PATH}/{$httpdconf_basename}", "{$DAEMON_PATH}/BackupConf/{$httpdconf_basename}");
        $GLOBALS["ToRestore"][] = "{$DAEMON_PATH}/BackupConf/{$httpdconf_basename}";
    }
    if (preg_match("#<Location \\/server-status>(.+?)<\\/Location>#is", $httpdconf_data, $re)) {
        $httpdconf_data = str_replace($re[0], "", $httpdconf_data);
    }
    $f = explode("\n", $httpdconf_data);
    while (list($num, $ligne) = each($f)) {
        if (preg_match("#^Include\\s+#", $ligne)) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Apache removing {$f[$num]}\n";
            $f[$num] = null;
        }
        if (preg_match("#\\#.*?Include\\s+#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#Listen\\s+#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#ProxyRequests#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#ProxyVia#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#AllowCONNECT#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#KeepAlive#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#Timeout\\s+[0-9]+#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#MaxKeepAliveRequests\\s+#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#KeepAliveTimeout\\s+#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#MinSpareServers\\s+#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#MaxSpareServers\\s+#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#StartServers\\s+#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#MaxClients\\s+#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#MaxRequestsPerChild\\s+#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#ExtendedStatus\\s+#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#LoadModule\\s+#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#ErrorLog\\s+#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#LogFormat\\s+#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#User\\s+#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#Group\\s+#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#CustomLog\\s+#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#LogLevel#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#ServerName#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#DavLockDB#", $ligne)) {
            $f[$num] = null;
        }
        if (trim($ligne) == "Loglevel info") {
            $f[$num] = null;
        }
    }
    $FreeWebPerformances = unserialize(base64_decode($sock->GET_INFO("FreeWebPerformances")));
    if (!isset($FreeWebPerformances["Timeout"])) {
        $FreeWebPerformances["Timeout"] = 300;
    }
    if (!isset($FreeWebPerformances["KeepAlive"])) {
        $FreeWebPerformances["KeepAlive"] = 0;
    }
    if (!isset($FreeWebPerformances["MaxKeepAliveRequests"])) {
        $FreeWebPerformances["MaxKeepAliveRequests"] = 100;
    }
    if (!isset($FreeWebPerformances["KeepAliveTimeout"])) {
        $FreeWebPerformances["KeepAliveTimeout"] = 15;
    }
    if (!isset($FreeWebPerformances["MinSpareServers"])) {
        $FreeWebPerformances["MinSpareServers"] = 1;
    }
    if (!isset($FreeWebPerformances["MaxSpareServers"])) {
        $FreeWebPerformances["MaxSpareServers"] = 2;
    }
    if (!isset($FreeWebPerformances["StartServers"])) {
        $FreeWebPerformances["StartServers"] = 1;
    }
    if (!isset($FreeWebPerformances["MaxClients"])) {
        $FreeWebPerformances["MaxClients"] = 50;
    }
    if (!isset($FreeWebPerformances["MaxRequestsPerChild"])) {
        $FreeWebPerformances["MaxRequestsPerChild"] = 10000;
    }
    if (!is_numeric($FreeWebPerformances["Timeout"])) {
        $FreeWebPerformances["Timeout"] = 300;
    }
    if (!is_numeric($FreeWebPerformances["KeepAlive"])) {
        $FreeWebPerformances["KeepAlive"] = 0;
    }
    if (!is_numeric($FreeWebPerformances["MaxKeepAliveRequests"])) {
        $FreeWebPerformances["MaxKeepAliveRequests"] = 100;
    }
    if (!is_numeric($FreeWebPerformances["KeepAliveTimeout"])) {
        $FreeWebPerformances["KeepAliveTimeout"] = 15;
    }
    if (!is_numeric($FreeWebPerformances["MinSpareServers"])) {
        $FreeWebPerformances["MinSpareServers"] = 1;
    }
    if (!is_numeric($FreeWebPerformances["MaxSpareServers"])) {
        $FreeWebPerformances["MaxSpareServers"] = 2;
    }
    if (!is_numeric($FreeWebPerformances["StartServers"])) {
        $FreeWebPerformances["StartServers"] = 1;
    }
    if (!is_numeric($FreeWebPerformances["MaxClients"])) {
        $FreeWebPerformances["MaxClients"] = 50;
    }
    if (!is_numeric($FreeWebPerformances["MaxRequestsPerChild"])) {
        $FreeWebPerformances["MaxRequestsPerChild"] = 10000;
    }
    reset($f);
    while (list($num, $ligne) = each($f)) {
        if (trim($ligne) == null) {
            continue;
        }
        if (substr($ligne, 0, 1) == "#") {
            continue;
        }
        $httpd[] = $ligne;
    }
    $php5 = $unix->LOCATE_PHP5_BIN();
    shell_exec("{$php5} /usr/share/artica-postfix/exec.samba.php --fix-etc-hosts >/dev/null 2>&1");
    if ($APACHE_SRC_GROUP == '${APACHE_RUN_GROUP}') {
        $APACHE_SRC_GROUP = $APACHE_SRC_ACCOUNT;
    }
    if ($FreeWebPerformances["KeepAlive"] == 1) {
        $FreeWebPerformances["KeepAlive"] = "On";
    } else {
        $FreeWebPerformances["KeepAlive"] = "Off";
    }
    $httpd[] = "User\t\t\t\t   {$APACHE_SRC_ACCOUNT}";
    $httpd[] = "Group\t\t\t\t   {$APACHE_SRC_GROUP}";
    $httpd[] = "Timeout              {$FreeWebPerformances["Timeout"]}";
    $httpd[] = "KeepAlive            {$FreeWebPerformances["KeepAlive"]}";
    $httpd[] = "KeepAliveTimeout     {$FreeWebPerformances["KeepAliveTimeout"]}";
    $httpd[] = "StartServers         {$FreeWebPerformances["StartServers"]}";
    $httpd[] = "MaxClients           {$FreeWebPerformances["MaxClients"]}";
    $httpd[] = "MinSpareServers      {$FreeWebPerformances["MinSpareServers"]}";
    $httpd[] = "MaxSpareServers      {$FreeWebPerformances["MaxSpareServers"]}";
    $httpd[] = "MaxRequestsPerChild  {$FreeWebPerformances["MaxRequestsPerChild"]}";
    $httpd[] = "MaxKeepAliveRequests {$FreeWebPerformances["MaxKeepAliveRequests"]}";
    $httpd[] = "ServerName {$hostname}";
    if ($FreeWebsEnableOpenVPNProxy == 1) {
        if ($FreeWebsOpenVPNRemotPort != null) {
            $httpd[] = "ProxyRequests On";
            $httpd[] = "ProxyVia On";
            $httpd[] = "AllowCONNECT {$FreeWebsOpenVPNRemotPort}";
            $httpd[] = "KeepAlive On";
        }
    }
    @unlink("{$DAEMON_PATH}/mods-enabled/klms.FastCgiExternalServer.conf");
    if ($users->KLMS_WEB_INSTALLED) {
        $sql = "SELECT COUNT(*) as tcount FROM freeweb WHERE groupware='KLMS'";
        $q = new mysql();
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
        $CountDeGroupware = $ligne["tcount"];
        echo "Starting......: " . date("H:i:s") . " {$CountDeGroupware} KLMS Groupware(s)\n";
        if ($CountDeGroupware > 0) {
            if (is_file("/opt/kaspersky/klmsui/share/htdocs/cgi-bin/klwi")) {
                @file_put_contents("{$DAEMON_PATH}/mods-enabled/klms.FastCgiExternalServer.conf", "FastCgiExternalServer /opt/kaspersky/klmsui/share/htdocs/cgi-bin/klwi -host 127.0.0.1:2711\n");
            }
        }
    }
    //$dir_master=$unix->getmodpathfromconf();
    if (is_file('/usr/lib/apache2/modules/mod_kav64.so')) {
        $sock = new sockets();
        $ApacheEnableKavModule = intval($sock->GET_INFO("ApacheEnableKavModule"));
        if ($ApacheEnableKavModule == 1) {
            $httpd[] = "LoadModule kav_module /usr/lib/apache2/modules/mod_kav64.so";
        }
    }
    if (!is_file("{$DAEMON_PATH}/videocache.conf")) {
        @touch("{$DAEMON_PATH}/videocache.conf");
    }
    $httpd[] = "Include {$DAEMON_PATH}/videocache.conf";
    if (is_file("{$DAEMON_PATH}/security.conf")) {
        $httpd[] = "Include {$DAEMON_PATH}/security.conf";
    }
    $httpd[] = "Include {$DAEMON_PATH}/mods-enabled/*.load";
    $httpd[] = "Include {$DAEMON_PATH}/mods-enabled/*.conf";
    $httpd[] = "Include {$DAEMON_PATH}/mods-enabled/*.init";
    $mod_php5[] = "<IfModule mod_php5.c>";
    $mod_php5[] = "    <FilesMatch \"\\.ph(p3?|tml)\$\">";
    $mod_php5[] = "\tSetHandler application/x-httpd-php";
    $mod_php5[] = "    </FilesMatch>";
    $mod_php5[] = "    <FilesMatch \"\\.phps\$\">";
    $mod_php5[] = "\tSetHandler application/x-httpd-php-source";
    $mod_php5[] = "    </FilesMatch>";
    $mod_php5[] = "    # To re-enable php in user directories comment the following lines";
    $mod_php5[] = "    # (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it";
    $mod_php5[] = "    # prevents .htaccess files from disabling it.";
    $mod_php5[] = "    <IfModule mod_userdir.c>";
    $mod_php5[] = "        <Directory /home/*/public_html>";
    $mod_php5[] = "            php_admin_value engine Off";
    $mod_php5[] = "        </Directory>";
    $mod_php5[] = "    </IfModule>";
    $mod_php5[] = "</IfModule>";
    echo "Starting......: " . date("H:i:s") . " [INIT]: Apache saving: {$DAEMON_PATH}/mods-enabled/mod_php5.conf\n";
    @file_put_contents("{$DAEMON_PATH}/mods-enabled/mod_php5.conf", @implode("\n", $mod_php5));
    $httpd[] = "Include {$DAEMON_PATH}/mods-enabled/mod_php5.conf";
    $mod_php5 = array();
    if (basename($httpdconf) != "httpd.conf") {
        $httpd[] = "Include {$DAEMON_PATH}/httpd.conf";
    }
    $httpd[] = "Include {$DAEMON_PATH}/ports.conf";
    if ($FreeWebsEnableModSecurity == 1) {
        $httpd[] = "Include {$DAEMON_PATH}/mod_security.conf";
    }
    if ($FreeWebsEnableModEvasive == 1) {
        $httpd[] = "Include {$DAEMON_PATH}/mod_evasive.conf";
    }
    echo "Starting......: " . date("H:i:s") . " [INIT]: Apache checks WebDav (ApacheDisableModDavFS = {$ApacheDisableModDavFS})\n";
    $freeweb_tmp = new freeweb();
    $WebDavContainers = $freeweb_tmp->WebDavContainers();
    echo "Starting......: " . date("H:i:s") . " [INIT]: Apache checks WebDav " . strlen($WebDavContainers) . " bytes\n";
    @file_put_contents("{$DAEMON_PATH}/webdavcontainers.conf", $WebDavContainers);
    if ($ApacheDisableModDavFS == 0) {
        $httpd[] = "DavLockDB \"/var/www/.DavLockDB\"";
        @mkdir("/var/www", 0755, true);
        @chown("/var/www", $APACHE_SRC_ACCOUNT);
        @chgrp("/var/www", $APACHE_SRC_GROUP);
    }
    @mkdir("/var/lib/apache2/fastcgi", 0755, true);
    @chown("/var/lib/apache2/fastcgi", $APACHE_SRC_ACCOUNT);
    @chgrp("/var/lib/apache2/fastcgi", $APACHE_SRC_GROUP);
    $httpd[] = 'Loglevel info';
    $httpd[] = 'ErrorLog /var/log/apache2/error.log';
    $httpd[] = 'LogFormat "%h %l %u %t \\"%r\\" %<s %b" common';
    $httpd[] = 'CustomLog /var/log/apache2/access.log common';
    $mod_status = $freeweb->mod_status();
    if ($mod_status != null) {
        $status[] = "<IfModule mod_status.c>";
        $status[] = "\tExtendedStatus On";
        $status[] = "{$mod_status}";
        $status[] = "</IfModule>";
        @file_put_contents("{$DAEMON_PATH}/mods-enabled/mod-status.init", @implode("\n", $status));
    }
    @unlink("{$DAEMON_PATH}/mods-enabled/pagespeed.conf");
    if ($users->APACHE_MOD_PAGESPEED) {
        if (!is_dir("/var/cache/apache2/mod_pagespeed/default/files")) {
            @mkdir("/var/cache/apache2/mod_pagespeed/default/files", 644, true);
        }
        $pspedd[] = "<IfModule pagespeed_module>";
        $pspedd[] = "\tModPagespeedFileCachePath            \"/var/cache/apache2/mod_pagespeed/default\"";
        $pspedd[] = "\tModPagespeedGeneratedFilePrefix      \"/var/cache/apache2/mod_pagespeed/files/\"";
        $pspedd[] = "\tSetOutputFilter MOD_PAGESPEED_OUTPUT_FILTER";
        $pspedd[] = "\tAddOutputFilterByType MOD_PAGESPEED_OUTPUT_FILTER text/html";
        $pspedd[] = "</IfModule>";
        @file_put_contents("{$DAEMON_PATH}/mods-enabled/pagespeed.conf", @implode("\n", $pspedd));
    }
    if ($users->APACHE_MOD_LOGSSQL) {
        if ($FreeWebEnableSQLLog == 1) {
            $q = new mysql();
            if (!$q->DATABASE_EXISTS("apachelogs")) {
                $q->CREATE_DATABASE("apachelogs");
            }
            $APACHE_MOD_LOGSSQL[] = "<IfModule log_sql_mysql_module>";
            $APACHE_MOD_LOGSSQL[] = "\tLogSQLLoginInfo mysql://{$q->mysql_admin}:{$q->mysql_password}@{$q->mysql_server}:{$q->mysql_port}/apachelogs";
            $APACHE_MOD_LOGSSQL[] = "\tLogSQLMassVirtualHosting On";
            $APACHE_MOD_LOGSSQL[] = "\tLogSQLmachineID {$users->hostname}";
            $APACHE_MOD_LOGSSQL[] = "\tLogSQLTransferLogFormat AbcHhmMpRSstTUuvz";
            $APACHE_MOD_LOGSSQL[] = "</IfModule>";
            @file_put_contents("{$DAEMON_PATH}/mods-enabled/log_sql_module.conf", @implode("\n", $APACHE_MOD_LOGSSQL));
        }
    }
    CheckHttpdConf_mime_module();
    CheckHttpdConf_mailman();
    if (is_file("/etc/apache2/mailman.conf")) {
        $httpd[] = "Include /etc/apache2/mailman.conf";
    }
    if (is_file("/etc/apache2/sysconfig.d/loadmodule.conf")) {
        $httpd[] = "Include /etc/apache2/sysconfig.d/loadmodule.conf";
    }
    if (is_file("/etc/apache2/uid.conf")) {
        $httpd[] = "Include /etc/apache2/uid.conf";
    }
    if (is_file("/etc/apache2/default-server.conf")) {
        patch_suse_default_server();
        $httpd[] = "Include /etc/apache2/default-server.conf";
    }
    $httpd[] = "Include {$DAEMON_PATH}/mime.conf";
    $httpd[] = "Include {$DAEMON_PATH}/conf.d/";
    $httpd[] = "Include {$DAEMON_PATH}/sites-enabled/";
    $httpd[] = "Include {$DAEMON_PATH}/webdavcontainers.conf";
    //PHP5 MODULE
    //if(is_file("$APACHE_MODULES_PATH/mod_php5.so")){$httpd[]="LoadModule php5_module $APACHE_MODULES_PATH/mod_php5.so";}
    //if(is_file("$APACHE_MODULES_PATH/mod_ldap.so")){$httpd[]="LoadModule ldap_module $APACHE_MODULES_PATH/mod_ldap.so";}
    if ($ApacheDisableModDavFS == 0) {
        if (is_file("{$APACHE_MODULES_PATH}/mod_dav.so")) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Apache module 'dav_module' enabled\n";
            $httpd[] = "LoadModule dav_module {$APACHE_MODULES_PATH}/mod_dav.so";
        }
        if (is_file("{$APACHE_MODULES_PATH}/mod_dav_lock.so")) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Apache module 'dav_lock_module' enabled\n";
            $httpd[] = "LoadModule dav_lock_module {$APACHE_MODULES_PATH}/mod_dav_lock.so";
        }
        if (is_file("{$APACHE_MODULES_PATH}/mod_dav_fs.so")) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Apache module 'dav_fs_module' enabled\n";
            $httpd[] = "LoadModule dav_fs_module {$APACHE_MODULES_PATH}/mod_dav_fs.so";
        }
    }
    $httpd[] = "";
    $httpd[] = YfiAdds();
    echo "Starting......: " . date("H:i:s") . " [INIT]: Apache {$httpdconf} done\n";
    @file_put_contents($httpdconf, @implode("\n", $httpd));
    // MODULES -----------------------------------------------------------------------
    if (!is_dir("{$DAEMON_PATH}/mods-enabled")) {
        @mkdir("{$DAEMON_PATH}/mods-enabled", 666, true);
    }
    if (!is_file("{$DAEMON_PATH}/httpd.conf")) {
        @file_put_contents("{$DAEMON_PATH}/httpd.conf", "#");
    }
    @unlink("/etc/libapache2-mod-jk/workers.properties");
    @unlink("/etc/apache2/workers.properties");
    @unlink("{$DAEMON_PATH}/conf.d/jk.conf");
    $free = new freeweb();
    $array["php5_module"] = "libphp5.so";
    if ($users->APACHE_MOD_SUPHP) {
        if ($FreeWebEnableModSUPhp == 1) {
            $array["suphp_module"] = "mod_suphp.so";
        }
    }
    //$array["access_module"]="mod_access.so";
    $array["qos_module"] = "mod_qos.so";
    $array["rewrite_module"] = "mod_rewrite.so";
    $array["cache_module"] = "mod_cache.so";
    $array["disk_cache_module"] = "mod_disk_cache.so";
    $array["mem_cache_module"] = "mod_mem_cache.so";
    $array["expires_module"] = "mod_expires.so";
    $ApacheDisableModStatus = intval($sock->GET_INFO("ApacheDisableModStatus"));
    echo "Starting......: " . date("H:i:s") . " [INIT]: Apache module ApacheDisableModStatus={$ApacheDisableModStatus}\n";
    if ($ApacheDisableModStatus == 0) {
        $array["status_module"] = "mod_status.so";
    }
    if (is_file($free->locate_geoip_db())) {
        $array["geoip_module"] = "mod_geoip.so";
    }
    $array["info_module"] = "mod_info.so";
    $array["suexec_module"] = "mod_suexec.so";
    $array["fcgid_module"] = "mod_fcgid.so";
    $array["authz_host_module"] = "mod_authz_host.so";
    $array["dir_module"] = "mod_dir.so";
    $array["mime_module"] = "mod_mime.so";
    $array["log_config_module"] = "mod_log_config.so";
    $array["alias_module"] = "mod_alias.so";
    $array["autoindex_module"] = "mod_autoindex.so";
    $array["negotiation_module"] = "mod_negotiation.so";
    $array["setenvif_module"] = "mod_setenvif.so";
    $array["logio_module"] = "mod_logio.so";
    $array["auth_basic_module"] = "mod_auth_basic.so";
    $array["authn_file_module"] = "mod_authn_file.so";
    $array["vhost_alias_module"] = "mod_vhost_alias.so";
    $array["python_module"] = "mod_python.so";
    $array["auth_digest_module"] = "mod_auth_digest.so";
    $array["mime_module"] = "mod_mime.so";
    $array["ssl_module"] = "mod_ssl.so";
    if ($FreeWebEnableSQLLog == 1) {
        $array["log_sql_module"] = "mod_log_sql.so";
        $array["log_sql_mysql_module"] = "mod_log_sql_mysql.so";
    }
    if (mod_bw_module_must_be_enabled()) {
        $array["bw_module"] = "mod_bw.so";
    }
    $array["actions_module"] = "mod_actions.so";
    $array["expires_module"] = "mod_expires.so";
    $array["include_module"] = "mod_include.so";
    $array["rpaf_module"] = "mod_rpaf-2.0.so";
    $array["fastcgi_module"] = "mod_fastcgi.so";
    $array["deflate_module"] = "mod_deflate.so";
    $array["headers_module"] = "mod_headers.so";
    $array["cband_module"] = "mod_cband.so";
    if (is_file("{$APACHE_MODULES_PATH}/mod_rpaf-2.0.so")) {
        $net = new networking();
        $ips = $net->ALL_IPS_GET_ARRAY();
        while (list($ip, $line) = each($ips)) {
            $tip[] = $ip;
        }
        $rpfmod[] = "<IfModule mod_rpaf.c>";
        $rpfmod[] = "\tRPAFenable On";
        $rpfmod[] = "\tRPAFsethostname On";
        $rpfmod[] = "\tRPAFproxy_ips " . @implode(" ", $tip);
        $rpfmod[] = "\tRPAFheader X-Forwarded-For";
        $rpfmod[] = "</IfModule>";
        $rpfmod[] = "<IfModule rpaf_module>";
        $rpfmod[] = "\tRPAFenable On";
        $rpfmod[] = "\tRPAFsethostname On";
        $rpfmod[] = "\tRPAFproxy_ips " . @implode(" ", $tip);
        $rpfmod[] = "\tRPAFheader X-Forwarded-For";
        $rpfmod[] = "</IfModule>";
        @file_put_contents("{$DAEMON_PATH}/mods-enabled/rpaf.conf", @implode("\n", $rpfmod));
    }
    if (is_file("{$APACHE_MODULES_PATH}/mod_pagespeed.so")) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: Apache module 'mod_pagespeed' enabled\n";
        $ppsped[] = "LoadModule pagespeed_module {$APACHE_MODULES_PATH}/mod_pagespeed.so";
        if (is_file("{$APACHE_MODULES_PATH}/mod_deflate.so")) {
            $ppsped[] = "# Only attempt to load mod_deflate if it hasn't been loaded already.";
            $ppsped[] = "<IfModule !mod_deflate.c>";
            $ppsped[] = "\tLoadModule deflate_module {$APACHE_MODULES_PATH}/mod_deflate.so";
            $ppsped[] = "</IfModule>";
        }
        @file_put_contents("{$DAEMON_PATH}/mods-enabled/mod_pagespeed.load", @implode("\n", $ppsped));
    } else {
        echo "Starting......: " . date("H:i:s") . " [INIT]: Apache module 'mod_pagespeed' {$APACHE_MODULES_PATH}/mod_pagespeed.so no such file\n";
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "Starting......: " . date("H:i:s") . " [DEBUG] Apache TOMCAT_INSTALLED -> {$users->TOMCAT_INSTALLED}\n";
    }
    if ($users->TOMCAT_INSTALLED) {
        if ($TomcatEnable == 1) {
            if (is_dir($users->TOMCAT_DIR)) {
                if (is_dir($users->TOMCAT_JAVA)) {
                    $array["jk_module"] = "mod_jk.so";
                    $ftom[] = "workers.tomcat_home={$users->TOMCAT_DIR}";
                    $ftom[] = "workers.java_home={$users->TOMCAT_JAVA}";
                    $ftom[] = "ps=/";
                    $ftom[] = "worker.list=ajp13_worker";
                    $ftom[] = "worker.ajp13_worker.port=8009";
                    $ftom[] = "worker.ajp13_worker.host=127.0.0.1";
                    $ftom[] = "worker.ajp13_worker.type=ajp13";
                    $ftom[] = "worker.ajp13_worker.lbfactor=1";
                    $ftom[] = "worker.loadbalancer.type=lb";
                    $ftom[] = "worker.loadbalancer.balance_workers=ajp13_worker";
                    $ftom[] = "";
                    @file_put_contents("/etc/apache2/workers.properties", @implode("\n", $ftom));
                    @mkdir("/etc/libapache2-mod-jk", 644);
                    @file_put_contents("/etc/libapache2-mod-jk/workers.properties", @implode("\n", $ftom));
                    $faptom[] = "<ifmodule mod_jk.c>";
                    $faptom[] = "\tJkWorkersFile /etc/apache2/workers.properties";
                    $faptom[] = "\tJkLogFile /var/log/apache2/mod_jk.log";
                    $faptom[] = "\tJkLogLevel error";
                    $faptom[] = "</ifmodule>";
                    @file_put_contents("{$DAEMON_PATH}/conf.d/jk.conf", @implode("\n", $faptom));
                }
            }
        }
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "Starting......: " . date("H:i:s") . " [DEBUG] Apache cleaning mods...\n";
    }
    @unlink("{$DAEMON_PATH}/mods-enabled/mod-security.load");
    @unlink("{$DAEMON_PATH}/mods-enabled/mod_security.load");
    @unlink("{$DAEMON_PATH}/mods-enabled/mod-evasive.load");
    @unlink("{$DAEMON_PATH}/mods-enabled/mod_evasive.load");
    @unlink("{$DAEMON_PATH}/mods-enabled/geoip.load");
    @unlink("{$DAEMON_PATH}/mods-enabled/status.conf");
    @unlink("{$DAEMON_PATH}/mods-enabled/status.load");
    @unlink("{$DAEMON_PATH}/mods-enabled/php5.load");
    @unlink("{$DAEMON_PATH}/mods-enabled/jk.load");
    @unlink("{$DAEMON_PATH}/mods-enabled/dav_lock_module.load");
    @unlink("{$DAEMON_PATH}/mods-enabled/dav_module.load");
    @unlink("{$DAEMON_PATH}/mods-enabled/dav_fs_module.load");
    @unlink("{$DAEMON_PATH}/mods-enabled/pagespeed.load");
    @unlink("{$DAEMON_PATH}/mods-enabled/rpaf.load");
    @unlink("{$DAEMON_PATH}/mods-enabled/alias.load");
    @unlink("{$DAEMON_PATH}/mods-enabled/auth_basic.load");
    @unlink("{$DAEMON_PATH}/mods-enabled/dir.load");
    @unlink("{$DAEMON_PATH}/mods-enabled/deflate.load");
    @unlink("{$DAEMON_PATH}/mods-enabled/negotiation.load");
    @unlink("{$DAEMON_PATH}/mods-enabled/authn_file.load");
    @unlink("{$DAEMON_PATH}/mods-enabled/authz_host.load");
    @unlink("{$DAEMON_PATH}/mods-enabled/setenvif.load");
    @unlink("{$DAEMON_PATH}/mods-enabled/ssl.load");
    @unlink("{$DAEMON_PATH}/mods-enabled/ldap.load");
    @unlink("{$DAEMON_PATH}/mods-enabled/authnz_ldap.load");
    $sock = new sockets();
    $FreeWebsDisableMOdQOS = $sock->GET_INFO("FreeWebsDisableMOdQOS");
    if ($GLOBALS["VERBOSE"]) {
        echo "Starting......: " . date("H:i:s") . " [DEBUG] Apache FreeWebsDisableMOdQOS = {$FreeWebsDisableMOdQOS} ...\n";
    }
    if (!is_numeric($FreeWebsDisableMOdQOS)) {
        $FreeWebsDisableMOdQOS = 0;
    }
    if ($FreeWebsEnableModQOS == 0) {
        $FreeWebsDisableMOdQOS = 1;
    }
    if ($FreeWebsDisableMOdQOS == 1) {
        unset($array["qos_module"]);
        @unlink("{$DAEMON_PATH}/mods-enabled/qos_module.load");
    }
    if ($FreeWebsEnableModEvasive == 1) {
        if (is_file("{$APACHE_MODULES_PATH}/mod_evasive20.so")) {
            $a[] = "LoadModule evasive20_module {$APACHE_MODULES_PATH}/mod_evasive20.so";
            echo "Starting......: " . date("H:i:s") . " [INIT]: Apache module 'mod_evasive2' enabled\n";
            @file_put_contents("{$DAEMON_PATH}/mods-enabled/mod_evasive.load", @implode("\n", $a));
        } else {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Apache {$APACHE_MODULES_PATH}/mod_evasive20.so no such file\n";
        }
    } else {
        echo "Starting......: " . date("H:i:s") . " [INIT]: Apache module 'mod_evasive2' disabled\n";
    }
    $sql = "SELECT COUNT(servername) as tcount FROM freeweb WHERE UseReverseProxy=1";
    if ($GLOBALS["VERBOSE"]) {
        echo "Starting......: " . date("H:i:s") . " [DEBUG] Apache {$sql}\n";
    }
    $q = new mysql();
    $ligne = @mysql_fetch_array($q->QUERY_SQL($sql, 'artica_backup'));
    echo "Starting......: " . date("H:i:s") . " [INIT]: Apache " . $ligne["tcount"] . " Reverse Proxy\n";
    $proxys_mods["proxy_module"] = "mod_proxy.so";
    $proxys_mods["proxy_http_module"] = "mod_proxy_http.so";
    $proxys_mods["proxy_ftp_module"] = "mod_proxy_ftp.so";
    $proxys_mods["proxy_connect_module"] = "mod_proxy_connect.so";
    $proxys_mods["headers_module"] = "mod_headers.so";
    $proxys_mods["deflate_module"] = "mod_deflate.so";
    $proxys_mods["xml2enc_module"] = "mod_xml2enc.so";
    $proxys_mods["proxy_html_module"] = "mod_proxy_html.so";
    $proxys_orgs[] = "proxy_ajp.load";
    $proxys_orgs[] = "proxy_balancer.load";
    $proxys_orgs[] = "proxy.conf";
    $proxys_orgs[] = "proxy_connect.load";
    $proxys_orgs[] = "proxy_ftp.load";
    $proxys_orgs[] = "proxy_html.conf";
    $proxys_orgs[] = "proxy_html.load";
    $proxys_orgs[] = "proxy_http.load";
    $proxys_orgs[] = "proxy.load";
    $proxys_orgs[] = "proxy_scgi.load";
    if (is_file("/etc/httpd/conf.d/proxy_ajp.conf")) {
        @unlink("/etc/httpd/conf.d/proxy_ajp.conf");
    }
    while (list($module, $lib) = each($proxys_orgs)) {
        if (is_file("{$DAEMON_PATH}/mods-enabled/{$lib}")) {
            @unlink("{$DAEMON_PATH}/mods-enabled/{$lib}");
        }
    }
    while (list($module, $lib) = each($proxys_mods)) {
        if (is_file("{$DAEMON_PATH}/mods-enabled/{$module}.load")) {
            @unlink("{$DAEMON_PATH}/mods-enabled/{$module}.load");
        }
    }
    echo "Starting......: " . date("H:i:s") . " [INIT]: Apache {$ligne["tcount"]} reverse proxy(s)\n";
    $countDeProxy = $ligne["tcount"];
    if ($FreeWebsEnableOpenVPNProxy == 1) {
        if ($FreeWebsOpenVPNRemotPort != null) {
            $countDeProxy = $countDeProxy + 1;
        }
    }
    if ($users->EJABBERD_INSTALLED) {
        if ($countDeProxy == 0) {
            $countDeProxy = 1;
        }
    }
    if ($countDeProxy > 0) {
        reset($proxys_mods);
        while (list($module, $lib) = each($proxys_mods)) {
            if (!is_file("{$APACHE_MODULES_PATH}/{$lib}")) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: Apache module '{$module}' '{$lib}' no such file\n";
                continue;
            }
            echo "Starting......: " . date("H:i:s") . " [INIT]: Apache module '{$module}' enabled\n";
            $final_proxys[] = "LoadModule {$module} {$APACHE_MODULES_PATH}/{$lib}";
        }
        @file_put_contents("{$DAEMON_PATH}/mods-enabled/proxy_module.load", @implode("\n", $final_proxys));
    }
    while (list($module, $lib) = each($array)) {
        if (!is_file("{$APACHE_MODULES_PATH}/{$lib}")) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Apache module '{$module}' '{$lib}' no such file\n";
            continue;
        }
        echo "Starting......: " . date("H:i:s") . " [INIT]: Apache module '{$module}' enabled\n";
        @file_put_contents("{$DAEMON_PATH}/mods-enabled/{$module}.load", "LoadModule {$module} {$APACHE_MODULES_PATH}/{$lib}");
    }
    ZarafaWebAccessInFrontEnd($DAEMON_PATH);
    echo "Starting......: " . date("H:i:s") . " [INIT]: Apache testing configuration file\n";
    if (!TestingApacheConfigurationFile()) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: Apache testing configuration file FAILED !! restore old config\n";
        while (list($index, $restorefile) = each($GLOBALS["ToRestore"])) {
            $basename = basename($restorefile);
            echo "Starting......: " . date("H:i:s") . " [INIT]: Apache Removing {$DAEMON_PATH}/{$basename}\n";
            @unlink("{$DAEMON_PATH}/{$basename}");
            echo "Starting......: " . date("H:i:s") . " [INIT]: Apache Restoring {$restorefile}\n";
            @copy($restorefile, "{$DAEMON_PATH}/{$basename}");
        }
    }
    echo "Starting......: " . date("H:i:s") . " [INIT]: Apache terminated... next process\n";
}
Exemple #2
0
function CheckHttpdConf(){
	EnableMods();
	apache_user();
	$sock=$GLOBALS["CLASS_SOCKETS"];
	$unix=new unix();
	$httpdconf=$unix->LOCATE_APACHE_CONF_PATH();
	$d_path=$unix->APACHE_DIR_SITES_ENABLED();
	$DAEMON_PATH=$unix->getmodpathfromconf($httpdconf);
	if(is_file("/etc/apache2/sites-available/default-ssl")){@unlink("/etc/apache2/sites-available/default-ssl");}
	
	$ApacheDisableModDavFS=$sock->GET_INFO("ApacheDisableModDavFS");
	$FreeWebListen=trim($sock->GET_INFO("FreeWebListen"));
	$FreeWebListenPort=$sock->GET_INFO("FreeWebListenPort");
	$FreeWebListenSSLPort=$sock->GET_INFO("FreeWebListenSSLPort");
	$FreeWebListen=$sock->GET_INFO("FreeWebListen");
	$FreeWebsEnableModSecurity=$sock->GET_INFO("FreeWebsEnableModSecurity");
	$FreeWebsEnableModEvasive=$sock->GET_INFO("FreeWebsEnableModEvasive");
	$FreeWebsEnableModQOS=$sock->GET_INFO("FreeWebsEnableModQOS");
	$FreeWebsEnableOpenVPNProxy=$sock->GET_INFO("FreeWebsEnableOpenVPNProxy");
	$FreeWebsOpenVPNRemotPort=trim($sock->GET_INFO("FreeWebsOpenVPNRemotPort"));
	
	if($FreeWebListen==null){$FreeWebListen="*";}
	if($FreeWebListen<>"*"){$FreeWebListenApache="$FreeWebListen";}
	if(!isset($FreeWebListenApache)){$FreeWebListenApache="*";}
	
	if(!is_numeric($FreeWebListenSSLPort)){$FreeWebListenSSLPort=443;}
	if(!is_numeric($FreeWebListenPort)){$FreeWebListenPort=80;}
	if(!is_numeric($ApacheDisableModDavFS)){$ApacheDisableModDavFS=80;}
	if(!is_numeric($FreeWebsEnableModSecurity)){$FreeWebsEnableModSecurity=0;}
	if(!is_numeric($FreeWebsEnableModEvasive)){$FreeWebsEnableModEvasive=0;}
	if(!is_numeric($FreeWebsEnableModQOS)){$FreeWebsEnableModQOS=0;}		
	if(!is_numeric($FreeWebsEnableOpenVPNProxy)){$FreeWebsEnableOpenVPNProxy=0;}
	
	
	if(is_file("/etc/apache2/sites-enabled/000-default")){@unlink("/etc/apache2/sites-enabled/000-default");}
	if(is_file("/etc/apache2/sites-available/default")){@unlink("/etc/apache2/sites-available/default");}
	
	
	$sql="SELECT ServerPort FROM freeweb WHERE ServerPort>0 GROUP BY ServerPort";
	$q=new mysql();
	$conf[]="NameVirtualHost {$FreeWebListenApache}:$FreeWebListenPort";
	$results=$q->QUERY_SQL($sql,'artica_backup');
	if(!$q->ok){if($GLOBALS["VERBOSE"]){echo $q->mysql_error."\n";return;}}
	while($ligne=mysql_fetch_array($results,MYSQL_ASSOC)){
		$conf[]="NameVirtualHost {$FreeWebListenApache}:{$ligne["ServerPort"]}";
	}	
	
	$conf[]="Listen $FreeWebListenPort";
	$conf[]="<IfModule mod_ssl.c>";
	$conf[]="\tListen $FreeWebListenSSLPort";
	$conf[]="\tNameVirtualHost $FreeWebListen:$FreeWebListenSSLPort";
	$conf[]="</IfModule>";
	$conf[]="";
	$conf[]="<IfModule mod_gnutls.c>";
	$conf[]="\tNameVirtualHost $FreeWebListen:$FreeWebListenSSLPort";
	$conf[]="\tListen $FreeWebListenSSLPort";
	$conf[]="</IfModule>";
	$conf[]="";
	if(!is_dir("$DAEMON_PATH/sites-available")){@mkdir("$DAEMON_PATH/sites-available",666,true);}
	@file_put_contents("$DAEMON_PATH/ports.conf",@implode("\n",$conf));
	
	echo "Starting......: Apache $DAEMON_PATH/ports.conf for NameVirtualHost $FreeWebListen:$FreeWebListenPort done\n";
	if($FreeWebsEnableModSecurity==1){
			$f[]="<IfModule security2_module>";
			$f[]="   SecRuleEngine On";
			$f[]="   #SecServerSignature";
			//$f[]="   #SecFilterCheckURLEncoding {$Params["SecFilterCheckURLEncoding"]}";
			//$f[]="   #SecFilterCheckUnicodeEncoding {$Params["SecFilterCheckUnicodeEncoding"]}";
			//$f[]="   SecFilterForceByteRange 1 255";
			//$f[]="   SecAuditEngine RelevantOnly";
			$f[]="   SecAuditEngine RelevantOnly";
			$f[]="   SecAuditLog /var/log/apache2/modsec_audit_log";
			$f[]="   SecDebugLog /var/log/apache2/modsec_debug_log";
			$f[]="   SecDebugLogLevel 0";
			$f[]="   SecRequestBodyAccess Off";
			$f[]="   SecDefaultAction \"phase:2,deny,log,status:'Hello World!'\"";
			$f[]="</IfModule>\n\n";
			echo "Starting......: Apache $DAEMON_PATH/mod_security.conf\n";
			@file_put_contents("$DAEMON_PATH/mod_security.conf",@implode("\n",$f));
			unset($f);
	}
	
	if($FreeWebsEnableModEvasive==1){
		$Params=unserialize(base64_decode($sock->GET_INFO("modEvasiveDefault")));
			if(!is_numeric($Params["DOSHashTableSize"])){$Params["DOSHashTableSize"]=1024;}
			if(!is_numeric($Params["DOSPageCount"])){$Params["DOSPageCount"]=10;}
			if(!is_numeric($Params["DOSSiteCount"])){$Params["DOSSiteCount"]=150;}
			if(!is_numeric($Params["DOSPageInterval"])){$Params["DOSPageInterval"]=1.5;}
			if(!is_numeric($Params["DOSSiteInterval"])){$Params["DOSSiteInterval"]=1.5;}
			if(!is_numeric($Params["DOSBlockingPeriod"])){$Params["DOSBlockingPeriod"]=10.7;}		
			$f[]="   LoadModule evasive20_module modules/mod_evasive20.so";
			$f[]="   ExtendedStatus On";
			$f[]="   DOSHashTableSize {$Params["DOSHashTableSize"]}";
			$f[]="   DOSPageCount {$Params["DOSPageCount"]}";
			$f[]="   DOSSiteCount {$Params["DOSSiteCount"]}";
			$f[]="   DOSPageInterval {$Params["DOSPageInterval"]}";
			$f[]="   DOSSiteInterval {$Params["DOSSiteInterval"]}";
			$f[]="   DOSBlockingPeriod {$Params["DOSBlockingPeriod"]}";
			$f[]="   DOSLogDir  \"/var/log/apache2/mod_evasive.log\"";
			$f[]="   DOSSystemCommand \"/bin/echo `date '+%F %T'` apache2  %s >> /var/log/apache2/dos_evasive_attacks.log\"";
			$f[]="";
			echo "Starting......: Apache $DAEMON_PATH/mod_evasive.conf\n";
			@file_put_contents("$DAEMON_PATH/mod_evasive.conf",@implode("\n",$f));
			unset($f);		
		
	}
	
	
	apache_security($DAEMON_PATH);
	
	
	
	
	
	$f=explode("\n",@file_get_contents($httpdconf));
	while (list ($num, $ligne) = each ($f) ){
		if(preg_match("#^Include\s+#",$ligne)){$f[$num]=null;}
		if(preg_match("#\#.*?Include\s+#",$ligne)){$f[$num]=null;}
		if(preg_match("#Listen\s+#",$ligne)){$f[$num]=null;}
		if(preg_match("#ProxyRequests#",$ligne)){$f[$num]=null;}
		if(preg_match("#ProxyVia#",$ligne)){$f[$num]=null;}
		if(preg_match("#AllowCONNECT#",$ligne)){$f[$num]=null;}
		if(preg_match("#KeepAlive#",$ligne)){$f[$num]=null;}
		if(preg_match("#Timeout\s+[0-9]+#",$ligne)){$f[$num]=null;}
		if(preg_match("#MaxKeepAliveRequests\s+#",$ligne)){$f[$num]=null;}
		if(preg_match("#KeepAliveTimeout\s+#",$ligne)){$f[$num]=null;}
		if(preg_match("#MinSpareServers\s+#",$ligne)){$f[$num]=null;}
		if(preg_match("#MaxSpareServers\s+#",$ligne)){$f[$num]=null;}
		if(preg_match("#StartServers\s+#",$ligne)){$f[$num]=null;}
		if(preg_match("#MaxClients\s+#",$ligne)){$f[$num]=null;}
		if(preg_match("#MaxRequestsPerChild\s+#",$ligne)){$f[$num]=null;}
	}
	
	
	$FreeWebPerformances=unserialize(base64_decode($sock->GET_INFO("FreeWebPerformances")));
	if(!is_numeric($FreeWebPerformances["Timeout"])){$FreeWebPerformances["Timeout"]=300;}
	if(!is_numeric($FreeWebPerformances["KeepAlive"])){$FreeWebPerformances["KeepAlive"]=0;}
	if(!is_numeric($FreeWebPerformances["MaxKeepAliveRequests"])){$FreeWebPerformances["MaxKeepAliveRequests"]=100;}
	if(!is_numeric($FreeWebPerformances["KeepAliveTimeout"])){$FreeWebPerformances["KeepAliveTimeout"]=15;}
	if(!is_numeric($FreeWebPerformances["MinSpareServers"])){$FreeWebPerformances["MinSpareServers"]=5;}
	if(!is_numeric($FreeWebPerformances["MaxSpareServers"])){$FreeWebPerformances["MaxSpareServers"]=10;}
	if(!is_numeric($FreeWebPerformances["StartServers"])){$FreeWebPerformances["StartServers"]=5;}
	if(!is_numeric($FreeWebPerformances["MaxClients"])){$FreeWebPerformances["MaxClients"]=50;}
	if(!is_numeric($FreeWebPerformances["MaxRequestsPerChild"])){$FreeWebPerformances["MaxRequestsPerChild"]=10000;}

	
	
	
	reset($f);
	while (list ($num, $ligne) = each ($f) ){
		if(trim($ligne)==null){continue;}
		if(substr($ligne,0,1)=="#"){continue;}
		$httpd[]=$ligne;
	}
	
	if($FreeWebPerformances["KeepAlive"]==1){$FreeWebPerformances["KeepAlive"]="On";}else{$FreeWebPerformances["KeepAlive"]="Off";}
	
	$httpd[]="Timeout              {$FreeWebPerformances["Timeout"]}";
	$httpd[]="KeepAlive            {$FreeWebPerformances["KeepAlive"]}";
	$httpd[]="KeepAliveTimeout     {$FreeWebPerformances["KeepAliveTimeout"]}";
	$httpd[]="StartServers         {$FreeWebPerformances["StartServers"]}";
	$httpd[]="MaxClients           {$FreeWebPerformances["MaxClients"]}";
	$httpd[]="MinSpareServers      {$FreeWebPerformances["MinSpareServers"]}";
	$httpd[]="MaxSpareServers      {$FreeWebPerformances["MaxSpareServers"]}"; 
	$httpd[]="MaxRequestsPerChild  {$FreeWebPerformances["MaxRequestsPerChild"]}";
	$httpd[]="MaxKeepAliveRequests {$FreeWebPerformances["MaxKeepAliveRequests"]}";
	
	
	if($FreeWebsEnableOpenVPNProxy==1){
		if($FreeWebsOpenVPNRemotPort<>null){
			$httpd[]="ProxyRequests On";
			$httpd[]="ProxyVia On";
			$httpd[]="AllowCONNECT $FreeWebsOpenVPNRemotPort";
			$httpd[]="KeepAlive On";
		}
	}
	
	
	
	$httpd[]="Include mods-enabled/*.load";
	$httpd[]="Include mods-enabled/*.conf";
	$httpd[]="Include mods-enabled/*.init";
	if(basename($httpdconf)<>"httpd.conf"){$httpd[]="Include httpd.conf";}
	$httpd[]="Include ports.conf";
	if($FreeWebsEnableModSecurity==1){$httpd[]="Include mod_security.conf";}
	if($FreeWebsEnableModEvasive==1){$httpd[]="Include mod_evasive.conf";}
	
	$status[]="<IfModule mod_status.c>";
	$status[]="\tExtendedStatus On";
	$status[]="\t<Location /server-status>";
	$status[]="\t\tSetHandler server-status";
	$status[]="\t\tOrder deny,allow";
	$status[]="\t\tDeny from all";
	$status[]="\t\tAllow from 127.0.0.1";
	$status[]="\t</Location>";
	$status[]="</IfModule>";
	@file_put_contents("$DAEMON_PATH/mods-enabled/mod-status.init", @implode("\n", $status));
	
	
	$httpd[]="Include conf.d/";
	$httpd[]="Include sites-enabled";
	$httpd[]="";
	echo "Starting......: Apache $httpdconf done\n";
	@file_put_contents($httpdconf,@implode("\n",$httpd));
	
	if(!is_dir("$DAEMON_PATH/mods-enabled")){@mkdir("$DAEMON_PATH/mods-enabled",666,true);}
	
	$users=new usersMenus();
	$APACHE_MODULES_PATH=$users->APACHE_MODULES_PATH;
	$array["php5_module"]="libphp5.so";
	$array["dav_module"]="mod_dav.so";
	$array["dav_lock_module"]="mod_dav_lock.so";
	$array["dav_fs_module"]="mod_dav_fs.so";
	$array["qos_module"]="mod_qos.so";
	$array["rewrite_module"]="mod_rewrite.so";
	$array["cache_module"]="mod_cache.so";
	$array["disk_cache_module"]="mod_disk_cache.so";
	$array["mem_cache_module"]="mod_mem_cache.so";
	$array["expires_module"]="mod_expires.so";
	$array["status_module"]="mod_status.so";
	 
	
	

	
	@unlink("$DAEMON_PATH/mods-enabled/mod-security.load");
	@unlink("$DAEMON_PATH/mods-enabled/mod_security.load");
	@unlink("$DAEMON_PATH/mods-enabled/mod-evasive.load");
	@unlink("$DAEMON_PATH/mods-enabled/mod_evasive.load");
	@unlink("$DAEMON_PATH/mods-enabled/status.conf");
	@unlink("$DAEMON_PATH/mods-enabled/status.load");
	@unlink("$DAEMON_PATH/mods-enabled/php5.load");
	
	$sock=new sockets();
	$FreeWebsDisableMOdQOS=$sock->GET_INFO("FreeWebsDisableMOdQOS");
	if(!is_numeric($FreeWebsDisableMOdQOS)){$FreeWebsDisableMOdQOS=0;}
	if($FreeWebsEnableModQOS==0){$FreeWebsDisableMOdQOS=1;}
	
	
	if($FreeWebsDisableMOdQOS==1){
		unset($array["qos_module"]);
		@unlink("$DAEMON_PATH/mods-enabled/qos_module.load");
	}
	
if($FreeWebsEnableModSecurity==1){
		if(is_file("$APACHE_MODULES_PATH/mod_security2.so")){
			$a[]="LoadFile /usr/lib/libxml2.so.2";
			$a[]="LoadModule security2_module $APACHE_MODULES_PATH/mod_security2.so";
			echo "Starting......: Apache mod_security2 is enabled\n";
			@file_put_contents("$DAEMON_PATH/mods-enabled/mod_security.load",@implode("\n",$a));
			unset($a);
		}else{
			echo "Starting......: Apache $APACHE_MODULES_PATH/mod_security2.so no such file\n";
		}
	}else{echo "Starting......: Apache mod_security2 is not enabled\n";}
	
if($FreeWebsEnableModEvasive==1){
		if(is_file("$APACHE_MODULES_PATH/mod_evasive20.so")){
			$a[]="LoadModule evasive20_module $APACHE_MODULES_PATH/mod_evasive20.so";
			echo "Starting......: Apache mod_evasive2 is enabled\n";
			@file_put_contents("$DAEMON_PATH/mods-enabled/mod_evasive.load",@implode("\n",$a));
		}else{
			echo "Starting......: Apache $APACHE_MODULES_PATH/mod_evasive20.so no such file\n";
		}
	}else{echo "Starting......: Apache mod_evasive2 is not enabled\n";}

	
	
	
	
	if($ApacheDisableModDavFS==1){
		unset($array["dav_fs_module"]);
		unset($array["dav_module"]);
		unset($array["dav_lock_module"]);
		@unlink("$DAEMON_PATH/mods-enabled/dav_lock_module.load");
		@unlink("$DAEMON_PATH/mods-enabled/dav_module.load");
		@unlink("$DAEMON_PATH/mods-enabled/dav_fs_module.load");
	}
	
	$sql="SELECT COUNT(servername) as tcount FROM freeweb WHERE UseReverseProxy=1";
	$ligne=@mysql_fetch_array($q->QUERY_SQL($sql,'artica_backup'));
	
		$proxys_mods["proxy_module"]="mod_proxy.so";
		$proxys_mods["proxy_http_module"]="mod_proxy_http.so";
		$proxys_mods["proxy_ftp_module"]="mod_proxy_ftp.so";
		$proxys_mods["proxy_connect_module"]="mod_proxy_connect.so";
		$proxys_mods["headers_module"]="mod_headers.so";
		$proxys_mods["deflate_module"]="mod_deflate.so";
		$proxys_mods["xml2enc_module"]="mod_xml2enc.so";
		$proxys_mods["proxy_html_module"]="mod_proxy_html.so";
		
		$proxys_orgs[]="proxy_ajp.load";  
		$proxys_orgs[]="proxy_balancer.load";   
		$proxys_orgs[]="proxy.conf";   
		$proxys_orgs[]="proxy_connect.load";   
		$proxys_orgs[]="proxy_ftp.load";   
		$proxys_orgs[]="proxy_html.conf";  
		$proxys_orgs[]="proxy_html.load";   
		$proxys_orgs[]="proxy_http.load";   
		$proxys_orgs[]="proxy.load";   
		$proxys_orgs[]="proxy_scgi.load"; 
		
		while (list ($module, $lib) = each ($proxys_orgs) ){if(is_file("$DAEMON_PATH/mods-enabled/$lib")){@unlink("$DAEMON_PATH/mods-enabled/$lib");}}
		while (list ($module, $lib) = each ($proxys_mods) ){if(is_file("$DAEMON_PATH/mods-enabled/$module.load")){@unlink("$DAEMON_PATH/mods-enabled/$module.load");}}
			
	echo "Starting......: Apache {$ligne["tcount"]} reverse proxy(s)\n";
	if($ligne["tcount"]>0){
		
		reset($proxys_mods);
		while (list ($module, $lib) = each ($proxys_mods) ){
			if(!is_file("$APACHE_MODULES_PATH/$lib")){echo "Starting......: Apache $module $lib no such file\n";continue;}
			echo "Starting......: Apache $module enabled\n";
			$final_proxys[]="LoadModule $module $APACHE_MODULES_PATH/$lib";
		}
		
		@file_put_contents("$DAEMON_PATH/mods-enabled/proxy_module.load", @implode("\n", $final_proxys));
	}		
	
	
	while (list ($module, $lib) = each ($array) ){
		if(!is_file("$APACHE_MODULES_PATH/$lib")){echo "Starting......: Apache modules '$module' '$lib' no such file\n";continue;}
		echo "Starting......: Apache modules '$module' enabled\n";
		@file_put_contents("$DAEMON_PATH/mods-enabled/$module.load","LoadModule $module $APACHE_MODULES_PATH/$lib");
		
	}
		
}	
Exemple #3
0
function CheckHttpdConf()
{
    EnableMods();
    apache_user();
    $sock = $GLOBALS["CLASS_SOCKETS"];
    $unix = new unix();
    $users = new usersMenus();
    $freeweb = new freeweb();
    $httpdconf = $unix->LOCATE_APACHE_CONF_PATH();
    if (!is_file($httpdconf)) {
        echo "Starting......: Apache unable to stat configuration file\n";
        return;
    }
    $d_path = $unix->APACHE_DIR_SITES_ENABLED();
    $DAEMON_PATH = $unix->getmodpathfromconf($httpdconf);
    $APACHE_SRC_ACCOUNT = $unix->APACHE_SRC_ACCOUNT();
    $APACHE_SRC_GROUP = $unix->APACHE_SRC_GROUP();
    if (is_file("/etc/apache2/sites-available/default-ssl")) {
        @unlink("/etc/apache2/sites-available/default-ssl");
    }
    echo "Starting......: Apache daemon path: \"{$DAEMON_PATH}\" run has \"{$APACHE_SRC_ACCOUNT}:{$APACHE_SRC_GROUP}\"\n";
    if ($APACHE_SRC_ACCOUNT == null) {
        echo "Starting......: Apache daemon unable to determine user that will run apache\n";
        die;
    }
    if (!is_dir("/var/log/apache2")) {
        @mkdir("/var/log/apache2", 755, true);
    }
    $ApacheDisableModDavFS = $sock->GET_INFO("ApacheDisableModDavFS");
    $FreeWebListen = trim($sock->GET_INFO("FreeWebListen"));
    $FreeWebListenPort = $sock->GET_INFO("FreeWebListenPort");
    $FreeWebListenSSLPort = $sock->GET_INFO("FreeWebListenSSLPort");
    $FreeWebListen = $sock->GET_INFO("FreeWebListen");
    $FreeWebsEnableModSecurity = $sock->GET_INFO("FreeWebsEnableModSecurity");
    $FreeWebsEnableModEvasive = $sock->GET_INFO("FreeWebsEnableModEvasive");
    $FreeWebsEnableModQOS = $sock->GET_INFO("FreeWebsEnableModQOS");
    $FreeWebsEnableOpenVPNProxy = $sock->GET_INFO("FreeWebsEnableOpenVPNProxy");
    $FreeWebsOpenVPNRemotPort = trim($sock->GET_INFO("FreeWebsOpenVPNRemotPort"));
    $FreeWebDisableSSL = trim($sock->GET_INFO("FreeWebDisableSSL"));
    $TomcatEnable = $sock->GET_INFO("TomcatEnable");
    if ($FreeWebListen == null) {
        $FreeWebListen = "*";
    }
    if ($FreeWebListen != "*") {
        $FreeWebListenApache = "{$FreeWebListen}";
    }
    if (!isset($FreeWebListenApache)) {
        $FreeWebListenApache = "*";
    }
    if (!is_numeric($FreeWebDisableSSL)) {
        $FreeWebDisableSSL = 0;
    }
    if (!is_numeric($FreeWebListenSSLPort)) {
        $FreeWebListenSSLPort = 443;
    }
    if (!is_numeric($FreeWebListenPort)) {
        $FreeWebListenPort = 80;
    }
    if (!is_numeric($ApacheDisableModDavFS)) {
        $ApacheDisableModDavFS = 0;
    }
    if (!is_numeric($FreeWebsEnableModSecurity)) {
        $FreeWebsEnableModSecurity = 0;
    }
    if (!is_numeric($FreeWebsEnableModEvasive)) {
        $FreeWebsEnableModEvasive = 0;
    }
    if (!is_numeric($FreeWebsEnableModQOS)) {
        $FreeWebsEnableModQOS = 0;
    }
    if (!is_numeric($FreeWebsEnableOpenVPNProxy)) {
        $FreeWebsEnableOpenVPNProxy = 0;
    }
    if (!is_numeric($TomcatEnable)) {
        $TomcatEnable = 1;
    }
    $users = new usersMenus();
    $APACHE_MODULES_PATH = $users->APACHE_MODULES_PATH;
    $toremove[] = "mod-status.init";
    $toremove[] = "status.conf";
    $toremove[] = "fcgid.load";
    $toremove[] = "fcgid.conf";
    $toremove[] = "log_sql.load";
    $toremove[] = "log_sql_mysql.load";
    if (is_file("/etc/apache2/sites-enabled/000-default")) {
        @unlink("/etc/apache2/sites-enabled/000-default");
    }
    if (is_file("/etc/apache2/sites-available/default")) {
        @unlink("/etc/apache2/sites-available/default");
    }
    if (is_file("/etc/apache2/conf.d/zarafa-webaccess.conf")) {
        @unlink("/etc/apache2/conf.d/zarafa-webaccess.conf");
    }
    if (is_file("/etc/apache2/conf.d/zarafa-webaccess-mobile.conf")) {
        @unlink("/etc/apache2/conf.d/zarafa-webaccess-mobile.conf");
    }
    if (is_file("/etc/httpd/conf/extra/httpd-info.conf")) {
        @unlink("/etc/httpd/conf/extra/httpd-info.conf");
    }
    while (list($num, $file) = each($toremove)) {
        shell_exec("/bin/rm -f {$DAEMON_PATH}/mods-enabled/{$file} >/dev/null 2>&1");
        shell_exec("/bin/rm -f {$DAEMON_PATH}/mods-available/{$file} >/dev/null 2>&1");
    }
    $sql = "SELECT ServerPort FROM freeweb WHERE ServerPort>0 GROUP BY ServerPort";
    $q = new mysql();
    $conf[] = "NameVirtualHost {$FreeWebListenApache}:{$FreeWebListenPort}";
    $results = $q->QUERY_SQL($sql, 'artica_backup');
    if (!$q->ok) {
        if ($GLOBALS["VERBOSE"]) {
            echo $q->mysql_error . "\n";
            return;
        }
    }
    while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) {
        $conf[] = "NameVirtualHost {$FreeWebListenApache}:{$ligne["ServerPort"]}";
    }
    $conf[] = "Listen {$FreeWebListenPort}";
    if ($FreeWebDisableSSL == 0) {
        $conf[] = "<IfModule mod_ssl.c>";
        $conf[] = "\tListen {$FreeWebListenSSLPort}";
        $conf[] = "\tNameVirtualHost {$FreeWebListen}:{$FreeWebListenSSLPort}";
        $conf[] = "</IfModule>";
        $conf[] = "";
        $conf[] = "<IfModule mod_gnutls.c>";
        $conf[] = "\tNameVirtualHost {$FreeWebListen}:{$FreeWebListenSSLPort}";
        $conf[] = "\tListen {$FreeWebListenSSLPort}";
        $conf[] = "</IfModule>";
        $conf[] = "<IfModule mod_fcgid.c>";
    }
    $conf[] = "\tPHP_Fix_Pathinfo_Enable 1";
    $conf[] = "";
    if (!is_dir("{$DAEMON_PATH}/sites-available")) {
        @mkdir("{$DAEMON_PATH}/sites-available", 666, true);
    }
    @file_put_contents("{$DAEMON_PATH}/ports.conf", @implode("\n", $conf));
    echo "Starting......: Apache {$DAEMON_PATH}/ports.conf for NameVirtualHost {$FreeWebListen}:{$FreeWebListenPort} done\n";
    if ($FreeWebsEnableModSecurity == 1) {
        $f[] = "<IfModule security2_module>";
        $f[] = "   SecRuleEngine On";
        $f[] = "   #SecServerSignature";
        //$f[]="   #SecFilterCheckURLEncoding {$Params["SecFilterCheckURLEncoding"]}";
        //$f[]="   #SecFilterCheckUnicodeEncoding {$Params["SecFilterCheckUnicodeEncoding"]}";
        //$f[]="   SecFilterForceByteRange 1 255";
        //$f[]="   SecAuditEngine RelevantOnly";
        $f[] = "   SecAuditEngine RelevantOnly";
        $f[] = "   SecAuditLog /var/log/apache2/modsec_audit_log";
        $f[] = "   SecDebugLog /var/log/apache2/modsec_debug_log";
        $f[] = "   SecDebugLogLevel 0";
        $f[] = "   SecRequestBodyAccess Off";
        $f[] = "   SecDefaultAction \"phase:2,deny,log,status:'Hello World!'\"";
        $f[] = "</IfModule>\n\n";
        echo "Starting......: Apache {$DAEMON_PATH}/mod_security.conf\n";
        @file_put_contents("{$DAEMON_PATH}/mod_security.conf", @implode("\n", $f));
        unset($f);
    }
    if ($FreeWebsEnableModEvasive == 1) {
        $Params = unserialize(base64_decode($sock->GET_INFO("modEvasiveDefault")));
        if (!is_numeric($Params["DOSHashTableSize"])) {
            $Params["DOSHashTableSize"] = 1024;
        }
        if (!is_numeric($Params["DOSPageCount"])) {
            $Params["DOSPageCount"] = 10;
        }
        if (!is_numeric($Params["DOSSiteCount"])) {
            $Params["DOSSiteCount"] = 150;
        }
        if (!is_numeric($Params["DOSPageInterval"])) {
            $Params["DOSPageInterval"] = 1.5;
        }
        if (!is_numeric($Params["DOSSiteInterval"])) {
            $Params["DOSSiteInterval"] = 1.5;
        }
        if (!is_numeric($Params["DOSBlockingPeriod"])) {
            $Params["DOSBlockingPeriod"] = 10.7;
        }
        $f[] = "   LoadModule evasive20_module modules/mod_evasive20.so";
        $f[] = "   ExtendedStatus On";
        $f[] = "   DOSHashTableSize {$Params["DOSHashTableSize"]}";
        $f[] = "   DOSPageCount {$Params["DOSPageCount"]}";
        $f[] = "   DOSSiteCount {$Params["DOSSiteCount"]}";
        $f[] = "   DOSPageInterval {$Params["DOSPageInterval"]}";
        $f[] = "   DOSSiteInterval {$Params["DOSSiteInterval"]}";
        $f[] = "   DOSBlockingPeriod {$Params["DOSBlockingPeriod"]}";
        $f[] = "   DOSLogDir  \"/var/log/apache2/mod_evasive.log\"";
        $f[] = "   DOSSystemCommand \"/bin/echo `date '+%F %T'` apache2  %s >> /var/log/apache2/dos_evasive_attacks.log\"";
        $f[] = "";
        echo "Starting......: Apache {$DAEMON_PATH}/mod_evasive.conf\n";
        @file_put_contents("{$DAEMON_PATH}/mod_evasive.conf", @implode("\n", $f));
        unset($f);
    }
    apache_security($DAEMON_PATH);
    $httpdconf_data = @file_get_contents($httpdconf);
    if (preg_match("#<Location \\/server-status>(.+?)<\\/Location>#is", $httpdconf_data, $re)) {
        $httpdconf_data = str_replace($re[0], "", $httpdconf_data);
    }
    $f = explode("\n", $httpdconf_data);
    while (list($num, $ligne) = each($f)) {
        if (preg_match("#^Include\\s+#", $ligne)) {
            echo "Starting......: Apache removing {$f[$num]}\n";
            $f[$num] = null;
        }
        if (preg_match("#\\#.*?Include\\s+#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#Listen\\s+#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#ProxyRequests#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#ProxyVia#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#AllowCONNECT#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#KeepAlive#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#Timeout\\s+[0-9]+#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#MaxKeepAliveRequests\\s+#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#KeepAliveTimeout\\s+#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#MinSpareServers\\s+#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#MaxSpareServers\\s+#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#StartServers\\s+#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#MaxClients\\s+#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#MaxRequestsPerChild\\s+#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#LoadModule\\s+#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#ErrorLog\\s+#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#LogFormat\\s+#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#User\\s+#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#Group\\s+#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#CustomLog\\s+#", $ligne)) {
            $f[$num] = null;
        }
        if (preg_match("#LogLevel#", $ligne)) {
            $f[$num] = null;
        }
        if (trim($ligne) == "Loglevel info") {
            $f[$num] = null;
        }
    }
    $FreeWebPerformances = unserialize(base64_decode($sock->GET_INFO("FreeWebPerformances")));
    if (!isset($FreeWebPerformances["Timeout"])) {
        $FreeWebPerformances["Timeout"] = 300;
    }
    if (!isset($FreeWebPerformances["KeepAlive"])) {
        $FreeWebPerformances["KeepAlive"] = 0;
    }
    if (!isset($FreeWebPerformances["MaxKeepAliveRequests"])) {
        $FreeWebPerformances["MaxKeepAliveRequests"] = 100;
    }
    if (!isset($FreeWebPerformances["KeepAliveTimeout"])) {
        $FreeWebPerformances["KeepAliveTimeout"] = 15;
    }
    if (!isset($FreeWebPerformances["MinSpareServers"])) {
        $FreeWebPerformances["MinSpareServers"] = 5;
    }
    if (!isset($FreeWebPerformances["MaxSpareServers"])) {
        $FreeWebPerformances["MaxSpareServers"] = 10;
    }
    if (!isset($FreeWebPerformances["StartServers"])) {
        $FreeWebPerformances["StartServers"] = 5;
    }
    if (!isset($FreeWebPerformances["MaxClients"])) {
        $FreeWebPerformances["MaxClients"] = 50;
    }
    if (!isset($FreeWebPerformances["MaxRequestsPerChild"])) {
        $FreeWebPerformances["MaxRequestsPerChild"] = 10000;
    }
    if (!is_numeric($FreeWebPerformances["Timeout"])) {
        $FreeWebPerformances["Timeout"] = 300;
    }
    if (!is_numeric($FreeWebPerformances["KeepAlive"])) {
        $FreeWebPerformances["KeepAlive"] = 0;
    }
    if (!is_numeric($FreeWebPerformances["MaxKeepAliveRequests"])) {
        $FreeWebPerformances["MaxKeepAliveRequests"] = 100;
    }
    if (!is_numeric($FreeWebPerformances["KeepAliveTimeout"])) {
        $FreeWebPerformances["KeepAliveTimeout"] = 15;
    }
    if (!is_numeric($FreeWebPerformances["MinSpareServers"])) {
        $FreeWebPerformances["MinSpareServers"] = 5;
    }
    if (!is_numeric($FreeWebPerformances["MaxSpareServers"])) {
        $FreeWebPerformances["MaxSpareServers"] = 10;
    }
    if (!is_numeric($FreeWebPerformances["StartServers"])) {
        $FreeWebPerformances["StartServers"] = 5;
    }
    if (!is_numeric($FreeWebPerformances["MaxClients"])) {
        $FreeWebPerformances["MaxClients"] = 50;
    }
    if (!is_numeric($FreeWebPerformances["MaxRequestsPerChild"])) {
        $FreeWebPerformances["MaxRequestsPerChild"] = 10000;
    }
    reset($f);
    while (list($num, $ligne) = each($f)) {
        if (trim($ligne) == null) {
            continue;
        }
        if (substr($ligne, 0, 1) == "#") {
            continue;
        }
        $httpd[] = $ligne;
    }
    if ($FreeWebPerformances["KeepAlive"] == 1) {
        $FreeWebPerformances["KeepAlive"] = "On";
    } else {
        $FreeWebPerformances["KeepAlive"] = "Off";
    }
    $httpd[] = "User\t\t\t\t   {$APACHE_SRC_ACCOUNT}";
    $httpd[] = "Group\t\t\t\t   {$APACHE_SRC_GROUP}";
    $httpd[] = "Timeout              {$FreeWebPerformances["Timeout"]}";
    $httpd[] = "KeepAlive            {$FreeWebPerformances["KeepAlive"]}";
    $httpd[] = "KeepAliveTimeout     {$FreeWebPerformances["KeepAliveTimeout"]}";
    $httpd[] = "StartServers         {$FreeWebPerformances["StartServers"]}";
    $httpd[] = "MaxClients           {$FreeWebPerformances["MaxClients"]}";
    $httpd[] = "MinSpareServers      {$FreeWebPerformances["MinSpareServers"]}";
    $httpd[] = "MaxSpareServers      {$FreeWebPerformances["MaxSpareServers"]}";
    $httpd[] = "MaxRequestsPerChild  {$FreeWebPerformances["MaxRequestsPerChild"]}";
    $httpd[] = "MaxKeepAliveRequests {$FreeWebPerformances["MaxKeepAliveRequests"]}";
    if ($FreeWebsEnableOpenVPNProxy == 1) {
        if ($FreeWebsOpenVPNRemotPort != null) {
            $httpd[] = "ProxyRequests On";
            $httpd[] = "ProxyVia On";
            $httpd[] = "AllowCONNECT {$FreeWebsOpenVPNRemotPort}";
            $httpd[] = "KeepAlive On";
        }
    }
    //$dir_master=$unix->getmodpathfromconf();
    $httpd[] = "Include {$DAEMON_PATH}/mods-enabled/*.load";
    $httpd[] = "Include {$DAEMON_PATH}/mods-enabled/*.conf";
    $httpd[] = "Include {$DAEMON_PATH}/mods-enabled/*.init";
    if (basename($httpdconf) != "httpd.conf") {
        $httpd[] = "Include {$DAEMON_PATH}/httpd.conf";
    }
    $httpd[] = "Include {$DAEMON_PATH}/ports.conf";
    if ($FreeWebsEnableModSecurity == 1) {
        $httpd[] = "Include {$DAEMON_PATH}/mod_security.conf";
    }
    if ($FreeWebsEnableModEvasive == 1) {
        $httpd[] = "Include {$DAEMON_PATH}/mod_evasive.conf";
    }
    $httpd[] = 'Loglevel info';
    $httpd[] = 'ErrorLog /var/log/apache2/error.log';
    $httpd[] = 'LogFormat "%h %l %u %t \\"%r\\" %<s %b" common';
    $httpd[] = 'CustomLog /var/log/apache2/access.log common';
    $mod_status = $freeweb->mod_status();
    if ($mod_status != null) {
        $status[] = "<IfModule mod_status.c>";
        $status[] = "\tExtendedStatus On";
        $status[] = "{$mod_status}";
        $status[] = "</IfModule>";
        @file_put_contents("{$DAEMON_PATH}/mods-enabled/mod-status.init", @implode("\n", $status));
    }
    @unlink("{$DAEMON_PATH}/mods-enabled/pagespeed.conf");
    if ($users->APACHE_MOD_PAGESPEED) {
        if (!is_dir("/var/cache/apache2/mod_pagespeed/default/files")) {
            @mkdir("/var/cache/apache2/mod_pagespeed/default/files", 644, true);
        }
        $pspedd[] = "<IfModule pagespeed_module>";
        $pspedd[] = "\tModPagespeedFileCachePath            \"/var/cache/apache2/mod_pagespeed/default\"";
        $pspedd[] = "\tModPagespeedGeneratedFilePrefix      \"/var/cache/apache2/mod_pagespeed/files/\"";
        $pspedd[] = "\tSetOutputFilter MOD_PAGESPEED_OUTPUT_FILTER";
        $pspedd[] = "\tAddOutputFilterByType MOD_PAGESPEED_OUTPUT_FILTER text/html";
        $pspedd[] = "</IfModule>";
        @file_put_contents("{$DAEMON_PATH}/mods-enabled/pagespeed.conf", @implode("\n", $pspedd));
    }
    if ($users->APACHE_MOD_LOGSSQL) {
        $q = new mysql();
        if (!$q->DATABASE_EXISTS("apachelogs")) {
            $q->CREATE_DATABASE("apachelogs");
        }
        $APACHE_MOD_LOGSSQL[] = "<IfModule log_sql_mysql_module>";
        $APACHE_MOD_LOGSSQL[] = "\tLogSQLLoginInfo mysql://{$q->mysql_admin}:{$q->mysql_password}@{$q->mysql_server}:{$q->mysql_port}/apachelogs";
        $APACHE_MOD_LOGSSQL[] = "\tLogSQLMassVirtualHosting On";
        $APACHE_MOD_LOGSSQL[] = "\tLogSQLmachineID {$users->hostname}";
        $APACHE_MOD_LOGSSQL[] = "\tLogSQLTransferLogFormat AbcHhmMpRSstTUuvz";
        $APACHE_MOD_LOGSSQL[] = "</IfModule>";
        @file_put_contents("{$DAEMON_PATH}/mods-enabled/log_sql_module.conf", @implode("\n", $APACHE_MOD_LOGSSQL));
    }
    if (is_file("/etc/apache2/sysconfig.d/loadmodule.conf")) {
        $httpd[] = "Include /etc/apache2/sysconfig.d/loadmodule.conf";
    }
    if (is_file("/etc/apache2/uid.conf")) {
        $httpd[] = "Include /etc/apache2/uid.conf";
    }
    if (is_file("/etc/apache2/default-server.conf")) {
        patch_suse_default_server();
        $httpd[] = "Include /etc/apache2/default-server.conf";
    }
    $httpd[] = "Include {$DAEMON_PATH}/conf.d/";
    $httpd[] = "Include {$DAEMON_PATH}/sites-enabled/";
    if (is_file("{$APACHE_MODULES_PATH}/mod_php5.so")) {
        $httpd[] = "LoadModule php5_module {$APACHE_MODULES_PATH}/mod_php5.so";
    }
    if (is_file("{$APACHE_MODULES_PATH}/mod_ldap.so")) {
        $httpd[] = "LoadModule ldap_module {$APACHE_MODULES_PATH}/mod_ldap.so";
    }
    if ($ApacheDisableModDavFS == 0) {
        if (is_file("{$APACHE_MODULES_PATH}/mod_dav.so")) {
            echo "Starting......: Apache module 'dav_module' enabled\n";
            $httpd[] = "LoadModule dav_module {$APACHE_MODULES_PATH}/mod_dav.so";
        }
        if (is_file("{$APACHE_MODULES_PATH}/mod_dav_lock.so")) {
            echo "Starting......: Apache module 'dav_lock_module' enabled\n";
            $httpd[] = "LoadModule dav_lock_module {$APACHE_MODULES_PATH}/mod_dav_lock.so";
        }
        if (is_file("{$APACHE_MODULES_PATH}/mod_dav_fs.so")) {
            echo "Starting......: Apache module 'dav_fs_module' enabled\n";
            $httpd[] = "LoadModule dav_fs_module {$APACHE_MODULES_PATH}/mod_dav_fs.so";
        }
    }
    $httpd[] = "";
    echo "Starting......: Apache {$httpdconf} done\n";
    @file_put_contents($httpdconf, @implode("\n", $httpd));
    // MODULES -----------------------------------------------------------------------
    if (!is_dir("{$DAEMON_PATH}/mods-enabled")) {
        @mkdir("{$DAEMON_PATH}/mods-enabled", 666, true);
    }
    if (!is_file("{$DAEMON_PATH}/httpd.conf")) {
        @file_put_contents("{$DAEMON_PATH}/httpd.conf", "#");
    }
    @unlink("/etc/libapache2-mod-jk/workers.properties");
    @unlink("/etc/apache2/workers.properties");
    @unlink("{$DAEMON_PATH}/conf.d/jk.conf");
    $array["php5_module"] = "libphp5.so";
    //$array["access_module"]="mod_access.so";
    $array["qos_module"] = "mod_qos.so";
    $array["rewrite_module"] = "mod_rewrite.so";
    $array["cache_module"] = "mod_cache.so";
    $array["disk_cache_module"] = "mod_disk_cache.so";
    $array["mem_cache_module"] = "mod_mem_cache.so";
    $array["expires_module"] = "mod_expires.so";
    $array["status_module"] = "mod_status.so";
    $array["geoip_module"] = "mod_geoip.so";
    $array["info_module"] = "mod_info.so";
    $array["suexec_module"] = "mod_suexec.so";
    $array["fcgid_module"] = "mod_fcgid.so";
    $array["authz_host_module"] = "mod_authz_host.so";
    $array["dir_module"] = "mod_dir.so";
    $array["mime_module"] = "mod_mime.so";
    $array["log_config_module"] = "mod_log_config.so";
    $array["alias_module"] = "mod_alias.so";
    $array["autoindex_module"] = "mod_autoindex.so";
    $array["negotiation_module"] = "mod_negotiation.so";
    $array["setenvif_module"] = "mod_setenvif.so";
    $array["logio_module"] = "mod_logio.so";
    $array["auth_basic_module"] = "mod_auth_basic.so";
    $array["authn_file_module"] = "mod_authn_file.so";
    $array["vhost_alias_module"] = "mod_vhost_alias.so";
    $array["ssl_module"] = "mod_ssl.so";
    $array["log_sql_module"] = "mod_log_sql.so";
    $array["log_sql_mysql_module"] = "mod_log_sql_mysql.so";
    if (is_file("{$APACHE_MODULES_PATH}/mod_pagespeed.so")) {
        echo "Starting......: Apache module 'mod_pagespeed' enabled\n";
        $ppsped[] = "LoadModule pagespeed_module {$APACHE_MODULES_PATH}/mod_pagespeed.so";
        if (is_file("{$APACHE_MODULES_PATH}/mod_deflate.so")) {
            $ppsped[] = "# Only attempt to load mod_deflate if it hasn't been loaded already.";
            $ppsped[] = "<IfModule !mod_deflate.c>";
            $ppsped[] = "\tLoadModule deflate_module {$APACHE_MODULES_PATH}/mod_deflate.so";
            $ppsped[] = "</IfModule>";
        }
        @file_put_contents("{$DAEMON_PATH}/mods-enabled/mod_pagespeed.load", @implode("\n", $ppsped));
    } else {
        echo "Starting......: Apache module 'mod_pagespeed' {$APACHE_MODULES_PATH}/mod_pagespeed.so no such file\n";
    }
    if ($users->TOMCAT_INSTALLED) {
        if ($TomcatEnable == 1) {
            if (is_dir($users->TOMCAT_DIR)) {
                if (is_dir($users->TOMCAT_JAVA)) {
                    $array["jk_module"] = "mod_jk.so";
                    $ftom[] = "workers.tomcat_home={$users->TOMCAT_DIR}";
                    $ftom[] = "workers.java_home={$users->TOMCAT_JAVA}";
                    $ftom[] = "ps=/";
                    $ftom[] = "worker.list=ajp13_worker";
                    $ftom[] = "worker.ajp13_worker.port=8009";
                    $ftom[] = "worker.ajp13_worker.host=127.0.0.1";
                    $ftom[] = "worker.ajp13_worker.type=ajp13";
                    $ftom[] = "worker.ajp13_worker.lbfactor=1";
                    $ftom[] = "worker.loadbalancer.type=lb";
                    $ftom[] = "worker.loadbalancer.balance_workers=ajp13_worker";
                    $ftom[] = "";
                    @file_put_contents("/etc/apache2/workers.properties", @implode("\n", $ftom));
                    @mkdir("/etc/libapache2-mod-jk", 644);
                    @file_put_contents("/etc/libapache2-mod-jk/workers.properties", @implode("\n", $ftom));
                    $faptom[] = "<ifmodule mod_jk.c>";
                    $faptom[] = "\tJkWorkersFile /etc/apache2/workers.properties";
                    $faptom[] = "\tJkLogFile /var/log/apache2/mod_jk.log";
                    $faptom[] = "\tJkLogLevel error";
                    $faptom[] = "</ifmodule>";
                    @file_put_contents("{$DAEMON_PATH}/conf.d/jk.conf", @implode("\n", $faptom));
                }
            }
        }
    }
    @unlink("{$DAEMON_PATH}/mods-enabled/mod-security.load");
    @unlink("{$DAEMON_PATH}/mods-enabled/mod_security.load");
    @unlink("{$DAEMON_PATH}/mods-enabled/mod-evasive.load");
    @unlink("{$DAEMON_PATH}/mods-enabled/mod_evasive.load");
    @unlink("{$DAEMON_PATH}/mods-enabled/geoip.load");
    @unlink("{$DAEMON_PATH}/mods-enabled/status.conf");
    @unlink("{$DAEMON_PATH}/mods-enabled/status.load");
    @unlink("{$DAEMON_PATH}/mods-enabled/php5.load");
    @unlink("{$DAEMON_PATH}/mods-enabled/jk.load");
    @unlink("{$DAEMON_PATH}/mods-enabled/dav_lock_module.load");
    @unlink("{$DAEMON_PATH}/mods-enabled/dav_module.load");
    @unlink("{$DAEMON_PATH}/mods-enabled/dav_fs_module.load");
    @unlink("{$DAEMON_PATH}/mods-enabled/pagespeed.load");
    $sock = new sockets();
    $FreeWebsDisableMOdQOS = $sock->GET_INFO("FreeWebsDisableMOdQOS");
    if (!is_numeric($FreeWebsDisableMOdQOS)) {
        $FreeWebsDisableMOdQOS = 0;
    }
    if ($FreeWebsEnableModQOS == 0) {
        $FreeWebsDisableMOdQOS = 1;
    }
    if ($FreeWebsDisableMOdQOS == 1) {
        unset($array["qos_module"]);
        @unlink("{$DAEMON_PATH}/mods-enabled/qos_module.load");
    }
    if ($FreeWebsEnableModSecurity == 1) {
        if (is_file("{$APACHE_MODULES_PATH}/mod_security2.so")) {
            $a[] = "LoadFile /usr/lib/libxml2.so.2";
            $a[] = "LoadModule security2_module {$APACHE_MODULES_PATH}/mod_security2.so";
            echo "Starting......: Apache module 'mod_security2' enabled\n";
            @file_put_contents("{$DAEMON_PATH}/mods-enabled/mod_security.load", @implode("\n", $a));
            unset($a);
        } else {
            echo "Starting......: Apache {$APACHE_MODULES_PATH}/mod_security2.so no such file\n";
        }
    } else {
        echo "Starting......: Apache module 'mod_security2' disabled\n";
    }
    if ($FreeWebsEnableModEvasive == 1) {
        if (is_file("{$APACHE_MODULES_PATH}/mod_evasive20.so")) {
            $a[] = "LoadModule evasive20_module {$APACHE_MODULES_PATH}/mod_evasive20.so";
            echo "Starting......: Apache module 'mod_evasive2' enabled\n";
            @file_put_contents("{$DAEMON_PATH}/mods-enabled/mod_evasive.load", @implode("\n", $a));
        } else {
            echo "Starting......: Apache {$APACHE_MODULES_PATH}/mod_evasive20.so no such file\n";
        }
    } else {
        echo "Starting......: Apache module 'mod_evasive2' disabled\n";
    }
    $sql = "SELECT COUNT(servername) as tcount FROM freeweb WHERE UseReverseProxy=1";
    $ligne = @mysql_fetch_array($q->QUERY_SQL($sql, 'artica_backup'));
    $proxys_mods["proxy_module"] = "mod_proxy.so";
    $proxys_mods["proxy_http_module"] = "mod_proxy_http.so";
    $proxys_mods["proxy_ftp_module"] = "mod_proxy_ftp.so";
    $proxys_mods["proxy_connect_module"] = "mod_proxy_connect.so";
    $proxys_mods["headers_module"] = "mod_headers.so";
    $proxys_mods["deflate_module"] = "mod_deflate.so";
    $proxys_mods["xml2enc_module"] = "mod_xml2enc.so";
    $proxys_mods["proxy_html_module"] = "mod_proxy_html.so";
    $proxys_orgs[] = "proxy_ajp.load";
    $proxys_orgs[] = "proxy_balancer.load";
    $proxys_orgs[] = "proxy.conf";
    $proxys_orgs[] = "proxy_connect.load";
    $proxys_orgs[] = "proxy_ftp.load";
    $proxys_orgs[] = "proxy_html.conf";
    $proxys_orgs[] = "proxy_html.load";
    $proxys_orgs[] = "proxy_http.load";
    $proxys_orgs[] = "proxy.load";
    $proxys_orgs[] = "proxy_scgi.load";
    if (is_file("/etc/httpd/conf.d/proxy_ajp.conf")) {
        @unlink("/etc/httpd/conf.d/proxy_ajp.conf");
    }
    while (list($module, $lib) = each($proxys_orgs)) {
        if (is_file("{$DAEMON_PATH}/mods-enabled/{$lib}")) {
            @unlink("{$DAEMON_PATH}/mods-enabled/{$lib}");
        }
    }
    while (list($module, $lib) = each($proxys_mods)) {
        if (is_file("{$DAEMON_PATH}/mods-enabled/{$module}.load")) {
            @unlink("{$DAEMON_PATH}/mods-enabled/{$module}.load");
        }
    }
    echo "Starting......: Apache {$ligne["tcount"]} reverse proxy(s)\n";
    $countDeProxy = $ligne["tcount"];
    if ($FreeWebsEnableOpenVPNProxy == 1) {
        if ($FreeWebsOpenVPNRemotPort != null) {
            $countDeProxy = $countDeProxy + 1;
        }
    }
    if ($countDeProxy > 0) {
        reset($proxys_mods);
        while (list($module, $lib) = each($proxys_mods)) {
            if (!is_file("{$APACHE_MODULES_PATH}/{$lib}")) {
                echo "Starting......: Apache module '{$module}' '{$lib}' no such file\n";
                continue;
            }
            echo "Starting......: Apache module '{$module}' enabled\n";
            $final_proxys[] = "LoadModule {$module} {$APACHE_MODULES_PATH}/{$lib}";
        }
        @file_put_contents("{$DAEMON_PATH}/mods-enabled/proxy_module.load", @implode("\n", $final_proxys));
    }
    while (list($module, $lib) = each($array)) {
        if (!is_file("{$APACHE_MODULES_PATH}/{$lib}")) {
            echo "Starting......: Apache module '{$module}' '{$lib}' no such file\n";
            continue;
        }
        echo "Starting......: Apache module '{$module}' enabled\n";
        @file_put_contents("{$DAEMON_PATH}/mods-enabled/{$module}.load", "LoadModule {$module} {$APACHE_MODULES_PATH}/{$lib}");
    }
}