Subversion Repositories vnag

Rev

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

  1. <?php /* <ViaThinkSoftSignature>
  2. Q+LgiqdSfhwY9Jlcm6yUYFLgrqbkPTtbTn00IzB/vNJZ7UwGuMZBLm/3wdSqobOjO
  3. aYwaWnxIqvl8IplgQf58a/wO1PS1Abz+T0yUL9bNL71JcJauTqNqNeSQUcPjDDn62
  4. tF5FiEhtVYPhiWYdY8O7hF9xOIot9XBjN6KPXOaOqRFreKgeF9P/WNIzHSdnDaZDX
  5. TP+tEvtCijPbcw+1n00Di0h5K/LBFXuItJvpeHmtew3XgBxQXedndOGA8ZVIo3tmH
  6. /n7s5s+CZboe+h/Ds9BMsAcEKv++d+9bJuPd/YsmwRrB0j22KRfyJmKKm96UBL/bs
  7. ORF5cb/f+Uqd86kpVk1MXY+CXARVNVrB1huyo7AZgvXePMkcTKSJBiHhfhNCjmrFy
  8. g8SkllXByUiyceZazlvxWCRpzqGzjXGw8ZWWjVIASP0BhgxIDwhtGBADs0c9SuWDa
  9. Y5mJ//E517rQm2uq9bQqmJ3JTPHB9r41VxO17hzlP9AZafo4ISLgiqghElKSvgcOy
  10. 8D1DYbVeYnoBK13GObzixhA+p+/Gs8IL8aiuFrffLU3aScwjvmNRA5YEVIM+QCyfX
  11. cbkQ5++1sqdNJZO5MufwVRJEjidvZqrsVEVdT8Oztu47v+8pA/RMabOVkR8TMAZB4
  12. PtzcM27uOUANXJlXbnyUQrA9qiyrklVY7mphdCrq2GpfaXWP5vYaRyV6BrooAJWSO
  13. 0Rl1nd2aIxjxb+tDWCgiXi9+bBTHAiqvj8jHSKlZqye+ECmdrsejBRqGKbeaws92v
  14. L3H152X+5VG7kni4xQEO75w+gNifzN6fUJNnk6/aIv5sOhiQcXAaOL5p0tUPTlvmG
  15. eerZGQGTGa5JW5Ns1zCiihoTpQ1VQ39gPntz3c7hTuCspMdSqB9nH7YylhRqt87Hv
  16. KzBXsNLnHbwrPLN5n2V3dMgC9pbKTXZ4pEYkVvn4/prIpscDlKezS7NXMz98gdNbV
  17. yAEItdnBK4zjUj8PnBKN579sU5+3NgkNRJrmsZJWjDDp5fwdpTTbHAbnixgfIKtI6
  18. fptjBozyBjzK+eXrPUhvseHg3GytlNoX3BLBNis6Ya917D79qiGpJlMjL6WX+EXpR
  19. +bYWChbMqJVxQC4z2Ui6PDtGj6v0UCiW5p3ag5zlJkJHVEUpbj1gFRVPb0LpJk676
  20. +lKqKQIrkHdOHwIN4yr6vlL2j95tCI4NF0+QSjvEGAORJJsmr8RoX30S1g9GrSLNI
  21. hhKaYpZ+wAteNYBIQ5b/O2F+tTnu4iw/Zc90jNtqGKP8S9Rgro4N6MDwk841jc7y/
  22. biAkj6zKbFNfaUhIqjPh+355VUWhzoYowY0sGST+v7+6NzIGHIW7+eMzta1aKbnBj
  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 2023-10-13
  33.  */
  34.  
  35. // TODO: Should we also warn if a newer major version is released?
  36.  
  37. declare(ticks=1);
  38.  
  39. class PhpBbVersionCheck extends VNag {
  40.         protected $argSystemDir = null;
  41.  
  42.         public function __construct() {
  43.                 parent::__construct();
  44.  
  45.                 $this->registerExpectedStandardArguments('Vvht');
  46.  
  47.                 $this->getHelpManager()->setPluginName('check_phpbb_version');
  48.                 $this->getHelpManager()->setVersion('1.0');
  49.                 $this->getHelpManager()->setShortDescription('This plugin checks if a local phpBB 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, 'phpBBPath', 'The local directory where your phpBB installation is located.'));
  56.         }
  57.  
  58.         protected function get_local_version($path) {
  59.                 $path = realpath($path) === false ? $path : realpath($path);
  60.  
  61.                 // Version 3 support
  62.                 $cont = @file_get_contents("$path/includes/constants.php");
  63.                 preg_match("@define\('PHPBB_VERSION', '(.*)'\);@ismU", $cont, $m);
  64.  
  65.                 if (isset($m[1])) {
  66.                         return $m[1];
  67.                 } else {
  68.                         // Version 2 support
  69.                         $cont = @file_get_contents("$path/docs/INSTALL.html");
  70.                         preg_match("@phpBB-(.*)_to_(.*)\.(zip|patch|tar)@ismU", $cont, $m);
  71.  
  72.                         if (isset($m[2])) {
  73.                                 return $m[2];
  74.                         } else {
  75.                                 return false;
  76.                         }
  77.                 }
  78.         }
  79.  
  80.         protected function isVersionCurrentStable($json, $version) {
  81.                 foreach ($json['stable'] as $major => $data) {
  82.                         if ($data['current'] == $version) return true;
  83.                 }
  84.                 return false;
  85.         }
  86.  
  87.         protected function isVersionCurrentUnstable($json, $version) {
  88.                 foreach ($json['unstable'] as $major => $data) {
  89.                         if ($data['current'] == $version) return true;
  90.                 }
  91.                 return false;
  92.         }
  93.  
  94.         protected function cbRun($optional_args=array()) {
  95.                 $system_dir = $this->argSystemDir->getValue();
  96.                 if (empty($system_dir)) {
  97.                         throw new Exception("Please specify the directory of the phpBB installation.");
  98.                 }
  99.                 $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir);
  100.  
  101.                 if (!is_dir($system_dir)) {
  102.                         throw new Exception('Directory "'.$system_dir.'" not found.');
  103.                 }
  104.  
  105.                 // 1. Checking the main system
  106.  
  107.                 // See also the original version checking code at "phpbb/version_helper.php"
  108.                 // More information about the JSON structure: https://area51.phpbb.com/docs/dev/extensions/tutorial_advanced.html#extension-version-checking
  109.                 // (Note: We should check regularly if the fields 'eol' and 'security' will be officially implemented/described)
  110.                 $versionCheckUrl = "https://version.phpbb.com/phpbb/versions.json";
  111.                 $cont = $this->url_get_contents($versionCheckUrl);
  112.                 if ($cont === false) {
  113.                         throw new Exception('Could not determinate latest phpBB version');
  114.                 }
  115.                 $json = @json_decode($cont,true);
  116.                 if ($json === false) {
  117.                         throw new Exception('Could not determinate latest phpBB version');
  118.                 }
  119.  
  120.                 $version = $this->get_local_version($system_dir);
  121.                 if ($version === false) {
  122.                         throw new Exception('Could not determinate current phpBB version in "'.$system_dir.'".');
  123.                 }
  124.  
  125.                 if ($this->isVersionCurrentStable($json, $version)) {
  126.                         $this->setStatus(VNag::STATUS_OK);
  127.                         $this->setHeadline("Version $version (Latest Stable version) at $system_dir", true);
  128.                 } else if ($this->isVersionCurrentUnstable($json, $version)) {
  129.                         $this->setStatus(VNag::STATUS_OK);
  130.                         $this->setHeadline("Version $version (Latest Unstable version) at $system_dir", true);
  131.                 } else {
  132.                         $this->setStatus(VNag::STATUS_WARNING);
  133.                         $this->setHeadline("Version $version (Old version!) at $system_dir", true);
  134.                 }
  135.  
  136.                 // 2. Checking extensions
  137.  
  138.                 $total_extensions = 0;
  139.                 $unknown_extensions = 0;
  140.                 $old_extensions = 0;
  141.                 $current_extensions = 0;
  142.                 $check_errors = 0;
  143.  
  144.                 $ext_json_files = glob($system_dir.'/ext/*/*/composer.json');
  145.                 foreach ($ext_json_files as $ext_json_file) {
  146.                         $ext_json_client = json_decode(file_get_contents($ext_json_file),true);
  147.                         $extname = $ext_json_client['name'];
  148.                         $version = $ext_json_client['version'];
  149.                         $total_extensions++;
  150.                         if (isset($ext_json_client['extra']) && isset($ext_json_client['extra']['version-check'])) {
  151.                                 if (!isset($ext_json_client['extra']['version-check']['ssl'])) $ext_json_client['extra']['version-check']['ssl'] = false;
  152.                                 $versionCheckUrl  = $ext_json_client['extra']['version-check']['ssl'] ? 'https://' : 'http://';
  153.                                 $versionCheckUrl .= $ext_json_client['extra']['version-check']['host'];
  154.                                 $versionCheckUrl .= $ext_json_client['extra']['version-check']['directory'].'/';
  155.                                 $versionCheckUrl .= $ext_json_client['extra']['version-check']['filename'];
  156.                                 $cont = @file_get_contents($versionCheckUrl);
  157.                                 if ($cont === false) {
  158.                                         $this->setStatus(VNag::STATUS_WARNING);
  159.                                         $this->addVerboseMessage("Extension $extname : Cannot reach update-server (Version $version)!", VNag::VERBOSITY_SUMMARY);
  160.                                         $check_errors++;
  161.                                         continue;
  162.                                 }
  163.                                 $json = @json_decode($cont,true);
  164.                                 if ($json === false) {
  165.                                         $this->setStatus(VNag::STATUS_WARNING);
  166.                                         $this->addVerboseMessage("Extension $extname : Cannot reach update-server (Version $version)!", VNag::VERBOSITY_SUMMARY);
  167.                                         $check_errors++;
  168.                                         continue;
  169.                                 }
  170.  
  171.                                 if ($this->isVersionCurrentStable($json, $version)) {
  172.                                         $this->setStatus(VNag::STATUS_OK);
  173.                                         $this->addVerboseMessage("Extension $extname : Version $version is latest stable.", VNag::VERBOSITY_ADDITIONAL_INFORMATION);
  174.                                         $current_extensions++;
  175.                                 } else if ($this->isVersionCurrentUnstable($json, $version)) {
  176.                                         $this->setStatus(VNag::STATUS_OK);
  177.                                         $this->addVerboseMessage("Extension $extname : Version $version is latest unstable.", VNag::VERBOSITY_ADDITIONAL_INFORMATION);
  178.                                         $current_extensions++;
  179.                                 } else {
  180.                                         $this->setStatus(VNag::STATUS_WARNING);
  181.                                         $this->addVerboseMessage("Extension $extname : Version $version is outdated!", VNag::VERBOSITY_SUMMARY);
  182.                                         $old_extensions++;
  183.                                 }
  184.                         } else {
  185.                                 $this->addVerboseMessage("Extension $extname (version $version) does not have any update server information.", VNag::VERBOSITY_ADDITIONAL_INFORMATION);
  186.                                 $unknown_extensions++;
  187.                         }
  188.                 }
  189.  
  190.                 if ($old_extensions > 0) {
  191.                         $this->setHeadline("$old_extensions extensions require an update", true);
  192.                 }
  193.                 if ($check_errors > 0) {
  194.                         $this->setHeadline("$old_extensions extensions can't be checked (update server error)", true);
  195.                 }
  196.                 $this->addVerboseMessage("$total_extensions extensions total, $current_extensions up-to-date, $old_extensions outdated, $unknown_extensions without update information, $check_errors update server errors", VNag::VERBOSITY_SUMMARY);
  197.         }
  198. }
  199.