/** * 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'); } } } } } }
/** * Umožňuje měnit parametry služeb * * @param IEService $service * @param IEHost $host ObjektHostu */ public function __construct($service, $host) { parent::__construct(); $this->service = $service; $this->host = $host; $this->command = new IECommand(); $this->command->setmyKeyColumn($this->command->nameColumn); $checkLocal = $this->service->getDataValue('check_command'); // $checkRemote = $this->service->getDataValue('check_command-remote'); if (isset($checkLocal)) { $this->command->loadFromMySQL($checkLocal); } $configurator = $this->service->getDataValue('configurator'); if ($configurator) { $module = 'modules/' . $configurator . '.inc.php'; if (file_exists($module)) { require_once $module; $this->configurator = $this->addItem(new $configurator($this)); } else { $this->addStatusMessage(sprintf(_('Modul %s nebyl nalezen'), $module), 'error'); } } else { $this->configurator = $this->addItem(new IEServiceConfigurator($this)); } }
function finalize() { $addNewItem = new IEServiceSelect('new_service_id'); $this->addItem(new EaseTWBFormGroup(_('Náhradní služba'), $addNewItem, _('Jméno služby'), sprintf(_('Tato služba se zamění za právě zvolenou službu <strong>%s</strong> u všech hostů kteří ji používají'), $this->service->getName()))); $this->addItem(new EaseTWBFormGroup(_('Vyměnit'), new EaseTWSubmitButton(_('Vyměnit službu') . ' ' . EaseTWBPart::GlyphIcon('flash'), 'info'))); $this->addItem(new EaseHtmlInputHiddenTag('service_id', $this->service->getID())); $this->addItem(new EaseHtmlInputHiddenTag('action', 'swap')); }
function finalize() { parent::finalize(); $platform = $this->service->getDataValue('platform'); $this->addItem(new EaseTWBFormGroup(_('Jméno'), new EaseHtmlInputTextTag('service_name', $this->service->getName()), $this->service->getName(), _('Název služby testu'))); $addNewItem = new EaseHtmlInputSearchTag('check_command-remote', $this->service->getDataValue('check_command-remote'), array('class' => 'search-input', 'title' => _('vzdálený test'))); $addNewItem->setDataSource('jsoncommand.php?maxRows=20&platform=' . $platform); $this->addItem(new EaseTWBFormGroup(_('Vzdálený Příkaz'), $addNewItem, _('Hledej příkazy pro: ') . $platform, _('Příkaz vykonávaný vzdáleným senzorem NRPE/NSCP.exe'))); $this->addItem(new EaseTWBFormGroup(_('Parametry'), new EaseHtmlInputTextTag('check_command-params', $this->service->getDataValue('check_command-params')), $this->service->getDataValue('command-params'), _('Parametry vzdáleného příkazu. (Pro nrpe oddělované vykřičníkem.)'))); $this->addItem(new EaseTWBFormGroup(_('Platforma'), new IEPlatformSelector('platform', null, $platform), _('Platforma sledovaného stroje'))); $this->addItem(new EaseTWSubmitButton(_('Založit') . ' ' . EaseTWBPart::GlyphIcon('forward'), 'success')); $serviceId = $this->service->getId(); if ($serviceId) { $this->addItem(new EaseHtmlInputHiddenTag('service_id', $serviceId)); } }
$pocHostgroups = $hostgroup->getMyRecordsCount(); if ($pocHostgroups) { $success = $oPage->columnI->addItem(new EaseHtmlDivTag('Hostgroup', new EaseTWBLinkButton('hostgroups.php', _('<i class="icon-list"></i>') . ' ' . sprintf(_('Definováno %s skupin hostů'), $pocHostgroups)), array('class' => 'alert alert-success'))); } else { $warning = $oPage->columnI->addItem(new EaseHtmlDivTag('Host', _('Nemáte definovaný žádnou skupinu hostů'), array('class' => 'alert alert-info'))); $warning->addItem(new EaseTWBLinkButton('hostgroup.php', _('Založit první skupinu hostů <i class="icon-edit"></i>'))); } $command = new IECommand(); $PocCommands = $command->getMyRecordsCount(); if ($PocCommands) { $success = $oPage->columnIII->addItem(new EaseHtmlDivTag('Command', new EaseTWBLinkButton('commands.php', _('<i class="icon-list"></i>') . ' ' . sprintf(_('Definováno %s příkazů'), $PocCommands)), array('class' => 'alert alert-success'))); } else { $warning = $oPage->columnIII->addItem(new EaseHtmlDivTag('Host', _('Nemáte definovaný žádné příkazy'), array('class' => 'alert alert-info'))); $warning->addItem(new EaseTWBLinkButton('importcommand.php', _('Importovat příkazy') . ' <i class="icon-download"></i>')); } $service = new IEService(); $pocServices = $service->getMyRecordsCount(); if ($pocServices) { $success = $oPage->columnIII->addItem(new EaseHtmlDivTag('Service', new EaseTWBLinkButton('services.php', _('<i class="icon-list"></i>') . ' ' . sprintf(_('Definováno %s služeb'), $pocServices)), array('class' => 'alert alert-success'))); } else { if ($PocCommands) { if ($pocTimeperiods) { $warning = $oPage->columnIII->addItem(new EaseHtmlDivTag('Host', _('Nemáte definovaný žádné služby'), array('class' => 'alert alert-info'))); $warning->addItem(new EaseTWBLinkButton('service.php', _('Založit první službu') . ' <i class="icon-edit"></i>')); } else { $warning = $oPage->columnIII->addItem(new EaseHtmlDivTag('Host', _('Služby vyžadují časovou periodu ..'), array('class' => 'alert alert-danger'))); } } else { $warning = $oPage->columnIII->addItem(new EaseHtmlDivTag('Host', _('Služby vyžadují příkazy ..'), array('class' => 'alert alert-danger'))); } }
/** * 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); } }
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'); } } }
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; } }
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 'clone': $service->unsetDataValue($service->getmyKeyColumn()); $service->setDataValue($service->nameColumn, $service->getName() . ' ' . _('Cloned')); if ($service->saveToMySQL()) { $oUser->addStatusMessage(_('Služba byla zklonovana'), 'success'); } else { $oUser->addStatusMessage(_('Služba nebyla zklonovana'), 'error'); } 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'));
/** * Editor k přidávání členů skupiny * * @param IEService|IEHost $holder */ public function __construct($holder) { $contactsAssigned = array(); parent::__construct(); $fieldName = $this->getmyKeyColumn(); $initialContent = new EaseTWBPanel(_('Cíle notifikací')); $initialContent->setTagCss(array('width' => '100%')); if (is_null($holder->getMyKey())) { $initialContent->addItem(_('Nejprve je potřeba uložit záznam')); } else { $serviceName = $holder->getName(); $contact = new IEContact(); $allContacts = $contact->getListing(null, true, array('alias', 'parent_id')); foreach ($holder->getDataValue('contacts') as $contactId => $contactName) { if (isset($allContacts[$contactId])) { $contactsAssigned[$contactId] = $allContacts[$contactId]; } } foreach ($allContacts as $contactID => $contactInfo) { if ($contactInfo['register'] != 1) { unset($allContacts[$contactID]); } if (!$contactInfo['parent_id']) { unset($allContacts[$contactID]); } } foreach ($contactsAssigned as $contactID => $contactInfo) { unset($allContacts[$contactID]); } if (count($allContacts)) { foreach ($allContacts as $contactID => $contactInfo) { $initialContent->addItem(new EaseTWBButtonDropdown($contactInfo[$contact->nameColumn], 'inverse', 'xs', array(new EaseHtmlATag('contacttweak.php?contact_id=' . $contactInfo['parent_id'] . '&service_id=' . $holder->getId(), EaseTWBPart::GlyphIcon('wrench') . ' ' . _('Editace')), new EaseHtmlATag('?addcontact=' . $contactInfo[$contact->nameColumn] . '&contact_id=' . $contactID . '&' . $holder->getmyKeyColumn() . '=' . $holder->getMyKey() . '&' . $holder->nameColumn . '=' . $holder->getName(), EaseTWBPart::GlyphIcon('plus') . ' ' . _('Začít obesílat'))))); } } if (count($contactsAssigned)) { $initialContent->addItem('<br/>'); foreach ($contactsAssigned as $contactID => $contactInfo) { $initialContent->addItem(new EaseTWBButtonDropdown($contactInfo[$contact->nameColumn], 'success', 'xs', array(new EaseHtmlATag('?delcontact=' . $contactInfo[$contact->nameColumn] . '&contact_id=' . $contactID . '&' . $holder->getmyKeyColumn() . '=' . $holder->getMyKey() . '&' . $holder->nameColumn . '=' . $holder->getName(), EaseTWBPart::GlyphIcon('remove') . ' ' . _('Přestat obesílat')), new EaseHtmlATag('contacttweak.php?contact_id=' . $contactInfo['parent_id'] . '&service_id=' . $holder->getId(), EaseTWBPart::GlyphIcon('wrench') . ' ' . _('Editace'))))); } } } $this->addItem($initialContent); }
} /* 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->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; } }
$commandEditor = new IECfgEditor($command); $form = new EaseTWBForm('Command', 'command.php', 'POST', $commandEditor, array('class' => 'form-horizontal')); if (!$command->getId()) { $form->addItem(new EaseTWSubmitButton(_('Založit'), 'success')); } else { $form->addItem(new EaseTWSubmitButton(_('Uložit'), 'success')); } break; } $oPage->addItem(new IEPageBottom()); $infopanel = new IEInfoBox($command); $tools = new EaseTWBPanel(_('Nástroje'), 'warning'); if ($command->getId()) { $tools->addItem($command->deleteButton()); $tools->addItem(new EaseTWBPanel(_('Transfer'), 'warning', $command->transferForm())); $service = new IEService(); $usages = $service->getColumnsFromMySQL(array($service->getMyKeyColumn(), $service->nameColumn), array('check_command' => $command->getName()), $service->nameColumn, $service->getMyKeyColumn()); if (count($usages)) { $usedBy = new EaseTWBPanel(_('Používající služby')); $listing = $usedBy->addItem(new EaseHtmlUlTag(null, array('class' => 'list-group'))); foreach ($usages as $usage) { $listing->addItem(new EaseHtmlLiTag(new EaseHtmlATag('service.php?service_id=' . $usage['service_id'], $usage[$service->nameColumn]), array('class' => 'list-group-item'))); } $infopanel->addItem($usedBy); } $contact = new IEContact(); $hostNotify = $contact->getColumnsFromMySQL(array($contact->getMyKeyColumn(), $contact->nameColumn), array('host_notification_commands' => '%' . $command->getName() . '%'), $contact->nameColumn, $contact->getMyKeyColumn()); $serviceNotify = $contact->getColumnsFromMySQL(array($contact->getMyKeyColumn(), $contact->nameColumn), array('service_notification_commands' => '%' . $command->getName() . '%'), $contact->nameColumn, $contact->getMyKeyColumn()); $usages = array_merge($hostNotify, $serviceNotify); if (count($usages)) { $usedBy = new EaseTWBPanel(_('Používající kontakty'));
} if (!$addressSix) { $addressSix = gethostbyname6($hostName); } $oUser->addStatusMessage('HostName: ' . $hostName); $oUser->addStatusMessage('Address: ' . $address); $oUser->addStatusMessage('Address6: ' . $addressSix); $host->setData(array($host->userColumn => $oUser->getUserID(), 'host_name' => $hostName, 'address' => $address, 'address6' => $addressSix, 'use' => 'generic-host', 'platform' => $platform, 'register' => true, 'generate' => TRUE, 'alias' => $hostName, 'active_checks_enabled' => 1, 'passive_checks_enabled' => 0)); if ($host_group) { $hostgroup = new IEHostgroup($host_group); $host->addMember('hostgroups', $hostgroup->getId(), $hostgroup->getName()); $hostgroup->addMember('members', $host->getId(), $host->getName()); $hostgroup->saveToMySQL(); } if ($host->saveToMysql()) { $service = new IEService('PING'); $service->addMember('host_name', $host->getId(), $host->getName()); $service->saveToMySQL(); $host->autoPopulateServices(); $hostGroup = new IEHostgroup(); if ($hostGroup->loadDefault()) { $hostGroup->setDataValue($hostGroup->nameColumn, EaseShared::user()->getUserLogin()); $hostGroup->addMember('members', $host->getId(), $host->getName()); $hostGroup->saveToMySQL(); $host->addMember('hostgroups', $hostGroup->getId(), $hostGroup->getName()); $host->saveToMysql(); } $oPage->redirect('host.php?host_id=' . $host->getId()); exit; } }
* @subpackage WebUI * @author Vitex <*****@*****.**> * @copyright 2012 Vitex@hippy.cz (G) */ require_once 'includes/IEInit.php'; $oPage->onlyForLogged(); $oPage->addPageColumns(); $userID = $oPage->getRequestValue('user_id', 'int'); if ($userID) { $oPage->onlyForAdmin(); } $host = new IEHost(); $hostgroup = new IEHostgroup(); $contact = new IETimeperiod(); $command = new IECommand(); $service = new IEService(); $serviceGroup = new IEServicegroup(); $ownership = $oPage->getRequestValue('ownership'); if ($ownership) { $host->switchOwners($userID, $ownership); $hostgroup->switchOwners($userID, $ownership); $contact->switchOwners($userID, $ownership); $command->switchOwners($userID, $ownership); $service->switchOwners($userID, $ownership); $serviceGroup->switchOwners($userID, $ownership); $oPage->addStatusMessage(_('Vlastnictví byla předána')); } $user = new IEUser($userID); $oPage->addItem(new IEPageTop($user->getUserName())); if ($oPage->getRequestValue('delete') == 'true') { if ($user->delete()) {
<?php /** * Icinga Editor služby * * @package IcingaEditor * @subpackage WebUI * @author Vitex <*****@*****.**> * @copyright 2012 Vitex@hippy.cz (G) */ require_once 'includes/IEInit.php'; $oPage->onlyForLogged(); $service = new IEService($oPage->getRequestValue('service_id', 'int')); $host = new IEHost($oPage->getRequestValue('host_id', 'int')); switch ($oPage->getRequestValue('action')) { case 'clone': $service->setDataValue('parent_id', $service->getId()); $service->unsetDataValue($service->getmyKeyColumn()); $service->addMember('host_name', $host->getId(), $host->getName()); $service->setDataValue('hostgroup_name', array()); $service->setDataValue('user_id', $oUser->getID()); $service->setDataValue($service->nameColumn, _('Klon') . ' ' . $service->getName()); if ($service->saveToMySQL()) { $oUser->addStatusMessage(_('Služba byla naklonována'), 'success'); $oPage->redirect('servicetweak.php?service_id=' . $service->getId() . '&host_id=' . $host->getId()); } else { $oUser->addStatusMessage(_('Sužba nebyla naklonována'), 'warning'); } break; case 'rename': $newname = $oPage->getRequestValue('newname');
* * @package IcingaEditor * @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;
/** * 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'); } } } } } }
/** * Vrací hash vypočítaný z aktuální konfigurace hosta */ function getConfigHash() { $configuration = array(); $service = new IEService(); $servicesAssigned = $service->myDbLink->queryToArray('SELECT `' . $service->getmyKeyColumn() . '` FROM ' . $service->myTable . ' WHERE host_name LIKE \'%"' . $this->getName() . '"%\'', $service->myKeyColumn); foreach ($servicesAssigned as $serviceAssigned) { $service->loadFromSQL((int) $serviceAssigned[$service->myKeyColumn]); $service->unsetDataValue('display_name'); //Položky které se mohou měnit bez nutnosti aktualizovat senzor $service->unsetDataValue('service_description'); $service->unsetDataValue('host_name'); $service->unsetDataValue('hostgroup_name'); $service->unsetDataValue('notes'); $service->unsetDataValue('notes_url'); $service->unsetDataValue('action_url'); $service->unsetDataValue('icon_image'); $service->unsetDataValue('icon_image_alt'); $service->unsetDataValue('public'); $service->unsetDataValue('user_id'); $service->unsetDataValue($service->myLastModifiedColumn); $configuration[] = $service->getEffectiveCfg(); } return hash('md5', $this->getName() . serialize($configuration)); }
* * @package IcingaEditor * @subpackage WebUI * @author Vitex <*****@*****.**> * @copyright 2012 Vitex@hippy.cz (G) */ require_once 'includes/IEInit.php'; require_once 'classes/IEServiceWizardForm.php'; require_once 'classes/IEServicegroup.php'; $oPage->onlyForLogged(); $serviceId = $oPage->getRequestValue('service_id', 'int'); $serviceName = trim($oPage->getRequestValue('service_name')); $remoteCmd = trim($oPage->getRequestValue('check_command-remote')); $remoteCmdParam = trim($oPage->getRequestValue('check_command-params')); $platform = trim($oPage->getRequestValue('platform')); $service = new IEService($serviceId); $service->owner =& $oUser; if (isset($platform)) { $service->setDataValue('platform', $platform); } if ($serviceName) { $data = array($service->userColumn => $oUser->getUserID(), 'service_description' => $serviceName, 'use' => 'generic-service', 'register' => true, 'generate' => true, 'display_name' => $serviceName, 'active_checks_enabled' => 0, 'passive_checks_enabled' => 1, 'check_freshness' => 1, 'check_command' => 'return-unknown'); if (isset($remoteCmd)) { $data['check_command-remote'] = $remoteCmd; } if (isset($remoteCmdParam)) { $data['check_command-params'] = $remoteCmdParam; } $service->setData($data); if ($service->saveToMysql()) { /*
/** * 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'); } }
/** * Přehodí * @param type $swapToID * @return boolean */ public function swapTo($swapToID) { $newService = new IEService($swapToID); $thisName = $this->getName(); $hostsOK = array(); $hostsErr = array(); $hostsAssigned = array(); $host = new IEHost(); if (EaseShared::user()->getSettingValue('admin')) { $allHosts = $host->getAllFromMySQL(NULL, array($host->myKeyColumn, $host->nameColumn, 'platform', 'register'), null, $host->nameColumn, $host->myKeyColumn); } else { $allHosts = $host->getListing(null, true, array('platform', 'register')); } $hosts = $this->getDataValue('host_name'); foreach ($hosts as $hostId => $hostName) { if (isset($allHosts[$hostId])) { $hostsAssigned[$hostId] = $allHosts[$hostId]; } } foreach ($hostsAssigned as $host_id => $hostAssigned) { if ($this->delMember('host_name', $host_id, $hostAssigned['host_name']) && $newService->addMember('host_name', $host_id, $hostAssigned['host_name'])) { $hostsOK[] = $hostAssigned['host_name']; } else { $hostsErr[] = $hostAssigned['host_name']; } } if ($this->saveToMySQL() && $newService->saveToMySQL() && count($hostsOK)) { $this->addStatusMessage(sprintf(_('%s byl přesunut z %s/%s do %s'), implode(',', $hostsOK), $this->keyword, $this->getName(), $newService->getName()), 'success'); return true; } else { $this->addStatusMessage(sprintf(_(' %s nebyl přesunut z %s/%s do %s'), implode(',', $hostsErr), $this->keyword, $this->getName(), $newService->getName()), 'warning'); return false; } }
$confirmator = $form->addItem(new EaseTWBPanel(_('Opravdu smazat ?')), 'danger'); $confirmator->addItem(new EaseTWBLinkButton('?' . $contact->myKeyColumn . '=' . $contact->getID(), _('Ne') . ' ' . EaseTWBPart::glyphIcon('ok'), 'success')); $confirmator->addItem(new EaseTWBLinkButton('?delete=true&' . $contact->myKeyColumn . '=' . $contact->getID(), _('Ano') . ' ' . EaseTWBPart::glyphIcon('remove'), 'danger')); break; default: $contactEdit = new IECfgEditor($contact); $form = new EaseHtmlForm('Contact', 'contact.php', 'POST', $contactEdit, array('class' => 'form-horizontal')); $form->setTagID($form->getTagName()); if (!is_null($contact->getMyKey())) { $form->addItem(new EaseHtmlInputHiddenTag($contact->getmyKeyColumn(), $contact->getMyKey())); } $form->addItem('<br>'); $form->addItem(new EaseTWSubmitButton(_('Uložit'), 'success')); break; } $service = new IEService(); $serviceUsages = $service->getColumnsFromMySQL(array($service->getMyKeyColumn(), $service->nameColumn), array('contacts' => '%' . $contact->getName() . '%'), $service->nameColumn, $service->getMyKeyColumn()); $oPage->addItem(new IEPageBottom()); $infopanel = new IEInfoBox($contact); $tools = new EaseTWBPanel(_('Nástroje'), 'warning'); if ($contact->getId()) { $tools->addItem($contact->deleteButton()); $tools->addItem(new EaseTWBPanel(_('Transfer'), 'warning', $contact->transferForm())); if (count($serviceUsages)) { $usedBy = new EaseTWBPanel(_('Používaný službami')); $listing = $usedBy->addItem(new EaseHtmlUlTag(null, array('class' => 'list-group'))); foreach ($serviceUsages as $usage) { $listing->addItem(new EaseHtmlLiTag(new EaseHtmlATag('service.php?service_id=' . $usage['service_id'], $usage[$service->nameColumn]), array('class' => 'list-group-item'))); } $infopanel->addItem($usedBy); }
/** * Vrací porty služeb k dispozici */ public function getServicePorts() { $ports = $this->service->getColumnsFromMySQL('tcp_port', 'tcp_port IS NOT NULL AND public = 1', 'tcp_port', 'tcp_port'); return array_keys($ports); }
<?php /** * Icinga Editor služby * * @package IcingaEditor * @subpackage WebUI * @author Vitex <*****@*****.**> * @copyright 2012 Vitex@hippy.cz (G) */ require_once 'includes/IEInit.php'; require_once 'classes/IEService.php'; $service = new IEService($oPage->getRequestValue('service_id', 'int')); $oPage->addItem(new IEPageTop(_('Migrace služby') . ' ' . $service->getName())); $oPage->addPageColumns(); $oPage->columnII->addItem(new EaseHtmlH3Tag(array(new IEPlatformIcon($service->getDataValue('platform')), $service->getName()))); $form = $oPage->columnII->addItem(new EaseTWBForm('Service', 'importer.php?class=service', 'POST')); $form->setTagID($form->getTagName()); if (!is_null($service->getMyKey())) { $form->addItem(new EaseHtmlInputHiddenTag($service->getMyKeyColumn(), $service->getMyKey())); } $form->addItem('<br>'); foreach ($service->data as $key => $value) { if (is_null($value)) { continue; } if (is_array($value)) { $form->addItem(new EaseHtmlTextareaTag($key, serialize($value))); } else { $form->addItem(new EaseHtmlInputTextTag($key, $value)); }
/** * Vložení menu */ public function afterAdd() { $nav = $this->addItem(new IEBootstrapMenu()); $user = EaseShared::user(); $userID = $user->getUserID(); if ($userID) { //Authenticated user $nav->addMenuItem(new IENavBarSearchBox('search', 'search.php')); if ($user->getSettingValue('admin')) { $users = $user->getColumnsFromMySQL(array('id', 'login'), array('id' => '!0'), 'login', $user->getmyKeyColumn()); $userList = array(); if ($users) { foreach ($users as $uID => $uInfo) { $userList['userinfo.php?user_id=' . $uInfo['id']] = EaseTWBPart::GlyphIcon('user') . ' ' . $uInfo['login']; } if (count($userList)) { $userList[] = ''; } } // $usergroups = $this->myDbLink->queryToArray('SELECT * FROM user_groups' . 'usergroup_id'); $nav->addDropDownMenu(_('Uživatelé'), array_merge($userList, array('createaccount.php' => EaseTWBPart::GlyphIcon('plus') . ' ' . _('Nový uživatel'), 'users.php' => EaseTWBPart::GlyphIcon('list') . ' ' . _('Přehled uživatelů'), 'usergroup.php' => EaseTWBPart::GlyphIcon('plus') . ' ' . _('Nová skupina uživatelů'), 'usergroups.php' => EaseTWBPart::GlyphIcon('list') . ' ' . _('Přehled skupin uživatelů')))); } $this->changesButton($nav); $this->groupsHostsMenu($nav); // $nav->addDropDownMenu(_('Hosti'), $hostGroupHostsMenuItem); if (EaseShared::user()->getSettingValue('admin')) { $nav->addDropDownMenu(_('Služby'), array('wizard-service.php' => EaseTWBPart::GlyphIcon('forward') . ' ' . _('Průvodce založením služby'), 'service.php' => EaseTWBPart::GlyphIcon('plus') . ' ' . _('Nová služba'), 'services.php' => EaseTWBPart::GlyphIcon('list') . ' ' . _('Přehled služeb'), 'servicegroup.php' => EaseTWBPart::GlyphIcon('plus') . ' ' . _('Nová skupina služeb'), 'servicegroups.php' => EaseTWBPart::GlyphIcon('list') . ' ' . _('Přehled skupin služeb'), '' => '', 'stemplate.php?action=new' => EaseTWBPart::GlyphIcon('plus') . ' ' . _('Nová předloha sledované služby'), 'stemplates.php' => EaseTWBPart::GlyphIcon('list') . ' ' . _('Přehled předloh sled. sl.'))); } else { $service = new IEService(); $services = $service->getListing(null, null, array('icon_image', 'platform')); if (count($services)) { $services_menu = array('services.php' => EaseTWBPart::GlyphIcon('list') . ' ' . _('Přehled služeb')); foreach ($services as $serviceID => $serviceInfo) { $services_menu['servicetweak.php?service_id=' . $serviceID] = $serviceInfo[$service->nameColumn]; } $nav->addDropDownMenu(_('Služby'), $services_menu); } } $contact = new IEContact(); $contacts = $contact->getListing(null, null, array('parent_id')); foreach ($contacts as $contactID => $contactInfo) { //Vyfiltrovat pouze primární kontakty if ($contactInfo['parent_id']) { unset($contacts[$contactID]); } } if (count($contacts)) { $contacts_menu = array('contacts.php' => EaseTWBPart::GlyphIcon('list') . ' ' . _('Přehled Kontaktů')); foreach ($contacts as $contactID => $contactInfo) { $contacts_menu['contacttweak.php?contact_id=' . $contactID] = $contactInfo[$contact->nameColumn]; } $contacts_menu[] = ''; } else { $contacts_menu = array(); } $nav->addDropDownMenu(_('Kontakty'), array_merge($contacts_menu, array('contacts.php' => EaseTWBPart::GlyphIcon('list') . ' ' . _('Přehled kontaktů'), 'newcontact.php' => EaseTWBPart::GlyphIcon('plus') . ' ' . _('Nový kontakt'), 'contactgroups.php' => EaseTWBPart::GlyphIcon('list') . ' ' . _('Přehled skupin kontaktů'), 'contactgroup.php' => EaseTWBPart::GlyphIcon('edit') . ' ' . _('Nová skupina kontaktů')))); if ($user->getSettingValue('admin')) { $nav->addDropDownMenu(_('Příkaz'), array('command.php' => EaseTWBPart::GlyphIcon('edit') . ' ' . _('Nový příkaz'), 'commands.php' => EaseTWBPart::GlyphIcon('list-alt') . ' ' . _('Přehled příkazů'), 'importcommand.php' => EaseTWBPart::GlyphIcon('import') . ' ' . _('Importovat'), '', 'script.php' => EaseTWBPart::GlyphIcon('edit') . ' ' . _('Nový skript'), 'scripts.php' => EaseTWBPart::GlyphIcon('list-alt') . ' ' . _('Přehled skriptů'))); $nav->addDropDownMenu(_('Rozšířené'), array('timeperiods.php' => EaseTWBPart::GlyphIcon('list') . ' ' . _('Přehled časových period'), 'timeperiod.php' => EaseTWBPart::GlyphIcon('plus') . ' ' . _('Nová časová perioda'), 'preferences.php' => EaseTWBPart::GlyphIcon('wrench') . ' ' . _('Nastavení icingy'), 'regenall.php' => EaseTWBPart::GlyphIcon('ok') . ' ' . _('Přegenerovat všechny konfiguráky'), 'reset.php' => EaseTWBPart::GlyphIcon('cog') . ' ' . _('Reset Objektů'), 'dbrecreate.php' => EaseTWBPart::GlyphIcon('wrench') . ' ' . _('Reinicializovat databázi'), 'fixer.php' => EaseTWBPart::GlyphIcon('ok-circle') . ' ' . _('Opravit databázi'), 'import.php' => EaseTWBPart::GlyphIcon('import') . ' ' . _('Importovat'))); } $results = array('nagstamon.php' => EaseTWBPart::GlyphIcon('info') . ' ' . _('PC Lin/Win/Mac'), 'anag.php' => EaseTWBPart::GlyphIcon('info') . ' ' . _('Android'), 'wpnag.php' => EaseTWBPart::GlyphIcon('Info') . ' ' . _('Win Phone')); if (file_exists('/etc/apache2/conf-enabled/icinga-web.conf')) { $results['/icinga-web/'] = EaseTWBPart::GlyphIcon('Info') . ' ' . _('Web'); } $nav->addDropDownMenu(_('Výsledky testů'), $results); } }