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

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