Ejemplo n.º 1
0
function apache_config()
{
    $sock = new sockets();
    $unix = new unix();
    $EnablePHPFPM = 0;
    $ipaddr = null;
    @mkdir("/var/run/apache2", 0755, true);
    @mkdir("/var/run/sarg-apache", 0755, true);
    @mkdir("/var/log/apache2", 0755, true);
    @mkdir(dirname($GLOBALS["APACHE_PID_PATH"]), 0755, true);
    $APACHE_SRC_ACCOUNT = $unix->APACHE_SRC_ACCOUNT();
    $APACHE_SRC_GROUP = $unix->APACHE_SRC_GROUP();
    $APACHE_MODULES_PATH = $unix->APACHE_MODULES_PATH();
    $SargOutputDir = $sock->GET_INFO("SargOutputDir");
    if ($SargOutputDir == null) {
        $SargOutputDir = "/var/www/html/squid-reports";
    }
    $SargWebPort = intval($sock->GET_INFO("SargWebPort"));
    if ($SargWebPort == 0) {
        $SargWebPort = rand(55600, 59000);
        $sock->SET_INFO("SargWebPort", $SargWebPort);
    }
    if (is_link($SargOutputDir)) {
        $SargOutputDir = @readlink($SargOutputDir);
    }
    @mkdir($SargOutputDir, 0755, true);
    if (!is_file("{$SargOutputDir}/index.html")) {
        $php = $unix->LOCATE_PHP5_BIN();
        shell_exec("{$php} /usr/share/artica-postfix/exec.sarg.php --exec --force >/dev/null 2>&1 &");
    }
    if ($ipaddr == null) {
        $ipaddr = "*";
    }
    $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;
    }
    $logfile = "/var/log/apache2/apache-sarg-access.log";
    $ErrorLog = "/var/log/apache2/apache-sarg-error.log";
    $unix->chown_func($APACHE_SRC_ACCOUNT, $APACHE_SRC_GROUP, "/var/run/sarg-apache");
    $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 ($APACHE_SRC_ACCOUNT == null) {
        $APACHE_SRC_ACCOUNT = "www-data";
        $APACHE_SRC_GROUP = "www-data";
        $unix->CreateUnixUser($APACHE_SRC_ACCOUNT, $APACHE_SRC_GROUP, "Apache username");
    }
    @unlink($ErrorLog);
    @unlink($logfile);
    if (!is_file("{$logfile}")) {
        @touch("{$logfile}");
    }
    if (!is_file("{$ErrorLog}")) {
        @touch("{$ErrorLog}");
    }
    $unix->chown_func($APACHE_SRC_ACCOUNT, $APACHE_SRC_GROUP, $ErrorLog);
    $unix->chown_func($APACHE_SRC_ACCOUNT, $APACHE_SRC_GROUP, $logfile);
    $unix->chown_func($APACHE_SRC_ACCOUNT, $APACHE_SRC_GROUP, "/var/run/sarg-apache");
    $unix->chown_func($APACHE_SRC_ACCOUNT, $APACHE_SRC_GROUP, "/var/log/apache2");
    $unix->chown_func($APACHE_SRC_ACCOUNT, $APACHE_SRC_GROUP, dirname($GLOBALS["APACHE_PID_PATH"]));
    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: {$ArticaSplashHotSpotPort} SSL Port: {$ArticaSplashHotSpotPortSSL}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} PHP-FPM: {$EnablePHPFPM}\n";
    }
    $f[] = "LockFile /var/run/apache2/sarg-artica-accept.lock";
    $f[] = "PidFile {$GLOBALS["APACHE_PID_PATH"]}";
    $f[] = "AcceptMutex flock";
    $f[] = "DocumentRoot {$SargOutputDir}";
    $f[] = "DirectoryIndex index.html";
    $f[] = "ErrorDocument 400 /index.html";
    $f[] = "ErrorDocument 401 /index.html";
    $f[] = "ErrorDocument 403 /index.html";
    $f[] = "ErrorDocument 404 /index.html";
    $f[] = "ErrorDocument 500 /index.html";
    $f[] = "NameVirtualHost {$ipaddr}:{$SargWebPort}";
    $f[] = "Listen {$ipaddr}:{$SargWebPort}";
    $f[] = "<VirtualHost {$ipaddr}:{$SargWebPort}>";
    $f[] = "\tServerName {$ipaddr}";
    $f[] = "\tDocumentRoot {$SargOutputDir}";
    $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();
    $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[]="Alias /index.php /usr/share/artica-postfix/hotspot.php";
    //$f[]="Alias /index.html /usr/share/artica-postfix/hotspot.php";
    $f[] = "<Directory \"{$SargOutputDir}\">";
    $f[] = "\tDirectorySlash On";
    $f[] = "\tDirectoryIndex index.html";
    $f[] = "\t\t<Files \"hostpot.php\">";
    $f[] = "\t\t\tOrder allow,deny";
    $f[] = "\t\t\tallow from all";
    $f[] = "\t\t</Files>";
    $f[] = "\tErrorDocument 400 /index.html";
    $f[] = "\tErrorDocument 401 /index.html";
    $f[] = "\tErrorDocument 403 /index.html";
    $f[] = "\tErrorDocument 404 /index.html";
    $f[] = "\tErrorDocument 500 /index.html";
    $f[] = "\tOptions -Indexes";
    $f[] = "\tAllowOverride All";
    $f[] = "\tOrder allow,deny";
    $f[] = "\tAllow from all";
    $f[] = "</Directory>";
    $f[] = "Loglevel debug";
    $f[] = "ErrorLog {$ErrorLog}";
    $f[] = "LogFormat \"%h %l %u %t \\\"%r\\\" %<s %b\" common";
    $f[] = "CustomLog {$logfile} common";
    $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";
    $array["headers_module"] = "mod_headers.so";
    //$array["ldap_module"]="mod_ldap.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($GLOBALS["APACHE_CONFIG_PATH"], @implode("\n", $f));
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} {$GLOBALS["APACHE_CONFIG_PATH"]} done\n";
    }
}
Ejemplo n.º 2
0
function APACHE_ADD_MODULE($moduleso_file)
{
    $unix = new unix();
    if (preg_match("#^mod_proxy#", $moduleso_file)) {
        return;
    }
    if ($moduleso_file == "mod_proxy_balancer.so") {
        return;
    }
    if ($moduleso_file == "mod_unique_id.so") {
        return;
    }
    if ($moduleso_file == "mod_proxy_ftp.so") {
        return;
    }
    if ($moduleso_file == "mod_proxy_html.so") {
        return;
    }
    if ($moduleso_file == "mod_rpaf-2.0.so") {
        return;
    }
    $APACHE_MODULES_PATH = $unix->APACHE_MODULES_PATH();
    if ($moduleso_file == 'mod_perl.so') {
        if (!AuthorizedModule($moduleso_file)) {
            if ($GLOBALS["VERBOSE"]) {
                echo "{$moduleso_file}: blacklisted\n";
            }
            return;
        }
        if ($GLOBALS["VERBOSE"]) {
            echo "{$moduleso_file}: perl_module OK\n";
        }
        return 'LoadModule perl_module' . "\t{$APACHE_MODULES_PATH}/{$moduleso_file}";
    }
    if ($moduleso_file == 'mod_log_config.so') {
        if (!AuthorizedModule($moduleso_file)) {
            if ($GLOBALS["VERBOSE"]) {
                echo "{$moduleso_file}: blacklisted\n";
            }
            return;
        }
        if ($GLOBALS["VERBOSE"]) {
            echo "{$moduleso_file}: log_config_module OK\n";
        }
        return 'LoadModule log_config_module' . "\t{$APACHE_MODULES_PATH}/{$moduleso_file}";
    }
    if ($moduleso_file == 'mod_vhost_ldap.so') {
        if (!AuthorizedModule($moduleso_file)) {
            if ($GLOBALS["VERBOSE"]) {
                echo "{$moduleso_file}: blacklisted\n";
            }
            return;
        }
        if ($GLOBALS["VERBOSE"]) {
            echo "{$moduleso_file}: vhost_ldap_module OK\n";
        }
        return 'LoadModule vhost_ldap_module' . "\t{$APACHE_MODULES_PATH}/{$moduleso_file}";
    }
    if ($moduleso_file == 'mod_ldap.so') {
        if (!AuthorizedModule($moduleso_file)) {
            if ($GLOBALS["VERBOSE"]) {
                echo "{$moduleso_file}: blacklisted\n";
            }
            return;
        }
        if ($GLOBALS["VERBOSE"]) {
            echo "{$moduleso_file}: ldap_module OK\n";
        }
        return 'LoadModule ldap_module' . "\t{$APACHE_MODULES_PATH}/{$moduleso_file}";
    }
    if ($moduleso_file == 'mod_rewrite.so') {
        if (!AuthorizedModule($moduleso_file)) {
            if ($GLOBALS["VERBOSE"]) {
                echo "{$moduleso_file}: blacklisted\n";
            }
            return;
        }
        if ($GLOBALS["VERBOSE"]) {
            echo "{$moduleso_file}: mod_rewrite OK\n";
        }
        return 'LoadModule rewrite_module' . "\t{$APACHE_MODULES_PATH}/{$moduleso_file}";
    }
    if ($moduleso_file == 'mod_dav.so') {
        if (!AuthorizedModule($moduleso_file)) {
            if ($GLOBALS["VERBOSE"]) {
                echo "{$moduleso_file}: blacklisted\n";
            }
            return;
        }
        if ($GLOBALS["VERBOSE"]) {
            echo "{$moduleso_file}: dav_module OK\n";
        }
        return 'LoadModule dav_module' . "\t{$APACHE_MODULES_PATH}/{$moduleso_file}";
    }
    if ($moduleso_file == 'mod_suexec.so') {
        if (!AuthorizedModule($moduleso_file)) {
            if ($GLOBALS["VERBOSE"]) {
                echo "{$moduleso_file}: blacklisted\n";
            }
            return;
        }
        if ($GLOBALS["VERBOSE"]) {
            echo "{$moduleso_file}: suexec_module OK\n";
        }
        return 'LoadModule suexec_module' . "\t{$APACHE_MODULES_PATH}/{$moduleso_file}";
    }
    if (!AuthorizedModule($moduleso_file)) {
        if ($GLOBALS["VERBOSE"]) {
            echo "{$moduleso_file}: blacklisted\n";
        }
        return null;
    }
    if ($moduleso_file == 'mod_php5.so') {
        if (!AuthorizedModule($moduleso_file)) {
            if ($GLOBALS["VERBOSE"]) {
                echo "{$moduleso_file}: blacklisted\n";
            }
            return;
        }
        return 'LoadModule php5_module' . "\t{$APACHE_MODULES_PATH}/{$moduleso_file}";
    }
    if ($moduleso_file == 'mod_proxy_connect.so') {
        if ($GLOBALS["VERBOSE"]) {
            echo "{$moduleso_file}: blacklisted\n";
        }
        return;
    }
    if ($moduleso_file == 'mod_dav_lock.so') {
        if ($GLOBALS["VERBOSE"]) {
            echo "{$moduleso_file}: blacklisted\n";
        }
        return;
    }
    if ($moduleso_file == 'mod_mem_cache.so') {
        if ($GLOBALS["VERBOSE"]) {
            echo "{$moduleso_file}: blacklisted\n";
        }
        return;
    }
    if ($moduleso_file == 'mod_cgid.so') {
        if ($GLOBALS["VERBOSE"]) {
            echo "{$moduleso_file}: blacklisted\n";
        }
        return;
    }
    if ($moduleso_file == 'mod_proxy.so') {
        if ($GLOBALS["VERBOSE"]) {
            echo "{$moduleso_file}: blacklisted\n";
        }
        return;
    }
    if ($moduleso_file == 'mod_proxy_http.so') {
        if ($GLOBALS["VERBOSE"]) {
            echo "{$moduleso_file}: blacklisted\n";
        }
        return;
    }
    if ($moduleso_file == 'mod_proxy_ajp.so') {
        if ($GLOBALS["VERBOSE"]) {
            echo "{$moduleso_file}: blacklisted\n";
        }
        return;
    }
    $module_name = null;
    $moduleso_file_pattern = str_replace('.', '\\.', $moduleso_file);
    if (preg_match("#^mod_(.+?)\\.so#", $moduleso_file, $re)) {
        $module_name = $re[1] . '_module';
    } else {
        if (preg_match("#^(.+?)\\.so#", $moduleso_file, $re)) {
            $module_name = $re[1] . '_module';
        }
    }
    if ($moduleso_file == 'libphp5.so') {
        $module_name = 'php5_module';
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "{$moduleso_file}: {$module_name} OK\n";
    }
    return "LoadModule {$module_name}\t{$APACHE_MODULES_PATH}/{$moduleso_file}";
}
Ejemplo n.º 3
0
function apache_config()
{
    $sock = new sockets();
    $unix = new unix();
    $EnablePHPFPM = 0;
    $APACHE_SRC_ACCOUNT = $unix->APACHE_SRC_ACCOUNT();
    $APACHE_SRC_GROUP = $unix->APACHE_SRC_GROUP();
    if (preg_match("#APACHE_RUN_GROUP#", $APACHE_SRC_GROUP)) {
        $APACHE_SRC_GROUP = "www-data";
    }
    $LogFilePath = "/var/log/artica-wifidog/access.log";
    $directories[] = "/var/run/apache2";
    $directories[] = "/var/run/artica-apache";
    $directories[] = "/var/log/artica-wifidog";
    $directories[] = "/home/artica/hotspot/sessions";
    $directories[] = "/home/artica/hotspot/caches";
    while (list($index, $maindir) = each($directories)) {
        @mkdir($maindir, 0755, true);
        @chown($maindir, $APACHE_SRC_ACCOUNT);
        @chgrp($maindir, $APACHE_SRC_GROUP);
    }
    $ErrorLog = dirname($LogFilePath) . "/error.log";
    if (!is_file($LogFilePath)) {
        @touch($LogFilePath);
    }
    @chown($LogFilePath, $APACHE_SRC_ACCOUNT);
    @chgrp($LogFilePath, $APACHE_SRC_GROUP);
    if (!is_file($ErrorLog)) {
        @touch($ErrorLog);
    }
    @chown($ErrorLog, $APACHE_SRC_ACCOUNT);
    @chgrp($ErrorLog, $APACHE_SRC_GROUP);
    $APACHE_MODULES_PATH = $unix->APACHE_MODULES_PATH();
    $HotSpotMaxClients = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/HotSpotMaxClients"));
    $HotSpotStartServers = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/HotSpotStartServers"));
    $HotSpotForceDDOSDisable = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/HotSpotForceDDOSDisable"));
    if ($HotSpotMaxClients == 0) {
        $HotSpotMaxClients = 20;
    }
    if ($HotSpotStartServers == 0) {
        $HotSpotStartServers = 5;
    }
    $EnableArticaHotSpot = $sock->GET_INFO("EnableArticaHotSpot");
    $SquidHotSpotPort = $sock->GET_INFO("SquidHotSpotPort");
    $ArticaHotSpotPort = $sock->GET_INFO("ArticaHotSpotPort");
    $ArticaSSLHotSpotPort = $sock->GET_INFO("ArticaSSLHotSpotPort");
    $ArticaSplashHotSpotPort = $sock->GET_INFO("ArticaSplashHotSpotPort");
    $ArticaSplashHotSpotPortSSL = $sock->GET_INFO("ArticaSplashHotSpotPortSSL");
    if (!is_numeric($ArticaHotSpotPort)) {
        $ArticaHotSpotPort = 0;
    }
    if (!is_numeric($ArticaSplashHotSpotPort)) {
        $ArticaSplashHotSpotPort = 16080;
    }
    if (!is_numeric($ArticaSplashHotSpotPortSSL)) {
        $ArticaSplashHotSpotPortSSL = 16443;
    }
    $ArticaHotSpotInterface = $sock->GET_INFO("ArticaHotSpotInterface");
    $HospotHTTPServerName = trim($sock->GET_INFO("HospotHTTPServerName"));
    $HotSpotErrorRedirect = $sock->GET_INFO("HotSpotErrorRedirect");
    if ($HotSpotErrorRedirect == null) {
        $HotSpotErrorRedirect = "http://www.msftncsi.com";
    }
    $Params = unserialize($sock->GET_INFO("HotSpotEvasive"));
    $ApacheEvasiveInstalled = intval($sock->GET_INFO("ApacheEvasiveInstalled"));
    if (!is_numeric($Params["DOSEnable"])) {
        $Params["DOSEnable"] = 1;
    }
    if (!is_numeric($Params["DOSHashTableSize"])) {
        $Params["DOSHashTableSize"] = 1024;
    }
    if (!is_numeric($Params["DOSPageCount"])) {
        $Params["DOSPageCount"] = 3;
    }
    if (!is_numeric($Params["DOSSiteCount"])) {
        $Params["DOSSiteCount"] = 20;
    }
    if (!is_numeric($Params["DOSPageInterval"])) {
        $Params["DOSPageInterval"] = 1;
    }
    if (!is_numeric($Params["DOSSiteInterval"])) {
        $Params["DOSSiteInterval"] = 10;
    }
    if (!is_numeric($Params["DOSBlockingPeriod"])) {
        $Params["DOSBlockingPeriod"] = 5;
    }
    $unix = new unix();
    $NETWORK_ALL_INTERFACES = $unix->NETWORK_ALL_INTERFACES();
    $ipaddr = $NETWORK_ALL_INTERFACES[$ArticaHotSpotInterface]["IPADDR"];
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} HotSpot run as {$ArticaHotSpotInterface} ( {$ipaddr} )\n";
    }
    if ($ipaddr == "0.0.0.0") {
        $ipaddr = "*";
    }
    if ($ipaddr == null) {
        $ipaddr = "*";
    }
    $GLOBALS["HOSTPOT_WEB_INTERFACE"] = $ipaddr;
    $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/artica-apache");
    $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 ($APACHE_SRC_ACCOUNT == null) {
        $APACHE_SRC_ACCOUNT = "www-data";
        $APACHE_SRC_GROUP = "www-data";
        $unix->CreateUnixUser($APACHE_SRC_ACCOUNT, $APACHE_SRC_GROUP, "Apache username");
    }
    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.: {$ArticaSplashHotSpotPort} SSL Port: {$ArticaSplashHotSpotPortSSL}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} PHP-FPM...: {$EnablePHPFPM}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} MaxClients: {$HotSpotMaxClients}\n";
    }
    $f[] = "Group {$APACHE_SRC_GROUP}";
    $f[] = "User {$APACHE_SRC_ACCOUNT}";
    $f[] = "LockFile /var/run/apache2/hotspot-artica-accept.lock";
    $f[] = "PidFile /var/run/artica-apache/hotspot-apache.pid";
    $f[] = "AcceptMutex flock";
    $f[] = "SSLRandomSeed startup file:/dev/urandom  256";
    $f[] = "SSLRandomSeed connect builtin";
    $f[] = "SSLSessionCache        shmcb:/var/run/apache2/ssl_scache-hotspot(512000)";
    $f[] = "SSLSessionCacheTimeout  300";
    $f[] = "SSLSessionCacheTimeout  300";
    $f[] = "DocumentRoot /usr/share/artica-postfix";
    $f[] = "DirectoryIndex hotspot.html";
    $f[] = "ErrorDocument 400 /hotspot.html";
    $f[] = "ErrorDocument 401 /hotspot.html";
    $f[] = "ErrorDocument 403 /hotspot.html";
    $f[] = "ErrorDocument 404 /hotspot.html";
    $f[] = "ErrorDocument 500 /hotspot.html";
    $NameVirtualHost = $ipaddr;
    if ($HospotHTTPServerName != null) {
        $NameVirtualHost = $HospotHTTPServerName;
    }
    $f[] = "NameVirtualHost {$NameVirtualHost}:{$ArticaSplashHotSpotPort}";
    $f[] = "NameVirtualHost {$NameVirtualHost}:{$ArticaSplashHotSpotPortSSL}";
    $f[] = "Listen {$NameVirtualHost}:{$ArticaSplashHotSpotPort}";
    $f[] = "Listen {$NameVirtualHost}:{$ArticaSplashHotSpotPortSSL}";
    $ddos_config = null;
    if ($HotSpotForceDDOSDisable == 1) {
        $Params["DOSEnable"] = 0;
    }
    if ($Params["DOSEnable"] == 1) {
        //$ddos[]="<IfModule mod_evasive20.c>";
        $ddos[] = "\tDOSHashTableSize {$Params["DOSHashTableSize"]}";
        $ddos[] = "\tDOSPageCount {$Params["DOSPageCount"]}";
        $ddos[] = "\tDOSSiteCount {$Params["DOSSiteCount"]}";
        $ddos[] = "\tDOSPageInterval {$Params["DOSPageInterval"]}";
        $ddos[] = "\tDOSSiteInterval {$Params["DOSSiteInterval"]}";
        $ddos[] = "\tDOSBlockingPeriod {$Params["DOSBlockingPeriod"]}";
        $ddos[] = "\tDOSLogDir  \"/var/log/artica-wifidog\"";
        $ddos[] = "\tDOSSystemCommand \"/bin/echo `date '+%F %T'` HOTSPOT  %s >> /var/log/artica-wifidog/dos_evasive_attacks.log\"";
        $ddos_config = @implode("\n", $ddos);
        //$ddos[]="</IfModule>";
    }
    $f[] = "<VirtualHost {$NameVirtualHost}:{$ArticaSplashHotSpotPort}>";
    $f[] = "\tServerName {$NameVirtualHost}";
    $f[] = "\tDocumentRoot /usr/share/artica-postfix";
    $f[] = "{$ddos_config}";
    $f[] = "\tErrorDocument 400 /hotspot.html";
    $f[] = "\tErrorDocument 401 /hotspot.html";
    $f[] = "\tErrorDocument 403 /hotspot.html";
    $f[] = "\tErrorDocument 404 /hotspot.html";
    $f[] = "\tErrorDocument 500 /hotspot.html";
    $f[] = "\tFallbackResource /hotspot.html";
    $f[] = "</VirtualHost>";
    $f[] = "<VirtualHost {$NameVirtualHost}:{$ArticaSplashHotSpotPortSSL}>";
    $f[] = "\tServerName {$NameVirtualHost}";
    $f[] = "\tDocumentRoot /usr/share/artica-postfix";
    $f[] = "\tSSLEngine on";
    $squid = new squidbee();
    $ArticaSplashHotSpotCertificate = $sock->GET_INFO("ArticaSplashHotSpotCertificate");
    $data = $squid->SaveCertificate($ArticaSplashHotSpotCertificate, false, true, false);
    if ($ArticaSplashHotSpotCertificate != null) {
        $apache = new apache_certificate($ArticaSplashHotSpotCertificate);
        $f[] = $apache->build();
    } else {
        if (preg_match("#ssl_certificate\\s+(.+?);\\s+ssl_certificate_key\\s+(.+?);#is", $data, $re)) {
            $cert = $re[1];
            $key = $re[2];
            $f[] = "\tSSLCertificateFile \"{$cert}\"";
            $f[] = "\tSSLCertificateKeyFile \"{$key}\"";
        }
    }
    $f[] = "\tSSLVerifyClient none";
    $f[] = "\tServerSignature Off";
    $f[] = "{$ddos_config}";
    $f[] = "\tErrorDocument 400 /hotspot.html";
    $f[] = "\tErrorDocument 401 /hotspot.html";
    $f[] = "\tErrorDocument 403 /hotspot.html";
    $f[] = "\tErrorDocument 404 /hotspot.html";
    $f[] = "\tErrorDocument 500 /hotspot.html";
    $f[] = "\tFallbackResource /hotspot.html";
    $f[] = "</VirtualHost>";
    $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     3";
    if ($HotSpotStartServers >= $HotSpotMaxClients) {
        $HotSpotMaxClients = $HotSpotMaxClients + $HotSpotStartServers;
    }
    if ($HotSpotMaxClients > 1024) {
        $HotSpotMaxClients = 1024;
    }
    $ServerLimit = $HotSpotMaxClients + 100;
    if ($ServerLimit > 2000) {
        $ServerLimit = 2000;
    }
    $f[] = "StartServers         {$HotSpotStartServers}";
    $f[] = "MaxClients           {$HotSpotMaxClients}";
    $f[] = "ServerLimit\t\t   {$ServerLimit}";
    $MinSpareServers = $HotSpotStartServers + 5;
    $MaxSpareServers = $MinSpareServers + 1;
    $f[] = "MinSpareServers      {$MinSpareServers}";
    $f[] = "MaxSpareServers      {$MaxSpareServers}";
    $f[] = "MaxRequestsPerChild  800";
    $f[] = "MaxKeepAliveRequests 100";
    $f[] = "ServerName " . $unix->hostname_g();
    $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-articahtp(512000)";
    $f[] = "\tSSLSessionCacheTimeout  300";
    $f[] = "\tSSLSessionCacheTimeout  300";
    $f[] = "\tSSLMutex  sem";
    $f[] = "\tSSLCipherSuite HIGH:MEDIUM:!ADH";
    $f[] = "\tSSLProtocol all -SSLv2";
    $f[] = "</IfModule>";
    $f[] = "";
    $f[] = "AddType application/x-httpd-php .php";
    $f[] = "php_value error_log \"/var/log/artica-wifidog/access.log\"";
    $f[] = "php_value session.save_path \"/home/artica/hotspot/sessions\"";
    $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[] = "Alias /index.php /hotspot.html";
    $f[] = "Alias /index.html /hotspot.html";
    $f[] = "Alias /Microsoft-Server-ActiveSync /hotspot-none.html";
    $f[] = "<Directory \"/usr/share/artica-postfix\">";
    $f[] = "\tDirectorySlash On";
    $f[] = "\tDirectoryIndex hostpot.php";
    $f[] = "\t\t<Files \"hostpot.php\">";
    $f[] = "\t\t\tOrder allow,deny";
    $f[] = "\t\t\tallow from all";
    $f[] = "\t\t</Files>";
    $f[] = "\t\t<Files \"hostpot.html\">";
    $f[] = "\t\t\tOrder allow,deny";
    $f[] = "\t\t\tallow from all";
    $f[] = "\t\t</Files>";
    $f[] = "\t\t<FilesMatch \"!(hostpot)\\.(html|php)\$\">";
    $f[] = "\t\t\tOrder allow,deny";
    $f[] = "\t\t\tdeny from all";
    $f[] = "\t\t</FilesMatch>";
    $f[] = "\tErrorDocument 400 /hotspot.html";
    $f[] = "\tErrorDocument 401 /hotspot.html";
    $f[] = "\tErrorDocument 403 /hotspot.html";
    $f[] = "\tErrorDocument 404 /hotspot.html";
    $f[] = "\tErrorDocument 500 /hotspot.html";
    $f[] = "\tFallbackResource /hotspot.html";
    $f[] = "\tOptions -Indexes";
    $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/artica-apache/php5.fastcgi";
        $f[] = "\tAddHandler php-script .php";
        $f[] = "\tFastCGIExternalServer /var/run/artica-apache/php5.fastcgi -socket /var/run/php-fpm.sock -idle-timeout 610";
        $f[] = "\tAction php-script /php5.fastcgi virtual";
        $f[] = "\t<Directory /var/run/artica-apache>";
        $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";
        }
    }
    $f[] = "Loglevel debug";
    $f[] = "ErrorLog {$ErrorLog}";
    $f[] = "LogFormat \"%h %l %u %t \\\"%r\\\" %<s %b\" common";
    $f[] = "CustomLog {$LogFilePath} common";
    if ($EnableArticaApachePHPFPM == 0) {
        $array["php5_module"] = "libphp5.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";
    $array["ssl_module"] = "mod_ssl.so";
    $array["headers_module"] = "mod_headers.so";
    $array["ldap_module"] = "mod_ldap.so";
    if ($Params["DOSEnable"] == 1) {
        $array["evasive20_module"] = "mod_evasive20.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";
            }
        }
    }
    build_error_page();
    @file_put_contents("/etc/artica-postfix/hotspot-httpd.conf", @implode("\n", $f) . "\n");
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} /etc/artica-postfix/hotspot-httpd.conf done\n";
    }
}
Ejemplo n.º 4
0
function apache_config()
{
    $sock = new sockets();
    $unix = new unix();
    $EnablePHPFPM = 0;
    @mkdir("/var/run/apache2", 0755, true);
    @mkdir("/var/run/artica-apache", 0755, true);
    @mkdir("/var/log/lighttpd", 0755, true);
    $APACHE_SRC_ACCOUNT = $unix->APACHE_SRC_ACCOUNT();
    $APACHE_SRC_GROUP = $unix->APACHE_SRC_GROUP();
    $APACHE_MODULES_PATH = $unix->APACHE_MODULES_PATH();
    $pydio_installed = false;
    if (is_file(" /etc/php5/cli/conf.d/ming.ini")) {
        @unlink(" /etc/php5/cli/conf.d/ming.ini");
    }
    @unlink("/var/log/lighttpd/apache-error.log");
    @touch("/var/log/lighttpd/apache-error.log");
    @chmod("/var/log/lighttpd/apache-error.log", 0755);
    $unix->chown_func($APACHE_SRC_ACCOUNT, $APACHE_SRC_GROUP, "/var/log/lighttpd/*");
    $unix->chown_func($APACHE_SRC_ACCOUNT, $APACHE_SRC_GROUP, "/usr/share/artica-postfix/ressources/logs/*");
    if (is_dir("/usr/share/artica-postfix/pydio")) {
        $pydio_installed = true;
    }
    $ArticaHttpsPort = 9000;
    $NoLDAPInLighttpdd = 0;
    $ArticaHttpUseSSL = 1;
    $ArticaHttpsPort = $sock->GET_INFO("ArticaHttpsPort");
    $ArticaHttpUseSSL = $sock->GET_INFO("ArticaHttpUseSSL");
    if (!is_numeric($ArticaHttpUseSSL)) {
        $ArticaHttpUseSSL = 1;
    }
    if (!is_numeric($ArticaHttpsPort)) {
        $ArticaHttpsPort = "9000";
    }
    $LighttpdArticaListenIP = $sock->GET_INFO("LighttpdArticaListenIP");
    $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;
    }
    $EnablePHPFPM = intval($sock->GET_INFO("EnablePHPFPM"));
    if (!is_numeric($EnablePHPFPM)) {
        $EnablePHPFPM = 0;
    }
    if ($EnablePHPFPM == 0) {
        $EnableArticaApachePHPFPM = 0;
    }
    $unix->chown_func($APACHE_SRC_ACCOUNT, $APACHE_SRC_GROUP, "/var/run/artica-apache");
    $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 ($APACHE_SRC_ACCOUNT == null) {
        $APACHE_SRC_ACCOUNT = "www-data";
        $APACHE_SRC_GROUP = "www-data";
        $unix->CreateUnixUser($APACHE_SRC_ACCOUNT, $APACHE_SRC_GROUP, "Apache username");
    }
    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"]} PHP-FPM: {$EnablePHPFPM}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} PHP-FPM Enabled: {$EnableArticaApachePHPFPM}\n";
    }
    $f[] = "LockFile /var/run/apache2/artica-accept.lock";
    $f[] = "PidFile /var/run/artica-apache/apache.pid";
    $f[] = "DocumentRoot /usr/share/artica-postfix";
    $open_basedir[] = "/usr/share/artica-postfix";
    $open_basedir[] = "/etc/artica-postfix";
    $open_basedir[] = "/etc/artica-postfix/settings";
    $open_basedir[] = "/var/log";
    $open_basedir[] = "/var/run/mysqld";
    $open_basedir[] = "/usr/share/php";
    $open_basedir[] = "/usr/share/php5";
    $open_basedir[] = "/var/lib/php5";
    $open_basedir[] = "/var/lighttpd/upload";
    $open_basedir[] = "/usr/share/artica-postfix/ressources";
    $open_basedir[] = "/usr/share/artica-postfix/framework";
    $open_basedir[] = "/etc/ssl/certs/mysql-client-download";
    $open_basedir[] = "/var/run";
    $open_basedir[] = "/bin";
    $open_basedir[] = "/tmp";
    $open_basedir[] = "/usr/sbin";
    $open_basedir[] = "/home";
    //$f[]="php_value open_basedir \"".@implode(":", $open_basedir)."\"";
    //$f[]="php_value output_buffering Off";
    //$f[]="php_flag magic_quotes_gpc Off";
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Listen Port: {$ArticaHttpsPort}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Listen IP: {$LighttpdArticaListenIP}\n";
    }
    if ($LighttpdArticaListenIP != null) {
        $unix = new unix();
        $IPS = $unix->NETWORK_ALL_INTERFACES(true);
        if (!isset($IPS[$LighttpdArticaListenIP])) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} ERROR! Listen IP: {$LighttpdArticaListenIP} -> FALSE !!\n";
            }
            $LighttpdArticaListenIP = null;
        }
    }
    if ($LighttpdArticaListenIP == null) {
        $LighttpdArticaListenIP = "*";
    }
    if ($LighttpdArticaListenIP != null) {
        $ArticaHttpsPort = "{$LighttpdArticaListenIP}:{$ArticaHttpsPort}";
    }
    $f[] = "Listen {$ArticaHttpsPort}";
    $MaxClients = 20;
    $f[] = "<IfModule mpm_prefork_module>";
    $f[] = "\tStartServers 1";
    $f[] = "\tMinSpareServers 2";
    $f[] = "\tMaxSpareServers 3";
    $f[] = "\tMaxClients {$MaxClients}";
    $f[] = "\tServerLimit {$MaxClients}";
    $f[] = "\tMaxRequestsPerChild 100";
    $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           {$MaxClients}";
    $f[] = "MinSpareServers      2";
    $f[] = "MaxSpareServers      3";
    $f[] = "MaxRequestsPerChild  100";
    $f[] = "MaxKeepAliveRequests 100";
    $ServerName = $unix->hostname_g();
    if ($ServerName == null) {
        $ServerName = "localhost.localdomain";
    }
    $f[] = "ServerName {$ServerName}";
    if ($ArticaHttpUseSSL == 1) {
        $mknod = $unix->find_program("mknod");
        shell_exec("{$mknod} /dev/random c 1 9 >/dev/null 2>&1");
        $f[] = "<IfModule mod_ssl.c>";
        $f[] = "\tListen {$ArticaHttpsPort}";
        $f[] = "\tSSLRandomSeed connect builtin";
        $f[] = "\tSSLRandomSeed connect file:/dev/urandom 256";
        $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-artica(512000)";
        $f[] = "\tSSLSessionCacheTimeout  300";
        $f[] = "\tSSLSessionCacheTimeout  300";
        $f[] = "\tSSLCipherSuite HIGH:MEDIUM:!ADH";
        $f[] = "\tSSLProtocol all -SSLv2";
        $f[] = "</IfModule>";
        $f[] = "";
        $f[] = "<IfModule mod_gnutls.c>";
        $f[] = "\tListen {$ArticaHttpsPort}";
        $f[] = "</IfModule>";
    }
    if (!is_file("/etc/ssl/certs/apache/server.crt")) {
        shell_exec("/usr/share/artica-postfix/bin/artica-install --apache-ssl-cert");
    }
    if ($ArticaHttpUseSSL == 1) {
        $f[] = "SSLEngine on";
        $f[] = "AcceptMutex flock";
        $f[] = "SSLCertificateFile \"/etc/ssl/certs/apache/server.crt\"";
        $f[] = "SSLCertificateKeyFile \"/etc/ssl/certs/apache/server.key\"";
        $f[] = "SSLVerifyClient none";
        $f[] = "ServerSignature Off";
        $f[] = "SSLRandomSeed startup file:/dev/urandom  256";
        $f[] = "SSLRandomSeed connect builtin";
    }
    $f[] = "AddType application/x-httpd-php .php";
    if ($EnableArticaApachePHPFPM == 0) {
        $f[] = "php_value error_log \"/var/log/php.log\"";
    }
    @chown("/var/log/php.log", $APACHE_SRC_ACCOUNT);
    $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[] = "\tAddType application/octet-stream .acl";
    $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[] = apache_nagios_config();
    $f[] = apache_phpldapadmin();
    $squid = $unix->LOCATE_SQUID_BIN();
    if (is_file($squid)) {
        $f[] = "Alias /proxy /usr/share/artica-postfix/squid.access.log.php";
        $f[] = "Alias /parent /usr/share/artica-postfix/squid.access.log.php";
        $f[] = "Alias /webfilter /usr/share/artica-postfix/squid.access.webfilter.log.php";
        $f[] = "Alias /meta-updates /home/artica-meta";
        $f[] = "Alias /categories /usr/share/artica-postfix/public.categories.personnal.php";
    }
    $f[] = "<Directory \"/home/artica-meta\">";
    $f[] = "\tOptions Indexes FollowSymLinks";
    $f[] = "</Directory>";
    $f[] = "<Directory \"/usr/share/artica-postfix\">";
    $f[] = "\tDirectoryIndex logon.php";
    $f[] = "\tSSLOptions +StdEnvVars";
    $f[] = "\tOptions Indexes FollowSymLinks";
    $f[] = "\tAllowOverride None";
    //$f[]="\tOrder allow,deny";
    //$f[]="\tAllow from all";
    $f[] = "</Directory>";
    if (is_file($unix->LOCATE_SQUID_BIN())) {
        $ArticaProxyStatisticsBackupFolder = $sock->GET_INFO("ArticaProxyStatisticsBackupFolder");
        if ($ArticaProxyStatisticsBackupFolder == null) {
            $ArticaProxyStatisticsBackupFolder = "/home/artica/squid/backup-statistics";
        }
        $ArticaProxyStatisticsOpenWeb = intval($sock->GET_INFO("ArticaProxyStatisticsOpenWeb"));
        if ($ArticaProxyStatisticsOpenWeb == 1) {
            $f[] = "Alias /backup-stats  \"{$ArticaProxyStatisticsBackupFolder}\"";
            $f[] = "<Directory \"{$ArticaProxyStatisticsBackupFolder}\">";
            $f[] = "\tSSLOptions +StdEnvVars";
            $f[] = "\tOptions Indexes FollowSymLinks";
            $f[] = "\tAllowOverride All";
            //$f[]="\tOrder allow,deny";
            //$f[]="\tAllow from all";
            $f[] = "</Directory>";
        }
    }
    if ($pydio_installed) {
        $directories[] = "/home/pydio/plugins/auth.serial";
        $directories[] = "/home/pydio/plugins/conf.serial";
        $directories[] = "/home/pydio/plugins";
        $directories[] = "/home/pydio/cache";
        $directories[] = "/home/pydio/files";
        $directories[] = "/home/pydio/logs";
        $directories[] = "/home/pydio/personal";
        $directories[] = "/home/pydio/public";
        $directories[] = "/home/pydio/tmp";
        while (list($index, $dir) = each($directories)) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} permissions on {$dir}\n";
            }
            @mkdir($dir, 0755, true);
            $unix->chown_func($APACHE_SRC_ACCOUNT, $APACHE_SRC_GROUP, $dir);
        }
        $unix->chown_func($APACHE_SRC_ACCOUNT, $APACHE_SRC_GROUP, "/home/pydio/cache");
        $unix->chown_func($APACHE_SRC_ACCOUNT, $APACHE_SRC_GROUP, "/home/pydio/plugins");
        $f[] = "Alias /explorer  \"/usr/share/artica-postfix/pyio\"";
        $f[] = "<Directory \"/usr/share/artica-postfix/pyio\">";
        $f[] = "\tDirectoryIndex index.php";
        $f[] = "\tSSLOptions +StdEnvVars";
        $f[] = "\tOptions Indexes FollowSymLinks";
        $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/artica-apache/php5.fastcgi";
        $f[] = "\tAddHandler php-script .php";
        $f[] = "\tFastCGIExternalServer /var/run/artica-apache/php5.fastcgi -socket /var/run/php-fpm.sock -idle-timeout 610";
        $f[] = "\tAction php-script /php5.fastcgi virtual";
        $f[] = "\t<Directory /var/run/artica-apache>";
        $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";
        }
    }
    $f[] = "Loglevel info";
    $f[] = "ErrorLog /var/log/lighttpd/apache-error.log";
    $f[] = "LogFormat \"%h %l %u %t \\\"%r\\\" %<s %b\" common";
    $f[] = "CustomLog /var/log/lighttpd/apache-access.log common";
    if ($EnableArticaApachePHPFPM == 0) {
        $array["php5_module"] = "libphp5.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["authn_file_module"] = "mod_authn_file.so";
    //$array["authz_host_module"]="mod_authz_host.so";
    $array["autoindex_module"] = "mod_autoindex.so";
    $array["negotiation_module"] = "mod_negotiation.so";
    $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";
            }
        }
    }
    $f[] = apache_phpmyadmin();
    @file_put_contents("/etc/artica-postfix/httpd.conf", @implode("\n", $f));
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} /etc/artica-postfix/httpd.conf done\n";
    }
}
Ejemplo n.º 5
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";
    }
}
Ejemplo n.º 6
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";
}
Ejemplo n.º 7
0
    }
}
if (preg_match("#--no-compile#", @implode(" ", $argv))) {
    $GLOBALS["NO_COMPILE"] = true;
}
if (preg_match("#--verbose#", @implode(" ", $argv))) {
    $GLOBALS["VERBOSE"] = true;
}
if (preg_match("#--repos#", @implode(" ", $argv))) {
    $GLOBALS["REPOS"] = true;
}
if (preg_match("#--force#", @implode(" ", $argv))) {
    $GLOBALS["FORCE"] = true;
}
$users = new usersMenus();
$APACHE_MODULES_PATH = $unix->APACHE_MODULES_PATH();
if (!is_dir($APACHE_MODULES_PATH)) {
    echo "Unable to locate APACHE MODULES DIRECTORY...\n";
    die;
}
$timefile = $unix->file_time_min("/etc/artica-postfix/mod_rpaf-2.0.so.compile");
if ($timefile < 60) {
    echo "Already executed since {$timefile}mn, need to wait 1h\n";
    die;
}
$wget = $unix->find_program("wget");
$tar = $unix->find_program("tar");
$rm = $unix->find_program("rm");
$cp = $unix->find_program("cp");
$dirsrc = "mod_rpaf";
$Architecture = Architecture();