/** * Uloží položky * * @param array $request */ public static function saveMembers($request) { $host = new IEHost(); if (isset($request[$host->myKeyColumn])) { if ($host->loadFromMySQL($request[$host->myKeyColumn])) { if (isset($request['addhost']) || isset($request['delhost'])) { if (isset($request['addhost'])) { $host->addMember('service_name', $request['service_id'], $request['service_name']); if ($host->saveToMySQL()) { $host->addStatusMessage(sprintf(_('položka %s byla přidána'), $request['addhost']), 'success'); } else { $host->addStatusMessage(sprintf(_('položka %s nebyla přidána'), $request['addhost']), 'warning'); } } if (isset($request['delhost'])) { $host->delMember('service_name', $request['service_id'], $request['service_name']); if ($host->saveToMySQL()) { $host->addStatusMessage(sprintf(_('položka %s byla odebrána'), $request['delhost']), 'success'); } else { $host->addStatusMessage(sprintf(_('položka %s nebyla odebrána'), $request['delhost']), 'warning'); } } } } } }
/** * Přiřadí služby k hostům podle výsledků scannu */ public function assignServices() { $success = 0; $hostmod = false; foreach ($this->results as $port) { switch ($port) { case 80: if ($this->host->favToIcon()) { $hostmod = true; } break; case 5666: $this->host->setDataValue('platform', 'linux'); $hostmod = true; break; case 12489: $this->host->setDataValue('platform', 'windows'); $hostmod = true; break; default: break; } $this->service->setmyKeyColumn('tcp_port'); $this->service->loadFromMySQL($port); $this->service->setmyKeyColumn('service_id'); $this->service->addMember('host_name', $this->host->getId(), $this->host->getName()); if ($this->service->saveToMySQL()) { $this->addStatusMessage(sprintf(_('Přidána sledovaná služba: %s'), $this->service->getName()), 'success'); $success++; } else { $this->addStatusMessage(sprintf(_('Přidání sledované služby: %s se nezdařilo'), $this->service->getName()), 'error'); } } if ($hostmod) { $this->host->saveToMySQL(); } return $success; }
/** * Smaže kontakt i jeho subkontakty * * @return boolean */ public function delete($id = null) { if (is_null($id)) { $id = $this->getId(); } else { if ($id != $this->getId()) { $this->loadFromMySQL($id); } } $childs = $this->getChilds(); if ($childs) { $parent = $id; foreach ($childs as $child_id => $child) { $this->delete($child_id); } $this->loadFromMySQL($parent); $id = $parent; } $contactgroup = new IEContactgroup(); $contactgroups = $this->myDbLink->queryTo2DArray('SELECT ' . $contactgroup->getmyKeyColumn() . ' FROM ' . $contactgroup->myTable . ' WHERE members LIKE \'%' . $this->getName() . '%\''); if (count($contactgroups)) { foreach ($contactgroups as $contactgroupID) { $contactgroup->loadFromMySQL((int) $contactgroupID); if ($contactgroup->delMember('members', null, $this->getName())) { if ($contactgroup->saveToMySQL()) { $this->addStatusMessage(sprintf(_('Kontakt <strong>%s</strong> byl odebrán ze skupiny <strong>%s</strong>'), $this->getName(), $contactgroup->getName()), 'success'); } } else { $this->addStatusMessage(sprintf(_('Kontakt <strong>%s</strong> nebyl odebrán ze skupiny <strong>%s</strong>'), $this->getName(), $contactgroup->getName()), 'warning'); } } } $service = new IEService(); $services = $this->myDbLink->queryTo2DArray('SELECT ' . $service->getmyKeyColumn() . ' FROM ' . $service->myTable . ' WHERE contacts LIKE \'%' . $this->getName() . '%\''); if (count($services)) { foreach ($services as $serviceID) { $service->loadFromMySQL((int) $serviceID); if ($service->delMember('contacts', $id)) { if ($service->saveToMySQL()) { $this->addStatusMessage(sprintf(_('Kontakt <strong>%s</strong> byl odebrán ze služby <strong>%s</strong>'), $this->getName(), $service->getName()), 'success'); } } else { $this->addStatusMessage(sprintf(_('Kontakt <strong>%s</strong> nebyl odebrán ze služby <strong>%s</strong>'), $this->getName(), $service->getName()), 'warning'); } } } $host = new IEHost(); $hosts = $this->myDbLink->queryTo2DArray('SELECT ' . $host->getmyKeyColumn() . ' FROM ' . $host->myTable . ' WHERE contacts LIKE \'%' . $this->getName() . '%\''); if (count($hosts)) { foreach ($hosts as $hostID) { $host->loadFromMySQL((int) $hostID); if ($host->delMember('contacts', $id)) { if ($host->saveToMySQL()) { $this->addStatusMessage(sprintf(_('Kontakt <strong>%s</strong> byl odebrán z hosta <strong>%s</strong>'), $this->getName(), $host->getName()), 'success'); } } else { $this->addStatusMessage(sprintf(_('Kontakt <strong>%s</strong> nebyl odebrán z hosta <strong>%s</strong>'), $this->getName(), $host->getName()), 'warning'); } } } $this->myDbLink->exeQuery('DELETE FROM `' . $this->myTable . '` WHERE `parent_id`=' . $id); return parent::delete($id); }
/** * Smaže záznam */ public function delete($id = null) { if (!is_null($id)) { $this->loadFromMySQL($id); } $hostGroup = new IEHostgroup(); $hostGroup->deleteHost($this->getName()); $delAll = true; $service = new IEService(); $servicesAssigned = $service->myDbLink->queryToArray('SELECT ' . $service->myKeyColumn . ',' . $service->nameColumn . ' FROM ' . $service->myTable . ' WHERE ' . 'host_name' . ' LIKE \'%"' . $this->getName() . '"%\'', $service->myKeyColumn); foreach ($servicesAssigned as $ServiceID => $ServiceInfo) { $service->loadFromMySQL($ServiceID); $service->delHostName($this->getId(), $this->getName()); if (!$service->saveToMySQL()) { $this->addStatusMessage(sprintf(_('Nepodařilo se odregistrovat %s ze služby %s'), $this->getName(), $service->getName()), 'Error'); $delAll = false; } } $childsOfMe = $this->myDbLink->queryToArray('SELECT ' . $this->myKeyColumn . ',' . $this->nameColumn . ' FROM ' . $this->myTable . ' WHERE parents ' . ' LIKE \'%' . $this->getName() . '%\'', $this->myKeyColumn); foreach ($childsOfMe as $chid_id => $child_info) { $child = new IEHost($chid_id); if ($child->delMember('parents', $this->getId(), $this->getName()) && $child->saveToMySQL()) { $this->addStatusMessage(sprintf(_('%s již není rodičem %s'), $this->getName(), $child->getName()), 'success'); } else { $this->addStatusMessage(sprintf(_('%s je stále rodičem %s'), $this->getName(), $child->getName()), 'warning'); } } if ($delAll) { return parent::delete(); } return false; }
$services = $stemplate->getDataValue('services'); if (count($services)) { $service = new IEService(); foreach ($services as $service_id => $service_name) { $service->loadFromMySQL($service_id); $service->addMember('host_name', $host->getId(), $host->getName()); $service->saveToMySQL(); $service->dataReset(); } } $contacts = $stemplate->getDataValue('contacts'); if (count($contacts)) { foreach ($contacts as $contact_id => $contact_name) { $host->addMember('contacts', $contact_id, $contact_name); } $host->saveToMySQL(); } break; case 'populate': $host->autoPopulateServices(); break; case 'icon': $icourl = $oPage->getRequestValue('icourl'); if (strlen($icourl)) { $tmpfilename = sys_get_temp_dir() . '/' . EaseSand::randomString(); $fp = fopen($tmpfilename, 'w'); $ch = curl_init($icourl); curl_setopt($ch, CURLOPT_FILE, $fp); $data = curl_exec($ch); $downloadErr = curl_error($ch); if ($downloadErr) {
*/ require_once 'includes/IEInit.php'; require_once 'classes/IEHost.php'; require_once 'classes/IEFXPreloader.php'; $oPage->onlyForLogged(); $hostId = $oPage->getRequestValue('host_id', 'int'); if ($hostId == 0) { $oPage->redirect('hosts.php'); exit; } $host = new IEHost($hostId); $operation = $oPage->getRequestValue('operation'); switch ($operation) { case 'confirm': $state = $oPage->getRequestValue('confirm'); if ($state == 'on') { $host->setDataValue('config_hash', $host->getConfigHash()); } else { $host->setDataValue('config_hash', null); } if ($host->saveToMySQL()) { $host->addStatusMessage(_('Stav nasazení senzoru byl nastaven ručně.')); } break; default: break; } $oPage->addItem(new IEPageTop(_('Sensor'))); $oPage->container->addItem(new IESensorTool($host)); $oPage->addItem(new IEPageBottom()); $oPage->draw();
function fixHostHostgroupID() { $hostgroupsOK = array(); $hostgroupsErr = array(); $host = new IEHost(); $hostgroup = new IEHostgroup(); $hosts = $host->getColumnsFromMySQL(array($host->myKeyColumn)); foreach ($hosts as $hostInfo) { $hostId = intval(current($hostInfo)); $host->loadFromMySQL($hostId); $hostgroupNames = $host->getDataValue('hostgroups'); if ($hostgroupNames) { foreach ($hostgroupNames as $hostgroupId => $hostgroupName) { $hostgroupFound = $hostgroup->loadFromMySQL($hostgroupName); if ($hostgroupId != $hostgroup->getId()) { if ($host->delMember('hostgroups', $hostgroupId, $hostgroupName) && $host->addMember('hostgroups', $hostgroup->getId(), $hostgroupName)) { $hostgroupsOK[] = $hostgroupName; } else { $hostgroupsErr[] = $hostgroupName; } } } } if (count($hostgroupsOK)) { if ($host->saveToMySQL()) { $this->addItemSmart(sprintf(_('<strong>%s</strong> : %s'), $host->getName(), implode(',', $hostgroupsOK)), array('class' => 'list-group-item')); $this->addStatusMessage(sprintf(_('%s : %s'), $host->getName(), implode(',', $hostgroupsOK)), 'success'); $hostgroupsOK = array(); } } } }