Exemplo n.º 1
0
 public function prepareViewForColumnTime(\Nethgui\Controller\Table\Read $action, \Nethgui\View\ViewInterface $view, $key, $values, &$rowMetadata)
 {
     if (!isset($values['Time'])) {
         return $view->translate('always_label');
     }
     return $this->formatObject($view, $values['Time'], 'always_label');
 }
Exemplo n.º 2
0
 private function getGroupsViewValue(\Nethgui\View\ViewInterface $view)
 {
     static $groupsState;
     if (isset($groupsState)) {
         return $groupsState;
     }
     $groupsState = array();
     foreach (iterator_to_array($this->getAdapter()) as $id => $yumGroup) {
         if ($yumGroup['status'] === 'available') {
             continue;
             // skip installed groups
         }
         if (isset($this->parameters['groups'][$id])) {
             $groupsState[$id] = $this->parameters['groups'][$id];
         } else {
             $groupsState[$id]['opackages_selected'] = array();
         }
         $groupsState[$id]['id'] = $yumGroup['id'];
         $groupsState[$id]['name'] = $yumGroup['name'];
         $groupsState[$id]['description'] = $yumGroup['description'];
         $groupsState[$id]['Edit'] = array($view->getModuleUrl('../../EditModule/' . $id), $view->translate('Edit_label'));
         $groupsState[$id]['Remove'] = array($view->getModuleUrl('../../Review?removeGroup=' . $id), $view->translate('Remove_label'));
     }
     foreach ($this->getCategories($view) as $category) {
         foreach ($category['groups'] as $id) {
             if (isset($groupsState[$id])) {
                 $groupsState[$id]['categories'][] = $category['name'];
             }
         }
     }
     usort($groupsState, function ($a, $b) {
         return strcasecmp($a['name'], $b['name']);
     });
     return $groupsState;
 }
Exemplo n.º 3
0
 private function formatObject(\Nethgui\View\ViewInterface $view, $val, $default = 'any_label')
 {
     if (!$val) {
         return $view->translate($default);
     }
     $tmp = explode(';', $val);
     return $view->translate($tmp[0] . '_label') . ": " . $tmp[1];
 }
 public function prepareViewForColumnRecipients(\Nethgui\Controller\Table\Read $action, \Nethgui\View\ViewInterface $view, $key, $values, &$rowMetadata)
 {
     $recipients = $values['Recipients'];
     if (count($recipients) <= 3) {
         return implode(', ', $recipients);
     }
     return implode(', ', array_merge(array_slice($recipients, 0, 2), array($view->translate('AndXMore', array(count($recipients) - 2)))));
 }
 private function getMessageText(\Nethgui\View\ViewInterface $view)
 {
     if (in_array($this->parameters['role'], array('bridged', 'slave', 'pppoe'))) {
         $msgTemplate = sprintf("ReleasePhysicalInterface_%s_message", $this->parameters['role']);
     } else {
         $msgTemplate = "ReleasePhysicalInterface_roled_message";
     }
     return $view->translate($msgTemplate, \iterator_to_array($this->parameters));
 }
 public function prepareViewForColumnMailSpamRetentionTime(\Nethgui\Controller\Table\Read $action, \Nethgui\View\ViewInterface $view, $key, $values, &$rowMetadata)
 {
     if ($values['MailSpamRetentionStatus'] == 'enabled') {
         if ($values['MailSpamRetentionTime'] == 'infinite') {
             return $view->translate('ever');
         } else {
             return $view->translate('${0} days', array(substr($values['MailSpamRetentionTime'], 0, -1)));
         }
     }
     return '-';
 }
Exemplo n.º 7
0
 public static function getConfigForView(\Nethgui\View\ViewInterface $view, $record)
 {
     $tcpPorts = implode(', ', array_filter(array_merge(explode(',', $record['TCPPort']), explode(',', $record['TCPPorts']))));
     $udpPorts = implode(', ', array_filter(array_merge(explode(',', $record['UDPPort']), explode(',', $record['UDPPorts']))));
     $ports = array($view->translate(sprintf('ServiceStatus_%s_label', $record['status'] === 'enabled' ? 'enabled' : 'disabled')));
     if ($tcpPorts) {
         $ports[] = $view->translate('TCP_ports_label', array($tcpPorts));
     }
     if ($udpPorts) {
         $ports[] = $view->translate('UDP_ports_label', array($udpPorts));
     }
     return $ports;
 }
Exemplo n.º 8
0
 public function prepareView(\Nethgui\View\ViewInterface $view)
 {
     if (!$this->getRequest()->isValidated()) {
         $this->getAdapter()->setLoader(NULL);
     } else {
         $view->getCommandList()->show();
     }
     if ($this->getRequest()->hasParameter('installSuccess')) {
         $this->getAction('AdminTodo')->emitNotifications = TRUE;
         $this->notifications->message($view->translate('package_success'));
     }
     parent::prepareView($view);
 }
 public function prepareView(\Nethgui\View\ViewInterface $view)
 {
     $sz = array('10' => '10 MB', '20' => '20 MB', '50' => '50 MB', '100' => '100 MB', '200' => '200 MB', '500' => '500 MB', '1000' => '1 GB', $this->parameters['MessageSizeMax'] => sprintf('%s MB', $this->parameters['MessageSizeMax']));
     ksort($sz, SORT_NUMERIC);
     $view['MessageSizeMaxDatasource'] = \Nethgui\Renderer\AbstractRenderer::hashToDatasource($sz);
     $lt = array('1' => $view->translate('${0} day', array(1)), '2' => $view->translate('${0} days', array(2)), '4' => $view->translate('${0} days', array(4)), '7' => $view->translate('${0} days', array(7)), '15' => $view->translate('${0} days', array(15)), '30' => $view->translate('${0} days', array(30)), $this->parameters['MessageQueueLifetime'] => $view->translate('${0} days', array($this->parameters['MessageQueueLifetime'])));
     ksort($lt, SORT_NUMERIC);
     $view['MessageQueueLifetimeDatasource'] = \Nethgui\Renderer\AbstractRenderer::hashToDatasource($lt);
     parent::prepareView($view);
 }
Exemplo n.º 10
0
 public function prepareView(\Nethgui\View\ViewInterface $view)
 {
     $module = $this->getTargetModule();
     if (is_null($module)) {
         $view->setTemplate(FALSE);
         return;
     }
     $moduleView = $view->spawnView($module);
     $module->prepareView($moduleView);
     $renderer = new \Nethgui\Module\Help\Renderer($moduleView, $this->getFileNameResolver(), 0);
     echo $renderer->render();
     exit(0);
     // FIXME not so correct, but works..
 }
 private function getActionsText(\Nethgui\View\ViewInterface $view)
 {
     $data = $this->parameters->getArrayCopy();
     if ($data['type'] == 'bridge') {
         $data['parts'] = str_replace(',', ', ', $data['bridge']);
     } elseif ($data['type'] == 'bond') {
         $data['parts'] = str_replace(',', ', ', $data['bond']);
         $data['bondMode'] = $view->translate("BondMode_{$data['bondMode']}_label");
     } elseif ($data['type'] == 'vlan') {
         $data['parts'] = $data['vlan'];
     } else {
         $data['parts'] = '';
     }
     $actions = array();
     $actions[] = $view->translate("Action_create_{$data['type']}", $data);
     if ($data['bootproto'] === 'dhcp') {
         $actions[] = $view->translate('Action_use_dhcp', $data);
     } elseif ($data['bootproto'] === 'none') {
         $actions[] = $view->translate('Action_set_static_ip', $data);
         if ($data['gateway']) {
             $actions[] = $view->translate('Action_use_gateway', $data);
         } else {
             $actions[] = $view->translate('Action_use_no_gateway', $data);
         }
     }
     $actions[] = $view->translate("Action_create_role", $data);
     return $actions;
 }
Exemplo n.º 12
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'));
     }
 }
Exemplo n.º 13
0
 public function getRoleText(\Nethgui\View\ViewInterface $view, $key, $values = NULL)
 {
     if (is_null($values)) {
         $values = $this->getAdapter()->offsetGet($key);
     }
     if (!isset($values['role']) || !$values['role']) {
         return '';
     }
     $roleLabel = $view->translate($values['role'] . "_label");
     if ($values['role'] === 'slave') {
         return $roleLabel . " (" . $values['master'] . ")";
     } elseif ($values['role'] === 'bridged') {
         return $roleLabel . " (" . $values['bridge'] . ")";
     }
     return $roleLabel;
 }
Exemplo n.º 14
0
 private function getAccounts(\Nethgui\View\ViewInterface $view)
 {
     static $ds;
     if (isset($ds)) {
         return $ds;
     }
     $data = json_decode($this->getPlatform()->exec("/usr/bin/sudo /usr/libexec/nethserver/read-mail-accounts")->getOutput(), TRUE);
     $users = \Nethgui\Widget\XhtmlWidget::hashToDatasource($data['users'], TRUE);
     $groups = \Nethgui\Widget\XhtmlWidget::hashToDatasource($data['groups'], TRUE);
     $ds = array();
     if ($users) {
         $ds[] = array($users, $view->translate('Users_label'));
     }
     if ($groups) {
         $ds[] = array($groups, $view->translate('Groups_label'));
     }
     return $ds;
 }
Exemplo n.º 15
0
 /**
  * For each known format extension adds a subview that renders into an html
  * fragment that include the required resources.
  * 
  * @param \Nethgui\View\ViewInterface $view
  * @return void
  */
 public function prepareViewXhtml(\Nethgui\View\ViewInterface $view)
 {
     $fragments = array('js' => "<script src='%URI'></script>", 'css' => "<link rel='stylesheet' type='text/css' href='%URI' />");
     foreach (array_keys($fragments) as $ext) {
         $view[$ext] = $view->spawnView($this);
         $thisModule = $this;
         $templateClosure = function (\Nethgui\Renderer\AbstractRenderer $renderer) use($ext, $thisModule, $fragments) {
             $uriList = $thisModule->getUseList($ext);
             $cachedFile = $thisModule->getFileName($ext);
             if ($cachedFile !== FALSE) {
                 $uriList[] = $renderer->getModuleUrl('/Resource/' . $cachedFile);
             }
             $output = '';
             foreach ($uriList as $uri) {
                 $output .= strtr($fragments[$ext], array('%URI' => $uri));
             }
             return $output;
         };
         $view[$ext]->setTemplate($templateClosure);
     }
     $view->setTemplate(FALSE);
 }
Exemplo n.º 16
0
 private function getNicInfo(\Nethgui\View\ViewInterface $view)
 {
     $v = array();
     $nicInfo = array();
     if ($this->getAdapter()->offsetGet('type') === 'ethernet') {
         // Array of informations about NIC.
         // Fields: name, hwaddr, bus, model, driver, speed, link
         // Eg: green,08:00:27:77:fd:be,pci,Intel Corporation 82540EM Gigabit Ethernet Controller (rev 02),e1000,1000,1
         $nicInfo = str_getcsv($this->getPlatform()->exec('/usr/bin/sudo -n /usr/libexec/nethserver/nic-info ${1}', array($this->parameters['device']))->getOutput());
     }
     $v['dev'] = isset($this->parameters['device']) ? $this->parameters['device'] : '';
     $v['mac'] = \strtolower(isset($nicInfo[1]) ? $nicInfo[1] : '');
     $v['bus'] = \strtolower(isset($nicInfo[2]) ? $nicInfo[2] : "");
     $v['model'] = isset($nicInfo[3]) ? $nicInfo[3] : "";
     $v['driver'] = isset($nicInfo[4]) ? $nicInfo[4] : "";
     $v['speed'] = isset($nicInfo[5]) && $nicInfo[5] ? $nicInfo[5] : "0";
     if (!isset($nicInfo[6]) || intval($nicInfo[6]) < 0) {
         $v['link'] = $view->translate('Link_status_na');
     } else {
         $v['link'] = $nicInfo[6] ? $view->translate('Link_status_up') : $view->translate('Link_status_down');
     }
     return $v;
 }
Exemplo n.º 17
0
 /**
  *
  * @param \Nethgui\Controller\Table\Read $action
  * @param \Nethgui\View\ViewInterface $view
  * @param string $key The data row key
  * @param array $values The data row values
  * @return string|\Nethgui\View\ViewInterface
  */
 public function prepareViewForColumnPorts(\Nethgui\Controller\Table\Read $action, \Nethgui\View\ViewInterface $view, $key, $values, &$rowMetadata)
 {
     $ret = " ";
     $tcp = isset($values['TCPPort']) ? $values['TCPPort'] : "";
     if ($tcp == "" && isset($values['TCPPorts'])) {
         $tcp = $values['TCPPorts'];
     }
     $udp = isset($values['UDPPort']) ? $values['UDPPort'] : "";
     if ($udp == "" && isset($values['UDPPorts'])) {
         $udp = $values['UDPPorts'];
     }
     if ($tcp !== "") {
         $ret .= $view->translate("TCPPorts_label") . ": {$tcp} ";
     }
     if ($udp !== "") {
         $ret .= " " . $view->translate("UDPPorts_label") . ": {$udp} ";
     }
     return $ret;
 }
Exemplo n.º 18
0
 public function getLog()
 {
     return $this->view->getLog();
 }
Exemplo n.º 19
0
 private function getCategoriesViewValue(\Nethgui\View\ViewInterface $view)
 {
     $groups = array();
     $categories = $this->getParent()->getYumCategories();
     if (count($categories) === 0) {
         return array();
     }
     foreach ($this->getAdapter() as $group) {
         $groups[] = $group['id'];
     }
     $everything = array('id' => 'everything', 'name' => $view->translate('Everything_category_label'), 'description' => $view->translate('Everything_category_description'), 'display_order' => 0, 'groups' => array_unique($groups), 'selected' => TRUE);
     return array_merge(array($everything), $categories);
 }
Exemplo n.º 20
0
 public function prepareView(\Nethgui\View\ViewInterface $view)
 {
     if (!$this->getRequest()->isValidated()) {
         $this->getAdapter()->setLoader(NULL);
     } else {
         $view->getCommandList()->show();
     }
     if ($this->getRequest()->hasParameter('installSuccess')) {
         $this->getAction('AdminTodo')->emitNotifications = TRUE;
         $this->notifications->yumSuccess(array('message' => $view->translate('YumSuccess_message'), 'description' => $view->translate('YumSuccess_description'), 'buttonLabel' => $view->translate('YumSuccess_button_label'), 'action' => $view->getModuleUrl('..')));
     } elseif ($this->getRequest()->hasParameter('installFailure')) {
         $taskStatus = $this->systemTasks->getTaskStatus($this->getRequest()->getParameter('taskId'));
         if (isset($taskStatus['children'][0]['message'])) {
             $message = $taskStatus['children'][0]['message'];
         } else {
             $message = $view->translate('An unknown installation error has occurred');
         }
         $this->notifications->yumError(array('message' => $message, 'description' => $view->translate('ClearYumCache_description'), 'buttonLabel' => $view->translate('ClearYumCache_label'), 'action' => $view->getModuleUrl('../ClearYumCache')));
     }
     parent::prepareView($view);
     if (isset($this->yumError)) {
         $this->notifications->yumError(array('message' => $this->yumError, 'description' => $view->translate('ClearYumCache_description'), 'buttonLabel' => $view->translate('ClearYumCache_label'), 'action' => $view->getModuleUrl('../ClearYumCache')));
     }
 }
Exemplo n.º 21
0
 /**
  * XXX: experimental -> CSS injection 
  **/
 public function prepareView(\Nethgui\View\ViewInterface $view)
 {
     $cssCode = "\n           tr.running td:nth-child(3) { color: green }\n           tr.stopped td:nth-child(3) { color: red }\n       ";
     $view->getCommandList('/Resource/css')->appendCode($cssCode, 'css');
     $moduleUrl = json_encode($view->getModuleUrl("/Dashboard/Services"));
     $jsCode = "\n(function ( \$ ) {\n    \$(document).ready(function() {\n        \$.Nethgui.Server.ajaxMessage({\n            isMutation: false,\n            url: {$moduleUrl}\n        });\n    });\n} ( jQuery ));\n       ";
     $view->getCommandList('/Resource/js')->appendCode($jsCode, 'js');
     parent::prepareView($view);
 }
Exemplo n.º 22
0
 public function hasCommandList($selector = '')
 {
     return $this->view->hasCommandList($selector);
 }
Exemplo n.º 23
0
 public function getSteps(\Nethgui\View\ViewInterface $view, $currentModuleIdentifier)
 {
     $steps = array();
     foreach ($this->getStepList() as $child) {
         $steps[] = array('target' => $view->getUniqueId($child->getIdentifier()), 'title' => $view->getTranslator()->translate($child, $child->getAttributesProvider()->getTitle()), 'description' => $view->getTranslator()->translate($child, $child->getAttributesProvider()->getDescription()), 'current?' => $child->getIdentifier() === $currentModuleIdentifier);
     }
     return $steps;
 }
 private function readDomainAddressDatasource(\Nethgui\View\ViewInterface $view)
 {
     $domains = array(array('', $view->translate('ANY_DOMAIN')));
     foreach ($this->getPlatform()->getDatabase('domains')->getAll('domain') as $key => $prop) {
         $domains[] = array($key, $key);
     }
     return $domains;
 }
Exemplo n.º 25
0
 public function prepareViewForColumnNoKeep(\Nethgui\Controller\Table\Read $action, \Nethgui\View\ViewInterface $view, $key, $values, &$rowMetadata)
 {
     return $view->translate($values['nokeep'] . "_label");
 }
 public function prepareView(\Nethgui\View\ViewInterface $view)
 {
     if ($this->getRequest()->isMutation()) {
         $this->getPlatform()->setDetachedProcessCondition('success', array('location' => array('url' => $view->getModuleUrl('Modules?installSuccess'), 'freeze' => TRUE)));
         $this->getPlatform()->setDetachedProcessCondition('failure', array('location' => array('url' => $view->getModuleUrl('Modules?installFailure&taskId={taskId}'), 'freeze' => TRUE)));
     }
     parent::prepareView($view);
 }
Exemplo n.º 27
0
 public function prepareView(\Nethgui\View\ViewInterface $view)
 {
     $view['download'] = $view->translate("see_log_label");
 }
Exemplo n.º 28
0
 public function prepareView(\Nethgui\View\ViewInterface $view)
 {
     if ($view->getTargetFormat() === $view::TARGET_JSON) {
         if ($this->getRequest()->isEmpty()) {
             return;
         }
         $view['tags'] = $this->searchTags($view, $this->parameters['search']);
         return;
     }
     parent::prepareView($view);
     $view->setTemplate(array($this, 'renderModuleMenu'));
     $categories = array();
     $translator = $view->getTranslator();
     if (defined('NETHGUI_MENU_CATEGORIES')) {
         $categoryOrder = array_flip(array_map('trim', explode(',', NETHGUI_MENU_CATEGORIES)));
     } else {
         $categoryOrder = array();
     }
     foreach ($this->moduleSet as $moduleIdentifier => $moduleInstance) {
         if (!$moduleInstance instanceof \Nethgui\Module\ModuleInterface) {
             continue;
         }
         $attributes = $moduleInstance->getAttributesProvider();
         $category = $attributes->getCategory();
         $title = $translator->translate($moduleInstance, $attributes->getTitle());
         $tags = $translator->translate($moduleInstance, $attributes->getTags());
         $description = $translator->translate($moduleInstance, $attributes->getDescription());
         $href = $view->spawnView($moduleInstance)->getModuleUrl();
         $position = $attributes->getMenuPosition();
         // skip elements without any category
         if (is_null($category)) {
             continue;
         }
         // initialize category:
         if (!isset($categories[$category])) {
             $categories[$category] = array('key' => $category, 'title' => $translator->translate($moduleInstance, $category), 'items' => array());
         }
         // add item to category
         if (!isset($categories[$category]['items'][$moduleIdentifier])) {
             $categories[$category]['items'][$moduleIdentifier] = array('identifier' => $moduleIdentifier, 'title' => $title, 'description' => $description, 'href' => $href, 'tags' => $tags, 'position' => $position);
         }
     }
     foreach ($categories as &$category) {
         usort($category['items'], array($this, 'sortItems'));
     }
     usort($categories, function ($c, $d) use($categoryOrder) {
         if (isset($categoryOrder[$c['key']], $categoryOrder[$d['key']])) {
             return $categoryOrder[$c['key']] - $categoryOrder[$d['key']];
         }
         return strcmp($c['title'], $d['title']);
     });
     $view['categories'] = $categories;
 }
Exemplo n.º 29
0
 /**
  *
  * @param \Nethgui\View\ViewInterface $view
  * @param string $key The data row key
  * @param array $values The data row values
  * @param array &$rowMetadata The metadadata row values, like css classes
  * @return \Nethgui\View\ViewInterface 
  */
 public function prepareViewForColumnActions(\Nethgui\View\ViewInterface $view, $key, $values, &$rowMetadata)
 {
     $cellView = $view->spawnView($this->getParent());
     $cellView->setTemplate(array($this, 'renderColumnActions'));
     foreach ($this->getParent()->getRowActions() as $action) {
         $actionId = $action->getIdentifier();
         $actionInfo = array();
         $actionInfo[] = $cellView->translate($actionId . '_label');
         $actionInfo[] = $cellView->getModuleUrl(sprintf('%s/%s', $action->getIdentifier(), $key));
         $cellView[$actionId] = $actionInfo;
     }
     return $cellView;
 }
Exemplo n.º 30
0
 public function prepareView(\Nethgui\View\ViewInterface $view)
 {
     $template = $this->getViewTemplate();
     if (!is_null($template)) {
         $view->setTemplate($template);
     }
 }