Subversion Repositories vnag

Rev

Rev 29 | Blame | Last modification | View Log | RSS feed

  1. <?php /* <ViaThinkSoftSignature>
  2. IVBwOjr3n/pCZ7PzcZqZdKFy6ibL85VvOoRY3/b9Y0f46+8ggo8jVRVChw9BQ8BEl
  3. tAr7KvfpxAcNf5TXhbrYurHeIJT2hM2x4ReAPEMcwxh7cdBYuaXAfq2rMKILRAKTy
  4. p+0M7thMCz5LUw+is5DWWtpuW1oaW6obOzJ43+y0QPz0EGE0RbUTLFyeTHmHTdCHk
  5. rETmMwty+s7tzdthAEB9fCviq34QlKiBmqMlw5DfwDJmLh+NK5Y441M8pJ31EZQvP
  6. nyyGab+i7ZukBApllkdzYyLWy0xVSHK8DaZ7qLK3Lz6t+ClZLa/1N3HsIiRLKYYZ/
  7. LAFZJyETaGaz3DrrbsdjtpKKEWe1GHIRLqW8h6ENFK9nBYC8NOSSLSt23W9B9T3RY
  8. pD4CrdxlOog1hEeAI5HBvJ0h9W8x2MvHPk9K2EgIQ2WR1ThwYjykuf2ohfukPe/zK
  9. tWUxYaAwzTOVGd+I/PGgEKFEbTa2Wk0cZJCSSkR7Tn67HpDle2Th6/KKq9se8GlMb
  10. dfs4CDulmCpoDslnBPxsdNMYQCJSTAVooVEPywg/MZsZUEgMn8kXDMNmPAVTz29Tr
  11. YCjcXRyiz3eWrCTyRpPCoAttfQnxdtebZi43rsI51wuetAzYUlmDxNMSfbfzyrIMN
  12. HXovpWmjaFni8unCe7KUNxwWZlEUnj06SjGrFCWpSmYBdKRt3k0cJUs2lEjVhiQ6W
  13. mNLLizMlw4/s5B5T8+P52+wcwGX8++etkM1GMDTnrA8yBH37gtOdnvOe7kr9pLO0Y
  14. 8zk5rJxBfQtc+eIflITiyrUNzLE3cznNzYPay2STW6v+iuRfXCPWEvxJbIOCcuwW4
  15. DX0cfCzhfoL1IuSAUVK8D7eoafnebdKJa+H8wNnK8SWejwa27z2HXXYXeZ4BUcfL7
  16. ubKtxOLRQLuqjKo5O3U9o9vMRi/OZLuBwYuabg/qYcPFEtBbI7JnyauU4qzWqL5m7
  17. dC+aWrvbhn8hHqMB8p9A3PilL0NlVBlQXwZfYxYIanfooxpVPiJHBjRafCjEBQwsq
  18. YYgDlcGfCl8r0yyw5Meq3hE91F1MWyW74nRzJPZElOCNmvAMxxdMk0N5Db5/KsC37
  19. mKb/9o6R3fe9SsjF+C189u6yXomVmJJPQc8xWvQWEZ/i3MIGwtGrMpEBMKCU2Qbxu
  20. mrVSsFzSZBBThut0deDgoTZ3B1VwJ3fcZdYCy7hsMBTtAxZbC/rtkMeUvSTRiHM0d
  21. fpMIt0utv9dF+nbnnx89k6W2ML+p3ZkfoRJ/0ANYUAyPG+tjpuB31t9FkDHCQBKdB
  22. 0A9IO8pG7STLiEm73ZKxF7oOZ8xwhaUqBr93brTRY1fmsKgRo7lAlHcSGe4viwDP5
  23. g==
  24. </ViaThinkSoftSignature> */ ?>
  25. <?php
  26.  
  27. /*
  28.  * VNag - Nagios Framework for PHP
  29.  * Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com>
  30.  * Licensed under the terms of the Apache 2.0 license
  31.  *
  32.  * Revision 2021-05-13
  33.  */
  34.  
  35. // TODO: Also check extensions
  36.  
  37. declare(ticks=1);
  38.  
  39. class JoomlaVersionCheck extends VNag {
  40.         protected $argSystemDir = null;
  41.  
  42.         public function __construct() {
  43.                 parent::__construct();
  44.  
  45.                 $this->registerExpectedStandardArguments('Vht');
  46.  
  47.                 $this->getHelpManager()->setPluginName('check_joomla_version');
  48.                 $this->getHelpManager()->setVersion('1.0');
  49.                 $this->getHelpManager()->setShortDescription('This plugin checks if a local Joomla system has the latest version installed.');
  50.                 $this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.');
  51.                 $this->getHelpManager()->setSyntax('$SCRIPTNAME$ [-d <directory>]');
  52.                 $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com');
  53.  
  54.                 // Individual (non-standard) arguments:
  55.                 $this->addExpectedArgument($this->argSystemDir = new VNagArgument('d', 'directory', VNagArgument::VALUE_REQUIRED, 'joomlaPath', 'The local directory where your Joomla installation is located.'));
  56.         }
  57.  
  58.         protected function check_joomla_system($path) {
  59.                 $path = realpath($path) === false ? $path : realpath($path);
  60.  
  61.                 $manifest_file = $path.'/administrator/manifests/files/joomla.xml';
  62.  
  63.                 if (!file_exists($manifest_file)) {
  64.                         throw new Exception("Manifest file $manifest_file not found");
  65.                 }
  66.  
  67.                 $cont = file_get_contents($manifest_file);
  68.                 $manifest = new SimpleXMLElement($cont);
  69.  
  70.                 $version = (string)$manifest->version;
  71.  
  72.                 $count = 0;
  73.                 foreach ($manifest->updateservers->server as $updateserver) {
  74.                         $cont = file_get_contents($updateserver);
  75.                         if ($cont) {
  76.                                 $extensions = new SimpleXMLElement($cont);
  77.                                 foreach ($extensions as $candidate) {
  78.                                         $count++;
  79.                                         if ($version == (string)$candidate['version']) {
  80.                                                 $detailsurl = (string)$candidate['detailsurl'];
  81.                                                 if ($detailsurl == 'https://update.joomla.org/core/extension.xml') $type = 1;
  82.                                                 else if ($detailsurl == 'https://update.joomla.org/core/sts/extension_sts.xml') $type = 2;
  83.                                                 else $type = 0;
  84.                                                 return array($type, $version);
  85.                                         }
  86.                                 }
  87.                         }
  88.                 }
  89.  
  90.                 if ($count == 0) {
  91.                         throw new Exception("Error checking update servers");
  92.                 }
  93.  
  94.                 return array(-1, $version);
  95.         }
  96.  
  97.         protected function cbRun($optional_args=array()) {
  98.                 $system_dir = $this->argSystemDir->getValue();
  99.                 if (empty($system_dir)) {
  100.                         throw new Exception("Please specify the directory of the Joomla installation.");
  101.                 }
  102.                 $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir);
  103.  
  104.                 if (!is_dir($system_dir)) {
  105.                         throw new Exception('Directory "'.$system_dir.'" not found.');
  106.                 }
  107.  
  108.                 list($type, $version) = $this->check_joomla_system($system_dir);
  109.  
  110.                 if ($type == 1) {
  111.                         $this->setStatus(VNag::STATUS_OK);
  112.                         $this->setHeadline("Version $version (Long-Term-Support) found at $system_dir", true);
  113.                 } else if ($type == 2) {
  114.                         $this->setStatus(VNag::STATUS_OK);
  115.                         $this->setHeadline("Version $version (Short-Term-Support) found at $system_dir", true);
  116.                 } else if ($type == 0) {
  117.                         // This should not happen
  118.                         $this->setStatus(VNag::STATUS_OK);
  119.                         $this->setHeadline("Version $version (supported) found at $system_dir", true);
  120.                 } else if ($type == -1) {
  121.                         $this->setStatus(VNag::STATUS_WARNING);
  122.                         $this->setHeadline("Version $version is outdated at $system_dir", true);
  123.                 } else {
  124.                         assert(false);
  125.                 }
  126.         }
  127. }
  128.  
  129.