Rev 1426 | 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 |
||
1321 | daniel-mar | 5 | * Copyright 2019 - 2023 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; |
||
1200 | daniel-mar | 22 | use ViaThinkSoft\OIDplus\OIDplusGui; |
1050 | daniel-mar | 23 | use ViaThinkSoft\OIDplus\OIDplusPageAdminVNagVersionCheck; |
24 | |||
1421 | daniel-mar | 25 | include __DIR__ . '/../../../../vendor/danielmarschall/vnag/src/framework/vnag_framework.inc.php'; |
648 | daniel-mar | 26 | include __DIR__ . '/../../../../includes/oidplus.inc.php'; |
635 | daniel-mar | 27 | |
1116 | daniel-mar | 28 | const OIDPLUS_VNAG_MAX_CACHE_AGE = 60; // seconds (TODO: in base config?) |
635 | daniel-mar | 29 | |
1200 | daniel-mar | 30 | set_exception_handler(array(OIDplusGui::class, 'html_exception_handler')); |
635 | daniel-mar | 31 | |
1200 | daniel-mar | 32 | OIDplus::init(true); |
33 | |||
1050 | daniel-mar | 34 | if (OIDplus::baseConfig()->getValue('DISABLE_PLUGIN_ViaThinkSoft\OIDplus\OIDplusPageAdminVNagVersionCheck', false)) { |
635 | daniel-mar | 35 | throw new OIDplusException(_L('This plugin was disabled by the system administrator!')); |
36 | } |
||
37 | |||
38 | class VNagMonitorDummy extends VNag { |
||
39 | |||
40 | private $status; |
||
41 | |||
42 | private $content; |
||
43 | |||
44 | public function __construct($status, $content) { |
||
45 | parent::__construct(); |
||
46 | $this->status = $status; |
||
47 | $this->content = $content; |
||
48 | } |
||
49 | |||
50 | protected function cbRun($optional_args = array()) { |
||
51 | $this->setStatus($this->status); |
||
52 | $this->setHeadline($this->content); |
||
53 | } |
||
54 | } |
||
55 | |||
56 | $cache_file = OIDplus::localpath() . 'userdata/cache/vnag_version_check.ser'; |
||
57 | |||
58 | if ((file_exists($cache_file)) && (time()-filemtime($cache_file) <= OIDPLUS_VNAG_MAX_CACHE_AGE)) { |
||
59 | // Anti DoS |
||
60 | |||
61 | // TODO: There is a small flaw: If the admin fails to secure the "cache/" folder |
||
62 | // from the public, then people can read the version file, even if the |
||
63 | // VNag script is intended to be protected by a vnag_password. |
||
64 | list($out_stat, $out_msg) = unserialize(file_get_contents($cache_file)); |
||
65 | |||
66 | } else { |
||
67 | |||
68 | $installType = OIDplus::getInstallType(); |
||
69 | |||
70 | if ($installType === 'ambigous') { |
||
71 | $out_stat = VNag::STATUS_UNKNOWN; |
||
1426 | daniel-mar | 72 | $out_msg = 'Multiple version files/directories (.git and .svn) are existing! Therefore, the distribution channel is ambiguous!'; // do not translate |
635 | daniel-mar | 73 | } else if ($installType === 'unknown') { |
74 | $out_stat = VNag::STATUS_UNKNOWN; |
||
75 | $out_msg = 'The version cannot be determined, and the update needs to be applied manually!'; // do not translate |
||
76 | } else if (($installType === 'svn-wc') || ($installType === 'git-wc')) { |
||
77 | $local_installation = OIDplus::getVersion(); |
||
648 | daniel-mar | 78 | $newest_version = getLatestRevision(); |
635 | daniel-mar | 79 | |
80 | $requireInfo = ($installType === 'svn-wc') ? 'shell access with svn/svnversion tool, or PDO/SQLite3 PHP extension' : 'shell access with Git client'; // do not translate |
||
81 | $updateCommand = ($installType === 'svn-wc') ? 'svn update' : 'git pull'; |
||
82 | |||
83 | if (!$newest_version) { |
||
84 | $out_stat = VNag::STATUS_UNKNOWN; |
||
85 | $out_msg = 'OIDplus could not determine the latest version. Probably the ViaThinkSoft server could not be reached.'; // do not translate |
||
86 | } else if (!$local_installation) { |
||
87 | $out_stat = VNag::STATUS_UNKNOWN; |
||
88 | $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 | 89 | } else if (version_compare($local_installation, $newest_version) >= 0) { |
635 | daniel-mar | 90 | $out_stat = VNag::STATUS_OK; |
91 | $out_msg = 'You are using the latest version of OIDplus (' . $local_installation . ' local / ' . $newest_version . ' remote)'; // do not translate |
||
92 | } else { |
||
93 | $out_stat = VNag::STATUS_WARNING; |
||
94 | $out_msg = 'OIDplus is outdated. (' . $local_installation . ' local / ' . $newest_version . ' remote)'; // do not translate |
||
95 | } |
||
1426 | daniel-mar | 96 | } else if ($installType === 'manual') { |
635 | daniel-mar | 97 | $local_installation = OIDplus::getVersion(); |
648 | daniel-mar | 98 | $newest_version = getLatestRevision(); |
635 | daniel-mar | 99 | |
100 | if (!$newest_version) { |
||
101 | $out_stat = VNag::STATUS_UNKNOWN; |
||
102 | $out_msg = 'OIDplus could not determine the latest version. Probably the ViaThinkSoft server could not be reached.'; // do not translate |
||
1143 | daniel-mar | 103 | } else if (!$local_installation) { |
104 | $out_stat = 'WARN'; |
||
105 | $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 | 106 | } else if (version_compare($local_installation, $newest_version) >= 0) { |
635 | daniel-mar | 107 | $out_stat = VNag::STATUS_OK; |
108 | $out_msg = 'You are using the latest version of OIDplus (' . $local_installation . ' local / ' . $newest_version . ' remote)'; // do not translate |
||
109 | } else { |
||
110 | $out_stat = VNag::STATUS_WARNING; |
||
111 | $out_msg = 'OIDplus is outdated. (' . $local_installation . ' local / ' . $newest_version . ' remote)'; // do not translate |
||
112 | } |
||
113 | } else { |
||
114 | assert(false); |
||
115 | die(); |
||
116 | } |
||
117 | |||
118 | @file_put_contents($cache_file, serialize(array($out_stat, $out_msg))); |
||
119 | } |
||
120 | |||
121 | $job = new VNagMonitorDummy($out_stat, $out_msg); |
||
122 | if (OIDplus::config()->getValue('vnag_version_check_password_protected','1') == '1') { |
||
123 | $job->http_visual_output = VNag::OUTPUT_NEVER; |
||
124 | $job->password_out = OIDplusPageAdminVNagVersionCheck::vnag_password(); |
||
125 | $job->outputHTML(_L('This page contains an encrypted VNag machine-readable status.')); |
||
126 | } else { |
||
127 | $job->http_visual_output = VNag::OUTPUT_ALWAYS; |
||
128 | } |
||
129 | if (OIDplus::getPkiStatus()) { |
||
830 | daniel-mar | 130 | $job->privkey = OIDplus::getSystemPrivateKey(); |
635 | daniel-mar | 131 | } |
132 | $job->run(); |
||
133 | unset($job); |
||
648 | daniel-mar | 134 | |
1005 | daniel-mar | 135 | OIDplus::invoke_shutdown(); |
136 | |||
648 | daniel-mar | 137 | # --- |
138 | |||
139 | function getLatestRevision() { |
||
140 | try { |
||
1442 | daniel-mar | 141 | $changelog_candidates = OIDplus::getEditionInfo()['master_changelog']; |
142 | if (!is_array($changelog_candidates)) $changelog_candidates = [ $changelog_candidates ]; |
||
143 | |||
144 | foreach ($changelog_candidates as $master_changelog) { |
||
145 | try { |
||
146 | $out = OIDplus::getVersion($master_changelog); |
||
147 | if ($out) return $out; |
||
148 | } catch (\Exception $e) { |
||
149 | } |
||
150 | } |
||
151 | return false; |
||
1050 | daniel-mar | 152 | } catch (\Exception $e) { |
648 | daniel-mar | 153 | return false; |
154 | } |
||
155 | } |