ISPConfig module for simplify the creation of websites and DNS zones in a only step
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

1875 строки
77 KiB

  1. <?php
  2. /*
  3. PHP por David Ramos García, Open6Hosting <dramos@open6hosting.com>
  4. SQL y expresiones regulares por Pablo Sarria Pérez, Open6Hosting <pablo@sarriaperez.com>
  5. 2017, All rights reserved.
  6. */
  7. require_once '../../lib/config.inc.php';
  8. require_once '../../lib/app.inc.php';
  9. //INICIO---CLASE PARA LOS LIMITES--------------------------------------------------------------------------------------------
  10. require_once 'clases/limites.inc.php';
  11. //FIN------CLASE PARA LOS LIMITES--------------------------------------------------------------------------------------------
  12. //require 'pdf_o6h.php';
  13. //Variable para cargar los distintos formularios.
  14. $tform_def_file = "form/new_service_webdns.tform.php";
  15. //Check permissions for module
  16. $app->auth->check_module_permissions('webdns');
  17. //Loading classes a usar.
  18. $app->uses('tpl,tform,tform_actions,remoting,tools_sites,remoting_lib,remoting_dns');
  19. $app->load('tform_actions');
  20. class page_action extends tform_actions {
  21. public $estaLogeado;
  22. function onShowNew() {
  23. global $app;
  24. /*$sesion = $_SESSION;
  25. $sesionDe = $_SESSION['s']['user']['typ'];
  26. $grupo = $_SESSION["s"]["user"]["default_group"];
  27. print_r('La session de ' . $sesionDe);
  28. print(', su grupo es ' . $grupo);
  29. print_r($sesion);*/
  30. //------LIMITES--------------------------------------------------------------------------------------------------
  31. $this->estaLogeado = $_SESSION['s']['user']['typ'];
  32. // we will check only users, not admins
  33. if($this->estaLogeado == 'user') {
  34. $client_group_id = $_SESSION["s"]["user"]["default_group"];
  35. $limitado = new limites($client_group_id);
  36. $limitado->limitesLoad();
  37. }
  38. //------LIMITES--------------------------------------------------------------------------------------------------
  39. parent::onShowNew();
  40. }
  41. function onShowEnd() {
  42. global $app, $conf, $interfaceConf;
  43. $this->tratarVariablesPrefix();
  44. $app->uses('getconf,tools_sites');
  45. $global_config = $app->getconf->get_global_config('sites');
  46. $ftpuser_prefix = $app->tools_sites->replacePrefix($global_config['ftpuser_prefix'], $this->dataRecord);
  47. if ($this->dataRecord['username'] != ""){
  48. /* REMOVE the restriction */
  49. $app->tpl->setVar("username", $app->tools_sites->removePrefix($this->dataRecord['username'], $this->dataRecord['username_prefix'], $ftpuser_prefix));
  50. }
  51. if($this->dataRecord['username'] == "") {
  52. $app->tpl->setVar("username_prefix", $ftpuser_prefix);
  53. } else {
  54. $app->tpl->setVar("username_prefix", $app->tools_sites->getPrefix($this->dataRecord['username_prefix'], $ftpuser_prefix, $global_config['ftpuser_prefix']));
  55. }
  56. //Get the database user prefix
  57. $app->uses('getconf,tools_sites');
  58. $global_config = $app->getconf->get_global_config('sites');
  59. //* Client: If the logged in user is not admin and has no sub clients (no reseller)
  60. if ($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) {
  61. // Get the limits of the client
  62. $client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
  63. $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);
  64. //* Reseller: If the logged in user is not admin and has sub clients (reseller)
  65. }elseif ($_SESSION["s"]["user"]["typ"] != 'admin' && $app->auth->has_clients($_SESSION['s']['user']['userid'])) {
  66. // Get the limits of the client
  67. $client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
  68. $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);
  69. // Fill the client select field
  70. $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";
  71. $records = $app->db->queryAllRecords($sql, $client['client_id']);
  72. $tmp = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = ?", $client['client_id']);
  73. $client_select = '<option value="'.$tmp['groupid'].'">'.$client['contact_name'].'</option>';
  74. //$tmp_data_record = $app->tform->getDataRecord($this->id);
  75. if(is_array($records)) {
  76. foreach( $records as $rec) {
  77. $selected = @(is_array($this->dataRecord) && ($rec["groupid"] == $this->dataRecord['client_group_id'] || $rec["groupid"] == $this->dataRecord['sys_groupid']))?'SELECTED':'';
  78. $client_select .= "<option value='$rec[groupid]' $selected>$rec[contactname]</option>\r\n";
  79. }
  80. }
  81. $app->tpl->setVar("client_group_id", $client_select);
  82. //* Es Admin
  83. } elseif($_SESSION["s"]["user"]["typ"] == 'admin') {
  84. // Fill the client select field
  85. $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";
  86. $clients = $app->db->queryAllRecords($sql);
  87. $client_select = "<option value='0'></option>";
  88. //$tmp_data_record = $app->tform->getDataRecord($this->id);
  89. if(is_array($clients)) {
  90. foreach( $clients as $client) {
  91. //$selected = @($client["groupid"] == $tmp_data_record["sys_groupid"])?'SELECTED':'';
  92. $selected = @(is_array($this->dataRecord) && ($client["groupid"] == $this->dataRecord['client_group_id'] || $client["groupid"] == $this->dataRecord['sys_groupid']))?'SELECTED':'';
  93. $client_select .= "<option value='$client[groupid]' $selected>$client[contactname]</option>\r\n";
  94. }
  95. }
  96. $app->tpl->setVar("client_group_id", $client_select);
  97. }
  98. if ($this->dataRecord['database_user'] != ""){
  99. /* REMOVE the restriction */
  100. $app->tpl->setVar("database_user", $app->tools_sites->removePrefix($this->dataRecord['database_user'], $this->dataRecord['database_user_prefix'], $dbuser_prefix));
  101. }
  102. if($this->dataRecord['database_user'] == "") {
  103. $app->tpl->setVar("database_user_prefix", $dbuser_prefix);
  104. } else {
  105. $app->tpl->setVar("database_user_prefix", $app->tools_sites->getPrefix($this->dataRecord['database_user_prefix'], $dbuser_prefix, $global_config['dbuser_prefix']));
  106. $app->tools_sites->getPrefix($this->dataRecord['database_user_prefix'], $dbuser_prefix, $global_config['dbuser_prefix']);
  107. $datos_prefix = $app->tools_sites->getPrefix($this->dataRecord['database_user_prefix'], $dbuser_prefix, $global_config['dbuser_prefix']);
  108. $fields['database_user_prefix'] = $datos_prefix;
  109. }
  110. if ($this->dataRecord['username'] != ""){
  111. /* REMOVE the restriction */
  112. $app->tpl->setVar("username", $app->tools_sites->removePrefix($this->dataRecord['username'], $this->dataRecord['username_prefix'], $ftpuser_prefix));
  113. }
  114. if($this->dataRecord['username'] == "") {
  115. $app->tpl->setVar("username_prefix", $ftpuser_prefix);
  116. } else {
  117. $app->tpl->setVar("username_prefix", $app->tools_sites->getPrefix($this->dataRecord['username_prefix'], $ftpuser_prefix, $global_config['ftpuser_prefix']));
  118. }
  119. parent::onShowEnd();
  120. }
  121. public $valor_prefix;
  122. public $valor_prefix_ftp;
  123. function tratarVariablesPrefix() {
  124. global $app, $conf, $interfaceConf;
  125. //Get the database name and database user prefix
  126. $app->uses('getconf,tools_sites');
  127. $global_config = $app->getconf->get_global_config('sites');
  128. $dbuser_prefix = $app->tools_sites->replacePrefix($global_config['dbuser_prefix'], $this->dataRecord);
  129. $ftpuser_prefix = $app->tools_sites->replacePrefix($global_config['ftpuser_prefix'], $this->dataRecord);
  130. $this->dataRecord['username_prefix'] = $ftpuser_prefix;
  131. $this->dataRecord['database_user_prefix'] = $dbuser_prefix;
  132. $this->valor_prefix = $this->dataRecord['database_user_prefix'] = $dbuser_prefix;
  133. $this->valor_prefix_ftp = $this->dataRecord['username_prefix'] = $ftpuser_prefix;
  134. if(strlen($dbuser_prefix . $this->dataRecord['database_user']) > 16)
  135. $app->tform->errorMessage .= str_replace('{user}', htmlentities($dbuser_prefix . $this->dataRecord['database_user'], ENT_QUOTES, 'UTF-8'),
  136. $app->tform->wordbook["database_user_error_len"]).'<br />';
  137. //Check database user against blacklist
  138. $dbuser_blacklist = array($conf['db_user'], 'mysql', 'root');
  139. if(is_array($dbuser_blacklist) && in_array($dbuser_prefix . $this->dataRecord['database_user'], $dbuser_blacklist)) {
  140. $app->tform->errorMessage .= $app->lng('Database user not allowed.').'<br />';
  141. }
  142. /* restrict the names */
  143. /* crop user names if they are too long -> mysql: user: 16 chars / db: 64 chars */
  144. if ($app->tform->errorMessage == ''){
  145. $this->dataRecord['database_user'] = substr($dbuser_prefix . $this->dataRecord['database_user'], 0, 16);
  146. }
  147. $this->dataRecord['server_id'] = 0; // we need this on all servers
  148. if ($this->dataRecord['database_user'] != ""){
  149. /* REMOVE the restriction */
  150. $app->tpl->setVar("database_user", $app->tools_sites->removePrefix($this->dataRecord['database_user'], $this->dataRecord['database_user_prefix'], $dbuser_prefix));
  151. }
  152. if($this->dataRecord['database_user'] == "") {
  153. $app->tpl->setVar("database_user_prefix", $dbuser_prefix);
  154. } else {
  155. $app->tpl->setVar("database_user_prefix", $app->tools_sites->getPrefix($this->dataRecord['database_user_prefix'], $dbuser_prefix, $global_config['dbuser_prefix']));
  156. }
  157. //* Reseller: If the logged in user is not admin and has sub clients (is a reseller)
  158. if($_SESSION["s"]["user"]["typ"] != 'admin' && $app->auth->has_clients($_SESSION['s']['user']['userid'])) {
  159. $this->valor_prefix = $dbuser_prefix;
  160. }
  161. }
  162. public $dominio;
  163. public $subdominio;
  164. public $es_subdominio = false;
  165. public $subdom_error = false;
  166. public $dominio_error = false;
  167. public $no_ip = false;
  168. //Campos para PDF
  169. public $usuario_db_txt;
  170. public $nombre_db_txt;
  171. public $pass_db_txt;
  172. public $usuario_ftp_txt;
  173. public $pass_ftp_txt;
  174. public $nombre_user_ftp;
  175. public $ip4_pdf;
  176. public $url_db;
  177. function generaNombreFTP(){
  178. $this->tratarVariablesPrefix();
  179. //Cadena de caractares para construir el nombre.
  180. $cadena = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ23456789";
  181. //Obtengo la longitud de las cadenas
  182. $longitudCadena=strlen($cadena);
  183. //Variable para el nombre
  184. $nombre = "";
  185. //Longitud para el nombre
  186. $longitudNombre=8;
  187. //Creo el nombre
  188. for($i=1 ; $i<=$longitudNombre ; $i++){
  189. //Número aleatorio entre 0 y la longitud de la cadena de caracteres-1
  190. $pos=rand(0,$longitudCadena-1);
  191. //Formo la nombre en cada iteracción del bucle, añadiendo a la cadena $nombre
  192. //la letra correspondiente a la posición $pos en la cadena de caracteres definida.
  193. $nombre .= substr($cadena,$pos,1);
  194. }
  195. return $nombre;
  196. }
  197. function generaPass(){
  198. //Cadena de caractares para construir las password.
  199. $cadena = "abcdefghijklmnopqrstuvwxyz!@#_ABCDEFGHIJKLMNOPQRSTUVWXYZ23456789";
  200. $cadSpeciales = "!@#_";
  201. //Obtengo la longitud de las cadenas
  202. $longitudCadena = strlen($cadena);
  203. $longSpeciales = strlen($cadSpeciales);
  204. //Variable para la password
  205. $pass = "";
  206. //Longitud para la password
  207. $longitudPass=13;
  208. //Creo la password
  209. for($i=1 ; $i<=$longitudPass ; $i++){
  210. //Número aleatorio entre 0 y la longitud de la cadena de caracteres-1
  211. $pos=rand(0,$longitudCadena-1);
  212. //Formo la password en cada iteracción del bucle, añadiendo a la cadena $pass
  213. //la letra correspondiente a la posición $pos en la cadena de caracteres definida.
  214. $pass .= substr($cadena,$pos,1);
  215. //Añado algún caracter especial en los últimos cuatro caracteres
  216. for($i2=13;$i2<=$i; $i2++){
  217. $poSpecial=rand(0,$longSpeciales-1);
  218. $pass .= substr($cadSpeciales, $poSpecial, 1);
  219. }
  220. }
  221. return $pass;
  222. }
  223. function generaNombreBD(){
  224. $this->tratarVariablesPrefix();
  225. //Cadena de caractares para construir las nombre.
  226. $cadena = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ23456789";
  227. //$cadSpeciales = "!@#_";
  228. //Obtengo la longitud de las cadenas
  229. $longitudCadena=strlen($cadena);
  230. //$longSpeciales = strlen($cadSpeciales);
  231. //Variable para la nombre
  232. $nombre = "";
  233. //Longitud para la nombre
  234. $longitudNombre=8;
  235. //Creo el nombre
  236. for($i=1 ; $i<=$longitudNombre ; $i++){
  237. //Número aleatorio entre 0 y la longitud de la cadena de caracteres-1
  238. $pos=rand(0,$longitudCadena-1);
  239. //Formo la nombre en cada iteracción del bucle, añadiendo a la cadena $nombre
  240. //la letra correspondiente a la posición $pos en la cadena de caracteres definida.
  241. $nombre .= substr($cadena,$pos,1);
  242. }
  243. return $this->valor_prefix . $nombre;
  244. }
  245. /*function comprobarPass($claveGenerada){
  246. //compruebo que el tamaño del string sea válido.
  247. if (strlen($claveGenerada)<3 || strlen($claveGenerada)>20){
  248. echo $claveGenerada . " no es válida0<br>";
  249. return false;
  250. }
  251. //compruebo que los caracteres sean los permitidos
  252. $alphachars = "abcdefghijkmnopqrstuvwxyz";
  253. $upperchars = "ABCDEFGHJKLMNPQRSTUVWXYZ";
  254. $numchars = "23456789";
  255. $specialchars = "!@#_";
  256. //$permitidos = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
  257. if (ereg("^[a-zA-Z0-9\-_]{3,20}$", $claveGenerada)) {
  258. echo $claveGenerada . " es válido<br>";
  259. return true;
  260. } else {
  261. echo $claveGenerada . " NO válido<br>";
  262. return false;
  263. }
  264. echo $claveGenerada . " es válido<br>";
  265. return true;
  266. }*/
  267. function crearBaseDatosFtp($remoto){
  268. global $app, $conf;
  269. $fields = $app->tform->encode($this->dataRecord, $app->tform->getCurrentTab(), true);
  270. $app->uses('ini_parser,getconf');
  271. $server_config_array = $app->getconf->get_global_config();
  272. $generated_usernameBBDD = $this->generaNombreBD();
  273. $sitio_id = $app->db->queryOneRecord(
  274. 'SELECT domain_id, domain FROM web_domain WHERE domain = "'.$fields['domain'].'"');
  275. $clavePass = $this->generaPass();
  276. //añado database user con su prefix
  277. $db_user_params = array(
  278. 'server_id' => $this->bbdd_serv,
  279. 'sysgroup_id' => $this->cli_grupo_id, //$this->sys_grupo_id,
  280. 'sys_userid' => $this->sys_usuario_id,
  281. 'sys_perm_other' => '-',
  282. 'database_user' => $generated_usernameBBDD,
  283. 'database_user_prefix' => $this->valor_prefix,
  284. 'database_password' => $clavePass
  285. );
  286. $this->usuario_db_txt = $db_user_params['database_user'];
  287. $this->pass_db_txt = $db_user_params['database_password'];
  288. //print "<pre> USUARIO BBDD "; print_r($db_user_params); print "</pre>\n";
  289. //print "<br>". $this->cli_id;
  290. //print "<br>". $this->usuario_db_txt;
  291. //print "<br>". $this->pass_db_txt;
  292. //print "<pre>"; print_r($fields); print "</pre>\n";
  293. //IMPORTANTE. PARA QUE EL PLUGING FUNCIONE HAY QUE CARGAR ANTES EL FORMULARIO
  294. //DE LO QUE SE QUIERE CREAR EN ESTE CASO BBDD. NO FUNCIONA SE LANZA EL AFTER INSERT EN NUESTRA FUNCION.
  295. $tform_def_file = "../sites/form/database_user.tform.php";
  296. $app->tform->loadFormDef($tform_def_file);
  297. $db_user_id = $remoto->insert_query('../sites/form/database_user.tform.php',
  298. $this->cli_id, $db_user_params, 'sites:web_database_user:on_after_insert');
  299. $remoto->sites_database_user_after_add($this->cli_grupo_id, $db_user_params);
  300. // add database
  301. $paramsBD = array(
  302. 'server_id' => $this->bbdd_serv, //$camDnsRR['server_id'],
  303. 'sysgroup_id' => $this->cli_grupo_id, //$this->sys_grupo_id,
  304. 'parent_domain_id' => $sitio_id['domain_id'],
  305. 'type' => 'mysql',
  306. 'database_quota' => '-1',
  307. 'database_name' => $generated_usernameBBDD,
  308. 'database_name_prefix' => $this->valor_prefix,
  309. 'database_user_id' => $db_user_id,
  310. 'database_charset' => 'utf8',
  311. 'remote_access' => 'n',
  312. 'remote_ips' => '-1',
  313. 'active' => 'y'
  314. );
  315. $this->nombre_db_txt = $paramsBD['database_name'];
  316. $db_id = $remoto->sites_database_add($this->cli_id, /*$this->cli_grupo_id,*/ $paramsBD);
  317. $this->urlBBDD($db_id, $this->bbdd_serv);
  318. //echo('Id de la BBDD ' . $db_id);
  319. // get site data para usarlo en la creación de la cuenta ftp, otra forma de cargar una tupla dandole un id
  320. //$app->uses('remoting_lib');
  321. //$app->remoting_lib->loadFormDef('../sites/form/web_vhost_domain.tform.php');
  322. //IMPORTANTE. AL NO PODER USAR LA FUNCION getDataRecord YA QUE NOS HACE ADMIN.
  323. //TENGO QUE LANZAR LA FUNCION sites_ftp_user_after_insert PARA SOLUCIONAR ESTE PROBLEMA Y NO getDataRecord().
  324. //$site_data = $app->remoting_lib->getDataRecord($sitio_id);
  325. //$site_data = $remoto->getDataRecordWebDNS($sitio_id);
  326. $this->nombre_user_ftp = $this->generaNombreFTP();
  327. // add ftp user
  328. $ftp_params = array(
  329. 'server_id' => $this->web_serv, //$camDnsRR['server_id'],
  330. 'parent_domain_id' => $sitio_id['domain_id'],
  331. 'username' => $this->valor_prefix_ftp . $this->nombre_user_ftp,
  332. 'username_prefix' => $this->valor_prefix_ftp,
  333. 'password' => $clavePass,
  334. 'quota_size' => '-1',
  335. 'dir' => $site_data['0']['document_root'],
  336. 'uid' => $site_data['0']['system_user'],
  337. 'gid' => $site_data['0']['system_group'],
  338. 'sys_groupid' => $site_data['0']['sys_groupid'],
  339. 'quota_files' => '-1',
  340. 'ul_ratio' => '-1',
  341. 'dl_ratio' => '-1',
  342. 'ul_bandwidth' => '-1',
  343. 'dl_bandwidth' => '-1',
  344. 'active' => 'y',
  345. );
  346. $this->usuario_ftp_txt = $ftp_params['username'];
  347. $this->pass_ftp_txt = $ftp_params['password'];
  348. //print "<pre> FTP "; print_r($ftp_params); print "</pre>\n";
  349. //print "<pre>"; print_r($site_data); print "</pre>\n";
  350. //echo('El grupo del usuario es ' . $this->cli_grupo_id);
  351. $tform_def_file = "../sites/form/ftp_user.tform.php";
  352. $app->tform->loadFormDef($tform_def_file);
  353. $remoto->insert_query('../sites/form/ftp_user.tform.php', $this->cli_id,/*$fields['client_group_id'],*/ $ftp_params);
  354. $app->uses('sites_ftp_user_plugin');
  355. global $app;
  356. //Register for the events. NO FUNCIONA.
  357. $app->plugin->registerEvent('sites:ftp_user:on_after_insert');
  358. //LO LANZAMOS DE NUESTRA FUNCION EXTRAIDA Y MODIFICADA DEL PLUGING QUE SE TENDRÍA QUE EJECUTAR PERO NO LO HACE.WHY?
  359. $remoto->sites_ftp_user_after_insert();
  360. echo '<br><div class="alert alert-success"><br>
  361. Altas de BBDD y FTP, ¡Correctas!<br><br>
  362. Usuario BBDD: <b>'. $this->usuario_db_txt .'</b><br>Contraseña: <b>' . $this->pass_db_txt . '
  363. </b><br>Nombre BBDD: <b>' . $this->nombre_db_txt . '</b><br>
  364. <br>Usuario FTP: <b>'. $this->usuario_ftp_txt .'</b><br>Contraseña: <b>' . $this->pass_ftp_txt . '</b><br><br>
  365. </div></br>';
  366. //$hoy = date("d-m-Y H:i:s");
  367. $html_resultado = '<br><br><b>BBDD</b><br>
  368. Usuario: <b>'. $this->usuario_db_txt .'</b><br>
  369. Nombre Base de Datos: <b>' . $this->nombre_db_txt .'</b><br>
  370. Clave: <b>' . $this->pass_db_txt . '</b><br><br>
  371. <b>FTP</b><br>
  372. Usuario: <b>'. $this->usuario_ftp_txt .'</b><br>
  373. Clave: <b>' . $this->pass_ftp_txt . '</b><br><br>
  374. <b> </b><br>Nuevo dominio: <b>'. $fields['domain'].'</b><br><br>';
  375. $eldom = $fields['domain'];
  376. echo '<form method="post" id="formulario" action="webdns/pdf_o6h.php" target="_blank">';
  377. echo '<input id="pdf_power" name="pdf_power" type="hidden" value="'.$html_resultado.'">';
  378. echo '<input id="nombre_bd" name="nombre_bd" type="hidden" value="'.$this->nombre_db_txt.'">';
  379. echo '<input id="usuario_bd" name="usuario_bd" type="hidden" value="'.$this->usuario_db_txt.'">';
  380. echo '<input id="pass_bd" name="pass_bd" type="hidden" value="'.$this->pass_db_txt.'">';
  381. echo '<input id="usuario_ftp" name="usuario_ftp" type="hidden" value="'.$this->usuario_ftp_txt.'">';
  382. echo '<input id="pass_ftp" name="pass_ftp" type="hidden" value="'.$this->pass_ftp_txt.'">';
  383. echo '<input id="ip4" name="ip4" type="hidden" value="'.$this->ip4_pdf.'">';
  384. echo '<input id="url_db" name="url_db" type="hidden" value="'.$this->url_db.'">';
  385. echo '<input id="dominio_nuevo" name="dominio_nuevo" type="hidden" value="'.$eldom.'">';
  386. echo '<input type="submit" class="btn btn-default formbutton-success" value="Descargar PDF">';
  387. echo '</form>';
  388. echo '<div id="resp"></div>';
  389. }
  390. function urlBBDD($idBBDD, $servidor_id){
  391. global $app, $conf;
  392. $dbData = $app->db->queryOneRecord(
  393. "SELECT server_id, database_name FROM web_database WHERE database_id = ?", $idBBDD);
  394. $serverData = $app->db->queryOneRecord(
  395. "SELECT server_name FROM server WHERE server_id = ?", $servidor_id);
  396. $app->uses('getconf');
  397. $global_config = $app->getconf->get_global_config('sites');
  398. $web_config = $app->getconf->get_server_config($servidor_id, 'web');
  399. //print "<pre>"; print_r($global_config); print "</pre>\n";
  400. //print "<pre>"; print_r($web_config); print "</pre>\n";
  401. if($global_config['phpmyadmin_url'] != '') {
  402. $phpmyadmin_url = $global_config['phpmyadmin_url'];
  403. $phpmyadmin_url = str_replace(array('[SERVERNAME]', '[DATABASENAME]'), array($serverData['server_name'], $dbData['database_name']), $phpmyadmin_url);
  404. //header('Location: '.$phpmyadmin_url);
  405. $this->url_db = $phpmyadmin_url;
  406. //print('la url ' . $phpmyadmin_url);
  407. }
  408. }
  409. //Expresiones regulares para comprobar si es subdominio
  410. function comprobarSubDominios($subdom) {
  411. global $app, $conf;
  412. $patronSubDominos = "/(.*?)\.(.*)$/";
  413. $patronWWW = "/^w{3}/";
  414. //Se comprueba que no tenga 3 w "www" al principio del nombre del dominio o subdomino
  415. $encontradoWWW = preg_match($patronWWW, $subdom, $coincidencias);
  416. if($encontradoWWW){
  417. $app->tform->errorMessage = $app->tform->wordbook['error_dominio_www'];
  418. return;
  419. }
  420. //print "<pre>"; print_r($subdom); print "</pre>\n";
  421. //Si el dominio tiene mas de dos puntos, es incorrecto
  422. if(substr_count($subdom,".") > 2) {
  423. $this->es_subdominio = false;
  424. $this->dominio_error = true;
  425. $app->tform->errorMessage = $app->tform->wordbook['error_dominio_mas_puntos'];
  426. //return;
  427. }else if(substr_count($subdom,".") == 2){
  428. $this->encontrado = preg_match($patronSubDominos, $subdom, $coincidencias);
  429. //print "<pre>"; print_r($coincidencias); print "</pre>\n";
  430. $this->subdominio = $coincidencias[1];
  431. $this->dominio = $coincidencias[2];
  432. $this->es_subdominio = true;
  433. }
  434. return $this->es_subdominio;
  435. }
  436. public $cli_id;
  437. public $cli_grupo_id;
  438. public $sys_usuario_id;
  439. public $sys_grupo_id;
  440. //Control del usuario logeado y captura de sus variables de systema.
  441. function controlUserGrupoId(){
  442. global $app, $conf;
  443. $fields = $app->tform->encode($this->dataRecord, $app->tform->getCurrentTab(), true);
  444. //* Client: If the logged in user is not admin and has no sub clients (no reseller)
  445. if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) {
  446. $this->cli_id = $_SESSION["s"]["user"]["client_id"];
  447. $this->cli_grupo_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
  448. $this->sys_usuario_id = $_SESSION["s"]["user"]["sys_userid"];
  449. $this->sys_grupo_id = $_SESSION["s"]["user"]["sys_groupid"];
  450. //echo('Es cliente cli_id ' . $this->cli_id . ' cli_grupo_id ' . $this->cli_grupo_id . ' sys_usuario ' . $this->sys_usuario_id . ' sys_grupo ' . $this->sys_grupo_id);
  451. } else {
  452. //Captura de los distintos ids del cliente y usuario de sistema.
  453. //combinando un query a las dos tablas sys_group y sys_user que comparten el client_id.
  454. //print "<pre>Seleccionado: "; print_r($fields['client_group_id']); print "</pre>\n";
  455. if($fields['client_group_id']==0) {
  456. //En la tabla sys_user el client_id 0 es admin. En sys_group este valor es 0
  457. $this->cli_id = 0;
  458. $this->cli_grupo_id = 1;
  459. $this->sys_usuario_id = 1;//$this->cli_id;
  460. $this->sys_grupo_id = 0; //$this->cli_grupo_id;//0
  461. //echo('Quien es ' . $_SESSION["s"]["user"]["typ"]);
  462. }else{
  463. //echo('Quien es else ' . $_SESSION["s"]["user"]["typ"]);
  464. $client = $app->db->queryOneRecord(
  465. 'SELECT sys_user.userid, sys_user.sys_userid, sys_user.sys_groupid, sys_user.default_group, sys_user.client_id
  466. FROM sys_group, sys_user
  467. WHERE sys_group.client_id = sys_user.client_id and sys_group.groupid = ?', $fields['client_group_id']);
  468. $this->cli_id = $client['client_id'];
  469. $this->cli_grupo_id = $client['default_group'];
  470. $this->sys_usuario_id = $client['userid'];//$client['sys_userid'];
  471. $this->sys_grupo_id = $this->cli_grupo_id;//$client['sys_groupid'];
  472. //echo('Es cliente cli_id ' . $this->cli_id . ' cli_grupo_id ' . $this->cli_grupo_id . ' sys_usuario ' . $this->sys_usuario_id . ' sys_grupo ' . $this->sys_grupo_id);
  473. }
  474. }
  475. //print "<pre>Valores : "; print_r($this->cli_id); print "</pre>\n";
  476. //print " cli_id " . $this->cli_id . ' cli_grupo ' . $this->cli_grupo_id . ' sys_usuario ' . $this->sys_usuario_id . ' sys grupo ' . $this->sys_grupo_id;
  477. }
  478. //Crear subdominio
  479. function crearSubDominio($remoto, $campoSubDominio){
  480. global $app, $conf;
  481. $fields = $app->tform->encode($this->dataRecord, $app->tform->getCurrentTab(), true);
  482. //COMO LE PASO EL DOMINIO CORRECTO NO ES NECESARIO PONER EL % EN LA SQL AÑADO EL PUNTO.
  483. //EL PROBLEMA ES QUE CON UN DOMINIO .COM TOMA POR VALIDO UN .CO POR EL %
  484. //NO --> ('SELECT server_id, name FROM dns_rr WHERE name LIKE "'.$this->dominio.'%"');
  485. $existeDominioParaSubDominio = $app->db->queryOneRecord(
  486. 'SELECT server_id, name FROM dns_rr WHERE name LIKE "'.$this->dominio.'."');
  487. // print "<pre>En crearSubDominio campo que se le pasa subdominio es: "; print_r($campoSubDominio); print "</pre>\n";
  488. //Compruebo que el subdominio no existe consultando la tabla web_domain.
  489. $existeSubDominioWeb = $app->db->queryOneRecord(
  490. 'SELECT domain_id, domain FROM web_domain
  491. WHERE domain = "'.$campoSubDominio.'"');
  492. //Compruebo que el subdominio no existe consultando la tabla dns_rr
  493. $existeSubDominioTipoA = $app->db->queryOneRecord(
  494. 'SELECT name, type FROM dns_rr
  495. WHERE name = "'.$campoSubDominio.'" AND type = "A"');
  496. if(!$existeDominioParaSubDominio['name']){
  497. $this->subdom_error = true;
  498. $app->tform->errorMessage = $app->tform->wordbook['error_no_existe_dominio_padre'];
  499. // print "<pre>Error En crearSubDominio campo comprobacion dns_rr es: "; print_r($existeDominioParaSubDominio); print "</pre>\n";
  500. $this->onError();
  501. return;
  502. }
  503. // print "<pre>En crearSubDominio campo comprobacion dns_rr es: "; print_r($existeDominioParaSubDominio); print "</pre>\n";
  504. //print '<pre>El Sub existe '. $existeSubDominio['domain'];
  505. if($existeSubDominioWeb['domain']){
  506. $this->subdom_error = true;
  507. $app->tform->errorMessage = $app->tform->wordbook['error_no_existe_dominio_padre'];
  508. $this->onError();
  509. return $this->subdom_error;
  510. }
  511. if($existeSubDominioTipoA['name']){
  512. $this->subdom_error = true;
  513. $app->tform->errorMessage = $app->tform->wordbook['error_no_existe_dominio_padre'];
  514. $this->onError();
  515. return $this->subdom_error;
  516. }
  517. //$camDominio = $app->db->queryOneRecord('SELECT domain_id, domain FROM domain WHERE domain = "'.$this->dominio.'"');
  518. $camDominio = $app->db->queryOneRecord('SELECT origin FROM dns_soa WHERE origin LIKE "'.$this->dominio.'."');
  519. //$camDominio = $app->db->queryOneRecord('SELECT origin FROM dns_soa WHERE origin LIKE "'.$campoSubDominio.'%"');
  520. $camDnsRR = $app->db->queryOneRecord('SELECT server_id, zone FROM dns_rr WHERE name LIKE "'.$this->dominio.'."');
  521. //Para los registros tipo A la ip tiene que ser tipo IPv4
  522. /* $camServIP = $app->db->queryOneRecord(
  523. "SELECT ip_address FROM server_ip
  524. WHERE server_id = ".$camDnsRR['server_id']." AND ip_type='IPv4'");
  525. */
  526. //print_r($camDominio);
  527. //print_r($camDnsRR);
  528. $this->ip4_ultima = $this->ip4_servidor_dns['ip_address'];
  529. //Si el dominio NO existe mostramos mensaje de error y salimos de la ejecución
  530. if(!$camDominio['origin']){
  531. $this->subdom_error = true;
  532. $app->tform->errorMessage = $app->tform->wordbook['error_no_existe_dominio_padre'];
  533. $this->onError();
  534. return $this->subdom_error;
  535. } else {
  536. //Parametros para la creación de subdominios
  537. $paramSubDominios = array(
  538. 'server_id' => $camDnsRR['server_id'],
  539. 'zone' => $camDnsRR['zone'],
  540. 'name' => $this->subdominio,
  541. 'type' => 'a',
  542. 'data' => $this->ip4_ultima, //$camServIP['ip_address'],
  543. //'aux' => '0',
  544. 'ttl' => '3600',
  545. 'active' => 'y',
  546. //comento el campo stamp, ya que introducia solo ceros en la bbdd
  547. //'stamp' => time(),
  548. 'serial' => '1',
  549. );
  550. //echo ('<br>El client_id GLOBAL ' . $this->cli_id . " <br>");
  551. // client group id
  552. /*$res = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = ".$app->functions->intval($fields['client_group_id']));
  553. $client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);//$res['groupid'];
  554. echo ('El client group id seleccion ' . $client_group_id . " <br>");
  555. echo ('El groupid de la tabla sys_group ' . $res['groupid'] . " ");*/
  556. //print "<pre>"; print_r($paramSubDominios); print "</pre>\n";
  557. //Inserto en bbdd usando la clase remoto que se la he pasado en parámetros de la función
  558. //$resultado = $remoto->insert_query('../dns/form/dns_a.tform.php', $fields['client_id'], $paramSubDominios);
  559. $resultado = $remoto->insert_query('form/dns_a_webdns.tform.php', $this->cli_id, /*$fields['client_group_id'],*/ $paramSubDominios);
  560. $remoto->dns_registro_tipo_a_after_insert($this->cli_grupo_id);
  561. echo '<br><div class="alert alert-success"><br>
  562. Se ha dado de alta Web y Subdominio, <b>'.$this->subdominio.'</b>, ¡Correctamente!
  563. <br><br></div></br>';
  564. //$this->onShow();
  565. }
  566. }
  567. function crearSitioWebSubdominio($remoto){
  568. global $app, $conf;
  569. $fields = $app->tform->encode($this->dataRecord, $app->tform->getCurrentTab(), true);
  570. /* print "<pre>DNS SERVER ";print_r($this->dns_serv);print "</pre>\n";
  571. print "<pre>WEB SERVER ";print_r($this->web_serv);print "</pre>\n";
  572. print "<pre>IP4 DNS ";print_r($this->ip4_servidor_dns);print "</pre>\n";
  573. print "<pre>IP6 DNS ";print_r($this->ip6_servidor_dns);print "</pre>\n";
  574. print "<pre>IP4 WEB ";print_r($this->ip4_servidor_web);print "</pre>\n";
  575. print "<pre>IP6 WEB ";print_r($this->ip6_servidor_web);print "</pre>\n";
  576. print "<pre>IP6 WEB LA OTRA ";print_r($this->ip6_ultima['ip_address']);print "</pre>\n";
  577. */
  578. //add site
  579. $paramsite = array(
  580. //"sys_userid" => $this->sys_usuario_id,
  581. //"sys_groupid" => $this->cli_grupo_id,
  582. 'type' => 'vhost',
  583. 'domain' => $fields['domain'], //$this->subdominio,
  584. 'server_id' => $this->web_serv, //$server_id,
  585. 'ip_address' => '*',
  586. 'ipv6_address' =>$this->ip6_servidor_web['ip_address'],
  587. 'traffic_quota' => '-1',
  588. 'hd_quota' => '0',
  589. 'cgi' => 'y',
  590. 'ssi' => 'y',
  591. 'suexec' => 'y',
  592. 'ruby' => 'n',
  593. 'python' => 'n',
  594. 'perl' => 'n',
  595. 'errordocs' => '1',
  596. 'subdomain' => '',
  597. 'php' => 'php-fpm',
  598. 'fastcgi_php_version' => '',
  599. 'seo_redirect' => '',
  600. 'rewrite_to_https' => 'n',
  601. 'allow_override' => 'All',
  602. 'http_port' => 80,
  603. 'https_port' => 443,
  604. 'apache_directives' => '',
  605. 'nginx_directives' => '',
  606. 'php_fpm_use_socket' => 'y',
  607. 'pm' => 'ondemand',
  608. 'pm_max_children' => 10,
  609. 'pm_start_servers' => 1,
  610. 'pm_min_spare_servers' => 1,
  611. 'pm_max_spare_servers' => 5,
  612. 'pm_process_idle_timeout' => 10,
  613. 'pm_max_requests' => 0,
  614. 'custom_php_ini' => '',
  615. 'active' => 'y',
  616. 'document_root' => '-',
  617. 'system_user' => '-',
  618. 'system_group' => '-',
  619. 'log_retention' => 30,
  620. 'client_group_id' => $this->cli_grupo_id, //$client_group_id,
  621. );
  622. //print "<pre> Parametros:"; print_r($paramsite); print "</pre>\n";
  623. /*print '<pre> cliente id ' . $fields['client_id'];
  624. print "<pre>";print_r($fields);print "</pre>\n" . $fields['client_id'];*/
  625. //print '<pre>DNS IPV6 ' . $dns_ip_servidor_ipv6['ip_address'];
  626. //IMPORTANTE. PARA QUE EL PLUGING FUNCIONE HAY QUE CARGAR ANTES EL FORMULARIO
  627. //DE LO QUE SE QUIERE CREAR EN ESTE CASO SITIO WEB
  628. $tform_def_file = "../sites/form/web_vhost_domain.tform.php";
  629. $app->tform->loadFormDef($tform_def_file);
  630. //El último parámetro es para lanzar un evento que llama a la función on_after_insert que prepara
  631. //los campos document_root, system_user y system_group
  632. //$site_id = $remoto->insert_query('../sites/form/web_vhost_domain.tform.php', $fields['client_group_id'], $paramsite, 'sites:web_vhost_domain:on_after_insert');
  633. $site_id = $remoto->insert_query('../sites/form/web_vhost_domain.tform.php',
  634. $this->cli_id, /*$cliente_id_seleccionado,*/
  635. $paramsite, 'sites:web_vhost_domain:on_after_insert');
  636. //IMPORTANTE. HAY QUE CARGAR EL FORMULARIO DE WEBDNS PARA QUE ENCUENTRE EL TAB.
  637. $tform_def_file = "form/new_service_webdns.tform.php";
  638. $app->tform->loadFormDef($tform_def_file);
  639. }
  640. public $ip4_servidor_dns;
  641. public $ip6_servidor_dns;
  642. public $ip4_servidor_web;
  643. public $ip6_servidor_web;
  644. public $ip4_servidor_bbdd;
  645. public $ip6_servidor_bbdd;
  646. public $ip4_servidor_ftp;
  647. public $ip6_servidor_ftp;
  648. public $dns_serv;
  649. public $web_serv;
  650. public $bbdd_serv;
  651. public $ftp_serv;
  652. function tieneServidorIPs(){
  653. global $app, $conf;
  654. $this->controlUserGrupoId();
  655. $app->uses('getconf');
  656. $global_config_sitio = $app->getconf->get_global_config('sites');
  657. $global_config_dns = $app->getconf->get_global_config('dns');
  658. if(!$global_config_dns['default_dnsserver']) {
  659. $app->tform->errorMessage = $app->tform->wordbook['error_no_servidor_default']. 'DNS.';
  660. $this->onError();
  661. return true;
  662. } else if(!$global_config_sitio['default_webserver']) {
  663. $app->tform->errorMessage = $app->tform->wordbook['error_no_servidor_default']. 'WEB.';
  664. $this->onError();
  665. return true;
  666. } else if(!$global_config_sitio['default_dbserver']) {
  667. $app->tform->errorMessage = $app->tform->wordbook['error_no_servidor_default']. 'DB.';
  668. $this->onError();
  669. return true;
  670. }
  671. //print "<pre>WEB SERVER por defecto ";print_r($global_config_sitio);print "</pre>\n";
  672. //print "<pre>DNS SERVER por defecto ";print_r($global_config_dns);print "</pre>\n";
  673. //El cliente 1 es admin.
  674. //Recupero los servidores asignados por defecto y se los asigno a admin o al usuario
  675. //que no tenga asignado ninguno.
  676. if($this->cli_id == 0) {
  677. $this->dns_serv = $global_config_dns['default_dnsserver'];//1;
  678. $this->web_serv = $global_config_sitio['default_webserver'];//1;
  679. $this->bbdd_serv = $global_config_sitio['default_dbserver'];//1;
  680. $this->ftp_serv = $global_config_sitio['default_webserver'];//1;
  681. //print "<pre>tieneServidorIPs el cli_id "; print_r($this->cli_id . ' el servidor ' . $this->dns_serv); print "</pre>\n";
  682. }else{
  683. $servidores = $app->db->queryOneRecord(
  684. "SELECT client_id, dns_servers, web_servers, db_servers FROM client
  685. WHERE client_id = ". $this->cli_id);
  686. $this->dns_serv = $servidores['dns_servers'];
  687. $this->web_serv = $servidores['web_servers'];
  688. $this->bbdd_serv = $servidores['db_servers'];
  689. //para el ftp el servidor es el mismo que para el sitio web.
  690. $this->ftp_serv = $servidores['web_servers'];
  691. //Si el cliente no tiene asignado un servidor se añade por defecto al que hay en la configuración por defecto
  692. if(!$this->dns_serv){
  693. $this->dns_serv = $global_config_dns['default_dnsserver'];//1;
  694. }
  695. //Si el cliente no tiene asignado un servidor se añade por defecto al que hay en la configuración por defecto
  696. if(!$this->web_serv){
  697. $this->web_serv = $global_config_sitio['default_webserver'];//1;
  698. }
  699. //Si el cliente no tiene asignado un servidor se añade por defecto al que hay en la configuración por defecto
  700. if(!$this->bbdd_serv){
  701. $this->bbdd_serv = $global_config_sitio['default_dbserver'];//1;
  702. }
  703. //Si el cliente no tiene asignado un servidor se añade por defecto al que hay en la configuración por defecto
  704. if(!$this->ftp_serv){
  705. $this->ftp_serv = $global_config_sitio['default_webserver'];//1;
  706. }
  707. }
  708. /*print "<pre>DNS SERVER ";print_r($this->dns_serv);print "</pre>\n";
  709. print "<pre>WEB SERVER ";print_r($this->web_serv);print "</pre>\n";
  710. print "<pre>DB SERVER ";print_r($this->bbdd_serv);print "</pre>\n";
  711. print "<pre>FTP SERVER ";print_r($this->ftp_serv);print "</pre>\n";*/
  712. //Captura de las ips del servidor dns de la variable global para ello.
  713. /* $global_dns_config = $app->getconf->get_server_config($this->dns_serv, 'server');
  714. $this->ip4_servidor_dns = $global_dns_config['ip_address'];
  715. $this->ip6_servidor_dns = $global_dns_config['v6_prefix'];*/
  716. //El cliente 1 es admin
  717. if($this->cli_id == 0){
  718. //Compruebo si hay datos para el client_id 0 y si no existe pruebo con el 1.
  719. //Alguno de los dos tiene que existir por configuración de ispconfig.
  720. $this->ip4_servidor_dns = $app->db->queryOneRecord(
  721. 'SELECT ip_type, ip_address FROM server_ip
  722. WHERE client_id = "0" AND server_id = "'.$this->dns_serv.'" AND ip_type="IPv4"');
  723. $this->ip6_servidor_dns = $app->db->queryOneRecord(
  724. 'SELECT ip_type, ip_address FROM server_ip
  725. WHERE client_id = "0" AND server_id = "'.$this->dns_serv.'" AND ip_type="IPv6"');
  726. /*if(!$this->ip4_servidor_dns){
  727. $this->ip4_servidor_dns = $app->db->queryOneRecord(
  728. 'SELECT ip_type, ip_address FROM server_ip
  729. WHERE client_id = "1" AND server_id = "'.$this->dns_serv.'" AND ip_type="IPv4"');
  730. }*/
  731. /* if(!$this->ip6_servidor_dns){
  732. $this->ip6_servidor_dns = $app->db->queryOneRecord(
  733. 'SELECT ip_type, ip_address FROM server_ip
  734. WHERE client_id = "1" AND server_id = "'.$this->dns_serv.'" AND ip_type="IPv6"');*/
  735. //}
  736. }else{
  737. // $this->ip4_servidor_dns = $global_dns_config['ip_address'];
  738. //Comprobamos si el cliente tiene servidor asignado, si no lo tiene asignamos el que admin a seleccionado
  739. //para este servidor.
  740. $this->ip4_servidor_dns = $app->db->queryOneRecord(
  741. 'SELECT ip_type, ip_address
  742. FROM server_ip
  743. WHERE client_id = "'.$this->cli_id.'" AND server_id = "'.$this->dns_serv.'" AND ip_type="IPv4"');
  744. $this->ip6_servidor_dns = $app->db->queryOneRecord(
  745. 'SELECT ip_type, ip_address
  746. FROM server_ip
  747. WHERE client_id = "'.$this->cli_id.'" AND server_id = "'.$this->dns_serv.'"AND ip_type="IPv6"');
  748. //echo(' la ip6 ' . $this->ip6_ultima);
  749. //si no tiene asignado le damos el de admin.
  750. /* if(!$this->ip4_servidor_dns){
  751. // $this->ip4_servidor_dns = $global_dns_config['ip_address'];
  752. //Compruebo si hay datos para el client_id 0 y si no existe pruebo con el 1. Es admin ya que este cliente no tiene ip4 ni ip6 asignadas
  753. //Tomamos las de admin.
  754. //Alguno de los dos tiene que existir por configuración de ispconfig.
  755. $this->ip4_servidor_dns = $app->db->queryOneRecord(
  756. 'SELECT ip_type, ip_address FROM server_ip
  757. WHERE client_id = "0" AND server_id = "'.$this->dns_serv.'" AND ip_type="IPv4"');
  758. if(!$this->ip4_servidor_dns){
  759. $this->ip4_servidor_dns = $app->db->queryOneRecord(
  760. 'SELECT ip_type, ip_address FROM server_ip
  761. WHERE client_id = "1" AND server_id = "'.$this->dns_serv.'" AND ip_type="IPv4"');
  762. }
  763. }*/
  764. if(!$this->ip6_servidor_dns){
  765. //Compruebo si hay datos para el client_id 0 y si no existe pruebo con el 1. Es admin ya que este cliente no tiene ip4 ni ip6 asignadas
  766. //Tomamos las de admin.
  767. //Alguno de los dos tiene que existir por configuración de ispconfig.
  768. //$this->ip4_servidor_dns = $app->db->queryOneRecord('SELECT ip_type, ip_address FROM server_ip WHERE client_id = "0" AND ip_type="IPv4"');
  769. $this->ip6_servidor_dns = $app->db->queryOneRecord(
  770. 'SELECT ip_type, ip_address FROM server_ip
  771. WHERE client_id = "0" AND server_id = "'.$this->dns_serv.'" AND ip_type="IPv6"');
  772. if(!$this->ip6_servidor_dns){
  773. $this->ip6_servidor_dns = $app->db->queryOneRecord(
  774. 'SELECT ip_type, ip_address FROM server_ip
  775. WHERE client_id = "1" AND server_id = "'.$this->dns_serv.'" AND ip_type="IPv6"');
  776. }
  777. }
  778. $this->ip6_ultima = $this->ip6_servidor_dns['ip_address'];
  779. }
  780. //Captura de las ips del servidor web
  781. if($this->cli_id == 0){
  782. //Compruebo si hay datos para el client_id 0 y si no existe pruebo con el 1.
  783. //Alguno de los dos tiene que existir por configuración de ispconfig.
  784. $this->ip4_servidor_web = $app->db->queryOneRecord(
  785. 'SELECT ip_type, ip_address FROM server_ip
  786. WHERE client_id = "0" AND server_id = "'.$this->web_serv.'" AND ip_type="IPv4"');
  787. $this->ip6_servidor_web = $app->db->queryOneRecord(
  788. 'SELECT ip_type, ip_address FROM server_ip
  789. WHERE client_id = "0" AND server_id = "'.$this->web_serv.'" AND ip_type="IPv6"');
  790. /*if(!$this->ip4_servidor_web){
  791. $this->ip4_servidor_web = $app->db->queryOneRecord(
  792. 'SELECT ip_type, ip_address FROM server_ip
  793. WHERE client_id = "1" AND server_id = "'.$this->web_serv.'" AND ip_type="IPv4"');
  794. }
  795. if(!$this->ip6_servidor_web){
  796. $this->ip6_servidor_web = $app->db->queryOneRecord(
  797. 'SELECT ip_type, ip_address FROM server_ip
  798. WHERE client_id = "1" AND server_id = "'.$this->web_serv.'" AND ip_type="IPv6"');
  799. }*/
  800. }else{//Comprobamos si el cliente tiene servidor asignado
  801. $this->ip4_servidor_web = $app->db->queryOneRecord(
  802. 'SELECT ip_type, ip_address
  803. FROM server_ip
  804. WHERE client_id = "'.$this->cli_id.'" AND server_id = "'.$this->web_serv.'" AND ip_type="IPv4"');
  805. $this->ip6_servidor_web = $app->db->queryOneRecord(
  806. 'SELECT ip_type, ip_address
  807. FROM server_ip
  808. WHERE client_id = "'.$this->cli_id.'" AND server_id = "'.$this->web_serv.'"AND ip_type="IPv6"');
  809. //si no tiene asignado le damos el de admin.
  810. if(!$this->ip4_servidor_web){
  811. $this->ip4_servidor_web = $app->db->queryOneRecord(
  812. 'SELECT ip_type, ip_address FROM server_ip
  813. WHERE client_id = "0" AND server_id = "'.$this->web_serv.'" AND ip_type="IPv4"');
  814. /*if(!$this->ip4_servidor_web){
  815. $this->ip4_servidor_web = $app->db->queryOneRecord(
  816. 'SELECT ip_type, ip_address FROM server_ip
  817. WHERE client_id = "1" AND server_id = "'.$this->web_serv.'" AND ip_type="IPv4"');
  818. }*/
  819. }
  820. //Cargamos variable para el pdf
  821. $this->ip4_pdf = $this->ip4_servidor_web['ip_address'];
  822. if(!$this->ip6_servidor_web){
  823. $this->ip6_servidor_web = $app->db->queryOneRecord(
  824. 'SELECT ip_type, ip_address FROM server_ip
  825. WHERE client_id = "0" AND server_id = "'.$this->web_serv.'" AND ip_type="IPv6"');
  826. /*if(!$this->ip6_servidor_web){
  827. $this->ip6_servidor_web = $app->db->queryOneRecord(
  828. 'SELECT ip_type, ip_address FROM server_ip
  829. WHERE client_id = "1" AND server_id = "'.$this->web_serv.'" AND ip_type="IPv6"');
  830. }*/
  831. }
  832. }
  833. //Captura de las ips del servidor bbdd
  834. if($this->cli_id == 0){
  835. //Compruebo si hay datos para el client_id 0 y si no existe pruebo con el 1.
  836. //Alguno de los dos tiene que existir por configuración de ispconfig.
  837. $this->ip4_servidor_bbdd = $app->db->queryOneRecord(
  838. 'SELECT ip_type, ip_address FROM server_ip
  839. WHERE client_id = "0" AND server_id = "'.$this->bbdd_serv.'" AND ip_type="IPv4"');
  840. $this->ip6_servidor_bbdd = $app->db->queryOneRecord(
  841. 'SELECT ip_type, ip_address FROM server_ip
  842. WHERE client_id = "0" AND server_id = "'.$this->bbdd_serv.'" AND ip_type="IPv6"');
  843. /*if(!$this->ip4_servidor_bbdd){
  844. $this->ip4_servidor_bbdd = $app->db->queryOneRecord(
  845. 'SELECT ip_type, ip_address FROM server_ip
  846. WHERE client_id = "1" AND server_id = "'.$this->bbdd_serv.'" AND ip_type="IPv4"');
  847. }
  848. if(!$this->ip6_servidor_bbdd){
  849. $this->ip6_servidor_bbdd = $app->db->queryOneRecord(
  850. 'SELECT ip_type, ip_address FROM server_ip
  851. WHERE client_id = "1" AND server_id = "'.$this->bbdd_serv.'" AND ip_type="IPv6"');
  852. }*/
  853. }else{//Comprobamos si el cliente tiene servidor asignado
  854. $this->ip4_servidor_bbdd = $app->db->queryOneRecord(
  855. 'SELECT ip_type, ip_address
  856. FROM server_ip
  857. WHERE client_id = "'.$this->cli_id.'" AND server_id = "'.$this->bbdd_serv.'" AND ip_type="IPv4"');
  858. $this->ip6_servidor_bbdd = $app->db->queryOneRecord(
  859. 'SELECT ip_type, ip_address
  860. FROM server_ip
  861. WHERE client_id = "'.$this->cli_id.'" AND server_id = "'.$this->bbdd_serv.'"AND ip_type="IPv6"');
  862. //si no tiene asignado le damos el de admin.
  863. if(!$this->ip4_servidor_bbdd){
  864. //Compruebo si hay datos para el client_id 0 y si no existe pruebo con el 1. Es admin ya que este cliente no tiene ip4 ni ip6 asignadas
  865. //Tomamos las de admin.
  866. //Alguno de los dos tiene que existir por configuración de ispconfig.
  867. $this->ip4_servidor_bbdd = $app->db->queryOneRecord(
  868. 'SELECT ip_type, ip_address FROM server_ip
  869. WHERE client_id = "0" AND server_id = "'.$this->bbdd_serv.'" AND ip_type="IPv4"');
  870. /*if(!$this->ip4_servidor_bbdd){
  871. $this->ip4_servidor_bbdd = $app->db->queryOneRecord(
  872. 'SELECT ip_type, ip_address FROM server_ip
  873. WHERE client_id = "1" AND server_id = "'.$this->bbdd_serv.'" AND ip_type="IPv4"');
  874. }*/
  875. }
  876. if(!$this->ip6_servidor_bbdd){
  877. $this->ip6_servidor_bbdd = $app->db->queryOneRecord(
  878. 'SELECT ip_type, ip_address FROM server_ip
  879. WHERE client_id = "0" AND server_id = "'.$this->bbdd_serv.'" AND ip_type="IPv6"');
  880. /*if(!$this->ip6_servidor_bbdd){
  881. $this->ip6_servidor_bbdd = $app->db->queryOneRecord(
  882. 'SELECT ip_type, ip_address FROM server_ip
  883. WHERE client_id = "1" AND server_id = "'.$this->bbdd_serv.'" AND ip_type="IPv6"');
  884. }*/
  885. }
  886. }
  887. //para el servidor ftp no se hacen comprobaciones
  888. //ya que las ips son las mismas que para el servidor web.
  889. //$la_ip4 = $app->db->queryOneRecord("SELECT ip_type, ip_address FROM server_ip WHERE ip_type='IPv4'");
  890. //$dns_ip_servidor['ip_address'];//$la_ip4['ip_address'];
  891. /*print "<pre>IP4 DNS ";print_r($this->ip4_servidor_dns);print "</pre>\n";
  892. print "<pre>IP6 DNS ";print_r($this->ip6_servidor_dns);print "</pre>\n";
  893. print "<pre>IP4 WEB ";print_r($this->ip4_servidor_web);print "</pre>\n";
  894. print "<pre>IP6 WEB ";print_r($this->ip6_servidor_web);print "</pre>\n";
  895. print "<pre>IP4 BBDD ";print_r($this->ip4_servidor_bbdd);print "</pre>\n";
  896. print "<pre>IP6 BBDD ";print_r($this->ip6_servidor_bbdd);print "</pre>\n";
  897. echo('El cliente ' . $this->cli_id . '<br>');*/
  898. if(!$this->ip4_servidor_dns['ip_address']){
  899. //si no tiene servidor dns en la lista de ips se toma el servidor por defecto web y se usan sus ips
  900. $global_web_config = $app->getconf->get_server_config($this->web_serv, 'server');
  901. $this->ip4_servidor_dns = $global_web_config;
  902. //$this->ip6_servidor_dns = $global_web_config;
  903. /*$servicio_dns = $app->db->queryOneRecord(
  904. 'SELECT server_id, dns_server, server_name FROM server
  905. WHERE server_id = "'.$this->dns_serv.'"');
  906. $nom_serv_dns = $servicio_dns['server_name'];
  907. $app->tform->errorMessage = $app->tform->wordbook['error_no_ip']. 'la IP4 para el servidor ' . $nom_serv_dns;
  908. $this->onError();
  909. return true;*/
  910. }
  911. if(!$this->ip6_servidor_dns['ip_address']){
  912. //si no tiene servidor dns en la lista de ips se toma el servidor por defecto web y se usan sus ips
  913. // $global_web_config = $app->getconf->get_server_config($this->web_serv, 'server');
  914. //$this->ip4_servidor_dns = $global_web_config;
  915. // $this->ip6_servidor_dns = $global_web_config['v6_prefix'];
  916. // $this->ip6_ultima = $this->ip6_servidor_dns;
  917. //echo(' la ip6 ' . $this->ip6_servidor_dns);
  918. /* $servicio_dns = $app->db->queryOneRecord(
  919. 'SELECT server_id, dns_server, server_name FROM server
  920. WHERE server_id = "'.$this->dns_serv.'"');
  921. $nom_serv_dns = $servicio_dns['server_name'];
  922. $app->tform->errorMessage = $app->tform->wordbook['error_no_ip']. 'la IP6 para el servidor '. $nom_serv_dns;
  923. $this->onError();
  924. return true;*/
  925. }
  926. if(!$this->ip4_servidor_web['ip_address']){
  927. $global_web_config = $app->getconf->get_server_config($this->web_serv, 'server');
  928. $this->ip4_servidor_web = $global_web_config;
  929. //Cargamos variable para el pdf
  930. $this->ip4_pdf = $this->ip4_servidor_web['ip_address'];
  931. if(!$this->ip4_servidor_web['ip_address']){
  932. $servidor_web = $app->db->queryOneRecord(
  933. 'SELECT server_id, web_server, server_name FROM server
  934. WHERE server_id = "'.$this->web_serv.'"');
  935. $nom_serv_web = $servidor_web['server_name'];
  936. $app->tform->errorMessage = $app->tform->wordbook['error_no_ip']. 'la IP4 para el servidor ' . $nom_serv_web;
  937. $this->onError();
  938. return true;
  939. }
  940. }
  941. if(!$this->ip6_servidor_web['ip_address']){
  942. $servidor_web = $app->db->queryOneRecord(
  943. 'SELECT server_id, web_server, server_name FROM server
  944. WHERE server_id = "'.$this->web_serv.'"');
  945. $nom_serv_web = $servidor_web['server_name'];
  946. $app->tform->errorMessage = $app->tform->wordbook['error_no_ip']. 'la IP6 para el servidor ' . $nom_serv_web;
  947. $this->onError();
  948. return true;
  949. }
  950. if(!$this->ip4_servidor_bbdd['ip_address']){
  951. $global_bbdd_config = $app->getconf->get_server_config($this->bbdd_serv, 'server');
  952. $this->ip4_servidor_bbdd = $global_bbdd_config;
  953. if(!$this->ip4_servidor_bbdd['ip_address']){
  954. $servicio_db = $app->db->queryOneRecord(
  955. 'SELECT server_id, db_server, server_name FROM server
  956. WHERE server_id = "'.$this->bbdd_serv.'"');
  957. $nom_serv_db = $servicio_db['server_name'];
  958. $app->tform->errorMessage = $app->tform->wordbook['error_no_ip']. 'la IP4 para el servidor ' . $nom_serv_db;
  959. $this->onError();
  960. return true;
  961. }
  962. }
  963. if(!$this->ip6_servidor_bbdd['ip_address']){
  964. $servicio_db = $app->db->queryOneRecord(
  965. 'SELECT server_id, db_server, server_name FROM server
  966. WHERE server_id = "'.$this->bbdd_serv.'"');
  967. $nom_serv_db = $servicio_db['server_name'];
  968. $app->tform->errorMessage = $app->tform->wordbook['error_no_ip']. 'la IP6 para el servidor ' . $nom_serv_db;
  969. $this->onError();
  970. return true;
  971. }
  972. return false;
  973. }
  974. //Comprueba si los servidores asignados al usuario seleccionado tiene los servicios activos para cada caso.
  975. function servidoresActivados(){
  976. global $app, $conf;
  977. $servicio_web = $app->db->queryOneRecord(
  978. 'SELECT server_id, web_server, server_name FROM server
  979. WHERE server_id = "'.$this->web_serv.'"');
  980. $nom_serv_web = $servicio_web['server_name'];
  981. $servicio_dns = $app->db->queryOneRecord(
  982. 'SELECT server_id, dns_server, server_name FROM server
  983. WHERE server_id = "'.$this->dns_serv.'"');
  984. $nom_serv_dns = $servicio_dns['server_name'];
  985. $servicio_ftp = $app->db->queryOneRecord(
  986. 'SELECT server_id, file_server, server_name FROM server
  987. WHERE server_id = "'.$this->ftp_serv.'"');
  988. $nom_serv_ftp = $servicio_ftp['server_name'];
  989. $servicio_db = $app->db->queryOneRecord(
  990. 'SELECT server_id, db_server, server_name FROM server
  991. WHERE server_id = "'.$this->bbdd_serv.'"');
  992. $nom_serv_db = $servicio_db['server_name'];
  993. //print "<pre>Servidor WEB ";print_r($servicio_web);print "</pre>\n";
  994. if($servicio_web['web_server'] == 0){
  995. $app->tform->errorMessage = $app->tform->wordbook['error_activado_servidor'] . $nom_serv_web . ' el servicio WEB.';
  996. $this->onError();
  997. return true;
  998. }
  999. //print "<pre>Servidor DNS ";print_r($servicio_dns);print "</pre>\n";
  1000. if($servicio_dns['dns_server'] == 0){
  1001. $app->tform->errorMessage = $app->tform->wordbook['error_activado_servidor'] . $nom_serv_dns . ' el servicio DNS.';
  1002. $this->onError();
  1003. return true;
  1004. }
  1005. //print "<pre>Servidor FTP ";print_r($servicio_ftp);print "</pre>\n";
  1006. if($servicio_ftp['file_server'] == 0){
  1007. $app->tform->errorMessage = $app->tform->wordbook['error_activado_servidor'] . $nom_serv_ftp . ' el servicio FTP.';
  1008. $this->onError();
  1009. return true;
  1010. }
  1011. //print "<pre>Servidor DB ";print_r($servicio_db);print "</pre>\n";
  1012. if($servicio_db['db_server'] == 0){
  1013. $app->tform->errorMessage = $app->tform->wordbook['error_activado_servidor'] . $nom_serv_db . ' el servicio DB.';
  1014. $this->onError();
  1015. return true;
  1016. }
  1017. return false;
  1018. }
  1019. //Comprobación de que tenemos instalada nuestra plantilla
  1020. function plantillaWebDNS(){
  1021. global $app;
  1022. if(!$app->db->queryOneRecord("SELECT name FROM dns_template WHERE name = 'webdns'")) {
  1023. $app->tform->errorMessage = $app->tform->wordbook['error_plantilla_webdns'];
  1024. $this->onError();
  1025. return true;
  1026. }
  1027. }
  1028. //Comprueba que no exista el dominio y que no tenga sitio web, puede tener sitio web y no tener dns.
  1029. function existeDominio($campos){
  1030. global $app, $conf;
  1031. if($app->db->queryOneRecord('SELECT * FROM dns_soa WHERE origin LIKE "'.$campos['domain'].'."')) {
  1032. $app->tform->errorMessage = $app->tform->wordbook['domain_error_unique'];
  1033. }
  1034. if($app->db->queryOneRecord('SELECT domain_id, domain FROM web_domain WHERE domain = "'.$campos['domain'].'"')) {
  1035. $app->tform->errorMessage = $app->tform->wordbook['error_sitio_web_existe'];
  1036. }
  1037. //IMPORTANTE. AQUI CONTROLAMOS LOS ERRORES QUE SE VALIDAN EN EL FORMULARIO, EN ESTE CASO EL CAMPO DEL DOMINIO.
  1038. if($app->tform->errorMessage)
  1039. {
  1040. $this->onError();
  1041. return true;
  1042. }
  1043. }
  1044. public $ip4_ultima;
  1045. public $ip6_ultima;
  1046. //Creación del las dns y sitio web para un dominio.
  1047. function crearDnsSitioWeb($remoto){
  1048. global $app, $conf;
  1049. $remote = new remote_actions;
  1050. //Carga de los campos del formulario.
  1051. $fields = $app->tform->encode($this->dataRecord, $app->tform->getCurrentTab(), true);
  1052. //Carga del formulario dns_soa para guardar en base de datos.
  1053. $tform_def_file = "../dns/form/dns_soa.tform.php";
  1054. $app->tform->loadFormDef($tform_def_file);
  1055. //Carga y seleccion de dns_template, si no esta creado se informa de que tiene que crearse.
  1056. $template_record = $app->db->queryOneRecord(
  1057. "SELECT * FROM dns_template WHERE visible = 'Y' AND name = 'webdns'"); /*'open6hosting'");*/
  1058. /*print "<pre>DNS SERVER ";print_r($this->dns_serv);print "</pre>\n";
  1059. print "<pre>WEB SERVER ";print_r($this->web_serv);print "</pre>\n";
  1060. print "<pre>IP4 DNS ";print_r($this->ip4_servidor_dns);print "</pre>\n";
  1061. print "<pre>IP6 DNS ";print_r($this->ip6_servidor_dns);print "</pre>\n";
  1062. print "<pre>IP4 WEB ";print_r($this->ip4_servidor_web);print "</pre>\n";
  1063. print "<pre>IP6 WEB ";print_r($this->ip6_servidor_web);print "</pre>\n";*/
  1064. //Si el servidor es el que tiene asignado el cliente o el de admin por defecto, le damos esta ip4
  1065. //if($this->dns_serv && $this->ip4_servidor_dns){
  1066. $this->ip4_ultima = $this->ip4_servidor_dns['ip_address'];
  1067. //}
  1068. //echo(' ips ' . $this->ip4_ultima . ' ip4dns ' . $this->ip4_servidor_dns);
  1069. //if($this->dns_serv && $this->ip6_servidor_dns){
  1070. $this->ip6_ultima = $this->ip6_servidor_dns['ip_address'];
  1071. //}
  1072. //echo(' ip4 ' . $this->ip4_ultima['ip_address'] . ' ip6 ' . $this->ip6_ultima);
  1073. //if($this->web_serv && $this->ip4_servidor_web){
  1074. //$this->ip4_ultima = $this->ip4_servidor_dns;//$this->ip4_servidor_web;
  1075. //}
  1076. //if($this->web_serv && $this->ip6_servidor_web){
  1077. //$this->ip6_ultima = $this->ip4_servidor_dns;//$this->ip6_servidor_web;
  1078. //}
  1079. $tpl_content = $template_record['template'];
  1080. // Reemplazo la variable que nos encontramos en base de datos por el valor que se ha introducido en el formulario
  1081. $tpl_content = str_replace('{DOMAIN}', $fields['domain'], $tpl_content);
  1082. //Carga de los datos en las variables de las ips.
  1083. $tpl_content = str_replace('{IP}', $this->ip4_ultima, $tpl_content);
  1084. $tpl_content = str_replace('{IPV6}', $this->ip6_ultima, $tpl_content);
  1085. $enable_dnssec = 'N';
  1086. // Parse the template
  1087. $tpl_rows = explode("\n", $tpl_content);
  1088. $section = '';
  1089. $vars = array();
  1090. $vars['xfer']='';
  1091. $dns_rr = array();
  1092. foreach($tpl_rows as $row) {
  1093. $row = trim($row);
  1094. if(substr($row, 0, 1) == '[') {
  1095. if($row == '[ZONE]') {
  1096. $section = 'zone';
  1097. } elseif($row == '[DNS_RECORDS]') {
  1098. $section = 'dns_records';
  1099. } else {
  1100. die('Unknown section type');
  1101. }
  1102. } else {
  1103. if($row != '') {
  1104. // Handle zone section
  1105. if($section == 'zone') {
  1106. $parts = explode('=', $row);
  1107. $key = trim($parts[0]);
  1108. $val = trim($parts[1]);
  1109. if($key != '') $vars[$key] = $val;
  1110. }
  1111. // Handle DNS Record rows
  1112. if($section == 'dns_records') {
  1113. $parts = explode('|', $row);
  1114. $dns_rr[] = array(
  1115. 'name' => $parts[1],
  1116. 'type' => $parts[0],
  1117. 'data' => $parts[2],
  1118. 'aux' => $parts[3],
  1119. 'ttl' => $parts[4]
  1120. );
  1121. }
  1122. }
  1123. }
  1124. } // end foreach
  1125. // Insert the soa record
  1126. $sys_userid = $this->cli_id;//$cliente_id_seleccionado;//$fields['client_group_id'];
  1127. $origin = $vars['origin'];
  1128. $ns = $vars['ns'];
  1129. $mbox = str_replace('@', '.', $vars['mbox']);
  1130. $refresh = $vars['refresh'];
  1131. $retry = $vars['retry'];
  1132. $expire = $vars['expire'];
  1133. $minimum = $vars['minimum'];
  1134. $ttl = $vars['ttl'];
  1135. $xfer = $vars['xfer'];
  1136. $also_notify = $vars['also_notify'];
  1137. $update_acl = $vars['update_acl'];
  1138. $serial = $app->validate_dns->increase_serial(0);
  1139. $insert_data = array(
  1140. "sys_userid" => $this->sys_usuario_id,//$sysUsuarioId,//$fields['client_group_id'],
  1141. "sys_groupid" => $this->cli_grupo_id,//$cliente_groupid,//$client_group_id,
  1142. "sys_perm_user" => 'riud',
  1143. "sys_perm_group" => 'riud',
  1144. "sys_perm_other" => '',
  1145. "server_id" => $this->dns_serv,
  1146. "origin" => $origin,
  1147. "ns" => $ns,
  1148. "mbox" => $mbox,
  1149. "serial" => $serial,
  1150. "refresh" => $refresh,
  1151. "retry" => $retry,
  1152. "expire" => $expire,
  1153. "minimum" => $minimum,
  1154. "ttl" => $ttl,
  1155. "active" => 'Y',
  1156. "xfer" => $xfer,
  1157. "also_notify" => $also_notify,
  1158. "update_acl" => $update_acl,
  1159. "dnssec_wanted" => $enable_dnssec
  1160. );
  1161. $dns_soa_id = $app->db->datalogInsert('dns_soa', $insert_data, 'id');
  1162. $remote->dns_soa_after_insert($dns_soa_id, $this->cli_grupo_id);
  1163. // Insert the dns_rr records
  1164. if(is_array($dns_rr) && $dns_soa_id > 0) {
  1165. foreach($dns_rr as $rr) {
  1166. $insert_data = array(
  1167. "sys_userid" => $this->sys_usuario_id,//$sysUsuarioId, //$fields['client_group_id'],
  1168. "sys_groupid" => $this->cli_grupo_id,//$cliente_groupid, //$client_group_id,
  1169. "sys_perm_user" => 'riud',
  1170. "sys_perm_group" => 'riud',
  1171. "sys_perm_other" => '',
  1172. "server_id" => $this->dns_serv,
  1173. "zone" => $dns_soa_id,
  1174. "name" => $rr['name'],
  1175. "type" => $rr['type'],
  1176. "data" => $rr['data'],
  1177. "aux" => $rr['aux'],
  1178. "ttl" => $rr['ttl'],
  1179. "active" => 'Y'
  1180. );
  1181. $dns_rr_id = $app->db->datalogInsert('dns_rr', $insert_data, 'id');
  1182. $remote->dns_rr_after_insert($dns_rr_id, $this->cli_grupo_id);
  1183. }
  1184. }
  1185. //sites_web_domain_add
  1186. $tform_def_file = "../sites/form/web_vhost_domain.tform.php";
  1187. $app->tform->loadFormDef($tform_def_file);
  1188. //print_r($fields);
  1189. //echo('La sesión user id ' . $_SESSION['s']['user']['userid']);
  1190. // add site
  1191. $paramsite = array(
  1192. 'type' => 'vhost',
  1193. 'domain' => $fields['domain'],
  1194. 'server_id' => $this->web_serv,// $web_servidor, //$server_id,//$dns_servidor['default_webserver'],
  1195. //IMPORTANTE. Aquí­ no se ponen los campos sys_userid ni sys_groupid, el evento on_after_insert
  1196. //'sys_userid' => $sysUsuarioId, //$fields['client_group_id'],//$sys_userid,
  1197. //'sys_groupid' => $cliente_groupid,
  1198. 'ip_address' => '*', //$dns_ip_servidor['ip_address'],
  1199. 'ipv6_address' => $this->ip6_servidor_web['ip_address'], //$this->ip6_ultima['ip_address'], //$dns_ip_servidor_ipv6['ip_address'],
  1200. 'traffic_quota' => '-1',
  1201. 'hd_quota' => '0',
  1202. 'cgi' => 'y',
  1203. 'ssi' => 'y',
  1204. 'suexec' => 'y',
  1205. 'ruby' => 'n',
  1206. 'python' => 'n',
  1207. 'perl' => 'n',
  1208. 'errordocs' => '1',
  1209. 'subdomain' => 'www',
  1210. 'php' => 'php-fpm',
  1211. 'fastcgi_php_version' => '',
  1212. 'seo_redirect' => '',
  1213. 'rewrite_to_https' => 'n',
  1214. 'allow_override' => 'All',
  1215. 'http_port' => 80,
  1216. 'https_port' => 443,
  1217. 'apache_directives' => '',
  1218. 'nginx_directives' => '',
  1219. 'php_fpm_use_socket' => 'y',
  1220. 'pm' => 'ondemand',
  1221. 'pm_max_children' => 10,
  1222. 'pm_start_servers' => 1,
  1223. 'pm_min_spare_servers' => 1,
  1224. 'pm_max_spare_servers' => 5,
  1225. 'pm_process_idle_timeout' => 10,
  1226. 'pm_max_requests' => 0,
  1227. 'custom_php_ini' => '',
  1228. 'active' => 'y',
  1229. 'document_root' => '-',
  1230. 'system_user' => '-',
  1231. 'system_group' => '-',
  1232. 'log_retention' => 30,
  1233. 'client_group_id' => $this->cli_grupo_id,//$cliente_groupid, //$client_group_id,
  1234. );
  1235. //print 'Valores: ' . $dns_ip_servidor_ipv6 . " " . $formulario . " Parametros: " ;
  1236. //print "<pre>"; print_r($paramsite); print "</pre>\n";
  1237. /*print '<pre> cliente id ' . $fields['client_id'];
  1238. print "<pre>";print_r($fields);print "</pre>\n";*/
  1239. //print "<pre>Formulario ";print_r($formulario);print "</pre>\n";
  1240. //$this->crearBaseDatosFtp($remote);
  1241. //print 'DNS IPV6 ' . $dns_ip_servidor_ipv6['ip_address'];
  1242. //IMPORTANTE. El último parámetro es para lanzar un evento que llama a la función on_after_insert
  1243. //que prepara los campos document_root, system_user y system_group
  1244. //$site_id = $remoto->insert_query('../sites/form/web_vhost_domain.tform.php', $fields['client_group_id'], $paramsite, 'sites:web_vhost_domain:on_after_insert');
  1245. //IMPORTANTE. ESTE ES EL ÚNICO PLUGING QUE FUNCIONA.
  1246. $site_id = $remoto->insert_query('../sites/form/web_vhost_domain.tform.php',
  1247. $this->cli_id, /*$cliente_id_seleccionado,*/
  1248. $paramsite, 'sites:web_vhost_domain:on_after_insert');
  1249. //print 'Sitio id '. $site_id;
  1250. }
  1251. function onSubmit() {
  1252. global $app, $conf;
  1253. /*$sesionesLog = $_SESSION["s"]["user"]["typ"];
  1254. $sesionesLog2 = $_SESSION["s"]["user"];
  1255. $sesiones = $_SESSION;
  1256. $sesionId = $_SESSION["s"]["id"];*/
  1257. //print_r($sesiones);
  1258. //print('la ssessison es ' .$ssionId);
  1259. //print_r($sesionesLog2);
  1260. if($this->plantillaWebDNS()){
  1261. return;
  1262. }
  1263. //Carga de campos del formulario.
  1264. $fields = $app->tform->encode($this->dataRecord, $app->tform->getCurrentTab(), true);
  1265. //Creo la clase remote para usar las librerias
  1266. $remote = new remote_actions;
  1267. if($this->tieneServidorIPs()){
  1268. return;
  1269. }
  1270. if($this->servidoresActivados()){
  1271. return;
  1272. }
  1273. //------INICIO LIMITES--------------------------------------------------------------------------------------------------
  1274. $limitado = new limites($this->cli_grupo_id);
  1275. $tieneLimitesDNS = $limitado->limClienteDns();
  1276. $tieneLimitesWeb = $limitado->limClienteWebDominio();
  1277. $tieneLimitesDB = $limitado->limClienteDB();
  1278. if($tieneLimitesDNS || $tieneLimitesWeb || $tieneLimitesDB){
  1279. return;
  1280. }
  1281. //------FIN LIMITES-----------------------------------------------------------------------------------------------------
  1282. if($this->existeDominio($fields)){
  1283. return;
  1284. }
  1285. //Esta variable nos llega por jQuery desde el htm para el control de errores en la vista.
  1286. if($_POST['create'] != 1)
  1287. {
  1288. $app->tform->errorMessage = 'DUMMY';
  1289. $app->tpl->setVar($this->dataRecord);
  1290. $this->onShow();
  1291. return;
  1292. }
  1293. if($this->comprobarSubDominios($fields['domain'])){
  1294. $this->crearSubDominio($remote, $fields['domain']);
  1295. if(!$this->subdom_error){
  1296. $this->crearSitioWebSubdominio($remote);
  1297. $this->crearBaseDatosFtp($remote);
  1298. }
  1299. } else {
  1300. if(!$this->dominio_error){
  1301. $this->crearDnsSitioWeb($remote);
  1302. //Si todo va bien, el resultado de la web y dns
  1303. echo '<br><div class="alert alert-success"><br>
  1304. Altas Web y DNS del dominio <b>'.$fields['domain'].'</b>, ¡Creadas correctamente!
  1305. <br><br></div></br>';
  1306. //IMPORTANTE, es necesario cargar nuestro formulario para poder ejecutar la función que crea
  1307. //la base de datos y el ftp ya que hay datos que tomamos de el antes de ejecutarla.
  1308. $app->tform->loadFormDef('form/new_service_webdns.tform.php');
  1309. $this->crearBaseDatosFtp($remote);
  1310. }else{
  1311. $this->onError();
  1312. return;
  1313. }
  1314. }
  1315. }
  1316. }
  1317. class remote_actions extends remoting {
  1318. public function insert_query($formdef_file, $client_id, $params, $event_identifier = '') {
  1319. global $app;
  1320. /*$sql = $this->insertQueryPrepare($formdef_file, $client_id, $params);
  1321. echo(' Query ' . $sql);
  1322. $app->uses('remoting_lib');
  1323. $app->remoting_lib->loadUserProfile();*/
  1324. //return $app->db->query($sql);//$this->insertQueryExecute($sql, $params, $event_identifier);
  1325. //echo(' insertQueryPrepare ' . $this->insertQueryExecute($sql, $params, $event_identifier));
  1326. return $this->insertQueryWebDNS($formdef_file, $client_id, $params, $event_identifier);
  1327. }
  1328. //------------------------------------------------------------------------------------------------------------
  1329. //IMPORTANTE. FUNCIONES EXTRAIDAS Y MODIFICADAS DE ISPCONFIG PARA SOLUCIONAR EL PROBLEMA DE AUTOLOGEO A ADMIN.
  1330. //------------------------------------------------------------------------------------------------------------
  1331. function insertQueryWebDNS($formdef_file, $client_id, $params, $event_identifier = '') {
  1332. //$sql = $app->remoting->insertQueryPrepare($formdef_file, $client_id, $params);
  1333. $sql = $this->insertQueryPrepareWebDNS($formdef_file, $client_id, $params);
  1334. if($sql !== false) return $this->insertQueryExecuteWebDNS($sql, $params, $event_identifier);
  1335. else return false;
  1336. }
  1337. function insertQueryPrepareWebDNS($formdef_file, $client_id, $params) {
  1338. global $app;
  1339. $app->uses('remoting_lib');
  1340. //* load the user profile of the client
  1341. //$app->remoting_lib->loadUserProfile($client_id);
  1342. //* Load the form definition
  1343. $app->remoting_lib->loadFormDef($formdef_file);
  1344. //echo(' Base de datos ' . $app->remoting_lib->loadFormDef($formdef_file));
  1345. //* Get the SQL query
  1346. $sql = $app->remoting_lib->getSQL($params, 'INSERT', 0);
  1347. /*if($app->remoting_lib->errorMessage != '') {
  1348. throw new SoapFault('data_processing_error', $app->remoting_lib->errorMessage);
  1349. return false;
  1350. }*/
  1351. $app->log('Executed insertQueryPrepareWebDNS', LOGLEVEL_DEBUG);
  1352. return $sql;
  1353. }
  1354. function insertQueryExecuteWebDNS($sql, $params, $event_identifier = '') {
  1355. global $app;
  1356. $app->uses('remoting_lib');
  1357. $app->db->query($sql);
  1358. /*if($app->db->errorMessage != '') {
  1359. throw new SoapFault('database_error', $app->db->errorMessage . ' '.$sql);
  1360. return false;
  1361. }*/
  1362. if ( isset($params['_primary_id'] ))
  1363. $insert_id = $params['_primary_id'];
  1364. else
  1365. $insert_id = $app->db->insertID();
  1366. // set a few values for compatibility with tform actions, mostly used by plugins
  1367. $this->id = $insert_id;
  1368. $this->dataRecord = $params;
  1369. $app->log('Executed insertQueryExecute, raising events now if any: ' . $event_identifier, LOGLEVEL_DEBUG);
  1370. if($event_identifier != '') $app->plugin->raiseEvent($event_identifier, $this);
  1371. //$app->uses('tform');
  1372. //* Save changes to Datalog
  1373. if($app->remoting_lib->formDef["db_history"] == 'yes') {
  1374. //$new_rec = $app->remoting_lib->getDataRecord($insert_id);
  1375. $new_rec = $this->getDataRecordWebDNS($insert_id);
  1376. $app->remoting_lib->datalogSave('INSERT', $primary_id, array(), $new_rec);
  1377. }
  1378. return $insert_id;
  1379. }
  1380. function sites_ftp_user_after_insert() {
  1381. global $app, $conf;
  1382. $web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ?", $this->dataRecord["parent_domain_id"]);
  1383. //echo(' Valor FTP ' . $this->dataRecord["parent_domain_id"]);
  1384. $server_id = $app->functions->intval($web["server_id"]);
  1385. $dir = $web["document_root"];
  1386. $uid = $web["system_user"];
  1387. $gid = $web["system_group"];
  1388. // Check system user and group
  1389. if($app->functions->is_allowed_user($uid) == false || $app->functions->is_allowed_group($gid) == false) {
  1390. $app->error('Invalid system user or group');
  1391. }
  1392. // The FTP user shall be owned by the same group then the website
  1393. $sys_groupid = $app->functions->intval($web['sys_groupid']);
  1394. $sql = "UPDATE ftp_user SET server_id = ?, dir = ?, uid = ?, gid = ?, sys_groupid = ? WHERE ftp_user_id = ?";
  1395. $app->db->query($sql, $server_id, $dir, $uid, $gid, $sys_groupid, $this->id);
  1396. }
  1397. function dns_rr_after_insert($dns_rr_id, $cliente_grupo_id) {
  1398. global $app, $conf;
  1399. //echo(' el cliente grupo id ' . $cliente_grupo_id . ' el id tupla en dns_rr ' . $dns_rr_id);
  1400. if($_SESSION["s"]["user"]["typ"] == 'user') {
  1401. $app->db->datalogUpdate('dns_rr', array("sys_userid" => $cliente_grupo_id,
  1402. "sys_groupid" => $cliente_grupo_id), 'id', $dns_rr_id);
  1403. }
  1404. if($_SESSION["s"]["user"]["typ"] == 'admin') {
  1405. $app->db->datalogUpdate('dns_rr', array("sys_userid" => 1, //$cliente_grupo_id,
  1406. "sys_groupid" => $cliente_grupo_id), 'id', $dns_rr_id);
  1407. }
  1408. }
  1409. function dns_soa_after_insert($dns_soa_id, $cliente_grupo_id) {
  1410. global $app, $conf;
  1411. //echo(' el cliente grupo id ' . $cliente_grupo_id . ' el id tupla en dns_rr ' . $dns_soa_id . ' sys usuario ' . $sys_usuario_id);
  1412. if($_SESSION["s"]["user"]["typ"] == 'user') {
  1413. $app->db->datalogUpdate('dns_soa', array("sys_userid" => $cliente_grupo_id,
  1414. "sys_groupid" => $cliente_grupo_id), 'id', $dns_soa_id);
  1415. }
  1416. if($_SESSION["s"]["user"]["typ"] == 'admin') {
  1417. $app->db->datalogUpdate('dns_soa', array("sys_userid" => 1, //$cliente_grupo_id,
  1418. "sys_groupid" => $cliente_grupo_id), 'id', $dns_soa_id);
  1419. }
  1420. }
  1421. function dns_registro_tipo_a_after_insert($cli_grupo_id) {
  1422. global $app, $conf;
  1423. //echo(' el valor zone ' . $this->dataRecord["zone"]);
  1424. //* Set the sys_groupid of the rr record to be the same then the sys_groupid of the soa record
  1425. if($_SESSION["s"]["user"]["typ"] == 'user') {
  1426. $soa = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ? AND " . $this->getAuthSQLWebDNS('r'), $this->dataRecord["zone"]);
  1427. $app->db->datalogUpdate('dns_rr', array("sys_groupid" => $soa['sys_groupid']), 'id', $this->id);
  1428. }
  1429. /*if($_SESSION["s"]["user"]["typ"] == 'admin') {
  1430. $soa = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ? AND " . $this->getAuthSQLWebDNS('r'), $this->dataRecord["zone"]);
  1431. $app->db->datalogUpdate('dns_rr', array("sys_groupid" => $soa['sys_groupid']), 'id', $this->id);
  1432. }*/
  1433. if($app->auth->has_clients($_SESSION['s']['user']['userid'])) {
  1434. $soa = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ? AND " . $this->getAuthSQLWebDNS('r'), $this->dataRecord["zone"]);
  1435. $app->db->datalogUpdate('dns_rr', array("sys_groupid" => $cli_grupo_id), 'id', $this->id);
  1436. }
  1437. //* Update the serial number of the SOA record
  1438. /*$soa_id = $app->functions->intval($_POST["zone"]);
  1439. $serial = $app->validate_dns->increase_serial($soa["serial"]);
  1440. $app->db->datalogUpdate('dns_soa', array("serial" => $serial), 'id', $soa_id);*/
  1441. }
  1442. public function sites_database_user_after_add($client_id, $params){
  1443. global $app, $conf;
  1444. //echo('Plugeando');
  1445. // if($_SESSION["s"]["user"]["typ"] == 'user' /*&& isset($this->dataRecord["client_group_id"])*/) {
  1446. //$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
  1447. $app->db->query("UPDATE web_database_user SET sys_groupid = ?, sys_perm_group = 'riud' WHERE database_user_id = ?", $client_id, $this->id);
  1448. /* }
  1449. if($_SESSION["s"]["user"]["typ"] == 'admin'/* && isset($this->dataRecord["client_group_id"])*///) {
  1450. //echo('Plugeando ' .$app->functions->intval($this->dataRecord["client_group_id"]) . ' y ' . $client_id . ' id ' . $this->id);
  1451. //$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
  1452. /* $app->db->query("UPDATE web_database_user SET sys_groupid = ?, sys_perm_group = 'riud' WHERE database_user_id = ?", $client_id, $this->id);
  1453. }
  1454. if($app->auth->has_clients($_SESSION['s']['user']['userid'])/* && isset($this->dataRecord["client_group_id"])*///) {
  1455. //$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
  1456. /* $app->db->query("UPDATE web_database_user SET sys_groupid = ?, sys_perm_group = 'riud' WHERE database_user_id = ?", $client_id, $this->id);
  1457. }
  1458. $app->uses('sites_web_database_user_plugin');
  1459. global $app;
  1460. //Register for the events
  1461. $app->plugin->registerEvent('sites:web_database_user:on_after_update', 'sites_web_database_user_plugin', 'sites_web_database_user_edit');
  1462. $app->plugin->registerEvent('sites:web_database_user:on_after_insert', 'sites_web_database_user_plugin', 'sites_web_database_user_edit');
  1463. */
  1464. }
  1465. public function sites_database_user_add($session_id, $client_id, $params, $event_identifier = '') {
  1466. global $app;
  1467. /*if(!$this->checkPerm($session_id, 'sites_database_user_add')) {
  1468. throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
  1469. return false;
  1470. }*/
  1471. //echo(' la tablita ' . $this->formDef['db_table']);
  1472. return $this->insertQueryWebDNS('../sites/form/database_user.tform.php', $client_id, $params, $event_identifier);
  1473. }
  1474. function getDataRecordWebDNS($primary_id) {
  1475. global $app;
  1476. $escape = '`';
  1477. //$this->loadUserProfile();
  1478. if(@is_numeric($primary_id)) {
  1479. if($primary_id > 0) {
  1480. // Return a single record
  1481. //return $this->getDataRecordPadreWebDNS($primary_id);
  1482. return $app->tform->getDataRecord($primary_id);
  1483. //return parent::getDataRecord($primary_id);
  1484. } elseif($primary_id == -1) {
  1485. // Return a array with all records
  1486. $sql = "SELECT * FROM ??";
  1487. return $app->db->queryAllRecords($sql, $this->formDef['db_table']);
  1488. } else {
  1489. throw new SoapFault('invalid_id', 'The ID has to be > 0 or -1.');
  1490. return array();
  1491. }
  1492. } elseif (@is_array($primary_id) || @is_object($primary_id)) {
  1493. if(@is_object($primary_id)) $primary_id = get_object_vars($primary_id); // do not use cast (array)xxx because it returns private and protected properties!
  1494. $sql_offset = 0;
  1495. $sql_limit = 0;
  1496. $sql_where = '';
  1497. $params = array($this->formDef['db_table']);
  1498. foreach($primary_id as $key => $val) {
  1499. if($key == '#OFFSET#') $sql_offset = $app->functions->intval($val);
  1500. elseif($key == '#LIMIT#') $sql_limit = $app->functions->intval($val);
  1501. elseif(stristr($val, '%')) {
  1502. $sql_where .= "?? like ? AND ";
  1503. } else {
  1504. $sql_where .= "?? = ? AND ";
  1505. }
  1506. $params[] = $key;
  1507. $params[] = $val;
  1508. }
  1509. $sql_where = substr($sql_where, 0, -5);
  1510. if($sql_where == '') $sql_where = '1';
  1511. //$sql = "SELECT * FROM ?? WHERE ".$sql_where. " AND " . $this->getAuthSQLWebDNS('r', $this->formDef['db_table']);
  1512. $sql = "SELECT * FROM ?? WHERE ".$sql_where. " AND " . $this->getAuthSQL('r', $this->formDef['db_table']);
  1513. if($sql_offset >= 0 && $sql_limit > 0) $sql .= ' LIMIT ' . $sql_offset . ',' . $sql_limit;
  1514. return $app->db->queryAllRecords($sql, true, $params);
  1515. } else {
  1516. $this->errorMessage = 'The ID must be either an integer or an array.';
  1517. return array();
  1518. }
  1519. }
  1520. /*function getDataRecordPadreWebDNS($primary_id) {
  1521. global $app;
  1522. $escape = '`';
  1523. $sql = "SELECT * FROM ?? WHERE ?? = ? AND ".$this->getAuthSQLWebDNS('r', $this->formDef['db_table']);
  1524. return $app->db->queryOneRecord($sql, $this->formDef['db_table'], $this->formDef['db_table_idx'], $primary_id);
  1525. }*/
  1526. function getAuthSQLWebDNS($perm, $table = '') {
  1527. if($_SESSION["s"]["user"]["typ"] == 'admin' || $_SESSION['s']['user']['mailuser_id'] > 0) {
  1528. return '1';
  1529. } else {
  1530. if ($table != ''){
  1531. $table = ' ' . $table . '.';
  1532. }
  1533. $groups = ( $_SESSION["s"]["user"]["groups"] ) ? $_SESSION["s"]["user"]["groups"] : 0;
  1534. $sql = '(';
  1535. $sql .= "(" . $table . "sys_userid = ".$_SESSION["s"]["user"]["userid"]." AND " . $table . "sys_perm_user like '%$perm%') OR ";
  1536. $sql .= "(" . $table . "sys_groupid IN (".$groups.") AND " . $table ."sys_perm_group like '%$perm%') OR ";
  1537. $sql .= $table . "sys_perm_other like '%$perm%'";
  1538. $sql .= ')';
  1539. return $sql;
  1540. }
  1541. }
  1542. //----------------------------------------------------------------------------------
  1543. //IMPORTANTE. ESTA FUNCION ES COMO LO HACE ISPCONFIG NO EXTRAIDA PERO SI MODIFICADA.
  1544. //----------------------------------------------------------------------------------
  1545. public function sites_database_add($client_id, $params){
  1546. global $app, $conf;
  1547. //IMPORTANTE. PARA QUE EL PLUGING FUNCIONE HAY QUE CARGAR ANTES EL FORMULARIO
  1548. //DE LO QUE SE QUIERE CREAR EN ESTE CASO SITIO WEB
  1549. $tform_def_file = "../sites/form/database.tform.php";
  1550. $app->tform->loadFormDef($tform_def_file);
  1551. $app->remoting_lib->loadFormDef('../sites/form/database.tform.php');
  1552. //$app->tform->formDef('../sites/form/database.tform.php');
  1553. //$sql = $app->remoting->insertQueryPrepare('../sites/form/database.tform.php', $client_id, $params);
  1554. $sql = $this->insertQueryPrepareWebDNS('../sites/form/database.tform.php', $client_id, $params);
  1555. if($sql !== false) {
  1556. $app->uses('sites_database_plugin');
  1557. //print_r($sql);
  1558. $this->id = 0;
  1559. $this->dataRecord = $params;
  1560. //$app->uses('sites_database_plugin');
  1561. //$app->sites_database_plugin->processDatabaseInsert($this);
  1562. //$retval = $this->insertQueryExecute($sql, $params);
  1563. $retval = $this->insertQueryExecuteWebDNS($sql, $params);
  1564. $app->sites_database_plugin->processDatabaseInsert($this);
  1565. //$app->plugin->raiseEvent('sites:web_database:on_after_insert', $this);
  1566. // set correct values for backup_interval and backup_copies
  1567. /*if(isset($params['backup_interval']) || isset($params['backup_copies'])){
  1568. $sql_set = array();
  1569. if(isset($params['backup_interval'])) $sql_set[] = "backup_interval = '".$app->db->quote($params['backup_interval'])."'";
  1570. if(isset($params['backup_copies'])) $sql_set[] = "backup_copies = ".$app->functions->intval($params['backup_copies']);
  1571. //$app->db->query("UPDATE web_database SET ".implode(', ', $sql_set)." WHERE database_id = ".$retval);
  1572. $this->updateQueryExecute("UPDATE web_database SET ".implode(', ', $sql_set)." WHERE database_id = ".$retval, $retval, $params);
  1573. }*/
  1574. return $retval;
  1575. }
  1576. return false;
  1577. }
  1578. }
  1579. $page = new page_action;
  1580. $page->onLoad();
  1581. //IMPORTENTE, es necesario estas lí­neas para que el botón del pdf funcione. Activa el javascript
  1582. //echo '<script type="text/javascript">';
  1583. //echo '</script>';
  1584. ?>
  1585. <!--IMPORTENTE, es necesario estas lí­neas para que el botón del pdf funcione. Activa el javascript -->
  1586. <script type="text/javascript">
  1587. </script>