Rev 26 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4 | daniel-mar | 1 | <?php /* <ViaThinkSoftSignature> |
29 | daniel-mar | 2 | c6K9U34rihSmV00RaktE6k1QfQMXELztOZJRg2Y/oTgHt9UsKQf3miExkxS1SlTM+ |
3 | e90vjqFv4CCayiwriwphQ2vGbel0NJMzNXLUpiajfS1uNvqbisve89dRxQzKahk6P |
||
4 | JKqm8+GfEJN0ytjLxMbYGEacwLONVsgrQpVFtsBpkrdPV3r45kIcfbe4uRotHPqgR |
||
5 | rdc05cxUWoGUmLy8aylO4IcrzgnV4Ca8YMV1gucKy2vhiGybySLrE6NHUtLqrHCCK |
||
6 | y3cZxxtkMvRx90UWfK6/wl7QJdHe93jfAU+pbXAiRmOhwIB4zB7umUjw8zKcS2/Dl |
||
7 | 0Tu5XY7FxpgkbueC3lKDXvFiVVTEb+pFSl/cVHktt+IaOYVVG0zwAwaMd0eaDr2Su |
||
8 | NdFSIQzYWjTQ5SrSORbao4WZdao4uN7YjYFSRcI7PRnFyaTfR/SoLOq1J/CK7SD2m |
||
9 | gG1xvVce0I3GpSjlWVksBu2R5Jr4/J1vT7wJZuuxLbJhcpH5PAhuzcAaCw0PrhTgT |
||
10 | IUjPwZbD1bzTO4HOx5WRCV9d68FbPoufhEesol7Zgb2gBbMSlkCmNpH+KQ9Dwv6/X |
||
11 | XUWgtQPA/CDBHRvVECzY1du6JdEnVZbjkRPuRmUBLu1ULsix3nQJxS0MGJsVVjWj7 |
||
12 | 1vD7LeRA86kw22/GKabMqSaJRyJM9b7w3xiWZiWvUEtSWieUWoK80qFwVrNhtgNtZ |
||
13 | UNs6dDXDkmzOjxmPBR5ZEhRkaCSMSTtI3GONxI5Fr/weBEMavurTqF0mDpDL+I5kJ |
||
14 | lTt9RIBG0vttzIx1a7ZR3T3NJp+3kNUr0xlikpCobf0lpd9aErkB5+Hv2JOa+Glbg |
||
15 | sDbFnOf+yUj4VHJoNgaLs+TafkSZ4a0j2dQSja1t+KMYjeUYH1Jxp4LJV/pUsn4Fc |
||
16 | 1fgF3onuq/hZO4BlVMU+3pDT7sfL9ofSuJ4SIjsD350aQZW0Hl91g990y7mjBGYM/ |
||
17 | dG9+NhfPJKqj0pe4l7Rqcfeo2whmWEmi+rO847gbEJtG6mDKl6fqwP+CtXkVb1QBb |
||
18 | reXI1aYc0cX7bAuvJ6Jut4OmtbYVS5I2xCl98cdmiyaGYtII8PPIzF8NOx6PbV+Yo |
||
19 | Cgl1KUNepBqVnODB6CfdJKLp2RBv1WIwGsRmzZ+cOYBVbntj6urUrwfRTBxb95NkF |
||
20 | nM6xiLZhPlQlLwlvDVlxONeVTrKiJ1T6jg/piv8AZunrTHRaTAJd8rEX4ZtJ4kJDw |
||
21 | Zdor1tSgWF4n7ZSs4eKxwRHTCe4+Y/CKCHUGT1ntmpfB75ZC12h+XiqOifG1p0l96 |
||
22 | sJhUNp6++mfh+nowQ02j3v6QMxOqRFwhfNfTTvQMlelLpXMU5lGjcv8GrecP4p+7s |
||
23 | w== |
||
4 | daniel-mar | 24 | </ViaThinkSoftSignature> */ ?> |
2 | daniel-mar | 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 | * |
||
26 | daniel-mar | 32 | * Revision 2021-04-10 |
2 | daniel-mar | 33 | */ |
34 | |||
35 | declare(ticks=1); |
||
36 | |||
37 | class MediaWikiVersionCheck 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_mediawiki_version'); |
||
46 | $this->getHelpManager()->setVersion('1.0'); |
||
47 | $this->getHelpManager()->setShortDescription('This plugin checks if a local MediaWiki 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, 'mediawikiPath', 'The local directory where MediaWiki installation is located.')); |
||
54 | } |
||
55 | |||
56 | protected function get_mediawiki_version($path) { |
||
57 | $path = realpath($path) === false ? $path : realpath($path); |
||
58 | |||
59 | $c = @file_get_contents("$path/includes/DefaultSettings.php"); |
||
60 | |||
61 | if (!preg_match('@\\$wgVersion = \'([0-9\\.]+)\';@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() { |
||
6 | daniel-mar | 69 | $cont = @file_get_contents('https://www.mediawiki.org/wiki/Download/en'); |
2 | daniel-mar | 70 | if (!$cont) { |
71 | throw new Exception("Cannot access website with latest version"); |
||
72 | } |
||
73 | |||
26 | daniel-mar | 74 | if (!preg_match('@//releases\.wikimedia\.org/mediawiki/([^"]+)/mediawiki\-([^"]+)\.tar\.gz"@ismU', $cont, $m)) { |
2 | daniel-mar | 75 | throw new Exception("Cannot find version information on the website"); |
76 | } |
||
77 | |||
26 | daniel-mar | 78 | return $m[2]; |
2 | daniel-mar | 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 MediaWiki 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.'); |
2 | daniel-mar | 90 | } |
91 | |||
92 | $version = $this->get_mediawiki_version($system_dir); |
||
93 | |||
94 | $latest_version = $this->get_latest_version(); |
||
95 | |||
96 | if ($version == $latest_version) { |
||
97 | $this->setStatus(VNag::STATUS_OK); |
||
98 | $this->setHeadline("Version $version at $system_dir", true); |
||
99 | } else { |
||
100 | $this->setStatus(VNag::STATUS_WARNING); |
||
101 | $this->setHeadline("Version $version is outdated (Latest version is $latest_version) at $system_dir", true); |
||
102 | } |
||
103 | } |
||
104 | } |