ISPConfig module for simplify the creation of websites and DNS zones in a only step
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

260 lignes
11 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. global $app;
  9. $app->uses('tform,tform_actions');
  10. $app->load('tform_actions');
  11. class limites {
  12. public $cliente;
  13. public $cliente_grupo_id;
  14. public function __construct($cliente_group_id){
  15. global $app, $conf;
  16. $this->cliente = $client = $app->db->queryOneRecord(
  17. "SELECT limit_dns_zone, limit_web_domain, limit_database, parent_client_id, client.client_id, client.contact_name
  18. FROM sys_group, client
  19. WHERE sys_group.client_id = client.client_id
  20. AND sys_group.groupid = ?", $cliente_group_id);
  21. $this->cliente_grupo_id = $cliente_group_id;
  22. }
  23. public $revendedor;
  24. public $revendedor_grupos;
  25. public $revendedor_grupo_def;
  26. public function getRevendedor(){
  27. global $app, $conf;
  28. $tmpReseller = $app->db->queryOneRecord(
  29. "SELECT userid, groups, default_group
  30. FROM sys_user
  31. WHERE client_id = ?", $this->cliente['parent_client_id']);
  32. $this->revendedor = $tmpReseller['userid'];
  33. $this->revendedor_grupos = $tmpReseller['groups'];
  34. $this->revendedor_grupo_def = $tmpReseller['default_group'];
  35. }
  36. public $esReventa;
  37. public $todosLosGrupos;
  38. //public $gruposDelReventa;
  39. public function esRevendedor(){
  40. global $app, $conf;
  41. //PARA SABER QUIEN ES UN RESELLER
  42. //SELECT client_id, company_name, limit_client FROM client WHERE limit_client > 0 OR limit_client = -1
  43. $this->esReventa = $app->db->queryOneRecord(
  44. "SELECT client_id, limit_client, contact_name, limit_dns_zone
  45. FROM client
  46. WHERE limit_client > 0 OR limit_client = -1 AND client_id = ?", $this->cliente['client_id']);
  47. //El campo contact_name es obligatorio. Si viene vacío no es reventa.
  48. if($this->esReventa['contact_name'] != ''){
  49. //Capturo los grupos que tiene este reventa
  50. $gruposDelReventa = $app->db->queryOneRecord(
  51. "SELECT client_id, groups FROM sys_user WHERE client_id = ?", $this->cliente['client_id']);
  52. $this->todosLosGrupos = explode(',', $gruposDelReventa['groups']);
  53. }
  54. }
  55. public function limClienteDns(){
  56. global $app, $conf;
  57. //Si el cliente esta vacío es admin.
  58. if($this->cliente){
  59. //echo(' Usuario grupo es ' .$this->cliente_grupo_id);
  60. if($this->cliente["limit_dns_zone"] >= 0) {
  61. $tmp = $app->db->queryOneRecord(
  62. "SELECT count(id) as number FROM dns_soa WHERE sys_groupid = ?", $this->cliente_grupo_id);
  63. if($tmp["number"] >= $this->cliente["limit_dns_zone"]) {
  64. $app->error($app->tform->wordbook["limit_dns_zone_txt"]);
  65. return true;
  66. }
  67. }
  68. //* If the client belongs to a reseller, we will check against the reseller Limit too
  69. if($this->cliente['parent_client_id'] != 0) {
  70. //* first we need to know the groups of this reseller
  71. $this->getRevendedor();
  72. //echo(' Valores '.$this->revendedor . ' otro ' . $this->revendedor_grupos . ' y otro ' .$this->revendedor_grupo_def);
  73. //echo(' El cliente es ' . $this->cliente['parent_client_id']);
  74. $reseller = $app->db->queryOneRecord(
  75. "SELECT limit_dns_zone as number, contact_name FROM client WHERE client_id = ?", $this->cliente['parent_client_id']);
  76. //echo(' Cliente Reventa limites DNS ' . $reseller['number']);
  77. // Check if the user may add another item
  78. if($reseller['number'] >= 0) {
  79. $tmpCliente = $app->db->queryOneRecord(
  80. "SELECT count(id) as number FROM dns_soa WHERE sys_groupid = ?", $this->cliente_grupo_id);
  81. $tmpReventa = $app->db->queryOneRecord(
  82. "SELECT count(id) as number FROM dns_soa WHERE sys_groupid = ?", $this->revendedor_grupo_def);
  83. $totalCreado = $tmpCliente['number'] + $tmpReventa['number'];
  84. if($totalCreado >= $reseller['number']) {
  85. $app->error($reseller['contact_name'] . '. ' . $app->tform->wordbook["limit_dns_zone_txt"]);
  86. return true;
  87. }
  88. }
  89. }
  90. $this->esRevendedor();
  91. if($this->esReventa){
  92. $sumaTotal = 0;
  93. foreach($this->todosLosGrupos as $grupos) {
  94. $tmpReventaALL = $app->db->queryOneRecord(
  95. "SELECT count(id) as number FROM dns_soa WHERE sys_groupid = ?", $grupos);
  96. $sumaTotal += $tmpReventaALL['number'];
  97. }
  98. if($sumaTotal >= $this->cliente["limit_dns_zone"]) {
  99. $app->error($this->esReventa['contact_name'] . '. ' . $app->tform->wordbook["limit_dns_zone_txt"]);
  100. return true;
  101. }
  102. }
  103. return false;
  104. }
  105. }
  106. public function limClienteWebDominio(){
  107. global $app, $conf;
  108. //Si el cliente esta vacío es admin.
  109. if($this->cliente){
  110. if($this->cliente["limit_web_domain"] >= 0) {
  111. $tmp = $app->db->queryOneRecord(
  112. "SELECT count(domain_id) as number FROM web_domain
  113. WHERE sys_groupid = ? and type = 'vhost'", $this->cliente_grupo_id);
  114. if($tmp["number"] >= $this->cliente["limit_web_domain"]) {
  115. $app->error($app->tform->wordbook["limit_web_domain_txt"]);
  116. return true;
  117. }
  118. }
  119. //* If the client belongs to a reseller, we will check against the reseller Limit too
  120. if($this->cliente['parent_client_id'] != 0) {
  121. //* first we need to know the groups of this reseller
  122. $this->getRevendedor();
  123. $reseller = $app->db->queryOneRecord(
  124. "SELECT limit_web_domain as number, contact_name FROM client WHERE client_id = ?", $this->cliente['parent_client_id']);
  125. //echo(' Cliente Reventa limites DNS ' . $reseller['number']);
  126. // Check if the user may add another item
  127. if($reseller['number'] >= 0) {
  128. $tmpCliente = $app->db->queryOneRecord(
  129. "SELECT count(domain_id) as number FROM web_domain
  130. WHERE sys_groupid = ? and type = 'vhost'", $this->cliente_grupo_id);
  131. $tmpReventa = $app->db->queryOneRecord(
  132. "SELECT count(domain_id) as number FROM web_domain
  133. WHERE sys_groupid = ? and type = 'vhost'", $this->revendedor_grupo_def);
  134. $totalCreado = $tmpCliente['number'] + $tmpReventa['number'];
  135. if($totalCreado >= $reseller['number']) {
  136. $app->error($reseller['contact_name'] . '. ' . $app->tform->wordbook["limit_web_domain_txt"]);
  137. return true;
  138. }
  139. }
  140. }
  141. $this->esRevendedor();
  142. if($this->esReventa){
  143. $sumaTotal = 0;
  144. foreach($this->todosLosGrupos as $grupos) {
  145. $tmpReventaALL = $app->db->queryOneRecord(
  146. "SELECT count(domain_id) as number FROM web_domain
  147. WHERE sys_groupid = ? and type = 'vhost'", $grupos);
  148. $sumaTotal += $tmpReventaALL['number'];
  149. }
  150. if($sumaTotal >= $this->cliente["limit_web_domain"]) {
  151. $app->error($this->esReventa['contact_name'] . '. ' . $app->tform->wordbook["limit_web_domain_txt"]);
  152. return true;
  153. }
  154. }
  155. return false;
  156. }
  157. }
  158. public function limClienteDB(){
  159. global $app, $conf;
  160. //Si el cliente esta vacío es admin.
  161. if($this->cliente){
  162. if($this->cliente["limit_database"] >= 0) {
  163. $tmp = $app->db->queryOneRecord(
  164. "SELECT count(database_id) as number
  165. FROM web_database WHERE sys_groupid = ?", $this->cliente_grupo_id);
  166. if($tmp["number"] >= $this->cliente["limit_database"]) {
  167. $app->error($app->tform->wordbook["limit_database_txt"]);
  168. return true;
  169. }
  170. }
  171. //* If the client belongs to a reseller, we will check against the reseller Limit too
  172. if($this->cliente['parent_client_id'] != 0) {
  173. //* first we need to know the groups of this reseller
  174. $this->getRevendedor();
  175. $reseller = $app->db->queryOneRecord(
  176. "SELECT limit_database as number, contact_name FROM client WHERE client_id = ?", $this->cliente['parent_client_id']);
  177. //echo(' Cliente Reventa limites DNS ' . $reseller['number']);
  178. // Check if the user may add another item
  179. if($reseller['number'] >= 0) {
  180. $tmpCliente = $app->db->queryOneRecord(
  181. "SELECT count(database_id) as number
  182. FROM web_database WHERE sys_groupid = ?", $this->cliente_grupo_id);
  183. $tmpReventa = $app->db->queryOneRecord(
  184. "SELECT count(database_id) as number
  185. FROM web_database WHERE sys_groupid = ?", $this->revendedor_grupo_def);
  186. $totalCreado = $tmpCliente['number'] + $tmpReventa['number'];
  187. if($totalCreado >= $reseller['number']) {
  188. $app->error($reseller['contact_name'] . '. ' . $app->tform->wordbook["limit_database_txt"]);
  189. return true;
  190. }
  191. }
  192. }
  193. $this->esRevendedor();
  194. if($this->esReventa){
  195. $sumaTotal = 0;
  196. foreach($this->todosLosGrupos as $grupos) {
  197. $tmpReventaALL = $app->db->queryOneRecord(
  198. "SELECT count(database_id) as number
  199. FROM web_database WHERE sys_groupid = ?", $grupos);
  200. $sumaTotal += $tmpReventaALL['number'];
  201. }
  202. if($sumaTotal >= $this->cliente["limit_database"]) {
  203. $app->error($this->esReventa['contact_name'] . '. ' . $app->tform->wordbook["limit_database_txt"]);
  204. return true;
  205. }
  206. }
  207. return false;
  208. }
  209. }
  210. }
  211. ?>