ISPConfig module for simplify the creation of websites and DNS zones in a only step
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

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