function WriteConfig($data, $base = '..') { $configText = buildConfig($data); file_put_contents($base . '/api/config.php', $configText); $configuration = "<?php\n\n/**\n * High priority use case, not super planned out yet.\n * This will be useful in the future as we do a better job organizing our application configuration.\n * We need to distinguish between configuration and application constants.\n */\n\nreturn array(\n\n 'session' => array(\n 'prefix' => 'directus6_'\n ),\n\n 'filesystem' => array(\n 'adapter' => 'local',\n 'root' => BASE_PATH . '/media',\n 'root_url' => '/media',\n 'root_thumb_url' => '/media/thumbs',\n // 'key' => 's3-key',\n // 'secret' => 's3-key',\n // 'region' => 's3-region',\n // 'version' => 's3-version',\n // 'bucket' => 's3-bucket'\n ),\n\n 'HTTP' => array(\n 'forceHttps' => false,\n 'isHttpsFn' => function () {\n // Override this check for custom arrangements, e.g. SSL-termination @ load balancer\n return isset(" . '$_SERVER[\'HTTPS\']) && $_SERVER[\'HTTPS\']' . " != 'off';\n }\n ),\n\n // Define this to send emails e.g. forgot password\n 'SMTP' => array(\n 'host' => '',\n 'port' => 25,\n 'username' => '',\n 'password' => ''\n ),\n\n 'dbHooks' => array(\n 'postInsert' => function (" . '$TableGateway, $record, $db, $acl' . ") {\n\n },\n 'postUpdate' => function (" . '$TableGateway, $record, $db, $acl' . ") {\n " . '$tableName = $TableGateway->getTable()' . ";\n switch(" . '$tableName' . ") {\n // ...\n }\n }\n ),\n\n // These tables will not be loaded in the directus schema\n 'tableBlacklist' => array(\n\n ),\n\n 'statusMapping' => array(\n '0' => array(\n 'name' => 'Delete',\n 'color' => '#C1272D',\n 'sort' => 3\n ),\n '1' => array(\n 'name' => 'Active',\n 'color' => '#5B5B5B',\n 'sort' => 1\n ),\n '2' => array(\n 'name' => 'Draft',\n 'color' => '#BBBBBB',\n 'sort' => 2\n )\n )\n\n);"; file_put_contents($base . '/api/configuration.php', $configuration); }
function WriteConfig($data, $base = '..') { $configText = buildConfig($data); file_put_contents($base . '/api/config.php', $configText); $configuration = "<?php\n\n/**\n * High priority use case, not super planned out yet.\n * This will be useful in the future as we do a better job organizing our application configuration.\n * We need to distinguish between configuration and application constants.\n */\n\nreturn array(\n\n 'session' => array(\n 'prefix' => 'directus6_'\n ),\n\n 'filesystem' => array(\n 'adapter' => 'local',\n // By default media directory are located at the same level of directus root\n // To make them a level up outsite the root directory\n // use this instead\n // Ex: 'root' => realpath(BASE_PATH.'/../media'),\n // Note: BASE_PATH constant doesn't end with trailing slash\n 'root' => BASE_PATH . '/media',\n // This is the url where all the media will be pointing to\n // here all assets will be (yourdomain)/media\n // same with thumbnails (yourdomain)/media/thumbs\n 'root_url' => '/media',\n 'root_thumb_url' => '/media/thumbs',\n // 'key' => 's3-key',\n // 'secret' => 's3-key',\n // 'region' => 's3-region',\n // 'version' => 's3-version',\n // 'bucket' => 's3-bucket'\n ),\n\n 'HTTP' => array(\n 'forceHttps' => false,\n 'isHttpsFn' => function () {\n // Override this check for custom arrangements, e.g. SSL-termination @ load balancer\n return isset(" . '$_SERVER[\'HTTPS\']) && $_SERVER[\'HTTPS\']' . " != 'off';\n }\n ),\n\n 'mail' => array(\n 'transport' => 'mail'\n ),\n // 'SMTP' => array(\n // 'host' => '',\n // 'port' => 25,\n // 'username' => '',\n // 'password' => ''\n // ),\n\n 'dbHooks' => array(\n 'postInsert' => function (" . '$TableGateway, $record, $db, $acl' . ") {\n\n },\n 'postUpdate' => function (" . '$TableGateway, $record, $db, $acl' . ") {\n " . '$tableName = $TableGateway->getTable()' . ";\n switch(" . '$tableName' . ") {\n // ...\n }\n }\n ),\n\n // These tables will not be loaded in the directus schema\n 'tableBlacklist' => array(\n\n ),\n\n 'statusMapping' => array(\n '0' => array(\n 'name' => 'Delete',\n 'color' => '#C1272D',\n 'sort' => 3\n ),\n '1' => array(\n 'name' => 'Active',\n 'color' => '#5B5B5B',\n 'sort' => 1\n ),\n '2' => array(\n 'name' => 'Draft',\n 'color' => '#BBBBBB',\n 'sort' => 2\n )\n )\n\n);"; file_put_contents($base . '/api/configuration.php', $configuration); }
function start($aspid = false) { $unix = new unix(); if (is_file("/etc/artica-postfix/FROM_ISO")) { if ($unix->file_time_min("/etc/artica-postfix/FROM_ISO") < 1) { return; } } $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()); } if (!is_file("/etc/modprobe.d/blacklist-floppy.conf")) { @mkdir("/etc/modprobe.d", 0755, true); $rmmod = $unix->find_program("rmmod"); $update_initframs = $unix->find_program("update-initramfs"); @file_put_contents("/etc/modprobe.d/blacklist-floppy.conf", "blacklist floppy\n"); shell_exec("{$rmmod} floppy"); shell_exec("{$update_initframs} -u >/dev/null 2>&1 &"); } $EnableArticaFrontEndToNGninx = $sock->GET_INFO("EnableArticaFrontEndToNGninx"); $EnableArticaFrontEndToApache = $sock->GET_INFO("EnableArticaFrontEndToApache"); if (!is_numeric($EnableArticaFrontEndToNGninx)) { $EnableArticaFrontEndToNGninx = 0; } if (!is_numeric($EnableArticaFrontEndToApache)) { $EnableArticaFrontEndToApache = 0; } $EnableNginx = $sock->GET_INFO("EnableNginx"); $EnableFreeWeb = $sock->GET_INFO("EnableFreeWeb"); if (!is_numeric($EnableFreeWeb)) { $EnableFreeWeb = 0; } if (!is_numeric($EnableNginx)) { $EnableNginx = 1; } if ($EnableNginx == 0) { $EnableArticaFrontEndToNGninx = 0; } $unix->CleanOldLibs(); $chmod = $unix->find_program("chmod"); @mkdir("/etc/artica-postfix/settings/Daemons", 0755, true); shell_exec("{$chmod} -R 0755 /etc/artica-postfix/settings >/dev/null 2>&1"); $sock = new sockets(); $DisableForceFCK = intval($sock->GET_INFO("DisableForceFCK")); @unlink("/forcefsck"); if ($DisableForceFCK == 0) { @touch("/forcefsck"); } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} EnableArticaFrontEndToNGninx:{$EnableArticaFrontEndToNGninx}\n"; } $pid = LIGHTTPD_PID(); if ($EnableArticaFrontEndToNGninx == 1) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} transfered to Nginx..\n"; } if ($unix->process_exists($pid)) { ToSyslog("Stopping artica-webinterface service using lighttpd (transfered to Nginx)..."); stop(true); apache_stop(); } shell_exec("/etc/init.d/nginx start"); return; } if ($EnableArticaFrontEndToApache == 1) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Transfered to Apache..\n"; } if ($unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Stopping Lighttpd PID {$pid}\n"; } ToSyslog("Stopping artica-webinterface service using lighttpd (transfered to Apache)..."); stop(true); } $apachebin = $unix->LOCATE_APACHE_BIN_PATH(); if (is_file($apachebin)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Starting Apache Mode...\n"; } apache_start(); } return; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} transfered to lighttpd..\n"; } $GLOBALS["SERVICE_NAME"] = "Artica lighttpd service"; $pid = LIGHTTPD_PID(); 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; } ToSyslog("Starting artica-webinterface service using lighttpd..."); $nohup = $unix->find_program("nohup"); $php5 = $unix->LOCATE_PHP5_BIN(); $rm = $unix->find_program("rm"); $lighttpd_bin = $unix->find_program("lighttpd"); $LIGHTTPD_CONF_PATH = LIGHTTPD_CONF_PATH(); @mkdir("/var/run/lighttpd", 0755, true); @mkdir("/var/log/lighttpd", 0755, true); $cmd = "{$nohup} {$php5} /usr/share/artica-postfix/exec.web-community-filter.php --register-lic >/dev/null 2>&1 &"; if ($GLOBALS["VERBOSE"]) { echo "{$cmd}\n"; } shell_exec($cmd); buildConfig(); $cmd = "{$lighttpd_bin} -f {$LIGHTTPD_CONF_PATH}"; if ($GLOBALS["VERBOSE"]) { echo "{$cmd}\n"; } shell_exec($cmd); for ($i = 0; $i < 8; $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}/8...\n"; } sleep(1); } $pid = LIGHTTPD_PID(); if ($unix->process_exists($pid)) { ToSyslog("{$GLOBALS["SERVICE_NAME"]} Success service started pid:{$pid}"); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Success service started pid:{$pid}...\n"; } shell_exec("{$php5} /usr/share/artica-postfix/exec.apc.compile.php"); if (!is_file('/etc/init.d/artica-memcache')) { shell_exec("{$php5} /usr/share/artica-postfix/exec.initslapd.php --memcache"); } shell_exec("{$nohup} {$php5} /usr/share/artica-postfix/exec.initslapd.php --phppfm-restart-back >/dev/null 2>&1 &"); shell_exec("{$nohup} /etc/init.d/artica-memcached start >/dev/null 2>&1 &"); shell_exec("{$nohup} /etc/init.d/monit restart >/dev/null 2>&1 &"); $APACHE_SRC_ACCOUNT = $unix->APACHE_SRC_ACCOUNT(); $APACHE_SRC_GROUP = $unix->APACHE_SRC_GROUP(); $unix->chown_func($APACHE_SRC_ACCOUNT, $APACHE_SRC_GROUP, "/var/lib/php5/*"); } 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"; } } }
function start($aspid = false) { $unix = new unix(); $scriptlog = null; if ($GLOBALS["BYSCRIPT"]) { $scriptlog = " by init.d script"; } if (is_file("/etc/artica-postfix/FROM_ISO")) { if ($unix->file_time_min("/etc/artica-postfix/FROM_ISO") < 1) { return; } } 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]: Already Artica task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); } $pid = LIGHTTPD_PID(); @mkdir("/usr/share/artica-postfix/ressources/web", 0755, true); if (!is_dir("/usr/share/artica-postfix/ressources/web")) { echo "Starting......: " . date("H:i:s") . " [INIT]: Framework service Warning !!! /usr/share/artica-postfix/ressources/web (permission denied !)\n"; } if ($unix->process_exists($pid)) { if (!$unix->is_socket("/usr/share/artica-postfix/ressources/web/framework.sock")) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Framework service framework.sock no such socket, stop framework\n"; } stop(true); } else { $timepid = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Framework Service already started {$pid} since {$timepid}Mn...\n"; } return; } } $nohup = $unix->find_program("nohup"); $php5 = $unix->LOCATE_PHP5_BIN(); $lighttpd_bin = $unix->find_program("lighttpd"); if (!is_file($lighttpd_bin)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Framework service lighttpd not found..\n"; } return; } @mkdir("/var/run/lighttpd", 0755, true); $cmd = "{$nohup} {$php5} /usr/share/artica-postfix/exec.web-community-filter.php --register-lic >/dev/null 2>&1 &"; if ($GLOBALS["VERBOSE"]) { echo "{$cmd}\n"; } shell_exec($cmd); buildConfig(); $cmd = "{$lighttpd_bin} -f /etc/artica-postfix/framework.conf"; if ($GLOBALS["VERBOSE"]) { echo "{$cmd}\n"; } shell_exec($cmd); for ($i = 0; $i < 6; $i++) { $pid = LIGHTTPD_PID(); if ($unix->process_exists($pid)) { if (!$unix->is_socket("/usr/share/artica-postfix/ressources/web/framework.sock")) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Framework service waiting framework.sock\n"; } } else { break; } } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Framework service waiting {$i}/6...\n"; } sleep(1); } $pid = LIGHTTPD_PID(); if ($unix->process_exists($pid)) { FrmToSyslog("Success service started pid:{$pid}{$scriptlog}"); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Framework service apply permissions on framework.sock\n"; } @chmod("/usr/share/artica-postfix/ressources/web/framework.sock", 0777); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Framework service apply permissions on Settings direcotry\n"; } $unix->chmod_alldirs(0755, "/etc/artica-postfix/settings/Daemons/*"); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Framework Success service started pid:{$pid}...\n"; } } else { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Framework service failed...\n"; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$cmd}\n"; } } }
function start($aspid = false) { $unix = new unix(); $sock = new sockets(); $postconf = $unix->find_program("postconf"); $Masterbin = "/opt/iRedAPD/iredapd.py"; if (!is_file($postconf)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, postfix not installed\n"; } return; } if (!is_file($Masterbin)) { $php = $unix->LOCATE_PHP5_BIN(); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, not installed\n"; } shell_exec("{$php} /usr/share/artica-postfix/exec.iredmail.install.php"); return; } 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["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); } $pid = PID_NUM(); if (!is_file("/var/log/iredapd.log")) { @touch("/var/log/iredapd.log"); } @chown("/var/log/iredapd.log", "postfix"); @chgrp("/var/log/iredapd.log", "postfix"); if ($unix->process_exists($pid)) { $timepid = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Service already started {$pid} since {$timepid}Mn...\n"; } return; } $php5 = $unix->LOCATE_PHP5_BIN(); $sysctl = $unix->find_program("sysctl"); $echo = $unix->find_program("echo"); $nohup = $unix->find_program("nohup"); $python = $unix->find_program("python"); $f[] = "{$python} {$Masterbin}"; buildConfig(); $cmd = @implode(" ", $f) . " >/dev/null 2>&1 &"; if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service\n"; } shell_exec($cmd); for ($i = 1; $i < 5; $i++) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} waiting {$i}/5\n"; } sleep(1); $pid = PID_NUM(); if ($unix->process_exists($pid)) { break; } } $pid = PID_NUM(); if ($unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Success PID {$pid}\n"; } } else { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Failed\n"; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} {$cmd}\n"; } } }
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"; } } }