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.
 
 
 
 

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