/**
  * Display the form for removing a comment list
  */
 public function deleteAllAction()
 {
     $this->assertPermission('monitoring/command/comment/delete');
     $listCommentsLink = Url::fromPath('monitoring/list/comments')->setQueryString('comment_type=(comment|ack)');
     $delCommentForm = new DeleteCommentsCommandForm();
     $delCommentForm->setTitle($this->view->translate('Remove all Comments'));
     $delCommentForm->addDescription(sprintf($this->translate('Confirm removal of %d comments.'), $this->comments->count()));
     $delCommentForm->setComments($this->comments->fetchAll())->setRedirectUrl($listCommentsLink)->handleRequest();
     $this->view->delCommentForm = $delCommentForm;
     $this->view->comments = $this->comments;
     $this->view->listAllLink = Url::fromPath('monitoring/list/comments')->setQueryString($this->filter->toQueryString());
 }
 /**
  * Display the form for removing a downtime list
  */
 public function deleteAllAction()
 {
     $this->assertPermission('monitoring/command/downtime/delete');
     $this->view->downtimes = $this->downtimes;
     $this->view->listAllLink = Url::fromPath('monitoring/list/downtimes')->setQueryString($this->filter->toQueryString());
     $delDowntimeForm = new DeleteDowntimesCommandForm();
     $delDowntimeForm->setTitle($this->view->translate('Remove all Downtimes'));
     $delDowntimeForm->addDescription(sprintf($this->translate('Confirm removal of %d downtimes.'), $this->downtimes->count()));
     $delDowntimeForm->setRedirectUrl(Url::fromPath('monitoring/list/downtimes'));
     $delDowntimeForm->setDowntimes($this->downtimes->fetchAll())->handleRequest();
     $this->view->delAllDowntimeForm = $delDowntimeForm;
 }
 public function filterAction()
 {
     $flat = array();
     $filter = Filter::fromQueryString('vars.bpconfig=*');
     Benchmark::measure('ready');
     $objs = IcingaHost::loadAll($this->db());
     Benchmark::measure('db done');
     foreach ($objs as $host) {
         $flat[$host->id] = (object) array();
         foreach ($host->getProperties() as $k => $v) {
             $flat[$host->id]->{$k} = $v;
         }
     }
     Benchmark::measure('objects ready');
     $vars = IcingaHostVar::loadAll($this->db());
     Benchmark::measure('vars loaded');
     foreach ($vars as $var) {
         if (!array_key_exists($var->host_id, $flat)) {
             continue;
         }
         // Templates?
         $flat[$var->host_id]->{'vars.' . $var->varname} = $var->varvalue;
     }
     Benchmark::measure('vars done');
     foreach ($flat as $host) {
         if ($filter->matches($host)) {
             echo $host->object_name . "\n";
         }
     }
     return;
     Benchmark::measure('all done');
 }
Example #4
0
 protected function filter()
 {
     if ($this->filter === null) {
         $this->filter = Filter::fromQueryString($this->filter_expression);
     }
     return $this->filter;
 }
 public function showAction()
 {
     $this->setAutorefreshInterval(15);
     $checkNowForm = new CheckNowCommandForm();
     $checkNowForm->setObjects($this->serviceList)->handleRequest();
     $this->view->checkNowForm = $checkNowForm;
     $this->serviceList->setColumns(array('host_display_name', 'host_handled', 'host_name', 'host_problem', 'host_state', 'service_acknowledged', 'service_active_checks_enabled', 'service_description', 'service_display_name', 'service_handled', 'service_in_downtime', 'service_is_flapping', 'service_last_state_change', 'service_notifications_enabled', 'service_passive_checks_enabled', 'service_problem', 'service_state'));
     $acknowledgedObjects = $this->serviceList->getAcknowledgedObjects();
     if (!empty($acknowledgedObjects)) {
         $removeAckForm = new RemoveAcknowledgementCommandForm();
         $removeAckForm->setObjects($acknowledgedObjects)->handleRequest();
         $this->view->removeAckForm = $removeAckForm;
     }
     $this->setAutorefreshInterval(15);
     $this->view->rescheduleAllLink = Url::fromRequest()->setPath('monitoring/services/reschedule-check');
     $this->view->downtimeAllLink = Url::fromRequest()->setPath('monitoring/services/schedule-downtime');
     $this->view->processCheckResultAllLink = Url::fromRequest()->setPath('monitoring/services/process-check-result');
     $this->view->addCommentLink = Url::fromRequest()->setPath('monitoring/services/add-comment');
     $this->view->deleteCommentLink = Url::fromRequest()->setPath('monitoring/services/delete-comment');
     $this->view->stats = $this->serviceList->getServiceStateSummary();
     $this->view->objects = $this->serviceList;
     $this->view->unhandledObjects = $this->serviceList->getUnhandledObjects();
     $this->view->problemObjects = $this->serviceList->getProblemObjects();
     $this->view->downtimeUnhandledLink = Url::fromPath('monitoring/services/schedule-downtime')->setQueryString($this->serviceList->getUnhandledObjects()->objectsFilter()->toQueryString());
     $this->view->downtimeLink = Url::fromPath('monitoring/services/schedule-downtime')->setQueryString($this->serviceList->getProblemObjects()->objectsFilter()->toQueryString());
     $this->view->acknowledgedObjects = $acknowledgedObjects;
     $this->view->acknowledgeLink = Url::fromPath('monitoring/services/acknowledge-problem')->setQueryString($this->serviceList->getUnacknowledgedObjects()->objectsFilter()->toQueryString());
     $this->view->unacknowledgedObjects = $this->serviceList->getUnacknowledgedObjects();
     $this->view->objectsInDowntime = $this->serviceList->getObjectsInDowntime();
     $this->view->inDowntimeLink = Url::fromPath('monitoring/list/services')->setQueryString($this->serviceList->getObjectsInDowntime()->objectsFilter(array('host' => 'host_name', 'service' => 'service_description'))->toQueryString());
     $this->view->showDowntimesLink = Url::fromPath('monitoring/downtimes/show')->setQueryString($this->serviceList->getObjectsInDowntime()->objectsFilter()->andFilter(Filter::where('object_type', 'service'))->toQueryString());
     $this->view->commentsLink = Url::fromRequest()->setPath('monitoring/list/comments');
     $this->view->sendCustomNotificationLink = Url::fromRequest()->setPath('monitoring/services/send-custom-notification');
 }
Example #6
0
 /**
  * {@inheritdoc}
  */
 public function render()
 {
     $repo = new AnnouncementIniRepository();
     $etag = $repo->getEtag();
     $cookie = new AnnouncementCookie();
     if ($cookie->getEtag() !== $etag) {
         $cookie->setEtag($etag);
         $cookie->setNextActive($repo->findNextActive());
         Icinga::app()->getResponse()->setCookie($cookie);
     }
     $acked = array();
     foreach ($cookie->getAcknowledged() as $hash) {
         $acked[] = Filter::expression('hash', '!=', $hash);
     }
     $acked = Filter::matchAll($acked);
     $announcements = $repo->findActive();
     $announcements->applyFilter($acked);
     if ($announcements->hasResult()) {
         $html = '<ul role="alert" id="announcements">';
         foreach ($announcements as $announcement) {
             $ackForm = new AcknowledgeAnnouncementForm();
             $ackForm->populate(array('hash' => $announcement->hash));
             $html .= '<li><div>' . $this->view()->escape($announcement->message) . '</div>' . $ackForm . '</li>';
         }
         $html .= '</ul>';
         return $html;
     }
     // Force container update on XHR
     return '<div style="display: none;"></div>';
 }
Example #7
0
 /**
  * Get the filter from URL parameters or exit immediately if the filter is empty
  *
  * @return Filter
  */
 protected function getFilterOrExitIfEmpty()
 {
     $filter = Filter::fromQueryString((string) $this->params);
     if ($filter->isEmpty()) {
         $this->getResponse()->json()->setFailData(array('filter' => 'Filter is required and must not be empty'))->sendResponse();
     }
     return $filter;
 }
 public function testAction()
 {
     $pdb = new PuppetDbApi('v4', 'pe2015.example.com');
     // $filter = Filter::fromQueryString('type=Nagios_host&exported=true');
     // echo FilterRenderer::forFilter($filter)->toJson();
     $facts = $pdb->fetchFacts(Filter::fromQueryString('name=kernel|name=osfamily|name=partitions'));
     // certname=pe2015.example.com
 }
Example #9
0
 /**
  * Returns a Filter that matches all hosts in this list
  *
  * @return Filter
  */
 public function objectsFilter($columns = array('host' => 'host'))
 {
     $filterExpression = array();
     foreach ($this as $host) {
         $filterExpression[] = Filter::where($columns['host'], $host->getName());
     }
     return FilterOr::matchAny($filterExpression);
 }
Example #10
0
 public function init()
 {
     $serviceList = new ServiceList($this->backend);
     $this->applyRestriction('monitoring/filter/objects', $serviceList);
     $serviceList->addFilter(Filter::fromQueryString((string) $this->params->without(array('service_problem', 'service_handled', 'view'))));
     $this->serviceList = $serviceList;
     $this->view->listAllLink = Url::fromRequest()->setPath('monitoring/list/services');
     $this->getTabs()->add('show', array('title' => sprintf($this->translate('Show summarized information for %u services'), count($this->serviceList)), 'label' => $this->translate('Services') . sprintf(' (%d)', count($this->serviceList)), 'url' => Url::fromRequest(), 'icon' => 'services'))->extend(new DashboardAction())->activate('show');
 }
 /**
  * Apply a restriction on the given data view
  *
  * @param   string      $restriction    The name of restriction
  * @param   Filterable  $filterable     The filterable to restrict
  *
  * @return  Filterable  The filterable
  */
 protected static function applyRestriction($restriction, Filterable $filterable)
 {
     $restrictions = Filter::matchAny();
     foreach (Manager::getInstance()->getRestrictions($restriction) as $filter) {
         $restrictions->addFilter(Filter::fromQueryString($filter));
     }
     $filterable->applyFilter($restrictions);
     return $filterable;
 }
Example #12
0
 public function init()
 {
     $hostList = new HostList($this->backend);
     $hostList->setFilter(Filter::fromQueryString((string) $this->params));
     $this->applyRestriction('monitoring/filter/objects', $hostList);
     $this->hostList = $hostList;
     $this->getTabs()->add('show', array('title' => sprintf($this->translate('Show summarized information for %u hosts'), count($this->hostList)), 'label' => $this->translate('Hosts') . sprintf(' (%d)', count($this->hostList)), 'url' => Url::fromRequest(), 'icon' => 'host'))->extend(new DashboardAction())->activate('show');
     $this->view->listAllLink = Url::fromRequest()->setPath('monitoring/list/hosts');
 }
 protected function filterChainToArray(Filter $filter)
 {
     if ($filter instanceof FilterAnd) {
         $op = 'and';
     } elseif ($filter instanceof FilterOr) {
         $op = 'or';
     } elseif ($filter instanceof FilterNot) {
         $op = 'not';
     } else {
         throw new QueryException('Cannot render filter: %s', $filter);
     }
     $parts = array($op);
     if (!$filter->isEmpty()) {
         foreach ($filter->filters() as $f) {
             $parts[] = $this->filterToArray($f);
         }
     }
     return $parts;
 }
Example #14
0
 public function init()
 {
     $hostList = new HostList($this->backend);
     $this->applyRestriction('monitoring/filter/objects', $hostList);
     $hostList->addFilter(Filter::fromQueryString((string) $this->params));
     $this->hostList = $hostList;
     $this->hostList->setColumns(array('host_acknowledged', 'host_active_checks_enabled', 'host_display_name', 'host_event_handler_enabled', 'host_flap_detection_enabled', 'host_handled', 'host_in_downtime', 'host_is_flapping', 'host_last_state_change', 'host_name', 'host_notifications_enabled', 'host_obsessing', 'host_passive_checks_enabled', 'host_problem', 'host_state', 'instance_name'));
     $this->view->baseFilter = $this->hostList->getFilter();
     $this->getTabs()->add('show', array('label' => $this->translate('Hosts') . sprintf(' (%d)', count($this->hostList)), 'title' => sprintf($this->translate('Show summarized information for %u hosts'), count($this->hostList)), 'url' => Url::fromRequest()))->extend(new DashboardAction())->extend(new MenuAction())->activate('show');
     $this->view->listAllLink = Url::fromRequest()->setPath('monitoring/list/hosts');
 }
Example #15
0
 /**
  * Fetch all comments matching the current filter and add tabs
  *
  * @throws Zend_Controller_Action_Exception
  */
 public function init()
 {
     $this->filter = Filter::fromQueryString(str_replace('comment_id', 'comment_internal_id', (string) $this->params));
     $query = $this->backend->select()->from('comment', array('id' => 'comment_internal_id', 'objecttype' => 'object_type', 'comment' => 'comment_data', 'author' => 'comment_author_name', 'timestamp' => 'comment_timestamp', 'type' => 'comment_type', 'persistent' => 'comment_is_persistent', 'expiration' => 'comment_expiration', 'host_name', 'service_description', 'host_display_name', 'service_display_name'))->addFilter($this->filter);
     $this->applyRestriction('monitoring/filter/objects', $query);
     $this->comments = $query->getQuery()->fetchAll();
     if (false === $this->comments) {
         throw new Zend_Controller_Action_Exception($this->translate('Comment not found'));
     }
     $this->getTabs()->add('comments', array('title' => $this->translate('Display detailed information about multiple comments.'), 'icon' => 'comment', 'label' => $this->translate('Comments') . sprintf(' (%d)', count($this->comments)), 'url' => 'monitoring/comments/show'))->activate('comments');
 }
 public function argumentsAction()
 {
     $this->getTabs()->activate('arguments');
     $this->view->title = $this->translate('Command arguments');
     $this->view->table = $this->loadTable('icingaCommandArgument')->setCommandObject($this->object)->setFilter(Filter::where('command', $this->params->get('name')));
     $form = $this->view->form = $this->loadForm('icingaCommandArgument')->setCommandObject($this->object);
     if ($id = $this->params->shift('argument_id')) {
         $form->loadObject($id);
     }
     $form->handleRequest();
 }
Example #17
0
 public function render()
 {
     $url = Url::fromRequest();
     $view = $this->view();
     $html = ' <form method="post" class="inline" action="' . $url . '"><input type="text" name="q" style="width: 8em" class="search" value="" placeholder="' . t('Add filter...') . '" /></form>';
     // $html .= $this->renderFilter($this->filter);
     $editorUrl = clone $url;
     $editorUrl->setParam('modifyFilter', true);
     if ($this->filter->isEmpty()) {
         $title = t('Filter this list');
         $txt = $view->icon('plus');
         $remove = '';
     } else {
         $txt = t('Filtered');
         $title = t('Modify this filter');
         $remove = ' <a href="' . Url::fromRequest()->setParams(array()) . '" title="' . t('Remove this filter') . '">' . $view->icon('cancel') . '</a>';
     }
     $filter = $this->filter->isEmpty() ? '' : ': ' . $this->filter;
     $html .= ($filter ? '<p>' : ' ') . '<a href="' . $editorUrl . '" title="' . $title . '">' . $txt . '</a>' . $this->shorten($filter, 72) . $remove . ($filter ? '</p>' : '');
     return $html;
 }
 public function renderSearch()
 {
     $html = ' <form method="post" class="search inline dontprint" action="' . $this->preservedUrl() . '"><input type="text" name="q" style="width: 8em" class="search" value="" placeholder="' . t('Search...') . '" /></form>';
     if ($this->filter->isEmpty()) {
         $title = t('Filter this list');
     } else {
         $title = t('Modify this filter');
         if (!$this->filter->isEmpty()) {
             $title .= ': ' . $this->filter;
         }
     }
     return $html . '<a href="' . $this->preservedUrl()->with('modifyFilter', true) . '" aria-label="' . $title . '" title="' . $title . '">' . '<i aria-hidden="true" class="icon-filter"></i>' . '</a>';
 }
Example #19
0
 /**
  * Create and add elements to this form
  *
  * @param   array   $formData   The data sent by the user
  */
 public function createElements(array $formData)
 {
     // TODO(jom): Fetching already existing members to prevent the user from mistakenly creating duplicate
     // memberships (no matter whether the data source permits it or not, a member does never need to be
     // added more than once) should be kept at backend level (GroupController::fetchUsers) but this does
     // not work currently as our ldap protocol stuff is unable to handle our filter implementation..
     $members = $this->backend->select()->from('group_membership', array('user_name'))->where('group_name', $this->groupName)->fetchColumn();
     $filter = empty($members) ? Filter::matchAll() : Filter::not(Filter::where('user_name', $members));
     $users = $this->ds->select()->from('user', array('user_name'))->applyFilter($filter)->fetchColumn();
     if (!empty($users)) {
         $this->addElement('multiselect', 'user_name', array('multiOptions' => array_combine($users, $users), 'label' => $this->translate('Backend Users'), 'description' => $this->translate('Select one or more users (fetched from your user backends) to add as group member'), 'class' => 'grant-permissions'));
     }
     $this->addElement('textarea', 'users', array('required' => empty($users), 'label' => $this->translate('Users'), 'description' => $this->translate('Provide one or more usernames separated by comma to add as group member')));
     $this->setTitle(sprintf($this->translate('Add members for group %s'), $this->groupName));
     $this->setSubmitLabel($this->translate('Add'));
 }
Example #20
0
 /**
  * Apply a restriction on the given data view
  *
  * @param   string      $restriction    The name of restriction
  * @param   Filterable  $view           The filterable to restrict
  *
  * @return  Filterable  The filterable
  */
 protected function applyRestriction($restriction, Filterable $view)
 {
     $restrictions = Filter::matchAny();
     $restrictions->setAllowedFilterColumns(array('host_name', 'hostgroup_name', 'service_description', 'servicegroup_name', function ($c) {
         return preg_match('/^_(?:host|service)_/', $c);
     }));
     foreach ($this->getRestrictions($restriction) as $filter) {
         try {
             $restrictions->addFilter(Filter::fromQueryString($filter));
         } catch (QueryException $e) {
             throw new ConfigurationError($this->translate('Cannot apply restriction %s using the filter %s. You can only use the following columns: %s'), $restriction, $filter, implode(', ', array('host_name', 'hostgroup_name', 'service_description', 'servicegroup_name', '_(host|service)_<customvar-name>')), $e);
         }
     }
     $view->applyFilter($restrictions);
     return $view;
 }
Example #21
0
 /**
  * Return the corresponding filter-object
  *
  * @returns Filter
  */
 public function getFilter()
 {
     $baseFilter = Filter::matchAny(Filter::expression('type', '=', 'hard_state'));
     if ($this->getValue('objecttype', 'hosts') === 'hosts') {
         $objectTypeFilter = Filter::expression('object_type', '=', 'host');
     } else {
         $objectTypeFilter = Filter::expression('object_type', '=', 'service');
     }
     $states = array('cnt_down_hard' => Filter::expression('state', '=', '1'), 'cnt_unreachable_hard' => Filter::expression('state', '=', '2'), 'cnt_up' => Filter::expression('state', '=', '0'), 'cnt_critical_hard' => Filter::expression('state', '=', '2'), 'cnt_warning_hard' => Filter::expression('state', '=', '1'), 'cnt_unknown_hard' => Filter::expression('state', '=', '3'), 'cnt_ok' => Filter::expression('state', '=', '0'));
     $state = $this->getValue('state', 'cnt_critical_hard');
     $stateFilter = $states[$state];
     if (in_array($state, array('cnt_ok', 'cnt_up'))) {
         return Filter::matchAll($objectTypeFilter, $stateFilter);
     }
     return Filter::matchAll($baseFilter, $objectTypeFilter, $stateFilter);
 }
 /**
  * {@inheritdoc}
  */
 public function onSuccess()
 {
     $cookie = new AnnouncementCookie();
     $repo = new AnnouncementIniRepository();
     $query = $repo->findActive();
     $filter = array();
     foreach ($cookie->getAcknowledged() as $hash) {
         $filter[] = Filter::expression('hash', '=', $hash);
     }
     $query->addFilter(Filter::matchAny($filter));
     $acknowledged = array();
     foreach ($query as $row) {
         $acknowledged[] = $row->hash;
     }
     $acknowledged[] = $this->getElement('hash')->getValue();
     $cookie->setAcknowledged($acknowledged);
     $this->getResponse()->setCookie($cookie);
     return true;
 }
Example #23
0
 /**
  * {@inheritdoc}
  */
 public function isValid($formData)
 {
     if (!parent::isValid($formData)) {
         return false;
     }
     if (($filterString = $this->getValue('filter')) !== null) {
         $filter = Filter::matchAll();
         $filter->setAllowedFilterColumns(array('host_name', 'hostgroup_name', 'instance_name', 'service_description', 'servicegroup_name', 'contact_name', 'contactgroup_name', function ($c) {
             return preg_match('/^_(?:host|service)_/', $c);
         }));
         try {
             $filter->addFilter(Filter::fromQueryString($filterString));
         } catch (QueryException $_) {
             $this->getElement('filter')->addError(sprintf($this->translate('Invalid filter provided. You can only use the following columns: %s'), implode(', ', array('instance_name', 'host_name', 'hostgroup_name', 'service_description', 'servicegroup_name', 'contact_name', 'contactgroup_name', '_(host|service)_<customvar-name>'))));
             return false;
         }
     }
     return true;
 }
Example #24
0
 public function showAction()
 {
     $this->setAutorefreshInterval(15);
     if ($this->Auth()->hasPermission('monitoring/command/schedule-check')) {
         $checkNowForm = new CheckNowCommandForm();
         $checkNowForm->setObjects($this->serviceList)->handleRequest();
         $this->view->checkNowForm = $checkNowForm;
     }
     $acknowledgedObjects = $this->serviceList->getAcknowledgedObjects();
     if (!empty($acknowledgedObjects)) {
         $removeAckForm = new RemoveAcknowledgementCommandForm();
         $removeAckForm->setObjects($acknowledgedObjects)->handleRequest();
         $this->view->removeAckForm = $removeAckForm;
     }
     $featureStatus = $this->serviceList->getFeatureStatus();
     $toggleFeaturesForm = new ToggleObjectFeaturesCommandForm(array('backend' => $this->backend, 'objects' => $this->serviceList));
     $toggleFeaturesForm->load((object) $featureStatus)->handleRequest();
     $this->view->toggleFeaturesForm = $toggleFeaturesForm;
     $this->setAutorefreshInterval(15);
     $this->view->rescheduleAllLink = Url::fromRequest()->setPath('monitoring/services/reschedule-check');
     $this->view->downtimeAllLink = Url::fromRequest()->setPath('monitoring/services/schedule-downtime');
     $this->view->processCheckResultAllLink = Url::fromRequest()->setPath('monitoring/services/process-check-result');
     $this->view->addCommentLink = Url::fromRequest()->setPath('monitoring/services/add-comment');
     $this->view->deleteCommentLink = Url::fromRequest()->setPath('monitoring/services/delete-comment');
     $this->view->stats = $this->serviceList->getServiceStateSummary();
     $this->view->objects = $this->serviceList;
     $this->view->unhandledObjects = $this->serviceList->getUnhandledObjects();
     $this->view->problemObjects = $this->serviceList->getProblemObjects();
     $this->view->downtimeUnhandledLink = Url::fromPath('monitoring/services/schedule-downtime')->setQueryString($this->serviceList->getUnhandledObjects()->objectsFilter()->toQueryString());
     $this->view->downtimeLink = Url::fromPath('monitoring/services/schedule-downtime')->setQueryString($this->serviceList->getProblemObjects()->objectsFilter()->toQueryString());
     $this->view->acknowledgedObjects = $acknowledgedObjects;
     $this->view->acknowledgeLink = Url::fromPath('monitoring/services/acknowledge-problem')->setQueryString($this->serviceList->getUnacknowledgedObjects()->objectsFilter()->toQueryString());
     $this->view->unacknowledgedObjects = $this->serviceList->getUnacknowledgedObjects();
     $this->view->objectsInDowntime = $this->serviceList->getObjectsInDowntime();
     $this->view->inDowntimeLink = Url::fromPath('monitoring/list/services')->setQueryString($this->serviceList->getObjectsInDowntime()->objectsFilter(array('host' => 'host_name', 'service' => 'service_description'))->toQueryString());
     $this->view->showDowntimesLink = Url::fromPath('monitoring/downtimes/show')->setQueryString($this->serviceList->getObjectsInDowntime()->objectsFilter()->andFilter(Filter::where('object_type', 'service'))->toQueryString());
     $this->view->commentsLink = Url::fromRequest()->setPath('monitoring/list/comments');
     $this->view->sendCustomNotificationLink = Url::fromRequest()->setPath('monitoring/services/send-custom-notification');
 }
Example #25
0
 /**
  * Create and return a filter to use when updating or deleting a group
  *
  * @return  Filter
  */
 protected function createFilter()
 {
     return Filter::where('group_name', $this->getIdentifier());
 }
Example #26
0
 protected function validateFilterColumns(Filter $filter)
 {
     if ($filter->isExpression()) {
         $valid = false;
         foreach ($this->allowedColumns as $column) {
             if (is_callable($column)) {
                 if (call_user_func($column, $filter->getColumn())) {
                     $valid = true;
                     break;
                 }
             } elseif ($filter->getColumn() === $column) {
                 $valid = true;
                 break;
             }
         }
         if (!$valid) {
             throw new QueryException('Invalid filter column provided: %s', $filter->getColumn());
         }
     } else {
         foreach ($filter->filters() as $subFilter) {
             $this->validateFilterColumns($subFilter);
         }
     }
 }
 public function matches(Filter $filter)
 {
     return $filter->matches($this->flattenProperties());
 }
Example #28
0
 /**
  * Render and return the given filter expression
  *
  * @param   Filter  $filter
  *
  * @return  string
  */
 protected function renderFilterExpression(Filter $filter)
 {
     $column = $filter->getColumn();
     $sign = $filter->getSign();
     $value = $filter->getExpression();
     if (is_array($value) && $sign === '=') {
         // TODO: Should we support this? Doesn't work for blub*
         return $column . ' IN (' . $this->dbAdapter->quote($value) . ')';
     } elseif ($sign === '=' && strpos($value, '*') !== false) {
         return $column . ' LIKE ' . $this->dbAdapter->quote(preg_replace('~\\*~', '%', $value));
     } elseif ($sign === '!=' && strpos($value, '*') !== false) {
         return $column . ' NOT LIKE ' . $this->dbAdapter->quote(preg_replace('~\\*~', '%', $value));
     } else {
         return $column . ' ' . $sign . ' ' . $this->dbAdapter->quote($value);
     }
 }
Example #29
0
 /**
  * Remove a group member
  */
 public function removememberAction()
 {
     $this->assertPermission('config/authentication/groups/edit');
     $this->assertHttpMethod('POST');
     $groupName = $this->params->getRequired('group');
     $backend = $this->getUserGroupBackend($this->params->getRequired('backend'), 'Icinga\\Data\\Reducible');
     $form = new Form(array('onSuccess' => function ($form) use($groupName, $backend) {
         foreach ($form->getValue('user_name') as $userName) {
             try {
                 $backend->delete('group_membership', Filter::matchAll(Filter::where('group_name', $groupName), Filter::where('user_name', $userName)));
                 Notification::success(sprintf(t('User "%s" has been removed from group "%s"'), $userName, $groupName));
             } catch (NotFoundError $e) {
                 throw $e;
             } catch (Exception $e) {
                 Notification::error($e->getMessage());
             }
         }
         $redirect = $form->getValue('redirect');
         if (!empty($redirect)) {
             $form->setRedirectUrl(htmlspecialchars_decode($redirect));
         }
         return true;
     }));
     $form->setUidDisabled();
     $form->setSubmitLabel('btn_submit');
     // Required to ensure that isSubmitted() is called
     $form->addElement('hidden', 'user_name', array('required' => true, 'isArray' => true));
     $form->addElement('hidden', 'redirect');
     try {
         $form->handleRequest();
     } catch (NotFoundError $_) {
         $this->httpNotFound(sprintf($this->translate('Group "%s" not found'), $groupName));
     }
 }
Example #30
0
 /**
  * Return whether this object matches the given filter
  *
  * @param   Filter  $filter
  *
  * @return  bool
  *
  * @throws  ProgrammingError    In case the object cannot be found
  *
  * @deprecated      Use $filter->matches($object) instead
  */
 public function matches(Filter $filter)
 {
     if ($this->properties === null && $this->fetch() === false) {
         throw new ProgrammingError('Unable to apply filter. Object %s of type %s not found.', $this->getName(), $this->getType());
     }
     return $filter->matches($this);
 }