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.
 
 
 
 

299 lines
12 KiB

  1. <?php
  2. /*
  3. PHP por David Ramos García, Open6Hosting <dramos@open6hosting.com>
  4. Clase para el control de los límites de los usuarios con el módulo WebDNS.
  5. 2017, All rights reserved.
  6. */
  7. require_once '../../lib/app.inc.php';
  8. //Carga de idioma para el texto de error de los límites DNS para el usuario logeado.
  9. $app->load_language_file('/web/webdns/lib/lang/'.$_SESSION['s']['language'].'_new_service_webdns.lng');
  10. $app->uses('tform,tform_actions');
  11. $app->load('tform_actions');
  12. class limites {
  13. public $cliente;
  14. public $cliente_grupo_id;
  15. public function __construct($cliente_group_id){
  16. global $app, $conf;
  17. $this->cliente = $client = $app->db->queryOneRecord(
  18. "SELECT limit_dns_zone, limit_web_domain, limit_database, parent_client_id, client.client_id, client.contact_name
  19. FROM sys_group, client
  20. WHERE sys_group.client_id = client.client_id
  21. AND sys_group.groupid = ?", $cliente_group_id);
  22. $this->cliente_grupo_id = $cliente_group_id;
  23. }
  24. public function limitesLoad(){
  25. global $app;
  26. //Límites DNS
  27. //Es necesario cargar estos valores en el formulario para que funcione la comprobación
  28. //de los límites para el cliente
  29. $app->tform->formDef['db_table_idx'] = 'id';
  30. $app->tform->formDef['db_table'] = 'dns_soa';
  31. if(!$app->tform->checkClientLimit('limit_dns_zone')) {
  32. $app->error($app->lng('limit_dns_zone_txt'));
  33. }
  34. if(!$app->tform->checkResellerLimit('limit_dns_zone')) {
  35. $app->error('Reventa: '.$app->lng('limit_dns_zone_txt'));
  36. }
  37. $app->tform->formDef['db_table_idx'] = 'database_id';
  38. $app->tform->formDef['db_table'] = 'web_database';
  39. //Límites BBDD
  40. if(!$app->tform->checkClientLimit('limit_database')) {
  41. $app->error($app->tform->wordbook["limit_database_txt"]);
  42. }
  43. if(!$app->tform->checkResellerLimit('limit_database')) {
  44. $app->error('Reventa: '.$app->tform->wordbook["limit_database_txt"]);
  45. }
  46. $app->tform->formDef['db_table_idx'] = 'domain_id';
  47. $app->tform->formDef['db_table'] = 'web_domain';
  48. //Límites Sitios Web
  49. if(!$app->tform->checkClientLimit('limit_web_domain')) {
  50. $app->error($app->tform->wordbook["limit_web_domain_txt"]);
  51. }
  52. if(!$app->tform->checkResellerLimit('limit_web_domain')) {
  53. $app->error('Reventa: '.$app->tform->wordbook["limit_web_domain_txt"]);
  54. }
  55. }
  56. public $revendedor;
  57. public $revendedor_grupos;
  58. public $revendedor_grupo_def;
  59. public function getRevendedor(){
  60. global $app, $conf;
  61. $tmpReseller = $app->db->queryOneRecord(
  62. "SELECT userid, groups, default_group
  63. FROM sys_user
  64. WHERE client_id = ?", $this->cliente['parent_client_id']);
  65. $this->revendedor = $tmpReseller['userid'];
  66. $this->revendedor_grupos = $tmpReseller['groups'];
  67. $this->revendedor_grupo_def = $tmpReseller['default_group'];
  68. }
  69. public $esReventa;
  70. public $todosLosGrupos;
  71. //public $gruposDelReventa;
  72. public function esRevendedor(){
  73. global $app, $conf;
  74. //PARA SABER QUIEN ES UN RESELLER
  75. //SELECT client_id, company_name, limit_client FROM client WHERE limit_client > 0 OR limit_client = -1
  76. $this->esReventa = $app->db->queryOneRecord(
  77. "SELECT client_id, limit_client, contact_name, limit_dns_zone
  78. FROM client
  79. WHERE limit_client > 0 OR limit_client = -1 AND client_id = ?", $this->cliente['client_id']);
  80. //El campo contact_name es obligatorio. Si viene vacío no es reventa.
  81. if($this->esReventa['contact_name'] != ''){
  82. //Capturo los grupos que tiene este reventa
  83. $gruposDelReventa = $app->db->queryOneRecord(
  84. "SELECT client_id, groups FROM sys_user WHERE client_id = ?", $this->cliente['client_id']);
  85. $this->todosLosGrupos = explode(',', $gruposDelReventa['groups']);
  86. }
  87. }
  88. public function limClienteDns(){
  89. global $app, $conf;
  90. //Si el cliente esta vacío es admin.
  91. if($this->cliente){
  92. //echo(' Usuario grupo es ' .$this->cliente_grupo_id . ' limites DNS ' . $this->cliente["limit_dns_zone"]);
  93. if($this->cliente["limit_dns_zone"] >= 0) {
  94. $tmp = $app->db->queryOneRecord(
  95. "SELECT count(id) as number FROM dns_soa WHERE sys_groupid = ?", $this->cliente_grupo_id);
  96. //echo(' Cantidad de DNS ' . $tmp["number"]);
  97. if($tmp["number"] >= $this->cliente["limit_dns_zone"]) {
  98. $app->error($app->tform->wordbook["limit_dns_zone_txt"]);
  99. return true;
  100. }
  101. }
  102. //* If the client belongs to a reseller, we will check against the reseller Limit too
  103. if($this->cliente['parent_client_id'] != 0) {
  104. //* first we need to know the groups of this reseller
  105. $this->getRevendedor();
  106. //echo(' Valores '.$this->revendedor . ' otro ' . $this->revendedor_grupos . ' y otro ' .$this->revendedor_grupo_def);
  107. //echo(' El cliente es ' . $this->cliente['parent_client_id']);
  108. $reseller = $app->db->queryOneRecord(
  109. "SELECT limit_dns_zone as number, contact_name FROM client WHERE client_id = ?", $this->cliente['parent_client_id']);
  110. //echo(' Cliente Reventa limites DNS ' . $reseller['number']);
  111. // Check if the user may add another item
  112. if($reseller['number'] >= 0) {
  113. $tmpCliente = $app->db->queryOneRecord(
  114. "SELECT count(id) as number FROM dns_soa WHERE sys_groupid = ?", $this->cliente_grupo_id);
  115. $tmpReventa = $app->db->queryOneRecord(
  116. "SELECT count(id) as number FROM dns_soa WHERE sys_groupid = ?", $this->revendedor_grupo_def);
  117. $totalCreado = $tmpCliente['number'] + $tmpReventa['number'];
  118. if($totalCreado >= $reseller['number']) {
  119. $app->error($reseller['contact_name'] . '. ' . $app->tform->wordbook["limit_dns_zone_txt"]);
  120. return true;
  121. }
  122. }
  123. }
  124. $this->esRevendedor();
  125. if($this->esReventa){
  126. $sumaTotal = 0;
  127. foreach($this->todosLosGrupos as $grupos) {
  128. $tmpReventaALL = $app->db->queryOneRecord(
  129. "SELECT count(id) as number FROM dns_soa WHERE sys_groupid = ?", $grupos);
  130. $sumaTotal += $tmpReventaALL['number'];
  131. }
  132. //echo(' La suma ' . $sumaTotal . ' limite ' . $this->cliente["limit_dns_zone"]);
  133. if($sumaTotal >= $this->cliente["limit_dns_zone"]) {
  134. $app->error($this->esReventa['contact_name'] . '. ' . $app->tform->wordbook["limit_dns_zone_txt"]);
  135. return true;
  136. }
  137. }
  138. return false;
  139. }
  140. }
  141. public function limClienteWebDominio(){
  142. global $app, $conf;
  143. //Si el cliente esta vacío es admin.
  144. if($this->cliente){
  145. if($this->cliente["limit_web_domain"] >= 0) {
  146. $tmp = $app->db->queryOneRecord(
  147. "SELECT count(domain_id) as number FROM web_domain
  148. WHERE sys_groupid = ? and type = 'vhost'", $this->cliente_grupo_id);
  149. if($tmp["number"] >= $this->cliente["limit_web_domain"]) {
  150. $app->error($app->tform->wordbook["limit_web_domain_txt"]);
  151. return true;
  152. }
  153. }
  154. //* If the client belongs to a reseller, we will check against the reseller Limit too
  155. if($this->cliente['parent_client_id'] != 0) {
  156. //* first we need to know the groups of this reseller
  157. $this->getRevendedor();
  158. $reseller = $app->db->queryOneRecord(
  159. "SELECT limit_web_domain as number, contact_name FROM client WHERE client_id = ?", $this->cliente['parent_client_id']);
  160. //echo(' Cliente Reventa limites DNS ' . $reseller['number']);
  161. // Check if the user may add another item
  162. if($reseller['number'] >= 0) {
  163. $tmpCliente = $app->db->queryOneRecord(
  164. "SELECT count(domain_id) as number FROM web_domain
  165. WHERE sys_groupid = ? and type = 'vhost'", $this->cliente_grupo_id);
  166. $tmpReventa = $app->db->queryOneRecord(
  167. "SELECT count(domain_id) as number FROM web_domain
  168. WHERE sys_groupid = ? and type = 'vhost'", $this->revendedor_grupo_def);
  169. $totalCreado = $tmpCliente['number'] + $tmpReventa['number'];
  170. if($totalCreado >= $reseller['number']) {
  171. $app->error($reseller['contact_name'] . '. ' . $app->tform->wordbook["limit_web_domain_txt"]);
  172. return true;
  173. }
  174. }
  175. }
  176. $this->esRevendedor();
  177. if($this->esReventa){
  178. $sumaTotal = 0;
  179. foreach($this->todosLosGrupos as $grupos) {
  180. $tmpReventaALL = $app->db->queryOneRecord(
  181. "SELECT count(domain_id) as number FROM web_domain
  182. WHERE sys_groupid = ? and type = 'vhost'", $grupos);
  183. $sumaTotal += $tmpReventaALL['number'];
  184. }
  185. if($sumaTotal >= $this->cliente["limit_web_domain"]) {
  186. $app->error($this->esReventa['contact_name'] . '. ' . $app->tform->wordbook["limit_web_domain_txt"]);
  187. return true;
  188. }
  189. }
  190. return false;
  191. }
  192. }
  193. public function limClienteDB(){
  194. global $app, $conf;
  195. //Si el cliente esta vacío es admin.
  196. if($this->cliente){
  197. if($this->cliente["limit_database"] >= 0) {
  198. $tmp = $app->db->queryOneRecord(
  199. "SELECT count(database_id) as number
  200. FROM web_database WHERE sys_groupid = ?", $this->cliente_grupo_id);
  201. if($tmp["number"] >= $this->cliente["limit_database"]) {
  202. $app->error($app->tform->wordbook["limit_database_txt"]);
  203. return true;
  204. }
  205. }
  206. //* If the client belongs to a reseller, we will check against the reseller Limit too
  207. if($this->cliente['parent_client_id'] != 0) {
  208. //* first we need to know the groups of this reseller
  209. $this->getRevendedor();
  210. $reseller = $app->db->queryOneRecord(
  211. "SELECT limit_database as number, contact_name FROM client WHERE client_id = ?", $this->cliente['parent_client_id']);
  212. //echo(' Cliente Reventa limites DNS ' . $reseller['number']);
  213. // Check if the user may add another item
  214. if($reseller['number'] >= 0) {
  215. $tmpCliente = $app->db->queryOneRecord(
  216. "SELECT count(database_id) as number
  217. FROM web_database WHERE sys_groupid = ?", $this->cliente_grupo_id);
  218. $tmpReventa = $app->db->queryOneRecord(
  219. "SELECT count(database_id) as number
  220. FROM web_database WHERE sys_groupid = ?", $this->revendedor_grupo_def);
  221. $totalCreado = $tmpCliente['number'] + $tmpReventa['number'];
  222. if($totalCreado >= $reseller['number']) {
  223. $app->error($reseller['contact_name'] . '. ' . $app->tform->wordbook["limit_database_txt"]);
  224. return true;
  225. }
  226. }
  227. }
  228. $this->esRevendedor();
  229. if($this->esReventa){
  230. $sumaTotal = 0;
  231. foreach($this->todosLosGrupos as $grupos) {
  232. $tmpReventaALL = $app->db->queryOneRecord(
  233. "SELECT count(database_id) as number
  234. FROM web_database WHERE sys_groupid = ?", $grupos);
  235. $sumaTotal += $tmpReventaALL['number'];
  236. }
  237. if($sumaTotal >= $this->cliente["limit_database"]) {
  238. $app->error($this->esReventa['contact_name'] . '. ' . $app->tform->wordbook["limit_database_txt"]);
  239. return true;
  240. }
  241. }
  242. return false;
  243. }
  244. }
  245. }
  246. ?>