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.
 
 
 
 

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