ISPConfig module for simplify the creation of websites and DNS zones in a only step
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 

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