/**
  * Pokus o zjistenu parametru prikazu
  */
 public function discoveryParams()
 {
     $cmdline = $this->command->getDataValue('command_line');
     $this->addItem('<br>' . $cmdline);
     $params = array();
     $parts = array_reverse(explode(' ', $cmdline));
     $checkCmd = end($parts);
     foreach ($parts as $cmdPartID => $cmdPart) {
         if (strstr($cmdPart, 'ARG')) {
             $params[substr($cmdPart, 5, 1)] = $parts[$cmdPartID + 1][1];
         }
     }
     $handle = popen($checkCmd . ' --help 2>&1', 'r');
     $help = '';
     while (!feof($handle)) {
         $help .= fread($handle, 2096);
     }
     pclose($handle);
     $helplines = explode("\n", $help);
     $options = array();
     foreach ($helplines as $hip => $helpline) {
         $helpline = trim($helpline);
         if (strlen($helpline) && $helpline[0] == '-') {
             $options[$helpline[1]] = trim($helplines[$hip + 1]);
         }
     }
     $this->addItem($this->printPre($params));
     $this->addItem($this->printPre($options));
     $twform = new EaseTWBForm('servtweak');
     foreach ($params as $id => $key) {
         if (isset($options[$key])) {
             $twform->addItem(new EaseTWBFormGroup('arg' . $id, new EaseHtmlInputTextTag($options[$key], ''), null, $options[$key]));
         }
     }
     $this->addItem($twform);
 }
 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');
         }
     }
 }
Example #3
0
        $scriptEditor = new IECfgEditor($script);
        $form = new EaseTWBForm('Script', 'script.php', 'POST', $scriptEditor, array('class' => 'form-horizontal'));
        if (!$script->getId()) {
            $form->addItem(new EaseTWSubmitButton(_('Založit'), 'success'));
        } else {
            $form->addItem(new EaseTWSubmitButton(_('Uložit'), 'success'));
        }
        break;
}
$oPage->addItem(new IEPageBottom());
$infopanel = new IEInfoBox($script);
$tools = new EaseTWBPanel(_('Nástroje'), 'warning');
if ($script->getId()) {
    $tools->addItem($script->deleteButton());
    $tools->addItem(new EaseTWBPanel(_('Transfer'), 'warning', $script->transferForm()));
    $command = new IECommand();
    $usages = $command->getColumnsFromMySQL(array($command->getMyKeyColumn(), $command->nameColumn), array('script_id' => $command->getId()), $command->nameColumn, $command->getMyKeyColumn());
    if (count($usages)) {
        $usedBy = new EaseTWBPanel(_('Používající příkazy'));
        $listing = new EaseHtmlUlTag(null, array('class' => 'list-group'));
        foreach ($usages as $usage) {
            if (!isset($usage[$command->nameColumn])) {
                $usage[$command->nameColumn] = 'n/a';
            }
            $listing->addItem(new EaseHtmlLiTag(new EaseHtmlATag('command.php?command_id=' . $usage['command_id'], $usage[$command->nameColumn]), array('class' => 'list-group-item')));
        }
        EaseContainer::addItemCustom($listing, $usedBy);
        $infopanel->addItem($usedBy);
    }
}
$pageRow = new EaseTWBRow();
Example #4
0
    if ($pocTimeperiods) {
        $warning = $oPage->columnI->addItem(new EaseHtmlDivTag('Host', _('Nemáte definovaný žádný host'), array('class' => 'alert alert-info')));
        $warning->addItem(new EaseTWBLinkButton('host.php', _('Založit první host') . ' ' . EaseTWBPart::GlyphIcon('edit')));
    } else {
        $warning = $oPage->columnI->addItem(new EaseHtmlDivTag('Host', _('Hosty vyžadují časovou periodu ..'), array('class' => 'alert alert-danger')));
    }
}
$hostgroup = new IEHostgroup();
$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')));
Example #5
0
 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;
     }
 }
<?php

/**
 * Import ze souboru
 *
 * @package    IcingaEditor
 * @subpackage WebUI
 * @author     Vitex <*****@*****.**>
 * @copyright  2012 Vitex@hippy.cz (G)
 */
require_once 'includes/IEInit.php';
if ($oPage->isPosted()) {
    $importer = new IECommand();
    $success = 0;
    $cfgText = $oPage->getRequestValue('cfgtext');
    if ($cfgText) {
        $success += $importer->importText($cfgText, array('command_type' => $oPage->getRequestValue('type')));
    }
    if (isset($_FILES['cfgfile']['tmp_name']) && strlen(trim($_FILES['cfgfile']['tmp_name']))) {
        $success += $importer->importFile($_FILES['cfgfile']['tmp_name'], array('command_type' => $oPage->getRequestValue('type')));
    }
    if ($success) {
        $oPage->addStatusMessage(sprintf(_('Příkaz %s byl naimportován'), $importer->getName()), 'success');
    } else {
        $oPage->addStatusMessage(_('Příkaz nebyl naimportován'), 'warning');
    }
} else {
    $oPage->addStatusMessage(_('Zadejte konfigurační fragment příkazu, nebo zvolte soubor k importu'));
}
$oPage->addItem(new IEPageTop(_('Načtení příkazů ze souboru')));
$fileForm = new EaseTWBForm('CfgFileUp', null, 'POST', null, array('class' => 'form-horizontal', 'enctype' => 'multipart/form-data'));
Example #7
0
        unset($allServices[$serviceID]);
        continue;
    }
    if (!$servicePassive) {
        unset($allServices[$serviceID]);
        continue;
    }
}
/* 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) {
Example #8
0
<?php

/**
 * Icinga Editor - titulní strana
 *
 * @package    IcingaEditor
 * @subpackage WebUI
 * @author     Vitex <*****@*****.**>
 * @copyright  2012 Vitex@hippy.cz (G)
 */
require_once 'includes/IEInit.php';
$oPage->onlyForLogged();
$command = new IECommand($oPage->getRequestValue('command_id', 'int'));
switch ($oPage->getRequestValue('action')) {
    case 'export':
        $command->transfer($oPage->getRequestValue('destination'));
        break;
    default:
        if ($oPage->isPosted()) {
            $command->takeData($_POST);
            if (!$command->getName()) {
                $oUser->addStatusMessage(_('Není zadán název'), 'warning');
            }
            $commandID = $command->saveToMySQL();
            if (is_null($commandID)) {
                $oUser->addStatusMessage(_('Příkaz nebyl uložen'), 'warning');
            } else {
                $oUser->addStatusMessage(_('Příkaz byl uložen'), 'success');
            }
        }
}
Example #9
0
 * @package    IcingaEditor
 * @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') {
 /**
  * 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);
     }
 }