ISPConfig module for simplify the creation of websites and DNS zones in a only step
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 

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