diff --git a/CHANGELOG b/CHANGELOG index ddab7acac1..23126f020a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,6 +5,7 @@ Git 1.5.x ------------------------------------------------------------------------------------------------------------------------ BACKEND + Added: Apache2 wildcard alias feature Added: Array::Utils library (PerlVendor) Added: iMSCP::Database::mariadb adapter (for use with new DBD::MariaDB driver for DBI, in place of DBD::mysql when available) Added: Support for per-Milter and per-policy server timeout (Servers::mta::postfix::postconf() - Postfix >= 3.0.0) @@ -43,6 +44,7 @@ DISTRIBUTIONS FRONTEND Added: ACL assertions for the navigation + Added: Apache2 wildcard alias feature Added: Patches for zendframework/zendframework1 dependency (PHP deprecations, Zend_Navigation component enhancement, small fixes) Added: Route injector service for i-MSCP plugins Added: Service provider injector for i-MSCP plugins diff --git a/configs/debian/database/database.sql b/configs/debian/database/database.sql index a4599cbe36..9e35fd04be 100644 --- a/configs/debian/database/database.sql +++ b/configs/debian/database/database.sql @@ -82,7 +82,7 @@ INSERT IGNORE INTO `config` (`name`, `value`) VALUES ('PREVENT_EXTERNAL_LOGIN_ADMIN', '1'), ('PREVENT_EXTERNAL_LOGIN_RESELLER', '1'), ('PREVENT_EXTERNAL_LOGIN_CLIENT', '1'), - ('DATABASE_REVISION', '273'); + ('DATABASE_REVISION', '274'); -- -------------------------------------------------------- @@ -145,6 +145,7 @@ CREATE TABLE IF NOT EXISTS `domain` ( `url_forward` varchar(255) collate utf8_unicode_ci NOT NULL DEFAULT 'no', `type_forward` varchar(5) collate utf8_unicode_ci DEFAULT NULL, `host_forward` varchar(3) collate utf8_unicode_ci NOT NULL DEFAULT 'Off', + `wildcard_alias` enum('yes', 'no') NOT NULL DEFAULT 'no', PRIMARY KEY (`domain_id`), UNIQUE KEY `domain_name` (`domain_name`), INDEX `i_domain_admin_id` (`domain_admin_id`) @@ -167,6 +168,7 @@ CREATE TABLE IF NOT EXISTS `domain_aliasses` ( `url_forward` varchar(255) collate utf8_unicode_ci NOT NULL DEFAULT 'no', `type_forward` varchar(5) collate utf8_unicode_ci DEFAULT NULL, `host_forward` varchar(3) collate utf8_unicode_ci NOT NULL DEFAULT 'Off', + `wildcard_alias` enum('yes', 'no') NOT NULL DEFAULT 'no', `external_mail` varchar(15) collate utf8_unicode_ci NOT NULL DEFAULT 'off', PRIMARY KEY (`alias_id`), INDEX `domain_id` (`domain_id`) @@ -627,6 +629,7 @@ CREATE TABLE IF NOT EXISTS `subdomain` ( `subdomain_url_forward` varchar(255) collate utf8_unicode_ci NOT NULL DEFAULT 'no', `subdomain_type_forward` varchar(5) collate utf8_unicode_ci DEFAULT NULL, `subdomain_host_forward` varchar(3) collate utf8_unicode_ci NOT NULL DEFAULT 'Off', + `subdomain_wildcard_alias` enum('yes', 'no') NOT NULL DEFAULT 'no', `subdomain_status` varchar(255) collate utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`subdomain_id`), INDEX `domain_id` (`domain_id`) @@ -647,6 +650,7 @@ CREATE TABLE IF NOT EXISTS `subdomain_alias` ( `subdomain_alias_url_forward` varchar(255) collate utf8_unicode_ci NOT NULL DEFAULT 'no', `subdomain_alias_type_forward` varchar(5) collate utf8_unicode_ci DEFAULT NULL, `subdomain_alias_host_forward` varchar(3) collate utf8_unicode_ci NOT NULL DEFAULT 'Off', + `subdomain_alias_wildcard_alias` enum('yes', 'no') NOT NULL DEFAULT 'no', `subdomain_alias_status` varchar(255) collate utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`subdomain_alias_id`), INDEX `alias_id` (`alias_id`) diff --git a/engine/PerlLib/Modules/Alias.pm b/engine/PerlLib/Modules/Alias.pm index 1661362db5..10aec4437e 100644 --- a/engine/PerlLib/Modules/Alias.pm +++ b/engine/PerlLib/Modules/Alias.pm @@ -331,7 +331,8 @@ sub _getData ALLOW_URL_FOPEN => $phpini->{'allow_url_fopen'} || 'off', PHP_FPM_LISTEN_PORT => ( $phpini->{'id'} // 1 )-1, EXTERNAL_MAIL => $self->{'external_mail'}, - MAIL_ENABLED => ( $self->{'external_mail'} eq 'off' && ( $self->{'mail_on_domain'} || $self->{'domain_mailacc_limit'} >= 0 ) ) + MAIL_ENABLED => ( $self->{'external_mail'} eq 'off' && ( $self->{'mail_on_domain'} || $self->{'domain_mailacc_limit'} >= 0 ) ), + WILDCARD_ALIAS => $self->{'wildcard_alias'} // 'no' } } unless %{ $self->{'_data'} }; diff --git a/engine/PerlLib/Modules/Domain.pm b/engine/PerlLib/Modules/Domain.pm index 1bffb8bbe7..01964a0699 100644 --- a/engine/PerlLib/Modules/Domain.pm +++ b/engine/PerlLib/Modules/Domain.pm @@ -337,7 +337,7 @@ sub _loadData " SELECT t1.domain_id, t1.domain_admin_id, t1.domain_mailacc_limit, t1.domain_name, t1.domain_status, t1.domain_php, t1.domain_cgi, t1.external_mail, t1.web_folder_protection, t1.document_root, - t1.url_forward, t1.type_forward, t1.host_forward, + t1.url_forward, t1.type_forward, t1.host_forward, t1.wildcard_alias, IFNULL(t2.ip_number, '0.0.0.0') AS ip_number, t3.private_key, t3.certificate, t3.ca_bundle, t3.allow_hsts, t3.hsts_max_age, t3.hsts_include_subdomains, @@ -442,7 +442,8 @@ sub _getData ALLOW_URL_FOPEN => $phpini->{'allow_url_fopen'} || 'off', PHP_FPM_LISTEN_PORT => ( $phpini->{'id'} // 1 )-1, EXTERNAL_MAIL => $self->{'external_mail'}, - MAIL_ENABLED => ( $self->{'external_mail'} eq 'off' && ( $self->{'mail_on_domain'} || $self->{'domain_mailacc_limit'} >= 0 ) ) + MAIL_ENABLED => ( $self->{'external_mail'} eq 'off' && ( $self->{'mail_on_domain'} || $self->{'domain_mailacc_limit'} >= 0 ) ), + WILDCARD_ALIAS => $self->{'wildcard_alias'} // 'no' } } unless %{ $self->{'_data'} }; diff --git a/engine/PerlLib/Modules/SubAlias.pm b/engine/PerlLib/Modules/SubAlias.pm index cc8e309c23..1549f7e194 100644 --- a/engine/PerlLib/Modules/SubAlias.pm +++ b/engine/PerlLib/Modules/SubAlias.pm @@ -255,7 +255,8 @@ sub _getData ALLOW_URL_FOPEN => $phpini->{'allow_url_fopen'} || 'off', PHP_FPM_LISTEN_PORT => ( $phpini->{'id'} // 1 )-1, EXTERNAL_MAIL => $self->{'external_mail'}, - MAIL_ENABLED => ( $self->{'external_mail'} eq 'off' && ( $self->{'mail_on_domain'} || $self->{'domain_mailacc_limit'} >= 0 ) ) + MAIL_ENABLED => ( $self->{'external_mail'} eq 'off' && ( $self->{'mail_on_domain'} || $self->{'domain_mailacc_limit'} >= 0 ) ), + WILDCARD_ALIAS => $self->{'subdomain_alias_wildcard_alias'} // 'no' } } unless %{ $self->{'_data'} }; diff --git a/engine/PerlLib/Modules/Subdomain.pm b/engine/PerlLib/Modules/Subdomain.pm index 378b15e398..8434bce35a 100644 --- a/engine/PerlLib/Modules/Subdomain.pm +++ b/engine/PerlLib/Modules/Subdomain.pm @@ -241,7 +241,8 @@ sub _getData ALLOW_URL_FOPEN => $phpini->{'allow_url_fopen'} || 'off', PHP_FPM_LISTEN_PORT => ( $phpini->{'id'} // 1 )-1, EXTERNAL_MAIL => $self->{'external_mail'}, - MAIL_ENABLED => ( $self->{'external_mail'} eq 'off' && ( $self->{'mail_on_domain'} || $self->{'domain_mailacc_limit'} >= 0 ) ) + MAIL_ENABLED => ( $self->{'external_mail'} eq 'off' && ( $self->{'mail_on_domain'} || $self->{'domain_mailacc_limit'} >= 0 ) ), + WILDCARD_ALIAS => $self->{'subdomain_wildcard_alias'} // 'no' } } unless %{ $self->{'_data'} }; diff --git a/engine/PerlLib/Servers/httpd/apache_fcgid.pm b/engine/PerlLib/Servers/httpd/apache_fcgid.pm index 74b01dcf0c..7cbda486de 100644 --- a/engine/PerlLib/Servers/httpd/apache_fcgid.pm +++ b/engine/PerlLib/Servers/httpd/apache_fcgid.pm @@ -386,7 +386,8 @@ sub disableDmn HTTP_URI_SCHEME => 'http://', HTTPD_LOG_DIR => $self->{'config'}->{'HTTPD_LOG_DIR'}, USER_WEB_DIR => $::imscpConfig{'USER_WEB_DIR'}, - SERVER_ALIASES => "www.$data->{'DOMAIN_NAME'}" + SERVER_ALIASES => ( $data->{'WILDCARD_ALIAS'} eq 'yes' ? '*.' : 'www.' ) + . $data->{'DOMAIN_NAME'} } ); # Create http vhost @@ -1741,7 +1742,8 @@ sub _addCfg HTTPD_CUSTOM_SITES_DIR => $self->{'config'}->{'HTTPD_CUSTOM_SITES_DIR'}, HTTPD_LOG_DIR => $self->{'config'}->{'HTTPD_LOG_DIR'}, PHP_FCGI_STARTER_DIR => $self->{'phpConfig'}->{'PHP_FCGI_STARTER_DIR'}, - SERVER_ALIASES => "www.$data->{'DOMAIN_NAME'}" + SERVER_ALIASES => ( $data->{'WILDCARD_ALIAS'} eq 'yes' ? '*.' : 'www.' ) + . $data->{'DOMAIN_NAME'} } ); # Create http vhost diff --git a/engine/PerlLib/Servers/httpd/apache_itk.pm b/engine/PerlLib/Servers/httpd/apache_itk.pm index 62eafad9ae..bb2009c189 100644 --- a/engine/PerlLib/Servers/httpd/apache_itk.pm +++ b/engine/PerlLib/Servers/httpd/apache_itk.pm @@ -379,7 +379,8 @@ sub disableDmn HTTP_URI_SCHEME => 'http://', HTTPD_LOG_DIR => $self->{'config'}->{'HTTPD_LOG_DIR'}, USER_WEB_DIR => $::imscpConfig{'USER_WEB_DIR'}, - SERVER_ALIASES => "www.$data->{'DOMAIN_NAME'}" + SERVER_ALIASES => ( $data->{'WILDCARD_ALIAS'} eq 'yes' ? '*.' : 'www.' ) + . $data->{'DOMAIN_NAME'} } ); # Create http vhost @@ -1719,7 +1720,8 @@ sub _addCfg } @domainIPs ), HTTPD_CUSTOM_SITES_DIR => $self->{'config'}->{'HTTPD_CUSTOM_SITES_DIR'}, HTTPD_LOG_DIR => $self->{'config'}->{'HTTPD_LOG_DIR'}, - SERVER_ALIASES => "www.$data->{'DOMAIN_NAME'}" + SERVER_ALIASES => ( $data->{'WILDCARD_ALIAS'} eq 'yes' ? '*.' : 'www.' ) + . $data->{'DOMAIN_NAME'} } ); # Create http vhost diff --git a/engine/PerlLib/Servers/httpd/apache_php_fpm.pm b/engine/PerlLib/Servers/httpd/apache_php_fpm.pm index 744c63127b..95173b7093 100644 --- a/engine/PerlLib/Servers/httpd/apache_php_fpm.pm +++ b/engine/PerlLib/Servers/httpd/apache_php_fpm.pm @@ -380,7 +380,8 @@ sub disableDmn HTTP_URI_SCHEME => 'http://', HTTPD_LOG_DIR => $self->{'config'}->{'HTTPD_LOG_DIR'}, USER_WEB_DIR => $::imscpConfig{'USER_WEB_DIR'}, - SERVER_ALIASES => "www.$data->{'DOMAIN_NAME'}" + SERVER_ALIASES => ( $data->{'WILDCARD_ALIAS'} eq 'yes' ? '*.' : 'www.' ) + . $data->{'DOMAIN_NAME'} } ); # Create http vhost @@ -1755,7 +1756,8 @@ sub _addCfg ? $confLevel : '127.0.0.1:' . ( $self->{'phpConfig'}->{'PHP_FPM_LISTEN_PORT_START'}+$data->{'PHP_FPM_LISTEN_PORT'} ) ), - SERVER_ALIASES => "www.$data->{'DOMAIN_NAME'}" + SERVER_ALIASES => ( $data->{'WILDCARD_ALIAS'} eq 'yes' ? '*.' : 'www.' ) + . $data->{'DOMAIN_NAME'} } ); # Create http vhost diff --git a/gui/library/iMSCP/Events.php b/gui/library/iMSCP/Events.php index e81afcf984..b0ac7a0f2d 100644 --- a/gui/library/iMSCP/Events.php +++ b/gui/library/iMSCP/Events.php @@ -876,7 +876,8 @@ class iMSCP_Events * - documentRoot : Domain document root * - forwardUrl : Domain forward URL, 'no' if no forward URL has been set * - forwardType : Domain forward URL type - * - forwardHost : Domain forward URL preserve host option + * - forwardHost : Domain forward URL preserve host option, + * - wildcardAlias : Wildcard alias option (yes|no) * * @const string */ @@ -895,7 +896,8 @@ class iMSCP_Events * - documentRoot : Domain document root * - forwardUrl : Domain forward URL, 'no' if no forward URL has been set * - forwardType : Domain forward URL type - * - forwardHost : Domain forward URL preserve host option + * - forwardHost : Domain forward URL preserve host option, + * - wildcardAlias : Wildcard alias option (yes|no) * * @const string */ @@ -911,7 +913,8 @@ class iMSCP_Events * - documentRoot : Domain document root * - forwardUrl : Domain forward URL, 'no' if no forward URL has been set * - forwardType : Domain forward URL type - * - forwardHost : Domain forward URL preserve host option + * - forwardHost : Domain forward URL preserve host option, + * - wildcardAlias : Wildcard alias option (yes|no) * * @const string */ @@ -947,6 +950,7 @@ class iMSCP_Events * - forwardUrl : Subdomain forward URL, 'no' if no forward URL has been set * - forwardType : Subdomain forward URL type * - forwardHost : Subdomain forward URL preserve host option + * - wildcardAlias : Wildcard alias option (yes|no) * - customerId : Subdomain owner unique identifier * * @const string @@ -968,6 +972,7 @@ class iMSCP_Events * been set * - forwardType : Subdomain forward URL type * - forwardHost : Subdomain forward URL preserve host option + * - wildcardAlias : Wildcard alias option (yes|no) * - customerId : Subdomain owner unique identifier * * @const string @@ -987,7 +992,8 @@ class iMSCP_Events * - forwardUrl : Subdomain forward URL, 'no' if no forward URL has * been set * - forwardType : Subdomain forward URL type - * - forwardHost : Subdomain forward URL preserve host option + * - forwardHost : Subdomain forward URL preserve host option, + * - wildcardAlias : Wildcard alias option (yes|no) * * @const string */ @@ -1006,7 +1012,8 @@ class iMSCP_Events * - forwardUrl : Subdomain forward URL, 'no' if no forward URL has * been set * - forwardType : Subdomain forward URL type - * - forwardHost : Subdomain forward URL preserve host option + * - forwardHost : Subdomain forward URL preserve host option, + * - wildcardAlias : Wildcard alias option (yes|no) * * @const string */ @@ -1054,6 +1061,7 @@ class iMSCP_Events * set * - forwardType: Domain alias forward URL type * - forwardHost: Domain alias forward URL preserve host option + * - wildcardAlias : Wildcard alias option (yes|no) * * @const string */ @@ -1071,7 +1079,8 @@ class iMSCP_Events * - forwardUrl: Domain alias forward URL, 'no' if no forward URL has been * set * - forwardType: Domain alias forward URL type - * - forwardHost: Domain alias forward URL preserve host optio + * - forwardHost: Domain alias forward URL preserve host option + * - wildcardAlias : Wildcard alias option (yes|no) * * @const string */ @@ -1089,6 +1098,7 @@ class iMSCP_Events * has been set * - forwardType : Domain alias forward URL type * - forwardHost : Domain alias forward URL preserve host option + * - wildcardAlias : Wildcard alias option (yes|no) * * @const string */ @@ -1097,7 +1107,7 @@ class iMSCP_Events /** * Event triggered after domain alias edition * - * iMSCP_Events_Event objectparameters: + * iMSCP_Events_Event object parameters: * - domainAliasId : Domain alias unique identifier * - domainAliasName : Domain alias name * - mountPoint : Domain alias mount point @@ -1105,7 +1115,8 @@ class iMSCP_Events * - forwardUrl : Domain alias forward URL, 'no' if no forward URL * has been set * - forwardType : Domain alias forward URL type - * - forwardHost : Domain alias forward URL preserve host option + * - forwardHost : Domain alias forward URL preserve host option, + * - wildcardAlias : Wildcard alias option (yes|no) * * @const string */ diff --git a/gui/library/iMSCP/Update/Database.php b/gui/library/iMSCP/Update/Database.php index e11774462f..80349cec80 100644 --- a/gui/library/iMSCP/Update/Database.php +++ b/gui/library/iMSCP/Update/Database.php @@ -64,7 +64,7 @@ class iMSCP_Update_Database extends iMSCP_Update /** * @var int Last database update revision */ - protected $lastUpdate = 273; + protected $lastUpdate = 274; /** * Singleton - Make new unavailable @@ -1977,4 +1977,35 @@ protected function r273() throw new RuntimeException($e->getMessage()); } } + + /** + * Add columns for the Apache2 wildcard alias feature + * + * @return array SQL statements to be executed + */ + protected function r274() + { + return [ + $this->addColumn( + 'domain', + 'wildcard_alias', + "enum('yes', 'no') NOT NULL DEFAULT 'no' AFTER `host_forward`" + ), + $this->addColumn( + 'subdomain', + 'subdomain_wildcard_alias', + "enum('yes', 'no') NOT NULL DEFAULT 'no' AFTER `subdomain_host_forward`" + ), + $this->addColumn( + 'domain_aliasses', + 'wildcard_alias', + "enum('yes', 'no') NOT NULL DEFAULT 'no' AFTER `host_forward`" + ), + $this->addColumn( + 'subdomain_alias', + 'subdomain_alias_wildcard_alias', + "enum('yes', 'no') NOT NULL DEFAULT 'no' AFTER `subdomain_alias_host_forward`" + ) + ]; + } } diff --git a/gui/public/client/alias_add.php b/gui/public/client/alias_add.php index 2fdbdb9ccf..d7f156e34a 100644 --- a/gui/public/client/alias_add.php +++ b/gui/public/client/alias_add.php @@ -1,7 +1,7 @@ + * Copyright (C) 2010-2019 by Laurent Declercq * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -18,31 +18,23 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -use iMSCP_Authentication as Authentication; -use iMSCP_Database as Database; -use iMSCP_Events as Events; -use iMSCP_Events_Aggregator as EventsManager; -use iMSCP_pTemplate as TemplateEngine; -use iMSCP_Registry as Registry; - -/*********************************************************************************************************************** - * Functions - */ +/** @noinspection PhpUnhandledExceptionInspection PhpDocMissingThrowsInspection */ /** * Send alias order email * - * @param string $aliasName + * @param string $aliasName * @return bool TRUE on success, FALSE on failure - * @throws Zend_Exception - * @throws iMSCP_Events_Manager_Exception - * @throws iMSCP_Exception - * @throws iMSCP_Exception_Database */ function send_alias_order_email($aliasName) { $stmt = exec_query( - 'SELECT admin_name, created_by, fname, lname, email FROM admin WHERE admin_id = ?', $_SESSION['user_id'] + ' + SELECT admin_name, created_by, fname, lname, email + FROM admin + WHERE admin_id = ? + ', + $_SESSION['user_id'] ); $row = $stmt->fetchRow(); $data = get_alias_order_email($row['created_by']); @@ -61,7 +53,10 @@ function send_alias_order_email($aliasName) ]); if (!$ret) { - write_log(sprintf("Couldn't send alias order to %s", $row['admin_name']), E_USER_ERROR); + write_log( + sprintf("Couldn't send alias order to %s", $row['admin_name']), + E_USER_ERROR + ); return false; } @@ -72,10 +67,6 @@ function send_alias_order_email($aliasName) * Get domains list * * @return array Domains list - * @throws Zend_Exception - * @throws iMSCP_Events_Exception - * @throws iMSCP_Exception - * @throws iMSCP_Exception_Database */ function getDomainsList() { @@ -101,7 +92,8 @@ function getDomainsList() $stmt = exec_query( " - SELECT CONCAT(t1.subdomain_name, '.', t2.domain_name) AS name, t1.subdomain_mount AS mount_point + SELECT CONCAT(t1.subdomain_name, '.', t2.domain_name) AS name, + t1.subdomain_mount AS mount_point FROM subdomain AS t1 JOIN domain AS t2 USING(domain_id) WHERE t1.domain_id = :domain_id @@ -114,7 +106,8 @@ function getDomainsList() AND alias_status = :status_ok AND url_forward = 'no' UNION ALL - SELECT CONCAT(t1.subdomain_alias_name, '.', t2.alias_name) AS name, t1.subdomain_alias_mount AS mount_point + SELECT CONCAT(t1.subdomain_alias_name, '.', t2.alias_name) AS name, + t1.subdomain_alias_mount AS mount_point FROM subdomain_alias AS t1 JOIN domain_aliasses AS t2 USING(alias_id) WHERE t2.domain_id = :domain_id @@ -125,7 +118,9 @@ function getDomainsList() ); if ($stmt->rowCount()) { - $domainsList = array_merge($domainsList, $stmt->fetchAll(PDO::FETCH_ASSOC)); + $domainsList = array_merge( + $domainsList, $stmt->fetchAll(PDO::FETCH_ASSOC) + ); usort($domainsList, function ($a, $b) { return strnatcmp(decode_idna($a['name']), decode_idna($b['name'])); }); @@ -137,55 +132,72 @@ function getDomainsList() /** * Generate page * - * @param $tpl TemplateEngine + * @param $tpl iMSCP_pTemplate * @return void - * @throws iMSCP_Events_Manager_Exception - * @throws iMSCP_Exception */ -function generatePage(TemplateEngine $tpl) +function generatePage(iMSCP_pTemplate $tpl) { $forwardType = ( isset($_POST['forward_type']) - && in_array($_POST['forward_type'], ['301', '302', '303', '307', 'proxy'], true) + && in_array( + $_POST['forward_type'], + ['301', '302', '303', '307', 'proxy'], + true + ) ) ? $_POST['forward_type'] : '302'; - $forwardHost = ($forwardType == 'proxy' && isset($_POST['forward_host'])) ? 'On' : 'Off'; + $forwardHost = ($forwardType == 'proxy' && isset($_POST['forward_host'])) + ? 'On' : 'Off'; + + $wildcardAlias = isset($_POST['wildcard_alias']) + && in_array($_POST['wildcard_alias'], ['yes', 'no'], true) + ? $_POST['wildcard_alias'] : 'no'; $tpl->assign([ - 'DOMAIN_ALIAS_NAME' => (isset($_POST['domain_alias_name'])) ? tohtml($_POST['domain_alias_name']) : '', - 'FORWARD_URL_YES' => (isset($_POST['url_forwarding']) && $_POST['url_forwarding'] == 'yes') ? ' checked' : '', - 'FORWARD_URL_NO' => (isset($_POST['url_forwarding']) && $_POST['url_forwarding'] == 'yes') ? '' : ' checked', - 'HTTP_YES' => (isset($_POST['forward_url_scheme']) && $_POST['forward_url_scheme'] == 'http://') - ? ' selected' : '', - 'HTTPS_YES' => (isset($_POST['forward_url_scheme']) && $_POST['forward_url_scheme'] == 'https://') - ? ' selected' : '', - 'FORWARD_URL' => (isset($_POST['forward_url'])) ? tohtml($_POST['forward_url']) : '', - 'FORWARD_TYPE_301' => ($forwardType == '301') ? ' checked' : '', - 'FORWARD_TYPE_302' => ($forwardType == '302') ? ' checked' : '', - 'FORWARD_TYPE_303' => ($forwardType == '303') ? ' checked' : '', - 'FORWARD_TYPE_307' => ($forwardType == '307') ? ' checked' : '', - 'FORWARD_TYPE_PROXY' => ($forwardType == 'proxy') ? ' checked' : '', - 'FORWARD_HOST' => ($forwardHost == 'On') ? ' checked' : '' + 'DOMAIN_ALIAS_NAME' => isset($_POST['domain_alias_name']) + ? tohtml($_POST['domain_alias_name']) : '', + 'FORWARD_URL_YES' => isset($_POST['url_forwarding']) + && $_POST['url_forwarding'] == 'yes' + ? ' checked' : '', + 'FORWARD_URL_NO' => isset($_POST['url_forwarding']) + && $_POST['url_forwarding'] == 'yes' + ? '' : ' checked', + 'HTTP_YES' => isset($_POST['forward_url_scheme']) + && $_POST['forward_url_scheme'] == 'http://' + ? ' selected' : '', + 'HTTPS_YES' => isset($_POST['forward_url_scheme']) + && $_POST['forward_url_scheme'] == 'https://' + ? ' selected' : '', + 'FORWARD_URL' => isset($_POST['forward_url']) + ? tohtml($_POST['forward_url']) : '', + 'FORWARD_TYPE_301' => $forwardType == '301' ? ' checked' : '', + 'FORWARD_TYPE_302' => $forwardType == '302' ? ' checked' : '', + 'FORWARD_TYPE_303' => $forwardType == '303' ? ' checked' : '', + 'FORWARD_TYPE_307' => $forwardType == '307' ? ' checked' : '', + 'FORWARD_TYPE_PROXY' => $forwardType == 'proxy' ? ' checked' : '', + 'FORWARD_HOST' => $forwardHost == 'On' ? ' checked' : '', + 'WILDCARD_ALIAS_YES' => $wildcardAlias == 'yes' ? ' checked' : '', + 'WILDCARD_ALIAS_NO' => $wildcardAlias == 'no' ? ' checked' : '' ]); $domainList = getDomainsList(); if (!empty($domainList)) { $tpl->assign([ - 'SHARED_MOUNT_POINT_YES' => (isset($_POST['shared_mount_point']) + 'SHARED_MOUNT_POINT_YES' => isset($_POST['shared_mount_point']) && $_POST['shared_mount_point'] == 'yes' - ) ? ' checked' : '', - 'SHARED_MOUNT_POINT_NO' => (isset($_POST['shared_mount_point']) + ? ' checked' : '', + 'SHARED_MOUNT_POINT_NO' => isset($_POST['shared_mount_point']) && $_POST['shared_mount_point'] == 'yes' - ) ? '' : ' checked', + ? '' : ' checked', ]); foreach ($domainList as $domain) { $tpl->assign([ - 'DOMAIN_NAME' => tohtml($domain['name']), + 'DOMAIN_NAME' => tohtml($domain['name'], 'htmlAttr'), 'DOMAIN_NAME_UNICODE' => tohtml(decode_idna($domain['name'])), - 'SHARED_MOUNT_POINT_DOMAIN_SELECTED' => (isset($_POST['shared_mount_point_domain']) + 'SHARED_MOUNT_POINT_DOMAIN_SELECTED' => isset($_POST['shared_mount_point_domain']) && $_POST['shared_mount_point_domain'] == $domain['name'] - ) ? ' selected' : '' + ? ' selected' : '' ]); $tpl->parse('SHARED_MOUNT_POINT_DOMAIN', '.shared_mount_point_domain'); } @@ -199,9 +211,6 @@ function generatePage(TemplateEngine $tpl) * Add new domain alias * * @return bool TRUE on success, FALSE on failure - * @throws Zend_Exception - * @throws iMSCP_Exception - * @throws iMSCP_Exception_Database */ function addDomainAlias() { @@ -229,7 +238,10 @@ function addDomainAlias() // Check for domain alias existence if (imscp_domain_exists($domainAliasName, $_SESSION['user_created_by'])) { - set_page_message(tr('Domain %s is unavailable.', "$domainAliasName"), 'error'); + set_page_message( + tohtml(tr('Domain %s is unavailable.', $domainAliasName)), + 'error' + ); return false; } @@ -239,12 +251,17 @@ function addDomainAlias() $mountPoint = "/$domainAliasNameAscii"; // Check for shared mount point option - if (isset($_POST['shared_mount_point']) && $_POST['shared_mount_point'] == 'yes') { // We are safe here + if (isset($_POST['shared_mount_point']) + && $_POST['shared_mount_point'] == 'yes' + ) { + // We are safe here if (!isset($_POST['shared_mount_point_domain'])) { showBadRequestErrorPage(); } - $sharedMountPointDomain = clean_input($_POST['shared_mount_point_domain']); + $sharedMountPointDomain = clean_input( + $_POST['shared_mount_point_domain'] + ); $domainList = getDomainsList(); if (!empty($domainList)) { @@ -269,13 +286,18 @@ function addDomainAlias() if (isset($_POST['url_forwarding']) && $_POST['url_forwarding'] == 'yes' && isset($_POST['forward_type']) - && in_array($_POST['forward_type'], ['301', '302', '303', '307', 'proxy'], true) + && in_array( + $_POST['forward_type'], ['301', '302', '303', '307', 'proxy'], true + ) ) { - if (!isset($_POST['forward_url_scheme']) || !isset($_POST['forward_url'])) { + if (!isset($_POST['forward_url_scheme']) + || !isset($_POST['forward_url']) + ) { showBadRequestErrorPage(); } - $forwardUrl = clean_input($_POST['forward_url_scheme']) . clean_input($_POST['forward_url']); + $forwardUrl = clean_input($_POST['forward_url_scheme']) + . clean_input($_POST['forward_url']); $forwardType = clean_input($_POST['forward_type']); if ($forwardType == 'proxy' && isset($_POST['forward_host'])) { @@ -286,63 +308,84 @@ function addDomainAlias() try { $uri = iMSCP_Uri_Redirect::fromString($forwardUrl); } catch (Zend_Uri_Exception $e) { - throw new iMSCP_Exception(tr('Forward URL %s is not valid.', "$forwardUrl")); + throw new iMSCP_Exception(tr('Forward URL %s is not valid.', $forwardUrl)); } - $uri->setHost(encode_idna(mb_strtolower($uri->getHost()))); // Normalize URI host - $uri->setPath(rtrim(utils_normalizePath($uri->getPath()), '/') . '/'); // Normalize URI path + // Normalize URI host + $uri->setHost(encode_idna(mb_strtolower($uri->getHost()))); + // Normalize URI path + $uri->setPath(rtrim(utils_normalizePath($uri->getPath()), '/') . '/'); if ($uri->getHost() == $domainAliasNameAscii - && ($uri->getPath() == '/' && in_array($uri->getPort(), ['', 80, 443])) + && ($uri->getPath() == '/' + && in_array($uri->getPort(), ['', 80, 443]) + ) ) { throw new iMSCP_Exception( - tr('Forward URL %s is not valid.', "$forwardUrl") . ' ' . - tr('Domain alias %s cannot be forwarded on itself.', "$domainAliasName") + tr('Forward URL %s is not valid.', $forwardUrl) . ' ' . + tr( + 'Domain alias %s cannot be forwarded on itself.', + $domainAliasName + ) ); } if ($forwardType == 'proxy') { $port = $uri->getPort(); if ($port && $port < 1025) { - throw new iMSCP_Exception(tr('Unallowed port in forward URL. Only ports above 1024 are allowed.', 'error')); + throw new iMSCP_Exception(tohtml( + tr('Unallowed port in forward URL. Only ports above 1024 are allowed.') + )); } } $forwardUrl = $uri->getUri(); } catch (Exception $e) { - set_page_message($e->getMessage(), 'error'); + set_page_message(tohtml($e->getMessage()), 'error'); return false; } } - $isSuUser = isset($_SESSION['logged_from_type']); # See http://youtrack.i-mscp.net/issue/IP-1486 - $db = Database::getInstance(); + $wildcardAlias = isset($_POST['wildcard_alias']) + && in_array($_POST['wildcard_alias'], ['yes', 'no'], true) + ? $_POST['wildcard_alias'] : 'no'; + + # See http://youtrack.i-mscp.net/issue/IP-1486 + $isSuUser = isset($_SESSION['logged_from_type']); + $db = iMSCP_Database::getInstance(); try { $db->beginTransaction(); - EventsManager::getInstance()->dispatch(Events::onBeforeAddDomainAlias, [ - 'domainId' => $mainDmnProps['domain_id'], - 'domainAliasName' => $domainAliasNameAscii, - 'mountPoint' => $mountPoint, - 'documentRoot' => $documentRoot, - 'forwardUrl' => $forwardUrl, - 'forwardType' => $forwardType, - 'forwardHost' => $forwardHost - ]); + iMSCP_Events_Aggregator::getInstance()->dispatch( + iMSCP_Events::onBeforeAddDomainAlias, + [ + 'domainId' => $mainDmnProps['domain_id'], + 'domainAliasName' => $domainAliasNameAscii, + 'mountPoint' => $mountPoint, + 'documentRoot' => $documentRoot, + 'forwardUrl' => $forwardUrl, + 'forwardType' => $forwardType, + 'forwardHost' => $forwardHost, + 'wildcardAlias' => $wildcardAlias + ] + ); exec_query( ' INSERT INTO domain_aliasses ( - domain_id, alias_name, alias_mount, alias_document_root, alias_status, alias_ip_id, url_forward, - type_forward, host_forward + domain_id, alias_name, alias_mount, alias_document_root, + alias_status, alias_ip_id, url_forward, type_forward, + host_forward, wildcard_alias ) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, ? + ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) ', [ - $mainDmnProps['domain_id'], $domainAliasNameAscii, $mountPoint, $documentRoot, - $isSuUser ? 'toadd' : 'ordered', $mainDmnProps['domain_ip_id'], $forwardUrl, $forwardType, $forwardHost + $mainDmnProps['domain_id'], $domainAliasNameAscii, $mountPoint, + $documentRoot, $isSuUser ? 'toadd' : 'ordered', + $mainDmnProps['domain_ip_id'], $forwardUrl, $forwardType, + $forwardHost, $wildcardAlias ] ); @@ -350,18 +393,21 @@ function addDomainAlias() // Create the phpini entry for that domain alias $phpini = iMSCP_PHPini::getInstance(); - $phpini->loadResellerPermissions($_SESSION['user_created_by']); // Load reseller PHP permissions - $phpini->loadClientPermissions($_SESSION['user_id']); // Load client PHP permissions - $phpini->loadDomainIni($_SESSION['user_id'], $mainDmnProps['domain_id'], 'dmn'); // Load main domain PHP configuration options + // Load reseller PHP permissions + $phpini->loadResellerPermissions($_SESSION['user_created_by']); + // Load client PHP permissions + $phpini->loadClientPermissions($_SESSION['user_id']); + // Load main domain PHP configuration options + $phpini->loadDomainIni($_SESSION['user_id'], $mainDmnProps['domain_id'], 'dmn'); $phpini->saveDomainIni($_SESSION['user_id'], $id, 'als'); if ($isSuUser) { - $cfg = Registry::get('config'); + $cfg = iMSCP_Registry::get('config'); if ($cfg['CREATE_DEFAULT_EMAIL_ADDRESSES']) { createDefaultMailAccounts( $mainDmnProps['domain_id'], - Authentication::getInstance()->getIdentity()->email, + iMSCP_Authentication::getInstance()->getIdentity()->email, $domainAliasNameAscii, MT_ALIAS_FORWARD, $id @@ -369,53 +415,92 @@ function addDomainAlias() } } - EventsManager::getInstance()->dispatch(Events::onAfterAddDomainAlias, [ - 'domainId' => $mainDmnProps['domain_id'], - 'domainAliasName' => $domainAliasNameAscii, - 'domainAliasId' => $id, - 'mountPoint' => $mountPoint, - 'documentRoot' => $documentRoot, - 'forwardUrl' => $forwardUrl, - 'forwardType' => $forwardType, - 'forwardHost' => $forwardHost - ]); + iMSCP_Events_Aggregator::getInstance()->dispatch( + iMSCP_Events::onAfterAddDomainAlias, + [ + 'domainId' => $mainDmnProps['domain_id'], + 'domainAliasName' => $domainAliasNameAscii, + 'domainAliasId' => $id, + 'mountPoint' => $mountPoint, + 'documentRoot' => $documentRoot, + 'forwardUrl' => $forwardUrl, + 'forwardType' => $forwardType, + 'forwardHost' => $forwardHost, + 'wildcardAlias' => $wildcardAlias + ] + ); $db->commit(); if ($isSuUser) { send_request(); - write_log(sprintf('A new domain alias (%s) has been created by %s', $domainAliasName, $_SESSION['user_logged']), E_USER_NOTICE); - set_page_message(tr('Domain alias successfully created.'), 'success'); + write_log( + sprintf( + 'A new domain alias (%s) has been created by %s', + $domainAliasName, + $_SESSION['user_logged'] + ), + E_USER_NOTICE + ); + set_page_message( + tohtml(tr('Domain alias successfully created.')), + 'success' + ); } else { send_alias_order_email($domainAliasName); - write_log(sprintf('A new domain alias (%s) has been ordered by %s', $domainAliasName, $_SESSION['user_logged']), E_USER_NOTICE); - set_page_message(tr('Domain alias successfully ordered.'), 'success'); + write_log( + sprintf( + 'A new domain alias (%s) has been ordered by %s', + $domainAliasName, + $_SESSION['user_logged'] + ), + E_USER_NOTICE + ); + set_page_message( + tohtml(tr('Domain alias successfully ordered.')), + 'success' + ); } } catch (iMSCP_Exception $e) { $db->rollBack(); - write_log(sprintf('System was unable to create the %s domain alias: %s', $domainAliasName, $e->getMessage()), E_USER_ERROR); - set_page_message(tr('Could not create domain alias. An unexpected error occurred.'), 'error'); + write_log( + sprintf( + 'System was unable to create the %s domain alias: %s', + $domainAliasName, + $e->getMessage() + ), + E_USER_ERROR + ); + set_page_message( + tohtml(tr('Could not create domain alias. An unexpected error occurred.')), + 'error' + ); return false; } return true; } -/*********************************************************************************************************************** - * Main - */ - require_once 'imscp-lib.php'; check_login('user'); -EventsManager::getInstance()->dispatch(Events::onClientScriptStart); +iMSCP_Events_Aggregator::getInstance()->dispatch( + iMSCP_Events::onClientScriptStart +); customerHasFeature('domain_aliases') or showBadRequestErrorPage(); $mainDmnProps = get_domain_default_props($_SESSION['user_id']); -$domainAliasesCount = get_customer_domain_aliases_count($mainDmnProps['domain_id']); - -if ($mainDmnProps['domain_alias_limit'] != 0 && $domainAliasesCount >= $mainDmnProps['domain_alias_limit']) { - set_page_message(tr('You have reached the maximum number of domain aliases allowed by your subscription.'), 'warning'); +$domainAliasesCount = get_customer_domain_aliases_count( + $mainDmnProps['domain_id'] +); + +if ($mainDmnProps['domain_alias_limit'] != 0 + && $domainAliasesCount >= $mainDmnProps['domain_alias_limit'] +) { + set_page_message( + tohtml(tr('You have reached the maximum number of domain aliases allowed by your subscription.')), + 'warning' + ); redirectTo('domains_manage.php'); } @@ -423,7 +508,7 @@ function addDomainAlias() redirectTo('domains_manage.php'); } -$tpl = new TemplateEngine(); +$tpl = new iMSCP_pTemplate(); $tpl->define_dynamic([ 'layout' => 'shared/layouts/ui.tpl', 'page' => 'client/alias_add.tpl', @@ -433,27 +518,29 @@ function addDomainAlias() 'shared_mount_point_domain' => 'shared_mount_point_option' ]); $tpl->assign([ - 'TR_PAGE_TITLE' => tr('Client / Domains / Add Domain Alias'), - 'TR_DOMAIN_ALIAS' => tr('Domain alias'), - 'TR_DOMAIN_ALIAS_NAME' => tr('Domain alias name'), - 'TR_SHARED_MOUNT_POINT' => tr('Shared mount point'), - 'TR_SHARED_MOUNT_POINT_TOOLTIP' => tr('Allows to share the mount point of another domain.'), - 'TR_URL_FORWARDING' => tr('URL forwarding'), - 'TR_URL_FORWARDING_TOOLTIP' => tr('Allows to forward any request made to this domain to a specific URL.'), - 'TR_FORWARD_TO_URL' => tr('Forward to URL'), - 'TR_YES' => tr('Yes'), - 'TR_NO' => tr('No'), - 'TR_HTTP' => 'http://', - 'TR_HTTPS' => 'https://', - 'TR_FORWARD_TYPE' => tr('Forward type'), - 'TR_301' => '301', - 'TR_302' => '302', - 'TR_303' => '303', - 'TR_307' => '307', - 'TR_PROXY' => 'PROXY', - 'TR_PROXY_PRESERVE_HOST' => tr('Preserve Host'), - 'TR_ADD' => tr('Add'), - 'TR_CANCEL' => tr('Cancel') + 'TR_PAGE_TITLE' => tohtml(tr('Client / Domains / Add Domain Alias')), + 'TR_DOMAIN_ALIAS' => tohtml(tr('Domain alias')), + 'TR_DOMAIN_ALIAS_NAME' => tohtml(tr('Domain alias name')), + 'TR_SHARED_MOUNT_POINT' => tohtml(tr('Shared mount point')), + 'TR_SHARED_MOUNT_POINT_TOOLTIP' => tohtml(tr('Allows to share the mount point of another domain.'), 'htmlAttr'), + 'TR_URL_FORWARDING' => tohtml(tr('URL forwarding')), + 'TR_URL_FORWARDING_TOOLTIP' => tohtml(tr('Allows to forward any request made to this domain to a specific URL.'), 'htmlAttr'), + 'TR_FORWARD_TO_URL' => tohtml(tr('Forward to URL')), + 'TR_YES' => tohtml(tr('Yes')), + 'TR_NO' => tohtml(tr('No')), + 'TR_HTTP' => tohtml('http://'), + 'TR_HTTPS' => tohtml('https://'), + 'TR_FORWARD_TYPE' => tohtml(tr('Forward type')), + 'TR_301' => tohtml('301'), + 'TR_302' => tohtml('302'), + 'TR_303' => tohtml('303'), + 'TR_307' => tohtml('307'), + 'TR_PROXY' => tohtml('PROXY'), + 'TR_PROXY_PRESERVE_HOST' => tohtml(tr('Preserve Host')), + 'TR_WILDCARD_ALIAS_TOOLTIP' => tohtml(tr("If enabled, a wildcard alias entry such as '*.domain.tld' will be added in the Web server configuration. This option is most suitable for software that provide multisite feature such as the Wordpress CMS. Be aware that the control panel won't check for possible conflicts with subdomains."), 'htmlAttr'), + 'TR_WILDCARD_ALIAS' => tohtml(tr('Wildcard alias')), + 'TR_ADD' => tohtml(tr('Add'), 'htmlAttr'), + 'TR_CANCEL' => tohtml(tr('Cancel')) ]); generateNavigation($tpl); @@ -461,7 +548,9 @@ function addDomainAlias() generatePageMessage($tpl); $tpl->parse('LAYOUT_CONTENT', 'page'); -EventsManager::getInstance()->dispatch(Events::onClientScriptEnd, ['templateEngine' => $tpl]); +iMSCP_Events_Aggregator::getInstance()->dispatch( + iMSCP_Events::onClientScriptEnd, ['templateEngine' => $tpl] +); $tpl->prnt(); unsetMessages(); diff --git a/gui/public/client/alias_edit.php b/gui/public/client/alias_edit.php index 2df988f3a3..5b1d0e3b24 100644 --- a/gui/public/client/alias_edit.php +++ b/gui/public/client/alias_edit.php @@ -1,7 +1,7 @@ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -18,11 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -use iMSCP\VirtualFileSystem as VirtualFileSystem; - -/*********************************************************************************************************************** - * Functions - */ +/** @noinspection PhpUnhandledExceptionInspection PhpDocMissingThrowsInspection */ /** * Get domain alias data @@ -30,8 +26,6 @@ * @access private * @param int $domainAliasId Subdomain unique identifier * @return array|bool Domain alias data or FALSE on error - * @throws iMSCP_Exception - * @throws iMSCP_Exception_Database */ function _client_getAliasData($domainAliasId) { @@ -43,7 +37,8 @@ function _client_getAliasData($domainAliasId) $stmt = exec_query( ' - SELECT alias_name, alias_mount, alias_document_root, url_forward, type_forward, host_forward + SELECT alias_name, alias_mount, alias_document_root, url_forward, + type_forward, host_forward, wildcard_alias FROM domain_aliasses WHERE alias_id = ? AND domain_id = ? @@ -57,7 +52,9 @@ function _client_getAliasData($domainAliasId) } $domainAliasData = $stmt->fetchRow(); - $domainAliasData['alias_name_utf8'] = decode_idna($domainAliasData['alias_name']); + $domainAliasData['alias_name_utf8'] = decode_idna( + $domainAliasData['alias_name'] + ); return $domainAliasData; } @@ -66,11 +63,6 @@ function _client_getAliasData($domainAliasId) * * @param $tpl iMSCP_pTemplate * @return void - * @throws Zend_Exception - * @throws Zend_Uri_Exception - * @throws iMSCP_Exception - * @throws iMSCP_Exception_Database - * @throws iMSCP_Uri_Exception */ function client_generatePage($tpl) { @@ -87,9 +79,9 @@ function client_generatePage($tpl) $forwardHost = 'Off'; if (empty($_POST)) { - $documentRoot = strpos($domainAliasData['alias_document_root'], '/htdocs') !== FALSE - ? substr($domainAliasData['alias_document_root'], 7) - : ''; + $documentRoot = strpos( + $domainAliasData['alias_document_root'], '/htdocs' + ) !== false ? substr($domainAliasData['alias_document_root'], 7) : ''; if ($domainAliasData['url_forward'] != 'no') { $urlForwarding = true; @@ -105,42 +97,62 @@ function client_generatePage($tpl) $forwardUrl = ''; $forwardType = '302'; } + + $wildcardAlias = $domainAliasData['wildcard_alias']; } else { - $documentRoot = (isset($_POST['document_root'])) ? $_POST['document_root'] : ''; - $urlForwarding = (isset($_POST['url_forwarding']) && $_POST['url_forwarding'] == 'yes') ? true : false; - $forwardUrlScheme = (isset($_POST['forward_url_scheme'])) ? $_POST['forward_url_scheme'] : 'http://'; - $forwardUrl = (isset($_POST['forward_url'])) ? $_POST['forward_url'] : ''; - $forwardType = ( - isset($_POST['forward_type']) - && in_array($_POST['forward_type'], ['301', '302', '303', '307', 'proxy'], true) - ) ? $_POST['forward_type'] : '302'; + $documentRoot = isset($_POST['document_root']) + ? $_POST['document_root'] : ''; + $urlForwarding = isset($_POST['url_forwarding']) + && $_POST['url_forwarding'] == 'yes' + ? true : false; + $forwardUrlScheme = isset($_POST['forward_url_scheme']) + ? $_POST['forward_url_scheme'] : 'http://'; + $forwardUrl = isset($_POST['forward_url']) + ? $_POST['forward_url'] : ''; + $forwardType = isset($_POST['forward_type']) + && in_array( + $_POST['forward_type'], + ['301', '302', '303', '307', 'proxy'], + true + ) + ? $_POST['forward_type'] : '302'; if ($forwardType == 'proxy' && isset($_POST['forward_host'])) { $forwardHost = 'On'; } + + $wildcardAlias = isset($_POST['wildcard_alias']) + && in_array($_POST['wildcard_alias'], ['yes', 'no'], true) + ? $_POST['wildcard_alias'] : 0; } $tpl->assign([ - 'DOMAIN_ALIAS_ID' => $domainAliasId, - 'DOMAIN_ALIAS_NAME' => tohtml($domainAliasData['alias_name_utf8']), - 'DOCUMENT_ROOT' => tohtml($documentRoot), - 'FORWARD_URL_YES' => ($urlForwarding) ? ' checked' : '', - 'FORWARD_URL_NO' => ($urlForwarding) ? '' : ' checked', - 'HTTP_YES' => ($forwardUrlScheme == 'http://') ? ' selected' : '', - 'HTTPS_YES' => ($forwardUrlScheme == 'https://') ? ' selected' : '', - 'FORWARD_URL' => tohtml($forwardUrl), - 'FORWARD_TYPE_301' => ($forwardType == '301') ? ' checked' : '', - 'FORWARD_TYPE_302' => ($forwardType == '302') ? ' checked' : '', - 'FORWARD_TYPE_303' => ($forwardType == '303') ? ' checked' : '', - 'FORWARD_TYPE_307' => ($forwardType == '307') ? ' checked' : '', - 'FORWARD_TYPE_PROXY' => ($forwardType == 'proxy') ? ' checked' : '', - 'FORWARD_HOST' => ($forwardHost == 'On') ? ' checked' : '' + 'DOMAIN_ALIAS_ID' => tohtml($domainAliasId, 'htmlAttr'), + 'DOMAIN_ALIAS_NAME' => tohtml($domainAliasData['alias_name_utf8'], 'htmlAttr'), + 'DOCUMENT_ROOT' => tohtml($documentRoot, 'htmlAttr'), + 'FORWARD_URL_YES' => $urlForwarding ? ' checked' : '', + 'FORWARD_URL_NO' => $urlForwarding ? '' : ' checked', + 'HTTP_YES' => $forwardUrlScheme == 'http://' + ? ' selected' : '', + 'HTTPS_YES' => $forwardUrlScheme == 'https://' + ? ' selected' : '', + 'FORWARD_URL' => tohtml($forwardUrl, 'htmlAttr'), + 'FORWARD_TYPE_301' => $forwardType == '301' ? ' checked' : '', + 'FORWARD_TYPE_302' => $forwardType == '302' ? ' checked' : '', + 'FORWARD_TYPE_303' => $forwardType == '303' ? ' checked' : '', + 'FORWARD_TYPE_307' => $forwardType == '307' ? ' checked' : '', + 'FORWARD_TYPE_PROXY' => $forwardType == 'proxy' ? ' checked' : '', + 'FORWARD_HOST' => $forwardHost == 'On' ? ' checked' : '', + 'WILDCARD_ALIAS_YES' => $wildcardAlias == 'yes' ? ' checked' : '', + 'WILDCARD_ALIAS_NO' => $wildcardAlias == 'no' ? ' checked' : '' ]); // Cover the case where URL forwarding feature is activated and that the // default /htdocs directory doesn't exists yet if ($domainAliasData['url_forward'] != 'no') { - $vfs = new VirtualFileSystem($_SESSION['user_logged'], $domainAliasData['alias_mount']); + $vfs = new iMSCP\VirtualFileSystem( + $_SESSION['user_logged'], $domainAliasData['alias_mount'] + ); if (!$vfs->exists('/htdocs')) { $tpl->assign('DOCUMENT_ROOT_BLOC', ''); @@ -149,9 +161,13 @@ function client_generatePage($tpl) } # Set parameters for the FTP chooser - $_SESSION['ftp_chooser_domain_id'] = get_user_domain_id($_SESSION['user_id']); + $_SESSION['ftp_chooser_domain_id'] = get_user_domain_id( + $_SESSION['user_id'] + ); $_SESSION['ftp_chooser_user'] = $_SESSION['user_logged']; - $_SESSION['ftp_chooser_root_dir'] = utils_normalizePath($domainAliasData['alias_mount'] . '/htdocs'); + $_SESSION['ftp_chooser_root_dir'] = utils_normalizePath( + $domainAliasData['alias_mount'] . '/htdocs' + ); $_SESSION['ftp_chooser_hidden_dirs'] = []; $_SESSION['ftp_chooser_unselectable_dirs'] = []; } @@ -160,10 +176,6 @@ function client_generatePage($tpl) * Edit domain alias * * @return bool TRUE on success, FALSE on failure - * @throws Zend_Exception - * @throws iMSCP_Events_Manager_Exception - * @throws iMSCP_Exception - * @throws iMSCP_Exception_Database */ function client_editDomainAlias() { @@ -188,13 +200,18 @@ function client_editDomainAlias() if (isset($_POST['url_forwarding']) && $_POST['url_forwarding'] == 'yes' && isset($_POST['forward_type']) - && in_array($_POST['forward_type'], ['301', '302', '303', '307', 'proxy'], true) + && in_array( + $_POST['forward_type'], ['301', '302', '303', '307', 'proxy'], true + ) ) { - if (!isset($_POST['forward_url_scheme']) || !isset($_POST['forward_url'])) { + if (!isset($_POST['forward_url_scheme']) + || !isset($_POST['forward_url']) + ) { showBadRequestErrorPage(); } - $forwardUrl = clean_input($_POST['forward_url_scheme']) . clean_input($_POST['forward_url']); + $forwardUrl = clean_input($_POST['forward_url_scheme']) + . clean_input($_POST['forward_url']); $forwardType = clean_input($_POST['forward_type']); if ($forwardType == 'proxy' && isset($_POST['forward_host'])) { @@ -205,20 +222,24 @@ function client_editDomainAlias() try { $uri = iMSCP_Uri_Redirect::fromString($forwardUrl); } catch (Zend_Uri_Exception $e) { - throw new iMSCP_Exception(tr('Forward URL %s is not valid.', "$forwardUrl")); + throw new iMSCP_Exception(tohtml( + tr('Forward URL %s is not valid.', $forwardUrl) + )); } - $uri->setHost(encode_idna(mb_strtolower($uri->getHost()))); // Normalize URI host - $uri->setPath(rtrim(utils_normalizePath($uri->getPath()), '/') . '/'); // Normalize URI path + // Normalize URI host + $uri->setHost(encode_idna(mb_strtolower($uri->getHost()))); + // Normalize URI path + $uri->setPath(rtrim(utils_normalizePath($uri->getPath()), '/') . '/'); if ($uri->getHost() == $domainAliasData['alias_name'] && ($uri->getPath() == '/' && in_array($uri->getPort(), ['', 80, 443])) ) { throw new iMSCP_Exception( - tr('Forward URL %s is not valid.', "$forwardUrl") . ' ' . + tr('Forward URL %s is not valid.', $forwardUrl) . ' ' . tr( 'Domain alias %s cannot be forwarded on itself.', - "{$domainAliasData['alias_name_utf8']}" + $domainAliasData['alias_name_utf8'] ) ); } @@ -226,24 +247,34 @@ function client_editDomainAlias() if ($forwardType == 'proxy') { $port = $uri->getPort(); if ($port && $port < 1025) { - throw new iMSCP_Exception(tr('Unallowed port in forward URL. Only ports above 1024 are allowed.', 'error')); + throw new iMSCP_Exception(tohtml( + tr('Unallowed port in forward URL. Only ports above 1024 are allowed.') + )); } } $forwardUrl = $uri->getUri(); } catch (Exception $e) { - set_page_message($e->getMessage(), 'error'); + set_page_message(tohtml($e->getMessage()), 'error'); return false; } - } // Check for alternative DocumentRoot option - elseif (isset($_POST['document_root'])) { + } elseif (isset($_POST['document_root'])) { + // Check for alternative DocumentRoot option $documentRoot = utils_normalizePath('/' . clean_input($_POST['document_root'])); if ($documentRoot !== '') { - $vfs = new VirtualFileSystem($_SESSION['user_logged'], $domainAliasData['alias_mount'] . '/htdocs'); + $vfs = new iMSCP\VirtualFileSystem( + $_SESSION['user_logged'], + $domainAliasData['alias_mount'] . '/htdocs' + ); - if ($documentRoot !== '/' && !$vfs->exists($documentRoot, VirtualFileSystem::VFS_TYPE_DIR)) { - set_page_message(tr('The new document root must pre-exists inside the /htdocs directory.'), 'error'); + if ($documentRoot !== '/' + && !$vfs->exists($documentRoot, iMSCP\VirtualFileSystem::VFS_TYPE_DIR) + ) { + set_page_message( + tohtml(tr('The new document root must pre-exists inside the /htdocs directory.')), + 'error' + ); return false; } } @@ -251,43 +282,61 @@ function client_editDomainAlias() $documentRoot = utils_normalizePath('/htdocs' . $documentRoot); } - iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onBeforeEditDomainAlias, [ - 'domainAliasId' => $domainAliasId, - 'mountPoint' => $domainAliasData['alias_mount'], - 'documentRoot' => $documentRoot, - 'forwardUrl' => $forwardUrl, - 'forwardType' => $forwardType, - 'forwardHost' => $forwardHost - ]); + $wildcardAlias = isset($_POST['wildcard_alias']) + && in_array($_POST['wildcard_alias'], ['yes', 'no'], true) + ? $_POST['wildcard_alias'] : 'no'; + + iMSCP_Events_Aggregator::getInstance()->dispatch( + iMSCP_Events::onBeforeEditDomainAlias, + [ + 'domainAliasId' => $domainAliasId, + 'mountPoint' => $domainAliasData['alias_mount'], + 'documentRoot' => $documentRoot, + 'forwardUrl' => $forwardUrl, + 'forwardType' => $forwardType, + 'forwardHost' => $forwardHost, + 'wildcardAlias' => $wildcardAlias + ] + ); exec_query( ' UPDATE domain_aliasses - SET alias_document_root = ?, url_forward = ?, type_forward = ?, host_forward = ?, alias_status = ? + SET alias_document_root = ?, url_forward = ?, type_forward = ?, + host_forward = ?, wildcard_alias = ?, alias_status = ? WHERE alias_id = ? ', - [$documentRoot, $forwardUrl, $forwardType, $forwardHost, 'tochange', $domainAliasId] + [ + $documentRoot, $forwardUrl, $forwardType, $forwardHost, + $wildcardAlias, 'tochange', $domainAliasId + ] ); - iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onAfterEditDomainAlias, [ - 'domainAliasId' => $domainAliasId, - 'mountPoint' => $domainAliasData['alias_mount'], - 'documentRoot' => $documentRoot, - 'forwardUrl' => $forwardUrl, - 'forwardType' => $forwardType, - 'forwardHost' => $forwardHost - ]); + iMSCP_Events_Aggregator::getInstance()->dispatch( + iMSCP_Events::onAfterEditDomainAlias, + [ + 'domainAliasId' => $domainAliasId, + 'mountPoint' => $domainAliasData['alias_mount'], + 'documentRoot' => $documentRoot, + 'forwardUrl' => $forwardUrl, + 'forwardType' => $forwardType, + 'forwardHost' => $forwardHost, + 'wildcardAlias' => $wildcardAlias + ] + ); send_request(); - write_log(sprintf('%s updated properties of the %s domain alias', $_SESSION['user_logged'], $domainAliasData['alias_name_utf8']), E_USER_NOTICE); + write_log( + sprintf( + '%s updated properties of the %s domain alias', + $_SESSION['user_logged'], + $domainAliasData['alias_name_utf8'] + ), + E_USER_NOTICE + ); return true; } -/*********************************************************************************************************************** - * Main - */ - - require_once 'imscp-lib.php'; check_login('user'); @@ -307,43 +356,51 @@ function client_editDomainAlias() 'document_root_bloc' => 'page' ]); $tpl->assign([ - 'TR_PAGE_TITLE' => tr('Client / Domains / Edit Domain Alias'), - 'TR_DOMAIN_ALIAS' => tr('Domain alias'), - 'TR_DOMAIN_ALIAS_NAME' => tr('Domain alias name'), - 'TR_DOCUMENT_ROOT' => tr('Document root'), - 'TR_DOCUMENT_ROOT_TOOLTIP' => tr("You can set an alternative document root. This is mostly needed when using a PHP framework such as Symfony. Note that the new document root will live inside the default `/htdocs' document root. Be aware that the directory for the new document root must pre-exist."), - 'TR_CHOOSE_DIR' => tr('Choose dir'), - 'TR_URL_FORWARDING' => tr('URL forwarding'), - 'TR_FORWARD_TO_URL' => tr('Forward to URL'), - 'TR_URL_FORWARDING_TOOLTIP' => tr('Allows to forward any request made to this domain to a specific URL.'), - 'TR_YES' => tr('Yes'), - 'TR_NO' => tr('No'), - 'TR_HTTP' => 'http://', - 'TR_HTTPS' => 'https://', - 'TR_FORWARD_TYPE' => tr('Forward type'), - 'TR_301' => '301', - 'TR_302' => '302', - 'TR_303' => '303', - 'TR_307' => '307', - 'TR_PROXY' => 'PROXY', - 'TR_PROXY_PRESERVE_HOST' => tr('Preserve Host'), - 'TR_UPDATE' => tr('Update'), - 'TR_CANCEL' => tr('Cancel') + 'TR_PAGE_TITLE' => tohtml(tr('Client / Domains / Edit Domain Alias')), + 'TR_DOMAIN_ALIAS' => tohtml(tr('Domain alias')), + 'TR_DOMAIN_ALIAS_NAME' => tohtml(tr('Domain alias name')), + 'TR_DOCUMENT_ROOT' => tohtml(tr('Document root')), + 'TR_DOCUMENT_ROOT_TOOLTIP' => tohtml(tr("You can set an alternative document root. This is mostly needed when using a PHP framework such as Symfony. Note that the new document root will live inside the default `/htdocs' document root. Be aware that the directory for the new document root must pre-exist."), 'htmlAttr'), + 'TR_CHOOSE_DIR' => tohtml(tr('Choose dir')), + 'TR_URL_FORWARDING' => tohtml(tr('URL forwarding')), + 'TR_FORWARD_TO_URL' => tohtml(tr('Forward to URL')), + 'TR_URL_FORWARDING_TOOLTIP' => tohtml(tr('Allows to forward any request made to this domain to a specific URL.'), 'htmlAttr'), + 'TR_YES' => tohtml(tr('Yes')), + 'TR_NO' => tohtml(tr('No')), + 'TR_HTTP' => tohtml('http://'), + 'TR_HTTPS' => tohtml('https://'), + 'TR_FORWARD_TYPE' => tohtml(tr('Forward type')), + 'TR_301' => tohtml('301'), + 'TR_302' => tohtml('302'), + 'TR_303' => tohtml('303'), + 'TR_307' => tohtml('307'), + 'TR_PROXY' => tohtml('PROXY'), + 'TR_PROXY_PRESERVE_HOST' => tohtml(tr('Preserve Host')), + 'TR_WILDCARD_ALIAS_TOOLTIP' => tohtml(tr("If enabled, a wildcard alias entry such as '*.domain.tld' will be added in the Web server configuration. This option is most suitable for software that provide multisite feature such as the Wordpress CMS. Be aware that the control panel won't check for possible conflicts with subdomains."), 'htmlAttr'), + 'TR_WILDCARD_ALIAS' => tohtml(tr('Wildcard alias')), + 'TR_UPDATE' => tohtml(tr('Update'), 'htmlAttr'), + 'TR_CANCEL' => tohtml(tr('Cancel')) ]); -iMSCP_Events_Aggregator::getInstance()->registerListener('onGetJsTranslations', function ($e) { - /** @var $e iMSCP_Events_Event */ - $translations = $e->getParam('translations'); - $translations['core']['close'] = tr('Close'); - $translations['core']['ftp_directories'] = tr('Select your own document root'); -}); +iMSCP_Events_Aggregator::getInstance()->registerListener( + iMSCP_Events::onGetJsTranslations, + function (iMSCP_Events_Event $e) { + $translations = $e->getParam('translations'); + $translations['core']['close'] = tr('Close'); + $translations['core']['ftp_directories'] = tr( + 'Select your own document root' + ); + } +); generateNavigation($tpl); client_generatePage($tpl); generatePageMessage($tpl); $tpl->parse('LAYOUT_CONTENT', 'page'); -iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onClientScriptEnd, ['templateEngine' => $tpl]); +iMSCP_Events_Aggregator::getInstance()->dispatch( + iMSCP_Events::onClientScriptEnd, ['templateEngine' => $tpl] +); $tpl->prnt(); unsetMessages(); diff --git a/gui/public/client/domain_edit.php b/gui/public/client/domain_edit.php index 0cb76cb7f8..77f309ef03 100644 --- a/gui/public/client/domain_edit.php +++ b/gui/public/client/domain_edit.php @@ -1,7 +1,7 @@ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -18,11 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -use iMSCP\VirtualFileSystem as VirtualFileSystem; - -/*********************************************************************************************************************** - * Functions - */ +/** @noinspection PhpUnhandledExceptionInspection PhpDocMissingThrowsInspection */ /** * Get domain data @@ -30,8 +26,6 @@ * @access private * @param int $domainId Domain unique identifier * @return array|bool Domain data or FALSE on error - * @throws iMSCP_Events_Exception - * @throws iMSCP_Exception_Database */ function _client_getDomainData($domainId) { @@ -43,7 +37,8 @@ function _client_getDomainData($domainId) $stmt = exec_query( ' - SELECT domain_name, document_root, url_forward, type_forward, host_forward + SELECT domain_name, document_root, url_forward, type_forward, + host_forward, wildcard_alias FROM domain WHERE domain_id = ? AND domain_admin_id = ? @@ -66,11 +61,6 @@ function _client_getDomainData($domainId) * * @param $tpl iMSCP_pTemplate * @return void - * @throws Zend_Exception - * @throws Zend_Uri_Exception - * @throws iMSCP_Exception - * @throws iMSCP_Exception_Database - * @throws iMSCP_Uri_Exception */ function client_generatePage($tpl) { @@ -87,9 +77,8 @@ function client_generatePage($tpl) $forwardHost = 'Off'; if (empty($_POST)) { - $documentRoot = strpos($domainData['document_root'], '/htdocs') !== FALSE - ? substr($domainData['document_root'], 7) - : ''; + $documentRoot = strpos($domainData['document_root'], '/htdocs') !== false + ? substr($domainData['document_root'], 7) : ''; if ($domainData['url_forward'] != 'no') { $urlForwarding = true; @@ -105,40 +94,55 @@ function client_generatePage($tpl) $forwardUrl = ''; $forwardType = '302'; } + + $wildcardAlias = $domainData['wildcard_alias']; } else { - $documentRoot = (isset($_POST['document_root'])) ? $_POST['document_root'] : ''; - $urlForwarding = (isset($_POST['url_forwarding']) && $_POST['url_forwarding'] == 'yes') ? true : false; - $forwardUrlScheme = (isset($_POST['forward_url_scheme'])) ? $_POST['forward_url_scheme'] : 'http://'; - $forwardUrl = (isset($_POST['forward_url'])) ? $_POST['forward_url'] : ''; - $forwardType = (isset($_POST['forward_type']) && in_array($_POST['forward_type'], ['301', '302', '303', '307', 'proxy'], true)) ? $_POST['forward_type'] : '302'; + $documentRoot = isset($_POST['document_root']) + ? $_POST['document_root'] : ''; + $urlForwarding = isset($_POST['url_forwarding']) + && $_POST['url_forwarding'] == 'yes' + ? true : false; + $forwardUrlScheme = isset($_POST['forward_url_scheme']) + ? $_POST['forward_url_scheme'] : 'http://'; + $forwardUrl = isset($_POST['forward_url']) ? $_POST['forward_url'] : ''; + $forwardType = isset($_POST['forward_type']) + && in_array($_POST['forward_type'], ['301', '302', '303', '307', 'proxy'], true) + ? $_POST['forward_type'] : '302'; if ($forwardType == 'proxy' && isset($_POST['forward_host'])) { $forwardHost = 'On'; } + + $wildcardAlias = isset($_POST['wildcard_alias']) + && in_array($_POST['wildcard_alias'], ['yes', 'no'], true) + ? $_POST['wildcard_alias'] : 'no'; } $tpl->assign([ - 'DOMAIN_ID' => $domainId, - 'DOMAIN_NAME' => tohtml($domainData['domain_name_utf8']), - 'DOCUMENT_ROOT' => tohtml($documentRoot), - 'FORWARD_URL_YES' => ($urlForwarding) ? ' checked' : '', - 'FORWARD_URL_NO' => ($urlForwarding) ? '' : ' checked', - 'HTTP_YES' => ($forwardUrlScheme == 'http://') ? ' selected' : '', - 'HTTPS_YES' => ($forwardUrlScheme == 'https://') ? ' selected' : '', - 'FORWARD_URL' => tohtml($forwardUrl), - 'FORWARD_TYPE_301' => ($forwardType == '301') ? ' checked' : '', - 'FORWARD_TYPE_302' => ($forwardType == '302') ? ' checked' : '', - 'FORWARD_TYPE_303' => ($forwardType == '303') ? ' checked' : '', - 'FORWARD_TYPE_307' => ($forwardType == '307') ? ' checked' : '', - 'FORWARD_TYPE_PROXY' => ($forwardType == 'proxy') ? ' checked' : '', - 'FORWARD_HOST' => ($forwardHost == 'On') ? ' checked' : '' + 'DOMAIN_ID' => tohtml($domainId, 'htmlAttr'), + 'DOMAIN_NAME' => tohtml($domainData['domain_name_utf8'], 'htmlAttr'), + 'DOCUMENT_ROOT' => tohtml($documentRoot, 'htmlAttr'), + 'FORWARD_URL_YES' => $urlForwarding ? ' checked' : '', + 'FORWARD_URL_NO' => $urlForwarding ? '' : ' checked', + 'HTTP_YES' => $forwardUrlScheme == 'http://' + ? ' selected' : '', + 'HTTPS_YES' => $forwardUrlScheme == 'https://' + ? ' selected' : '', + 'FORWARD_URL' => tohtml($forwardUrl, 'htmlAttr'), + 'FORWARD_TYPE_301' => $forwardType == '301' ? ' checked' : '', + 'FORWARD_TYPE_302' => $forwardType == '302' ? ' checked' : '', + 'FORWARD_TYPE_303' => $forwardType == '303' ? ' checked' : '', + 'FORWARD_TYPE_307' => $forwardType == '307' ? ' checked' : '', + 'FORWARD_TYPE_PROXY' => $forwardType == 'proxy' ? ' checked' : '', + 'FORWARD_HOST' => $forwardHost == 'On' ? ' checked' : '', + 'WILDCARD_ALIAS_YES' => $wildcardAlias == 'yes' ? ' checked' : '', + 'WILDCARD_ALIAS_NO' => $wildcardAlias == 'no' ? ' checked' : '' ]); // Cover the case where URL forwarding feature is activated and that the // default /htdocs directory doesn't exists yet if ($domainData['url_forward'] != 'no') { - $vfs = new VirtualFileSystem($_SESSION['user_logged']); - + $vfs = new iMSCP\VirtualFileSystem($_SESSION['user_logged']); if (!$vfs->exists('/htdocs')) { $tpl->assign('DOCUMENT_ROOT_BLOC', ''); return; @@ -157,10 +161,6 @@ function client_generatePage($tpl) * Edit domain * * @return bool TRUE on success, FALSE on failure - * @throws Zend_Exception - * @throws iMSCP_Events_Manager_Exception - * @throws iMSCP_Exception - * @throws iMSCP_Exception_Database */ function client_editDomain() { @@ -185,13 +185,20 @@ function client_editDomain() if (isset($_POST['url_forwarding']) && $_POST['url_forwarding'] == 'yes' && isset($_POST['forward_type']) - && in_array($_POST['forward_type'], ['301', '302', '303', '307', 'proxy'], true) + && in_array( + $_POST['forward_type'], + ['301', '302', '303', '307', 'proxy'], + true + ) ) { - if (!isset($_POST['forward_url_scheme']) || !isset($_POST['forward_url'])) { + if (!isset($_POST['forward_url_scheme']) + || !isset($_POST['forward_url']) + ) { showBadRequestErrorPage(); } - $forwardUrl = clean_input($_POST['forward_url_scheme']) . clean_input($_POST['forward_url']); + $forwardUrl = clean_input($_POST['forward_url_scheme']) + . clean_input($_POST['forward_url']); $forwardType = clean_input($_POST['forward_type']); if ($forwardType == 'proxy' && isset($_POST['forward_host'])) { @@ -202,20 +209,26 @@ function client_editDomain() try { $uri = iMSCP_Uri_Redirect::fromString($forwardUrl); } catch (Zend_Uri_Exception $e) { - throw new iMSCP_Exception(tr('Forward URL %s is not valid.', "$forwardUrl")); + throw new iMSCP_Exception( + tr('Forward URL %s is not valid.', $forwardUrl) + ); } - $uri->setHost(encode_idna(mb_strtolower($uri->getHost()))); // Normalize URI host - $uri->setPath(rtrim(utils_normalizePath($uri->getPath()), '/') . '/'); // Normalize URI path + // Normalize URI host + $uri->setHost(encode_idna(mb_strtolower($uri->getHost()))); + // Normalize URI path + $uri->setPath(rtrim(utils_normalizePath($uri->getPath()), '/') . '/'); if ($uri->getHost() == $domainData['domain_name'] - && ($uri->getPath() == '/' && in_array($uri->getPort(), ['', 80, 443])) + && ($uri->getPath() == '/' + && in_array($uri->getPort(), ['', 80, 443]) + ) ) { throw new iMSCP_Exception( - tr('Forward URL %s is not valid.', "$forwardUrl") . ' ' . + tr('Forward URL %s is not valid.', $forwardUrl) . ' ' . tr( 'Domain %s cannot be forwarded on itself.', - "{$domainData['domain_name_utf8']}" + $domainData['domain_name_utf8'] ) ); } @@ -223,24 +236,35 @@ function client_editDomain() if ($forwardType == 'proxy') { $port = $uri->getPort(); if ($port && $port < 1025) { - throw new iMSCP_Exception(tr('Unallowed port in forward URL. Only ports above 1024 are allowed.', 'error')); + throw new iMSCP_Exception( + tr('Unallowed port in forward URL. Only ports above 1024 are allowed.') + ); } } $forwardUrl = $uri->getUri(); } catch (Exception $e) { - set_page_message($e->getMessage(), 'error'); + set_page_message(tohtml($e->getMessage()), 'error'); return false; } } // Check for alternative DocumentRoot option elseif (isset($_POST['document_root'])) { - $documentRoot = utils_normalizePath('/' . clean_input($_POST['document_root'])); + $documentRoot = utils_normalizePath( + '/' . clean_input($_POST['document_root']) + ); if ($documentRoot !== '') { - $vfs = new VirtualFileSystem($_SESSION['user_logged'], '/htdocs'); + $vfs = new iMSCP\VirtualFileSystem( + $_SESSION['user_logged'], '/htdocs' + ); - if ($documentRoot !== '/' && !$vfs->exists($documentRoot, VirtualFileSystem::VFS_TYPE_DIR)) { - set_page_message(tr('The new document root must pre-exists inside the /htdocs directory.'), 'error'); + if ($documentRoot !== '/' + && !$vfs->exists($documentRoot, iMSCP\VirtualFileSystem::VFS_TYPE_DIR) + ) { + set_page_message( + tohtml(tr('The new document root must pre-exists inside the /htdocs directory.')), + 'error' + ); return false; } } @@ -248,51 +272,72 @@ function client_editDomain() $documentRoot = utils_normalizePath('/htdocs' . $documentRoot); } - iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onBeforeEditDomain, [ - 'domainId' => $domainId, - 'domainName' => $domainData['domain_name'], - 'mountPoint' => '/', - 'documentRoot' => $documentRoot, - 'forwardUrl' => $forwardUrl, - 'forwardType' => $forwardType, - 'forwardHost' => $forwardHost - ]); + $wildcardAlias = isset($_POST['wildcard_alias']) + && in_array($_POST['wildcard_alias'], ['yes', 'no'], true) + ? $_POST['wildcard_alias'] : 'no'; + + iMSCP_Events_Aggregator::getInstance()->dispatch( + iMSCP_Events::onBeforeEditDomain, + [ + 'domainId' => $domainId, + 'domainName' => $domainData['domain_name'], + 'mountPoint' => '/', + 'documentRoot' => $documentRoot, + 'forwardUrl' => $forwardUrl, + 'forwardType' => $forwardType, + 'forwardHost' => $forwardHost, + 'wildcardAlias' => $wildcardAlias + ] + ); exec_query( ' UPDATE domain - SET document_root = ?, url_forward = ?, type_forward = ?, host_forward = ?, domain_status = ? + SET document_root = ?, url_forward = ?, type_forward = ?, + host_forward = ?, wildcard_alias = ?, domain_status = ? WHERE domain_id = ? ', - [$documentRoot, $forwardUrl, $forwardType, $forwardHost, 'tochange', $domainId] + [ + $documentRoot, $forwardUrl, $forwardType, $forwardHost, + $wildcardAlias, 'tochange', $domainId + ] ); - iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onAfterEditDomain, [ - 'domainId' => $domainId, - 'domainName' => $domainData['domain_name'], - 'mountPoint' => '/', - 'documentRoot' => $documentRoot, - 'forwardUrl' => $forwardUrl, - 'forwardType' => $forwardType, - 'forwardHost' => $forwardHost - ]); + iMSCP_Events_Aggregator::getInstance()->dispatch( + iMSCP_Events::onAfterEditDomain, + [ + 'domainId' => $domainId, + 'domainName' => $domainData['domain_name'], + 'mountPoint' => '/', + 'documentRoot' => $documentRoot, + 'forwardUrl' => $forwardUrl, + 'forwardType' => $forwardType, + 'forwardHost' => $forwardHost, + 'wildcardAlias' => $wildcardAlias + ] + ); send_request(); - write_log(sprintf('The %s domain properties were updated by', $_SESSION['user_logged'], $_SESSION['user_logged']), E_USER_NOTICE); + write_log( + sprintf( + 'The %s domain properties were updated by', + $_SESSION['user_logged'], + $_SESSION['user_logged'] + ), + E_USER_NOTICE + ); return true; } -/*********************************************************************************************************************** - * Main - */ - require_once 'imscp-lib.php'; check_login('user'); -iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onClientScriptStart); +iMSCP_Events_Aggregator::getInstance()->dispatch( + iMSCP_Events::onClientScriptStart +); if (!empty($_POST) && client_editDomain()) { - set_page_message(tr('Domain successfully scheduled for update.'), 'success'); + set_page_message(tohtml(tr('Domain successfully scheduled for update.')), 'success'); redirectTo('domains_manage.php'); } @@ -304,36 +349,40 @@ function client_editDomain() 'document_root_bloc' => 'page' ]); $tpl->assign([ - 'TR_PAGE_TITLE' => tr('Client / Domains / Edit Domain'), - 'TR_DOMAIN' => tr('Domain'), - 'TR_DOMAIN_NAME' => tr('Domain name'), - 'TR_DOCUMENT_ROOT' => tr('Document root'), - 'TR_DOCUMENT_ROOT_TOOLTIP' => tr("You can set an alternative document root. This is mostly needed when using a PHP framework such as Symfony. Note that the new document root will live inside the default `/htdocs' document root. Be aware that the directory for the new document root must pre-exist."), - 'TR_CHOOSE_DIR' => tr('Choose dir'), - 'TR_URL_FORWARDING' => tr('URL forwarding'), - 'TR_FORWARD_TO_URL' => tr('Forward to URL'), - 'TR_URL_FORWARDING_TOOLTIP' => tr('Allows to forward any request made to this domain to a specific URL.'), - 'TR_YES' => tr('Yes'), - 'TR_NO' => tr('No'), - 'TR_HTTP' => 'http://', - 'TR_HTTPS' => 'https://', - 'TR_FORWARD_TYPE' => tr('Forward type'), - 'TR_301' => '301', - 'TR_302' => '302', - 'TR_303' => '303', - 'TR_307' => '307', - 'TR_PROXY' => 'PROXY', - 'TR_PROXY_PRESERVE_HOST' => tr('Preserve Host'), - 'TR_UPDATE' => tr('Update'), - 'TR_CANCEL' => tr('Cancel') + 'TR_PAGE_TITLE' => tohtml(tr('Client / Domains / Edit Domain')), + 'TR_DOMAIN' => tohtml(tr('Domain')), + 'TR_DOMAIN_NAME' => tohtml(tr('Domain name')), + 'TR_DOCUMENT_ROOT' => tohtml(tr('Document root')), + 'TR_DOCUMENT_ROOT_TOOLTIP' => tohtml(tr("You can set an alternative document root. This is mostly needed when using a PHP framework such as Symfony. Note that the new document root will live inside the default `/htdocs' document root. Be aware that the directory for the new document root must pre-exist."), 'htmlAttr'), + 'TR_CHOOSE_DIR' => tohtml(tr('Choose dir')), + 'TR_URL_FORWARDING' => tohtml(tr('URL forwarding')), + 'TR_FORWARD_TO_URL' => tohtml(tr('Forward to URL')), + 'TR_URL_FORWARDING_TOOLTIP' => tohtml(tr('Allows to forward any request made to this domain to a specific URL.'), 'htmlAttr'), + 'TR_YES' => tohtml(tr('Yes')), + 'TR_NO' => tohtml(tr('No')), + 'TR_HTTP' => tohtml('http://'), + 'TR_HTTPS' => tohtml('https://'), + 'TR_FORWARD_TYPE' => tohtml(tr('Forward type')), + 'TR_301' => tohtml('301'), + 'TR_302' => tohtml('302'), + 'TR_303' => tohtml('303'), + 'TR_307' => tohtml('307'), + 'TR_PROXY' => tohtml('PROXY'), + 'TR_PROXY_PRESERVE_HOST' => tohtml(tr('Preserve Host')), + 'TR_WILDCARD_ALIAS_TOOLTIP' => tohtml(tr("If enabled, a wildcard alias entry such as '*.domain.tld' will be added in the Web server configuration. This option is most suitable for software that provide multisite feature such as the Wordpress CMS. Be aware that the control panel won't check for possible conflicts with subdomains."), 'htmlAttr'), + 'TR_WILDCARD_ALIAS' => tohtml(tr('Wildcard alias')), + 'TR_UPDATE' => tohtml(tr('Update'), 'htmlAttr'), + 'TR_CANCEL' => tohtml(tr('Cancel')) ]); -iMSCP_Events_Aggregator::getInstance()->registerListener('onGetJsTranslations', function ($e) { - /** @var $e iMSCP_Events_Event */ - $translations = $e->getParam('translations'); - $translations['core']['close'] = tr('Close'); - $translations['core']['ftp_directories'] = tr('Select your own document root'); -}); +iMSCP_Events_Aggregator::getInstance()->registerListener( + iMSCP_Events::onGetJsTranslations, + function (iMSCP_Events_Event $e) { + $translations = $e->getParam('translations'); + $translations['core']['close'] = tr('Close'); + $translations['core']['ftp_directories'] = tr('Select your own document root'); + } +); generateNavigation($tpl); client_generatePage($tpl); diff --git a/gui/public/client/subdomain_add.php b/gui/public/client/subdomain_add.php index 657b09adc1..7670be325e 100644 --- a/gui/public/client/subdomain_add.php +++ b/gui/public/client/subdomain_add.php @@ -1,7 +1,7 @@ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -18,18 +18,12 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -/*********************************************************************************************************************** - * Functions - */ +/** @noinspection PhpUnhandledExceptionInspection PhpDocMissingThrowsInspection */ /** * Get domains list * * @return array Domains list - * @throws Zend_Exception - * @throws iMSCP_Events_Exception - * @throws iMSCP_Exception - * @throws iMSCP_Exception_Database */ function getDomainsList() { @@ -52,8 +46,10 @@ function getDomainsList() $stmt = exec_query( " - SELECT CONCAT(t1.subdomain_name, '.', t2.domain_name) AS name, t1.subdomain_id AS id, - 'sub' AS type, t1.subdomain_mount AS mount_point, t1.subdomain_url_forward AS url_forward + SELECT CONCAT(t1.subdomain_name, '.', t2.domain_name) AS name, + t1.subdomain_id AS id, 'sub' AS type, + t1.subdomain_mount AS mount_point, + t1.subdomain_url_forward AS url_forward FROM subdomain AS t1 JOIN domain AS t2 USING(domain_id) WHERE t1.domain_id = :domain_id @@ -64,8 +60,9 @@ function getDomainsList() WHERE domain_id = :domain_id AND alias_status = :status_ok UNION ALL - SELECT CONCAT(t1.subdomain_alias_name, '.', t2.alias_name), t1.subdomain_alias_id, 'alssub', - t1.subdomain_alias_mount, t1.subdomain_alias_url_forward AS url_forward + SELECT CONCAT(t1.subdomain_alias_name, '.', t2.alias_name), + t1.subdomain_alias_id, 'alssub', t1.subdomain_alias_mount, + t1.subdomain_alias_url_forward AS url_forward FROM subdomain_alias AS t1 JOIN domain_aliasses AS t2 USING(alias_id) WHERE t2.domain_id = :domain_id @@ -75,7 +72,9 @@ function getDomainsList() ); if ($stmt->rowCount()) { - $domainsList = array_merge($domainsList, $stmt->fetchAll(PDO::FETCH_ASSOC)); + $domainsList = array_merge( + $domainsList, $stmt->fetchAll(PDO::FETCH_ASSOC) + ); usort($domainsList, function ($a, $b) { return strnatcmp(decode_idna($a['name']), decode_idna($b['name'])); }); @@ -89,30 +88,43 @@ function getDomainsList() * * @param $tpl iMSCP_pTemplate * @return void - * @throws iMSCP_Events_Manager_Exception - * @throws iMSCP_Exception */ function generatePage($tpl) { - $forwardType = ( - isset($_POST['forward_type']) + $forwardType = isset($_POST['forward_type']) && in_array($_POST['forward_type'], ['301', '302', '303', '307', 'proxy'], true) - ) ? $_POST['forward_type'] : '302'; - $forwardHost = ($forwardType == 'proxy' && isset($_POST['forward_host'])) ? 'On' : 'Off'; + ? $_POST['forward_type'] : '302'; + $forwardHost = $forwardType == 'proxy' && isset($_POST['forward_host']) + ? 'On' : 'Off'; + $wildcardAlias = isset($_POST['wildcard_alias']) + && in_array($_POST['wildcard_alias'], ['yes', 'no'], true) + ? $_POST['wildcard_alias'] : 'no'; $tpl->assign([ - 'SUBDOMAIN_NAME' => (isset($_POST['subdomain_name'])) ? tohtml($_POST['subdomain_name']) : '', - 'FORWARD_URL_YES' => (isset($_POST['url_forwarding']) && $_POST['url_forwarding'] == 'yes') ? ' checked' : '', - 'FORWARD_URL_NO' => (isset($_POST['url_forwarding']) && $_POST['url_forwarding'] == 'yes') ? '' : ' checked', - 'HTTP_YES' => (isset($_POST['forward_url_scheme']) && $_POST['forward_url_scheme'] == 'http://') ? ' selected' : '', - 'HTTPS_YES' => (isset($_POST['forward_url_scheme']) && $_POST['forward_url_scheme'] == 'https://') ? ' selected' : '', - 'FORWARD_URL' => (isset($_POST['forward_url'])) ? tohtml($_POST['forward_url']) : '', - 'FORWARD_TYPE_301' => ($forwardType == '301') ? ' checked' : '', - 'FORWARD_TYPE_302' => ($forwardType == '302') ? ' checked' : '', - 'FORWARD_TYPE_303' => ($forwardType == '303') ? ' checked' : '', - 'FORWARD_TYPE_307' => ($forwardType == '307') ? ' checked' : '', - 'FORWARD_TYPE_PROXY' => ($forwardType == 'proxy') ? ' checked' : '', - 'FORWARD_HOST' => ($forwardHost == 'On') ? ' checked' : '' + 'SUBDOMAIN_NAME' => isset($_POST['subdomain_name']) + ? tohtml($_POST['subdomain_name'], 'htmlAttr') : '', + 'FORWARD_URL_YES' => isset($_POST['url_forwarding']) + && $_POST['url_forwarding'] == 'yes' + ? ' checked' : '', + 'FORWARD_URL_NO' => isset($_POST['url_forwarding']) + && $_POST['url_forwarding'] == 'yes' + ? '' : ' checked', + 'HTTP_YES' => isset($_POST['forward_url_scheme']) + && $_POST['forward_url_scheme'] == 'http://' + ? ' selected' : '', + 'HTTPS_YES' => isset($_POST['forward_url_scheme']) + && $_POST['forward_url_scheme'] == 'https://' + ? ' selected' : '', + 'FORWARD_URL' => isset($_POST['forward_url']) + ? tohtml($_POST['forward_url']) : '', + 'FORWARD_TYPE_301' => $forwardType == '301' ? ' checked' : '', + 'FORWARD_TYPE_302' => $forwardType == '302' ? ' checked' : '', + 'FORWARD_TYPE_303' => $forwardType == '303' ? ' checked' : '', + 'FORWARD_TYPE_307' => $forwardType == '307' ? ' checked' : '', + 'FORWARD_TYPE_PROXY' => $forwardType == 'proxy' ? ' checked' : '', + 'FORWARD_HOST' => $forwardHost == 'On' ? ' checked' : '', + 'WILDCARD_ALIAS_YES' => $wildcardAlias == 'yes' ? ' checked' : '', + 'WILDCARD_ALIAS_NO' => $wildcardAlias == 'no' ? ' checked' : '' ]); $shareableMountpointCount = 0; @@ -122,9 +134,11 @@ function generatePage($tpl) } $tpl->assign([ - 'DOMAIN_NAME' => tohtml($domain['name']), + 'DOMAIN_NAME' => tohtml($domain['name'], 'htmlAttr'), 'DOMAIN_NAME_UNICODE' => tohtml(decode_idna($domain['name'])), - 'DOMAIN_NAME_SELECTED' => (isset($_POST['domain_name']) && $_POST['domain_name'] == $domain['name']) ? ' selected' : '', + 'DOMAIN_NAME_SELECTED' => isset($_POST['domain_name']) + && $_POST['domain_name'] == $domain['name'] + ? ' selected' : '', ]); if ($domain['type'] == 'dmn' || $domain['type'] == 'als') { @@ -134,7 +148,9 @@ function generatePage($tpl) if ($domain['url_forward'] == 'no') { $tpl->assign( 'SHARED_MOUNT_POINT_DOMAIN_SELECTED', - (isset($_POST['shared_mount_point_domain']) && $_POST['shared_mount_point_domain'] == $domain['name']) ? ' selected' : '' + isset($_POST['shared_mount_point_domain']) + && $_POST['shared_mount_point_domain'] == $domain['name'] + ? ' selected' : '' ); $tpl->parse('SHARED_MOUNT_POINT_DOMAIN', '.shared_mount_point_domain'); } @@ -145,8 +161,12 @@ function generatePage($tpl) $tpl->assign('SHARED_MOUNT_POINT_OPTION', ''); } else { $tpl->assign([ - 'SHARED_MOUNT_POINT_YES' => (isset($_POST['shared_mount_point']) && $_POST['shared_mount_point'] == 'yes') ? ' checked' : '', - 'SHARED_MOUNT_POINT_NO' => (isset($_POST['shared_mount_point']) && $_POST['shared_mount_point'] == 'yes') ? '' : ' checked' + 'SHARED_MOUNT_POINT_YES' => isset($_POST['shared_mount_point']) + && $_POST['shared_mount_point'] == 'yes' + ? ' checked' : '', + 'SHARED_MOUNT_POINT_NO' => isset($_POST['shared_mount_point']) + && $_POST['shared_mount_point'] == 'yes' + ? '' : ' checked' ]); } } @@ -155,9 +175,6 @@ function generatePage($tpl) * Add new subdomain * * @return bool TRUE on success, FALSE on failure - * @throws Zend_Exception - * @throws iMSCP_Exception - * @throws iMSCP_Exception_Database */ function addSubdomain() { @@ -179,7 +196,9 @@ function addSubdomain() $domainList = getDomainsList(); foreach ($domainList as $domain) { - if (($domain['type'] == 'dmn' || $domain['type'] == 'als') && $domain['name'] == $domainName) { + if (($domain['type'] == 'dmn' || $domain['type'] == 'als') + && $domain['name'] == $domainName + ) { $domainType = $domain['type']; $domainId = $domain['id']; } @@ -192,7 +211,7 @@ function addSubdomain() $subLabel = mb_strtolower(clean_input($_POST['subdomain_name'])); if ($subLabel == 'www' || strpos($subLabel, 'www.') === 0) { - set_page_message(tr('%s is not allowed as subdomain label.', "www"), 'error'); + set_page_message(tohtml(tr('%s is not allowed as subdomain label.'), 'www'), 'error'); return false; } @@ -200,19 +219,24 @@ function addSubdomain() // Check for subdomain syntax if (!isValidDomainName($subdomainName)) { - set_page_message(tr('Subdomain name is not valid.'), 'error'); + set_page_message(tohtml(tr('Subdomain name is not valid.')), 'error'); return false; } // Ensure that this subdomain doesn't already exists as domain or domain alias - $stmt = exec_query(' - SELECT domain_id FROM domain WHERE domain_name = :subdomain_name - UNION ALL - SELECT alias_id FROM domain_aliasses WHERE alias_name = :subdomain_name', - ['subdomain_name' => $subdomainName] + $stmt = exec_query( + ' + SELECT domain_id FROM domain WHERE domain_name = ? + UNION ALL + SELECT alias_id FROM domain_aliasses WHERE alias_name = ? + ', + [$subdomainName, $subdomainName] ); if ($stmt->rowCount()) { - set_page_message(tr('Subdomain %s is unavailable.', "$subdomainName"), 'error'); + set_page_message( + tohtml(tr('Subdomain %s is unavailable.', $subdomainName)), + 'error' + ); return false; } @@ -222,14 +246,19 @@ function addSubdomain() // Check for subdomain existence foreach ($domainList as $domain) { if ($domain['name'] == $subdomainNameAscii) { - set_page_message(tr('Subdomain %s already exist.', "$subdomainName"), 'error'); + set_page_message(tohtml( + tr('Subdomain %s already exist.', $subdomainName)), + 'error' + ); return false; } } // Set default mount point if ($domainType == 'dmn') { - if (in_array($subLabelAscii, ['backups', 'cgi-bin', 'errors', 'logs', 'phptmp'])) { + if (in_array($subLabelAscii, [ + 'backups', 'cgi-bin', 'errors', 'logs', 'phptmp' + ])) { $mountPoint = "/sub_$subLabelAscii"; } else { $mountPoint = "/$subLabelAscii"; @@ -243,12 +272,18 @@ function addSubdomain() } // Check for shared mount point option - if (isset($_POST['shared_mount_point']) && $_POST['shared_mount_point'] == 'yes') { // We are safe here + if (isset($_POST['shared_mount_point']) + && $_POST['shared_mount_point'] == 'yes' + ) { + // We are safe here + if (!isset($_POST['shared_mount_point_domain'])) { showBadRequestErrorPage(); } - $sharedMountPointDomain = clean_input($_POST['shared_mount_point_domain']); + $sharedMountPointDomain = clean_input( + $_POST['shared_mount_point_domain'] + ); // Get shared mount point foreach ($domainList as $domain) { @@ -269,13 +304,18 @@ function addSubdomain() if (isset($_POST['url_forwarding']) && $_POST['url_forwarding'] == 'yes' && isset($_POST['forward_type']) - && in_array($_POST['forward_type'], ['301', '302', '303', '307', 'proxy'], true) + && in_array( + $_POST['forward_type'], ['301', '302', '303', '307', 'proxy'], true + ) ) { - if (!isset($_POST['forward_url_scheme']) || !isset($_POST['forward_url'])) { + if (!isset($_POST['forward_url_scheme']) + || !isset($_POST['forward_url']) + ) { showBadRequestErrorPage(); } - $forwardUrl = clean_input($_POST['forward_url_scheme']) . clean_input($_POST['forward_url']); + $forwardUrl = clean_input($_POST['forward_url_scheme']) + . clean_input($_POST['forward_url']); $forwardType = clean_input($_POST['forward_type']); if ($forwardType == 'proxy' && isset($_POST['forward_host'])) { @@ -286,85 +326,114 @@ function addSubdomain() try { $uri = iMSCP_Uri_Redirect::fromString($forwardUrl); } catch (Zend_Uri_Exception $e) { - throw new iMSCP_Exception(tr('Forward URL %s is not valid.', "$forwardUrl")); + throw new iMSCP_Exception( + tr('Forward URL %s is not valid.', $forwardUrl) + ); } - $uri->setHost(encode_idna(mb_strtolower($uri->getHost()))); // Normalize URI host - $uri->setPath(rtrim(utils_normalizePath($uri->getPath()), '/') . '/'); // Normalize URI path + // Normalize URI host + $uri->setHost(encode_idna(mb_strtolower($uri->getHost()))); + // Normalize URI path + $uri->setPath(rtrim(utils_normalizePath($uri->getPath()), '/') . '/'); if ($uri->getHost() == $subdomainNameAscii - && ($uri->getPath() == '/' && in_array($uri->getPort(), ['', 80, 443])) + && ($uri->getPath() == '/' + && in_array($uri->getPort(), ['', 80, 443]) + ) ) { throw new iMSCP_Exception( - tr('Forward URL %s is not valid.', "$forwardUrl") . ' ' . - tr('Subdomain %s cannot be forwarded on itself.', "$subdomainName") + tr('Forward URL %s is not valid.', $forwardUrl) . ' ' . + tr('Subdomain %s cannot be forwarded on itself.', $subdomainName) ); } if ($forwardType == 'proxy') { $port = $uri->getPort(); if ($port && $port < 1025) { - throw new iMSCP_Exception(tr('Unallowed port in forward URL. Only ports above 1024 are allowed.', 'error')); + throw new iMSCP_Exception( + tr('Unallowed port in forward URL. Only ports above 1024 are allowed.') + ); } } $forwardUrl = $uri->getUri(); } catch (Exception $e) { - set_page_message($e->getMessage(), 'error'); + set_page_message(tohtml($e->getMessage()), 'error'); return false; } } + $wildcardAlias = isset($_POST['wildcard_alias']) + && in_array($_POST['wildcard_alias'], ['yes', 'no'], true) + ? $_POST['wildcard_alias'] : 'no'; + $db = iMSCP_Database::getInstance(); try { $db->beginTransaction(); - iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onBeforeAddSubdomain, [ - 'subdomainName' => $subdomainName, - 'subdomainType' => $domainType, - 'parentDomainId' => $domainId, - 'mountPoint' => $mountPoint, - 'documentRoot' => $documentRoot, - 'forwardUrl' => $forwardUrl, - 'forwardType' => $forwardType, - 'forwardHost' => $forwardHost, - 'customerId' => $_SESSION['user_id'] - ]); + iMSCP_Events_Aggregator::getInstance()->dispatch( + iMSCP_Events::onBeforeAddSubdomain, + [ + 'subdomainName' => $subdomainName, + 'subdomainType' => $domainType, + 'parentDomainId' => $domainId, + 'mountPoint' => $mountPoint, + 'documentRoot' => $documentRoot, + 'forwardUrl' => $forwardUrl, + 'forwardType' => $forwardType, + 'forwardHost' => $forwardHost, + 'wildcardAlias' => $wildcardAlias, + 'customerId' => $_SESSION['user_id'] + ] + ); if ($domainType == 'als') { $query = " INSERT INTO subdomain_alias ( - alias_id, subdomain_alias_name, subdomain_alias_mount, subdomain_alias_document_root, - subdomain_alias_url_forward, subdomain_alias_type_forward, subdomain_alias_host_forward, - subdomain_alias_status + alias_id, subdomain_alias_name, subdomain_alias_mount, + subdomain_alias_document_root, subdomain_alias_url_forward, + subdomain_alias_type_forward, subdomain_alias_host_forward, + subdomain_alias_wildcard_alias, subdomain_alias_status ) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ? + ?, ?, ?, ?, ?, ?, ?, ?, ? ) "; } else { $query = " INSERT INTO subdomain ( - domain_id, subdomain_name, subdomain_mount, subdomain_document_root, subdomain_url_forward, - subdomain_type_forward, subdomain_host_forward, subdomain_status + domain_id, subdomain_name, subdomain_mount, + subdomain_document_root, subdomain_url_forward, + subdomain_type_forward, subdomain_host_forward, + subdomain_wildcard_alias, subdomain_status ) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ? + ?, ?, ?, ?, ?, ?, ?, ?, ? ) "; } exec_query($query, [ - $domainId, $subLabelAscii, $mountPoint, $documentRoot, $forwardUrl, $forwardType, $forwardHost, 'toadd' + $domainId, $subLabelAscii, $mountPoint, $documentRoot, $forwardUrl, + $forwardType, $forwardHost, $wildcardAlias, 'toadd' ]); $subdomainId = $db->insertId(); // Create the phpini entry for that subdomain $phpini = iMSCP_PHPini::getInstance(); - $phpini->loadResellerPermissions($_SESSION['user_created_by']); // Load reseller PHP permissions - $phpini->loadClientPermissions($_SESSION['user_id']); // Load client PHP permissions - $phpini->loadDomainIni($_SESSION['user_id'], $mainDmnProps['domain_id'], 'dmn'); // Load main domain PHP configuration options - $phpini->saveDomainIni($_SESSION['user_id'], $subdomainId, $domainType == 'dmn' ? 'sub' : 'subals'); + // Load reseller PHP permissions + $phpini->loadResellerPermissions($_SESSION['user_created_by']); + // Load client PHP permissions + $phpini->loadClientPermissions($_SESSION['user_id']); + // Load main domain PHP configuration options + $phpini->loadDomainIni( + $_SESSION['user_id'], $mainDmnProps['domain_id'], 'dmn' + ); + $phpini->saveDomainIni( + $_SESSION['user_id'], + $subdomainId, + $domainType == 'dmn' ? 'sub' : 'subals' + ); $cfg = iMSCP_Registry::get('config'); @@ -373,55 +442,80 @@ function addSubdomain() $mainDmnProps['domain_id'], iMSCP_Authentication::getInstance()->getIdentity()->email, $subdomainNameAscii, - ($domainType == 'dmn') ? MT_SUBDOM_FORWARD : MT_ALSSUB_FORWARD, $subdomainId + $domainType == 'dmn' ? MT_SUBDOM_FORWARD : MT_ALSSUB_FORWARD, + $subdomainId ); } - iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onAfterAddSubdomain, [ - 'subdomainName' => $subdomainName, - 'subdomainType' => $domainType, - 'parentDomainId' => $domainId, - 'mountPoint' => $mountPoint, - 'documentRoot' => $documentRoot, - 'forwardUrl' => $forwardUrl, - 'forwardType' => $forwardType, - 'forwardHost' => $forwardHost, - 'customerId' => $_SESSION['user_id'], - 'subdomainId' => $subdomainId - ]); + iMSCP_Events_Aggregator::getInstance()->dispatch( + iMSCP_Events::onAfterAddSubdomain, + [ + 'subdomainName' => $subdomainName, + 'subdomainType' => $domainType, + 'parentDomainId' => $domainId, + 'mountPoint' => $mountPoint, + 'documentRoot' => $documentRoot, + 'forwardUrl' => $forwardUrl, + 'forwardType' => $forwardType, + 'forwardHost' => $forwardHost, + 'wildcardAlias' => $wildcardAlias, + 'customerId' => $_SESSION['user_id'], + 'subdomainId' => $subdomainId + ] + ); $db->commit(); send_request(); - write_log(sprintf('A new subdomain (%s) has been created by %s', $subdomainName, $_SESSION['user_logged']), E_USER_NOTICE); + write_log( + sprintf('A new subdomain (%s) has been created by %s', + $subdomainName, + $_SESSION['user_logged']), + E_USER_NOTICE + ); return true; } catch (iMSCP_Exception $e) { $db->rollBack(); - write_log(sprintf('System was unable to create the %s subdomain: %s', $subdomainName, $e->getMessage()), E_USER_ERROR); - set_page_message('Could not create subdomain. An unexpected error occurred.', 'error'); + write_log( + sprintf('System was unable to create the %s subdomain: %s', + $subdomainName, + $e->getMessage() + ), + E_USER_ERROR + ); + set_page_message( + tohtml(tr('Could not create subdomain. An unexpected error occurred.')), + 'error' + ); return false; } } -/*********************************************************************************************************************** - * Main - */ - require_once 'imscp-lib.php'; check_login('user'); -iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onClientScriptStart); +iMSCP_Events_Aggregator::getInstance()->dispatch( + iMSCP_Events::onClientScriptStart +); customerHasFeature('subdomains') or showBadRequestErrorPage(); $mainDmnProps = get_domain_default_props($_SESSION['user_id']); $subdomainsCount = get_customer_subdomains_count($mainDmnProps['domain_id']); -if ($mainDmnProps['domain_subd_limit'] != 0 && $subdomainsCount >= $mainDmnProps['domain_subd_limit']) { - set_page_message(tr('You have reached the maximum number of subdomains allowed by your subscription.'), 'warning'); +if ($mainDmnProps['domain_subd_limit'] != 0 + && $subdomainsCount >= $mainDmnProps['domain_subd_limit'] +) { + set_page_message( + tohtml(tr('You have reached the maximum number of subdomains allowed by your subscription.')), + 'warning' + ); redirectTo('domains_manage.php'); } if (!empty($_POST) && addSubdomain()) { - set_page_message(tr('Subdomain successfully scheduled for addition.'), 'success'); + set_page_message( + tohtml(tr('Subdomain successfully scheduled for addition.')), + 'success' + ); redirectTo('domains_manage.php'); } @@ -436,27 +530,29 @@ function addSubdomain() 'shared_mount_point_domain' => 'shared_mount_point_option' ]); $tpl->assign([ - 'TR_PAGE_TITLE' => tr('Client / Domains / Add Subdomain'), - 'TR_SUBDOMAIN' => tr('Subdomain'), - 'TR_SUBDOMAIN_NAME' => tr('Subdomain name'), - 'TR_SHARED_MOUNT_POINT' => tr('Shared mount point'), - 'TR_SHARED_MOUNT_POINT_TOOLTIP' => tr('Allows to share the mount point of another domain.'), - 'TR_URL_FORWARDING' => tr('URL forwarding'), - 'TR_URL_FORWARDING_TOOLTIP' => tr('Allows to forward any request made to this domain to a specific URL.'), - 'TR_FORWARD_TO_URL' => tr('Forward to URL'), - 'TR_YES' => tr('Yes'), - 'TR_NO' => tr('No'), - 'TR_HTTP' => 'http://', - 'TR_HTTPS' => 'https://', - 'TR_FORWARD_TYPE' => tr('Forward type'), - 'TR_301' => '301', - 'TR_302' => '302', - 'TR_303' => '303', - 'TR_307' => '307', - 'TR_PROXY' => 'PROXY', - 'TR_PROXY_PRESERVE_HOST' => tr('Preserve Host'), - 'TR_ADD' => tr('Add'), - 'TR_CANCEL' => tr('Cancel') + 'TR_PAGE_TITLE' => tohtml(tr('Client / Domains / Add Subdomain')), + 'TR_SUBDOMAIN' => tohtml(tr('Subdomain')), + 'TR_SUBDOMAIN_NAME' => tohtml(tr('Subdomain name')), + 'TR_SHARED_MOUNT_POINT' => tohtml(tr('Shared mount point')), + 'TR_SHARED_MOUNT_POINT_TOOLTIP' => tohtml(tr('Allows to share the mount point of another domain.'), 'htmlAttr'), + 'TR_URL_FORWARDING' => tohtml(tr('URL forwarding')), + 'TR_URL_FORWARDING_TOOLTIP' => tohtml(tr('Allows to forward any request made to this domain to a specific URL.'), 'htmlAttr'), + 'TR_FORWARD_TO_URL' => tohtml(tr('Forward to URL')), + 'TR_YES' => tohtml(tr('Yes')), + 'TR_NO' => tohtml(tr('No')), + 'TR_HTTP' => tohtml('http://'), + 'TR_HTTPS' => tohtml('https://'), + 'TR_FORWARD_TYPE' => tohtml(tr('Forward type')), + 'TR_301' => tohtml('301'), + 'TR_302' => tohtml('302'), + 'TR_303' => tohtml('303'), + 'TR_307' => tohtml('307'), + 'TR_PROXY' => tohtml('PROXY'), + 'TR_PROXY_PRESERVE_HOST' => tohtml(tr('Preserve Host')), + 'TR_WILDCARD_ALIAS_TOOLTIP' => tohtml(tr("If enabled, a wildcard alias entry such as '*.sub.domain.tld' will be added. This option is most suitable for software that provide multisite feature such as the Wordpress CMS. Be aware that the control panel doesn't check for possible conflicts with other subdomains."), 'htmlAttr'), + 'TR_WILDCARD_ALIAS' => tohtml(tr('Wildcard alias')), + 'TR_ADD' => tohtml(tr('Add'), 'htmlAttr'), + 'TR_CANCEL' => tohtml(tr('Cancel')) ]); generateNavigation($tpl); diff --git a/gui/public/client/subdomain_edit.php b/gui/public/client/subdomain_edit.php index f228f7dd28..54e2ab6fa8 100644 --- a/gui/public/client/subdomain_edit.php +++ b/gui/public/client/subdomain_edit.php @@ -1,7 +1,7 @@ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -18,11 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -use iMSCP\VirtualFileSystem as VirtualFileSystem; - -/*********************************************************************************************************************** - * Functions - */ +/** @noinspection PhpUnhandledExceptionInspection PhpDocMissingThrowsInspection */ /** * Get subdomain data @@ -31,10 +27,6 @@ * @param int $subdomainId Subdomain unique identifier * @param string $subdomainType Subdomain Type * @return array|bool Subdomain data or FALSE on error - * @throws Zend_Exception - * @throws iMSCP_Events_Exception - * @throws iMSCP_Exception - * @throws iMSCP_Exception_Database */ function _client_getSubdomainData($subdomainId, $subdomainType) { @@ -50,9 +42,12 @@ function _client_getSubdomainData($subdomainId, $subdomainType) if ($subdomainType == 'dmn') { $query = ' - SELECT subdomain_name , subdomain_mount AS subdomain_mount, subdomain_document_root AS document_root, - subdomain_url_forward AS url_forward, subdomain_type_forward AS type_forward, - subdomain_host_forward AS host_forward + SELECT subdomain_name , subdomain_mount AS subdomain_mount, + subdomain_document_root AS document_root, + subdomain_url_forward AS url_forward, + subdomain_type_forward AS type_forward, + subdomain_host_forward AS host_forward, + subdomain_wildcard_alias AS wildcard_alias FROM subdomain WHERE subdomain_id = ? AND domain_id = ? @@ -60,10 +55,14 @@ function _client_getSubdomainData($subdomainId, $subdomainType) '; } else { $query = ' - SELECT t1.subdomain_alias_name AS subdomain_name, t1.subdomain_alias_mount AS subdomain_mount, - t1.subdomain_alias_document_root AS document_root, t1.subdomain_alias_url_forward AS url_forward, - t1.subdomain_alias_type_forward AS type_forward, t1.subdomain_alias_host_forward AS host_forward, - t2.alias_name AS alias_name + SELECT t1.subdomain_alias_name AS subdomain_name, + t1.subdomain_alias_mount AS subdomain_mount, + t1.subdomain_alias_document_root AS document_root, + t1.subdomain_alias_url_forward AS url_forward, + t1.subdomain_alias_type_forward AS type_forward, + t1.subdomain_alias_host_forward AS host_forward, + t1.subdomain_alias_wildcard_alias AS wildcard_alias, + t2.alias_name AS alias_name FROM subdomain_alias AS t1 JOIN domain_aliasses AS t2 USING(alias_id) WHERE subdomain_alias_id = ? @@ -81,10 +80,14 @@ function _client_getSubdomainData($subdomainId, $subdomainType) if ($subdomainType == 'dmn') { $subdomainData['subdomain_name'] .= '.' . $domainName; - $subdomainData['subdomain_name_utf8'] = decode_idna($subdomainData['subdomain_name']); + $subdomainData['subdomain_name_utf8'] = decode_idna( + $subdomainData['subdomain_name'] + ); } else { $subdomainData['subdomain_name'] .= '.' . $subdomainData['alias_name']; - $subdomainData['subdomain_name_utf8'] = decode_idna($subdomainData['subdomain_name']); + $subdomainData['subdomain_name_utf8'] = decode_idna( + $subdomainData['subdomain_name'] + ); } return $subdomainData; @@ -95,15 +98,14 @@ function _client_getSubdomainData($subdomainId, $subdomainType) * * @param $tpl iMSCP_pTemplate * @return void - * @throws Zend_Exception - * @throws Zend_Uri_Exception - * @throws iMSCP_Exception - * @throws iMSCP_Exception_Database - * @throws iMSCP_Uri_Exception */ function client_generatePage($tpl) { - if (!isset($_GET['id']) || !isset($_GET['type']) || !($_GET['type'] == 'dmn' || $_GET['type'] == 'als')) { + if (!isset($_GET['id']) + || !isset($_GET['type']) + || !($_GET['type'] == 'dmn' + || $_GET['type'] == 'als') + ) { showBadRequestErrorPage(); } @@ -117,13 +119,17 @@ function client_generatePage($tpl) $forwardHost = 'Off'; if (empty($_POST)) { - $documentRoot = strpos($subdomainData['document_root'], '/htdocs') !== FALSE + $documentRoot = strpos( + $subdomainData['document_root'], '/htdocs' + ) !== false ? substr($subdomainData['document_root'], 7) : ''; if ($subdomainData['url_forward'] != 'no') { $urlForwarding = true; - $uri = iMSCP_Uri_Redirect::fromString($subdomainData['url_forward']); + $uri = iMSCP_Uri_Redirect::fromString( + $subdomainData['url_forward'] + ); $uri->setHost(decode_idna($uri->getHost())); $forwardUrlScheme = $uri->getScheme() . '://'; $forwardUrl = substr($uri->getUri(), strlen($forwardUrlScheme)); @@ -135,43 +141,63 @@ function client_generatePage($tpl) $forwardUrl = ''; $forwardType = '302'; } - } else { - $documentRoot = (isset($_POST['document_root'])) ? $_POST['document_root'] : ''; - $urlForwarding = (isset($_POST['url_forwarding']) && $_POST['url_forwarding'] == 'yes') ? true : false; - $forwardUrlScheme = isset($_POST['forward_url_scheme']) ? $_POST['forward_url_scheme'] : 'http://'; - $forwardUrl = isset($_POST['forward_url']) ? $_POST['forward_url'] : ''; - $forwardType = ( - isset($_POST['forward_type']) - && in_array($_POST['forward_type'], ['301', '302', '303', '307', 'proxy'], true) - ) ? $_POST['forward_type'] : '302'; - if ($forwardType == 'proxy' && isset($_POST['forward_host'])) { + $wildcardAlias = $subdomainData['wildcard_alias']; + } else { + $documentRoot = isset($_POST['document_root']) + ? $_POST['document_root'] : ''; + $urlForwarding = isset($_POST['url_forwarding']) + && $_POST['url_forwarding'] == 'yes' + ? true : false; + $forwardUrlScheme = isset($_POST['forward_url_scheme']) + ? $_POST['forward_url_scheme'] : 'http://'; + $forwardUrl = isset($_POST['forward_url']) + ? $_POST['forward_url'] : ''; + $forwardType = isset($_POST['forward_type']) + && in_array( + $_POST['forward_type'], + ['301', '302', '303', '307', 'proxy'], + true + ) + ? $_POST['forward_type'] : '302'; + + if ($forwardType == 'proxy' + && isset($_POST['forward_host']) + ) { $forwardHost = 'On'; } + + $wildcardAlias = isset($_POST['wildcard_alias']) + && in_array($_POST['wildcard_alias'], ['yes', 'no'], true) + ? $_POST['wildcard_alias'] : 'no'; } $tpl->assign([ - 'SUBDOMAIN_ID' => $subdomainId, - 'SUBDOMAIN_TYPE' => $subdomainType, - 'SUBDOMAIN_NAME' => tohtml($subdomainData['subdomain_name_utf8']), - 'DOCUMENT_ROOT' => tohtml($documentRoot), - 'FORWARD_URL_YES' => ($urlForwarding) ? ' checked' : '', - 'FORWARD_URL_NO' => ($urlForwarding) ? '' : ' checked', - 'HTTP_YES' => ($forwardUrlScheme == 'http://') ? ' selected' : '', - 'HTTPS_YES' => ($forwardUrlScheme == 'https://') ? ' selected' : '', - 'FORWARD_URL' => tohtml($forwardUrl), - 'FORWARD_TYPE_301' => ($forwardType == '301') ? ' checked' : '', - 'FORWARD_TYPE_302' => ($forwardType == '302') ? ' checked' : '', - 'FORWARD_TYPE_303' => ($forwardType == '303') ? ' checked' : '', - 'FORWARD_TYPE_307' => ($forwardType == '307') ? ' checked' : '', - 'FORWARD_TYPE_PROXY' => ($forwardType == 'proxy') ? ' checked' : '', - 'FORWARD_HOST' => ($forwardHost == 'On') ? ' checked' : '' + 'SUBDOMAIN_ID' => tohtml($subdomainId, 'htmlAttr'), + 'SUBDOMAIN_TYPE' => tohtml($subdomainType, 'htmlAttr'), + 'SUBDOMAIN_NAME' => tohtml($subdomainData['subdomain_name_utf8'], 'htmlAttr'), + 'DOCUMENT_ROOT' => tohtml($documentRoot, 'htmlAttr'), + 'FORWARD_URL_YES' => $urlForwarding ? ' checked' : '', + 'FORWARD_URL_NO' => $urlForwarding ? '' : ' checked', + 'HTTP_YES' => $forwardUrlScheme == 'http://' ? ' selected' : '', + 'HTTPS_YES' => $forwardUrlScheme == 'https://' ? ' selected' : '', + 'FORWARD_URL' => tohtml($forwardUrl, 'htmlAttr'), + 'FORWARD_TYPE_301' => $forwardType == '301' ? ' checked' : '', + 'FORWARD_TYPE_302' => $forwardType == '302' ? ' checked' : '', + 'FORWARD_TYPE_303' => $forwardType == '303' ? ' checked' : '', + 'FORWARD_TYPE_307' => $forwardType == '307' ? ' checked' : '', + 'FORWARD_TYPE_PROXY' => $forwardType == 'proxy' ? ' checked' : '', + 'FORWARD_HOST' => $forwardHost == 'On' ? ' checked' : '', + 'WILDCARD_ALIAS_YES' => $wildcardAlias == 'yes' ? ' checked' : '', + 'WILDCARD_ALIAS_NO' => $wildcardAlias == 'no' ? ' checked' : '' ]); // Cover the case where URL forwarding feature is activated and that the // default /htdocs directory doesn't exists yet if ($subdomainData['url_forward'] != 'no') { - $vfs = new VirtualFileSystem($_SESSION['user_logged'], $subdomainData['subdomain_mount']); + $vfs = new iMSCP\VirtualFileSystem( + $_SESSION['user_logged'], $subdomainData['subdomain_mount'] + ); if (!$vfs->exists('/htdocs')) { $tpl->assign('DOCUMENT_ROOT_BLOC', ''); @@ -180,9 +206,13 @@ function client_generatePage($tpl) } # Set parameters for the FTP chooser - $_SESSION['ftp_chooser_domain_id'] = get_user_domain_id($_SESSION['user_id']); + $_SESSION['ftp_chooser_domain_id'] = get_user_domain_id( + $_SESSION['user_id'] + ); $_SESSION['ftp_chooser_user'] = $_SESSION['user_logged']; - $_SESSION['ftp_chooser_root_dir'] = utils_normalizePath($subdomainData['subdomain_mount'] . '/htdocs'); + $_SESSION['ftp_chooser_root_dir'] = utils_normalizePath( + $subdomainData['subdomain_mount'] . '/htdocs' + ); $_SESSION['ftp_chooser_hidden_dirs'] = []; $_SESSION['ftp_chooser_unselectable_dirs'] = []; } @@ -191,14 +221,14 @@ function client_generatePage($tpl) * Edit subdomain * * @return bool TRUE on success, FALSE on failure - * @throws Zend_Exception - * @throws iMSCP_Events_Manager_Exception - * @throws iMSCP_Exception - * @throws iMSCP_Exception_Database */ function client_editSubdomain() { - if (!isset($_GET['id']) || !isset($_GET['type']) || !($_GET['type'] == 'dmn' || $_GET['type'] == 'als')) { + if (!isset($_GET['id']) + | !isset($_GET['type']) + || !($_GET['type'] == 'dmn' + || $_GET['type'] == 'als') + ) { showBadRequestErrorPage(); } @@ -220,13 +250,18 @@ function client_editSubdomain() if (isset($_POST['url_forwarding']) && $_POST['url_forwarding'] == 'yes' && isset($_POST['forward_type']) - && in_array($_POST['forward_type'], ['301', '302', '303', '307', 'proxy'], true) + && in_array( + $_POST['forward_type'], ['301', '302', '303', '307', 'proxy'], true + ) ) { - if (!isset($_POST['forward_url_scheme']) || !isset($_POST['forward_url'])) { + if (!isset($_POST['forward_url_scheme']) + || !isset($_POST['forward_url']) + ) { showBadRequestErrorPage(); } - $forwardUrl = clean_input($_POST['forward_url_scheme']) . clean_input($_POST['forward_url']); + $forwardUrl = clean_input($_POST['forward_url_scheme']) + . clean_input($_POST['forward_url']); $forwardType = clean_input($_POST['forward_type']); if ($forwardType == 'proxy' && isset($_POST['forward_host'])) { @@ -237,20 +272,26 @@ function client_editSubdomain() try { $uri = iMSCP_Uri_Redirect::fromString($forwardUrl); } catch (Zend_Uri_Exception $e) { - throw new iMSCP_Exception(tr('Forward URL %s is not valid.', "$forwardUrl")); + throw new iMSCP_Exception( + tr('Forward URL %s is not valid.', $forwardUrl) + ); } - $uri->setHost(encode_idna(mb_strtolower($uri->getHost()))); // Normalize URI host - $uri->setPath(rtrim(utils_normalizePath($uri->getPath()), '/') . '/'); // Normalize URI path + // Normalize URI host + $uri->setHost(encode_idna(mb_strtolower($uri->getHost()))); + // Normalize URI path + $uri->setPath(rtrim(utils_normalizePath($uri->getPath()), '/') . '/'); if ($uri->getHost() == $subdomainData['subdomain_name'] - && ($uri->getPath() == '/' && in_array($uri->getPort(), ['', 80, 443])) + && ($uri->getPath() == '/' + && in_array($uri->getPort(), ['', 80, 443]) + ) ) { throw new iMSCP_Exception( - tr('Forward URL %s is not valid.', "$forwardUrl") . ' ' . + tr('Forward URL %s is not valid.', $forwardUrl) . ' ' . tr( 'Subdomain %s cannot be forwarded on itself.', - "{$subdomainData['subdomain_name_utf8']}" + $subdomainData['subdomain_name_utf8'] ) ); } @@ -258,24 +299,36 @@ function client_editSubdomain() if ($forwardType == 'proxy') { $port = $uri->getPort(); if ($port && $port < 1025) { - throw new iMSCP_Exception(tr('Unallowed port in forward URL. Only ports above 1024 are allowed.', 'error')); + throw new iMSCP_Exception( + tr('Unallowed port in forward URL. Only ports above 1024 are allowed.') + ); } } $forwardUrl = $uri->getUri(); } catch (Exception $e) { - set_page_message($e->getMessage(), 'error'); + set_page_message(tohtml($e->getMessage()), 'error'); return false; } } // Check for alternative DocumentRoot option elseif (isset($_POST['document_root'])) { - $documentRoot = utils_normalizePath('/' . clean_input($_POST['document_root'])); + $documentRoot = utils_normalizePath( + '/' . clean_input($_POST['document_root']) + ); if ($documentRoot !== '') { - $vfs = new VirtualFileSystem($_SESSION['user_logged'], $subdomainData['subdomain_mount'] . '/htdocs'); + $vfs = new iMSCP\VirtualFileSystem( + $_SESSION['user_logged'], + $subdomainData['subdomain_mount'] . '/htdocs' + ); - if ($documentRoot !== '/' && !$vfs->exists($documentRoot, VirtualFileSystem::VFS_TYPE_DIR)) { - set_page_message(tr('The new document root must pre-exists inside the /htdocs directory.'), 'error'); + if ($documentRoot !== '/' + && !$vfs->exists($documentRoot, iMSCP\VirtualFileSystem::VFS_TYPE_DIR) + ) { + set_page_message( + tohtml(tr('The new document root must pre-exists inside the /htdocs directory.')), + 'error' + ); return false; } } @@ -283,64 +336,88 @@ function client_editSubdomain() $documentRoot = utils_normalizePath('/htdocs' . $documentRoot); } - iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onBeforeEditSubdomain, [ - 'subdomainId' => $subdomainId, - 'subdomainName' => $subdomainData['subdomain_name'], - 'subdomainType' => $subdomainType, - 'mountPoint' => $subdomainData['subdomain_mount'], - 'documentRoot' => $documentRoot, - 'forwardUrl' => $forwardUrl, - 'forwardType' => $forwardType, - 'forwardHost' => $forwardHost - ]); + $wildcardAlias = isset($_POST['wildcard_alias']) + && in_array($_POST['wildcard_alias'], [0, 1]) + ? $_POST['wildcard_alias'] : 0; + + iMSCP_Events_Aggregator::getInstance()->dispatch( + iMSCP_Events::onBeforeEditSubdomain, [ + 'subdomainId' => $subdomainId, + 'subdomainName' => $subdomainData['subdomain_name'], + 'subdomainType' => $subdomainType, + 'mountPoint' => $subdomainData['subdomain_mount'], + 'documentRoot' => $documentRoot, + 'forwardUrl' => $forwardUrl, + 'forwardType' => $forwardType, + 'forwardHost' => $forwardHost, + 'wildcardAlias' => $wildcardAlias + ] + ); if ($subdomainType == 'dmn') { $query = ' UPDATE subdomain - SET subdomain_document_root = ?, subdomain_url_forward = ?, subdomain_type_forward = ?, - subdomain_host_forward = ?, subdomain_status = ? + SET subdomain_document_root = ?, subdomain_url_forward = ?, + subdomain_type_forward = ?, subdomain_host_forward = ?, + subdomain_wildcard_alias = ?, subdomain_status = ? WHERE subdomain_id = ? '; } else { $query = ' UPDATE subdomain_alias - SET subdomain_alias_document_root = ?, subdomain_alias_url_forward = ?, subdomain_alias_type_forward = ?, - subdomain_alias_host_forward = ?, subdomain_alias_status = ? + SET subdomain_alias_document_root = ?, + subdomain_alias_url_forward = ?, + subdomain_alias_type_forward = ?, + subdomain_alias_host_forward = ?, + subdomain_wildcard_alias = ?, subdomain_alias_status = ? WHERE subdomain_alias_id = ? '; } - exec_query($query, [$documentRoot, $forwardUrl, $forwardType, $forwardHost, 'tochange', $subdomainId]); - - iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onAfterEditSubdomain, [ - 'subdomainId' => $subdomainId, - 'subdomainName' => $subdomainData['subdomain_name'], - 'subdomainType' => $subdomainType, - 'mountPoint' => $subdomainData['subdomain_mount'], - 'documentRoot' => $documentRoot, - 'forwardUrl' => $forwardUrl, - 'forwardType' => $forwardType, - 'forwardHost' => $forwardHost + exec_query($query, [ + $documentRoot, $forwardUrl, $forwardType, $forwardHost, $wildcardAlias, + 'tochange', $subdomainId ]); + iMSCP_Events_Aggregator::getInstance()->dispatch( + iMSCP_Events::onAfterEditSubdomain, + [ + 'subdomainId' => $subdomainId, + 'subdomainName' => $subdomainData['subdomain_name'], + 'subdomainType' => $subdomainType, + 'mountPoint' => $subdomainData['subdomain_mount'], + 'documentRoot' => $documentRoot, + 'forwardUrl' => $forwardUrl, + 'forwardType' => $forwardType, + 'forwardHost' => $forwardHost, + 'wildcardAlias' => $wildcardAlias + ] + ); + send_request(); - write_log(sprintf('%s updated properties of the Ms subdomain', $_SESSION['user_logged'], $subdomainData['subdomain_name_utf8']), E_USER_NOTICE); + write_log( + sprintf( + '%s updated properties of the %s subdomain', + $_SESSION['user_logged'], $subdomainData['subdomain_name_utf8'] + ), + E_USER_NOTICE + ); return true; } -/*********************************************************************************************************************** - * Main - */ - - require_once 'imscp-lib.php'; check_login('user'); -iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onClientScriptStart); +iMSCP_Events_Aggregator::getInstance()->dispatch( + iMSCP_Events::onClientScriptStart +); customerHasFeature('subdomains') or showBadRequestErrorPage(); if (!empty($_POST) && client_editSubdomain()) { - set_page_message(tr('Subdomain successfully scheduled for update'), 'success'); + set_page_message( + tohtml(tr('Subdomain successfully scheduled for update')), + 'success' + ); redirectTo('domains_manage.php'); } @@ -352,43 +429,51 @@ function client_editSubdomain() 'document_root_bloc' => 'page' ]); $tpl->assign([ - 'TR_PAGE_TITLE' => tr('Client / Domains / Edit Subdomain'), - 'TR_SUBDOMAIN' => tr('Subdomain'), - 'TR_SUBDOMAIN_NAME' => tr('Subdomain name'), - 'TR_DOCUMENT_ROOT' => tr('Document root'), - 'TR_DOCUMENT_ROOT_TOOLTIP' => tr("You can set an alternative document root. This is mostly needed when using a PHP framework such as Symfony. Note that the new document root will live inside the default `/htdocs' document root. Be aware that the directory for the new document root must pre-exist."), - 'TR_CHOOSE_DIR' => tr('Choose dir'), - 'TR_URL_FORWARDING' => tr('URL forwarding'), - 'TR_FORWARD_TO_URL' => tr('Forward to URL'), - 'TR_URL_FORWARDING_TOOLTIP' => tr('Allows to forward any request made to this domain to a specific URL.'), - 'TR_YES' => tr('Yes'), - 'TR_NO' => tr('No'), - 'TR_HTTP' => 'http://', - 'TR_HTTPS' => 'https://', - 'TR_FORWARD_TYPE' => tr('Forward type'), - 'TR_301' => '301', - 'TR_302' => '302', - 'TR_303' => '303', - 'TR_307' => '307', - 'TR_PROXY' => 'PROXY', - 'TR_PROXY_PRESERVE_HOST' => tr('Preserve Host'), - 'TR_UPDATE' => tr('Update'), - 'TR_CANCEL' => tr('Cancel') + 'TR_PAGE_TITLE' => tohtml(tr('Client / Domains / Edit Subdomain')), + 'TR_SUBDOMAIN' => tohtml(tr('Subdomain')), + 'TR_SUBDOMAIN_NAME' => tohtml(tr('Subdomain name')), + 'TR_DOCUMENT_ROOT' => tohtml(tr('Document root')), + 'TR_DOCUMENT_ROOT_TOOLTIP' => tohtml(tr("You can set an alternative document root. This is mostly needed when using a PHP framework such as Symfony. Note that the new document root will live inside the default `/htdocs' document root. Be aware that the directory for the new document root must pre-exist.")), + 'TR_CHOOSE_DIR' => tohtml(tr('Choose dir')), + 'TR_URL_FORWARDING' => tohtml(tr('URL forwarding')), + 'TR_FORWARD_TO_URL' => tohtml(tr('Forward to URL')), + 'TR_URL_FORWARDING_TOOLTIP' => tohtml(tr('Allows to forward any request made to this domain to a specific URL.')), + 'TR_YES' => tohtml(tr('Yes')), + 'TR_NO' => tohtml(tr('No')), + 'TR_HTTP' => tohtml('http://'), + 'TR_HTTPS' => tohtml('https://'), + 'TR_FORWARD_TYPE' => tohtml(tr('Forward type')), + 'TR_301' => tohtml('301'), + 'TR_302' => tohtml('302'), + 'TR_303' => tohtml('303'), + 'TR_307' => tohtml('307'), + 'TR_PROXY' => tohtml('PROXY'), + 'TR_PROXY_PRESERVE_HOST' => tohtml(tr('Preserve Host')), + 'TR_WILDCARD_ALIAS_TOOLTIP' => tohtml(tr("If enabled, a wildcard alias entry such as '*.sub.domain.tld' will be added. This option is most suitable for software that provide multisite feature such as the Wordpress CMS. Be aware that the control panel doesn't check for possible conflicts with other subdomains."), 'htmlAttr'), + 'TR_WILDCARD_ALIAS' => tohtml(tr('Wildcard alias')), + 'TR_UPDATE' => tohtml(tr('Update'), 'htmlAttr'), + 'TR_CANCEL' => tohtml(tr('Cancel')) ]); -iMSCP_Events_Aggregator::getInstance()->registerListener('onGetJsTranslations', function ($e) { - /** @var $e iMSCP_Events_Event */ - $translations = $e->getParam('translations'); - $translations['core']['close'] = tr('Close'); - $translations['core']['ftp_directories'] = tr('Select your own document root'); -}); +iMSCP_Events_Aggregator::getInstance()->registerListener( + iMSCP_Events::onGetJsTranslations, + function (iMSCP_Events_Event $e) { + $translations = $e->getParam('translations'); + $translations['core']['close'] = tr('Close'); + $translations['core']['ftp_directories'] = tr( + 'Select your own document root' + ); + } +); generateNavigation($tpl); client_generatePage($tpl); generatePageMessage($tpl); $tpl->parse('LAYOUT_CONTENT', 'page'); -iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onClientScriptEnd, ['templateEngine' => $tpl]); +iMSCP_Events_Aggregator::getInstance()->dispatch( + iMSCP_Events::onClientScriptEnd, ['templateEngine' => $tpl] +); $tpl->prnt(); unsetMessages(); diff --git a/gui/public/reseller/alias_add.php b/gui/public/reseller/alias_add.php index b407a01cd6..c62165e7f9 100644 --- a/gui/public/reseller/alias_add.php +++ b/gui/public/reseller/alias_add.php @@ -1,7 +1,7 @@ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -18,18 +18,12 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -/*********************************************************************************************************************** - * Functions - */ +/** @noinspection PhpUnhandledExceptionInspection PhpDocMissingThrowsInspection */ /** * Get customers list * * @return array Domains list - * @throws Zend_Exception - * @throws iMSCP_Events_Exception - * @throws iMSCP_Exception - * @throws iMSCP_Exception_Database */ function getCustomersList() { @@ -64,10 +58,6 @@ function getCustomersList() * * @param int $customerId Customer unique identifier * @return array Domains list - * @throws Zend_Exception - * @throws iMSCP_Events_Exception - * @throws iMSCP_Exception - * @throws iMSCP_Exception_Database */ function getDomainsList($customerId) { @@ -78,7 +68,9 @@ function getDomainsList($customerId) } $domainsList = []; - $mainDmnProps = get_domain_default_props($customerId, $_SESSION['user_id']); + $mainDmnProps = get_domain_default_props( + $customerId, $_SESSION['user_id'] + ); $domainsList = [ [ @@ -91,7 +83,8 @@ function getDomainsList($customerId) $stmt = exec_query( " - SELECT CONCAT(t1.subdomain_name, '.', t2.domain_name) AS name, t1.subdomain_mount AS mount_point + SELECT CONCAT(t1.subdomain_name, '.', t2.domain_name) AS name, + t1.subdomain_mount AS mount_point FROM subdomain AS t1 JOIN domain AS t2 USING(domain_id) WHERE t1.domain_id = :domain_id @@ -103,7 +96,8 @@ function getDomainsList($customerId) AND alias_status = :status_ok AND url_forward = 'no' UNION ALL - SELECT CONCAT(t1.subdomain_alias_name, '.', t2.alias_name) AS name, t1.subdomain_alias_mount AS mount_point + SELECT CONCAT(t1.subdomain_alias_name, '.', t2.alias_name) AS name, + t1.subdomain_alias_mount AS mount_point FROM subdomain_alias AS t1 JOIN domain_aliasses AS t2 USING(alias_id) WHERE t2.domain_id = :domain_id @@ -131,7 +125,6 @@ function getDomainsList($customerId) * * @param int $customerId Customer unique identifier * @return string Json Domains list - * @throws iMSCP_Exception */ function getJsonDomainsList($customerId) { @@ -152,9 +145,6 @@ function getJsonDomainsList($customerId) * * @param $tpl iMSCP_pTemplate * @return void - * @throws iMSCP_Events_Manager_Exception - * @throws iMSCP_Exception - * @throws Zend_Exception */ function generatePage($tpl) { @@ -171,42 +161,66 @@ function generatePage($tpl) $forwardType = ( isset($_POST['forward_type']) - && in_array($_POST['forward_type'], ['301', '302', '303', '307', 'proxy'], true) + && in_array( + $_POST['forward_type'], ['301', '302', '303', '307', 'proxy'], true + ) ) ? $_POST['forward_type'] : '302'; - $forwardHost = ($forwardType == 'proxy' && isset($_POST['forward_host'])) ? 'On' : 'Off'; + $forwardHost = $forwardType == 'proxy' && isset($_POST['forward_host']) + ? 'On' : 'Off'; + $wildcardAlias = isset($_POST['wildcard_alias']) + && in_array($_POST['wildcard_alias'], ['yes', 'no'], true) + ? $_POST['wildcard_alias'] : 'no'; $tpl->assign([ - 'DOMAIN_ALIAS_NAME' => (isset($_POST['domain_alias_name'])) ? tohtml($_POST['domain_alias_name']) : '', - 'FORWARD_URL_YES' => (isset($_POST['url_forwarding']) && $_POST['url_forwarding'] == 'yes') ? ' checked' : '', - 'FORWARD_URL_NO' => (isset($_POST['url_forwarding']) && $_POST['url_forwarding'] == 'yes') ? '' : ' checked', - 'HTTP_YES' => (isset($_POST['forward_url_scheme']) && $_POST['forward_url_scheme'] == 'http://') ? ' selected' : '', - 'HTTPS_YES' => (isset($_POST['forward_url_scheme']) && $_POST['forward_url_scheme'] == 'https://') ? ' selected' : '', - 'FORWARD_URL' => (isset($_POST['forward_url'])) ? tohtml($_POST['forward_url']) : '', - 'FORWARD_TYPE_301' => ($forwardType == '301') ? ' checked' : '', - 'FORWARD_TYPE_302' => ($forwardType == '302') ? ' checked' : '', - 'FORWARD_TYPE_303' => ($forwardType == '303') ? ' checked' : '', - 'FORWARD_TYPE_307' => ($forwardType == '307') ? ' checked' : '', - 'FORWARD_TYPE_PROXY' => ($forwardType == 'proxy') ? ' checked' : '', - 'FORWARD_HOST' => ($forwardHost == 'On') ? ' checked' : '' + 'DOMAIN_ALIAS_NAME' => isset($_POST['domain_alias_name']) + ? tohtml($_POST['domain_alias_name'], 'htmlAttr') : '', + 'FORWARD_URL_YES' => isset($_POST['url_forwarding']) + && $_POST['url_forwarding'] == 'yes' + ? ' checked' : '', + 'FORWARD_URL_NO' => isset($_POST['url_forwarding']) + && $_POST['url_forwarding'] == 'yes' + ? '' : ' checked', + 'HTTP_YES' => isset($_POST['forward_url_scheme']) + && $_POST['forward_url_scheme'] == 'http://' + ? ' selected' : '', + 'HTTPS_YES' => isset($_POST['forward_url_scheme']) + && $_POST['forward_url_scheme'] == 'https://' + ? ' selected' : '', + 'FORWARD_URL' => isset($_POST['forward_url']) + ? tohtml($_POST['forward_url']) : '', + 'FORWARD_TYPE_301' => $forwardType == '301' ? ' checked' : '', + 'FORWARD_TYPE_302' => $forwardType == '302' ? ' checked' : '', + 'FORWARD_TYPE_303' => $forwardType == '303' ? ' checked' : '', + 'FORWARD_TYPE_307' => $forwardType == '307' ? ' checked' : '', + 'FORWARD_TYPE_PROXY' => $forwardType == 'proxy' ? ' checked' : '', + 'FORWARD_HOST' => $forwardHost == 'On' ? ' checked' : '', + 'WILDCARD_ALIAS_YES' => $wildcardAlias == 'yes' ? ' checked' : '', + 'WILDCARD_ALIAS_NO' => $wildcardAlias == 'no' ? ' checked' : '' ]); $domainList = getDomainsList( - isset($_POST['customer_id']) ? clean_input($_POST['customer_id']) : $customersList[0]['admin_id'] + isset($_POST['customer_id']) + ? clean_input($_POST['customer_id']) + : $customersList[0]['admin_id'] ); if (!empty($domainList)) { $tpl->assign([ - 'SHARED_MOUNT_POINT_YES' => (isset($_POST['shared_mount_point']) && $_POST['shared_mount_point'] == 'yes') ? ' checked' : '', - 'SHARED_MOUNT_POINT_NO' => (isset($_POST['shared_mount_point']) && $_POST['shared_mount_point'] == 'yes') ? '' : ' checked', + 'SHARED_MOUNT_POINT_YES' => isset($_POST['shared_mount_point']) + && $_POST['shared_mount_point'] == 'yes' + ? ' checked' : '', + 'SHARED_MOUNT_POINT_NO' => isset($_POST['shared_mount_point']) + && $_POST['shared_mount_point'] == 'yes' + ? '' : ' checked', ]); foreach ($domainList as $domain) { $tpl->assign([ 'DOMAIN_NAME' => tohtml($domain['name']), 'DOMAIN_NAME_UNICODE' => tohtml(decode_idna($domain['name'])), - 'SHARED_MOUNT_POINT_DOMAIN_SELECTED' => ( - isset($_POST['shared_mount_point_domain']) && $_POST['shared_mount_point_domain'] == $domain['name'] - ) ? ' selected' : '' + 'SHARED_MOUNT_POINT_DOMAIN_SELECTED' => isset($_POST['shared_mount_point_domain']) + && $_POST['shared_mount_point_domain'] == $domain['name'] + ? ' selected' : '' ]); $tpl->parse('SHARED_MOUNT_POINT_DOMAIN', '.shared_mount_point_domain'); } @@ -220,9 +234,6 @@ function generatePage($tpl) * Add new domain alias * * @return bool - * @throws Exception - * @throws iMSCP_Exception - * @throws iMSCP_Exception_Database */ function addDomainAlias() { @@ -254,7 +265,10 @@ function addDomainAlias() // Check for domain alias existence if (imscp_domain_exists($domainAliasName, $_SESSION['user_id'])) { - set_page_message(tr('Domain %s is unavailable.', "$domainAliasName"), 'error'); + set_page_message( + tohtml(tr('Domain %s is unavailable.'), $domainAliasName), + 'error' + ); return false; } @@ -264,12 +278,16 @@ function addDomainAlias() $mountPoint = "/$domainAliasNameAscii"; // Check for shared mount point option - if (isset($_POST['shared_mount_point']) && $_POST['shared_mount_point'] == 'yes') { + if (isset($_POST['shared_mount_point']) + && $_POST['shared_mount_point'] == 'yes' + ) { if (!isset($_POST['shared_mount_point_domain'])) { showBadRequestErrorPage(); } - $sharedMountPointDomain = clean_input($_POST['shared_mount_point_domain']); + $sharedMountPointDomain = clean_input( + $_POST['shared_mount_point_domain'] + ); $domainList = getDomainsList($customerId); if (!empty($domainList)) { @@ -294,13 +312,18 @@ function addDomainAlias() if (isset($_POST['url_forwarding']) && $_POST['url_forwarding'] == 'yes' && isset($_POST['forward_type']) - && in_array($_POST['forward_type'], ['301', '302', '303', '307', 'proxy'], true) + && in_array( + $_POST['forward_type'], ['301', '302', '303', '307', 'proxy'], true + ) ) { - if (!isset($_POST['forward_url_scheme']) || !isset($_POST['forward_url'])) { + if (!isset($_POST['forward_url_scheme']) + || !isset($_POST['forward_url']) + ) { showBadRequestErrorPage(); } - $forwardUrl = clean_input($_POST['forward_url_scheme']) . clean_input($_POST['forward_url']); + $forwardUrl = clean_input($_POST['forward_url_scheme']) + . clean_input($_POST['forward_url']); $forwardType = clean_input($_POST['forward_type']); if ($forwardType == 'proxy' && isset($_POST['forward_host'])) { @@ -311,63 +334,83 @@ function addDomainAlias() try { $uri = iMSCP_Uri_Redirect::fromString($forwardUrl); } catch (Zend_Uri_Exception $e) { - throw new iMSCP_Exception(tr('Forward URL %s is not valid.', "$forwardUrl")); + throw new iMSCP_Exception( + tr('Forward URL %s is not valid.', $forwardUrl) + ); } - $uri->setHost(encode_idna(mb_strtolower($uri->getHost()))); // Normalize URI host - $uri->setPath(rtrim(utils_normalizePath($uri->getPath()), '/') . '/'); // Normalize URI path + // Normalize URI host + $uri->setHost(encode_idna(mb_strtolower($uri->getHost()))); + // Normalize URI path + $uri->setPath(rtrim(utils_normalizePath($uri->getPath()), '/') . '/'); if ($uri->getHost() == $domainAliasNameAscii - && ($uri->getPath() == '/' && in_array($uri->getPort(), ['', 80, 443])) + && ($uri->getPath() == '/' + && in_array($uri->getPort(), ['', 80, 443]) + ) ) { throw new iMSCP_Exception( - tr('Forward URL %s is not valid.', "$forwardUrl") . ' ' . - tr('Domain alias %s cannot be forwarded on itself.', "$domainAliasName") + tr('Forward URL %s is not valid.', $forwardUrl) . ' ' . + tr('Domain alias %s cannot be forwarded on itself.', $domainAliasName) ); } if ($forwardType == 'proxy') { $port = $uri->getPort(); if ($port && $port < 1025) { - throw new iMSCP_Exception(tr('Unallowed port in forward URL. Only ports above 1024 are allowed.', 'error')); + throw new iMSCP_Exception( + tr('Unallowed port in forward URL. Only ports above 1024 are allowed.') + ); } } $forwardUrl = $uri->getUri(); } catch (Exception $e) { - set_page_message($e->getMessage(), 'error'); + set_page_message(tohtml($e->getMessage()), 'error'); return false; } } - $mainDmnProps = get_domain_default_props($customerId, $_SESSION['user_id']); + $wildcardAlias = isset($_POST['wildcard_alias']) + && in_array($_POST['wildcard_alias'], ['yes', 'no'], true) + ? $_POST['wildcard_alias'] : 'no'; + + $mainDmnProps = get_domain_default_props( + $customerId, $_SESSION['user_id'] + ); $db = iMSCP_Database::getInstance(); try { $db->beginTransaction(); - iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onBeforeAddDomainAlias, [ - 'domainId' => $mainDmnProps['domain_id'], - 'domainAliasName' => $domainAliasNameAscii, - 'mountPoint' => $mountPoint, - 'documentRoot' => $documentRoot, - 'forwardUrl' => $forwardUrl, - 'forwardType' => $forwardType, - 'forwardHost' => $forwardHost - ]); + iMSCP_Events_Aggregator::getInstance()->dispatch( + iMSCP_Events::onBeforeAddDomainAlias, + [ + 'domainId' => $mainDmnProps['domain_id'], + 'domainAliasName' => $domainAliasNameAscii, + 'mountPoint' => $mountPoint, + 'documentRoot' => $documentRoot, + 'forwardUrl' => $forwardUrl, + 'forwardType' => $forwardType, + 'forwardHost' => $forwardHost, + 'wildcardAlias' => $wildcardAlias + ] + ); exec_query( ' INSERT INTO domain_aliasses ( - domain_id, alias_name, alias_mount, alias_document_root, alias_status, alias_ip_id, url_forward, - type_forward, host_forward + domain_id, alias_name, alias_mount, alias_document_root, + alias_status, alias_ip_id, url_forward, type_forward, + host_forward, wildcard_alias ) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, ? + ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) ', [ - $mainDmnProps['domain_id'], $domainAliasNameAscii, $mountPoint, $documentRoot, 'toadd', - $mainDmnProps['domain_ip_id'], $forwardUrl, $forwardType, $forwardHost + $mainDmnProps['domain_id'], $domainAliasNameAscii, $mountPoint, + $documentRoot, 'toadd', $mainDmnProps['domain_ip_id'], + $forwardUrl, $forwardType, $forwardHost, $wildcardAlias ] ); @@ -375,33 +418,56 @@ function addDomainAlias() // Create the phpini entry for that domain alias $phpini = iMSCP_PHPini::getInstance(); - $phpini->loadResellerPermissions($_SESSION['user_id']); // Load reseller PHP permissions - $phpini->loadClientPermissions($mainDmnProps['admin_id']); // Load client PHP permissions - $phpini->loadDomainIni($mainDmnProps['admin_id'], $mainDmnProps['domain_id'], 'dmn'); // Load main domain PHP configuration options + // Load reseller PHP permissions + $phpini->loadResellerPermissions($_SESSION['user_id']); + // Load client PHP permissions + $phpini->loadClientPermissions($mainDmnProps['admin_id']); + // Load main domain PHP configuration options + $phpini->loadDomainIni( + $mainDmnProps['admin_id'], $mainDmnProps['domain_id'], 'dmn' + ); $phpini->saveDomainIni($mainDmnProps['admin_id'], $id, 'als'); // Create default email addresses if needed if (iMSCP_Registry::get('config')['CREATE_DEFAULT_EMAIL_ADDRESSES']) { createDefaultMailAccounts( - $mainDmnProps['domain_id'], $mainDmnProps['email'], $domainAliasNameAscii, MT_ALIAS_FORWARD, $id + $mainDmnProps['domain_id'], + $mainDmnProps['email'], + $domainAliasNameAscii, + MT_ALIAS_FORWARD, + $id ); } - iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onAfterAddDomainAlias, [ - 'domainId' => $mainDmnProps['domain_id'], - 'domainAliasName' => $domainAliasNameAscii, - 'domainAliasId' => $id, - 'mountPoint' => $mountPoint, - 'documentRoot' => $documentRoot, - 'forwardUrl' => $forwardUrl, - 'forwardType' => $forwardType, - 'forwardHost' => $forwardHost - ]); + iMSCP_Events_Aggregator::getInstance()->dispatch( + iMSCP_Events::onAfterAddDomainAlias, + [ + 'domainId' => $mainDmnProps['domain_id'], + 'domainAliasName' => $domainAliasNameAscii, + 'domainAliasId' => $id, + 'mountPoint' => $mountPoint, + 'documentRoot' => $documentRoot, + 'forwardUrl' => $forwardUrl, + 'forwardType' => $forwardType, + 'forwardHost' => $forwardHost, + 'wildcardAlias' => $wildcardAlias + ] + ); $db->commit(); send_request(); - write_log(sprintf('A new domain alias (%s) has been added by %s', $domainAliasName, $_SESSION['user_logged']), E_USER_NOTICE); - set_page_message(tr('Domain alias successfully scheduled for addition.'), 'success'); + write_log( + sprintf( + 'A new domain alias (%s) has been added by %s', + $domainAliasName, + $_SESSION['user_logged'] + ), + E_USER_NOTICE + ); + set_page_message( + tohtml(tr('Domain alias successfully scheduled for addition.')), + 'success' + ); } catch (iMSCP_Exception $e) { $db->rollBack(); throw $e; @@ -410,15 +476,14 @@ function addDomainAlias() return true; } -/*********************************************************************************************************************** - * Main - */ - require_once 'imscp-lib.php'; check_login('reseller'); -iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onResellerScriptStart); -resellerHasFeature('domain_aliases') && resellerHasCustomers() or showBadRequestErrorPage(); +iMSCP_Events_Aggregator::getInstance()->dispatch( + iMSCP_Events::onResellerScriptStart +); +resellerHasFeature('domain_aliases') +&& resellerHasCustomers() or showBadRequestErrorPage(); if (is_xhr() && isset($_POST['customer_id'])) { echo getJsonDomainsList(clean_input($_POST['customer_id'])); @@ -426,8 +491,13 @@ function addDomainAlias() } $resellerProps = imscp_getResellerProperties($_SESSION['user_id']); -if ($resellerProps['max_als_cnt'] != 0 && $resellerProps['current_als_cnt'] >= $resellerProps['max_als_cnt']) { - set_page_message(tr('You have reached the maximum number of domain aliases allowed by your subscription.'), 'warning'); +if ($resellerProps['max_als_cnt'] != 0 + && $resellerProps['current_als_cnt'] >= $resellerProps['max_als_cnt'] +) { + set_page_message( + tohtml(tr('You have reached the maximum number of domain aliases allowed by your subscription.')), + 'warning' + ); redirectTo('users.php'); } @@ -446,28 +516,30 @@ function addDomainAlias() 'shared_mount_point_domain' => 'shared_mount_point_option' ]); $tpl->assign([ - 'TR_PAGE_TITLE' => tr('Reseller / Domains / Add Domain Alias'), - 'TR_CUSTOMER_ACCOUNT' => tr('Customer account'), - 'TR_DOMAIN_ALIAS' => tr('Domain alias'), - 'TR_DOMAIN_ALIAS_NAME' => tr('Domain alias name'), - 'TR_SHARED_MOUNT_POINT' => tr('Shared mount point'), - 'TR_SHARED_MOUNT_POINT_TOOLTIP' => tr('Allows to share the mount point of another domain.'), - 'TR_URL_FORWARDING' => tr('URL forwarding'), - 'TR_URL_FORWARDING_TOOLTIP' => tr('Allows to forward any request made to this domain to a specific URL.'), - 'TR_FORWARD_TO_URL' => tr('Forward to URL'), - 'TR_YES' => tr('Yes'), - 'TR_NO' => tr('No'), - 'TR_HTTP' => 'http://', - 'TR_HTTPS' => 'https://', - 'TR_FORWARD_TYPE' => tr('Forward type'), - 'TR_301' => '301', - 'TR_302' => '302', - 'TR_303' => '303', - 'TR_307' => '307', - 'TR_PROXY' => 'PROXY', - 'TR_PROXY_PRESERVE_HOST' => tr('Preserve Host'), - 'TR_ADD' => tr('Add'), - 'TR_CANCEL' => tr('Cancel') + 'TR_PAGE_TITLE' => tohtml(tr('Reseller / Domains / Add Domain Alias')), + 'TR_CUSTOMER_ACCOUNT' => tohtml(tr('Customer account')), + 'TR_DOMAIN_ALIAS' => tohtml(tr('Domain alias')), + 'TR_DOMAIN_ALIAS_NAME' => tohtml(tr('Domain alias name')), + 'TR_SHARED_MOUNT_POINT' => tohtml(tr('Shared mount point')), + 'TR_SHARED_MOUNT_POINT_TOOLTIP' => tohtml(tr('Allows to share the mount point of another domain.'), 'htmlAttr'), + 'TR_URL_FORWARDING' => tohtml(tr('URL forwarding')), + 'TR_URL_FORWARDING_TOOLTIP' => tohtml(tr('Allows to forward any request made to this domain to a specific URL.'), 'htmlAttr'), + 'TR_FORWARD_TO_URL' => tohtml(tr('Forward to URL')), + 'TR_YES' => tohtml(tr('Yes')), + 'TR_NO' => tohtml(tr('No')), + 'TR_HTTP' => tohtml('http://'), + 'TR_HTTPS' => tohtml('https://'), + 'TR_FORWARD_TYPE' => tohtml(tr('Forward type')), + 'TR_301' => tohtml('301'), + 'TR_302' => tohtml('302'), + 'TR_303' => tohtml('303'), + 'TR_307' => tohtml('307'), + 'TR_PROXY' => tohtml('PROXY'), + 'TR_PROXY_PRESERVE_HOST' => tohtml(tr('Preserve Host')), + 'TR_WILDCARD_ALIAS_TOOLTIP' => tohtml(tr("If enabled, a wildcard alias entry such as '*.domain.tld' will be added in the Web server configuration. This option is most suitable for software that provide multisite feature such as the Wordpress CMS. Be aware that the control panel won't check for possible conflicts with subdomains."), 'htmlAttr'), + 'TR_WILDCARD_ALIAS' => tohtml(tr('Wildcard alias')), + 'TR_ADD' => tohtml(tr('Add'), 'htmlAttr'), + 'TR_CANCEL' => tohtml(tr('Cancel')) ]); generateNavigation($tpl); @@ -475,7 +547,9 @@ function addDomainAlias() generatePageMessage($tpl); $tpl->parse('LAYOUT_CONTENT', 'page'); -iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onResellerScriptEnd, ['templateEngine' => $tpl]); +iMSCP_Events_Aggregator::getInstance()->dispatch( + iMSCP_Events::onResellerScriptEnd, ['templateEngine' => $tpl] +); $tpl->prnt(); unsetMessages(); diff --git a/gui/public/reseller/alias_edit.php b/gui/public/reseller/alias_edit.php index e98e0ef067..53d657c734 100644 --- a/gui/public/reseller/alias_edit.php +++ b/gui/public/reseller/alias_edit.php @@ -1,7 +1,7 @@ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -18,11 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -use iMSCP\VirtualFileSystem as VirtualFileSystem; - -/*********************************************************************************************************************** - * Functions - */ +/** @noinspection PhpUnhandledExceptionInspection PhpDocMissingThrowsInspection */ /** * Get domain alias data @@ -30,8 +26,6 @@ * @access private * @param int $domainAliasId Subdomain unique identifier * @return array|bool Domain alias data. If any error occurs FALSE is returned - * @throws iMSCP_Events_Exception - * @throws iMSCP_Exception_Database */ function _reseller_getAliasData($domainAliasId) { @@ -40,8 +34,9 @@ function _reseller_getAliasData($domainAliasId) if (NULL === $domainAliasData) { $stmt = exec_query( " - SELECT t1.alias_name, t1.alias_mount, t1.alias_document_root, t1.url_forward, t1.type_forward, - t1.host_forward, t2.domain_id + SELECT t1.alias_name, t1.alias_mount, t1.alias_document_root, + t1.url_forward, t1.type_forward, t1.host_forward, + t1.wildcard_alias, t2.domain_id FROM domain_aliasses AS t1 JOIN domain AS t2 USING(domain_id) JOIN admin AS t3 ON(admin_id = domain_admin_id) @@ -57,7 +52,9 @@ function _reseller_getAliasData($domainAliasId) } $domainAliasData = $stmt->fetchRow(PDO::FETCH_ASSOC); - $domainAliasData['alias_name_utf8'] = decode_idna($domainAliasData['alias_name']); + $domainAliasData['alias_name_utf8'] = decode_idna( + $domainAliasData['alias_name'] + ); } return $domainAliasData; @@ -68,11 +65,6 @@ function _reseller_getAliasData($domainAliasId) * * @param $tpl iMSCP_pTemplate * @return void - * @throws Zend_Exception - * @throws Zend_Uri_Exception - * @throws iMSCP_Exception - * @throws iMSCP_Exception_Database - * @throws iMSCP_Uri_Exception */ function reseller_generatePage($tpl) { @@ -90,13 +82,17 @@ function reseller_generatePage($tpl) $forwardHost = 'Off'; if (empty($_POST)) { - $documentRoot = strpos($domainAliasData['alias_document_root'], '/htdocs') !== FALSE + $documentRoot = strpos( + $domainAliasData['alias_document_root'], '/htdocs' + ) !== false ? substr($domainAliasData['alias_document_root'], 7) : ''; if ($domainAliasData['url_forward'] != 'no') { $urlForwarding = true; - $uri = iMSCP_Uri_Redirect::fromString($domainAliasData['url_forward']); + $uri = iMSCP_Uri_Redirect::fromString( + $domainAliasData['url_forward'] + ); $uri->setHost(decode_idna($uri->getHost())); $forwardUrlScheme = $uri->getScheme() . '://'; $forwardUrl = substr($uri->getUri(), strlen($forwardUrlScheme)); @@ -108,42 +104,58 @@ function reseller_generatePage($tpl) $forwardUrl = ''; $forwardType = '302'; } + + $wildcardAlias = $domainAliasData['wildcard_alias']; } else { - $documentRoot = (isset($_POST['document_root'])) ? $_POST['document_root'] : ''; - $urlForwarding = (isset($_POST['url_forwarding']) && $_POST['url_forwarding'] == 'yes') ? true : false; - $forwardUrlScheme = (isset($_POST['forward_url_scheme'])) ? $_POST['forward_url_scheme'] : 'http://'; - $forwardUrl = (isset($_POST['forward_url'])) ? $_POST['forward_url'] : ''; - $forwardType = ( - isset($_POST['forward_type']) - && in_array($_POST['forward_type'], ['301', '302', '303', '307', 'proxy'], true) - ) ? $_POST['forward_type'] : '302'; + $documentRoot = isset($_POST['document_root']) + ? $_POST['document_root'] : ''; + $urlForwarding = isset($_POST['url_forwarding']) && $_POST['url_forwarding'] == 'yes' + ? true : false; + $forwardUrlScheme = isset($_POST['forward_url_scheme']) + ? $_POST['forward_url_scheme'] : 'http://'; + $forwardUrl = isset($_POST['forward_url']) + ? $_POST['forward_url'] : ''; + $forwardType = isset($_POST['forward_type']) + && in_array($_POST['forward_type'], + ['301', '302', '303', '307', 'proxy'], + true + ) + ? $_POST['forward_type'] : '302'; if ($forwardType == 'proxy' && isset($_POST['forward_host'])) { $forwardHost = 'On'; } + + $wildcardAlias = isset($_POST['wildcard_alias']) + && in_array($_POST['wildcard_alias'], ['yes', 'no'], true) + ? $_POST['wildcard_alias'] : 'no'; } $tpl->assign([ - 'DOMAIN_ALIAS_ID' => $domainAliasId, - 'DOMAIN_ALIAS_NAME' => tohtml($domainAliasData['alias_name_utf8']), - 'DOCUMENT_ROOT' => tohtml($documentRoot), - 'FORWARD_URL_YES' => ($urlForwarding) ? ' checked' : '', - 'FORWARD_URL_NO' => ($urlForwarding) ? '' : ' checked', - 'HTTP_YES' => ($forwardUrlScheme == 'http://') ? ' selected' : '', - 'HTTPS_YES' => ($forwardUrlScheme == 'https://') ? ' selected' : '', - 'FORWARD_URL' => tohtml($forwardUrl), - 'FORWARD_TYPE_301' => ($forwardType == '301') ? ' checked' : '', - 'FORWARD_TYPE_302' => ($forwardType == '302') ? ' checked' : '', - 'FORWARD_TYPE_303' => ($forwardType == '303') ? ' checked' : '', - 'FORWARD_TYPE_307' => ($forwardType == '307') ? ' checked' : '', - 'FORWARD_TYPE_PROXY' => ($forwardType == '307') ? ' checked' : '', - 'FORWARD_HOST' => ($forwardHost == 'On') ? ' checked' : '' + 'DOMAIN_ALIAS_ID' => tohtml($domainAliasId, 'htmlAttr'), + 'DOMAIN_ALIAS_NAME' => tohtml($domainAliasData['alias_name_utf8'], 'htmlAttr'), + 'DOCUMENT_ROOT' => tohtml($documentRoot, 'htmlAttr'), + 'FORWARD_URL_YES' => $urlForwarding ? ' checked' : '', + 'FORWARD_URL_NO' => $urlForwarding ? '' : ' checked', + 'HTTP_YES' => $forwardUrlScheme == 'http://' ? ' selected' : '', + 'HTTPS_YES' => $forwardUrlScheme == 'https://' ? ' selected' : '', + 'FORWARD_URL' => tohtml($forwardUrl, 'htmlAttr'), + 'FORWARD_TYPE_301' => $forwardType == '301' ? ' checked' : '', + 'FORWARD_TYPE_302' => $forwardType == '302' ? ' checked' : '', + 'FORWARD_TYPE_303' => $forwardType == '303' ? ' checked' : '', + 'FORWARD_TYPE_307' => $forwardType == '307' ? ' checked' : '', + 'FORWARD_TYPE_PROXY' => $forwardType == '307' ? ' checked' : '', + 'FORWARD_HOST' => $forwardHost == 'On' ? ' checked' : '', + 'WILDCARD_ALIAS_YES' => $wildcardAlias == 'yes' ? ' checked' : '', + 'WILDCARD_ALIAS_NO' => $wildcardAlias == 'no' ? ' checked' : '' ]); // Cover the case where URL forwarding feature is activated and that the // default /htdocs directory doesn't exists yet if ($domainAliasData['url_forward'] != 'no') { - $vfs = new VirtualFileSystem($_SESSION['user_logged'], $domainAliasData['alias_mount']); + $vfs = new iMSCP\VirtualFileSystem( + $_SESSION['user_logged'], $domainAliasData['alias_mount'] + ); if (!$vfs->exists('/htdocs')) { $tpl->assign('DOCUMENT_ROOT_BLOC', ''); @@ -154,7 +166,9 @@ function reseller_generatePage($tpl) # Set parameters for the FTP chooser $_SESSION['ftp_chooser_domain_id'] = $domainAliasData['domain_id']; $_SESSION['ftp_chooser_user'] = $_SESSION['user_logged']; - $_SESSION['ftp_chooser_root_dir'] = utils_normalizePath($domainAliasData['alias_mount'] . '/htdocs'); + $_SESSION['ftp_chooser_root_dir'] = utils_normalizePath( + $domainAliasData['alias_mount'] . '/htdocs' + ); $_SESSION['ftp_chooser_hidden_dirs'] = []; $_SESSION['ftp_chooser_unselectable_dirs'] = []; } @@ -163,10 +177,6 @@ function reseller_generatePage($tpl) * Edit domain alias * * @return bool TRUE on success, FALSE on failure - * @throws Zend_Exception - * @throws iMSCP_Events_Manager_Exception - * @throws iMSCP_Exception - * @throws iMSCP_Exception_Database */ function reseller_editDomainAlias() { @@ -190,13 +200,18 @@ function reseller_editDomainAlias() if (isset($_POST['url_forwarding']) && $_POST['url_forwarding'] == 'yes' && isset($_POST['forward_type']) - && in_array($_POST['forward_type'], ['301', '302', '303', '307', 'proxy'], true) + && in_array( + $_POST['forward_type'], ['301', '302', '303', '307', 'proxy'], true + ) ) { - if (!isset($_POST['forward_url_scheme']) || !isset($_POST['forward_url'])) { + if (!isset($_POST['forward_url_scheme']) + || !isset($_POST['forward_url']) + ) { showBadRequestErrorPage(); } - $forwardUrl = clean_input($_POST['forward_url_scheme']) . clean_input($_POST['forward_url']); + $forwardUrl = clean_input($_POST['forward_url_scheme']) + . clean_input($_POST['forward_url']); $forwardType = clean_input($_POST['forward_type']); if ($forwardType == 'proxy' && isset($_POST['forward_host'])) { @@ -207,20 +222,24 @@ function reseller_editDomainAlias() try { $uri = iMSCP_Uri_Redirect::fromString($forwardUrl); } catch (Zend_Uri_Exception $e) { - throw new iMSCP_Exception(tr('Forward URL %s is not valid.', "$forwardUrl")); + throw new iMSCP_Exception( + tr('Forward URL %s is not valid.', $forwardUrl) + ); } - $uri->setHost(encode_idna(mb_strtolower($uri->getHost()))); // Normalize URI host - $uri->setPath(rtrim(utils_normalizePath($uri->getPath()), '/') . '/'); // Normalize URI path + // Normalize URI host + $uri->setHost(encode_idna(mb_strtolower($uri->getHost()))); + // Normalize URI path + $uri->setPath(rtrim(utils_normalizePath($uri->getPath()), '/') . '/'); if ($uri->getHost() == $domainAliasData['alias_name'] && ($uri->getPath() == '/' && in_array($uri->getPort(), ['', 80, 443])) ) { throw new iMSCP_Exception( - tr('Forward URL %s is not valid.', "$forwardUrl") . ' ' . + tr('Forward URL %s is not valid.', $forwardUrl) . ' ' . tr( 'Domain alias %s cannot be forwarded on itself.', - "{$domainAliasData['alias_name_utf8']}" + $domainAliasData['alias_name_utf8'] ) ); } @@ -228,24 +247,37 @@ function reseller_editDomainAlias() if ($forwardType == 'proxy') { $port = $uri->getPort(); if ($port && $port < 1025) { - throw new iMSCP_Exception(tr('Unallowed port in forward URL. Only ports above 1024 are allowed.', 'error')); + throw new iMSCP_Exception( + tr('Unallowed port in forward URL. Only ports above 1024 are allowed.') + ); } } $forwardUrl = $uri->getUri(); } catch (Exception $e) { - set_page_message($e->getMessage(), 'error'); + set_page_message(tohtml($e->getMessage()), 'error'); return false; } } // Check for alternative DocumentRoot option elseif (isset($_POST['document_root'])) { - $documentRoot = utils_normalizePath('/' . clean_input($_POST['document_root'])); + $documentRoot = utils_normalizePath('/' + . clean_input($_POST['document_root'])); if ($documentRoot !== '') { - $vfs = new VirtualFileSystem($_SESSION['user_logged'], $domainAliasData['alias_mount'] . '/htdocs'); - - if ($documentRoot !== '/' && !$vfs->exists($documentRoot, VirtualFileSystem::VFS_TYPE_DIR)) { - set_page_message(tr('The new document root must pre-exists inside the /htdocs directory.'), 'error'); + $vfs = new iMSCP\VirtualFileSystem( + $_SESSION['user_logged'], + $domainAliasData['alias_mount'] . '/htdocs' + ); + + if ($documentRoot !== '/' + && !$vfs->exists( + $documentRoot, iMSCP\VirtualFileSystem::VFS_TYPE_DIR + ) + ) { + set_page_message( + tohtml(tr('The new document root must pre-exists inside the /htdocs directory.')), + 'error' + ); return false; } } @@ -253,50 +285,75 @@ function reseller_editDomainAlias() $documentRoot = utils_normalizePath('/htdocs' . $documentRoot); } - iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onBeforeEditDomainAlias, [ - 'domainAliasId' => $domainAliasId, - 'mountPoint' => $domainAliasData['alias_mount'], - 'documentRoot' => $documentRoot, - 'forwardUrl' => $forwardUrl, - 'forwardType' => $forwardType, - 'forwardHost' => $forwardHost - ]); + $wildcardAlias = isset($_POST['wildcard_alias']) + && in_array($_POST['wildcard_alias'], ['yes', 'no'], true) + ? $_POST['wildcard_alias'] : 'no'; + + iMSCP_Events_Aggregator::getInstance()->dispatch( + iMSCP_Events::onBeforeEditDomainAlias, + [ + 'domainAliasId' => $domainAliasId, + 'mountPoint' => $domainAliasData['alias_mount'], + 'documentRoot' => $documentRoot, + 'forwardUrl' => $forwardUrl, + 'forwardType' => $forwardType, + 'forwardHost' => $forwardHost, + 'wildcardAlias' => $wildcardAlias + ] + ); exec_query( ' UPDATE domain_aliasses - SET alias_document_root = ?, url_forward = ?, type_forward = ?, host_forward = ?, alias_status = ? + SET alias_document_root = ?, url_forward = ?, type_forward = ?, + host_forward = ?, wildcard_alias = ?, alias_status = ? WHERE alias_id = ? ', - [$documentRoot, $forwardUrl, $forwardType, $forwardHost, 'tochange', $domainAliasId] + [ + $documentRoot, $forwardUrl, $forwardType, $forwardHost, + $wildcardAlias, 'tochange', $domainAliasId + ] ); - iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onAfterEditDomainAlias, [ - 'domainAliasId' => $domainAliasId, - 'mountPoint' => $domainAliasData['alias_mount'], - 'documentRoot' => $documentRoot, - 'forwardUrl' => $forwardUrl, - 'forwardType' => $forwardType, - 'forwardHost' => $forwardHost - ]); + iMSCP_Events_Aggregator::getInstance()->dispatch( + iMSCP_Events::onAfterEditDomainAlias, + [ + 'domainAliasId' => $domainAliasId, + 'mountPoint' => $domainAliasData['alias_mount'], + 'documentRoot' => $documentRoot, + 'forwardUrl' => $forwardUrl, + 'forwardType' => $forwardType, + 'forwardHost' => $forwardHost, + 'wildcardAlias' => $wildcardAlias + ] + ); send_request(); - write_log(sprintf('%s updated properties of the %s domain alias', $_SESSION['user_logged'], $domainAliasData['alias_name_utf8']), E_USER_NOTICE); + write_log( + sprintf( + '%s updated properties of the %s domain alias', + $_SESSION['user_logged'], + $domainAliasData['alias_name_utf8'] + ), + E_USER_NOTICE + ); return true; } -/*********************************************************************************************************************** - * Main - */ - require_once 'imscp-lib.php'; check_login('reseller'); -iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onResellerScriptStart); -resellerHasFeature('domain_aliases') && resellerHasCustomers() or showBadRequestErrorPage(); +iMSCP_Events_Aggregator::getInstance()->dispatch( + iMSCP_Events::onResellerScriptStart +); +resellerHasFeature('domain_aliases') +&& resellerHasCustomers() or showBadRequestErrorPage(); if (!empty($_POST) && reseller_editDomainAlias()) { - set_page_message(tr('Domain alias successfully scheduled for update.'), 'success'); + set_page_message( + tohtml(tr('Domain alias successfully scheduled for update.')), + 'success' + ); redirectTo('alias.php'); } @@ -309,43 +366,49 @@ function reseller_editDomainAlias() ]); $tpl->assign([ - 'TR_PAGE_TITLE' => tr('Reseller / Domains / Edit Domain Alias'), - 'TR_DOMAIN_ALIAS' => tr('Domain alias'), - 'TR_DOMAIN_ALIAS_NAME' => tr('Domain alias name'), - 'TR_DOCUMENT_ROOT' => tr('Document root'), - 'TR_DOCUMENT_ROOT_TOOLTIP' => tr("You can set an alternative document root. This is mostly needed when using a PHP framework such as Symfony. Note that the new document root will live inside the default `/htdocs' document root. Be aware that the directory for the new document root must pre-exist."), - 'TR_CHOOSE_DIR' => tr('Choose dir'), - 'TR_URL_FORWARDING' => tr('URL forwarding'), - 'TR_FORWARD_TO_URL' => tr('Forward to URL'), - 'TR_URL_FORWARDING_TOOLTIP' => tr('Allows to forward any request made to this domain to a specific URL.'), - 'TR_YES' => tr('Yes'), - 'TR_NO' => tr('No'), - 'TR_HTTP' => 'http://', - 'TR_HTTPS' => 'https://', - 'TR_FORWARD_TYPE' => tr('Forward type'), - 'TR_301' => '301', - 'TR_302' => '302', - 'TR_303' => '303', - 'TR_307' => '307', - 'TR_PROXY' => 'PROXY', - 'TR_PROXY_PRESERVE_HOST' => tr('Preserve Host'), - 'TR_UPDATE' => tr('Update'), - 'TR_CANCEL' => tr('Cancel') + 'TR_PAGE_TITLE' => tohtml(tr('Reseller / Domains / Edit Domain Alias')), + 'TR_DOMAIN_ALIAS' => tohtml(tr('Domain alias')), + 'TR_DOMAIN_ALIAS_NAME' => tohtml(tr('Domain alias name')), + 'TR_DOCUMENT_ROOT' => tohtml(tr('Document root')), + 'TR_DOCUMENT_ROOT_TOOLTIP' => tohtml(tr("You can set an alternative document root. This is mostly needed when using a PHP framework such as Symfony. Note that the new document root will live inside the default `/htdocs' document root. Be aware that the directory for the new document root must pre-exist."), 'htmlAttr'), + 'TR_CHOOSE_DIR' => tohtml(tr('Choose dir')), + 'TR_URL_FORWARDING' => tohtml(tr('URL forwarding')), + 'TR_FORWARD_TO_URL' => tohtml(tr('Forward to URL')), + 'TR_URL_FORWARDING_TOOLTIP' => tohtml(tr('Allows to forward any request made to this domain to a specific URL.'), 'htmlAttr'), + 'TR_YES' => tohtml(tr('Yes')), + 'TR_NO' => tohtml(tr('No')), + 'TR_HTTP' => tohtml('http://'), + 'TR_HTTPS' => tohtml('https://'), + 'TR_FORWARD_TYPE' => tohtml(tr('Forward type')), + 'TR_301' => tohtml('301'), + 'TR_302' => tohtml('302'), + 'TR_303' => tohtml('303'), + 'TR_307' => tohtml('307'), + 'TR_PROXY' => tohtml('PROXY'), + 'TR_PROXY_PRESERVE_HOST' => tohtml(tr('Preserve Host')), + 'TR_WILDCARD_ALIAS_TOOLTIP' => tohtml(tr("If enabled, a wildcard alias entry such as '*.domain.tld' will be added in the Web server configuration. This option is most suitable for software that provide multisite feature such as the Wordpress CMS. Be aware that the control panel won't check for possible conflicts with subdomains."), 'htmlAttr'), + 'TR_WILDCARD_ALIAS' => tohtml(tr('Wildcard alias')), + 'TR_UPDATE' => tohtml(tr('Update'), 'htmlAttr'), + 'TR_CANCEL' => tohtml(tr('Cancel')) ]); -iMSCP_Events_Aggregator::getInstance()->registerListener('onGetJsTranslations', function ($e) { - /** @var $e iMSCP_Events_Event */ - $translations = $e->getParam('translations'); - $translations['core']['close'] = tr('Close'); - $translations['core']['ftp_directories'] = tr('Select your own document root'); -}); +iMSCP_Events_Aggregator::getInstance()->registerListener( + iMSCP_Events::onGetJsTranslations, + function (iMSCP_Events_Event $e) { + $translations = $e->getParam('translations'); + $translations['core']['close'] = tr('Close'); + $translations['core']['ftp_directories'] = tr('Select your own document root'); + } +); generateNavigation($tpl); reseller_generatePage($tpl); generatePageMessage($tpl); $tpl->parse('LAYOUT_CONTENT', 'page'); -iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onResellerScriptEnd, ['templateEngine' => $tpl]); +iMSCP_Events_Aggregator::getInstance()->dispatch( + iMSCP_Events::onResellerScriptEnd, ['templateEngine' => $tpl] +); $tpl->prnt(); unsetMessages(); diff --git a/gui/public/reseller/user_add1.php b/gui/public/reseller/user_add1.php index 212455dd56..167850024d 100644 --- a/gui/public/reseller/user_add1.php +++ b/gui/public/reseller/user_add1.php @@ -1,41 +1,29 @@ * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the - * License for the specific language governing rights and limitations - * under the License. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * The Original Code is "VHCS - Virtual Hosting Control System". - * - * The Initial Developer of the Original Code is moleSoftware GmbH. - * Portions created by Initial Developer are Copyright (C) 2001-2006 - * by moleSoftware GmbH. All Rights Reserved. - * - * Portions created by the ispCP Team are Copyright (C) 2006-2010 by - * isp Control Panel. All Rights Reserved. - * - * Portions created by the i-MSCP Team are Copyright (C) 2010-2017 by - * i-MSCP - internet Multi Server Control Panel. All Rights Reserved. + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -/*********************************************************************************************************************** - * Functions - */ +/** @noinspection PhpUnhandledExceptionInspection PhpDocMissingThrowsInspection */ /** * Check input data * * @return void - * @throws Zend_Exception - * @throws iMSCP_Exception - * @throws iMSCP_Exception_Database */ function reseller_checkData() { @@ -60,7 +48,10 @@ function reseller_checkData() $asciiDmnName = encode_idna($dmnName); if (imscp_domain_exists($asciiDmnName, $_SESSION['user_id'])) { - set_page_message(tr('Domain %s is unavailable.', "$dmnName"), 'error'); + set_page_message( + tohtml(tr('Domain %s is unavailable.'), $dmnName), + 'error' + ); return; } @@ -72,13 +63,18 @@ function reseller_checkData() if (isset($_POST['url_forwarding']) && $_POST['url_forwarding'] == 'yes' && isset($_POST['forward_type']) - && in_array($_POST['forward_type'], ['301', '302', '303', '307', 'proxy'], true) + && in_array( + $_POST['forward_type'], ['301', '302', '303', '307', 'proxy'], true + ) ) { - if (!isset($_POST['forward_url_scheme']) || !isset($_POST['forward_url'])) { + if (!isset($_POST['forward_url_scheme']) + || !isset($_POST['forward_url']) + ) { showBadRequestErrorPage(); } - $forwardUrl = clean_input($_POST['forward_url_scheme']) . clean_input($_POST['forward_url']); + $forwardUrl = clean_input($_POST['forward_url_scheme']) + . clean_input($_POST['forward_url']); $forwardType = clean_input($_POST['forward_type']); if ($forwardType == 'proxy' && isset($_POST['forward_host'])) { @@ -89,48 +85,65 @@ function reseller_checkData() try { $uri = iMSCP_Uri_Redirect::fromString($forwardUrl); } catch (Zend_Uri_Exception $e) { - throw new iMSCP_Exception(tr('Forward URL %s is not valid.', "$forwardUrl")); + throw new iMSCP_Exception( + tr('Forward URL %s is not valid.', $forwardUrl) + ); } - $uri->setHost(encode_idna(mb_strtolower($uri->getHost()))); // Normalize URI host - $uri->setPath(rtrim(utils_normalizePath($uri->getPath()), '/') . '/'); // Normalize URI path + // Normalize URI host + $uri->setHost(encode_idna(mb_strtolower($uri->getHost()))); + // Normalize URI path + $uri->setPath(rtrim(utils_normalizePath($uri->getPath()), '/') . '/'); if ($uri->getHost() == $asciiDmnName && ($uri->getPath() == '/' && in_array($uri->getPort(), ['', 80, 443])) ) { throw new iMSCP_Exception( - tr('Forward URL %s is not valid.', "$forwardUrl") . ' ' . - tr('Domain %s cannot be forwarded on itself.', "$dmnName") + tr('Forward URL %s is not valid.', $forwardUrl) . ' ' . + tr('Domain %s cannot be forwarded on itself.', $dmnName) ); } if ($forwardType == 'proxy') { $port = $uri->getPort(); if ($port && $port < 1025) { - throw new iMSCP_Exception(tr('Unallowed port in forward URL. Only ports above 1024 are allowed.', 'error')); + throw new iMSCP_Exception( + tr('Unallowed port in forward URL. Only ports above 1024 are allowed.') + ); } } $forwardUrl = $uri->getUri(); } catch (Exception $e) { - set_page_message($e->getMessage(), 'error'); + set_page_message(tohtml($e->getMessage()), 'error'); return; } } - if ((!isset($_POST['datepicker']) || $_POST['datepicker'] === '') && !isset($_POST['never_expire'])) { - set_page_message(tr('Domain expiration date must be filled.'), 'error'); + $wildcardAlias = isset($_POST['wildcard_alias']) + && in_array($_POST['wildcard_alias'], ['yes', 'no'], true) + ? $_POST['wildcard_alias'] : 'no'; + + if ((!isset($_POST['datepicker']) + || $_POST['datepicker'] === '') + && !isset($_POST['never_expire']) + ) { + set_page_message( + tohtml(tr('Domain expiration date must be filled.')), 'error' + ); return; } - $dmnExpire = (isset($_POST['datepicker'])) ? @strtotime(clean_input($_POST['datepicker'])) : 0; + $dmnExpire = isset($_POST['datepicker']) + ? @strtotime(clean_input($_POST['datepicker'])) : 0; + if ($dmnExpire === false) { set_page_message('Invalid expiration date.', 'error'); return; } $hpId = isset($_POST['dmn_tpl']) ? clean_input($_POST['dmn_tpl']) : 0; - $customizeHp = ($hpId > 0 && isset($_POST['chtpl'])) ? $_POST['chtpl'] : '_no_'; + $customizeHp = $hpId > 0 && isset($_POST['chtpl']) ? $_POST['chtpl'] : '_no_'; if ($hpId == 0 || $customizeHp == '_yes_') { $_SESSION['dmn_name'] = $asciiDmnName; @@ -138,6 +151,7 @@ function reseller_checkData() $_SESSION['dmn_url_forward'] = $forwardUrl; $_SESSION['dmn_type_forward'] = $forwardType; $_SESSION['dmn_host_forward'] = $forwardHost; + $_SESSION['dmn_wildcard_alias'] = $wildcardAlias; $_SESSION['dmn_tpl'] = $hpId; $_SESSION['chtpl'] = '_yes_'; $_SESSION['step_one'] = '_yes_'; @@ -145,7 +159,10 @@ function reseller_checkData() } if (!reseller_limits_check($_SESSION['user_id'], $hpId)) { - set_page_message(tr('Hosting plan limits exceed reseller limits.'), 'error'); + set_page_message( + tohtml(tr('Hosting plan limits exceed reseller limits.')), + 'error' + ); return; } @@ -154,6 +171,7 @@ function reseller_checkData() $_SESSION['dmn_url_forward'] = $forwardUrl; $_SESSION['dmn_type_forward'] = $forwardType; $_SESSION['dmn_host_forward'] = $forwardHost; + $_SESSION['dmn_wildcard_alias'] = $wildcardAlias; $_SESSION['dmn_tpl'] = $hpId; $_SESSION['chtpl'] = $customizeHp; $_SESSION['step_one'] = '_yes_'; @@ -165,45 +183,70 @@ function reseller_checkData() * * @param iMSCP_pTemplate $tpl Template engine * @return void - * @throws iMSCP_Events_Manager_Exception - * @throws iMSCP_Exception - * @throws iMSCP_Exception_Database */ function reseller_generatePage($tpl) { $forwardType = ( isset($_POST['forward_type']) - && in_array($_POST['forward_type'], ['301', '302', '303', '307', 'proxy'], true) + && in_array( + $_POST['forward_type'], ['301', '302', '303', '307', 'proxy'], true + ) ) ? $_POST['forward_type'] : '302'; - $forwardHost = ($forwardType == 'proxy' && isset($_POST['forward_host'])) ? 'On' : 'Off'; + $forwardHost = $forwardType == 'proxy' && isset($_POST['forward_host']) + ? 'On' : 'Off'; + $wildcardAlias = isset($_POST['wildcard_alias']) + && in_array($_POST['wildcard_alias'], ['yes', 'no'], true) + ? $_POST['wildcard_alias'] : 'no'; $tpl->assign([ - 'DOMAIN_NAME_VALUE' => (isset($_POST['dmn_name'])) ? tohtml($_POST['dmn_name']) : '', - 'FORWARD_URL_YES' => (isset($_POST['url_forwarding']) && $_POST['url_forwarding'] == 'yes') - ? ' checked' : '', - 'FORWARD_URL_NO' => (isset($_POST['url_forwarding']) && $_POST['url_forwarding'] == 'yes') + 'DOMAIN_NAME_VALUE' => isset($_POST['dmn_name']) + ? tohtml($_POST['dmn_name']) : '', + 'FORWARD_URL_YES' => isset($_POST['url_forwarding']) + && $_POST['url_forwarding'] == 'yes' + ? ' checked' : '', + 'FORWARD_URL_NO' => isset($_POST['url_forwarding']) + && $_POST['url_forwarding'] == 'yes' + ? '' : ' checked', + 'HTTP_YES' => isset($_POST['forward_url_scheme']) + && $_POST['forward_url_scheme'] == 'http://' + ? ' selected' : '', + 'HTTPS_YES' => isset($_POST['forward_url_scheme']) + && $_POST['forward_url_scheme'] == 'https://' + ? ' selected' : '', + 'FORWARD_URL' => isset($_POST['forward_url']) + ? tohtml($_POST['forward_url']) : '', + 'FORWARD_TYPE_301' => $forwardType == '301' ? ' checked' : '', + 'FORWARD_TYPE_302' => $forwardType == '302' ? ' checked' : '', + 'FORWARD_TYPE_303' => $forwardType == '303' ? ' checked' : '', + 'FORWARD_TYPE_307' => $forwardType == '307' ? ' checked' : '', + 'FORWARD_TYPE_PROXY' => $forwardType == 'proxy' ? ' checked' : '', + 'FORWARD_HOST' => $forwardHost == 'On' ? ' checked' : '', + 'WILDCARD_ALIAS_YES' => $wildcardAlias == 'yes' ? ' checked' : '', + 'WILDCARD_ALIAS_NO' => $wildcardAlias == 'no' ? ' checked' : '', + 'DATEPICKER_VALUE' => isset($_POST['datepicker']) + ? tohtml($_POST['datepicker']) : '', + 'DATEPICKER_DISABLED' => isset($_POST['datepicker']) + ? '' : ' disabled', + 'NEVER_EXPIRE_CHECKED' => isset($_POST['datepicker']) ? '' : ' checked', - 'HTTP_YES' => (isset($_POST['forward_url_scheme']) && $_POST['forward_url_scheme'] == 'http://') - ? ' selected' : '', - 'HTTPS_YES' => (isset($_POST['forward_url_scheme']) && $_POST['forward_url_scheme'] == 'https://') - ? ' selected' : '', - 'FORWARD_URL' => (isset($_POST['forward_url'])) ? tohtml($_POST['forward_url']) : '', - 'FORWARD_TYPE_301' => ($forwardType == '301') ? ' checked' : '', - 'FORWARD_TYPE_302' => ($forwardType == '302') ? ' checked' : '', - 'FORWARD_TYPE_303' => ($forwardType == '303') ? ' checked' : '', - 'FORWARD_TYPE_307' => ($forwardType == '307') ? ' checked' : '', - 'FORWARD_TYPE_PROXY' => ($forwardType == 'proxy') ? ' checked' : '', - 'FORWARD_HOST' => ($forwardHost == 'On') ? ' checked' : '', - 'DATEPICKER_VALUE' => (isset($_POST['datepicker'])) ? tohtml($_POST['datepicker']) : '', - 'DATEPICKER_DISABLED' => (isset($_POST['datepicker'])) ? '' : ' disabled', - 'NEVER_EXPIRE_CHECKED' => (isset($_POST['datepicker'])) ? '' : ' checked', - 'CHTPL1_VAL' => (isset($_POST['chtpl']) && $_POST['chtpl'] == '_yes_') ? ' checked' : '', - 'CHTPL2_VAL' => (isset($_POST['chtpl']) && $_POST['chtpl'] == '_yes_') ? '' : ' checked' + 'CHTPL1_VAL' => isset($_POST['chtpl']) + && $_POST['chtpl'] == '_yes_' + ? ' checked' : '', + 'CHTPL2_VAL' => isset($_POST['chtpl']) + && $_POST['chtpl'] == '_yes_' + ? '' : ' checked' ]); - $stmt = exec_query('SELECT id, name FROM hosting_plans WHERE reseller_id = ? AND status = ? ORDER BY name', [ - $_SESSION['user_id'], '1' - ]); + $stmt = exec_query( + ' + SELECT id, name + FROM hosting_plans + WHERE reseller_id = ? + AND status = ? + ORDER BY name + ', + [$_SESSION['user_id'], '1'] + ); if (!$stmt->rowCount()) { $tpl->assign('HOSTING_PLAN_ENTRIES_BLOCK', ''); @@ -214,21 +257,19 @@ function reseller_generatePage($tpl) $hpId = isset($_POST['dmn_tpl']) ? $_POST['dmn_tpl'] : ''; $tpl->assign([ 'HP_NAME' => tohtml($row['name']), - 'HP_ID' => tohtml($row['id']), - 'HP_SELECTED' => ($row['id'] == $hpId) ? ' selected' : '' + 'HP_ID' => tohtml($row['id'], 'htmlAttr'), + 'HP_SELECTED' => $row['id'] == $hpId ? ' selected' : '' ]); $tpl->parse('HOSTING_PLAN_ENTRY_BLOCK', '.hosting_plan_entry_block'); } } -/*********************************************************************************************************************** - * Main - */ - require 'imscp-lib.php'; check_login('reseller'); -iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onResellerScriptStart); +iMSCP_Events_Aggregator::getInstance()->dispatch( + iMSCP_Events::onResellerScriptStart +); if (!empty($_POST)) { reseller_checkData(); @@ -244,29 +285,30 @@ function reseller_generatePage($tpl) 'customize_hosting_plan_block' => 'hosting_plan_entries_block' ]); $tpl->assign([ - 'TR_PAGE_TITLE' => tr('Reseller / Customers / Add Customer'), - 'TR_ADD_USER' => tr('Add user'), - 'TR_CORE_DATA' => tr('Domain data'), - 'TR_DOMAIN_NAME' => tr('Domain name'), - 'TR_DOMAIN_EXPIRE' => tr('Domain expiration date'), - 'TR_EXPIRE_CHECKBOX' => tr('Never'), - 'TR_CHOOSE_HOSTING_PLAN' => tr('Choose hosting plan'), - 'TR_PERSONALIZE_TEMPLATE' => tr('Personalise template'), - 'TR_URL_FORWARDING' => tr('URL forwarding'), - 'TR_URL_FORWARDING_TOOLTIP' => tr('Allows to forward any request made to this domain to a specific URL.'), - 'TR_FORWARD_TO_URL' => tr('Forward to URL'), - 'TR_YES' => tr('Yes'), - 'TR_NO' => tr('No'), - 'TR_HTTP' => 'http://', - 'TR_HTTPS' => 'https://', - 'TR_FORWARD_TYPE' => tr('Forward type'), - 'TR_301' => '301', - 'TR_302' => '302', - 'TR_303' => '303', - 'TR_307' => '307', - 'TR_PROXY' => 'PROXY', - 'TR_PROXY_PRESERVE_HOST' => tr('Preserve Host'), - 'TR_NEXT_STEP' => tr('Next step') + 'TR_PAGE_TITLE' => tohtml(tr('Reseller / Customers / Add Customer')), + 'TR_CORE_DATA' => tohtml(tr('Domain data')), + 'TR_DOMAIN_NAME' => tohtml(tr('Domain name')), + 'TR_DOMAIN_EXPIRE' => tohtml(tr('Domain expiration date')), + 'TR_EXPIRE_CHECKBOX' => tohtml(tr('Never')), + 'TR_CHOOSE_HOSTING_PLAN' => tohtml(tr('Choose hosting plan')), + 'TR_PERSONALIZE_TEMPLATE' => tohtml(tr('Personalise template')), + 'TR_URL_FORWARDING' => tohtml(tr('URL forwarding')), + 'TR_URL_FORWARDING_TOOLTIP' => tohtml(tr('Allows to forward any request made to this domain to a specific URL.'), 'htmlAttr'), + 'TR_FORWARD_TO_URL' => tohtml(tr('Forward to URL')), + 'TR_YES' => tohtml(tr('Yes')), + 'TR_NO' => tohtml(tr('No')), + 'TR_HTTP' => tohtml('http://'), + 'TR_HTTPS' => tohtml('https://'), + 'TR_FORWARD_TYPE' => tohtml(tr('Forward type')), + 'TR_301' => tohtml('301'), + 'TR_302' => tohtml('302'), + 'TR_303' => tohtml('303'), + 'TR_307' => tohtml('307'), + 'TR_PROXY' => tohtml('PROXY'), + 'TR_PROXY_PRESERVE_HOST' => tohtml(tr('Preserve Host')), + 'TR_WILDCARD_ALIAS_TOOLTIP' => tohtml(tr("If enabled, a wildcard alias entry such as '*.domain.tld' will be added in the Web server configuration. This option is most suitable for software that provide multisite feature such as the Wordpress CMS. Be aware that the control panel won't check for possible conflicts with subdomains."), 'htmlAttr'), + 'TR_WILDCARD_ALIAS' => tohtml(tr('Wildcard alias')), + 'TR_NEXT_STEP' => tohtml(tr('Next step'), 'htmlAttr') ]); generateNavigation($tpl); diff --git a/gui/public/reseller/user_add2.php b/gui/public/reseller/user_add2.php index e1675b2228..42e14195ed 100644 --- a/gui/public/reseller/user_add2.php +++ b/gui/public/reseller/user_add2.php @@ -1,7 +1,7 @@ + * Copyright (C) 2010-2019 by Laurent Declercq * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -18,9 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -/*********************************************************************************************************************** - * Functions - */ +/** @noinspection PhpUnhandledExceptionInspection PhpDocMissingThrowsInspection */ /** * Get first step data @@ -31,7 +29,12 @@ function getFirstStepData() { global $dmnName, $hpId; - foreach (['dmn_name', 'dmn_expire', 'dmn_url_forward', 'dmn_type_forward', 'dmn_host_forward', 'dmn_tpl'] as $data) { + foreach ( + [ + 'dmn_name', 'dmn_expire', 'dmn_url_forward', 'dmn_type_forward', + 'dmn_host_forward', 'dmn_tpl' + ] as $data + ) { if (!array_key_exists($data, $_SESSION)) { return false; } @@ -47,33 +50,33 @@ function getFirstStepData() * * @param iMSCP_pTemplate $tpl Template engine * @return void - * @throws Zend_Exception - * @throws iMSCP_Exception */ function generatePage($tpl) { - global $hpName, $php, $cgi, $sub, $als, $mail, $mailQuota, $ftp, $sqld, $sqlu, $traffic, $diskspace, $backup, $dns, - $aps, $extMail, $webFolderProtection; + global $hpName, $php, $cgi, $sub, $als, $mail, $mailQuota, $ftp, $sqld, + $sqlu, $traffic, $diskspace, $backup, $dns, $aps, $extMail, + $webFolderProtection; $cfg = iMSCP_Registry::get('config'); $tpl->assign([ - 'VL_TEMPLATE_NAME' => tohtml($hpName, 'htmlAttr'), - 'MAX_SUBDMN_CNT' => tohtml($sub, 'htmlAttr'), - 'MAX_DMN_ALIAS_CNT' => tohtml($als, 'htmlAttr'), - 'MAX_MAIL_CNT' => tohtml($mail, 'htmlAttr'), - 'MAIL_QUOTA' => tohtml($mailQuota, 'htmlAttr'), - 'MAX_FTP_CNT' => tohtml($ftp, 'htmlAttr'), - 'MAX_SQL_CNT' => tohtml($sqld, 'htmlAttr'), - 'VL_MAX_SQL_USERS' => tohtml($sqlu, 'htmlAttr'), - 'VL_MAX_TRAFFIC' => tohtml($traffic, 'htmlAttr'), - 'VL_MAX_DISK_USAGE' => tohtml($diskspace, 'htmlAttr'), - 'VL_EXTMAILY' => $extMail == '_yes_' ? ' checked' : '', - 'VL_EXTMAILN' => $extMail == '_yes_' ? '' : ' checked', - 'VL_PHPY' => $php == '_yes_' ? ' checked' : '', - 'VL_PHPN' => $php == '_yes_' ? '' : ' checked', - 'VL_CGIY' => $cgi == '_yes_' ? ' checked' : '', - 'VL_CGIN' => $cgi == '_yes_' ? '' : ' checked' + 'VL_TEMPLATE_NAME_VAL' => tohtml($hpName, 'htmlAttr'), + 'VL_TEMPLATE_NAME' => tohtml($hpName), + 'MAX_SUBDMN_CNT' => tohtml($sub, 'htmlAttr'), + 'MAX_DMN_ALIAS_CNT' => tohtml($als, 'htmlAttr'), + 'MAX_MAIL_CNT' => tohtml($mail, 'htmlAttr'), + 'MAIL_QUOTA' => tohtml($mailQuota, 'htmlAttr'), + 'MAX_FTP_CNT' => tohtml($ftp, 'htmlAttr'), + 'MAX_SQL_CNT' => tohtml($sqld, 'htmlAttr'), + 'VL_MAX_SQL_USERS' => tohtml($sqlu, 'htmlAttr'), + 'VL_MAX_TRAFFIC' => tohtml($traffic, 'htmlAttr'), + 'VL_MAX_DISK_USAGE' => tohtml($diskspace, 'htmlAttr'), + 'VL_EXTMAILY' => $extMail == '_yes_' ? ' checked' : '', + 'VL_EXTMAILN' => $extMail == '_yes_' ? '' : ' checked', + 'VL_PHPY' => $php == '_yes_' ? ' checked' : '', + 'VL_PHPN' => $php == '_yes_' ? '' : ' checked', + 'VL_CGIY' => $cgi == '_yes_' ? ' checked' : '', + 'VL_CGIN' => $cgi == '_yes_' ? '' : ' checked' ]); if (!resellerHasFeature('subdomains')) { @@ -126,8 +129,10 @@ function generatePage($tpl) } $tpl->assign([ - 'VL_WEB_FOLDER_PROTECTION_YES' => $webFolderProtection == '_yes_' ? ' checked' : '', - 'VL_WEB_FOLDER_PROTECTION_NO' => $webFolderProtection == '_yes_' ? '' : ' checked' + 'VL_WEB_FOLDER_PROTECTION_YES' => $webFolderProtection == '_yes_' + ? ' checked' : '', + 'VL_WEB_FOLDER_PROTECTION_NO' => $webFolderProtection == '_yes_' + ? '' : ' checked' ]); $phpini = iMSCP_PHPini::getInstance(); @@ -138,25 +143,29 @@ function generatePage($tpl) } $tpl->assign([ - 'PHP_EDITOR_YES' => $phpini->clientHasPermission('phpiniSystem') ? ' checked' : '', - 'PHP_EDITOR_NO' => $phpini->clientHasPermission('phpiniSystem') ? '' : ' checked', - 'TR_PHP_EDITOR' => tr('PHP Editor'), - 'TR_PHP_EDITOR_SETTINGS' => tr('PHP Settings'), - 'TR_SETTINGS' => tr('PHP Settings'), - 'TR_DIRECTIVES_VALUES' => tr('PHP Configuration options'), - 'TR_FIELDS_OK' => tr('All fields are valid.'), - 'TR_MIB' => tr('MiB'), - 'TR_SEC' => tr('Sec.') + 'PHP_EDITOR_YES' => $phpini->clientHasPermission('phpiniSystem') + ? ' checked' : '', + 'PHP_EDITOR_NO' => $phpini->clientHasPermission('phpiniSystem') + ? '' : ' checked', + 'TR_PHP_EDITOR' => tohtml(tr('PHP Editor')), + 'TR_PHP_EDITOR_SETTINGS' => tohtml(tr('PHP Settings')), + 'TR_SETTINGS' => tohtml(tr('PHP Settings')), + 'TR_DIRECTIVES_VALUES' => tohtml(tr('PHP Configuration options')), + 'TR_FIELDS_OK' => tohtml(tr('All fields are valid.')), + 'TR_MIB' => tohtml(tr('MiB')), + 'TR_SEC' => tohtml(tr('Sec.')) ]); - iMSCP_Events_Aggregator::getInstance()->registerListener('onGetJsTranslations', function ($e) { - /** @var iMSCP_Events_Event $e */ - $translations = $e->getParam('translations'); - $translations['core']['close'] = tr('Close'); - $translations['core']['fields_ok'] = tr('All fields are valid.'); - $translations['core']['out_of_range_value_error'] = tr('Value for the PHP %%s directive must be in range %%d to %%d.'); - $translations['core']['lower_value_expected_error'] = tr('%%s cannot be greater than %%s.'); - $translations['core']['error_field_stack'] = iMSCP_Registry::isRegistered('errFieldsStack') ? iMSCP_Registry::get('errFieldsStack') : []; + iMSCP_Events_Aggregator::getInstance()->registerListener( + iMSCP_Events::onGetJsTranslations, + function (iMSCP_Events_Event $e) { + $translations = $e->getParam('translations'); + $translations['core']['close'] = tr('Close'); + $translations['core']['fields_ok'] = tr('All fields are valid.'); + $translations['core']['out_of_range_value_error'] = tr('Value for the PHP %%s directive must be in range %%d to %%d.'); + $translations['core']['lower_value_expected_error'] = tr('%%s cannot be greater than %%s.'); + $translations['core']['error_field_stack'] = iMSCP_Registry::isRegistered('errFieldsStack') + ? iMSCP_Registry::get('errFieldsStack') : []; }); $permissionsBlock = false; @@ -165,9 +174,16 @@ function generatePage($tpl) $tpl->assign('PHP_EDITOR_ALLOW_URL_FOPEN_BLOCK', ''); } else { $tpl->assign([ - 'TR_CAN_EDIT_ALLOW_URL_FOPEN' => tr('Can edit the PHP %s configuration option', 'allow_url_fopen'), - 'ALLOW_URL_FOPEN_YES' => $phpini->clientHasPermission('phpiniAllowUrlFopen') ? ' checked' : '', - 'ALLOW_URL_FOPEN_NO' => $phpini->clientHasPermission('phpiniAllowUrlFopen') ? '' : ' checked' + 'TR_CAN_EDIT_ALLOW_URL_FOPEN' => tohtml(tr( + 'Can edit the PHP %s configuration option', + 'allow_url_fopen' + )), + 'ALLOW_URL_FOPEN_YES' => $phpini->clientHasPermission( + 'phpiniAllowUrlFopen' + ) ? ' checked' : '', + 'ALLOW_URL_FOPEN_NO' => $phpini->clientHasPermission( + 'phpiniAllowUrlFopen' + ) ? '' : ' checked' ]); $permissionsBlock = true; } @@ -176,9 +192,16 @@ function generatePage($tpl) $tpl->assign('PHP_EDITOR_DISPLAY_ERRORS_BLOCK', ''); } else { $tpl->assign([ - 'TR_CAN_EDIT_DISPLAY_ERRORS' => tr('Can edit the PHP %s configuration option', 'display_errors'), - 'DISPLAY_ERRORS_YES' => $phpini->clientHasPermission('phpiniDisplayErrors') ? ' checked' : '', - 'DISPLAY_ERRORS_NO' => $phpini->clientHasPermission('phpiniDisplayErrors') ? '' : ' checked' + 'TR_CAN_EDIT_DISPLAY_ERRORS' => tohtml(tr( + 'Can edit the PHP %s configuration option', + 'display_errors' + )), + 'DISPLAY_ERRORS_YES' => $phpini->clientHasPermission( + 'phpiniDisplayErrors' + ) ? ' checked' : '', + 'DISPLAY_ERRORS_NO' => $phpini->clientHasPermission( + 'phpiniDisplayErrors' + ) ? '' : ' checked' ]); $permissionsBlock = true; } @@ -191,10 +214,19 @@ function generatePage($tpl) } else { if ($phpini->resellerHasPermission('phpiniDisableFunctions')) { $tpl->assign([ - 'TR_CAN_EDIT_DISABLE_FUNCTIONS' => tr('Can edit the PHP %s configuration option', 'disable_functions'), - 'DISABLE_FUNCTIONS_YES' => $phpini->getClientPermission('phpiniDisableFunctions') == 'yes' ? ' checked' : '', - 'DISABLE_FUNCTIONS_NO' => $phpini->getClientPermission('phpiniDisableFunctions') == 'no' ? ' checked' : '', - 'DISABLE_FUNCTIONS_EXEC' => $phpini->getClientPermission('phpiniDisableFunctions') == 'exec' ? ' checked' : '', + 'TR_CAN_EDIT_DISABLE_FUNCTIONS' => tohtml(tr( + 'Can edit the PHP %s configuration option', + 'disable_functions' + )), + 'DISABLE_FUNCTIONS_YES' => $phpini->getClientPermission( + 'phpiniDisableFunctions' + ) == 'yes' ? ' checked' : '', + 'DISABLE_FUNCTIONS_NO' => $phpini->getClientPermission( + 'phpiniDisableFunctions' + ) == 'no' ? ' checked' : '', + 'DISABLE_FUNCTIONS_EXEC' => $phpini->getClientPermission( + 'phpiniDisableFunctions' + ) == 'exec' ? ' checked' : '', 'TR_ONLY_EXEC' => tr('Only exec') ]); } else { @@ -203,9 +235,15 @@ function generatePage($tpl) if ($phpini->resellerHasPermission('phpiniMailFunction')) { $tpl->assign([ - 'TR_CAN_USE_MAIL_FUNCTION' => tr('Can use the PHP %s function', 'mail'), - 'MAIL_FUNCTION_YES' => $phpini->clientHasPermission('phpiniMailFunction') ? ' checked' : '', - 'MAIL_FUNCTION_NO' => $phpini->clientHasPermission('phpiniMailFunction') ? '' : ' checked' + 'TR_CAN_USE_MAIL_FUNCTION' => tohtml( + tr('Can use the PHP %s function', 'mail') + ), + 'MAIL_FUNCTION_YES' => $phpini->clientHasPermission( + 'phpiniMailFunction' + ) ? ' checked' : '', + 'MAIL_FUNCTION_NO' => $phpini->clientHasPermission( + 'phpiniMailFunction' + ) ? '' : ' checked' ]); } else { $tpl->assign('PHP_EDITOR_MAIL_FUNCTION_BLOCK', ''); @@ -224,21 +262,52 @@ function generatePage($tpl) } $tpl->assign([ - 'TR_POST_MAX_SIZE' => tr('PHP %s configuration option', 'post_max_size'), - 'POST_MAX_SIZE' => tohtml($phpini->getDomainIni('phpiniPostMaxSize'), 'htmlAttr'), - 'TR_UPLOAD_MAX_FILEZISE' => tr('PHP %s configuration option', 'upload_max_filesize'), - 'UPLOAD_MAX_FILESIZE' => tohtml($phpini->getDomainIni('phpiniUploadMaxFileSize'), 'htmlAttr'), - 'TR_MAX_EXECUTION_TIME' => tr('PHP %s configuration option', 'max_execution_time'), - 'MAX_EXECUTION_TIME' => tohtml($phpini->getDomainIni('phpiniMaxExecutionTime'), 'htmlAttr'), - 'TR_MAX_INPUT_TIME' => tr('PHP %s configuration option', 'max_input_time'), - 'MAX_INPUT_TIME' => tohtml($phpini->getDomainIni('phpiniMaxInputTime'), 'htmlAttr'), - 'TR_MEMORY_LIMIT' => tr('PHP %s configuration option', 'memory_limit'), - 'MEMORY_LIMIT' => tohtml($phpini->getDomainIni('phpiniMemoryLimit'), 'htmlAttr'), - 'POST_MAX_SIZE_LIMIT' => tohtml($phpini->getResellerPermission('phpiniPostMaxSize'), 'htmlAttr'), - 'UPLOAD_MAX_FILESIZE_LIMIT' => tohtml($phpini->getResellerPermission('phpiniUploadMaxFileSize'), 'htmlAttr'), - 'MAX_EXECUTION_TIME_LIMIT' => tohtml($phpini->getResellerPermission('phpiniMaxExecutionTime'), 'htmlAttr'), - 'MAX_INPUT_TIME_LIMIT' => tohtml($phpini->getResellerPermission('phpiniMaxInputTime'), 'htmlAttr'), - 'MEMORY_LIMIT_LIMIT' => tohtml($phpini->getResellerPermission('phpiniMemoryLimit'), 'htmlAttr') + 'TR_POST_MAX_SIZE' => tohtml( + tr('PHP %s configuration option', 'post_max_size') + ), + 'POST_MAX_SIZE' => tohtml( + $phpini->getDomainIni('phpiniPostMaxSize'), 'htmlAttr' + ), + 'TR_UPLOAD_MAX_FILEZISE' => tohtml( + tr('PHP %s configuration option', 'upload_max_filesize') + ), + 'UPLOAD_MAX_FILESIZE' => tohtml( + $phpini->getDomainIni('phpiniUploadMaxFileSize'), 'htmlAttr' + ), + 'TR_MAX_EXECUTION_TIME' => tohtml( + tr('PHP %s configuration option', 'max_execution_time')), + 'MAX_EXECUTION_TIME' => tohtml( + $phpini->getDomainIni('phpiniMaxExecutionTime'), 'htmlAttr' + ), + 'TR_MAX_INPUT_TIME' => tohtml( + tr('PHP %s configuration option', 'max_input_time') + ), + 'MAX_INPUT_TIME' => tohtml( + $phpini->getDomainIni('phpiniMaxInputTime'), 'htmlAttr' + ), + 'TR_MEMORY_LIMIT' => tohtml( + tr('PHP %s configuration option', 'memory_limit') + ), + 'MEMORY_LIMIT' => tohtml( + $phpini->getDomainIni('phpiniMemoryLimit'), 'htmlAttr' + ), + 'POST_MAX_SIZE_LIMIT' => tohtml( + $phpini->getResellerPermission('phpiniPostMaxSize'), 'htmlAttr' + ), + 'UPLOAD_MAX_FILESIZE_LIMIT' => tohtml( + $phpini->getResellerPermission('phpiniUploadMaxFileSize'), + 'htmlAttr' + ), + 'MAX_EXECUTION_TIME_LIMIT' => tohtml( + $phpini->getResellerPermission('phpiniMaxExecutionTime'), + 'htmlAttr' + ), + 'MAX_INPUT_TIME_LIMIT' => tohtml( + $phpini->getResellerPermission('phpiniMaxInputTime'), 'htmlAttr' + ), + 'MEMORY_LIMIT_LIMIT' => tohtml( + $phpini->getResellerPermission('phpiniMemoryLimit'), 'htmlAttr' + ) ]); } @@ -246,23 +315,26 @@ function generatePage($tpl) * Get hosting plan data * * @return void - * @throws Zend_Exception - * @throws iMSCP_Events_Exception - * @throws iMSCP_Exception - * @throws iMSCP_Exception_Database */ function getHostingPlanData() { - global $hpId, $hpName, $php, $cgi, $sub, $als, $mail, $mailQuota, $ftp, $sqld, $sqlu, $traffic, $diskspace, $backup, - $dns, $aps, $extMail, $webFolderProtection; + global $hpId, $hpName, $php, $cgi, $sub, $als, $mail, $mailQuota, $ftp, + $sqld, $sqlu, $traffic, $diskspace, $backup, $dns, $aps, $extMail, + $webFolderProtection; if ($hpId == 0) { return; } - $stmt = exec_query('SELECT name, props FROM hosting_plans WHERE reseller_id = ? AND id = ?', [ - $_SESSION['user_id'], $hpId - ]); + $stmt = exec_query( + ' + SELECT name, props + FROM hosting_plans + WHERE reseller_id = ? + AND id = ? + ', + [$_SESSION['user_id'], $hpId] + ); if (!$stmt->rowCount()) { showBadRequestErrorPage(); @@ -271,9 +343,11 @@ function getHostingPlanData() $data = $stmt->fetchRow(); list( - $php, $cgi, $sub, $als, $mail, $ftp, $sqld, $sqlu, $traffic, $diskspace, $backup, $dns, $aps, $phpEditor, - $phpiniAllowUrlFopen, $phpiniDisplayErrors, $phpiniDisableFunctions, $phpiniMailFunction, $phpiniPostMaxSize, - $phpiniUploadMaxFileSize, $phpiniMaxExecutionTime, $phpiniMaxInputTime, $phpiniMemoryLimit, $extMail, + $php, $cgi, $sub, $als, $mail, $ftp, $sqld, $sqlu, $traffic, + $diskspace, $backup, $dns, $aps, $phpEditor, $phpiniAllowUrlFopen, + $phpiniDisplayErrors, $phpiniDisableFunctions, $phpiniMailFunction, + $phpiniPostMaxSize, $phpiniUploadMaxFileSize, $phpiniMaxExecutionTime, + $phpiniMaxInputTime, $phpiniMemoryLimit, $extMail, $webFolderProtection, $mailQuota ) = explode(';', $data['props']); @@ -285,11 +359,15 @@ function getHostingPlanData() $phpini->setClientPermission('phpiniSystem', $phpEditor); $phpini->setClientPermission('phpiniAllowUrlFopen', $phpiniAllowUrlFopen); $phpini->setClientPermission('phpiniDisplayErrors', $phpiniDisplayErrors); - $phpini->setClientPermission('phpiniDisableFunctions', $phpiniDisableFunctions); + $phpini->setClientPermission( + 'phpiniDisableFunctions', $phpiniDisableFunctions + ); $phpini->setClientPermission('phpiniMailFunction', $phpiniMailFunction); - $phpini->setDomainIni('phpiniMemoryLimit', $phpiniMemoryLimit); // Must be set before phpiniPostMaxSize - $phpini->setDomainIni('phpiniPostMaxSize', $phpiniPostMaxSize); // Must be set before phpiniUploadMaxFileSize + // Must be set before phpiniPostMaxSize + $phpini->setDomainIni('phpiniMemoryLimit', $phpiniMemoryLimit); + // Must be set before phpiniUploadMaxFileSize + $phpini->setDomainIni('phpiniPostMaxSize', $phpiniPostMaxSize); $phpini->setDomainIni('phpiniUploadMaxFileSize', $phpiniUploadMaxFileSize); $phpini->setDomainIni('phpiniMaxExecutionTime', $phpiniMaxExecutionTime); $phpini->setDomainIni('phpiniMaxInputTime', $phpiniMaxInputTime); @@ -299,40 +377,54 @@ function getHostingPlanData() * Check input data * * @return bool TRUE if all data are valid, FALSE otherwise - * @throws Zend_Exception - * @throws iMSCP_Exception */ function checkInputData() { - global $php, $cgi, $sub, $als, $mail, $mailQuota, $ftp, $sqld, $sqlu, $traffic, $diskspace, $backup, $dns, $aps, - $extMail, $webFolderProtection; - - $sub = isset($_POST['nreseller_max_subdomain_cnt']) ? clean_input($_POST['nreseller_max_subdomain_cnt']) : $sub; - $als = isset($_POST['nreseller_max_alias_cnt']) ? clean_input($_POST['nreseller_max_alias_cnt']) : $als; - $mail = isset($_POST['nreseller_max_mail_cnt']) ? clean_input($_POST['nreseller_max_mail_cnt']) : $mail; - $mailQuota = isset($_POST['nreseller_mail_quota']) ? clean_input($_POST['nreseller_mail_quota']) : $mailQuota; - $ftp = isset($_POST['nreseller_max_ftp_cnt']) ? clean_input($_POST['nreseller_max_ftp_cnt']) : $ftp; - $sqld = isset($_POST['nreseller_max_sql_db_cnt']) ? clean_input($_POST['nreseller_max_sql_db_cnt']) : $sqld; - $sqlu = isset($_POST['nreseller_max_sql_user_cnt']) ? clean_input($_POST['nreseller_max_sql_user_cnt']) : $sqlu; - $traffic = isset($_POST['nreseller_max_traffic']) ? clean_input($_POST['nreseller_max_traffic']) : $traffic; - $diskspace = isset($_POST['nreseller_max_disk']) ? clean_input($_POST['nreseller_max_disk']) : $diskspace; + global $php, $cgi, $sub, $als, $mail, $mailQuota, $ftp, $sqld, $sqlu, + $traffic, $diskspace, $backup, $dns, $aps, $extMail, $webFolderProtection; + + $sub = isset($_POST['nreseller_max_subdomain_cnt']) + ? clean_input($_POST['nreseller_max_subdomain_cnt']) : $sub; + $als = isset($_POST['nreseller_max_alias_cnt']) + ? clean_input($_POST['nreseller_max_alias_cnt']) : $als; + $mail = isset($_POST['nreseller_max_mail_cnt']) + ? clean_input($_POST['nreseller_max_mail_cnt']) : $mail; + $mailQuota = isset($_POST['nreseller_mail_quota']) + ? clean_input($_POST['nreseller_mail_quota']) : $mailQuota; + $ftp = isset($_POST['nreseller_max_ftp_cnt']) + ? clean_input($_POST['nreseller_max_ftp_cnt']) : $ftp; + $sqld = isset($_POST['nreseller_max_sql_db_cnt']) + ? clean_input($_POST['nreseller_max_sql_db_cnt']) : $sqld; + $sqlu = isset($_POST['nreseller_max_sql_user_cnt']) + ? clean_input($_POST['nreseller_max_sql_user_cnt']) : $sqlu; + $traffic = isset($_POST['nreseller_max_traffic']) + ? clean_input($_POST['nreseller_max_traffic']) : $traffic; + $diskspace = isset($_POST['nreseller_max_disk']) + ? clean_input($_POST['nreseller_max_disk']) : $diskspace; $php = isset($_POST['php']) ? clean_input($_POST['php']) : $php; $cgi = isset($_POST['cgi']) ? clean_input($_POST['cgi']) : $cgi; $dns = isset($_POST['dns']) ? clean_input($_POST['dns']) : $dns; - $backup = isset($_POST['backup']) && is_array($_POST['backup']) ? $_POST['backup'] : $backup; - $aps = isset($_POST['software_allowed']) ? clean_input($_POST['software_allowed']) : $aps; - $extMail = isset($_POST['external_mail']) ? clean_input($_POST['external_mail']) : $extMail; - $webFolderProtection = isset($_POST['web_folder_protection']) ? clean_input($_POST['web_folder_protection']) : $webFolderProtection; + $backup = isset($_POST['backup']) && is_array($_POST['backup']) + ? $_POST['backup'] : $backup; + $aps = isset($_POST['software_allowed']) + ? clean_input($_POST['software_allowed']) : $aps; + $extMail = isset($_POST['external_mail']) + ? clean_input($_POST['external_mail']) : $extMail; + $webFolderProtection = isset($_POST['web_folder_protection']) + ? clean_input($_POST['web_folder_protection']) : $webFolderProtection; $php = $php === '_yes_' ? '_yes_' : '_no_'; $cgi = $cgi === '_yes_' ? '_yes_' : '_no_'; - $dns = resellerHasFeature('custom_dns_records') && $dns === '_yes_' ? '_yes_' : '_no_'; - $backup = resellerHasFeature('backup') ? array_intersect($backup, ['_dmn_', '_sql_', '_mail_']) : []; + $dns = resellerHasFeature('custom_dns_records') && $dns === '_yes_' + ? '_yes_' : '_no_'; + $backup = resellerHasFeature('backup') + ? array_intersect($backup, ['_dmn_', '_sql_', '_mail_']) : []; $aps = resellerHasFeature('aps') && $aps === '_yes_' ? '_yes_' : '_no_'; $extMail = $extMail === '_yes_' ? '_yes_' : '_no_'; $webFolderProtection = $webFolderProtection === '_yes_' ? '_yes_' : '_no_'; - if ($aps == '_yes_') { // Ensure that PHP is enabled when software installer is enabled + if ($aps == '_yes_') { + // Ensure that PHP is enabled when software installer is enabled $php = '_yes_'; } @@ -342,14 +434,14 @@ function checkInputData() if (!resellerHasFeature('subdomains')) { $sub = '-1'; } elseif (!imscp_limit_check($sub, -1)) { - set_page_message(tr('Incorrect subdomain limit.'), 'error'); + set_page_message(tohtml(tr('Incorrect subdomain limit.')), 'error'); $errFieldsStack[] = 'nreseller_max_subdomain_cnt'; } if (!resellerHasFeature('domain_aliases')) { $als = '-1'; } elseif (!imscp_limit_check($als, -1)) { - set_page_message(tr('Incorrect alias limit.'), 'error'); + set_page_message(tohtml(tr('Incorrect alias limit.')), 'error'); $errFieldsStack[] = 'nreseller_max_alias_cnt'; } @@ -357,7 +449,9 @@ function checkInputData() if (!resellerHasFeature('mail')) { $mail = '-1'; } elseif (!imscp_limit_check($mail, -1)) { - set_page_message(tr('Incorrect mail accounts limit.'), 'error'); + set_page_message( + tohtml(tr('Incorrect mail accounts limit.')), 'error' + ); $errFieldsStack[] = 'nreseller_max_mail_cnt'; } @@ -366,10 +460,19 @@ function checkInputData() set_page_message(tr('Incorrect mail quota.'), 'error'); $errFieldsStack[] = 'nreseller_mail_quota'; } elseif ($diskspace != '0' && $mailQuota > $diskspace) { - set_page_message(tr('Mail quota cannot be bigger than disk space limit.'), 'error'); + set_page_message( + tohtml(tr('Mail quota cannot be bigger than disk space limit.')), + 'error' + ); $errFieldsStack[] = 'nreseller_mail_quota'; } elseif ($diskspace != '0' && $mailQuota == '0') { - set_page_message(tr('Mail quota cannot be unlimited. Max value is %d MiB.', $diskspace), 'error'); + set_page_message( + tohtml(tr( + 'Mail quota cannot be unlimited. Max value is %d MiB.', + $diskspace + )), + 'error' + ); $errFieldsStack[] = 'nreseller_mail_quota'; } @@ -377,7 +480,7 @@ function checkInputData() if (!resellerHasFeature('ftp')) { $ftp = '-1'; } elseif (!imscp_limit_check($ftp, -1)) { - set_page_message(tr('Incorrect FTP accounts limit.'), 'error'); + set_page_message(tohtml(tr('Incorrect FTP accounts limit.')), 'error'); $errFieldsStack[] = 'nreseller_max_ftp_cnt'; } @@ -385,7 +488,9 @@ function checkInputData() if (!resellerHasFeature('sql_db')) { $sqld = -1; } elseif (!imscp_limit_check($sqld, -1)) { - set_page_message(tr('Incorrect SQL databases limit.'), 'error'); + set_page_message( + tohtml(tr('Incorrect SQL databases limit.')), 'error' + ); $errFieldsStack[] = 'nreseller_max_sql_db_cnt'; } elseif ($sqld != -1 && $sqlu == -1) { set_page_message(tr('SQL users limit is disabled.'), 'error'); @@ -397,23 +502,29 @@ function checkInputData() if (!resellerHasFeature('sql_user')) { $sqlu = -1; } elseif (!imscp_limit_check($sqlu, -1)) { - set_page_message(tr('Incorrect SQL users limit.'), 'error'); + set_page_message(tohtml(tr('Incorrect SQL users limit.')), 'error'); $errFieldsStack[] = 'nreseller_max_sql_user_cnt'; } elseif ($sqlu != -1 && $sqld == -1) { - set_page_message(tr("SQL databases limit is disabled."), 'error'); + set_page_message( + tohtml(tr("SQL databases limit is disabled."), 'error') + ); $errFieldsStack[] = 'nreseller_max_sql_user_cnt'; $errFieldsStack[] = 'nreseller_max_sql_db_cnt'; } // Monthly traffic limit if (!imscp_limit_check($traffic, NULL)) { - set_page_message(tr('Incorrect monthly traffic limit.'), 'error'); + set_page_message( + tohtml(tr('Incorrect monthly traffic limit.')), 'error' + ); $errFieldsStack[] = 'nreseller_max_traffic'; } // Disk space limit if (!imscp_limit_check($diskspace, NULL)) { - set_page_message(tr('Incorrect disk space limit.'), 'error'); + set_page_message( + tohtml(tr('Incorrect disk space limit.')), 'error' + ); $errFieldsStack[] = 'nreseller_max_disk'; } @@ -423,45 +534,70 @@ function checkInputData() if (isset($_POST['php_ini_system']) && $php != '_no_' && $phpini->resellerHasPermission('phpiniSystem') ) { - $phpini->setClientPermission('phpiniSystem', clean_input($_POST['php_ini_system'])); + $phpini->setClientPermission( + 'phpiniSystem', clean_input($_POST['php_ini_system']) + ); if ($phpini->clientHasPermission('phpiniSystem')) { if (isset($_POST['phpini_perm_allow_url_fopen'])) { - $phpini->setClientPermission('phpiniAllowUrlFopen', clean_input($_POST['phpini_perm_allow_url_fopen'])); + $phpini->setClientPermission( + 'phpiniAllowUrlFopen', + clean_input($_POST['phpini_perm_allow_url_fopen']) + ); } if (isset($_POST['phpini_perm_display_errors'])) { - $phpini->setClientPermission('phpiniDisplayErrors', clean_input($_POST['phpini_perm_display_errors'])); + $phpini->setClientPermission( + 'phpiniDisplayErrors', + clean_input($_POST['phpini_perm_display_errors']) + ); } if (isset($_POST['phpini_perm_disable_functions'])) { $phpini->setClientPermission( - 'phpiniDisableFunctions', clean_input($_POST['phpini_perm_disable_functions']) + 'phpiniDisableFunctions', + clean_input($_POST['phpini_perm_disable_functions']) ); } if (isset($_POST['phpini_perm_mail_function'])) { - $phpini->setClientPermission('phpiniMailFunction', clean_input($_POST['phpini_perm_mail_function'])); + $phpini->setClientPermission( + 'phpiniMailFunction', + clean_input($_POST['phpini_perm_mail_function']) + ); } - if (isset($_POST['memory_limit'])) { // Must be set before phpiniPostMaxSize - $phpini->setDomainIni('phpiniMemoryLimit', clean_input($_POST['memory_limit'])); + if (isset($_POST['memory_limit'])) { + // Must be set before phpiniPostMaxSize + $phpini->setDomainIni( + 'phpiniMemoryLimit', clean_input($_POST['memory_limit'])); } - if (isset($_POST['post_max_size'])) { // Must be set before phpiniUploadMaxFileSize - $phpini->setDomainIni('phpiniPostMaxSize', clean_input($_POST['post_max_size'])); + if (isset($_POST['post_max_size'])) { + // Must be set before phpiniUploadMaxFileSize + $phpini->setDomainIni('phpiniPostMaxSize', + clean_input($_POST['post_max_size']) + ); } if (isset($_POST['upload_max_filesize'])) { - $phpini->setDomainIni('phpiniUploadMaxFileSize', clean_input($_POST['upload_max_filesize'])); + $phpini->setDomainIni(' + phpiniUploadMaxFileSize', + clean_input($_POST['upload_max_filesize']) + ); } if (isset($_POST['max_execution_time'])) { - $phpini->setDomainIni('phpiniMaxExecutionTime', clean_input($_POST['max_execution_time'])); + $phpini->setDomainIni( + 'phpiniMaxExecutionTime', + clean_input($_POST['max_execution_time']) + ); } if (isset($_POST['max_input_time'])) { - $phpini->setDomainIni('phpiniMaxInputTime', clean_input($_POST['max_input_time'])); + $phpini->setDomainIni( + 'phpiniMaxInputTime', clean_input($_POST['max_input_time']) + ); } } } @@ -474,33 +610,38 @@ function checkInputData() return true; } -/*********************************************************************************************************************** - * Main - */ - require 'imscp-lib.php'; check_login('reseller'); -iMSCP_Events_Aggregator::getInstance()->dispatch(iMSCP_Events::onResellerScriptStart); +iMSCP_Events_Aggregator::getInstance()->dispatch( + iMSCP_Events::onResellerScriptStart +); // Initialize global variables global $dmnName, $hpId; $hpName = 'Custom'; -$sub = $als = $mail = $mailQuota = $ftp = $sqld = $sqlu = $traffic = $diskspace = '0'; +$sub = $als = $mail = $mailQuota = $ftp = $sqld = $sqlu = $traffic + = $diskspace = '0'; $php = $cgi = $dns = $aps = $extMail = '_no_'; $webFolderProtection = '_yes_'; $backup = []; if (!getFirstStepData()) { - set_page_message(tr('Domain data were altered. Please try again.'), 'error'); + set_page_message( + tohtml(tr('Domain data were altered. Please try again.')), + 'error' + ); unsetMessages(); redirectTo('user_add1.php'); } $phpini = iMSCP_PHPini::getInstance(); -$phpini->loadResellerPermissions($_SESSION['user_id']); // Load reseller PHP permissions -$phpini->loadClientPermissions(); // Load client default PHP permissions -$phpini->loadDomainIni(); // Load domain default PHP configuration options +// Load reseller PHP permissions +$phpini->loadResellerPermissions($_SESSION['user_id']); +// Load client default PHP permissions +$phpini->loadClientPermissions(); +// Load domain default PHP configuration options +$phpini->loadDomainIni(); if (isset($_POST['uaction']) && 'user_add2_nxt' == $_POST['uaction'] @@ -509,7 +650,8 @@ function checkInputData() if (checkInputData()) { $_SESSION['step_two_data'] = "$dmnName;0"; $_SESSION['ch_hpprops'] = - "$php;$cgi;$sub;$als;$mail;$ftp;$sqld;$sqlu;$traffic;$diskspace;" . implode('|', $backup) . ";$dns;$aps;" . + "$php;$cgi;$sub;$als;$mail;$ftp;$sqld;$sqlu;$traffic;$diskspace;" + . implode('|', $backup) . ";$dns;$aps;" . $phpini->getClientPermission('phpiniSystem') . ';' . $phpini->getClientPermission('phpiniAllowUrlFopen') . ';' . $phpini->getClientPermission('phpiniDisplayErrors') . ';' . @@ -522,7 +664,9 @@ function checkInputData() $phpini->getDomainIni('phpiniMemoryLimit') . ';' . $extMail . ';' . $webFolderProtection . ';' . $mailQuota * 1048576; - if (reseller_limits_check($_SESSION['user_id'], $_SESSION['ch_hpprops'])) { + if (reseller_limits_check( + $_SESSION['user_id'], $_SESSION['ch_hpprops']) + ) { redirectTo('user_add3.php'); } } @@ -554,36 +698,34 @@ function checkInputData() 'php_editor_default_values_block' => 'php_editor_block' ]); $tpl->assign([ - 'TR_PAGE_TITLE' => tr('Reseller / Customers / Add Customer - Next Step'), - 'TR_ADD_USER' => tr('Add user'), - 'TR_HOSTING_PLAN' => tr('Hosting plan'), - 'TR_NAME' => tr('Name'), - 'TR_MAX_DOMAIN' => tr('Domains limit') . '
(-1 ' . tr('disabled') . ', 0 ∞)', - 'TR_MAX_SUBDOMAIN' => tr('Subdomains limit') . '
(-1 ' . tr('disabled') . ', 0 ∞)', - 'TR_MAX_DOMAIN_ALIAS' => tr('Domain aliases limit') . '
(-1 ' . tr('disabled') . ', 0 ∞)', - 'TR_MAX_MAIL_COUNT' => tr('Mail accounts limit') . '
(-1 ' . tr('disabled') . ', 0 ∞)', - 'TR_MAIL_QUOTA' => tr('Mail quota [MiB]') . '
(0 ∞)', - 'TR_MAX_FTP' => tr('FTP accounts limit') . '
(-1 ' . tr('disabled') . ', 0 ∞)', - 'TR_MAX_SQL_DB' => tr('SQL databases limit') . '
(-1 ' . tr('disabled') . ', 0 ∞)', - 'TR_MAX_SQL_USERS' => tr('SQL users limit') . '
(-1 ' . tr('disabled') . ', 0 ∞)', - 'TR_MAX_TRAFFIC' => tr('Monthly traffic limit [MiB]') . '
(0 ∞)', - 'TR_MAX_DISK_USAGE' => tr('Disk space limit [MiB]') . '
(0 ∞)', - 'TR_EXTMAIL' => tr('External mail server'), - 'TR_PHP' => tr('PHP'), - 'TR_CGI' => tr('CGI'), - 'TR_BACKUP' => tr('Backup'), - 'TR_BACKUP_DOMAIN' => tr('Domain'), - 'TR_BACKUP_SQL' => tr('SQL'), - 'TR_BACKUP_MAIL' => tr('Mail'), - 'TR_DNS' => tr('Custom DNS records'), - 'TR_YES' => tr('yes'), - 'TR_NO' => tr('no'), - 'TR_NEXT_STEP' => tr('Next step'), - 'TR_FEATURES' => tr('Features'), - 'TR_LIMITS' => tr('Limits'), - 'TR_WEB_FOLDER_PROTECTION' => tr('Web folder protection'), - 'TR_WEB_FOLDER_PROTECTION_HELP' => tr('If set to `yes`, Web folders will be protected against deletion.'), - 'TR_SOFTWARE_SUPP' => tr('Software installer') + 'TR_PAGE_TITLE' => tohtml(tr('Reseller / Customers / Add Customer - Next Step')), + 'TR_HOSTING_PLAN' => tohtml(tr('Hosting plan')), + 'TR_NAME' => tohtml(tr('Name')), + 'TR_MAX_SUBDOMAIN' => tohtml(tr('Subdomains limit')) . '
(-1 ' . tohtml(tr('disabled')) . ', 0 ∞)', + 'TR_MAX_DOMAIN_ALIAS' => tohtml(tr('Domain aliases limit')) . '
(-1 ' . tohtml(tr('disabled')) . ', 0 ∞)', + 'TR_MAX_MAIL_COUNT' => tohtml(tr('Mail accounts limit')) . '
(-1 ' . tohtml(tr('disabled')) . ', 0 ∞)', + 'TR_MAIL_QUOTA' => tohtml(tr('Mail quota [MiB]')). '
(0 ∞)', + 'TR_MAX_FTP' => tohtml(tr('FTP accounts limit')) . '
(-1 ' . tohtml(tr('disabled')) . ', 0 ∞)', + 'TR_MAX_SQL_DB' => tohtml(tr('SQL databases limit')) . '
(-1 ' . tohtml(tr('disabled')) . ', 0 ∞)', + 'TR_MAX_SQL_USERS' => tohtml(tr('SQL users limit')) . '
(-1 ' . tohtml(tr('disabled')) . ', 0 ∞)', + 'TR_MAX_TRAFFIC' => tohtml(tr('Monthly traffic limit [MiB]')) . '
(0 ∞)', + 'TR_MAX_DISK_USAGE' => tohtml(tr('Disk space limit [MiB]')) . '
(0 ∞)', + 'TR_EXTMAIL' => tohtml(tr('External mail server')), + 'TR_PHP' => tohtml(tr('PHP')), + 'TR_CGI' => tohtml(tr('CGI')), + 'TR_BACKUP' => tohtml(tr('Backup')), + 'TR_BACKUP_DOMAIN' => tohtml(tr('Domain')), + 'TR_BACKUP_SQL' => tohtml(tr('SQL')), + 'TR_BACKUP_MAIL' => tohtml(tr('Mail')), + 'TR_DNS' => tohtml(tr('Custom DNS records')), + 'TR_YES' => tohtml(tr('yes')), + 'TR_NO' => tohtml(tr('no')), + 'TR_NEXT_STEP' => tohtml(tr('Next step')), + 'TR_FEATURES' => tohtml(tr('Features')), + 'TR_LIMITS' => tohtml(tr('Limits')), + 'TR_WEB_FOLDER_PROTECTION' => tohtml(tr('Web folder protection')), + 'TR_WEB_FOLDER_PROTECTION_HELP' => tohtml(tr('If set to `yes`, Web folders will be protected against deletion.'), 'htmlAttr'), + 'TR_SOFTWARE_SUPP' => tohtml(tr('Software installer')) ]); generateNavigation($tpl); diff --git a/gui/public/reseller/user_add3.php b/gui/public/reseller/user_add3.php index 558c7de13f..1226626ac2 100644 --- a/gui/public/reseller/user_add3.php +++ b/gui/public/reseller/user_add3.php @@ -1,7 +1,7 @@ + * Copyright (C) 2010-2019 by Laurent Declercq * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -18,34 +18,23 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -use iMSCP\Crypt as Crypt; -use iMSCP_Database as Database; -use iMSCP_Events as Events; -use iMSCP_Events_Aggregator as EventsManager; -use iMSCP_Exception as iMSCPException; -use iMSCP_PHPini as PhpIni; -use iMSCP_pTemplate as TemplateEngine; -use iMSCP_Registry as Registry; -use Zend_Form as Form; - -/*********************************************************************************************************************** - * Functions - */ +/** @noinspection PhpUnhandledExceptionInspection PhpDocMissingThrowsInspection */ /** * Get data from previous step * * @return bool - * @throws Zend_Exception */ function getPreviousStepData() { - global $adminName, $hpId, $dmnName, $dmnExpire, $dmnUrlForward, $dmnTypeForward, $dmnHostForward; + global $adminName, $hpId, $dmnName, $dmnExpire, $dmnUrlForward, + $dmnTypeForward, $dmnHostForward, $dmnWildcardAlias; $dmnExpire = $_SESSION['dmn_expire']; $dmnUrlForward = $_SESSION['dmn_url_forward']; $dmnTypeForward = $_SESSION['dmn_type_forward']; $dmnHostForward = $_SESSION['dmn_host_forward']; + $dmnWildcardAlias = $_SESSION['dmn_wildcard_alias']; if (isset($_SESSION['step_one'])) { $stepTwo = $_SESSION['dmn_name'] . ';' . $_SESSION['dmn_tpl']; @@ -76,15 +65,14 @@ function getPreviousStepData() /** * Add customer user - * - * @throws Exception - * @throws iMSCP_Exception - * @param Form $form + * + * @param Zend_Form $form * @return void */ -function addCustomer(Form $form) +function addCustomer(Zend_Form $form) { - global $hpId, $dmnName, $dmnExpire, $dmnUrlForward, $dmnTypeForward, $dmnHostForward, $domainIp, $adminName; + global $hpId, $dmnName, $dmnExpire, $dmnUrlForward, $dmnTypeForward, + $dmnHostForward, $dmnWildcardAlias, $domainIp, $adminName; if (!isset($_POST['domain_ip'])) { showBadRequestErrorPage(); @@ -99,9 +87,14 @@ function addCustomer(Form $form) } $domainIp = intval($_POST['domain_ip']); - $stmt = exec_query('SELECT reseller_ips FROM reseller_props WHERE reseller_id = ?', $_SESSION['user_id']); + $stmt = exec_query( + 'SELECT reseller_ips FROM reseller_props WHERE reseller_id = ?', + [$_SESSION['user_id']] + ); if (!$stmt->rowCount()) { - throw new iMSCPException(sprintf('Could not find IPs for reseller with ID %s', $_SESSION['user_id'])); + throw new iMSCP_Exception(sprintf( + 'Could not find IPs for reseller with ID %s', $_SESSION['user_id'] + )); } $resellerIps = $stmt->fetchRow(); @@ -110,23 +103,26 @@ function addCustomer(Form $form) showBadRequestErrorPage(); } - $cfg = Registry::get('config'); + $cfg = iMSCP_Registry::get('config'); if (isset($_SESSION['ch_hpprops'])) { $props = $_SESSION['ch_hpprops']; unset($_SESSION['ch_hpprops']); } else { - $stmt = exec_query('SELECT props FROM hosting_plans WHERE reseller_id = ? AND id = ?', [ - $_SESSION['user_id'], $hpId - ]); + $stmt = exec_query( + 'SELECT props FROM hosting_plans WHERE reseller_id = ? AND id = ?', + [$_SESSION['user_id'], $hpId] + ); $data = $stmt->fetchRow(); $props = $data['props']; } list( - $php, $cgi, $sub, $als, $mail, $ftp, $sql_db, $sql_user, $traff, $disk, $backup, $dns, $aps, $phpEditor, - $phpiniAllowUrlFopen, $phpiniDisplayErrors, $phpiniDisableFunctions, $phpMailFunction, $phpiniPostMaxSize, - $phpiniUploadMaxFileSize, $phpiniMaxExecutionTime, $phpiniMaxInputTime, $phpiniMemoryLimit, $extMailServer, + $php, $cgi, $sub, $als, $mail, $ftp, $sql_db, $sql_user, $traff, $disk, + $backup, $dns, $aps, $phpEditor, $phpiniAllowUrlFopen, + $phpiniDisplayErrors, $phpiniDisableFunctions, $phpMailFunction, + $phpiniPostMaxSize, $phpiniUploadMaxFileSize, $phpiniMaxExecutionTime, + $phpiniMaxInputTime, $phpiniMemoryLimit, $extMailServer, $webFolderProtection, $mailQuota ) = explode(';', $props); @@ -137,7 +133,7 @@ function addCustomer(Form $form) $aps = str_replace('_', '', $aps); $extMailServer = str_replace('_', '', $extMailServer); $webFolderProtection = str_replace('_', '', $webFolderProtection); - $db = Database::getInstance(); + $db = iMSCP_Database::getInstance(); try { $db->beginTransaction(); @@ -145,104 +141,149 @@ function addCustomer(Form $form) exec_query( " INSERT INTO admin ( - admin_name, admin_pass, admin_type, domain_created, created_by, fname, lname, firm, zip, city, state, - country, email, phone, fax, street1, street2, gender, admin_status + admin_name, admin_pass, admin_type, domain_created, + created_by, fname, lname, firm, zip, city, state, country, + email, phone, fax, street1, street2, gender, admin_status ) VALUES ( - ?, ?, ?, unix_timestamp(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'toadd' + ?, ?, ?, unix_timestamp(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, 'toadd' ) ", [ - $adminName, Crypt::apr1MD5($form->getValue('admin_pass')), 'user', $_SESSION['user_id'], - $form->getValue('fname'), $form->getValue('lname'), $form->getValue('firm'), $form->getValue('zip'), - $form->getValue('city'), $form->getValue('state'), $form->getValue('country'), - encode_idna($form->getValue('email')), $form->getValue('phone'), $form->getValue('fax'), - $form->getValue('street1'), $form->getValue('street2'), $form->getValue('gender') + $adminName, iMSCP\Crypt::apr1MD5($form->getValue('admin_pass')), + 'user', $_SESSION['user_id'], $form->getValue('fname'), + $form->getValue('lname'), $form->getValue('firm'), + $form->getValue('zip'), $form->getValue('city'), + $form->getValue('state'), $form->getValue('country'), + encode_idna($form->getValue('email')), $form->getValue('phone'), + $form->getValue('fax'), + $form->getValue('street1'), $form->getValue('street2'), + $form->getValue('gender') ] ); $adminId = $db->insertId(); - EventsManager::getInstance()->dispatch(Events::onBeforeAddDomain, [ - 'createdBy' => $_SESSION['user_id'], - 'customerId' => $adminId, - 'customerEmail' => $form->getValue('email'), - 'domainName' => $dmnName, - 'mountPoint' => '/', - 'documentRoot' => '/htdocs', - 'forwardUrl' => $dmnUrlForward, - 'forwardType' => $dmnTypeForward, - 'forwardHost' => $dmnHostForward - ]); + iMSCP_Events_Aggregator::getInstance()->dispatch( + iMSCP_Events::onBeforeAddDomain, + [ + 'createdBy' => $_SESSION['user_id'], + 'customerId' => $adminId, + 'customerEmail' => $form->getValue('email'), + 'domainName' => $dmnName, + 'mountPoint' => '/', + 'documentRoot' => '/htdocs', + 'forwardUrl' => $dmnUrlForward, + 'forwardType' => $dmnTypeForward, + 'forwardHost' => $dmnHostForward, + 'wildcardAlias' => $dmnWildcardAlias + ] + ); exec_query( ' INSERT INTO domain ( - domain_name, domain_admin_id, domain_created, domain_expires, domain_mailacc_limit, - domain_ftpacc_limit, domain_traffic_limit, domain_sqld_limit, domain_sqlu_limit, domain_status, - domain_alias_limit, domain_subd_limit, domain_ip_id, domain_disk_limit, domain_disk_usage, - domain_php, domain_cgi, allowbackup, domain_dns, domain_software_allowed, phpini_perm_system, - phpini_perm_allow_url_fopen, phpini_perm_display_errors, phpini_perm_disable_functions, - phpini_perm_mail_function, domain_external_mail, web_folder_protection, mail_quota, url_forward, - type_forward, host_forward + domain_name, domain_admin_id, domain_created, + domain_expires, domain_mailacc_limit, domain_ftpacc_limit, + domain_traffic_limit, domain_sqld_limit, domain_sqlu_limit, + domain_status, domain_alias_limit, domain_subd_limit, + domain_ip_id, domain_disk_limit, domain_disk_usage, + domain_php, domain_cgi, allowbackup, domain_dns, + domain_software_allowed, phpini_perm_system, + phpini_perm_allow_url_fopen, phpini_perm_display_errors, + phpini_perm_disable_functions, phpini_perm_mail_function, + domain_external_mail, web_folder_protection, mail_quota, + url_forward, type_forward, host_forward, wildcard_alias ) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? + ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) ', [ - $dmnName, $adminId, time(), $dmnExpire, $mail, $ftp, $traff, $sql_db, $sql_user, 'toadd', $als, $sub, - $domainIp, $disk, 0, $php, $cgi, $backup, $dns, $aps, $phpEditor, $phpiniAllowUrlFopen, - $phpiniDisplayErrors, $phpiniDisableFunctions, $phpMailFunction, $extMailServer, $webFolderProtection, - $mailQuota, $dmnUrlForward, $dmnTypeForward, $dmnHostForward + $dmnName, $adminId, time(), $dmnExpire, $mail, $ftp, $traff, + $sql_db, $sql_user, 'toadd', $als, $sub, $domainIp, $disk, 0, + $php, $cgi, $backup, $dns, $aps, $phpEditor, + $phpiniAllowUrlFopen, $phpiniDisplayErrors, + $phpiniDisableFunctions, $phpMailFunction, $extMailServer, + $webFolderProtection, $mailQuota, $dmnUrlForward, + $dmnTypeForward, $dmnHostForward, $dmnWildcardAlias ] ); $dmnId = $db->insertId(); - $phpini = PhpIni::getInstance(); - $phpini->loadResellerPermissions($_SESSION['user_id']); // Load reseller PHP permissions - $phpini->loadClientPermissions(); // Load client default PHP permissions - $phpini->loadDomainIni(); // Load domain default PHP configuration options - - $phpini->setDomainIni('phpiniMemoryLimit', $phpiniMemoryLimit); // Must be set before phpiniPostMaxSize - $phpini->setDomainIni('phpiniPostMaxSize', $phpiniPostMaxSize); // Must be set before phpiniUploadMaxFileSize - $phpini->setDomainIni('phpiniUploadMaxFileSize', $phpiniUploadMaxFileSize); - $phpini->setDomainIni('phpiniMaxExecutionTime', $phpiniMaxExecutionTime); + $phpini = iMSCP_PHPini::getInstance(); + // Load reseller PHP permissions + $phpini->loadResellerPermissions($_SESSION['user_id']); + // Load client default PHP permissions + $phpini->loadClientPermissions(); + // Load domain default PHP configuration options + $phpini->loadDomainIni(); + + // Must be set before phpiniPostMaxSize + $phpini->setDomainIni('phpiniMemoryLimit', $phpiniMemoryLimit); + // Must be set before phpiniUploadMaxFileSize + $phpini->setDomainIni('phpiniPostMaxSize', $phpiniPostMaxSize); + $phpini->setDomainIni( + 'phpiniUploadMaxFileSize', $phpiniUploadMaxFileSize + ); + $phpini->setDomainIni( + 'phpiniMaxExecutionTime', $phpiniMaxExecutionTime + ); $phpini->setDomainIni('phpiniMaxInputTime', $phpiniMaxInputTime); $phpini->saveDomainIni($adminId, $dmnId, 'dmn'); if ($cfg['CREATE_DEFAULT_EMAIL_ADDRESSES']) { - createDefaultMailAccounts($dmnId, $form->getValue('email'), $dmnName); + createDefaultMailAccounts( + $dmnId, $form->getValue('email'), $dmnName + ); } send_add_user_auto_msg( - $_SESSION['user_id'], $adminName, $form->getValue('admin_pass'), $form->getValue('email'), - $form->getValue('fname'), $form->getValue('lname'), tr('Customer') + $_SESSION['user_id'], $adminName, $form->getValue('admin_pass'), + $form->getValue('email'), $form->getValue('fname'), + $form->getValue('lname'), tr('Customer') + ); + exec_query( + ' + INSERT INTO user_gui_props ( + user_id, lang, layout + ) VALUES (?, ?, ?) + ', + [$adminId, $cfg['USER_INITIAL_LANG'], $cfg['USER_INITIAL_THEME']] ); - exec_query('INSERT INTO user_gui_props (user_id, lang, layout) VALUES (?, ?, ?)', [ - $adminId, $cfg['USER_INITIAL_LANG'], $cfg['USER_INITIAL_THEME'] - ]); update_reseller_c_props($_SESSION['user_id']); - EventsManager::getInstance()->dispatch(Events::onAfterAddDomain, [ - 'createdBy' => $_SESSION['user_id'], - 'customerId' => $adminId, - 'customerEmail' => $form->getValue('email'), - 'domainId' => $dmnId, - 'domainName' => $dmnName, - 'mountPoint' => '/', - 'documentRoot' => '/htdocs', - 'forwardUrl' => $dmnUrlForward, - 'forwardType' => $dmnTypeForward, - 'forwardHost' => $dmnHostForward - ]); + iMSCP_Events_Aggregator::getInstance()->dispatch( + iMSCP_Events::onAfterAddDomain, + [ + 'createdBy' => $_SESSION['user_id'], + 'customerId' => $adminId, + 'customerEmail' => $form->getValue('email'), + 'domainId' => $dmnId, + 'domainName' => $dmnName, + 'mountPoint' => '/', + 'documentRoot' => '/htdocs', + 'forwardUrl' => $dmnUrlForward, + 'forwardType' => $dmnTypeForward, + 'forwardHost' => $dmnHostForward, + 'wildcardAlias' => $dmnWildcardAlias + ] + ); $db->commit(); send_request(); write_log( - sprintf('A new customer (%s) has been created by: %s:', $adminName, $_SESSION['user_logged']), + sprintf( + 'A new customer (%s) has been created by: %s', + $adminName, $_SESSION['user_logged'] + ), E_USER_NOTICE ); - set_page_message(tr('Customer account successfully scheduled for creation.'), 'success'); + set_page_message( + tohtml(tr('Customer account successfully scheduled for creation.')), + 'success' + ); unsetMessages(); redirectTo('users.php'); } catch (Exception $e) { @@ -254,15 +295,11 @@ function addCustomer(Form $form) /** * Generates page * - * @param TemplateEngine $tpl Template engine - * @param Form $form + * @param iMSCP_pTemplate $tpl Template engine + * @param Zend_Form $form * @return void - * @throws Zend_Exception - * @throws iMSCP_Events_Manager_Exception - * @throws iMSCP_Exception - * @throws iMSCP_Exception_Database */ -function generatePage(TemplateEngine $tpl, Form $form) +function generatePage(iMSCP_pTemplate $tpl, Zend_Form $form) { global $hpId, $dmnName, $domainIp; @@ -274,22 +311,24 @@ function generatePage(TemplateEngine $tpl, Form $form) $_SESSION['local_data'] = "$dmnName;$hpId"; } -/*********************************************************************************************************************** - * Main - */ - require 'imscp-lib.php'; check_login('reseller'); -EventsManager::getInstance()->dispatch(Events::onResellerScriptStart); +iMSCP_Events_Aggregator::getInstance()->dispatch( + iMSCP_Events::onResellerScriptStart +); if (!getPreviousStepData()) { - set_page_message(tr('Data were altered. Please try again.'), 'error'); + set_page_message( + tohtml(tr('Data were altered. Please try again.')), 'error' + ); unsetMessages(); redirectTo('user_add1.php'); } -$form = getUserLoginDataForm(false, true)->addElements(getUserPersonalDataForm()->getElements()); +$form = getUserLoginDataForm(false, true)->addElements( + getUserPersonalDataForm()->getElements() +); $form->setDefault('gender', 'U'); if (isset($_POST['uaction']) @@ -301,7 +340,7 @@ function generatePage(TemplateEngine $tpl, Form $form) unset($_SESSION['step_two_data']); } -$tpl = new TemplateEngine(); +$tpl = new iMSCP_pTemplate(); $tpl->define_dynamic([ 'layout' => 'shared/layouts/ui.tpl', 'page' => 'reseller/user_add3.phtml', @@ -315,5 +354,7 @@ function generatePage(TemplateEngine $tpl, Form $form) generatePageMessage($tpl); $tpl->parse('LAYOUT_CONTENT', 'page'); -EventsManager::getInstance()->dispatch(Events::onResellerScriptEnd, ['templateEngine' => $tpl]); +iMSCP_Events_Aggregator::getInstance()->dispatch( + iMSCP_Events::onResellerScriptEnd, ['templateEngine' => $tpl] +); $tpl->prnt(); diff --git a/gui/themes/default/client/alias_add.tpl b/gui/themes/default/client/alias_add.tpl index dcf90f6d1d..99cf691d33 100644 --- a/gui/themes/default/client/alias_add.tpl +++ b/gui/themes/default/client/alias_add.tpl @@ -117,6 +117,17 @@ + + {TR_WILDCARD_ALIAS} + + + + + + + + +
diff --git a/gui/themes/default/client/alias_edit.tpl b/gui/themes/default/client/alias_edit.tpl index c9bdc58955..f8e1034c0e 100644 --- a/gui/themes/default/client/alias_edit.tpl +++ b/gui/themes/default/client/alias_edit.tpl @@ -95,6 +95,17 @@ + + {TR_WILDCARD_ALIAS} + + + + + + + + +
diff --git a/gui/themes/default/client/domain_edit.tpl b/gui/themes/default/client/domain_edit.tpl index 6bf5e8e97a..d6b5538530 100644 --- a/gui/themes/default/client/domain_edit.tpl +++ b/gui/themes/default/client/domain_edit.tpl @@ -95,6 +95,17 @@ + + {TR_WILDCARD_ALIAS} + + + + + + + + +
diff --git a/gui/themes/default/client/subdomain_add.tpl b/gui/themes/default/client/subdomain_add.tpl index dce7663fd0..8393fec92d 100644 --- a/gui/themes/default/client/subdomain_add.tpl +++ b/gui/themes/default/client/subdomain_add.tpl @@ -119,6 +119,17 @@ + + {TR_WILDCARD_ALIAS} + + + + + + + + +
diff --git a/gui/themes/default/client/subdomain_edit.tpl b/gui/themes/default/client/subdomain_edit.tpl index fe5b298e2c..10bdf506bd 100644 --- a/gui/themes/default/client/subdomain_edit.tpl +++ b/gui/themes/default/client/subdomain_edit.tpl @@ -92,6 +92,17 @@ + + {TR_WILDCARD_ALIAS} + + + + + + + + +
diff --git a/gui/themes/default/reseller/alias_add.tpl b/gui/themes/default/reseller/alias_add.tpl index af1d515203..7b8cd55cb9 100644 --- a/gui/themes/default/reseller/alias_add.tpl +++ b/gui/themes/default/reseller/alias_add.tpl @@ -136,6 +136,17 @@ + + {TR_WILDCARD_ALIAS} + + + + + + + + +
diff --git a/gui/themes/default/reseller/alias_edit.tpl b/gui/themes/default/reseller/alias_edit.tpl index 8cc0b965ee..0ecb8a1fd6 100644 --- a/gui/themes/default/reseller/alias_edit.tpl +++ b/gui/themes/default/reseller/alias_edit.tpl @@ -95,6 +95,17 @@ + + {TR_WILDCARD_ALIAS} + + + + + + + + +
diff --git a/gui/themes/default/reseller/user_add1.tpl b/gui/themes/default/reseller/user_add1.tpl index 6eac151dc9..00d04f20f2 100644 --- a/gui/themes/default/reseller/user_add1.tpl +++ b/gui/themes/default/reseller/user_add1.tpl @@ -101,6 +101,17 @@ + + {TR_WILDCARD_ALIAS} + + + + + + + + + diff --git a/gui/themes/default/reseller/user_add2.tpl b/gui/themes/default/reseller/user_add2.tpl index c5ed8d99b0..27e61c913e 100644 --- a/gui/themes/default/reseller/user_add2.tpl +++ b/gui/themes/default/reseller/user_add2.tpl @@ -45,7 +45,7 @@ {TR_NAME} - {VL_TEMPLATE_NAME} + {VL_TEMPLATE_NAME}