Rev 1116 | Rev 1200 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
635 | daniel-mar | 1 | <?php |
2 | |||
3 | /* |
||
4 | * OIDplus 2.0 |
||
997 | daniel-mar | 5 | * Copyright 2019 - 2022 Daniel Marschall, ViaThinkSoft |
635 | daniel-mar | 6 | * |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
||
8 | * you may not use this file except in compliance with the License. |
||
9 | * You may obtain a copy of the License at |
||
10 | * |
||
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
||
12 | * |
||
13 | * Unless required by applicable law or agreed to in writing, software |
||
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
||
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||
16 | * See the License for the specific language governing permissions and |
||
17 | * limitations under the License. |
||
18 | */ |
||
19 | |||
1050 | daniel-mar | 20 | use ViaThinkSoft\OIDplus\OIDplus; |
21 | use ViaThinkSoft\OIDplus\OIDplusException; |
||
22 | use ViaThinkSoft\OIDplus\OIDplusPageAdminVNagVersionCheck; |
||
23 | |||
648 | daniel-mar | 24 | include __DIR__ . '/../../../../vendor/danielmarschall/vnag/framework/vnag_framework.inc.php'; |
25 | include __DIR__ . '/../../../../includes/oidplus.inc.php'; |
||
635 | daniel-mar | 26 | |
1116 | daniel-mar | 27 | const OIDPLUS_VNAG_MAX_CACHE_AGE = 60; // seconds (TODO: in base config?) |
635 | daniel-mar | 28 | |
29 | OIDplus::init(false); |
||
30 | |||
1050 | daniel-mar | 31 | if (OIDplus::baseConfig()->getValue('DISABLE_PLUGIN_ViaThinkSoft\OIDplus\OIDplusPageAdminVNagVersionCheck', false)) { |
635 | daniel-mar | 32 | throw new OIDplusException(_L('This plugin was disabled by the system administrator!')); |
33 | } |
||
34 | |||
35 | class VNagMonitorDummy extends VNag { |
||
36 | |||
37 | private $status; |
||
38 | |||
39 | private $content; |
||
40 | |||
41 | public function __construct($status, $content) { |
||
42 | parent::__construct(); |
||
43 | $this->status = $status; |
||
44 | $this->content = $content; |
||
45 | } |
||
46 | |||
47 | protected function cbRun($optional_args = array()) { |
||
48 | $this->setStatus($this->status); |
||
49 | $this->setHeadline($this->content); |
||
50 | } |
||
51 | } |
||
52 | |||
53 | $cache_file = OIDplus::localpath() . 'userdata/cache/vnag_version_check.ser'; |
||
54 | |||
55 | if ((file_exists($cache_file)) && (time()-filemtime($cache_file) <= OIDPLUS_VNAG_MAX_CACHE_AGE)) { |
||
56 | // Anti DoS |
||
57 | |||
58 | // TODO: There is a small flaw: If the admin fails to secure the "cache/" folder |
||
59 | // from the public, then people can read the version file, even if the |
||
60 | // VNag script is intended to be protected by a vnag_password. |
||
61 | list($out_stat, $out_msg) = unserialize(file_get_contents($cache_file)); |
||
62 | |||
63 | } else { |
||
64 | |||
65 | $installType = OIDplus::getInstallType(); |
||
66 | |||
67 | if ($installType === 'ambigous') { |
||
68 | $out_stat = VNag::STATUS_UNKNOWN; |
||
716 | daniel-mar | 69 | $out_msg = 'Multiple version files/directories (oidplus_version.txt, .version.php, .git, or .svn) are existing! Therefore, the version is ambiguous!'; // do not translate |
635 | daniel-mar | 70 | } else if ($installType === 'unknown') { |
71 | $out_stat = VNag::STATUS_UNKNOWN; |
||
72 | $out_msg = 'The version cannot be determined, and the update needs to be applied manually!'; // do not translate |
||
73 | } else if (($installType === 'svn-wc') || ($installType === 'git-wc')) { |
||
74 | $local_installation = OIDplus::getVersion(); |
||
648 | daniel-mar | 75 | $newest_version = getLatestRevision(); |
635 | daniel-mar | 76 | |
77 | $requireInfo = ($installType === 'svn-wc') ? 'shell access with svn/svnversion tool, or PDO/SQLite3 PHP extension' : 'shell access with Git client'; // do not translate |
||
78 | $updateCommand = ($installType === 'svn-wc') ? 'svn update' : 'git pull'; |
||
79 | |||
80 | if (!$newest_version) { |
||
81 | $out_stat = VNag::STATUS_UNKNOWN; |
||
82 | $out_msg = 'OIDplus could not determine the latest version. Probably the ViaThinkSoft server could not be reached.'; // do not translate |
||
83 | } else if (!$local_installation) { |
||
84 | $out_stat = VNag::STATUS_UNKNOWN; |
||
85 | $out_msg = 'OIDplus could not determine its version (Required: ' . $requireInfo . '). Please update your system manually via the "' . $updateCommand . '" command regularly.'; // do not translate |
||
997 | daniel-mar | 86 | } else if (version_compare($local_installation, $newest_version) >= 0) { |
635 | daniel-mar | 87 | $out_stat = VNag::STATUS_OK; |
88 | $out_msg = 'You are using the latest version of OIDplus (' . $local_installation . ' local / ' . $newest_version . ' remote)'; // do not translate |
||
89 | } else { |
||
90 | $out_stat = VNag::STATUS_WARNING; |
||
91 | $out_msg = 'OIDplus is outdated. (' . $local_installation . ' local / ' . $newest_version . ' remote)'; // do not translate |
||
92 | } |
||
93 | } else if ($installType === 'svn-snapshot') { |
||
94 | $local_installation = OIDplus::getVersion(); |
||
648 | daniel-mar | 95 | $newest_version = getLatestRevision(); |
635 | daniel-mar | 96 | |
97 | if (!$newest_version) { |
||
98 | $out_stat = VNag::STATUS_UNKNOWN; |
||
99 | $out_msg = 'OIDplus could not determine the latest version. Probably the ViaThinkSoft server could not be reached.'; // do not translate |
||
1143 | daniel-mar | 100 | } else if (!$local_installation) { |
101 | $out_stat = 'WARN'; |
||
102 | $out_msg = 'OIDplus could not determine its version. Please update your system manually by downloading the latest archive file from oidplus.com.'; // do not translate |
||
997 | daniel-mar | 103 | } else if (version_compare($local_installation, $newest_version) >= 0) { |
635 | daniel-mar | 104 | $out_stat = VNag::STATUS_OK; |
105 | $out_msg = 'You are using the latest version of OIDplus (' . $local_installation . ' local / ' . $newest_version . ' remote)'; // do not translate |
||
106 | } else { |
||
107 | $out_stat = VNag::STATUS_WARNING; |
||
108 | $out_msg = 'OIDplus is outdated. (' . $local_installation . ' local / ' . $newest_version . ' remote)'; // do not translate |
||
109 | } |
||
110 | } else { |
||
111 | assert(false); |
||
112 | die(); |
||
113 | } |
||
114 | |||
115 | @file_put_contents($cache_file, serialize(array($out_stat, $out_msg))); |
||
116 | } |
||
117 | |||
118 | $job = new VNagMonitorDummy($out_stat, $out_msg); |
||
119 | if (OIDplus::config()->getValue('vnag_version_check_password_protected','1') == '1') { |
||
120 | $job->http_visual_output = VNag::OUTPUT_NEVER; |
||
121 | $job->password_out = OIDplusPageAdminVNagVersionCheck::vnag_password(); |
||
122 | $job->outputHTML(_L('This page contains an encrypted VNag machine-readable status.')); |
||
123 | } else { |
||
124 | $job->http_visual_output = VNag::OUTPUT_ALWAYS; |
||
125 | } |
||
126 | if (OIDplus::getPkiStatus()) { |
||
830 | daniel-mar | 127 | $job->privkey = OIDplus::getSystemPrivateKey(); |
635 | daniel-mar | 128 | } |
129 | $job->run(); |
||
130 | unset($job); |
||
648 | daniel-mar | 131 | |
1005 | daniel-mar | 132 | OIDplus::invoke_shutdown(); |
133 | |||
648 | daniel-mar | 134 | # --- |
135 | |||
136 | function getLatestRevision() { |
||
137 | try { |
||
716 | daniel-mar | 138 | if (function_exists('gzdecode')) { |
139 | $url = OIDplus::getEditionInfo()['revisionlog_gz']; |
||
140 | $cont = url_get_contents($url); |
||
141 | if ($cont !== false) $cont = @gzdecode($cont); |
||
142 | } else { |
||
143 | $url = OIDplus::getEditionInfo()['revisionlog']; |
||
144 | $cont = url_get_contents($url); |
||
145 | } |
||
648 | daniel-mar | 146 | if ($cont === false) return false; |
147 | $ary = @unserialize($cont); |
||
148 | if ($ary === false) return false; |
||
149 | krsort($ary); |
||
150 | $max_rev = array_keys($ary)[0]; |
||
151 | return 'svn-' . $max_rev; |
||
1050 | daniel-mar | 152 | } catch (\Exception $e) { |
648 | daniel-mar | 153 | return false; |
154 | } |
||
155 | } |
||
156 |