public function validate(\Nethgui\Controller\ValidationReportInterface $report)
 {
     parent::validate($report);
     if (!$this->getRequest()->isMutation()) {
         return;
     }
     $getSecondField = function ($line) {
         $a = str_getcsv($line);
         return $a[1];
     };
     $validInterfaces = array_keys($this->getUnassignedInterfaces());
     $validMacs = array_map($getSecondField, $this->getNicInfo());
     $duplicatesCheck = array();
     foreach ($this->parameters['cards'] as $interface => $setting) {
         if (in_array($setting['interface'], $duplicatesCheck)) {
             $report->addValidationErrorMessage($this, 'cards', 'Duplicated assignment');
         }
         if (isset($setting['interface']) && $setting['interface'] && !in_array($setting['interface'], $validInterfaces)) {
             $report->addValidationErrorMessage($this, 'cards', 'Inconsistent interface name');
         }
         if (!in_array($setting['hwaddr'], $validMacs)) {
             $report->addValidationErrorMessage($this, 'cards', 'Inconsistent mac address');
         }
         if ($setting['interface']) {
             $duplicatesCheck[] = $setting['interface'];
         }
     }
 }
 public function validate(\Nethgui\Controller\ValidationReportInterface $report)
 {
     parent::validate($report);
     if (!$this->getRequest()->isMutation()) {
         return;
     }
     $hostnameValidator = $this->createValidator(Validate::HOSTNAME_FQDN);
     $domains = array_filter(preg_split('/[,\\s]+/', $this->parameters['LetsEncryptDomains']));
     foreach ($domains as $domain) {
         if (!$hostnameValidator->evaluate($domain)) {
             $report->addValidationErrorMessage($this, 'LetsEncryptDomains', "Domain {$domain} is not a valid domain FQDN");
         }
     }
     if (!$report->hasValidationErrors()) {
         //test with LetsEncrypt script. Use -d DOMAINS because LetsEncryptDomains isn't written yet
         $cmd = "/usr/bin/sudo /usr/libexec/nethserver/letsencrypt-certs -t -d " . join(",", $domains);
         $this->getPlatform()->getLog()->notice("Testing LetsEncrypt: {$cmd}");
         $p = $this->getPlatform()->exec($cmd);
         $stderr = $p->getErrorOutput();
         $stdout = $p->getOutput();
         $ret = $p->getexitCode();
         if ($ret != 0) {
             $report->addValidationErrorMessage($this, 'LetsEncryptDomains', $stderr);
             $this->getPlatform()->getLog()->notice("Error testing LetsEncrypt: " . $stderr);
         }
     }
 }
Exemple #3
0
 public function validate(\Nethgui\Controller\ValidationReportInterface $report)
 {
     if ($this->parameters['Provider'] === 'ad') {
         $this->getValidator('AdDns')->platform('ad-dns');
     }
     parent::validate($report);
 }
Exemple #4
0
 public function validate(\Nethgui\Controller\ValidationReportInterface $report)
 {
     if ($this->getRequest()->isMutation()) {
         $this->getValidator('timezone')->memberOf($this->tzCodes);
     }
     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);
 }
 public function validate(\Nethgui\Controller\ValidationReportInterface $report)
 {
     parent::validate($report);
     $itemValidator = $this->getPlatform()->createValidator(\Nethgui\System\PlatformInterface::IP);
     foreach (self::splitLines($this->parameters['AccessBypassList']) as $v) {
         if (!$itemValidator->evaluate($v)) {
             $report->addValidationErrorMessage($this, 'AccessBypassList', 'IP address list', array($v));
             break;
         }
     }
 }
 public function validate(\Nethgui\Controller\ValidationReportInterface $report)
 {
     parent::validate($report);
     if (!$this->getRequest()->isMutation()) {
         return;
     }
     $validKeys = array_keys($this->getNetworkInterfaces());
     foreach (array_keys($this->getRequest()->getParameter('interfaces')) as $key) {
         if (!in_array($key, $validKeys)) {
             $report->addValidationErrorMessage($this, 'interfaces', 'invalid alias interface');
         }
     }
 }
 public function validate(\Nethgui\Controller\ValidationReportInterface $report)
 {
     parent::validate($report);
     $logFileValidator = $this->createValidator()->platform('logfile');
     if (!$logFileValidator->evaluate($this->logFile)) {
         throw new \Nethgui\Exception\HttpException(sprintf("%s: resource not found", __CLASS__), 404, 1366643514);
     }
     $offsetValidator = $this->createValidator(\Nethgui\System\PlatformInterface::NONNEGATIVE_INTEGER);
     $queryValidator = $this->createValidator(\Nethgui\System\PlatformInterface::ANYTHING);
     if (!$offsetValidator->evaluate($this->offset)) {
         $report->addValidationError($this, 'o', $offsetValidator);
     }
     if (!$queryValidator->evaluate($this->query)) {
         $report->addValidationError($this, 'q', $queryValidator);
     }
 }
 public function validate(\Nethgui\Controller\ValidationReportInterface $report)
 {
     parent::validate($report);
     $hostNames = array_filter(preg_split("/[,\\s]+/", $this->parameters['SubjectAltName']), function ($v) {
         return preg_match("/[a-zA-Z]/", $v);
     });
     $validator = $this->createValidator()->hostname(1);
     foreach ($hostNames as $origHostName) {
         $hostName = trim($origHostName);
         if (substr($hostName, 0, 2) === '*.') {
             $hostName = substr($hostName, 2);
         }
         if (!$validator->evaluate($hostName)) {
             $report->addValidationErrorMessage($this, 'SubjectAltName', 'valid_hostname_instance', array($origHostName));
             break;
         }
     }
 }
 public function validate(\Nethgui\Controller\ValidationReportInterface $report)
 {
     parent::validate($report);
     if (!$this->getRequest()->isMutation()) {
         return;
     }
     $validInterfaces = array_keys($this->getUnassignedInterfaces());
     $duplicatesCheck = array();
     foreach ($this->parameters['cards'] as $interface => $setting) {
         if (in_array($setting['interface'], $duplicatesCheck)) {
             $report->addValidationErrorMessage($this, 'cards', 'Duplicated assignment');
         }
         if (isset($setting['interface']) && $setting['interface'] && !in_array($setting['interface'], $validInterfaces)) {
             $report->addValidationErrorMessage($this, 'cards', 'Inconsistent interface name');
         }
         if ($setting['interface']) {
             $duplicatesCheck[] = $setting['interface'];
         }
     }
 }
 public function validate(\Nethgui\Controller\ValidationReportInterface $report)
 {
     parent::validate($report);
     $submittedInterfaces = array_keys($this->getRequest()->getParameter('interfaces'));
     $existingInterfaces = array_keys($this->getNetworkInterfaces());
     if (count($submittedInterfaces) !== count(\array_intersect($existingInterfaces, $submittedInterfaces))) {
         $report->addValidationErrorMessage($this, 'interfaces', 'valid_interface_existing');
     }
     $statusValidator = $this->createValidator(Validate::SERVICESTATUS);
     $hostnameValidator = $this->createValidator(Validate::HOSTNAME);
     $positiveValidator = $this->createValidator(Validate::POSITIVE_INTEGER);
     $ipValidator = $this->createValidator()->ipV4Address();
     $interfaces = $this->getNetworkInterfaces();
     foreach ($this->getRequest()->getParameter('interfaces') as $key => $record) {
         $fakeModule = $this->getFakeModule('interfaces_' . $key);
         if (!$statusValidator->evaluate($record['status'])) {
             $report->addValidationError($fakeModule, 'status', $statusValidator);
             continue;
         }
         if ($record['status'] !== 'enabled') {
             continue;
             /* skip range validation if DHCP is disabled */
         }
         if ($ipValidator->evaluate($record['DhcpRangeStart'])) {
             if (ip2long($record['DhcpRangeStart']) < ip2long($this->getDefaultRange('start', $key, $interfaces[$key]))) {
                 $report->addValidationErrorMessage($fakeModule, 'DhcpRangeStart', 'valid_iprange_outofbounds');
             }
         } else {
             $report->addValidationError($fakeModule, 'DhcpRangeStart', $ipValidator);
         }
         if ($ipValidator->evaluate($record['DhcpRangeEnd'])) {
             if (ip2long($record['DhcpRangeEnd']) > ip2long($this->getDefaultRange('end', $key, $interfaces[$key]))) {
                 $report->addValidationErrorMessage($fakeModule, 'DhcpRangeEnd', 'valid_iprange_outofbounds');
             }
         } else {
             $report->addValidationError($fakeModule, 'DhcpRangeEnd', $ipValidator);
         }
         if (isset($record['DhcpGatewayIP']) && $record['DhcpGatewayIP']) {
             if (!$ipValidator->evaluate($record['DhcpGatewayIP'])) {
                 $report->addValidationError($fakeModule, 'DhcpGatewayIP', $ipValidator);
             }
         }
         if (isset($record['DhcpLeaseTime']) && $record['DhcpLeaseTime'] > 0) {
             if (!$positiveValidator->evaluate($record['DhcpLeaseTime'])) {
                 $report->addValidationError($fakeModule, 'DhcpLeaseTime', $positiveValidator);
             }
         }
         if (isset($record['DhcpDomain']) && $record['DhcpDomain']) {
             if (!$hostnameValidator->evaluate($record['DhcpDomain'])) {
                 $report->addValidationError($fakeModule, 'DhcpDomain', $hostnameValidator);
             }
         }
         $props = array('DhcpDNS', 'DhcpWINS', 'DhcpNTP', 'DhcpTFTP');
         foreach ($props as $prop) {
             if (isset($record[$prop]) && $record[$prop]) {
                 foreach (explode(',', $record[$prop]) as $ip) {
                     if (!$ipValidator->evaluate($ip)) {
                         $report->addValidationError($fakeModule, $prop, $ipValidator);
                     }
                 }
             }
         }
     }
 }
Exemple #12
0
 public function validate(\Nethgui\Controller\ValidationReportInterface $report)
 {
     parent::validate($report);
     if ($report->hasValidationErrors()) {
         return;
     }
     /* @var $user \Nethgui\Authorization\User */
     $user = $this->getRequest()->getUser();
     if (!$user->isAuthenticated() && $this->getRequest()->isMutation()) {
         $authenticated = $user->authenticate($this->parameters['username'], $this->parameters['password']);
         $user->setLocale($this->parameters['language']);
         if (!$authenticated) {
             $report->addValidationError($this, 'password', $this->loginValidator);
         }
     }
 }