| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- * Description of Validator
- *
- * @author Vitalii Aloksa
- */
- namespace MGModule\DNSManager2\mgLibs\ModuleAPI;
- use \MGModule\DNSManager2\mgLibs\custom\dns\utils;
- use \MGModule\DNSManager2\mgLibs\custom\reverse\IPHelper;
- use \MGModule\DNSManager2\mgLibs\custom\manager\ClientHelper;
- use \MGModule\DNSManager2\mgLibs\lang;
- use \MGModule\DNSManager2\mgLibs\custom\manager\GlobalSettingHelper;
- use MGModule\DNSManager2\models\custom\globalsetting\GlobalSettingEnum;
- class Validator
- {
-
-
-
- public static function isValidZoneCreateData( $data )
- {
- $ClientHelper = new ClientHelper($data['userid']);
- if(!$ClientHelper->canUserCreatesNewZonesIn($data['type'], $data['relid']))
- {
- throw new \Exception(lang::T( 'addonCA','dashboard', 'errors' ,'you_cant_add_new_zones_within_this_group' ));
- }
-
- if(GlobalSettingHelper::getSetting(GlobalSettingEnum::OWNED_DOMAINS_ONLY) == 'on' && !in_array($data['zone_name'], $ClientHelper->getClientDomains()))
- {
- throw new \Exception(lang::T( 'addonCA','dashboard', 'errors' ,'you_cant_use_domain_that_does_not_belong_to_you' ));
- }
-
- self::validateIP($data);
- }
-
-
-
- public static function isValidZoneDeleteData( $data, $zone )
- {
- $ClientHelper = new ClientHelper($data['userid']);
- if(!$ClientHelper->isZoneOwnedByClient($zone) && !$_SESSION['adminid'])
- {
- throw new \Exception(lang::T( 'addonCA','dashboard', 'errors' ,'you_cant_remove_this_zone_because_it_is_not_belongs_to_you' ));
- }
- }
-
-
- public static function isValidZoneID( $id )
- {
- if(empty($id) || !is_integer( $id ))
- {
- throw new \Exception(lang::T( 'addonCA','dashboard', 'errors' ,'invalid_zone_id' ));
- }
- }
-
-
-
- public static function isValidModuleConfig( $modulename, $config )
- {
- if(empty($modulename) || empty($config))
- {
- throw new \Exception(lang::T( 'addonCA','dashboard', 'errors' ,'invalid_module_config' ));
- }
- }
-
-
-
- public static function validateBlockIP( $data )
- {
- /*
- * not used now
- */
-
- list($str,$pool,$mask) = explode('|',$input['zone_ip']);
-
- $input['zone_ip'] = $input['zone_ip_from_block'];
-
- }
-
-
-
- public static function validateIP( $data )
- {
- $IP = new utils\IP($data['zone_ip']);
-
- if(!empty($data['zone_ip']) && (!$IP->isValid() || $data['type'] != '0' || $data['relid'] != '0'))
- {
- IPHelper::validateIfClientCanUseIP($data['userid'], $data['type'], $data['relid'], $data['zone_ip'], true);
- }
- }
-
- }
|