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

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