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

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