<?php /** * A view to display the MIB - in various formats * * @author Gaetano Giunta * @copyright (c) 2009-2012 G. Giunta * @license code licensed under the GPL License: see README */ $server = new eZSNMPd(); switch ($Params['format']) { case 'html': $format = 'html'; $mib = $server->getMIBArray(); break; default: header('Content-Type: text/plain'); echo $server->getFullMIB(); eZExecution::cleanExit(); } $tpl = eZsnmpdTools::eZTemplateFactory(); $tpl->setVariable('mib', $mib); $Result = array(); $Result['content'] = $tpl->fetch("design:snmp/mib/{$format}.tpl"); //include_once( 'kernel/common/i18n.php' ); $Result['path'] = array(array('url' => '', 'text' => 'SNMP Monitoring'), array('url' => 'snmp/mib/html', 'text' => 'MIB'));
/** * @todo we should return an error if the scalar values are queried without a .0 appendeded... */ function get($oid) { // warm up list of existing oids, if not yet done $this->oidList(); $internaloid = preg_replace('/\\.0$/', '', $oid); if (array_key_exists($internaloid, self::$simplequeries)) { $count = -1; if (strpos($internaloid, '2.1.4.') === 0) { // session-related queries: return -1 if not using db-based storage $ini = eZINI::instance(); $sessionHandler = $ini->variable('Session', 'Handler'); if ($sessionHandler != 'ezpSessionHandlerDB') { return array('oid' => $oid, 'type' => eZSNMPd::TYPE_INTEGER, 'value' => $count); } } if (strpos($internaloid, '2.1.6.') === 0) { // async-publication-related queries: return -1 if not using it $ini = eZINI::instance('content.ini'); if ($ini->variable('PublishingSettings', 'AsynchronousPublishing') != 'enabled') { return array('oid' => $oid, 'type' => eZSNMPd::TYPE_INTEGER, 'value' => $count); } } $db = self::eZDBinstance(); if ($db) { $results = $db->arrayQuery(str_replace('/*anonymousId*/', eZUser::anonymousId(), self::$simplequeries[$internaloid])); $db->close(); if (is_array($results) && count($results)) { $count = $results[0]['count']; } } return array('oid' => $oid, 'type' => eZSNMPd::TYPE_INTEGER, 'value' => $count); } if (array_key_exists($internaloid, self::$orderstatuslist)) { $oids = explode('.', $internaloid); switch ($oids[5]) { case '1': return array('oid' => $oid, 'type' => eZSNMPd::TYPE_INTEGER, 'value' => self::$orderstatuslist[$internaloid]); case '2': return array('oid' => $oid, 'type' => eZSNMPd::TYPE_STRING, 'value' => self::$orderstatuslist[$internaloid]); case '3': case '4': $count = -1; $db = self::eZDBinstance(); if ($db) { $status = $db->arrayQuery('select count(*) as num from ezorder where is_temporary=0 and is_archived=' . ($oids[5] + 1) % 2 . ' and status_id=' . self::$orderstatuslist[$internaloid], array('column' => 'num')); $db->close(); if (is_array($status) && count($status)) { $count = $status[0]; } } return array('oid' => $oid, 'type' => eZSNMPd::TYPE_INTEGER, 'value' => $count); } } if (array_key_exists($internaloid, self::$cachelist)) { $cacheinfo = eZCache::fetchByID(self::$cachelist[$internaloid]); $oids = explode('.', $internaloid); switch ($oids[3]) { case '1': return array('oid' => $oid, 'type' => eZSNMPd::TYPE_STRING, 'value' => $cacheinfo['name']); case '2': return array('oid' => $oid, 'type' => eZSNMPd::TYPE_INTEGER, 'value' => (int) $cacheinfo['enabled']); case '3': case '4': $fileINI = eZINI::instance('file.ini'); $handlerName = $fileINI->variable('ClusteringSettings', 'FileHandler'); switch ($handlerName) { case 'ezfs': case 'eZFSFileHandler': case 'eZFS2FileHandler': break; default: // the db-based filehandlers + dfs one not yet supported return array('oid' => $oid, 'type' => eZSNMPd::TYPE_INTEGER, 'value' => -1); } // take care: this is hardcoded from knowledge of cache structure... if (strpos($cacheinfo['path'], 'var/cache/') === 0) { $cachedir = $cacheinfo['path']; } else { $cachedir = eZSys::cacheDirectory() . '/' . $cacheinfo['path']; } if ($oids[3] == '3') { $out = (int) eZsnmpdTools::countFilesInDir($cachedir); } else { $out = (int) eZsnmpdTools::countFilesSizeInDir($cachedir); } return array('oid' => $oid, 'type' => eZSNMPd::TYPE_INTEGER, 'value' => $out); } } if (array_key_exists($internaloid, self::$storagedirlist)) { $oids = explode('.', $internaloid); switch ($oids[3]) { case '1': return array('oid' => $oid, 'type' => eZSNMPd::TYPE_STRING, 'value' => self::$storagedirlist[$internaloid]); case '2': case '3': $fileINI = eZINI::instance('file.ini'); $handlerName = $fileINI->variable('ClusteringSettings', 'FileHandler'); switch ($handlerName) { case 'ezfs': case 'eZFSFileHandler': case 'eZFS2FileHandler': break; default: // the db-based filehandlers + dfs one not yet supported return array('oid' => $oid, 'type' => eZSNMPd::TYPE_INTEGER, 'value' => -1); } if ($oids[3] == '2') { $out = (int) eZsnmpdTools::countFilesInDir(self::$storagedirlist[$internaloid]); } else { $out = (int) eZsnmpdTools::countFilesSizeInDir(self::$storagedirlist[$internaloid]); } return array('oid' => $oid, 'type' => eZSNMPd::TYPE_INTEGER, 'value' => $out); } } switch ($internaloid) { case '2.1.1': // verify if db can be connected to $ok = 1; $db = self::eZDBinstance(); if (!$db) { $ok = 0; } else { $db->close(); } return array('oid' => $oid, 'type' => eZSNMPd::TYPE_INTEGER, 'value' => $ok); /*case '2.2.1': // cache-blocks /// @todo ... $handlerName = $fileINI->variable( 'ClusteringSettings', 'FileHandler' ); switch( $handlerName ) { case 'ezfs': break; case 'ezdb': break; default: } case '2.2.2': // view-cache /// @todo ... $handlerName = $fileINI->variable( 'ClusteringSettings', 'FileHandler' ); switch( $handlerName ) { case 'ezfs': break; case 'ezdb': break; default: }*/ /*case '2.2.1': // cache-blocks /// @todo ... $handlerName = $fileINI->variable( 'ClusteringSettings', 'FileHandler' ); switch( $handlerName ) { case 'ezfs': break; case 'ezdb': break; default: } case '2.2.2': // view-cache /// @todo ... $handlerName = $fileINI->variable( 'ClusteringSettings', 'FileHandler' ); switch( $handlerName ) { case 'ezfs': break; case 'ezdb': break; default: }*/ case '2.4.1': // ldap connection $ini = eZINI::instance('ldap.ini'); if ($ini->variable('LDAPSettings', 'LDAPEnabled') == 'true' && $ini->variable('LDAPSettings', 'LDAPServer') != '') { $ok = 0; // code copied over from ezldapuser class... $LDAPVersion = $ini->variable('LDAPSettings', 'LDAPVersion'); $LDAPServer = $ini->variable('LDAPSettings', 'LDAPServer'); $LDAPPort = $ini->variable('LDAPSettings', 'LDAPPort'); $LDAPBindUser = $ini->variable('LDAPSettings', 'LDAPBindUser'); $LDAPBindPassword = $ini->variable('LDAPSettings', 'LDAPBindPassword'); $ds = ldap_connect($LDAPServer, $LDAPPort); if ($ds) { ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, $LDAPVersion); if ($LDAPBindUser == '') { $r = ldap_bind($ds); } else { $r = ldap_bind($ds, $LDAPBindUser, $LDAPBindPassword); } if ($r) { $ok = 1; } // added: release resources, be ready for next test ldap_close($ds); } } else { $ok = -1; } return array('oid' => $oid, 'type' => eZSNMPd::TYPE_INTEGER, 'value' => $ok); case '2.4.2': // web connection $ini = eZINI::instance('snmpd.ini'); $websites = $ini->variable('StatusHandler', 'WebBeacons'); $ok = 0; if (is_string($websites)) { $websites = array($websites); } foreach ($websites as $key => $site) { if (trim($site) == '') { unset($websites[$key]); } } if (count($websites)) { foreach ($websites as $site) { // current eZ code is broken if no curl is installed, as it does not check for 404 or such. // besides, it does not even support proxies... if (extension_loaded('curl')) { if (eZHTTPTool::getDataByURL($site, true)) { $ok = 1; break; } } else { $data = eZHTTPTool::getDataByURL($site, false); if ($data !== false && sysInfoTools::isHTTP200($data)) { $ok = 1; break; } } } } else { $ok = -1; } return array('oid' => $oid, 'type' => eZSNMPd::TYPE_INTEGER, 'value' => $ok); case '2.4.3': // email connection $ini = eZINI::instance('snmpd.ini'); $recipient = $ini->variable('StatusHandler', 'MailReceiver'); $ok = 0; $mail = new eZMail(); if (trim($recipient) != '' && $mail->validate($recipient)) { $mail->setReceiver($recipient); $ini = eZINI::instance(); $sender = $ini->variable('MailSettings', 'EmailSender'); $mail->setSender($sender); $mail->setSubject("Test email"); $mail->setBody("This email was automatically sent while testing eZ Publish connectivity to the mail server. Please do not reply."); $mailResult = eZMailTransport::send($mail); if ($mailResult) { $ok = 1; } } else { $ok = -1; } return array('oid' => $oid, 'type' => eZSNMPd::TYPE_INTEGER, 'value' => $ok); case '2.5.1': $fileINI = eZINI::instance('file.ini'); $clusterhandler = $fileINI->variable('ClusteringSettings', 'FileHandler'); if ($clusterhandler == 'ezdb' || $clusterhandler == 'eZDBFileHandler') { $ok = 0; $dbFileHandler = eZClusterFileHandler::instance(); if ($dbFileHandler instanceof eZDBFileHandler) { // warning - we dig into the private parts of the cluster file handler, // as no real API are provided for it (yet) if (is_resource($dbFileHandler->backend->db)) { $ok = 1; } } } else { if ($clusterhandler == 'eZDFSFileHandler') { // This is even worse: we have no right to know if db connection is ok. // So we replicate some code here... $dbbackend = eZExtension::getHandlerClass(new ezpExtensionOptions(array('iniFile' => 'file.ini', 'iniSection' => 'eZDFSClusteringSettings', 'iniVariable' => 'DBBackend'))); try { $dbbackend->_connect(); $ok = 1; } catch (exception $e) { $ok = 0; } } else { $ok = -1; } } return array('oid' => $oid, 'type' => eZSNMPd::TYPE_INTEGER, 'value' => $ok); } return self::NO_SUCH_OID; // oid not managed }