/** * Uloží položky * * @param array $Request */ public static function saveMembers($Request) { $Service = new IEService(); if (isset($Request[$Service->myKeyColumn])) { if ($Service->loadFromMySQL($Request[$Service->myKeyColumn])) { if (isset($Request['addservice']) || isset($Request['delservice'])) { if (isset($Request['addservice'])) { $Service->addHostName($Request['host_id'], $Request['host_name']); if ($Service->saveToMySQL()) { $Service->addStatusMessage(sprintf(_('položka %s byla přidána'), $Request['addservice']), 'success'); } else { $Service->addStatusMessage(sprintf(_('položka %s nebyla přidána'), $Request['addservice']), 'warning'); } } if (isset($Request['delservice'])) { $Service->delHostName($Request['host_id'], $Request['host_name']); if ($Service->saveToMySQL()) { $Service->addStatusMessage(sprintf(_('položka %s byla odebrána'), $Request['delservice']), 'success'); } else { $Service->addStatusMessage(sprintf(_('položka %s nebyla odebrána'), $Request['delservice']), '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; }
/** * Smazaže kontakt i jeho subkontakty * * @return boolean */ public function rename($newname) { $oldname = $this->getName(); $this->setDataValue($this->nameColumn, $newname); if ($this->saveToMySQL()) { $childs = $this->getChilds(); $subcontact = new IEContact(); $service = new IEService(); foreach ($childs as $childID => $childInfo) { $subcontact->loadFromMySQL($childID); $type = $subcontact->getDataValue('alias'); $subcontact->setDataValue($subcontact->nameColumn, $newname . ' ' . $type); $services = $this->myDbLink->queryTo2DArray('SELECT ' . $service->getmyKeyColumn() . ' FROM ' . $service->myTable . ' WHERE contacts LIKE \'%' . $oldname . ' ' . $type . '%\''); if (count($services)) { foreach ($services as $serviceID) { $service->loadFromMySQL((int) $serviceID); if ($service->delMember('contacts', $id)) { $service->addMember('contacts', $id, $newname . ' ' . $type); $service->saveToMySQL(); } } } $subcontact->saveToMySQL(); } } else { $this->addStatusMessage(_('Kontakt nelze přejmenovat'), 'warning'); } }
function cfgServices() { $service = new IEService(); $servicesAssigned = $service->myDbLink->queryToArray('SELECT ' . $service->myKeyColumn . ',' . $service->nameColumn . ',`use` FROM ' . $service->myTable . ' WHERE host_name LIKE \'%"' . $this->host->getName() . '"%\'', $service->myKeyColumn); $allServices = $service->getListing(null, true, array('platform', 'check_command-remote', 'check_command-params', 'passive_checks_enabled', 'active_checks_enabled', 'use', 'check_interval', 'check_command-remote')); foreach ($allServices as $serviceID => $serviceInfo) { if (!array_key_exists($serviceID, $servicesAssigned)) { unset($allServices[$serviceID]); continue; //Služba není přiřazena k hostu } } /* Naplní hodnoty z předloh */ $usedCache = array(); $commandsCache = array(); foreach ($allServices as $rowId => $service) { if (isset($service['use'])) { $remote = $service['check_command-remote']; if (!isset($commandsCache[$remote])) { $command = new IECommand($remote); $script_id = $command->getDataValue('script_id'); if ($script_id) { $this->scriptsToDeploy[$command->getName()] = $script_id; } $commandsCache[$remote] = $command->getData(); } } if (isset($service['use'])) { $use = $service['use']; if (!isset($usedCache[$use])) { $used = new IEService(); $used->nameColumn = 'name'; if ($used->loadFromMySQL($use)) { $used->resetObjectIdentity(); $usedCache[$use] = $used->getData(); } } if (isset($usedCache[$use])) { foreach ($usedCache[$use] as $templateKey => $templateValue) { if ($templateKey != 'check_interval') { continue; } if (!is_null($templateValue) && !isset($allServices[$rowId][$templateKey])) { $allServices[$rowId][$templateKey] = $templateValue; } } } } } foreach ($allServices as $serviceId => $service) { $serviceName = $service['service_description']; $serviceCmd = $service['check_command-remote']; if (is_null($serviceCmd)) { continue; } $serviceParams = $service['check_command-params']; switch ($this->platform) { case 'windows': $this->nscBatArray[] = "\n\nREM #" . $service['service_id'] . ' ' . $serviceName . "\n"; break; case 'linux': $this->nscBatArray[] = "\n\n# #" . $service['service_id'] . ' ' . $serviceName . "\n"; break; default: break; } if (isset($commandsCache[$serviceCmd])) { $cmdline = $commandsCache[$serviceCmd]['command_line']; } else { $cmdline = $serviceCmd; } $checkCommand = str_replace('\\', '\\\\', $cmdline . ' ' . $serviceParams); if (preg_match("/\\.(vbs|bat|ps1|wsf)/", $cmdline)) { $this->addCfg('/settings/external scripts/wrapped scripts', $this->stripServiceName($serviceName), $checkCommand); } else { $this->addCfg('/settings/external scripts/alias', $this->stripServiceName($serviceName), $checkCommand); } if ($this->hostPassiveMode) { $this->addCfg('/settings/scheduler/schedules/' . $this->stripServiceName($serviceName) . '-' . EaseShared::user()->getUserLogin(), 'command', $this->stripServiceName($serviceName)); $this->addCfg('/settings/scheduler/schedules/' . $this->stripServiceName($serviceName) . '-' . EaseShared::user()->getUserLogin(), 'interval', $service['check_interval'] . 'm'); } } }
/** * Přejmenuje hosta a závistlosti * @param type $newname */ public function rename($newname) { $oldname = $this->getName(); $this->setDataValue($this->nameColumn, $newname); $hostGroup = new IEHostgroup(); $hostGroup->renameHost($oldname, $newname); $renameAll = true; $service = new IEService(); $servicesAssigned = $service->myDbLink->queryToArray('SELECT ' . $service->myKeyColumn . ',' . $service->nameColumn . ' FROM ' . $service->myTable . ' WHERE ' . 'host_name' . ' LIKE \'%"' . $oldname . '"%\'', $service->myKeyColumn); foreach ($servicesAssigned as $serviceID => $serviceInfo) { $service->loadFromMySQL($serviceID); $service->renameHostName($this->getId(), $newname); if (!$service->saveToMySQL()) { $this->addStatusMessage(sprintf(_('Nepodařilo se přejmenovat %s ve službě %s'), $this->getName(), $service->getName()), $Type); $renameAll = false; } } $childsAssigned = $this->myDbLink->queryToArray('SELECT ' . $this->myKeyColumn . ',' . $this->nameColumn . ' FROM ' . $this->myTable . ' WHERE ' . 'parents' . ' LIKE \'%"' . $oldname . '"%\'', $this->myKeyColumn); foreach ($childsAssigned as $chid_id => $child_info) { $child = new IEHost($chid_id); $child->delMember('parents', $this->getId(), $oldname); $child->addMember('parents', $this->getId(), $newname); $child->updateToMySQL(); } if ($this->save() && $renameAll) { return true; } return false; }
public function delete($id = null) { if (is_null($id)) { $id = $this->getId(); } if ($id != $this->getId()) { $this->loadFromMySQL($id); } $userGroup = new IEUserGroup(); $userGroup->delUser($id); $command = new IECommand(); $myCommand = $command->getOwned($id); if ($myCommand) { foreach ($myCommand as $command_id => $cmd) { $command->loadFromMySQL((int) $command_id); $command->delete(); } } $contact = new IEContact(); $myContact = $contact->getOwned($id); if ($myContact) { foreach ($myContact as $contact_id => $cmd) { if ($contact->loadFromMySQL((int) $contact_id)) { $contact->delete(); } } } $contactgroup = new IEContactgroup(); $myContactgroup = $contactgroup->getOwned($id); if ($myContactgroup) { foreach ($myContactgroup as $contactgroup_id => $cmd) { $contactgroup->loadFromMySQL((int) $contactgroup_id); $contactgroup->delete(); } } $hostgroup = new IEHostgroup(); $myHostgroup = $hostgroup->getOwned($id); if ($myHostgroup) { foreach ($myHostgroup as $hostgroup_id => $cmd) { $hostgroup->loadFromMySQL((int) $hostgroup_id); $hostgroup->delete(); } } $host = new IEHost(); $myHost = $host->getOwned($id); if ($myHost) { foreach ($myHost as $host_id => $cmd) { $host->loadFromMySQL((int) $host_id); $host->delete(); } } $servicegroup = new IEServicegroup(); $myServicegroup = $servicegroup->getOwned($id); if ($myServicegroup) { foreach ($myServicegroup as $servicegroup_id => $cmd) { $servicegroup->loadFromMySQL((int) $servicegroup_id); $servicegroup->delete(); } } $service = new IEService(); $myService = $service->getOwned($id); if ($myService) { foreach ($myService as $service_id => $cmd) { $service->loadFromMySQL((int) $service_id); $service->delete(); } } $timeperiod = new IETimeperiod(); $myTimeperiod = $timeperiod->getOwned($id); if ($myTimeperiod) { foreach ($myTimeperiod as $timeperiod_id => $cmd) { $timeperiod->loadFromMySQL((int) $timeperiod_id); $timeperiod->delete(); } } $cfgfile = constant('CFG_GENERATED') . '/' . $this->getUserLogin() . '.cfg'; if (file_exists($cfgfile)) { if (unlink($cfgfile)) { $this->addStatusMessage(sprintf(_('Konfigurace uživatele %s byla smazána'), $this->getUserLogin()), 'success'); } else { $this->addStatusMessage(sprintf(_('Konfigurace uživatele %s nebyla smazána'), $this->getUserLogin()), 'error'); } } if ($this->deleteFromMySQL()) { $this->addStatusMessage(sprintf(_('Uživatel %s byl smazán'), $this->getUserLogin())); require_once 'Ease/EaseMail.php'; $email = new EaseMail($this->getDataValue('email'), _('Oznámení o zrušení účtu')); $email->setMailHeaders(array('From' => EMAIL_FROM)); $email->addItem(new EaseHtmlDivTag(null, "Právě jste byl/a smazán/a z Aplikace VSMonitoring s těmito přihlašovacími údaji:\n")); $email->addItem(new EaseHtmlDivTag(null, ' Login: ' . $this->GetUserLogin() . "\n")); $email->send(); return true; } else { return FALSE; } }
* @subpackage WebUI * @author Vitex <*****@*****.**> * @copyright 2012 Vitex@hippy.cz (G) */ require_once 'includes/IEInit.php'; $oPage->onlyForLogged(); $hostId = $oPage->getRequestValue('host_id', 'int'); $host = new IEHost($hostId); switch ($oPage->getRequestValue('action')) { case 'applystemplate': $stemplate = new IEStemplate($oPage->getRequestValue('stemplate_id', 'int')); $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();
/** * Uloží položky * * @param array $request */ public static function saveMembers($request) { $service = new IEService(); if (isset($request[$service->myKeyColumn])) { if ($service->loadFromMySQL((int) $request[$service->myKeyColumn])) { if (isset($request['addservice']) || isset($request['delservice'])) { if (isset($request['addservice'])) { $service->addMember('host_name', $request['host_id'], $request['host_name']); if ($service->saveToMySQL()) { $service->addStatusMessage(sprintf(_('položka %s byla přidána'), $request['addservice']), 'success'); if ($service->getDataValue('autocfg') == '1') { $service->addStatusMessage(sprintf(_('Službu %s je nutné nejprve zkonfigurovat'), $request['addservice']), 'warning'); EaseShared::webPage()->redirect('servicetweak.php?host_id=' . $request['host_id'] . '&service_id=' . $request[$service->myKeyColumn]); exit; } } else { $service->addStatusMessage(sprintf(_('položka %s nebyla přidána'), $request['addservice']), 'warning'); } } if (isset($request['delservice'])) { $service->delMember('host_name', $request['host_id'], $request['host_name']); if ($service->saveToMySQL()) { $service->addStatusMessage(sprintf(_('položka %s byla odebrána'), $request['delservice']), 'success'); } else { $service->addStatusMessage(sprintf(_('položka %s nebyla odebrána'), $request['delservice']), 'warning'); } } } } } }
function fixContactIDs() { $contactsOK = array(); $contactsErr = array(); $contact = new IEContact(); $service = new IEService(); $services = $service->getColumnsFromMySQL(array($service->myKeyColumn)); foreach ($services as $serviceId => $serviceInfo) { $serviceId = intval(current($serviceInfo)); $service->loadFromMySQL($serviceId); $contactNames = $service->getDataValue('contacts'); if ($contactNames) { foreach ($contactNames as $contactId => $contactName) { $contactFound = $contact->loadFromMySQL($contactName); if ($contactId != $contact->getId()) { if ($service->delMember('contacts', $contactId, $contactName) && $service->addMember('contacts', $contact->getId(), $contactName)) { $contactsOK[] = $contactName; } else { $contactsErr[] = $contactName; } } } } if (count($contactsOK)) { if ($service->saveToMySQL()) { $this->addItemSmart(sprintf(_('<strong>%s</strong> : %s'), $service->getName(), implode(',', $contactsOK)), array('class' => 'list-group-item')); $this->addStatusMessage(sprintf(_('%s : %s'), $service->getName(), implode(',', $contactsOK)), 'success'); $contactsOK = array(); } } } $host = new IEHost(); $hosts = $host->getColumnsFromMySQL(array($host->myKeyColumn)); foreach ($hosts as $hostInfo) { $hostId = intval(current($hostInfo)); $host->loadFromMySQL($hostId); $contactNames = $host->getDataValue('contacts'); if ($contactNames) { foreach ($contactNames as $contactId => $contactName) { $contactFound = $contact->loadFromMySQL($contactName); if ($contactId != $contact->getId()) { if ($host->delMember('contacts', $contactId, $contactName) && $host->addMember('contacts', $contact->getId(), $contactName)) { $contactsOK[] = $contactName; } else { $contactsErr[] = $contactName; } } } } if (count($contactsOK)) { if ($host->saveToMySQL()) { $this->addItemSmart(sprintf(_('<strong>%s</strong> : %s'), $host->getName(), implode(',', $contactsOK)), array('class' => 'list-group-item')); $this->addStatusMessage(sprintf(_('%s : %s'), $host->getName(), implode(',', $contactsOK)), 'success'); $contactsOK = array(); } } } }
} break; case 'system': $hosts = $service->getDataValue('host_name'); foreach ($hosts as $host_id => $host_name) { $host = new IEHost($host_id); $newService = new IEService($service->getId()); $newService->setDataValue($service->userColumn, 0); $newService->setDataValue('public', 0); if ($newService->fork($host, $host->getDataValue($host->userColumn))) { $oUser->addStatusMessage(sprintf(_('Služba %s byla odvozena'), $newService->getName()), 'success'); } else { $oUser->addStatusMessage(_('Služba nebyla odvozena'), 'error'); } } $service->loadFromMySQL($service->getId()); break; case 'swap': $service->swapTo($oPage->getRequestValue('new_service_id', 'int')); break; case 'export': $service->transferDeps($oPage->getRequestValue('destination'), $oPage->getRequestValue('rels')); break; default: if ($oPage->isPosted()) { if ($oPage->getRequestValue('action') != 'rename') { if ($oPage->getRequestValue('action') == 'clone') { $oUser->addStatusMessage(_('Služba byla zklonovana'), 'info'); $service->unsetDataValue($service->getMyKey()); } else { $service->takeData($_POST);
$usedCache = array(); $commandsCache = array(); foreach ($allServices as $rowId => $service) { if (isset($service['use'])) { $remote = $service['check_command-remote']; if (!isset($commandsCache[$remote])) { $command = new IECommand($remote); $commandsCache[$remote] = $command->getData(); } } if (isset($service['use'])) { $use = $service['use']; if (!isset($usedCache[$use])) { $used = new IEService(); $used->setmyKeyColumn('name'); if ($used->loadFromMySQL($use)) { $used->resetObjectIdentity(); $usedCache[$use] = $used->getData(); } } if (isset($usedCache[$use])) { foreach ($usedCache[$use] as $templateKey => $templateValue) { if ($templateKey != 'check_interval') { continue; } if (!is_null($templateValue) && !isset($allServices[$rowId][$templateKey])) { $allServices[$rowId][$templateKey] = $templateValue; } } } }
/** * Konfigurace sluzeb */ function cfgServices() { $service = new IEService(); $servicesAssigned = $service->myDbLink->queryToArray('SELECT ' . $service->myKeyColumn . ',' . $service->nameColumn . ',`use` FROM ' . $service->myTable . ' WHERE host_name LIKE \'%"' . $this->host->getName() . '"%\'', $service->myKeyColumn); $allServices = $service->getListing(null, true, array('platform', 'check_command-remote', 'check_command-params', 'passive_checks_enabled', 'active_checks_enabled', 'use', 'check_interval', 'check_command-remote')); foreach ($allServices as $serviceID => $serviceInfo) { if (!array_key_exists($serviceID, $servicesAssigned)) { unset($allServices[$serviceID]); continue; //Služba není přiřazena k hostu } } /* Naplní hodnoty z předloh */ $usedCache = array(); $commandsCache = array(); foreach ($allServices as $rowId => $service) { if (isset($service['use'])) { $remote = $service['check_command-remote']; if (!isset($commandsCache[$remote])) { $command = new IECommand($remote); $commandsCache[$remote] = $command->getData(); } } if (isset($service['use'])) { $use = $service['use']; if (!isset($usedCache[$use])) { $used = new IEService(); $used->nameColumn = 'name'; if ($used->loadFromMySQL($use)) { $used->resetObjectIdentity(); $usedCache[$use] = $used->getData(); } } if (isset($usedCache[$use])) { foreach ($usedCache[$use] as $templateKey => $templateValue) { if ($templateKey != 'check_interval') { continue; } if (!is_null($templateValue) && !isset($allServices[$rowId][$templateKey])) { $allServices[$rowId][$templateKey] = $templateValue; } } } } } foreach ($allServices as $serviceId => $service) { $serviceName = $service['service_description']; $serviceCmd = $service['check_command-remote']; if (is_null($serviceCmd)) { continue; } $serviceParams = $service['check_command-params']; $this->nscCfgArray[] = "\n# #" . $service['service_id'] . ' ' . $serviceName; if (isset($commandsCache[$serviceCmd])) { if (isset($commandsCache[$serviceCmd]['deploy'])) { $this->nscCfgArray[] = $commandsCache[$serviceCmd]['deploy']; } $cmdline = $commandsCache[$serviceCmd]['command_line']; } else { $cmdline = $serviceCmd; } $this->addCfg('command[' . str_replace(' ', '_', $serviceName) . ']', $cmdline . ' ' . $serviceParams); } }