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

1855 строки
75 KiB

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