Subversion Repositories vnag

Rev

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

  1. <?php /* <ViaThinkSoftSignature>
  2. IvzBH2MGR7iuY8ypKdaWeNlTFUDviDbO7/OB8VBORbHEEsLkTdH/PYxpmlvrI5KWl
  3. NwVu87C8TziS10APkoVpPaMR/5UtGbU8dNEuBzMZOkH2sLSmjYqj8Eo+RswjNtFHc
  4. nmn6lEmHHXYDibl+8ante/SL15CBYBaFS5ZEt96tZHz1z6v31QVpmOmSfMoKFlnhJ
  5. G9mnmfJlplnUJuYk84LIgUe4rBrvU6bivOkkTNOg0MKQdcWDb6y1j20fojGbUWXkc
  6. RzaKESzNS/cA8shEuaO4UwXifkuxwgzRpzGR19k83xLnzvboPmbqt9BWgtKrV09Is
  7. UbEOEcczA6r0/phKLMl1svf6syhyPuEmmplyxzobiOgoclwUbTqNyJU06M78HkJZ0
  8. Apjh3M56pKAxfJE0PLusZT6Fj2F2Ww0Y85rtF41NfWb4LmHFBiys+SL5eYZ8vSQEF
  9. Dlot/K9qGb24UUWP0IiGrIL1b+0huGdb1L6msWVM4DMJDcA+L0afMfxKccQsAslfA
  10. lOEq+PL3tbrcyWyxcmvnNopr0/8ZjLWr8Vc6B2oT7Y7SgqPeChsGAIR8k9tB26K9l
  11. eCSC87JnHnJY98wc7acgoLAIdTI4Djfsp47/Ke21FLRtW6PbV20wzFcxEiECKT6U0
  12. P2x8oWaRK1FD5UQpm0qoDV1G0R/GrkbjSgK5Or1OTeDF/cGL47LQy2Z9IUbmzc9o5
  13. S47WI4+4UxBTgEluO5REwg7lBBh3T8o6VdpjWSwuES+tgvhBCc0eGhHfDAlwDkxaA
  14. cKBdUyP0SPbc8OKQySmjmNCwFWsu6W/IbZDDWoyA1eZtJL5x5EY8sDGY3tEPPWZ6r
  15. BdK/F9OocrLiAyqP3ExjGg895KlxEzF1udxxtUL/sjZcz31/MAkYylqCl2eOdUa6l
  16. 4iFv6hWyNnxdkEvHB0MIxHE/1JKYqXTckGiBz758ATyFxwz7B+Ln5H4Cck6DHP1e9
  17. 5VT33ScKyh0D4CQSd/MNe/JxvyjQEDdbpJDZ/Nm/kxjhkLkYvz4sQGdS/oxYCmLXM
  18. xO2ESmZI+thCSdLz4sFRvikCQIPlU6VuxmsKXMoa1irESaDqcYfcVOIL8chUvikwQ
  19. 3GH8hNVV257SJN3MO8Nd2Fj/WpgIgV5TXRsfk/KujjnF62zkLc0eATo0vkwVlQ+9d
  20. gtTHL4R40c+jy1u0jDRxvtkgJ5dIETpkvzpu0/thWRXIv+sTtTQ/a60S4ZkHGM3za
  21. 0GCX+lu83OpzrYkb0HTjrfA04k2SgvxtV1z0vqj5mPCSIEGx76LEApCHvPCl1QecK
  22. ze+Jd6kZVOY/JFuU02o2iRx+7fYFxAHoXOmjZMfSlLAQ+/vvs7TA3hsbXMcihhLfg
  23. w==
  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-06-26
  33.  */
  34.  
  35. declare(ticks=1);
  36.  
  37. class OwnCloudVersionCheck extends VNag {
  38.         protected $argSystemDir = null;
  39.  
  40.         public function __construct() {
  41.                 parent::__construct();
  42.  
  43.                 $this->registerExpectedStandardArguments('Vvht');
  44.  
  45.                 $this->getHelpManager()->setPluginName('check_owncloud_version');
  46.                 $this->getHelpManager()->setVersion('1.0');
  47.                 $this->getHelpManager()->setShortDescription('This plugin checks if a local ownCloud system has the latest version installed.');
  48.                 $this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.');
  49.                 $this->getHelpManager()->setSyntax('$SCRIPTNAME$ [-d <directory>]');
  50.                 $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com');
  51.  
  52.                 // Individual (non-standard) arguments:
  53.                 $this->addExpectedArgument($this->argSystemDir = new VNagArgument('d', 'directory', VNagArgument::VALUE_REQUIRED, 'ownCloudPath', 'The local directory where your ownCloud installation is located.'));
  54.         }
  55.  
  56.         protected function get_owncloud_version($local_path) {
  57.                 $local_path = realpath($local_path) === false ? $local_path : realpath($local_path);
  58.  
  59.                 if (!file_exists($local_path . '/version.php')) {
  60.                         throw new Exception('This is not a valid ownCloud installation in "'.$local_path.'".');
  61.                 }
  62.  
  63.                 // We don't include version.php because it would be a security vulnerability
  64.                 // code injection if somebody controls version.php
  65.                 $cont = file_get_contents($local_path . '/version.php');
  66.                 if (preg_match('@\\$(OC_Version)\\s*=\\s*array\\(\\s*(.+)\\s*,\\s*(.+)\\s*,\\s*(.+)\\s*,\\s*(.+)\\s*\\)\\s*;@ismU', $cont, $m)) {
  67.                         $OC_Version = array($m[2],$m[3],$m[4],$m[5]);
  68.                 } else {
  69.                         throw new Exception('This is not a valid ownCloud installation in "'.$local_path.'". Missing "OC_Version".');
  70.                 }
  71.                 if (preg_match('@\\$(OC_VersionString)\\s*=\\s*([\'"])(.*)\\2\\s*;@ismU', $cont, $m)) {
  72.                         $OC_VersionString = $m[3];
  73.                 } else {
  74.                         throw new Exception('This is not a valid ownCloud installation in "'.$local_path.'". Missing "OC_VersionString".');
  75.                 }
  76.                 if (preg_match('@\\$(OC_Edition)\\s*=\\s*([\'"])(.*)\\2\\s*;@ismU', $cont, $m)) {
  77.                         $OC_Edition = $m[3];
  78.                 } else {
  79.                         throw new Exception('This is not a valid ownCloud installation in "'.$local_path.'". Missing "OC_Edition".');
  80.                 }
  81.                 if (preg_match('@\\$(OC_Channel)\\s*=\\s*([\'"])(.*)\\2\\s*;@ismU', $cont, $m)) {
  82.                         $OC_Channel = $m[3];
  83.                 } else {
  84.                         throw new Exception('This is not a valid ownCloud installation in "'.$local_path.'". Missing "OC_Channel".');
  85.                 }
  86.                 if (preg_match('@\\$(OC_Build)\\s*=\\s*([\'"])(.*)\\2\\s*;@ismU', $cont, $m)) {
  87.                         $OC_Build = $m[3];
  88.                 } else {
  89.                         throw new Exception('This is not a valid ownCloud installation in "'.$local_path.'". Missing "OC_Build".');
  90.                 }
  91.                 if (preg_match('@\\$(vendor)\\s*=\\s*([\'"])(.*)\\2\\s*;@ismU', $cont, $m)) {
  92.                         $vendor = $m[3];
  93.                         if ($vendor != 'owncloud') {
  94.                                 throw new Exception('This is not a valid ownCloud installation in "'.$local_path.'". It is "'.$vendor.'".');
  95.                         }
  96.                 } else {
  97.                         throw new Exception('This is not a valid ownCloud installation in "'.$local_path.'". Missing "vendor".');
  98.                 }
  99.  
  100.                 // Owncloud\Updater\Utils\Fetcher::DEFAULT_BASE_URL
  101.                 $baseUrl = 'https://updates.owncloud.com/server/';
  102.  
  103.                 $update_url = $baseUrl . '?version='.
  104.                               implode('x', $OC_Version).'x'.
  105.                               'installedatx'.
  106.                               'lastupdatedatx'.
  107.                               $OC_Channel.'x'.
  108.                               $OC_Edition.'x'.
  109.                               urlencode($OC_Build);
  110.  
  111.                 $cont = file_get_contents($update_url);
  112.                 if ($cont === false) {
  113.                         throw new Exception('Could not determinate current ownCloud version in "'.$local_path.'".');
  114.                 }
  115.  
  116.                 if ($cont === '') {
  117.                         return array($OC_VersionString, $OC_VersionString, $OC_Channel);
  118.                 } else {
  119.                         $xml = simplexml_load_string($cont);
  120.                         $new_ver = (string)$xml->version;
  121.                         return array($OC_VersionString, $new_ver, $OC_Channel);
  122.                 }
  123.         }
  124.  
  125.         protected function cbRun($optional_args=array()) {
  126.                 $system_dir = $this->argSystemDir->getValue();
  127.                 if (empty($system_dir)) {
  128.                         throw new Exception("Please specify the directory of the ownCloud installation.");
  129.                 }
  130.                 $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir);
  131.  
  132.                 if (!is_dir($system_dir)) {
  133.                         throw new Exception('Directory "'.$system_dir.'" not found.');
  134.                 }
  135.  
  136.                 list($cur_ver, $new_ver, $channel) = $this->get_owncloud_version($system_dir);
  137.  
  138.                 if ($cur_ver === $new_ver) {
  139.                         $this->setStatus(VNag::STATUS_OK);
  140.                         $this->setHeadline("ownCloud version $cur_ver [$channel] is the latest available version for your ownCloud installation at $system_dir", true);
  141.                 } else {
  142.                         $this->setStatus(VNag::STATUS_WARNING);
  143.                         $this->setHeadline("ownCloud version $cur_ver [$channel] is outdated. Newer version is $new_ver [$channel] for installation at $system_dir", true);
  144.                 }
  145.         }
  146. }
  147.