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') . '&nbsp' . EaseTWBPart::GlyphIcon('forward'), 'success'));
     $serviceId = $this->service->getId();
     if ($serviceId) {
         $this->addItem(new EaseHtmlInputHiddenTag('service_id', $serviceId));
     }
 }
 /**
  * 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'] . '&amp;service_id=' . $holder->getId(), EaseTWBPart::GlyphIcon('wrench') . ' ' . _('Editace')), new EaseHtmlATag('?addcontact=' . $contactInfo[$contact->nameColumn] . '&amp;contact_id=' . $contactID . '&amp;' . $holder->getmyKeyColumn() . '=' . $holder->getMyKey() . '&amp;' . $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] . '&amp;contact_id=' . $contactID . '&amp;' . $holder->getmyKeyColumn() . '=' . $holder->getMyKey() . '&amp;' . $holder->nameColumn . '=' . $holder->getName(), EaseTWBPart::GlyphIcon('remove') . ' ' . _('Přestat obesílat')), new EaseHtmlATag('contacttweak.php?contact_id=' . $contactInfo['parent_id'] . '&amp;service_id=' . $holder->getId(), EaseTWBPart::GlyphIcon('wrench') . ' ' . _('Editace')))));
             }
         }
     }
     $this->addItem($initialContent);
 }
 /**
  * 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;
 }
示例#5
0
<?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));
    }
示例#6
0
 /**
  * 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);
 }
示例#7
0
 /**
  * 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;
 }
示例#8
0
 * @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');
        if (strlen($newname)) {
            if ($service->rename($newname)) {
                $oUser->addStatusMessage(_('Služba byla přejmenována'), 'success');
            } else {
                $oUser->addStatusMessage(_('Sužba nebyla přejmenována'), 'warning');
            }
示例#9
0
 /**
  * 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;
     }
 }
示例#10
0
 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();
             }
         }
     }
 }
示例#11
0
     $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'));
     break;
 default:
     if ($oPage->isPosted()) {
         if ($oPage->getRequestValue('action') != 'rename') {