/** * Export all clients */ public function exportAction() { $request = $this->getRequest(); $directory = $request->getParam('directory'); $validate = $request->getParam('validate') || $request->getParam('v'); if (!is_dir($directory) or !is_writable($directory)) { $model = new \Zend\Mvc\Console\View\ViewModel(); $model->setErrorLevel(10); $model->setResult("Directory '{$directory}' does not exist or is not writable.\n"); return $model; } $clients = $this->_clientManager->getClients(null, 'IdString'); foreach ($clients as $client) { $id = $client['IdString']; $this->console->writeLine("Exporting {$id}"); $document = $client->toDomDocument(); $document->save($directory . '/' . $document->getFilename()); if ($validate and !$document->isValid()) { $model = new \Zend\Mvc\Console\View\ViewModel(); $model->setErrorLevel(11); $model->setResult("Validation failed for {$id}.\n"); return $model; } } }
/** * Show excluded computers * * @return array sorting, group, computers, order, direction */ public function excludedAction() { $this->setActiveMenu('Groups'); $vars['sorting'] = $this->getOrder('InventoryDate', 'desc'); $vars['group'] = $this->_currentGroup; $vars['computers'] = $this->_clientManager->getClients(array('Name', 'UserName', 'InventoryDate'), $vars['sorting']['order'], $vars['sorting']['direction'], 'ExcludedFrom', $this->_currentGroup); return $vars; }
/** * Show list of clients, filtered by various criteria * * All query parameters are optional, but the filter, search, operator and * invert parameters should match. * * - filter or filter1, filter2...: (string|array) Name of a filter to apply * - search or search1, search2...: (string|array) Filter criteria * - operator or operator1, operator2...: (string|array) Operator for filter * - invert or invert1, invert2...: (bool|array) Invert filter results * - columns: Comma-separated list of columns to display (a default set is available) * - jumpto: Subpage (action) for the client link (default: general) * * This action also acts as a handler for the search form (via GET method), * denoted by the presence of the customSearch parameter. * * @return array|\Zend\Http\Response array(filter, search, operator, invert, * columns[], jumpto, isCustomSearch, order, direction) or redirect response * in case of invalid search form data */ public function indexAction() { $params = $this->params(); if ($params->fromQuery('customSearch')) { // Submitted from search form $form = $this->_formManager->get('Console\\Form\\Search'); $form->remove('_csrf'); $form->setData($params->fromQuery()); if ($form->isValid()) { $isCustomSearch = true; $data = $form->getData(); $filter = $data['filter']; $search = $data['search']; $operator = $data['operator']; $invert = $data['invert']; // Request minimal column list and add columns for non-equality searches $columns = array('Name', 'UserName', 'InventoryDate'); if (($invert or $data['operator'] != 'eq') and !in_array($filter, $columns)) { $columns[] = $filter; } } else { return $this->redirectToRoute('client', 'search', $params->fromQuery()); } } else { // Direct query via URL with optional builtin filter $isCustomSearch = false; $filter = $params->fromQuery('filter'); $search = $params->fromQuery('search'); $invert = $params->fromQuery('invert'); $operator = $params->fromQuery('operator'); if (!$filter) { $index = 1; while ($params->fromQuery('filter' . $index)) { $filter[] = $params->fromQuery('filter' . $index); $search[] = $params->fromQuery('search' . $index); $operator[] = $params->fromQuery('operator' . $index); $invert[] = $params->fromQuery('invert' . $index); $index++; } } $columns = explode(',', $params->fromQuery('columns', 'Name,UserName,OsName,Type,CpuClock,PhysicalMemory,InventoryDate')); } $vars = $this->getOrder('InventoryDate', 'desc'); $vars['clients'] = $this->_clientManager->getClients($columns, $vars['order'], $vars['direction'], $filter, $search, $operator, $invert); $jumpto = $params->fromQuery('jumpto'); if (!method_exists($this, static::getMethodFromAction($jumpto))) { $jumpto = 'general'; // Default for missing or invalid argument } $vars['jumpto'] = $jumpto; $vars['filter'] = $filter; $vars['search'] = $search; $vars['operator'] = $operator; $vars['invert'] = $invert; $vars['isCustomSearch'] = $isCustomSearch; $vars['columns'] = $columns; return $vars; }
/** * Retrieve duplicate clients with given criteria * * @param string $criteria One of Name|MacAddress|Serial|AssetTag * @param string $order Sorting order (default: 'Id') * @param string $direction One of asc|desc (default: 'asc') * @return \Zend\Db\ResultSet\AbstractResultSet \Model\Client\Client iterator */ public function find($criteria, $order = 'Id', $direction = 'asc') { $subQuery = $this->_getDuplicateValues($criteria); $column = $subQuery->getRawState($subQuery::COLUMNS)[0]; $select = $this->_clientManager->getClients(array('Id', 'Name', 'LastContactDate', 'Serial', 'AssetTag'), $order, $direction, null, null, null, null, false, false, false); $select->join('networks', 'networks.hardware_id = clients.id', array('networkinterface_macaddr' => 'macaddr'), $select::JOIN_LEFT)->where(array(new \Zend\Db\Sql\Predicate\In($column, $subQuery))); if ($order != 'Name') { // Secondary ordering by name $select->order('name'); } if ($order != 'Id') { // Additional ordering by ID, to ensure multiple rows for the same // client are kept together where primary ordering allows $select->order('clients.id'); } return $this->_clients->selectWith($select); }