public function bind(\Nethgui\Controller\RequestInterface $request)
 {
     $keyValue = \Nethgui\array_head($request->getPath());
     $this->getAdapter()->setKeyValue($keyValue);
     parent::bind($request);
     $this->parameters['active'] = $this->getIdentifier() === 'enable' ? 'YES' : 'NO';
 }
Ejemplo n.º 2
0
 protected function establishCurrentActionId()
 {
     $request = $this->getRequest();
     $params = array();
     if ($request->hasParameter('create')) {
         $params = $request->getParameter('create');
         $action = 'create';
     } elseif ($request->hasParameter('update')) {
         if ($request->isMutation()) {
             $params = $request->getParameter('update');
         } else {
             $subRequest = $request->spawnRequest('update');
             $params = $subRequest->getParameter(\Nethgui\array_head($subRequest->getPath()));
         }
         $action = implode('/', $request->getPath());
     }
     if (isset($params['PickSource']) && $request->isMutation()) {
         $this->getAction('SaveState')->setField('SrcRaw')->setReturnPath($action)->setResumeState($params);
         return 'SaveState';
     }
     $this->myCurrentAction = parent::establishCurrentActionId();
     if (isset($params['f'], $params['h']) && !$request->isMutation()) {
         $this->getAction('SaveState')->setResumeCallback(function (\Nethgui\View\ViewInterface $view, $state) {
             $view['Priority'] = $state['Priority'];
             $view['Description'] = $state['Description'];
             $view['SrcRaw'] = $state['SrcRaw'];
             $view['Source'] = \NethServer\Module\FirewallRules\RuleGenericController::translateFirewallObjectTitle($view, $state['SrcRaw']);
             $view->getCommandList()->show();
         });
     }
     return $this->myCurrentAction;
 }
Ejemplo n.º 3
0
 public function bind(\Nethgui\Controller\RequestInterface $request)
 {
     parent::bind($request);
     if (!$this->getRequest()->isMutation()) {
         $this->parameters['name'] = \Nethgui\array_head($request->getPath());
         $this->parameters['components'] = $this->getInstalledComponents();
     }
 }
Ejemplo n.º 4
0
 public function bind(\Nethgui\Controller\RequestInterface $request)
 {
     $ruleId = \Nethgui\array_head($request->getPath());
     if (!$this->getAdapter()->offsetExists($ruleId)) {
         throw new \Nethgui\Exception\HttpException('Not found', 404, 1399992974);
     }
     parent::bind($request);
     $this->parameters['ruleId'] = $ruleId;
 }
Ejemplo n.º 5
0
 protected function bindPosition(\Nethgui\Controller\RequestInterface $request)
 {
     $A = $this->getAdapter();
     $position = \Nethgui\array_head($request->getPath());
     $id = $request->spawnRequest($position)->getParameter('id');
     if (isset($id, $A[$id])) {
         $this->copyDefaults = \iterator_to_array($A[$id]);
     }
     return $position;
 }
Ejemplo n.º 6
0
 /**
  * Add default Cancel and FormAction URLs 
  * 
  * @param \Nethgui\View\ViewInterface $view 
  */
 public function prepareView(\Nethgui\View\ViewInterface $view)
 {
     parent::prepareView($view);
     if (!isset($view['Cancel'])) {
         $view['Cancel'] = $view->getModuleUrl('/' . \Nethgui\array_head($view->resolvePath('')));
     }
     if (!$this instanceof \Nethgui\Module\ModuleCompositeInterface) {
         $view['FormAction'] = $view->getModuleUrl(implode('/', $this->getRequest()->getPath()));
     }
 }
Ejemplo n.º 7
0
 public function bind(\Nethgui\Controller\RequestInterface $request)
 {
     $keyValue = \Nethgui\array_head($request->getPath());
     $A = $this->getParent()->getAdapter();
     if (!isset($A[$keyValue])) {
         throw new \Nethgui\Exception\HttpException('Not found', 404, 1399033549);
     }
     if (isset($A[$keyValue]['role']) && in_array($A[$keyValue]['role'], array('bridged', 'slave', 'alias'))) {
         throw new \Nethgui\Exception\HttpException('Not found', 404, 1399033550);
     }
     $this->getAdapter()->setKeyValue($keyValue);
     parent::bind($request);
 }
 public function bind(\Nethgui\Controller\RequestInterface $request)
 {
     $keyValue = \Nethgui\array_head($request->getPath());
     $adapter = $this->getParent()->getAdapter();
     if (!isset($adapter[$keyValue])) {
         throw new \Nethgui\Exception\HttpException('Not found', 404, 1399456808);
     }
     $props = $adapter[$keyValue];
     if ($props['type'] !== 'ethernet') {
         throw new \Nethgui\Exception\HttpException('Not found', 404, 1399456809);
     }
     parent::bind($request);
     $this->parameters['device'] = $keyValue;
 }
 public function bind(\Nethgui\Controller\RequestInterface $request)
 {
     $keyValue = \Nethgui\array_head($request->getPath());
     $adapter = $this->getParent()->getAdapter();
     if (!isset($adapter[$keyValue])) {
         throw new \Nethgui\Exception\HttpException('Not found', 404, 1399456905);
     }
     if (!in_array($adapter[$keyValue]['type'], array('bridge', 'bond', 'alias', 'vlan', 'xdsl'))) {
         throw new \Nethgui\Exception\HttpException('Not found', 404, 1399456906);
     }
     parent::bind($request);
     $this->parameters['type'] = $adapter[$keyValue]['type'];
     $this->parameters['device'] = $keyValue;
 }
Ejemplo n.º 10
0
 public function prepareView(\Nethgui\View\ViewInterface $view)
 {
     parent::prepareView($view);
     $name = \Nethgui\array_head($this->getRequest()->getPath());
     $view['ovpn'] = $view->getModuleUrl('/VPN/Accounts/download/ovpn/' . $name);
     $view['pem'] = $view->getModuleUrl('/VPN/Accounts/download/pem/' . \Nethgui\array_head($this->getRequest()->getPath()));
     $view['ca'] = $view->getModuleUrl('/VPN/Accounts/download/ca/' . \Nethgui\array_head($this->getRequest()->getPath()));
     $view['pkcs12'] = $view->getModuleUrl('/VPN/Accounts/download/pkcs12/' . \Nethgui\array_head($this->getRequest()->getPath()));
     if ($this->getRequest()->isValidated()) {
         $command = "";
         $file = "";
         $path = $this->getRequest()->getPath();
         $name = array_pop($path);
         $type = array_pop($path);
         $mime = 'text/plain; charset=UTF-8';
         switch ($type) {
             case 'ovpn':
                 $command = $this->prepareCommand("/usr/libexec/nethserver/openvpn-local-client", array($name));
                 $mime = 'application/x-openvpn-profile';
                 $file = "{$name}.ovpn";
                 break;
             case 'ca':
                 $command = $this->prepareCommand("/bin/cat", array("/etc/pki/tls/certs/NSRV.crt"));
                 $mime = 'application/x-pem-file';
                 $file = "ca.crt";
                 break;
             case 'pem':
                 $command = $this->prepareCommand("/bin/cat", array("/var/lib/nethserver/certs/{$name}.key", "/var/lib/nethserver/certs/{$name}.crt", "/etc/pki/tls/certs/NSRV.crt"));
                 $file = "{$name}.pem";
                 $mime = 'application/x-pem-file';
                 break;
             case 'pkcs12':
                 $command = $this->prepareCommand("/bin/cat", array("/var/lib/nethserver/certs/{$name}.p12"));
                 $file = "{$name}.p12";
                 $mime = 'application/x-pkcs12';
                 break;
         }
         $view->getCommandList('/Main')->setDecoratorTemplate(function (\Nethgui\View\ViewInterface $view) use($command, $file, $mime) {
             // Discard any output buffer:
             while (ob_get_level() > 0) {
                 ob_end_clean();
             }
             header(sprintf('Content-type: %s', $mime));
             header('Content-Disposition: attachment; filename="' . $file . '"');
             passthru($command);
             exit(0);
         });
     }
 }
Ejemplo n.º 11
0
 public function prepareView(\Nethgui\View\ViewInterface $view)
 {
     if ($this->getRequest()->isMutation()) {
         $this->getPlatform()->setDetachedProcessCondition('success', array('location' => array('url' => $view->getModuleUrl('/Account/DomainController?installSuccess'), 'freeze' => TRUE)));
     }
     parent::prepareView($view);
     $view['NetbiosDomain'] = $this->getPlatform()->getDatabase('configuration')->getProp('smb', 'Workgroup');
     if (!$view['NetbiosDomain']) {
         $domainName = $this->getPlatform()->getDatabase('configuration')->getType('DomainName');
         $view['NetbiosDomain'] = \Nethgui\array_head(explode('.', $domainName));
     }
     $view['NetbiosDomain'] = strtoupper(substr($view['NetbiosDomain'], 0, 15));
     if ($this->getRequest()->hasParameter('installSuccess')) {
         $view->getCommandList('/Main')->sendQuery($view->getModuleUrl('/Account'));
     }
 }
Ejemplo n.º 12
0
 /**
  * Establish what is the key value, then invoke setKeyValue() on the 
  * RecordAdapter BEFORE parent::bind()
  * 
  * @param \Nethgui\Controller\RequestInterface $request 
  */
 public function bind(\Nethgui\Controller\RequestInterface $request)
 {
     if ($this->getIdentifier() === 'create') {
         if ($request->isMutation()) {
             $keyValue = $this->calculateKeyFromRequest($request);
         } else {
             $keyValue = FALSE;
         }
     } else {
         $keyValue = \Nethgui\array_head($request->getPath());
         $this->ensureKeyExists($keyValue);
     }
     // bind the record adapter to the row with identifier equal to $keyValue
     if (is_null($this->getAdapter()->getKeyValue())) {
         $this->getAdapter()->setKeyValue($keyValue);
     }
     parent::bind($request);
 }
Ejemplo n.º 13
0
 private function generateKey($request)
 {
     $device = \Nethgui\array_head($request->getPath());
     $A = $this->getParent()->getAdapter();
     if (!isset($A[$device])) {
         throw new \Nethgui\Exception\HttpException('Not found', 404, 1399459956);
     }
     if ($A[$device]['type'] === 'alias') {
         throw new \Nethgui\Exception\HttpException('Not found', 404, 1399459957);
     }
     $aliasNb = 0;
     foreach ($A as $key => $props) {
         if ($props['type'] === 'alias' && substr($key, 0, strlen($device)) === $device) {
             $aliasNb++;
         }
     }
     return sprintf('%s:%d', $device, $aliasNb);
 }
 private function generateKey($request)
 {
     $device = \Nethgui\array_head($request->getPath());
     $A = $this->getParent()->getAdapter();
     if (!isset($A[$device])) {
         throw new \Nethgui\Exception\HttpException('Not found', 404, 1399459956);
     }
     if ($A[$device]['type'] === 'alias') {
         throw new \Nethgui\Exception\HttpException('Not found', 404, 1399459957);
     }
     $existingAliases = array();
     foreach ($A as $key => $props) {
         if ($props['type'] === 'alias' && substr($key, 0, strlen($device)) === $device) {
             $existingAliases[] = substr($key, strlen($device) + 1);
             // remove the prefix up to ":"
         }
     }
     for ($aliasNb = 0; in_array($aliasNb, $existingAliases); $aliasNb++) {
     }
     return sprintf('%s:%d', $device, $aliasNb);
 }
Ejemplo n.º 15
0
 public function bind(\Nethgui\Controller\RequestInterface $request)
 {
     $idList = array_filter($request->getParameterNames(), function ($p) use($request) {
         return is_array($request->getParameter($p));
     });
     $this->moduleId = \Nethgui\array_head($request->getPath());
     if (!$this->moduleId) {
         return;
     }
     try {
         foreach ($idList as $moduleIdentifier) {
             $moduleInstance = $this->moduleSet->getModule($moduleIdentifier);
             $this->addChild($moduleInstance);
         }
     } catch (\Nethgui\Exception\AuthorizationException $ex) {
         throw $ex;
     } catch (\RuntimeException $ex) {
         throw new \Nethgui\Exception\HttpException('Not found', 404, 1324379722, $ex);
     }
     $this->authorize($request);
     parent::bind($request);
 }
Ejemplo n.º 16
0
 public function bind(\Nethgui\Controller\RequestInterface $request)
 {
     parent::bind($request);
     $fileName = \Nethgui\array_head($request->getPath());
     if (preg_match('/[a-z][a-z0-9]+(.rst)/i', $fileName) == 0 && preg_match('/[a-z][a-z0-9]+(.html)/i', $fileName) == 0) {
         throw new \Nethgui\Exception\HttpException('Not found', 404, 1322148405);
     }
     // Now assuming a trailing ".rst" or ".html" suffix.
     if (substr($fileName, -3) == 'rst') {
         $this->module = $this->getModuleSet()->getModule(substr($fileName, 0, -4));
     } else {
         //html
         $this->module = $this->getModuleSet()->getModule(substr($fileName, 0, -5));
     }
     if (is_null($this->module)) {
         throw new \Nethgui\Exception\HttpException('Not found', 404, 1322148406);
     }
     $this->module->setPlatform($this->getPlatform());
     if (!$this->module->isInitialized()) {
         $this->module->initialize();
     }
 }
Ejemplo n.º 17
0
 public function bind(\Nethgui\Controller\RequestInterface $request)
 {
     $ruleId = \Nethgui\array_head($request->getPath());
     if (!$this->getAdapter()->offsetExists($ruleId)) {
         throw new \Nethgui\Exception\HttpException('Not found', 404, 1399992975);
     }
     $this->worker->ruleId = $ruleId;
     $this->worker->bind($request);
     $subrequest = $request->spawnRequest($ruleId);
     if ($subrequest->hasParameter('f') || $subrequest->hasParameter('Submit')) {
         // resume values from
         $this->workflow->resume($this->getParent()->getSession())->copyTo($this->worker->parameters, array('SrcRaw', 'DstRaw', 'ServiceRaw', 'status', 'Description', 'LogType', 'Action'));
     } else {
         // start new workflow
         $defaults = array();
         foreach (array('SrcRaw', 'DstRaw', 'ServiceRaw', 'status', 'Description', 'LogType', 'Action') as $f) {
             if ($request->hasParameter($f)) {
                 $defaults[$f] = $request->getParameter($f);
             }
         }
         $this->workflow->start($this->getParent()->getSession(), $this->getIdentifier(), 'Edit/' . $ruleId, $ruleId, $defaults);
     }
 }
Ejemplo n.º 18
0
 /**
  *
  * @param \Nethgui\Controller\RequestInterface $originalRequest
  * @return \Nethgui\Module\Menu
  */
 public function setCurrentModuleIdentifier(\Nethgui\Controller\RequestInterface $originalRequest)
 {
     $this->currentItem = \Nethgui\array_head($originalRequest->getPath());
     return $this;
 }
Ejemplo n.º 19
0
 public function prepareView(\Nethgui\View\ViewInterface $view)
 {
     parent::prepareView($view);
     $view['WinregistryPatches'] = $view->getSiteUrl() . '/winregistry-patches';
     $view['defaultRealm'] = strtoupper($this->getPlatform()->getDatabase('configuration')->getType('DomainName'));
     $view['defaultDomain'] = \Nethgui\array_head(explode('.', strtoupper($this->getPlatform()->getDatabase('configuration')->getType('DomainName'))));
     $view['defaultWorkgroup'] = 'WORKGROUP';
     $view['defaultLdapAccountsBranch'] = 'cn=Users';
 }
Ejemplo n.º 20
0
 private function createLoginRequest(\Nethgui\Controller\Request $originalRequest)
 {
     $m = $originalRequest->toArray();
     unset($m[\Nethgui\array_head($originalRequest->getPath())]);
     $r = new \Nethgui\Controller\Request(array_replace_recursive(array('Login' => array('path' => '/' . implode('/', $originalRequest->getPath()))), $m));
     $r->setAttribute('locale', $originalRequest->getLocale());
     $r->setAttribute('userClosure', $originalRequest->getAttribute('userClosure'));
     return $r;
 }
Ejemplo n.º 21
0
 /**
  *
  * @param mixed $value
  * @return AbstractExpression
  */
 private function parseMatcher($value)
 {
     // Convert an array into AnyOfPolicyRuleMatcher:
     if (is_array($value)) {
         if (empty($value)) {
             return $this->parseMatcher('!*');
         }
         $a = $this->parseMatcher(\Nethgui\array_head($value));
         if (count($value) == 1) {
             return $a;
         }
         $b = $this->parseMatcher(\Nethgui\array_rest($value));
         return new AnyOfExpression($a, $b);
     }
     $parser = new PolicyExpressionParser($value);
     $parseTree = $parser->parse();
     return $parseTree;
 }
Ejemplo n.º 22
0
 private function prepareInitializationView(\Nethgui\View\ViewInterface $view)
 {
     $firstRunningTask = \Nethgui\array_head(array_keys($this->systemTasks->getRunningTasks()));
     if ($firstRunningTask) {
         // Notify that the task is running:
         $this->notifications->trackerRunning(array('taskId' => $firstRunningTask));
         $view['trackerState'] = FALSE;
         $view['progress'] = FALSE;
         $view['message'] = '';
         return;
     }
     $firstStartingTask = \Nethgui\array_head(array_keys($this->systemTasks->getStartingTasks()));
     if ($firstStartingTask) {
         $view['progress'] = 0;
         $view['message'] = '...';
         $view['trackerState'] = array('dialog' => array('title' => $view->translate('Tracker_title_taskStarting'), 'action' => 'open'), 'location' => array('sleep' => 2000, 'url' => $view->getModuleUrl($firstStartingTask)));
         return;
     }
 }
Ejemplo n.º 23
0
 /**
  * Save a request/response round, putting the next view data in the response
  * 
  * @param \Nethgui\View\ViewInterface $view 
  */
 private function prepareNextViewOptimized(\Nethgui\View\ViewInterface $view)
 {
     $np = $this->currentAction->nextPath();
     if ($np === FALSE) {
         return;
     }
     $nextModule = $this->getAction(\Nethgui\array_head(explode('/', $np)));
     $location = $view->getModuleUrl($np);
     if ($nextModule instanceof \Nethgui\View\ViewableInterface) {
         // spawn and prepare the next view data:
         $nextView = $view->spawnView($nextModule, TRUE);
         $nextModule->prepareView($nextView);
         if ($view->getTargetFormat() === $view::TARGET_JSON) {
             $nextView->getCommandList()->prefetched();
             // placeholder.
             $nextView->getCommandList()->show();
             // Display the prefetched view
             $this->getPlatform()->setDetachedProcessCondition('success', array('location' => array('url' => $location . '?taskStatus=success&taskId={taskId}'), 'freeze' => TRUE))->setDetachedProcessCondition('failure', array('location' => array('url' => $location . '?taskStatus=failure&taskId={taskId}'), 'freeze' => TRUE));
         } else {
             // show is implemented as HTTP redirection. Avoid self-loops:
             if ($nextModule !== $this->currentAction) {
                 $view->getCommandList()->sendQuery($location);
             }
         }
     } else {
         // next path does not corresponds to a child action: start
         // a new query request to get the next view data:
         $view->getCommandList()->sendQuery($location);
     }
 }
Ejemplo n.º 24
0
 protected function bindPosition(\Nethgui\Controller\RequestInterface $request)
 {
     return \Nethgui\array_head($request->getPath());
 }
Ejemplo n.º 25
0
 public function validate(\Nethgui\Controller\ValidationReportInterface $report)
 {
     parent::validate($report);
     if ($this->getRequest()->isMutation()) {
         $v = $this->createValidator()->platform('interface-config');
         if (!$v->evaluate(json_encode($this->parameters->getArrayCopy()))) {
             $report->addValidationError($this, 'interface-config', $v);
         }
         $providers = $this->getPlatform()->getDatabase('networks')->getAll();
         $request = $this->getRequest();
         $device = \Nethgui\array_head($request->getPath());
         if (!empty($providers[$this->parameters['ProviderName']]) && $providers[$this->parameters['ProviderName']]['interface'] != $device) {
             $report->addValidationError($this, 'interface-config', $v);
         }
     }
 }
Ejemplo n.º 26
0
 protected function renderContent()
 {
     $name = $this->getAttribute('name');
     $flags = $this->getAttribute('flags');
     $label = $this->getAttribute('label', $this->getTranslateClosure($name . '_label'));
     $content = '';
     $attributes = array();
     $cssClass = 'Button';
     if ($this->hasAttribute('receiver')) {
         $attributes['id'] = $this->view->getUniqueId($this->getAttribute('receiver'));
     } else {
         $attributes['id'] = FALSE;
     }
     if ($flags & (\Nethgui\Renderer\WidgetFactoryInterface::BUTTON_LINK | \Nethgui\Renderer\WidgetFactoryInterface::BUTTON_CANCEL | \Nethgui\Renderer\WidgetFactoryInterface::BUTTON_HELP)) {
         $value = $this->getAttribute('value', $this->getDefaultValue($name));
         if (empty($value)) {
             $value = '';
         } elseif (is_array($value)) {
             $label = $value[1];
             $value = $value[0];
         }
         if ($flags & \Nethgui\Renderer\WidgetFactoryInterface::BUTTON_CANCEL) {
             $cssClass .= ' cancel';
             $flags |= \Nethgui\Renderer\WidgetFactoryInterface::STATE_UNOBTRUSIVE;
         } elseif ($flags & \Nethgui\Renderer\WidgetFactoryInterface::BUTTON_HELP) {
             if ($value === '') {
                 $value = $this->view->getModuleUrl('/Help/Read/' . \Nethgui\array_head($this->view->getModulePath()) . '.html');
             }
             $cssClass .= ' Help';
         } else {
             $cssClass .= ' link ' . $this->getClientEventTarget();
         }
         if ($flags & \Nethgui\Renderer\WidgetFactoryInterface::STATE_DISABLED) {
             $cssClass .= ' disabled';
             $tag = 'span';
         } else {
             $attributes['href'] = $value;
             $tag = 'a';
         }
         $attributes['class'] = $cssClass;
         $attributes['title'] = $this->getAttribute('title', FALSE);
         $content .= $this->openTag($tag, $attributes);
         $content .= htmlspecialchars($label);
         $content .= $this->closeTag($tag);
     } else {
         if ($flags & \Nethgui\Renderer\WidgetFactoryInterface::BUTTON_SUBMIT) {
             $attributes['type'] = 'submit';
             $cssClass .= ' submit';
         } elseif ($flags & \Nethgui\Renderer\WidgetFactoryInterface::BUTTON_RESET) {
             $attributes['type'] = 'reset';
             $cssClass .= ' reset';
         } elseif ($flags & \Nethgui\Renderer\WidgetFactoryInterface::BUTTON_CUSTOM) {
             $attributes['type'] = 'button';
             $cssClass .= ' custom';
         } elseif ($flags & \Nethgui\Renderer\WidgetFactoryInterface::BUTTON_DROPDOWN) {
             $attributes['type'] = 'button';
             $attributes['name'] = FALSE;
             $cssClass .= ' dropdown';
             $childContent = $this->renderChildren();
         }
         $attributes['value'] = $label;
         $content .= $this->controlTag('button', $name, $flags, $this->getAttribute('class', $cssClass), $attributes);
         if (isset($childContent)) {
             $content .= $childContent;
         }
     }
     if ($this->canEscapeUnobstrusive($flags)) {
         return $this->escapeUnobstrusive($content);
     }
     return $content;
 }