Clase para el control de los límites de los usuarios con el módulo WebDNS. 2017, All rights reserved. */ require_once '../../lib/app.inc.php'; //Carga de idioma para el texto de error de los límites DNS para el cliente $app->load_language_file('/web/dns/lib/lang/'.$_SESSION['s']['language'].'_dns_wizard.lng'); $app->uses('tform,tform_actions'); $app->load('tform_actions'); class limites { public $cliente; public $cliente_grupo_id; public function __construct($cliente_group_id){ global $app, $conf; $this->cliente = $client = $app->db->queryOneRecord( "SELECT limit_dns_zone, limit_web_domain, limit_database, parent_client_id, client.client_id, client.contact_name FROM sys_group, client WHERE sys_group.client_id = client.client_id AND sys_group.groupid = ?", $cliente_group_id); $this->cliente_grupo_id = $cliente_group_id; } public function limitesLoad(){ global $app; //Límites DNS //Es necesario cargar estos valores en el formulario para que funcione la comprobación de los límites para el cliente $app->tform->formDef['db_table_idx'] = 'id'; $app->tform->formDef['db_table'] = 'dns_soa'; if(!$app->tform->checkClientLimit('limit_dns_zone')) { $app->error($app->lng('limit_dns_zone_txt')); } if(!$app->tform->checkResellerLimit('limit_dns_zone')) { $app->error('Reseller: '.$app->lng('limit_dns_zone_txt')); } //Límites BBDD if(!$app->tform->checkClientLimit('limit_database')) { $app->error($app->tform->wordbook["limit_database_txt"]); } if(!$app->tform->checkResellerLimit('limit_database')) { $app->error('Reseller: '.$app->tform->wordbook["limit_database_txt"]); } //Límites Sitios Web if(!$app->tform->checkClientLimit('limit_web_domain')) { $app->error($app->tform->wordbook["limit_web_domain_txt"]); } if(!$app->tform->checkResellerLimit('limit_web_domain')) { $app->error('Reseller: '.$app->tform->wordbook["limit_web_domain_txt"]); } } public $revendedor; public $revendedor_grupos; public $revendedor_grupo_def; public function getRevendedor(){ global $app, $conf; $tmpReseller = $app->db->queryOneRecord( "SELECT userid, groups, default_group FROM sys_user WHERE client_id = ?", $this->cliente['parent_client_id']); $this->revendedor = $tmpReseller['userid']; $this->revendedor_grupos = $tmpReseller['groups']; $this->revendedor_grupo_def = $tmpReseller['default_group']; } public $esReventa; public $todosLosGrupos; //public $gruposDelReventa; public function esRevendedor(){ global $app, $conf; //PARA SABER QUIEN ES UN RESELLER //SELECT client_id, company_name, limit_client FROM client WHERE limit_client > 0 OR limit_client = -1 $this->esReventa = $app->db->queryOneRecord( "SELECT client_id, limit_client, contact_name, limit_dns_zone FROM client WHERE limit_client > 0 OR limit_client = -1 AND client_id = ?", $this->cliente['client_id']); //El campo contact_name es obligatorio. Si viene vacío no es reventa. if($this->esReventa['contact_name'] != ''){ //Capturo los grupos que tiene este reventa $gruposDelReventa = $app->db->queryOneRecord( "SELECT client_id, groups FROM sys_user WHERE client_id = ?", $this->cliente['client_id']); $this->todosLosGrupos = explode(',', $gruposDelReventa['groups']); } } public function limClienteDns(){ global $app, $conf; //Si el cliente esta vacío es admin. if($this->cliente){ //echo(' Usuario grupo es ' .$this->cliente_grupo_id . ' limites DNS ' . $this->cliente["limit_dns_zone"]); if($this->cliente["limit_dns_zone"] >= 0) { $tmp = $app->db->queryOneRecord( "SELECT count(id) as number FROM dns_soa WHERE sys_groupid = ?", $this->cliente_grupo_id); //echo(' Cantidad de DNS ' . $tmp["number"]); if($tmp["number"] >= $this->cliente["limit_dns_zone"]) { $app->error($app->tform->wordbook["limit_dns_zone_txt"]); return true; } } //* If the client belongs to a reseller, we will check against the reseller Limit too if($this->cliente['parent_client_id'] != 0) { //* first we need to know the groups of this reseller $this->getRevendedor(); //echo(' Valores '.$this->revendedor . ' otro ' . $this->revendedor_grupos . ' y otro ' .$this->revendedor_grupo_def); //echo(' El cliente es ' . $this->cliente['parent_client_id']); $reseller = $app->db->queryOneRecord( "SELECT limit_dns_zone as number, contact_name FROM client WHERE client_id = ?", $this->cliente['parent_client_id']); //echo(' Cliente Reventa limites DNS ' . $reseller['number']); // Check if the user may add another item if($reseller['number'] >= 0) { $tmpCliente = $app->db->queryOneRecord( "SELECT count(id) as number FROM dns_soa WHERE sys_groupid = ?", $this->cliente_grupo_id); $tmpReventa = $app->db->queryOneRecord( "SELECT count(id) as number FROM dns_soa WHERE sys_groupid = ?", $this->revendedor_grupo_def); $totalCreado = $tmpCliente['number'] + $tmpReventa['number']; if($totalCreado >= $reseller['number']) { $app->error($reseller['contact_name'] . '. ' . $app->tform->wordbook["limit_dns_zone_txt"]); return true; } } } $this->esRevendedor(); if($this->esReventa){ $sumaTotal = 0; foreach($this->todosLosGrupos as $grupos) { $tmpReventaALL = $app->db->queryOneRecord( "SELECT count(id) as number FROM dns_soa WHERE sys_groupid = ?", $grupos); $sumaTotal += $tmpReventaALL['number']; } //echo(' La suma ' . $sumaTotal . ' limite ' . $this->cliente["limit_dns_zone"]); if($sumaTotal >= $this->cliente["limit_dns_zone"]) { $app->error($this->esReventa['contact_name'] . '. ' . $app->tform->wordbook["limit_dns_zone_txt"]); return true; } } return false; } } public function limClienteWebDominio(){ global $app, $conf; //Si el cliente esta vacío es admin. if($this->cliente){ if($this->cliente["limit_web_domain"] >= 0) { $tmp = $app->db->queryOneRecord( "SELECT count(domain_id) as number FROM web_domain WHERE sys_groupid = ? and type = 'vhost'", $this->cliente_grupo_id); if($tmp["number"] >= $this->cliente["limit_web_domain"]) { $app->error($app->tform->wordbook["limit_web_domain_txt"]); return true; } } //* If the client belongs to a reseller, we will check against the reseller Limit too if($this->cliente['parent_client_id'] != 0) { //* first we need to know the groups of this reseller $this->getRevendedor(); $reseller = $app->db->queryOneRecord( "SELECT limit_web_domain as number, contact_name FROM client WHERE client_id = ?", $this->cliente['parent_client_id']); //echo(' Cliente Reventa limites DNS ' . $reseller['number']); // Check if the user may add another item if($reseller['number'] >= 0) { $tmpCliente = $app->db->queryOneRecord( "SELECT count(domain_id) as number FROM web_domain WHERE sys_groupid = ? and type = 'vhost'", $this->cliente_grupo_id); $tmpReventa = $app->db->queryOneRecord( "SELECT count(domain_id) as number FROM web_domain WHERE sys_groupid = ? and type = 'vhost'", $this->revendedor_grupo_def); $totalCreado = $tmpCliente['number'] + $tmpReventa['number']; if($totalCreado >= $reseller['number']) { $app->error($reseller['contact_name'] . '. ' . $app->tform->wordbook["limit_web_domain_txt"]); return true; } } } $this->esRevendedor(); if($this->esReventa){ $sumaTotal = 0; foreach($this->todosLosGrupos as $grupos) { $tmpReventaALL = $app->db->queryOneRecord( "SELECT count(domain_id) as number FROM web_domain WHERE sys_groupid = ? and type = 'vhost'", $grupos); $sumaTotal += $tmpReventaALL['number']; } if($sumaTotal >= $this->cliente["limit_web_domain"]) { $app->error($this->esReventa['contact_name'] . '. ' . $app->tform->wordbook["limit_web_domain_txt"]); return true; } } return false; } } public function limClienteDB(){ global $app, $conf; //Si el cliente esta vacío es admin. if($this->cliente){ if($this->cliente["limit_database"] >= 0) { $tmp = $app->db->queryOneRecord( "SELECT count(database_id) as number FROM web_database WHERE sys_groupid = ?", $this->cliente_grupo_id); if($tmp["number"] >= $this->cliente["limit_database"]) { $app->error($app->tform->wordbook["limit_database_txt"]); return true; } } //* If the client belongs to a reseller, we will check against the reseller Limit too if($this->cliente['parent_client_id'] != 0) { //* first we need to know the groups of this reseller $this->getRevendedor(); $reseller = $app->db->queryOneRecord( "SELECT limit_database as number, contact_name FROM client WHERE client_id = ?", $this->cliente['parent_client_id']); //echo(' Cliente Reventa limites DNS ' . $reseller['number']); // Check if the user may add another item if($reseller['number'] >= 0) { $tmpCliente = $app->db->queryOneRecord( "SELECT count(database_id) as number FROM web_database WHERE sys_groupid = ?", $this->cliente_grupo_id); $tmpReventa = $app->db->queryOneRecord( "SELECT count(database_id) as number FROM web_database WHERE sys_groupid = ?", $this->revendedor_grupo_def); $totalCreado = $tmpCliente['number'] + $tmpReventa['number']; if($totalCreado >= $reseller['number']) { $app->error($reseller['contact_name'] . '. ' . $app->tform->wordbook["limit_database_txt"]); return true; } } } $this->esRevendedor(); if($this->esReventa){ $sumaTotal = 0; foreach($this->todosLosGrupos as $grupos) { $tmpReventaALL = $app->db->queryOneRecord( "SELECT count(database_id) as number FROM web_database WHERE sys_groupid = ?", $grupos); $sumaTotal += $tmpReventaALL['number']; } if($sumaTotal >= $this->cliente["limit_database"]) { $app->error($this->esReventa['contact_name'] . '. ' . $app->tform->wordbook["limit_database_txt"]); return true; } } return false; } } } ?>