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.
 
 
 
 

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