Rev 29 | 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> |
76 | daniel-mar | 2 | L2cLimf5MKzRpuLa3QN3ZXwPjg1yIeFbWqIvkJGaSwRxKCg/LL/E2yEQHXu1mHH/8 |
3 | kBIyH2DQ/9fSsSlcNOt4mJfZQ6Ij6999+3AYLR/IGbDTfug1+zvwYwHx4zRSQS2fo |
||
4 | PSHsUL6lAp2G7s+PhLAZywm+vlz1AGHQmXrmPkD8WVlxX9dNpeyGmVpQh+I8+LcRf |
||
5 | WDdLjeW3MphaOWSh6/MQxG60BZEJHjDpGcPiJm38FRBq0l5nH/2pEV0XkRwOsKHbx |
||
6 | hHLc5scufol/6b5GYAG0aiKrbml4mSO41J8r3k0eVdeeXpYJzUR2yDYacOxas/HKZ |
||
7 | +7G7DsgXpY31ELTHIf52h9PIils+DYM2ZG5oGYn85jhqLGAKgd2ZHSTw7ZZ1AZkwY |
||
8 | g+7dZmRZ6Z0QgFTA0eOTpQx61KWxQTFfhEqchtrmeL1xhOG3KPVaNfDJFIqeZV8HJ |
||
9 | 5spNP0rer2gaB9PkbfWAz9yM7hXV7qCSkv1vKD1iwOG+JjeYLbEhHPntx8Hgoxx6K |
||
10 | VEg+F0WUbK0nUYuUMso3alMciLB0igIF+Uf4KmJmpSEKIFezbg2A54ADOf22pnjHJ |
||
11 | rOcmKWOlbfNKFeTqqvadj0KYrYWzCfZkGhFc9xwJs+jh48mUAb+LtQOEejJH7l1cn |
||
12 | 2jnqLJgd0yvnSRc+wTSEWuoFLqA0MiDcfmY8NbtFuXMGiisFk30NSDgHDxbsLjcR1 |
||
13 | pSr0w6iuD6fLa0f07B8DgH0YnZSIP6tJazL7Ho32eXUqeHkryg1b9fzzZmaD0/ISh |
||
14 | bi5OXffJGXog1qvhF9Ga6nQ4qwYtHthOtQh9hgg9VhRtNN9XoHIE//JZWvUCVNhVz |
||
15 | 00g8GOCAiYvobxndpXy9N6D7mA4B0SBkhPuW0UXLOC9MazQIXV9Sqx5kkF3l46tZv |
||
16 | akC7lQyB15W/+vIiVScs3p7r2CC6vh6D8WZH/nBPyetbK8afXkOg0ZfZJznauyt+y |
||
17 | VvXpPBGJjA1UYAmLmcyjkMFY4j0qkY+sRmPTXAVPE1H9GbK2GSNlR2amB98SNxBit |
||
18 | fch507ub1jAAS+a8M3p69Hb9Mv9ljrQpanbabN01rFTuI2yToxTBqdPgUpejKnVpz |
||
19 | 1XjeghVz6ODfDnpyzPhlHzgF2fLj3YZ1SiWVHq+Oeni3uUfSI60Ps0IBQb8MI0+Sj |
||
20 | nJ9w+9y7AuyruCuE0duli9wzNGJOqHYPLmOAxv780dnkFkFK3JUZowaJbpEJAauZ3 |
||
21 | 2kybuyOSwa+hYX4jonikPuQoIKKFZAOEMVUvJK4Rswq2H8jb3y28XHrisPm2f0thM |
||
22 | iAWxG+mm7Fam9DYtIRKzJNKNrYyB1NBMnHa3ev5bxrhCkma9Zj04re8tAZUNSj3Sy |
||
23 | A== |
||
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 | * |
||
76 | daniel-mar | 32 | * Revision 2023-10-13 |
2 | daniel-mar | 33 | */ |
34 | |||
35 | declare(ticks=1); |
||
36 | |||
37 | class RoundcubeVersionCheck 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_roundcube_version'); |
||
46 | $this->getHelpManager()->setVersion('1.0'); |
||
47 | $this->getHelpManager()->setShortDescription('This plugin checks if a local Roundcube Webmail 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, 'roundcubePath', 'The local directory where your Roundcube installation is located.')); |
||
54 | } |
||
55 | |||
76 | daniel-mar | 56 | protected function get_local_version($path) { |
2 | daniel-mar | 57 | $path = realpath($path) === false ? $path : realpath($path); |
58 | |||
59 | $cont = @file_get_contents("$path/program/lib/Roundcube/bootstrap.php"); |
||
60 | if (!preg_match("@define\('RCUBE_VERSION', '(.*)'\);@ismU", $cont, $m)) { |
||
61 | throw new Exception("Cannot find version information at $path"); |
||
62 | } |
||
63 | |||
64 | return $m[1]; |
||
65 | } |
||
66 | |||
76 | daniel-mar | 67 | protected function get_latest_version() { |
68 | $cont = $this->url_get_contents('https://api.github.com/repos/roundcube/roundcubemail/releases/latest'); |
||
69 | if ($cont === false) { |
||
70 | throw new Exception('Cannot parse version from GitHub API. The plugin probably needs to be updated. A'); |
||
71 | } |
||
72 | |||
73 | $data = @json_decode($cont, true); |
||
74 | if ($data === false) { |
||
75 | throw new Exception('Cannot parse version from GitHub API. The plugin probably needs to be updated. B'); |
||
76 | } |
||
77 | |||
78 | return $data['tag_name']; // e.g. "1.6.3" |
||
79 | } |
||
80 | |||
81 | protected function get_latest_versions_with_lts() { |
||
82 | $cont = $this->url_get_contents('https://roundcube.net/download/'); |
||
83 | if ($cont === false) { |
||
84 | throw new Exception('Cannot parse version from Roundcube website. The plugin probably needs to be updated. A'); |
||
85 | } |
||
86 | |||
87 | if (!preg_match_all('@https://github.com/roundcube/roundcubemail/releases/download/([^/]+)/@ismU', $cont, $m)) { |
||
88 | throw new Exception('Cannot parse version from Roundcube website. The plugin probably needs to be updated. B'); |
||
89 | } |
||
90 | |||
91 | return $m[1]; |
||
92 | } |
||
93 | |||
2 | daniel-mar | 94 | protected function cbRun($optional_args=array()) { |
95 | $system_dir = $this->argSystemDir->getValue(); |
||
96 | if (empty($system_dir)) { |
||
97 | throw new Exception("Please specify the directory of the Roundcube installation."); |
||
98 | } |
||
99 | $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir); |
||
100 | |||
101 | if (!is_dir($system_dir)) { |
||
29 | daniel-mar | 102 | throw new Exception('Directory "'.$system_dir.'" not found.'); |
2 | daniel-mar | 103 | } |
104 | |||
76 | daniel-mar | 105 | $version = $this->get_local_version($system_dir); |
2 | daniel-mar | 106 | |
76 | daniel-mar | 107 | try { |
108 | $stable_versions = $this->get_latest_versions_with_lts(); |
||
109 | $latest_version = $stable_versions[0]; |
||
110 | } catch (Exception $e) { |
||
111 | // roundcube.net blocks HTTPS connections from the ViaThinkSoft server since 13 Oct 2023. WHY?! |
||
112 | // Access GitHub instead (but we do not get the LTS information there...) |
||
113 | $latest_version = $this->get_latest_version(); |
||
114 | $stable_versions = [ $latest_version ]; |
||
2 | daniel-mar | 115 | } |
116 | |||
76 | daniel-mar | 117 | if (in_array($version, $stable_versions)) { |
2 | daniel-mar | 118 | if ($version === $latest_version) { |
119 | $this->setStatus(VNag::STATUS_OK); |
||
120 | $this->setHeadline("Version $version (Latest Stable version) at $system_dir", true); |
||
121 | } else { |
||
122 | $this->setStatus(VNag::STATUS_OK); |
||
123 | $this->setHeadline("Version $version (Old Stable / LTS version; latest version is $latest_version) at $system_dir", true); |
||
124 | } |
||
125 | } else { |
||
126 | $this->setStatus(VNag::STATUS_WARNING); |
||
127 | $this->setHeadline("Version $version is outdated (Latest version is $latest_version) at $system_dir", true); |
||
128 | } |
||
129 | } |
||
130 | } |
||
131 |