Subversion Repositories vnag

Rev

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

  1. <?php /* <ViaThinkSoftSignature>
  2. HlSVetfv0XKCBAHe5nbDalbR8T1VTGwFp5Sso+NV+Ai6FGDOxUZ5V74bkZm6zjj0l
  3. geBvlNO5x4g5a8VBt1g5p0drOul4hbXTSX8GtOzNGLWrglTmsF3RHDWUMMKOI4EMq
  4. lqi7fUsppvUJ61PnR+XFIx5zNomQ3FNI3NNPnfHiN4O5c0Rz6WzEF5TVT2F7DPlDo
  5. ZbEdmo7cXZuSJG0fGpD6Qelkq2eKNxkE0DyNJrLAcEnntvuTYpoc06QYiNJk+OIED
  6. kd5i0KB9poE5BORsGMhVMwWK2s4ajE/TqZ9fGACbyk+lbinTMJ2VAGzR4KTSThJfb
  7. KbavleaX9ITi9jbBVxGorDiFY2Ly8BvJ0gaJmSXwjUDSUsLdJuMruNVULjhoGgzAs
  8. lXGu6RZ0GvuPly6jBkXGqdguqrjBvczkGLc+SQM1TkxafWK3rjnVlL3NcAVeNp1mm
  9. +F+UawOvT1nBNXsAodiv8G5Vt75t9/KxPZ/9pSfoui2efNodb+WWUVM5y2/2bSuWR
  10. 7jSuquWKooOdHa3KIppD4RDhV2q2eq8AQhP2d+KihlJCoPMB3BZgmut++BBT3K4LN
  11. vp084TEGxwi4vJmFXBuHMzLBG5I0RFaAdtiO6MFuJLfYx2Y1A+rP5C0dAlnqQSD45
  12. KF/ibeJM0FP+9XxT4OhGxehwbKTm9waBBqc2k7d3h45XTFZ3ygP9UmffI1Nol9N2g
  13. kWFAdelxZxiMX/AOl+kGm8lv1oCJbpdFWle6YSunl7PUV38llVeFMcNsTf6rM+ZdG
  14. c2O3bHvcVt39tRBS2eGDwg90dxCMUwVu4k8DbmU0ga5FyjfvEZLDDceYFR9xgu3TT
  15. p+62MtDaxkPIku4XinpH95FbF/m/ZETBM1r1wMa8+C7qp6exBmrKas1e7cy482Sx8
  16. MoD6prrA35xL3dUnr7dZJwtVS68Znpb1hy/adYKNCOnzidZYsK2e+BcnY9IMaI3aX
  17. 4B6ZNoJTRVxFKTkgNx6uZC22HVwcp/EtOW0SAHUGax7ICDY7f2FhUnTOXh3pU3KBW
  18. 9h0MgnzC4jjE96F1ROUw0gGT8wA+a6yugaPGjaKVVWWJiyEikHofPt3YkEVZUPOV0
  19. q7I0kgW0PqqqzzlMu4rJicTWEWXofYAI6j4zuTZ9XrHNPp0vw+f5stt/zYqAJ609h
  20. VhL+iYaqO2r+3p+YMDLzL7WQCQA2VDNpzV9XVrQEAPLYkSgS9ZFZ/o8TgjgVpGnv/
  21. AfEwJned7Te2NDzlIAcg4UoEk3NL8sCcIyPvwxf2zbzceqEAlnfryacxS3Tt8vrde
  22. F31XxnfmY43Tzzoa0I0P5xPRAhmcwnraY/emXTAcoAYmkJpO1fp7mqDpDPHHbydtv
  23. Q==
  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. 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_versions($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 = $this->url_get_contents($update_url);
  112.                 if ($cont === false) {
  113.                         throw new Exception('Could not determinate current ownCloud version in "'.$local_path.'". A');
  114.                 }
  115.  
  116.                 if ($cont === '') {
  117.                         return array($OC_VersionString, $OC_VersionString, $OC_Channel);
  118.                 } else {
  119.                         $xml = simplexml_load_string($cont);
  120.                         if ($xml === false) {
  121.                                 throw new Exception('Could not determinate current ownCloud version in "'.$local_path.'". B');
  122.                         }
  123.                         $new_ver = (string)$xml->version;
  124.                         return array($OC_VersionString, $new_ver, $OC_Channel);
  125.                 }
  126.         }
  127.  
  128.         protected function cbRun($optional_args=array()) {
  129.                 $system_dir = $this->argSystemDir->getValue();
  130.                 if (empty($system_dir)) {
  131.                         throw new Exception("Please specify the directory of the ownCloud installation.");
  132.                 }
  133.                 $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir);
  134.  
  135.                 if (!is_dir($system_dir)) {
  136.                         throw new Exception('Directory "'.$system_dir.'" not found.');
  137.                 }
  138.  
  139.                 list($cur_ver, $new_ver, $channel) = $this->get_versions($system_dir);
  140.  
  141.                 if (version_compare($cur_ver,$new_ver) >= 0) {
  142.                         $this->setStatus(VNag::STATUS_OK);
  143.                         $this->setHeadline("ownCloud version $cur_ver [$channel] is the latest available version for your ownCloud installation at $system_dir", true);
  144.                 } else {
  145.                         $this->setStatus(VNag::STATUS_WARNING);
  146.                         $this->setHeadline("ownCloud version $cur_ver [$channel] is outdated. Newer version is $new_ver [$channel] for installation at $system_dir", true);
  147.                 }
  148.         }
  149. }
  150.