| @@ -180,4 +180,6 @@ $wb['http_port_txt'] = 'HTTP Port'; | |||
| $wb['https_port_txt'] = 'HTTPS Port'; | |||
| $wb['http_port_error_regex'] = 'HTTP Port invalid.'; | |||
| $wb['https_port_error_regex'] = 'HTTPS Port invalid.'; | |||
| $wb['error_dominio_mas_puntos'] = 'El Dominio no es correcto, hay 3 puntos o más.'; | |||
| $wb['error_dominio_www'] = 'El Dominio no es correcto. No escriba "www" antes del dominio.'; | |||
| ?> | |||
| @@ -180,4 +180,6 @@ $wb['http_port_txt'] = 'HTTP Port'; | |||
| $wb['https_port_txt'] = 'HTTPS Port'; | |||
| $wb['http_port_error_regex'] = 'HTTP Port invalid.'; | |||
| $wb['https_port_error_regex'] = 'HTTPS Port invalid.'; | |||
| $wb['error_dominio_mas_puntos'] = 'El Dominio no es correcto, hay 3 puntos o más.'; | |||
| $wb['error_dominio_www'] = 'El Dominio no es correcto. No escriba "www" antes del dominio.'; | |||
| ?> | |||
| @@ -27,10 +27,11 @@ $app->auth->check_module_permissions('webdns'); | |||
| die; | |||
| }*/ | |||
| // Loading classes | |||
| $app->uses('tpl,tform,tform_actions,remoting,tools_sites,remoting_lib'); | |||
| // Loading classes, asi es como se carga la api, busco la clase que contiene los métodos que se necesiten y se añade aquí | |||
| $app->uses('tpl,tform,tform_actions,remoting,tools_sites,remoting_lib,remoting_dns'); | |||
| $app->load('tform_actions'); | |||
| class page_action extends tform_actions { | |||
| //Con esta funcion se parsean y preparan los campos del formulario, new_service_dns.tform.php | |||
| //justo después de la carga de este. | |||
| @@ -50,7 +51,7 @@ class page_action extends tform_actions { | |||
| //BASE DE DATOS - TEMPLATE | |||
| //Cargo todos los valores de la tabla dns_template que coincidan con id del template seleccionado. | |||
| ///$template_record = $app->db->queryOneRecord("SELECT * FROM dns_template WHERE template_id = ?", $fields['dns_template_id']); | |||
| //IMPORTANTE, aquí cargo el campo fields de la tabla dns_template | |||
| //IMPORTANTE, aquí cargo el campo fields de la tabla dns_template | |||
| //que contiene una lista de los campos que se muestran en el template(vista) | |||
| /*$fields = explode(',', $template_record['fields']); | |||
| if(is_array($fields)) { | |||
| @@ -64,12 +65,227 @@ class page_action extends tform_actions { | |||
| /*parent::onShowEnd(); | |||
| }*/ | |||
| public $dominio; | |||
| public $subdominio; | |||
| public $es_subdominio = false; | |||
| public $subdom_error = false; | |||
| //Expresiones regulares para comprobar si es subdominio | |||
| function comprobarSubDominios($subdom) { | |||
| global $app, $conf; | |||
| $patronSubDominos = "/(.*?)\.(.*)$/"; | |||
| $patronWWW = "/^w{3}/"; | |||
| //$patronPunto = '/(\.)/'; | |||
| $patronP1 = '/(^\.)/'; | |||
| $patronP2 = '/(\.$)/'; | |||
| $patronP3 = '/(\.\.+)/'; | |||
| $patronP4 = '/(\.[[:alpha:]]*)$/'; | |||
| //Se comprueba que no tenga 3 w "www" al principio del nombre del dominio o subdomino | |||
| $encontradoWWW = preg_match($patronWWW, $subdom, $coincidencias); | |||
| //print "Patron WWW " . $encontrado; | |||
| if($encontradoWWW){ | |||
| $app->tform->errorMessage = $app->tform->wordbook['error_dominio_www']; | |||
| return; | |||
| } | |||
| //Si el dominio tiene mas de dos puntos, es incorrecto | |||
| if (substr_count($subdom,".") > 2) { | |||
| $app->tform->errorMessage = $app->tform->wordbook['error_dominio_mas_puntos']; | |||
| return; | |||
| //print 'El Dominio ¡¡NO!! es correcto, hay 3 puntos o más.</p>\n'; | |||
| //$this->subdom_error = true; | |||
| } else if(substr_count($subdom,".") == 2){ | |||
| $this->encontrado = preg_match($patronSubDominos, $subdom, $coincidencias); | |||
| //print "<pre>"; print_r($coincidencias); print "</pre>\n"; | |||
| $this->subdominio = $coincidencias[1]; | |||
| $this->dominio = $coincidencias[2]; | |||
| //print "Subdomino: " . $this->subdomino . "</p>\n Dominio: " . $this->domino; | |||
| $this->es_subdominio = true; | |||
| } | |||
| //print "<pre>El dominio es: " . $this->dominio; | |||
| return $this->es_subdominio; | |||
| } | |||
| //Crear subdominio | |||
| function crearSubDominio($remoto){ | |||
| //para usar variables globales en las funciones hay que declararlas dentro de la funcion, ¿? | |||
| global $app, $conf; | |||
| //print "<pre>El dominio es: " . $this->dominio; | |||
| $camDominio = $app->db->queryOneRecord('SELECT domain_id, domain FROM domain WHERE domain = "'.$this->dominio.'"'); | |||
| $camDnsRR = $app->db->queryOneRecord('SELECT server_id, zone FROM dns_rr WHERE name LIKE "'.$this->dominio.'%"'); | |||
| $camServIP = $app->db->queryOneRecord('SELECT ip_address FROM server_ip WHERE server_id = "'.$camDnsRR['server_id'].'"'); | |||
| //Si el dominio NO existe mostramos mensaje de error y salimos de la ejecución | |||
| if(!$camDominio['domain']){ | |||
| echo '<div class="table-wrapper marginTop15"> | |||
| <table class="table"> | |||
| <tbody> | |||
| <tr> | |||
| <td bgcolor="#f7dfdf" colspan="2"><b>El dominio padre para este subdominio ¡NO EXISTE!</b></td> | |||
| </tr> | |||
| </tbody> | |||
| </table> | |||
| </div>'; | |||
| //print 'No existe el dominio'; | |||
| return; | |||
| } else { | |||
| //Parametros para la creación de subdominios | |||
| $paramSubDominios = array( | |||
| 'server_id' => $camDnsRR['server_id'], | |||
| 'zone' => $camDnsRR['zone'], | |||
| 'name' => $this->subdominio, | |||
| 'type' => 'a', | |||
| 'data' => $camServIP['ip_address'], | |||
| //'aux' => '0', | |||
| 'ttl' => '3600', | |||
| 'active' => 'y', | |||
| //comento el campo stamp, ya que introducia solo ceros en la bbdd | |||
| //'stamp' => time(), | |||
| 'serial' => '1', | |||
| ); | |||
| //print "<pre>"; print_r($paramSubDominios); print "</pre>\n"; | |||
| //$remote = new remote_actions; | |||
| //Inserto en bbdd usando la clase remoto que se la he pasado en parámetros de la función | |||
| $resultado = $remoto->insert_query('../dns/form/dns_a.tform.php', $fields['client_id'], $paramSubDominios); | |||
| echo '<div class="table-wrapper marginTop15"> | |||
| <table class="table"> | |||
| <tbody> | |||
| <tr> | |||
| <td bgcolor="#1ccb00" colspan="2"><b>Se ha dado de alta Web y Subdominio, '.$this->subdominio.', ¡Correctamente!</b></td> | |||
| </tr> | |||
| </tbody> | |||
| </table> | |||
| </div>'; | |||
| } | |||
| } | |||
| function crearSitioWebSubdominio($remoto){ | |||
| global $app, $conf; | |||
| $fields = $app->tform->encode($this->dataRecord, $app->tform->getCurrentTab(), true); | |||
| $dns_ip_servidor_ipv6 = $app->db->queryOneRecord("SELECT ip_type, ip_address FROM server_ip WHERE client_id = ".$fields['client_id']." AND ip_type='IPv6'"); | |||
| //Comprobamos que el resultado para el cliente seleccionado no esta vacÃo, | |||
| //si lo esta tomamos los datos del cliente id 0 | |||
| if(!$dns_ip_servidor_ipv6){ | |||
| $dns_ip_servidor = $app->db->queryOneRecord("SELECT ip_type, ip_address FROM server_ip WHERE client_id = 0 AND ip_type='IPv4'"); | |||
| $dns_ip_servidor_ipv6 = $app->db->queryOneRecord("SELECT ip_type, ip_address FROM server_ip WHERE client_id = 0 AND ip_type='IPv6'"); | |||
| /*echo '<br><br>Valor de la consulta '.$dns_ip_servidor_ipv6[ip_address].' '; | |||
| echo '<br><br>Valor de la consulta '.$dns_ip_servidor[ip_address].' ';*/ | |||
| } | |||
| $dns_servidor = $app->db->queryOneRecord("SELECT client_id, default_dnsserver, default_webserver FROM client WHERE client_id = ".$app->functions->intval($fields['client_id'])); | |||
| $clienteID = $dns_servidor['client_id']; | |||
| $res = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = ".$app->functions->intval($fields['client_id'])); | |||
| $client_group_id = $res['groupid']; | |||
| // add site | |||
| $paramsite = array( | |||
| 'type' => 'vhost', | |||
| 'domain' => $fields['domain'], //$this->subdominio, | |||
| 'server_id' => $dns_servidor['default_webserver'], | |||
| 'ip_address' => '*', //$dns_ip_servidor['ip_address'], | |||
| 'ipv6_address' => $dns_ip_servidor_ipv6['ip_address'], | |||
| 'traffic_quota' => '-1', | |||
| 'hd_quota' => '0', | |||
| 'cgi' => 'y', | |||
| 'ssi' => 'y', | |||
| 'suexec' => 'y', | |||
| 'ruby' => 'n', | |||
| 'python' => 'n', | |||
| 'perl' => 'n', | |||
| 'errordocs' => '1', | |||
| 'subdomain' => '', | |||
| 'php' => 'php-fpm', | |||
| 'fastcgi_php_version' => '', | |||
| 'seo_redirect' => '', | |||
| 'rewrite_to_https' => 'n', | |||
| 'allow_override' => 'All', | |||
| 'http_port' => 80, | |||
| 'https_port' => 443, | |||
| 'apache_directives' => '', | |||
| 'nginx_directives' => '', | |||
| 'php_fpm_use_socket' => 'y', | |||
| 'pm' => 'ondemand', | |||
| 'pm_max_children' => 10, | |||
| 'pm_start_servers' => 1, | |||
| 'pm_min_spare_servers' => 1, | |||
| 'pm_max_spare_servers' => 5, | |||
| 'pm_process_idle_timeout' => 10, | |||
| 'pm_max_requests' => 0, | |||
| 'custom_php_ini' => '', | |||
| 'active' => 'y', | |||
| 'document_root' => '-', | |||
| 'system_user' => '-', | |||
| 'system_group' => '-', | |||
| 'log_retention' => 30, | |||
| 'client_group_id' => $client_group_id, | |||
| ); | |||
| //$app->uses('remoting_lib'); | |||
| //$formulario = $app->remoting_lib->loadFormDef('../sites/form/web_vhost_domain.tform.php'); | |||
| //$formulario = $app->tform->loadFormDef('../sites/form/web_vhost_domain.tform.php'); | |||
| /*print 'Valores: ' . $dns_ip_servidor_ipv6; | |||
| print "<pre> Parametros:"; print_r($paramsite); print "</pre>\n"; | |||
| print '<pre> cliente id ' . $fields['client_id']; | |||
| print "<pre>";print_r($fields);print "</pre>\n" . $fields['client_id'];*/ | |||
| //print "<pre>Formulario ";print_r($formulario);print "</pre>\n"; | |||
| //print '<pre>DNS IPV6 ' . $dns_ip_servidor_ipv6['ip_address']; | |||
| //$tform_def_file2 = "../sites/form/web_vhost_domain.tform.php"; | |||
| //$app->tform->loadFormDef($tform_def_file2); | |||
| //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 = $remoto->insert_query('../sites/form/web_vhost_domain.tform.php', $fields['client_id'], $paramsite, 'sites:web_vhost_domain:on_after_insert'); | |||
| //print '<pre>ID sitio web del subdominio --> ' . $site_id; | |||
| } | |||
| function onSubmit() { | |||
| global $app, $conf; | |||
| //Carga de campos del formulario. | |||
| $fields = $app->tform->encode($this->dataRecord, $app->tform->getCurrentTab(), true); | |||
| //Creo la clase remote para usar las librerias | |||
| $remote = new remote_actions; | |||
| if($this->comprobarSubDominios($fields['domain'])){ | |||
| $this->crearSubDominio($remote); | |||
| $this->crearSitioWebSubdominio($remote); | |||
| return; | |||
| } //else if(!$this->subdom_error){ | |||
| // 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']; | |||
| @@ -87,10 +303,10 @@ class page_action extends tform_actions { | |||
| $app->tpl->setVar($this->dataRecord); | |||
| $this->onShow(); | |||
| return; | |||
| } | |||
| } | |||
| // Domain OK, continue | |||
| $remote = new remote_actions; | |||
| //$remote = new remote_actions; | |||
| // client prefix and group id | |||
| $res = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = ".$app->functions->intval($fields['client_id'])); | |||
| @@ -132,7 +348,7 @@ class page_action extends tform_actions { | |||
| $dns_ip_servidor_ipv6 = $app->db->queryOneRecord("SELECT ip_type, ip_address FROM server_ip WHERE client_id = ".$fields['client_id']." AND ip_type='IPv6'"); | |||
| //Comprobamos que el resultado para el cliente seleccionado no esta vacío, | |||
| //Comprobamos que el resultado para el cliente seleccionado no esta vacÃo, | |||
| //si lo esta tomamos los datos del cliente id 0 | |||
| if(!$dns_ip_servidor_ipv6){ | |||
| $dns_ip_servidor = $app->db->queryOneRecord("SELECT ip_type, ip_address FROM server_ip WHERE client_id = 0 AND ip_type='IPv4'"); | |||
| @@ -286,7 +502,7 @@ class page_action extends tform_actions { | |||
| $app->tform->loadFormDef($tform_def_file); | |||
| //$app->remoting_lib->loadFormDef($tform_def_file); | |||
| // add site | |||
| $paramsite = array( | |||
| 'type' => 'vhost', | |||
| @@ -330,6 +546,16 @@ class page_action extends tform_actions { | |||
| 'client_group_id' => $client_group_id, | |||
| ); | |||
| print 'Valores: ' . $dns_ip_servidor_ipv6 . " " . $formulario . " Parametros: " ; | |||
| print "<pre>"; print_r($paramsite); print "</pre>\n"; | |||
| print '<pre> cliente id ' . $fields['client_id']; | |||
| print "<pre>";print_r($fields);print "</pre>\n"; | |||
| //print "<pre>Formulario ";print_r($formulario);print "</pre>\n"; | |||
| 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'); | |||
| @@ -341,12 +567,23 @@ class page_action extends tform_actions { | |||
| //$remote->insert_query('../sites/form/web_vhost_domain.tform.php', $fields['client_id'], $paramsite); | |||
| //Si todo va bien, el resultado | |||
| echo '<br><br>Altas Web y DNS del dominio '.$fields['domain'].', ¡Creadas correctamente!<br>'; | |||
| echo '<div class="table-wrapper marginTop15"> | |||
| <table class="table"> | |||
| <tbody> | |||
| <tr> | |||
| <td bgcolor="#1ccb00" colspan="2"><b>Altas Web y DNS del dominio '.$fields['domain'].', ¡Creadas correctamente!</b></td> | |||
| </tr> | |||
| </tbody> | |||
| </table> | |||
| </div>'; | |||
| //} | |||
| //parent::onSubmit(); | |||
| //}//FIN IF | |||
| } | |||
| } | |||
| class remote_actions extends remoting { | |||
| @@ -0,0 +1,359 @@ | |||
| <?php | |||
| /* | |||
| 2017, David Ramos García, Open6Hosting <dramos@open6hosting.com> | |||
| All rights reserved. | |||
| */ | |||
| /****************************************** | |||
| * Begin Form configuration | |||
| ******************************************/ | |||
| //Solo se puede tener una variable para cargar los distintos formularios | |||
| $tform_def_file = "form/new_service_webdns.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('webdns'); | |||
| // Check the module permissions and redirect if not allowed. | |||
| /*if(!stristr($_SESSION['s']['user']['modules'],'customdns')) { | |||
| header('Location: ../index.php'); | |||
| die; | |||
| }*/ | |||
| // Loading classes | |||
| $app->uses('tpl,tform,tform_actions,remoting,tools_sites,remoting_lib'); | |||
| $app->load('tform_actions'); | |||
| class page_action extends tform_actions { | |||
| //Con esta funcion se parsean y preparan los campos del formulario, new_service_dns.tform.php | |||
| //justo después de la carga de este. | |||
| /*function onShowEnd() { | |||
| global $app, $conf;*/ | |||
| //FORMULARIO | |||
| //Con esta llamada a al clase $app cargo todos los campos definidos en el formulario, | |||
| //en este caso, los definidos en el array $form["tabs"]['webdns']; | |||
| //$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']; | |||
| }*/ | |||
| //BASE DE DATOS - TEMPLATE | |||
| //Cargo todos los valores de la tabla dns_template que coincidan con id del template seleccionado. | |||
| ///$template_record = $app->db->queryOneRecord("SELECT * FROM dns_template WHERE template_id = ?", $fields['dns_template_id']); | |||
| //IMPORTANTE, aquí cargo el campo fields de la tabla dns_template | |||
| //que contiene una lista de los campos que se muestran en el template(vista) | |||
| /*$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; | |||
| //Carga de campos del formulario. | |||
| $fields = $app->tform->encode($this->dataRecord, $app->tform->getCurrentTab(), true); | |||
| // 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']; | |||
| } | |||
| if($app->tform->errorMessage) | |||
| { | |||
| $this->onError(); | |||
| return; | |||
| } | |||
| //Esta variable nos llega por jQuery desde el htm para el control de errores en la vista. | |||
| if($_POST['create'] != 1) | |||
| { | |||
| $app->tform->errorMessage = 'DUMMY'; | |||
| $app->tpl->setVar($this->dataRecord); | |||
| $this->onShow(); | |||
| return; | |||
| } | |||
| // Domain OK, continue | |||
| $remote = new remote_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. 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'])); | |||
| //Carga del formulario dns_soa para guardar en base de datos | |||
| $tform_def_file = "../dns/form/dns_soa.tform.php"; | |||
| $app->tform->loadFormDef($tform_def_file); | |||
| // Carga y seleccion de dns_template, si no esta creado se informa de que tiene que crearse | |||
| $template_record = $app->db->queryOneRecord("SELECT * FROM dns_template WHERE visible = 'Y' AND name = 'webdns'"); /*'open6hosting'");*/ | |||
| /*if($template_record) { | |||
| //echo '<br><br>Teplate '.$template_record.', '; | |||
| $app->tform->errorMessage = 'Error hay que crear un template llamado webdns'; | |||
| $this->onError(); | |||
| return; | |||
| } else { | |||
| $app->tform->errorMessage = 'Error hay que crear un template llamado webdnsssssss'; | |||
| $this->onError(); | |||
| return; | |||
| }*/ | |||
| /*if($app->tform->errorMessage) | |||
| { | |||
| $this->onError(); | |||
| return; | |||
| }*/ | |||
| //$template_record = $app->db->queryOneRecord("SELECT * FROM dns_template WHERE visible = 'Y' AND name = 'webdns'"); /*'open6hosting'");*/ | |||
| //Llamada a la tabla server_ip para recuperar la ip4 e ip6 | |||
| $dns_ip_servidor = $app->db->queryOneRecord("SELECT ip_type, ip_address FROM server_ip WHERE client_id = ".$app->functions->intval($fields['client_id']. " AND ip_type='IPv4'")); | |||
| $dns_ip_servidor_ipv6 = $app->db->queryOneRecord("SELECT ip_type, ip_address FROM server_ip WHERE client_id = ".$fields['client_id']." AND ip_type='IPv6'"); | |||
| //Comprobamos que el resultado para el cliente seleccionado no esta vacÃo, | |||
| //si lo esta tomamos los datos del cliente id 0 | |||
| if(!$dns_ip_servidor_ipv6){ | |||
| $dns_ip_servidor = $app->db->queryOneRecord("SELECT ip_type, ip_address FROM server_ip WHERE client_id = 0 AND ip_type='IPv4'"); | |||
| $dns_ip_servidor_ipv6 = $app->db->queryOneRecord("SELECT ip_type, ip_address FROM server_ip WHERE client_id = 0 AND ip_type='IPv6'"); | |||
| /*echo '<br><br>Valor de la consulta '.$dns_ip_servidor_ipv6[ip_address].' '; | |||
| echo '<br><br>Valor de la consulta '.$dns_ip_servidor[ip_address].' ';*/ | |||
| } | |||
| $tpl_content = $template_record['template']; | |||
| // Reemplazo la variable que nos encontramos en base de datos por el valor que se ha introducido en el formulario | |||
| $tpl_content = str_replace('{DOMAIN}', $fields['domain'], $tpl_content); | |||
| //Carga de los datos en las variables ns | |||
| $tpl_content = str_replace('{IP}', $dns_ip_servidor['ip_address'], $tpl_content); | |||
| $tpl_content = str_replace('{IPV6}', $dns_ip_servidor_ipv6['ip_address'], $tpl_content); | |||
| /*$tpl_content = str_replace('{NS1}', '.open6servers.com', $tpl_content); | |||
| $tpl_content = str_replace('{NS2}', '.open6servers.com', $tpl_content); */ | |||
| $enable_dnssec = 'N';//(($_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').'<br />'; | |||
| if($vars['ns'] == '') $dns_error .= $app->lng('error_ns_empty').'<br />'; | |||
| if($vars['mbox'] == '') $dns_error .= $app->lng('error_mbox_empty').'<br />'; | |||
| if($vars['refresh'] == '') $dns_error .= $app->lng('error_refresh_empty').'<br />'; | |||
| if($vars['retry'] == '') $dns_error .= $app->lng('error_retry_empty').'<br />'; | |||
| if($vars['expire'] == '') $dns_error .= $app->lng('error_expire_empty').'<br />'; | |||
| if($vars['minimum'] == '') $dns_error .= $app->lng('error_minimum_empty').'<br />'; | |||
| if($vars['ttl'] == '') $dns_error .= $app->lng('error_ttl_empty').'<br />'; | |||
| // check for dns errors | |||
| if($dns_error) | |||
| { | |||
| $app->tform->errorMessage = $dns_error; | |||
| $this->onError(); | |||
| return; | |||
| }*/ | |||
| //Llamada a la tabla client para recuperar el client_id y su default_dnsserver | |||
| $dns_servidor = $app->db->queryOneRecord("SELECT client_id, default_dnsserver, default_webserver FROM client WHERE client_id = ".$app->functions->intval($fields['client_id'])); | |||
| $valor_recuperado1 = $dns_servidor['client_id']; | |||
| /*$valor_recuperado2 = $dns_servidor['default_dnsserver']; | |||
| $valor_recuperado3 = $dns_servidor['default_webserver']; | |||
| */ | |||
| // 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" => $dns_servidor['default_dnsserver'], | |||
| "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" => $dns_servidor['default_dnsserver'], | |||
| "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'); | |||
| } | |||
| } | |||
| //sites_web_domain_add | |||
| $tform_def_file = "../sites/form/web_vhost_domain.tform.php"; | |||
| $app->tform->loadFormDef($tform_def_file); | |||
| //$app->remoting_lib->loadFormDef($tform_def_file); | |||
| // add site | |||
| $paramsite = array( | |||
| 'type' => 'vhost', | |||
| 'domain' => $fields['domain'], | |||
| 'server_id' => $dns_servidor['default_webserver'], | |||
| 'ip_address' => '*', //$dns_ip_servidor['ip_address'], | |||
| 'ipv6_address' => $dns_ip_servidor_ipv6['ip_address'], | |||
| 'traffic_quota' => '-1', | |||
| 'hd_quota' => '0', | |||
| 'cgi' => 'y', | |||
| 'ssi' => 'y', | |||
| 'suexec' => 'y', | |||
| 'ruby' => 'n', | |||
| 'python' => 'n', | |||
| 'perl' => 'n', | |||
| 'errordocs' => '1', | |||
| 'subdomain' => 'www', | |||
| 'php' => 'php-fpm', | |||
| 'fastcgi_php_version' => '', | |||
| 'seo_redirect' => '', | |||
| 'rewrite_to_https' => 'n', | |||
| 'allow_override' => 'All', | |||
| 'http_port' => 80, | |||
| 'https_port' => 443, | |||
| 'apache_directives' => '', | |||
| 'nginx_directives' => '', | |||
| 'php_fpm_use_socket' => 'y', | |||
| 'pm' => 'ondemand', | |||
| 'pm_max_children' => 10, | |||
| 'pm_start_servers' => 1, | |||
| 'pm_min_spare_servers' => 1, | |||
| 'pm_max_spare_servers' => 5, | |||
| 'pm_process_idle_timeout' => 10, | |||
| 'pm_max_requests' => 0, | |||
| 'custom_php_ini' => '', | |||
| 'active' => 'y', | |||
| 'document_root' => '-', | |||
| 'system_user' => '-', | |||
| 'system_group' => '-', | |||
| 'log_retention' => 30, | |||
| 'client_group_id' => $client_group_id, | |||
| ); | |||
| //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'); | |||
| // 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); | |||
| //$remote->insert_query('../sites/form/web_vhost_domain.tform.php', $fields['client_id'], $paramsite); | |||
| //Si todo va bien, el resultado | |||
| echo '<br><br>Altas Web y DNS del dominio '.$fields['domain'].', ¡Creadas correctamente!<br>'; | |||
| //parent::onSubmit(); | |||
| } | |||
| } | |||
| 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); | |||
| } | |||
| } | |||
| $page = new page_action; | |||
| $page->onLoad(); | |||