Ejemplo n.º 1
0
 public function validate(\Nethgui\Controller\ValidationReportInterface $report)
 {
     if (!$this->getRequest()->isMutation()) {
         return;
     }
     if ($this->getIdentifier() === 'delete') {
         $v = $this->createValidator()->platform('group-delete');
         if (!$v->evaluate($this->getAdapter()->getKeyValue())) {
             $report->addValidationError($this, 'groupname', $v);
         }
     }
     if ($this->getIdentifier() === 'update' || $this->getIdentifier() === 'create') {
         $users = array_keys($this->getUserProvider()->getUsers());
         $this->getValidator('members')->memberOf($users);
     }
     if ($this->getIdentifier() === 'create') {
         $groups = array();
         $groupProvider = new \NethServer\Tool\GroupProvider($this->getPlatform());
         foreach (array_keys($groupProvider->getGroups()) as $u) {
             $tmp = explode('@', $u);
             $groups[] = $tmp[0];
         }
         if (in_array($this->parameters['groupname'], $groups)) {
             # group already exists
             $report->addValidationErrorMessage($this, 'groupname', 'group_exists');
         }
     }
     parent::validate($report);
 }
Ejemplo n.º 2
0
 public function validate(\Nethgui\Controller\ValidationReportInterface $report)
 {
     if ($this->getRequest()->isMutation()) {
         $ports = explode(',', $this->parameters['Ports']);
         $v = $this->createValidator(Validate::PORTNUMBER);
         foreach ($ports as $port) {
             if (!$v->evaluate($port)) {
                 $report->addValidationErrorMessage($this, 'Ports', 'Ports_validator');
             }
         }
     }
     $keyExists = $this->getPlatform()->getDatabase('fwservices')->getType($this->parameters['name']) != '';
     if ($this->getIdentifier() === 'create' && $keyExists) {
         $report->addValidationErrorMessage($this, 'name', 'Service_key_exists_message');
     }
     if ($this->getIdentifier() !== 'create' && !$keyExists) {
         throw new \Nethgui\Exception\HttpException('Not found', 404, 1407169969);
     }
     if ($this->getIdentifier() === 'delete') {
         $v = $this->createValidator()->platform('fwobject-fwservice-delete', 'fwservices');
         if (!$v->evaluate($this->parameters['name'])) {
             $report->addValidationError($this, 'ServicesKey', $v);
         }
     }
     parent::validate($report);
 }
Ejemplo n.º 3
0
 public function validate(\Nethgui\Controller\ValidationReportInterface $report)
 {
     $key = $this->parameters['port'];
     if ($this->getIdentifier() == 'create' && $this->getRequest()->isMutation() && $this->getPlatform()->getDatabase('tc')->getType($key)) {
         $report->addValidationErrorMessage($this, 'port', 'Port_key_exists_message');
     }
     parent::validate($report);
 }
 public function validate(\Nethgui\Controller\ValidationReportInterface $report)
 {
     $key = $this->parameters['name'];
     if ($this->getPlatform()->getDatabase('hosts')->getType($key)) {
         $report->addValidationErrorMessage($this, 'name', 'Host_key_exists_message');
     }
     parent::validate($report);
 }
 public function validate(\Nethgui\Controller\ValidationReportInterface $report)
 {
     $this->getValidator('SpamTag2Level')->lessThan($this->parameters['SpamKillLevel']);
     $message = '';
     $args = array();
     if ($this->validateAddressAcl($message, $args) === FALSE) {
         $report->addValidationErrorMessage($this, 'AddressAcl', $message, $args);
     }
     parent::validate($report);
 }
Ejemplo n.º 6
0
 public function validate(\Nethgui\Controller\ValidationReportInterface $report)
 {
     if ($this->getIdentifier() === 'delete') {
         $v = $this->createValidator(Validate::USERNAME)->platform('user-delete');
         if (!$v->evaluate($this->getAdapter()->getKeyValue())) {
             $report->addValidationError($this, 'username', $v);
         }
     }
     parent::validate($report);
 }
Ejemplo n.º 7
0
 public function validate(\Nethgui\Controller\ValidationReportInterface $report)
 {
     if ($this->getIdentifier() === 'delete') {
         $v = $this->createValidator()->platform('host-delete', 'hosts');
         if (!$v->evaluate($this->parameters['hostname'])) {
             $report->addValidationError($this, 'Key', $v);
         }
     }
     parent::validate($report);
 }
Ejemplo n.º 8
0
 public function validate(\Nethgui\Controller\ValidationReportInterface $report)
 {
     $keyExists = $this->keyExists('bypass;' . $this->parameters['name']);
     if ($this->getIdentifier() === 'create' && $keyExists) {
         $report->addValidationErrorMessage($this, 'name', 'key_exists_message');
     }
     if ($this->getIdentifier() && $this->parameters['Host'] && !$this->keyExists($this->parameters['Host'])) {
         $report->addValidationErrorMessage($this, 'Host', 'key_doesnt_exists_message');
     }
     parent::validate($report);
 }
Ejemplo n.º 9
0
 public function validate(\Nethgui\Controller\ValidationReportInterface $report)
 {
     // Bind the dhcp-reservation platform validator:
     if ($this->getRequest()->isMutation()) {
         $this->getValidator('IpAddress')->platform('dhcp-reservation', $this->parameters['MacAddress'], $this->parameters['hostname']);
     }
     if ($this->getIdentifier() === 'delete') {
         $v = $this->createValidator()->platform('host-delete');
         if (!$v->evaluate($this->parameters['hostname'])) {
             $report->addValidationError($this, 'Key', $v);
         }
     }
     parent::validate($report);
 }
 public function validate(\Nethgui\Controller\ValidationReportInterface $report)
 {
     $key = $this->parameters['name'];
     if ($this->getPlatform()->getDatabase('fwservices')->getType($key)) {
         $report->addValidationErrorMessage($this, 'name', 'Service_key_exists_message');
     }
     if ($this->getRequest()->isMutation()) {
         $ports = explode(',', $this->parameters['Ports']);
         $v = $this->createValidator(Validate::PORTNUMBER);
         foreach ($ports as $port) {
             if (!$v->evaluate($port)) {
                 $report->addValidationErrorMessage($this, 'Ports', 'Ports_validator');
             }
         }
     }
     parent::validate($report);
 }
Ejemplo n.º 11
0
 public function validate(\Nethgui\Controller\ValidationReportInterface $report)
 {
     $keyExists = $this->getPlatform()->getDatabase('contentfilter')->getType($this->parameters['name']) != '';
     if ($this->getIdentifier() === 'create' && $keyExists) {
         $report->addValidationErrorMessage($this, 'name', 'key_exists_message');
     }
     if ($this->getIdentifier() !== 'create' && !$keyExists) {
         throw new \Nethgui\Exception\HttpException('Not found', 404, 1416876002);
     } else {
         $startTime = strtotime($this->parameters['StartTime']);
         $endTime = strtotime($this->parameters['EndTime']);
         if ($startTime > $endTime) {
             $report->addValidationErrorMessage($this, 'EndTime', 'endtime_grater_than_starttime');
         }
     }
     parent::validate($report);
 }
Ejemplo n.º 12
0
 public function validate(\Nethgui\Controller\ValidationReportInterface $report)
 {
     $keyExists = $this->getPlatform()->getDatabase('hosts')->getType($this->parameters['name']) != '';
     if ($this->getIdentifier() === 'create' && $keyExists) {
         $report->addValidationErrorMessage($this, 'name', 'Host_key_exists_message');
     }
     if ($this->getIdentifier() !== 'create' && !$keyExists) {
         throw new \Nethgui\Exception\HttpException('Not found', 404, 1407169968);
     }
     if ($this->getIdentifier() === 'delete') {
         $v = $this->createValidator()->platform('fwobject-host-group-delete', 'hosts');
         if (!$v->evaluate($this->parameters['name'])) {
             $report->addValidationError($this, 'HostGroupsKey', $v);
         }
     }
     parent::validate($report);
 }
 public function validate(\Nethgui\Controller\ValidationReportInterface $report)
 {
     if ($this->parameters['type'] == 'bond') {
         $this->getValidator('bond')->notEmpty();
     }
     if ($this->parameters['type'] == 'bridge') {
         $this->getValidator('bridge')->notEmpty();
     }
     if ($this->getRequest()->isMutation() && $this->parameters['type'] == 'xdsl') {
         $hasXdsl = $this->getPlatform()->getDatabase('networks')->getType('ppp0') === 'xdsl';
         if ($hasXdsl) {
             $report->addValidationErrorMessage($this, 'xdsl', 'valid_pppoe_already_configured');
         } elseif ($this->parameters['role'] !== 'red') {
             $report->addValidationErrorMessage($this, 'role', 'valid_pppoe_red_role_only');
         }
     }
     parent::validate($report);
 }
Ejemplo n.º 14
0
 public function validate(\Nethgui\Controller\ValidationReportInterface $report)
 {
     $ips = explode(',', $this->parameters['AllowHosts']);
     $ipvalidator = $this->createValidator(Validate::IPv4_OR_EMPTY);
     $cidrvalidator = $this->createValidator(Validate::CIDR_BLOCK);
     foreach ($ips as $ip) {
         if (!$ipvalidator->evaluate($ip) && !$cidrvalidator->evaluate($ip)) {
             $report->addValidationErrorMessage($this, 'AllowHosts', 'AllowHosts_validator');
         }
     }
     $ips = explode(',', $this->parameters['DenyHosts']);
     $ipvalidator = $this->createValidator(Validate::IPv4_OR_EMPTY);
     foreach ($ips as $ip) {
         if (!$ipvalidator->evaluate($ip) && !$cidrvalidator->evaluate($ip)) {
             $report->addValidationErrorMessage($this, 'DenyHosts', 'DenyHosts_validator');
         }
     }
     parent::validate($report);
 }
Ejemplo n.º 15
0
 public function validate(\Nethgui\Controller\ValidationReportInterface $report)
 {
     if (!$this->getRequest()->isMutation()) {
         return;
     }
     if ($this->getIdentifier() === 'delete') {
         $v = $this->createValidator()->platform('user-delete');
         if (!$v->evaluate($this->getAdapter()->getKeyValue())) {
             $report->addValidationError($this, 'username', $v);
         }
     }
     if ($this->getIdentifier() === 'update' || $this->getIdentifier() === 'create') {
         $groups = array_keys($this->getGroupProvider()->getGroups());
         $this->getValidator('groups')->memberOf($groups);
     }
     if ($this->getIdentifier() === 'create') {
         $users = array();
         if ($this->parameters['setPassword'] === 'enabled') {
             $passwordValidator = $this->getPlatform()->createValidator()->platform('password-strength', 'Users');
             $this->stash = new \NethServer\Tool\PasswordStash();
             $this->stash->store($this->parameters['newPassword']);
             if ($this->parameters['newPassword'] !== $this->parameters['confirmNewPassword']) {
                 $report->addValidationErrorMessage($this, 'confirmNewPassword', 'ConfirmNoMatch_label');
             } elseif (!$passwordValidator->evaluate($this->stash->getFilePath())) {
                 $report->addValidationError($this, 'newPassword', $passwordValidator);
             }
         }
         $userProvider = new \NethServer\Tool\UserProvider($this->getPlatform());
         foreach (array_keys($userProvider->getUsers()) as $u) {
             $tmp = explode('@', $u);
             $users[] = $tmp[0];
         }
         if (in_array($this->parameters['username'], $users)) {
             # user already exists
             $report->addValidationErrorMessage($this, 'username', 'user_exists');
         }
     }
     parent::validate($report);
 }
Ejemplo n.º 16
0
 public function validate(\Nethgui\Controller\ValidationReportInterface $report)
 {
     $keyExists = $this->getPlatform()->getDatabase('hosts')->getType($this->parameters['name']) != '';
     if ($this->getIdentifier() === 'create' && $keyExists) {
         $report->addValidationErrorMessage($this, 'name', 'IpRange_key_exists_message');
     }
     if ($this->getIdentifier() !== 'create' && !$keyExists) {
         throw new \Nethgui\Exception\HttpException('Not found', 404, 1428599495);
     }
     if ($this->getIdentifier() === 'delete') {
         $v = $this->createValidator()->platform('fwobject-iprange-delete', 'hosts');
         if (!$v->evaluate($this->parameters['name'])) {
             $report->addValidationError($this, 'IpRangeKey', $v);
         }
     }
     $ipValidator = $this->createValidator()->ipV4Address();
     if (($this->getIdentifier() === 'create' || $this->getIdentifier() == 'update') && $ipValidator->evaluate($this->parameters['Start']) && $ipValidator->evaluate($this->parameters['End'])) {
         if (ip2long($this->parameters['Start']) >= ip2long($this->parameters['End'])) {
             $report->addValidationErrorMessage($this, 'Start', 'valid_iprange_outofbounds');
             $report->addValidationErrorMessage($this, 'End', 'valid_iprange_outofbounds');
         }
     }
     parent::validate($report);
 }
Ejemplo n.º 17
0
 public function validate(\Nethgui\Controller\ValidationReportInterface $report)
 {
     $keyExists = $this->keyExists($this->parameters['name']);
     if ($this->getIdentifier() === 'create' && $keyExists) {
         $report->addValidationErrorMessage($this, 'name', 'key_exists_message');
     }
     if ($this->getIdentifier() && $this->parameters['Src']) {
         if (strpos($this->parameters['Src'], ';') === false) {
             // User from active directory, no further check
         } else {
             if (!$this->keyExists($this->parameters['Src'])) {
                 $report->addValidationErrorMessage($this, 'Src', 'key_doesnt_exists_message');
             }
         }
     }
     if ($this->getIdentifier() && $this->parameters['Filter'] && !$this->keyExists($this->parameters['Filter'])) {
         $report->addValidationErrorMessage($this, 'Filter', 'key_doesnt_exists_message');
     }
     if ($this->parameters['Time'] && !$this->keyExists($this->parameters['Time'])) {
         $report->addValidationErrorMessage($this, 'Time', 'key_doesnt_exists_message');
     }
     parent::validate($report);
 }
Ejemplo n.º 18
0
 public function validate(\Nethgui\Controller\ValidationReportInterface $report)
 {
     foreach ($this->parameters->getKeys() as $parameterName) {
         if (!$this->getRequest()->hasParameter($parameterName)) {
             continue;
             // missing parameters are not validated
         }
         if (!isset($this->validators[$parameterName])) {
             throw new \Nethgui\Exception\HttpException(sprintf('%s: Do not know how to validate `%s`', get_class($this), $parameterName), 400, 1322148402);
         }
         $validator = $this->validators[$parameterName];
         $isValid = $validator->evaluate($this->parameters[$parameterName]);
         if ($isValid !== TRUE) {
             $report->addValidationError($this, $parameterName, $validator);
             $this->invalidParameters[] = $parameterName;
         }
     }
 }
Ejemplo n.º 19
0
 public function validate(\Nethgui\Controller\ValidationReportInterface $report)
 {
     $keyExists = $this->getPlatform()->getDatabase('contentfilter')->getType($this->parameters['name']) != '';
     if ($this->getIdentifier() === 'create' && $keyExists) {
         $report->addValidationErrorMessage($this, 'name', 'key_exists_message');
     }
     if ($this->getIdentifier() !== 'create' && !$keyExists) {
         throw new \Nethgui\Exception\HttpException('Not found', 404, 1416876015);
     }
     parent::validate($report);
 }
Ejemplo n.º 20
0
 public function validate(\Nethgui\Controller\ValidationReportInterface $report)
 {
     if ($this->parameters['Allow']) {
         $validator = $this->createValidator()->orValidator($this->createValidator(Validate::IPv4), $this->createValidator(Validate::CIDR_BLOCK));
         $values = explode(',', $this->parameters['Allow']);
         foreach ($values as $v) {
             if (!$validator->evaluate($v)) {
                 $report->addValidationError($this, 'Allow', $validator);
             }
         }
     }
     parent::validate($report);
 }