/**
  * vrací vyrendrovaný konfigurační skript
  *
  * @param boolean $send Přidat HTTP hlavičku pro odeslání souboru
  * @return string BAT soubor
  */
 public function getCfg($send = TRUE)
 {
     $nscbat = implode('', $this->nscBatArray);
     if ($send) {
         header('Content-Description: File Transfer');
         header('Content-Type: application/octet-stream');
         header('Content-Transfer-Encoding: binary');
         header('Expires: 0');
         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
         header('Pragma: public');
     }
     switch ($this->platform) {
         case 'windows':
             if ($send) {
                 header('Content-Disposition: attachment; filename=' . $this->host->getName() . '_nscp.bat');
             }
             $nscbat = str_replace("\n", "\r\n", $nscbat);
             break;
         case 'linux':
             if ($send) {
                 header('Content-Disposition: attachment; filename=' . $this->host->getName() . '_nscp.sh');
             }
             break;
         default:
             break;
     }
     if ($send) {
         header('Content-Length: ' . strlen($nscbat));
         echo $nscbat;
     } else {
         return $nscbat;
     }
 }
Ejemplo n.º 2
0
/**
 * Formulář cíle cesty pro hosta
 * @param IEHost $host
 * @return \EaseTWBPanel
 */
function endRouteForm($host)
{
    $form = new EaseTWBForm('traceto');
    $form->addInput(new IEHostSelect('dest_host_id'), _('Gateway'), null, _('Zvolte již definovanou gateway, nabo zadejte konkrétní adresu.'));
    $form->addInput(new EaseHtmlInputTextTag('ip'), _('IP Adresa'), null, _('První pingnutelná veřejá adresa po cestě z hostu na monitorovací server'));
    $form->addItem(new EaseTWSubmitButton(_('Sledovat cestu'), 'success', array('onClick' => "\$('#preload').css('visibility', 'visible');")));
    EaseShared::webPage()->addItem(new EaseHtmlDivTag('preload', new IEFXPreloader(), array('class' => 'fuelux')));
    return new EaseTWBPanel(_('Volba cíle sledování') . ': ' . $host->getName(), 'default', $form, _('Vyberte hosta nebo zadejte IP adresu'));
}
Ejemplo n.º 3
0
 /**
  * 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] . '&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);
 }
Ejemplo n.º 4
0
 /**
  * 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;
 }
 /**
  * vrací vyrendrovaný konfigurační skript
  */
 public function getCfg($send = TRUE)
 {
     $nrpesh = implode("\n", $this->nscCfgArray);
     if ($send) {
         header('Content-Description: File Transfer');
         header('Content-Type: application/octet-stream');
         header('Content-Transfer-Encoding: binary');
         header('Expires: 0');
         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
         header('Pragma: public');
         header('Content-Disposition: attachment; filename=' . $this->host->getName() . '_nrpe.sh');
         header('Content-Length: ' . strlen($nrpesh));
         echo $nrpesh;
     } else {
         return $nrpesh;
     }
 }
Ejemplo n.º 6
0
 /**
  * Smaže hostgrupu i její použití v hostech
  *
  * @param int $id
  * @return boolean
  */
 function delete($id = null)
 {
     if (isset($id) && $this->getId() != $id) {
         $this->loadFromSQL($id);
     } else {
         $id = $this->getId();
     }
     $host = new IEHost();
     $hosts = $host->getColumnsFromMySQL(array($host->myKeyColumn), array('hostgroups' => '%' . $this->getName() . '%'));
     foreach ($hosts as $hostInfo) {
         $hostId = intval(current($hostInfo));
         $host->loadFromMySQL($hostId);
         $hostgroupNames = $host->getDataValue('hostgroups');
         if ($hostgroupNames) {
             foreach ($hostgroupNames as $hostgroupId => $hostgroupName) {
                 if ($hostgroupId == $this->getId()) {
                     if ($host->delMember('hostgroups', $hostgroupId, $hostgroupName)) {
                         $this->addStatusMessage(sprintf(_('host %s byl odstraněn ze skupiny %s'), $host->getName(), $hostgroupName), 'success');
                     } else {
                         $this->addStatusMessage(sprintf(_('host %s byl odstraněn ze skupiny %s'), $host->getName(), $hostgroupName), 'error');
                     }
                 }
             }
         }
     }
     $subgroup = new IEHostgroup();
     $subgroups = $subgroup->getColumnsFromMySQL(array($subgroup->myKeyColumn), array('hostgroup_members' => '%' . $this->getName() . '%'));
     foreach ($subgroups as $subgroupInfo) {
         $subgroupId = intval(current($subgroupInfo));
         $subgroup->loadFromMySQL($subgroupId);
         $subgroupgroupNames = $subgroup->getDataValue('hostgroup_members');
         if ($subgroupgroupNames) {
             foreach ($subgroupgroupNames as $subgroupgroupId => $subgroupgroupName) {
                 if ($subgroupgroupId == $this->getId()) {
                     if ($subgroup->delMember('hostgroup_members', $subgroupgroupId, $subgroupgroupName)) {
                         $this->addStatusMessage(sprintf(_('subgroup %s byl odstraněn ze skupiny %s'), $subgroup->getName(), $subgroupgroupName), 'success');
                     } else {
                         $this->addStatusMessage(sprintf(_('subgroup %s byl odstraněn ze skupiny %s'), $subgroup->getName(), $subgroupgroupName), 'error');
                     }
                 }
             }
         }
     }
     return parent::delete($id);
 }
Ejemplo n.º 7
0
 /**
  * Připraví podřízenu službu
  *
  * @param  IEHost $host
  * @param  int    $ownerId
  * @return int    ID nově vytvořené služby
  */
 public function fork($host, $ownerId = null)
 {
     if (is_null($ownerId)) {
         $ownerId = EaseShared::user()->getUserID();
     }
     $this->delMember('host_name', $host->getId(), $host->getName());
     $this->saveToMySQL();
     $this->setDataValue('parent_id', $this->getId());
     $this->unsetDataValue($this->getmyKeyColumn());
     $this->setDataValue('public', 0);
     $this->unsetDataValue('tcp_port');
     $this->unsetDataValue('DatSave');
     $this->unsetDataValue('DatCreate');
     $this->setDataValue('action_url', $_SERVER['REQUEST_URI']);
     $this->setDataValue($this->userColumn, $ownerId);
     $this->setDataValue('contacts', $host->owner->getFirstContact());
     $newname = $this->getName() . ' ' . $host->getName();
     $servcount = $this->myDbLink->queryToCount('SELECT ' . $this->getmyKeyColumn() . ' FROM ' . $this->myTable . ' WHERE ' . $this->nameColumn . ' LIKE \'' . $newname . '%\' ');
     if ($servcount) {
         $newname .= ' ' . ($servcount + 1);
     }
     $this->setDataValue($this->nameColumn, $newname);
     $this->setDataValue('host_name', array());
     $this->addMember('host_name', $host->getId(), $host->getName());
     return $this->saveToMySQL();
 }
Ejemplo n.º 8
0
 /**
  * Stav senzoru a jeho nastavení
  *
  * @param IEHost $host
  */
 public function __construct($host)
 {
     $commonWell = new EaseTWBWell();
     $commonRow = new EaseTWBRow();
     $hostColumn = $commonRow->addColumn(6, new EaseHtmlATag('host.php?host_id=' . $host->getId(), new EaseHtmlH1Tag($host->getName())));
     $hostColumn->addItem($host);
     $hostColumn->addItem($host->sensorStatusLabel());
     $commonWell->addItem($commonRow);
     $commonRow->addColumn(4, new EaseTWBPanel(_('Ruční nastavení stavu senzoru'), 'info', new IESensorConfirmForm($host)));
     $sensorTabs = new EaseTWBTabs('sensorTabs');
     switch ($host->getDataValue('platform')) {
         case 'windows':
             $pltIco = 'logos/base/win40.gif';
             $cfgGenerator = new IENSCPConfigGenerator($host);
             if ($host->getCfgValue('active_checks_enabled')) {
                 $windowsActiveTab = $sensorTabs->addTab(_('Windows NRPE'));
                 $windowsActiveTab->addItem(new EaseHtmlH1Tag('<img src="' . $pltIco . '">' . _('aktivní NRPE pro NSC++')));
                 $windowsActiveTab->addItem(new EaseTWBLinkButton('http://www.nsclient.org/download/', ' NSC++ ' . EaseTWBPart::GlyphIcon('download'), 'success', array('style' => "background-image:url('img/nscpp.png'); width: 212px; height: 60px; ", 'title' => 'Download')));
                 $windowsActiveTab->addItem(new EaseTWBLinkButton('host.php?action=populate&host_id=' . $host->getID(), _('Oskenovat a sledovat služby'), null, array('onClick' => "\$('#preload').css('visibility', 'visible');")));
                 $windowsActiveTab->addItem(new EaseTWBLinkButton('nscpcfggen.php?host_id=' . $host->getId(), $host->getName() . '_nscp.bat ' . EaseTWBPart::GlyphIcon('download'), 'success'));
                 $windowsActiveTab->addItem(new EaseTWBContainer('<pre>' . htmlspecialchars($cfgGenerator->getCfg(false)) . '</pre>', array('font-face' => 'fixed')));
             }
             if ($host->getCfgValue('passive_checks_enabled')) {
                 $windowsPassiveTab = $sensorTabs->addTab(_('Windows NSCA'));
                 $windowsPassiveTab->addItem(new EaseHtmlH1Tag('<img src="' . $pltIco . '">' . _('pasivní NSCA pro NSC++')));
                 $windowsPassiveTab->addItem(new EaseTWBLinkButton('http://www.nsclient.org/download/', ' NSC++ ' . EaseTWBPart::GlyphIcon('download'), 'success', array('style' => "background-image:url('img/nscpp.png'); width: 212px; height: 60px; ", 'title' => 'Download')));
                 $windowsPassiveTab->addItem(new EaseTWBLinkButton('nscpcfggen.php?host_id=' . $host->getId(), $host->getName() . '_nscp.bat ' . EaseTWBPart::GlyphIcon('download'), 'success'));
                 $windowsPassiveTab->addItem(new EaseTWBWell('<pre>' . htmlspecialchars($cfgGenerator->getCfg(false), ENT_QUOTES) . '</pre>', array('font-face' => 'fixed')));
             }
             break;
         case 'linux':
             $pltIco = 'logos/base/linux40.gif';
             $preferences = new IEPreferences();
             $prefs = $preferences->getPrefs();
             if ($host->getCfgValue('active_checks_enabled')) {
                 $nrpe_cfgGenerator = new IENRPEConfigGenerator($host);
                 $linuxActiveTab = $sensorTabs->addTab(_('Linux NRPE'));
                 $linuxActiveTab->addItem(new EaseHtmlH1Tag('<img src="' . $pltIco . '">' . _('aktivní NRPE pro NRPE Server')));
                 $linuxActiveTab->addItem(new EaseHtmlPTag(_('Nainstalujte nejprve senzor tímto příkazem') . ':'));
                 $linuxActiveTab->addItem(new EaseHtmlDiv('<pre>sudo aptitude -y install nagios-nrpe-server</pre>', array('class' => 'code')));
                 $linuxActiveTab->addItem(new EaseTWBLinkButton('nrpecfggen.php?host_id=' . $host->getId(), $host->getName() . '_nrpe.sh ' . EaseTWBPart::GlyphIcon('download'), 'success'));
                 $linuxActiveTab->addItem(new EaseTWBContainer('<pre>' . htmlspecialchars($nrpe_cfgGenerator->getCfg(false)) . '</pre>', array('font-face' => 'fixed')));
                 $linuxActiveTab->addItem(new EaseTWBLinkButton('host.php?action=populate&host_id=' . $host->getID(), _('Oskenovat a sledovat služby'), null, array('onClick' => "\$('#preload').css('visibility', 'visible');")));
             }
             if ($host->getCfgValue('passive_checks_enabled')) {
                 $linuxPassiveTab = $sensorTabs->addTab(_('Linux NSCA'));
                 $linuxPassiveTab->addItem(new EaseHtmlH1Tag('<img src="' . $pltIco . '">' . _('pasivní NSCA pro NSCP Senzor')));
                 $linuxPassiveTab->addItem(new EaseTWBLinkButton('nscpcfggen.php?host_id=' . $host->getId(), $host->getName() . '_nscp.sh ' . EaseTWBPart::GlyphIcon('download'), 'success'));
                 $cfgGenerator = new IENSCPConfigGenerator($host);
                 $linuxPassiveTab->addItem(new EaseTWBContainer('<pre>' . htmlspecialchars($cfgGenerator->getCfg(false)) . '</pre>', array('font-face' => 'fixed')));
             }
             break;
         default:
             $pltIco = 'logos/unknown.gif';
             if ($host->getCfgValue('active_checks_enabled')) {
                 $genericActiveTab = $sensorTabs->addTab(_('Generic Active'));
                 $genericActiveTab->addItem(new EaseTWBLinkButton('host.php?action=populate&host_id=' . $host->getID(), _('Oskenovat a sledovat služby'), null, array('onClick' => "\$('#preload').css('visibility', 'visible');")));
             }
             if ($host->getCfgValue('passive_checks_enabled')) {
                 $genericPassiveTab = $sensorTabs->addTab(_('Generic Passive'));
             }
             break;
     }
     parent::__construct($commonWell);
     $this->addItem($sensorTabs);
 }
 * @copyright  2012 Vitex@hippy.cz (G)
 */
require_once 'includes/IEInit.php';
require_once 'classes/IEPassiveCheckedHostForm.php';
$oPage->onlyForLogged();
$hostName = trim($oPage->getRequestValue('host_name'));
$platform = trim($oPage->getRequestValue('platform'));
$host_group = $oPage->getRequestValue('host_group', 'int');
$host = new IEHost();
$host->owner =& $oUser;
if ($hostName && $platform) {
    $host->setData(array($host->userColumn => $oUser->getUserID(), 'host_name' => $hostName, 'use' => 'generic-host', 'platform' => 'generic', 'register' => true, 'generate' => TRUE, 'platform' => $platform, 'alias' => $hostName, 'active_checks_enabled' => 0, 'passive_checks_enabled' => 1, 'check_freshness' => 1, 'freshness_threshold' => 900, 'flap_detection_enabled' => 0, 'check_command' => 'return-unknown'));
    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()) {
        $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;
    }
} else {
Ejemplo n.º 10
0
/**
 * Icinga Editor - potvrzení nasazení konfigurace
 *
 * @package    IcingaEditor
 * @subpackage WebUI
 * @author     Vitex <*****@*****.**>
 * @copyright  2012 Vitex@hippy.cz (G)
 */
require_once 'includes/IEInit.php';
$host_id = $oPage->getRequestValue('host_id', 'int');
$hash = $oPage->getRequestValue('hash');
if ($host_id && $hash) {
    $host = new IEHost($host_id);
    $host->setDataValue('config_hash', $hash);
    if ($host->saveToMySQL()) {
        echo sprintf(_('Konfigurace %s potvrzena'), $host->getName());
    } else {
        echo sprintf(_('Chyba potvrzení konfigurace'), $host->getName());
    }
    echo "\n<br>" . _('Sledovat cestu k hostu') . ":\n";
    if (isset($_SERVER['REQUEST_SCHEME'])) {
        $scheme = $_SERVER['REQUEST_SCHEME'];
    } else {
        $scheme = 'http';
    }
    $enterPoint = $scheme . '://' . $_SERVER['SERVER_NAME'] . dirname($_SERVER['REQUEST_URI']) . '/';
    $enterPoint = str_replace('\\', '', $enterPoint);
    //Win Hack
    $confirmUrl = $enterPoint . 'watchroute.php?action=parent&host_id=' . $host_id . '&ip=' . $_SERVER['REMOTE_ADDR'];
    echo '<a href="' . $confirmUrl . '"> ' . $confirmUrl . ' </a>';
} else {
Ejemplo n.º 11
0
 function fixHostHostgroupID()
 {
     $hostgroupsOK = array();
     $hostgroupsErr = array();
     $host = new IEHost();
     $hostgroup = new IEHostgroup();
     $hosts = $host->getColumnsFromMySQL(array($host->myKeyColumn));
     foreach ($hosts as $hostInfo) {
         $hostId = intval(current($hostInfo));
         $host->loadFromMySQL($hostId);
         $hostgroupNames = $host->getDataValue('hostgroups');
         if ($hostgroupNames) {
             foreach ($hostgroupNames as $hostgroupId => $hostgroupName) {
                 $hostgroupFound = $hostgroup->loadFromMySQL($hostgroupName);
                 if ($hostgroupId != $hostgroup->getId()) {
                     if ($host->delMember('hostgroups', $hostgroupId, $hostgroupName) && $host->addMember('hostgroups', $hostgroup->getId(), $hostgroupName)) {
                         $hostgroupsOK[] = $hostgroupName;
                     } else {
                         $hostgroupsErr[] = $hostgroupName;
                     }
                 }
             }
         }
         if (count($hostgroupsOK)) {
             if ($host->saveToMySQL()) {
                 $this->addItemSmart(sprintf(_('<strong>%s</strong> : %s'), $host->getName(), implode(',', $hostgroupsOK)), array('class' => 'list-group-item'));
                 $this->addStatusMessage(sprintf(_('%s : %s'), $host->getName(), implode(',', $hostgroupsOK)), 'success');
                 $hostgroupsOK = array();
             }
         }
     }
 }
Ejemplo n.º 12
0
%NSCLIENT% service --stop

del "%ProgramFiles%\\NSClient++\\nsclient.ini"
%NSCLIENT% settings --generate --add-defaults --load-all

%NSCLIENT% settings --path "/modules" --key Scheduler --set enabled
%NSCLIENT% settings --path "/modules" --key CheckDisk --set enabled
%NSCLIENT% settings --path "/modules" --key CheckEventLog --set enabled
%NSCLIENT% settings --path "/modules" --key CheckExternalScripts --set enabled
%NSCLIENT% settings --path "/modules" --key CheckHelpers --set enabled
%NSCLIENT% settings --path "/modules" --key CheckNSCP --set enabled
%NSCLIENT% settings --path "/modules" --key CheckSystem --set enabled
%NSCLIENT% settings --path "/modules" --key CheckWMI --set enabled
%NSCLIENT% settings --path "/modules" --key NSCAClient --set enabled

%NSCLIENT% settings --path /settings/NSCA/client --key hostname --set ' . $host->getName() . '
%NSCLIENT% settings --path /settings/NSCA/client --key channel --set NSCA
%NSCLIENT% settings --path /settings/NSCA/client/targets/default --key "allowed ciphers" --set "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH"
%NSCLIENT% settings --path /settings/NSCA/client/targets/default --key encryption --set 3des
%NSCLIENT% settings --path /settings/NSCA/client/targets/default --key password --set ' . $prefs['nscapassword'] . '
%NSCLIENT% settings --path /settings/NSCA/client/targets/default --key address --set ' . $prefs['serverip'] . '
%NSCLIENT% settings --path /settings/NSCA/client/targets/default --key port --set 5667
%NSCLIENT% settings --path /settings/NSCA/client/targets/default --key timeout --set 30
%NSCLIENT% settings --path /settings/scheduler/schedules/default --key interval --set 60s
';
$hostName = $host->getName();
$service = new IEService();
$host_passive = (bool) $host->getDataValue('passive_checks_enabled');
if (!$host_passive) {
    die(_('Host neni konfigurovan pro pasivni checky'));
}
Ejemplo n.º 13
0
 * @copyright  2012 Vitex@hippy.cz (G)
 */
require_once 'includes/IEInit.php';
$oPage->onlyForLogged();
$hostgroup = new IEHostgroup($oPage->getRequestValue('hostgroup_id', 'int'));
switch ($oPage->getRequestValue('action')) {
    case 'contactAsign':
        $contact = new IEContact($oPage->getRequestValue('contact_id', 'int'));
        if ($contact->getId()) {
            $host = new IEHost();
            $groupMembers = $hostgroup->getMembers();
            foreach ($groupMembers as $gmID => $hostName) {
                $host->loadFromSQL((int) $gmID);
                $host->addMember('contacts', $contact->getId(), $contact->getName());
                if ($host->saveToMySQL()) {
                    $host->addStatusMessage(sprintf(_('<strong>%s</strong> byl přidán mezi kontakty <strong>%s</strong>'), $contact->getName(), $host->getName()), 'success');
                } else {
                    $host->addStatusMessage(sprintf(_('<strong>%s</strong> nebyl přidán mezi kontakty <strong>%s</strong>'), $contact->getName(), $host->getName()), 'warning');
                }
            }
        } else {
            $hostgroup->addStatusMessage(_('Chyba přiřazení kontaktu'), 'warning');
        }
        break;
    default:
        if ($oPage->isPosted()) {
            $hostgroup->takeData($_POST);
            if (!$hostgroup->getId()) {
                $hostgroup->setDataValue('members', array());
            }
            $hostgroupID = $hostgroup->saveToMySQL();
Ejemplo n.º 14
0
                 $hostName = gethostbyaddr6($addressSix);
             }
         }
     }
 }
 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();
     }
Ejemplo n.º 15
0
 * @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();
        break;
Ejemplo n.º 16
0
 /**
  * Uloží ikonu do správné složky
  *
  * @param  string  $tmpfilename
  * @param  IEHost  $host
  * @return boolean
  */
 public static function saveIcon($tmpfilename, $host)
 {
     $id = $host->owner->getUserID();
     $thumbnailImagePath = $tmpfilename . '40';
     list($sourceImageWidth, $sourceImageHeight, $sourceImageType) = getimagesize($tmpfilename);
     switch ($sourceImageType) {
         case IMAGETYPE_ICO:
             $tmpfilenameIco = $tmpfilename . '.ico';
             $tmpfilenameGif = $tmpfilename . '.gif';
             rename($tmpfilename, $tmpfilenameIco);
             system("convert '" . $tmpfilenameIco . "[0]' " . $tmpfilenameGif);
             $tmpfilename = $tmpfilenameGif;
             unlink($tmpfilenameIco);
         case IMAGETYPE_GIF:
             $sourceGdImage = imagecreatefromgif($tmpfilename);
             $suffix = 'gif';
             break;
         case IMAGETYPE_JPEG:
             $sourceGdImage = imagecreatefromjpeg($tmpfilename);
             $suffix = 'jpg';
             break;
         case IMAGETYPE_PNG:
             $sourceGdImage = imagecreatefrompng($tmpfilename);
             $suffix = 'png';
             break;
     }
     if (!$sourceImageHeight || !$sourceImageWidth) {
         return NULL;
     }
     if ($sourceImageWidth > $sourceImageHeight) {
         $thumbnailImageWidth = self::$imageSize;
     } else {
         $thumbnailImageHeight = self::$imageSize;
     }
     if (isset($thumbnailImageWidth) and !isset($thumbnailImageHeight)) {
         // autocompute height if only width is set
         if ($thumbnailImageWidth) {
             $thumbnailImageHeight = 100 / ($sourceImageWidth / $thumbnailImageWidth) * 0.01;
         }
         $thumbnailImageHeight = @round($sourceImageHeight * $thumbnailImageHeight);
     } elseif (isset($thumbnailImageHeight) and !isset($thumbnailImageWidth)) {
         // autocompute width if only height is set
         if ($thumbnailImageHeight) {
             $thumbnailImageWidth = 100 / ($sourceImageHeight / $thumbnailImageHeight) * 0.01;
         }
         $thumbnailImageWidth = @round($sourceImageWidth * $thumbnailImageWidth);
     } elseif (isset($thumbnailImageHeight) and isset($thumbnailImageWidth) and isset($constrain)) {
         // get the smaller resulting image dimension if both height
         // and width are set and $constrain is also set
         $hx = 100 / ($sourceImageWidth / $thumbnailImageWidth) * 0.01;
         $hx = @round($sourceImageHeight * $hx);
         $wx = 100 / ($sourceImageHeight / $thumbnailImageHeight) * 0.01;
         $wx = @round($sourceImageWidth * $wx);
         if ($hx < $thumbnailImageHeight) {
             $thumbnailImageHeight = 100 / ($sourceImageWidth / $thumbnailImageWidth) * 0.01;
             $thumbnailImageHeight = @round($sourceImageHeight * $thumbnailImageHeight);
         } else {
             $thumbnailImageWidth = 100 / ($sourceImageHeight / $thumbnailImageHeight) * 0.01;
             $thumbnailImageWidth = @round($sourceImageWidth * $thumbnailImageWidth);
         }
     }
     $thumbnailGdImage = imagecreatetruecolor($thumbnailImageWidth, $thumbnailImageHeight);
     switch ($sourceImageType) {
         case IMAGETYPE_PNG:
             // integer representation of the color black (rgb: 0,0,0)
             $background = imagecolorallocate($sourceGdImage, 0, 0, 0);
             // removing the black from the placeholder
             imagecolortransparent($thumbnailGdImage, $background);
             // turning off alpha blending (to ensure alpha channel information
             // is preserved, rather than removed (blending with the rest of the
             // image in the form of black))
             imagealphablending($thumbnailGdImage, false);
             // turning on alpha channel information saving (to ensure the full range
             // of transparency is preserved)
             imagesavealpha($sourceGdImage, true);
             break;
         case IMAGETYPE_GIF:
             // integer representation of the color black (rgb: 0,0,0)
             $background = imagecolorallocate($sourceGdImage, 0, 0, 0);
             // removing the black from the placeholder
             imagecolortransparent($thumbnailGdImage, $background);
             break;
     }
     imagecopyresampled($thumbnailGdImage, $sourceGdImage, 0, 0, 0, 0, $thumbnailImageWidth, $thumbnailImageHeight, $sourceImageWidth, $sourceImageHeight);
     switch ($sourceImageType) {
         case IMAGETYPE_ICO:
         case IMAGETYPE_GIF:
             imagegif($thumbnailGdImage, $thumbnailImagePath);
             break;
         case IMAGETYPE_JPEG:
             imagejpeg($thumbnailGdImage, $thumbnailImagePath, 90);
             break;
         case IMAGETYPE_PNG:
             imagepng($thumbnailGdImage, $thumbnailImagePath, 9);
             break;
     }
     imagedestroy($sourceGdImage);
     imagedestroy($thumbnailGdImage);
     $newname = 'custom/' . $id . '-' . $host->getName() . '.' . $suffix;
     if (rename($thumbnailImagePath, self::$webdir . self::$icodir . '/' . $newname)) {
         unlink($tmpfilename);
         return $newname;
     }
     return false;
 }
Ejemplo n.º 17
0
 /**
  * Smaže záznam
  */
 public function delete($id = null)
 {
     if (!is_null($id)) {
         $this->loadFromMySQL($id);
     }
     $hostGroup = new IEHostgroup();
     $hostGroup->deleteHost($this->getName());
     $delAll = true;
     $service = new IEService();
     $servicesAssigned = $service->myDbLink->queryToArray('SELECT ' . $service->myKeyColumn . ',' . $service->nameColumn . ' FROM ' . $service->myTable . ' WHERE ' . 'host_name' . ' LIKE \'%"' . $this->getName() . '"%\'', $service->myKeyColumn);
     foreach ($servicesAssigned as $ServiceID => $ServiceInfo) {
         $service->loadFromMySQL($ServiceID);
         $service->delHostName($this->getId(), $this->getName());
         if (!$service->saveToMySQL()) {
             $this->addStatusMessage(sprintf(_('Nepodařilo se odregistrovat %s ze služby %s'), $this->getName(), $service->getName()), 'Error');
             $delAll = false;
         }
     }
     $childsOfMe = $this->myDbLink->queryToArray('SELECT ' . $this->myKeyColumn . ',' . $this->nameColumn . ' FROM ' . $this->myTable . ' WHERE parents ' . ' LIKE \'%' . $this->getName() . '%\'', $this->myKeyColumn);
     foreach ($childsOfMe as $chid_id => $child_info) {
         $child = new IEHost($chid_id);
         if ($child->delMember('parents', $this->getId(), $this->getName()) && $child->saveToMySQL()) {
             $this->addStatusMessage(sprintf(_('%s již není rodičem %s'), $this->getName(), $child->getName()), 'success');
         } else {
             $this->addStatusMessage(sprintf(_('%s je stále rodičem %s'), $this->getName(), $child->getName()), 'warning');
         }
     }
     if ($delAll) {
         return parent::delete();
     }
     return false;
 }
 /**
  * Editor k přidávání členů skupiny
  *
  * @param IEHost $host
  */
 public function __construct($host)
 {
     parent::__construct();
     $fieldName = $this->getmyKeyColumn();
     if ($host->getDataValue('platform') == 'generic') {
         $note = '<small><span class="label label-info">Tip:</span> ' . _('Další sledovatelné služby budou nabídnuty po nastavení platformy hosta a vzdáleného senzoru.') . '</small>';
     } else {
         $note = array();
     }
     $initialContent = new EaseTWBPanel(_('Sledované služby'), 'default', null, $note);
     $initialContent->setTagCss(array('width' => '100%'));
     if (is_null($host->getMyKey())) {
         $initialContent->addItem(_('Nejprve je potřeba uložit záznam'));
     } else {
         $hostName = $host->getName();
         $service = new IEService();
         $parentServUsed = array();
         $host_active = (bool) $host->getCfgValue('active_checks_enabled');
         $host_passive = (bool) $host->getCfgValue('passive_checks_enabled');
         $servicesAssigned = $service->myDbLink->queryToArray('SELECT ' . $service->myKeyColumn . ',display_name,' . $service->nameColumn . ' FROM ' . $service->myTable . ' WHERE ' . $fieldName . ' LIKE \'%"' . $host->getName() . '"%\'', $service->myKeyColumn);
         $allServices = $service->getListing(null, true, array('platform', 'parent_id', 'passive_checks_enabled', 'active_checks_enabled', 'display_name'));
         foreach ($allServices as $serviceID => $serviceInfo) {
             $servicePassive = (bool) $serviceInfo['passive_checks_enabled'];
             $serviceActive = (bool) $serviceInfo['active_checks_enabled'];
             if ($serviceInfo['register'] != 1) {
                 unset($allServices[$serviceID]);
                 continue;
             }
             if ($serviceInfo['platform'] != 'generic' && $serviceInfo['platform'] != $host->getDataValue('platform')) {
                 unset($allServices[$serviceID]);
                 continue;
             }
             if ((!$host_passive || !$servicePassive) && (!$host_active || !$serviceActive)) {
                 unset($allServices[$serviceID]);
                 continue;
             }
         }
         foreach ($servicesAssigned as $serviceID => $serviceInfo) {
             if (isset($allServices[$serviceID]) && isset($parentServUsed[$allServices[$serviceID]['parent_id']])) {
                 $parentServUsed[$allServices[$serviceID]['parent_id']] = $allServices[$serviceID]['parent_id'];
             }
             unset($allServices[$serviceID]);
         }
         if (count($allServices)) {
             foreach ($allServices as $serviceID => $serviceInfo) {
                 if (isset($parentServUsed[$serviceInfo['parent_id']])) {
                     continue;
                 }
                 $unchMenu = array();
                 if (intval($serviceInfo['parent_id'])) {
                     $unchMenu[] = new EaseHtmlATag('servicetweak.php?service_id=' . $serviceID, EaseTWBPart::GlyphIcon('wrench') . ' ' . _('Editace'));
                 }
                 $unchMenu[] = new EaseHtmlATag('?addservice=' . $serviceInfo[$service->nameColumn] . '&amp;service_id=' . $serviceID . '&amp;' . $host->getmyKeyColumn() . '=' . $host->getMyKey() . '&amp;' . $host->nameColumn . '=' . $host->getName(), EaseTWBPart::GlyphIcon('plus') . ' ' . _('Začít sledovat'));
                 if (strlen($serviceInfo['display_name'])) {
                     $serviceName = $serviceInfo['display_name'];
                 } else {
                     $serviceName = $serviceInfo[$service->nameColumn];
                 }
                 $initialContent->addItem(new EaseTWBButtonDropdown($serviceName, 'inverse', 'xs', $unchMenu));
             }
         }
         if (count($servicesAssigned)) {
             $saveAsTemplateButton = new EaseTWBLinkButton('stemplate.php?action=copyhost&host_id=' . $host->getId(), _('Uložit jako předlohu'), 'success');
             $initialContent->footer($saveAsTemplateButton);
             $initialContent->addItem('</br>');
             foreach ($servicesAssigned as $serviceID => $serviceInfo) {
                 if (strlen($serviceInfo['display_name'])) {
                     $serviceName = $serviceInfo['display_name'];
                 } else {
                     $serviceName = $serviceInfo[$service->nameColumn];
                 }
                 $initialContent->addItem(new EaseTWBButtonDropdown($serviceName, 'success', 'xs', array(new EaseHtmlATag('?delservice=' . $serviceInfo[$service->nameColumn] . '&amp;service_id=' . $serviceID . '&amp;' . $host->getmyKeyColumn() . '=' . $host->getMyKey() . '&amp;' . $host->nameColumn . '=' . $host->getName(), EaseTWBPart::GlyphIcon('remove') . ' ' . _('Přestat sledovat')), new EaseHtmlATag('servicetweak.php?service_id=' . $serviceID . '&amp;host_id=' . $host->getId(), EaseTWBPart::GlyphIcon('wrench') . ' ' . _('Editace')))));
             }
         } else {
             $presetSelForm = new EaseTWBForm('presetSelForm');
             $presetSelForm->addItem(new EaseHtmlInputHiddenTag($host->getmyKeyColumn(), $host->getId()));
             $presetSelForm->addItem(new EaseHtmlInputHiddenTag('action', 'applystemplate'));
             $presetSelForm->addItem(new IEStemplateSelect('stemplate_id'));
             $presetSelForm->addItem(new EaseTWSubmitButton(_('Aplikovat předlohu'), 'success'));
             $presetSelForm->setTagClass('form-inline');
             $initialContent->footer($presetSelForm);
         }
     }
     $this->addItem($initialContent);
 }
Ejemplo n.º 19
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);
 }
Ejemplo n.º 20
0
 * @author     Vitex <*****@*****.**>
 * @copyright  2012 Vitex@hippy.cz (G)
 */
require_once 'includes/IEInit.php';
$oPage->onlyForLogged();
$stemplate = new IEStemplate($oPage->getRequestValue('stemplate_id', 'int'));
switch ($oPage->getRequestValue('action')) {
    case 'new':
        $stemplate->setDataValue($stemplate->nameColumn, _('Nová předloha'));
        $stemplate->insertToSQL();
        $stemplate->setDataValue($stemplate->nameColumn, _('Nová předloha') . ' #' . $stemplate->getId());
        $stemplate->updateToMySQL();
        break;
    case 'copyhost':
        $host = new IEHost($oPage->getRequestValue('host_id', 'int'));
        $stemplate->setDataValue($stemplate->nameColumn, $host->getName());
        $stemplate->setDataValue('services', $host->getServices());
        if ($stemplate->saveToSQL()) {
            $stemplate->addStatusMessage(sprintf(_('Vytvořena nová předloha sledovaných služeb: %s'), $stemplate->getName()), 'success');
        } else {
            $stemplate->addStatusMessage(sprintf(_('Nebyla vytvořena nová předloha')), 'warning');
        }
        break;
    case 'export':
        $stemplate->transfer($oPage->getRequestValue('destination'));
        break;
    default:
        if ($oPage->isPosted()) {
            $stemplate->takeData($_POST);
            if (!$stemplate->getName()) {
                $oUser->addStatusMessage(_('Není zadán název'), 'warning');