From 41d7d170bc4673e9a4e89a49c191b414e38ef0d7 Mon Sep 17 00:00:00 2001
From: Sergio Cambra <sergio@programatica.es>
Date: Tue, 08 Jul 2014 08:00:01 -0400
Subject: [PATCH] default servers on system config for admin use
---
server/plugins-available/apache2_plugin.inc.php | 92 +++++++++++++++++++++++++++++++++++++---------
1 files changed, 74 insertions(+), 18 deletions(-)
diff --git a/server/plugins-available/apache2_plugin.inc.php b/server/plugins-available/apache2_plugin.inc.php
index 8940cfd..f1a08af 100644
--- a/server/plugins-available/apache2_plugin.inc.php
+++ b/server/plugins-available/apache2_plugin.inc.php
@@ -104,7 +104,7 @@
/* $data contains an array with these keys:
* file -> full path of changed php_ini
- * mode -> web_domain php modes to change (mod, fast-cgi, php-fpm or '' for all except 'mod')
+ * mode -> web_domain php modes to change (mod, fast-cgi, php-fpm, hhvm or '' for all except 'mod')
* php_version -> php ini path that changed (additional php versions)
*/
@@ -118,6 +118,11 @@
}
} elseif($data['mode'] == 'php-fpm') {
$qrystr .= " AND php = 'php-fpm'";
+ if($data['php_version']) {
+ $qrystr .= " AND fastcgi_php_version LIKE '%:" . $app->db->quote($data['php_version']) . ":%'";
+ }
+ } elseif($data['mode'] == 'hhvm') {
+ $qrystr .= " AND php = 'hhvm'";
if($data['php_version']) {
$qrystr .= " AND fastcgi_php_version LIKE '%:" . $app->db->quote($data['php_version']) . ":%'";
}
@@ -444,13 +449,26 @@
$web_folder = 'web';
$log_folder = 'log';
+ $old_web_folder = 'web';
+ $old_log_folder = 'log';
if($data['new']['type'] == 'vhostsubdomain' || $data['new']['type'] == 'vhostalias') {
+ // new one
$tmp = $app->db->queryOneRecord('SELECT `domain` FROM web_domain WHERE domain_id = '.intval($data['new']['parent_domain_id']));
$subdomain_host = preg_replace('/^(.*)\.' . preg_quote($tmp['domain'], '/') . '$/', '$1', $data['new']['domain']);
if($subdomain_host == '') $subdomain_host = 'web'.$data['new']['domain_id'];
$web_folder = $data['new']['web_folder'];
$log_folder .= '/' . $subdomain_host;
unset($tmp);
+
+ if(isset($data['old']['parent_domain_id'])) {
+ // old one
+ $tmp = $app->db->queryOneRecord('SELECT `domain` FROM web_domain WHERE domain_id = '.intval($data['old']['parent_domain_id']));
+ $subdomain_host = preg_replace('/^(.*)\.' . preg_quote($tmp['domain'], '/') . '$/', '$1', $data['old']['domain']);
+ if($subdomain_host == '') $subdomain_host = 'web'.$data['old']['domain_id'];
+ $old_web_folder = $data['old']['web_folder'];
+ $old_log_folder .= '/' . $subdomain_host;
+ unset($tmp);
+ }
}
// Create group and user, if not exist
@@ -562,9 +580,11 @@
if($apache_chrooted) $this->_exec('chroot '.escapeshellcmd($web_config['website_basedir']).' '.$command);
//* Change the log mount
- $fstab_line = '/var/log/ispconfig/httpd/'.$data['old']['domain'].' '.$data['old']['document_root'].'/'.$log_folder.' none bind';
+ $fstab_line = '/var/log/ispconfig/httpd/'.$data['old']['domain'].' '.$data['old']['document_root'].'/'.$old_log_folder.' none bind';
$app->system->removeLine('/etc/fstab', $fstab_line);
- $fstab_line = '/var/log/ispconfig/httpd/'.$data['new']['domain'].' '.$data['new']['document_root'].'/'.$log_folder.' none bind,nobootwait 0 0';
+ $fstab_line = '/var/log/ispconfig/httpd/'.$data['old']['domain'].' '.$data['old']['document_root'].'/'.$old_log_folder.' none bind,nobootwait';
+ $app->system->removeLine('/etc/fstab', $fstab_line);
+ $fstab_line = '/var/log/ispconfig/httpd/'.$data['new']['domain'].' '.$data['new']['document_root'].'/'.$log_folder.' none bind,nobootwait,_netdev 0 0';
$app->system->replaceLine('/etc/fstab', $fstab_line, $fstab_line, 1, 1);
}
@@ -594,14 +614,14 @@
// Remove the symlink for the site, if site is renamed
if($this->action == 'update' && $data['old']['domain'] != '' && $data['new']['domain'] != $data['old']['domain']) {
if(is_dir('/var/log/ispconfig/httpd/'.$data['old']['domain'])) exec('rm -rf /var/log/ispconfig/httpd/'.$data['old']['domain']);
- if(is_link($data['old']['document_root'].'/'.$log_folder)) $app->system->unlink($data['old']['document_root'].'/'.$log_folder);
+ if(is_link($data['old']['document_root'].'/'.$old_log_folder)) $app->system->unlink($data['old']['document_root'].'/'.$old_log_folder);
//* remove old log mount
- $fstab_line = '/var/log/ispconfig/httpd/'.$data['old']['domain'].' '.$data['old']['document_root'].'/'.$log_folder.' none bind';
+ $fstab_line = '/var/log/ispconfig/httpd/'.$data['old']['domain'].' '.$data['old']['document_root'].'/'.$old_log_folder.' none bind';
$app->system->removeLine('/etc/fstab', $fstab_line);
//* Unmount log directory
- exec('umount '.escapeshellarg($data['old']['document_root'].'/'.$log_folder));
+ exec('umount '.escapeshellarg($data['old']['document_root'].'/'.$old_log_folder));
}
//* Create the log dir if nescessary and mount it
@@ -614,7 +634,7 @@
$app->system->chmod($data['new']['document_root'].'/'.$log_folder, 0755);
exec('mount --bind '.escapeshellarg('/var/log/ispconfig/httpd/'.$data['new']['domain']).' '.escapeshellarg($data['new']['document_root'].'/'.$log_folder));
//* add mountpoint to fstab
- $fstab_line = '/var/log/ispconfig/httpd/'.$data['new']['domain'].' '.$data['new']['document_root'].'/'.$log_folder.' none bind,nobootwait 0 0';
+ $fstab_line = '/var/log/ispconfig/httpd/'.$data['new']['domain'].' '.$data['new']['document_root'].'/'.$log_folder.' none bind,nobootwait,_netdev 0 0';
$app->system->replaceLine('/etc/fstab', $fstab_line, $fstab_line, 1, 1);
}
@@ -778,7 +798,7 @@
if($web_config['security_level'] == 20) {
$app->system->chmod($data['new']['document_root'], 0755);
- $app->system->chmod($data['new']['document_root'].'/web', 0710);
+ $app->system->chmod($data['new']['document_root'].'/web', 0711);
$app->system->chmod($data['new']['document_root'].'/webdav', 0710);
$app->system->chmod($data['new']['document_root'].'/private', 0710);
$app->system->chmod($data['new']['document_root'].'/ssl', 0755);
@@ -983,6 +1003,8 @@
// Make sure we only have Unix linebreaks
$vhost_data['apache_directives'] = str_replace("\r\n", "\n", $vhost_data['apache_directives']);
$vhost_data['apache_directives'] = str_replace("\r", "\n", $vhost_data['apache_directives']);
+ $trans = array('{DOCROOT}' => $vhost_data['web_document_root_www']);
+ $vhost_data['apache_directives'] = strtr($vhost_data['apache_directives'], $trans);
// Check if a SSL cert exists
$ssl_dir = $data['new']['document_root'].'/ssl';
@@ -1090,7 +1112,7 @@
}
// get alias domains (co-domains and subdomains)
- $aliases = $app->db->queryAllRecords('SELECT * FROM web_domain WHERE parent_domain_id = '.$data['new']['domain_id']." AND active = 'y' AND (type != 'vhostsubdomain' OR type != 'vhostalias')");
+ $aliases = $app->db->queryAllRecords('SELECT * FROM web_domain WHERE parent_domain_id = '.$data['new']['domain_id']." AND active = 'y' AND (type != 'vhostsubdomain' AND type != 'vhostalias')");
$alias_seo_redirects = array();
switch($data['new']['subdomain']) {
case 'www':
@@ -1256,6 +1278,7 @@
$fcgi_tpl->setVar('php_fcgi_bin', escapeshellcmd($custom_fastcgi_php_executable));
}
$fcgi_tpl->setVar('security_level', intval($web_config['security_level']));
+ $fcgi_tpl->setVar('domain', escapeshellcmd($data['new']['domain']));
$php_open_basedir = ($data['new']['php_open_basedir'] == '')?$data['new']['document_root']:$data['new']['php_open_basedir'];
$fcgi_tpl->setVar('open_basedir', escapeshellcmd($php_open_basedir));
@@ -1300,7 +1323,7 @@
* PHP-FPM
*/
// Support for multiple PHP versions
- if($data['new']['php'] == 'php-fpm'){
+ if($data['new']['php'] == 'php-fpm' || $data['new']['php'] == 'hhvm'){
if(trim($data['new']['fastcgi_php_version']) != ''){
$default_php_fpm = false;
list($custom_php_fpm_name, $custom_php_fpm_init_script, $custom_php_fpm_ini_dir, $custom_php_fpm_pool_dir) = explode(':', trim($data['new']['fastcgi_php_version']));
@@ -1309,7 +1332,7 @@
$default_php_fpm = true;
}
} else {
- if(trim($data['old']['fastcgi_php_version']) != '' && $data['old']['php'] == 'php-fpm'){
+ if(trim($data['old']['fastcgi_php_version']) != '' && ($data['old']['php'] == 'php-fpm' || $data['old']['php'] == 'hhvm')){
$default_php_fpm = false;
list($custom_php_fpm_name, $custom_php_fpm_init_script, $custom_php_fpm_ini_dir, $custom_php_fpm_pool_dir) = explode(':', trim($data['old']['fastcgi_php_version']));
if(substr($custom_php_fpm_ini_dir, -1) != '/') $custom_php_fpm_ini_dir .= '/';
@@ -1568,6 +1591,7 @@
}
$this->php_fpm_pool_update($data, $web_config, $pool_dir, $pool_name, $socket_dir);
+ $this->hhvm_update($data, $web_config);
if($web_config['check_apache_config'] == 'y') {
//* Test if apache starts with the new configuration file
@@ -1708,7 +1732,6 @@
//* Unset action to clean it for next processed vhost.
$this->action = '';
-
}
function delete($event_name, $data) {
@@ -1916,6 +1939,8 @@
// remove PHP-FPM pool
if ($data['old']['php'] == 'php-fpm') {
$this->php_fpm_pool_delete($data, $web_config);
+ } elseif($data['old']['php'] == 'hhvm') {
+ $this->hhvm_update($data, $web_config);
}
//remove the php cgi starter script if available
@@ -2105,9 +2130,7 @@
//* Create the folder path, if it does not exist
if(!is_dir($folder_path)) {
- $app->system->mkdirpath($folder_path);
- $app->system->chown($folder_path, $website['system_user']);
- $app->system->chgrp($folder_path, $website['system_group']);
+ $app->system->mkdirpath($folder_path, 0755, $website['system_user'], $website['system_group']);
}
//* Create empty .htpasswd file, if it does not exist
@@ -2333,6 +2356,15 @@
$app->system->chown($new_folder_path.'.htaccess', $website['system_user']);
$app->system->chgrp($new_folder_path.'.htaccess', $website['system_group']);
$app->log('Created/modified file '.$new_folder_path.'.htaccess', LOGLEVEL_DEBUG);
+
+ //* Create empty .htpasswd file, if it does not exist
+ if(!is_file($folder_path.'.htpasswd')) {
+ $app->system->touch($new_folder_path.'.htpasswd');
+ $app->system->chmod($new_folder_path.'.htpasswd', 0750);
+ $app->system->chown($new_folder_path.'.htpasswd', $website['system_user']);
+ $app->system->chgrp($new_folder_path.'.htpasswd', $website['system_group']);
+ $app->log('Created file '.$new_folder_path.'.htpasswd', LOGLEVEL_DEBUG);
+ }
}
//* Remove .htaccess file
@@ -2698,6 +2730,28 @@
}
}
+ private function hhvm_update($data, $web_config) {
+ global $app, $conf;
+
+ if(file_exists($conf['rootpath'] . '/conf-custom/hhvm_starter.master')) {
+ $content = file_get_contents($conf['rootpath'] . '/conf-custom/hhvm_starter.master');
+ } else {
+ $content = file_get_contents($conf['rootpath'] . '/conf/hhvm_starter.master');
+ }
+
+ if($data['new']['php'] == 'hhvm' && $data['old']['php'] != 'hhvm') {
+ $content = str_replace('{SYSTEM_USER}', $data['new']['system_user'], $content);
+ file_put_contents('/etc/init.d/hhvm_' . $data['new']['system_user'], $content);
+ exec('chmod +x /etc/init.d/hhvm_' . $data['new']['system_user'] . ' >/dev/null 2>&1');
+ exec('/usr/sbin/update-rc.d hhvm_' . $data['new']['system_user'] . ' defaults >/dev/null 2>&1');
+ exec('/etc/init.d/hhvm_' . $data['new']['system_user'] . ' start >/dev/null 2>&1');
+ } elseif($data['new']['php'] != 'hhvm' && $data['old']['php'] == 'hhvm') {
+ exec('/etc/init.d/hhvm_' . $data['old']['system_user'] . ' stop >/dev/null 2>&1');
+ exec('/usr/sbin/update-rc.d hhvm_' . $data['old']['system_user'] . ' remove >/dev/null 2>&1');
+ unlink('/etc/init.d/hhvm_' . $data['old']['system_user'] . ' >/dev/null 2>&1');
+ }
+ }
+
//* Update the PHP-FPM pool configuration file
private function php_fpm_pool_update ($data, $web_config, $pool_dir, $pool_name, $socket_dir) {
global $app, $conf;
@@ -2758,6 +2812,7 @@
$fpm_socket = $socket_dir.$pool_name.'.sock';
$tpl->setVar('fpm_socket', $fpm_socket);
+ $tpl->setVar('fpm_listen_mode', '0600');
$tpl->setVar('fpm_pool', $pool_name);
$tpl->setVar('fpm_port', $web_config['php_fpm_start_port'] + $data['new']['domain_id'] - 1);
@@ -2773,6 +2828,7 @@
$tpl->setVar('pm_max_requests', $data['new']['pm_max_requests']);
$tpl->setVar('document_root', $data['new']['document_root']);
$tpl->setVar('security_level', $web_config['security_level']);
+ $tpl->setVar('domain', $data['new']['domain']);
$php_open_basedir = ($data['new']['php_open_basedir'] == '')?escapeshellcmd($data['new']['document_root']):escapeshellcmd($data['new']['php_open_basedir']);
$tpl->setVar('php_open_basedir', $php_open_basedir);
if($php_open_basedir != ''){
@@ -2795,9 +2851,9 @@
if(substr($ini_setting, 0, 1) == ';') continue;
if(substr($ini_setting, 0, 1) == '#') continue;
if(substr($ini_setting, 0, 2) == '//') continue;
- list($key, $value) = explode('=', $ini_setting);
- if($value){
- $value = trim($value);
+ list($key, $value) = explode('=', $ini_setting, 2);
+ $value = trim($value);
+ if($value != ''){
$key = trim($key);
switch (strtolower($value)) {
case '0':
--
Gitblit v1.9.1