ISPConfig module for simplify the creation of websites and DNS zones in a only step
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 

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