Subversion Repositories vnag

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
32 daniel-mar 1
<?php /* <ViaThinkSoftSignature>
2
TAItYQDND8ibGUd1YC/f04SIIzeSm99JNg+mmSjefJjt841dZ7o9BCrAGDh2jiv+7
3
akv0WmInOLOjoJPsglVIAEEBh/SfaxvzGfprA8vj54DZ11seUBF7jXUy+WCVapBke
4
yAGvtEAIZ5gToiyzs0aE94svxZZfpC7clFRhqON5u1XMZhdSsVgEfzJcIJroq35NE
5
2IRUebM4La1mBuopQWwx6FSFuxUjwcn7Q/zUP1rCwU8VAL/ycbG10FGNtYU14sOXl
6
ymQoh2A2ODFO2LYpMxh+7vHASw2Nnk6BhuvQAwM3C+SBW56SkWZK/JkRXLN9NoqKk
7
5uxSC6YUlsi1OPJULaVWOoBvjUIau809jeeW72COFRjZKkX266Rv7mm6wrcxoOIXh
8
Cj+m2bP42thx+Df1i4/CFFsxg/sHvorkwS+6B+0kGl1+2Ghwx3L94F+ThJxWtGOhM
9
Jawl3weaWZuojsU79HRnqBK+Yy8Shuzq/k+FonrJE4FE4oogIf7pzXGKOqXvjtXxG
10
DoWCa/hotEFcs+mCYeAAjpDf2V8qSFKT2odHjJwLklKpIov+Tlr/XtMrZtCIDjDh3
11
KBH6/9+8Bw5S5nFGvNfThSihlWKloqvysKDiCxIaLCOszzWNgsUUbUgppv2NFFzso
12
QkJ22yObljS6p47cYnNmd5Pp3q9+JCTn5epn+XP4RRN3Z+ax7tiusqqVnlik0pwb3
13
+9Yrl4Pq4QkloolrEnsQtyy3xlrk53fVCWoA3aLNcYVHN8Nl4OjyIEImLbkNPddHz
14
RUqGSNgoEZDKKbfi7i52VssHWzv/9HzHvNpoThbln8C3q8WFlgnuSStpwZSonZEPo
15
9wvnVo8orJjLzflkjPtBLIS7EL+R66RqpP3PF1lTi4Xl6fh9BFxif9juBSsCaJAjV
16
H0YECXyGiNPb1XcUXrDhWUrCViloHDq6sEQgW64s33SGqksFXG6IN/NV+54mW0hG4
17
PUzIZ6Bgu9HggpfgFSAuzAW5xTMq/ng19pjo9y7cdeSnMF43BPhg3SSdvX2W8oRn1
18
Fv5BHbsvw5vvHJUf+kUA5YN0IRUtOmoDB2Z4kkzuP9VBLoqK9KWG9PXZ5sMWp6ib9
19
1KqMuFbx4y5NI9kjwhCQXuDAF2bJhtCHuPU+IyjhWqtFTWhD583AaHjt0gaVzkcuN
20
umskt4IR5Yqvo6oDtWCP7YRWJnzAFB9zDItFk1OjjomaSkKQvhztITWO4N3jmtonG
21
PkIUkR8DWEYLZUSP+zWV9UZ2yE5KYAwgXIstx2ovLSvV6f5kyz+z+x0sU7fo4m0qa
22
2HjjwaFSWf/yGHDkEch/5woquK4YWrrlFzCQZmhok6tSF8WS+eb6Ci4/wsCa1Znx4
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
                // TODO: this is a security vulnerability if an non-root user can control the input of version.php !
64
                $vendor = 'unknown';
65
                $OC_Version = array(0,0,0,0);
66
                $OC_VersionString = 'unknown';
67
                $OC_Edition = 'unknown';
68
                $OC_Channel = 'unknown';
69
                $OC_Build = 'unknown';
70
                include $local_path . '/version.php';
71
 
72
                if ($vendor != 'owncloud') {
73
                        throw new Exception('This is not a valid ownCloud installation in "'.$local_path.'". It is "$vendor".');
74
                }
75
 
76
                // Owncloud\Updater\Utils\Fetcher::DEFAULT_BASE_URL
77
                $baseUrl = 'https://updates.owncloud.com/server/';
78
 
79
                $update_url = $baseUrl . '?version='.
80
                              implode('x', $OC_Version).'x'.
81
                              'installedatx'.
82
                              'lastupdatedatx'.
83
                              $OC_Channel.'x'.
84
                              $OC_Edition.'x'.
85
                              urlencode($OC_Build);
86
 
87
                $cont = file_get_contents($update_url);
88
                if ($cont === false) {
89
                        throw new Exception('Could not determinate current ownCloud version in "'.$local_path.'".');
90
                }
91
 
92
                if ($cont === '') {
93
                        return array($OC_VersionString, $OC_VersionString, $OC_Channel);
94
                } else {
95
                        $xml = simplexml_load_string($cont);
96
                        $new_ver = (string)$xml->version;
97
                        return array($OC_VersionString, $new_ver, $OC_Channel);
98
                }
99
        }
100
 
101
        protected function cbRun($optional_args=array()) {
102
                $system_dir = $this->argSystemDir->getValue();
103
                if (empty($system_dir)) {
104
                        throw new Exception("Please specify the directory of the ownCloud installation.");
105
                }
106
                $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir);
107
 
108
                if (!is_dir($system_dir)) {
109
                        throw new Exception('Directory "'.$system_dir.'" not found.');
110
                }
111
 
112
                list($cur_ver, $new_ver, $channel) = $this->get_owncloud_version($system_dir);
113
 
114
                if ($cur_ver === $new_ver) {
115
                        $this->setStatus(VNag::STATUS_OK);
116
                        $this->setHeadline("ownCloud version $cur_ver [$channel] is the latest available version for your ownCloud installation at $system_dir", true);
117
                } else {
118
                        $this->setStatus(VNag::STATUS_WARNING);
119
                        $this->setHeadline("ownCloud version $cur_ver [$channel] is outdated. Newer version is $new_ver [$channel] for installation at $system_dir", true);
120
                }
121
        }
122
}