diff --git a/form/ftp_bd_service.tform.php b/form/ftp_bd_service.tform.php
index dfd7060..8561df8 100755
--- a/form/ftp_bd_service.tform.php
+++ b/form/ftp_bd_service.tform.php
@@ -63,14 +63,15 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-$form["title"] = "Baicon, queso y Ftp con BBDD";
+$form["title"] = "Crear BBDD y FTP";
$form["description"] = "";
$form["name"] = "ftp_bd_service";
$form["action"] = "ftp_bd_service.php";
$form["db_table"] = "server";
$form["db_table_idx"] = "server_id";
-$form["db_history"] = "no";
-$form["tab_default"] = "client";
+$form["db_history"] = "yes";
+$form["tab_default"] = "database_user";
+//$form["list_default"] = "database_user_list.php";
$form["auth"] = 'yes'; // yes / no
$form["auth_preset"]["userid"] = 0; // 0 = id of the user, > 0 id must match with id of current user
@@ -79,35 +80,11 @@ $form["auth_preset"]["perm_user"] = 'riud'; //r = read, i = insert, u = update,
$form["auth_preset"]["perm_group"] = 'riud'; //r = read, i = insert, u = update, d = delete
$form["auth_preset"]["perm_other"] = ''; //r = read, i = insert, u = update, d = delete
-$form["tabs"]['client'] = array(
- 'title' => "Ftp vs BBDD",
- 'description' => 'Create domain, mail domain, site, database and ftp/ssh',
+$form["tabs"]['database_user'] = array (
+ 'title' => "Altas",
'width' => 100,
'template' => "templates/ftp_bd_service.htm",
'fields' => array (
- 'domain' => 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'=> 'domain_error_empty'),
- 2 => array ( 'type' => 'REGEX',
- 'regex' => '/^[\w\.\-]{2,255}\.[a-zA-Z0-9\-]{2,30}$/',
- 'errmsg'=> 'domain_error_regex'),
- ),
- 'default' => '',
- 'value' => '',
- 'width' => '30',
- 'maxlength' => '255'
- ),
'client_id' => array (
'datatype' => 'INTEGER',
'formtype' => 'SELECT',
@@ -119,112 +96,42 @@ $form["tabs"]['client'] = array(
),
'value' => ''
),
- 'template_id' => array(
+ 'parent_domain_id' => array (
'datatype' => 'INTEGER',
'formtype' => 'SELECT',
'default' => '',
'datasource' => array ( 'type' => 'SQL',
- 'querystring' => 'SELECT template_id, template_name FROM wizard_template WHERE {AUTHSQL} ORDER BY template_name',
- 'keyfield'=> 'template_id',
- 'valuefield'=> 'template_name'
+ 'querystring' => "SELECT web_domain.domain_id, CONCAT(web_domain.domain, ' :: ', server.server_name) AS parent_domain FROM web_domain, server WHERE web_domain.type = 'vhost' AND web_domain.server_id = server.server_id AND {AUTHSQL::web_domain} ORDER BY web_domain.domain",
+ 'keyfield'=> 'domain_id',
+ 'valuefield'=> 'parent_domain'
),
- 'value' => '',
- ),
- 'db' => array (
- 'datatype' => 'VARCHAR',
- 'formtype' => 'CHECKBOX',
- 'default' => 'y',
- 'value' => array(0 => 'n', 1 => 'y')
- ),
- 'db_type' => array (
- 'datatype' => 'VARCHAR',
- 'formtype' => 'SELECT',
- 'default' => 'mysql',
- 'value' => array(
- //'mongo' => 'MongoDB',
- 'mysql' => 'MySQL'
- )
- ),
- 'ftp' => array (
- 'datatype' => 'VARCHAR',
- 'formtype' => 'CHECKBOX',
- 'default' => 'y',
- 'value' => array(0 => 'n', 1 => 'y')
- ),
- 'ssh' => array (
- 'datatype' => 'VARCHAR',
- 'formtype' => 'CHECKBOX',
- 'default' => 'y',
- 'value' => array(0 => 'n', 1 => 'y')
+ 'value' => ''
),
- 'mail' => array (
+ 'username' => array (
'datatype' => 'VARCHAR',
- 'formtype' => 'CHECKBOX',
- 'default' => 'y',
- 'value' => array(0 => 'n', 1 => 'y')
- ),
- 'mailboxes' => array (
- 'datatype' => 'TEXT',
- 'formtype' => 'TEXTAREA',
+ 'formtype' => 'TEXT',
+ 'validators' => array ( 0 => array ( 'type' => 'UNIQUE',
+ 'errmsg'=> 'username_error_unique'),
+ 1 => array ( 'type' => 'REGEX',
+ 'regex' => '/^[\w\.\-@\+]{0,64}$/',
+ 'errmsg'=> 'username_error_regex'),
+ ),
'default' => '',
'value' => '',
'width' => '30',
+ 'maxlength' => '255',
+ 'searchable' => 1
),
- 'dkim' => array (
- 'datatype' => 'VARCHAR',
- 'formtype' => 'CHECKBOX',
- 'default' => 'n',
- 'value' => array(0 => 'n', 1 => 'y')
- ),
- 'dkim_private' => array (
- 'datatype' => 'TEXT',
- 'formtype' => 'TEXTAREA',
- 'default' => '',
- 'value' => '',
- 'cols' => '30',
- 'rows' => '10',
- 'validators' => array ( 0 => array ('type' => 'CUSTOM',
- 'class' => 'validate_dkim',
- 'function' => 'check_private_key',
- 'errmsg'=> 'dkim_private_key_error'),
- ),
- ),
- 'dkim_public' => array (
- 'datatype' => 'TEXT',
- 'formtype' => 'TEXTAREA',
- 'default' => '',
- 'value' => '',
- 'cols' => '30',
- 'rows' => '10'
- ),
- 'dkim_selector' => array (
- 'datatype' => 'VARCHAR',
- 'formtype' => 'TEXT',
- 'default' => 'default',
- 'value' => 'default',
- 'width' => '20',
- 'maxlength' => '63',
- 'validators' => array ( 0 => array ( 'type' => 'REGEX',
- 'regex' => '/^[a-z0-9]{0,63}$/',
- 'errmsg'=> 'dkim_selector_error'),
- ),
- ),
- 'dns' => array (
+ 'username_prefix' => array (
'datatype' => 'VARCHAR',
- 'formtype' => 'CHECKBOX',
- 'default' => 'y',
- 'value' => array(0 => 'n', 1 => 'y')
- ),
- 'dns_template_id' => array(
- 'datatype' => 'INTEGER',
- 'formtype' => 'SELECT',
+ 'formtype' => 'TEXT',
'default' => '',
- 'datasource' => array ( 'type' => 'SQL',
- 'querystring' => "SELECT template_id, name FROM dns_template WHERE visible = 'Y' ORDER BY name ASC",
- 'keyfield'=> 'template_id',
- 'valuefield'=> 'name'
- ),
- 'value' => '',
+ 'value' => '',
+ 'width' => '30',
+ 'maxlength' => '25'
),
)
-);
\ No newline at end of file
+);
+
+
+?>
diff --git a/ftp_bd_service.php b/ftp_bd_service.php
index 31f1c23..8e44c9e 100755
--- a/ftp_bd_service.php
+++ b/ftp_bd_service.php
@@ -45,35 +45,11 @@ require_once '../../lib/app.inc.php';
$app->auth->check_module_permissions('webdns');
// Loading classes
-$app->uses('tpl,tform,remoting');
+$app->uses('tpl,tform,remoting,tform_actions,tools_sites,remoting_lib');
$app->load('tform_actions');
class page_action extends tform_actions {
- function onShowEnd() {
- global $app, $conf;
-
- $fields = $app->tform->encode($this->dataRecord, $app->tform->getCurrentTab(), true);
-
- // select first template as default
- if($fields['dns_template_id'] == 0)
- {
- $first_template = $app->db->queryOneRecord("SELECT template_id FROM dns_template WHERE visible = 'Y' ORDER BY name ASC");
- $fields['dns_template_id'] = $first_template['template_id'];
- }
-
- $template_record = $app->db->queryOneRecord("SELECT * FROM dns_template WHERE template_id = ?", $fields['dns_template_id']);
- $fields = explode(',', $template_record['fields']);
- if(is_array($fields)) {
- foreach($fields as $field) {
- $app->tpl->setVar($field."_VISIBLE", 1);
- $field = strtolower($field);
- $app->tpl->setVar($field, $_POST['dns_'.$field]);
- }
- }
-
- parent::onShowEnd();
- }
function onSubmit() {
global $app, $conf;
@@ -113,319 +89,7 @@ class page_action extends tform_actions {
// add domain
$domain_id = $remote->insert_query('../client/form/domain.tform.php', $fields['client_id'], array('domain' => $fields['domain']));
- // DNS Zone
- if($fields['dns'])
- {
- if(isset($_POST['dns_ns1']) && $_POST['dns_ns1'] != ''){
- $_POST['dns_ns1'] = $app->functions->idn_encode($_POST['dns_ns1']);
- $_POST['dns_ns1'] = strtolower($_POST['dns_ns1']);
- }
- if(isset($_POST['dns_ns2']) && $_POST['dns_ns2'] != ''){
- $_POST['dns_ns2'] = $app->functions->idn_encode($_POST['dns_ns2']);
- $_POST['dns_ns2'] = strtolower($_POST['dns_ns2']);
- }
- if(isset($_POST['dns_email']) && $_POST['dns_email'] != ''){
- $_POST['dns_email'] = $app->functions->idn_encode($_POST['dns_email']);
- $_POST['dns_email'] = strtolower($_POST['dns_email']);
- }
-
- $dns_error = '';
-
- if(isset($_POST['dns_ip']) && $_POST['dns_ip'] == '') $dns_error .= $app->lng('error_ip_empty').'
';
-
- if(isset($_POST['dns_ipv6']) && $_POST['dns_ipv6'] == '') $dns_error .= $app->lng('error_ipv6_empty').'
';
-
- if(isset($_POST['dns_ns1']) && $_POST['dns_ns1'] == '') $dns_error .= $app->lng('error_ns1_empty').'
';
- elseif(isset($_POST['ns1']) && !preg_match('/^[\w\.\-]{2,64}\.[a-zA-Z0-9]{2,30}$/', $_POST['ns1'])) $dns_error .= $app->lng('error_ns1_regex').'
';
-
- if(isset($_POST['dns_ns2']) && $_POST['dns_ns2'] == '') $dns_error .= $app->lng('error_ns2_empty').'
';
- elseif(isset($_POST['ns2']) && !preg_match('/^[\w\.\-]{2,64}\.[a-zA-Z0-9]{2,30}$/', $_POST['ns2'])) $dns_error .= $app->lng('error_ns2_regex').'
';
-
- if(isset($_POST['dns_email']) && $_POST['dns_email'] == '') $dns_error .= $app->lng('error_email_empty').'
';
- elseif(isset($_POST['dns_email']) && filter_var($_POST['dns_email'], FILTER_VALIDATE_EMAIL) === false) $dns_error .= $app->lng('error_email_regex').'
';
-
- // check for dns errors
- if($dns_error)
- {
- $app->tform->errorMessage = $dns_error;
- $this->onError();
- return;
- }
-
- $tform_def_file = "../dns/form/dns_soa.tform.php";
- $app->tform->loadFormDef($tform_def_file);
-
- // replace template placeholders
- $template_record = $app->db->queryOneRecord("SELECT * FROM dns_template WHERE template_id = ?", $fields['dns_template_id']);
- $tpl_content = $template_record['template'];
- $tpl_content = str_replace('{DOMAIN}', $fields['domain'], $tpl_content);
- if($_POST['dns_ip'] != '') $tpl_content = str_replace('{IP}', $_POST['dns_ip'], $tpl_content);
- if($_POST['dns_ipv6'] != '') $tpl_content = str_replace('{IPV6}',$_POST['dns_ipv6'],$tpl_content);
- if($_POST['dns_ns1'] != '') $tpl_content = str_replace('{NS1}', $_POST['dns_ns1'], $tpl_content);
- if($_POST['dns_ns2'] != '') $tpl_content = str_replace('{NS2}', $_POST['dns_ns2'], $tpl_content);
- if($_POST['dns_email'] != '') $tpl_content = str_replace('{EMAIL}', $_POST['dns_email'], $tpl_content);
-
- $enable_dnssec = (($_POST['dns_dnssec'] == 'Y') ? 'Y' : 'N');
-
- // Parse the template
- $tpl_rows = explode("\n", $tpl_content);
- $section = '';
- $vars = array();
- $vars['xfer']='';
- $dns_rr = array();
- foreach($tpl_rows as $row) {
- $row = trim($row);
- if(substr($row, 0, 1) == '[') {
- if($row == '[ZONE]') {
- $section = 'zone';
- } elseif($row == '[DNS_RECORDS]') {
- $section = 'dns_records';
- } else {
- die('Unknown section type');
- }
- } else {
- if($row != '') {
- // Handle zone section
- if($section == 'zone') {
- $parts = explode('=', $row);
- $key = trim($parts[0]);
- $val = trim($parts[1]);
- if($key != '') $vars[$key] = $val;
- }
- // Handle DNS Record rows
- if($section == 'dns_records') {
- $parts = explode('|', $row);
- $dns_rr[] = array(
- 'name' => $parts[1],
- 'type' => $parts[0],
- 'data' => $parts[2],
- 'aux' => $parts[3],
- 'ttl' => $parts[4]
- );
- }
- }
- }
-
- } // end foreach
-
- $dns_error = '';
-
- if($vars['origin'] == '') $dns_error .= $app->lng('error_origin_empty').'
';
- if($vars['ns'] == '') $dns_error .= $app->lng('error_ns_empty').'
';
- if($vars['mbox'] == '') $dns_error .= $app->lng('error_mbox_empty').'
';
- if($vars['refresh'] == '') $dns_error .= $app->lng('error_refresh_empty').'
';
- if($vars['retry'] == '') $dns_error .= $app->lng('error_retry_empty').'
';
- if($vars['expire'] == '') $dns_error .= $app->lng('error_expire_empty').'
';
- if($vars['minimum'] == '') $dns_error .= $app->lng('error_minimum_empty').'
';
- if($vars['ttl'] == '') $dns_error .= $app->lng('error_ttl_empty').'
';
-
- // check for dns errors
- if($dns_error)
- {
- $app->tform->errorMessage = $dns_error;
- $this->onError();
- return;
- }
-
- // Insert the soa record
- $sys_userid = $_SESSION['s']['user']['userid'];
- $origin = $vars['origin'];
- $ns = $vars['ns'];
- $mbox = str_replace('@', '.', $vars['mbox']);
- $refresh = $vars['refresh'];
- $retry = $vars['retry'];
- $expire = $vars['expire'];
- $minimum = $vars['minimum'];
- $ttl = $vars['ttl'];
- $xfer = $vars['xfer'];
- $also_notify = $vars['also_notify'];
- $update_acl = $vars['update_acl'];
- $serial = $app->validate_dns->increase_serial(0);
-
- $insert_data = array(
- "sys_userid" => $sys_userid,
- "sys_groupid" => $client_group_id,
- "sys_perm_user" => 'riud',
- "sys_perm_group" => 'riud',
- "sys_perm_other" => '',
- "server_id" => $template['dns_server_id'],
- "origin" => $origin,
- "ns" => $ns,
- "mbox" => $mbox,
- "serial" => $serial,
- "refresh" => $refresh,
- "retry" => $retry,
- "expire" => $expire,
- "minimum" => $minimum,
- "ttl" => $ttl,
- "active" => 'Y',
- "xfer" => $xfer,
- "also_notify" => $also_notify,
- "update_acl" => $update_acl,
- "dnssec_wanted" => $enable_dnssec
- );
- $dns_soa_id = $app->db->datalogInsert('dns_soa', $insert_data, 'id');
-
- // Insert the dns_rr records
- if(is_array($dns_rr) && $dns_soa_id > 0) {
- foreach($dns_rr as $rr) {
- $insert_data = array(
- "sys_userid" => $sys_userid,
- "sys_groupid" => $client_group_id,
- "sys_perm_user" => 'riud',
- "sys_perm_group" => 'riud',
- "sys_perm_other" => '',
- "server_id" => $template['dns_server_id'],
- "zone" => $dns_soa_id,
- "name" => $rr['name'],
- "type" => $rr['type'],
- "data" => $rr['data'],
- "aux" => $rr['aux'],
- "ttl" => $rr['ttl'],
- "active" => 'Y'
- );
- $dns_rr_id = $app->db->datalogInsert('dns_rr', $insert_data, 'id');
- }
-
- if($fields['dkim'])
- {
- $insert_data = array(
- "sys_userid" => $sys_userid,
- "sys_groupid" => $client_group_id,
- "sys_perm_user" => 'riud',
- "sys_perm_group" => 'riud',
- "sys_perm_other" => '',
- "server_id" => $template['dns_server_id'],
- "zone" => $dns_soa_id,
- "name" => $fields['dkim_selector'].'._domainkey.'.$fields['domain'].'.',
- "type" => 'TXT',
- "data" => 'v=DKIM1; t=s; p='.str_replace(array('-----BEGIN PUBLIC KEY-----','-----END PUBLIC KEY-----',"\r","\n"), '', $_POST['dkim_public']),
- "aux" => 0,
- "ttl" => 86400,
- "active" => 'Y'
- );
- $dns_rr_id = $app->db->datalogInsert('dns_rr', $insert_data, 'id');
- }
- }
-
- $tform_def_file = "form/ftp_bd_service.tform.php";
- $app->tform->loadFormDef($tform_def_file);
- }
-
- if($fields['mail'])
- {
- // add mail domain
- $params = array(
- 'server_id' => $template['mail_server_id'],
- 'domain' => $fields['domain'],
- 'dkim' => $fields['dkim'],
- 'dkim_private' => $_POST['dkim_private'],
- 'dkim_public' => $_POST['dkim_public'],
- 'dkim_selector' => $fields['dkim_selector'],
- 'active' => 'y'
- );
-
- $mail_domain_id = $remote->insert_query('../mail/form/mail_domain.tform.php', $fields['client_id'], $params);
-
- if($template['policy'])
- {
- $params = array(
- 'server_id' => $template['mail_server_id'],
- 'policy_id' => $template['policy'],
- 'priority' => 5,
- 'email' => '@'.$fields['domain'],
- 'fullname' => '@'.$fields['domain'],
- 'local' => 'Y',
- );
-
- $remote->insert_query('../mail/form/spamfilter_users.tform.php', $fields['client_id'], $params);
- }
-
- if($fields['mailboxes'])
- {
- $mailboxes = explode(',', $fields['mailboxes']);
- $mailbox_passwords = array();
-
- foreach($mailboxes as $alias)
- {
- $alias = strtolower($app->functions->idn_encode($alias));
- $mailbox = $alias.'@'.$fields['domain'];
-
- // validate, on error skip
- if( ! preg_match('/^[_a-z0-9][\w\.\-_\+@]{1,63}$/', $mailbox)) continue;
-
- $mailbox_passwords[$mailbox] = substr(sha1(rand()), 0, 10);
-
- $params = array(
- 'server_id' => $template['mail_server_id'],
- 'uid' => -1,
- 'gid' => -1,
- 'email' => $mailbox,
- 'login' => $mailbox,
- 'password' => $mailbox_passwords[$mailbox],
- 'quota' => $template['mailbox_quota']*1024*1024,
- 'postfix' => 'y',
- 'disableimap' => ($template['enableimap'] == 'y' ? 'n' : 'y'),
- 'disablepop3' => ($template['enablepop3'] == 'y' ? 'n' : 'y'),
- 'disablesmtp' => ($template['enablesmtp'] == 'y' ? 'n' : 'y'),
- 'maildir' => '/var/vmail/'.$fields['domain'].'/'.$alias,
- 'homedir' => '/var/vmail',
- );
-
- $remote->insert_query('../mail/form/mail_user.tform.php', $fields['client_id'], $params);
- }
- }
- }
-
- // add site
- $params = array(
- 'type' => 'vhost',
- 'domain' => $fields['domain'],
- 'server_id' => $template['web_server_id'],
- 'ip_address' => $template['ip_address'],
- 'ipv6_address' => $template['ipv6_address'],
- 'traffic_quota' => $template['traffic_quota'],
- 'hd_quota' => $template['hd_quota'],
- 'cgi' => $template['cgi'],
- 'ssi' => $template['ssi'],
- 'suexec' => $template['suexec'],
- 'ruby' => $template['ruby'],
- 'python' => $template['python'],
- 'perl' => $template['perl'],
- 'errordocs' => $template['errordocs'],
- 'subdomain' => $template['subdomain'],
- 'php' => $template['php'],
- 'fastcgi_php_version' => $template['fastcgi_php_version'],
- 'seo_redirect' => $template['seo_redirect'],
- 'rewrite_to_https' => $template['rewrite_to_https'],
- 'allow_override' => $template['allow_override'],
- 'http_port' => $template['http_port'],
- 'https_port' => $template['https_port'],
- 'apache_directives' => $template['apache_directives'],
- 'nginx_directives' => $template['nginx_directives'],
- 'php_fpm_use_socket' => $template['php_fpm_use_socket'],
- 'pm' => $template['pm'],
- 'pm_max_children' => $template['pm_max_children'],
- 'pm_start_servers' => $template['pm_start_servers'],
- 'pm_min_spare_servers' => $template['pm_min_spare_servers'],
- 'pm_max_spare_servers' => $template['pm_max_spare_servers'],
- 'pm_process_idle_timeout' => $template['pm_process_idle_timeout'],
- 'pm_max_requests' => $template['pm_max_requests'],
- 'custom_php_ini' => $template['custom_php_ini'],
- 'active' => 'y',
- 'document_root' => '-',
- 'system_user' => '-',
- 'system_group' => '-',
- 'client_group_id' => $client_group_id,
- );
-
- $site_id = $remote->insert_query('../sites/form/web_vhost_domain.tform.php', $fields['client_id'], $params, 'sites:web_vhost_domain:on_after_insert');
-
- // get site data
- $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);
@@ -477,31 +141,6 @@ class page_action extends tform_actions {
$remote->insert_query('../sites/form/ftp_user.tform.php', $fields['client_id'], $ftp_params);
}
- if($fields['ssh']) {
- // add ssh user
- $ssh_params = array(
- 'server_id' => $template['web_server_id'],
- 'parent_domain_id' => $site_id,
- 'quota_size' => $template['hd_quota'],
- 'dir' => $site_data['document_root'],
- 'puser' => $site_data['system_user'],
- 'pgroup' => $site_data['system_group'],
- 'sys_groupid' => $site_data['sys_groupid'],
- 'chroot' => $template['shell_chroot'],
- 'shell' => $template['shell'],
- 'active' => 'y',
- 'username' => $generated_username,
- );
-
- // username, password
- if(isset($ftp_params)) {
- $ssh_params['password'] = $ftp_params['password'];
- } else {
- $ssh_params['password'] = substr(sha1(rand()), 0, 10);
- }
-
- $remote->insert_query('../sites/form/shell_user.tform.php', $fields['client_id'], $ssh_params);
- }
// results
echo '
@@ -511,9 +150,9 @@ class page_action extends tform_actions {
| '.$ftp_params['password'].' | '; } - if(isset($ssh_params)) { - echo' -|
| SSH user | -SSH password | -
|---|---|
| '.$ssh_params['username'].' | -'.$ssh_params['password'].' | -
| Mailbox | -Password | -
| '.$mail.' | -'.$pass.' | -
"; print_r($generated_username); print "\n"; + $sitio_id = $app->db->queryOneRecord('SELECT domain_id, domain FROM web_domain WHERE domain = "'.$fields['domain'].'"'); + //print "
"; print_r($camDnsRR); print "\n"; + $camDnsRR = $app->db->queryOneRecord('SELECT server_id, zone FROM dns_rr WHERE name LIKE "'.$this->dominio.'%"'); + + // add database user + $db_user_params = array( + 'server_id' => $camDnsRR['server_id'], + 'database_user' => $generated_username, + 'database_password' => substr(sha1(rand()), 0, 10) + ); + + //print "
"; print_r($db_user_params); print "\n"; + //print "
"; print_r($fields); print "\n"; + $db_user_id = $remoto->insert_query('../sites/form/database_user.tform.php', $fields['client_id'], $db_user_params, 'sites:web_database_user:on_after_insert'); + + // add database + $paramsBD = array( + 'server_id' => $camDnsRR['server_id'], + 'parent_domain_id' => $sitio_id['domain_id'], + 'type' => 'y', + 'database_quota' => '-1', + 'database_name' => $db_user_params['database_user'], + 'database_user_id' => $db_user_id, + 'database_charset' => 'utf8', + 'remote_access' => 'n', + 'remote_ips' => '-1', + 'active' => 'y' + ); + //print "
"; print_r($paramsBD); print "\n"; + //print "
"; print_r($fields); print "\n"; + $remoto->sites_database_add($fields['client_id'], $paramsBD); + + // get site data para usarlo en la creación de la cuenta ftp, otra forma de cargar una tupla dandole un id + //$app->uses('remoting_lib'); + $app->remoting_lib->loadFormDef('../sites/form/web_vhost_domain.tform.php'); + $site_data = $app->remoting_lib->getDataRecord($sitio_id); + + // add ftp user + $ftp_params = array( + 'server_id' => $camDnsRR['server_id'],//$template['web_server_id'], + 'parent_domain_id' => $sitio_id['domain_id'],//$site_id, + 'username' => $generated_username, + 'password' => substr(sha1(rand()), 0, 10), + 'quota_size' => '-1',//$template['hd_quota'], + 'dir' => $site_data['0']['document_root'], + 'uid' => $site_data['0']['system_user'], + 'gid' => $site_data['0']['system_group'], + 'sys_groupid' => $site_data['0']['sys_groupid'], + 'quota_files' => '-1',//$template['quota_files'], + 'ul_ratio' => '-1',//$template['ul_ratio'], + 'dl_ratio' => '-1',//$template['dl_ratio'], + 'ul_bandwidth' => '-1',//$template['ul_bandwidth'], + 'dl_bandwidth' => '-1',//$template['dl_bandwidth'], + 'active' => 'y', + ); + //print "
"; print_r($ftp_params); print "\n"; + //print "
"; print_r($site_data); print "\n"; + $remoto->insert_query('../sites/form/ftp_user.tform.php', $fields['client_id'], $ftp_params); + } + //Expresiones regulares para comprobar si es subdominio function comprobarSubDominios($subdom) { global $app, $conf; @@ -81,10 +148,10 @@ class page_action extends tform_actions { $patronSubDominos = "/(.*?)\.(.*)$/"; $patronWWW = "/^w{3}/"; //$patronPunto = '/(\.)/'; - $patronP1 = '/(^\.)/'; + /*$patronP1 = '/(^\.)/'; $patronP2 = '/(\.$)/'; $patronP3 = '/(\.\.+)/'; - $patronP4 = '/(\.[[:alpha:]]*)$/'; + $patronP4 = '/(\.[[:alpha:]]*)$/';*/ //Se comprueba que no tenga 3 w "www" al principio del nombre del dominio o subdomino $encontradoWWW = preg_match($patronWWW, $subdom, $coincidencias); @@ -98,7 +165,6 @@ class page_action extends tform_actions { $app->tform->errorMessage = $app->tform->wordbook['error_dominio_mas_puntos']; return; - //$this->subdom_error = true; } else if(substr_count($subdom,".") == 2){ $this->encontrado = preg_match($patronSubDominos, $subdom, $coincidencias); @@ -313,9 +379,10 @@ class page_action extends tform_actions { if(!$this->subdom_error){ $this->crearSitioWebSubdominio($remote); } + $this->crearBaseDatosFtp($remote); return; } //else if(!$this->subdom_error){ - + //$this->crearBaseDatosFtp($remote); // check for domain unique name if($app->db->queryOneRecord('SELECT domain_id FROM domain WHERE domain = "'.$fields['domain'].'"')) { $app->tform->errorMessage = $app->tform->wordbook['domain_error_unique']; @@ -345,7 +412,7 @@ class page_action extends tform_actions { // add domain. Llamada que inserta el dominio en la tabla domain $domain_id = $remote->insert_query('../client/form/domain.tform.php', $fields['client_id'], array('domain' => $fields['domain'])); - + //$this->crearBaseDatosFtp($remote); //Carga del formulario dns_soa para guardar en base de datos $tform_def_file = "../dns/form/dns_soa.tform.php"; @@ -583,17 +650,22 @@ class page_action extends tform_actions { print "
";print_r($fields);print "\n";*/ //print "
Formulario ";print_r($formulario);print "\n"; - + //$this->crearBaseDatosFtp($remote); //print 'DNS IPV6 ' . $dns_ip_servidor_ipv6['ip_address']; //El último parámetro es para lanzar un evento que llama a la función on_after_insert que prepara los campos document_root, system_user y system_group $site_id = $remote->insert_query('../sites/form/web_vhost_domain.tform.php', $fields['client_id'], $paramsite, 'sites:web_vhost_domain:on_after_insert'); - + print 'Sitio id '. $site_id; + //$this->crearBaseDatosFtp($remote); // get site data $app->uses('remoting_lib'); $app->remoting_lib->loadFormDef('../sites/form/web_vhost_domain.tform.php'); $site_data = $app->remoting_lib->getDataRecord($site_id); - + + //IMPORTANTE, es necesario cargar nuestro formulario para poder ejecutar la función que crea + //la base de datos y el ftp ya que hay datos que tomamos de el antes de ejecutarla. + $app->tform->loadFormDef('form/new_service_webdns.tform.php'); + $this->crearBaseDatosFtp($remote); //$remote->insert_query('../sites/form/web_vhost_domain.tform.php', $fields['client_id'], $paramsite); //Si todo va bien, el resultado @@ -616,15 +688,43 @@ class page_action extends tform_actions { //parent::onSubmit(); //}//FIN IF + //$this->crearBaseDatosFtp($remote); } - } class remote_actions extends remoting { public function insert_query($formdef_file, $client_id, $params, $event_identifier = '') { return $this->insertQuery($formdef_file, $client_id, $params, $event_identifier); } + + public function sites_database_add($client_id, $params){ + global $app; + + $sql = $this->insertQueryPrepare('../sites/form/database.tform.php', $client_id, $params); + if($sql !== false) { + $app->uses('sites_database_plugin'); + + $this->id = 0; + $this->dataRecord = $params; + $app->sites_database_plugin->processDatabaseInsert($this); + + $retval = $this->insertQueryExecute($sql, $params); + + // set correct values for backup_interval and backup_copies + if(isset($params['backup_interval']) || isset($params['backup_copies'])){ + $sql_set = array(); + if(isset($params['backup_interval'])) $sql_set[] = "backup_interval = '".$app->db->quote($params['backup_interval'])."'"; + if(isset($params['backup_copies'])) $sql_set[] = "backup_copies = ".$app->functions->intval($params['backup_copies']); + //$app->db->query("UPDATE web_database SET ".implode(', ', $sql_set)." WHERE database_id = ".$retval); + $this->updateQueryExecute("UPDATE web_database SET ".implode(', ', $sql_set)." WHERE database_id = ".$retval, $retval, $params); + } + + return $retval; + } + + return false; + } } $page = new page_action; diff --git a/templates/ftp_bd_service.htm b/templates/ftp_bd_service.htm index 83fc5b4..e7f9636 100644 --- a/templates/ftp_bd_service.htm +++ b/templates/ftp_bd_service.htm @@ -1,10 +1,21 @@ +