ISPConfig module for simplify the creation of websites and DNS zones in a only step
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

1887 linhas
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"]["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. 'type' => 'vhost',
  586. 'domain' => $fields['domain'],
  587. 'server_id' => $this->web_serv,// $web_servidor, //$server_id,//$dns_servidor['default_webserver'],
  588. //IMPORTANTE. Aquí­ no se ponen los campos sys_userid ni sys_groupid, el evento on_after_insert
  589. //'sys_userid' => $sysUsuarioId, //$fields['client_group_id'],//$sys_userid,
  590. //'sys_groupid' => $cliente_groupid,
  591. 'ip_address' => '*', //$dns_ip_servidor['ip_address'],
  592. 'ipv6_address' => $this->ip6_servidor_web['ip_address'], //$this->ip6_ultima['ip_address'], //$dns_ip_servidor_ipv6['ip_address'],
  593. 'traffic_quota' => '-1',
  594. 'hd_quota' => '0',
  595. 'cgi' => 'y',
  596. 'ssi' => 'y',
  597. 'suexec' => 'y',
  598. 'ruby' => 'n',
  599. 'python' => 'n',
  600. 'perl' => 'n',
  601. 'errordocs' => '1',
  602. 'subdomain' => 'none',
  603. 'php' => 'php-fpm',
  604. 'fastcgi_php_version' => '',
  605. 'seo_redirect' => '',
  606. 'rewrite_to_https' => 'n',
  607. 'allow_override' => 'All',
  608. 'http_port' => 80,
  609. 'https_port' => 443,
  610. 'apache_directives' => '',
  611. 'nginx_directives' => '',
  612. 'php_fpm_use_socket' => 'y',
  613. 'pm' => 'dynamic',
  614. 'pm_max_children' => 10,
  615. 'pm_start_servers' => 1,
  616. 'pm_min_spare_servers' => 1,
  617. 'pm_max_spare_servers' => 1,
  618. 'pm_process_idle_timeout' => 10,
  619. 'pm_max_requests' => 10,
  620. 'custom_php_ini' => '',
  621. 'active' => 'y',
  622. 'document_root' => '-',
  623. 'system_user' => '-',
  624. 'system_group' => '-',
  625. 'log_retention' => 30,
  626. 'client_group_id' => $this->cli_grupo_id,//$cliente_groupid, //$client_group_id,
  627. );
  628. //print "<pre> Parametros:"; print_r($paramsite); print "</pre>\n";
  629. /*print '<pre> cliente id ' . $fields['client_id'];
  630. print "<pre>";print_r($fields);print "</pre>\n" . $fields['client_id'];*/
  631. //print '<pre>DNS IPV6 ' . $dns_ip_servidor_ipv6['ip_address'];
  632. //IMPORTANTE. PARA QUE EL PLUGING FUNCIONE HAY QUE CARGAR ANTES EL FORMULARIO
  633. //DE LO QUE SE QUIERE CREAR EN ESTE CASO SITIO WEB
  634. $tform_def_file = "../sites/form/web_vhost_domain.tform.php";
  635. $app->tform->loadFormDef($tform_def_file);
  636. //El último parámetro es para lanzar un evento que llama a la función on_after_insert que prepara
  637. //los campos document_root, system_user y system_group
  638. //$site_id = $remoto->insert_query('../sites/form/web_vhost_domain.tform.php', $fields['client_group_id'], $paramsite, 'sites:web_vhost_domain:on_after_insert');
  639. $site_id = $remoto->insert_query('../sites/form/web_vhost_domain.tform.php',
  640. $this->cli_id, /*$cliente_id_seleccionado,*/
  641. $paramsite, 'sites:web_vhost_domain:on_after_insert');
  642. //IMPORTANTE. HAY QUE CARGAR EL FORMULARIO DE WEBDNS PARA QUE ENCUENTRE EL TAB.
  643. $tform_def_file = "form/new_service_webdns.tform.php";
  644. $app->tform->loadFormDef($tform_def_file);
  645. }
  646. public $ip4_servidor_dns;
  647. public $ip6_servidor_dns;
  648. public $ip4_servidor_web;
  649. public $ip6_servidor_web;
  650. public $ip4_servidor_bbdd;
  651. public $ip6_servidor_bbdd;
  652. public $ip4_servidor_ftp;
  653. public $ip6_servidor_ftp;
  654. public $dns_serv;
  655. public $web_serv;
  656. public $bbdd_serv;
  657. public $ftp_serv;
  658. function tieneServidorIPs(){
  659. global $app, $conf;
  660. $this->controlUserGrupoId();
  661. $app->uses('getconf');
  662. $global_config_sitio = $app->getconf->get_global_config('sites');
  663. $global_config_dns = $app->getconf->get_global_config('dns');
  664. if(!$global_config_dns['default_dnsserver']) {
  665. $app->tform->errorMessage = $app->tform->wordbook['error_no_servidor_default']. 'DNS.';
  666. $this->onError();
  667. return true;
  668. } else if(!$global_config_sitio['default_webserver']) {
  669. $app->tform->errorMessage = $app->tform->wordbook['error_no_servidor_default']. 'WEB.';
  670. $this->onError();
  671. return true;
  672. } else if(!$global_config_sitio['default_dbserver']) {
  673. $app->tform->errorMessage = $app->tform->wordbook['error_no_servidor_default']. 'DB.';
  674. $this->onError();
  675. return true;
  676. }
  677. //print "<pre>WEB SERVER por defecto ";print_r($global_config_sitio);print "</pre>\n";
  678. //print "<pre>DNS SERVER por defecto ";print_r($global_config_dns);print "</pre>\n";
  679. //El cliente 1 es admin.
  680. //Recupero los servidores asignados por defecto y se los asigno a admin o al usuario
  681. //que no tenga asignado ninguno.
  682. if($this->cli_id == 0) {
  683. $this->dns_serv = $global_config_dns['default_dnsserver'];//1;
  684. $this->web_serv = $global_config_sitio['default_webserver'];//1;
  685. $this->bbdd_serv = $global_config_sitio['default_dbserver'];//1;
  686. $this->ftp_serv = $global_config_sitio['default_webserver'];//1;
  687. //print "<pre>tieneServidorIPs el cli_id "; print_r($this->cli_id . ' el servidor ' . $this->dns_serv); print "</pre>\n";
  688. }else{
  689. $servidores = $app->db->queryOneRecord(
  690. "SELECT client_id, dns_servers, web_servers, db_servers FROM client
  691. WHERE client_id = ". $this->cli_id);
  692. $this->dns_serv = $servidores['dns_servers'];
  693. $this->web_serv = $servidores['web_servers'];
  694. $this->bbdd_serv = $servidores['db_servers'];
  695. //para el ftp el servidor es el mismo que para el sitio web.
  696. $this->ftp_serv = $servidores['web_servers'];
  697. //Si el cliente no tiene asignado un servidor se añade por defecto al que hay en la configuración por defecto
  698. if(!$this->dns_serv){
  699. $this->dns_serv = $global_config_dns['default_dnsserver'];//1;
  700. }
  701. //Si el cliente no tiene asignado un servidor se añade por defecto al que hay en la configuración por defecto
  702. if(!$this->web_serv){
  703. $this->web_serv = $global_config_sitio['default_webserver'];//1;
  704. }
  705. //Si el cliente no tiene asignado un servidor se añade por defecto al que hay en la configuración por defecto
  706. if(!$this->bbdd_serv){
  707. $this->bbdd_serv = $global_config_sitio['default_dbserver'];//1;
  708. }
  709. //Si el cliente no tiene asignado un servidor se añade por defecto al que hay en la configuración por defecto
  710. if(!$this->ftp_serv){
  711. $this->ftp_serv = $global_config_sitio['default_webserver'];//1;
  712. }
  713. }
  714. /*print "<pre>DNS SERVER ";print_r($this->dns_serv);print "</pre>\n";
  715. print "<pre>WEB SERVER ";print_r($this->web_serv);print "</pre>\n";
  716. print "<pre>DB SERVER ";print_r($this->bbdd_serv);print "</pre>\n";
  717. print "<pre>FTP SERVER ";print_r($this->ftp_serv);print "</pre>\n";*/
  718. //Captura de las ips del servidor dns de la variable global para ello.
  719. /* $global_dns_config = $app->getconf->get_server_config($this->dns_serv, 'server');
  720. $this->ip4_servidor_dns = $global_dns_config['ip_address'];
  721. $this->ip6_servidor_dns = $global_dns_config['v6_prefix'];*/
  722. //El cliente 1 es admin
  723. if($this->cli_id == 0){
  724. //Compruebo si hay datos para el client_id 0 y si no existe pruebo con el 1.
  725. //Alguno de los dos tiene que existir por configuración de ispconfig.
  726. $this->ip4_servidor_dns = $app->db->queryOneRecord(
  727. 'SELECT ip_type, ip_address FROM server_ip
  728. WHERE client_id = "0" AND server_id = "'.$this->dns_serv.'" AND ip_type="IPv4"');
  729. $this->ip6_servidor_dns = $app->db->queryOneRecord(
  730. 'SELECT ip_type, ip_address FROM server_ip
  731. WHERE client_id = "0" AND server_id = "'.$this->dns_serv.'" AND ip_type="IPv6"');
  732. /*if(!$this->ip4_servidor_dns){
  733. $this->ip4_servidor_dns = $app->db->queryOneRecord(
  734. 'SELECT ip_type, ip_address FROM server_ip
  735. WHERE client_id = "1" AND server_id = "'.$this->dns_serv.'" AND ip_type="IPv4"');
  736. }*/
  737. /* if(!$this->ip6_servidor_dns){
  738. $this->ip6_servidor_dns = $app->db->queryOneRecord(
  739. 'SELECT ip_type, ip_address FROM server_ip
  740. WHERE client_id = "1" AND server_id = "'.$this->dns_serv.'" AND ip_type="IPv6"');*/
  741. //}
  742. }else{
  743. // $this->ip4_servidor_dns = $global_dns_config['ip_address'];
  744. //Comprobamos si el cliente tiene servidor asignado, si no lo tiene asignamos el que admin a seleccionado
  745. //para este servidor.
  746. $this->ip4_servidor_dns = $app->db->queryOneRecord(
  747. 'SELECT ip_type, ip_address
  748. FROM server_ip
  749. WHERE client_id = "'.$this->cli_id.'" AND server_id = "'.$this->dns_serv.'" AND ip_type="IPv4"');
  750. $this->ip6_servidor_dns = $app->db->queryOneRecord(
  751. 'SELECT ip_type, ip_address
  752. FROM server_ip
  753. WHERE client_id = "'.$this->cli_id.'" AND server_id = "'.$this->dns_serv.'"AND ip_type="IPv6"');
  754. //echo(' la ip6 ' . $this->ip6_ultima);
  755. //si no tiene asignado le damos el de admin.
  756. /* if(!$this->ip4_servidor_dns){
  757. // $this->ip4_servidor_dns = $global_dns_config['ip_address'];
  758. //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
  759. //Tomamos las de admin.
  760. //Alguno de los dos tiene que existir por configuración de ispconfig.
  761. $this->ip4_servidor_dns = $app->db->queryOneRecord(
  762. 'SELECT ip_type, ip_address FROM server_ip
  763. WHERE client_id = "0" AND server_id = "'.$this->dns_serv.'" AND ip_type="IPv4"');
  764. if(!$this->ip4_servidor_dns){
  765. $this->ip4_servidor_dns = $app->db->queryOneRecord(
  766. 'SELECT ip_type, ip_address FROM server_ip
  767. WHERE client_id = "1" AND server_id = "'.$this->dns_serv.'" AND ip_type="IPv4"');
  768. }
  769. }*/
  770. if(!$this->ip6_servidor_dns){
  771. //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
  772. //Tomamos las de admin.
  773. //Alguno de los dos tiene que existir por configuración de ispconfig.
  774. //$this->ip4_servidor_dns = $app->db->queryOneRecord('SELECT ip_type, ip_address FROM server_ip WHERE client_id = "0" AND ip_type="IPv4"');
  775. $this->ip6_servidor_dns = $app->db->queryOneRecord(
  776. 'SELECT ip_type, ip_address FROM server_ip
  777. WHERE client_id = "0" AND server_id = "'.$this->dns_serv.'" AND ip_type="IPv6"');
  778. /*if(!$this->ip6_servidor_dns){
  779. $this->ip6_servidor_dns = $app->db->queryOneRecord(
  780. 'SELECT ip_type, ip_address FROM server_ip
  781. WHERE client_id = "1" AND server_id = "'.$this->dns_serv.'" AND ip_type="IPv6"');
  782. }*/
  783. }
  784. $this->ip6_ultima = $this->ip6_servidor_dns['ip_address'];
  785. }
  786. //Captura de las ips del servidor web
  787. if($this->cli_id == 0){
  788. //Compruebo si hay datos para el client_id 0 y si no existe pruebo con el 1.
  789. //Alguno de los dos tiene que existir por configuración de ispconfig.
  790. $this->ip4_servidor_web = $app->db->queryOneRecord(
  791. 'SELECT ip_type, ip_address FROM server_ip
  792. WHERE client_id = "0" AND server_id = "'.$this->web_serv.'" AND ip_type="IPv4"');
  793. $this->ip6_servidor_web = $app->db->queryOneRecord(
  794. 'SELECT ip_type, ip_address FROM server_ip
  795. WHERE client_id = "0" AND server_id = "'.$this->web_serv.'" AND ip_type="IPv6"');
  796. /*if(!$this->ip4_servidor_web){
  797. $this->ip4_servidor_web = $app->db->queryOneRecord(
  798. 'SELECT ip_type, ip_address FROM server_ip
  799. WHERE client_id = "1" AND server_id = "'.$this->web_serv.'" AND ip_type="IPv4"');
  800. }
  801. if(!$this->ip6_servidor_web){
  802. $this->ip6_servidor_web = $app->db->queryOneRecord(
  803. 'SELECT ip_type, ip_address FROM server_ip
  804. WHERE client_id = "1" AND server_id = "'.$this->web_serv.'" AND ip_type="IPv6"');
  805. }*/
  806. }else{//Comprobamos si el cliente tiene servidor asignado
  807. $this->ip4_servidor_web = $app->db->queryOneRecord(
  808. 'SELECT ip_type, ip_address
  809. FROM server_ip
  810. WHERE client_id = "'.$this->cli_id.'" AND server_id = "'.$this->web_serv.'" AND ip_type="IPv4"');
  811. $this->ip6_servidor_web = $app->db->queryOneRecord(
  812. 'SELECT ip_type, ip_address
  813. FROM server_ip
  814. WHERE client_id = "'.$this->cli_id.'" AND server_id = "'.$this->web_serv.'"AND ip_type="IPv6"');
  815. //si no tiene asignado le damos el de admin.
  816. if(!$this->ip4_servidor_web){
  817. $this->ip4_servidor_web = $app->db->queryOneRecord(
  818. 'SELECT ip_type, ip_address FROM server_ip
  819. WHERE client_id = "0" AND server_id = "'.$this->web_serv.'" AND ip_type="IPv4"');
  820. /*if(!$this->ip4_servidor_web){
  821. $this->ip4_servidor_web = $app->db->queryOneRecord(
  822. 'SELECT ip_type, ip_address FROM server_ip
  823. WHERE client_id = "1" AND server_id = "'.$this->web_serv.'" AND ip_type="IPv4"');
  824. }*/
  825. }
  826. //Cargamos variable para el pdf
  827. $this->ip4_pdf = $this->ip4_servidor_web['ip_address'];
  828. if(!$this->ip6_servidor_web){
  829. $this->ip6_servidor_web = $app->db->queryOneRecord(
  830. 'SELECT ip_type, ip_address FROM server_ip
  831. WHERE client_id = "0" AND server_id = "'.$this->web_serv.'" AND ip_type="IPv6"');
  832. /*if(!$this->ip6_servidor_web){
  833. $this->ip6_servidor_web = $app->db->queryOneRecord(
  834. 'SELECT ip_type, ip_address FROM server_ip
  835. WHERE client_id = "1" AND server_id = "'.$this->web_serv.'" AND ip_type="IPv6"');
  836. }*/
  837. }
  838. }
  839. //Captura de las ips del servidor bbdd
  840. if($this->cli_id == 0){
  841. //Compruebo si hay datos para el client_id 0 y si no existe pruebo con el 1.
  842. //Alguno de los dos tiene que existir por configuración de ispconfig.
  843. $this->ip4_servidor_bbdd = $app->db->queryOneRecord(
  844. 'SELECT ip_type, ip_address FROM server_ip
  845. WHERE client_id = "0" AND server_id = "'.$this->bbdd_serv.'" AND ip_type="IPv4"');
  846. $this->ip6_servidor_bbdd = $app->db->queryOneRecord(
  847. 'SELECT ip_type, ip_address FROM server_ip
  848. WHERE client_id = "0" AND server_id = "'.$this->bbdd_serv.'" AND ip_type="IPv6"');
  849. /*if(!$this->ip4_servidor_bbdd){
  850. $this->ip4_servidor_bbdd = $app->db->queryOneRecord(
  851. 'SELECT ip_type, ip_address FROM server_ip
  852. WHERE client_id = "1" AND server_id = "'.$this->bbdd_serv.'" AND ip_type="IPv4"');
  853. }
  854. if(!$this->ip6_servidor_bbdd){
  855. $this->ip6_servidor_bbdd = $app->db->queryOneRecord(
  856. 'SELECT ip_type, ip_address FROM server_ip
  857. WHERE client_id = "1" AND server_id = "'.$this->bbdd_serv.'" AND ip_type="IPv6"');
  858. }*/
  859. }else{//Comprobamos si el cliente tiene servidor asignado
  860. $this->ip4_servidor_bbdd = $app->db->queryOneRecord(
  861. 'SELECT ip_type, ip_address
  862. FROM server_ip
  863. WHERE client_id = "'.$this->cli_id.'" AND server_id = "'.$this->bbdd_serv.'" AND ip_type="IPv4"');
  864. $this->ip6_servidor_bbdd = $app->db->queryOneRecord(
  865. 'SELECT ip_type, ip_address
  866. FROM server_ip
  867. WHERE client_id = "'.$this->cli_id.'" AND server_id = "'.$this->bbdd_serv.'"AND ip_type="IPv6"');
  868. //echo(' (1) la ip4 bbdd ' . print_r($this->ip4_servidor_bbdd));
  869. //si no tiene asignado le damos el de admin.
  870. if(!$this->ip4_servidor_bbdd){
  871. //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
  872. //Tomamos las de admin.
  873. //Alguno de los dos tiene que existir por configuración de ispconfig.
  874. $this->ip4_servidor_bbdd = $app->db->queryOneRecord(
  875. 'SELECT ip_type, ip_address FROM server_ip
  876. WHERE client_id = "0" AND server_id = "'.$this->bbdd_serv.'" AND ip_type="IPv4"');
  877. //echo(' (2) la ip4 bbdd ' . print_r($this->ip4_servidor_bbdd));
  878. /*if(!$this->ip4_servidor_bbdd){
  879. $this->ip4_servidor_bbdd = $app->db->queryOneRecord(
  880. 'SELECT ip_type, ip_address FROM server_ip
  881. WHERE client_id = "1" AND server_id = "'.$this->bbdd_serv.'" AND ip_type="IPv4"');
  882. }*/
  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 = "0" AND server_id = "'.$this->bbdd_serv.'" AND ip_type="IPv6"');
  888. /*if(!$this->ip6_servidor_bbdd){
  889. $this->ip6_servidor_bbdd = $app->db->queryOneRecord(
  890. 'SELECT ip_type, ip_address FROM server_ip
  891. WHERE client_id = "1" AND server_id = "'.$this->bbdd_serv.'" AND ip_type="IPv6"');
  892. }*/
  893. }
  894. }
  895. //para el servidor ftp no se hacen comprobaciones
  896. //ya que las ips son las mismas que para el servidor web.
  897. //$la_ip4 = $app->db->queryOneRecord("SELECT ip_type, ip_address FROM server_ip WHERE ip_type='IPv4'");
  898. //$dns_ip_servidor['ip_address'];//$la_ip4['ip_address'];
  899. /*print "<pre>IP4 DNS ";print_r($this->ip4_servidor_dns);print "</pre>\n";
  900. print "<pre>IP6 DNS ";print_r($this->ip6_servidor_dns);print "</pre>\n";
  901. print "<pre>IP4 WEB ";print_r($this->ip4_servidor_web);print "</pre>\n";
  902. print "<pre>IP6 WEB ";print_r($this->ip6_servidor_web);print "</pre>\n";
  903. print "<pre>IP4 BBDD ";print_r($this->ip4_servidor_bbdd);print "</pre>\n";
  904. print "<pre>IP6 BBDD ";print_r($this->ip6_servidor_bbdd);print "</pre>\n";
  905. echo('El cliente ' . $this->cli_id . '<br>');*/
  906. if(!$this->ip4_servidor_dns['ip_address']){
  907. //si no tiene servidor dns en la lista de ips se toma el servidor por defecto web y se usan sus ips
  908. $global_web_config = $app->getconf->get_server_config($this->web_serv, 'server');
  909. $this->ip4_servidor_dns = $global_web_config;
  910. //$this->ip6_servidor_dns = $global_web_config;
  911. /*$servicio_dns = $app->db->queryOneRecord(
  912. 'SELECT server_id, dns_server, server_name FROM server
  913. WHERE server_id = "'.$this->dns_serv.'"');
  914. $nom_serv_dns = $servicio_dns['server_name'];
  915. $app->tform->errorMessage = $app->tform->wordbook['error_no_ip']. 'la IP4 para el servidor ' . $nom_serv_dns;
  916. $this->onError();
  917. return true;*/
  918. }
  919. //Si no tiene ip6 asignada tomamos la del servidor web
  920. if(!$this->ip6_servidor_dns['ip_address']){
  921. $this->ip6_servidor_dns = $app->db->queryOneRecord(
  922. 'SELECT ip_type, ip_address
  923. FROM server_ip
  924. WHERE client_id = "0" AND server_id = "'.$this->web_serv.'"AND ip_type="IPv6"');
  925. //si no tiene servidor dns en la lista de ips se toma el servidor por defecto web y se usan sus ips
  926. // $global_web_config = $app->getconf->get_server_config($this->web_serv, 'server');
  927. //$this->ip4_servidor_dns = $global_web_config;
  928. // $this->ip6_servidor_dns = $global_web_config['v6_prefix'];
  929. // $this->ip6_ultima = $this->ip6_servidor_dns;
  930. //echo(' la ip6 ' . $this->ip6_servidor_dns);
  931. /* $servicio_dns = $app->db->queryOneRecord(
  932. 'SELECT server_id, dns_server, server_name FROM server
  933. WHERE server_id = "'.$this->dns_serv.'"');
  934. $nom_serv_dns = $servicio_dns['server_name'];
  935. $app->tform->errorMessage = $app->tform->wordbook['error_no_ip']. 'la IP6 para el servidor '. $nom_serv_dns;
  936. $this->onError();
  937. return true;*/
  938. }
  939. if(!$this->ip4_servidor_web['ip_address']){
  940. //Si no hay ip4 en la lista de ips, tomamos esta de la configuración principal.
  941. $global_web_config = $app->getconf->get_server_config($this->web_serv, 'server');
  942. $this->ip4_servidor_web = $global_web_config;
  943. //Cargamos variable para el pdf
  944. $this->ip4_pdf = $this->ip4_servidor_web['ip_address'];
  945. if(!$this->ip4_servidor_web['ip_address']){
  946. $servidor_web = $app->db->queryOneRecord(
  947. 'SELECT server_id, web_server, server_name FROM server
  948. WHERE server_id = "'.$this->web_serv.'"');
  949. $nom_serv_web = $servidor_web['server_name'];
  950. $app->tform->errorMessage = $app->tform->wordbook['error_no_ip']. 'la IP4 para el servidor ' . $nom_serv_web;
  951. $this->onError();
  952. return true;
  953. }
  954. }
  955. if(!$this->ip6_servidor_web['ip_address']){
  956. $servidor_web = $app->db->queryOneRecord(
  957. 'SELECT server_id, web_server, server_name FROM server
  958. WHERE server_id = "'.$this->web_serv.'"');
  959. $nom_serv_web = $servidor_web['server_name'];
  960. $app->tform->errorMessage = $app->tform->wordbook['error_no_ip']. 'la IP6 para el servidor ' . $nom_serv_web;
  961. $this->onError();
  962. return true;
  963. }
  964. if(!$this->ip4_servidor_bbdd['ip_address']){
  965. $global_bbdd_config = $app->getconf->get_server_config($this->bbdd_serv, 'server');
  966. $this->ip4_servidor_bbdd = $global_bbdd_config;
  967. //echo(' (3) la ip4 bbdd ' . print_r($this->ip4_servidor_bbdd));
  968. //Como la ip4 para las bbdd es la ip4 para el sitio web, no es necesario esta comprobación
  969. /* if(!$this->ip4_servidor_bbdd['ip_address']){
  970. $servicio_db = $app->db->queryOneRecord(
  971. 'SELECT server_id, db_server, server_name FROM server
  972. WHERE server_id = "'.$this->bbdd_serv.'"');
  973. $nom_serv_db = $servicio_db['server_name'];
  974. $app->tform->errorMessage = $app->tform->wordbook['error_no_ip']. 'la IP4 para el servidor ' . $nom_serv_db;
  975. $this->onError();
  976. return true;
  977. }*/
  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. return false;
  1034. }
  1035. //Comprobación de que tenemos instalada nuestra plantilla
  1036. function plantillaWebDNS(){
  1037. global $app;
  1038. if(!$app->db->queryOneRecord("SELECT name FROM dns_template WHERE name = 'webdns'")) {
  1039. $app->tform->errorMessage = $app->tform->wordbook['error_plantilla_webdns'];
  1040. $this->onError();
  1041. return true;
  1042. }
  1043. }
  1044. //Comprueba que no exista el dominio y que no tenga sitio web, puede tener sitio web y no tener dns.
  1045. function existeDominio($campos){
  1046. global $app, $conf;
  1047. if($app->db->queryOneRecord('SELECT * FROM dns_soa WHERE origin LIKE "'.$campos['domain'].'."')) {
  1048. $app->tform->errorMessage = $app->tform->wordbook['domain_error_unique'];
  1049. }
  1050. if($app->db->queryOneRecord('SELECT domain_id, domain FROM web_domain WHERE domain = "'.$campos['domain'].'"')) {
  1051. $app->tform->errorMessage = $app->tform->wordbook['error_sitio_web_existe'];
  1052. }
  1053. //IMPORTANTE. AQUI CONTROLAMOS LOS ERRORES QUE SE VALIDAN EN EL FORMULARIO, EN ESTE CASO EL CAMPO DEL DOMINIO.
  1054. if($app->tform->errorMessage)
  1055. {
  1056. $this->onError();
  1057. return true;
  1058. }
  1059. }
  1060. public $ip4_ultima;
  1061. public $ip6_ultima;
  1062. //Creación del las dns y sitio web para un dominio.
  1063. function crearDnsSitioWeb($remoto){
  1064. global $app, $conf;
  1065. $remote = new remote_actions;
  1066. //Carga de los campos del formulario.
  1067. $fields = $app->tform->encode($this->dataRecord, $app->tform->getCurrentTab(), true);
  1068. //Carga del formulario dns_soa para guardar en base de datos.
  1069. $tform_def_file = "../dns/form/dns_soa.tform.php";
  1070. $app->tform->loadFormDef($tform_def_file);
  1071. //Carga y seleccion de dns_template, si no esta creado se informa de que tiene que crearse.
  1072. $template_record = $app->db->queryOneRecord(
  1073. "SELECT * FROM dns_template WHERE visible = 'Y' AND name = 'webdns'"); /*'open6hosting'");*/
  1074. /*print "<pre>DNS SERVER ";print_r($this->dns_serv);print "</pre>\n";
  1075. print "<pre>WEB SERVER ";print_r($this->web_serv);print "</pre>\n";
  1076. print "<pre>IP4 DNS ";print_r($this->ip4_servidor_dns);print "</pre>\n";
  1077. print "<pre>IP6 DNS ";print_r($this->ip6_servidor_dns);print "</pre>\n";
  1078. print "<pre>IP4 WEB ";print_r($this->ip4_servidor_web);print "</pre>\n";
  1079. print "<pre>IP6 WEB ";print_r($this->ip6_servidor_web);print "</pre>\n";*/
  1080. //Si el servidor es el que tiene asignado el cliente o el de admin por defecto, le damos esta ip4
  1081. //if($this->dns_serv && $this->ip4_servidor_dns){
  1082. $this->ip4_ultima = $this->ip4_servidor_dns['ip_address'];
  1083. //}
  1084. //echo(' ips ' . $this->ip4_ultima . ' ip4dns ' . $this->ip4_servidor_dns);
  1085. //if($this->dns_serv && $this->ip6_servidor_dns){
  1086. $this->ip6_ultima = $this->ip6_servidor_dns['ip_address'];
  1087. //}
  1088. //echo(' ip4 ' . $this->ip4_ultima['ip_address'] . ' ip6 ' . $this->ip6_ultima);
  1089. //if($this->web_serv && $this->ip4_servidor_web){
  1090. //$this->ip4_ultima = $this->ip4_servidor_dns;//$this->ip4_servidor_web;
  1091. //}
  1092. //if($this->web_serv && $this->ip6_servidor_web){
  1093. //$this->ip6_ultima = $this->ip4_servidor_dns;//$this->ip6_servidor_web;
  1094. //}
  1095. $tpl_content = $template_record['template'];
  1096. // Reemplazo la variable que nos encontramos en base de datos por el valor que se ha introducido en el formulario
  1097. $tpl_content = str_replace('{DOMAIN}', $fields['domain'], $tpl_content);
  1098. //Carga de los datos en las variables de las ips.
  1099. $tpl_content = str_replace('{IP}', $this->ip4_ultima, $tpl_content);
  1100. $tpl_content = str_replace('{IPV6}', $this->ip6_ultima, $tpl_content);
  1101. $enable_dnssec = 'N';
  1102. // Parse the template
  1103. $tpl_rows = explode("\n", $tpl_content);
  1104. $section = '';
  1105. $vars = array();
  1106. $vars['xfer']='';
  1107. $dns_rr = array();
  1108. foreach($tpl_rows as $row) {
  1109. $row = trim($row);
  1110. if(substr($row, 0, 1) == '[') {
  1111. if($row == '[ZONE]') {
  1112. $section = 'zone';
  1113. } elseif($row == '[DNS_RECORDS]') {
  1114. $section = 'dns_records';
  1115. } else {
  1116. die('Unknown section type');
  1117. }
  1118. } else {
  1119. if($row != '') {
  1120. // Handle zone section
  1121. if($section == 'zone') {
  1122. $parts = explode('=', $row);
  1123. $key = trim($parts[0]);
  1124. $val = trim($parts[1]);
  1125. if($key != '') $vars[$key] = $val;
  1126. }
  1127. // Handle DNS Record rows
  1128. if($section == 'dns_records') {
  1129. $parts = explode('|', $row);
  1130. $dns_rr[] = array(
  1131. 'name' => $parts[1],
  1132. 'type' => $parts[0],
  1133. 'data' => $parts[2],
  1134. 'aux' => $parts[3],
  1135. 'ttl' => $parts[4]
  1136. );
  1137. }
  1138. }
  1139. }
  1140. } // end foreach
  1141. // Insert the soa record
  1142. $sys_userid = $this->cli_id;//$cliente_id_seleccionado;//$fields['client_group_id'];
  1143. $origin = $vars['origin'];
  1144. $ns = $vars['ns'];
  1145. $mbox = str_replace('@', '.', $vars['mbox']);
  1146. $refresh = $vars['refresh'];
  1147. $retry = $vars['retry'];
  1148. $expire = $vars['expire'];
  1149. $minimum = $vars['minimum'];
  1150. $ttl = $vars['ttl'];
  1151. $xfer = $vars['xfer'];
  1152. $also_notify = $vars['also_notify'];
  1153. $update_acl = $vars['update_acl'];
  1154. $serial = $app->validate_dns->increase_serial(0);
  1155. $insert_data = array(
  1156. "sys_userid" => $this->sys_usuario_id,//$sysUsuarioId,//$fields['client_group_id'],
  1157. "sys_groupid" => $this->cli_grupo_id,//$cliente_groupid,//$client_group_id,
  1158. "sys_perm_user" => 'riud',
  1159. "sys_perm_group" => 'riud',
  1160. "sys_perm_other" => '',
  1161. "server_id" => $this->dns_serv,
  1162. "origin" => $origin,
  1163. "ns" => $ns,
  1164. "mbox" => $mbox,
  1165. "serial" => $serial,
  1166. "refresh" => $refresh,
  1167. "retry" => $retry,
  1168. "expire" => $expire,
  1169. "minimum" => $minimum,
  1170. "ttl" => $ttl,
  1171. "active" => 'Y',
  1172. "xfer" => $xfer,
  1173. "also_notify" => $also_notify,
  1174. "update_acl" => $update_acl,
  1175. "dnssec_wanted" => $enable_dnssec
  1176. );
  1177. $dns_soa_id = $app->db->datalogInsert('dns_soa', $insert_data, 'id');
  1178. $remote->dns_soa_after_insert($dns_soa_id, $this->sys_usuario_id, $this->cli_grupo_id);
  1179. // Insert the dns_rr records
  1180. if(is_array($dns_rr) && $dns_soa_id > 0) {
  1181. foreach($dns_rr as $rr) {
  1182. $insert_data = array(
  1183. "sys_userid" => $this->sys_usuario_id,//$sysUsuarioId, //$fields['client_group_id'],
  1184. "sys_groupid" => $this->cli_grupo_id,//$cliente_groupid, //$client_group_id,
  1185. "sys_perm_user" => 'riud',
  1186. "sys_perm_group" => 'riud',
  1187. "sys_perm_other" => '',
  1188. "server_id" => $this->dns_serv,
  1189. "zone" => $dns_soa_id,
  1190. "name" => $rr['name'],
  1191. "type" => $rr['type'],
  1192. "data" => $rr['data'],
  1193. "aux" => $rr['aux'],
  1194. "ttl" => $rr['ttl'],
  1195. "active" => 'Y'
  1196. );
  1197. $dns_rr_id = $app->db->datalogInsert('dns_rr', $insert_data, 'id');
  1198. $remote->dns_rr_after_insert($dns_rr_id, $this->sys_usuario_id, $this->cli_grupo_id);
  1199. }
  1200. }
  1201. //sites_web_domain_add
  1202. $tform_def_file = "../sites/form/web_vhost_domain.tform.php";
  1203. $app->tform->loadFormDef($tform_def_file);
  1204. //print_r($fields);
  1205. //echo('La sesión user id ' . $_SESSION['s']['user']['userid']);
  1206. // add site
  1207. $paramsite = array(
  1208. 'type' => 'vhost',
  1209. 'domain' => $fields['domain'],
  1210. 'server_id' => $this->web_serv,// $web_servidor, //$server_id,//$dns_servidor['default_webserver'],
  1211. //IMPORTANTE. Aquí­ no se ponen los campos sys_userid ni sys_groupid, el evento on_after_insert
  1212. //'sys_userid' => $sysUsuarioId, //$fields['client_group_id'],//$sys_userid,
  1213. //'sys_groupid' => $cliente_groupid,
  1214. 'ip_address' => '*', //$dns_ip_servidor['ip_address'],
  1215. 'ipv6_address' => $this->ip6_servidor_web['ip_address'], //$this->ip6_ultima['ip_address'], //$dns_ip_servidor_ipv6['ip_address'],
  1216. 'traffic_quota' => '-1',
  1217. 'hd_quota' => '0',
  1218. 'cgi' => 'n',
  1219. 'ssi' => 'n',
  1220. 'suexec' => 'y',
  1221. 'ruby' => 'n',
  1222. 'python' => 'n',
  1223. 'perl' => 'n',
  1224. 'errordocs' => '1',
  1225. 'subdomain' => 'www',
  1226. 'php' => 'php-fpm',
  1227. 'fastcgi_php_version' => '',
  1228. 'seo_redirect' => '',
  1229. 'rewrite_to_https' => 'n',
  1230. 'allow_override' => 'All',
  1231. 'http_port' => 80,
  1232. 'https_port' => 443,
  1233. 'apache_directives' => '',
  1234. 'nginx_directives' => '',
  1235. 'php_fpm_use_socket' => 'y',
  1236. 'pm' => 'dynamic',
  1237. 'pm_max_children' => 10,
  1238. 'pm_start_servers' => 1,
  1239. 'pm_min_spare_servers' => 1,
  1240. 'pm_max_spare_servers' => 1,
  1241. 'pm_process_idle_timeout' => 10,
  1242. 'pm_max_requests' => 10,
  1243. 'custom_php_ini' => '',
  1244. 'active' => 'y',
  1245. 'document_root' => '-',
  1246. 'system_user' => '-',
  1247. 'system_group' => '-',
  1248. 'log_retention' => 30,
  1249. 'client_group_id' => $this->cli_grupo_id,//$cliente_groupid, //$client_group_id,
  1250. );
  1251. //print 'Valores: ' . $dns_ip_servidor_ipv6 . " " . $formulario . " Parametros: " ;
  1252. //print "<pre>"; print_r($paramsite); print "</pre>\n";
  1253. /*print '<pre> cliente id ' . $fields['client_id'];
  1254. print "<pre>";print_r($fields);print "</pre>\n";*/
  1255. //print "<pre>Formulario ";print_r($formulario);print "</pre>\n";
  1256. //$this->crearBaseDatosFtp($remote);
  1257. //print 'DNS IPV6 ' . $dns_ip_servidor_ipv6['ip_address'];
  1258. //IMPORTANTE. El último parámetro es para lanzar un evento que llama a la función on_after_insert
  1259. //que prepara los campos document_root, system_user y system_group
  1260. //$site_id = $remoto->insert_query('../sites/form/web_vhost_domain.tform.php', $fields['client_group_id'], $paramsite, 'sites:web_vhost_domain:on_after_insert');
  1261. //IMPORTANTE. ESTE ES EL ÚNICO PLUGING QUE FUNCIONA.
  1262. $site_id = $remoto->insert_query('../sites/form/web_vhost_domain.tform.php',
  1263. $this->cli_id, /*$cliente_id_seleccionado,*/
  1264. $paramsite, 'sites:web_vhost_domain:on_after_insert');
  1265. //print 'Sitio id '. $site_id;
  1266. }
  1267. function onSubmit() {
  1268. global $app, $conf;
  1269. /*$sesionesLog = $_SESSION["s"]["user"]["typ"];
  1270. $sesionesLog2 = $_SESSION["s"]["user"];
  1271. $sesiones = $_SESSION;
  1272. $sesionId = $_SESSION["s"]["id"];*/
  1273. //print_r($sesiones);
  1274. //print('la ssessison es ' .$ssionId);
  1275. //print_r($sesionesLog2);
  1276. if($this->plantillaWebDNS()){
  1277. return;
  1278. }
  1279. //Carga de campos del formulario.
  1280. $fields = $app->tform->encode($this->dataRecord, $app->tform->getCurrentTab(), true);
  1281. //Creo la clase remote para usar las librerias
  1282. $remote = new remote_actions;
  1283. if($this->tieneServidorIPs()){
  1284. return;
  1285. }
  1286. if($this->servidoresActivados()){
  1287. return;
  1288. }
  1289. //------INICIO LIMITES--------------------------------------------------------------------------------------------------
  1290. $limitado = new limites($this->cli_grupo_id);
  1291. $tieneLimitesDNS = $limitado->limClienteDns();
  1292. $tieneLimitesWeb = $limitado->limClienteWebDominio();
  1293. $tieneLimitesDB = $limitado->limClienteDB();
  1294. if($tieneLimitesDNS || $tieneLimitesWeb || $tieneLimitesDB){
  1295. return;
  1296. }
  1297. //------FIN LIMITES-----------------------------------------------------------------------------------------------------
  1298. if($this->existeDominio($fields)){
  1299. return;
  1300. }
  1301. //Esta variable nos llega por jQuery desde el htm para el control de errores en la vista.
  1302. if($_POST['create'] != 1)
  1303. {
  1304. $app->tform->errorMessage = 'DUMMY';
  1305. $app->tpl->setVar($this->dataRecord);
  1306. $this->onShow();
  1307. return;
  1308. }
  1309. if($this->comprobarSubDominios($fields['domain'])){
  1310. $this->crearSubDominio($remote, $fields['domain']);
  1311. if(!$this->subdom_error){
  1312. $this->crearSitioWebSubdominio($remote);
  1313. $this->crearBaseDatosFtp($remote);
  1314. }
  1315. } else {
  1316. if(!$this->dominio_error){
  1317. $this->crearDnsSitioWeb($remote);
  1318. //Si todo va bien, el resultado de la web y dns
  1319. echo '<br><div class="alert alert-success"><br>
  1320. Altas Web y DNS del dominio <b>'.$fields['domain'].'</b>, ¡Creadas correctamente!
  1321. <br><br></div></br>';
  1322. //IMPORTANTE, es necesario cargar nuestro formulario para poder ejecutar la función que crea
  1323. //la base de datos y el ftp ya que hay datos que tomamos de el antes de ejecutarla.
  1324. $app->tform->loadFormDef('form/new_service_webdns.tform.php');
  1325. $this->crearBaseDatosFtp($remote);
  1326. }else{
  1327. $this->onError();
  1328. return;
  1329. }
  1330. }
  1331. }
  1332. }
  1333. class remote_actions extends remoting {
  1334. public function insert_query($formdef_file, $client_id, $params, $event_identifier = '') {
  1335. global $app;
  1336. /*$sql = $this->insertQueryPrepare($formdef_file, $client_id, $params);
  1337. echo(' Query ' . $sql);
  1338. $app->uses('remoting_lib');
  1339. $app->remoting_lib->loadUserProfile();*/
  1340. //return $app->db->query($sql);//$this->insertQueryExecute($sql, $params, $event_identifier);
  1341. //echo(' insertQueryPrepare ' . $this->insertQueryExecute($sql, $params, $event_identifier));
  1342. return $this->insertQueryWebDNS($formdef_file, $client_id, $params, $event_identifier);
  1343. }
  1344. //------------------------------------------------------------------------------------------------------------
  1345. //IMPORTANTE. FUNCIONES EXTRAIDAS Y MODIFICADAS DE ISPCONFIG PARA SOLUCIONAR EL PROBLEMA DE AUTOLOGEO A ADMIN.
  1346. //------------------------------------------------------------------------------------------------------------
  1347. function insertQueryWebDNS($formdef_file, $client_id, $params, $event_identifier = '') {
  1348. //$sql = $app->remoting->insertQueryPrepare($formdef_file, $client_id, $params);
  1349. $sql = $this->insertQueryPrepareWebDNS($formdef_file, $client_id, $params);
  1350. if($sql !== false) return $this->insertQueryExecuteWebDNS($sql, $params, $event_identifier);
  1351. else return false;
  1352. }
  1353. function insertQueryPrepareWebDNS($formdef_file, $client_id, $params) {
  1354. global $app;
  1355. $app->uses('remoting_lib');
  1356. //* load the user profile of the client
  1357. //$app->remoting_lib->loadUserProfile($client_id);
  1358. //* Load the form definition
  1359. $app->remoting_lib->loadFormDef($formdef_file);
  1360. //echo(' Base de datos ' . $app->remoting_lib->loadFormDef($formdef_file));
  1361. //* Get the SQL query
  1362. $sql = $app->remoting_lib->getSQL($params, 'INSERT', 0);
  1363. /*if($app->remoting_lib->errorMessage != '') {
  1364. throw new SoapFault('data_processing_error', $app->remoting_lib->errorMessage);
  1365. return false;
  1366. }*/
  1367. $app->log('Executed insertQueryPrepareWebDNS', LOGLEVEL_DEBUG);
  1368. return $sql;
  1369. }
  1370. function insertQueryExecuteWebDNS($sql, $params, $event_identifier = '') {
  1371. global $app;
  1372. $app->uses('remoting_lib');
  1373. $app->db->query($sql);
  1374. /*if($app->db->errorMessage != '') {
  1375. throw new SoapFault('database_error', $app->db->errorMessage . ' '.$sql);
  1376. return false;
  1377. }*/
  1378. if ( isset($params['_primary_id'] ))
  1379. $insert_id = $params['_primary_id'];
  1380. else
  1381. $insert_id = $app->db->insertID();
  1382. // set a few values for compatibility with tform actions, mostly used by plugins
  1383. $this->id = $insert_id;
  1384. $this->dataRecord = $params;
  1385. $app->log('Executed insertQueryExecute, raising events now if any: ' . $event_identifier, LOGLEVEL_DEBUG);
  1386. if($event_identifier != '') $app->plugin->raiseEvent($event_identifier, $this);
  1387. //$app->uses('tform');
  1388. //* Save changes to Datalog
  1389. if($app->remoting_lib->formDef["db_history"] == 'yes') {
  1390. //$new_rec = $app->remoting_lib->getDataRecord($insert_id);
  1391. $new_rec = $this->getDataRecordWebDNS($insert_id);
  1392. $app->remoting_lib->datalogSave('INSERT', $primary_id, array(), $new_rec);
  1393. }
  1394. return $insert_id;
  1395. }
  1396. function sites_ftp_user_after_insert() {
  1397. global $app, $conf;
  1398. $web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ?", $this->dataRecord["parent_domain_id"]);
  1399. //echo(' Valor FTP ' . $this->dataRecord["parent_domain_id"]);
  1400. $server_id = $app->functions->intval($web["server_id"]);
  1401. $dir = $web["document_root"];
  1402. $uid = $web["system_user"];
  1403. $gid = $web["system_group"];
  1404. // Check system user and group
  1405. if($app->functions->is_allowed_user($uid) == false || $app->functions->is_allowed_group($gid) == false) {
  1406. $app->error('Invalid system user or group');
  1407. }
  1408. // The FTP user shall be owned by the same group then the website
  1409. $sys_groupid = $app->functions->intval($web['sys_groupid']);
  1410. $sql = "UPDATE ftp_user SET server_id = ?, dir = ?, uid = ?, gid = ?, sys_groupid = ? WHERE ftp_user_id = ?";
  1411. $app->db->query($sql, $server_id, $dir, $uid, $gid, $sys_groupid, $this->id);
  1412. }
  1413. function dns_rr_after_insert($dns_rr_id, $cliente_usuario_id, $cliente_grupo_id) {
  1414. global $app, $conf;
  1415. //echo(' el cliente grupo id ' . $cliente_grupo_id . ' el id tupla en dns_rr ' . $dns_rr_id);
  1416. if($_SESSION["s"]["user"]["typ"] == 'user') {
  1417. $app->db->datalogUpdate('dns_rr', array("sys_userid" => $cliente_usuario_id,
  1418. "sys_groupid" => $cliente_grupo_id), 'id', $dns_rr_id);
  1419. }
  1420. if($_SESSION["s"]["user"]["typ"] == 'admin') {
  1421. $app->db->datalogUpdate('dns_rr', array("sys_userid" => 1, //$cliente_grupo_id,
  1422. "sys_groupid" => $cliente_grupo_id), 'id', $dns_rr_id);
  1423. }
  1424. }
  1425. function dns_soa_after_insert($dns_soa_id, $cliente_usuario_id, $cliente_grupo_id) {
  1426. global $app, $conf;
  1427. //echo(' el cliente grupo id ' . $cliente_grupo_id . ' el id tupla en dns_rr ' . $dns_soa_id . ' sys usuario ' . $sys_usuario_id);
  1428. if($_SESSION["s"]["user"]["typ"] == 'user') {
  1429. $app->db->datalogUpdate('dns_soa', array("sys_userid" => $cliente_usuario_id,
  1430. "sys_groupid" => $cliente_grupo_id), 'id', $dns_soa_id);
  1431. }
  1432. if($_SESSION["s"]["user"]["typ"] == 'admin') {
  1433. $app->db->datalogUpdate('dns_soa', array("sys_userid" => 1, //$cliente_grupo_id,
  1434. "sys_groupid" => $cliente_grupo_id), 'id', $dns_soa_id);
  1435. }
  1436. }
  1437. function dns_registro_tipo_a_after_insert($cli_grupo_id) {
  1438. global $app, $conf;
  1439. //echo(' el valor zone ' . $this->dataRecord["zone"]);
  1440. //* Set the sys_groupid of the rr record to be the same then the sys_groupid of the soa record
  1441. if($_SESSION["s"]["user"]["typ"] == 'user') {
  1442. $soa = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ? AND " . $this->getAuthSQLWebDNS('r'), $this->dataRecord["zone"]);
  1443. $app->db->datalogUpdate('dns_rr', array("sys_groupid" => $soa['sys_groupid']), 'id', $this->id);
  1444. }
  1445. /*if($_SESSION["s"]["user"]["typ"] == 'admin') {
  1446. $soa = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ? AND " . $this->getAuthSQLWebDNS('r'), $this->dataRecord["zone"]);
  1447. $app->db->datalogUpdate('dns_rr', array("sys_groupid" => $soa['sys_groupid']), 'id', $this->id);
  1448. }*/
  1449. if($app->auth->has_clients($_SESSION['s']['user']['userid'])) {
  1450. $soa = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ? AND " . $this->getAuthSQLWebDNS('r'), $this->dataRecord["zone"]);
  1451. $app->db->datalogUpdate('dns_rr', array("sys_groupid" => $cli_grupo_id), 'id', $this->id);
  1452. }
  1453. //* Update the serial number of the SOA record
  1454. /*$soa_id = $app->functions->intval($_POST["zone"]);
  1455. $serial = $app->validate_dns->increase_serial($soa["serial"]);
  1456. $app->db->datalogUpdate('dns_soa', array("serial" => $serial), 'id', $soa_id);*/
  1457. }
  1458. public function sites_database_user_after_add($client_id, $params){
  1459. global $app, $conf;
  1460. //echo('Plugeando');
  1461. // if($_SESSION["s"]["user"]["typ"] == 'user' /*&& isset($this->dataRecord["client_group_id"])*/) {
  1462. //$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
  1463. $app->db->query("UPDATE web_database_user SET sys_groupid = ?, sys_perm_group = 'riud' WHERE database_user_id = ?", $client_id, $this->id);
  1464. /* }
  1465. if($_SESSION["s"]["user"]["typ"] == 'admin'/* && isset($this->dataRecord["client_group_id"])*///) {
  1466. //echo('Plugeando ' .$app->functions->intval($this->dataRecord["client_group_id"]) . ' y ' . $client_id . ' id ' . $this->id);
  1467. //$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
  1468. /* $app->db->query("UPDATE web_database_user SET sys_groupid = ?, sys_perm_group = 'riud' WHERE database_user_id = ?", $client_id, $this->id);
  1469. }
  1470. if($app->auth->has_clients($_SESSION['s']['user']['userid'])/* && isset($this->dataRecord["client_group_id"])*///) {
  1471. //$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);
  1472. /* $app->db->query("UPDATE web_database_user SET sys_groupid = ?, sys_perm_group = 'riud' WHERE database_user_id = ?", $client_id, $this->id);
  1473. }
  1474. $app->uses('sites_web_database_user_plugin');
  1475. global $app;
  1476. //Register for the events
  1477. $app->plugin->registerEvent('sites:web_database_user:on_after_update', 'sites_web_database_user_plugin', 'sites_web_database_user_edit');
  1478. $app->plugin->registerEvent('sites:web_database_user:on_after_insert', 'sites_web_database_user_plugin', 'sites_web_database_user_edit');
  1479. */
  1480. }
  1481. public function sites_database_user_add($session_id, $client_id, $params, $event_identifier = '') {
  1482. global $app;
  1483. /*if(!$this->checkPerm($session_id, 'sites_database_user_add')) {
  1484. throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
  1485. return false;
  1486. }*/
  1487. //echo(' la tablita ' . $this->formDef['db_table']);
  1488. return $this->insertQueryWebDNS('../sites/form/database_user.tform.php', $client_id, $params, $event_identifier);
  1489. }
  1490. function getDataRecordWebDNS($primary_id) {
  1491. global $app;
  1492. $escape = '`';
  1493. //$this->loadUserProfile();
  1494. if(@is_numeric($primary_id)) {
  1495. if($primary_id > 0) {
  1496. // Return a single record
  1497. //return $this->getDataRecordPadreWebDNS($primary_id);
  1498. return $app->tform->getDataRecord($primary_id);
  1499. //return parent::getDataRecord($primary_id);
  1500. } elseif($primary_id == -1) {
  1501. // Return a array with all records
  1502. $sql = "SELECT * FROM ??";
  1503. return $app->db->queryAllRecords($sql, $this->formDef['db_table']);
  1504. } else {
  1505. throw new SoapFault('invalid_id', 'The ID has to be > 0 or -1.');
  1506. return array();
  1507. }
  1508. } elseif (@is_array($primary_id) || @is_object($primary_id)) {
  1509. 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!
  1510. $sql_offset = 0;
  1511. $sql_limit = 0;
  1512. $sql_where = '';
  1513. $params = array($this->formDef['db_table']);
  1514. foreach($primary_id as $key => $val) {
  1515. if($key == '#OFFSET#') $sql_offset = $app->functions->intval($val);
  1516. elseif($key == '#LIMIT#') $sql_limit = $app->functions->intval($val);
  1517. elseif(stristr($val, '%')) {
  1518. $sql_where .= "?? like ? AND ";
  1519. } else {
  1520. $sql_where .= "?? = ? AND ";
  1521. }
  1522. $params[] = $key;
  1523. $params[] = $val;
  1524. }
  1525. $sql_where = substr($sql_where, 0, -5);
  1526. if($sql_where == '') $sql_where = '1';
  1527. //$sql = "SELECT * FROM ?? WHERE ".$sql_where. " AND " . $this->getAuthSQLWebDNS('r', $this->formDef['db_table']);
  1528. $sql = "SELECT * FROM ?? WHERE ".$sql_where. " AND " . $this->getAuthSQL('r', $this->formDef['db_table']);
  1529. if($sql_offset >= 0 && $sql_limit > 0) $sql .= ' LIMIT ' . $sql_offset . ',' . $sql_limit;
  1530. return $app->db->queryAllRecords($sql, true, $params);
  1531. } else {
  1532. $this->errorMessage = 'The ID must be either an integer or an array.';
  1533. return array();
  1534. }
  1535. }
  1536. /*function getDataRecordPadreWebDNS($primary_id) {
  1537. global $app;
  1538. $escape = '`';
  1539. $sql = "SELECT * FROM ?? WHERE ?? = ? AND ".$this->getAuthSQLWebDNS('r', $this->formDef['db_table']);
  1540. return $app->db->queryOneRecord($sql, $this->formDef['db_table'], $this->formDef['db_table_idx'], $primary_id);
  1541. }*/
  1542. function getAuthSQLWebDNS($perm, $table = '') {
  1543. if($_SESSION["s"]["user"]["typ"] == 'admin' || $_SESSION['s']['user']['mailuser_id'] > 0) {
  1544. return '1';
  1545. } else {
  1546. if ($table != ''){
  1547. $table = ' ' . $table . '.';
  1548. }
  1549. $groups = ( $_SESSION["s"]["user"]["groups"] ) ? $_SESSION["s"]["user"]["groups"] : 0;
  1550. $sql = '(';
  1551. $sql .= "(" . $table . "sys_userid = ".$_SESSION["s"]["user"]["userid"]." AND " . $table . "sys_perm_user like '%$perm%') OR ";
  1552. $sql .= "(" . $table . "sys_groupid IN (".$groups.") AND " . $table ."sys_perm_group like '%$perm%') OR ";
  1553. $sql .= $table . "sys_perm_other like '%$perm%'";
  1554. $sql .= ')';
  1555. return $sql;
  1556. }
  1557. }
  1558. //----------------------------------------------------------------------------------
  1559. //IMPORTANTE. ESTA FUNCION ES COMO LO HACE ISPCONFIG NO EXTRAIDA PERO SI MODIFICADA.
  1560. //----------------------------------------------------------------------------------
  1561. public function sites_database_add($client_id, $params){
  1562. global $app, $conf;
  1563. //IMPORTANTE. PARA QUE EL PLUGING FUNCIONE HAY QUE CARGAR ANTES EL FORMULARIO
  1564. //DE LO QUE SE QUIERE CREAR EN ESTE CASO SITIO WEB
  1565. $tform_def_file = "../sites/form/database.tform.php";
  1566. $app->tform->loadFormDef($tform_def_file);
  1567. $app->remoting_lib->loadFormDef('../sites/form/database.tform.php');
  1568. //$app->tform->formDef('../sites/form/database.tform.php');
  1569. //$sql = $app->remoting->insertQueryPrepare('../sites/form/database.tform.php', $client_id, $params);
  1570. $sql = $this->insertQueryPrepareWebDNS('../sites/form/database.tform.php', $client_id, $params);
  1571. if($sql !== false) {
  1572. $app->uses('sites_database_plugin');
  1573. //print_r($sql);
  1574. $this->id = 0;
  1575. $this->dataRecord = $params;
  1576. //$app->uses('sites_database_plugin');
  1577. //$app->sites_database_plugin->processDatabaseInsert($this);
  1578. //$retval = $this->insertQueryExecute($sql, $params);
  1579. $retval = $this->insertQueryExecuteWebDNS($sql, $params);
  1580. $app->sites_database_plugin->processDatabaseInsert($this);
  1581. //$app->plugin->raiseEvent('sites:web_database:on_after_insert', $this);
  1582. // set correct values for backup_interval and backup_copies
  1583. /*if(isset($params['backup_interval']) || isset($params['backup_copies'])){
  1584. $sql_set = array();
  1585. if(isset($params['backup_interval'])) $sql_set[] = "backup_interval = '".$app->db->quote($params['backup_interval'])."'";
  1586. if(isset($params['backup_copies'])) $sql_set[] = "backup_copies = ".$app->functions->intval($params['backup_copies']);
  1587. //$app->db->query("UPDATE web_database SET ".implode(', ', $sql_set)." WHERE database_id = ".$retval);
  1588. $this->updateQueryExecute("UPDATE web_database SET ".implode(', ', $sql_set)." WHERE database_id = ".$retval, $retval, $params);
  1589. }*/
  1590. return $retval;
  1591. }
  1592. return false;
  1593. }
  1594. }
  1595. $page = new page_action;
  1596. $page->onLoad();
  1597. //IMPORTENTE, es necesario estas lí­neas para que el botón del pdf funcione. Activa el javascript
  1598. //echo '<script type="text/javascript">';
  1599. //echo '</script>';
  1600. ?>
  1601. <!--IMPORTENTE, es necesario estas lí­neas para que el botón del pdf funcione. Activa el javascript -->
  1602. <script type="text/javascript">
  1603. </script>