ISPConfig module for simplify the creation of websites and DNS zones in a only step
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 

1958 wiersze
80 KiB

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