Пример #1
0
function php_fpm($aspid = false)
{
    $unix = new unix();
    if (is_file("/etc/lsb-release")) {
        if ($GLOBALS["VERBOSE"]) {
            "CheckSourcesList: Ubuntu system, aborting\n";
        }
    }
    if (!is_file("/etc/debian_version")) {
        return;
    }
    $phpfpm = $unix->APACHE_LOCATE_PHP_FPM();
    if (is_file($phpfpm)) {
        nginx();
        return;
    }
    if ($aspid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pidTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
        $kill = $unix->find_program("kill");
        $timexec = $unix->file_time_min($pidTime);
        if ($timexec < 240) {
            return;
        }
        @unlink($pidTime);
        @file_put_contents($pidTime, time());
        $pid = $unix->get_pid_from_file($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($time < 30) {
                return;
            }
            unix_system_kill_force($pid);
        }
        @file_put_contents($pidfile, getmypid());
    }
    $ver = trim(@file_get_contents("/etc/debian_version"));
    preg_match("#^([0-9]+)\\.#", $ver, $re);
    if (preg_match("#squeeze\\/sid#", $ver)) {
        $Major = 6;
    }
    $Major = $re[1];
    if ($Major != 6) {
        echo "CheckSourcesList: Debian version <> {$Major} aborting...\n";
        return;
    }
    Check_dotdeb();
    $unix = new unix();
    $aptget = $unix->find_program("apt-get");
    echo "CheckSourcesList: Installing php5-fpm\n";
    $cmd = "DEBIAN_FRONTEND=noninteractive {$aptget} -o Dpkg::Options::=\"--force-confnew\" --force-yes -y install php5-fpm libapache2-mod-fastcgi 2>&1";
    echo "CheckSourcesList: {$cmd}\n";
    shell_exec($cmd);
    $phpfpm = $unix->APACHE_LOCATE_PHP_FPM();
    if (is_file($phpfpm)) {
        $php = $unix->LOCATE_PHP5_BIN();
        shell_exec("{$php} /usr/share/artica-postfix/exec.initslapd.php --phppfm");
        APTToSyslog("Restarting PHP-FPM");
        shell_exec("/etc/init.d/php5-fpm restart");
        shell_exec("/etc/init.d/artica-postfix restart apache");
        shell_exec("/etc/init.d/artica-status reload");
        shell_exec("/etc/init.d/artica-framework restart");
        shell_exec("/etc/init.d/monit restart");
        shell_exec("{$php} /usr/share/artica-postfix/exec.freeweb.php --build");
    }
}
Пример #2
0
function BuildArticaInNginx()
{
    $sock = new sockets();
    $unix = new unix();
    $BuildFrameWorkInNginx = false;
    $EnableArticaFrontEndToNGninx = intval($sock->GET_INFO("EnableArticaFrontEndToNGninx"));
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx, EnableArticaFrontEndToNGninx = {$EnableArticaFrontEndToNGninx}\n";
    }
    if ($EnableArticaFrontEndToNGninx == 0) {
        return;
    }
    $SargOutputDir = $sock->GET_INFO("SargOutputDir");
    if ($SargOutputDir == null) {
        $SargOutputDir = "/var/www/html/squid-reports";
    }
    if (!is_dir($SargOutputDir)) {
        @mkdir($SargOutputDir, 0755, true);
    }
    if (!is_file("{$SargOutputDir}/logo.gif")) {
        @copy("/usr/share/artica-postfix/css/images/logo.gif", "{$SargOutputDir}/logo.gif");
    }
    if (!is_file("{$SargOutputDir}/pattern.png")) {
        @copy("/usr/share/artica-postfix/css/images/pattern.png", "{$SargOutputDir}/pattern.png");
    }
    $phpfpm = $unix->APACHE_LOCATE_PHP_FPM();
    $EnablePHPFPM = $sock->GET_INFO("EnablePHPFPM");
    $EnableArticaApachePHPFPM = $sock->GET_INFO("EnableArticaApachePHPFPM");
    if (!is_numeric($EnableArticaApachePHPFPM)) {
        $EnableArticaApachePHPFPM = 0;
    }
    if ($EnableArticaApachePHPFPM == 0) {
        $EnablePHPFPM = 0;
    }
    $EnableSargGenerator = $sock->GET_INFO("EnableSargGenerator");
    if (!is_numeric($EnableSargGenerator)) {
        $EnableSargGenerator = 1;
    }
    if (!is_numeric($EnablePHPFPM)) {
        $EnablePHPFPM = 0;
    }
    if (!is_file($phpfpm)) {
        $EnablePHPFPM = 0;
    }
    if ($EnablePHPFPM == 1) {
        ToSyslog("Restarting PHP5-FPM");
        shell_exec("/etc/init.d/php5-fpm reload >/dev/null 2>&1");
    }
    $host = new nginx("0.0.0.0:9000");
    $host->set_ssl();
    $host->set_proxy_disabled();
    $host->set_DocumentRoot("/usr/share/artica-postfix");
    $host->set_index_file("admin.index.php");
    $host->build_proxy();
    $lighttpdbin = $unix->find_program("lighttpd");
    if (!is_file($lighttpdbin)) {
        $BuildFrameWorkInNginx = true;
    }
    if (is_file("/etc/artica-postfix/WORDPRESS_APPLIANCE")) {
        $BuildFrameWorkInNginx = true;
    }
    if ($EnableSargGenerator == 1) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx, SARG is enabled...\n";
        }
        $host->SargDir();
        $host->build_proxy();
    }
    if ($BuildFrameWorkInNginx) {
        if (is_file("/etc/php5/fpm/pool.d/framework.conf")) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx, building framework...\n";
            }
            $host = new nginx(47980);
            $host->set_proxy_disabled();
            $host->set_DocumentRoot("/usr/share/artica-postfix/framework");
            $host->set_framework();
            $host->set_listen_ip("127.0.0.1");
            $host->set_servers_aliases(array("127.0.0.1"));
            $host->build_proxy();
        }
    }
}
Пример #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";
    }
}
Пример #4
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";
    }
}
Пример #5
0
function phppfm()
{
    if (is_file("/etc/artica-postfix/FROM_ISO")) {
        if (!is_file("/etc/artica-postfix/artica-iso-setup-launched")) {
            die;
        }
    }
    $unix = new unix();
    if (is_file("/etc/artica-postfix/FROM_ISO")) {
        $daemon_path = "/usr/sbin/php5-fpm";
        $php = $GLOBALS["PHP5_BIN_PATH"];
    } else {
        $php = $unix->LOCATE_PHP5_BIN();
        $daemon_path = $unix->APACHE_LOCATE_PHP_FPM();
    }
    $INITD_PATH = "/etc/init.d/php5-fpm";
    $php5script = "exec.php-fpm.php";
    $daemonbinLog = "PHP5 FastCGI Process Manager Daemon";
    $f[] = "#!/bin/sh";
    $f[] = "### BEGIN INIT INFO";
    $f[] = "# Provides:         php5-fpm";
    $f[] = "# Required-Start:    \$local_fs \$syslog";
    $f[] = "# Required-Stop:     \$local_fs \$syslog";
    $f[] = "# Should-Start:";
    $f[] = "# Should-Stop:";
    $f[] = "# Default-Start:     2 3 4 5";
    $f[] = "# Default-Stop:      0 1 6";
    $f[] = "# Short-Description: {$daemonbinLog}";
    $f[] = "# chkconfig: - 80 75";
    $f[] = "# description: {$daemonbinLog}";
    $f[] = "### END INIT INFO";
    $f[] = "DAEMON={$daemon_path}";
    $f[] = "[ -x \"\$DAEMON\" ] || exit 0";
    $f[] = "case \"\$1\" in";
    $f[] = " start)";
    $f[] = "    {$php} /usr/share/artica-postfix/{$php5script} --start --script \$2 \$3";
    $f[] = "    ;;";
    $f[] = "";
    $f[] = "  stop)";
    $f[] = "    {$php} /usr/share/artica-postfix/{$php5script} --stop --script \$2 \$3";
    $f[] = "    ;;";
    $f[] = "";
    $f[] = " restart)";
    $f[] = "    {$php} /usr/share/artica-postfix/{$php5script} --restart --script \$2 \$3";
    $f[] = "    ;;";
    $f[] = "";
    $f[] = "  *)";
    $f[] = "    echo \"Usage: \$0 {start|stop|restart} (+ '--verbose' for more infos)\"";
    $f[] = "    exit 1";
    $f[] = "    ;;";
    $f[] = "esac";
    $f[] = "exit 0\n";
    echo "{$daemonbinLog}: [INFO] Writing {$INITD_PATH} with new config\n";
    @unlink($INITD_PATH);
    @file_put_contents($INITD_PATH, @implode("\n", $f));
    @chmod($INITD_PATH, 0755);
    if (is_file('/usr/sbin/update-rc.d')) {
        shell_exec("/usr/sbin/update-rc.d -f " . basename($INITD_PATH) . " defaults >/dev/null 2>&1");
    }
    if (is_file('/sbin/chkconfig')) {
        shell_exec("/sbin/chkconfig --add " . basename($INITD_PATH) . " >/dev/null 2>&1");
        shell_exec("/sbin/chkconfig --level 345 " . basename($INITD_PATH) . " on >/dev/null 2>&1");
    }
}
Пример #6
0
function buildConfig()
{
    $unix = new unix();
    $sock = new sockets();
    $phpcgi = $unix->LIGHTTPD_PHP5_CGI_BIN_PATH();
    $chown = $unix->find_program("chown");
    $perlbin = $unix->find_program("perl");
    $nohup = $unix->find_program("nohup");
    $php = $unix->LOCATE_PHP5_BIN();
    $PHP_STANDARD_MODE = true;
    $phpfpm = $unix->find_program('php5-fpm');
    if (!is_file($phpfpm)) {
        $phpfpm = $unix->find_program('php-fpm');
    }
    @mkdir("/usr/share/artica-postfix/framework", 0755, true);
    @mkdir("/usr/share/artica-postfix/ressources/sock", 0755, true);
    $LighttpdRunAsminimal = $sock->GET_INFO("LighttpdRunAsminimal");
    $LighttpdArticaMaxProcs = $sock->GET_INFO("LighttpdArticaMaxProcs");
    $LighttpdArticaMaxChildren = $sock->GET_INFO("LighttpdArticaMaxChildren");
    $PHP_FCGI_MAX_REQUESTS = $sock->GET_INFO("PHP_FCGI_MAX_REQUESTS");
    $SessionPathInMemory = $sock->GET_INFO("SessionPathInMemory");
    if (!is_numeric($LighttpdRunAsminimal)) {
        $LighttpdRunAsminimal = 0;
    }
    if (!is_numeric($LighttpdArticaMaxProcs)) {
        $LighttpdArticaMaxProcs = 0;
    }
    if (!is_numeric($LighttpdArticaMaxChildren)) {
        $LighttpdArticaMaxChildren = 0;
    }
    if (!is_numeric($PHP_FCGI_MAX_REQUESTS)) {
        $PHP_FCGI_MAX_REQUESTS = 200;
    }
    if (!is_numeric($SessionPathInMemory)) {
        $SessionPathInMemory = 0;
    }
    $EnableArticaApachePHPFPM = $sock->GET_INFO("EnableArticaApachePHPFPM");
    if (!is_numeric($EnableArticaApachePHPFPM)) {
        $EnableArticaApachePHPFPM = 0;
    }
    if (!is_file("/opt/artica/ssl/certs/lighttpd.pem")) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} creating SSL certificate..\n";
        }
        exec("/usr/share/artica-postfix/bin/artica-install -lighttpd-cert 2>&1", $results);
        while (list($pid, $line) = each($results)) {
            $line = trim($line);
            if ($line == null) {
                continue;
            }
            if (preg_match("#Starting.*?lighttpd(.+)#", $line, $re)) {
                $line = $re[1];
            }
            $line = str_replace(": ", "", $line);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [ARTI]: {$GLOBALS["SERVICE_NAME"]} {$line}\n";
            }
        }
    }
    $results = array();
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Creating PHP configuration..\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Executing artica-install --php-ini..\n";
    }
    exec("/usr/share/artica-postfix/bin/artica-install --php-ini 2>&1", $results);
    while (list($pid, $line) = each($results)) {
        $line = trim($line);
        if ($line == null) {
            continue;
        }
        if (preg_match("#Starting.*?lighttpd(.+)#", $line, $re)) {
            $line = $re[1];
        }
        $line = str_replace(": ", "", $line);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [ARTI]: {$GLOBALS["SERVICE_NAME"]} {$line}\n";
        }
    }
    PHP_MYADMIN();
    $PHP_FCGI_CHILDREN = 3;
    $max_procs = 3;
    if ($LighttpdArticaMaxProcs > 0) {
        $max_procs = $LighttpdArticaMaxProcs;
    }
    if ($LighttpdArticaMaxChildren > 0) {
        $PHP_FCGI_CHILDREN = $LighttpdArticaMaxChildren;
    }
    if (!$unix->ISMemoryHiger1G()) {
        $PHP_FCGI_CHILDREN = 2;
        $max_procs = 1;
    }
    $MEMORY = $unix->MEM_TOTAL_INSTALLEE();
    if ($MEMORY < 624288) {
        $LighttpdRunAsminimal = 1;
    }
    if ($LighttpdRunAsminimal == 1) {
        $max_procs = 1;
        $PHP_FCGI_CHILDREN = 2;
        $PHP_FCGI_MAX_REQUESTS = 500;
    }
    $phpfpm = $unix->APACHE_LOCATE_PHP_FPM();
    $EnablePHPFPM = $sock->GET_INFO("EnablePHPFPM");
    if (!is_numeric($EnablePHPFPM)) {
        $EnablePHPFPM = 0;
    }
    if (!is_file($phpfpm)) {
        $EnablePHPFPM = 0;
    }
    if ($EnablePHPFPM == 0) {
        $EnableArticaApachePHPFPM = 0;
    }
    if ($EnableArticaApachePHPFPM == 0) {
        $EnablePHPFPM = 0;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} EnableArticaApachePHPFPM = {$EnableArticaApachePHPFPM}\n";
    }
    if ($EnablePHPFPM == 1) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Using PHP-FPM........: Yes\n";
        }
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Using PHP-FPM........: No\n";
        }
    }
    $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";
    }
    $ArticaHttpUseSSL = $sock->GET_INFO('ArticaHttpUseSSL');
    if (!is_numeric($ArticaHttpUseSSL)) {
        $ArticaHttpUseSSL = 1;
    }
    $NoLDAPInLighttpdd = $sock->GET_INFO('NoLDAPInLighttpdd');
    if (!is_numeric($NoLDAPInLighttpdd)) {
        $NoLDAPInLighttpdd = 0;
    }
    $LighttpdUseUnixSocket = $sock->GET_INFO('LighttpdUseUnixSocket');
    if (!is_numeric($LighttpdUseUnixSocket)) {
        $LighttpdUseUnixSocket = 0;
    }
    $lighttpdPhpPort = $sock->GET_INFO('lighttpdPhpPort');
    if (!is_numeric($lighttpdPhpPort)) {
        $lighttpdPhpPort = 1808;
    }
    $DenyMiniWebFromStandardPort = $sock->GET_INFO('DenyMiniWebFromStandardPort');
    if (!is_numeric($DenyMiniWebFromStandardPort)) {
        $DenyMiniWebFromStandardPort = 0;
    }
    $LighttpdArticaDisableSSLv2 = $sock->GET_INFO('LighttpdArticaDisableSSLv2');
    if (!is_numeric($LighttpdArticaDisableSSLv2)) {
        $LighttpdArticaDisableSSLv2 = 1;
    }
    $LighttpdArticaMaxProcs = $sock->GET_INFO('LighttpdArticaMaxProcs');
    if (!is_numeric($LighttpdArticaMaxProcs)) {
        $LighttpdArticaMaxProcs = 0;
    }
    $LighttpdArticaMaxChildren = $sock->GET_INFO('LighttpdArticaMaxChildren');
    if (!is_numeric($LighttpdArticaMaxChildren)) {
        $LighttpdArticaMaxChildren = 0;
    }
    $LighttpdRunAsminimal = $sock->GET_INFO('LighttpdRunAsminimal');
    if (!is_numeric($LighttpdRunAsminimal)) {
        $LighttpdRunAsminimal = 0;
    }
    $PHP_FCGI_MAX_REQUESTS = $sock->GET_INFO('PHP_FCGI_MAX_REQUESTS');
    if (!is_numeric($PHP_FCGI_MAX_REQUESTS)) {
        $PHP_FCGI_MAX_REQUESTS = 200;
    }
    $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;
    }
    if ($EnableArticaApachePHPFPM == 0) {
        $EnablePHPFPM = 0;
    }
    $PHP_STANDARD_MODE = true;
    $LighttpdArticaListenIP = $sock->GET_INFO('LighttpdArticaListenIP');
    $phpcgi_path = $unix->LIGHTTPD_PHP5_CGI_BIN_PATH();
    $LIGHTTPD_GET_USER = LIGHTTPD_GET_USER();
    $LIGHTTPD_CONF_PATH = LIGHTTPD_CONF_PATH();
    if (preg_match("#^(.+?):(.+)#", $LIGHTTPD_GET_USER, $re)) {
        $LIGHTTPD_USER = $re[1];
        $LIGHTTPD_GROUP = $re[1];
    }
    $PHP_FCGI_CHILDREN = 1;
    $max_procs = 2;
    @mkdir("/var/log/lighttpd", 0755, true);
    @mkdir("/usr/share/artica-postfix/ressources/logs", 0755, true);
    if (!is_file("/var/log/lighttpd/access.log")) {
        @touch("/var/log/lighttpd/access.log");
    }
    @chown("/var/log/lighttpd", $LIGHTTPD_USER);
    @chgrp("/var/log/lighttpd", $LIGHTTPD_GROUP);
    @chown("/var/log/lighttpd/access.log", $LIGHTTPD_USER);
    @chgrp("/var/log/lighttpd/access.log", $LIGHTTPD_GROUP);
    @chmod("/var/log/lighttpd/access.log", 0777);
    $unix->chown_func($LIGHTTPD_USER, $LIGHTTPD_GROUP, "/var/log/lighttpd/*");
    $unix->chown_func($LIGHTTPD_USER, $LIGHTTPD_GROUP, "/usr/share/artica-postfix/ressources/logs/*");
    if ($LighttpdArticaMaxProcs > 0) {
        $max_procs = $LighttpdArticaMaxProcs;
    }
    if ($LighttpdArticaMaxChildren > 0) {
        $HP_FCGI_CHILDREN = $LighttpdArticaMaxChildren;
    }
    if ($LighttpdRunAsminimal == 1) {
        $max_procs = 2;
        $PHP_FCGI_CHILDREN = 2;
    }
    $mod_auth = isModule('mod_auth');
    if (is_file('/proc/user_beancounters')) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} VPS mode enabled, swith to socket mode for PHP\n";
        }
        $LighttpdUseUnixSocket = 1;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} MAX Procs............: {$max_procs}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Php5 processes.......: {$PHP_FCGI_CHILDREN}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Max cnx/processes....: {$PHP_FCGI_MAX_REQUESTS}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} php-cgi path.........: {$phpcgi_path}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} chown path...........: {$chown}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} php path.............: {$php}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} php FPM Path.........: {$phpfpm}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} php FPM Enabled......: {$EnableArticaApachePHPFPM}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Perl Path............: {$perlbin}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Conf Path............: {$LIGHTTPD_CONF_PATH}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Pid Path.............: /var/run/lighttpd/lighttpd.pid\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} SSL enabled..........: {$ArticaHttpUseSSL}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Disable SSLv2........: {$LighttpdArticaDisableSSLv2}\n";
    }
    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"]} Run as...............: {$LIGHTTPD_USER} / {$LIGHTTPD_GROUP}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} No LDAP in Lighttpd..: {$NoLDAPInLighttpdd}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Mod auth installed...: {$mod_auth}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Use Unix socket......: {$LighttpdUseUnixSocket}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Sessions in Memory...: {$SessionPathInMemory}MB\n";
    }
    $MakeDirs[] = "/opt/artica/ssl/certs";
    $MakeDirs[] = "/var/lib/php/session";
    $MakeDirs[] = "/var/lighttpd/upload";
    $MakeDirs[] = "/var/run/lighttpd";
    $MakeDirs[] = "/var/log/lighttpd";
    $MakeDirs[] = "/opt/artica/share/www/jpegPhoto";
    $MakeDirs[] = dirname($LIGHTTPD_CONF_PATH);
    while (list($pid, $dir) = each($MakeDirs)) {
        if (!is_dir($dir)) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} creating {$dir}\n";
            }
        }
        @mkdir($dir, 0755, true);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} permissions on {$dir}\n";
        }
        shell_exec("{$chown} {$LIGHTTPD_GET_USER} {$dir}");
    }
    $f[] = '#artica-postfix saved by artica lighttpd.conf (Artica Install binary) v3.0';
    $f[] = '';
    $f[] = 'server.modules = (';
    $f[] = '        "mod_alias",';
    $f[] = '        "mod_access",';
    $f[] = '        "mod_accesslog",';
    $f[] = '        "mod_compress",';
    $f[] = '        "mod_fastcgi",';
    $f[] = '        "mod_cgi",';
    $f[] = '	       "mod_status",';
    if ($NoLDAPInLighttpdd == 1) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} LDAP Mode is disabled\n";
        }
    }
    if ($mod_auth) {
        $f[] = '	       "mod_auth"';
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} mod_auth module does not exists (should be a security issue !!!)\n";
        }
    }
    $f[] = ')';
    $f[] = '';
    $f[] = 'server.document-root        = "/usr/share/artica-postfix"';
    $f[] = 'server.username = "******"';
    $f[] = 'server.groupname = "' . $LIGHTTPD_GROUP . '"';
    $f[] = 'server.errorlog-use-syslog = "enable"';
    //$f[]='server.errorlog             = "/var/log/lighttpd/error.log"';
    $f[] = 'index-file.names            = ( "index.php","index.cgi")';
    $f[] = '';
    $f[] = 'mimetype.assign             = (';
    $f[] = '  ".pdf"          =>      "application/pdf",';
    $f[] = '  ".sig"          =>      "application/pgp-signature",';
    $f[] = '  ".spl"          =>      "application/futuresplash",';
    $f[] = '  ".class"        =>      "application/octet-stream",';
    $f[] = '  ".ps"           =>      "application/postscript",';
    $f[] = '  ".torrent"      =>      "application/x-bittorrent",';
    $f[] = '  ".dvi"          =>      "application/x-dvi",';
    $f[] = '  ".gz"           =>      "application/x-gzip",';
    $f[] = '  ".pac"          =>      "application/x-ns-proxy-autoconfig",';
    $f[] = '  ".swf"          =>      "application/x-shockwave-flash",';
    $f[] = '  ".tar.gz"       =>      "application/x-tgz",';
    $f[] = '  ".tgz"          =>      "application/x-tgz",';
    $f[] = '  ".tar"          =>      "application/x-tar",';
    $f[] = '  ".zip"          =>      "application/zip",';
    $f[] = '  ".mp3"          =>      "audio/mpeg",';
    $f[] = '  ".m3u"          =>      "audio/x-mpegurl",';
    $f[] = '  ".wma"          =>      "audio/x-ms-wma",';
    $f[] = '  ".wax"          =>      "audio/x-ms-wax",';
    $f[] = '  ".ogg"          =>      "application/ogg",';
    $f[] = '  ".wav"          =>      "audio/x-wav",';
    $f[] = '  ".gif"          =>      "image/gif",';
    $f[] = '  ".jar"          =>      "application/x-java-archive",';
    $f[] = '  ".jpg"          =>      "image/jpeg",';
    $f[] = '  ".jpeg"         =>      "image/jpeg",';
    $f[] = '  ".png"          =>      "image/png",';
    $f[] = '  ".xbm"          =>      "image/x-xbitmap",';
    $f[] = '  ".xpm"          =>      "image/x-xpixmap",';
    $f[] = '  ".xwd"          =>      "image/x-xwindowdump",';
    $f[] = '  ".css"          =>      "text/css",';
    $f[] = '  ".html"         =>      "text/html",';
    $f[] = '  ".htm"          =>      "text/html",';
    $f[] = '  ".js"           =>      "text/javascript",';
    $f[] = '  ".asc"          =>      "text/plain",';
    $f[] = '  ".c"            =>      "text/plain",';
    $f[] = '  ".cpp"          =>      "text/plain",';
    $f[] = '  ".log"          =>      "text/plain",';
    $f[] = '  ".conf"         =>      "text/plain",';
    $f[] = '  ".text"         =>      "text/plain",';
    $f[] = '  ".txt"          =>      "text/plain",';
    $f[] = '  ".dtd"          =>      "text/xml",';
    $f[] = '  ".xml"          =>      "text/xml",';
    $f[] = '  ".mpeg"         =>      "video/mpeg",';
    $f[] = '  ".mpg"          =>      "video/mpeg",';
    $f[] = '  ".mov"          =>      "video/quicktime",';
    $f[] = '  ".qt"           =>      "video/quicktime",';
    $f[] = '  ".avi"          =>      "video/x-msvideo",';
    $f[] = '  ".asf"          =>      "video/x-ms-asf",';
    $f[] = '  ".asx"          =>      "video/x-ms-asf",';
    $f[] = '  ".wmv"          =>      "video/x-ms-wmv",';
    $f[] = '  ".bz2"          =>      "application/x-bzip",';
    $f[] = '  ".tbz"          =>      "application/x-bzip-compressed-tar",';
    $f[] = '  ".tar.bz2"      =>      "application/x-bzip-compressed-tar",';
    $f[] = '  ""              =>      "application/octet-stream",';
    $f[] = ' )';
    $f[] = '';
    $f[] = '';
    $f[] = 'accesslog.filename          = "/var/log/lighttpd/access.log"';
    $f[] = 'url.access-deny             = ( "~", ".inc",".log",".ini" )';
    $f[] = '';
    $f[] = 'static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )';
    $f[] = 'server.port                 = ' . $ArticaHttpsPort;
    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 (strlen($LighttpdArticaListenIP) > 3) {
        $f[] = 'server.bind                = "' . $LighttpdArticaListenIP . '"';
    }
    $f[] = 'server.pid-file             = "/var/run/lighttpd/lighttpd.pid"';
    $f[] = 'server.max-fds 		   = 2048';
    $f[] = 'server.max-connections      = 512';
    $f[] = 'server.network-backend      = "write"';
    shell_exec("{$php} /usr/share/artica-postfix/exec.lighttpd.nets.php");
    shell_exec("{$php} /usr/share/artica-postfix/exec.lighttpd.nets.php --phpmyadmin");
    if (is_file('/etc/artica-postfix/lighttpd_nets')) {
        $f[] = @file_get_contents("/etc/artica-postfix/lighttpd_nets");
    }
    $f[] = '';
    if (is_file($phpfpm)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} PHP-FPM is installed\n";
        }
        if ($EnablePHPFPM == 1) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} PHP-FPM is enabled\n";
            }
            $PHP_STANDARD_MODE = false;
            $f[] = 'fastcgi.server = ( ".php" =>((';
            $f[] = '         "socket" => "/var/run/php-fpm.sock",';
        }
    }
    if ($PHP_STANDARD_MODE) {
        $f[] = 'fastcgi.server = ( ".php" =>((';
        $f[] = '         "bin-path" => "/usr/bin/php-cgi",';
        if ($LighttpdUseUnixSocket == 1) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Fast-cgi server unix socket mode\n";
            }
            $f[] = '         "socket" => "/var/run/lighttpd/php.socket" + var.PID,';
        } else {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Fast-cgi server socket 127.0.0.1:{$lighttpdPhpPort}\n";
            }
            $f[] = '         "host" => "127.0.0.1","port" =>' . $lighttpdPhpPort . ',';
        }
    }
    $f[] = '         "min-procs" => 1,';
    $f[] = '         "max-procs" => 1,';
    $f[] = '         "idle-timeout" => 10,';
    $f[] = '         "bin-environment" => (';
    $f[] = '             "PHP_FCGI_CHILDREN" => "' . $PHP_FCGI_CHILDREN . '",';
    $f[] = '             "PHP_FCGI_MAX_REQUESTS" => "' . $PHP_FCGI_MAX_REQUESTS . '"';
    $f[] = '          ),';
    $f[] = '          "bin-copy-environment" => (';
    $f[] = '            "PATH", "SHELL", "USER"';
    $f[] = '           ),';
    $f[] = '          "broken-scriptfilename" => "enable"';
    $f[] = '        ))';
    $f[] = ')';
    if ($ArticaHttpUseSSL == 1) {
        $f[] = 'ssl.engine                 = "enable"';
        $f[] = 'ssl.pemfile                = "/opt/artica/ssl/certs/lighttpd.pem"';
    }
    if ($LighttpdArticaDisableSSLv2 == 1) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Disable SSLv2 and weak ssl cipher\n";
        }
        $f[] = 'ssl.use-sslv2              = "disable"';
        $f[] = 'ssl.cipher-list            = "TLSv1+HIGH !SSLv2 RC4+MEDIUM !aNULL !eNULL !3DES @STRENGTH"';
    } else {
        $f[] = 'ssl.use-sslv2              = "enable"';
        $f[] = 'ssl.cipher-list            = "TLSv1+HIGH RC4+MEDIUM !SSLv2 !3DES !aNULL @STRENGTH"';
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} No LDAP In lighttpd: {$NoLDAPInLighttpdd}\n";
    }
    if ($NoLDAPInLighttpdd == 0) {
        if ($mod_auth) {
            $f[] = 'status.status-url          = "/server-status"';
            $f[] = 'status.config-url          = "/server-config"';
        }
    }
    $f[] = 'server.upload-dirs         = ( "/var/lighttpd/upload" )';
    $f[] = '	server.follow-symlink = "enable"';
    $f[] = 'alias.url +=("/monitorix"  => "/var/www/monitorix/")';
    $f[] = 'alias.url += ("/blocked_attachments"=> "/var/spool/artica-filter/bightml")';
    $f[] = 'alias.url += ("/squid-rrd"=> "/opt/artica/share/www/squid/rrd")';
    $f[] = 'alias.url += ("/artica-agent"=> "/usr/share/artica-postfix/ressources/artica-agent")';
    if ($DenyMiniWebFromStandardPort == 1) {
        $f[] = '$HTTP["url"] =~ "^/miniadm.*|/computers|/user-backup" { url.access-deny = ( "" )}';
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} checking AWSTATS...\n";
    }
    $AWSTATS_www_root = AWSTATS_www_root();
    $f[] = '$HTTP["url"] =~ "^/prxy.*\\.php" { url.access-deny = ( "" )}';
    if (is_dir($AWSTATS_www_root)) {
        $f[] = 'alias.url += ( "/awstats" => "' . $AWSTATS_www_root . '" )';
    }
    if (is_file('/usr/share/poweradmin/index.php')) {
        $f[] = 'alias.url += ( "/powerdns" => "/usr/share/poweradmin" )';
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Checking PowerAdmin\n";
        }
        shell_exec("{$nohup} {$php} /usr/share/artica-postfix/exec.pdns.php --poweradmin >/dev/null 2>&1 &");
    }
    //$perlbin
    $f[] = 'alias.url += ( "/cgi-bin/" => "/usr/lib/cgi-bin/" )';
    $f[] = '';
    $f[] = 'cgi.assign= (';
    $f[] = '	".pl"  => "' . $perlbin . '",';
    $f[] = '	".php" => "/usr/bin/php-cgi",';
    $f[] = '	".py"  => "/usr/bin/python",';
    $f[] = '	".cgi"  => "' . $perlbin . '",';
    if (is_file("/usr/lib/mailman/bin/mailmanctl")) {
        $f[] = '"/admin" => "",';
        $f[] = '"/admindb" => "",';
        $f[] = '"/confirm" => "",';
        $f[] = '"/create" => "",';
        $f[] = '"/edithtml" => "",';
        $f[] = '"/listinfo" => "",';
        $f[] = '"/options" => "",';
        $f[] = '"/private" => "",';
        $f[] = '"/rmlist" => "",';
        $f[] = '"/roster" => "",';
        $f[] = '"/subscribe" => ""';
    }
    $f[] = ')';
    $f[] = '';
    if ($mod_auth) {
        $f[] = 'auth.debug = 2';
        $f[] = '$HTTP["url"] =~ "^/cgi-bin/" {';
        $f[] = 'auth.backend = "plain"';
        $f[] = 'auth.backend.plain.userfile = "/etc/lighttpd/.lighttpdpassword" ';
        $f[] = 'auth.require = ("/cgi-bin/" => (';
        $f[] = '     "method"  => "basic",';
        $f[] = '     "realm"   => "awstats Statistics",';
        $f[] = '     "require" => "valid-user"';
        $f[] = '  ))';
        $f[] = '}';
        $f[] = '';
        $f[] = '$HTTP["url"] =~ "^/server-status" {';
        $f[] = 'auth.backend = "plain"';
        $f[] = 'auth.backend.plain.userfile = "/etc/lighttpd/.lighttpdpassword" ';
        $f[] = 'auth.require = ("/server-status" => (';
        $f[] = '     "method"  => "basic",';
        $f[] = '     "realm"   => "Lighttpd config - status",';
        $f[] = '     "require" => "valid-user"';
        $f[] = '  ))';
        $f[] = '}';
        $f[] = '';
        $f[] = '$HTTP["url"] =~ "^/server-config" {';
        $f[] = 'auth.backend = "plain"';
        $f[] = 'auth.backend.plain.userfile = "/etc/lighttpd/.lighttpdpassword" ';
        $f[] = 'auth.require = ("/server-config" => (';
        $f[] = '     "method"  => "basic",';
        $f[] = '     "realm"   => "Lighttpd config - status",';
        $f[] = '     "require" => "valid-user"';
        $f[] = '  ))';
        $f[] = '}';
        $f[] = '';
        $f[] = '$HTTP["url"] =~ "^/squid/" {';
        $f[] = 'auth.backend = "plain"';
        $f[] = 'auth.debug = 2';
        $f[] = 'auth.backend.plain.userfile = "/etc/lighttpd/squid-users.passwd" ';
        $f[] = 'auth.require = ("/squid/" => (';
        $f[] = '     "method"  => "basic",';
        $f[] = '     "realm"   => "Squid Statistics",';
        $f[] = '     "require" => "valid-user"';
        $f[] = '  ))';
        $f[] = '}';
        $f[] = '';
        $f[] = '$HTTP["url"] =~ "^/cluebringer/" {';
        $f[] = 'auth.backend = "plain"';
        $f[] = 'auth.debug = 2';
        $f[] = 'auth.backend.plain.userfile = "/etc/lighttpd/cluebringer.passwd" ';
        $f[] = 'auth.require = ("/cluebringer/" => (';
        $f[] = '     "method"  => "basic",';
        $f[] = '     "realm"   => "ClueBringer (Policyd V2) administration",';
        $f[] = '     "require" => "valid-user"';
        $f[] = '  ))';
        $f[] = '}';
        $f[] = '';
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} writing {$LIGHTTPD_CONF_PATH}..\n";
    }
    @file_put_contents($LIGHTTPD_CONF_PATH, @implode("\n", $f));
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} {$LIGHTTPD_CONF_PATH} done\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Check sessions...\n";
    }
    shell_exec("{$nohup} {$php} /usr/share/artica-postfix/exec.shm.php --SessionMem >/dev/null 2>&1 &");
    shell_exec("{$nohup} {$php} /usr/share/artica-postfix/exec.shm.php --service-up >/dev/null 2>&1 &");
}
Пример #7
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";
    }
}
Пример #8
0
function php5_fpm()
{
    $unix = new unix();
    $daemon_path = $unix->APACHE_LOCATE_PHP_FPM();
    if (!is_file($daemon_path)) {
        return;
    }
    $f[] = "# PHP-FPM configuration";
    $f[] = "<IfModule mod_fastcgi.c>";
    $f[] = "  Alias /php5.fastcgi /var/lib/apache2/fastcgi/php5.fastcgi";
    $f[] = "  AddHandler php-script .php";
    $f[] = "  FastCGIExternalServer /var/lib/apache2/fastcgi/php5.fastcgi -socket /var/run/php-fpm-apache2.sock -idle-timeout 610";
    $f[] = "  Action php-script /php5.fastcgi virtual";
    $f[] = "";
    $f[] = "  # Forbid access to the fastcgi handler.";
    $f[] = "  <Directory /var/lib/apache2/fastcgi>";
    $f[] = "    <Files php5.fastcgi>";
    $f[] = "      Order deny,allow";
    $f[] = "      Allow from all";
    $f[] = "    </Files>";
    $f[] = "  </Directory>";
    $f[] = "";
    $f[] = "  # FPM status page.";
    $f[] = "  <Location /php-fpm-status>";
    $f[] = "    SetHandler php-script";
    $f[] = "    Order deny,allow";
    $f[] = "    Deny from all";
    $f[] = "    Allow from 127.0.0.1 ::1";
    $f[] = "  </Location>";
    $f[] = "";
    $f[] = "  # FPM ping page.";
    $f[] = "  <Location /php-fpm-ping>";
    $f[] = "    SetHandler php-script";
    $f[] = "    Order deny,allow";
    $f[] = "    Deny from all";
    $f[] = "    Allow from 127.0.0.1 ::1";
    $f[] = "  </Location>";
    $f[] = "</IfModule>";
    @file_put_contents("/etc/apache2/mods-available/php5-fpm.conf", @implode("\n", $f));
}
Пример #9
0
function apache_config()
{
    $sock = new sockets();
    $unix = new unix();
    $EnablePHPFPM = 0;
    @mkdir("/var/run/apache2", 0755, true);
    @mkdir("/var/run/artica-roundcube", 0755, true);
    @mkdir("/var/run/roundcube-apache", 0755, true);
    @mkdir("/var/log/apache2", 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/apache2/roundcube-error.log");
    @touch("/var/log/apache2/roundcube-error.log");
    @chmod("/var/log/apache2/roundcube-error.log", 0755);
    $unix->chown_func($APACHE_SRC_ACCOUNT, $APACHE_SRC_GROUP, "/var/log/apache2/*");
    $unix->chown_func($APACHE_SRC_ACCOUNT, $APACHE_SRC_GROUP, "/usr/share/artica-postfix/ressources/logs/*");
    $RoundCubeHTTPPort = 8888;
    $RoundCubeHTTPSPort = 449;
    $NoLDAPInLighttpdd = 0;
    $RoundCubeHTTPSPort = intval($sock->GET_INFO("RoundCubeHTTPSPort"));
    $RoundCubeHTTPPort = intval($sock->GET_INFO("RoundCubeHTTPPort"));
    $RoundCubeUseSSL = intval($sock->GET_INFO("RoundCubeUseSSL"));
    $RoundCubeUploadMaxFilesize = intval($sock->GET_INFO("RoundCubeUploadMaxFilesize"));
    if ($RoundCubeUploadMaxFilesize == 0) {
        $RoundCubeUploadMaxFilesize = 128;
    }
    if ($RoundCubeHTTPSPort == 0) {
        $RoundCubeHTTPSPort = 449;
    }
    if ($RoundCubeHTTPPort == 0) {
        $RoundCubeHTTPPort = 8888;
    }
    $RoundCubeListenIP = $sock->GET_INFO("RoundCubeListenIP");
    $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-roundcube");
    $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";
    }
    $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[] = "<Directory \"/usr/share/roundcube\">";
    $f[] = "\tOptions Indexes FollowSymLinks";
    $f[] = "\tphp_value open_basedir \"/usr/share/roundcube\"";
    $f[] = "\tphp_admin_value upload_tmp_dir \"/usr/share/roundcube/uploads\"";
    $f[] = "\tphp_flag register_globals off";
    $f[] = "\tphp_flag magic_quotes_gpc off";
    $f[] = "\tphp_flag magic_quotes_runtime off";
    $f[] = "\tphp_value post_max_size {$RoundCubeUploadMaxFilesize}M";
    $f[] = "\tphp_value upload_max_filesize {$RoundCubeUploadMaxFilesize}M";
    $f[] = "\tphp_flag short_open_tag on";
    $f[] = "\tphp_flag safe_mode off";
    $f[] = "\tDirectoryIndex index.php";
    $f[] = "\tSSLOptions +StdEnvVars";
    $f[] = "\tOptions Indexes FollowSymLinks";
    $f[] = "\tAllowOverride None";
    $f[] = "</Directory>";
    $MyDirectory = @implode("\n", $f);
    $f = array();
    //$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: {$RoundCubeHTTPSPort}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Listen IP: {$RoundCubeListenIP}\n";
    }
    if ($RoundCubeListenIP != null) {
        $unix = new unix();
        $IPS = $unix->NETWORK_ALL_INTERFACES(true);
        if (!isset($IPS[$RoundCubeListenIP])) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} ERROR! Listen IP: {$RoundCubeListenIP} -> FALSE !!\n";
            }
            $RoundCubeListenIP = null;
        }
    }
    if ($RoundCubeListenIP == null) {
        $RoundCubeListenIP = "*";
    }
    if ($RoundCubeListenIP != null) {
        $RoundCubeHTTPSPort = "{$RoundCubeListenIP}:{$RoundCubeHTTPSPort}";
    }
    $f[] = "";
    $f[] = "LockFile /var/run/apache2/artica-accept.lock";
    $f[] = "PidFile /var/run/roundcube-apache/apache.pid";
    $f[] = "DocumentRoot /usr/share/roundcube";
    $f[] = "Listen {$RoundCubeListenIP}:{$RoundCubeHTTPPort}";
    $f[] = "NameVirtualHost {$RoundCubeListenIP}:{$RoundCubeHTTPPort}";
    if ($RoundCubeUseSSL == 1) {
        $f[] = "Listen {$RoundCubeHTTPSPort}";
        $f[] = "NameVirtualHost {$RoundCubeHTTPSPort}";
    }
    $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[] = "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}";
    $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>";
    $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[] = "<VirtualHost {$RoundCubeListenIP}:{$RoundCubeHTTPPort}>";
    $f[] = "ServerAdmin webmaster@none.tld";
    $f[] = "DocumentRoot /usr/share/roundcube";
    $f[] = "{$MyDirectory}";
    $f[] = "</VirtualHost>";
    if ($RoundCubeUseSSL == 1) {
        $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[] = "\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[] = "<VirtualHost {$RoundCubeHTTPSPort}>";
        $f[] = "ServerAdmin webmaster@none.tld";
        $f[] = "DocumentRoot /usr/share/roundcube";
        $f[] = "{$MyDirectory}";
        $mknod = $unix->find_program("mknod");
        shell_exec("{$mknod} /dev/random c 1 9 >/dev/null 2>&1");
        $f[] = "SSLEngine on";
        $f[] = "</VirtualHost>";
        $f[] = "";
    }
    if (!is_file("/etc/ssl/certs/apache/server.crt")) {
        shell_exec("/usr/share/artica-postfix/bin/artica-install --apache-ssl-cert");
    }
    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-roundcube/php5.fastcgi";
        $f[] = "\tAddHandler php-script .php";
        $f[] = "\tFastCGIExternalServer /var/run/artica-roundcube/php5.fastcgi -socket /var/run/php-fpm.sock -idle-timeout 610";
        $f[] = "\tAction php-script /php5.fastcgi virtual";
        $f[] = "\t<Directory /var/run/artica-roundcube>";
        $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/apache2/roundcube-error.log";
    $f[] = "LogFormat \"%h %l %u %t \\\"%r\\\" %<s %b\" common";
    $f[] = "CustomLog /var/log/apache2/roundcube-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[] = "\n\n";
    @file_put_contents("/etc/artica-postfix/apache-roundcube.conf", @implode("\n", $f));
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} /etc/artica-postfix/apache-roundcube.conf done\n";
    }
    $apachename = $unix->APACHE_SRC_ACCOUNT();
    $apachegroup = $unix->APACHE_SRC_GROUP();
    @mkdir("/usr/share/roundcube/uploads", 0755, true);
    $dirs = $unix->dirdir("/usr/share/roundcube");
    while (list($dirname, $lib) = each($dirs)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Privileges on {$dirname}\n";
        }
        $unix->chown_func($APACHE_SRC_ACCOUNT, $APACHE_SRC_GROUP, $dirname);
        $unix->chmod_func(0755, $dirname);
    }
}
Пример #10
0
function buildConfig()
{
    $unix = new unix();
    $sock = new sockets();
    $phpcgi = $unix->LIGHTTPD_PHP5_CGI_BIN_PATH();
    @mkdir("/usr/share/artica-postfix/framework", 0755, true);
    @mkdir("/usr/share/artica-postfix/ressources/sock", 0755, true);
    @mkdir("/usr/share/artica-postfix/ressources/web", 0755, true);
    @mkdir("/var/run/artica-framework", 0755, true);
    $LighttpdRunAsminimal = $sock->GET_INFO("LighttpdRunAsminimal");
    $LighttpdArticaMaxProcs = $sock->GET_INFO("LighttpdArticaMaxProcs");
    $LighttpdArticaMaxChildren = $sock->GET_INFO("LighttpdArticaMaxChildren");
    $PHP_FCGI_MAX_REQUESTS = $sock->GET_INFO("PHP_FCGI_MAX_REQUESTS");
    $EnablePHPFPMFrameWork = $sock->GET_INFO("EnablePHPFPMFrameWork");
    if (!is_numeric($EnablePHPFPMFrameWork)) {
        $EnablePHPFPMFrameWork = 0;
    }
    if (!is_numeric($LighttpdRunAsminimal)) {
        $LighttpdRunAsminimal = 0;
    }
    if (!is_numeric($LighttpdArticaMaxProcs)) {
        $LighttpdArticaMaxProcs = 0;
    }
    if (!is_numeric($LighttpdArticaMaxChildren)) {
        $LighttpdArticaMaxChildren = 0;
    }
    if (!is_numeric($PHP_FCGI_MAX_REQUESTS)) {
        $PHP_FCGI_MAX_REQUESTS = 200;
    }
    $PHP_FCGI_CHILDREN = 1;
    $max_procs = 5;
    if ($LighttpdArticaMaxProcs > 0) {
        $max_procs = $LighttpdArticaMaxProcs;
    }
    if ($LighttpdArticaMaxChildren > 0) {
        $PHP_FCGI_CHILDREN = $LighttpdArticaMaxChildren;
    }
    if (!$unix->ISMemoryHiger1G()) {
        $PHP_FCGI_CHILDREN = 2;
        $max_procs = 2;
        $PHP_FCGI_MAX_REQUESTS = 200;
    }
    $MEMORY = $unix->MEM_TOTAL_INSTALLEE();
    if ($MEMORY < 624288) {
        $LighttpdRunAsminimal = 1;
    }
    if ($LighttpdRunAsminimal == 1) {
        $max_procs = 2;
        $PHP_FCGI_CHILDREN = 1;
        $PHP_FCGI_MAX_REQUESTS = 500;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: MAX Procs............: {$max_procs}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: Php5 processes.......: {$PHP_FCGI_CHILDREN}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: Max cnx/processes....: {$PHP_FCGI_MAX_REQUESTS}\n";
    }
    $phpfpm = $unix->APACHE_LOCATE_PHP_FPM();
    $EnablePHPFPM = $sock->GET_INFO("EnablePHPFPM");
    if (!is_numeric($EnablePHPFPM)) {
        $EnablePHPFPM = 0;
    }
    if (!is_file($phpfpm)) {
        $EnablePHPFPM = 0;
    }
    $PHP_FPM_Params = PHP_FPM_Params();
    if (!isset($ParseParams["allow-to-run-as-root"])) {
        $EnablePHPFPMFrameWork = 0;
    }
    if ($EnablePHPFPMFrameWork == 0) {
        $EnablePHPFPM = 0;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: php-fpm..............: {$phpfpm}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: EnablePHPFPMFrameWork: {$EnablePHPFPMFrameWork}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: EnablePHPFPM.........: {$EnablePHPFPM}\n";
    }
    if ($EnablePHPFPM == 1) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Using PHP-FPM........: Yes\n";
        }
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Using PHP-FPM........: No\n";
        }
    }
    $phpcgi_path = $unix->LIGHTTPD_PHP5_CGI_BIN_PATH();
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: php-cgi path.........: {$phpcgi_path}\n";
    }
    $f[] = "#artica-postfix saved by artica lighttpd.conf";
    $f[] = "";
    $f[] = "server.modules = (";
    $f[] = "        \"mod_alias\",";
    $f[] = "        \"mod_access\",";
    $f[] = "        \"mod_accesslog\",";
    $f[] = "        \"mod_compress\",";
    $f[] = "        \"mod_fastcgi\",";
    $f[] = "        \"mod_cgi\",";
    $f[] = "\t       \"mod_status\"";
    $f[] = ")";
    $f[] = "";
    $f[] = "server.document-root        = \"/usr/share/artica-postfix/framework\"";
    $f[] = "server.errorlog             = \"/var/log/artica-postfix/framework_error.log\"";
    $f[] = "index-file.names            = ( \"index.php\")";
    $f[] = "";
    $f[] = "mimetype.assign             = (";
    $f[] = "  \".pdf\"          =>      \"application/pdf\",";
    $f[] = "  \".sig\"          =>      \"application/pgp-signature\",";
    $f[] = "  \".spl\"          =>      \"application/futuresplash\",";
    $f[] = "  \".class\"        =>      \"application/octet-stream\",";
    $f[] = "  \".ps\"           =>      \"application/postscript\",";
    $f[] = "  \".torrent\"      =>      \"application/x-bittorrent\",";
    $f[] = "  \".dvi\"          =>      \"application/x-dvi\",";
    $f[] = "  \".gz\"           =>      \"application/x-gzip\",";
    $f[] = "  \".pac\"          =>      \"application/x-ns-proxy-autoconfig\",";
    $f[] = "  \".swf\"          =>      \"application/x-shockwave-flash\",";
    $f[] = "  \".tar.gz\"       =>      \"application/x-tgz\",";
    $f[] = "  \".tgz\"          =>      \"application/x-tgz\",";
    $f[] = "  \".tar\"          =>      \"application/x-tar\",";
    $f[] = "  \".zip\"          =>      \"application/zip\",";
    $f[] = "  \".mp3\"          =>      \"audio/mpeg\",";
    $f[] = "  \".m3u\"          =>      \"audio/x-mpegurl\",";
    $f[] = "  \".wma\"          =>      \"audio/x-ms-wma\",";
    $f[] = "  \".wax\"          =>      \"audio/x-ms-wax\",";
    $f[] = "  \".ogg\"          =>      \"application/ogg\",";
    $f[] = "  \".wav\"          =>      \"audio/x-wav\",";
    $f[] = "  \".gif\"          =>      \"image/gif\",";
    $f[] = "  \".jar\"          =>      \"application/x-java-archive\",";
    $f[] = "  \".jpg\"          =>      \"image/jpeg\",";
    $f[] = "  \".jpeg\"         =>      \"image/jpeg\",";
    $f[] = "  \".png\"          =>      \"image/png\",";
    $f[] = "  \".xbm\"          =>      \"image/x-xbitmap\",";
    $f[] = "  \".xpm\"          =>      \"image/x-xpixmap\",";
    $f[] = "  \".xwd\"          =>      \"image/x-xwindowdump\",";
    $f[] = "  \".css\"          =>      \"text/css\",";
    $f[] = "  \".html\"         =>      \"text/html\",";
    $f[] = "  \".htm\"          =>      \"text/html\",";
    $f[] = "  \".js\"           =>      \"text/javascript\",";
    $f[] = "  \".asc\"          =>      \"text/plain\",";
    $f[] = "  \".c\"            =>      \"text/plain\",";
    $f[] = "  \".cpp\"          =>      \"text/plain\",";
    $f[] = "  \".log\"          =>      \"text/plain\",";
    $f[] = "  \".conf\"         =>      \"text/plain\",";
    $f[] = "  \".text\"         =>      \"text/plain\",";
    $f[] = "  \".txt\"          =>      \"text/plain\",";
    $f[] = "  \".dtd\"          =>      \"text/xml\",";
    $f[] = "  \".xml\"          =>      \"text/xml\",";
    $f[] = "  \".mpeg\"         =>      \"video/mpeg\",";
    $f[] = "  \".mpg\"          =>      \"video/mpeg\",";
    $f[] = "  \".mov\"          =>      \"video/quicktime\",";
    $f[] = "  \".qt\"           =>      \"video/quicktime\",";
    $f[] = "  \".avi\"          =>      \"video/x-msvideo\",";
    $f[] = "  \".asf\"          =>      \"video/x-ms-asf\",";
    $f[] = "  \".asx\"          =>      \"video/x-ms-asf\",";
    $f[] = "  \".wmv\"          =>      \"video/x-ms-wmv\",";
    $f[] = "  \".bz2\"          =>      \"application/x-bzip\",";
    $f[] = "  \".tbz\"          =>      \"application/x-bzip-compressed-tar\",";
    $f[] = "  \".tar.bz2\"      =>      \"application/x-bzip-compressed-tar\",";
    $f[] = "  \"\"              =>      \"application/octet-stream\",";
    $f[] = " )";
    $f[] = "";
    $f[] = "";
    $f[] = "accesslog.filename          = \"/var/log/artica-postfix/framework.log\"";
    $f[] = "url.access-deny             = ( \"~\", \".inc\" )";
    $f[] = "";
    $f[] = "static-file.exclude-extensions = ( \".php\", \".pl\", \".fcgi\" )";
    $f[] = "#server.port                 = 47980";
    $f[] = "server.bind                = \"/usr/share/artica-postfix/ressources/web/framework.sock\"";
    $f[] = "#server.error-handler-404   = \"/error-handler.html\"";
    $f[] = "#server.error-handler-404   = \"/error-handler.php\"";
    $f[] = "server.pid-file             = \"/var/run/lighttpd/framework.pid\"";
    $f[] = "server.max-keep-alive-requests = 0";
    $f[] = "server.max-keep-alive-idle = 4";
    $f[] = "server.stat-cache-engine = \"simple\"";
    $f[] = "server.max-fds \t\t   = 2048";
    $f[] = "server.network-backend      = \"writev\"";
    $f[] = "";
    if ($EnablePHPFPM == 0) {
        $f[] = "fastcgi.server = ( \".php\" =>((";
        $f[] = "                \"bin-path\" => \"{$phpcgi_path}\",";
        $f[] = "                \"socket\" => \"/var/run/artica-framework/fastcgi-\" + PID + \".sock\",";
    } else {
        $f[] = "fastcgi.server = ( \".php\" =>((";
        $f[] = "                \"socket\" => \"/var/run/php-fpm-framework.sock\",";
    }
    $f[] = "                \"max-procs\" => {$max_procs},";
    $f[] = "                \"idle-timeout\" => 20,";
    $f[] = "                \"bin-environment\" => (";
    $f[] = "                        \"PHP_FCGI_CHILDREN\" => \"{$PHP_FCGI_CHILDREN}\",";
    $f[] = "                        \"HOME\" => \"/home\",";
    $f[] = "                        \"PHP_FCGI_MAX_REQUESTS\" => \"{$PHP_FCGI_MAX_REQUESTS}\",";
    $f[] = "                        \"PATH\" => \"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin:/usr/kerberos/bin\",";
    $f[] = "                        \"LD_LIBRARY_PATH\" => \"/lib:/usr/local/lib:/usr/lib/libmilter:/usr/lib\",";
    $f[] = "                        \"CPPFLAGS\" => \"-I/usr/include/libmilter -I/usr/include -I/usr/local/include -I/usr/include/linux -I/usr/include/sm/os\",";
    $f[] = "                        \"LDFLAGS\" => \"-L/lib -L/usr/local/lib -L/usr/lib/libmilter -L/usr/lib\",";
    $f[] = "                ),";
    $f[] = "                \"broken-scriptfilename\" => \"enable\"";
    $f[] = "        ))";
    $f[] = ")";
    $f[] = "ssl.engine                 = \"disable\"";
    $f[] = "status.status-url          = \"/server-status\"";
    $f[] = "status.config-url          = \"/server-config\"";
    $f[] = "\$HTTP[\"url\"] =~ \"^/webmail\" {";
    $f[] = "\tserver.follow-symlink = \"enable\"";
    $f[] = "}";
    $f[] = "alias.url += ( \"/cgi-bin/\" => \"/usr/lib/cgi-bin/\" )";
    $f[] = "alias.url += ( \"/css/\" => \"/usr/share/artica-postfix/css/\" )";
    $f[] = "alias.url += ( \"/img/\" => \"/usr/share/artica-postfix/img/\" )";
    $f[] = "alias.url += ( \"/js/\" => \"/usr/share/artica-postfix/js/\" )";
    $f[] = "";
    $f[] = "cgi.assign= (";
    $f[] = "\t\".pl\"  => \"/usr/bin/perl\",";
    $f[] = "\t\".php\" => \"/usr/bin/php-cgi\",";
    $f[] = "\t\".py\"  => \"/usr/bin/python\",";
    $f[] = "\t\".cgi\"  => \"/usr/bin/perl\",";
    $f[] = ")\n";
    @unlink("/var/log/artica-postfix/framework_error.log");
    @unlink("/var/log/artica-postfix/framework.log");
    @touch("/var/log/artica-postfix/framework_error.log");
    @touch("/var/log/artica-postfix/framework.log");
    @file_put_contents("/etc/artica-postfix/framework.conf", @implode("\n", $f));
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: /etc/artica-postfix/framework.conf done\n";
    }
}
Пример #11
0
function buildConfig($aspid = false)
{
    $unix = new unix();
    if ($aspid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = $unix->get_pid_from_file($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: PHP-FPM: Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $sock = new sockets();
    $phpfpm = $unix->APACHE_LOCATE_PHP_FPM();
    if (!is_file($phpfpm)) {
        return;
    }
    $APACHE_USER = $unix->APACHE_SRC_ACCOUNT();
    $APACHE_GROUP = $unix->APACHE_SRC_GROUP();
    $VERSION = GetVersion();
    $AsRoot = false;
    $tr = explode(".", $VERSION);
    $MAJOR = $tr[0];
    $MINOR = $tr[1];
    $REV = $tr[2];
    $process_priority = false;
    $syslog_facility = true;
    $process_max = true;
    if ($MAJOR > 4) {
        if ($MINOR > 2) {
            if ($REV > 20) {
                $process_priority = true;
            }
        }
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: PHP-FPM: Parse Parameters\n";
    }
    $ParseParams = ParseParams();
    $AsRoot = true;
    if (isset($ParseParams["allow-to-run-as-root"])) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: PHP-FPM: Allow run as root TRUE\n";
        }
        $AsRoot = true;
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: PHP-FPM: Allow run as root is disabled\n";
        }
    }
    $PHPFPMNoSyslog = trim(@file_get_contents("/etc/artica-postfix/settings/Daemons/PHPFPMNoSyslog"));
    $PHPFPMNoProcessMax = trim(@file_get_contents("/etc/artica-postfix/settings/Daemons/PHPFPMNoProcessMax"));
    if (!is_numeric($PHPFPMNoSyslog)) {
        $PHPFPMNoSyslog = 0;
    }
    if (!is_numeric($PHPFPMNoProcessMax)) {
        $PHPFPMNoProcessMax = 0;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: PHP-FPM: PHPFPMNoSyslog:{$PHPFPMNoSyslog}\n";
    }
    if ($PHPFPMNoSyslog == 1) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: PHP-FPM: Disabling process.priority token\n";
        }
        $syslog_facility = false;
    }
    if ($PHPFPMNoProcessMax == 1) {
        $process_max = false;
    }
    $ProcessNice = $unix->GET_PERFS('ProcessNice');
    if (!is_numeric($ProcessNice)) {
        $ProcessNice = 19;
    }
    if ($ProcessNice > 19) {
        $ProcessNice = 19;
    }
    if ($ProcessNice < 1) {
        $ProcessNice = 19;
    }
    $EnableArticaApachePHPFPM = intval($sock->GET_INFO("EnableArticaApachePHPFPM"));
    $EnablePHPFPMFreeWeb = intval($sock->GET_INFO("EnablePHPFPMFreeWeb"));
    $EnablePHPFPMFrameWork = $sock->GET_INFO("EnablePHPFPMFrameWork");
    $EnableFreeWeb = $sock->GET_INFO("EnableFreeWeb");
    if (!is_numeric($EnablePHPFPMFrameWork)) {
        $EnablePHPFPMFrameWork = 0;
    }
    if (!is_numeric($EnableArticaApachePHPFPM)) {
        $EnableArticaApachePHPFPM = 0;
    }
    if (!is_numeric($EnablePHPFPMFreeWeb)) {
        $EnablePHPFPMFreeWeb = 0;
    }
    if (!is_numeric($EnableFreeWeb)) {
        $EnableFreeWeb = 0;
    }
    if ($EnableFreeWeb == 0) {
        $EnablePHPFPMFreeWeb = 0;
    }
    if (is_file("/etc/artica-postfix/WORDPRESS_APPLIANCE")) {
        $EnablePHPFPMFreeWeb = 1;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: PHP-FPM: will run as {$APACHE_USER}:{$APACHE_GROUP}\n";
    }
    $f[] = ";Writing by Artica," . date("Y-m-d H:i:s") . " file will be erased, change the " . __FILE__ . " code instead...";
    @unlink("/etc/php5/fpm/pool.d/www.conf");
    @unlink("/etc/php5/fpm/pool.d/apache2.conf");
    @unlink("/etc/php5/fpm/pool.d/zarafa.conf");
    @unlink("/etc/php5/fpm/pool.d/framework.conf");
    @unlink("/etc/php5/fpm/pool.d/nginx-authenticator.conf");
    if ($EnableArticaApachePHPFPM == 1) {
        $f[] = "[www]";
        $f[] = "user = {$APACHE_USER}";
        $f[] = "group = {$APACHE_GROUP}";
        $f[] = "listen = /var/run/php-fpm.sock";
        $f[] = "listen.mode = 0777";
        $f[] = ";listen.allowed_clients = 127.0.0.1";
        if ($process_priority) {
            $f[] = "process.priority = {$ProcessNice}";
        }
        $f[] = "pm = dynamic";
        //$f[]="log_level = debug";
        $f[] = "pm.max_children = 20";
        $f[] = "pm.start_servers = 2";
        $f[] = "pm.min_spare_servers = 1";
        $f[] = "pm.max_spare_servers = 5";
        $f[] = ";pm.process_idle_timeout = 10s;";
        $f[] = "pm.max_requests = 80";
        $f[] = "pm.status_path = /fpm.status.php";
        $f[] = "ping.path = /fpm.ping";
        $f[] = ";ping.response = pong";
        $f[] = "chdir = /";
        $f[] = "";
        @mkdir("/etc/php5/fpm/pool.d", 0755, true);
        @file_put_contents("/etc/php5/fpm/pool.d/www.conf", @implode("\n", $f));
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: PHP-FPM: /etc/php5/fpm/pool.d/www.conf done\n";
        }
    }
    $f = array();
    if ($EnablePHPFPMFreeWeb == 1) {
        $f[] = "[apache2]";
        $f[] = "user = {$APACHE_USER}";
        $f[] = "group = {$APACHE_GROUP}";
        $f[] = "listen = /var/run/php-fpm-apache2.sock";
        $f[] = "listen.mode = 0777";
        $f[] = ";listen.allowed_clients = 127.0.0.1";
        if ($process_priority) {
            $f[] = "process.priority = {$ProcessNice}";
        }
        $f[] = "pm = dynamic";
        $f[] = "pm.max_children = 50";
        $f[] = "pm.start_servers = 2";
        $f[] = "pm.min_spare_servers = 1";
        $f[] = "pm.max_spare_servers = 5";
        $f[] = ";pm.process_idle_timeout = 10s;";
        $f[] = "pm.max_requests = 60";
        $f[] = "pm.status_path = /fpm.status.php";
        $f[] = "request_terminate_timeout = 605";
        $f[] = "ping.path = /php-fpm-ping";
        $f[] = ";ping.response = pong";
        $f[] = "chdir = /";
        $f[] = "";
        @file_put_contents("/etc/php5/fpm/pool.d/apache2.conf", @implode("\n", $f));
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: PHP-FPM: /etc/php5/fpm/pool.d/apache2.conf done\n";
        }
    }
    $zarafabin = $unix->find_program("zarafa-server");
    if (is_file($zarafabin)) {
        $FreeWebPerformances = unserialize(base64_decode($sock->GET_INFO("ZarafaApachePerformances")));
        if (!is_numeric($FreeWebPerformances["post_max_size"])) {
            $FreeWebPerformances["post_max_size"] = 50;
        }
        if (!is_numeric($FreeWebPerformances["upload_max_filesize"])) {
            $FreeWebPerformances["upload_max_filesize"] = 50;
        }
        if (!is_numeric($FreeWebPerformances["PhpStartServers"])) {
            $FreeWebPerformances["PhpStartServers"] = 20;
        }
        if (!is_numeric($FreeWebPerformances["PhpMinSpareServers"])) {
            $FreeWebPerformances["PhpMinSpareServers"] = 5;
        }
        if (!is_numeric($FreeWebPerformances["PhpMaxSpareServers"])) {
            $FreeWebPerformances["PhpMaxSpareServers"] = 25;
        }
        if (!is_numeric($FreeWebPerformances["PhpMaxClients"])) {
            $FreeWebPerformances["PhpMaxClients"] = 128;
        }
        $f = array();
        $f[] = "[zarafa]";
        $f[] = "user = {$APACHE_USER}";
        $f[] = "group = {$APACHE_GROUP}";
        $f[] = "listen = /var/run/php-fpm-zarafa.sock";
        $f[] = "listen.mode = 0777";
        $f[] = ";listen.allowed_clients = 127.0.0.1";
        if ($process_priority) {
            $f[] = "process.priority = {$ProcessNice}";
        }
        $f[] = "pm = dynamic";
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: PHP-FPM: Zarafa max_children.....: {$FreeWebPerformances["PhpMaxClients"]}\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: PHP-FPM: Zarafa start_servers....: {$FreeWebPerformances["PhpStartServers"]}\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: PHP-FPM: Zarafa min_spare_servers: {$FreeWebPerformances["PhpMinSpareServers"]}\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: PHP-FPM: Zarafa max_spare_servers: {$FreeWebPerformances["PhpMaxSpareServers"]}\n";
        }
        @mkdir("/var/lib/php5-zarafa", 0755, true);
        $unix->chown_func($APACHE_USER, $APACHE_GROUP, "/var/lib/php5-zarafa");
        $f[] = "pm.max_children = {$FreeWebPerformances["PhpMaxClients"]}";
        $f[] = "pm.start_servers = {$FreeWebPerformances["PhpStartServers"]}";
        $f[] = "pm.min_spare_servers = {$FreeWebPerformances["PhpMinSpareServers"]}";
        $f[] = "pm.max_spare_servers = {$FreeWebPerformances["PhpMaxSpareServers"]}";
        $f[] = ";pm.process_idle_timeout = 10s;";
        $f[] = "pm.max_requests = 60";
        $f[] = "pm.status_path = /fpm.status.php";
        $f[] = "request_terminate_timeout = 605";
        $f[] = "ping.path = /php-fpm-ping";
        $f[] = ";ping.response = pong";
        $f[] = "chdir = /";
        $f[] = "php_value[include_path]=\".:/usr/share/php:/usr/share/php5:/usr/local/share/php:/usr/share/php5/PEAR:/usr/share/pear:/tmp\"";
        $f[] = "php_value[magic_quotes_gpc] = 0";
        $f[] = "php_value[short_open_tag] = 0";
        $f[] = "php_value[magic_quotes_runtime] = 0";
        $f[] = "php_value[safe_mode] = 0";
        $f[] = "php_value[register_globals] = 0";
        $f[] = "php_value[max_input_time] = 300";
        $f[] = "php_value[register_globals] = 0";
        $f[] = "php_value[post_max_size] = {$FreeWebPerformances["post_max_size"]}M";
        $f[] = "php_value[upload_max_filesize] = {$FreeWebPerformances["upload_max_filesize"]}M";
        $f[] = "php_value[session.save_path] = /var/lib/php5-zarafa";
        $f[] = "";
        @file_put_contents("/etc/php5/fpm/pool.d/zarafa.conf", @implode("\n", $f));
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: PHP-FPM: Zarafa /etc/php5/fpm/pool.d/zarafa.conf done\n";
        }
    }
    $f = array();
    if ($EnablePHPFPMFrameWork == 1) {
        if ($AsRoot) {
            $f[] = "[framework]";
            $f[] = "user = root";
            $f[] = "group = root";
            $f[] = "listen = /var/run/php-fpm-framework.sock";
            $f[] = "listen.mode = 0777";
            $f[] = ";listen.allowed_clients = 127.0.0.1";
            if ($process_priority) {
                $f[] = "process.priority = {$ProcessNice}";
            }
            $f[] = "pm = dynamic";
            $f[] = "pm.max_children = 50";
            $f[] = "pm.start_servers = 2";
            $f[] = "pm.min_spare_servers = 1";
            $f[] = "pm.max_spare_servers = 5";
            $f[] = ";pm.process_idle_timeout = 10s;";
            $f[] = "pm.max_requests = 60";
            $f[] = "pm.status_path = /fpm.status.php";
            $f[] = "request_terminate_timeout = 605";
            $f[] = "ping.path = /php-fpm-ping";
            $f[] = ";ping.response = pong";
            $f[] = "chdir = /";
            $f[] = "";
            @file_put_contents("/etc/php5/fpm/pool.d/framework.conf", @implode("\n", $f));
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: PHP-FPM: /etc/php5/fpm/pool.d/framework.conf done\n";
            }
        } else {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: PHP-FPM: As root is FALSE for framework..\n";
            }
        }
    }
    $f = array();
    $f[] = ";Writing by Artica," . date("Y-m-d H:i:s") . " file will be erased, change the " . __FILE__ . " code instead...";
    $f[] = "[global]";
    $f[] = "pid = /var/run/php5-fpm.pid";
    $f[] = "error_log = /var/log/php.log";
    if ($syslog_facility) {
        $f[] = "syslog.facility = daemon";
    }
    if ($syslog_facility) {
        $f[] = "syslog.ident = php-fpm";
    }
    $f[] = "log_level = ERROR";
    $f[] = ";emergency_restart_threshold = 0";
    $f[] = ";emergency_restart_interval = 0";
    $f[] = ";process_control_timeout = 0";
    if ($process_max) {
        $f[] = "process.max = 128";
    }
    if ($process_priority) {
        $f[] = "process.priority = {$ProcessNice}";
    }
    $f[] = "daemonize = yes";
    $f[] = ";rlimit_files = 1024";
    $f[] = ";rlimit_core = 0";
    $f[] = "include=/etc/php5/fpm/pool.d/*.conf\n";
    @file_put_contents("/etc/php5/fpm/php-fpm.conf", @implode("\n", $f));
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: PHP-FPM: /etc/php5/fpm/php-fpm.conf done\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: PHP-FPM: Check settings\n";
    }
    $sock = new sockets();
    exec("{$phpfpm} -t -y /etc/php5/fpm/php-fpm.conf 2>&1", $results);
    while (list($index, $line) = each($results)) {
        if (trim($line) == null) {
            continue;
        }
        if (strpos($line, "unknown entry 'syslog.facility'") > 0) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: PHP-FPM: syslog not supported..\n";
            }
            @file_put_contents("/etc/artica-postfix/settings/Daemons/PHPFPMNoSyslog", 1);
            buildConfig();
            return;
        }
        if (strpos($line, "unknown entry 'process.max'") > 0) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: PHP-FPM: process.max not supported..\n";
            }
            @file_put_contents("/etc/artica-postfix/settings/Daemons/PHPFPMNoProcessMax", 1);
            buildConfig();
            return;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: PHP-FPM: {$line}\n";
        }
    }
}