Commit c56a0a90 authored by Kristián Feldsam's avatar Kristián Feldsam
Browse files

Merge branch 'develop'

parents f5c34356 b4af8135
......@@ -65,6 +65,7 @@ CREATE TABLE `wizard_template` (
`apache_directives` mediumtext,
`nginx_directives` mediumtext,
`php_fpm_use_socket` enum('n','y') NOT NULL DEFAULT 'n',
`php_fpm_chroot` enum('n','y') NOT NULL DEFAULT 'n',
`pm` enum('static','dynamic','ondemand') NOT NULL DEFAULT 'dynamic',
`pm_max_children` int(11) unsigned NOT NULL DEFAULT '10',
`pm_start_servers` int(11) unsigned NOT NULL DEFAULT '2',
......
......@@ -119,6 +119,37 @@ $form["tabs"]['client'] = array(
),
'value' => ''
),
'username' => array (
'datatype' => 'VARCHAR',
'formtype' => 'TEXT',
'filters' => array(
0 => array( 'event' => 'SAVE',
'type' => 'IDNTOASCII'),
1 => array( 'event' => 'SHOW',
'type' => 'IDNTOUTF8'),
2 => array( 'event' => 'SAVE',
'type' => 'TOLOWER')
),
'validators' => array (
0 => array ( 'type' => 'NOTEMPTY',
'errmsg'=> 'username_error_empty'),
2 => array ( 'type' => 'REGEX',
'regex' => '/^[\w\.\-\_]{0,64}$/',
'errmsg'=> 'username_error_regex'),
),
'default' => '',
'value' => '',
'width' => '15',
'maxlength' => '30'
),
'username_prefix' => array (
'datatype' => 'VARCHAR',
'formtype' => 'TEXT',
'default' => '',
'value' => '',
'width' => '30',
'maxlength' => '25'
),
'template_id' => array(
'datatype' => 'INTEGER',
'formtype' => 'SELECT',
......
<?php
$wb["client_id_txt"] = 'Client';
$wb["domain_txt"] = 'Domain';
$wb["username_txt"] = 'Username';
$wb["db_txt"] = 'Create DB';
$wb["db_type_txt"] = 'DB type';
$wb["ftp_txt"] = 'Create FTP';
......
......@@ -72,6 +72,10 @@ class page_action extends tform_actions {
}
}
$global_config = $app->getconf->get_global_config('sites');
$shelluser_prefix = $global_config['shelluser_prefix'];
$app->tpl->setVar("username_prefix", $shelluser_prefix, true);
parent::onShowEnd();
}
......@@ -108,10 +112,12 @@ class page_action extends tform_actions {
// client prefix and group id
$res = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = ".$app->functions->intval($fields['client_id']));
$client_group_id = $res['groupid'];
$client_prefix = 'c'.$fields['client_id'];
// add domain
$domain_id = $remote->insert_query('../client/form/domain.tform.php', $fields['client_id'], array('domain' => $fields['domain']));
$min_password_length = 8;
if(isset($server_config_array['misc']['min_password_length'])) $min_password_length = $server_config_array['misc']['min_password_length'];
// DNS Zone
if($fields['dns'])
......@@ -354,7 +360,7 @@ class page_action extends tform_actions {
// validate, on error skip
if( ! preg_match('/^[_a-z0-9][\w\.\-_\+@]{1,63}$/', $mailbox)) continue;
$mailbox_passwords[$mailbox] = substr(sha1(rand()), 0, 10);
$mailbox_passwords[$mailbox] = $app->auth->get_random_password($min_password_length, true);
$params = array(
'server_id' => $template['mail_server_id'],
......@@ -426,17 +432,30 @@ class page_action extends tform_actions {
$app->uses('remoting_lib');
$app->remoting_lib->loadFormDef('../sites/form/web_vhost_domain.tform.php');
$site_data = $app->remoting_lib->getDataRecord($site_id);
// generate username
$generated_username = $client_prefix.substr(sha1(rand()), 0, 8);
$app->uses('getconf,tools_sites');
$global_config = $app->getconf->get_global_config('sites');
$client_shell_prefix = $app->tools_sites->replacePrefix($global_config['shelluser_prefix'], array('client_group_id' => $client_group_id));
$client_ftp_prefix = $app->tools_sites->replacePrefix($global_config['ftpuser_prefix'], array('client_group_id' => $client_group_id));
$client_db_prefix = $app->tools_sites->replacePrefix($global_config['dbuser_prefix'], array('client_group_id' => $client_group_id));
if (empty($fields['username'])) {
// generate username
$generated_username = substr(sha1(rand()), 0, 8);
}
else {
$generated_username = $fields['username'];
}
if($fields['db'])
{
// add database user
$db_user_params = array(
'server_id' => $template['database_server_id'],
'database_user' => $generated_username,
'database_password' => substr(sha1(rand()), 0, 10)
'database_user' => $client_db_prefix . $generated_username,
'database_user_prefix' => $client_db_prefix,
'database_password' => $app->auth->get_random_password($min_password_length, true),
);
$db_user_id = $remote->insert_query('../sites/form/database_user.tform.php', $fields['client_id'], $db_user_params, 'sites:web_database_user:on_after_insert');
......@@ -447,6 +466,7 @@ class page_action extends tform_actions {
'type' => $fields['db_type'],
'database_quota' => $template['database_quota'],
'database_name' => $db_user_params['database_user'],
'database_name_prefix' => $db_user_params['database_user_prefix'],
'database_user_id' => $db_user_id,
'database_charset' => $template['database_charset'],
'remote_access' => $template['database_remote_access'],
......@@ -461,8 +481,9 @@ class page_action extends tform_actions {
$ftp_params = array(
'server_id' => $template['web_server_id'],
'parent_domain_id' => $site_id,
'username' => $generated_username,
'password' => substr(sha1(rand()), 0, 10),
'username' => $client_ftp_prefix . $generated_username,
'username_prefix' => $client_prefix,
'password' => $app->auth->get_random_password($min_password_length, true),
'quota_size' => $template['hd_quota'],
'dir' => $site_data['document_root'],
'uid' => $site_data['system_user'],
......@@ -491,14 +512,15 @@ class page_action extends tform_actions {
'chroot' => $template['shell_chroot'],
'shell' => $template['shell'],
'active' => 'y',
'username' => $generated_username,
'username' => $client_shell_prefix . $generated_username,
'username_prefix' => $client_prefix,
);
// username, password
if(isset($ftp_params)) {
$ssh_params['password'] = $ftp_params['password'];
} else {
$ssh_params['password'] = substr(sha1(rand()), 0, 10);
$ssh_params['password'] = $app->auth->get_random_password($min_password_length, true);
}
$remote->insert_query('../sites/form/shell_user.tform.php', $fields['client_id'], $ssh_params);
......
<?php
/*
Copyright (c) 2016, Kristián Feldsam, FELDSAM s.r.o. <info@feldsam.cz>
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of ISPConfig nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/******************************************
* Begin Form configuration
******************************************/
$list_def_file = "list/template.list.php";
$tform_def_file = "form/template.tform.php";
/******************************************
* End Form configuration
******************************************/
require_once '../../lib/config.inc.php';
require_once '../../lib/app.inc.php';
//* Check permissions for module
$app->auth->check_module_permissions('wizard');
$app->auth->check_module_permissions('sites');
$app->uses("tform_actions");
$app->tform_actions->onDelete();
?>
......@@ -14,6 +14,16 @@
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="domain">{tmpl_var name='username_txt'}</label>
<div class="col-sm-9">
<div class="input-group">
<span class="input-group-addon" id="username-desc">{tmpl_var name='username_prefix'}</span>
<input class="form-control" id="username" maxlength="255" name="username" size="30" type="text" value="{tmpl_var name='username'}">
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="template_id">{tmpl_var name='template_id_txt'}</label>
<div class="col-sm-9">
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment