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.
 
 
 
 

295 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 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);
  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. if($tmp["number"] >= $this->cliente["limit_dns_zone"]) {
  92. $app->error($app->tform->wordbook["limit_dns_zone_txt"]);
  93. return true;
  94. }
  95. }
  96. //* If the client belongs to a reseller, we will check against the reseller Limit too
  97. if($this->cliente['parent_client_id'] != 0) {
  98. //* first we need to know the groups of this reseller
  99. $this->getRevendedor();
  100. //echo(' Valores '.$this->revendedor . ' otro ' . $this->revendedor_grupos . ' y otro ' .$this->revendedor_grupo_def);
  101. //echo(' El cliente es ' . $this->cliente['parent_client_id']);
  102. $reseller = $app->db->queryOneRecord(
  103. "SELECT limit_dns_zone as number, contact_name FROM client WHERE client_id = ?", $this->cliente['parent_client_id']);
  104. //echo(' Cliente Reventa limites DNS ' . $reseller['number']);
  105. // Check if the user may add another item
  106. if($reseller['number'] >= 0) {
  107. $tmpCliente = $app->db->queryOneRecord(
  108. "SELECT count(id) as number FROM dns_soa WHERE sys_groupid = ?", $this->cliente_grupo_id);
  109. $tmpReventa = $app->db->queryOneRecord(
  110. "SELECT count(id) as number FROM dns_soa WHERE sys_groupid = ?", $this->revendedor_grupo_def);
  111. $totalCreado = $tmpCliente['number'] + $tmpReventa['number'];
  112. if($totalCreado >= $reseller['number']) {
  113. $app->error($reseller['contact_name'] . '. ' . $app->tform->wordbook["limit_dns_zone_txt"]);
  114. return true;
  115. }
  116. }
  117. }
  118. $this->esRevendedor();
  119. if($this->esReventa){
  120. $sumaTotal = 0;
  121. foreach($this->todosLosGrupos as $grupos) {
  122. $tmpReventaALL = $app->db->queryOneRecord(
  123. "SELECT count(id) as number FROM dns_soa WHERE sys_groupid = ?", $grupos);
  124. $sumaTotal += $tmpReventaALL['number'];
  125. }
  126. if($sumaTotal >= $this->cliente["limit_dns_zone"]) {
  127. $app->error($this->esReventa['contact_name'] . '. ' . $app->tform->wordbook["limit_dns_zone_txt"]);
  128. return true;
  129. }
  130. }
  131. return false;
  132. }
  133. }
  134. public function limClienteWebDominio(){
  135. global $app, $conf;
  136. //Si el cliente esta vacío es admin.
  137. if($this->cliente){
  138. if($this->cliente["limit_web_domain"] >= 0) {
  139. $tmp = $app->db->queryOneRecord(
  140. "SELECT count(domain_id) as number FROM web_domain
  141. WHERE sys_groupid = ? and type = 'vhost'", $this->cliente_grupo_id);
  142. if($tmp["number"] >= $this->cliente["limit_web_domain"]) {
  143. $app->error($app->tform->wordbook["limit_web_domain_txt"]);
  144. return true;
  145. }
  146. }
  147. //* If the client belongs to a reseller, we will check against the reseller Limit too
  148. if($this->cliente['parent_client_id'] != 0) {
  149. //* first we need to know the groups of this reseller
  150. $this->getRevendedor();
  151. $reseller = $app->db->queryOneRecord(
  152. "SELECT limit_web_domain as number, contact_name FROM client WHERE client_id = ?", $this->cliente['parent_client_id']);
  153. //echo(' Cliente Reventa limites DNS ' . $reseller['number']);
  154. // Check if the user may add another item
  155. if($reseller['number'] >= 0) {
  156. $tmpCliente = $app->db->queryOneRecord(
  157. "SELECT count(domain_id) as number FROM web_domain
  158. WHERE sys_groupid = ? and type = 'vhost'", $this->cliente_grupo_id);
  159. $tmpReventa = $app->db->queryOneRecord(
  160. "SELECT count(domain_id) as number FROM web_domain
  161. WHERE sys_groupid = ? and type = 'vhost'", $this->revendedor_grupo_def);
  162. $totalCreado = $tmpCliente['number'] + $tmpReventa['number'];
  163. if($totalCreado >= $reseller['number']) {
  164. $app->error($reseller['contact_name'] . '. ' . $app->tform->wordbook["limit_web_domain_txt"]);
  165. return true;
  166. }
  167. }
  168. }
  169. $this->esRevendedor();
  170. if($this->esReventa){
  171. $sumaTotal = 0;
  172. foreach($this->todosLosGrupos as $grupos) {
  173. $tmpReventaALL = $app->db->queryOneRecord(
  174. "SELECT count(domain_id) as number FROM web_domain
  175. WHERE sys_groupid = ? and type = 'vhost'", $grupos);
  176. $sumaTotal += $tmpReventaALL['number'];
  177. }
  178. if($sumaTotal >= $this->cliente["limit_web_domain"]) {
  179. $app->error($this->esReventa['contact_name'] . '. ' . $app->tform->wordbook["limit_web_domain_txt"]);
  180. return true;
  181. }
  182. }
  183. return false;
  184. }
  185. }
  186. public function limClienteDB(){
  187. global $app, $conf;
  188. //Si el cliente esta vacío es admin.
  189. if($this->cliente){
  190. if($this->cliente["limit_database"] >= 0) {
  191. $tmp = $app->db->queryOneRecord(
  192. "SELECT count(database_id) as number
  193. FROM web_database WHERE sys_groupid = ?", $this->cliente_grupo_id);
  194. if($tmp["number"] >= $this->cliente["limit_database"]) {
  195. $app->error($app->tform->wordbook["limit_database_txt"]);
  196. return true;
  197. }
  198. }
  199. //* If the client belongs to a reseller, we will check against the reseller Limit too
  200. if($this->cliente['parent_client_id'] != 0) {
  201. //* first we need to know the groups of this reseller
  202. $this->getRevendedor();
  203. $reseller = $app->db->queryOneRecord(
  204. "SELECT limit_database as number, contact_name FROM client WHERE client_id = ?", $this->cliente['parent_client_id']);
  205. //echo(' Cliente Reventa limites DNS ' . $reseller['number']);
  206. // Check if the user may add another item
  207. if($reseller['number'] >= 0) {
  208. $tmpCliente = $app->db->queryOneRecord(
  209. "SELECT count(database_id) as number
  210. FROM web_database WHERE sys_groupid = ?", $this->cliente_grupo_id);
  211. $tmpReventa = $app->db->queryOneRecord(
  212. "SELECT count(database_id) as number
  213. FROM web_database WHERE sys_groupid = ?", $this->revendedor_grupo_def);
  214. $totalCreado = $tmpCliente['number'] + $tmpReventa['number'];
  215. if($totalCreado >= $reseller['number']) {
  216. $app->error($reseller['contact_name'] . '. ' . $app->tform->wordbook["limit_database_txt"]);
  217. return true;
  218. }
  219. }
  220. }
  221. $this->esRevendedor();
  222. if($this->esReventa){
  223. $sumaTotal = 0;
  224. foreach($this->todosLosGrupos as $grupos) {
  225. $tmpReventaALL = $app->db->queryOneRecord(
  226. "SELECT count(database_id) as number
  227. FROM web_database WHERE sys_groupid = ?", $grupos);
  228. $sumaTotal += $tmpReventaALL['number'];
  229. }
  230. if($sumaTotal >= $this->cliente["limit_database"]) {
  231. $app->error($this->esReventa['contact_name'] . '. ' . $app->tform->wordbook["limit_database_txt"]);
  232. return true;
  233. }
  234. }
  235. return false;
  236. }
  237. }
  238. }
  239. ?>