| @@ -19,12 +19,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'); | |||
| @@ -36,15 +30,12 @@ class page_action extends tform_actions { | |||
| function onShowNew() { | |||
| global $app; | |||
| //if($_SESSION['s']['user']['typ'] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) unset($this->dataRecord["client_group_id"]); | |||
| //unset($_SESSION['s_old']); | |||
| //echo('Data record '. $this->dataRecord["username_prefix"] . print_r($this->dataRecord)); | |||
| //$sesion = $_SESSION; | |||
| /*$sesionDe = $_SESSION['s']['user']['typ']; | |||
| /*$sesion = $_SESSION; | |||
| $sesionDe = $_SESSION['s']['user']['typ']; | |||
| $grupo = $_SESSION["s"]["user"]["default_group"]; | |||
| print_r('La session de ' . $sesionDe); | |||
| print(', su grupo es ' . $grupo);*/ | |||
| //print_r($sesion); | |||
| print(', su grupo es ' . $grupo); | |||
| print_r($sesion);*/ | |||
| //------LIMITES-------------------------------------------------------------------------------------------------- | |||
| $this->estaLogeado = $_SESSION['s']['user']['typ']; | |||
| // we will check only users, not admins | |||
| @@ -52,7 +43,6 @@ class page_action extends tform_actions { | |||
| $client_group_id = $_SESSION["s"]["user"]["default_group"]; | |||
| $limitado = new limites($client_group_id); | |||
| $limitado->limitesLoad(); | |||
| } | |||
| //------LIMITES-------------------------------------------------------------------------------------------------- | |||
| parent::onShowNew(); | |||
| @@ -80,36 +70,19 @@ class page_action extends tform_actions { | |||
| //Get the database user prefix | |||
| $app->uses('getconf,tools_sites'); | |||
| $global_config = $app->getconf->get_global_config('sites'); | |||
| //$this->valor_prefix = $dbuser_prefix = $app->tools_sites->replacePrefix($global_config['dbuser_prefix'], $this->dataRecord); | |||
| //$this->valor_prefix_ftp = $ftpuser_prefix = $app->tools_sites->replacePrefix($global_config['ftpuser_prefix'], $this->dataRecord); | |||
| //echo('PRe antes ' . $ftpuser_prefix . ' DataRecord ' . print_r($this->dataRecord)); | |||
| //echo('PRe antes2 ' . print_r($global_config)); | |||
| //* 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); | |||
| //echo('PRe antes2 ' . print_r($global_config)); | |||
| // 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']); | |||
| $tmp = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = ?", $client['client_id']); | |||
| $client_select = '<option value="'.$tmp['groupid'].'">'.$client['contact_name'].'</option>'; | |||
| //$tmp_data_record = $app->tform->getDataRecord($this->id); | |||
| if(is_array($records)) { | |||
| foreach( $records as $rec) { | |||
| $selected = @(is_array($this->dataRecord) && ($rec["groupid"] == $this->dataRecord['client_group_id'] || $rec["groupid"] == $this->dataRecord['sys_groupid']))?'SELECTED':''; | |||
| $client_select .= "<option value='$rec[groupid]' $selected>$rec[contactname]</option>\r\n"; | |||
| } | |||
| } | |||
| $app->tpl->setVar("client_group_id", $client_select);*/ | |||
| //* 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); | |||
| //echo('PRe antes2 ' . print_r($global_config)); | |||
| // 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']); | |||
| @@ -123,6 +96,8 @@ class page_action extends tform_actions { | |||
| } | |||
| } | |||
| $app->tpl->setVar("client_group_id", $client_select); | |||
| //* Es Admin | |||
| } elseif($_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"; | |||
| @@ -138,22 +113,18 @@ class page_action extends tform_actions { | |||
| } | |||
| $app->tpl->setVar("client_group_id", $client_select); | |||
| } | |||
| // echo('Prefix Global ' . $this->valor_prefix); | |||
| if ($this->dataRecord['database_user'] != ""){ | |||
| /* REMOVE the restriction */ | |||
| //echo(' (1)Remove las restrinciones'); | |||
| $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); | |||
| //echo(' (2)user DB vacío '); | |||
| } else { | |||
| //echo(' (3)user DB con algo ' . $this->dataRecord['database_user_prefix']); | |||
| $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']); | |||
| //echo(' Datos prefix ' . $datos_prefix); | |||
| $fields['database_user_prefix'] = $datos_prefix; | |||
| } | |||
| @@ -186,13 +157,10 @@ 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; | |||
| //echo('(1)Prefix ' . $this->valor_prefix . '(2)Prefix ftp ' . $this->valor_prefix_ftp ); | |||
| 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"]).'<br />'; | |||
| @@ -211,7 +179,6 @@ class page_action extends tform_actions { | |||
| $this->dataRecord['server_id'] = 0; // we need this on all servers | |||
| //echo('Usuarios ' .$this->dataRecord['database_user'] . ' Prefix ' . $this->dataRecord['database_user_prefix'] . ' Mas ' . $dbuser_prefix); | |||
| 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)); | |||
| @@ -251,7 +218,6 @@ class page_action extends tform_actions { | |||
| $this->tratarVariablesPrefix(); | |||
| //echo ('PreFIX Valor ' . $dbuser_prefix_valor); | |||
| //Cadena de caractares para construir el nombre. | |||
| $cadena = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ23456789"; | |||
| @@ -310,7 +276,6 @@ class page_action extends tform_actions { | |||
| $this->tratarVariablesPrefix(); | |||
| //echo ('PreFIX Valor ' . $dbuser_prefix_valor); | |||
| //Cadena de caractares para construir las nombre. | |||
| $cadena = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ23456789"; | |||
| //$cadSpeciales = "!@#_"; | |||
| @@ -374,20 +339,12 @@ class page_action extends tform_actions { | |||
| $server_config_array = $app->getconf->get_global_config(); | |||
| $generated_usernameBBDD = $this->generaNombreBD(); | |||
| //print "<pre>"; print_r($generated_usernameBBDD); print "</pre>\n"; | |||
| $sitio_id = $app->db->queryOneRecord( | |||
| 'SELECT domain_id, domain FROM web_domain WHERE domain = "'.$fields['domain'].'"'); | |||
| //print_r($fields); | |||
| //echo(' Campo en formulario ' . $fields['database_user_prefix']); | |||
| //print "<pre>"; print_r($camDnsRR); print "</pre>\n"; | |||
| // echo(' El nuevo prefix ' . $this->valor_prefix_ftp); | |||
| $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);*/ | |||
| //echo('Cliente ' . $this->cli_id . ' cli grupo ' . $this->cli_grupo_id . ' sys user ' . $this->sys_usuario_id . ' sys grupo ' . $this->sys_grupo_id); | |||
| //añado database user con su prefix | |||
| $db_user_params = array( | |||
| 'server_id' => $this->bbdd_serv, | |||
| @@ -409,21 +366,19 @@ class page_action extends tform_actions { | |||
| //print "<pre>"; print_r($fields); print "</pre>\n"; | |||
| //IMPORTANTE. PARA QUE EL PLUGING FUNCIONE HAY QUE CARGAR ANTES EL FORMULARIO | |||
| //DE LO QUE SE QUIERE CREAR EN ESTE CASO SITIO WEB | |||
| //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'); | |||
| //echo('El id ' . $this->id); | |||
| //$remoto2 = new remote_actions; | |||
| $remoto->sites_database_user_after_add($this->cli_grupo_id, $db_user_params); | |||
| //echo(' El cliente en webdns ' . $this->cli_id); | |||
| // add database | |||
| $paramsBD = array( | |||
| 'server_id' => $this->bbdd_serv, //$camDnsRR['server_id'], | |||
| 'sysgroup_id' => $this->cli_grupo_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', | |||
| @@ -435,20 +390,22 @@ class page_action extends tform_actions { | |||
| 'remote_ips' => '-1', | |||
| 'active' => 'y' | |||
| ); | |||
| //print "<pre> BBDD "; print_r($paramsBD); print "</pre>\n"; | |||
| $this->nombre_db_txt = $paramsBD['database_name']; | |||
| //IMPORTANTE. COMPROBAR EL VALOR QUE HAY QUE ENVIAR, SI ES CLI GRUPO Ó CLI ID | |||
| $db_id = $remoto->sites_database_add($this->cli_id, /*$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->remoting_lib->loadFormDef('../sites/form/web_vhost_domain.tform.php'); | |||
| // $site_data = $app->remoting_lib->getDataRecord($sitio_id); | |||
| // $site_data = $remoto->getDataRecordWebDNS($sitio_id); | |||
| //$app->remoting_lib->loadFormDef('../sites/form/web_vhost_domain.tform.php'); | |||
| //IMPORTANTE. AL NO PODER USAR LA FUNCION getDataRecord YA QUE NOS HACE ADMIN. | |||
| //TENGO QUE LANZAR LA FUNCION sites_ftp_user_after_insert PARA SOLUCIONAR ESTE PROBLEMA. | |||
| //$site_data = $app->remoting_lib->getDataRecord($sitio_id); | |||
| //$site_data = $remoto->getDataRecordWebDNS($sitio_id); | |||
| $this->nombre_user_ftp = $this->generaNombreFTP(); | |||
| // add ftp user | |||
| $ftp_params = array( | |||
| @@ -481,10 +438,12 @@ class page_action extends tform_actions { | |||
| $app->uses('sites_ftp_user_plugin'); | |||
| global $app; | |||
| //Register for the events | |||
| //Register for the events. NO FUNCIONA. | |||
| $app->plugin->registerEvent('sites:ftp_user:on_after_insert'); | |||
| //Lo lanzo yo. | |||
| $remoto->sites_ftp_user_after_insert(); | |||
| echo '<br><div class="alert alert-success"><br> | |||
| Altas de BBDD y FTP, ¡Correctas!<br><br> | |||
| Usuario BBDD: <b>'. $this->usuario_db_txt .'</b><br>Contraseña: <b>' . $this->pass_db_txt . ' | |||
| @@ -536,9 +495,6 @@ class page_action extends tform_actions { | |||
| $web_config = $app->getconf->get_server_config($servidor_id, 'web'); | |||
| //print "<pre>"; print_r($global_config); print "</pre>\n"; | |||
| //print "<pre>"; print_r($web_config); print "</pre>\n"; | |||
| /* | |||
| * We only redirect to the login-form, so there is no need, to check any rights | |||
| */ | |||
| if($global_config['phpmyadmin_url'] != '') { | |||
| $phpmyadmin_url = $global_config['phpmyadmin_url']; | |||
| @@ -546,16 +502,7 @@ class page_action extends tform_actions { | |||
| //header('Location: '.$phpmyadmin_url); | |||
| $this->url_db = $phpmyadmin_url; | |||
| //print('la url ' . $phpmyadmin_url); | |||
| } /*else { | |||
| isset($_SERVER['HTTPS'])? $http = 'https' : $http = 'http'; | |||
| if($web_config['server_type'] == 'nginx') { | |||
| //header('Location: http://' . $serverData['server_name'] . ':8081/phpmyadmin'); | |||
| print('la url http://' . $serverData['server_name'] . ':8081/phpmyadmin'); | |||
| } else { | |||
| //header('Location: ' . $http . '://' . $serverData['server_name'] . '/phpmyadmin'); | |||
| print('la url http://' . $serverData['server_name'] . ':8081/phpmyadmin'); | |||
| } | |||
| }*/ | |||
| } | |||
| } | |||
| //Expresiones regulares para comprobar si es subdominio | |||