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); }
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); }
public function validate(\Nethgui\Controller\ValidationReportInterface $report) { parent::validate($report); if ($this->getRequest()->isMutation() && !$this->parameters['interface']) { $report->addValidationErrorMessage($this, 'interface', 'valid_no_red_interface'); } }
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) { 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); }
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); }
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); }
public function validate(\Nethgui\Controller\ValidationReportInterface $report) { parent::validate($report); // we must explicitly validate the pseudonym parameter because is not posted with create request if ($this->getRequest()->isMutation() && $this->getIdentifier() === 'create') { if ($this->getValidator('pseudonym')->evaluate($this->parameters['pseudonym']) !== TRUE) { $report->addValidationErrorMessage($this, 'localAddress', 'valid_email,malformed-localpart'); } elseif ($this->getIdentifier() === 'create' && $this->getParent()->getAdapter()->offsetExists($this->parameters['pseudonym'])) { $report->addValidationErrorMessage($this, 'localAddress', 'valid_pseudonym_unique'); } } }
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) { $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) { $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); }
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); }
public function validate(\Nethgui\Controller\ValidationReportInterface $report) { parent::validate($report); if (!$this->getRequest()->isMutation() || $report->hasValidationErrors()) { return; } // check the "network" parameter is consistent with its "Mask" (only 0-bits in tail) $net = long2ip(ip2long($this->parameters['network']) & ip2long($this->parameters['Mask'])); if ($net != $this->parameters['network']) { $report->addValidationErrorMessage($this, 'network', 'invalid_network', array($this->parameters['network'])); return; } // check the network is not subnet of existing networks and vice-versa foreach ($this->getParent()->getAdapter() as $net => $props) { if ($this->isUsed($this->parameters['network'], $this->parameters['Mask'], $net, $props['Mask'])) { $report->addValidationErrorMessage($this, 'network', 'used_network', array($this->parameters['network'], $net)); return; } } }
public function validate(\Nethgui\Controller\ValidationReportInterface $report) { parent::validate($report); if (!$this->getRequest()->isMutation()) { return; } if ($this->getIdentifier() === 'create' && $this->getPlatform()->getDatabase('proxypass')->getKey($this->parameters['Name'])) { $report->addValidationErrorMessage($this, 'Name', 'Name_Already_Exists'); } if (!filter_var($this->parameters['Target'], FILTER_VALIDATE_URL) || strpos($this->parameters['Target'], 'http') !== 0) { $report->addValidationErrorMessage($this, 'Target', 'Invalid_Target'); } $cidrList = preg_split('/\\s*,\\s*/', $this->parameters['ValidFrom']); $cidrValidator = $this->createValidator(Validate::CIDR_BLOCK); foreach ($cidrList as $cidr) { if ($cidr !== '' && !$cidrValidator->evaluate($cidr)) { $report->addValidationErrorMessage($this, 'ValidFrom', 'ValidFrom_validator'); break; } } }
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); }
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); }
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); }
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); }
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); }