From 6fb93dd3b9817a656570a8ace8d22d1617fda506 Mon Sep 17 00:00:00 2001 From: mcramer Date: Mon, 20 Aug 2012 11:12:57 +0000 Subject: [PATCH] Implemented (as optional!) FS#1993 - Creating Subdomains as VirtualHost --- install/sql/incremental/upd_0038.sql | 5 + install/sql/ispconfig3.sql | 1 + .../web/admin/form/system_config.tform.php | 8 +- .../web/admin/lib/lang/de_system_config.lng | 2 + .../web/admin/lib/lang/en_system_config.lng | 2 + interface/web/admin/system_config_edit.php | 11 +- .../templates/system_config_sites_edit.htm | 6 + interface/web/sites/form/web_folder.tform.php | 2 +- .../sites/form/web_vhost_subdomain.tform.php | 705 ++++++++++++++++++ .../web/sites/lib/lang/de_web_domain.lng | 1 + .../sites/lib/lang/de_web_vhost_subdomain.lng | 110 +++ .../lib/lang/de_web_vhost_subdomain_list.lng | 8 + .../web/sites/lib/lang/en_web_domain.lng | 1 + .../sites/lib/lang/en_web_vhost_subdomain.lng | 110 +++ .../lib/lang/en_web_vhost_subdomain_list.lng | 8 + interface/web/sites/lib/module.conf.php | 5 +- interface/web/sites/list/web_folder.list.php | 2 +- .../sites/list/web_vhost_subdomain.list.php | 99 +++ .../templates/web_vhost_subdomain_edit.htm | 207 +++++ .../templates/web_vhost_subdomain_list.htm | 60 ++ interface/web/sites/web_domain_edit.php | 2 +- interface/web/sites/web_domain_list.php | 2 +- interface/web/sites/web_subdomain_edit.php | 4 +- .../web/sites/web_vhost_subdomain_del.php | 72 ++ .../web/sites/web_vhost_subdomain_edit.php | 456 +++++++++++ .../web/sites/web_vhost_subdomain_list.php | 55 ++ server/conf/vhost.conf.master | 4 +- .../plugins-available/apache2_plugin.inc.php | 355 +++++---- server/plugins-available/nginx_plugin.inc.php | 579 ++++++++------ .../nginx_reverseproxy_plugin.inc.php | 6 +- 30 files changed, 2486 insertions(+), 402 deletions(-) create mode 100644 install/sql/incremental/upd_0038.sql create mode 100644 interface/web/sites/form/web_vhost_subdomain.tform.php create mode 100644 interface/web/sites/lib/lang/de_web_vhost_subdomain.lng create mode 100644 interface/web/sites/lib/lang/de_web_vhost_subdomain_list.lng create mode 100644 interface/web/sites/lib/lang/en_web_vhost_subdomain.lng create mode 100644 interface/web/sites/lib/lang/en_web_vhost_subdomain_list.lng create mode 100644 interface/web/sites/list/web_vhost_subdomain.list.php create mode 100644 interface/web/sites/templates/web_vhost_subdomain_edit.htm create mode 100644 interface/web/sites/templates/web_vhost_subdomain_list.htm create mode 100644 interface/web/sites/web_vhost_subdomain_del.php create mode 100644 interface/web/sites/web_vhost_subdomain_edit.php create mode 100644 interface/web/sites/web_vhost_subdomain_list.php diff --git a/install/sql/incremental/upd_0038.sql b/install/sql/incremental/upd_0038.sql new file mode 100644 index 0000000000..f0d723c79e --- /dev/null +++ b/install/sql/incremental/upd_0038.sql @@ -0,0 +1,5 @@ +-- -------------------------------------------------------- + +ALTER TABLE `web_domain` ADD `web_folder` VARCHAR( 100 ) DEFAULT NULL AFTER `document_root` ; + + diff --git a/install/sql/ispconfig3.sql b/install/sql/ispconfig3.sql index e69f624bfd..58e017845f 100644 --- a/install/sql/ispconfig3.sql +++ b/install/sql/ispconfig3.sql @@ -1648,6 +1648,7 @@ CREATE TABLE `web_domain` ( `parent_domain_id` int(11) unsigned NOT NULL default '0', `vhost_type` varchar(32) default NULL, `document_root` varchar(255) default NULL, + `web_folder` varchar(100) default NULL, `system_user` varchar(255) default NULL, `system_group` varchar(255) default NULL, `hd_quota` bigint(20) NOT NULL default '0', diff --git a/interface/web/admin/form/system_config.tform.php b/interface/web/admin/form/system_config.tform.php index 0bb993c5c2..0d776d9c5c 100644 --- a/interface/web/admin/form/system_config.tform.php +++ b/interface/web/admin/form/system_config.tform.php @@ -148,6 +148,12 @@ $form["tabs"]['sites'] = array ( 'width' => '30', 'maxlength' => '255' ), + 'vhost_subdomains' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'CHECKBOX', + 'default' => 'n', + 'value' => array(0 => 'n',1 => 'y') + ), ################################## # ENDE Datatable fields ################################## @@ -252,7 +258,7 @@ $form["tabs"]['mail'] = array ( ), 'smtp_pass' => array ( 'datatype' => 'VARCHAR', - 'formtype' => 'TEXT', + 'formtype' => 'PASSWORD', 'default' => '', 'value' => '', 'width' => '30', diff --git a/interface/web/admin/lib/lang/de_system_config.lng b/interface/web/admin/lib/lang/de_system_config.lng index 9ead3acc5f..79f80c2f8b 100644 --- a/interface/web/admin/lib/lang/de_system_config.lng +++ b/interface/web/admin/lib/lang/de_system_config.lng @@ -5,6 +5,8 @@ $wb['dbname_prefix_txt'] = 'Datenbanknamen Prefix'; $wb['dbuser_prefix_txt'] = 'Datenbankbenutzer Prefix'; $wb['shelluser_prefix_txt'] = 'Shellbenutzer Prefix'; $wb['ftpuser_prefix_txt'] = 'FTP Benutzer Prefix'; +$wb['vhost_subdomains_txt'] = 'Subdomains als Website anlegen'; +$wb['vhost_subdomains_note_txt'] = 'Diese Einstellung kann nicht geändert werden, wenn Subdomains im System vorhanden sind!'; $wb['dbname_prefix_error_regex'] = 'Zeichen nicht erlaubt in Datenbanknamen Prefix.'; $wb['dbuser_prefix_error_regex'] = 'Zeichen nicht erlaubt in Datenbankbenutzer Prefix.'; $wb['ftpuser_prefix_error_regex'] = 'Zeichen nicht erlaubt in FTP Benutzer Prefix.'; diff --git a/interface/web/admin/lib/lang/en_system_config.lng b/interface/web/admin/lib/lang/en_system_config.lng index 4495b4c78c..dc2f96e154 100644 --- a/interface/web/admin/lib/lang/en_system_config.lng +++ b/interface/web/admin/lib/lang/en_system_config.lng @@ -9,6 +9,8 @@ $wb["dbuser_prefix_txt"] = 'Database user prefix'; $wb["shelluser_prefix_txt"] = 'Shell user prefix'; $wb["webdavuser_prefix_txt"] = 'Webdav user prefix'; $wb["ftpuser_prefix_txt"] = 'FTP user prefix'; +$wb['vhost_subdomains_txt'] = 'Create Subdomains as web site'; +$wb['vhost_subdomains_note_txt'] = 'You cannot change this as long as subdomains exist in the system!'; $wb["dbname_prefix_error_regex"] = 'Char not allowed in database name prefix.'; $wb["dbuser_prefix_error_regex"] = 'Char not allowed in database user prefix.'; $wb["ftpuser_prefix_error_regex"] = 'Char not allowed in ftp user prefix.'; diff --git a/interface/web/admin/system_config_edit.php b/interface/web/admin/system_config_edit.php index 700b96e35d..c78e91917f 100644 --- a/interface/web/admin/system_config_edit.php +++ b/interface/web/admin/system_config_edit.php @@ -85,8 +85,17 @@ class page_action extends tform_actions { $section = $app->tform->getCurrentTab(); + $server_config_array = $app->getconf->get_global_config(); - $server_config_array[$section] = $app->tform->encode($this->dataRecord,$section); + $new_config = $app->tform->encode($this->dataRecord,$section); + if($section == 'sites' && $new_config['vhost_subdomains'] != $server_config_array['vhost_subdomains']) { + // check for existing subdomains + $check = $app->db->queryOneRecord("SELECT COUNT(*) as `cnt` FROM `web_domain` WHERE `type` = 'subdomain' OR `type` = 'vhostsubdomain'"); + if($check['cnt'] > 0) { + $new_config['vhost_subdomains'] = $server_config_array['vhost_subdomains']; + } + } + $server_config_array[$section] = $new_config; $server_config_str = $app->ini_parser->get_ini_string($server_config_array); $sql = "UPDATE sys_ini SET config = '".$app->db->quote($server_config_str)."' WHERE sysini_id = 1"; diff --git a/interface/web/admin/templates/system_config_sites_edit.htm b/interface/web/admin/templates/system_config_sites_edit.htm index 21bbf0ef15..121d607a38 100644 --- a/interface/web/admin/templates/system_config_sites_edit.htm +++ b/interface/web/admin/templates/system_config_sites_edit.htm @@ -39,6 +39,12 @@ +
+

{tmpl_var name='vhost_subdomains_txt'}

+
+ {tmpl_var name='vhost_subdomains'} {tmpl_var name='vhost_subdomains_note_txt'} +
+
diff --git a/interface/web/sites/form/web_folder.tform.php b/interface/web/sites/form/web_folder.tform.php index 8e5de211dd..5a6e565883 100644 --- a/interface/web/sites/form/web_folder.tform.php +++ b/interface/web/sites/form/web_folder.tform.php @@ -74,7 +74,7 @@ $form["tabs"]['folder'] = array ( 'formtype' => 'SELECT', 'default' => '', 'datasource' => array ( 'type' => 'SQL', - 'querystring' => "SELECT domain_id,domain FROM web_domain WHERE type = 'vhost' AND {AUTHSQL} ORDER BY domain", + 'querystring' => "SELECT domain_id,domain FROM web_domain WHERE (type = 'vhost' OR type = 'vhostsubdomain') AND {AUTHSQL} ORDER BY domain", 'keyfield'=> 'domain_id', 'valuefield'=> 'domain' ), diff --git a/interface/web/sites/form/web_vhost_subdomain.tform.php b/interface/web/sites/form/web_vhost_subdomain.tform.php new file mode 100644 index 0000000000..448e3ae339 --- /dev/null +++ b/interface/web/sites/form/web_vhost_subdomain.tform.php @@ -0,0 +1,705 @@ + 0 id must match with id of current user +$form["auth_preset"]["groupid"] = 0; // 0 = default groupid of the user, > 0 id must match with groupid of current user +$form["auth_preset"]["perm_user"] = 'riud'; //r = read, i = insert, u = update, d = delete +$form["auth_preset"]["perm_group"] = 'riud'; //r = read, i = insert, u = update, d = delete +$form["auth_preset"]["perm_other"] = ''; //r = read, i = insert, u = update, d = delete + +$wildcard_available = false; +$ssl_available = true; +if(!$app->auth->is_admin()) { + $client_group_id = $_SESSION["s"]["user"]["default_group"]; + $client = $app->db->queryOneRecord("SELECT limit_wildcard, limit_ssl FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id"); + + if($client['limit_ssl'] != 'y') $ssl_available = false; +} + +$form["tabs"]['domain'] = array ( + 'title' => "Domain", + 'width' => 100, + 'template' => "templates/web_vhost_subdomain_edit.htm", + 'readonly' => false, + 'fields' => array ( + ################################## + # Begin Datatable fields + ################################## + 'server_id' => array ( + 'datatype' => 'INTEGER', + 'formtype' => 'SELECT', + 'default' => '', + 'datasource' => array ( 'type' => 'SQL', + 'querystring' => 'SELECT server_id,server_name FROM server WHERE mirror_server_id = 0 AND web_server = 1 AND {AUTHSQL} ORDER BY server_name', + 'keyfield'=> 'server_id', + 'valuefield'=> 'server_name' + ), + 'value' => '' + ), + 'ip_address' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'SELECT', + 'default' => '', + /*'datasource' => array ( 'type' => 'SQL', + 'querystring' => "SELECT ip_address,ip_address FROM server_ip WHERE ip_type = 'IPv4' AND {AUTHSQL} ORDER BY ip_address", + 'keyfield'=> 'ip_address', + 'valuefield'=> 'ip_address' + ),*/ + 'value' => '', + 'searchable' => 2 + ), + 'ipv6_address' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'SELECT', + 'default' => '', + /*'datasource' => array ( 'type' => 'SQL', + 'querystring' => "SELECT ip_address,ip_address FROM server_ip WHERE ip_type = 'IPv6' AND {AUTHSQL} ORDER BY ip_address", + 'keyfield'=> 'ip_address', + 'valuefield'=> 'ip_address' + ),*/ + 'value' => '', + 'searchable' => 2 + ), + 'domain' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'TEXT', + 'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY', + 'errmsg'=> 'domain_error_empty'), + 1 => array ( 'type' => 'UNIQUE', + 'errmsg'=> 'domain_error_unique'), + 2 => array ( 'type' => 'REGEX', + 'regex' => '/^[\w\.\-]{2,255}\.[a-zA-Z0-9\-]{2,30}$/', + 'errmsg'=> 'domain_error_regex'), + ), + 'default' => '', + 'value' => '', + 'width' => '30', + 'maxlength' => '255', + 'searchable' => 1 + ), + 'type' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'SELECT', + 'default' => 'y', + 'value' => array('vhost' => 'Site', 'alias' => 'Alias', 'subdomain' => 'Subdomain', 'vhostsubdomain' => 'Subdomain') + ), + 'parent_domain_id' => array ( + 'datatype' => 'INTEGER', + 'formtype' => 'SELECT', + 'default' => '', + 'datasource' => array ( 'type' => 'SQL', + 'querystring' => "SELECT domain_id,domain FROM web_domain WHERE type = 'vhost' AND {AUTHSQL} ORDER BY domain", + 'keyfield'=> 'domain_id', + 'valuefield'=> 'domain' + ), + 'value' => '' + ), + 'web_folder' => array ( + 'datatype' => 'VARCHAR', + 'validators' => array ( 0 => array ( 'type' => 'REGEX', + 'regex' => '@^([\w/_\.\-]{1,100})$@', + 'errmsg'=> 'web_folder_error_regex'), + ), + 'formtype' => 'TEXT', + 'default' => '', + 'value' => '', + 'width' => '30', + 'maxlength' => '255' + ), + 'vhost_type' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'SELECT', + 'default' => 'y', + 'value' => array('name' => 'Namebased', 'ip' => 'IP-Based') + ), + 'hd_quota' => array ( + 'datatype' => 'INTEGER', + 'formtype' => 'TEXT', + 'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY', + 'errmsg'=> 'hd_quota_error_empty'), + 1 => array ( 'type' => 'REGEX', + 'regex' => '/^(\-1|[0-9]{1,10})$/', + 'errmsg'=> 'hd_quota_error_regex'), + ), + 'default' => '-1', + 'value' => '', + 'width' => '7', + 'maxlength' => '7' + ), + 'traffic_quota' => array ( + 'datatype' => 'INTEGER', + 'formtype' => 'TEXT', + 'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY', + 'errmsg'=> 'traffic_quota_error_empty'), + 1 => array ( 'type' => 'REGEX', + 'regex' => '/^(\-1|[0-9]{1,10})$/', + 'errmsg'=> 'traffic_quota_error_regex'), + ), + 'default' => '-1', + 'value' => '', + 'width' => '7', + 'maxlength' => '7' + ), + 'cgi' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'CHECKBOX', + 'default' => 'n', + 'value' => array(0 => 'n',1 => 'y') + ), + 'ssi' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'CHECKBOX', + 'default' => 'n', + 'value' => array(0 => 'n',1 => 'y') + ), + 'suexec' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'CHECKBOX', + 'default' => 'y', + 'value' => array(0 => 'n',1 => 'y') + ), + 'errordocs' => array ( + 'datatype' => 'INTEGER', + 'formtype' => 'CHECKBOX', + 'default' => '1', + 'value' => array(0 => '0',1 => '1') + ), + 'subdomain' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'SELECT', + 'default' => 'www', + 'value' => ($wildcard_available ? array('none' => 'none_txt', 'www' => 'www.', '*' => '*.') : array('none' => 'none_txt', 'www' => 'www.')) + ), + 'ssl' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'CHECKBOX', + 'default' => 'n', + 'value' => array(0 => 'n',1 => 'y') + ), + 'php' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'SELECT', + 'default' => 'fast-cgi', + 'valuelimit' => 'client:web_php_options', + 'value' => array('no' => 'disabled_txt', 'fast-cgi' => 'Fast-CGI', 'cgi' => 'CGI', 'mod' => 'Mod-PHP', 'suphp' => 'SuPHP', 'php-fpm' => 'PHP-FPM'), + 'searchable' => 2 + ), + 'fastcgi_php_version' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'SELECT', + 'default' => '', + /*'datasource' => array ( 'type' => 'SQL', + 'querystring' => "SELECT ip_address,ip_address FROM server_ip WHERE ip_type = 'IPv4' AND {AUTHSQL} ORDER BY ip_address", + 'keyfield'=> 'ip_address', + 'valuefield'=> 'ip_address' + ),*/ + 'value' => '' + ), + 'perl' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'CHECKBOX', + 'default' => 'n', + 'value' => array(0 => 'n',1 => 'y') + ), + 'ruby' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'CHECKBOX', + 'default' => 'n', + 'value' => array(0 => 'n',1 => 'y') + ), + 'python' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'CHECKBOX', + 'default' => 'n', + 'value' => array(0 => 'n',1 => 'y') + ), + 'active' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'CHECKBOX', + 'default' => 'y', + 'value' => array(0 => 'n',1 => 'y') + ), + ################################## + # ENDE Datatable fields + ################################## + ) +); + + +$form["tabs"]['redirect'] = array ( + 'title' => "Redirect", + 'width' => 100, + 'template' => "templates/web_domain_redirect.htm", + 'readonly' => false, + 'fields' => array ( + ################################## + # Begin Datatable fields + ################################## + 'redirect_type' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'SELECT', + 'default' => '', + 'value' => array('' => 'no_redirect_txt', 'no' => 'no_flag_txt', 'R' => 'R', 'L' => 'L', 'R,L' => 'R,L', 'R=301,L' => 'R=301,L', 'last' => 'last', 'break' => 'break', 'redirect' => 'redirect', 'permanent' => 'permanent') + ), + 'redirect_path' => array ( + 'datatype' => 'VARCHAR', + 'validators' => array ( 0 => array ( 'type' => 'REGEX', + 'regex' => '@^(([\.]{0})|(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.\,\-\+\?\~]*(\?\S+)?)?)?)|(\[scheme\]://([-\w\.]+)+(:\d+)?(/([\w/_\.\-\,\+\?\~]*(\?\S+)?)?)?)|(/[\w/_\.\-]{1,255}/))$@', + 'errmsg'=> 'redirect_error_regex'), + ), + 'formtype' => 'TEXT', + 'default' => '', + 'value' => '', + 'width' => '30', + 'maxlength' => '255' + ), + 'seo_redirect' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'SELECT', + 'default' => '', + 'value' => array('' => 'no_redirect_txt', 'non_www_to_www' => 'non_www_to_www_txt', 'www_to_non_www' => 'www_to_non_www_txt') + ), + ################################## + # ENDE Datatable fields + ################################## + ) +); + +if($ssl_available) { +$form["tabs"]['ssl'] = array ( + 'title' => "SSL", + 'width' => 100, + 'template' => "templates/web_domain_ssl.htm", + 'readonly' => false, + 'fields' => array ( + ################################## + # Begin Datatable fields + ################################## + 'ssl_state' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'TEXT', + 'validators' => array ( 0 => array ( 'type' => 'REGEX', + 'regex' => '/^(([\.]{0})|([a-zA-Z0-9\ \.\-\_\,]{1,255}))$/', + 'errmsg'=> 'ssl_state_error_regex'), + ), + 'default' => '', + 'value' => '', + 'width' => '30', + 'maxlength' => '255' + ), + 'ssl_locality' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'TEXT', + 'validators' => array ( 0 => array ( 'type' => 'REGEX', + 'regex' => '/^(([\.]{0})|([a-zA-Z0-9\ \.\-\_\,]{1,255}))$/', + 'errmsg'=> 'ssl_locality_error_regex'), + ), + 'default' => '', + 'value' => '', + 'width' => '30', + 'maxlength' => '255' + ), + 'ssl_organisation' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'TEXT', + 'validators' => array ( 0 => array ( 'type' => 'REGEX', + 'regex' => '/^(([\.]{0})|([a-zA-Z0-9\ \.\-\_\,]{1,255}))$/', + 'errmsg'=> 'ssl_organisation_error_regex'), + ), + 'default' => '', + 'value' => '', + 'width' => '30', + 'maxlength' => '255' + ), + 'ssl_organisation_unit' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'TEXT', + 'validators' => array ( 0 => array ( 'type' => 'REGEX', + 'regex' => '/^(([\.]{0})|([a-zA-Z0-9\ \.\-\_\,]{1,255}))$/', + 'errmsg'=> 'ssl_organistaion_unit_error_regex'), + ), + 'default' => '', + 'value' => '', + 'width' => '30', + 'maxlength' => '255' + ), + /* + 'ssl_country' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'TEXT', + 'validators' => array ( 0 => array ( 'type' => 'REGEX', + 'regex' => '/^(([\.]{0})|([A-Z]{2,2}))$/', + 'errmsg'=> 'ssl_country_error_regex'), + ), + 'default' => '', + 'value' => '', + 'width' => '2', + 'maxlength' => '2' + ), + */ + 'ssl_country' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'SELECT', + 'default' => '', + 'datasource' => array ( 'type' => 'SQL', + 'querystring' => 'SELECT iso,printable_name FROM country ORDER BY printable_name', + 'keyfield'=> 'iso', + 'valuefield'=> 'printable_name' + ), + 'value' => '' + ), + 'ssl_domain' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'TEXT', + 'default' => '', + 'value' => '', + 'width' => '30', + 'maxlength' => '255' + ), + 'ssl_key' => array ( + 'datatype' => 'TEXT', + 'formtype' => 'TEXTAREA', + 'default' => '', + 'value' => '', + 'cols' => '30', + 'rows' => '10' + ), + 'ssl_request' => array ( + 'datatype' => 'TEXT', + 'formtype' => 'TEXTAREA', + 'default' => '', + 'value' => '', + 'cols' => '30', + 'rows' => '10' + ), + 'ssl_cert' => array ( + 'datatype' => 'TEXT', + 'formtype' => 'TEXTAREA', + 'default' => '', + 'value' => '', + 'cols' => '30', + 'rows' => '10' + ), + 'ssl_bundle' => array ( + 'datatype' => 'TEXT', + 'formtype' => 'TEXTAREA', + 'default' => '', + 'value' => '', + 'cols' => '30', + 'rows' => '10' + ), + 'ssl_action' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'SELECT', + 'default' => '', + 'value' => array('' => 'none_txt', 'save' => 'save_certificate_txt', 'create' => 'create_certificate_txt','del' => 'delete_certificate_txt') + ), + ################################## + # ENDE Datatable fields + ################################## + ) +); +} + +//* Statistics +$form["tabs"]['stats'] = array ( + 'title' => "Stats", + 'width' => 100, + 'template' => "templates/web_domain_stats.htm", + 'readonly' => false, + 'fields' => array ( + ################################## + # Begin Datatable fields + ################################## + 'stats_password' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'PASSWORD', + 'encryption' => 'CRYPT', + 'default' => '', + 'value' => '', + 'width' => '30', + 'maxlength' => '255' + ), + 'stats_type' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'SELECT', + 'default' => 'webalizer', + 'value' => array('webalizer' => 'Webalizer', 'awstats' => 'AWStats') + ), + ################################## + # ENDE Datatable fields + ################################## + ) +); + +// if($_SESSION["s"]["user"]["typ"] == 'admin') { + +//* Backup +$form["tabs"]['backup'] = array ( + 'title' => "Backup", + 'width' => 100, + 'template' => "templates/web_domain_backup.htm", + 'readonly' => false, + 'fields' => array ( + ################################## + # Begin Datatable fields + ################################## + 'backup_interval' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'SELECT', + 'default' => '', + 'value' => array('none' => 'No backup', 'daily' => 'Daily', 'weekly' => 'Weekly', 'monthly' => 'Monthly') + ), + 'backup_copies' => array ( + 'datatype' => 'INTEGER', + 'formtype' => 'SELECT', + 'default' => '', + 'value' => array('1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6', '7' => '7', '8' => '8', '9' => '9', '10' => '10') + ), + ################################## + # ENDE Datatable fields + ################################## + ), + 'plugins' => array ( + 'backup_records' => array ( + 'class' => 'plugin_backuplist', + 'options' => array( + ) + ) + ) +); + +// } + +if($_SESSION["s"]["user"]["typ"] == 'admin') { + +$form["tabs"]['advanced'] = array ( + 'title' => "Options", + 'width' => 100, + 'template' => "templates/web_domain_advanced.htm", + 'readonly' => false, + 'fields' => array ( + ################################## + # Begin Datatable fields + ################################## + 'document_root' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'TEXT', + 'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY', + 'errmsg'=> 'documentroot_error_empty'), + ), + 'default' => '', + 'value' => '', + 'width' => '30', + 'maxlength' => '255' + ), + 'system_user' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'TEXT', + 'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY', + 'errmsg'=> 'sysuser_error_empty'), + ), + 'default' => '', + 'value' => '', + 'width' => '30', + 'maxlength' => '255' + ), + 'system_group' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'TEXT', + 'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY', + 'errmsg'=> 'sysgroup_error_empty'), + ), + 'default' => '', + 'value' => '', + 'width' => '30', + 'maxlength' => '255' + ), + 'allow_override' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'TEXT', + 'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY', + 'errmsg'=> 'allow_override_error_empty'), + ), + 'default' => 'All', + 'value' => '', + 'width' => '30', + 'maxlength' => '255' + ), + 'php_fpm_use_socket' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'CHECKBOX', + 'default' => 'n', + 'value' => array(0 => 'n',1 => 'y') + ), + 'pm' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'SELECT', + 'default' => 'dynamic', + 'value' => array('static' => 'static', 'dynamic' => 'dynamic', 'ondemand' => 'ondemand (PHP Version >= 5.3.9)') + ), + 'pm_max_children' => array ( + 'datatype' => 'INTEGER', + 'formtype' => 'TEXT', + 'validators' => array ( 0 => array ( 'type' => 'REGEX', + 'regex' => '/^([1-9][0-9]{0,10})$/', + 'errmsg'=> 'pm_max_children_error_regex'), + ), + 'default' => '10', + 'value' => '', + 'width' => '3', + 'maxlength' => '3' + ), + 'pm_start_servers' => array ( + 'datatype' => 'INTEGER', + 'formtype' => 'TEXT', + 'validators' => array ( 0 => array ( 'type' => 'REGEX', + 'regex' => '/^([1-9][0-9]{0,10})$/', + 'errmsg'=> 'pm_start_servers_error_regex'), + ), + 'default' => '2', + 'value' => '', + 'width' => '3', + 'maxlength' => '3' + ), + 'pm_min_spare_servers' => array ( + 'datatype' => 'INTEGER', + 'formtype' => 'TEXT', + 'validators' => array ( 0 => array ( 'type' => 'REGEX', + 'regex' => '/^([1-9][0-9]{0,10})$/', + 'errmsg'=> 'pm_min_spare_servers_error_regex'), + ), + 'default' => '1', + 'value' => '', + 'width' => '3', + 'maxlength' => '3' + ), + 'pm_max_spare_servers' => array ( + 'datatype' => 'INTEGER', + 'formtype' => 'TEXT', + 'validators' => array ( 0 => array ( 'type' => 'REGEX', + 'regex' => '/^([1-9][0-9]{0,10})$/', + 'errmsg'=> 'pm_max_spare_servers_error_regex'), + ), + 'default' => '5', + 'value' => '', + 'width' => '3', + 'maxlength' => '3' + ), + 'pm_process_idle_timeout' => array ( + 'datatype' => 'INTEGER', + 'formtype' => 'TEXT', + 'validators' => array ( 0 => array ( 'type' => 'REGEX', + 'regex' => '/^([1-9][0-9]{0,10})$/', + 'errmsg'=> 'pm_process_idle_timeout_error_regex'), + ), + 'default' => '10', + 'value' => '', + 'width' => '3', + 'maxlength' => '6' + ), + 'pm_max_requests' => array ( + 'datatype' => 'INTEGER', + 'formtype' => 'TEXT', + 'validators' => array ( 0 => array ( 'type' => 'REGEX', + 'regex' => '/^([0-9]{1,11})$/', + 'errmsg'=> 'pm_max_requests_error_regex'), + ), + 'default' => '0', + 'value' => '', + 'width' => '3', + 'maxlength' => '6' + ), + 'php_open_basedir' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'TEXT', + /*'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY', + 'errmsg'=> 'php_open_basedir_error_empty'), + ), */ + 'default' => 'All', + 'value' => '', + 'width' => '30', + 'maxlength' => '255' + ), + 'custom_php_ini' => array ( + 'datatype' => 'TEXT', + 'formtype' => 'TEXT', + 'default' => '', + 'value' => '', + 'width' => '30', + 'maxlength' => '255' + ), + 'apache_directives' => array ( + 'datatype' => 'TEXT', + 'formtype' => 'TEXT', + 'default' => '', + 'value' => '', + 'width' => '30', + 'maxlength' => '255' + ), + 'nginx_directives' => array ( + 'datatype' => 'TEXT', + 'formtype' => 'TEXT', + 'default' => '', + 'value' => '', + 'width' => '30', + 'maxlength' => '255' + ) + ################################## + # ENDE Datatable fields + ################################## + ) +); + +} + + +?> diff --git a/interface/web/sites/lib/lang/de_web_domain.lng b/interface/web/sites/lib/lang/de_web_domain.lng index a160ba1340..8e79f9c911 100644 --- a/interface/web/sites/lib/lang/de_web_domain.lng +++ b/interface/web/sites/lib/lang/de_web_domain.lng @@ -13,6 +13,7 @@ $wb['server_id_txt'] = 'Server'; $wb['domain_txt'] = 'Domain'; $wb['type_txt'] = 'Typ'; $wb['parent_domain_id_txt'] = 'Zugehörige Website'; +$wb['web_folder_error_regex'] = 'Ungültige Ordnerangabe, bitte keinen / eingeben.'; $wb['redirect_type_txt'] = 'Redirect Typ'; $wb['redirect_path_txt'] = 'Redirect Pfad'; $wb['active_txt'] = 'Aktiv'; diff --git a/interface/web/sites/lib/lang/de_web_vhost_subdomain.lng b/interface/web/sites/lib/lang/de_web_vhost_subdomain.lng new file mode 100644 index 0000000000..909e5b69b6 --- /dev/null +++ b/interface/web/sites/lib/lang/de_web_vhost_subdomain.lng @@ -0,0 +1,110 @@ += 0 sein.'; +$wb["pm_ondemand_hint_txt"] = 'Bitte beachten Sie, daß Ihre PHP-Version >= 5.3.9 sein muß, wenn Sie den ondemand Process-Manager nutzen möchten. Wenn Sie ondemand für eine ältere PHP-Version auswählen, wird PHP nicht mehr starten!'; +$wb['generate_password_txt'] = 'Passwort erzeugen'; +$wb['repeat_password_txt'] = 'Passwort wiederholen'; +$wb['password_mismatch_txt'] = 'Die Passwörter stimmen nicht überein.'; +$wb['password_match_txt'] = 'Die Passwörter stimmen überein.'; +?> diff --git a/interface/web/sites/lib/lang/de_web_vhost_subdomain_list.lng b/interface/web/sites/lib/lang/de_web_vhost_subdomain_list.lng new file mode 100644 index 0000000000..ba4fc6dadd --- /dev/null +++ b/interface/web/sites/lib/lang/de_web_vhost_subdomain_list.lng @@ -0,0 +1,8 @@ + diff --git a/interface/web/sites/lib/lang/en_web_domain.lng b/interface/web/sites/lib/lang/en_web_domain.lng index ba17f7e05d..87462db567 100644 --- a/interface/web/sites/lib/lang/en_web_domain.lng +++ b/interface/web/sites/lib/lang/en_web_domain.lng @@ -14,6 +14,7 @@ $wb["ssl_action_txt"] = 'SSL Action'; $wb["ssl_domain_txt"] = 'SSL Domain'; $wb["server_id_txt"] = 'Server'; $wb["domain_txt"] = 'Domain'; +$wb['web_folder_error_regex'] = 'Invalid folder entered. Please do not enter a slash.'; $wb["type_txt"] = 'Type'; $wb["parent_domain_id_txt"] = 'Parent Website'; $wb["redirect_type_txt"] = 'Redirect Type'; diff --git a/interface/web/sites/lib/lang/en_web_vhost_subdomain.lng b/interface/web/sites/lib/lang/en_web_vhost_subdomain.lng new file mode 100644 index 0000000000..8b76375bb5 --- /dev/null +++ b/interface/web/sites/lib/lang/en_web_vhost_subdomain.lng @@ -0,0 +1,110 @@ += 0.'; +$wb["pm_ondemand_hint_txt"] = 'Please note that you must have PHP version >= 5.3.9 in order to use the ondemand process manager. If you select ondemand for an older PHP version, PHP will not start anymore!'; +$wb['generate_password_txt'] = 'Generate Password'; +$wb['repeat_password_txt'] = 'Repeat Password'; +$wb['password_mismatch_txt'] = 'The passwords do not match.'; +$wb['password_match_txt'] = 'The passwords do match.'; +?> \ No newline at end of file diff --git a/interface/web/sites/lib/lang/en_web_vhost_subdomain_list.lng b/interface/web/sites/lib/lang/en_web_vhost_subdomain_list.lng new file mode 100644 index 0000000000..8273dbd066 --- /dev/null +++ b/interface/web/sites/lib/lang/en_web_vhost_subdomain_list.lng @@ -0,0 +1,8 @@ + \ No newline at end of file diff --git a/interface/web/sites/lib/module.conf.php b/interface/web/sites/lib/module.conf.php index fdce4de74f..aa0cb67efa 100644 --- a/interface/web/sites/lib/module.conf.php +++ b/interface/web/sites/lib/module.conf.php @@ -21,9 +21,12 @@ $items[] = array( 'title' => "Website", if($app->auth->get_client_limit($userid,'web_subdomain') != 0) { + // read web config + $app->uses('getconf'); + $sys_config = $app->getconf->get_global_config('sites'); $items[] = array( 'title' => "Subdomain", 'target' => 'content', - 'link' => 'sites/web_subdomain_list.php', + 'link' => 'sites/' . ($sys_config['vhost_subdomains'] == 'y' ? 'web_vhost_subdomain_list.php' : 'web_subdomain_list.php'), 'html_id' => 'subdomain_list'); } diff --git a/interface/web/sites/list/web_folder.list.php b/interface/web/sites/list/web_folder.list.php index 73101b2ad6..b8b22a0a7c 100644 --- a/interface/web/sites/list/web_folder.list.php +++ b/interface/web/sites/list/web_folder.list.php @@ -79,7 +79,7 @@ $liste["item"][] = array( 'field' => "parent_domain_id", 'prefix' => "", 'suffix' => "", 'datasource' => array ( 'type' => 'SQL', - 'querystring' => "SELECT domain_id,domain FROM web_domain WHERE type = 'vhost' AND {AUTHSQL} ORDER BY domain", + 'querystring' => "SELECT domain_id,domain FROM web_domain WHERE (type = 'vhost' OR type = 'vhostsubdomain') AND {AUTHSQL} ORDER BY domain", 'keyfield'=> 'domain_id', 'valuefield'=> 'domain' ), diff --git a/interface/web/sites/list/web_vhost_subdomain.list.php b/interface/web/sites/list/web_vhost_subdomain.list.php new file mode 100644 index 0000000000..7b7a8d7706 --- /dev/null +++ b/interface/web/sites/list/web_vhost_subdomain.list.php @@ -0,0 +1,99 @@ + "active", + 'datatype' => "VARCHAR", + 'formtype' => "SELECT", + 'op' => "=", + 'prefix' => "", + 'suffix' => "", + 'width' => "", + 'value' => array('y' => "
Yes
",'n' => "
No
")); + + +$liste["item"][] = array( 'field' => "server_id", + 'datatype' => "VARCHAR", + 'formtype' => "SELECT", + 'op' => "like", + 'prefix' => "%", + 'suffix' => "%", + 'datasource' => array ( 'type' => 'SQL', + 'querystring' => 'SELECT server_id,server_name FROM server WHERE {AUTHSQL} ORDER BY server_name', + 'keyfield'=> 'server_id', + 'valuefield'=> 'server_name' + ), + 'width' => "", + 'value' => ""); + +$liste["item"][] = array( 'field' => "parent_domain_id", + 'datatype' => "VARCHAR", + 'formtype' => "SELECT", + 'op' => "=", + 'prefix' => "", + 'suffix' => "", + 'datasource' => array ( 'type' => 'SQL', + 'querystring' => "SELECT domain_id,domain FROM web_domain WHERE type = 'vhost' AND {AUTHSQL} ORDER BY domain", + 'keyfield'=> 'domain_id', + 'valuefield'=> 'domain' + ), + 'width' => "", + 'value' => ""); + +$liste["item"][] = array( 'field' => "domain", + 'datatype' => "VARCHAR", + 'formtype' => "TEXT", + 'op' => "like", + 'prefix' => "%", + 'suffix' => "%", + 'width' => "", + 'value' => ""); + + +?> \ No newline at end of file diff --git a/interface/web/sites/templates/web_vhost_subdomain_edit.htm b/interface/web/sites/templates/web_vhost_subdomain_edit.htm new file mode 100644 index 0000000000..0c6877d73f --- /dev/null +++ b/interface/web/sites/templates/web_vhost_subdomain_edit.htm @@ -0,0 +1,207 @@ +

+

+ +
+ +
+
+
+ + +
+
+ + +
+
+ + +
+
+ +  MB +
+
+ +  MB +
+
+

{tmpl_var name='cgi_txt'}

+
+ {tmpl_var name='cgi'} +
+
+
+

{tmpl_var name='ssi_txt'}

+
+ {tmpl_var name='ssi'} +
+
+
+

{tmpl_var name='perl_txt'}

+
+ {tmpl_var name='perl'} +
+
+
+

{tmpl_var name='ruby_txt'}

+
+ {tmpl_var name='ruby'} +
+
+
+

{tmpl_var name='python_txt'}

+
+ {tmpl_var name='python'} +
+
+
+

{tmpl_var name='suexec_txt'}

+
+ {tmpl_var name='suexec'} +
+
+
+

{tmpl_var name='errordocs_txt'}

+
+ {tmpl_var name='errordocs'} +
+
+ +
+ + +
+
+

{tmpl_var name='ssl_txt'}

+
+ {tmpl_var name='ssl'} +
+
+
+ + +
+
+ + +
+
+

{tmpl_var name='active_txt'}

+
+ {tmpl_var name='active'} +
+
+
+ + + +
+ + +
+
+ +
+ \ No newline at end of file diff --git a/interface/web/sites/templates/web_vhost_subdomain_list.htm b/interface/web/sites/templates/web_vhost_subdomain_list.htm new file mode 100644 index 0000000000..f216988998 --- /dev/null +++ b/interface/web/sites/templates/web_vhost_subdomain_list.htm @@ -0,0 +1,60 @@ +

+

+ +
+ +
+
{tmpl_var name="toolsarea_head_txt"} +
+ +
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{tmpl_var name='search_limit'}
{tmpl_var name="active"}{tmpl_var name="server_id"}{tmpl_var name="parent_domain_id"}{tmpl_var name="domain"} + +
+
+
+ +
\ No newline at end of file diff --git a/interface/web/sites/web_domain_edit.php b/interface/web/sites/web_domain_edit.php index 99e6670fe8..f972b0db19 100644 --- a/interface/web/sites/web_domain_edit.php +++ b/interface/web/sites/web_domain_edit.php @@ -768,7 +768,7 @@ class page_action extends tform_actions { //* If the domain name has been changed, we will have to change all subdomains if(!empty($this->dataRecord["domain"]) && !empty($this->oldDataRecord["domain"]) && $this->dataRecord["domain"] != $this->oldDataRecord["domain"]) { - $records = $app->db->queryAllRecords("SELECT domain_id,domain FROM web_domain WHERE type = 'subdomain' AND domain LIKE '%.".$app->db->quote($this->oldDataRecord["domain"])."'"); + $records = $app->db->queryAllRecords("SELECT domain_id,domain FROM web_domain WHERE (type = 'subdomain' OR type = 'vhostsubdomain') AND domain LIKE '%.".$app->db->quote($this->oldDataRecord["domain"])."'"); foreach($records as $rec) { $subdomain = $app->db->quote(str_replace($this->oldDataRecord["domain"],$this->dataRecord["domain"],$rec['domain'])); $app->db->datalogUpdate('web_domain', "domain = '".$subdomain."'", 'domain_id', $rec['domain_id']); diff --git a/interface/web/sites/web_domain_list.php b/interface/web/sites/web_domain_list.php index 16cac5a46b..feae9c8896 100644 --- a/interface/web/sites/web_domain_list.php +++ b/interface/web/sites/web_domain_list.php @@ -52,7 +52,7 @@ class list_action extends listform_actions { } $list = new list_action; -$list->SQLExtWhere = "type = 'vhost'"; +$list->SQLExtWhere = "type = 'vhost' AND parent_domain_id = '0'"; $list->SQLOrderBy = 'ORDER BY domain'; $list->onLoad(); diff --git a/interface/web/sites/web_subdomain_edit.php b/interface/web/sites/web_subdomain_edit.php index e2902816bf..0f2e6f14dc 100644 --- a/interface/web/sites/web_subdomain_edit.php +++ b/interface/web/sites/web_subdomain_edit.php @@ -57,10 +57,10 @@ class page_action extends tform_actions { // we will check only users, not admins if($_SESSION["s"]["user"]["typ"] == 'user') { - if(!$app->tform->checkClientLimit('limit_web_subdomain',"type = 'subdomain'")) { + if(!$app->tform->checkClientLimit('limit_web_subdomain',"(type = 'subdomain' OR type = 'vhostsubdomain')")) { $app->error($app->tform->wordbook["limit_web_subdomain_txt"]); } - if(!$app->tform->checkResellerLimit('limit_web_subdomain',"type = 'subdomain'")) { + if(!$app->tform->checkResellerLimit('limit_web_subdomain',"(type = 'subdomain' OR type = 'vhostsubdomain')")) { $app->error('Reseller: '.$app->tform->wordbook["limit_web_subdomain_txt"]); } } diff --git a/interface/web/sites/web_vhost_subdomain_del.php b/interface/web/sites/web_vhost_subdomain_del.php new file mode 100644 index 0000000000..4f6948a701 --- /dev/null +++ b/interface/web/sites/web_vhost_subdomain_del.php @@ -0,0 +1,72 @@ +auth->check_module_permissions('sites'); + +$app->uses('tpl,tform,tform_actions'); +$app->load("tform_actions"); +class page_action extends tform_actions { + + function onBeforeDelete() { + global $app; $conf; + + //* Delete all web folders + $records = $app->db->queryAllRecords("SELECT web_folder_id FROM web_folder WHERE parent_domain_id = '".intval($this->id)."'"); + foreach($records as $rec) { + //* Delete all web folder users + $records2 = $app->db->queryAllRecords("SELECT web_folder_user_id FROM web_folder_user WHERE web_folder_id = '".$rec['web_folder_id']."'"); + foreach($records2 as $rec2) { + $app->db->datalogDelete('web_folder_user','web_folder_user_id',$rec2['web_folder_user_id']); + } + $app->db->datalogDelete('web_folder','web_folder_id',$rec['web_folder_id']); + } + + } +} + +$page = new page_action; +$page->onDelete(); + +?> \ No newline at end of file diff --git a/interface/web/sites/web_vhost_subdomain_edit.php b/interface/web/sites/web_vhost_subdomain_edit.php new file mode 100644 index 0000000000..afe8c38cb7 --- /dev/null +++ b/interface/web/sites/web_vhost_subdomain_edit.php @@ -0,0 +1,456 @@ +auth->check_module_permissions('sites'); + +// Loading classes +$app->uses('tpl,tform,tform_actions'); +$app->load('tform_actions'); + +class page_action extends tform_actions { + + //* Returna a "3/2/1" path hash from a numeric id '123' + function id_hash($id,$levels) { + $hash = "" . $id % 10 ; + $id /= 10 ; + $levels -- ; + while ( $levels > 0 ) { + $hash .= "/" . $id % 10 ; + $id /= 10 ; + $levels-- ; + } + return $hash; + } + + function onShowNew() { + global $app, $conf; + + // we will check only users, not admins + if($_SESSION["s"]["user"]["typ"] == 'user') { + if(!$app->tform->checkClientLimit('limit_web_subdomain',"(type = 'subdomain' OR type = 'vhostsubdomain')")) { + $app->error($app->tform->wordbook["limit_web_subdomain_txt"]); + } + if(!$app->tform->checkResellerLimit('limit_web_subdomain',"(type = 'subdomain' OR type = 'vhostsubdomain')")) { + $app->error('Reseller: '.$app->tform->wordbook["limit_web_subdomain_txt"]); + } + } + parent::onShowNew(); + } + + function onShowEnd() { + global $app, $conf; + + $app->uses('ini_parser,getconf'); + + $read_limits = array('limit_cgi', 'limit_ssi', 'limit_perl', 'limit_ruby', 'limit_python', 'force_suexec', 'limit_hterror', 'limit_wildcard', 'limit_ssl'); + + $parent_domain = $app->db->queryOneRecord("select * FROM web_domain WHERE domain_id = ".intval(@$this->dataRecord["parent_domain_id"])); + + //* Client: If the logged in user is not admin and has no sub clients (no reseller) + if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) { + + // Get the limits of the client + $client_group_id = $_SESSION["s"]["user"]["default_group"]; + $client = $app->db->queryOneRecord("SELECT client.limit_web_domain, client.default_webserver, client." . implode(", client.", $read_limits) . " FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id"); + + //* Get global web config + $web_config = $app->getconf->get_server_config($parent_domain['server_id'], 'web'); + + //PHP Version Selection (FastCGI) + $server_type = 'apache'; + if(!empty($web_config['server_type'])) $server_type = $web_config['server_type']; + if($server_type == 'nginx' && $this->dataRecord['php'] == 'fast-cgi') $this->dataRecord['php'] = 'php-fpm'; + if($this->dataRecord['php'] == 'php-fpm'){ + $php_records = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fpm_init_script != '' AND php_fpm_ini_dir != '' AND php_fpm_pool_dir != '' AND server_id = ".$parent_domain['server_id']." AND (client_id = 0 OR client_id=".$_SESSION['s']['user']['client_id'].")"); + } + if($this->dataRecord['php'] == 'fast-cgi'){ + $php_records = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fastcgi_binary != '' AND php_fastcgi_ini_dir != '' AND server_id = ".$parent_domain['server_id']." AND (client_id = 0 OR client_id=".$_SESSION['s']['user']['client_id'].")"); + } + $php_select = ""; + if(is_array($php_records) && !empty($php_records)) { + foreach( $php_records as $php_record) { + if($this->dataRecord['php'] == 'php-fpm'){ + $php_version = $php_record['name'].':'.$php_record['php_fpm_init_script'].':'.$php_record['php_fpm_ini_dir'].':'.$php_record['php_fpm_pool_dir']; + } else { + $php_version = $php_record['name'].':'.$php_record['php_fastcgi_binary'].':'.$php_record['php_fastcgi_ini_dir']; + } + $selected = ($php_version == $this->dataRecord["fastcgi_php_version"])?'SELECTED':''; + $php_select .= "\r\n"; + } + } + $app->tpl->setVar("fastcgi_php_version",$php_select); + unset($php_records); + + // add limits to template to be able to hide settings + foreach($read_limits as $limit) $app->tpl->setVar($limit, $client[$limit]); + + + //* Reseller: If the logged in user is not admin and has sub clients (is a reseller) + } elseif ($_SESSION["s"]["user"]["typ"] != 'admin' && $app->auth->has_clients($_SESSION['s']['user']['userid'])) { + + // Get the limits of the client + $client_group_id = $_SESSION["s"]["user"]["default_group"]; + $client = $app->db->queryOneRecord("SELECT client.client_id, client.limit_web_domain, client.default_webserver, client.contact_name, CONCAT(client.company_name,' :: ',client.contact_name) as contactname, sys_group.name, client." . implode(", client.", $read_limits) . " FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id"); + + //* Get global web config + $web_config = $app->getconf->get_server_config($parent_domain['server_id'], 'web'); + + //PHP Version Selection (FastCGI) + $server_type = 'apache'; + if(!empty($web_config['server_type'])) $server_type = $web_config['server_type']; + if($server_type == 'nginx' && $this->dataRecord['php'] == 'fast-cgi') $this->dataRecord['php'] = 'php-fpm'; + if($this->dataRecord['php'] == 'php-fpm'){ + $php_records = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fpm_init_script != '' AND php_fpm_ini_dir != '' AND php_fpm_pool_dir != '' AND server_id = ".$parent_domain['server_id']." AND (client_id = 0 OR client_id=".$_SESSION['s']['user']['client_id'].")"); + } + if($this->dataRecord['php'] == 'fast-cgi') { + $php_records = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fastcgi_binary != '' AND php_fastcgi_ini_dir != '' AND server_id = ".$parent_domain['server_id']." AND (client_id = 0 OR client_id=".$_SESSION['s']['user']['client_id'].")"); + } + $php_select = ""; + if(is_array($php_records) && !empty($php_records)) { + foreach( $php_records as $php_record) { + if($this->dataRecord['php'] == 'php-fpm'){ + $php_version = $php_record['name'].':'.$php_record['php_fpm_init_script'].':'.$php_record['php_fpm_ini_dir'].':'.$php_record['php_fpm_pool_dir']; + } else { + $php_version = $php_record['name'].':'.$php_record['php_fastcgi_binary'].':'.$php_record['php_fastcgi_ini_dir']; + } + $selected = ($php_version == $this->dataRecord["fastcgi_php_version"])?'SELECTED':''; + $php_select .= "\r\n"; + } + } + $app->tpl->setVar("fastcgi_php_version",$php_select); + unset($php_records); + + // add limits to template to be able to hide settings + foreach($read_limits as $limit) $app->tpl->setVar($limit, $client[$limit]); + + + //* Admin: If the logged in user is admin + } else { + + //* get global web config + $web_config = $app->getconf->get_server_config($parent_domain['server_id'], 'web'); + + //PHP Version Selection (FastCGI) + $server_type = 'apache'; + if(!empty($web_config['server_type'])) $server_type = $web_config['server_type']; + if($server_type == 'nginx' && $this->dataRecord['php'] == 'fast-cgi') $this->dataRecord['php'] = 'php-fpm'; + if($this->dataRecord['php'] == 'php-fpm'){ + $php_records = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fpm_init_script != '' AND php_fpm_ini_dir != '' AND php_fpm_pool_dir != '' AND server_id = " . $parent_domain['server_id']); + } + if($this->dataRecord['php'] == 'fast-cgi') { + $php_records = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fastcgi_binary != '' AND php_fastcgi_ini_dir != '' AND server_id = " . $parent_domain['server_id']); + } + $php_select = ""; + if(is_array($php_records) && !empty($php_records)) { + foreach( $php_records as $php_record) { + if($this->dataRecord['php'] == 'php-fpm'){ + $php_version = $php_record['name'].':'.$php_record['php_fpm_init_script'].':'.$php_record['php_fpm_ini_dir'].':'.$php_record['php_fpm_pool_dir']; + } else { + $php_version = $php_record['name'].':'.$php_record['php_fastcgi_binary'].':'.$php_record['php_fastcgi_ini_dir']; + } + $selected = ($php_version == $this->dataRecord["fastcgi_php_version"])?'SELECTED':''; + $php_select .= "\r\n"; + } + } + $app->tpl->setVar("fastcgi_php_version",$php_select); + unset($php_records); + + foreach($read_limits as $limit) $app->tpl->setVar($limit, 'y'); + } + + $ssl_domain_select = ''; + $tmp = $app->db->queryOneRecord("SELECT domain FROM web_domain WHERE domain_id = ".$this->id); + $ssl_domains = array($tmp["domain"],'www.'.$tmp["domain"]); + if(is_array($ssl_domains)) { + foreach( $ssl_domains as $ssl_domain) { + $selected = ($ssl_domain == $this->dataRecord['ssl_domain'])?'SELECTED':''; + $ssl_domain_select .= "\r\n"; + } + } + + if($this->id > 0) $app->tpl->setVar('fixed_folder', 'y'); + else $app->tpl->setVar('fixed_folder', 'n'); + + $app->tpl->setVar("ssl_domain",$ssl_domain_select); + unset($ssl_domain_select); + unset($ssl_domains); + unset($ssl_domain); + + $tmp_txt = ($this->dataRecord['traffic_quota_lock'] == 'y')?'('.$app->tform->lng('traffic_quota_exceeded_txt').')':''; + $app->tpl->setVar("traffic_quota_exceeded_txt", $tmp_txt); + + // remove the parent domain part of the domain name before we show it in the text field. + $this->dataRecord["domain"] = str_replace('.'.$parent_domain["domain"],'',$this->dataRecord["domain"]); + $app->tpl->setVar("domain",$this->dataRecord["domain"]); + + parent::onShowEnd(); + } + + function onSubmit() { + global $app, $conf; + + // Get the record of the parent domain + $parent_domain = $app->db->queryOneRecord("select * FROM web_domain WHERE domain_id = ".intval(@$this->dataRecord["parent_domain_id"])); + + // Set a few fixed values + $this->dataRecord["type"] = 'vhostsubdomain'; + $this->dataRecord["server_id"] = $parent_domain["server_id"]; + $this->dataRecord["ip_address"] = $parent_domain["ip_address"]; + $this->dataRecord["ipv6_address"] = $parent_domain["ipv6_address"]; + $this->dataRecord["client_group_id"] = $parent_domain["client_group_id"]; + $this->dataRecord["vhost_type"] = 'name'; + $this->dataRecord["domain"] = $this->dataRecord["domain"].'.'.$parent_domain["domain"]; + + $this->parent_domain_record = $parent_domain; + + $read_limits = array('limit_cgi', 'limit_ssi', 'limit_perl', 'limit_ruby', 'limit_python', 'force_suexec', 'limit_hterror', 'limit_wildcard', 'limit_ssl'); + + + if($_SESSION["s"]["user"]["typ"] != 'admin') { + // Get the limits of the client + $client_group_id = $_SESSION["s"]["user"]["default_group"]; + $client = $app->db->queryOneRecord("SELECT limit_traffic_quota, limit_web_domain, default_webserver, parent_client_id, limit_web_quota, client." . implode(", client.", $read_limits) . " FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id"); + + if($client['limit_cgi'] != 'y') $this->dataRecord['cgi'] = '-'; + if($client['limit_ssi'] != 'y') $this->dataRecord['ssi'] = '-'; + if($client['limit_perl'] != 'y') $this->dataRecord['perl'] = '-'; + if($client['limit_ruby'] != 'y') $this->dataRecord['ruby'] = '-'; + if($client['limit_python'] != 'y') $this->dataRecord['python'] = '-'; + if($client['force_suexec'] != 'n') $this->dataRecord['suexec'] = '-'; + if($client['limit_hterror'] != 'y') $this->dataRecord['errordocs'] = '-'; + if($client['limit_wildcard'] != 'y' && $this->dataRecord['subdomain'] == '*') $this->dataRecord['subdomain'] = '-'; + if($client['limit_ssl'] != 'y') $this->dataRecord['ssl'] = '-'; + + //* Check the website quota of the client + if(isset($_POST["hd_quota"]) && $client["limit_web_quota"] >= 0) { + $tmp = $app->db->queryOneRecord("SELECT sum(hd_quota) as webquota FROM web_domain WHERE domain_id != ".intval($this->id)." AND ".$app->tform->getAuthSQL('u')); + $webquota = $tmp["webquota"]; + $new_web_quota = intval($this->dataRecord["hd_quota"]); + if(($webquota + $new_web_quota > $client["limit_web_quota"]) || ($new_web_quota < 0 && $client["limit_web_quota"] >= 0)) { + $max_free_quota = floor($client["limit_web_quota"] - $webquota); + if($max_free_quota < 0) $max_free_quota = 0; + $app->tform->errorMessage .= $app->tform->lng("limit_web_quota_free_txt").": ".$max_free_quota." MB
"; + // Set the quota field to the max free space + $this->dataRecord["hd_quota"] = $max_free_quota; + } + unset($tmp); + unset($tmp_quota); + } + + //* Check the traffic quota of the client + if(isset($_POST["traffic_quota"]) && $client["limit_traffic_quota"] > 0) { + $tmp = $app->db->queryOneRecord("SELECT sum(traffic_quota) as trafficquota FROM web_domain WHERE domain_id != ".intval($this->id)." AND ".$app->tform->getAuthSQL('u')); + $trafficquota = $tmp["trafficquota"]; + $new_traffic_quota = intval($this->dataRecord["traffic_quota"]); + if(($trafficquota + $new_traffic_quota > $client["limit_traffic_quota"]) || ($new_traffic_quota < 0 && $client["limit_traffic_quota"] >= 0)) { + $max_free_quota = floor($client["limit_traffic_quota"] - $trafficquota); + if($max_free_quota < 0) $max_free_quota = 0; + $app->tform->errorMessage .= $app->tform->lng("limit_traffic_quota_free_txt").": ".$max_free_quota." MB
"; + // Set the quota field to the max free space + $this->dataRecord["traffic_quota"] = $max_free_quota; + } + unset($tmp); + unset($tmp_quota); + } + + if($client['parent_client_id'] > 0) { + // Get the limits of the reseller + $reseller = $app->db->queryOneRecord("SELECT limit_traffic_quota, limit_web_domain, default_webserver, limit_web_quota FROM client WHERE client_id = ".$client['parent_client_id']); + + //* Check the website quota of the client + if(isset($_POST["hd_quota"]) && $reseller["limit_web_quota"] >= 0) { + $tmp = $app->db->queryOneRecord("SELECT sum(hd_quota) as webquota FROM web_domain WHERE domain_id != ".intval($this->id)." AND ".$app->tform->getAuthSQL('u')); + $webquota = $tmp["webquota"]; + $new_web_quota = intval($this->dataRecord["hd_quota"]); + if(($webquota + $new_web_quota > $reseller["limit_web_quota"]) || ($new_web_quota < 0 && $reseller["limit_web_quota"] >= 0)) { + $max_free_quota = floor($reseller["limit_web_quota"] - $webquota); + if($max_free_quota < 0) $max_free_quota = 0; + $app->tform->errorMessage .= $app->tform->lng("limit_web_quota_free_txt").": ".$max_free_quota." MB
"; + // Set the quota field to the max free space + $this->dataRecord["hd_quota"] = $max_free_quota; + } + unset($tmp); + unset($tmp_quota); + } + + //* Check the traffic quota of the client + if(isset($_POST["traffic_quota"]) && $reseller["limit_traffic_quota"] > 0) { + $tmp = $app->db->queryOneRecord("SELECT sum(traffic_quota) as trafficquota FROM web_domain WHERE domain_id != ".intval($this->id)." AND ".$app->tform->getAuthSQL('u')); + $trafficquota = $tmp["trafficquota"]; + $new_traffic_quota = intval($this->dataRecord["traffic_quota"]); + if(($trafficquota + $new_traffic_quota > $reseller["limit_traffic_quota"]) || ($new_traffic_quota < 0 && $reseller["limit_traffic_quota"] >= 0)) { + $max_free_quota = floor($reseller["limit_traffic_quota"] - $trafficquota); + if($max_free_quota < 0) $max_free_quota = 0; + $app->tform->errorMessage .= $app->tform->lng("limit_traffic_quota_free_txt").": ".$max_free_quota." MB
"; + // Set the quota field to the max free space + $this->dataRecord["traffic_quota"] = $max_free_quota; + } + unset($tmp); + unset($tmp_quota); + } + } + + // When the record is updated + if($this->id > 0) { + // restore the server ID if the user is not admin and record is edited + $tmp = $app->db->queryOneRecord("SELECT server_id, `web_folder`, `cgi`, `ssi`, `perl`, `ruby`, `python`, `suexec`, `errordocs`, `subdomain`, `ssl` FROM web_domain WHERE domain_id = ".intval($this->id)); + $this->dataRecord['web_folder'] = $tmp['web_folder']; // cannot be changed! + + // set the settings to current if not provided (or cleared due to limits) + if($this->dataRecord['cgi'] == '-') $this->dataRecord['cgi'] = $tmp['cgi']; + if($this->dataRecord['ssi'] == '-') $this->dataRecord['ssi'] = $tmp['ssi']; + if($this->dataRecord['perl'] == '-') $this->dataRecord['perl'] = $tmp['perl']; + if($this->dataRecord['ruby'] == '-') $this->dataRecord['ruby'] = $tmp['ruby']; + if($this->dataRecord['python'] == '-') $this->dataRecord['python'] = $tmp['python']; + if($this->dataRecord['suexec'] == '-') $this->dataRecord['suexec'] = $tmp['suexec']; + if($this->dataRecord['errordocs'] == '-') $this->dataRecord['errordocs'] = $tmp['errordocs']; + if($this->dataRecord['subdomain'] == '-') $this->dataRecord['subdomain'] = $tmp['subdomain']; + if($this->dataRecord['ssl'] == '-') $this->dataRecord['ssl'] = $tmp['ssl']; + + unset($tmp); + // When the record is inserted + } else { + // Check if the user may add another web_domain + if($client["limit_web_subdomain"] >= 0) { + $tmp = $app->db->queryOneRecord("SELECT count(domain_id) as number FROM web_domain WHERE sys_groupid = $client_group_id and (type = 'subdomain' OR type = 'vhostsubdomain')"); + if($tmp["number"] >= $client["limit_web_subdomain"]) { + $app->error($app->tform->wordbook["limit_web_subdomain_txt"]); + } + } + } + } + + //* make sure that the domain is lowercase + if(isset($this->dataRecord["domain"])) $this->dataRecord["domain"] = strtolower($this->dataRecord["domain"]); + + //* get the server config for this server + $app->uses("getconf"); + $web_config = $app->getconf->get_server_config(intval(isset($this->dataRecord["server_id"]) ? $this->dataRecord["server_id"] : 0),'web'); + //* Check for duplicate ssl certs per IP if SNI is disabled + if(isset($this->dataRecord['ssl']) && $this->dataRecord['ssl'] == 'y' && $web_config['enable_sni'] != 'y') { + $sql = "SELECT count(domain_id) as number FROM web_domain WHERE `ssl` = 'y' AND ip_address = '".$app->db->quote($this->dataRecord['ip_address'])."' and domain_id != ".$this->id; + $tmp = $app->db->queryOneRecord($sql); + if($tmp['number'] > 0) $app->tform->errorMessage .= $app->tform->lng("error_no_sni_txt"); + } + + // Check if pm.max_children >= pm.max_spare_servers >= pm.start_servers >= pm.min_spare_servers > 0 + if(isset($this->dataRecord['pm_max_children']) && $this->dataRecord['pm'] == 'dynamic') { + if(intval($this->dataRecord['pm_max_children']) >= intval($this->dataRecord['pm_max_spare_servers']) && intval($this->dataRecord['pm_max_spare_servers']) >= intval($this->dataRecord['pm_start_servers']) && intval($this->dataRecord['pm_start_servers']) >= intval($this->dataRecord['pm_min_spare_servers']) && intval($this->dataRecord['pm_min_spare_servers']) > 0){ + + } else { + $app->tform->errorMessage .= $app->tform->lng("error_php_fpm_pm_settings_txt").'
'; + } + } + + parent::onSubmit(); + } + + function onAfterInsert() { + global $app, $conf; + + // Get configuration for the web system + $app->uses("getconf"); + $web_rec = $app->tform->getDataRecord($this->id); + $web_config = $app->getconf->get_server_config(intval($web_rec["server_id"]),'web'); + var_dump($this->parent_domain_record, $web_rec); + // Set the values for document_root, system_user and system_group + $system_user = $app->db->quote($this->parent_domain_record['system_user']); + $system_group = $app->db->quote($this->parent_domain_record['system_group']); + $document_root = $app->db->quote($this->parent_domain_record['document_root']); + $php_open_basedir = str_replace("[website_path]/web",$document_root.'/'.$web_rec['web_folder'],$web_config["php_open_basedir"]); + $php_open_basedir = str_replace("[website_domain]/web",$web_rec['domain'].'/'.$web_rec['web_folder'],$php_open_basedir); + $php_open_basedir = str_replace("[website_path]",$document_root,$php_open_basedir); + $php_open_basedir = $app->db->quote(str_replace("[website_domain]",$web_rec['domain'],$php_open_basedir)); + $htaccess_allow_override = $app->db->quote($this->parent_domain_record['allow_override']); + + $sql = "UPDATE web_domain SET sys_groupid = ".intval($this->parent_domain_record['sys_groupid']).",system_user = '$system_user', system_group = '$system_group', document_root = '$document_root', allow_override = '$htaccess_allow_override', php_open_basedir = '$php_open_basedir' WHERE domain_id = ".$this->id; + $app->db->query($sql); + } + + function onBeforeUpdate () { + global $app, $conf; + + //* Check that all fields for the SSL cert creation are filled + if(isset($this->dataRecord['ssl_action']) && $this->dataRecord['ssl_action'] == 'create') { + if($this->dataRecord['ssl_state'] == '') $app->tform->errorMessage .= $app->tform->lng('error_ssl_state_empty').'
'; + if($this->dataRecord['ssl_locality'] == '') $app->tform->errorMessage .= $app->tform->lng('error_ssl_locality_empty').'
'; + if($this->dataRecord['ssl_organisation'] == '') $app->tform->errorMessage .= $app->tform->lng('error_ssl_organisation_empty').'
'; + if($this->dataRecord['ssl_organisation_unit'] == '') $app->tform->errorMessage .= $app->tform->lng('error_ssl_organisation_unit_empty').'
'; + if($this->dataRecord['ssl_country'] == '') $app->tform->errorMessage .= $app->tform->lng('error_ssl_country_empty').'
'; + } + + if(isset($this->dataRecord['ssl_action']) && $this->dataRecord['ssl_action'] == 'save') { + if(trim($this->dataRecord['ssl_cert']) == '') $app->tform->errorMessage .= $app->tform->lng('error_ssl_cert_empty').'
'; + } + + } + + function onAfterUpdate() { + global $app, $conf; + + // Get configuration for the web system + $app->uses("getconf"); + $web_rec = $app->tform->getDataRecord($this->id); + $web_config = $app->getconf->get_server_config(intval($web_rec["server_id"]),'web'); + + // Set the values for document_root, system_user and system_group + $system_user = $app->db->quote($this->parent_domain_record['system_user']); + $system_group = $app->db->quote($this->parent_domain_record['system_group']); + $document_root = $app->db->quote($this->parent_domain_record['document_root']); + $php_open_basedir = str_replace("[website_path]/web",$document_root.'/'.$web_rec['web_folder'],$web_config["php_open_basedir"]); + $php_open_basedir = str_replace("[website_domain]/web",$web_rec['domain'].'/'.$web_rec['web_folder'],$php_open_basedir); + $php_open_basedir = str_replace("[website_path]",$document_root,$php_open_basedir); + $php_open_basedir = $app->db->quote(str_replace("[website_domain]",$web_rec['domain'],$php_open_basedir)); + $htaccess_allow_override = $app->db->quote($this->parent_domain_record['allow_override']); + + $sql = "UPDATE web_domain SET sys_groupid = ".intval($this->parent_domain_record['sys_groupid']).",system_user = '$system_user', system_group = '$system_group', document_root = '$document_root', allow_override = '$htaccess_allow_override', php_open_basedir = '$php_open_basedir' WHERE domain_id = ".$this->id; + $app->db->query($sql); + } + +} + +$page = new page_action; +$page->onLoad(); + +?> \ No newline at end of file diff --git a/interface/web/sites/web_vhost_subdomain_list.php b/interface/web/sites/web_vhost_subdomain_list.php new file mode 100644 index 0000000000..8c483399f9 --- /dev/null +++ b/interface/web/sites/web_vhost_subdomain_list.php @@ -0,0 +1,55 @@ +auth->check_module_permissions('sites'); + +$app->uses('listform_actions'); + +// Limit the results to alias domains +$app->listform_actions->SQLExtWhere = "type = 'vhostsubdomain'"; +$app->listform_actions->SQLOrderBy = 'ORDER BY domain'; +$app->listform_actions->onLoad(); + + +?> \ No newline at end of file diff --git a/server/conf/vhost.conf.master b/server/conf/vhost.conf.master index 6c9513a567..7e9df0ec97 100644 --- a/server/conf/vhost.conf.master +++ b/server/conf/vhost.conf.master @@ -114,11 +114,13 @@ PerlModule ModPerl::Registry PerlModule Apache2::Reload - SetHandler perl-script PerlResponseHandler ModPerl::Registry PerlOptions +ParseHeaders Options +ExecCGI + + SetHandler perl-script + diff --git a/server/plugins-available/apache2_plugin.inc.php b/server/plugins-available/apache2_plugin.inc.php index ad2abcc310..a861265a92 100644 --- a/server/plugins-available/apache2_plugin.inc.php +++ b/server/plugins-available/apache2_plugin.inc.php @@ -103,7 +103,7 @@ class apache2_plugin { $app->log("CA path error, file does not exist:".$web_config['CA_path'].'/openssl.conf',LOGLEVEL_ERROR); //* Only vhosts can have a ssl cert - if($data["new"]["type"] != "vhost") return; + if($data["new"]["type"] != "vhost" && $data["new"]["type"] != "vhostsubdomain") return; // if(!is_dir($data['new']['document_root'].'/ssl')) exec('mkdir -p '.$data['new']['document_root'].'/ssl'); if(!is_dir($data['new']['document_root'].'/ssl')) $app->system->mkdirpath($data['new']['document_root'].'/ssl'); @@ -279,7 +279,7 @@ class apache2_plugin { if($this->action != 'insert') $this->action = 'update'; - if($data['new']['type'] != 'vhost' && $data['new']['parent_domain_id'] > 0) { + if($data['new']['type'] != 'vhost' && $data['new']['type'] != 'vhostsubdomain' && $data['new']['parent_domain_id'] > 0) { $old_parent_domain_id = intval($data['old']['parent_domain_id']); $new_parent_domain_id = intval($data['new']['parent_domain_id']); @@ -325,6 +325,13 @@ class apache2_plugin { return 0; } + $web_folder = 'web'; + $log_folder = 'log'; + if($data['new']['type'] == 'vhostsubdomain') { + $web_folder = $data['new']['web_folder']; + $log_folder .= '_web' . $data['new']['domain_id']; + } + // Create group and user, if not exist $app->uses('system'); @@ -437,9 +444,9 @@ class apache2_plugin { // Check if the directories are there and create them if necessary. $app->system->web_folder_protection($data['new']['document_root'],false); - if(!is_dir($data['new']['document_root'].'/web')) $app->system->mkdirpath($data['new']['document_root'].'/web'); - if(!is_dir($data['new']['document_root'].'/web/error') and $data['new']['errordocs']) $app->system->mkdirpath($data['new']['document_root'].'/web/error'); - //if(!is_dir($data['new']['document_root'].'/log')) exec('mkdir -p '.$data['new']['document_root'].'/log'); + if(!is_dir($data['new']['document_root'].'/' . $web_folder)) $app->system->mkdirpath($data['new']['document_root'].'/' . $web_folder); + if(!is_dir($data['new']['document_root'].'/' . $web_folder . '/error') and $data['new']['errordocs']) $app->system->mkdirpath($data['new']['document_root'].'/' . $web_folder . '/error'); + //if(!is_dir($data['new']['document_root'].'/'.$log_folder)) exec('mkdir -p '.$data['new']['document_root'].'/'.$log_folder); if(!is_dir($data['new']['document_root'].'/ssl')) $app->system->mkdirpath($data['new']['document_root'].'/ssl'); if(!is_dir($data['new']['document_root'].'/cgi-bin')) $app->system->mkdirpath($data['new']['document_root'].'/cgi-bin'); if(!is_dir($data['new']['document_root'].'/tmp')) $app->system->mkdirpath($data['new']['document_root'].'/tmp'); @@ -457,19 +464,20 @@ class apache2_plugin { // 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')) $app->system->unlink($data['old']['document_root'].'/log'); + if(is_link($data['old']['document_root'].'/'.$log_folder)) $app->system->unlink($data['old']['document_root'].'/'.$log_folder); } //* Create the log dir if nescessary and mount it - if(!is_dir($data['new']['document_root'].'/log') || is_link($data['new']['document_root'].'/log')) { - if(is_link($data['new']['document_root'].'/log')) unlink($data['new']['document_root'].'/log'); - $app->system->mkdir($data['new']['document_root'].'/log'); - $app->system->chown($data['new']['document_root'].'/log','root'); - $app->system->chgrp($data['new']['document_root'].'/log','root'); - $app->system->chmod($data['new']['document_root'].'/log',0755); - exec('mount --bind '.escapeshellarg('/var/log/ispconfig/httpd/'.$data['new']['domain']).' '.escapeshellarg($data['new']['document_root'].'/log')); + if(!is_dir('/var/log/ispconfig/httpd/'.$data['new']['domain'])) exec('mkdir -p /var/log/ispconfig/httpd/'.$data['new']['domain']); + if(!is_dir($data['new']['document_root'].'/'.$log_folder) || is_link($data['new']['document_root'].'/'.$log_folder)) { + if(is_link($data['new']['document_root'].'/'.$log_folder)) unlink($data['new']['document_root'].'/'.$log_folder); + $app->system->mkdir($data['new']['document_root'].'/'.$log_folder); + $app->system->chown($data['new']['document_root'].'/'.$log_folder,'root'); + $app->system->chgrp($data['new']['document_root'].'/'.$log_folder,'root'); + $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 none bind 0 0'; + $fstab_line = '/var/log/ispconfig/httpd/'.$data['new']['domain'].' '.$data['new']['document_root'].'/'.$log_folder.' none bind 0 0'; $app->system->replaceLine('/etc/fstab',$fstab_line,$fstab_line,1,1); } @@ -532,11 +540,11 @@ class apache2_plugin { // setting a local var here // normally $conf['templates'] = "/usr/local/ispconfig/server/conf"; - - if($this->action == 'insert' && $data['new']['type'] == 'vhost') { - // Copy the error pages + if($this->action == 'insert' && ($data['new']['type'] == 'vhost' || $data['new']['type'] == 'vhostsubdomain')) { + + // Copy the error pages if($data['new']['errordocs']) { - $error_page_path = escapeshellcmd($data['new']['document_root']).'/web/error/'; + $error_page_path = escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/error/'; if (file_exists($conf['rootpath'] . '/conf-custom/error/'.substr(escapeshellcmd($conf['language']),0,2))) { exec('cp ' . $conf['rootpath'] . '/conf-custom/error/'.substr(escapeshellcmd($conf['language']),0,2).'/* '.$error_page_path); } @@ -552,35 +560,35 @@ class apache2_plugin { } if (file_exists($conf['rootpath'] . '/conf-custom/index/standard_index.html_'.substr(escapeshellcmd($conf['language']),0,2))) { - exec('cp ' . $conf['rootpath'] . '/conf-custom/index/standard_index.html_'.substr(escapeshellcmd($conf['language']),0,2).' '.escapeshellcmd($data['new']['document_root']).'/web/index.html'); + exec('cp ' . $conf['rootpath'] . '/conf-custom/index/standard_index.html_'.substr(escapeshellcmd($conf['language']),0,2).' '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html'); if(is_file($conf['rootpath'] . '/conf-custom/index/favicon.ico')) { - exec('cp ' . $conf['rootpath'] . '/conf-custom/index/favicon.ico '.escapeshellcmd($data['new']['document_root']).'/web/'); + exec('cp ' . $conf['rootpath'] . '/conf-custom/index/favicon.ico '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/'); } if(is_file($conf['rootpath'] . '/conf-custom/index/robots.txt')) { - exec('cp ' . $conf['rootpath'] . '/conf-custom/index/robots.txt '.escapeshellcmd($data['new']['document_root']).'/web/'); + exec('cp ' . $conf['rootpath'] . '/conf-custom/index/robots.txt '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/'); } if(is_file($conf['rootpath'] . '/conf-custom/index/.htaccess')) { - exec('cp ' . $conf['rootpath'] . '/conf-custom/index/.htaccess '.escapeshellcmd($data['new']['document_root']).'/web/'); + exec('cp ' . $conf['rootpath'] . '/conf-custom/index/.htaccess '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/'); } } else { if (file_exists($conf['rootpath'] . '/conf-custom/index/standard_index.html')) { - exec('cp ' . $conf['rootpath'] . '/conf-custom/index/standard_index.html '.escapeshellcmd($data['new']['document_root']).'/web/index.html'); + exec('cp ' . $conf['rootpath'] . '/conf-custom/index/standard_index.html '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html'); } else { - exec('cp ' . $conf['rootpath'] . '/conf/index/standard_index.html_'.substr(escapeshellcmd($conf['language']),0,2).' '.escapeshellcmd($data['new']['document_root']).'/web/index.html'); - if(is_file($conf['rootpath'] . '/conf/index/favicon.ico')) exec('cp ' . $conf['rootpath'] . '/conf/index/favicon.ico '.escapeshellcmd($data['new']['document_root']).'/web/'); - if(is_file($conf['rootpath'] . '/conf/index/robots.txt')) exec('cp ' . $conf['rootpath'] . '/conf/index/robots.txt '.escapeshellcmd($data['new']['document_root']).'/web/'); - if(is_file($conf['rootpath'] . '/conf/index/.htaccess')) exec('cp ' . $conf['rootpath'] . '/conf/index/.htaccess '.escapeshellcmd($data['new']['document_root']).'/web/'); + exec('cp ' . $conf['rootpath'] . '/conf/index/standard_index.html_'.substr(escapeshellcmd($conf['language']),0,2).' '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html'); + if(is_file($conf['rootpath'] . '/conf/index/favicon.ico')) exec('cp ' . $conf['rootpath'] . '/conf/index/favicon.ico '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/'); + if(is_file($conf['rootpath'] . '/conf/index/robots.txt')) exec('cp ' . $conf['rootpath'] . '/conf/index/robots.txt '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/'); + if(is_file($conf['rootpath'] . '/conf/index/.htaccess')) exec('cp ' . $conf['rootpath'] . '/conf/index/.htaccess '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/'); } } - exec('chmod -R a+r '.escapeshellcmd($data['new']['document_root']).'/web/'); + exec('chmod -R a+r '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/'); //** Copy the error documents on update when the error document checkbox has been activated and was deactivated before - } elseif ($this->action == 'update' && $data['new']['type'] == 'vhost' && $data['old']['errordocs'] == 0 && $data['new']['errordocs'] == 1) { - - $error_page_path = escapeshellcmd($data['new']['document_root']).'/web/error/'; + } elseif ($this->action == 'update' && ($data['new']['type'] == 'vhost' || $data['new']['type'] == 'vhostsubdomain') && $data['old']['errordocs'] == 0 && $data['new']['errordocs'] == 1) { + + $error_page_path = escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/error/'; if (file_exists($conf['rootpath'] . '/conf-custom/error/'.substr(escapeshellcmd($conf['language']),0,2))) { exec('cp ' . $conf['rootpath'] . '/conf-custom/error/'.substr(escapeshellcmd($conf['language']),0,2).'/* '.$error_page_path); } @@ -610,12 +618,12 @@ class apache2_plugin { if($this->action == 'insert' || $data["new"]["system_user"] != $data["old"]["system_user"]) { // Chown and chmod the directories below the document root - $this->_exec('chown -R '.$username.':'.$groupname.' '.escapeshellcmd($data['new']['document_root']).'/web'); + $this->_exec('chown -R '.$username.':'.$groupname.' '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder); // The document root itself has to be owned by root in normal level and by the web owner in security level 20 if($web_config['security_level'] == 20) { - $this->_exec('chown '.$username.':'.$groupname.' '.escapeshellcmd($data['new']['document_root']).'/web'); + $this->_exec('chown '.$username.':'.$groupname.' '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder); } else { - $this->_exec('chown root:root '.escapeshellcmd($data['new']['document_root']).'/web'); + $this->_exec('chown root:root '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder); } } @@ -639,8 +647,8 @@ class apache2_plugin { $app->system->chmod($data['new']['document_root'].'/tmp',0777); // Set Log directory to 755 to make the logs accessible by the FTP user - if(realpath($data['new']['document_root'].'/log') == '/var/log/ispconfig/httpd/'.$data['new']['domain'].'/error.log') { - $app->system->chmod($data['new']['document_root'].'/log',0755); + if(realpath($data['new']['document_root'].'/'.$log_folder) == '/var/log/ispconfig/httpd/'.$data['new']['domain'].'/error.log') { + $app->system->chmod($data['new']['document_root'].'/'.$log_folder,0755); } if($web_config['add_web_users_to_sshusers_group'] == 'y') { @@ -670,9 +678,9 @@ class apache2_plugin { $app->system->chgrp($data['new']['document_root'],'root'); $app->system->chown($data['new']['document_root'].'/cgi-bin',$username); $app->system->chgrp($data['new']['document_root'].'/cgi-bin',$groupname); - if(realpath($data['new']['document_root'].'/log') == '/var/log/ispconfig/httpd/'.$data['new']['domain'].'/error.log') { - $app->system->chown($data['new']['document_root'].'/log','root',false); - $app->system->chgrp($data['new']['document_root'].'/log',$groupname,false); + if(realpath($data['new']['document_root'].'/'.$log_folder) == '/var/log/ispconfig/httpd/'.$data['new']['domain'].'/error.log') { + $app->system->chown($data['new']['document_root'].'/'.$log_folder,'root',false); + $app->system->chgrp($data['new']['document_root'].'/'.$log_folder,$groupname,false); } $app->system->chown($data['new']['document_root'].'/ssl','root'); $app->system->chgrp($data['new']['document_root'].'/ssl','root'); @@ -697,22 +705,25 @@ class apache2_plugin { $app->system->chmod($data['new']['document_root'].'/webdav',0755); $app->system->chmod($data['new']['document_root'].'/ssl',0755); $app->system->chmod($data['new']['document_root'].'/cgi-bin',0755); - if(realpath($data['new']['document_root'].'/log') == '/var/log/ispconfig/httpd/'.$data['new']['domain'].'/error.log') { - $app->system->chmod($data['new']['document_root'].'/log',0755); - } // make temp directory writable for Apache and the website users $app->system->chmod($data['new']['document_root'].'/tmp',0777); + // Set Log directory to 755 to make the logs accessible by the FTP user + if(realpath($data['new']['document_root'].'/'.$log_folder) == '/var/log/ispconfig/httpd/'.$data['new']['domain'].'/error.log') { + $app->system->chmod($data['new']['document_root'].'/'.$log_folder,0755); + } + $app->system->chown($data['new']['document_root'],'root'); $app->system->chgrp($data['new']['document_root'],'root'); $app->system->chown($data['new']['document_root'].'/cgi-bin',$username); $app->system->chgrp($data['new']['document_root'].'/cgi-bin',$groupname); - if(realpath($data['new']['document_root'].'/log') == '/var/log/ispconfig/httpd/'.$data['new']['domain'].'/error.log') { - $app->system->chown($data['new']['document_root'].'/log','root',false); - $app->system->chgrp($data['new']['document_root'].'/log','root',false); + if(realpath($data['new']['document_root'].'/'.$log_folder) == '/var/log/ispconfig/httpd/'.$data['new']['domain'].'/error.log') { + $app->system->chown($data['new']['document_root'].'/'.$log_folder,'root',false); + $app->system->chgrp($data['new']['document_root'].'/'.$log_folder,$groupname,false); } - $app->system->chown($data['new']['document_root'].'/ssl','root'); + + $app->system->chown($data['new']['document_root'].'/ssl','root'); $app->system->chgrp($data['new']['document_root'].'/ssl','root'); $app->system->chown($data['new']['document_root'].'/tmp',$username); $app->system->chgrp($data['new']['document_root'].'/tmp',$groupname); @@ -725,19 +736,39 @@ class apache2_plugin { $app->system->chown($data['new']['document_root'].'/webdav',$username); $app->system->chgrp($data['new']['document_root'].'/webdav',$groupname); } - } + } elseif(($this->action == 'insert' && $data['new']['type'] == 'vhostsubdomain') or ($web_config['set_folder_permissions_on_update'] == 'y' && $data['new']['type'] == 'vhostsubdomain')) { + if($web_config['security_level'] == 20) { + $app->system->chmod($data['new']['document_root'].'/' . $web_folder,0710); + $app->system->chown($data['new']['document_root'].'/' . $web_folder,$username); + $app->system->chgrp($data['new']['document_root'].'/' . $web_folder,$groupname); + $app->system->chown($data['new']['document_root'].'/' . $web_folder . '/error',$username); + $app->system->chgrp($data['new']['document_root'].'/' . $web_folder . '/error',$groupname); + $app->system->chown($data['new']['document_root'].'/' . $web_folder . '/stats',$username); + $app->system->chgrp($data['new']['document_root'].'/' . $web_folder . '/stats',$groupname); + } else { + $app->system->chmod($data['new']['document_root'].'/' . $web_folder,0755); + $app->system->chown($data['new']['document_root'].'/' . $web_folder,$username); + $app->system->chgrp($data['new']['document_root'].'/' . $web_folder,$groupname); + $app->system->chown($data['new']['document_root'].'/' . $web_folder . '/error',$username); + $app->system->chgrp($data['new']['document_root'].'/' . $web_folder . '/error',$groupname); + $app->system->chown($data['new']['document_root'].'/' . $web_folder . '/stats',$username); + $app->system->chgrp($data['new']['document_root'].'/' . $web_folder . '/stats',$groupname); + } + } //* Protect web folders $app->system->web_folder_protection($data['new']['document_root'],true); - // Change the ownership of the error log to the root user - if(!@is_file('/var/log/ispconfig/httpd/'.$data['new']['domain'].'/error.log')) exec('touch '.escapeshellcmd('/var/log/ispconfig/httpd/'.$data['new']['domain'].'/error.log')); - $app->system->chown('/var/log/ispconfig/httpd/'.$data['new']['domain'].'/error.log','root'); - $app->system->chgrp('/var/log/ispconfig/httpd/'.$data['new']['domain'].'/error.log','root'); - + if($data['new']['type'] == 'vhost') { + // Change the ownership of the error log to the root user + if(!@is_file('/var/log/ispconfig/httpd/'.$data['new']['domain'].'/error.log')) exec('touch '.escapeshellcmd('/var/log/ispconfig/httpd/'.$data['new']['domain'].'/error.log')); + $app->system->chown('/var/log/ispconfig/httpd/'.$data['new']['domain'].'/error.log','root'); + $app->system->chgrp('/var/log/ispconfig/httpd/'.$data['new']['domain'].'/error.log','root'); + } //* Write the custom php.ini file, if custom_php_ini fieled is not empty $custom_php_ini_dir = $web_config['website_basedir'].'/conf/'.$data['new']['system_user']; + if($data['new']['type'] == 'vhostsubdomain') $custom_php_ini_dir .= '_' . $web_folder; if(!is_dir($web_config['website_basedir'].'/conf')) $app->system->mkdir($web_config['website_basedir'].'/conf'); //* add open_basedir restriction to custom php.ini content, required for suphp only @@ -777,8 +808,8 @@ class apache2_plugin { $vhost_data = $data['new']; //unset($vhost_data['ip_address']); - $vhost_data['web_document_root'] = $data['new']['document_root'].'/web'; - $vhost_data['web_document_root_www'] = $web_config['website_basedir'].'/'.$data['new']['domain'].'/web'; + $vhost_data['web_document_root'] = $data['new']['document_root'].'/' . $web_folder; + $vhost_data['web_document_root_www'] = $web_config['website_basedir'].'/'.$data['new']['domain'].'/' . $web_folder; $vhost_data['web_basedir'] = $web_config['website_basedir']; $vhost_data['security_level'] = $web_config['security_level']; $vhost_data['allow_override'] = ($data['new']['allow_override'] == '')?'All':$data['new']['allow_override']; @@ -811,7 +842,7 @@ class apache2_plugin { if(@is_file($bundle_file)) $vhost_data['has_bundle_cert'] = 1; - //$vhost_data['document_root'] = $data['new']['document_root'].'/web'; + //$vhost_data['document_root'] = $data['new']['document_root'].'/' . $web_folder; // Set SEO Redirect if($data['new']['seo_redirect'] != '' && ($data['new']['subdomain'] == 'www' || $data['new']['subdomain'] == '*')){ @@ -889,7 +920,7 @@ class apache2_plugin { } // 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'"); + $aliases = $app->db->queryAllRecords('SELECT * FROM web_domain WHERE parent_domain_id = '.$data['new']['domain_id']." AND active = 'y' AND type != 'vhostsubdomain'"); switch($data['new']['subdomain']) { case 'www': $server_alias[] .= 'www.'.$data['new']['domain'].' '; @@ -1039,7 +1070,7 @@ class apache2_plugin { $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)); - $fcgi_starter_script = escapeshellcmd($fastcgi_starter_path.$fastcgi_config['fastcgi_starter_script']); + $fcgi_starter_script = escapeshellcmd($fastcgi_starter_path.$fastcgi_config['fastcgi_starter_script'].($data['new']['type'] == 'vhostsubdomain' ? '_web' . $data['new']['domain_id'] : '')); $app->system->file_put_contents($fcgi_starter_script,$fcgi_tpl->grab()); unset($fcgi_tpl); @@ -1051,18 +1082,25 @@ class apache2_plugin { $tpl->setVar('fastcgi_alias',$fastcgi_config['fastcgi_alias']); $tpl->setVar('fastcgi_starter_path',$fastcgi_starter_path); - $tpl->setVar('fastcgi_starter_script',$fastcgi_config['fastcgi_starter_script']); + $tpl->setVar('fastcgi_starter_script',$fastcgi_config['fastcgi_starter_script'].($data['new']['type'] == 'vhostsubdomain' ? '_web' . $data['new']['domain_id'] : '')); $tpl->setVar('fastcgi_config_syntax',$fastcgi_config['fastcgi_config_syntax']); } else { //remove the php fastgi starter script if available if ($data['old']['php'] == 'fast-cgi') { - $fastcgi_config = $app->getconf->get_server_config($conf['server_id'], 'fastcgi'); - $fastcgi_starter_path = str_replace('[system_user]',$data['old']['system_user'],$fastcgi_config['fastcgi_starter_path']); - $fastcgi_starter_path = str_replace('[client_id]',$client_id,$fastcgi_starter_path); - if (is_dir($fastcgi_starter_path)) { - exec('rm -rf '.$fastcgi_starter_path); - } + $fastcgi_config = $app->getconf->get_server_config($conf['server_id'], 'fastcgi'); + $fastcgi_starter_path = str_replace('[system_user]',$data['old']['system_user'],$fastcgi_config['fastcgi_starter_path']); + $fastcgi_starter_path = str_replace('[client_id]',$client_id,$fastcgi_starter_path); + if($data['old']['type'] == 'vhost') { + if (is_dir($fastcgi_starter_path)) { + exec('rm -rf '.$fastcgi_starter_path); + } + } else { + $fcgi_starter_script = $fastcgi_starter_path.$fastcgi_config['fastcgi_starter_script'].'_web' . $data['old']['domain_id']; + if (file_exists($fcgi_starter_script)) { + exec('rm -f '.$fcgi_starter_script); + } + } } } @@ -1122,7 +1160,7 @@ class apache2_plugin { //$cgi_config = $app->getconf->get_server_config($conf['server_id'], 'cgi'); $cgi_config['cgi_starter_path'] = $web_config['website_basedir'].'/php-cgi-scripts/[system_user]/'; - $cgi_config['cgi_starter_script'] = 'php-cgi-starter'; + $cgi_config['cgi_starter_script'] = 'php-cgi-starter'.($data['new']['type'] == 'vhostsubdomain' ? '_web' . $data['new']['domain_id'] : ''); $cgi_config['cgi_bin'] = '/usr/bin/php-cgi'; $cgi_starter_path = str_replace('[system_user]',$data['new']['system_user'],$cgi_config['cgi_starter_path']); @@ -1157,7 +1195,7 @@ class apache2_plugin { $cgi_tpl->setVar('php_ini_path',escapeshellcmd($fastcgi_config['fastcgi_phpini_path'])); } - $cgi_starter_script = escapeshellcmd($cgi_starter_path.$cgi_config['cgi_starter_script']); + $cgi_starter_script = escapeshellcmd($cgi_starter_path.$cgi_config['cgi_starter_script'].($data['new']['type'] == 'vhostsubdomain' ? '_web' . $data['new']['domain_id'] : '')); $app->system->file_put_contents($cgi_starter_script,$cgi_tpl->grab()); unset($cgi_tpl); @@ -1169,7 +1207,7 @@ class apache2_plugin { $app->system->chgrp($cgi_starter_script,$data['new']['system_group']); $tpl->setVar('cgi_starter_path',$cgi_starter_path); - $tpl->setVar('cgi_starter_script',$cgi_config['cgi_starter_script']); + $tpl->setVar('cgi_starter_script',$cgi_config['cgi_starter_script'].($data['new']['type'] == 'vhostsubdomain' ? '_web' . $data['new']['domain_id'] : '')); } @@ -1288,11 +1326,11 @@ class apache2_plugin { } //* Create .htaccess and .htpasswd file for website statistics - if(!is_file($data['new']['document_root'].'/web/stats/.htaccess') or $data['old']['document_root'] != $data['new']['document_root']) { - if(!is_dir($data['new']['document_root'].'/web/stats')) $app->system->mkdir($data['new']['document_root'].'/web/stats'); + if(!is_file($data['new']['document_root'].'/' . $web_folder . '/stats/.htaccess') or $data['old']['document_root'] != $data['new']['document_root']) { + if(!is_dir($data['new']['document_root'].'/' . $web_folder . '/stats')) $app->system->mkdir($data['new']['document_root'].'/' . $web_folder . '/stats'); $ht_file = "AuthType Basic\nAuthName \"Members Only\"\nAuthUserFile ".$data['new']['document_root']."/.htpasswd_stats\nrequire valid-user"; - $app->system->file_put_contents($data['new']['document_root'].'/web/stats/.htaccess',$ht_file); - $app->system->chmod($data['new']['document_root'].'/web/stats/.htaccess',0755); + $app->system->file_put_contents($data['new']['document_root'].'/' . $web_folder . '/stats/.htaccess',$ht_file); + $app->system->chmod($data['new']['document_root'].'/' . $web_folder . '/stats/.htaccess',0755); unset($ht_file); } @@ -1308,7 +1346,7 @@ class apache2_plugin { } //* Create awstats configuration - if($data['new']['stats_type'] == 'awstats' && $data['new']['type'] == 'vhost') { + if($data['new']['stats_type'] == 'awstats' && ($data['new']['type'] == 'vhost' || $data['new']['type'] == 'vhostsubdomain')) { $this->awstats_update($data,$web_config); } @@ -1419,7 +1457,7 @@ class apache2_plugin { $apache_chrooted = false; } - if($data['old']['type'] != 'vhost' && $data['old']['parent_domain_id'] > 0) { + if($data['old']['type'] != 'vhost' && $data['old']['type'] != 'vhostsubdomain' && $data['old']['parent_domain_id'] > 0) { //* This is a alias domain or subdomain, so we have to update the website instead $parent_domain_id = intval($data['old']['parent_domain_id']); $tmp = $app->db->queryOneRecord('SELECT * FROM web_domain WHERE domain_id = '.$parent_domain_id." AND active = 'y'"); @@ -1452,72 +1490,92 @@ class apache2_plugin { $app->system->unlink($vhost_file); $app->log('Removing vhost file: '.$vhost_file,LOGLEVEL_DEBUG); - - $docroot = escapeshellcmd($data['old']['document_root']); - if($docroot != '' && !stristr($docroot,'..')) exec('rm -rf '.$docroot); - - - //remove the php fastgi starter script if available - if ($data['old']['php'] == 'fast-cgi') { - $fastcgi_starter_path = str_replace('[system_user]',$data['old']['system_user'],$web_config['fastcgi_starter_path']); - if (is_dir($fastcgi_starter_path)) { - exec('rm -rf '.$fastcgi_starter_path); - } - } + + if($data['old']['type'] == 'vhost') { + $docroot = escapeshellcmd($data['old']['document_root']); + if($docroot != '' && !stristr($docroot,'..')) exec('rm -rf '.$docroot); - // remove PHP-FPM pool - if ($data['old']['php'] == 'php-fpm') { - $this->php_fpm_pool_delete($data,$web_config); - } - - //remove the php cgi starter script if available - if ($data['old']['php'] == 'cgi') { - // TODO: fetch the date from the server-settings - $web_config['cgi_starter_path'] = $web_config['website_basedir'].'/php-cgi-scripts/[system_user]/'; - - $cgi_starter_path = str_replace('[system_user]',$data['old']['system_user'],$web_config['cgi_starter_path']); - if (is_dir($cgi_starter_path)) { - exec('rm -rf '.$cgi_starter_path); - } - } - - $app->log('Removing website: '.$docroot,LOGLEVEL_DEBUG); - - // Delete the symlinks for the sites - $client = $app->db->queryOneRecord('SELECT client_id FROM sys_group WHERE sys_group.groupid = '.intval($data['old']['sys_groupid'])); - $client_id = intval($client['client_id']); - unset($client); - $tmp_symlinks_array = explode(':',$web_config['website_symlinks']); - if(is_array($tmp_symlinks_array)) { - foreach($tmp_symlinks_array as $tmp_symlink) { - $tmp_symlink = str_replace('[client_id]',$client_id,$tmp_symlink); - $tmp_symlink = str_replace('[website_domain]',$data['old']['domain'],$tmp_symlink); - // Remove trailing slash - if(substr($tmp_symlink, -1, 1) == '/') $tmp_symlink = substr($tmp_symlink, 0, -1); - // create the symlinks, if not exist - if(is_link($tmp_symlink)) { - $app->system->unlink($tmp_symlink); - $app->log('Removing symlink: '.$tmp_symlink,LOGLEVEL_DEBUG); - } - } - } - // end removing symlinks + //remove the php fastgi starter script if available + if ($data['old']['php'] == 'fast-cgi') { + $fastcgi_starter_path = str_replace('[system_user]',$data['old']['system_user'],$web_config['fastcgi_starter_path']); + if($data['old']['type'] == 'vhost') { + if (is_dir($fastcgi_starter_path)) { + exec('rm -rf '.$fastcgi_starter_path); + } + } else { + $fcgi_starter_script = $fastcgi_starter_path.$web_config['fastcgi_starter_script'].'_web'.$data['old']['domain_id']; + if (file_exists($fcgi_starter_script)) { + exec('rm -f '.$fcgi_starter_script); + } + } + } + + // remove PHP-FPM pool + if ($data['old']['php'] == 'php-fpm') { + $this->php_fpm_pool_delete($data,$web_config); + } - // Delete the log file directory - $vhost_logfile_dir = escapeshellcmd('/var/log/ispconfig/httpd/'.$data['old']['domain']); - if($data['old']['domain'] != '' && !stristr($vhost_logfile_dir,'..')) exec('rm -rf '.$vhost_logfile_dir); - $app->log('Removing website logfile directory: '.$vhost_logfile_dir,LOGLEVEL_DEBUG); + //remove the php cgi starter script if available + if ($data['old']['php'] == 'cgi') { + // TODO: fetch the date from the server-settings + $web_config['cgi_starter_path'] = $web_config['website_basedir'].'/php-cgi-scripts/[system_user]/'; + + $cgi_starter_path = str_replace('[system_user]',$data['old']['system_user'],$web_config['cgi_starter_path']); + if($data['old']['type'] == 'vhost') { + if (is_dir($cgi_starter_path)) { + exec('rm -rf '.$cgi_starter_path); + } + } else { + $cgi_starter_script = $cgi_starter_path.'php-cgi-starter_web'.$data['old']['domain_id']; + if (file_exists($cgi_starter_script)) { + exec('rm -f '.$cgi_starter_script); + } + } + } + + $app->log('Removing website: '.$docroot,LOGLEVEL_DEBUG); + + // Delete the symlinks for the sites + $client = $app->db->queryOneRecord('SELECT client_id FROM sys_group WHERE sys_group.groupid = '.intval($data['old']['sys_groupid'])); + $client_id = intval($client['client_id']); + unset($client); + $tmp_symlinks_array = explode(':',$web_config['website_symlinks']); + if(is_array($tmp_symlinks_array)) { + foreach($tmp_symlinks_array as $tmp_symlink) { + $tmp_symlink = str_replace('[client_id]',$client_id,$tmp_symlink); + $tmp_symlink = str_replace('[website_domain]',$data['old']['domain'],$tmp_symlink); + // Remove trailing slash + if(substr($tmp_symlink, -1, 1) == '/') $tmp_symlink = substr($tmp_symlink, 0, -1); + // create the symlinks, if not exist + if(is_link($tmp_symlink)) { + $app->system->unlink($tmp_symlink); + $app->log('Removing symlink: '.$tmp_symlink,LOGLEVEL_DEBUG); + } + } + } + // end removing symlinks + } else { + // vhost subdomain + } - //delete the web user - $command = 'userdel'; - $command .= ' '.$data['old']['system_user']; - exec($command); - if($apache_chrooted) $this->_exec('chroot '.escapeshellcmd($web_config['website_basedir']).' '.$command); - - //* Remove the awstats configuration file - if($data['old']['stats_type'] == 'awstats') { - $this->awstats_delete($data,$web_config); - } + // Delete the log file directory + $vhost_logfile_dir = escapeshellcmd('/var/log/ispconfig/httpd/'.$data['old']['domain']); + if($data['old']['domain'] != '' && !stristr($vhost_logfile_dir,'..')) exec('rm -rf '.$vhost_logfile_dir); + $app->log('Removing website logfile directory: '.$vhost_logfile_dir,LOGLEVEL_DEBUG); + + if($data['old']['type'] == 'vhost') { + //delete the web user + $command = 'userdel'; + $command .= ' '.$data['old']['system_user']; + exec($command); + if($apache_chrooted) $this->_exec('chroot '.escapeshellcmd($web_config['website_basedir']).' '.$command); + + } + + //* Remove the awstats configuration file + if($data['old']['stats_type'] == 'awstats') { + $this->awstats_delete($data,$web_config); + } if($apache_chrooted) { $app->services->restartServiceDelayed('httpd','restart'); @@ -1595,10 +1653,13 @@ class apache2_plugin { return false; } + $web_folder = 'web'; + if($website['type'] == 'vhostsubdomain') $web_folder = $website['web_folder']; + //* Get the folder path. if(substr($folder['path'],0,1) == '/') $folder['path'] = substr($folder['path'],1); if(substr($folder['path'],-1) == '/') $folder['path'] = substr($folder['path'],0,-1); - $folder_path = escapeshellcmd($website['document_root'].'/web/'.$folder['path']); + $folder_path = escapeshellcmd($website['document_root'].'/' . $web_folder . '/'.$folder['path']); if(substr($folder_path,-1) != '/') $folder_path .= '/'; //* Check if the resulting path is inside the docroot @@ -1679,10 +1740,13 @@ class apache2_plugin { return false; } + $web_folder = 'web'; + if($website['type'] == 'vhostsubdomain') $web_folder = $website['web_folder']; + //* Get the folder path. if(substr($folder['path'],0,1) == '/') $folder['path'] = substr($folder['path'],1); if(substr($folder['path'],-1) == '/') $folder['path'] = substr($folder['path'],0,-1); - $folder_path = realpath($website['document_root'].'/web/'.$folder['path']); + $folder_path = realpath($website['document_root'].'/' . $web_folder . '/'.$folder['path']); if(substr($folder_path,-1) != '/') $folder_path .= '/'; //* Check if the resulting path is inside the docroot @@ -1715,15 +1779,18 @@ class apache2_plugin { return false; } + $web_folder = 'web'; + if($website['type'] == 'vhostsubdomain') $web_folder = $website['web_folder']; + //* Get the folder path. if(substr($data['old']['path'],0,1) == '/') $data['old']['path'] = substr($data['old']['path'],1); if(substr($data['old']['path'],-1) == '/') $data['old']['path'] = substr($data['old']['path'],0,-1); - $old_folder_path = realpath($website['document_root'].'/web/'.$data['old']['path']); + $old_folder_path = realpath($website['document_root'].'/' . $web_folder . '/'.$data['old']['path']); if(substr($old_folder_path,-1) != '/') $old_folder_path .= '/'; if(substr($data['new']['path'],0,1) == '/') $data['new']['path'] = substr($data['new']['path'],1); if(substr($data['new']['path'],-1) == '/') $data['new']['path'] = substr($data['new']['path'],0,-1); - $new_folder_path = escapeshellcmd($website['document_root'].'/web/'.$data['new']['path']); + $new_folder_path = escapeshellcmd($website['document_root'].'/' . $web_folder . '/'.$data['new']['path']); if(substr($new_folder_path,-1) != '/') $new_folder_path .= '/'; //* Check if the resulting path is inside the docroot @@ -2075,9 +2142,11 @@ class apache2_plugin { private function awstats_update ($data,$web_config) { global $app; + $web_folder = $data['new']['web_folder']; + if($data['new']['type'] == 'vhost') $web_folder = 'web'; $awstats_conf_dir = $web_config['awstats_conf_dir']; - if(!is_dir($data['new']['document_root']."/web/stats/")) mkdir($data['new']['document_root']."/web/stats"); + if(!is_dir($data['new']['document_root']."/" . $web_folder . "/stats/")) mkdir($data['new']['document_root']."/" . $web_folder . "/stats"); if(!@is_file($awstats_conf_dir.'/awstats.'.$data['new']['domain'].'.conf') || ($data['old']['domain'] != '' && $data['new']['domain'] != $data['old']['domain'])) { if ( @is_file($awstats_conf_dir.'/awstats.'.$data['old']['domain'].'.conf') ) { $app->system->unlink($awstats_conf_dir.'/awstats.'.$data['old']['domain'].'.conf'); @@ -2093,8 +2162,8 @@ class apache2_plugin { $app->log('Created AWStats config file: '.$awstats_conf_dir.'/awstats.'.$data['new']['domain'].'.conf',LOGLEVEL_DEBUG); } - if(is_file($data['new']['document_root']."/web/stats/index.html")) $app->system->unlink($data['new']['document_root']."/web/stats/index.html"); - $app->system->copy("/usr/local/ispconfig/server/conf/awstats_index.php.master",$data['new']['document_root']."/web/stats/index.php"); + if(is_file($data['new']['document_root']."/" . $web_folder . "/stats/index.html")) $app->system->unlink($data['new']['document_root']."/" . $web_folder . "/stats/index.html"); + $app->system->copy("/usr/local/ispconfig/server/conf/awstats_index.php.master",$data['new']['document_root']."/" . $web_folder . "/stats/index.php"); } //* Delete the awstats configuration file diff --git a/server/plugins-available/nginx_plugin.inc.php b/server/plugins-available/nginx_plugin.inc.php index 5050e01ec0..424d96fa8e 100644 --- a/server/plugins-available/nginx_plugin.inc.php +++ b/server/plugins-available/nginx_plugin.inc.php @@ -91,6 +91,8 @@ class nginx_plugin { // Handle the creation of SSL certificates function ssl($event_name,$data) { global $app, $conf; + + $app->uses('system'); // load the server configuration options $app->uses('getconf'); @@ -99,9 +101,11 @@ class nginx_plugin { $app->log("CA path error, file does not exist:".$web_config['CA_path'].'/openssl.conf',LOGLEVEL_ERROR); //* Only vhosts can have a ssl cert - if($data["new"]["type"] != "vhost") return; + if($data["new"]["type"] != "vhost" && $data["new"]["type"] != "vhostsubdomain") return; - if(!is_dir($data['new']['document_root'].'/ssl')) exec('mkdir -p '.$data['new']['document_root'].'/ssl'); + // if(!is_dir($data['new']['document_root'].'/ssl')) exec('mkdir -p '.$data['new']['document_root'].'/ssl'); + if(!is_dir($data['new']['document_root'].'/ssl')) $app->system->mkdirpath($data['new']['document_root'].'/ssl'); + $ssl_dir = $data['new']['document_root'].'/ssl'; $domain = $data['new']['ssl_domain']; $key_file = $ssl_dir.'/'.$domain.'.key.org'; @@ -119,7 +123,7 @@ class nginx_plugin { $rand_data .= md5(uniqid(microtime(),1)); $rand_data .= md5(uniqid(microtime(),1)); } - file_put_contents($rand_file, $rand_data); + $app->system->file_put_contents($rand_file, $rand_data); $ssl_password = substr(md5(uniqid(microtime(),1)), 0, 15); @@ -134,11 +138,11 @@ class nginx_plugin { output_password = $ssl_password [ req_distinguished_name ] - C = ".$data['new']['ssl_country']." - ST = ".$data['new']['ssl_state']." - L = ".$data['new']['ssl_locality']." - O = ".$data['new']['ssl_organisation']." - OU = ".$data['new']['ssl_organisation_unit']." + C = ".trim($data['new']['ssl_country'])." + ST = ".trim($data['new']['ssl_state'])." + L = ".trim($data['new']['ssl_locality'])." + O = ".trim($data['new']['ssl_organisation'])." + OU = ".trim($data['new']['ssl_organisation_unit'])." CN = $domain emailAddress = webmaster@".$data['new']['domain']." @@ -146,7 +150,7 @@ class nginx_plugin { challengePassword = A challenge password"; $ssl_cnf_file = $ssl_dir.'/openssl.conf'; - file_put_contents($ssl_cnf_file,$ssl_cnf); + $app->system->file_put_contents($ssl_cnf_file,$ssl_cnf); $rand_file = escapeshellcmd($rand_file); $key_file = escapeshellcmd($key_file); @@ -156,7 +160,7 @@ class nginx_plugin { $config_file = escapeshellcmd($ssl_cnf_file); $crt_file = escapeshellcmd($crt_file); - if(is_file($ssl_cnf_file)) { + if(is_file($ssl_cnf_file) && !is_link($ssl_cnf_file)) { exec("openssl genrsa -des3 -rand $rand_file -passout pass:$ssl_password -out $key_file 2048"); exec("openssl req -new -passin pass:$ssl_password -passout pass:$ssl_password -key $key_file -out $csr_file -days $ssl_days -config $config_file"); @@ -175,16 +179,17 @@ class nginx_plugin { } - exec('chmod 400 '.$key_file2); - @unlink($config_file); - @unlink($rand_file); - $ssl_request = $app->db->quote(file_get_contents($csr_file)); - $ssl_cert = $app->db->quote(file_get_contents($crt_file)); + $app->system->chmod($key_file2,0400); + @$app->system->unlink($config_file); + @$app->system->unlink($rand_file); + $ssl_request = $app->db->quote($app->system->file_get_contents($csr_file)); + $ssl_cert = $app->db->quote($app->system->file_get_contents($crt_file)); + $ssl_key2 = $app->db->quote($app->system->file_get_contents($key_file2)); /* Update the DB of the (local) Server */ - $app->db->query("UPDATE web_domain SET ssl_request = '$ssl_request', ssl_cert = '$ssl_cert' WHERE domain = '".$data['new']['domain']."'"); + $app->db->query("UPDATE web_domain SET ssl_request = '$ssl_request', ssl_cert = '$ssl_cert', ssl_key = '$ssl_key2' WHERE domain = '".$data['new']['domain']."'"); $app->db->query("UPDATE web_domain SET ssl_action = '' WHERE domain = '".$data['new']['domain']."'"); /* Update also the master-DB of the Server-Farm */ - $app->dbmaster->query("UPDATE web_domain SET ssl_request = '$ssl_request', ssl_cert = '$ssl_cert' WHERE domain = '".$data['new']['domain']."'"); + $app->dbmaster->query("UPDATE web_domain SET ssl_request = '$ssl_request', ssl_cert = '$ssl_cert', ssl_key = '$ssl_key2' WHERE domain = '".$data['new']['domain']."'"); $app->dbmaster->query("UPDATE web_domain SET ssl_action = '' WHERE domain = '".$data['new']['domain']."'"); } @@ -192,6 +197,8 @@ class nginx_plugin { if($data["new"]["ssl_action"] == 'save') { $ssl_dir = $data["new"]["document_root"]."/ssl"; $domain = ($data["new"]["ssl_domain"] != '')?$data["new"]["ssl_domain"]:$data["new"]["domain"]; + $key_file = $ssl_dir.'/'.$domain.'.key.org'; + $key_file2 = $ssl_dir.'/'.$domain.'.key'; $csr_file = $ssl_dir.'/'.$domain.".csr"; $crt_file = $ssl_dir.'/'.$domain.".crt"; //$bundle_file = $ssl_dir.'/'.$domain.".bundle"; @@ -211,6 +218,7 @@ class nginx_plugin { } /* Update the DB of the (local) Server */ $app->db->query("UPDATE web_domain SET ssl_action = '' WHERE domain = '".$data['new']['domain']."'"); + /* Update also the master-DB of the Server-Farm */ $app->dbmaster->query("UPDATE web_domain SET ssl_action = '' WHERE domain = '".$data['new']['domain']."'"); $app->log('Saving SSL Cert for: '.$domain,LOGLEVEL_DEBUG); @@ -228,9 +236,9 @@ class nginx_plugin { exec("openssl ca -batch -config ".$web_config['CA_path']."/openssl.cnf -passin pass:".$web_config['CA_pass']." -revoke $crt_file"); $app->log("Revoking CA-signed SSL Cert for: $domain",LOGLEVEL_DEBUG); }; - unlink($csr_file); - unlink($crt_file); - //unlink($bundle_file); + $app->system->unlink($csr_file); + $app->system->unlink($crt_file); + //$app->system->unlink($bundle_file); /* Update the DB of the (local) Server */ $app->db->query("UPDATE web_domain SET ssl_request = '', ssl_cert = '' WHERE domain = '".$data['new']['domain']."'"); $app->db->query("UPDATE web_domain SET ssl_action = '' WHERE domain = '".$data['new']['domain']."'"); @@ -265,7 +273,7 @@ class nginx_plugin { if($this->action != 'insert') $this->action = 'update'; - if($data['new']['type'] != 'vhost' && $data['new']['parent_domain_id'] > 0) { + if($data['new']['type'] != 'vhost' && $data['new']['type'] != 'vhostsubdomain' && $data['new']['parent_domain_id'] > 0) { $old_parent_domain_id = intval($data['old']['parent_domain_id']); $new_parent_domain_id = intval($data['new']['parent_domain_id']); @@ -306,6 +314,58 @@ class nginx_plugin { $app->log('Websites cannot be owned by the root user or group.',LOGLEVEL_WARN); return 0; } + if(trim($data['new']['domain']) == '') { + $app->log('domain is empty',LOGLEVEL_WARN); + return 0; + } + + $web_folder = 'web'; + $log_folder = 'log'; + if($data['new']['type'] == 'vhostsubdomain') { + $web_folder = $data['new']['web_folder']; + $log_folder .= '_web' . $data['new']['domain_id']; + } + + // Create group and user, if not exist + $app->uses('system'); + + if($web_config['connect_userid_to_webid'] == 'y') { + //* Calculate the uid and gid + $connect_userid_to_webid_start = ($web_config['connect_userid_to_webid_start'] < 1000)?1000:intval($web_config['connect_userid_to_webid_start']); + $fixed_uid_gid = intval($connect_userid_to_webid_start + $data['new']['domain_id']); + $fixed_uid_param = '--uid '.$fixed_uid_gid; + $fixed_gid_param = '--gid '.$fixed_uid_gid; + + //* Check if a ispconfigend user and group exists and create them + if(!$app->system->is_group('ispconfigend')) { + exec('groupadd --gid '.($connect_userid_to_webid_start + 10000).' ispconfigend'); + } + if(!$app->system->is_user('ispconfigend')) { + exec('useradd -g ispconfigend -d /usr/local/ispconfig --uid '.($connect_userid_to_webid_start + 10000).' ispconfigend'); + } + } else { + $fixed_uid_param = ''; + $fixed_gid_param = ''; + } + + $groupname = escapeshellcmd($data['new']['system_group']); + if($data['new']['system_group'] != '' && !$app->system->is_group($data['new']['system_group'])) { + exec('groupadd '.$fixed_gid_param.' '.$groupname); + if($apache_chrooted) $this->_exec('chroot '.escapeshellcmd($web_config['website_basedir']).' groupadd '.$groupname); + $app->log('Adding the group: '.$groupname,LOGLEVEL_DEBUG); + } + + $username = escapeshellcmd($data['new']['system_user']); + if($data['new']['system_user'] != '' && !$app->system->is_user($data['new']['system_user'])) { + if($web_config['add_web_users_to_sshusers_group'] == 'y') { + exec('useradd -d '.escapeshellcmd($data['new']['document_root'])." -g $groupname $fixed_uid_param -G sshusers $username -s /bin/false"); + if($apache_chrooted) $this->_exec('chroot '.escapeshellcmd($web_config['website_basedir']).' useradd -d '.escapeshellcmd($data['new']['document_root'])." -g $groupname $fixed_uid_param -G sshusers $username -s /bin/false"); + } else { + exec('useradd -d '.escapeshellcmd($data['new']['document_root'])." -g $groupname $fixed_uid_param $username -s /bin/false"); + if($apache_chrooted) $this->_exec('chroot '.escapeshellcmd($web_config['website_basedir']).' useradd -d '.escapeshellcmd($data['new']['document_root'])." -g $groupname $fixed_uid_param $username -s /bin/false"); + } + $app->log('Adding the user: '.$username,LOGLEVEL_DEBUG); + } //* If the client of the site has been changed, we have a change of the document root if($this->action == 'update' && $data['new']['document_root'] != $data['old']['document_root']) { @@ -339,16 +399,17 @@ class nginx_plugin { $tmp_docroot = explode('/',$data['old']['document_root']); unset($tmp_docroot[count($tmp_docroot)-1]); $old_dir = implode('/',$tmp_docroot); - + //* Check if there is already some data in the new docroot and rename it as we need a clean path to move the existing site to the new path if(@is_dir($data['new']['document_root'])) { - rename($data['new']['document_root'],$data['new']['document_root'].'_bak_'.date('Y_m_d')); + $app->system->rename($data['new']['document_root'],$data['new']['document_root'].'_bak_'.date('Y_m_d')); $app->log('Renaming existing directory in new docroot location. mv '.$data['new']['document_root'].' '.$data['new']['document_root'].'_bak_'.date('Y_m_d'),LOGLEVEL_DEBUG); } //* Create new base directory, if it does not exist yet - if(!is_dir($new_dir)) exec('mkdir -p '.$new_dir); - exec('mv '.$data['old']['document_root'].' '.$new_dir); + if(!is_dir($new_dir)) $app->system->mkdirpath($new_dir); + //exec('mv '.$data['old']['document_root'].' '.$new_dir); + $app->system->rename($data['old']['document_root'],$new_dir); $app->log('Moving site to new document root: mv '.$data['old']['document_root'].' '.$new_dir,LOGLEVEL_DEBUG); // Handle the change in php_open_basedir @@ -372,40 +433,41 @@ class nginx_plugin { //print_r($data); // Check if the directories are there and create them if necessary. - if(!is_dir($data['new']['document_root'].'/web')) exec('mkdir -p '.$data['new']['document_root'].'/web'); - if(!is_dir($data['new']['document_root'].'/web/error') and $data['new']['errordocs']) exec('mkdir -p '.$data['new']['document_root'].'/web/error'); - //if(!is_dir($data['new']['document_root'].'/log')) exec('mkdir -p '.$data['new']['document_root'].'/log'); - if(!is_dir($data['new']['document_root'].'/ssl')) exec('mkdir -p '.$data['new']['document_root'].'/ssl'); - if(!is_dir($data['new']['document_root'].'/cgi-bin')) exec('mkdir -p '.$data['new']['document_root'].'/cgi-bin'); - if(!is_dir($data['new']['document_root'].'/tmp')) exec('mkdir -p '.$data['new']['document_root'].'/tmp'); - + if(!is_dir($data['new']['document_root'].'/' . $web_folder)) $app->system->mkdirpath($data['new']['document_root'].'/' . $web_folder); + if(!is_dir($data['new']['document_root'].'/' . $web_folder . '/error') and $data['new']['errordocs']) $app->system->mkdirpath($data['new']['document_root'].'/' . $web_folder . '/error'); + //if(!is_dir($data['new']['document_root'].'/'.$log_folder)) exec('mkdir -p '.$data['new']['document_root'].'/'.$log_folder); + if(!is_dir($data['new']['document_root'].'/ssl')) $app->system->mkdirpath($data['new']['document_root'].'/ssl'); + if(!is_dir($data['new']['document_root'].'/cgi-bin')) $app->system->mkdirpath($data['new']['document_root'].'/cgi-bin'); + if(!is_dir($data['new']['document_root'].'/tmp')) $app->system->mkdirpath($data['new']['document_root'].'/tmp'); + + //* Create the new private directory + if(!is_dir($data['new']['document_root'].'/private')) { + $app->system->mkdirpath($data['new']['document_root'].'/private'); + $app->system->chmod($data['new']['document_root'].'/private',0710); + $app->system->chown($data['new']['document_root'].'/private',$username); + $app->system->chgrp($data['new']['document_root'].'/private',$groupname); + } + + // 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')) unlink($data['old']['document_root'].'/log'); - } - - // Create the symlink for the logfiles - if(!is_dir('/var/log/ispconfig/httpd/'.$data['new']['domain'])) exec('mkdir -p /var/log/ispconfig/httpd/'.$data['new']['domain']); - if(!is_link($data['new']['document_root'].'/log')) { - exec('ln -s /var/log/ispconfig/httpd/'.$data['new']['domain'].' '.$data['new']['document_root'].'/log'); - $app->log('Creating symlink: ln -s /var/log/ispconfig/httpd/'.$data['new']['domain'].' '.$data['new']['document_root'].'/log',LOGLEVEL_DEBUG); - } - /* - // Create the symlink for the logfiles - // This does not work as vlogger cannot log trough symlinks. - if($this->action == 'update' && $data['old']['domain'] != '' && $data['new']['domain'] != $data['old']['domain']) { - if(is_dir($data['old']['document_root'].'/log')) exec('rm -rf '.$data['old']['document_root'].'/log'); - if(is_link('/var/log/ispconfig/httpd/'.$data['old']['domain'])) unlink('/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); } - // Create the symlink for the logfiles - if(!is_dir($data['new']['document_root'].'/log')) exec('mkdir -p '.$data['new']['document_root'].'/log'); - if(!is_link('/var/log/ispconfig/httpd/'.$data['new']['domain'])) { - exec('ln -s '.$data['new']['document_root'].'/log /var/log/ispconfig/httpd/'.$data['new']['domain']); - $app->log('Creating symlink: ln -s '.$data['new']['document_root'].'/log /var/log/ispconfig/httpd/'.$data['new']['domain'],LOGLEVEL_DEBUG); + //* Create the log dir if nescessary and mount it + if(!is_dir('/var/log/ispconfig/httpd/'.$data['new']['domain'])) exec('mkdir -p /var/log/ispconfig/httpd/'.$data['new']['domain']); + if(!is_dir($data['new']['document_root'].'/'.$log_folder) || is_link($data['new']['document_root'].'/'.$log_folder)) { + if(is_link($data['new']['document_root'].'/'.$log_folder)) unlink($data['new']['document_root'].'/'.$log_folder); + $app->system->mkdir($data['new']['document_root'].'/'.$log_folder); + $app->system->chown($data['new']['document_root'].'/'.$log_folder,'root'); + $app->system->chgrp($data['new']['document_root'].'/'.$log_folder,'root'); + $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 0 0'; + $app->system->replaceLine('/etc/fstab',$fstab_line,$fstab_line,1,1); } - */ // Get the client ID $client = $app->dbmaster->queryOneRecord('SELECT client_id FROM sys_group WHERE sys_group.groupid = '.intval($data['new']['sys_groupid'])); @@ -440,11 +502,17 @@ class nginx_plugin { if(substr($tmp_symlink, -1, 1) == '/') $tmp_symlink = substr($tmp_symlink, 0, -1); //* Remove symlink if target folder has been changed. if($data['old']['document_root'] != '' && $data['old']['document_root'] != $data['new']['document_root'] && is_link($tmp_symlink)) { - unlink($tmp_symlink); + $app->system->unlink($tmp_symlink); } // create the symlinks, if not exist if(!is_link($tmp_symlink)) { - exec('ln -s '.escapeshellcmd($data['new']['document_root']).'/ '.escapeshellcmd($tmp_symlink)); +// exec("ln -s ".escapeshellcmd($data["new"]["document_root"])."/ ".escapeshellcmd($tmp_symlink)); + if ($web_config["website_symlinks_rel"] == 'y') { + $this->create_relative_link(escapeshellcmd($data["new"]["document_root"]), escapeshellcmd($tmp_symlink)); + } else { + exec("ln -s ".escapeshellcmd($data["new"]["document_root"])."/ ".escapeshellcmd($tmp_symlink)); + } + $app->log('Creating symlink: ln -s '.$data['new']['document_root'].'/ '.$tmp_symlink,LOGLEVEL_DEBUG); } } @@ -458,17 +526,17 @@ class nginx_plugin { // setting a local var here // normally $conf['templates'] = "/usr/local/ispconfig/server/conf"; - - if($this->action == 'insert' && $data['new']['type'] == 'vhost') { - // Copy the error pages + if($this->action == 'insert' && ($data['new']['type'] == 'vhost' || $data['new']['type'] == 'vhostsubdomain')) { + + // Copy the error pages if($data['new']['errordocs']) { - $error_page_path = escapeshellcmd($data['new']['document_root']).'/web/error/'; - if (file_exists($conf['rootpath'].'/conf-custom/error/'.substr(escapeshellcmd($conf['language']),0,2))) { - exec('cp ' . $conf['rootpath'].'/conf-custom/error/'.substr(escapeshellcmd($conf['language']),0,2).'/* '.$error_page_path); + $error_page_path = escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/error/'; + if (file_exists($conf['rootpath'] . '/conf-custom/error/'.substr(escapeshellcmd($conf['language']),0,2))) { + exec('cp ' . $conf['rootpath'] . '/conf-custom/error/'.substr(escapeshellcmd($conf['language']),0,2).'/* '.$error_page_path); } else { - if (file_exists($conf['rootpath'].'/conf-custom/error/400.html')) { - exec('cp '. $conf['rootpath'].'/conf-custom/error/*.html '.$error_page_path); + if (file_exists($conf['rootpath'] . '/conf-custom/error/400.html')) { + exec('cp '. $conf['rootpath'] . '/conf-custom/error/*.html '.$error_page_path); } else { exec('cp ' . $conf['rootpath'] . '/conf/error/'.substr(escapeshellcmd($conf['language']),0,2).'/* '.$error_page_path); @@ -478,35 +546,35 @@ class nginx_plugin { } if (file_exists($conf['rootpath'] . '/conf-custom/index/standard_index.html_'.substr(escapeshellcmd($conf['language']),0,2))) { - exec('cp ' . $conf['rootpath'] . '/conf-custom/index/standard_index.html_'.substr(escapeshellcmd($conf['language']),0,2).' '.escapeshellcmd($data['new']['document_root']).'/web/index.html'); + exec('cp ' . $conf['rootpath'] . '/conf-custom/index/standard_index.html_'.substr(escapeshellcmd($conf['language']),0,2).' '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html'); if(is_file($conf['rootpath'] . '/conf-custom/index/favicon.ico')) { - exec('cp ' . $conf['rootpath'] . '/conf-custom/index/favicon.ico '.escapeshellcmd($data['new']['document_root']).'/web/'); + exec('cp ' . $conf['rootpath'] . '/conf-custom/index/favicon.ico '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/'); } if(is_file($conf['rootpath'] . '/conf-custom/index/robots.txt')) { - exec('cp ' . $conf['rootpath'] . '/conf-custom/index/robots.txt '.escapeshellcmd($data['new']['document_root']).'/web/'); + exec('cp ' . $conf['rootpath'] . '/conf-custom/index/robots.txt '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/'); } if(is_file($conf['rootpath'] . '/conf-custom/index/.htaccess')) { - exec('cp ' . $conf['rootpath'] . '/conf-custom/index/.htaccess '.escapeshellcmd($data['new']['document_root']).'/web/'); + exec('cp ' . $conf['rootpath'] . '/conf-custom/index/.htaccess '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/'); } } else { if (file_exists($conf['rootpath'] . '/conf-custom/index/standard_index.html')) { - exec('cp ' . $conf['rootpath'] . '/conf-custom/index/standard_index.html '.escapeshellcmd($data['new']['document_root']).'/web/index.html'); + exec('cp ' . $conf['rootpath'] . '/conf-custom/index/standard_index.html '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html'); } else { - exec('cp ' . $conf['rootpath'] . '/conf/index/standard_index.html_'.substr(escapeshellcmd($conf['language']),0,2).' '.escapeshellcmd($data['new']['document_root']).'/web/index.html'); - if(is_file($conf['rootpath'] . '/conf/index/favicon.ico')) exec('cp ' . $conf['rootpath'] . '/conf/index/favicon.ico '.escapeshellcmd($data['new']['document_root']).'/web/'); - if(is_file($conf['rootpath'] . '/conf/index/robots.txt')) exec('cp ' . $conf['rootpath'] . '/conf/index/robots.txt '.escapeshellcmd($data['new']['document_root']).'/web/'); - if(is_file($conf['rootpath'] . '/conf/index/.htaccess')) exec('cp ' . $conf['rootpath'] . '/conf/index/.htaccess '.escapeshellcmd($data['new']['document_root']).'/web/'); + exec('cp ' . $conf['rootpath'] . '/conf/index/standard_index.html_'.substr(escapeshellcmd($conf['language']),0,2).' '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html'); + if(is_file($conf['rootpath'] . '/conf/index/favicon.ico')) exec('cp ' . $conf['rootpath'] . '/conf/index/favicon.ico '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/'); + if(is_file($conf['rootpath'] . '/conf/index/robots.txt')) exec('cp ' . $conf['rootpath'] . '/conf/index/robots.txt '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/'); + if(is_file($conf['rootpath'] . '/conf/index/.htaccess')) exec('cp ' . $conf['rootpath'] . '/conf/index/.htaccess '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/'); } } - exec('chmod -R a+r '.escapeshellcmd($data['new']['document_root']).'/web/'); + exec('chmod -R a+r '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/'); //** Copy the error documents on update when the error document checkbox has been activated and was deactivated before - } elseif ($this->action == 'update' && $data['new']['type'] == 'vhost' && $data['old']['errordocs'] == 0 && $data['new']['errordocs'] == 1) { - - $error_page_path = escapeshellcmd($data['new']['document_root']).'/web/error/'; + } elseif ($this->action == 'update' && ($data['new']['type'] == 'vhost' || $data['new']['type'] == 'vhostsubdomain') && $data['old']['errordocs'] == 0 && $data['new']['errordocs'] == 1) { + + $error_page_path = escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/error/'; if (file_exists($conf['rootpath'] . '/conf-custom/error/'.substr(escapeshellcmd($conf['language']),0,2))) { exec('cp ' . $conf['rootpath'] . '/conf-custom/error/'.substr(escapeshellcmd($conf['language']),0,2).'/* '.$error_page_path); } @@ -522,47 +590,6 @@ class nginx_plugin { exec('chown -R '.$data['new']['system_user'].':'.$data['new']['system_group'].' '.$error_page_path); } // end copy error docs - // Create group and user, if not exist - $app->uses('system'); - - if($web_config['connect_userid_to_webid'] == 'y') { - //* Calculate the uid and gid - $connect_userid_to_webid_start = ($web_config['connect_userid_to_webid_start'] < 1000)?1000:intval($web_config['connect_userid_to_webid_start']); - $fixed_uid_gid = intval($connect_userid_to_webid_start + $data['new']['domain_id']); - $fixed_uid_param = '--uid '.$fixed_uid_gid; - $fixed_gid_param = '--gid '.$fixed_uid_gid; - - //* Check if a ispconfigend user and group exists and create them - if(!$app->system->is_group('ispconfigend')) { - exec('groupadd --gid '.($connect_userid_to_webid_start + 10000).' ispconfigend'); - } - if(!$app->system->is_user('ispconfigend')) { - exec('useradd -g ispconfigend -d /usr/local/ispconfig --uid '.($connect_userid_to_webid_start + 10000).' ispconfigend'); - } - } else { - $fixed_uid_param = ''; - $fixed_gid_param = ''; - } - - $groupname = escapeshellcmd($data['new']['system_group']); - if($data['new']['system_group'] != '' && !$app->system->is_group($data['new']['system_group'])) { - exec('groupadd '.$fixed_gid_param.' '.$groupname); - if($apache_chrooted) $this->_exec('chroot '.escapeshellcmd($web_config['website_basedir']).' groupadd '.$groupname); - $app->log('Adding the group: '.$groupname,LOGLEVEL_DEBUG); - } - - $username = escapeshellcmd($data['new']['system_user']); - if($data['new']['system_user'] != '' && !$app->system->is_user($data['new']['system_user'])) { - if($web_config['add_web_users_to_sshusers_group'] == 'y') { - exec('useradd -d '.escapeshellcmd($data['new']['document_root'])." -g $groupname $fixed_uid_param -G sshusers $username -s /bin/false"); - if($nginx_chrooted) $this->_exec('chroot '.escapeshellcmd($web_config['website_basedir']).' useradd -d '.escapeshellcmd($data['new']['document_root'])." -g $groupname $fixed_uid_param -G sshusers $username -s /bin/false"); - } else { - exec('useradd -d '.escapeshellcmd($data['new']['document_root'])." -g $groupname $fixed_uid_param $username -s /bin/false"); - if($nginx_chrooted) $this->_exec('chroot '.escapeshellcmd($web_config['website_basedir']).' useradd -d '.escapeshellcmd($data['new']['document_root'])." -g $groupname $fixed_uid_param $username -s /bin/false"); - } - $app->log('Adding the user: '.$username,LOGLEVEL_DEBUG); - } - // Set the quota for the user if($username != '' && $app->system->is_user($username)) { if($data['new']['hd_quota'] > 0) { @@ -577,29 +604,36 @@ class nginx_plugin { if($this->action == 'insert' || $data["new"]["system_user"] != $data["old"]["system_user"]) { // Chown and chmod the directories below the document root - $this->_exec('chown -R '.$username.':'.$groupname.' '.escapeshellcmd($data['new']['document_root']).'/web'); + $this->_exec('chown -R '.$username.':'.$groupname.' '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder); // The document root itself has to be owned by root in normal level and by the web owner in security level 20 if($web_config['security_level'] == 20) { - $this->_exec('chown '.$username.':'.$groupname.' '.escapeshellcmd($data['new']['document_root']).'/web'); + $this->_exec('chown '.$username.':'.$groupname.' '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder); } else { - $this->_exec('chown root:root '.escapeshellcmd($data['new']['document_root']).'/web'); + $this->_exec('chown root:root '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder); } } - + //* If the security level is set to high if(($this->action == 'insert' && $data['new']['type'] == 'vhost') or ($web_config['set_folder_permissions_on_update'] == 'y' && $data['new']['type'] == 'vhost')) { + //* Check if we have the new private folder and create it if nescessary + if(!is_dir($data['new']['document_root'].'/private')) $app->system->mkdir($data['new']['document_root'].'/private'); + if($web_config['security_level'] == 20) { - - $this->_exec('chmod 751 '.escapeshellcmd($data['new']['document_root'])); - $this->_exec('chmod 751 '.escapeshellcmd($data['new']['document_root']).'/*'); - $this->_exec('chmod 710 '.escapeshellcmd($data['new']['document_root'].'/web')); + + $app->system->chmod($data['new']['document_root'],0755); + $app->system->chmod($data['new']['document_root'].'/web',0710); + $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); // make tmp directory writable for nginx and the website users - $this->_exec('chmod 777 '.escapeshellcmd($data['new']['document_root'].'/tmp')); + $app->system->chmod($data['new']['document_root'].'/tmp',0777); - // Set Log symlink to 755 to make the logs accessible by the FTP user - $this->_exec("chmod 755 ".escapeshellcmd($data["new"]["document_root"])."/log"); - + // Set Log directory to 755 to make the logs accessible by the FTP user + if(realpath($data['new']['document_root'].'/'.$log_folder) == '/var/log/ispconfig/httpd/'.$data['new']['domain'].'/error.log') { + $app->system->chmod($data['new']['document_root'].'/'.$log_folder,0755); + } + if($web_config['add_web_users_to_sshusers_group'] == 'y') { $command = 'usermod'; $command .= ' --groups sshusers'; @@ -624,7 +658,8 @@ class nginx_plugin { //* Chown all default directories $this->_exec('chown '.$username.':'.$groupname.' '.escapeshellcmd($data['new']['document_root'])); - $this->_exec('chown '.$username.':'.$groupname.' '.escapeshellcmd($data['new']['document_root'].'/cgi-bin')); + $app->system->chown($data['new']['document_root'].'/cgi-bin',$username); + $app->system->chgrp($data['new']['document_root'].'/cgi-bin',$groupname); $this->_exec('chown '.$username.':'.$groupname.' '.escapeshellcmd($data['new']['document_root'].'/log')); $this->_exec('chown '.$username.':'.$groupname.' '.escapeshellcmd($data['new']['document_root'].'/ssl')); $this->_exec('chown '.$username.':'.$groupname.' '.escapeshellcmd($data['new']['document_root'].'/tmp')); @@ -662,7 +697,25 @@ class nginx_plugin { $this->_exec('chown '.$username.':'.$groupname.' '.escapeshellcmd($data['new']['document_root'].'/ssl')); $this->_exec('chown '.$username.':'.$groupname.' '.escapeshellcmd($data['new']['document_root'].'/web')); } - } + } elseif(($this->action == 'insert' && $data['new']['type'] == 'vhostsubdomain') or ($web_config['set_folder_permissions_on_update'] == 'y' && $data['new']['type'] == 'vhostsubdomain')) { + if($web_config['security_level'] == 20) { + $app->system->chmod($data['new']['document_root'].'/' . $web_folder,0710); + $app->system->chown($data['new']['document_root'].'/' . $web_folder,$username); + $app->system->chgrp($data['new']['document_root'].'/' . $web_folder,$groupname); + $app->system->chown($data['new']['document_root'].'/' . $web_folder . '/error',$username); + $app->system->chgrp($data['new']['document_root'].'/' . $web_folder . '/error',$groupname); + $app->system->chown($data['new']['document_root'].'/' . $web_folder . '/stats',$username); + $app->system->chgrp($data['new']['document_root'].'/' . $web_folder . '/stats',$groupname); + } else { + $app->system->chmod($data['new']['document_root'].'/' . $web_folder,0755); + $app->system->chown($data['new']['document_root'].'/' . $web_folder,$username); + $app->system->chgrp($data['new']['document_root'].'/' . $web_folder,$groupname); + $app->system->chown($data['new']['document_root'].'/' . $web_folder . '/error',$username); + $app->system->chgrp($data['new']['document_root'].'/' . $web_folder . '/error',$groupname); + $app->system->chown($data['new']['document_root'].'/' . $web_folder . '/stats',$username); + $app->system->chgrp($data['new']['document_root'].'/' . $web_folder . '/stats',$groupname); + } + } // Change the ownership of the error log to the owner of the website if(!@is_file($data['new']['document_root'].'/log/error.log')) exec('touch '.escapeshellcmd($data['new']['document_root']).'/log/error.log'); @@ -675,7 +728,7 @@ class nginx_plugin { if(!is_dir($web_config['website_basedir'].'/conf')) mkdir($web_config['website_basedir'].'/conf'); if(trim($data['new']['custom_php_ini']) != '') { $has_custom_php_ini = true; - if(!is_dir($custom_php_ini_dir)) mkdir($custom_php_ini_dir); + if(!is_dir($custom_php_ini_dir)) $app->system->mkdir($custom_php_ini_dir); $php_ini_content = ''; if($data['new']['php'] == 'mod') { $master_php_ini_path = $web_config['php_ini_path_apache']; @@ -687,13 +740,13 @@ class nginx_plugin { } } if($master_php_ini_path != '' && substr($master_php_ini_path,-7) == 'php.ini' && is_file($master_php_ini_path)) { - $php_ini_content .= file_get_contents($master_php_ini_path)."\n"; + $php_ini_content .= $app->system->file_get_contents($master_php_ini_path)."\n"; } - $php_ini_content .= trim($data['new']['custom_php_ini']); - file_put_contents($custom_php_ini_dir.'/php.ini',$php_ini_content); + $php_ini_content .= str_replace("\r",'',trim($data['new']['custom_php_ini'])); + $app->system->file_put_contents($custom_php_ini_dir.'/php.ini',$php_ini_content); } else { $has_custom_php_ini = false; - if(is_file($custom_php_ini_dir.'/php.ini')) unlink($custom_php_ini_dir.'/php.ini'); + if(is_file($custom_php_ini_dir.'/php.ini')) $app->system->unlink($custom_php_ini_dir.'/php.ini'); } */ @@ -704,8 +757,9 @@ class nginx_plugin { $tpl->newTemplate('nginx_vhost.conf.master'); $vhost_data = $data['new']; - $vhost_data['web_document_root'] = $data['new']['document_root'].'/web'; - $vhost_data['web_document_root_www'] = $web_config['website_basedir'].'/'.$data['new']['domain'].'/web'; + //unset($vhost_data['ip_address']); + $vhost_data['web_document_root'] = $data['new']['document_root'].'/' . $web_folder; + $vhost_data['web_document_root_www'] = $web_config['website_basedir'].'/'.$data['new']['domain'].'/' . $web_folder; $vhost_data['web_basedir'] = $web_config['website_basedir']; // IPv6 @@ -930,7 +984,7 @@ class nginx_plugin { } // 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'"); + $aliases = $app->db->queryAllRecords('SELECT * FROM web_domain WHERE parent_domain_id = '.$data['new']['domain_id']." AND active = 'y' AND type != 'vhostsubdomain'"); switch($data['new']['subdomain']) { case 'www': $server_alias[] = 'www.'.$data['new']['domain'].' '; @@ -1100,12 +1154,12 @@ class nginx_plugin { if($data['new']['subdomain'] != $data['old']['subdomain'] or $data['new']['active'] == 'n') { $vhost_symlink = escapeshellcmd($web_config['nginx_vhost_conf_enabled_dir'].'/900-'.$data['new']['domain'].'.vhost'); if(is_link($vhost_symlink)) { - unlink($vhost_symlink); + $app->system->unlink($vhost_symlink); $app->log('Removing symlink: '.$vhost_symlink.'->'.$vhost_file,LOGLEVEL_DEBUG); } $vhost_symlink = escapeshellcmd($web_config['nginx_vhost_conf_enabled_dir'].'/100-'.$data['new']['domain'].'.vhost'); if(is_link($vhost_symlink)) { - unlink($vhost_symlink); + $app->system->unlink($vhost_symlink); $app->log('Removing symlink: '.$vhost_symlink.'->'.$vhost_file,LOGLEVEL_DEBUG); } } @@ -1125,21 +1179,21 @@ class nginx_plugin { if($this->action == 'update' && $data['old']['domain'] != '' && $data['new']['domain'] != $data['old']['domain']) { $vhost_symlink = escapeshellcmd($web_config['nginx_vhost_conf_enabled_dir'].'/900-'.$data['old']['domain'].'.vhost'); if(is_link($vhost_symlink)) { - unlink($vhost_symlink); + $app->system->unlink($vhost_symlink); $app->log('Removing symlink: '.$vhost_symlink.'->'.$vhost_file,LOGLEVEL_DEBUG); } $vhost_symlink = escapeshellcmd($web_config['nginx_vhost_conf_enabled_dir'].'/100-'.$data['old']['domain'].'.vhost'); if(is_link($vhost_symlink)) { - unlink($vhost_symlink); + $app->system->unlink($vhost_symlink); $app->log('Removing symlink: '.$vhost_symlink.'->'.$vhost_file,LOGLEVEL_DEBUG); } $vhost_symlink = escapeshellcmd($web_config['nginx_vhost_conf_enabled_dir'].'/'.$data['old']['domain'].'.vhost'); if(is_link($vhost_symlink)) { - unlink($vhost_symlink); + $app->system->unlink($vhost_symlink); $app->log('Removing symlink: '.$vhost_symlink.'->'.$vhost_file,LOGLEVEL_DEBUG); } $vhost_file = escapeshellcmd($web_config['nginx_vhost_conf_dir'].'/'.$data['old']['domain'].'.vhost'); - unlink($vhost_file); + $app->system->unlink($vhost_file); $app->log('Removing file: '.$vhost_file,LOGLEVEL_DEBUG); } @@ -1154,7 +1208,7 @@ class nginx_plugin { } //* Create awstats configuration - if($data['new']['stats_type'] == 'awstats' && $data['new']['type'] == 'vhost') { + if($data['new']['stats_type'] == 'awstats' && ($data['new']['type'] == 'vhost' || $data['new']['type'] == 'vhostsubdomain')) { $this->awstats_update($data,$web_config); } @@ -1178,7 +1232,7 @@ class nginx_plugin { copy($vhost_file,$vhost_file.'.err'); if(is_file($vhost_file.'~')) { //* Copy back the last backup file - copy($vhost_file.'~',$vhost_file); + $app->system->copy($vhost_file.'~',$vhost_file); } else { //* There is no backup file, so we create a empty vhost file with a warning message inside file_put_contents($vhost_file,"# nginx did not start after modifying this vhost file.\n# Please check file $vhost_file.err for syntax errors."); @@ -1196,8 +1250,7 @@ class nginx_plugin { } // Remove the backup copy of the config file. - if(@is_file($vhost_file.'~')) unlink($vhost_file.'~'); - + if(@is_file($vhost_file.'~')) $app->system->unlink($vhost_file.'~'); //* Unset action to clean it for next processed vhost. $this->action = ''; @@ -1209,6 +1262,7 @@ class nginx_plugin { // load the server configuration options $app->uses('getconf'); + $app->uses('system'); $web_config = $app->getconf->get_server_config($conf['server_id'], 'web'); //* Check if this is a chrooted setup @@ -1218,7 +1272,7 @@ class nginx_plugin { $nginx_chrooted = false; } - if($data['old']['type'] != 'vhost' && $data['old']['parent_domain_id'] > 0) { + if($data['old']['type'] != 'vhost' && $data['old']['type'] != 'vhostsubdomain' && $data['old']['parent_domain_id'] > 0) { //* This is a alias domain or subdomain, so we have to update the website instead $parent_domain_id = intval($data['old']['parent_domain_id']); $tmp = $app->db->queryOneRecord('SELECT * FROM web_domain WHERE domain_id = '.$parent_domain_id." AND active = 'y'"); @@ -1235,87 +1289,108 @@ class nginx_plugin { $vhost_symlink = escapeshellcmd($web_config['nginx_vhost_conf_enabled_dir'].'/'.$data['old']['domain'].'.vhost'); if(is_link($vhost_symlink)){ - unlink($vhost_symlink); + $app->system->unlink($vhost_symlink); $app->log('Removing symlink: '.$vhost_symlink.'->'.$vhost_file,LOGLEVEL_DEBUG); } $vhost_symlink = escapeshellcmd($web_config['nginx_vhost_conf_enabled_dir'].'/900-'.$data['old']['domain'].'.vhost'); if(is_link($vhost_symlink)){ - unlink($vhost_symlink); + $app->system->unlink($vhost_symlink); $app->log('Removing symlink: '.$vhost_symlink.'->'.$vhost_file,LOGLEVEL_DEBUG); } $vhost_symlink = escapeshellcmd($web_config['nginx_vhost_conf_enabled_dir'].'/100-'.$data['old']['domain'].'.vhost'); if(is_link($vhost_symlink)){ - unlink($vhost_symlink); + $app->system->unlink($vhost_symlink); $app->log('Removing symlink: '.$vhost_symlink.'->'.$vhost_file,LOGLEVEL_DEBUG); } - unlink($vhost_file); + $app->system->unlink($vhost_file); $app->log('Removing vhost file: '.$vhost_file,LOGLEVEL_DEBUG); - - $docroot = escapeshellcmd($data['old']['document_root']); - if($docroot != '' && !stristr($docroot,'..')) exec('rm -rf '.$docroot); - - //remove the php fastgi starter script and PHP-FPM pool definition if available - if ($data['old']['php'] == 'fast-cgi') { - $this->php_fpm_pool_delete($data,$web_config); - $fastcgi_starter_path = str_replace('[system_user]',$data['old']['system_user'],$web_config['fastcgi_starter_path']); - if (is_dir($fastcgi_starter_path)) { - exec('rm -rf '.$fastcgi_starter_path); - } - } + + if($data['old']['type'] == 'vhost') { + $docroot = escapeshellcmd($data['old']['document_root']); + if($docroot != '' && !stristr($docroot,'..')) exec('rm -rf '.$docroot); - // remove PHP-FPM pool - if ($data['old']['php'] == 'php-fpm') { - $this->php_fpm_pool_delete($data,$web_config); - } - - //remove the php cgi starter script if available - if ($data['old']['php'] == 'cgi') { - // TODO: fetch the date from the server-settings - $web_config['cgi_starter_path'] = $web_config['website_basedir'].'/php-cgi-scripts/[system_user]/'; - - $cgi_starter_path = str_replace('[system_user]',$data['old']['system_user'],$web_config['cgi_starter_path']); - if (is_dir($cgi_starter_path)) { - exec('rm -rf '.$cgi_starter_path); - } - } - - $app->log('Removing website: '.$docroot,LOGLEVEL_DEBUG); - - // Delete the symlinks for the sites - $client = $app->db->queryOneRecord('SELECT client_id FROM sys_group WHERE sys_group.groupid = '.intval($data['old']['sys_groupid'])); - $client_id = intval($client['client_id']); - unset($client); - $tmp_symlinks_array = explode(':',$web_config['website_symlinks']); - if(is_array($tmp_symlinks_array)) { - foreach($tmp_symlinks_array as $tmp_symlink) { - $tmp_symlink = str_replace('[client_id]',$client_id,$tmp_symlink); - $tmp_symlink = str_replace('[website_domain]',$data['old']['domain'],$tmp_symlink); - // Remove trailing slash - if(substr($tmp_symlink, -1, 1) == '/') $tmp_symlink = substr($tmp_symlink, 0, -1); - // create the symlinks, if not exist - if(is_link($tmp_symlink)) { - unlink($tmp_symlink); - $app->log('Removing symlink: '.$tmp_symlink,LOGLEVEL_DEBUG); - } - } - } - // end removing symlinks + //remove the php fastgi starter script if available + if ($data['old']['php'] == 'fast-cgi') { + $this->php_fpm_pool_delete($data,$web_config); + $fastcgi_starter_path = str_replace('[system_user]',$data['old']['system_user'],$web_config['fastcgi_starter_path']); + if($data['old']['type'] == 'vhost') { + if (is_dir($fastcgi_starter_path)) { + exec('rm -rf '.$fastcgi_starter_path); + } + } else { + $fcgi_starter_script = $fastcgi_starter_path.$web_config['fastcgi_starter_script'].'_web'.$data['old']['domain_id']; + if (file_exists($fcgi_starter_script)) { + exec('rm -f '.$fcgi_starter_script); + } + } + } + + // remove PHP-FPM pool + if ($data['old']['php'] == 'php-fpm') { + $this->php_fpm_pool_delete($data,$web_config); + } - // Delete the log file directory - $vhost_logfile_dir = escapeshellcmd('/var/log/ispconfig/httpd/'.$data['old']['domain']); - if($data['old']['domain'] != '' && !stristr($vhost_logfile_dir,'..')) exec('rm -rf '.$vhost_logfile_dir); - $app->log('Removing website logfile directory: '.$vhost_logfile_dir,LOGLEVEL_DEBUG); + //remove the php cgi starter script if available + if ($data['old']['php'] == 'cgi') { + // TODO: fetch the date from the server-settings + $web_config['cgi_starter_path'] = $web_config['website_basedir'].'/php-cgi-scripts/[system_user]/'; + + $cgi_starter_path = str_replace('[system_user]',$data['old']['system_user'],$web_config['cgi_starter_path']); + if($data['old']['type'] == 'vhost') { + if (is_dir($cgi_starter_path)) { + exec('rm -rf '.$cgi_starter_path); + } + } else { + $cgi_starter_script = $cgi_starter_path.'php-cgi-starter_web'.$data['old']['domain_id']; + if (file_exists($cgi_starter_script)) { + exec('rm -f '.$cgi_starter_script); + } + } + } + + $app->log('Removing website: '.$docroot,LOGLEVEL_DEBUG); + + // Delete the symlinks for the sites + $client = $app->db->queryOneRecord('SELECT client_id FROM sys_group WHERE sys_group.groupid = '.intval($data['old']['sys_groupid'])); + $client_id = intval($client['client_id']); + unset($client); + $tmp_symlinks_array = explode(':',$web_config['website_symlinks']); + if(is_array($tmp_symlinks_array)) { + foreach($tmp_symlinks_array as $tmp_symlink) { + $tmp_symlink = str_replace('[client_id]',$client_id,$tmp_symlink); + $tmp_symlink = str_replace('[website_domain]',$data['old']['domain'],$tmp_symlink); + // Remove trailing slash + if(substr($tmp_symlink, -1, 1) == '/') $tmp_symlink = substr($tmp_symlink, 0, -1); + // create the symlinks, if not exist + if(is_link($tmp_symlink)) { + $app->system->unlink($tmp_symlink); + $app->log('Removing symlink: '.$tmp_symlink,LOGLEVEL_DEBUG); + } + } + } + // end removing symlinks + } else { + // vhost subdomain + } - //delete the web user - $command = 'userdel'; - $command .= ' '.$data['old']['system_user']; - exec($command); - if($nginx_chrooted) $this->_exec('chroot '.escapeshellcmd($web_config['website_basedir']).' '.$command); - - //* Remove the awstats configuration file - if($data['old']['stats_type'] == 'awstats') { - $this->awstats_delete($data,$web_config); + // Delete the log file directory + $vhost_logfile_dir = escapeshellcmd('/var/log/ispconfig/httpd/'.$data['old']['domain']); + if($data['old']['domain'] != '' && !stristr($vhost_logfile_dir,'..')) exec('rm -rf '.$vhost_logfile_dir); + $app->log('Removing website logfile directory: '.$vhost_logfile_dir,LOGLEVEL_DEBUG); + + if($data['old']['type'] == 'vhost') { + //delete the web user + $command = 'userdel'; + $command .= ' '.$data['old']['system_user']; + exec($command); + if($nginx_chrooted) $this->_exec('chroot '.escapeshellcmd($web_config['website_basedir']).' '.$command); + + } + + //* Remove the awstats configuration file + if($data['old']['stats_type'] == 'awstats') { + $this->awstats_delete($data,$web_config); } $app->services->restartServiceDelayed('httpd','reload'); @@ -1348,10 +1423,13 @@ class nginx_plugin { return false; } + $web_folder = 'web'; + if($website['type'] == 'vhostsubdomain') $web_folder = $website['web_folder']; + //* Get the folder path. if(substr($folder['path'],0,1) == '/') $folder['path'] = substr($folder['path'],1); if(substr($folder['path'],-1) == '/') $folder['path'] = substr($folder['path'],0,-1); - $folder_path = escapeshellcmd($website['document_root'].'/web/'.$folder['path']); + $folder_path = escapeshellcmd($website['document_root'].'/' . $web_folder . '/'.$folder['path']); if(substr($folder_path,-1) != '/') $folder_path .= '/'; //* Check if the resulting path is inside the docroot @@ -1362,18 +1440,18 @@ class nginx_plugin { //* Create the folder path, if it does not exist if(!is_dir($folder_path)) { - exec('mkdir -p '.$folder_path); - chown($folder_path,$website['system_user']); - chgrp($folder_path,$website['system_group']); + $app->system->mkdirpath($folder_path); + $app->system->chown($folder_path,$website['system_user']); + $app->system->chgrp($folder_path,$website['system_group']); } //* Create empty .htpasswd file, if it does not exist if(!is_file($folder_path.'.htpasswd')) { touch($folder_path.'.htpasswd'); - chmod($folder_path.'.htpasswd',0755); - chown($folder_path.'.htpasswd',$website['system_user']); - chgrp($folder_path.'.htpasswd',$website['system_group']); - $app->log('Created file'.$folder_path.'.htpasswd',LOGLEVEL_DEBUG); + $app->system->chmod($folder_path.'.htpasswd',0755); + $app->system->chown($folder_path.'.htpasswd',$website['system_user']); + $app->system->chgrp($folder_path.'.htpasswd',$website['system_group']); + $app->log('Created file '.$folder_path.'.htpasswd',LOGLEVEL_DEBUG); } /* @@ -1424,10 +1502,13 @@ class nginx_plugin { return false; } + $web_folder = 'web'; + if($website['type'] == 'vhostsubdomain') $web_folder = $website['web_folder']; + //* Get the folder path. if(substr($folder['path'],0,1) == '/') $folder['path'] = substr($folder['path'],1); if(substr($folder['path'],-1) == '/') $folder['path'] = substr($folder['path'],0,-1); - $folder_path = realpath($website['document_root'].'/web/'.$folder['path']); + $folder_path = realpath($website['document_root'].'/' . $web_folder . '/'.$folder['path']); if(substr($folder_path,-1) != '/') $folder_path .= '/'; //* Check if the resulting path is inside the docroot @@ -1438,7 +1519,7 @@ class nginx_plugin { //* Remove .htpasswd file if(is_file($folder_path.'.htpasswd')) { - unlink($folder_path.'.htpasswd'); + $app->system->unlink($folder_path.'.htpasswd'); $app->log('Removed file '.$folder_path.'.htpasswd',LOGLEVEL_DEBUG); } @@ -1458,15 +1539,18 @@ class nginx_plugin { return false; } + $web_folder = 'web'; + if($website['type'] == 'vhostsubdomain') $web_folder = $website['web_folder']; + //* Get the folder path. if(substr($data['old']['path'],0,1) == '/') $data['old']['path'] = substr($data['old']['path'],1); if(substr($data['old']['path'],-1) == '/') $data['old']['path'] = substr($data['old']['path'],0,-1); - $old_folder_path = realpath($website['document_root'].'/web/'.$data['old']['path']); + $old_folder_path = realpath($website['document_root'].'/' . $web_folder . '/'.$data['old']['path']); if(substr($old_folder_path,-1) != '/') $old_folder_path .= '/'; if(substr($data['new']['path'],0,1) == '/') $data['new']['path'] = substr($data['new']['path'],1); if(substr($data['new']['path'],-1) == '/') $data['new']['path'] = substr($data['new']['path'],0,-1); - $new_folder_path = escapeshellcmd($website['document_root'].'/web/'.$data['new']['path']); + $new_folder_path = escapeshellcmd($website['document_root'].'/' . $web_folder . '/'.$data['new']['path']); if(substr($new_folder_path,-1) != '/') $new_folder_path .= '/'; //* Check if the resulting path is inside the docroot @@ -1490,14 +1574,14 @@ class nginx_plugin { } //* Create the folder path, if it does not exist - if(!is_dir($new_folder_path)) exec('mkdir -p '.$new_folder_path); + if(!is_dir($new_folder_path)) $app->system->mkdirpath($new_folder_path); if($data['old']['path'] != $data['new']['path']) { //* move .htpasswd file if(is_file($old_folder_path.'.htpasswd')) { - rename($old_folder_path.'.htpasswd',$new_folder_path.'.htpasswd'); + $app->system->rename($old_folder_path.'.htpasswd',$new_folder_path.'.htpasswd'); $app->log('Moved file '.$old_folder_path.'.htpasswd to '.$new_folder_path.'.htpasswd',LOGLEVEL_DEBUG); } @@ -1527,7 +1611,7 @@ class nginx_plugin { $website_auth_location['path'] .= '/'; } $basic_auth_locations[] = array('htpasswd_location' => '/'.$website_auth_location['path'], - 'htpasswd_path' => $website['document_root'].'/web/'.$website_auth_location['path']); + 'htpasswd_path' => $website['document_root'].'/' . ($website['type'] == 'vhostsubdomain' ? $website['web_folder'] : 'web') . '/'.$website_auth_location['path']); } } return $basic_auth_locations; @@ -1542,12 +1626,14 @@ class nginx_plugin { private function awstats_update ($data,$web_config) { global $app; + $web_folder = $data['new']['web_folder']; + if($data['new']['type'] == 'vhost') $web_folder = 'web'; $awstats_conf_dir = $web_config['awstats_conf_dir']; - if(!is_dir($data['new']['document_root']."/web/stats/")) mkdir($data['new']['document_root']."/web/stats"); + if(!is_dir($data['new']['document_root']."/" . $web_folder . "/stats/")) mkdir($data['new']['document_root']."/" . $web_folder . "/stats"); if(!@is_file($awstats_conf_dir.'/awstats.'.$data['new']['domain'].'.conf') || ($data['old']['domain'] != '' && $data['new']['domain'] != $data['old']['domain'])) { if ( @is_file($awstats_conf_dir.'/awstats.'.$data['old']['domain'].'.conf') ) { - unlink($awstats_conf_dir.'/awstats.'.$data['old']['domain'].'.conf'); + $app->system->unlink($awstats_conf_dir.'/awstats.'.$data['old']['domain'].'.conf'); } $content = ''; @@ -1556,12 +1642,12 @@ class nginx_plugin { $content .= "SiteDomain=\"".$data['new']['domain']."\"\n"; $content .= "HostAliases=\"www.".$data['new']['domain']." localhost 127.0.0.1\"\n"; - file_put_contents($awstats_conf_dir.'/awstats.'.$data['new']['domain'].'.conf',$content); + $app->system->file_put_contents($awstats_conf_dir.'/awstats.'.$data['new']['domain'].'.conf',$content); $app->log('Created AWStats config file: '.$awstats_conf_dir.'/awstats.'.$data['new']['domain'].'.conf',LOGLEVEL_DEBUG); } - if(is_file($data['new']['document_root']."/web/stats/index.html")) unlink($data['new']['document_root']."/web/stats/index.html"); - copy("/usr/local/ispconfig/server/conf/awstats_index.php.master",$data['new']['document_root']."/web/stats/index.php"); + if(is_file($data['new']['document_root']."/" . $web_folder . "/stats/index.html")) $app->system->unlink($data['new']['document_root']."/" . $web_folder . "/stats/index.html"); + $app->system->copy("/usr/local/ispconfig/server/conf/awstats_index.php.master",$data['new']['document_root']."/" . $web_folder . "/stats/index.php"); } //* Delete the awstats configuration file @@ -1571,7 +1657,7 @@ class nginx_plugin { $awstats_conf_dir = $web_config['awstats_conf_dir']; if ( @is_file($awstats_conf_dir.'/awstats.'.$data['old']['domain'].'.conf') ) { - unlink($awstats_conf_dir.'/awstats.'.$data['old']['domain'].'.conf'); + $app->system->unlink($awstats_conf_dir.'/awstats.'.$data['old']['domain'].'.conf'); $app->log('Removed AWStats config file: '.$awstats_conf_dir.'/awstats.'.$data['old']['domain'].'.conf',LOGLEVEL_DEBUG); } } @@ -1611,7 +1697,8 @@ class nginx_plugin { if($data['new']['php'] == 'no'){ if(@is_file($pool_dir.$pool_name.'.conf')){ - unlink($pool_dir.$pool_name.'.conf'); + $app->system->unlink($pool_dir.$pool_name.'.conf'); + //$reload = true; } if($data['old']['php'] != 'no'){ if(!$default_php_fpm){ @@ -1630,7 +1717,7 @@ class nginx_plugin { if($data['new']['php_fpm_use_socket'] == 'y'){ $use_tcp = 0; $use_socket = 1; - if(!is_dir($socket_dir)) exec('mkdir -p '.$socket_dir); + if(!is_dir($socket_dir)) $app->system->mkdirpath($socket_dir); } else { $use_tcp = 1; $use_socket = 0; @@ -1699,7 +1786,7 @@ class nginx_plugin { $tpl->setLoop('custom_php_ini_settings', $final_php_ini_settings); - file_put_contents($pool_dir.$pool_name.'.conf',$tpl->grab()); + $app->system->file_put_contents($pool_dir.$pool_name.'.conf',$tpl->grab()); $app->log('Writing the PHP-FPM config file: '.$pool_dir.$pool_name.'.conf',LOGLEVEL_DEBUG); unset($tpl); @@ -1708,7 +1795,7 @@ class nginx_plugin { if(substr($default_pool_dir,-1) != '/') $default_pool_dir .= '/'; if($default_pool_dir != $pool_dir){ if ( @is_file($default_pool_dir.$pool_name.'.conf') ) { - unlink($default_pool_dir.$pool_name.'.conf'); + $app->system->unlink($default_pool_dir.$pool_name.'.conf'); $app->log('Removed PHP-FPM config file: '.$default_pool_dir.$pool_name.'.conf',LOGLEVEL_DEBUG); $app->services->restartService('php-fpm','reload:'.$conf['init_scripts'].'/'.$web_config['php_fpm_init_script']); } @@ -1719,7 +1806,7 @@ class nginx_plugin { if(substr($php_version['php_fpm_pool_dir'],-1) != '/') $php_version['php_fpm_pool_dir'] .= '/'; if($php_version['php_fpm_pool_dir'] != $pool_dir){ if ( @is_file($php_version['php_fpm_pool_dir'].$pool_name.'.conf') ) { - unlink($php_version['php_fpm_pool_dir'].$pool_name.'.conf'); + $app->system->unlink($php_version['php_fpm_pool_dir'].$pool_name.'.conf'); $app->log('Removed PHP-FPM config file: '.$php_version['php_fpm_pool_dir'].$pool_name.'.conf',LOGLEVEL_DEBUG); $app->services->restartService('php-fpm','reload:'.$php_version['php_fpm_init_script']); } @@ -1757,7 +1844,7 @@ class nginx_plugin { $pool_name = 'web'.$data['old']['domain_id']; if ( @is_file($pool_dir.$pool_name.'.conf') ) { - unlink($pool_dir.$pool_name.'.conf'); + $app->system->unlink($pool_dir.$pool_name.'.conf'); $app->log('Removed PHP-FPM config file: '.$pool_dir.$pool_name.'.conf',LOGLEVEL_DEBUG); } @@ -1766,7 +1853,7 @@ class nginx_plugin { if(substr($default_pool_dir,-1) != '/') $default_pool_dir .= '/'; if($default_pool_dir != $pool_dir){ if ( @is_file($default_pool_dir.$pool_name.'.conf') ) { - unlink($default_pool_dir.$pool_name.'.conf'); + $app->system->unlink($default_pool_dir.$pool_name.'.conf'); $app->log('Removed PHP-FPM config file: '.$default_pool_dir.$pool_name.'.conf',LOGLEVEL_DEBUG); $app->services->restartService('php-fpm','reload:'.$conf['init_scripts'].'/'.$web_config['php_fpm_init_script']); } @@ -1777,7 +1864,7 @@ class nginx_plugin { if(substr($php_version['php_fpm_pool_dir'],-1) != '/') $php_version['php_fpm_pool_dir'] .= '/'; if($php_version['php_fpm_pool_dir'] != $pool_dir){ if ( @is_file($php_version['php_fpm_pool_dir'].$pool_name.'.conf') ) { - unlink($php_version['php_fpm_pool_dir'].$pool_name.'.conf'); + $app->system->unlink($php_version['php_fpm_pool_dir'].$pool_name.'.conf'); $app->log('Removed PHP-FPM config file: '.$php_version['php_fpm_pool_dir'].$pool_name.'.conf',LOGLEVEL_DEBUG); $app->services->restartService('php-fpm','reload:'.$php_version['php_fpm_init_script']); } @@ -1911,4 +1998,4 @@ class nginx_plugin { } // end class -?> \ No newline at end of file +?> diff --git a/server/plugins-available/nginx_reverseproxy_plugin.inc.php b/server/plugins-available/nginx_reverseproxy_plugin.inc.php index ec0e225d70..ae4ffe9b95 100644 --- a/server/plugins-available/nginx_reverseproxy_plugin.inc.php +++ b/server/plugins-available/nginx_reverseproxy_plugin.inc.php @@ -63,7 +63,7 @@ class nginx_reverseproxy_plugin { if($this->action != 'insert') $this->action = 'update'; - if($data['new']['type'] != 'vhost' && $data['new']['parent_domain_id'] > 0) { + if($data['new']['type'] != 'vhost' && $data['new']['type'] != 'vhostsubdomain' && $data['new']['parent_domain_id'] > 0) { $old_parent_domain_id = intval($data['old']['parent_domain_id']); $new_parent_domain_id = intval($data['new']['parent_domain_id']); @@ -130,7 +130,7 @@ class nginx_reverseproxy_plugin { // get alias domains (co-domains and subdomains) - $aliases = $app->dbmaster->queryAllRecords('SELECT * FROM web_domain WHERE parent_domain_id = '.$data['new']['domain_id']." AND active = 'y'"); + $aliases = $app->dbmaster->queryAllRecords('SELECT * FROM web_domain WHERE parent_domain_id = '.$data['new']['domain_id']." AND type != 'vhostsubdomain' AND active = 'y'"); $server_alias = array(); switch($data['new']['subdomain']) { case 'www': @@ -280,7 +280,7 @@ class nginx_reverseproxy_plugin { $nginx_config = $app->getconf->get_server_config($conf['server_id'], 'web'); - if($data['old']['type'] == 'vhost') { + if($data['old']['type'] == 'vhost' || $data['old']['type'] == 'vhostsubdomain') { //* This is a website // Deleting the vhost file, symlink and the data directory -- GitLab