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

1586 строки
62 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. //require 'pdf_o6h.php';
  10. //Variable para cargar los distintos formularios.
  11. $tform_def_file = "form/new_service_webdns.tform.php";
  12. //Check permissions for module
  13. $app->auth->check_module_permissions('webdns');
  14. //Check the module permissions and redirect if not allowed.
  15. /*if(!stristr($_SESSION['s']['user']['modules'],'customdns')) {
  16. header('Location: ../index.php');
  17. die;
  18. }*/
  19. //Loading classes a usar.
  20. $app->uses('tpl,tform,tform_actions,remoting,tools_sites,remoting_lib,remoting_dns');
  21. $app->load('tform_actions');
  22. class page_action extends tform_actions {
  23. function onShowNew() {
  24. global $app;
  25. // we will check only users, not admins
  26. if($_SESSION['s']['user']['typ'] == 'user') {
  27. $app->error($app->tform->wordbook["error_usuario_no_permitido_webdns"]);
  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. if($fields['client_group_id']==0) {
  459. //En la tabla sys_user el userid 1 es admin. No esta en sys_group.
  460. $this->cli_id = 1;
  461. //En la tabla dns_soa y dns_rr se guarda el valor 0 en sys_groupid cuando es admin.
  462. $this->cli_grupo_id = 0;
  463. $this->sys_usuario_id = $this->cli_id;
  464. $this->sys_grupo_id = $this->cli_grupo_id;
  465. }else{
  466. $client = $app->db->queryOneRecord(
  467. 'SELECT sys_user.sys_userid, sys_user.sys_groupid, sys_user.default_group, sys_user.client_id
  468. FROM sys_group, sys_user
  469. WHERE sys_group.client_id = sys_user.client_id and sys_group.groupid = ?', $fields['client_group_id']);
  470. $this->cli_id = $client['client_id'];
  471. $this->cli_grupo_id = $client['default_group'];
  472. $this->sys_usuario_id = $client['sys_userid'];
  473. $this->sys_grupo_id = $client['sys_groupid'];
  474. }
  475. }
  476. //Crear subdominio
  477. function crearSubDominio($remoto, $campoSubDominio){
  478. global $app, $conf;
  479. $fields = $app->tform->encode($this->dataRecord, $app->tform->getCurrentTab(), true);
  480. //COMO LE PASO EL DOMINIO CORRECTO NO ES NECESARIO PONER EL % EN LA SQL AÑADO EL PUNTO.
  481. //EL PROBLEMA ES QUE CON UN DOMINIO .COM TOMA POR VALIDO UN .CO POR EL %
  482. //NO --> ('SELECT server_id, name FROM dns_rr WHERE name LIKE "'.$this->dominio.'%"');
  483. $existeDominioParaSubDominio = $app->db->queryOneRecord(
  484. 'SELECT server_id, name FROM dns_rr WHERE name LIKE "'.$this->dominio.'."');
  485. // print "<pre>En crearSubDominio campo que se le pasa subdominio es: "; print_r($campoSubDominio); print "</pre>\n";
  486. //Compruebo que el subdominio no existe consultando la tabla web_domain.
  487. $existeSubDominioWeb = $app->db->queryOneRecord(
  488. 'SELECT domain_id, domain FROM web_domain
  489. WHERE domain = "'.$campoSubDominio.'"');
  490. //Compruebo que el subdominio no existe consultando la tabla dns_rr
  491. $existeSubDominioTipoA = $app->db->queryOneRecord(
  492. 'SELECT name, type FROM dns_rr
  493. WHERE name = "'.$campoSubDominio.'" AND type = "A"');
  494. if(!$existeDominioParaSubDominio['name']){
  495. $this->subdom_error = true;
  496. $app->tform->errorMessage = $app->tform->wordbook['error_no_existe_dominio_padre'];
  497. // print "<pre>Error En crearSubDominio campo comprobacion dns_rr es: "; print_r($existeDominioParaSubDominio); print "</pre>\n";
  498. $this->onError();
  499. return;
  500. }
  501. // print "<pre>En crearSubDominio campo comprobacion dns_rr es: "; print_r($existeDominioParaSubDominio); print "</pre>\n";
  502. //print '<pre>El Sub existe '. $existeSubDominio['domain'];
  503. if($existeSubDominioWeb['domain']){
  504. $this->subdom_error = true;
  505. $app->tform->errorMessage = $app->tform->wordbook['error_no_existe_dominio_padre'];
  506. $this->onError();
  507. return $this->subdom_error;
  508. }
  509. if($existeSubDominioTipoA['name']){
  510. $this->subdom_error = true;
  511. $app->tform->errorMessage = $app->tform->wordbook['error_no_existe_dominio_padre'];
  512. $this->onError();
  513. return $this->subdom_error;
  514. }
  515. //$camDominio = $app->db->queryOneRecord('SELECT domain_id, domain FROM domain WHERE domain = "'.$this->dominio.'"');
  516. $camDominio = $app->db->queryOneRecord('SELECT origin FROM dns_soa WHERE origin LIKE "'.$this->dominio.'."');
  517. //$camDominio = $app->db->queryOneRecord('SELECT origin FROM dns_soa WHERE origin LIKE "'.$campoSubDominio.'%"');
  518. $camDnsRR = $app->db->queryOneRecord('SELECT server_id, zone FROM dns_rr WHERE name LIKE "'.$this->dominio.'."');
  519. //Para los registros tipo A la ip tiene que ser tipo IPv4
  520. $camServIP = $app->db->queryOneRecord(
  521. "SELECT ip_address FROM server_ip
  522. WHERE server_id = ".$camDnsRR['server_id']." AND ip_type='IPv4'");
  523. //print_r($camDominio);
  524. //print_r($camDnsRR);
  525. //Si el dominio NO existe mostramos mensaje de error y salimos de la ejecución
  526. if(!$camDominio['origin']){
  527. $this->subdom_error = true;
  528. $app->tform->errorMessage = $app->tform->wordbook['error_no_existe_dominio_padre'];
  529. $this->onError();
  530. //return;
  531. //print 'No existe el dominio';
  532. return $this->subdom_error;
  533. } else {
  534. //Parametros para la creación de subdominios
  535. $paramSubDominios = array(
  536. 'server_id' => $camDnsRR['server_id'],
  537. 'zone' => $camDnsRR['zone'],
  538. 'name' => $this->subdominio,
  539. 'type' => 'a',
  540. 'data' => $camServIP['ip_address'],
  541. //'aux' => '0',
  542. 'ttl' => '3600',
  543. 'active' => 'y',
  544. //comento el campo stamp, ya que introducia solo ceros en la bbdd
  545. //'stamp' => time(),
  546. 'serial' => '1',
  547. );
  548. //echo ('<br>El client_id GLOBAL ' . $this->cli_id . " <br>");
  549. // client group id
  550. /*$res = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = ".$app->functions->intval($fields['client_group_id']));
  551. $client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);//$res['groupid'];
  552. echo ('El client group id seleccion ' . $client_group_id . " <br>");
  553. echo ('El groupid de la tabla sys_group ' . $res['groupid'] . " ");*/
  554. //print "<pre>"; print_r($paramSubDominios); print "</pre>\n";
  555. //Inserto en bbdd usando la clase remoto que se la he pasado en parámetros de la función
  556. //$resultado = $remoto->insert_query('../dns/form/dns_a.tform.php', $fields['client_id'], $paramSubDominios);
  557. $resultado = $remoto->insert_query('form/dns_a_webdns.tform.php', $this->cli_id, /*$fields['client_group_id'],*/ $paramSubDominios);
  558. echo '<br><div class="alert alert-success"><br>
  559. Se ha dado de alta Web y Subdominio, <b>'.$this->subdominio.'</b>, ¡Correctamente!
  560. <br><br></div></br>';
  561. //$this->onShow();
  562. }
  563. }
  564. function crearSitioWebSubdominio($remoto){
  565. global $app, $conf;
  566. $fields = $app->tform->encode($this->dataRecord, $app->tform->getCurrentTab(), true);
  567. /* print "<pre>DNS SERVER ";print_r($this->dns_serv);print "</pre>\n";
  568. print "<pre>WEB SERVER ";print_r($this->web_serv);print "</pre>\n";
  569. print "<pre>IP4 DNS ";print_r($this->ip4_servidor_dns);print "</pre>\n";
  570. print "<pre>IP6 DNS ";print_r($this->ip6_servidor_dns);print "</pre>\n";
  571. print "<pre>IP4 WEB ";print_r($this->ip4_servidor_web);print "</pre>\n";
  572. print "<pre>IP6 WEB ";print_r($this->ip6_servidor_web);print "</pre>\n";
  573. print "<pre>IP6 WEB LA OTRA ";print_r($this->ip6_ultima['ip_address']);print "</pre>\n";
  574. */
  575. //add site
  576. $paramsite = array(
  577. //"sys_userid" => $this->sys_usuario_id,
  578. //"sys_groupid" => $this->cli_grupo_id,
  579. 'type' => 'vhost',
  580. 'domain' => $fields['domain'], //$this->subdominio,
  581. 'server_id' => $this->web_serv, //$server_id,
  582. 'ip_address' => '*',
  583. 'ipv6_address' =>$this->ip6_servidor_web['ip_address'],
  584. 'traffic_quota' => '-1',
  585. 'hd_quota' => '0',
  586. 'cgi' => 'y',
  587. 'ssi' => 'y',
  588. 'suexec' => 'y',
  589. 'ruby' => 'n',
  590. 'python' => 'n',
  591. 'perl' => 'n',
  592. 'errordocs' => '1',
  593. 'subdomain' => '',
  594. 'php' => 'php-fpm',
  595. 'fastcgi_php_version' => '',
  596. 'seo_redirect' => '',
  597. 'rewrite_to_https' => 'n',
  598. 'allow_override' => 'All',
  599. 'http_port' => 80,
  600. 'https_port' => 443,
  601. 'apache_directives' => '',
  602. 'nginx_directives' => '',
  603. 'php_fpm_use_socket' => 'y',
  604. 'pm' => 'ondemand',
  605. 'pm_max_children' => 10,
  606. 'pm_start_servers' => 1,
  607. 'pm_min_spare_servers' => 1,
  608. 'pm_max_spare_servers' => 5,
  609. 'pm_process_idle_timeout' => 10,
  610. 'pm_max_requests' => 0,
  611. 'custom_php_ini' => '',
  612. 'active' => 'y',
  613. 'document_root' => '-',
  614. 'system_user' => '-',
  615. 'system_group' => '-',
  616. 'log_retention' => 30,
  617. 'client_group_id' => $this->cli_grupo_id, //$client_group_id,
  618. );
  619. //print "<pre> Parametros:"; print_r($paramsite); print "</pre>\n";
  620. /*print '<pre> cliente id ' . $fields['client_id'];
  621. print "<pre>";print_r($fields);print "</pre>\n" . $fields['client_id'];*/
  622. //print '<pre>DNS IPV6 ' . $dns_ip_servidor_ipv6['ip_address'];
  623. //$tform_def_file2 = "../sites/form/web_vhost_domain.tform.php";
  624. //$app->tform->loadFormDef($tform_def_file2);
  625. //El último parámetro es para lanzar un evento que llama a la función on_after_insert que prepara
  626. //los campos document_root, system_user y system_group
  627. //$site_id = $remoto->insert_query('../sites/form/web_vhost_domain.tform.php', $fields['client_group_id'], $paramsite, 'sites:web_vhost_domain:on_after_insert');
  628. $site_id = $remoto->insert_query('../sites/form/web_vhost_domain.tform.php', $this->cli_id, $paramsite, 'sites:web_vhost_domain:on_after_insert');
  629. }
  630. public $ip4_servidor_dns;
  631. public $ip6_servidor_dns;
  632. public $ip4_servidor_web;
  633. public $ip6_servidor_web;
  634. public $ip4_servidor_bbdd;
  635. public $ip6_servidor_bbdd;
  636. public $ip4_servidor_ftp;
  637. public $ip6_servidor_ftp;
  638. public $dns_serv;
  639. public $web_serv;
  640. public $bbdd_serv;
  641. public $ftp_serv;
  642. function tieneServidorIPs(){
  643. global $app, $conf;
  644. $this->controlUserGrupoId();
  645. $app->uses('getconf');
  646. $global_config_sitio = $app->getconf->get_global_config('sites');
  647. $global_config_dns = $app->getconf->get_global_config('dns');
  648. //print "<pre>WEB SERVER por defecto ";print_r($global_config_sitio);print "</pre>\n";
  649. //print "<pre>DNS SERVER por defecto ";print_r($global_config_dns);print "</pre>\n";
  650. //El cliente 1 es admin.
  651. //Recupero los servidores asignados por defecto y se los asigno a admin o al usuario
  652. //que no tenga asignado ninguno.
  653. if($this->cli_id == 1) {
  654. $this->dns_serv = $global_config_dns['default_dnsserver'];//1;
  655. $this->web_serv = $global_config_sitio['default_webserver'];//1;
  656. $this->bbdd_serv = $global_config_sitio['default_dbserver'];//1;
  657. $this->ftp_serv = $global_config_sitio['default_webserver'];//1;
  658. }else{
  659. $servidores = $app->db->queryOneRecord(
  660. "SELECT client_id, dns_servers, web_servers, db_servers FROM client
  661. WHERE client_id = ". $this->cli_id);
  662. $this->dns_serv = $servidores['dns_servers'];
  663. $this->web_serv = $servidores['web_servers'];
  664. $this->bbdd_serv = $servidores['db_servers'];
  665. //para el ftp el servidor es el mismo que para el sitio web.
  666. $this->ftp_serv = $servidores['web_servers'];
  667. //Si el cliente no tiene asignado un servidor se añade por defecto al 1
  668. if(!$this->dns_serv){
  669. $this->dns_serv = $global_config_dns['default_dnsserver'];//1;
  670. }
  671. //Si el cliente no tiene asignado un servidor se añade por defecto al 1
  672. if(!$this->web_serv){
  673. $this->web_serv = $global_config_sitio['default_webserver'];//1;
  674. }
  675. //Si el cliente no tiene asignado un servidor se añade por defecto al 1
  676. if(!$this->bbdd_serv){
  677. $this->bbdd_serv = $global_config_sitio['default_dbserver'];//1;
  678. }
  679. //Si el cliente no tiene asignado un servidor se añade por defecto al 1
  680. if(!$this->ftp_serv){
  681. $this->ftp_serv = $global_config_sitio['default_webserver'];//1;
  682. }
  683. }
  684. /*print "<pre>DNS SERVER ";print_r($this->dns_serv);print "</pre>\n";
  685. print "<pre>WEB SERVER ";print_r($this->web_serv);print "</pre>\n";
  686. print "<pre>DB SERVER ";print_r($this->bbdd_serv);print "</pre>\n";
  687. print "<pre>FTP SERVER ";print_r($this->ftp_serv);print "</pre>\n";*/
  688. //El cliente 1 es admin
  689. //Captura de las ips del servidor dns
  690. if($this->cli_id == 1){
  691. //Compruebo si hay datos para el client_id 0 y si no existe pruebo con el 1.
  692. //Alguno de los dos tiene que existir por configuración de ispconfig.
  693. $this->ip4_servidor_dns = $app->db->queryOneRecord(
  694. 'SELECT ip_type, ip_address FROM server_ip
  695. WHERE client_id = "0" AND server_id = "'.$this->dns_serv.'" AND ip_type="IPv4"');
  696. $this->ip6_servidor_dns = $app->db->queryOneRecord(
  697. 'SELECT ip_type, ip_address FROM server_ip
  698. WHERE client_id = "0" AND server_id = "'.$this->dns_serv.'" AND ip_type="IPv6"');
  699. if(!$this->ip4_servidor_dns){
  700. $this->ip4_servidor_dns = $app->db->queryOneRecord(
  701. 'SELECT ip_type, ip_address FROM server_ip
  702. WHERE client_id = "1" AND server_id = "'.$this->dns_serv.'" AND ip_type="IPv4"');
  703. }
  704. if(!$this->ip6_servidor_dns){
  705. $this->ip6_servidor_dns = $app->db->queryOneRecord(
  706. 'SELECT ip_type, ip_address FROM server_ip
  707. WHERE client_id = "1" AND server_id = "'.$this->dns_serv.'" AND ip_type="IPv6"');
  708. }
  709. }else{//Comprobamos si el cliente tiene servidor asignado, si no lo tiene asignamos el que admin a seleccionado
  710. //para este servidor.
  711. $this->ip4_servidor_dns = $app->db->queryOneRecord(
  712. 'SELECT ip_type, ip_address
  713. FROM server_ip
  714. WHERE client_id = "'.$this->cli_id.'" AND server_id = "'.$this->dns_serv.'" AND ip_type="IPv4"');
  715. $this->ip6_servidor_dns = $app->db->queryOneRecord(
  716. 'SELECT ip_type, ip_address
  717. FROM server_ip
  718. WHERE client_id = "'.$this->cli_id.'" AND server_id = "'.$this->dns_serv.'"AND ip_type="IPv6"');
  719. //si no tiene asignado le damos el de admin.
  720. if(!$this->ip4_servidor_dns){
  721. //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
  722. //Tomamos las de admin.
  723. //Alguno de los dos tiene que existir por configuración de ispconfig.
  724. $this->ip4_servidor_dns = $app->db->queryOneRecord(
  725. 'SELECT ip_type, ip_address FROM server_ip
  726. WHERE client_id = "0" AND server_id = "'.$this->dns_serv.'" AND ip_type="IPv4"');
  727. if(!$this->ip4_servidor_dns){
  728. $this->ip4_servidor_dns = $app->db->queryOneRecord(
  729. 'SELECT ip_type, ip_address FROM server_ip
  730. WHERE client_id = "1" AND server_id = "'.$this->dns_serv.'" AND ip_type="IPv4"');
  731. }
  732. }
  733. if(!$this->ip6_servidor_dns){
  734. //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
  735. //Tomamos las de admin.
  736. //Alguno de los dos tiene que existir por configuración de ispconfig.
  737. //$this->ip4_servidor_dns = $app->db->queryOneRecord('SELECT ip_type, ip_address FROM server_ip WHERE client_id = "0" AND ip_type="IPv4"');
  738. $this->ip6_servidor_dns = $app->db->queryOneRecord(
  739. 'SELECT ip_type, ip_address FROM server_ip
  740. WHERE client_id = "0" AND server_id = "'.$this->dns_serv.'" AND ip_type="IPv6"');
  741. if(!$this->ip6_servidor_dns){
  742. $this->ip6_servidor_dns = $app->db->queryOneRecord(
  743. 'SELECT ip_type, ip_address FROM server_ip
  744. WHERE client_id = "1" AND server_id = "'.$this->dns_serv.'" AND ip_type="IPv6"');
  745. }
  746. }
  747. }
  748. //Captura de las ips del servidor web
  749. if($this->cli_id == 1){
  750. //Compruebo si hay datos para el client_id 0 y si no existe pruebo con el 1.
  751. //Alguno de los dos tiene que existir por configuración de ispconfig.
  752. $this->ip4_servidor_web = $app->db->queryOneRecord(
  753. 'SELECT ip_type, ip_address FROM server_ip
  754. WHERE client_id = "0" AND server_id = "'.$this->web_serv.'" AND ip_type="IPv4"');
  755. $this->ip6_servidor_web = $app->db->queryOneRecord(
  756. 'SELECT ip_type, ip_address FROM server_ip
  757. WHERE client_id = "0" AND server_id = "'.$this->web_serv.'" AND ip_type="IPv6"');
  758. if(!$this->ip4_servidor_web){
  759. $this->ip4_servidor_web = $app->db->queryOneRecord(
  760. 'SELECT ip_type, ip_address FROM server_ip
  761. WHERE client_id = "1" AND server_id = "'.$this->web_serv.'" AND ip_type="IPv4"');
  762. }
  763. if(!$this->ip6_servidor_web){
  764. $this->ip6_servidor_web = $app->db->queryOneRecord(
  765. 'SELECT ip_type, ip_address FROM server_ip
  766. WHERE client_id = "1" AND server_id = "'.$this->web_serv.'" AND ip_type="IPv6"');
  767. }
  768. }else{//Comprobamos si el cliente tiene servidor asignado
  769. $this->ip4_servidor_web = $app->db->queryOneRecord(
  770. 'SELECT ip_type, ip_address
  771. FROM server_ip
  772. WHERE client_id = "'.$this->cli_id.'" AND server_id = "'.$this->web_serv.'" AND ip_type="IPv4"');
  773. $this->ip6_servidor_web = $app->db->queryOneRecord(
  774. 'SELECT ip_type, ip_address
  775. FROM server_ip
  776. WHERE client_id = "'.$this->cli_id.'" AND server_id = "'.$this->web_serv.'"AND ip_type="IPv6"');
  777. //si no tiene asignado le damos el de admin.
  778. if(!$this->ip4_servidor_web){
  779. $this->ip4_servidor_web = $app->db->queryOneRecord(
  780. 'SELECT ip_type, ip_address FROM server_ip
  781. WHERE client_id = "0" AND server_id = "'.$this->web_serv.'" AND ip_type="IPv4"');
  782. if(!$this->ip4_servidor_web){
  783. $this->ip4_servidor_web = $app->db->queryOneRecord(
  784. 'SELECT ip_type, ip_address FROM server_ip
  785. WHERE client_id = "1" AND server_id = "'.$this->web_serv.'" AND ip_type="IPv4"');
  786. }
  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 = "0" AND server_id = "'.$this->web_serv.'" AND ip_type="IPv6"');
  792. if(!$this->ip6_servidor_web){
  793. $this->ip6_servidor_web = $app->db->queryOneRecord(
  794. 'SELECT ip_type, ip_address FROM server_ip
  795. WHERE client_id = "1" AND server_id = "'.$this->web_serv.'" AND ip_type="IPv6"');
  796. }
  797. }
  798. }
  799. //Captura de las ips del servidor bbdd
  800. if($this->cli_id == 1){
  801. //Compruebo si hay datos para el client_id 0 y si no existe pruebo con el 1.
  802. //Alguno de los dos tiene que existir por configuración de ispconfig.
  803. $this->ip4_servidor_bbdd = $app->db->queryOneRecord(
  804. 'SELECT ip_type, ip_address FROM server_ip
  805. WHERE client_id = "0" AND server_id = "'.$this->bbdd_serv.'" AND ip_type="IPv4"');
  806. $this->ip6_servidor_bbdd = $app->db->queryOneRecord(
  807. 'SELECT ip_type, ip_address FROM server_ip
  808. WHERE client_id = "0" AND server_id = "'.$this->bbdd_serv.'" AND ip_type="IPv6"');
  809. if(!$this->ip4_servidor_bbdd){
  810. $this->ip4_servidor_bbdd = $app->db->queryOneRecord(
  811. 'SELECT ip_type, ip_address FROM server_ip
  812. WHERE client_id = "1" AND server_id = "'.$this->bbdd_serv.'" AND ip_type="IPv4"');
  813. }
  814. if(!$this->ip6_servidor_bbdd){
  815. $this->ip6_servidor_bbdd = $app->db->queryOneRecord(
  816. 'SELECT ip_type, ip_address FROM server_ip
  817. WHERE client_id = "1" AND server_id = "'.$this->bbdd_serv.'" AND ip_type="IPv6"');
  818. }
  819. }else{//Comprobamos si el cliente tiene servidor asignado
  820. $this->ip4_servidor_bbdd = $app->db->queryOneRecord(
  821. 'SELECT ip_type, ip_address
  822. FROM server_ip
  823. WHERE client_id = "'.$this->cli_id.'" AND server_id = "'.$this->bbdd_serv.'" AND ip_type="IPv4"');
  824. $this->ip6_servidor_bbdd = $app->db->queryOneRecord(
  825. 'SELECT ip_type, ip_address
  826. FROM server_ip
  827. WHERE client_id = "'.$this->cli_id.'" AND server_id = "'.$this->bbdd_serv.'"AND ip_type="IPv6"');
  828. //si no tiene asignado le damos el de admin.
  829. if(!$this->ip4_servidor_bbdd){
  830. //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
  831. //Tomamos las de admin.
  832. //Alguno de los dos tiene que existir por configuración de ispconfig.
  833. $this->ip4_servidor_bbdd = $app->db->queryOneRecord(
  834. 'SELECT ip_type, ip_address FROM server_ip
  835. WHERE client_id = "0" AND server_id = "'.$this->bbdd_serv.'" AND ip_type="IPv4"');
  836. if(!$this->ip4_servidor_bbdd){
  837. $this->ip4_servidor_bbdd = $app->db->queryOneRecord(
  838. 'SELECT ip_type, ip_address FROM server_ip
  839. WHERE client_id = "1" AND server_id = "'.$this->bbdd_serv.'" AND ip_type="IPv4"');
  840. }
  841. }
  842. if(!$this->ip6_servidor_bbdd){
  843. $this->ip6_servidor_bbdd = $app->db->queryOneRecord(
  844. 'SELECT ip_type, ip_address FROM server_ip
  845. WHERE client_id = "0" AND server_id = "'.$this->bbdd_serv.'" AND ip_type="IPv6"');
  846. if(!$this->ip6_servidor_bbdd){
  847. $this->ip6_servidor_bbdd = $app->db->queryOneRecord(
  848. 'SELECT ip_type, ip_address FROM server_ip
  849. WHERE client_id = "1" AND server_id = "'.$this->bbdd_serv.'" AND ip_type="IPv6"');
  850. }
  851. }
  852. }
  853. //para el servidor ftp no se hacen comprobaciones
  854. //ya que las ips son las mismas que para el servidor web.
  855. //$la_ip4 = $app->db->queryOneRecord("SELECT ip_type, ip_address FROM server_ip WHERE ip_type='IPv4'");
  856. $this->ip4_pdf = $this->ip4_servidor_dns['ip_address'];//$dns_ip_servidor['ip_address'];//$la_ip4['ip_address'];
  857. /*print "<pre>IP4 DNS ";print_r($this->ip4_servidor_dns);print "</pre>\n";
  858. print "<pre>IP6 DNS ";print_r($this->ip6_servidor_dns);print "</pre>\n";
  859. print "<pre>IP4 WEB ";print_r($this->ip4_servidor_web);print "</pre>\n";
  860. print "<pre>IP6 WEB ";print_r($this->ip6_servidor_web);print "</pre>\n";
  861. print "<pre>IP4 BBDD ";print_r($this->ip4_servidor_bbdd);print "</pre>\n";
  862. print "<pre>IP6 BBDD ";print_r($this->ip6_servidor_bbdd);print "</pre>\n";
  863. echo('El cliente ' . $this->cli_id . '<br>');*/
  864. if(!$this->ip4_servidor_dns['ip_address']){
  865. $servicio_dns = $app->db->queryOneRecord(
  866. 'SELECT server_id, dns_server, server_name FROM server
  867. WHERE server_id = "'.$this->dns_serv.'"');
  868. $nom_serv_dns = $servicio_dns['server_name'];
  869. $app->tform->errorMessage = $app->tform->wordbook['error_no_ip']. 'la IP4 para el servidor ' . $nom_serv_dns;
  870. $this->onError();
  871. return true;
  872. }
  873. if(!$this->ip6_servidor_dns['ip_address']){
  874. $servicio_dns = $app->db->queryOneRecord(
  875. 'SELECT server_id, dns_server, server_name FROM server
  876. WHERE server_id = "'.$this->dns_serv.'"');
  877. $nom_serv_dns = $servicio_dns['server_name'];
  878. $app->tform->errorMessage = $app->tform->wordbook['error_no_ip']. 'la IP6 para el servidor '. $nom_serv_dns;
  879. $this->onError();
  880. return true;
  881. }
  882. if(!$this->ip4_servidor_web['ip_address']){
  883. $servidor_web = $app->db->queryOneRecord(
  884. 'SELECT server_id, web_server, server_name FROM server
  885. WHERE server_id = "'.$this->web_serv.'"');
  886. $nom_serv_web = $servidor_web['server_name'];
  887. $app->tform->errorMessage = $app->tform->wordbook['error_no_ip']. 'la IP4 para el servidor ' . $nom_serv_web;
  888. $this->onError();
  889. return true;
  890. }
  891. if(!$this->ip6_servidor_web['ip_address']){
  892. $servidor_web = $app->db->queryOneRecord(
  893. 'SELECT server_id, web_server, server_name FROM server
  894. WHERE server_id = "'.$this->web_serv.'"');
  895. $nom_serv_web = $servidor_web['server_name'];
  896. $app->tform->errorMessage = $app->tform->wordbook['error_no_ip']. 'la IP6 para el servidor ' . $nom_serv_web;
  897. $this->onError();
  898. return true;
  899. }
  900. if(!$this->ip4_servidor_bbdd['ip_address']){
  901. $servicio_db = $app->db->queryOneRecord(
  902. 'SELECT server_id, db_server, server_name FROM server
  903. WHERE server_id = "'.$this->bbdd_serv.'"');
  904. $nom_serv_db = $servicio_db['server_name'];
  905. $app->tform->errorMessage = $app->tform->wordbook['error_no_ip']. 'la IP4 para el servidor ' . $nom_serv_db;
  906. $this->onError();
  907. return true;
  908. }
  909. if(!$this->ip6_servidor_bbdd['ip_address']){
  910. $servicio_db = $app->db->queryOneRecord(
  911. 'SELECT server_id, db_server, server_name FROM server
  912. WHERE server_id = "'.$this->bbdd_serv.'"');
  913. $nom_serv_db = $servicio_db['server_name'];
  914. $app->tform->errorMessage = $app->tform->wordbook['error_no_ip']. 'la IP6 para el servidor ' . $nom_serv_db;
  915. $this->onError();
  916. return true;
  917. }
  918. return false;
  919. }
  920. //Comprueba si los servidores asignados al usuario seleccionado tiene los servicios activos para cada caso.
  921. function servidoresActivados(){
  922. global $app, $conf;
  923. $servicio_web = $app->db->queryOneRecord(
  924. 'SELECT server_id, web_server, server_name FROM server
  925. WHERE server_id = "'.$this->web_serv.'"');
  926. $nom_serv_web = $servicio_web['server_name'];
  927. $servicio_dns = $app->db->queryOneRecord(
  928. 'SELECT server_id, dns_server, server_name FROM server
  929. WHERE server_id = "'.$this->dns_serv.'"');
  930. $nom_serv_dns = $servicio_dns['server_name'];
  931. $servicio_ftp = $app->db->queryOneRecord(
  932. 'SELECT server_id, file_server, server_name FROM server
  933. WHERE server_id = "'.$this->ftp_serv.'"');
  934. $nom_serv_ftp = $servicio_ftp['server_name'];
  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. //print "<pre>Servidor WEB ";print_r($servicio_web);print "</pre>\n";
  940. if($servicio_web['web_server'] == 0){
  941. $app->tform->errorMessage = $app->tform->wordbook['error_activado_servidor'] . $nom_serv_web . ' el servicio WEB.';
  942. $this->onError();
  943. return true;
  944. }
  945. //print "<pre>Servidor DNS ";print_r($servicio_dns);print "</pre>\n";
  946. if($servicio_dns['dns_server'] == 0){
  947. $app->tform->errorMessage = $app->tform->wordbook['error_activado_servidor'] . $nom_serv_dns . ' el servicio DNS.';
  948. $this->onError();
  949. return true;
  950. }
  951. //print "<pre>Servidor FTP ";print_r($servicio_ftp);print "</pre>\n";
  952. if($servicio_ftp['file_server'] == 0){
  953. $app->tform->errorMessage = $app->tform->wordbook['error_activado_servidor'] . $nom_serv_ftp . ' el servicio FTP.';
  954. $this->onError();
  955. return true;
  956. }
  957. //print "<pre>Servidor DB ";print_r($servicio_db);print "</pre>\n";
  958. if($servicio_db['db_server'] == 0){
  959. $app->tform->errorMessage = $app->tform->wordbook['error_activado_servidor'] . $nom_serv_db . ' el servicio DB.';
  960. $this->onError();
  961. return true;
  962. }
  963. /*$servidores = $app->db->queryAllRecords(
  964. 'SELECT server_id, server_name, web_server, dns_server, file_server, db_server FROM server');
  965. foreach($servidores as $servidor){
  966. $serv_web = $servidor['web_server'];
  967. $serv_dns = $servidor['dns_server'];
  968. $serv_ftp = $servidor['file_server'];
  969. $serv_db = $servidor['db_server'];
  970. $nombre_server = $servidor['server_name'];
  971. //print "<pre>Todos los servidores ";print_r($servidor);print "</pre>\n";
  972. //Si alguno de los servidores no esta activo, mostramos error.
  973. if($serv_web == 0){
  974. $app->tform->errorMessage = $app->tform->wordbook['error_activado_servidor'] . $nombre_server . ' el servicio WEB';
  975. $this->onError();
  976. return true;
  977. } else if($serv_dns == 0){
  978. $app->tform->errorMessage = $app->tform->wordbook['error_activado_servidor'] . $nombre_server . ' el servicio DNS';
  979. $this->onError();
  980. return true;
  981. } else if($serv_ftp == 0){
  982. $app->tform->errorMessage = $app->tform->wordbook['error_activado_servidor'] . $nombre_server . ' el servicio FTP';
  983. $this->onError();
  984. return true;
  985. } else if($serv_db == 0){
  986. $app->tform->errorMessage = $app->tform->wordbook['error_activado_servidor'] . $nombre_server . ' el servicio DB';
  987. $this->onError();
  988. return true;
  989. }*/
  990. //}
  991. return false;
  992. }
  993. //Comprueba que no exista el dominio y que no tenga sitio web, puede tener sitio web y no tener dns.
  994. function existeDominio($campos){
  995. global $app, $conf;
  996. if($app->db->queryOneRecord('SELECT * FROM dns_soa WHERE origin LIKE "'.$campos['domain'].'%"')) {
  997. $app->tform->errorMessage = $app->tform->wordbook['domain_error_unique'];
  998. }
  999. if($app->db->queryOneRecord('SELECT domain_id, domain FROM web_domain WHERE domain = "'.$campos['domain'].'"')) {
  1000. $app->tform->errorMessage = $app->tform->wordbook['error_sitio_web_existe'];
  1001. }
  1002. if($app->tform->errorMessage)
  1003. {
  1004. $this->onError();
  1005. return true;
  1006. }
  1007. }
  1008. public $ip4_ultima;
  1009. public $ip6_ultima;
  1010. //Creación del las dns y sitio web para un dominio.
  1011. function crearDnsSitioWeb($remoto){
  1012. global $app, $conf;
  1013. //Carga de los campos del formulario.
  1014. $fields = $app->tform->encode($this->dataRecord, $app->tform->getCurrentTab(), true);
  1015. //Carga del formulario dns_soa para guardar en base de datos.
  1016. $tform_def_file = "../dns/form/dns_soa.tform.php";
  1017. $app->tform->loadFormDef($tform_def_file);
  1018. //Carga y seleccion de dns_template, si no esta creado se informa de que tiene que crearse.
  1019. $template_record = $app->db->queryOneRecord(
  1020. "SELECT * FROM dns_template WHERE visible = 'Y' AND name = 'webdns'"); /*'open6hosting'");*/
  1021. /*print "<pre>DNS SERVER ";print_r($this->dns_serv);print "</pre>\n";
  1022. print "<pre>WEB SERVER ";print_r($this->web_serv);print "</pre>\n";
  1023. print "<pre>IP4 DNS ";print_r($this->ip4_servidor_dns);print "</pre>\n";
  1024. print "<pre>IP6 DNS ";print_r($this->ip6_servidor_dns);print "</pre>\n";
  1025. print "<pre>IP4 WEB ";print_r($this->ip4_servidor_web);print "</pre>\n";
  1026. print "<pre>IP6 WEB ";print_r($this->ip6_servidor_web);print "</pre>\n";*/
  1027. //Si el servidor es el que tiene asignado el cliente o el de admin por defecto, le damos esta ip4
  1028. if($this->dns_serv && $this->ip4_servidor_dns){
  1029. $this->ip4_ultima = $this->ip4_servidor_dns;
  1030. }
  1031. if($this->dns_serv && $this->ip6_servidor_dns){
  1032. $this->ip6_ultima = $this->ip6_servidor_dns;
  1033. }
  1034. if($this->web_serv && $this->ip4_servidor_web){
  1035. $this->ip4_ultima = $this->ip4_servidor_web;
  1036. }
  1037. if($this->web_serv && $this->ip6_servidor_web){
  1038. $this->ip6_ultima = $this->ip6_servidor_web;
  1039. }
  1040. $tpl_content = $template_record['template'];
  1041. // Reemplazo la variable que nos encontramos en base de datos por el valor que se ha introducido en el formulario
  1042. $tpl_content = str_replace('{DOMAIN}', $fields['domain'], $tpl_content);
  1043. //Carga de los datos en las variables de las ips.
  1044. $tpl_content = str_replace('{IP}', $this->ip4_ultima['ip_address'],/*$dns_ip_servidor['ip_address'],*/ $tpl_content);
  1045. $tpl_content = str_replace('{IPV6}', $this->ip6_ultima['ip_address'], /*$dns_ip_servidor_ipv6['ip_address'],*/ $tpl_content);
  1046. $enable_dnssec = 'N';//(($_POST['dns_dnssec'] == 'Y') ? 'Y' : 'N');
  1047. // Parse the template
  1048. $tpl_rows = explode("\n", $tpl_content);
  1049. $section = '';
  1050. $vars = array();
  1051. $vars['xfer']='';
  1052. $dns_rr = array();
  1053. foreach($tpl_rows as $row) {
  1054. $row = trim($row);
  1055. if(substr($row, 0, 1) == '[') {
  1056. if($row == '[ZONE]') {
  1057. $section = 'zone';
  1058. } elseif($row == '[DNS_RECORDS]') {
  1059. $section = 'dns_records';
  1060. } else {
  1061. die('Unknown section type');
  1062. }
  1063. } else {
  1064. if($row != '') {
  1065. // Handle zone section
  1066. if($section == 'zone') {
  1067. $parts = explode('=', $row);
  1068. $key = trim($parts[0]);
  1069. $val = trim($parts[1]);
  1070. if($key != '') $vars[$key] = $val;
  1071. }
  1072. // Handle DNS Record rows
  1073. if($section == 'dns_records') {
  1074. $parts = explode('|', $row);
  1075. $dns_rr[] = array(
  1076. 'name' => $parts[1],
  1077. 'type' => $parts[0],
  1078. 'data' => $parts[2],
  1079. 'aux' => $parts[3],
  1080. 'ttl' => $parts[4]
  1081. );
  1082. }
  1083. }
  1084. }
  1085. } // end foreach
  1086. // Insert the soa record
  1087. $sys_userid = $this->cli_id;//$cliente_id_seleccionado;//$fields['client_group_id'];
  1088. $origin = $vars['origin'];
  1089. $ns = $vars['ns'];
  1090. $mbox = str_replace('@', '.', $vars['mbox']);
  1091. $refresh = $vars['refresh'];
  1092. $retry = $vars['retry'];
  1093. $expire = $vars['expire'];
  1094. $minimum = $vars['minimum'];
  1095. $ttl = $vars['ttl'];
  1096. $xfer = $vars['xfer'];
  1097. $also_notify = $vars['also_notify'];
  1098. $update_acl = $vars['update_acl'];
  1099. $serial = $app->validate_dns->increase_serial(0);
  1100. $insert_data = array(
  1101. "sys_userid" => $this->sys_usuario_id,//$sysUsuarioId,//$fields['client_group_id'],
  1102. "sys_groupid" => $this->cli_grupo_id,//$cliente_groupid,//$client_group_id,
  1103. "sys_perm_user" => 'riud',
  1104. "sys_perm_group" => 'riud',
  1105. "sys_perm_other" => '',
  1106. "server_id" => $this->dns_serv, //$dns_servidor,//$server_id,//$dns_servidor, //$server_id,//$dns_servidor['default_dnsserver'],
  1107. "origin" => $origin,
  1108. "ns" => $ns,
  1109. "mbox" => $mbox,
  1110. "serial" => $serial,
  1111. "refresh" => $refresh,
  1112. "retry" => $retry,
  1113. "expire" => $expire,
  1114. "minimum" => $minimum,
  1115. "ttl" => $ttl,
  1116. "active" => 'Y',
  1117. "xfer" => $xfer,
  1118. "also_notify" => $also_notify,
  1119. "update_acl" => $update_acl,
  1120. "dnssec_wanted" => $enable_dnssec
  1121. );
  1122. $dns_soa_id = $app->db->datalogInsert('dns_soa', $insert_data, 'id');
  1123. // Insert the dns_rr records
  1124. if(is_array($dns_rr) && $dns_soa_id > 0) {
  1125. foreach($dns_rr as $rr) {
  1126. $insert_data = array(
  1127. "sys_userid" => $this->sys_usuario_id,//$sysUsuarioId, //$fields['client_group_id'],
  1128. "sys_groupid" => $this->cli_grupo_id,//$cliente_groupid, //$client_group_id,
  1129. "sys_perm_user" => 'riud',
  1130. "sys_perm_group" => 'riud',
  1131. "sys_perm_other" => '',
  1132. "server_id" => $this->dns_serv,
  1133. "zone" => $dns_soa_id,
  1134. "name" => $rr['name'],
  1135. "type" => $rr['type'],
  1136. "data" => $rr['data'],
  1137. "aux" => $rr['aux'],
  1138. "ttl" => $rr['ttl'],
  1139. "active" => 'Y'
  1140. );
  1141. $dns_rr_id = $app->db->datalogInsert('dns_rr', $insert_data, 'id');
  1142. }
  1143. }
  1144. //sites_web_domain_add
  1145. $tform_def_file = "../sites/form/web_vhost_domain.tform.php";
  1146. $app->tform->loadFormDef($tform_def_file);
  1147. //print_r($fields);
  1148. //echo('La sesión user id ' . $_SESSION['s']['user']['userid']);
  1149. // add site
  1150. $paramsite = array(
  1151. 'type' => 'vhost',
  1152. 'domain' => $fields['domain'],
  1153. 'server_id' => $this->web_serv,// $web_servidor, //$server_id,//$dns_servidor['default_webserver'],
  1154. //IMPORTANTE. Aquí no se ponen los campos sys_userid ni sys_groupid, el evento on_after_insert
  1155. //'sys_userid' => $sysUsuarioId, //$fields['client_group_id'],//$sys_userid,
  1156. //'sys_groupid' => $cliente_groupid,
  1157. 'ip_address' => '*', //$dns_ip_servidor['ip_address'],
  1158. 'ipv6_address' => $this->ip6_servidor_web['ip_address'], //$this->ip6_ultima['ip_address'], //$dns_ip_servidor_ipv6['ip_address'],
  1159. 'traffic_quota' => '-1',
  1160. 'hd_quota' => '0',
  1161. 'cgi' => 'y',
  1162. 'ssi' => 'y',
  1163. 'suexec' => 'y',
  1164. 'ruby' => 'n',
  1165. 'python' => 'n',
  1166. 'perl' => 'n',
  1167. 'errordocs' => '1',
  1168. 'subdomain' => 'www',
  1169. 'php' => 'php-fpm',
  1170. 'fastcgi_php_version' => '',
  1171. 'seo_redirect' => '',
  1172. 'rewrite_to_https' => 'n',
  1173. 'allow_override' => 'All',
  1174. 'http_port' => 80,
  1175. 'https_port' => 443,
  1176. 'apache_directives' => '',
  1177. 'nginx_directives' => '',
  1178. 'php_fpm_use_socket' => 'y',
  1179. 'pm' => 'ondemand',
  1180. 'pm_max_children' => 10,
  1181. 'pm_start_servers' => 1,
  1182. 'pm_min_spare_servers' => 1,
  1183. 'pm_max_spare_servers' => 5,
  1184. 'pm_process_idle_timeout' => 10,
  1185. 'pm_max_requests' => 0,
  1186. 'custom_php_ini' => '',
  1187. 'active' => 'y',
  1188. 'document_root' => '-',
  1189. 'system_user' => '-',
  1190. 'system_group' => '-',
  1191. 'log_retention' => 30,
  1192. 'client_group_id' => $this->cli_grupo_id,//$cliente_groupid, //$client_group_id,
  1193. );
  1194. //print 'Valores: ' . $dns_ip_servidor_ipv6 . " " . $formulario . " Parametros: " ;
  1195. //print "<pre>"; print_r($paramsite); print "</pre>\n";
  1196. /*print '<pre> cliente id ' . $fields['client_id'];
  1197. print "<pre>";print_r($fields);print "</pre>\n";*/
  1198. //print "<pre>Formulario ";print_r($formulario);print "</pre>\n";
  1199. //$this->crearBaseDatosFtp($remote);
  1200. //print 'DNS IPV6 ' . $dns_ip_servidor_ipv6['ip_address'];
  1201. //IMPORTANTE. El último parámetro es para lanzar un evento que llama a la función on_after_insert
  1202. //que prepara los campos document_root, system_user y system_group
  1203. //$site_id = $remoto->insert_query('../sites/form/web_vhost_domain.tform.php', $fields['client_group_id'], $paramsite, 'sites:web_vhost_domain:on_after_insert');
  1204. $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');
  1205. //print 'Sitio id '. $site_id;
  1206. }
  1207. function onSubmit() {
  1208. global $app, $conf;
  1209. //Carga de campos del formulario.
  1210. $fields = $app->tform->encode($this->dataRecord, $app->tform->getCurrentTab(), true);
  1211. //Creo la clase remote para usar las librerias
  1212. $remote = new remote_actions;
  1213. if($this->tieneServidorIPs()){
  1214. return;
  1215. }
  1216. if($this->servidoresActivados()){
  1217. return;
  1218. }
  1219. if($this->existeDominio($fields)){
  1220. return;
  1221. }
  1222. //Esta variable nos llega por jQuery desde el htm para el control de errores en la vista.
  1223. if($_POST['create'] != 1)
  1224. {
  1225. $app->tform->errorMessage = 'DUMMY';
  1226. $app->tpl->setVar($this->dataRecord);
  1227. $this->onShow();
  1228. return;
  1229. }
  1230. /*echo ('Lo seleccionado ' . $fields['client_group_id'] . " <br>");
  1231. echo ('Tabla sys_group --> client id ' . $this->cli_id . " <br>");
  1232. echo ('Tabla sys_group --> groupid ' . $this->cli_grupo_id . " <br>");
  1233. echo ('Tabla sys_user --> userid ' . $this->sys_usuario_id . " <br>");
  1234. echo ('Tabla sys_user --> sys_groupid ' . $this->sys_grupo_id . " <br>");*/
  1235. //print "Subdomino: " . $this->subdomino . "</p>\n Dominio: " . $this->domino;
  1236. if($this->comprobarSubDominios($fields['domain'])){
  1237. $this->crearSubDominio($remote, $fields['domain']);
  1238. if(!$this->subdom_error){
  1239. $this->crearSitioWebSubdominio($remote);
  1240. $this->crearBaseDatosFtp($remote);
  1241. }
  1242. } else {
  1243. if(!$this->dominio_error){
  1244. $this->crearDnsSitioWeb($remote);
  1245. //$variablePHP = "<script> document.write(test) </script>";
  1246. //Si todo va bien, el resultado de la web y dns
  1247. echo '<br><div class="alert alert-success"><br>
  1248. Altas Web y DNS del dominio <b>'.$fields['domain'].'</b>, ¡Creadas correctamente!
  1249. <br><br></div></br>';
  1250. //IMPORTANTE, es necesario cargar nuestro formulario para poder ejecutar la función que crea
  1251. //la base de datos y el ftp ya que hay datos que tomamos de él antes de ejecutarla.
  1252. $app->tform->loadFormDef('form/new_service_webdns.tform.php');
  1253. $this->crearBaseDatosFtp($remote);
  1254. }else{
  1255. $this->onError();
  1256. return;
  1257. }
  1258. }
  1259. }
  1260. }
  1261. class remote_actions extends remoting {
  1262. public function insert_query($formdef_file, $client_id, $params, $event_identifier = '') {
  1263. return $this->insertQuery($formdef_file, $client_id, $params, $event_identifier);
  1264. }
  1265. public function sites_database_add($client_id, $params){
  1266. global $app, $conf;
  1267. //$app->remoting_lib->loadFormDef('../sites/form/database.tform.php');
  1268. //$app->tform->formDef('../sites/form/database.tform.php');
  1269. $sql = $this->insertQueryPrepare('../sites/form/database.tform.php', $client_id, $params);
  1270. if($sql !== false) {
  1271. $app->uses('sites_database_plugin');
  1272. //print_r($sql);
  1273. $this->id = 0;
  1274. $this->dataRecord = $params;
  1275. //$app->uses('sites_database_plugin');
  1276. $app->sites_database_plugin->processDatabaseInsert($this);
  1277. $retval = $this->insertQueryExecute($sql, $params);
  1278. // set correct values for backup_interval and backup_copies
  1279. if(isset($params['backup_interval']) || isset($params['backup_copies'])){
  1280. $sql_set = array();
  1281. if(isset($params['backup_interval'])) $sql_set[] = "backup_interval = '".$app->db->quote($params['backup_interval'])."'";
  1282. if(isset($params['backup_copies'])) $sql_set[] = "backup_copies = ".$app->functions->intval($params['backup_copies']);
  1283. //$app->db->query("UPDATE web_database SET ".implode(', ', $sql_set)." WHERE database_id = ".$retval);
  1284. $this->updateQueryExecute("UPDATE web_database SET ".implode(', ', $sql_set)." WHERE database_id = ".$retval, $retval, $params);
  1285. }
  1286. return $retval;
  1287. }
  1288. return false;
  1289. }
  1290. }
  1291. $page = new page_action;
  1292. $page->onLoad();
  1293. //IMPORTENTE, es necesario estas líneas para que el botón del pdf funcione. Activa el javascript
  1294. //echo '<script type="text/javascript">';
  1295. //echo 'alert (password(7, false, 1));';
  1296. //echo '</script>';
  1297. ?>
  1298. <!--IMPORTENTE, es necesario estas líneas para que el botón del pdf funcione. Activa el javascript -->
  1299. <script type="text/javascript">
  1300. /*var test = "PARALACLAVE";
  1301. function getRandomInt(min, max){
  1302. return Math.floor(Math.random() * (max - min + 1)) + min;
  1303. }
  1304. var clave = password(7, false, 1);
  1305. function password(minLength, special, num_special){
  1306. minLength = minLength || 10;
  1307. if(minLength < 8) minLength = 8;
  1308. var maxLength = minLength + 5;
  1309. var length = getRandomInt(minLength, maxLength);
  1310. var alphachars = "abcdefghijkmnopqrstuvwxyz";
  1311. var upperchars = "ABCDEFGHJKLMNPQRSTUVWXYZ";
  1312. var numchars = "23456789";
  1313. var specialchars = "!@#_";
  1314. if(num_special == undefined) num_special = 0;
  1315. if(special != undefined && special == true) {
  1316. num_special = Math.floor(Math.random() * (length / 4)) + 1;
  1317. }
  1318. var numericlen = getRandomInt(1, 2);
  1319. var alphalen = length - num_special - numericlen;
  1320. var upperlen = Math.floor(alphalen / 2);
  1321. alphalen = alphalen - upperlen;
  1322. var password = "";
  1323. for(i = 0; i < alphalen; i++) {
  1324. password += alphachars.charAt(Math.floor(Math.random() * alphachars.length));
  1325. }
  1326. for(i = 0; i < upperlen; i++) {
  1327. password += upperchars.charAt(Math.floor(Math.random() * upperchars.length));
  1328. }
  1329. for(i = 0; i < num_special; i++) {
  1330. password += specialchars.charAt(Math.floor(Math.random() * specialchars.length));
  1331. }
  1332. for(i = 0; i < numericlen; i++) {
  1333. password += numchars.charAt(Math.floor(Math.random() * numchars.length));
  1334. }
  1335. password = password.split('').sort(function() { return 0.5 - Math.random(); }).join('');
  1336. return password;
  1337. }*/
  1338. </script>