Subversion Repositories vnag

Rev

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

  1. <?php /* <ViaThinkSoftSignature>
  2. K33sSoM0IKpmPqNAvAJX4IZOxiI4PJ3Az1/SbwuExGGZCAoXMGdC4qJwLQdefulEV
  3. W8GKw5FJq/aBeUb1JIHdh22S45AcdWp5zeyY1uOHi7kkI9LIobrtyI/KZ4gGp6b3m
  4. pmFSgAUJAiuXdO2+BW6PLAi5yBwODAtD3oWeIVTINfyY+hyMb79qYxi703sTc+CG2
  5. BUggv91FVPIOQ0j3if3kTjX4pm2SQrogm+tcq/w57b2uKME/3E3MxzIHJl0d2V1jI
  6. KXPlf3zgz6ifT007mSMEXBqcmhOLGLDpkWzm81dFM6WDg/xkS3rTrL0fKDT4YNDjM
  7. CV430Sbr3bghuhEAtC168PNyDUnH4rKV2dn3DhQYA7Ubh9Y5BUvAOjKMkuXtyUlkP
  8. G/enu4v6+uH2RQIXW0KSGXvvCDayTjEZRUI5x6Co069LOQ0p2/Z2PB1feVwtFnv7i
  9. LojjxhPVP9lbeNh38QhRF3SxcnW0oXF1U7hqwBS/n5P38FVKtOy7EUFA+PqOiqLh9
  10. fvsr+Oz/yXP0W1uvaWai4l1v1g2YbSe5YLfA6QrAxB/z8KeEy1zkjVhigtOTiT7Gv
  11. xywredNXsMTC9fGpfmnJx82CcVpGDFy2PNzILYP44ubjeLliXOUSOA4wXcnegUh5Q
  12. G41z3mDIrUTCwuZ+93LbCWzw5DuPPAj6tXndfKAhtZJTNDeQMkHZgOZjwBIHP38Wm
  13. BglIhY9RsWPdI6J59GMBIfCmGElHRQjtxscrMNtfHmPLM+fue6RAHQ5fi8Zok49x4
  14. z+EXm2cTWs0AwmVmojluDZENV1tLxXloioalY+x5VuvTcAfbE7IAXeblkrIOJQrRM
  15. WcbUzfLXkLQqjPqpj1mZ10X7+zWm/hY718nITJCBtTcJ/QSHHVqsh2GNAVrO4UPY5
  16. mB5qLGq5kFOtwW4sSCQ5l97++zQ0cDIQiL0Xxy6YabYTTePodD/ncr1HfB8Jm/380
  17. E3pULdzyhbHmyIn03/g43nkbhOogVMEFmwTprDchfzCVj8QJf9XG8SRVhbtqugYP9
  18. hhCLvRtBtX0vTiYJL0n/shPZ7ZN89PDYLRMnuxu1L3r/syYulLtqykOHdto3K6PyS
  19. FofDhfwXXezLcf99yyZhf9w01zkK1szRwEaz2vJseQXtMXzwGu1RzxXqfSyFXblpw
  20. /2OujCLG/AKoT718DseQBOQAqCKpKLmNlGFmdI0tPQcqwwm6KF7dTy67PBQIZ7IHd
  21. /BpuMjdyKpZOKTpGEBvDjk1a2CRDAhDNQreJaqw3bW1vNbLiqtjARKEDSXg3fx84h
  22. 8ont601uiedZGJ/o2lWwaZ5uU7tPQXEmL2eNvbUoXnYG3gCZSCVhpAYjzhnKxygeP
  23. A==
  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.