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 &"); }
function start($aspid = false) { $unix = new unix(); $sock = new sockets(); 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]: {$GLOBALS["SERVICE_NAME"]} Already Artica task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); } $ROUNDCUBE_MAIN_FOLDER = ROUNDCUBE_MAIN_FOLDER(); if (!is_dir(ROUNDCUBE_MAIN_FOLDER())) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} not installed\n"; } return; } $RoundCubeHTTPEngineEnabled = intval($sock->GET_INFO("RoundCubeHTTPEngineEnabled")); $pid = LIGHTTPD_PID(); if ($RoundCubeHTTPEngineEnabled == 0) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} disabled (RoundCubeHTTPEngineEnabled)..\n"; } if ($unix->process_exists($pid)) { stop(true); } return; } if ($unix->process_exists($pid)) { $timepid = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} {$GLOBALS["SERVICE_NAME"]} already started {$pid} since {$timepid}Mn...\n"; } return; } $nohup = $unix->find_program("nohup"); $php5 = $unix->LOCATE_PHP5_BIN(); $apache2ctl = $unix->LOCATE_APACHE_CTL(); $LIGHTTPD_CONF_PATH = LIGHTTPD_CONF_PATH(); $RoundCubeHTTPSPort = intval($sock->GET_INFO("RoundCubeHTTPSPort")); $RoundCubeHTTPPort = intval($sock->GET_INFO("RoundCubeHTTPPort")); $RoundCubeUseSSL = intval($sock->GET_INFO("RoundCubeUseSSL")); if ($RoundCubeHTTPSPort == 0) { $RoundCubeHTTPSPort = 449; } if ($RoundCubeHTTPPort == 0) { $RoundCubeHTTPPort = 8888; } 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($num, $line) = each($results)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} {$line}\n"; } } } apache_config(); if ($RoundCubeUseSSL == 1) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Get PID from PORT HTTPS/TCP:{$RoundCubeHTTPSPort}\n"; } $pids = $unix->PIDOF_BY_PORT($RoundCubeHTTPSPort); if (count($pids) > 0) { while (list($pid, $line) = each($pids)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} kill PID {$pid} that listens {$RoundCubeHTTPSPort}\n"; } $unix->KILL_PROCESS($pid, 9); } } } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Get PID from PORT HTTP/TCP:{$RoundCubeHTTPPort}\n"; } $pids = $unix->PIDOF_BY_PORT($RoundCubeHTTPPort); if (count($pids) > 0) { while (list($pid, $line) = each($pids)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} kill PID {$pid} that listens {$RoundCubeHTTPPort}\n"; } $unix->KILL_PROCESS($pid, 9); } } $cmd = "{$apache2ctl} -f {$LIGHTTPD_CONF_PATH} -k start"; if ($GLOBALS["VERBOSE"]) { echo "{$cmd}\n"; } shell_exec($cmd); for ($i = 0; $i < 6; $i++) { $pid = LIGHTTPD_PID(); if ($unix->process_exists($pid)) { break; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} waiting {$i}/6...\n"; } sleep(1); } $pid = LIGHTTPD_PID(); if ($unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Success service started pid:{$pid}...\n"; } } else { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} failed...\n"; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$cmd}\n"; } } }