Subversion Repositories oidplus

Rev

Rev 1278 | Rev 1375 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1278 Rev 1293
1
<?php
1
<?php
2
 
2
 
3
/*
3
/*
4
 * OIDplus 2.0
4
 * OIDplus 2.0
5
 * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft
5
 * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft
6
 *
6
 *
7
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with 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
9
 * You may obtain a copy of the License at
10
 *
10
 *
11
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 *
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 * See the License for the specific language governing permissions and
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
17
 * limitations under the License.
18
 */
18
 */
19
 
19
 
20
namespace ViaThinkSoft\OIDplus;
20
namespace ViaThinkSoft\OIDplus;
21
 
21
 
22
// phpcs:disable PSR1.Files.SideEffects
22
// phpcs:disable PSR1.Files.SideEffects
23
\defined('INSIDE_OIDPLUS') or die;
23
\defined('INSIDE_OIDPLUS') or die;
24
// phpcs:enable PSR1.Files.SideEffects
24
// phpcs:enable PSR1.Files.SideEffects
25
 
25
 
26
class OIDplusPageAdminSoftwareUpdate extends OIDplusPagePluginAdmin
26
class OIDplusPageAdminSoftwareUpdate extends OIDplusPagePluginAdmin
27
        implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_8 /* getNotifications */
27
        implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_8 /* getNotifications */
28
{
28
{
29
 
29
 
30
        /**
30
        /**
31
         * @param bool $html
31
         * @param bool $html
32
         * @return void
32
         * @return void
33
         */
33
         */
34
        public function init(bool $html=true) {
34
        public function init(bool $html=true) {
35
        }
35
        }
36
 
36
 
37
        /**
37
        /**
38
         * @return string
38
         * @return string
39
         */
39
         */
40
        private function getGitCommand(): string {
40
        private function getGitCommand(): string {
41
                return 'git --git-dir='.escapeshellarg(OIDplus::findGitFolder()).' --work-tree='.escapeshellarg(OIDplus::localpath()).' -C "" pull origin master -s recursive -X theirs';
41
                return 'git --git-dir='.escapeshellarg(OIDplus::findGitFolder()).' --work-tree='.escapeshellarg(OIDplus::localpath()).' -C "" pull origin master -s recursive -X theirs';
42
        }
42
        }
43
 
43
 
44
        /**
44
        /**
45
         * @return string
45
         * @return string
46
         */
46
         */
47
        private function getSvnCommand(): string {
47
        private function getSvnCommand(): string {
48
                return 'svn update --accept theirs-full';
48
                return 'svn update --accept theirs-full';
49
        }
49
        }
50
 
50
 
51
        /**
51
        /**
52
         * @param string $actionID
-
 
53
         * @param array $params
52
         * @param array $params
54
         * @return array
53
         * @return array
55
         * @throws OIDplusException
54
         * @throws OIDplusException
56
         */
55
         */
57
        public function action(string $actionID, array $params): array {
56
        private function action_Update(array $params): array {
58
                if ($actionID == 'update_now') {
-
 
59
                        @set_time_limit(0);
57
                @set_time_limit(0);
60
 
58
 
61
                        if (!OIDplus::authUtils()->isAdminLoggedIn()) {
59
                if (!OIDplus::authUtils()->isAdminLoggedIn()) {
62
                                throw new OIDplusHtmlException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')), null, 401);
60
                        throw new OIDplusHtmlException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')), null, 401);
63
                        }
61
                }
64
 
62
 
65
                        if (OIDplus::getInstallType() === 'git-wc') {
63
                if (OIDplus::getInstallType() === 'git-wc') {
66
                                $cmd = $this->getGitCommand().' 2>&1';
64
                        $cmd = $this->getGitCommand().' 2>&1';
67
 
65
 
68
                                $ec = -1;
66
                        $ec = -1;
69
                                $out = array();
67
                        $out = array();
70
                                exec($cmd, $out, $ec);
68
                        exec($cmd, $out, $ec);
71
 
69
 
72
                                $res = _L('Execute command:').' '.$cmd."\n\n".trim(implode("\n",$out));
70
                        $res = _L('Execute command:').' '.$cmd."\n\n".trim(implode("\n",$out));
73
                                if ($ec === 0) {
71
                        if ($ec === 0) {
74
                                        $rev = 'HEAD'; // do not translate
72
                                $rev = 'HEAD'; // do not translate
75
                                        return array("status" => 0, "content" => $res, "rev" => $rev);
73
                                return array("status" => 0, "content" => $res, "rev" => $rev);
76
                                } else {
74
                        } else {
77
                                        return array("status" => -1, "error" => $res, "content" => "");
75
                                return array("status" => -1, "error" => $res, "content" => "");
78
                                }
76
                        }
79
                        }
77
                }
80
                        else if (OIDplus::getInstallType() === 'svn-wc') {
78
                else if (OIDplus::getInstallType() === 'svn-wc') {
81
                                $cmd = $this->getSvnCommand().' 2>&1';
79
                        $cmd = $this->getSvnCommand().' 2>&1';
82
 
80
 
83
                                $ec = -1;
81
                        $ec = -1;
84
                                $out = array();
82
                        $out = array();
85
                                exec($cmd, $out, $ec);
83
                        exec($cmd, $out, $ec);
86
 
84
 
87
                                $res = _L('Execute command:').' '.$cmd."\n\n".trim(implode("\n",$out));
85
                        $res = _L('Execute command:').' '.$cmd."\n\n".trim(implode("\n",$out));
88
                                if ($ec === 0) {
86
                        if ($ec === 0) {
89
                                        $rev = 'HEAD'; // do not translate
87
                                $rev = 'HEAD'; // do not translate
90
                                        return array("status" => 0, "content" => $res, "rev" => $rev);
88
                                return array("status" => 0, "content" => $res, "rev" => $rev);
91
                                } else {
89
                        } else {
92
                                        return array("status" => -1, "error" => $res, "content" => "");
90
                                return array("status" => -1, "error" => $res, "content" => "");
93
                                }
91
                        }
94
                        }
92
                }
95
                        else if (OIDplus::getInstallType() === 'svn-snapshot') {
93
                else if (OIDplus::getInstallType() === 'svn-snapshot') {
96
 
94
 
97
                                $rev = $params['rev'];
95
                        $rev = $params['rev'];
98
 
96
 
99
                                $update_version = $params['update_version'] ?? 1;
97
                        $update_version = $params['update_version'] ?? 1;
100
                                if (($update_version != 1) && ($update_version != 2)) {
98
                        if (($update_version != 1) && ($update_version != 2)) {
101
                                        throw new OIDplusException(_L('Unknown update version'));
99
                                throw new OIDplusException(_L('Unknown update version'));
102
                                }
100
                        }
103
 
101
 
104
                                // Download and unzip
102
                        // Download and unzip
105
 
103
 
106
                                $cont = false;
104
                        $cont = false;
107
                                for ($retry=1; $retry<=3; $retry++) {
105
                        for ($retry=1; $retry<=3; $retry++) {
108
                                        if (function_exists('gzdecode')) {
106
                                if (function_exists('gzdecode')) {
109
                                                $url = sprintf(OIDplus::getEditionInfo()['update_package_gz'], $rev-1, $rev);
107
                                        $url = sprintf(OIDplus::getEditionInfo()['update_package_gz'], $rev-1, $rev);
110
                                                $cont = url_get_contents($url);
108
                                        $cont = url_get_contents($url);
111
                                                if ($cont !== false) $cont = @gzdecode($cont);
109
                                        if ($cont !== false) $cont = @gzdecode($cont);
112
                                        } else {
110
                                } else {
113
                                                $url = sprintf(OIDplus::getEditionInfo()['update_package'], $rev-1, $rev);
111
                                        $url = sprintf(OIDplus::getEditionInfo()['update_package'], $rev-1, $rev);
114
                                                $cont = url_get_contents($url);
112
                                        $cont = url_get_contents($url);
115
                                        }
113
                                }
116
                                        if ($cont !== false) {
114
                                if ($cont !== false) {
117
                                                break;
115
                                        break;
118
                                        } else {
116
                                } else {
119
                                                sleep(1);
117
                                        sleep(1);
120
                                        }
118
                                }
121
                                }
119
                        }
122
                                if ($cont === false) throw new OIDplusException(_L("Update %1 could not be downloaded from ViaThinkSoft server. Please try again later.",$rev));
120
                        if ($cont === false) throw new OIDplusException(_L("Update %1 could not be downloaded from ViaThinkSoft server. Please try again later.",$rev));
123
 
121
 
124
                                // Check signature...
122
                        // Check signature...
125
 
123
 
126
                                if (function_exists('openssl_verify')) {
124
                        if (function_exists('openssl_verify')) {
127
 
125
 
128
                                        $m = array();
126
                                $m = array();
129
                                        if (!preg_match('@<\?php /\* <ViaThinkSoftSignature>(.+)</ViaThinkSoftSignature> \*/ \?>\n@ismU', $cont, $m)) {
127
                                if (!preg_match('@<\?php /\* <ViaThinkSoftSignature>(.+)</ViaThinkSoftSignature> \*/ \?>\n@ismU', $cont, $m)) {
130
                                                throw new OIDplusException(_L("Update package file of revision %1 not digitally signed",$rev));
128
                                        throw new OIDplusException(_L("Update package file of revision %1 not digitally signed",$rev));
131
                                        }
129
                                }
132
                                        $signature = base64_decode($m[1]);
130
                                $signature = base64_decode($m[1]);
133
 
131
 
134
                                        $naked = preg_replace('@<\?php /\* <ViaThinkSoftSignature>(.+)</ViaThinkSoftSignature> \*/ \?>\n@ismU', '', $cont);
132
                                $naked = preg_replace('@<\?php /\* <ViaThinkSoftSignature>(.+)</ViaThinkSoftSignature> \*/ \?>\n@ismU', '', $cont);
135
                                        $hash = hash("sha256", $naked."update_".($rev-1)."_to_".($rev).".txt");
133
                                $hash = hash("sha256", $naked."update_".($rev-1)."_to_".($rev).".txt");
136
 
134
 
137
                                        $public_key = file_get_contents(__DIR__.'/public.pem');
135
                                $public_key = file_get_contents(__DIR__.'/public.pem');
138
                                        if (!openssl_verify($hash, $signature, $public_key, OPENSSL_ALGO_SHA256)) {
136
                                if (!openssl_verify($hash, $signature, $public_key, OPENSSL_ALGO_SHA256)) {
139
                                                throw new OIDplusException(_L("Update package file of revision %1: Signature invalid",$rev));
137
                                        throw new OIDplusException(_L("Update package file of revision %1: Signature invalid",$rev));
140
                                        }
138
                                }
141
 
139
 
142
                                }
140
                        }
143
 
141
 
144
                                // All OK! Now write the file
142
                        // All OK! Now write the file
145
 
143
 
146
                                $tmp_filename = 'update_'.generateRandomString(10).'.tmp.php';
144
                        $tmp_filename = 'update_'.generateRandomString(10).'.tmp.php';
147
                                $local_file = OIDplus::localpath().$tmp_filename;
145
                        $local_file = OIDplus::localpath().$tmp_filename;
148
 
146
 
149
                                @file_put_contents($local_file, $cont);
147
                        @file_put_contents($local_file, $cont);
150
 
148
 
151
                                if (!file_exists($local_file) || (@file_get_contents($local_file) !== $cont)) {
149
                        if (!file_exists($local_file) || (@file_get_contents($local_file) !== $cont)) {
152
                                        throw new OIDplusException(_L('Update file could not written. Probably there are no write-permissions to the root folder.'));
150
                                throw new OIDplusException(_L('Update file could not written. Probably there are no write-permissions to the root folder.'));
153
                                }
151
                        }
154
 
152
 
155
                                if ($update_version == 1) {
153
                        if ($update_version == 1) {
156
                                        // Now call the written file
154
                                // Now call the written file
157
                                        // Note: we may not use eval($cont) because the script uses die(),
155
                                // Note: we may not use eval($cont) because the script uses die(),
158
                                        // and things in the script might collide with currently (un)loaded source code files, shutdown procedues, etc.
156
                                // and things in the script might collide with currently (un)loaded source code files, shutdown procedues, etc.
159
                                        $web_file = OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE).$tmp_filename; // NOT canonical URL! This might fail with reverse proxies which can only be executed from outside
157
                                $web_file = OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE).$tmp_filename; // NOT canonical URL! This might fail with reverse proxies which can only be executed from outside
160
                                        $res = url_get_contents($web_file);
158
                                $res = url_get_contents($web_file);
161
                                        if ($res === false) {
159
                                if ($res === false) {
162
                                                throw new OIDplusException(_L('Update-script %1 could not be executed',$web_file));
160
                                        throw new OIDplusException(_L('Update-script %1 could not be executed',$web_file));
163
                                        }
161
                                }
164
                                        return array("status" => 0, "content" => $res, "rev" => $rev);
162
                                return array("status" => 0, "content" => $res, "rev" => $rev);
165
                                } else if ($update_version == 2) {
163
                        } else if ($update_version == 2) {
166
                                        // In this version, the client will call the web-update file.
164
                                // In this version, the client will call the web-update file.
167
                                        // This has the advantage that it will also work if the system is htpasswd protected
165
                                // This has the advantage that it will also work if the system is htpasswd protected
168
                                        return array("status" => 0, "update_file" => $tmp_filename, "rev" => $rev);
166
                                return array("status" => 0, "update_file" => $tmp_filename, "rev" => $rev);
169
                                } else {
167
                        } else {
170
                                        throw new OIDplusException(_L("Unexpected update version"));
168
                                throw new OIDplusException(_L("Unexpected update version"));
171
                                }
169
                        }
172
                        }
170
                }
173
                        else {
171
                else {
174
                                throw new OIDplusException(_L('Multiple version files/directories (oidplus_version.txt, .version.php, .git, or .svn) are existing! Therefore, the version is ambiguous!'));
172
                        throw new OIDplusException(_L('Multiple version files/directories (oidplus_version.txt, .version.php, .git, or .svn) are existing! Therefore, the version is ambiguous!'));
175
                        }
173
                }
-
 
174
        }
-
 
175
 
-
 
176
        /**
-
 
177
         * @param string $actionID
-
 
178
         * @param array $params
-
 
179
         * @return array
-
 
180
         * @throws OIDplusException
-
 
181
         */
-
 
182
        public function action(string $actionID, array $params): array {
-
 
183
                if ($actionID == 'update_now') {
-
 
184
                        return $this->action_Update($params);
176
                } else {
185
                } else {
177
                        return parent::action($actionID, $params);
186
                        return parent::action($actionID, $params);
178
                }
187
                }
179
        }
188
        }
180
 
189
 
181
        /**
190
        /**
182
         * @param string $id
191
         * @param string $id
183
         * @param array $out
192
         * @param array $out
184
         * @param bool $handled
193
         * @param bool $handled
185
         * @return void
194
         * @return void
186
         * @throws OIDplusException
195
         * @throws OIDplusException
187
         */
196
         */
188
        public function gui(string $id, array &$out, bool &$handled) {
197
        public function gui(string $id, array &$out, bool &$handled) {
189
                if ($id == 'oidplus:software_update') {
198
                if ($id == 'oidplus:software_update') {
190
                        @set_time_limit(0);
199
                        @set_time_limit(0);
191
 
200
 
192
                        $handled = true;
201
                        $handled = true;
193
                        $out['title'] = _L('Software update');
202
                        $out['title'] = _L('Software update');
194
                        $out['icon']  = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png';
203
                        $out['icon']  = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png';
195
 
204
 
196
                        if (!OIDplus::authUtils()->isAdminLoggedIn()) {
205
                        if (!OIDplus::authUtils()->isAdminLoggedIn()) {
197
                                throw new OIDplusHtmlException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')), $out['title'], 401);
206
                                throw new OIDplusHtmlException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')), $out['title'], 401);
198
                        }
207
                        }
199
 
208
 
200
                        $out['text'] .= '<div id="update_versioninfo">';
209
                        $out['text'] .= '<div id="update_versioninfo">';
201
 
210
 
202
                        $out['text'] .= '<p><u>'._L('There are three possibilities how to keep OIDplus up-to-date').':</u></p>';
211
                        $out['text'] .= '<p><u>'._L('There are three possibilities how to keep OIDplus up-to-date').':</u></p>';
203
 
212
 
204
                        if (isset(OIDplus::getEditionInfo()['svnrepo']) && (OIDplus::getEditionInfo()['svnrepo'] != '')) {
213
                        if (isset(OIDplus::getEditionInfo()['svnrepo']) && (OIDplus::getEditionInfo()['svnrepo'] != '')) {
205
                                $out['text'] .= '<p><b>'._L('Method A').'</b>: '._L('Install OIDplus using the subversion tool in your SSH/Linux shell using the command <code>svn co %1</code> and update it regularly with the command <code>svn update</code> . This will automatically download the latest version and check for conflicts.',htmlentities(OIDplus::getEditionInfo()['svnrepo']).'/trunk/');
214
                                $out['text'] .= '<p><b>'._L('Method A').'</b>: '._L('Install OIDplus using the subversion tool in your SSH/Linux shell using the command <code>svn co %1</code> and update it regularly with the command <code>svn update</code> . This will automatically download the latest version and check for conflicts.',htmlentities(OIDplus::getEditionInfo()['svnrepo']).'/trunk/');
206
                                if (!str_starts_with(PHP_OS, 'WIN')) {
215
                                if (!str_starts_with(PHP_OS, 'WIN')) {
207
                                        $out['text'] .= ' '._L('Make sure that you invoke the <code>%1</code> command as the user who runs PHP or that you <code>chown -R</code> the files after invoking <code>%1</code>','svn update');
216
                                        $out['text'] .= ' '._L('Make sure that you invoke the <code>%1</code> command as the user who runs PHP or that you <code>chown -R</code> the files after invoking <code>%1</code>','svn update');
208
                                }
217
                                }
209
                                $out['text'] .= '</p>';
218
                                $out['text'] .= '</p>';
210
                        } else {
219
                        } else {
211
                                $out['text'] .= '<p><b>'._L('Method A').'</b>: '._L('Distribution via %1 is not possible with this edition of OIDplus','GIT').'</p>';
220
                                $out['text'] .= '<p><b>'._L('Method A').'</b>: '._L('Distribution via %1 is not possible with this edition of OIDplus','GIT').'</p>';
212
                        }
221
                        }
213
 
222
 
214
                        if (isset(OIDplus::getEditionInfo()['gitrepo']) && (OIDplus::getEditionInfo()['gitrepo'] != '')) {
223
                        if (isset(OIDplus::getEditionInfo()['gitrepo']) && (OIDplus::getEditionInfo()['gitrepo'] != '')) {
215
                                $out['text'] .= '<p><b>'._L('Method B').'</b>: '._L('Install OIDplus using the Git client in your SSH/Linux shell using the command <code>git clone %1</code> and update it regularly with the command <code>git pull</code> . This will automatically download the latest version and check for conflicts.',htmlentities(OIDplus::getEditionInfo()['gitrepo'].'.git'));
224
                                $out['text'] .= '<p><b>'._L('Method B').'</b>: '._L('Install OIDplus using the Git client in your SSH/Linux shell using the command <code>git clone %1</code> and update it regularly with the command <code>git pull</code> . This will automatically download the latest version and check for conflicts.',htmlentities(OIDplus::getEditionInfo()['gitrepo'].'.git'));
216
                                if (!str_starts_with(PHP_OS, 'WIN')) {
225
                                if (!str_starts_with(PHP_OS, 'WIN')) {
217
                                        $out['text'] .= ' '._L('Make sure that you invoke the <code>%1</code> command as the user who runs PHP or that you <code>chown -R</code> the files after invoking <code>%1</code>','git pull');
226
                                        $out['text'] .= ' '._L('Make sure that you invoke the <code>%1</code> command as the user who runs PHP or that you <code>chown -R</code> the files after invoking <code>%1</code>','git pull');
218
                                }
227
                                }
219
                                $out['text'] .= '</p>';
228
                                $out['text'] .= '</p>';
220
                        } else {
229
                        } else {
221
                                $out['text'] .= '<p><b>'._L('Method B').'</b>: '._L('Distribution via %1 is not possible with this edition of OIDplus','SVN').'</p>';
230
                                $out['text'] .= '<p><b>'._L('Method B').'</b>: '._L('Distribution via %1 is not possible with this edition of OIDplus','SVN').'</p>';
222
                        }
231
                        }
223
 
232
 
224
                        if (isset(OIDplus::getEditionInfo()['downloadpage']) && (OIDplus::getEditionInfo()['downloadpage'] != '')) {
233
                        if (isset(OIDplus::getEditionInfo()['downloadpage']) && (OIDplus::getEditionInfo()['downloadpage'] != '')) {
225
                                $out['text'] .= '<p><b>'._L('Method C').'</b>: '._L('Install OIDplus by downloading a TAR.GZ file from %1, which contains an SVN snapshot, and extract it to your webspace. The TAR.GZ file contains a file named ".version.php" which contains the SVN revision of the snapshot. This update-tool will then try to update your files on-the-fly by downloading them from the ViaThinkSoft SVN repository directly into your webspace directory. A change conflict detection is NOT implemented. It is required that the files on your webspace have create/write/delete permissions. Only recommended if you have no access to the SSH/Linux shell.','<a href="'.OIDplus::getEditionInfo()['downloadpage'].'">'.parse_url(OIDplus::getEditionInfo()['downloadpage'])['host'].'</a>').'</p>';
234
                                $out['text'] .= '<p><b>'._L('Method C').'</b>: '._L('Install OIDplus by downloading a TAR.GZ file from %1, which contains an SVN snapshot, and extract it to your webspace. The TAR.GZ file contains a file named ".version.php" which contains the SVN revision of the snapshot. This update-tool will then try to update your files on-the-fly by downloading them from the ViaThinkSoft SVN repository directly into your webspace directory. A change conflict detection is NOT implemented. It is required that the files on your webspace have create/write/delete permissions. Only recommended if you have no access to the SSH/Linux shell.','<a href="'.OIDplus::getEditionInfo()['downloadpage'].'">'.parse_url(OIDplus::getEditionInfo()['downloadpage'])['host'].'</a>').'</p>';
226
                        } else {
235
                        } else {
227
                                $out['text'] .= '<p><b>'._L('Method C').'</b>: '._L('Distribution via %1 is not possible with this edition of OIDplus','Snapshot').'</p>';
236
                                $out['text'] .= '<p><b>'._L('Method C').'</b>: '._L('Distribution via %1 is not possible with this edition of OIDplus','Snapshot').'</p>';
228
                        }
237
                        }
229
 
238
 
230
 
239
 
231
                        $out['text'] .= '<hr>';
240
                        $out['text'] .= '<hr>';
232
 
241
 
233
                        $installType = OIDplus::getInstallType();
242
                        $installType = OIDplus::getInstallType();
234
 
243
 
235
                        if ($installType === 'ambigous') {
244
                        if ($installType === 'ambigous') {
236
                                $out['text'] .= '<font color="red">'.mb_strtoupper(_L('Error')).': '._L('Multiple version files/directories (oidplus_version.txt, .version.php, .git, or .svn) are existing! Therefore, the version is ambiguous!').'</font>';
245
                                $out['text'] .= '<font color="red">'.mb_strtoupper(_L('Error')).': '._L('Multiple version files/directories (oidplus_version.txt, .version.php, .git, or .svn) are existing! Therefore, the version is ambiguous!').'</font>';
237
                                $out['text'] .= '</div>';
246
                                $out['text'] .= '</div>';
238
                        } else if ($installType === 'unknown') {
247
                        } else if ($installType === 'unknown') {
239
                                $out['text'] .= '<font color="red">'.mb_strtoupper(_L('Error')).': '._L('The version cannot be determined, and the update needs to be applied manually!').'</font>';
248
                                $out['text'] .= '<font color="red">'.mb_strtoupper(_L('Error')).': '._L('The version cannot be determined, and the update needs to be applied manually!').'</font>';
240
                                $out['text'] .= '</div>';
249
                                $out['text'] .= '</div>';
241
                        } else if (($installType === 'svn-wc') || ($installType === 'git-wc') || ($installType === 'svn-snapshot')) {
250
                        } else if (($installType === 'svn-wc') || ($installType === 'git-wc') || ($installType === 'svn-snapshot')) {
242
                                if ($installType === 'svn-wc') {
251
                                if ($installType === 'svn-wc') {
243
                                        $out['text'] .= '<p>'._L('You are using <b>method A</b> (SVN working copy).').'</p>';
252
                                        $out['text'] .= '<p>'._L('You are using <b>method A</b> (SVN working copy).').'</p>';
244
                                        $requireInfo = _L('shell access with svn/svnversion tool, or PDO/SQLite3 PHP extension');
253
                                        $requireInfo = _L('shell access with svn/svnversion tool, or PDO/SQLite3 PHP extension');
245
                                        $updateCommand = $this->getSvnCommand();
254
                                        $updateCommand = $this->getSvnCommand();
246
                                } else if ($installType === 'git-wc') {
255
                                } else if ($installType === 'git-wc') {
247
                                        $out['text'] .= '<p>'._L('You are using <b>method B</b> (Git working copy).').'</p>';
256
                                        $out['text'] .= '<p>'._L('You are using <b>method B</b> (Git working copy).').'</p>';
248
                                        $requireInfo = _L('shell access with Git client');
257
                                        $requireInfo = _L('shell access with Git client');
249
                                        $updateCommand = $this->getGitCommand();
258
                                        $updateCommand = $this->getGitCommand();
250
                                } else if ($installType === 'svn-snapshot') {
259
                                } else if ($installType === 'svn-snapshot') {
251
                                        $out['text'] .= '<p>'._L('You are using <b>method C</b> (Snapshot TAR.GZ file with .version.php file).').'</p>';
260
                                        $out['text'] .= '<p>'._L('You are using <b>method C</b> (Snapshot TAR.GZ file with .version.php file).').'</p>';
252
                                        $requireInfo = ''; // unused
261
                                        $requireInfo = ''; // unused
253
                                        $updateCommand = ''; // unused
262
                                        $updateCommand = ''; // unused
254
                                } else {
263
                                } else {
255
                                        assert(false);
264
                                        assert(false);
256
                                }
265
                                }
257
 
266
 
258
                                $local_installation = OIDplus::getVersion();
267
                                $local_installation = OIDplus::getVersion();
259
                                $newest_version = $this->getLatestRevision();
268
                                $newest_version = $this->getLatestRevision();
260
 
269
 
261
                                $out['text'] .= _L('Local installation: %1',($local_installation ?: _L('unknown'))).'<br>';
270
                                $out['text'] .= _L('Local installation: %1',($local_installation ?: _L('unknown'))).'<br>';
262
                                $out['text'] .= _L('Latest published version: %1',($newest_version ?: _L('unknown'))).'<br><br>';
271
                                $out['text'] .= _L('Latest published version: %1',($newest_version ?: _L('unknown'))).'<br><br>';
263
 
272
 
264
                                if (!$newest_version) {
273
                                if (!$newest_version) {
265
                                        if (!url_get_contents_available(true, $reason)) {
274
                                        if (!url_get_contents_available(true, $reason)) {
266
                                                $out['text'] .= '<p><font color="red">'._L('OIDplus could not determine the latest version.').'<br>'.$reason.'</p>';
275
                                                $out['text'] .= '<p><font color="red">'._L('OIDplus could not determine the latest version.').'<br>'.$reason.'</p>';
267
                                        } else {
276
                                        } else {
268
                                                $out['text'] .= '<p><font color="red">'._L('OIDplus could not determine the latest version.').'<br>'._L('Probably the ViaThinkSoft server could not be reached.').'</font></p>';
277
                                                $out['text'] .= '<p><font color="red">'._L('OIDplus could not determine the latest version.').'<br>'._L('Probably the ViaThinkSoft server could not be reached.').'</font></p>';
269
                                        }
278
                                        }
270
                                        $out['text'] .= '</div>';
279
                                        $out['text'] .= '</div>';
271
                                } else if (!$local_installation) {
280
                                } else if (!$local_installation) {
272
                                        if ($installType === 'svn-snapshot') {
281
                                        if ($installType === 'svn-snapshot') {
273
                                                $out['text'] .= '<p><font color="red">'._L('OIDplus could not determine its version.').'</font></p>';
282
                                                $out['text'] .= '<p><font color="red">'._L('OIDplus could not determine its version.').'</font></p>';
274
                                        } else {
283
                                        } else {
275
                                                $out['text'] .= '<p><font color="red">'._L('OIDplus could not determine its version. (Required: %1). Please update your system manually via the "%2" command regularly.',$requireInfo,$updateCommand).'</font></p>';
284
                                                $out['text'] .= '<p><font color="red">'._L('OIDplus could not determine its version. (Required: %1). Please update your system manually via the "%2" command regularly.',$requireInfo,$updateCommand).'</font></p>';
276
                                        }
285
                                        }
277
                                        $out['text'] .= '</div>';
286
                                        $out['text'] .= '</div>';
278
                                } else if (version_compare($local_installation, $newest_version) >= 0) {
287
                                } else if (version_compare($local_installation, $newest_version) >= 0) {
279
                                        $out['text'] .= '<p><font color="green">'._L('You are already using the latest version of OIDplus.').'</font></p>';
288
                                        $out['text'] .= '<p><font color="green">'._L('You are already using the latest version of OIDplus.').'</font></p>';
280
                                        $out['text'] .= '</div>';
289
                                        $out['text'] .= '</div>';
281
                                } else {
290
                                } else {
282
                                        if (($installType === 'svn-wc') || ($installType === 'git-wc')) {
291
                                        if (($installType === 'svn-wc') || ($installType === 'git-wc')) {
283
                                                $out['text'] .= '<p><font color="blue">'._L('Please enter %1 into the SSH shell to update OIDplus to the latest version.','<code>'.$updateCommand.'</code>').'</font></p>';
292
                                                $out['text'] .= '<p><font color="blue">'._L('Please enter %1 into the SSH shell to update OIDplus to the latest version.','<code>'.$updateCommand.'</code>').'</font></p>';
284
                                                $out['text'] .= '<p>'._L('Alternatively, click this button to execute the command through the web-interface (command execution and write permissions required).').'</p>';
293
                                                $out['text'] .= '<p>'._L('Alternatively, click this button to execute the command through the web-interface (command execution and write permissions required).').'</p>';
285
                                        }
294
                                        }
286
 
295
 
287
                                        $out['text'] .= '<p><input type="button" onclick="OIDplusPageAdminSoftwareUpdate.doUpdateOIDplus('.((int)substr($local_installation,4)+1).', '.substr($newest_version,4).')" value="'._L('Update NOW').'"></p>';
296
                                        $out['text'] .= '<p><input type="button" onclick="OIDplusPageAdminSoftwareUpdate.doUpdateOIDplus('.((int)substr($local_installation,4)+1).', '.substr($newest_version,4).')" value="'._L('Update NOW').'"></p>';
288
 
297
 
289
                                        // TODO: Open "system_file_check" without page reload.
298
                                        // TODO: Open "system_file_check" without page reload.
290
                                        // TODO: Only show link if the plugin is installed
299
                                        // TODO: Only show link if the plugin is installed
291
                                        $out['text'] .= '<p><font color="red">'.mb_strtoupper(_L('Warning')).': '._L('Please make a backup of your files before updating. In case of an error, the OIDplus system (including this update-assistant) might become unavailable. Also, since the web-update does not contain collision-detection, changes you have applied (like adding, removing or modified files) might get reverted/lost! (<a href="%1">Click here to check which files have been modified</a>) In case the update fails, you can download and extract the complete <a href="%s">SVN-Snapshot TAR.GZ file</a> again. Since all your data should lay inside the folder "userdata" and "userdata_pub", this should be safe.','?goto='.urlencode('oidplus:system_file_check'),OIDplus::getEditionInfo()['downloadpage']).'</font></p>';
300
                                        $out['text'] .= '<p><font color="red">'.mb_strtoupper(_L('Warning')).': '._L('Please make a backup of your files before updating. In case of an error, the OIDplus system (including this update-assistant) might become unavailable. Also, since the web-update does not contain collision-detection, changes you have applied (like adding, removing or modified files) might get reverted/lost! (<a href="%1">Click here to check which files have been modified</a>) In case the update fails, you can download and extract the complete <a href="%s">SVN-Snapshot TAR.GZ file</a> again. Since all your data should lay inside the folder "userdata" and "userdata_pub", this should be safe.','?goto='.urlencode('oidplus:system_file_check'),OIDplus::getEditionInfo()['downloadpage']).'</font></p>';
292
 
301
 
293
                                        $out['text'] .= '</div>';
302
                                        $out['text'] .= '</div>';
294
 
303
 
295
                                        $out['text'] .= $this->showPreview($local_installation, $newest_version);
304
                                        $out['text'] .= $this->showPreview($local_installation, $newest_version);
296
                                }
305
                                }
297
                        }
306
                        }
298
                } else {
307
                } else {
299
                        $handled = false;
308
                        $handled = false;
300
                }
309
                }
301
        }
310
        }
302
 
311
 
303
        /**
312
        /**
304
         * @param array $json
313
         * @param array $json
305
         * @param string|null $ra_email
314
         * @param string|null $ra_email
306
         * @param bool $nonjs
315
         * @param bool $nonjs
307
         * @param string $req_goto
316
         * @param string $req_goto
308
         * @return bool
317
         * @return bool
309
         * @throws OIDplusException
318
         * @throws OIDplusException
310
         */
319
         */
311
        public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool {
320
        public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool {
312
                if (!OIDplus::authUtils()->isAdminLoggedIn()) return false;
321
                if (!OIDplus::authUtils()->isAdminLoggedIn()) return false;
313
 
322
 
314
                if (file_exists(__DIR__.'/img/main_icon16.png')) {
323
                if (file_exists(__DIR__.'/img/main_icon16.png')) {
315
                        $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png';
324
                        $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png';
316
                } else {
325
                } else {
317
                        $tree_icon = null; // default icon (folder)
326
                        $tree_icon = null; // default icon (folder)
318
                }
327
                }
319
 
328
 
320
                $json[] = array(
329
                $json[] = array(
321
                        'id' => 'oidplus:software_update',
330
                        'id' => 'oidplus:software_update',
322
                        'icon' => $tree_icon,
331
                        'icon' => $tree_icon,
323
                        'text' => _L('Software update')
332
                        'text' => _L('Software update')
324
                );
333
                );
325
 
334
 
326
                return true;
335
                return true;
327
        }
336
        }
328
 
337
 
329
        /**
338
        /**
330
         * @param string $request
339
         * @param string $request
331
         * @return array|false
340
         * @return array|false
332
         */
341
         */
333
        public function tree_search(string $request) {
342
        public function tree_search(string $request) {
334
                return false;
343
                return false;
335
        }
344
        }
336
 
345
 
337
        /**
346
        /**
338
         * @var string|null
347
         * @var string|null
339
         */
348
         */
340
        private $releases_ser = null;
349
        private $releases_ser = null;
341
 
350
 
342
        /**
351
        /**
343
         * @param string $local_ver
352
         * @param string $local_ver
344
         * @return false|string
353
         * @return false|string
345
         */
354
         */
346
        private function showChangelog(string $local_ver) {
355
        private function showChangelog(string $local_ver) {
347
 
356
 
348
                try {
357
                try {
349
                        if (is_null($this->releases_ser)) {
358
                        if (is_null($this->releases_ser)) {
350
                                if (function_exists('gzdecode')) {
359
                                if (function_exists('gzdecode')) {
351
                                        $url = OIDplus::getEditionInfo()['revisionlog_gz'];
360
                                        $url = OIDplus::getEditionInfo()['revisionlog_gz'];
352
                                        $cont = url_get_contents($url);
361
                                        $cont = url_get_contents($url);
353
                                        if ($cont !== false) $cont = @gzdecode($cont);
362
                                        if ($cont !== false) $cont = @gzdecode($cont);
354
                                } else {
363
                                } else {
355
                                        $url = OIDplus::getEditionInfo()['revisionlog'];
364
                                        $url = OIDplus::getEditionInfo()['revisionlog'];
356
                                        $cont = url_get_contents($url);
365
                                        $cont = url_get_contents($url);
357
                                }
366
                                }
358
                                if ($cont === false) return false;
367
                                if ($cont === false) return false;
359
                                $this->releases_ser = $cont;
368
                                $this->releases_ser = $cont;
360
                        } else {
369
                        } else {
361
                                $cont = $this->releases_ser;
370
                                $cont = $this->releases_ser;
362
                        }
371
                        }
363
                        $content = '';
372
                        $content = '';
364
                        $ary = @unserialize($cont);
373
                        $ary = @unserialize($cont);
365
                        if ($ary === false) return false;
374
                        if ($ary === false) return false;
366
                        krsort($ary);
375
                        krsort($ary);
367
                        foreach ($ary as $rev => $data) {
376
                        foreach ($ary as $rev => $data) {
368
                                if (version_compare("svn-$rev", $local_ver) <= 0) continue;
377
                                if (version_compare("svn-$rev", $local_ver) <= 0) continue;
369
                                $comment = empty($data['msg']) ? _L('No comment') : $data['msg'];
378
                                $comment = empty($data['msg']) ? _L('No comment') : $data['msg'];
370
                                $tex = _L("New revision %1 by %2",$rev,$data['author'])." (".$data['date'].") ";
379
                                $tex = _L("New revision %1 by %2",$rev,$data['author'])." (".$data['date'].") ";
371
                                $content .= trim($tex . str_replace("\n", "\n".str_repeat(' ', strlen($tex)), $comment));
380
                                $content .= trim($tex . str_replace("\n", "\n".str_repeat(' ', strlen($tex)), $comment));
372
                                $content .= "\n";
381
                                $content .= "\n";
373
                        }
382
                        }
374
                        return $content;
383
                        return $content;
375
                } catch (\Exception $e) {
384
                } catch (\Exception $e) {
376
                        return false;
385
                        return false;
377
                }
386
                }
378
 
387
 
379
        }
388
        }
380
 
389
 
381
        /**
390
        /**
382
         * @return false|string
391
         * @return false|string
383
         */
392
         */
384
        private function getLatestRevision() {
393
        private function getLatestRevision() {
385
                try {
394
                try {
386
                        if (is_null($this->releases_ser)) {
395
                        if (is_null($this->releases_ser)) {
387
                                if (function_exists('gzdecode')) {
396
                                if (function_exists('gzdecode')) {
388
                                        $url = OIDplus::getEditionInfo()['revisionlog_gz'];
397
                                        $url = OIDplus::getEditionInfo()['revisionlog_gz'];
389
                                        $cont = url_get_contents($url);
398
                                        $cont = url_get_contents($url);
390
                                        if ($cont !== false) $cont = @gzdecode($cont);
399
                                        if ($cont !== false) $cont = @gzdecode($cont);
391
                                } else {
400
                                } else {
392
                                        $url = OIDplus::getEditionInfo()['revisionlog'];
401
                                        $url = OIDplus::getEditionInfo()['revisionlog'];
393
                                        $cont = url_get_contents($url);
402
                                        $cont = url_get_contents($url);
394
                                }
403
                                }
395
                                if ($cont === false) return false;
404
                                if ($cont === false) return false;
396
                                $this->releases_ser = $cont;
405
                                $this->releases_ser = $cont;
397
                        } else {
406
                        } else {
398
                                $cont = $this->releases_ser;
407
                                $cont = $this->releases_ser;
399
                        }
408
                        }
400
                        $ary = @unserialize($cont);
409
                        $ary = @unserialize($cont);
401
                        if ($ary === false) return false;
410
                        if ($ary === false) return false;
402
                        krsort($ary);
411
                        krsort($ary);
403
                        $max_rev = array_keys($ary)[0];
412
                        $max_rev = array_keys($ary)[0];
404
                        return 'svn-' . $max_rev;
413
                        return 'svn-' . $max_rev;
405
                } catch (\Exception $e) {
414
                } catch (\Exception $e) {
406
                        return false;
415
                        return false;
407
                }
416
                }
408
        }
417
        }
409
 
418
 
410
        /**
419
        /**
411
         * @param string $local_installation
420
         * @param string $local_installation
412
         * @param string $newest_version
421
         * @param string $newest_version
413
         * @return string
422
         * @return string
414
         */
423
         */
415
        private function showPreview(string $local_installation, string $newest_version): string {
424
        private function showPreview(string $local_installation, string $newest_version): string {
416
                $out = '<h2 id="update_header">'._L('Preview of update %1 &rarr; %2',$local_installation,$newest_version).'</h2>';
425
                $out = '<h2 id="update_header">'._L('Preview of update %1 &rarr; %2',$local_installation,$newest_version).'</h2>';
417
 
426
 
418
                ob_start();
427
                ob_start();
419
                try {
428
                try {
420
                        $cont = $this->showChangelog($local_installation);
429
                        $cont = $this->showChangelog($local_installation);
421
                } catch (\Exception $e) {
430
                } catch (\Exception $e) {
422
                        $htmlmsg = $e instanceof OIDplusException ? $e->getHtmlMessage() : htmlentities($e->getMessage());
431
                        $htmlmsg = $e instanceof OIDplusException ? $e->getHtmlMessage() : htmlentities($e->getMessage());
423
                        $cont = _L('Error: %1',$htmlmsg);
432
                        $cont = _L('Error: %1',$htmlmsg);
424
                }
433
                }
425
                ob_end_clean();
434
                ob_end_clean();
426
 
435
 
427
                $cont = preg_replace('@!!!(.+)\\n@', '<font color="red">!!!\\1</font>'."\n", "$cont\n");
436
                $cont = preg_replace('@!!!(.+)\\n@', '<font color="red">!!!\\1</font>'."\n", "$cont\n");
428
                $cont = preg_replace('@\\*\\*\\*(.+)\\n@', '<strong>!!!\\1</strong>'."\n", "$cont\n");
437
                $cont = preg_replace('@\\*\\*\\*(.+)\\n@', '<strong>!!!\\1</strong>'."\n", "$cont\n");
429
 
438
 
430
                $out .= '<pre id="update_infobox">'.$cont.'</pre>';
439
                $out .= '<pre id="update_infobox">'.$cont.'</pre>';
431
 
440
 
432
                return $out;
441
                return $out;
433
        }
442
        }
434
 
443
 
435
        /**
444
        /**
436
         * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_8
445
         * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_8
437
         * @param string|null $user
446
         * @param string|null $user
438
         * @return array
447
         * @return array
439
         * @throws OIDplusException
448
         * @throws OIDplusException
440
         */
449
         */
441
        public function getNotifications(string $user=null): array {
450
        public function getNotifications(string $user=null): array {
442
                $notifications = array();
451
                $notifications = array();
443
                if ((!$user || ($user == 'admin')) && OIDplus::authUtils()->isAdminLoggedIn()) {
452
                if ((!$user || ($user == 'admin')) && OIDplus::authUtils()->isAdminLoggedIn()) {
444
 
453
 
445
                        // Following code is based on the VNag plugin (admin 901) code
454
                        // Following code is based on the VNag plugin (admin 901) code
446
 
455
 
447
                        $installType = OIDplus::getInstallType();
456
                        $installType = OIDplus::getInstallType();
448
 
457
 
449
                        if ($installType === 'ambigous') {
458
                        if ($installType === 'ambigous') {
450
                                $out_stat = 'WARN';
459
                                $out_stat = 'WARN';
451
                                $out_msg  = _L('Multiple version files/directories (oidplus_version.txt, .version.php, .git, or .svn) are existing! Therefore, the version is ambiguous!');
460
                                $out_msg  = _L('Multiple version files/directories (oidplus_version.txt, .version.php, .git, or .svn) are existing! Therefore, the version is ambiguous!');
452
                        } else if ($installType === 'unknown') {
461
                        } else if ($installType === 'unknown') {
453
                                $out_stat = 'WARN';
462
                                $out_stat = 'WARN';
454
                                $out_msg  = _L('The version cannot be determined, and the update needs to be applied manually!');
463
                                $out_msg  = _L('The version cannot be determined, and the update needs to be applied manually!');
455
                        } else if (($installType === 'svn-wc') || ($installType === 'git-wc')) {
464
                        } else if (($installType === 'svn-wc') || ($installType === 'git-wc')) {
456
                                if (!url_get_contents_available(true, $reason)) {
465
                                if (!url_get_contents_available(true, $reason)) {
457
                                        $out_stat = 'WARN';
466
                                        $out_stat = 'WARN';
458
                                        $out_msg  = _L('OIDplus could not determine the latest version.').' '.$reason;
467
                                        $out_msg  = _L('OIDplus could not determine the latest version.').' '.$reason;
459
                                } else {
468
                                } else {
460
                                        $local_installation = OIDplus::getVersion();
469
                                        $local_installation = OIDplus::getVersion();
461
                                        $newest_version = $this->getLatestRevision();
470
                                        $newest_version = $this->getLatestRevision();
462
 
471
 
463
                                        $requireInfo = ($installType === 'svn-wc') ? _L('shell access with svn/svnversion tool, or PDO/SQLite3 PHP extension') : _L('shell access with Git client');
472
                                        $requireInfo = ($installType === 'svn-wc') ? _L('shell access with svn/svnversion tool, or PDO/SQLite3 PHP extension') : _L('shell access with Git client');
464
                                        $updateCommand = ($installType === 'svn-wc') ? 'svn update' : 'git pull';
473
                                        $updateCommand = ($installType === 'svn-wc') ? 'svn update' : 'git pull';
465
 
474
 
466
                                        if (!$newest_version) {
475
                                        if (!$newest_version) {
467
                                                $out_stat = 'WARN';
476
                                                $out_stat = 'WARN';
468
                                                $out_msg = _L('OIDplus could not determine the latest version.') . ' ' . _L('Probably the ViaThinkSoft server could not be reached.');
477
                                                $out_msg = _L('OIDplus could not determine the latest version.') . ' ' . _L('Probably the ViaThinkSoft server could not be reached.');
469
                                        } else if (!$local_installation) {
478
                                        } else if (!$local_installation) {
470
                                                $out_stat = 'WARN';
479
                                                $out_stat = 'WARN';
471
                                                $out_msg = _L('OIDplus could not determine its version (Required: %1). Please update your system manually via the "%2" command regularly.', $requireInfo, $updateCommand);
480
                                                $out_msg = _L('OIDplus could not determine its version (Required: %1). Please update your system manually via the "%2" command regularly.', $requireInfo, $updateCommand);
472
                                        } else if (version_compare($local_installation, $newest_version) >= 0) {
481
                                        } else if (version_compare($local_installation, $newest_version) >= 0) {
473
                                                $out_stat = 'INFO';
482
                                                $out_stat = 'INFO';
474
                                                $out_msg = _L('You are using the latest version of OIDplus (%1 local / %2 remote)', $local_installation, $newest_version);
483
                                                $out_msg = _L('You are using the latest version of OIDplus (%1 local / %2 remote)', $local_installation, $newest_version);
475
                                        } else {
484
                                        } else {
476
                                                $out_stat = 'WARN';
485
                                                $out_stat = 'WARN';
477
                                                $out_msg = _L('OIDplus is outdated. (%1 local / %2 remote)', $local_installation, $newest_version);
486
                                                $out_msg = _L('OIDplus is outdated. (%1 local / %2 remote)', $local_installation, $newest_version);
478
                                        }
487
                                        }
479
                                }
488
                                }
480
                        } else if ($installType === 'svn-snapshot') {
489
                        } else if ($installType === 'svn-snapshot') {
481
                                if (!url_get_contents_available(true, $reason)) {
490
                                if (!url_get_contents_available(true, $reason)) {
482
                                        $out_stat = 'WARN';
491
                                        $out_stat = 'WARN';
483
                                        $out_msg  = _L('OIDplus could not determine the latest version.').' '.$reason;
492
                                        $out_msg  = _L('OIDplus could not determine the latest version.').' '.$reason;
484
                                } else {
493
                                } else {
485
                                        $local_installation = OIDplus::getVersion();
494
                                        $local_installation = OIDplus::getVersion();
486
                                        $newest_version = $this->getLatestRevision();
495
                                        $newest_version = $this->getLatestRevision();
487
 
496
 
488
                                        if (!$newest_version) {
497
                                        if (!$newest_version) {
489
                                                $out_stat = 'WARN';
498
                                                $out_stat = 'WARN';
490
                                                $out_msg = _L('OIDplus could not determine the latest version.') . ' ' . _L('Probably the ViaThinkSoft server could not be reached.');
499
                                                $out_msg = _L('OIDplus could not determine the latest version.') . ' ' . _L('Probably the ViaThinkSoft server could not be reached.');
491
                                        } else if (!$local_installation) {
500
                                        } else if (!$local_installation) {
492
                                                $out_stat = 'WARN';
501
                                                $out_stat = 'WARN';
493
                                                $out_msg = _L('OIDplus could not determine its version. Please update your system manually by downloading the latest archive file from oidplus.com.');
502
                                                $out_msg = _L('OIDplus could not determine its version. Please update your system manually by downloading the latest archive file from oidplus.com.');
494
                                        } else if (version_compare($local_installation, $newest_version) >= 0) {
503
                                        } else if (version_compare($local_installation, $newest_version) >= 0) {
495
                                                $out_stat = 'INFO';
504
                                                $out_stat = 'INFO';
496
                                                $out_msg = _L('You are using the latest version of OIDplus (%1 local / %2 remote)', $local_installation, $newest_version);
505
                                                $out_msg = _L('You are using the latest version of OIDplus (%1 local / %2 remote)', $local_installation, $newest_version);
497
                                        } else {
506
                                        } else {
498
                                                $out_stat = 'WARN';
507
                                                $out_stat = 'WARN';
499
                                                $out_msg = _L('OIDplus is outdated. (%1 local / %2 remote)', $local_installation, $newest_version);
508
                                                $out_msg = _L('OIDplus is outdated. (%1 local / %2 remote)', $local_installation, $newest_version);
500
                                        }
509
                                        }
501
                                }
510
                                }
502
                        } else {
511
                        } else {
503
                                assert(false);
512
                                assert(false);
504
                                return $notifications;
513
                                return $notifications;
505
                        }
514
                        }
506
 
515
 
507
                        if ($out_stat != 'INFO') {
516
                        if ($out_stat != 'INFO') {
508
                                $out_msg = '<a '.OIDplus::gui()->link('oidplus:software_update').'>'._L('Software update').'</a>: ' . $out_msg;
517
                                $out_msg = '<a '.OIDplus::gui()->link('oidplus:software_update').'>'._L('Software update').'</a>: ' . $out_msg;
509
 
518
 
510
                                $notifications[] = new OIDplusNotification($out_stat, $out_msg);
519
                                $notifications[] = new OIDplusNotification($out_stat, $out_msg);
511
                        }
520
                        }
512
 
521
 
513
                }
522
                }
514
                return $notifications;
523
                return $notifications;
515
        }
524
        }
516
 
525
 
517
}
526
}
518
 
527