public function testInputFilterScanInvalidNetwork() { $data = array('Scan' => array('allowScan' => '1', 'scanThisNetwork' => 'invalid', 'scanSnmp' => '1')); $this->_client->expects($this->once())->method('getItems')->with('NetworkInterface', 'Subnet')->willReturn(array(array('Subnet' => '192.0.2.0'))); $this->_form->setClientObject($this->_client); $this->_form->setValidationGroup('Scan'); $this->_form->setData($data); $this->assertFalse($this->_form->isValid()); }
/** * Download client as XML file * * @return \Zend\Http\Response Response with downloadable XML content */ public function exportAction() { $document = $this->_currentClient->toDomDocument(); if (\Library\Application::isDevelopment()) { $document->forceValid(); } $filename = $document->getFilename(); $xml = $document->saveXml(); $response = $this->getResponse(); $response->getHeaders()->addHeaders(array('Content-Type' => 'text/xml; charset="utf-8"', 'Content-Disposition' => "attachment; filename=\"{$filename}\"", 'Content-Length' => strlen($xml))); $response->setContent($xml); return $response; }
/** * Delete a client * * @param \Model\Client\Client $client Client to be deleted * @param bool $deleteInterfaces Delete interfaces from scanned interfaces * @throws \RuntimeException if the client is locked by another instance */ public function deleteClient(\Model\Client\Client $client, $deleteInterfaces) { if (!$client->lock()) { throw new \RuntimeException('Could not lock client for deletion'); } $connection = $this->_serviceLocator->get('Db')->getDriver()->getConnection(); $id = $client['Id']; // Start transaction to keep database consistent in case of errors // If a transaction is already in progress, an exception will be thrown // which has to be caught. The commit() and rollBack() methods can only // be called if the transaction has been started here. try { $connection->beginTransaction(); $transactionStarted = true; } catch (\Exception $exception) { $transactionStarted = false; } try { // If requested, delete client's network interfaces from the list of // scanned interfaces. Also delete any manually entered description. if ($deleteInterfaces) { $macAddresses = $this->_serviceLocator->get('Database\\Table\\NetworkInterfaces')->getSql()->select(); $macAddresses->columns(array('macaddr')); $macAddresses->where(array('hardware_id' => $id)); $this->_serviceLocator->get('Database\\Table\\NetworkDevicesIdentified')->delete(new \Zend\Db\Sql\Predicate\In('macaddr', $macAddresses)); $this->_serviceLocator->get('Database\\Table\\NetworkDevicesScanned')->delete(new \Zend\Db\Sql\Predicate\In('mac', $macAddresses)); } // Delete rows from foreign tables $tables = array('AndroidInstallations', 'ClientSystemInfo', 'Comments', 'CustomFields', 'PackageHistory', 'WindowsProductKeys', 'GroupMemberships', 'ClientConfig'); foreach ($tables as $table) { $this->_serviceLocator->get("Database\\Table\\{$table}")->delete(array('hardware_id' => $id)); } $this->_serviceLocator->get('Database\\Table\\Attachments')->delete(array('id_dde' => $id, 'table_name' => \Database\Table\Attachments::OBJECT_TYPE_CLIENT)); $this->_serviceLocator->get('Model\\Client\\ItemManager')->deleteItems($id); // Delete row in clients table $this->_serviceLocator->get('Database\\Table\\ClientsAndGroups')->delete(array('id' => $id)); if ($transactionStarted) { $connection->commit(); } } catch (\Exception $exception) { if ($transactionStarted) { $connection->rollback(); } $client->unlock(); throw $exception; } $client->unlock(); }