Subversion Repositories vnag

Rev

Rev 18 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
18 daniel-mar 1
<?php /* <ViaThinkSoftSignature>
29 daniel-mar 2
NYkLKM16RHNYfXmjgdkPJRDFv60IevURDpDXhislrri20CeCNbL85l/s8qTzwi3B3
3
DBka6P0CaPrhOx1eBOTJ1/DgFMP8peQnG/VE+Riq35tzS5m0rX7b8zAt0f14HmuB4
4
cpLY91ZtLUEb+KM+rKLu+mn+oXHbUo8+Tti7MAOp+GxR2mBPHJFgW3NgfaFdmBWiY
5
MQiVUcpo4+Jc3iLUkMEHvUpspOJLWwXdl5iznN98AvboiMd30qujSZDcFXvyRgsJv
6
BMhw8k/snsHTBvsfsDsaluVNGIK97Vuj70fRUeYxhWgLwuZogHu6T4LL0rpk7sMuN
7
BM3kZJ8/7o9rP0JiKuEsGchn04sr5DmOL6k3W1DN/BwhUEEjqAqfKD1X06fkXlNeb
8
BXOK21kKvjOk3EdUlEAWH+xiMf5eFAYNl4EjKPNwRMZXF4j2oU3VLBqjWWJtUfIfi
9
7HaxyNMafm0d0coVgqoTJfnpXGVjPDVsRKJvKhRemjP9orra9Uxi9y3ONKAgB0ekW
10
FeoTps5GyOZCRuUPnJ9dAQpz//COJX/AXG8qDYsVxx9CMyEyIvb5dcFF3RVbsYvNN
11
i1TpvlVMgcTAzWAmXm0EQ53+Q823Kk3IuYUTUj/W6Azzz5SR6wFjwUumRF0EKsgBW
12
zuh7xcXGrVoqmel+qb0vRLWC39sLtxcFEDDPsDHKOS5CsoRT+CbZuLujh6fOz+PMc
13
H42WIFPDKVLw/t2v3GFNxwMNCS3B1zazEGzRhuAkZH2tl8+i6jALKalhS9YUpEIrW
14
ctW//ddZycxhRcmiRJABCZvKNDNEbWGu2FGvBDyA2tpsNwtrLHl5EzJV/UqusV853
15
eMVoCz+QA170yxOgjos91Bizs/AIJnlYTOqXDaJQLA48qwCW+SqDJtnuvVVDwaRPY
16
4G138y45OVyg9tEihatiTupXtI30DoAadPZSx2pdEIbCegKrfX5CicjJseIegqTdh
17
Dfk6LrTfZLlZH7I3bqTbent8ksfY5HUVBhYDHYxe8WuYaH/JjoQR+OetX4Oc4H7TL
18
02J+8ZlRtbPC/RiJBiCvkrfdIKfEgPuAe7tJcak/qkOX732n9YbG57FGkLN8O1UL5
19
Zq5JGoraJCPQ7n0DQFVJE6czbagE8qRsIg8vcojkggm3keP1lHLD9d9iCFXxmq3nR
20
t48A0i4MOoviV+9b6flfEBzXc2E8QN0fe+7Y/3zBASpBp7y/93dvPJHXHUqQy/3IA
21
YE9Pis9ln8iBIlgXycu0PAeeHZgAOoXwxmZci/etLAiSJ3Uy/lfriyBBg7bR0U554
22
OofVYwCyRyh9V46ifqhpYVdsqpFllmyiZGdJgm0CfIcAFiEjXAwljH8i0wU+hEHza
23
w==
18 daniel-mar 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 2020-03-12
33
 */
34
 
35
declare(ticks=1);
36
 
37
class PmWikiVersionCheck 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_pmwiki_version');
46
                $this->getHelpManager()->setVersion('1.0');
47
                $this->getHelpManager()->setShortDescription('This plugin checks if a local PmWiki 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, 'pmWikiPath', 'The local directory where PmWiki installation is located.'));
54
        }
55
 
56
        protected function get_pmwiki_version($path) {
57
                $path = realpath($path) === false ? $path : realpath($path);
58
 
59
                $c = @file_get_contents("$path/scripts/version.php");
60
 
61
                if (!preg_match('@\\$Version="pmwiki-(.+)";@is', $c, $m)) {
62
                        throw new Exception("Cannot find version information at $path");
63
                }
64
 
65
                return $m[1];
66
        }
67
 
68
        protected function get_latest_version() {
69
                $cont = @file_get_contents('https://www.pmwiki.org/wiki/PmWiki/Download');
70
                if (!$cont) {
71
                        throw new Exception("Cannot access website with latest version");
72
                }
73
 
74
                if (!preg_match('@Latest <em>stable</em> release \(pmwiki-(.+)<@ismU', $cont, $m)) {
75
                        throw new Exception("Cannot find version information on the website");
76
                }
77
 
78
                return $m[1];
79
        }
80
 
81
        protected function cbRun($optional_args=array()) {
82
                $system_dir = $this->argSystemDir->getValue();
83
                if (empty($system_dir)) {
84
                        throw new Exception("Please specify the directory of the PmWiki installation.");
85
                }
86
                $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir);
87
 
88
                if (!is_dir($system_dir)) {
29 daniel-mar 89
                        throw new Exception('Directory "'.$system_dir.'" not found.');
18 daniel-mar 90
                }
91
 
92
                $version = $this->get_pmwiki_version($system_dir);
93
 
94
                $latest_version = $this->get_latest_version();
95
 
96
                // TODO: We should probably use version_compare() instead of string comparison
97
                if ($version == $latest_version) {
98
                        $this->setStatus(VNag::STATUS_OK);
99
                        $this->setHeadline("Version $version at $system_dir", true);
100
                } else {
101
                        $this->setStatus(VNag::STATUS_WARNING);
102
                        $this->setHeadline("Version $version is outdated (Latest version is $latest_version) at $system_dir", true);
103
                }
104
        }
105
}