Subversion Repositories vnag

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. <?php /* <ViaThinkSoftSignature>FiyjR9oqgAeei220CERRBiLHuRAHb0/kx6b9OY4Ltv2b0fJO25aP3K18k/KQntpXh28Yw3g1W/w807lr4xgRILQhhA3/JejkqNlKMb5bTZMcaNbTxBD44K/AHHXE62HesAYgtFyG0j8qRn+MpTEBktuwxUmMqU1HT+SHQYq9Ytj0jVX4o0hbZ29yv23waZUYI7q5as5ROs4veCrjPDSlVRty/jjviFe9ercdIta/ihXGfTR4MNymXCLKO3c3Y52yVBcIN0xd0D3YvWZb1eyjMT1akpnFWfg+2RSqkwtNJUGHmiTF9m54dE3OfQGLEQhx062oYWkbB7/Mc1sSs/U7eBdN553UycFI6j+M5yXhKmcAFTb3RMdiNRL5RsWYkx6u/tvJxOCmJZ8Ln41pqdJiXSjE52psHLNcVlOAwzKdjqsC8l4kpYBQJhVMaIkfAiJ8t5lKkYjT73QpaJl2db2Z95Skk8Utp+apI2jK/1x6IGE+PXUAIP7luQLPBrSaOrcCRRr1gXzXWJJNpDuWMVIfsFqaLblSMcRwEKz8fRHM3Z/fiRKHW4Zo5eBmoq5kqafSHmZnA3jVyQkIuqYa7nrwLpmsVT1rHqKWYbj7NduStIm0MNwdkui2AWZsA0G/NsXx08IrZlJ8Cd3U0pZ1QGbGrOSfyWzLZh6oGCHnbHFgAIz5x6uWrwLpxXhuTDVws+oiSA02YdC8Flbew71AQKkqVsV0U6hQYFsHsL+pvu04TcqP05xfwBZl3UWtRPuSg5pio5vOdtGIVFa3m3D01fQ9F4iRSZJCCMLcndD5F94CSCimd3zUyjNU9fMYaZ1Z9NE7HEt4tzhM7M0wD/ea3HhG1cjNfulUFvy+04x0YuS7cIT/zCiDFkAB4T+hWwgbPBIJHumVCVbVhQr8glc+RGWMIrQ1BfHIsxOdnGxrW/jxMpcqzjO9nNB0QDsMSNaAuXQ8EVOMnDmiH8daaQMQH2QBKXtgcKPVPJpqSbvPT2WGEAgdlfDphFhOC/L18dt5Ja8KGbBtQ2dhL6FLoPmcWPY9jFrxv+eSICvUi5Wc6okClao/ml2xPis+O+kRbve1r6PkfKFhnG3hCQ+jxyO1MRM4D+oEOAP/Xbl4/Uc+u5Ot1sbFGs4VoiKibPeiggIizzfp05R+tMgMIz7hUmAM6YFkZzxzKThl8V3s4yXLGv/drBJpSa1fG4lZmmOXfCvsAf15J660ObOxn7AiJN8fT4EfLjHgoTZiCFYU2UMFwXpfKedm7u6+0gLyFk6ni4C6DAlUKKEVK5Cm+p/Ql3cNr70mUhimfsrB26EYkwFWcfQGWhkUs1F5fmglVC1TSn9MflBEO0hUH2e/ivQIdNssN7Ni1w==</ViaThinkSoftSignature> */ ?>
  2. <?php
  3.  
  4. /*
  5.  * VNag - Nagios Framework for PHP
  6.  * Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com>
  7.  * Licensed under the terms of the Apache 2.0 license
  8.  *
  9.  * Revision 2018-07-15
  10.  */
  11.  
  12. // TODO: Also check extensions
  13.  
  14. declare(ticks=1);
  15.  
  16. class JoomlaVersionCheck extends VNag {
  17.         protected $argSystemDir = null;
  18.  
  19.         public function __construct() {
  20.                 parent::__construct();
  21.  
  22.                 $this->registerExpectedStandardArguments('Vht');
  23.  
  24.                 $this->getHelpManager()->setPluginName('check_joomla_version');
  25.                 $this->getHelpManager()->setVersion('1.0');
  26.                 $this->getHelpManager()->setShortDescription('This plugin checks if a local Joomla system has the latest version installed.');
  27.                 $this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.');
  28.                 $this->getHelpManager()->setSyntax('$SCRIPTNAME$ [-d <directory>]');
  29.                 $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com');
  30.  
  31.                 // Individual (non-standard) arguments:
  32.                 $this->addExpectedArgument($this->argSystemDir = new VNagArgument('d', 'directory', VNagArgument::VALUE_REQUIRED, 'joomlaPath', 'The local directory where your Joomla installation is located.'));
  33.         }
  34.  
  35.         protected function check_joomla_system($path) {
  36.                 $path = realpath($path) === false ? $path : realpath($path);
  37.  
  38.                 $manifest_file = $path.'/administrator/manifests/files/joomla.xml';
  39.  
  40.                 if (!file_exists($manifest_file)) {
  41.                         throw new Exception("Manifest file $manifest_file not found");
  42.                 }
  43.  
  44.                 $cont = file_get_contents($manifest_file);
  45.                 $manifest = new SimpleXMLElement($cont);
  46.  
  47.                 $version = (string)$manifest->version;
  48.  
  49.                 $count = 0;
  50.                 foreach ($manifest->updateservers->server as $updateserver) {
  51.                         $cont = @file_get_contents($updateserver);
  52.                         if ($cont) {
  53.                                 $extensions = new SimpleXMLElement($cont);
  54.                                 foreach ($extensions as $candidate) {
  55.                                         $count++;
  56.                                         if ($version == (string)$candidate['version']) {
  57.                                                 $detailsurl = (string)$candidate['detailsurl'];
  58.                                                 if ($detailsurl == 'https://update.joomla.org/core/extension.xml') $type = 1;
  59.                                                 else if ($detailsurl == 'https://update.joomla.org/core/sts/extension_sts.xml') $type = 2;
  60.                                                 else $type == 0;
  61.                                                 return array($type, $version);
  62.                                         }
  63.                                 }
  64.                         }
  65.                 }
  66.  
  67.                 if ($count == 0) {
  68.                         throw new Exception("Error checking update servers");
  69.                 }
  70.  
  71.                 return array(-1, $version);
  72.         }
  73.  
  74.         protected function cbRun($optional_args=array()) {
  75.                 $system_dir = $this->argSystemDir->getValue();
  76.                 if (empty($system_dir)) {
  77.                         throw new Exception("Please specify the directory of the Joomla installation.");
  78.                 }
  79.                 $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir);
  80.  
  81.                 if (!is_dir($system_dir)) {
  82.                         throw new Exception('Directory "'.$system_dir.'" not found.', false);
  83.                 }
  84.  
  85.                 list($type, $version) = $this->check_joomla_system($system_dir);
  86.  
  87.                 if ($type == 1) {
  88.                         $this->setStatus(VNag::STATUS_OK);
  89.                         $this->setHeadline("Version $version (Long-Term-Support) found at $system_dir", true);
  90.                 } else if ($type == 2) {
  91.                         $this->setStatus(VNag::STATUS_OK);
  92.                         $this->setHeadline("Version $version (Short-Term-Support) found at $system_dir", true);
  93.                 } else if ($type == 0) {
  94.                         // This should not happen
  95.                         $this->setStatus(VNag::STATUS_OK);
  96.                         $this->setHeadline("Version $version (supported) found at $system_dir", true);
  97.                 } else if ($type == -1) {
  98.                         $this->setStatus(VNag::STATUS_WARNING);
  99.                         $this->setHeadline("Version $version is outdated at $system_dir", true);
  100.                 } else {
  101.                         assert(false);
  102.                 }
  103.         }
  104. }
  105.  
  106.