Rev 59 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
59 | daniel-mar | 1 | <?php /* <ViaThinkSoftSignature> |
76 | daniel-mar | 2 | Os6Vigdt4/PI0epPcVQLiFdxgBhWiu8NEIPIqX9z3giSygs8qTKj6ySf+t3QkS9Hr |
3 | DckIspa6rb9LPdgsWzIen0c7AdZIktyvnr0aRJytTvsEi39htzI9065rPoMTYzdNd |
||
4 | UrunPx0DJkr3GxKOFpEv9BiqNdQJVQQTmrfa5+73DoBcJ1Rgd/LqeBa8YPYlaYe4U |
||
5 | 3JbEdd3ZBSNxAv4b/qk0S4b8d1HVZWslpqCdOxJmaQM0xqCmkDPRtBIoVKsdTQ0NN |
||
6 | CGcM5lmo/eyk+N1HNtpIZxrkfOil8OAy1Nhfq90f8IQJiolOn9/+SWqfwtPADb2jC |
||
7 | LE7Ed1jgcAHfDbzD4E7NfBWL3dREiLBwnZbbdLV4EwojAhpPyRTBT9CQk0HbhF2Zs |
||
8 | EEZMEzV/ebWQ1/S8xjC+cDIw4I0nKCg1/di50e07yP1Dkoau5aUiS9FcY5BhAkW1i |
||
9 | PdgJz6MrtQv7t9aqhf6XeF8PCEVbkbdckzIWMJTYP1IC8DDwBzvIQ6Ss8g+YlWsgx |
||
10 | fHw1ZKSF5YSnkgrxzAOnzAWNk9/68OKwEe5PzLLCqyktWw0+E4FGHiXIkVY8jyc41 |
||
11 | 5Lg/2iE6t9k4KLmq1uk29DnNmeydujMjaUoT8+NetCPKPQT9hQtClliw9rPVlHawa |
||
12 | XqpBsHamsz3ZWEQfF+P+jKJj9azgB9pMv52nYEEwuWOUp78aAWEDgtT0MeOb1JXk6 |
||
13 | kBmekIj208tOcrHH0qQr/03Z3jEMoMgGfa1IX0JEK7v/lJWbPSkT4PdxgefGjWKcC |
||
14 | Zosc7WsjUfasiSN/Qr08DjV2hEBbYg9j2o6zl3JqjGr8bkCmIlewl9II8u2Ioc6vL |
||
15 | bGRnLtbiGvHAOkPhGYwWG2Y6oLyrQQQzHsSTvPARN1zqCPjlkCntGW3tH4hg+aFvN |
||
16 | R932hgONDUtxH5W0Azqq0UgE8tA7r4HWwPbN81UT6trJXvOg3CCT5Gz0CJm4vc1xV |
||
17 | BG1ez3NwYVVECH7I5pjRI87xBhb0GoKJGK6oAf4zzSLIhCGhWeVc2iJmGyoLkzImG |
||
18 | 2g7AI9ddpqqTcEqYusnhc5HaNccaq91ABLtBZ44zpIaqT+YBEigQ9G2AhwcA+L3In |
||
19 | 4zj9wvjiM8kbgyi6g9JsUncPi6+9KoZbMpVtX9vOX5FnUuUZ2ktzH1tDp2ZkuUM1d |
||
20 | AhXTFR21ZnD9Ji2LPs6piFGOQEwwjPwImV/Xd1KkNC+E4UkfKZn8IEP5eG6FvL4p9 |
||
21 | KY8nmjQixlnAH1SlQD50PWXWSEhW6JW+Zr5VFwVnBEgHFb2mXqqeQE/s6JdQCVi4K |
||
22 | 3H+twnvPtn2rCnOZ2OpeTPqGiJ1JEt/cLdNl2a3MD6tduHuvlWE7fTMnO2poU0BDh |
||
59 | daniel-mar | 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 | * |
||
76 | daniel-mar | 32 | * Revision 2023-10-13 |
59 | daniel-mar | 33 | */ |
34 | |||
35 | declare(ticks=1); |
||
36 | |||
37 | class ViewVCVersionCheck extends VNag { |
||
38 | protected $argSystemDir = null; |
||
39 | |||
40 | public function __construct() { |
||
41 | parent::__construct(); |
||
42 | |||
43 | $this->registerExpectedStandardArguments('Vht'); |
||
44 | |||
45 | $this->getHelpManager()->setPluginName('check_viewvc_version'); |
||
46 | $this->getHelpManager()->setVersion('1.0'); |
||
47 | $this->getHelpManager()->setShortDescription('This plugin checks if a local ViewVC 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, 'viewvcPath', 'The local directory where your ViewVC installation is located.')); |
||
54 | } |
||
55 | |||
56 | protected function get_local_version($path) { |
||
57 | $path = realpath($path) === false ? $path : realpath($path); |
||
58 | |||
59 | if (!file_exists("$path/lib/viewvc.py")) { |
||
60 | throw new Exception("Cannot find ViewVC settings file at $path"); |
||
61 | } |
||
62 | |||
63 | $cont = @file_get_contents("$path/lib/viewvc.py"); |
||
64 | |||
65 | if (!preg_match('@__version__\\s*=\\s*([\'"])(.+)\\1@ismU', $cont, $m)) { |
||
66 | throw new Exception("Cannot determine version for system $path"); |
||
67 | } |
||
68 | |||
69 | return $m[2]; // e.g. "1.3.0-dev" |
||
70 | } |
||
71 | |||
72 | protected function get_latest_version() { |
||
76 | daniel-mar | 73 | $cont = $this->url_get_contents('https://api.github.com/repos/viewvc/viewvc/releases/latest'); |
74 | if ($cont === false) { |
||
75 | throw new Exception('Cannot parse version from GitHub API. The plugin probably needs to be updated. A'); |
||
59 | daniel-mar | 76 | } |
77 | |||
78 | $data = @json_decode($cont, true); |
||
76 | daniel-mar | 79 | if ($data === false) { |
59 | daniel-mar | 80 | throw new Exception('Cannot parse version from GitHub API. The plugin probably needs to be updated. B'); |
81 | } |
||
82 | |||
83 | return $data['tag_name']; // e.g. "1.2.1" |
||
84 | } |
||
85 | |||
86 | protected function cbRun($optional_args=array()) { |
||
87 | $system_dir = $this->argSystemDir->getValue(); |
||
88 | if (empty($system_dir)) { |
||
89 | throw new Exception("Please specify the directory of the ViewVC installation."); |
||
90 | } |
||
91 | $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir); |
||
92 | |||
93 | if (!is_dir($system_dir)) { |
||
94 | throw new Exception('Directory "'.$system_dir.'" not found.'); |
||
95 | } |
||
96 | |||
97 | $local_version = $this->get_local_version($system_dir); |
||
98 | |||
99 | $latest_stable = $this->get_latest_version(); |
||
100 | |||
101 | // Note: version_compare() correctly assumes that 1.3.0-dev is higher than 1.3.0 |
||
102 | if (version_compare($local_version,$latest_stable,'>')) { |
||
103 | $this->setStatus(VNag::STATUS_OK); |
||
104 | $this->setHeadline("Version $local_version (Latest stable version $latest_stable) at $system_dir", true); |
||
105 | } else if (version_compare($local_version,$latest_stable,'=')) { |
||
106 | $this->setStatus(VNag::STATUS_OK); |
||
107 | $this->setHeadline("Version $local_version (Latest stable version) at $system_dir", true); |
||
108 | } else { |
||
109 | $this->setStatus(VNag::STATUS_WARNING); |
||
110 | $this->setHeadline("Version $local_version is outdated (Latest version is $latest_stable) at $system_dir", true); |
||
111 | } |
||
112 | } |
||
113 | } |