diff --git a/new_service_webdns.php b/new_service_webdns.php
index e86dc08..ec96f25 100755
--- a/new_service_webdns.php
+++ b/new_service_webdns.php
@@ -16,12 +16,6 @@ $tform_def_file = "form/new_service_webdns.tform.php";
//Check permissions for module
$app->auth->check_module_permissions('webdns');
-//Check the module permissions and redirect if not allowed.
-/*if(!stristr($_SESSION['s']['user']['modules'],'customdns')) {
- header('Location: ../index.php');
- die;
-}*/
-
//Loading classes a usar.
$app->uses('tpl,tform,tform_actions,remoting,tools_sites,remoting_lib,remoting_dns');
$app->load('tform_actions');
@@ -32,7 +26,7 @@ class page_action extends tform_actions {
function onShowNew() {
global $app;
- // we will check only users, not admins
+ //Si es usuario no puede usar el módulo webdns
if($_SESSION['s']['user']['typ'] == 'user') {
$app->error($app->tform->wordbook["error_usuario_no_permitido_webdns"]);
}
@@ -42,21 +36,38 @@ class page_action extends tform_actions {
function onShowEnd() {
global $app, $conf, $interfaceConf;
- /*
- * If the names are restricted -> remove the restriction, so that the
- * data can be edited
- */
- //Get the database user prefix
+
+ $this->tratarVariablesPrefix();
$app->uses('getconf,tools_sites');
$global_config = $app->getconf->get_global_config('sites');
- $dbuser_prefix = $app->tools_sites->replacePrefix($global_config['dbuser_prefix'], $this->dataRecord);
$ftpuser_prefix = $app->tools_sites->replacePrefix($global_config['ftpuser_prefix'], $this->dataRecord);
- if ($_SESSION["s"]["user"]["typ"] != 'admin' && $app->auth->has_clients($_SESSION['s']['user']['userid'])) {
+ if ($this->dataRecord['username'] != ""){
+ /* REMOVE the restriction */
+ $app->tpl->setVar("username", $app->tools_sites->removePrefix($this->dataRecord['username'], $this->dataRecord['username_prefix'], $ftpuser_prefix));
+ }
+
+ if($this->dataRecord['username'] == "") {
+ $app->tpl->setVar("username_prefix", $ftpuser_prefix);
+ } else {
+ $app->tpl->setVar("username_prefix", $app->tools_sites->getPrefix($this->dataRecord['username_prefix'], $ftpuser_prefix, $global_config['ftpuser_prefix']));
+ }
+ //Get the database user prefix
+ $app->uses('getconf,tools_sites');
+ $global_config = $app->getconf->get_global_config('sites');
+
+ //* Client: If the logged in user is not admin and has no sub clients (no reseller)
+/* if ($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) {
// Get the limits of the client
$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
$client = $app->db->queryOneRecord("SELECT client.company_name, client.contact_name, client.client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id);
+ //* Reseller: If the logged in user is not admin and has sub clients (reseller)
+ }elseif ($_SESSION["s"]["user"]["typ"] != 'admin' && $app->auth->has_clients($_SESSION['s']['user']['userid'])) {
+ // Get the limits of the client
+ $client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
+ $client = $app->db->queryOneRecord("SELECT client.company_name, client.contact_name, client.client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id);
+
// Fill the client select field
$sql = "SELECT sys_group.groupid, sys_group.name, CONCAT(IF(client.company_name != '', CONCAT(client.company_name, ' :: '), ''), client.contact_name, ' (', client.username, IF(client.customer_no != '', CONCAT(', ', client.customer_no), ''), ')') as contactname FROM sys_group, client WHERE sys_group.client_id = client.client_id AND client.parent_client_id = ? ORDER BY client.company_name, client.contact_name, sys_group.name";
$records = $app->db->queryAllRecords($sql, $client['client_id']);
@@ -70,7 +81,9 @@ class page_action extends tform_actions {
}
}
$app->tpl->setVar("client_group_id", $client_select);
- } elseif($_SESSION["s"]["user"]["typ"] == 'admin') {
+
+ //* Es Admin
+ } else*/if($_SESSION["s"]["user"]["typ"] == 'admin') {
// Fill the client select field
$sql = "SELECT sys_group.groupid, sys_group.name, CONCAT(IF(client.company_name != '', CONCAT(client.company_name, ' :: '), ''), client.contact_name, ' (', client.username, IF(client.customer_no != '', CONCAT(', ', client.customer_no), ''), ')') as contactname FROM sys_group, client WHERE sys_group.client_id = client.client_id AND sys_group.client_id > 0 ORDER BY client.company_name, client.contact_name, sys_group.name";
$clients = $app->db->queryAllRecords($sql);
@@ -95,6 +108,9 @@ class page_action extends tform_actions {
$app->tpl->setVar("database_user_prefix", $dbuser_prefix);
} else {
$app->tpl->setVar("database_user_prefix", $app->tools_sites->getPrefix($this->dataRecord['database_user_prefix'], $dbuser_prefix, $global_config['dbuser_prefix']));
+ $app->tools_sites->getPrefix($this->dataRecord['database_user_prefix'], $dbuser_prefix, $global_config['dbuser_prefix']);
+ $datos_prefix = $app->tools_sites->getPrefix($this->dataRecord['database_user_prefix'], $dbuser_prefix, $global_config['dbuser_prefix']);
+ $fields['database_user_prefix'] = $datos_prefix;
}
if ($this->dataRecord['username'] != ""){
@@ -107,6 +123,7 @@ class page_action extends tform_actions {
} else {
$app->tpl->setVar("username_prefix", $app->tools_sites->getPrefix($this->dataRecord['username_prefix'], $ftpuser_prefix, $global_config['ftpuser_prefix']));
}
+
parent::onShowEnd();
}
@@ -125,7 +142,6 @@ class page_action extends tform_actions {
$this->dataRecord['username_prefix'] = $ftpuser_prefix;
$this->dataRecord['database_user_prefix'] = $dbuser_prefix;
- $valor2 = $this->dataRecord['database_user_prefix'] = $dbuser_prefix;
$this->valor_prefix = $this->dataRecord['database_user_prefix'] = $dbuser_prefix;
$this->valor_prefix_ftp = $this->dataRecord['username_prefix'] = $ftpuser_prefix;
@@ -147,6 +163,21 @@ class page_action extends tform_actions {
}
$this->dataRecord['server_id'] = 0; // we need this on all servers
+
+ if ($this->dataRecord['database_user'] != ""){
+ /* REMOVE the restriction */
+ $app->tpl->setVar("database_user", $app->tools_sites->removePrefix($this->dataRecord['database_user'], $this->dataRecord['database_user_prefix'], $dbuser_prefix));
+ }
+
+ if($this->dataRecord['database_user'] == "") {
+ $app->tpl->setVar("database_user_prefix", $dbuser_prefix);
+ } else {
+ $app->tpl->setVar("database_user_prefix", $app->tools_sites->getPrefix($this->dataRecord['database_user_prefix'], $dbuser_prefix, $global_config['dbuser_prefix']));
+ }
+ //* Reseller: If the logged in user is not admin and has sub clients (is a reseller)
+/* if($_SESSION["s"]["user"]["typ"] != 'admin' && $app->auth->has_clients($_SESSION['s']['user']['userid'])) {
+ $this->valor_prefix = $dbuser_prefix;
+ }*/
}
@@ -169,38 +200,9 @@ class page_action extends tform_actions {
function generaNombreFTP(){
- global $app, $conf, $interfaceConf;
-
- //Get the database name and database user prefix
- $app->uses('getconf,tools_sites');
- $global_config = $app->getconf->get_global_config('sites');
- $dbuser_prefix = $app->tools_sites->replacePrefix($global_config['dbuser_prefix'], $this->dataRecord);
-
- $dbuser_prefix_valor = $app->tpl->setVar("database_name", $app->tools_sites->removePrefix($this->dataRecord['database_name'], $this->dataRecord['database_name_prefix'], $dbname_prefix));
- //echo ('El prefix ' . $dbuser_prefix);
- $this->dataRecord['database_user_prefix'] = $dbuser_prefix_valor;
- //echo ('PreFIX ' . '{user}' . str_replace('{user}', htmlentities($dbuser_prefix . $this->dataRecord['database_user'], ENT_QUOTES, 'UTF-8')));
- if(strlen($dbuser_prefix . $this->dataRecord['database_user']) > 16)
- $app->tform->errorMessage .= str_replace('{user}', htmlentities($dbuser_prefix . $this->dataRecord['database_user'], ENT_QUOTES, 'UTF-8'),
- $app->tform->wordbook["database_user_error_len"]).'
';
-
- //Check database user against blacklist
- $dbuser_blacklist = array($conf['db_user'], 'mysql', 'root');
- if(is_array($dbuser_blacklist) && in_array($dbuser_prefix . $this->dataRecord['database_user'], $dbuser_blacklist)) {
- $app->tform->errorMessage .= $app->lng('Database user not allowed.').'
';
- }
-
- /* restrict the names */
- /* crop user names if they are too long -> mysql: user: 16 chars / db: 64 chars */
- if ($app->tform->errorMessage == ''){
- $this->dataRecord['database_user'] = substr($dbuser_prefix . $this->dataRecord['database_user'], 0, 16);
- }
-
- $this->dataRecord['server_id'] = 0; // we need this on all servers
$this->tratarVariablesPrefix();
- //echo ('PreFIX Valor ' . $dbuser_prefix_valor);
//Cadena de caractares para construir el nombre.
$cadena = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ23456789";
@@ -256,38 +258,9 @@ class page_action extends tform_actions {
function generaNombreBD(){
- global $app, $conf, $interfaceConf;
-
- //Get the database name and database user prefix
- $app->uses('getconf,tools_sites');
- $global_config = $app->getconf->get_global_config('sites');
- $dbuser_prefix = $app->tools_sites->replacePrefix($global_config['dbuser_prefix'], $this->dataRecord);
-
- $dbuser_prefix_valor = $app->tpl->setVar("database_name", $app->tools_sites->removePrefix($this->dataRecord['database_name'], $this->dataRecord['database_name_prefix'], $dbname_prefix));
- //echo ('El prefix ' . $dbuser_prefix);
- $this->dataRecord['database_user_prefix'] = $dbuser_prefix_valor;
- //echo ('PreFIX ' . '{user}' . str_replace('{user}', htmlentities($dbuser_prefix . $this->dataRecord['database_user'], ENT_QUOTES, 'UTF-8')));
- if(strlen($dbuser_prefix . $this->dataRecord['database_user']) > 16)
- $app->tform->errorMessage .= str_replace('{user}', htmlentities($dbuser_prefix . $this->dataRecord['database_user'], ENT_QUOTES, 'UTF-8'),
- $app->tform->wordbook["database_user_error_len"]).'
';
-
- //Check database user against blacklist
- $dbuser_blacklist = array($conf['db_user'], 'mysql', 'root');
- if(is_array($dbuser_blacklist) && in_array($dbuser_prefix . $this->dataRecord['database_user'], $dbuser_blacklist)) {
- $app->tform->errorMessage .= $app->lng('Database user not allowed.').'
';
- }
-
- /* restrict the names */
- /* crop user names if they are too long -> mysql: user: 16 chars / db: 64 chars */
- if ($app->tform->errorMessage == ''){
- $this->dataRecord['database_user'] = substr($dbuser_prefix . $this->dataRecord['database_user'], 0, 16);
- }
-
- $this->dataRecord['server_id'] = 0; // we need this on all servers
$this->tratarVariablesPrefix();
- //echo ('PreFIX Valor ' . $dbuser_prefix_valor);
//Cadena de caractares para construir las nombre.
$cadena = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ23456789";
//$cadSpeciales = "!@#_";
@@ -313,36 +286,6 @@ class page_action extends tform_actions {
return $this->valor_prefix . $nombre;
}
-
- /*function comprobarPass($claveGenerada){
- //compruebo que el tamaño del string sea válido.
- if (strlen($claveGenerada)<3 || strlen($claveGenerada)>20){
- echo $claveGenerada . " no es válida0
";
- return false;
- }
-
- //compruebo que los caracteres sean los permitidos
- $alphachars = "abcdefghijkmnopqrstuvwxyz";
- $upperchars = "ABCDEFGHJKLMNPQRSTUVWXYZ";
- $numchars = "23456789";
- $specialchars = "!@#_";
-
- //$permitidos = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
-
-
- if (ereg("^[a-zA-Z0-9\-_]{3,20}$", $claveGenerada)) {
- echo $claveGenerada . " es válido
";
- return true;
- } else {
- echo $claveGenerada . " NO válido
";
- return false;
- }
-
- echo $claveGenerada . " es válido
";
- return true;
- }*/
-
-
function crearBaseDatosFtp($remoto){
global $app, $conf;
@@ -352,24 +295,16 @@ class page_action extends tform_actions {
$server_config_array = $app->getconf->get_global_config();
$generated_usernameBBDD = $this->generaNombreBD();
- //print "
"; print_r($generated_usernameBBDD); 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.'."'); - //print "
"; print_r($fields['client_id']); print "\n"; - $clavePass = $this->generaPass(); - //*Recupero todos los prefix necesarios - $app->uses('getconf,tools_sites'); - $global_config = $app->getconf->get_global_config('sites'); - $ftpuser_prefix = $app->tools_sites->replacePrefix($global_config['ftpuser_prefix'], $this->dataRecord); //añado database user con su prefix $db_user_params = array( 'server_id' => $this->bbdd_serv, - 'sysgroup_id' => $this->sys_grupo_id, + 'sysgroup_id' => $this->cli_grupo_id, //$this->sys_grupo_id, 'sys_userid' => $this->sys_usuario_id, 'sys_perm_other' => '-', 'database_user' => $generated_usernameBBDD, @@ -386,12 +321,21 @@ class page_action extends tform_actions { //print "
"; print_r($fields); print "\n"; - $db_user_id = $remoto->insert_query('../sites/form/database_user.tform.php', $this->cli_id, $db_user_params, 'sites:web_database_user:on_after_insert'); - + //IMPORTANTE. PARA QUE EL PLUGING FUNCIONE HAY QUE CARGAR ANTES EL FORMULARIO + //DE LO QUE SE QUIERE CREAR EN ESTE CASO BBDD. NO FUNCIONA SE LANZA EL AFTER INSERT EN NUESTRA FUNCION. + $tform_def_file = "../sites/form/database_user.tform.php"; + $app->tform->loadFormDef($tform_def_file); + + $db_user_id = $remoto->insert_query('../sites/form/database_user.tform.php', + $this->cli_id, $db_user_params, 'sites:web_database_user:on_after_insert'); + + $global_web_config = $app->getconf->get_server_config($this->web_serv, 'server'); + $ip4_bbdd = $global_web_config; + // add database $paramsBD = array( 'server_id' => $this->bbdd_serv, //$camDnsRR['server_id'], - 'sysgroup_id' => $this->sys_grupo_id, //$fields['client_group_id'], + 'sysgroup_id' => $this->cli_grupo_id, //$this->sys_grupo_id, 'parent_domain_id' => $sitio_id['domain_id'], 'type' => 'mysql', 'database_quota' => '-1', @@ -399,27 +343,28 @@ class page_action extends tform_actions { 'database_name_prefix' => $this->valor_prefix, 'database_user_id' => $db_user_id, 'database_charset' => 'utf8', - 'remote_access' => 'n', - 'remote_ips' => '-1', + 'remote_access' => 'y', + 'remote_ips' => $ip4_bbdd['ip_address'], //'-1', 'active' => 'y' ); - //print "
BBDD "; print_r($paramsBD); print "\n"; $this->nombre_db_txt = $paramsBD['database_name']; - - $db_id = $remoto->sites_database_add($this->cli_id,/*$fields['client_group_id'],*/ $paramsBD); + + $db_id = $remoto->sites_database_add($this->cli_id, /*$this->cli_grupo_id,*/ $paramsBD); $this->urlBBDD($db_id, $this->bbdd_serv); + //echo('Id de la BBDD ' . $db_id); // 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->uses('remoting_lib'); $app->remoting_lib->loadFormDef('../sites/form/web_vhost_domain.tform.php'); + $site_data = $app->remoting_lib->getDataRecord($sitio_id); - + $this->nombre_user_ftp = $this->generaNombreFTP(); // add ftp user $ftp_params = array( - 'server_id' => $this->web_serv, //$camDnsRR['server_id'], + 'server_id' => $this->web_serv, 'parent_domain_id' => $sitio_id['domain_id'], 'username' => $this->valor_prefix_ftp . $this->nombre_user_ftp, 'username_prefix' => $this->valor_prefix_ftp, @@ -440,8 +385,11 @@ class page_action extends tform_actions { $this->pass_ftp_txt = $ftp_params['password']; //print "
FTP "; print_r($ftp_params); print "\n"; //print "
"; print_r($site_data); print "\n"; - //echo('El usuario es ' . $fields['client_group_id']); - $remoto->insert_query('../sites/form/ftp_user.tform.php', $fields['client_group_id'], $ftp_params); + //echo('El grupo del usuario es ' . $this->cli_grupo_id); + $tform_def_file = "../sites/form/ftp_user.tform.php"; + $app->tform->loadFormDef($tform_def_file); + + $remoto->insert_query('../sites/form/ftp_user.tform.php', $this->cli_id,/*$fields['client_group_id'],*/ $ftp_params); echo '