Exemple #1
0
 /**
  * @todo set up soap and webdav tests
  */
 public static function runTests()
 {
     $status_tests = array('db' => '0', 'cluster db' => '0', 'ldap server' => '0', 'web access' => '0', 'ezfind' => '0', 'mail' => '0');
     $db = eZDB::instance();
     if ($db->isConnected() === true) {
         $status_tests['db'] = '1';
     }
     $clusterDBHandler = ezSysinfoClusterManager::clusterDBHandler();
     if ($clusterDBHandler 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($clusterDBHandler->backend->db)) {
             $status_tests['cluster db'] = '1';
         }
     } else {
         if (is_object($clusterDBHandler)) {
             // This is even worse: we have no right to know if db connection is ok.
             // So we replicate some code here...
             try {
                 $clusterDBHandler->_connect();
                 $status_tests['cluster db'] = '1';
             } catch (exception $e) {
             }
         } else {
             $status_tests['cluster db'] = 'X';
         }
     }
     if (in_array('ezfind', eZExtension::activeExtensions())) {
         $ini = eZINI::instance('solr.ini');
         $ezfinpingurl = $ini->variable('SolrBase', 'SearchServerURI') . "/admin/ping";
         $data = eZHTTPTool::getDataByURL($ezfinpingurl, false);
         $pos2 = stripos($data, '<str name="status">OK</str>');
         if ($pos2 !== false) {
             $status_tests['ezfind'] = '1';
         } else {
             $status_tests['ezfind'] = '0';
         }
     } else {
         $status_tests['ezfind'] = 'X';
     }
     $ini = eZINI::instance('ldap.ini');
     if ($ini->variable('LDAPSettings', 'LDAPEnabled') == 'true' && $ini->variable('LDAPSettings', 'LDAPServer') != '') {
         if (function_exists('ldap_connect')) {
             // code copied over 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) {
                     $status_tests['ldap server'] = '1';
                 }
             }
         }
     } else {
         $status_tests['ldap server'] = 'X';
     }
     $ini = eZINI::instance('sysinfo.ini');
     $websites = $ini->variable('SystemStatus', 'WebBeacons');
     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)) {
                     $status_tests['web access'] = '1';
                     break;
                 }
             } else {
                 $data = eZHTTPTool::getDataByURL($site, false);
                 if ($data !== false && sysInfoTools::isHTTP200($data)) {
                     $status_tests['web access'] = '1';
                     break;
                 }
             }
         }
     } else {
         $status_tests['web access'] = 'X';
     }
     $ini = eZINI::instance('sysinfo.ini');
     $recipient = $ini->variable('SystemStatus', 'MailReceiver');
     $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) {
             $status_tests['mail'] = '1';
         }
     } else {
         $status_tests['mail'] = 'X';
     }
     /*
     $ini = eZINI::instance( 'soap.ini' );
     if ( $ini->variable( 'GeneralSettings', 'EnableSOAP' ) == 'true' )
     {
         /// @todo...
     }
     else
     {
         $status_tests['ez soap'] = 'X';
     }
     
     $ini = eZINI::instance( 'webdav.ini' );
     if ( $ini->variable( 'GeneralSettings', 'EnableWebDAV' ) == 'true' )
     {
         /// @todo...
     }
     else
     {
         $status_tests['ez webdav'] = 'X';
     }
     */
     return $status_tests;
 }
 /**
  * @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
 }