Пример #1
0
 * @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'));
$fileForm->addInput(new EaseHtmlTextareaTag('cfgtext', ''), _('konfigurační fragment'));
$fileForm->addInput(new EaseHtmlInputFileTag('cfgfile', null), _('konfigurační soubor'));
$typeSelector = new EaseHtmlSelect('type', 'check');
$typeSelector->addItems(array('check' => 'check', 'notify' => 'notify', 'handler' => 'handler'));
$fileForm->addInput($typeSelector, _('druh vkládaných příkazů'));
$fileForm->addItem(new EaseTWSubmitButton(_('importovat'), 'success'));
$oPage->container->addItem(new EaseTWBPanel(_('Import příkazu do konfigurace'), 'success', $fileForm));
 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');
         }
     }
 }
Пример #3
0
 * @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');
            }
        }
}
$delete = $oPage->getGetValue('delete', 'bool');
if ($delete == 'true') {
    $command->delete();
}
$oPage->addItem(new IEPageTop(_('Editace příkazu') . ' ' . $command->getName()));