From a1db6855a18e6b35c5236d85c06bbe1cba8fa90a Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Mon, 7 Jul 2014 15:40:45 +0200 Subject: [PATCH] default servers on client templates --- install/sql/incremental/upd_0078.sql | 5 ++ .../lib/classes/client_templates.inc.php | 16 +++++- interface/web/client/client_template_edit.php | 9 ++- .../web/client/form/client_template.tform.php | 55 +++++++++++++++++++ .../client/lib/lang/en_client_template.lng | 5 ++ .../client/lib/lang/es_client_template.lng | 5 ++ .../templates/client_template_edit_limits.htm | 30 ++++++++++ 7 files changed, 122 insertions(+), 3 deletions(-) create mode 100644 install/sql/incremental/upd_0078.sql diff --git a/install/sql/incremental/upd_0078.sql b/install/sql/incremental/upd_0078.sql new file mode 100644 index 0000000000..b5c72bef62 --- /dev/null +++ b/install/sql/incremental/upd_0078.sql @@ -0,0 +1,5 @@ +ALTER TABLE `client_template` ADD `default_mailserver` INT(11) NOT NULL DEFAULT 1; +ALTER TABLE `client_template` ADD `default_webserver` INT(11) NOT NULL DEFAULT 1; +ALTER TABLE `client_template` ADD `default_dnsserver` INT(11) NOT NULL DEFAULT 1; +ALTER TABLE `client_template` ADD `default_slave_dnsserver` INT(11) NOT NULL DEFAULT 1; +ALTER TABLE `client_template` ADD `default_dbserver` INT(11) NOT NULL DEFAULT 1; diff --git a/interface/lib/classes/client_templates.inc.php b/interface/lib/classes/client_templates.inc.php index 81f8bd37f5..993936b2ce 100644 --- a/interface/lib/classes/client_templates.inc.php +++ b/interface/lib/classes/client_templates.inc.php @@ -146,7 +146,7 @@ class client_templates { if (is_array($addLimits)){ foreach($addLimits as $k => $v){ /* we can remove this condition, but it is easier to debug with it (don't add ids and other non-limit values) */ - if (strpos($k, 'limit') !== false or $k == 'ssh_chroot' or $k == 'web_php_options' or $k == 'force_suexec'){ + if (strpos($k, 'limit') !== false or strpos($k, 'default') !== false or $k == 'ssh_chroot' or $k == 'web_php_options' or $k == 'force_suexec'){ $app->log('Template processing key ' . $k . ' for client ' . $clientId, LOGLEVEL_DEBUG); /* process the numerical limits */ @@ -160,6 +160,15 @@ class client_templates { if ($limits[$k] < 1) $limits[$k] = 1; break; + case 'default_mailserver': + case 'default_webserver': + case 'default_dnsserver': + case 'default_slave_dnsserver': + case 'default_dbserver': + /* additional templates don't override default server from main template */ + if ($limits[$k] == 0) $limits[$k] = $v; + break; + default: if ($limits[$k] > -1){ if ($v == -1){ @@ -225,7 +234,10 @@ class client_templates { $update = ''; if(!$is_reseller) unset($limits['limit_client']); // Only Resellers may have limit_client set in template to ensure that we do not convert a client to reseller accidently. foreach($limits as $k => $v){ - if ((strpos($k, 'limit') !== false or $k == 'ssh_chroot' or $k == 'web_php_options' or $k == 'force_suexec') && !is_array($v)){ + if (strpos($k, 'default') !== false and $v == 0) { + continue; // template doesn't define default server, client's default musn't be changed + } + if ((strpos($k, 'limit') !== false or strpos($k, 'default') !== false or $k == 'ssh_chroot' or $k == 'web_php_options' or $k == 'force_suexec') && !is_array($v)){ if ($update != '') $update .= ', '; $update .= '`' . $k . "`='" . $v . "'"; } diff --git a/interface/web/client/client_template_edit.php b/interface/web/client/client_template_edit.php index bc5c6d22cf..256ff49732 100644 --- a/interface/web/client/client_template_edit.php +++ b/interface/web/client/client_template_edit.php @@ -88,10 +88,17 @@ class page_action extends tform_actions { global $app; $app->uses('client_templates'); + if (isset($this->dataRecord["template_type"])) { + $template_type = $this->dataRecord["template_type"]; + } else { + $tmp = $app->tform->getDataRecord($this->id); + $template_type = $tmp['template_type']; + } + /* * the template has changed. apply the new data to all clients */ - if ($this->dataRecord["template_type"] == 'm'){ + if ($template_type == 'm'){ $sql = "SELECT client_id FROM client WHERE template_master = " . $this->id; } else { $sql = "SELECT client_id FROM client WHERE template_additional LIKE '%/" . $this->id . "/%' OR template_additional LIKE '" . $this->id . "/%' OR template_additional LIKE '%/" . $this->id . "' UNION SELECT client_id FROM client_template_assigned WHERE client_template_id = " . $this->id; diff --git a/interface/web/client/form/client_template.tform.php b/interface/web/client/form/client_template.tform.php index dff2dcf4eb..b1fd7d350f 100644 --- a/interface/web/client/form/client_template.tform.php +++ b/interface/web/client/form/client_template.tform.php @@ -115,6 +115,17 @@ $form["tabs"]['limits'] = array ( 'rows' => '', 'cols' => '' ), + 'default_mailserver' => array ( + 'datatype' => 'INTEGER', + 'formtype' => 'SELECT', + 'default' => '0', + 'datasource' => array ( 'type' => 'CUSTOM', + 'class'=> 'custom_datasource', + 'function'=> 'client_servers' + ), + 'value' => array(''), + 'name' => 'default_mailserver' + ), 'limit_maildomain' => array ( 'datatype' => 'INTEGER', 'formtype' => 'TEXT', @@ -311,6 +322,17 @@ $form["tabs"]['limits'] = array ( 'rows' => '', 'cols' => '' ), + 'default_webserver' => array ( + 'datatype' => 'INTEGER', + 'formtype' => 'SELECT', + 'default' => '0', + 'datasource' => array ( 'type' => 'CUSTOM', + 'class'=> 'custom_datasource', + 'function'=> 'client_servers' + ), + 'value' => array(''), + 'name' => 'default_webserver' + ), 'limit_web_domain' => array ( 'datatype' => 'INTEGER', 'formtype' => 'TEXT', @@ -491,6 +513,17 @@ $form["tabs"]['limits'] = array ( 'default' => 'y', 'value' => array(0 => 'n', 1 => 'y') ), + 'default_dnsserver' => array ( + 'datatype' => 'INTEGER', + 'formtype' => 'SELECT', + 'default' => '0', + 'datasource' => array ( 'type' => 'CUSTOM', + 'class'=> 'custom_datasource', + 'function'=> 'client_servers' + ), + 'value' => array(''), + 'name' => 'default_dnsserver' + ), 'limit_dns_zone' => array ( 'datatype' => 'INTEGER', 'formtype' => 'TEXT', @@ -505,6 +538,17 @@ $form["tabs"]['limits'] = array ( 'rows' => '', 'cols' => '' ), + 'default_slave_dnsserver' => array ( + 'datatype' => 'INTEGER', + 'formtype' => 'SELECT', + 'default' => '0', + 'datasource' => array ( 'type' => 'CUSTOM', + 'class'=> 'custom_datasource', + 'function'=> 'client_servers' + ), + 'value' => array(''), + 'name' => 'default_slave_dnsserver' + ), 'limit_dns_slave_zone' => array ( 'datatype' => 'INTEGER', 'formtype' => 'TEXT', @@ -549,6 +593,17 @@ $form["tabs"]['limits'] = array ( 'cols' => '' ), */ + 'default_dbserver' => array ( + 'datatype' => 'INTEGER', + 'formtype' => 'SELECT', + 'default' => '0', + 'datasource' => array ( 'type' => 'CUSTOM', + 'class'=> 'custom_datasource', + 'function'=> 'client_servers' + ), + 'value' => array(''), + 'name' => 'default_dbserver' + ), 'limit_database' => array ( 'datatype' => 'INTEGER', 'formtype' => 'TEXT', diff --git a/interface/web/client/lib/lang/en_client_template.lng b/interface/web/client/lib/lang/en_client_template.lng index 5d8c3f3b19..9aacf40319 100644 --- a/interface/web/client/lib/lang/en_client_template.lng +++ b/interface/web/client/lib/lang/en_client_template.lng @@ -2,6 +2,7 @@ $wb["template_type_txt"] = 'Template type'; $wb["template_name_txt"] = 'Template name'; $wb["limit_client_error_notint"] = 'Client Limit is not a number.'; +$wb["default_mailserver_txt"] = 'Default Mailserver'; $wb["limit_maildomain_txt"] = 'Max. number of email domains'; $wb["limit_mailbox_txt"] = 'Max. number of mailboxes'; $wb["limit_mailalias_txt"] = 'Max. number of email aliases'; @@ -23,11 +24,14 @@ $wb["limit_database_txt"] = 'limit_database'; $wb["limit_cron_txt"] = 'Max. number of cron jobs'; $wb["limit_cron_type_txt"] = 'Max. type of cron jobs (chrooted and full implies url)'; $wb["limit_cron_frequency_txt"] = 'Min. delay between executions'; +$wb["default_webserver_txt"] = 'Default Webserver'; $wb["limit_web_domain_txt"] = 'Max. number of web domains'; $wb["limit_web_aliasdomain_txt"] = 'Max. number of web aliasdomains'; $wb["limit_web_subdomain_txt"] = 'Max. number of web subdomains'; $wb["limit_ftp_user_txt"] = 'Max. number of FTP users'; +$wb["default_dnsserver_txt"] = 'Default DNS Server'; $wb["limit_dns_zone_txt"] = 'Max. number of DNS zones'; +$wb["default_slave_dnsserver_txt"] = 'Default Secondary DNS Server'; $wb["limit_dns_slave_zone_txt"] = 'Max. number of secondary DNS zones'; $wb["limit_dns_record_txt"] = 'Max. number DNS records'; $wb["limit_shell_user_txt"] = 'Max. number of Shell users'; @@ -57,6 +61,7 @@ $wb["limit_webdav_user_error_notint"] = 'The webdav user limit must be a number. $wb["limit_dns_zone_error_notint"] = 'The dns zone limit must be a number.'; $wb["limit_dns_slave_zone_error_notint"] = 'The dns slave zone limit must be a number.'; $wb["limit_dns_record_error_notint"] = 'The dns record limit must be a number.'; +$wb["default_dbserver_txt"] = 'Default Database Server'; $wb["limit_database_txt"] = 'Max. number of Databases'; $wb["limit_database_error_notint"] = 'The database limit must be a number.'; $wb["limit_cron_error_notint"] = 'The cron limit must be a number.'; diff --git a/interface/web/client/lib/lang/es_client_template.lng b/interface/web/client/lib/lang/es_client_template.lng index afde4152c3..156f272260 100644 --- a/interface/web/client/lib/lang/es_client_template.lng +++ b/interface/web/client/lib/lang/es_client_template.lng @@ -1,5 +1,6 @@ <?php $wb['limit_client_error_notint'] = 'El lÃmite de subclientes debe ser un número.'; +$wb['default_mailserver_txt'] = 'Servidor de correo por defecto'; $wb['limit_maildomain_txt'] = 'Número máximo de dominios de correo'; $wb['limit_mailbox_txt'] = 'Número máximo de buzones de correo'; $wb['limit_mailalias_txt'] = 'Número máximo de alias de correo'; @@ -17,11 +18,14 @@ $wb['limit_domain_txt'] = 'Número máximo de dominios '; $wb['limit_subdomain_txt'] = 'Número máximo de subdominios '; $wb['limit_webquota_txt'] = 'Cuota de web'; $wb['limit_database_txt'] = 'Número máximo de bases de datos'; +$wb['default_webserver_txt'] = 'Servidor web por defecto'; $wb['limit_web_domain_txt'] = 'Número máximo de sitios web'; $wb['limit_web_aliasdomain_txt'] = 'Número máximo de alias de dominios'; $wb['limit_web_subdomain_txt'] = 'Número máximo de subdominios'; $wb['limit_ftp_user_txt'] = 'Número máximo de usuarios FTP'; +$wb['default_dnsserver_txt'] = 'Servidor DNS por defecto'; $wb['limit_dns_zone_txt'] = 'Número máximo de zonas DNS'; +$wb['default_slave_dnsserver_txt'] = 'Servidor DNS secundario por defecto'; $wb['limit_dns_slave_zone_txt'] = 'Número máximo de zonas DNS secundarias'; $wb['limit_dns_record_txt'] = 'Número máximo de registros DNS'; $wb['limit_shell_user_txt'] = 'Número máximo de usuarios de consola'; @@ -45,6 +49,7 @@ $wb['limit_shell_user_error_notint'] = 'El lÃmite de usuarios de consola debe s $wb['limit_dns_zone_error_notint'] = 'El lÃmite de registros DNS debe ser un número.'; $wb['limit_dns_slave_zone_error_notint'] = 'El lÃmite de zonas DNS secundarias debe ser un número.'; $wb['limit_dns_record_error_notint'] = 'El lÃmite de registros DNS debe ser un número.'; +$wb['default_dbserver_txt'] = 'Servidor de bases de datos por defecto'; $wb['limit_database_error_notint'] = 'El lÃmite de bases de datos debe ser un número.'; $wb['error_template_name_empty'] = 'Por favor, introduzca un nombre de plantilla'; $wb['limit_cron_txt'] = 'Número máximo de tareas cron'; diff --git a/interface/web/client/templates/client_template_edit_limits.htm b/interface/web/client/templates/client_template_edit_limits.htm index dc83c6eef1..71ab963f3e 100644 --- a/interface/web/client/templates/client_template_edit_limits.htm +++ b/interface/web/client/templates/client_template_edit_limits.htm @@ -7,6 +7,12 @@ <fieldset class="inlineLabels"><legend>Limits</legend> <div class="subsectiontoggle"><span class="showing"></span>{tmpl_var name='web_limits_txt'}<em class="showing"></em></div> <div> + <div class="ctrlHolder"> + <label for="default_webserver">{tmpl_var name='default_webserver_txt'}</label> + <select name="default_webserver" id="default_webserver" class="selectInput"> + {tmpl_var name='default_webserver'} + </select> + </div> <div class="ctrlHolder"> <label for="limit_web_domain">{tmpl_var name='limit_web_domain_txt'}</label> <input name="limit_web_domain" id="limit_web_domain" value="{tmpl_var name='limit_web_domain'}" size="10" maxlength="10" type="text" class="textInput formLengthLimit" /> @@ -114,6 +120,12 @@ </div> <div class="subsectiontoggle"><span></span>{tmpl_var name='email_limits_txt'}<em></em></div> <div style="display:none;"> + <div class="ctrlHolder"> + <label for="default_mailserver">{tmpl_var name='default_mailserver_txt'}</label> + <select name="default_mailserver" id="default_mailserver" class="selectInput"> + {tmpl_var name='default_mailserver'} + </select> + </div> <div class="ctrlHolder"> <label for="limit_maildomain">{tmpl_var name='limit_maildomain_txt'}</label> <input name="limit_maildomain" id="limit_maildomain" value="{tmpl_var name='limit_maildomain'}" size="10" maxlength="10" type="text" class="textInput formLengthLimit" /> @@ -173,6 +185,12 @@ </div> <div class="subsectiontoggle"><span></span>{tmpl_var name='database_limits_txt'}<em></em></div> <div style="display:none;"> + <div class="ctrlHolder"> + <label for="default_dbserver">{tmpl_var name='default_dbserver_txt'}</label> + <select name="default_dbserver" id="default_dbserver" class="selectInput"> + {tmpl_var name='default_dbserver'} + </select> + </div> <div class="ctrlHolder"> <label for="limit_database">{tmpl_var name='limit_database_txt'}</label> <input name="limit_database" id="limit_database" value="{tmpl_var name='limit_database'}" size="10" maxlength="10" type="text" class="textInput formLengthLimit" /> @@ -201,9 +219,21 @@ </div> <div class="subsectiontoggle"><span></span>{tmpl_var name='dns_limits_txt'}<em></em></div> <div style="display:none;"> + <div class="ctrlHolder"> + <label for="default_dnsserver">{tmpl_var name='default_dnsserver_txt'}</label> + <select name="default_dnsserver" id="default_dnsserver" class="selectInput"> + {tmpl_var name='default_dnsserver'} + </select> + </div> <div class="ctrlHolder"> <label for="limit_dns_zone">{tmpl_var name='limit_dns_zone_txt'}</label> <input name="limit_dns_zone" id="limit_dns_zone" value="{tmpl_var name='limit_dns_zone'}" size="10" maxlength="10" type="text" class="textInput formLengthLimit" /> + </div> + <div class="ctrlHolder"> + <label for="default_slave_dnsserver">{tmpl_var name='default_slave_dnsserver_txt'}</label> + <select name="default_slave_dnsserver" id="default_slave_dnsserver" class="selectInput"> + {tmpl_var name='default_slave_dnsserver'} + </select> </div> <div class="ctrlHolder"> <label for="limit_dns_slave_zone">{tmpl_var name='limit_dns_slave_zone_txt'}</label> -- GitLab