ISPConfig module for simplify the creation of websites and DNS zones in a only step
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

1939 lines
78 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.
  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 lanzo yo.
  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. function controlUserGrupoId(){
  441. global $app, $conf;
  442. $fields = $app->tform->encode($this->dataRecord, $app->tform->getCurrentTab(), true);
  443. //* Client: If the logged in user is not admin and has no sub clients (no reseller)
  444. if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) {
  445. $this->cli_id = $_SESSION["s"]["user"]["client_id"];
  446. $this->cli_grupo_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
  447. $this->sys_usuario_id = $_SESSION["s"]["user"]["sys_userid"];
  448. $this->sys_grupo_id = $_SESSION["s"]["user"]["sys_groupid"];
  449. //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);
  450. } else {
  451. //Captura de los distintos ids del cliente y usuario de sistema.
  452. //combinando un query a las dos tablas sys_group y sys_user que comparten el client_id.
  453. //print "<pre>Seleccionado: "; print_r($fields['client_group_id']); print "</pre>\n";
  454. if($fields['client_group_id']==0) {
  455. //En la tabla sys_user el client_id 0 es admin. En sys_group este valor es 0
  456. $this->cli_id = 0;
  457. $this->cli_grupo_id = 1;
  458. $this->sys_usuario_id = 1;//$this->cli_id;
  459. $this->sys_grupo_id = 0; //$this->cli_grupo_id;//0
  460. //echo('Quien es ' . $_SESSION["s"]["user"]["typ"]);
  461. }else{
  462. //echo('Quien es else ' . $_SESSION["s"]["user"]["typ"]);
  463. $client = $app->db->queryOneRecord(
  464. 'SELECT sys_user.userid, sys_user.sys_userid, sys_user.sys_groupid, sys_user.default_group, sys_user.client_id
  465. FROM sys_group, sys_user
  466. WHERE sys_group.client_id = sys_user.client_id and sys_group.groupid = ?', $fields['client_group_id']);
  467. $this->cli_id = $client['client_id'];
  468. $this->cli_grupo_id = $client['default_group'];
  469. $this->sys_usuario_id = $client['userid'];//$client['sys_userid'];
  470. $this->sys_grupo_id = $this->cli_grupo_id;//$client['sys_groupid'];
  471. //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);
  472. }
  473. }
  474. //print "<pre>Valores : "; print_r($this->cli_id); print "</pre>\n";
  475. //print " cli_id " . $this->cli_id . ' cli_grupo ' . $this->cli_grupo_id . ' sys_usuario ' . $this->sys_usuario_id . ' sys grupo ' . $this->sys_grupo_id;
  476. }
  477. //Crear subdominio
  478. function crearSubDominio($remoto, $campoSubDominio){
  479. global $app, $conf;
  480. $fields = $app->tform->encode($this->dataRecord, $app->tform->getCurrentTab(), true);
  481. //COMO LE PASO EL DOMINIO CORRECTO NO ES NECESARIO PONER EL % EN LA SQL AÑADO EL PUNTO.
  482. //EL PROBLEMA ES QUE CON UN DOMINIO .COM TOMA POR VALIDO UN .CO POR EL %
  483. //NO --> ('SELECT server_id, name FROM dns_rr WHERE name LIKE "'.$this->dominio.'%"');
  484. $existeDominioParaSubDominio = $app->db->queryOneRecord(
  485. 'SELECT server_id, name FROM dns_rr WHERE name LIKE "'.$this->dominio.'."');
  486. // print "<pre>En crearSubDominio campo que se le pasa subdominio es: "; print_r($campoSubDominio); print "</pre>\n";
  487. //Compruebo que el subdominio no existe consultando la tabla web_domain.
  488. $existeSubDominioWeb = $app->db->queryOneRecord(
  489. 'SELECT domain_id, domain FROM web_domain
  490. WHERE domain = "'.$campoSubDominio.'"');
  491. //Compruebo que el subdominio no existe consultando la tabla dns_rr
  492. $existeSubDominioTipoA = $app->db->queryOneRecord(
  493. 'SELECT name, type FROM dns_rr
  494. WHERE name = "'.$campoSubDominio.'" AND type = "A"');
  495. if(!$existeDominioParaSubDominio['name']){
  496. $this->subdom_error = true;
  497. $app->tform->errorMessage = $app->tform->wordbook['error_no_existe_dominio_padre'];
  498. // print "<pre>Error En crearSubDominio campo comprobacion dns_rr es: "; print_r($existeDominioParaSubDominio); print "</pre>\n";
  499. $this->onError();
  500. return;
  501. }
  502. // print "<pre>En crearSubDominio campo comprobacion dns_rr es: "; print_r($existeDominioParaSubDominio); print "</pre>\n";
  503. //print '<pre>El Sub existe '. $existeSubDominio['domain'];
  504. if($existeSubDominioWeb['domain']){
  505. $this->subdom_error = true;
  506. $app->tform->errorMessage = $app->tform->wordbook['error_no_existe_dominio_padre'];
  507. $this->onError();
  508. return $this->subdom_error;
  509. }
  510. if($existeSubDominioTipoA['name']){
  511. $this->subdom_error = true;
  512. $app->tform->errorMessage = $app->tform->wordbook['error_no_existe_dominio_padre'];
  513. $this->onError();
  514. return $this->subdom_error;
  515. }
  516. //$camDominio = $app->db->queryOneRecord('SELECT domain_id, domain FROM domain WHERE domain = "'.$this->dominio.'"');
  517. $camDominio = $app->db->queryOneRecord('SELECT origin FROM dns_soa WHERE origin LIKE "'.$this->dominio.'."');
  518. //$camDominio = $app->db->queryOneRecord('SELECT origin FROM dns_soa WHERE origin LIKE "'.$campoSubDominio.'%"');
  519. $camDnsRR = $app->db->queryOneRecord('SELECT server_id, zone FROM dns_rr WHERE name LIKE "'.$this->dominio.'."');
  520. //Para los registros tipo A la ip tiene que ser tipo IPv4
  521. $camServIP = $app->db->queryOneRecord(
  522. "SELECT ip_address FROM server_ip
  523. WHERE server_id = ".$camDnsRR['server_id']." AND ip_type='IPv4'");
  524. //print_r($camDominio);
  525. //print_r($camDnsRR);
  526. //Si el dominio NO existe mostramos mensaje de error y salimos de la ejecución
  527. if(!$camDominio['origin']){
  528. $this->subdom_error = true;
  529. $app->tform->errorMessage = $app->tform->wordbook['error_no_existe_dominio_padre'];
  530. $this->onError();
  531. //return;
  532. //print 'No existe el dominio';
  533. return $this->subdom_error;
  534. } else {
  535. //Parametros para la creación de subdominios
  536. $paramSubDominios = array(
  537. 'server_id' => $camDnsRR['server_id'],
  538. 'zone' => $camDnsRR['zone'],
  539. 'name' => $this->subdominio,
  540. 'type' => 'a',
  541. 'data' => $camServIP['ip_address'],
  542. //'aux' => '0',
  543. 'ttl' => '3600',
  544. 'active' => 'y',
  545. //comento el campo stamp, ya que introducia solo ceros en la bbdd
  546. //'stamp' => time(),
  547. 'serial' => '1',
  548. );
  549. //echo ('<br>El client_id GLOBAL ' . $this->cli_id . " <br>");
  550. // client group id
  551. /*$res = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = ".$app->functions->intval($fields['client_group_id']));
  552. $client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);//$res['groupid'];
  553. echo ('El client group id seleccion ' . $client_group_id . " <br>");
  554. echo ('El groupid de la tabla sys_group ' . $res['groupid'] . " ");*/
  555. //print "<pre>"; print_r($paramSubDominios); print "</pre>\n";
  556. //Inserto en bbdd usando la clase remoto que se la he pasado en parámetros de la función
  557. //$resultado = $remoto->insert_query('../dns/form/dns_a.tform.php', $fields['client_id'], $paramSubDominios);
  558. $resultado = $remoto->insert_query('form/dns_a_webdns.tform.php', $this->cli_id, /*$fields['client_group_id'],*/ $paramSubDominios);
  559. $remoto->dns_registro_tipo_a_after_insert($this->cli_grupo_id);
  560. echo '<br><div class="alert alert-success"><br>
  561. Se ha dado de alta Web y Subdominio, <b>'.$this->subdominio.'</b>, ¡Correctamente!
  562. <br><br></div></br>';
  563. //$this->onShow();
  564. }
  565. }
  566. function crearSitioWebSubdominio($remoto){
  567. global $app, $conf;
  568. $fields = $app->tform->encode($this->dataRecord, $app->tform->getCurrentTab(), true);
  569. /* print "<pre>DNS SERVER ";print_r($this->dns_serv);print "</pre>\n";
  570. print "<pre>WEB SERVER ";print_r($this->web_serv);print "</pre>\n";
  571. print "<pre>IP4 DNS ";print_r($this->ip4_servidor_dns);print "</pre>\n";
  572. print "<pre>IP6 DNS ";print_r($this->ip6_servidor_dns);print "</pre>\n";
  573. print "<pre>IP4 WEB ";print_r($this->ip4_servidor_web);print "</pre>\n";
  574. print "<pre>IP6 WEB ";print_r($this->ip6_servidor_web);print "</pre>\n";
  575. print "<pre>IP6 WEB LA OTRA ";print_r($this->ip6_ultima['ip_address']);print "</pre>\n";
  576. */
  577. //add site
  578. $paramsite = array(
  579. //"sys_userid" => $this->sys_usuario_id,
  580. //"sys_groupid" => $this->cli_grupo_id,
  581. 'type' => 'vhost',
  582. 'domain' => $fields['domain'], //$this->subdominio,
  583. 'server_id' => $this->web_serv, //$server_id,
  584. 'ip_address' => '*',
  585. 'ipv6_address' =>$this->ip6_servidor_web['ip_address'],
  586. 'traffic_quota' => '-1',
  587. 'hd_quota' => '0',
  588. 'cgi' => 'y',
  589. 'ssi' => 'y',
  590. 'suexec' => 'y',
  591. 'ruby' => 'n',
  592. 'python' => 'n',
  593. 'perl' => 'n',
  594. 'errordocs' => '1',
  595. 'subdomain' => '',
  596. 'php' => 'php-fpm',
  597. 'fastcgi_php_version' => '',
  598. 'seo_redirect' => '',
  599. 'rewrite_to_https' => 'n',
  600. 'allow_override' => 'All',
  601. 'http_port' => 80,
  602. 'https_port' => 443,
  603. 'apache_directives' => '',
  604. 'nginx_directives' => '',
  605. 'php_fpm_use_socket' => 'y',
  606. 'pm' => 'ondemand',
  607. 'pm_max_children' => 10,
  608. 'pm_start_servers' => 1,
  609. 'pm_min_spare_servers' => 1,
  610. 'pm_max_spare_servers' => 5,
  611. 'pm_process_idle_timeout' => 10,
  612. 'pm_max_requests' => 0,
  613. 'custom_php_ini' => '',
  614. 'active' => 'y',
  615. 'document_root' => '-',
  616. 'system_user' => '-',
  617. 'system_group' => '-',
  618. 'log_retention' => 30,
  619. 'client_group_id' => $this->cli_grupo_id, //$client_group_id,
  620. );
  621. //print "<pre> Parametros:"; print_r($paramsite); print "</pre>\n";
  622. /*print '<pre> cliente id ' . $fields['client_id'];
  623. print "<pre>";print_r($fields);print "</pre>\n" . $fields['client_id'];*/
  624. //print '<pre>DNS IPV6 ' . $dns_ip_servidor_ipv6['ip_address'];
  625. //IMPORTANTE. PARA QUE EL PLUGING FUNCIONE HAY QUE CARGAR ANTES EL FORMULARIO
  626. //DE LO QUE SE QUIERE CREAR EN ESTE CASO SITIO WEB
  627. $tform_def_file = "../sites/form/web_vhost_domain.tform.php";
  628. $app->tform->loadFormDef($tform_def_file);
  629. //El último parámetro es para lanzar un evento que llama a la función on_after_insert que prepara
  630. //los campos document_root, system_user y system_group
  631. //$site_id = $remoto->insert_query('../sites/form/web_vhost_domain.tform.php', $fields['client_group_id'], $paramsite, 'sites:web_vhost_domain:on_after_insert');
  632. $site_id = $remoto->insert_query('../sites/form/web_vhost_domain.tform.php',
  633. $this->cli_id, /*$cliente_id_seleccionado,*/
  634. $paramsite, 'sites:web_vhost_domain:on_after_insert');
  635. //IMPORTANTE. HAY QUE CARGAR EL FORMULARIO DE WEBDNS PARA QUE ENCUENTRE EL TAB.
  636. $tform_def_file = "form/new_service_webdns.tform.php";
  637. $app->tform->loadFormDef($tform_def_file);
  638. }
  639. public $ip4_servidor_dns;
  640. public $ip6_servidor_dns;
  641. public $ip4_servidor_web;
  642. public $ip6_servidor_web;
  643. public $ip4_servidor_bbdd;
  644. public $ip6_servidor_bbdd;
  645. public $ip4_servidor_ftp;
  646. public $ip6_servidor_ftp;
  647. public $dns_serv;
  648. public $web_serv;
  649. public $bbdd_serv;
  650. public $ftp_serv;
  651. function tieneServidorIPs(){
  652. global $app, $conf;
  653. $this->controlUserGrupoId();
  654. $app->uses('getconf');
  655. $global_config_sitio = $app->getconf->get_global_config('sites');
  656. $global_config_dns = $app->getconf->get_global_config('dns');
  657. if(!$global_config_dns['default_dnsserver']) {
  658. $app->tform->errorMessage = $app->tform->wordbook['error_no_servidor_default']. 'DNS.';
  659. $this->onError();
  660. return true;
  661. } else if(!$global_config_sitio['default_webserver']) {
  662. $app->tform->errorMessage = $app->tform->wordbook['error_no_servidor_default']. 'WEB.';
  663. $this->onError();
  664. return true;
  665. } else if(!$global_config_sitio['default_dbserver']) {
  666. $app->tform->errorMessage = $app->tform->wordbook['error_no_servidor_default']. 'DB.';
  667. $this->onError();
  668. return true;
  669. }
  670. //print "<pre>WEB SERVER por defecto ";print_r($global_config_sitio);print "</pre>\n";
  671. //print "<pre>DNS SERVER por defecto ";print_r($global_config_dns);print "</pre>\n";
  672. //El cliente 1 es admin.
  673. //Recupero los servidores asignados por defecto y se los asigno a admin o al usuario
  674. //que no tenga asignado ninguno.
  675. if($this->cli_id == 0) {
  676. $this->dns_serv = $global_config_dns['default_dnsserver'];//1;
  677. $this->web_serv = $global_config_sitio['default_webserver'];//1;
  678. $this->bbdd_serv = $global_config_sitio['default_dbserver'];//1;
  679. $this->ftp_serv = $global_config_sitio['default_webserver'];//1;
  680. //print "<pre>tieneServidorIPs el cli_id "; print_r($this->cli_id . ' el servidor ' . $this->dns_serv); print "</pre>\n";
  681. }else{
  682. $servidores = $app->db->queryOneRecord(
  683. "SELECT client_id, dns_servers, web_servers, db_servers FROM client
  684. WHERE client_id = ". $this->cli_id);
  685. $this->dns_serv = $servidores['dns_servers'];
  686. $this->web_serv = $servidores['web_servers'];
  687. $this->bbdd_serv = $servidores['db_servers'];
  688. //para el ftp el servidor es el mismo que para el sitio web.
  689. $this->ftp_serv = $servidores['web_servers'];
  690. //Si el cliente no tiene asignado un servidor se añade por defecto al 1
  691. if(!$this->dns_serv){
  692. $this->dns_serv = $global_config_dns['default_dnsserver'];//1;
  693. }
  694. //Si el cliente no tiene asignado un servidor se añade por defecto al 1
  695. if(!$this->web_serv){
  696. $this->web_serv = $global_config_sitio['default_webserver'];//1;
  697. }
  698. //Si el cliente no tiene asignado un servidor se añade por defecto al 1
  699. if(!$this->bbdd_serv){
  700. $this->bbdd_serv = $global_config_sitio['default_dbserver'];//1;
  701. }
  702. //Si el cliente no tiene asignado un servidor se añade por defecto al 1
  703. if(!$this->ftp_serv){
  704. $this->ftp_serv = $global_config_sitio['default_webserver'];//1;
  705. }
  706. }
  707. /*print "<pre>DNS SERVER ";print_r($this->dns_serv);print "</pre>\n";
  708. print "<pre>WEB SERVER ";print_r($this->web_serv);print "</pre>\n";
  709. print "<pre>DB SERVER ";print_r($this->bbdd_serv);print "</pre>\n";
  710. print "<pre>FTP SERVER ";print_r($this->ftp_serv);print "</pre>\n";*/
  711. //El cliente 1 es admin
  712. //Captura de las ips del servidor dns
  713. if($this->cli_id == 0){
  714. //Compruebo si hay datos para el client_id 0 y si no existe pruebo con el 1.
  715. //Alguno de los dos tiene que existir por configuración de ispconfig.
  716. $this->ip4_servidor_dns = $app->db->queryOneRecord(
  717. 'SELECT ip_type, ip_address FROM server_ip
  718. WHERE client_id = "0" AND server_id = "'.$this->dns_serv.'" AND ip_type="IPv4"');
  719. $this->ip6_servidor_dns = $app->db->queryOneRecord(
  720. 'SELECT ip_type, ip_address FROM server_ip
  721. WHERE client_id = "0" AND server_id = "'.$this->dns_serv.'" AND ip_type="IPv6"');
  722. if(!$this->ip4_servidor_dns){
  723. $this->ip4_servidor_dns = $app->db->queryOneRecord(
  724. 'SELECT ip_type, ip_address FROM server_ip
  725. WHERE client_id = "1" AND server_id = "'.$this->dns_serv.'" AND ip_type="IPv4"');
  726. }
  727. if(!$this->ip6_servidor_dns){
  728. $this->ip6_servidor_dns = $app->db->queryOneRecord(
  729. 'SELECT ip_type, ip_address FROM server_ip
  730. WHERE client_id = "1" AND server_id = "'.$this->dns_serv.'" AND ip_type="IPv6"');
  731. }
  732. }else{//Comprobamos si el cliente tiene servidor asignado, si no lo tiene asignamos el que admin a seleccionado
  733. //para este servidor.
  734. $this->ip4_servidor_dns = $app->db->queryOneRecord(
  735. 'SELECT ip_type, ip_address
  736. FROM server_ip
  737. WHERE client_id = "'.$this->cli_id.'" AND server_id = "'.$this->dns_serv.'" AND ip_type="IPv4"');
  738. $this->ip6_servidor_dns = $app->db->queryOneRecord(
  739. 'SELECT ip_type, ip_address
  740. FROM server_ip
  741. WHERE client_id = "'.$this->cli_id.'" AND server_id = "'.$this->dns_serv.'"AND ip_type="IPv6"');
  742. //si no tiene asignado le damos el de admin.
  743. if(!$this->ip4_servidor_dns){
  744. //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
  745. //Tomamos las de admin.
  746. //Alguno de los dos tiene que existir por configuración de ispconfig.
  747. $this->ip4_servidor_dns = $app->db->queryOneRecord(
  748. 'SELECT ip_type, ip_address FROM server_ip
  749. WHERE client_id = "0" AND server_id = "'.$this->dns_serv.'" AND ip_type="IPv4"');
  750. if(!$this->ip4_servidor_dns){
  751. $this->ip4_servidor_dns = $app->db->queryOneRecord(
  752. 'SELECT ip_type, ip_address FROM server_ip
  753. WHERE client_id = "1" AND server_id = "'.$this->dns_serv.'" AND ip_type="IPv4"');
  754. }
  755. }
  756. if(!$this->ip6_servidor_dns){
  757. //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
  758. //Tomamos las de admin.
  759. //Alguno de los dos tiene que existir por configuración de ispconfig.
  760. //$this->ip4_servidor_dns = $app->db->queryOneRecord('SELECT ip_type, ip_address FROM server_ip WHERE client_id = "0" AND ip_type="IPv4"');
  761. $this->ip6_servidor_dns = $app->db->queryOneRecord(
  762. 'SELECT ip_type, ip_address FROM server_ip
  763. WHERE client_id = "0" AND server_id = "'.$this->dns_serv.'" AND ip_type="IPv6"');
  764. if(!$this->ip6_servidor_dns){
  765. $this->ip6_servidor_dns = $app->db->queryOneRecord(
  766. 'SELECT ip_type, ip_address FROM server_ip
  767. WHERE client_id = "1" AND server_id = "'.$this->dns_serv.'" AND ip_type="IPv6"');
  768. }
  769. }
  770. }
  771. //Captura de las ips del servidor web
  772. if($this->cli_id == 0){
  773. //Compruebo si hay datos para el client_id 0 y si no existe pruebo con el 1.
  774. //Alguno de los dos tiene que existir por configuración de ispconfig.
  775. $this->ip4_servidor_web = $app->db->queryOneRecord(
  776. 'SELECT ip_type, ip_address FROM server_ip
  777. WHERE client_id = "0" AND server_id = "'.$this->web_serv.'" AND ip_type="IPv4"');
  778. $this->ip6_servidor_web = $app->db->queryOneRecord(
  779. 'SELECT ip_type, ip_address FROM server_ip
  780. WHERE client_id = "0" AND server_id = "'.$this->web_serv.'" AND ip_type="IPv6"');
  781. /*if(!$this->ip4_servidor_web){
  782. $this->ip4_servidor_web = $app->db->queryOneRecord(
  783. 'SELECT ip_type, ip_address FROM server_ip
  784. WHERE client_id = "1" AND server_id = "'.$this->web_serv.'" AND ip_type="IPv4"');
  785. }
  786. if(!$this->ip6_servidor_web){
  787. $this->ip6_servidor_web = $app->db->queryOneRecord(
  788. 'SELECT ip_type, ip_address FROM server_ip
  789. WHERE client_id = "1" AND server_id = "'.$this->web_serv.'" AND ip_type="IPv6"');
  790. }*/
  791. }else{//Comprobamos si el cliente tiene servidor asignado
  792. $this->ip4_servidor_web = $app->db->queryOneRecord(
  793. 'SELECT ip_type, ip_address
  794. FROM server_ip
  795. WHERE client_id = "'.$this->cli_id.'" AND server_id = "'.$this->web_serv.'" AND ip_type="IPv4"');
  796. $this->ip6_servidor_web = $app->db->queryOneRecord(
  797. 'SELECT ip_type, ip_address
  798. FROM server_ip
  799. WHERE client_id = "'.$this->cli_id.'" AND server_id = "'.$this->web_serv.'"AND ip_type="IPv6"');
  800. //si no tiene asignado le damos el de admin.
  801. if(!$this->ip4_servidor_web){
  802. $this->ip4_servidor_web = $app->db->queryOneRecord(
  803. 'SELECT ip_type, ip_address FROM server_ip
  804. WHERE client_id = "0" AND server_id = "'.$this->web_serv.'" AND ip_type="IPv4"');
  805. /*if(!$this->ip4_servidor_web){
  806. $this->ip4_servidor_web = $app->db->queryOneRecord(
  807. 'SELECT ip_type, ip_address FROM server_ip
  808. WHERE client_id = "1" AND server_id = "'.$this->web_serv.'" AND ip_type="IPv4"');
  809. }*/
  810. }
  811. if(!$this->ip6_servidor_web){
  812. $this->ip6_servidor_web = $app->db->queryOneRecord(
  813. 'SELECT ip_type, ip_address FROM server_ip
  814. WHERE client_id = "0" AND server_id = "'.$this->web_serv.'" AND ip_type="IPv6"');
  815. /*if(!$this->ip6_servidor_web){
  816. $this->ip6_servidor_web = $app->db->queryOneRecord(
  817. 'SELECT ip_type, ip_address FROM server_ip
  818. WHERE client_id = "1" AND server_id = "'.$this->web_serv.'" AND ip_type="IPv6"');
  819. }*/
  820. }
  821. }
  822. //Captura de las ips del servidor bbdd
  823. if($this->cli_id == 0){
  824. //Compruebo si hay datos para el client_id 0 y si no existe pruebo con el 1.
  825. //Alguno de los dos tiene que existir por configuración de ispconfig.
  826. $this->ip4_servidor_bbdd = $app->db->queryOneRecord(
  827. 'SELECT ip_type, ip_address FROM server_ip
  828. WHERE client_id = "0" AND server_id = "'.$this->bbdd_serv.'" AND ip_type="IPv4"');
  829. $this->ip6_servidor_bbdd = $app->db->queryOneRecord(
  830. 'SELECT ip_type, ip_address FROM server_ip
  831. WHERE client_id = "0" AND server_id = "'.$this->bbdd_serv.'" AND ip_type="IPv6"');
  832. /*if(!$this->ip4_servidor_bbdd){
  833. $this->ip4_servidor_bbdd = $app->db->queryOneRecord(
  834. 'SELECT ip_type, ip_address FROM server_ip
  835. WHERE client_id = "1" AND server_id = "'.$this->bbdd_serv.'" AND ip_type="IPv4"');
  836. }
  837. if(!$this->ip6_servidor_bbdd){
  838. $this->ip6_servidor_bbdd = $app->db->queryOneRecord(
  839. 'SELECT ip_type, ip_address FROM server_ip
  840. WHERE client_id = "1" AND server_id = "'.$this->bbdd_serv.'" AND ip_type="IPv6"');
  841. }*/
  842. }else{//Comprobamos si el cliente tiene servidor asignado
  843. $this->ip4_servidor_bbdd = $app->db->queryOneRecord(
  844. 'SELECT ip_type, ip_address
  845. FROM server_ip
  846. WHERE client_id = "'.$this->cli_id.'" AND server_id = "'.$this->bbdd_serv.'" AND ip_type="IPv4"');
  847. $this->ip6_servidor_bbdd = $app->db->queryOneRecord(
  848. 'SELECT ip_type, ip_address
  849. FROM server_ip
  850. WHERE client_id = "'.$this->cli_id.'" AND server_id = "'.$this->bbdd_serv.'"AND ip_type="IPv6"');
  851. //si no tiene asignado le damos el de admin.
  852. if(!$this->ip4_servidor_bbdd){
  853. //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
  854. //Tomamos las de admin.
  855. //Alguno de los dos tiene que existir por configuración de ispconfig.
  856. $this->ip4_servidor_bbdd = $app->db->queryOneRecord(
  857. 'SELECT ip_type, ip_address FROM server_ip
  858. WHERE client_id = "0" AND server_id = "'.$this->bbdd_serv.'" AND ip_type="IPv4"');
  859. /*if(!$this->ip4_servidor_bbdd){
  860. $this->ip4_servidor_bbdd = $app->db->queryOneRecord(
  861. 'SELECT ip_type, ip_address FROM server_ip
  862. WHERE client_id = "1" AND server_id = "'.$this->bbdd_serv.'" AND ip_type="IPv4"');
  863. }*/
  864. }
  865. if(!$this->ip6_servidor_bbdd){
  866. $this->ip6_servidor_bbdd = $app->db->queryOneRecord(
  867. 'SELECT ip_type, ip_address FROM server_ip
  868. WHERE client_id = "0" AND server_id = "'.$this->bbdd_serv.'" AND ip_type="IPv6"');
  869. /*if(!$this->ip6_servidor_bbdd){
  870. $this->ip6_servidor_bbdd = $app->db->queryOneRecord(
  871. 'SELECT ip_type, ip_address FROM server_ip
  872. WHERE client_id = "1" AND server_id = "'.$this->bbdd_serv.'" AND ip_type="IPv6"');
  873. }*/
  874. }
  875. }
  876. //para el servidor ftp no se hacen comprobaciones
  877. //ya que las ips son las mismas que para el servidor web.
  878. //$la_ip4 = $app->db->queryOneRecord("SELECT ip_type, ip_address FROM server_ip WHERE ip_type='IPv4'");
  879. $this->ip4_pdf = $this->ip4_servidor_dns['ip_address'];//$dns_ip_servidor['ip_address'];//$la_ip4['ip_address'];
  880. /*print "<pre>IP4 DNS ";print_r($this->ip4_servidor_dns);print "</pre>\n";
  881. print "<pre>IP6 DNS ";print_r($this->ip6_servidor_dns);print "</pre>\n";
  882. print "<pre>IP4 WEB ";print_r($this->ip4_servidor_web);print "</pre>\n";
  883. print "<pre>IP6 WEB ";print_r($this->ip6_servidor_web);print "</pre>\n";
  884. print "<pre>IP4 BBDD ";print_r($this->ip4_servidor_bbdd);print "</pre>\n";
  885. print "<pre>IP6 BBDD ";print_r($this->ip6_servidor_bbdd);print "</pre>\n";
  886. echo('El cliente ' . $this->cli_id . '<br>');*/
  887. if(!$this->ip4_servidor_dns['ip_address']){
  888. $servicio_dns = $app->db->queryOneRecord(
  889. 'SELECT server_id, dns_server, server_name FROM server
  890. WHERE server_id = "'.$this->dns_serv.'"');
  891. $nom_serv_dns = $servicio_dns['server_name'];
  892. $app->tform->errorMessage = $app->tform->wordbook['error_no_ip']. 'la IP4 para el servidor ' . $nom_serv_dns;
  893. $this->onError();
  894. return true;
  895. }
  896. if(!$this->ip6_servidor_dns['ip_address']){
  897. $servicio_dns = $app->db->queryOneRecord(
  898. 'SELECT server_id, dns_server, server_name FROM server
  899. WHERE server_id = "'.$this->dns_serv.'"');
  900. $nom_serv_dns = $servicio_dns['server_name'];
  901. $app->tform->errorMessage = $app->tform->wordbook['error_no_ip']. 'la IP6 para el servidor '. $nom_serv_dns;
  902. $this->onError();
  903. return true;
  904. }
  905. if(!$this->ip4_servidor_web['ip_address']){
  906. $servidor_web = $app->db->queryOneRecord(
  907. 'SELECT server_id, web_server, server_name FROM server
  908. WHERE server_id = "'.$this->web_serv.'"');
  909. $nom_serv_web = $servidor_web['server_name'];
  910. $app->tform->errorMessage = $app->tform->wordbook['error_no_ip']. 'la IP4 para el servidor ' . $nom_serv_web;
  911. $this->onError();
  912. return true;
  913. }
  914. if(!$this->ip6_servidor_web['ip_address']){
  915. $servidor_web = $app->db->queryOneRecord(
  916. 'SELECT server_id, web_server, server_name FROM server
  917. WHERE server_id = "'.$this->web_serv.'"');
  918. $nom_serv_web = $servidor_web['server_name'];
  919. $app->tform->errorMessage = $app->tform->wordbook['error_no_ip']. 'la IP6 para el servidor ' . $nom_serv_web;
  920. $this->onError();
  921. return true;
  922. }
  923. if(!$this->ip4_servidor_bbdd['ip_address']){
  924. $servicio_db = $app->db->queryOneRecord(
  925. 'SELECT server_id, db_server, server_name FROM server
  926. WHERE server_id = "'.$this->bbdd_serv.'"');
  927. $nom_serv_db = $servicio_db['server_name'];
  928. $app->tform->errorMessage = $app->tform->wordbook['error_no_ip']. 'la IP4 para el servidor ' . $nom_serv_db;
  929. $this->onError();
  930. return true;
  931. }
  932. if(!$this->ip6_servidor_bbdd['ip_address']){
  933. $servicio_db = $app->db->queryOneRecord(
  934. 'SELECT server_id, db_server, server_name FROM server
  935. WHERE server_id = "'.$this->bbdd_serv.'"');
  936. $nom_serv_db = $servicio_db['server_name'];
  937. $app->tform->errorMessage = $app->tform->wordbook['error_no_ip']. 'la IP6 para el servidor ' . $nom_serv_db;
  938. $this->onError();
  939. return true;
  940. }
  941. return false;
  942. }
  943. //Comprueba si los servidores asignados al usuario seleccionado tiene los servicios activos para cada caso.
  944. function servidoresActivados(){
  945. global $app, $conf;
  946. $servicio_web = $app->db->queryOneRecord(
  947. 'SELECT server_id, web_server, server_name FROM server
  948. WHERE server_id = "'.$this->web_serv.'"');
  949. $nom_serv_web = $servicio_web['server_name'];
  950. $servicio_dns = $app->db->queryOneRecord(
  951. 'SELECT server_id, dns_server, server_name FROM server
  952. WHERE server_id = "'.$this->dns_serv.'"');
  953. $nom_serv_dns = $servicio_dns['server_name'];
  954. $servicio_ftp = $app->db->queryOneRecord(
  955. 'SELECT server_id, file_server, server_name FROM server
  956. WHERE server_id = "'.$this->ftp_serv.'"');
  957. $nom_serv_ftp = $servicio_ftp['server_name'];
  958. $servicio_db = $app->db->queryOneRecord(
  959. 'SELECT server_id, db_server, server_name FROM server
  960. WHERE server_id = "'.$this->bbdd_serv.'"');
  961. $nom_serv_db = $servicio_db['server_name'];
  962. //print "<pre>Servidor WEB ";print_r($servicio_web);print "</pre>\n";
  963. if($servicio_web['web_server'] == 0){
  964. $app->tform->errorMessage = $app->tform->wordbook['error_activado_servidor'] . $nom_serv_web . ' el servicio WEB.';
  965. $this->onError();
  966. return true;
  967. }
  968. //print "<pre>Servidor DNS ";print_r($servicio_dns);print "</pre>\n";
  969. if($servicio_dns['dns_server'] == 0){
  970. $app->tform->errorMessage = $app->tform->wordbook['error_activado_servidor'] . $nom_serv_dns . ' el servicio DNS.';
  971. $this->onError();
  972. return true;
  973. }
  974. //print "<pre>Servidor FTP ";print_r($servicio_ftp);print "</pre>\n";
  975. if($servicio_ftp['file_server'] == 0){
  976. $app->tform->errorMessage = $app->tform->wordbook['error_activado_servidor'] . $nom_serv_ftp . ' el servicio FTP.';
  977. $this->onError();
  978. return true;
  979. }
  980. //print "<pre>Servidor DB ";print_r($servicio_db);print "</pre>\n";
  981. if($servicio_db['db_server'] == 0){
  982. $app->tform->errorMessage = $app->tform->wordbook['error_activado_servidor'] . $nom_serv_db . ' el servicio DB.';
  983. $this->onError();
  984. return true;
  985. }
  986. /*$servidores = $app->db->queryAllRecords(
  987. 'SELECT server_id, server_name, web_server, dns_server, file_server, db_server FROM server');
  988. foreach($servidores as $servidor){
  989. $serv_web = $servidor['web_server'];
  990. $serv_dns = $servidor['dns_server'];
  991. $serv_ftp = $servidor['file_server'];
  992. $serv_db = $servidor['db_server'];
  993. $nombre_server = $servidor['server_name'];
  994. //print "<pre>Todos los servidores ";print_r($servidor);print "</pre>\n";
  995. //Si alguno de los servidores no esta activo, mostramos error.
  996. if($serv_web == 0){
  997. $app->tform->errorMessage = $app->tform->wordbook['error_activado_servidor'] . $nombre_server . ' el servicio WEB';
  998. $this->onError();
  999. return true;
  1000. } else if($serv_dns == 0){
  1001. $app->tform->errorMessage = $app->tform->wordbook['error_activado_servidor'] . $nombre_server . ' el servicio DNS';
  1002. $this->onError();
  1003. return true;
  1004. } else if($serv_ftp == 0){
  1005. $app->tform->errorMessage = $app->tform->wordbook['error_activado_servidor'] . $nombre_server . ' el servicio FTP';
  1006. $this->onError();
  1007. return true;
  1008. } else if($serv_db == 0){
  1009. $app->tform->errorMessage = $app->tform->wordbook['error_activado_servidor'] . $nombre_server . ' el servicio DB';
  1010. $this->onError();
  1011. return true;
  1012. }*/
  1013. //}
  1014. return false;
  1015. }
  1016. //Comprobación de que tenemos instalada nuestra plantilla
  1017. function plantillaWebDNS(){
  1018. global $app;
  1019. if(!$app->db->queryOneRecord("SELECT name FROM dns_template WHERE name = 'webdns'")) {
  1020. $app->tform->errorMessage = $app->tform->wordbook['error_plantilla_webdns'];
  1021. $this->onError();
  1022. return true;
  1023. }
  1024. }
  1025. //Comprueba que no exista el dominio y que no tenga sitio web, puede tener sitio web y no tener dns.
  1026. function existeDominio($campos){
  1027. global $app, $conf;
  1028. if($app->db->queryOneRecord('SELECT * FROM dns_soa WHERE origin LIKE "'.$campos['domain'].'."')) {
  1029. $app->tform->errorMessage = $app->tform->wordbook['domain_error_unique'];
  1030. }
  1031. if($app->db->queryOneRecord('SELECT domain_id, domain FROM web_domain WHERE domain = "'.$campos['domain'].'"')) {
  1032. $app->tform->errorMessage = $app->tform->wordbook['error_sitio_web_existe'];
  1033. }
  1034. //IMPORTANTE. AQUI CONTROLAMOS LOS ERRORES QUE SE VALIDAN EN EL FORMULARIO, EN ESTE CASO EL CAMPO DEL DOMINIO.
  1035. if($app->tform->errorMessage)
  1036. {
  1037. $this->onError();
  1038. return true;
  1039. }
  1040. }
  1041. public $ip4_ultima;
  1042. public $ip6_ultima;
  1043. //Creación del las dns y sitio web para un dominio.
  1044. function crearDnsSitioWeb($remoto){
  1045. global $app, $conf;
  1046. $remote = new remote_actions;
  1047. //Carga de los campos del formulario.
  1048. $fields = $app->tform->encode($this->dataRecord, $app->tform->getCurrentTab(), true);
  1049. //Carga del formulario dns_soa para guardar en base de datos.
  1050. $tform_def_file = "../dns/form/dns_soa.tform.php";
  1051. $app->tform->loadFormDef($tform_def_file);
  1052. //Carga y seleccion de dns_template, si no esta creado se informa de que tiene que crearse.
  1053. $template_record = $app->db->queryOneRecord(
  1054. "SELECT * FROM dns_template WHERE visible = 'Y' AND name = 'webdns'"); /*'open6hosting'");*/
  1055. /*print "<pre>DNS SERVER ";print_r($this->dns_serv);print "</pre>\n";
  1056. print "<pre>WEB SERVER ";print_r($this->web_serv);print "</pre>\n";
  1057. print "<pre>IP4 DNS ";print_r($this->ip4_servidor_dns);print "</pre>\n";
  1058. print "<pre>IP6 DNS ";print_r($this->ip6_servidor_dns);print "</pre>\n";
  1059. print "<pre>IP4 WEB ";print_r($this->ip4_servidor_web);print "</pre>\n";
  1060. print "<pre>IP6 WEB ";print_r($this->ip6_servidor_web);print "</pre>\n";*/
  1061. //Si el servidor es el que tiene asignado el cliente o el de admin por defecto, le damos esta ip4
  1062. if($this->dns_serv && $this->ip4_servidor_dns){
  1063. $this->ip4_ultima = $this->ip4_servidor_dns;
  1064. }
  1065. if($this->dns_serv && $this->ip6_servidor_dns){
  1066. $this->ip6_ultima = $this->ip6_servidor_dns;
  1067. }
  1068. if($this->web_serv && $this->ip4_servidor_web){
  1069. $this->ip4_ultima = $this->ip4_servidor_web;
  1070. }
  1071. if($this->web_serv && $this->ip6_servidor_web){
  1072. $this->ip6_ultima = $this->ip6_servidor_web;
  1073. }
  1074. $tpl_content = $template_record['template'];
  1075. // Reemplazo la variable que nos encontramos en base de datos por el valor que se ha introducido en el formulario
  1076. $tpl_content = str_replace('{DOMAIN}', $fields['domain'], $tpl_content);
  1077. //Carga de los datos en las variables de las ips.
  1078. $tpl_content = str_replace('{IP}', $this->ip4_ultima['ip_address'],/*$dns_ip_servidor['ip_address'],*/ $tpl_content);
  1079. $tpl_content = str_replace('{IPV6}', $this->ip6_ultima['ip_address'], /*$dns_ip_servidor_ipv6['ip_address'],*/ $tpl_content);
  1080. $enable_dnssec = 'N';//(($_POST['dns_dnssec'] == 'Y') ? 'Y' : 'N');
  1081. // Parse the template
  1082. $tpl_rows = explode("\n", $tpl_content);
  1083. $section = '';
  1084. $vars = array();
  1085. $vars['xfer']='';
  1086. $dns_rr = array();
  1087. foreach($tpl_rows as $row) {
  1088. $row = trim($row);
  1089. if(substr($row, 0, 1) == '[') {
  1090. if($row == '[ZONE]') {
  1091. $section = 'zone';
  1092. } elseif($row == '[DNS_RECORDS]') {
  1093. $section = 'dns_records';
  1094. } else {
  1095. die('Unknown section type');
  1096. }
  1097. } else {
  1098. if($row != '') {
  1099. // Handle zone section
  1100. if($section == 'zone') {
  1101. $parts = explode('=', $row);
  1102. $key = trim($parts[0]);
  1103. $val = trim($parts[1]);
  1104. if($key != '') $vars[$key] = $val;
  1105. }
  1106. // Handle DNS Record rows
  1107. if($section == 'dns_records') {
  1108. $parts = explode('|', $row);
  1109. $dns_rr[] = array(
  1110. 'name' => $parts[1],
  1111. 'type' => $parts[0],
  1112. 'data' => $parts[2],
  1113. 'aux' => $parts[3],
  1114. 'ttl' => $parts[4]
  1115. );
  1116. }
  1117. }
  1118. }
  1119. } // end foreach
  1120. // Insert the soa record
  1121. $sys_userid = $this->cli_id;//$cliente_id_seleccionado;//$fields['client_group_id'];
  1122. $origin = $vars['origin'];
  1123. $ns = $vars['ns'];
  1124. $mbox = str_replace('@', '.', $vars['mbox']);
  1125. $refresh = $vars['refresh'];
  1126. $retry = $vars['retry'];
  1127. $expire = $vars['expire'];
  1128. $minimum = $vars['minimum'];
  1129. $ttl = $vars['ttl'];
  1130. $xfer = $vars['xfer'];
  1131. $also_notify = $vars['also_notify'];
  1132. $update_acl = $vars['update_acl'];
  1133. $serial = $app->validate_dns->increase_serial(0);
  1134. $insert_data = array(
  1135. "sys_userid" => $this->sys_usuario_id,//$sysUsuarioId,//$fields['client_group_id'],
  1136. "sys_groupid" => $this->cli_grupo_id,//$cliente_groupid,//$client_group_id,
  1137. "sys_perm_user" => 'riud',
  1138. "sys_perm_group" => 'riud',
  1139. "sys_perm_other" => '',
  1140. "server_id" => $this->dns_serv, //$dns_servidor,//$server_id,//$dns_servidor, //$server_id,//$dns_servidor['default_dnsserver'],
  1141. "origin" => $origin,
  1142. "ns" => $ns,
  1143. "mbox" => $mbox,
  1144. "serial" => $serial,
  1145. "refresh" => $refresh,
  1146. "retry" => $retry,
  1147. "expire" => $expire,
  1148. "minimum" => $minimum,
  1149. "ttl" => $ttl,
  1150. "active" => 'Y',
  1151. "xfer" => $xfer,
  1152. "also_notify" => $also_notify,
  1153. "update_acl" => $update_acl,
  1154. "dnssec_wanted" => $enable_dnssec
  1155. );
  1156. $dns_soa_id = $app->db->datalogInsert('dns_soa', $insert_data, 'id');
  1157. $remote->dns_soa_after_insert($dns_soa_id, $this->cli_grupo_id);
  1158. // Insert the dns_rr records
  1159. if(is_array($dns_rr) && $dns_soa_id > 0) {
  1160. foreach($dns_rr as $rr) {
  1161. $insert_data = array(
  1162. "sys_userid" => $this->sys_usuario_id,//$sysUsuarioId, //$fields['client_group_id'],
  1163. "sys_groupid" => $this->cli_grupo_id,//$cliente_groupid, //$client_group_id,
  1164. "sys_perm_user" => 'riud',
  1165. "sys_perm_group" => 'riud',
  1166. "sys_perm_other" => '',
  1167. "server_id" => $this->dns_serv,
  1168. "zone" => $dns_soa_id,
  1169. "name" => $rr['name'],
  1170. "type" => $rr['type'],
  1171. "data" => $rr['data'],
  1172. "aux" => $rr['aux'],
  1173. "ttl" => $rr['ttl'],
  1174. "active" => 'Y'
  1175. );
  1176. $dns_rr_id = $app->db->datalogInsert('dns_rr', $insert_data, 'id');
  1177. $remote->dns_rr_after_insert($dns_rr_id, $this->cli_grupo_id);
  1178. }
  1179. }
  1180. //sites_web_domain_add
  1181. $tform_def_file = "../sites/form/web_vhost_domain.tform.php";
  1182. $app->tform->loadFormDef($tform_def_file);
  1183. //print_r($fields);
  1184. //echo('La sesión user id ' . $_SESSION['s']['user']['userid']);
  1185. // add site
  1186. $paramsite = array(
  1187. 'type' => 'vhost',
  1188. 'domain' => $fields['domain'],
  1189. 'server_id' => $this->web_serv,// $web_servidor, //$server_id,//$dns_servidor['default_webserver'],
  1190. //IMPORTANTE. Aquí­ no se ponen los campos sys_userid ni sys_groupid, el evento on_after_insert
  1191. //'sys_userid' => $sysUsuarioId, //$fields['client_group_id'],//$sys_userid,
  1192. //'sys_groupid' => $cliente_groupid,
  1193. 'ip_address' => '*', //$dns_ip_servidor['ip_address'],
  1194. 'ipv6_address' => $this->ip6_servidor_web['ip_address'], //$this->ip6_ultima['ip_address'], //$dns_ip_servidor_ipv6['ip_address'],
  1195. 'traffic_quota' => '-1',
  1196. 'hd_quota' => '0',
  1197. 'cgi' => 'y',
  1198. 'ssi' => 'y',
  1199. 'suexec' => 'y',
  1200. 'ruby' => 'n',
  1201. 'python' => 'n',
  1202. 'perl' => 'n',
  1203. 'errordocs' => '1',
  1204. 'subdomain' => 'www',
  1205. 'php' => 'php-fpm',
  1206. 'fastcgi_php_version' => '',
  1207. 'seo_redirect' => '',
  1208. 'rewrite_to_https' => 'n',
  1209. 'allow_override' => 'All',
  1210. 'http_port' => 80,
  1211. 'https_port' => 443,
  1212. 'apache_directives' => '',
  1213. 'nginx_directives' => '',
  1214. 'php_fpm_use_socket' => 'y',
  1215. 'pm' => 'ondemand',
  1216. 'pm_max_children' => 10,
  1217. 'pm_start_servers' => 1,
  1218. 'pm_min_spare_servers' => 1,
  1219. 'pm_max_spare_servers' => 5,
  1220. 'pm_process_idle_timeout' => 10,
  1221. 'pm_max_requests' => 0,
  1222. 'custom_php_ini' => '',
  1223. 'active' => 'y',
  1224. 'document_root' => '-',
  1225. 'system_user' => '-',
  1226. 'system_group' => '-',
  1227. 'log_retention' => 30,
  1228. 'client_group_id' => $this->cli_grupo_id,//$cliente_groupid, //$client_group_id,
  1229. );
  1230. //print 'Valores: ' . $dns_ip_servidor_ipv6 . " " . $formulario . " Parametros: " ;
  1231. //print "<pre>"; print_r($paramsite); print "</pre>\n";
  1232. /*print '<pre> cliente id ' . $fields['client_id'];
  1233. print "<pre>";print_r($fields);print "</pre>\n";*/
  1234. //print "<pre>Formulario ";print_r($formulario);print "</pre>\n";
  1235. //$this->crearBaseDatosFtp($remote);
  1236. //print 'DNS IPV6 ' . $dns_ip_servidor_ipv6['ip_address'];
  1237. //IMPORTANTE. El último parámetro es para lanzar un evento que llama a la función on_after_insert
  1238. //que prepara los campos document_root, system_user y system_group
  1239. //$site_id = $remoto->insert_query('../sites/form/web_vhost_domain.tform.php', $fields['client_group_id'], $paramsite, 'sites:web_vhost_domain:on_after_insert');
  1240. //IMPORTANTE. ESTE ES EL ÚNICO PLUGING QUE FUNCIONA.
  1241. $site_id = $remoto->insert_query('../sites/form/web_vhost_domain.tform.php',
  1242. $this->cli_id, /*$cliente_id_seleccionado,*/
  1243. $paramsite, 'sites:web_vhost_domain:on_after_insert');
  1244. //print 'Sitio id '. $site_id;
  1245. }
  1246. function onSubmit() {
  1247. global $app, $conf;
  1248. /*$sesionesLog = $_SESSION["s"]["user"]["typ"];
  1249. $sesionesLog2 = $_SESSION["s"]["user"];
  1250. $sesiones = $_SESSION;
  1251. $sesionId = $_SESSION["s"]["id"];*/
  1252. //print_r($sesiones);
  1253. //print('la ssessison es ' .$ssionId);
  1254. //print_r($sesionesLog2);
  1255. //echo('(Sub)Prefix ' . $this->valor_prefix . '(Sub)Prefix ftp ' . $this->valor_prefix_ftp );
  1256. if($this->plantillaWebDNS()){
  1257. return;
  1258. }
  1259. //Carga de campos del formulario.
  1260. $fields = $app->tform->encode($this->dataRecord, $app->tform->getCurrentTab(), true);
  1261. //Creo la clase remote para usar las librerias
  1262. $remote = new remote_actions;
  1263. /*$sitiosBoom = new sitios_remoting;
  1264. $sitiosBoom->test();*/
  1265. if($this->tieneServidorIPs()){
  1266. return;
  1267. }
  1268. if($this->servidoresActivados()){
  1269. return;
  1270. }
  1271. //------INICIO LIMITES--------------------------------------------------------------------------------------------------
  1272. $limitado = new limites($this->cli_grupo_id);
  1273. $tieneLimitesDNS = $limitado->limClienteDns();
  1274. $tieneLimitesWeb = $limitado->limClienteWebDominio();
  1275. $tieneLimitesDB = $limitado->limClienteDB();
  1276. if($tieneLimitesDNS || $tieneLimitesWeb || $tieneLimitesDB){
  1277. return;
  1278. }
  1279. //------FIN LIMITES-----------------------------------------------------------------------------------------------------
  1280. if($this->existeDominio($fields)){
  1281. return;
  1282. }
  1283. //Esta variable nos llega por jQuery desde el htm para el control de errores en la vista.
  1284. if($_POST['create'] != 1)
  1285. {
  1286. $app->tform->errorMessage = 'DUMMY';
  1287. $app->tpl->setVar($this->dataRecord);
  1288. $this->onShow();
  1289. return;
  1290. }
  1291. /*echo ('Lo seleccionado ' . $fields['client_group_id'] . " <br>");
  1292. echo ('Tabla sys_group --> client id ' . $this->cli_id . " <br>");
  1293. echo ('Tabla sys_group --> groupid ' . $this->cli_grupo_id . " <br>");
  1294. echo ('Tabla sys_user --> userid ' . $this->sys_usuario_id . " <br>");
  1295. echo ('Tabla sys_user --> sys_groupid ' . $this->sys_grupo_id . " <br>");*/
  1296. //print "Subdomino: " . $this->subdomino . "</p>\n Dominio: " . $this->domino;
  1297. if($this->comprobarSubDominios($fields['domain'])){
  1298. $this->crearSubDominio($remote, $fields['domain']);
  1299. if(!$this->subdom_error){
  1300. $this->crearSitioWebSubdominio($remote);
  1301. //if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])){
  1302. // $this->crearBaseDatosFtpClientes($remote);
  1303. //}else{
  1304. $this->crearBaseDatosFtp($remote);
  1305. //}
  1306. }
  1307. } else {
  1308. if(!$this->dominio_error){
  1309. $this->crearDnsSitioWeb($remote);
  1310. //$variablePHP = "<script> document.write(test) </script>";
  1311. //Si todo va bien, el resultado de la web y dns
  1312. echo '<br><div class="alert alert-success"><br>
  1313. Altas Web y DNS del dominio <b>'.$fields['domain'].'</b>, ¡Creadas correctamente!
  1314. <br><br></div></br>';
  1315. //IMPORTANTE, es necesario cargar nuestro formulario para poder ejecutar la función que crea
  1316. //la base de datos y el ftp ya que hay datos que tomamos de el antes de ejecutarla.
  1317. $app->tform->loadFormDef('form/new_service_webdns.tform.php');
  1318. //if(!$app->auth->is_admin()){
  1319. //if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])){
  1320. //$this->crearBaseDatosFtpClientes($remote);
  1321. //}else{
  1322. //echo('Esto es mental ' . $app->auth->is_admin());
  1323. $this->crearBaseDatosFtp($remote);
  1324. //}
  1325. //}
  1326. }else{
  1327. $this->onError();
  1328. return;
  1329. }
  1330. }
  1331. //parent::onSubmit();
  1332. }
  1333. }
  1334. /*class sitios_remoting extends remoting_sites {
  1335. public function test(){
  1336. echo('Texto test');
  1337. }
  1338. }*/
  1339. class remote_actions extends remoting {
  1340. public function insert_query($formdef_file, $client_id, $params, $event_identifier = '') {
  1341. global $app;
  1342. /*$sql = $this->insertQueryPrepare($formdef_file, $client_id, $params);
  1343. echo(' Query ' . $sql);
  1344. $app->uses('remoting_lib');
  1345. $app->remoting_lib->loadUserProfile();*/
  1346. //return $app->db->query($sql);//$this->insertQueryExecute($sql, $params, $event_identifier);
  1347. //echo(' insertQueryPrepare ' . $this->insertQueryExecute($sql, $params, $event_identifier));
  1348. return $this->insertQueryWebDNS($formdef_file, $client_id, $params, $event_identifier);
  1349. }
  1350. function insertQueryWebDNS($formdef_file, $client_id, $params, $event_identifier = '') {
  1351. //$sql = $app->remoting->insertQueryPrepare($formdef_file, $client_id, $params);
  1352. $sql = $this->insertQueryPrepareWebDNS($formdef_file, $client_id, $params);
  1353. if($sql !== false) return $this->insertQueryExecuteWebDNS($sql, $params, $event_identifier);
  1354. else return false;
  1355. }
  1356. function insertQueryPrepareWebDNS($formdef_file, $client_id, $params) {
  1357. global $app;
  1358. $app->uses('remoting_lib');
  1359. //* load the user profile of the client
  1360. //$app->remoting_lib->loadUserProfile($client_id);
  1361. //* Load the form definition
  1362. $app->remoting_lib->loadFormDef($formdef_file);
  1363. //echo(' Base de datos ' . $app->remoting_lib->loadFormDef($formdef_file));
  1364. //* Get the SQL query
  1365. $sql = $app->remoting_lib->getSQL($params, 'INSERT', 0);
  1366. /*if($app->remoting_lib->errorMessage != '') {
  1367. throw new SoapFault('data_processing_error', $app->remoting_lib->errorMessage);
  1368. return false;
  1369. }*/
  1370. $app->log('Executed insertQueryPrepareWebDNS', LOGLEVEL_DEBUG);
  1371. return $sql;
  1372. }
  1373. function insertQueryExecuteWebDNS($sql, $params, $event_identifier = '') {
  1374. global $app;
  1375. $app->uses('remoting_lib');
  1376. $app->db->query($sql);
  1377. /*if($app->db->errorMessage != '') {
  1378. throw new SoapFault('database_error', $app->db->errorMessage . ' '.$sql);
  1379. return false;
  1380. }*/
  1381. if ( isset($params['_primary_id'] ))
  1382. $insert_id = $params['_primary_id'];
  1383. else
  1384. $insert_id = $app->db->insertID();
  1385. // set a few values for compatibility with tform actions, mostly used by plugins
  1386. $this->id = $insert_id;
  1387. $this->dataRecord = $params;
  1388. $app->log('Executed insertQueryExecute, raising events now if any: ' . $event_identifier, LOGLEVEL_DEBUG);
  1389. if($event_identifier != '') $app->plugin->raiseEvent($event_identifier, $this);
  1390. //$app->uses('tform');
  1391. //* Save changes to Datalog
  1392. if($app->remoting_lib->formDef["db_history"] == 'yes') {
  1393. //$new_rec = $app->remoting_lib->getDataRecord($insert_id);
  1394. $new_rec = $this->getDataRecordWebDNS($insert_id);
  1395. $app->remoting_lib->datalogSave('INSERT', $primary_id, array(), $new_rec);
  1396. }
  1397. return $insert_id;
  1398. }
  1399. function sites_ftp_user_after_insert() {
  1400. global $app, $conf;
  1401. $web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ?", $this->dataRecord["parent_domain_id"]);
  1402. //echo(' Valor FTP ' . $this->dataRecord["parent_domain_id"]);
  1403. $server_id = $app->functions->intval($web["server_id"]);
  1404. $dir = $web["document_root"];
  1405. $uid = $web["system_user"];
  1406. $gid = $web["system_group"];
  1407. // Check system user and group
  1408. if($app->functions->is_allowed_user($uid) == false || $app->functions->is_allowed_group($gid) == false) {
  1409. $app->error('Invalid system user or group');
  1410. }
  1411. // The FTP user shall be owned by the same group then the website
  1412. $sys_groupid = $app->functions->intval($web['sys_groupid']);
  1413. $sql = "UPDATE ftp_user SET server_id = ?, dir = ?, uid = ?, gid = ?, sys_groupid = ? WHERE ftp_user_id = ?";
  1414. $app->db->query($sql, $server_id, $dir, $uid, $gid, $sys_groupid, $this->id);
  1415. }
  1416. function dns_rr_after_insert($dns_rr_id, $cliente_grupo_id) {
  1417. global $app, $conf;
  1418. //echo(' el cliente grupo id ' . $cliente_grupo_id . ' el id tupla en dns_rr ' . $dns_rr_id);
  1419. if($_SESSION["s"]["user"]["typ"] == 'user') {
  1420. $app->db->datalogUpdate('dns_rr', array("sys_userid" => $cliente_grupo_id,
  1421. "sys_groupid" => $cliente_grupo_id), 'id', $dns_rr_id);
  1422. }
  1423. if($_SESSION["s"]["user"]["typ"] == 'admin') {
  1424. $app->db->datalogUpdate('dns_rr', array("sys_userid" => 1, //$cliente_grupo_id,
  1425. "sys_groupid" => $cliente_grupo_id), 'id', $dns_rr_id);
  1426. }
  1427. }
  1428. function dns_soa_after_insert($dns_soa_id, $cliente_grupo_id) {
  1429. global $app, $conf;
  1430. //echo(' el cliente grupo id ' . $cliente_grupo_id . ' el id tupla en dns_rr ' . $dns_soa_id . ' sys usuario ' . $sys_usuario_id);
  1431. if($_SESSION["s"]["user"]["typ"] == 'user') {
  1432. $app->db->datalogUpdate('dns_soa', array("sys_userid" => $cliente_grupo_id,
  1433. "sys_groupid" => $cliente_grupo_id), 'id', $dns_soa_id);
  1434. }
  1435. if($_SESSION["s"]["user"]["typ"] == 'admin') {
  1436. $app->db->datalogUpdate('dns_soa', array("sys_userid" => 1, //$cliente_grupo_id,
  1437. "sys_groupid" => $cliente_grupo_id), 'id', $dns_soa_id);
  1438. }
  1439. }
  1440. function dns_registro_tipo_a_after_insert($cli_grupo_id) {
  1441. global $app, $conf;
  1442. //echo(' el valor zone ' . $this->dataRecord["zone"]);
  1443. //* Set the sys_groupid of the rr record to be the same then the sys_groupid of the soa record
  1444. if($_SESSION["s"]["user"]["typ"] == 'user') {
  1445. $soa = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ? AND " . $this->getAuthSQLWebDNS('r'), $this->dataRecord["zone"]);
  1446. $app->db->datalogUpdate('dns_rr', array("sys_groupid" => $soa['sys_groupid']), 'id', $this->id);
  1447. }
  1448. /*if($_SESSION["s"]["user"]["typ"] == 'admin') {
  1449. $soa = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ? AND " . $this->getAuthSQLWebDNS('r'), $this->dataRecord["zone"]);
  1450. $app->db->datalogUpdate('dns_rr', array("sys_groupid" => $soa['sys_groupid']), 'id', $this->id);
  1451. }*/
  1452. if($app->auth->has_clients($_SESSION['s']['user']['userid'])) {
  1453. $soa = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ? AND " . $this->getAuthSQLWebDNS('r'), $this->dataRecord["zone"]);
  1454. $app->db->datalogUpdate('dns_rr', array("sys_groupid" => $cli_grupo_id), 'id', $this->id);
  1455. }
  1456. //* Update the serial number of the SOA record
  1457. /*$soa_id = $app->functions->intval($_POST["zone"]);
  1458. $serial = $app->validate_dns->increase_serial($soa["serial"]);
  1459. $app->db->datalogUpdate('dns_soa', array("serial" => $serial), 'id', $soa_id);*/
  1460. }
  1461. public function sites_database_user_after_add($client_id, $params){
  1462. global $app, $conf;
  1463. //echo('Plugeando');
  1464. // if($_SESSION["s"]["user"]["typ"] == 'user' /*&& isset($this->dataRecord["client_group_id"])*/) {
  1465. //$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
  1466. $app->db->query("UPDATE web_database_user SET sys_groupid = ?, sys_perm_group = 'riud' WHERE database_user_id = ?", $client_id, $this->id);
  1467. /* }
  1468. if($_SESSION["s"]["user"]["typ"] == 'admin'/* && isset($this->dataRecord["client_group_id"])*///) {
  1469. //echo('Plugeando ' .$app->functions->intval($this->dataRecord["client_group_id"]) . ' y ' . $client_id . ' id ' . $this->id);
  1470. //$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
  1471. /* $app->db->query("UPDATE web_database_user SET sys_groupid = ?, sys_perm_group = 'riud' WHERE database_user_id = ?", $client_id, $this->id);
  1472. }
  1473. if($app->auth->has_clients($_SESSION['s']['user']['userid'])/* && isset($this->dataRecord["client_group_id"])*///) {
  1474. //$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
  1475. /* $app->db->query("UPDATE web_database_user SET sys_groupid = ?, sys_perm_group = 'riud' WHERE database_user_id = ?", $client_id, $this->id);
  1476. }
  1477. $app->uses('sites_web_database_user_plugin');
  1478. global $app;
  1479. //Register for the events
  1480. $app->plugin->registerEvent('sites:web_database_user:on_after_update', 'sites_web_database_user_plugin', 'sites_web_database_user_edit');
  1481. $app->plugin->registerEvent('sites:web_database_user:on_after_insert', 'sites_web_database_user_plugin', 'sites_web_database_user_edit');
  1482. */
  1483. }
  1484. public function sites_database_user_add($session_id, $client_id, $params, $event_identifier = '') {
  1485. global $app;
  1486. /*if(!$this->checkPerm($session_id, 'sites_database_user_add')) {
  1487. throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
  1488. return false;
  1489. }*/
  1490. //echo(' la tablita ' . $this->formDef['db_table']);
  1491. return $this->insertQueryWebDNS('../sites/form/database_user.tform.php', $client_id, $params, $event_identifier);
  1492. }
  1493. function getDataRecordWebDNS($primary_id) {
  1494. global $app;
  1495. $escape = '`';
  1496. //$this->loadUserProfile();
  1497. if(@is_numeric($primary_id)) {
  1498. if($primary_id > 0) {
  1499. // Return a single record
  1500. //return $this->getDataRecordPadreWebDNS($primary_id);
  1501. return $app->tform->getDataRecord($primary_id);
  1502. //return parent::getDataRecord($primary_id);
  1503. } elseif($primary_id == -1) {
  1504. // Return a array with all records
  1505. $sql = "SELECT * FROM ??";
  1506. return $app->db->queryAllRecords($sql, $this->formDef['db_table']);
  1507. } else {
  1508. throw new SoapFault('invalid_id', 'The ID has to be > 0 or -1.');
  1509. return array();
  1510. }
  1511. } elseif (@is_array($primary_id) || @is_object($primary_id)) {
  1512. 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!
  1513. $sql_offset = 0;
  1514. $sql_limit = 0;
  1515. $sql_where = '';
  1516. $params = array($this->formDef['db_table']);
  1517. foreach($primary_id as $key => $val) {
  1518. if($key == '#OFFSET#') $sql_offset = $app->functions->intval($val);
  1519. elseif($key == '#LIMIT#') $sql_limit = $app->functions->intval($val);
  1520. elseif(stristr($val, '%')) {
  1521. $sql_where .= "?? like ? AND ";
  1522. } else {
  1523. $sql_where .= "?? = ? AND ";
  1524. }
  1525. $params[] = $key;
  1526. $params[] = $val;
  1527. }
  1528. $sql_where = substr($sql_where, 0, -5);
  1529. if($sql_where == '') $sql_where = '1';
  1530. //$sql = "SELECT * FROM ?? WHERE ".$sql_where. " AND " . $this->getAuthSQLWebDNS('r', $this->formDef['db_table']);
  1531. $sql = "SELECT * FROM ?? WHERE ".$sql_where. " AND " . $this->getAuthSQL('r', $this->formDef['db_table']);
  1532. if($sql_offset >= 0 && $sql_limit > 0) $sql .= ' LIMIT ' . $sql_offset . ',' . $sql_limit;
  1533. return $app->db->queryAllRecords($sql, true, $params);
  1534. } else {
  1535. $this->errorMessage = 'The ID must be either an integer or an array.';
  1536. return array();
  1537. }
  1538. }
  1539. /*function getDataRecordPadreWebDNS($primary_id) {
  1540. global $app;
  1541. $escape = '`';
  1542. $sql = "SELECT * FROM ?? WHERE ?? = ? AND ".$this->getAuthSQLWebDNS('r', $this->formDef['db_table']);
  1543. return $app->db->queryOneRecord($sql, $this->formDef['db_table'], $this->formDef['db_table_idx'], $primary_id);
  1544. }*/
  1545. function getAuthSQLWebDNS($perm, $table = '') {
  1546. if($_SESSION["s"]["user"]["typ"] == 'admin' || $_SESSION['s']['user']['mailuser_id'] > 0) {
  1547. return '1';
  1548. } else {
  1549. if ($table != ''){
  1550. $table = ' ' . $table . '.';
  1551. }
  1552. $groups = ( $_SESSION["s"]["user"]["groups"] ) ? $_SESSION["s"]["user"]["groups"] : 0;
  1553. $sql = '(';
  1554. $sql .= "(" . $table . "sys_userid = ".$_SESSION["s"]["user"]["userid"]." AND " . $table . "sys_perm_user like '%$perm%') OR ";
  1555. $sql .= "(" . $table . "sys_groupid IN (".$groups.") AND " . $table ."sys_perm_group like '%$perm%') OR ";
  1556. $sql .= $table . "sys_perm_other like '%$perm%'";
  1557. $sql .= ')';
  1558. return $sql;
  1559. }
  1560. }
  1561. public function sites_database_add($client_id, $params){
  1562. global $app, $conf;
  1563. //IMPORTANTE. PARA QUE EL PLUGING FUNCIONE HAY QUE CARGAR ANTES EL FORMULARIO
  1564. //DE LO QUE SE QUIERE CREAR EN ESTE CASO SITIO WEB
  1565. $tform_def_file = "../sites/form/database.tform.php";
  1566. $app->tform->loadFormDef($tform_def_file);
  1567. $app->remoting_lib->loadFormDef('../sites/form/database.tform.php');
  1568. //$app->tform->formDef('../sites/form/database.tform.php');
  1569. //$sql = $app->remoting->insertQueryPrepare('../sites/form/database.tform.php', $client_id, $params);
  1570. $sql = $this->insertQueryPrepareWebDNS('../sites/form/database.tform.php', $client_id, $params);
  1571. if($sql !== false) {
  1572. $app->uses('sites_database_plugin');
  1573. //print_r($sql);
  1574. $this->id = 0;
  1575. $this->dataRecord = $params;
  1576. //$app->uses('sites_database_plugin');
  1577. //$app->sites_database_plugin->processDatabaseInsert($this);
  1578. //$retval = $this->insertQueryExecute($sql, $params);
  1579. $retval = $this->insertQueryExecuteWebDNS($sql, $params);
  1580. $app->sites_database_plugin->processDatabaseInsert($this);
  1581. //$app->plugin->raiseEvent('sites:web_database:on_after_insert', $this);
  1582. // set correct values for backup_interval and backup_copies
  1583. /*if(isset($params['backup_interval']) || isset($params['backup_copies'])){
  1584. $sql_set = array();
  1585. if(isset($params['backup_interval'])) $sql_set[] = "backup_interval = '".$app->db->quote($params['backup_interval'])."'";
  1586. if(isset($params['backup_copies'])) $sql_set[] = "backup_copies = ".$app->functions->intval($params['backup_copies']);
  1587. //$app->db->query("UPDATE web_database SET ".implode(', ', $sql_set)." WHERE database_id = ".$retval);
  1588. $this->updateQueryExecute("UPDATE web_database SET ".implode(', ', $sql_set)." WHERE database_id = ".$retval, $retval, $params);
  1589. }*/
  1590. return $retval;
  1591. }
  1592. return false;
  1593. }
  1594. }
  1595. $page = new page_action;
  1596. $page->onLoad();
  1597. //IMPORTENTE, es necesario estas lí­neas para que el botón del pdf funcione. Activa el javascript
  1598. //echo '<script type="text/javascript">';
  1599. //echo 'alert (password(7, false, 1));';
  1600. //echo '</script>';
  1601. ?>
  1602. <!--IMPORTENTE, es necesario estas lí­neas para que el botón del pdf funcione. Activa el javascript -->
  1603. <script type="text/javascript">
  1604. /*var test = "PARALACLAVE";
  1605. function getRandomInt(min, max){
  1606. return Math.floor(Math.random() * (max - min + 1)) + min;
  1607. }
  1608. var clave = password(7, false, 1);
  1609. function password(minLength, special, num_special){
  1610. minLength = minLength || 10;
  1611. if(minLength < 8) minLength = 8;
  1612. var maxLength = minLength + 5;
  1613. var length = getRandomInt(minLength, maxLength);
  1614. var alphachars = "abcdefghijkmnopqrstuvwxyz";
  1615. var upperchars = "ABCDEFGHJKLMNPQRSTUVWXYZ";
  1616. var numchars = "23456789";
  1617. var specialchars = "!@#_";
  1618. if(num_special == undefined) num_special = 0;
  1619. if(special != undefined && special == true) {
  1620. num_special = Math.floor(Math.random() * (length / 4)) + 1;
  1621. }
  1622. var numericlen = getRandomInt(1, 2);
  1623. var alphalen = length - num_special - numericlen;
  1624. var upperlen = Math.floor(alphalen / 2);
  1625. alphalen = alphalen - upperlen;
  1626. var password = "";
  1627. for(i = 0; i < alphalen; i++) {
  1628. password += alphachars.charAt(Math.floor(Math.random() * alphachars.length));
  1629. }
  1630. for(i = 0; i < upperlen; i++) {
  1631. password += upperchars.charAt(Math.floor(Math.random() * upperchars.length));
  1632. }
  1633. for(i = 0; i < num_special; i++) {
  1634. password += specialchars.charAt(Math.floor(Math.random() * specialchars.length));
  1635. }
  1636. for(i = 0; i < numericlen; i++) {
  1637. password += numchars.charAt(Math.floor(Math.random() * numchars.length));
  1638. }
  1639. password = password.split('').sort(function() { return 0.5 - Math.random(); }).join('');
  1640. return password;
  1641. }*/
  1642. </script>