Subversion Repositories oidplus

Rev

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

Rev 1132 Rev 1143
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
52
         * @param string $actionID
53
         * @param array $params
53
         * @param array $params
54
         * @return array
54
         * @return array
55
         * @throws OIDplusException
55
         * @throws OIDplusException
56
         */
56
         */
57
        public function action(string $actionID, array $params): array {
57
        public function action(string $actionID, array $params): array {
58
                if ($actionID == 'update_now') {
58
                if ($actionID == 'update_now') {
59
                        @set_time_limit(0);
59
                        @set_time_limit(0);
60
 
60
 
61
                        if (!OIDplus::authUtils()->isAdminLoggedIn()) {
61
                        if (!OIDplus::authUtils()->isAdminLoggedIn()) {
62
                                throw new OIDplusException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')));
62
                                throw new OIDplusException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')));
63
                        }
63
                        }
64
 
64
 
65
                        if (OIDplus::getInstallType() === 'git-wc') {
65
                        if (OIDplus::getInstallType() === 'git-wc') {
66
                                $cmd = $this->getGitCommand().' 2>&1';
66
                                $cmd = $this->getGitCommand().' 2>&1';
67
 
67
 
68
                                $ec = -1;
68
                                $ec = -1;
69
                                $out = array();
69
                                $out = array();
70
                                exec($cmd, $out, $ec);
70
                                exec($cmd, $out, $ec);
71
 
71
 
72
                                $res = _L('Execute command:').' '.$cmd."\n\n".trim(implode("\n",$out));
72
                                $res = _L('Execute command:').' '.$cmd."\n\n".trim(implode("\n",$out));
73
                                if ($ec === 0) {
73
                                if ($ec === 0) {
74
                                        $rev = 'HEAD'; // do not translate
74
                                        $rev = 'HEAD'; // do not translate
75
                                        return array("status" => 0, "content" => $res, "rev" => $rev);
75
                                        return array("status" => 0, "content" => $res, "rev" => $rev);
76
                                } else {
76
                                } else {
77
                                        return array("status" => -1, "error" => $res, "content" => "");
77
                                        return array("status" => -1, "error" => $res, "content" => "");
78
                                }
78
                                }
79
                        }
79
                        }
80
                        else if (OIDplus::getInstallType() === 'svn-wc') {
80
                        else if (OIDplus::getInstallType() === 'svn-wc') {
81
                                $cmd = $this->getSvnCommand().' 2>&1';
81
                                $cmd = $this->getSvnCommand().' 2>&1';
82
 
82
 
83
                                $ec = -1;
83
                                $ec = -1;
84
                                $out = array();
84
                                $out = array();
85
                                exec($cmd, $out, $ec);
85
                                exec($cmd, $out, $ec);
86
 
86
 
87
                                $res = _L('Execute command:').' '.$cmd."\n\n".trim(implode("\n",$out));
87
                                $res = _L('Execute command:').' '.$cmd."\n\n".trim(implode("\n",$out));
88
                                if ($ec === 0) {
88
                                if ($ec === 0) {
89
                                        $rev = 'HEAD'; // do not translate
89
                                        $rev = 'HEAD'; // do not translate
90
                                        return array("status" => 0, "content" => $res, "rev" => $rev);
90
                                        return array("status" => 0, "content" => $res, "rev" => $rev);
91
                                } else {
91
                                } else {
92
                                        return array("status" => -1, "error" => $res, "content" => "");
92
                                        return array("status" => -1, "error" => $res, "content" => "");
93
                                }
93
                                }
94
                        }
94
                        }
95
                        else if (OIDplus::getInstallType() === 'svn-snapshot') {
95
                        else if (OIDplus::getInstallType() === 'svn-snapshot') {
96
 
96
 
97
                                $rev = $params['rev'];
97
                                $rev = $params['rev'];
98
 
98
 
99
                                $update_version = $params['update_version'] ?? 1;
99
                                $update_version = $params['update_version'] ?? 1;
100
                                if (($update_version != 1) && ($update_version != 2)) {
100
                                if (($update_version != 1) && ($update_version != 2)) {
101
                                        throw new OIDplusException(_L('Unknown update version'));
101
                                        throw new OIDplusException(_L('Unknown update version'));
102
                                }
102
                                }
103
 
103
 
104
                                // Download and unzip
104
                                // Download and unzip
105
 
105
 
106
                                $cont = false;
106
                                $cont = false;
107
                                for ($retry=1; $retry<=3; $retry++) {
107
                                for ($retry=1; $retry<=3; $retry++) {
108
                                        if (function_exists('gzdecode')) {
108
                                        if (function_exists('gzdecode')) {
109
                                                $url = sprintf(OIDplus::getEditionInfo()['update_package_gz'], $rev-1, $rev);
109
                                                $url = sprintf(OIDplus::getEditionInfo()['update_package_gz'], $rev-1, $rev);
110
                                                $cont = url_get_contents($url);
110
                                                $cont = url_get_contents($url);
111
                                                if ($cont !== false) $cont = @gzdecode($cont);
111
                                                if ($cont !== false) $cont = @gzdecode($cont);
112
                                        } else {
112
                                        } else {
113
                                                $url = sprintf(OIDplus::getEditionInfo()['update_package'], $rev-1, $rev);
113
                                                $url = sprintf(OIDplus::getEditionInfo()['update_package'], $rev-1, $rev);
114
                                                $cont = url_get_contents($url);
114
                                                $cont = url_get_contents($url);
115
                                        }
115
                                        }
116
                                        if ($cont !== false) {
116
                                        if ($cont !== false) {
117
                                                break;
117
                                                break;
118
                                        } else {
118
                                        } else {
119
                                                sleep(1);
119
                                                sleep(1);
120
                                        }
120
                                        }
121
                                }
121
                                }
122
                                if ($cont === false) throw new OIDplusException(_L("Update %1 could not be downloaded from ViaThinkSoft server. Please try again later.",$rev));
122
                                if ($cont === false) throw new OIDplusException(_L("Update %1 could not be downloaded from ViaThinkSoft server. Please try again later.",$rev));
123
 
123
 
124
                                // Check signature...
124
                                // Check signature...
125
 
125
 
126
                                if (function_exists('openssl_verify')) {
126
                                if (function_exists('openssl_verify')) {
127
 
127
 
128
                                        $m = array();
128
                                        $m = array();
129
                                        if (!preg_match('@<\?php /\* <ViaThinkSoftSignature>(.+)</ViaThinkSoftSignature> \*/ \?>\n@ismU', $cont, $m)) {
129
                                        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));
130
                                                throw new OIDplusException(_L("Update package file of revision %1 not digitally signed",$rev));
131
                                        }
131
                                        }
132
                                        $signature = base64_decode($m[1]);
132
                                        $signature = base64_decode($m[1]);
133
 
133
 
134
                                        $naked = preg_replace('@<\?php /\* <ViaThinkSoftSignature>(.+)</ViaThinkSoftSignature> \*/ \?>\n@ismU', '', $cont);
134
                                        $naked = preg_replace('@<\?php /\* <ViaThinkSoftSignature>(.+)</ViaThinkSoftSignature> \*/ \?>\n@ismU', '', $cont);
135
                                        $hash = hash("sha256", $naked."update_".($rev-1)."_to_".($rev).".txt");
135
                                        $hash = hash("sha256", $naked."update_".($rev-1)."_to_".($rev).".txt");
136
 
136
 
137
                                        $public_key = file_get_contents(__DIR__.'/public.pem');
137
                                        $public_key = file_get_contents(__DIR__.'/public.pem');
138
                                        if (!openssl_verify($hash, $signature, $public_key, OPENSSL_ALGO_SHA256)) {
138
                                        if (!openssl_verify($hash, $signature, $public_key, OPENSSL_ALGO_SHA256)) {
139
                                                throw new OIDplusException(_L("Update package file of revision %1: Signature invalid",$rev));
139
                                                throw new OIDplusException(_L("Update package file of revision %1: Signature invalid",$rev));
140
                                        }
140
                                        }
141
 
141
 
142
                                }
142
                                }
143
 
143
 
144
                                // All OK! Now write file
144
                                // All OK! Now write file
145
 
145
 
146
                                $tmp_filename = 'update_'.generateRandomString(10).'.tmp.php';
146
                                $tmp_filename = 'update_'.generateRandomString(10).'.tmp.php';
147
                                $local_file = OIDplus::localpath().$tmp_filename;
147
                                $local_file = OIDplus::localpath().$tmp_filename;
148
 
148
 
149
                                @file_put_contents($local_file, $cont);
149
                                @file_put_contents($local_file, $cont);
150
 
150
 
151
                                if (!file_exists($local_file) || (@file_get_contents($local_file) !== $cont)) {
151
                                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.'));
152
                                        throw new OIDplusException(_L('Update file could not written. Probably there are no write-permissions to the root folder.'));
153
                                }
153
                                }
154
 
154
 
155
                                if ($update_version == 1) {
155
                                if ($update_version == 1) {
156
                                        // Now call the written file
156
                                        // Now call the written file
157
                                        // Note: we may not use eval($cont) because the script uses die(),
157
                                        // 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.
158
                                        // 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
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
160
                                        $res = url_get_contents($web_file);
160
                                        $res = url_get_contents($web_file);
161
                                        if ($res === false) {
161
                                        if ($res === false) {
162
                                                throw new OIDplusException(_L('Update-script %1 could not be executed',$web_file));
162
                                                throw new OIDplusException(_L('Update-script %1 could not be executed',$web_file));
163
                                        }
163
                                        }
164
                                        return array("status" => 0, "content" => $res, "rev" => $rev);
164
                                        return array("status" => 0, "content" => $res, "rev" => $rev);
165
                                } else if ($update_version == 2) {
165
                                } else if ($update_version == 2) {
166
                                        // In this version, the client will call the web-update file.
166
                                        // 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
167
                                        // 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);
168
                                        return array("status" => 0, "update_file" => $tmp_filename, "rev" => $rev);
169
                                } else {
169
                                } else {
170
                                        throw new OIDplusException(_L("Unexpected update version"));
170
                                        throw new OIDplusException(_L("Unexpected update version"));
171
                                }
171
                                }
172
                        }
172
                        }
173
                        else {
173
                        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!'));
174
                                throw new OIDplusException(_L('Multiple version files/directories (oidplus_version.txt, .version.php, .git, or .svn) are existing! Therefore, the version is ambiguous!'));
175
                        }
175
                        }
176
                } else {
176
                } else {
177
                        return parent::action($actionID, $params);
177
                        return parent::action($actionID, $params);
178
                }
178
                }
179
        }
179
        }
180
 
180
 
181
        /**
181
        /**
182
         * @param string $id
182
         * @param string $id
183
         * @param array $out
183
         * @param array $out
184
         * @param bool $handled
184
         * @param bool $handled
185
         * @return void
185
         * @return void
186
         * @throws OIDplusException
186
         * @throws OIDplusException
187
         */
187
         */
188
        public function gui(string $id, array &$out, bool &$handled) {
188
        public function gui(string $id, array &$out, bool &$handled) {
189
                $parts = explode('.',$id,2);
189
                $parts = explode('.',$id,2);
190
                if (!isset($parts[1])) $parts[1] = '';
190
                if (!isset($parts[1])) $parts[1] = '';
191
                if ($parts[0] == 'oidplus:software_update') {
191
                if ($parts[0] == 'oidplus:software_update') {
192
                        @set_time_limit(0);
192
                        @set_time_limit(0);
193
 
193
 
194
                        $handled = true;
194
                        $handled = true;
195
                        $out['title'] = _L('Software update');
195
                        $out['title'] = _L('Software update');
196
                        $out['icon']  = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png';
196
                        $out['icon']  = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png';
197
 
197
 
198
                        if (!OIDplus::authUtils()->isAdminLoggedIn()) {
198
                        if (!OIDplus::authUtils()->isAdminLoggedIn()) {
199
                                $out['icon'] = 'img/error.png';
199
                                $out['icon'] = 'img/error.png';
200
                                $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')).'</p>';
200
                                $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')).'</p>';
201
                                return;
201
                                return;
202
                        }
202
                        }
203
 
203
 
204
                        $out['text'] .= '<div id="update_versioninfo">';
204
                        $out['text'] .= '<div id="update_versioninfo">';
205
 
205
 
206
                        $out['text'] .= '<p><u>'._L('There are three possibilities how to keep OIDplus up-to-date').':</u></p>';
206
                        $out['text'] .= '<p><u>'._L('There are three possibilities how to keep OIDplus up-to-date').':</u></p>';
207
 
207
 
208
                        if (isset(OIDplus::getEditionInfo()['svnrepo']) && (OIDplus::getEditionInfo()['svnrepo'] != '')) {
208
                        if (isset(OIDplus::getEditionInfo()['svnrepo']) && (OIDplus::getEditionInfo()['svnrepo'] != '')) {
209
                                $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/');
209
                                $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/');
210
                                if (!str_starts_with(PHP_OS, 'WIN')) {
210
                                if (!str_starts_with(PHP_OS, 'WIN')) {
211
                                        $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');
211
                                        $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');
212
                                }
212
                                }
213
                                $out['text'] .= '</p>';
213
                                $out['text'] .= '</p>';
214
                        } else {
214
                        } else {
215
                                $out['text'] .= '<p><b>'._L('Method A').'</b>: '._L('Distribution via %1 is not possible with this edition of OIDplus','GIT').'</p>';
215
                                $out['text'] .= '<p><b>'._L('Method A').'</b>: '._L('Distribution via %1 is not possible with this edition of OIDplus','GIT').'</p>';
216
                        }
216
                        }
217
 
217
 
218
                        if (isset(OIDplus::getEditionInfo()['gitrepo']) && (OIDplus::getEditionInfo()['gitrepo'] != '')) {
218
                        if (isset(OIDplus::getEditionInfo()['gitrepo']) && (OIDplus::getEditionInfo()['gitrepo'] != '')) {
219
                                $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'));
219
                                $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'));
220
                                if (!str_starts_with(PHP_OS, 'WIN')) {
220
                                if (!str_starts_with(PHP_OS, 'WIN')) {
221
                                        $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');
221
                                        $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');
222
                                }
222
                                }
223
                                $out['text'] .= '</p>';
223
                                $out['text'] .= '</p>';
224
                        } else {
224
                        } else {
225
                                $out['text'] .= '<p><b>'._L('Method B').'</b>: '._L('Distribution via %1 is not possible with this edition of OIDplus','SVN').'</p>';
225
                                $out['text'] .= '<p><b>'._L('Method B').'</b>: '._L('Distribution via %1 is not possible with this edition of OIDplus','SVN').'</p>';
226
                        }
226
                        }
227
 
227
 
228
                        if (isset(OIDplus::getEditionInfo()['downloadpage']) && (OIDplus::getEditionInfo()['downloadpage'] != '')) {
228
                        if (isset(OIDplus::getEditionInfo()['downloadpage']) && (OIDplus::getEditionInfo()['downloadpage'] != '')) {
229
                                $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>';
229
                                $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>';
230
                        } else {
230
                        } else {
231
                                $out['text'] .= '<p><b>'._L('Method C').'</b>: '._L('Distribution via %1 is not possible with this edition of OIDplus','Snapshot').'</p>';
231
                                $out['text'] .= '<p><b>'._L('Method C').'</b>: '._L('Distribution via %1 is not possible with this edition of OIDplus','Snapshot').'</p>';
232
                        }
232
                        }
233
 
233
 
234
 
234
 
235
                        $out['text'] .= '<hr>';
235
                        $out['text'] .= '<hr>';
236
 
236
 
237
                        $installType = OIDplus::getInstallType();
237
                        $installType = OIDplus::getInstallType();
238
 
238
 
239
                        if ($installType === 'ambigous') {
239
                        if ($installType === 'ambigous') {
240
                                $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>';
240
                                $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>';
241
                                $out['text'] .= '</div>';
241
                                $out['text'] .= '</div>';
242
                        } else if ($installType === 'unknown') {
242
                        } else if ($installType === 'unknown') {
243
                                $out['text'] .= '<font color="red">'.mb_strtoupper(_L('Error')).': '._L('The version cannot be determined, and the update needs to be applied manually!').'</font>';
243
                                $out['text'] .= '<font color="red">'.mb_strtoupper(_L('Error')).': '._L('The version cannot be determined, and the update needs to be applied manually!').'</font>';
244
                                $out['text'] .= '</div>';
244
                                $out['text'] .= '</div>';
245
                        } else if (($installType === 'svn-wc') || ($installType === 'git-wc') || ($installType === 'svn-snapshot')) {
245
                        } else if (($installType === 'svn-wc') || ($installType === 'git-wc') || ($installType === 'svn-snapshot')) {
246
                                if ($installType === 'svn-wc') {
246
                                if ($installType === 'svn-wc') {
247
                                        $out['text'] .= '<p>'._L('You are using <b>method A</b> (SVN working copy).').'</p>';
247
                                        $out['text'] .= '<p>'._L('You are using <b>method A</b> (SVN working copy).').'</p>';
248
                                        $requireInfo = _L('shell access with svn/svnversion tool, or PDO/SQLite3 PHP extension');
248
                                        $requireInfo = _L('shell access with svn/svnversion tool, or PDO/SQLite3 PHP extension');
249
                                        $updateCommand = $this->getSvnCommand();
249
                                        $updateCommand = $this->getSvnCommand();
250
                                } else if ($installType === 'git-wc') {
250
                                } else if ($installType === 'git-wc') {
251
                                        $out['text'] .= '<p>'._L('You are using <b>method B</b> (Git working copy).').'</p>';
251
                                        $out['text'] .= '<p>'._L('You are using <b>method B</b> (Git working copy).').'</p>';
252
                                        $requireInfo = _L('shell access with Git client');
252
                                        $requireInfo = _L('shell access with Git client');
253
                                        $updateCommand = $this->getGitCommand();
253
                                        $updateCommand = $this->getGitCommand();
254
                                } else if ($installType === 'svn-snapshot') {
254
                                } else if ($installType === 'svn-snapshot') {
255
                                        $out['text'] .= '<p>'._L('You are using <b>method C</b> (Snapshot TAR.GZ file with .version.php file).').'</p>';
255
                                        $out['text'] .= '<p>'._L('You are using <b>method C</b> (Snapshot TAR.GZ file with .version.php file).').'</p>';
256
                                        $requireInfo = ''; // unused
256
                                        $requireInfo = ''; // unused
257
                                        $updateCommand = ''; // unused
257
                                        $updateCommand = ''; // unused
258
                                } else {
258
                                } else {
259
                                        assert(false);
259
                                        assert(false);
260
                                }
260
                                }
261
 
261
 
262
                                $local_installation = OIDplus::getVersion();
262
                                $local_installation = OIDplus::getVersion();
263
                                $newest_version = $this->getLatestRevision();
263
                                $newest_version = $this->getLatestRevision();
264
 
264
 
265
                                $out['text'] .= _L('Local installation: %1',($local_installation ?: _L('unknown'))).'<br>';
265
                                $out['text'] .= _L('Local installation: %1',($local_installation ?: _L('unknown'))).'<br>';
266
                                $out['text'] .= _L('Latest published version: %1',($newest_version ?: _L('unknown'))).'<br><br>';
266
                                $out['text'] .= _L('Latest published version: %1',($newest_version ?: _L('unknown'))).'<br><br>';
267
 
267
 
268
                                if (!$newest_version) {
268
                                if (!$newest_version) {
269
                                        if (!function_exists('curl_init')) {
269
                                        if (!function_exists('curl_init')) {
270
                                                $out['text'] .= '<p><font color="red">'._L('OIDplus could not determine the latest version.').'<br>'._L('The "%1" PHP extension is not installed at your system. Please enable the PHP extension <code>%2</code>.','CURL','php_curl').'</font></p>';
270
                                                $out['text'] .= '<p><font color="red">'._L('OIDplus could not determine the latest version.').'<br>'._L('The "%1" PHP extension is not installed at your system. Please enable the PHP extension <code>%2</code>.','CURL','php_curl').'</font></p>';
271
                                        } else {
271
                                        } else {
272
                                                $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>';
272
                                                $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>';
273
                                        }
273
                                        }
274
                                        $out['text'] .= '</div>';
274
                                        $out['text'] .= '</div>';
275
                                } else if (!$local_installation) {
275
                                } else if (!$local_installation) {
276
                                        if ($installType === 'svn-snapshot') {
276
                                        if ($installType === 'svn-snapshot') {
277
                                                $out['text'] .= '<p><font color="red">'._L('OIDplus could not determine its version.').'</font></p>';
277
                                                $out['text'] .= '<p><font color="red">'._L('OIDplus could not determine its version.').'</font></p>';
278
                                        } else {
278
                                        } else {
279
                                                $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>';
279
                                                $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>';
280
                                        }
280
                                        }
281
                                        $out['text'] .= '</div>';
281
                                        $out['text'] .= '</div>';
282
                                } else if (version_compare($local_installation, $newest_version) >= 0) {
282
                                } else if (version_compare($local_installation, $newest_version) >= 0) {
283
                                        $out['text'] .= '<p><font color="green">'._L('You are already using the latest version of OIDplus.').'</font></p>';
283
                                        $out['text'] .= '<p><font color="green">'._L('You are already using the latest version of OIDplus.').'</font></p>';
284
                                        $out['text'] .= '</div>';
284
                                        $out['text'] .= '</div>';
285
                                } else {
285
                                } else {
286
                                        if (($installType === 'svn-wc') || ($installType === 'git-wc')) {
286
                                        if (($installType === 'svn-wc') || ($installType === 'git-wc')) {
287
                                                $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>';
287
                                                $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>';
288
                                                $out['text'] .= '<p>'._L('Alternatively, click this button to execute the command through the web-interface (command execution and write permissions required).').'</p>';
288
                                                $out['text'] .= '<p>'._L('Alternatively, click this button to execute the command through the web-interface (command execution and write permissions required).').'</p>';
289
                                        }
289
                                        }
290
 
290
 
291
                                        $out['text'] .= '<p><input type="button" onclick="OIDplusPageAdminSoftwareUpdate.doUpdateOIDplus('.((int)substr($local_installation,4)+1).', '.substr($newest_version,4).')" value="'._L('Update NOW').'"></p>';
291
                                        $out['text'] .= '<p><input type="button" onclick="OIDplusPageAdminSoftwareUpdate.doUpdateOIDplus('.((int)substr($local_installation,4)+1).', '.substr($newest_version,4).')" value="'._L('Update NOW').'"></p>';
292
 
292
 
293
                                        // TODO: Open "system_file_check" without page reload.
293
                                        // TODO: Open "system_file_check" without page reload.
294
                                        // TODO: Only show link if the plugin is installed
294
                                        // TODO: Only show link if the plugin is installed
295
                                        $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>';
295
                                        $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>';
296
 
296
 
297
                                        $out['text'] .= '</div>';
297
                                        $out['text'] .= '</div>';
298
 
298
 
299
                                        $out['text'] .= $this->showPreview($local_installation, $newest_version);
299
                                        $out['text'] .= $this->showPreview($local_installation, $newest_version);
300
                                }
300
                                }
301
                        }
301
                        }
302
                } else {
302
                } else {
303
                        $handled = false;
303
                        $handled = false;
304
                }
304
                }
305
        }
305
        }
306
 
306
 
307
        /**
307
        /**
308
         * @param array $json
308
         * @param array $json
309
         * @param string|null $ra_email
309
         * @param string|null $ra_email
310
         * @param bool $nonjs
310
         * @param bool $nonjs
311
         * @param string $req_goto
311
         * @param string $req_goto
312
         * @return bool
312
         * @return bool
313
         * @throws OIDplusException
313
         * @throws OIDplusException
314
         */
314
         */
315
        public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool {
315
        public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool {
316
                if (!OIDplus::authUtils()->isAdminLoggedIn()) return false;
316
                if (!OIDplus::authUtils()->isAdminLoggedIn()) return false;
317
 
317
 
318
                if (file_exists(__DIR__.'/img/main_icon16.png')) {
318
                if (file_exists(__DIR__.'/img/main_icon16.png')) {
319
                        $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png';
319
                        $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png';
320
                } else {
320
                } else {
321
                        $tree_icon = null; // default icon (folder)
321
                        $tree_icon = null; // default icon (folder)
322
                }
322
                }
323
 
323
 
324
                $json[] = array(
324
                $json[] = array(
325
                        'id' => 'oidplus:software_update',
325
                        'id' => 'oidplus:software_update',
326
                        'icon' => $tree_icon,
326
                        'icon' => $tree_icon,
327
                        'text' => _L('Software update')
327
                        'text' => _L('Software update')
328
                );
328
                );
329
 
329
 
330
                return true;
330
                return true;
331
        }
331
        }
332
 
332
 
333
        /**
333
        /**
334
         * @param string $request
334
         * @param string $request
335
         * @return array|false
335
         * @return array|false
336
         */
336
         */
337
        public function tree_search(string $request) {
337
        public function tree_search(string $request) {
338
                return false;
338
                return false;
339
        }
339
        }
340
 
340
 
341
        /**
341
        /**
342
         * @var string|null
342
         * @var string|null
343
         */
343
         */
344
        private $releases_ser = null;
344
        private $releases_ser = null;
345
 
345
 
346
        /**
346
        /**
347
         * @param string $local_ver
347
         * @param string $local_ver
348
         * @return false|string
348
         * @return false|string
349
         */
349
         */
350
        private function showChangelog(string $local_ver) {
350
        private function showChangelog(string $local_ver) {
351
 
351
 
352
                try {
352
                try {
353
                        if (is_null($this->releases_ser)) {
353
                        if (is_null($this->releases_ser)) {
354
                                if (function_exists('gzdecode')) {
354
                                if (function_exists('gzdecode')) {
355
                                        $url = OIDplus::getEditionInfo()['revisionlog_gz'];
355
                                        $url = OIDplus::getEditionInfo()['revisionlog_gz'];
356
                                        $cont = url_get_contents($url);
356
                                        $cont = url_get_contents($url);
357
                                        if ($cont !== false) $cont = @gzdecode($cont);
357
                                        if ($cont !== false) $cont = @gzdecode($cont);
358
                                } else {
358
                                } else {
359
                                        $url = OIDplus::getEditionInfo()['revisionlog'];
359
                                        $url = OIDplus::getEditionInfo()['revisionlog'];
360
                                        $cont = url_get_contents($url);
360
                                        $cont = url_get_contents($url);
361
                                }
361
                                }
362
                                if ($cont === false) return false;
362
                                if ($cont === false) return false;
363
                                $this->releases_ser = $cont;
363
                                $this->releases_ser = $cont;
364
                        } else {
364
                        } else {
365
                                $cont = $this->releases_ser;
365
                                $cont = $this->releases_ser;
366
                        }
366
                        }
367
                        $content = '';
367
                        $content = '';
368
                        $ary = @unserialize($cont);
368
                        $ary = @unserialize($cont);
369
                        if ($ary === false) return false;
369
                        if ($ary === false) return false;
370
                        krsort($ary);
370
                        krsort($ary);
371
                        foreach ($ary as $rev => $data) {
371
                        foreach ($ary as $rev => $data) {
372
                                if (version_compare("svn-$rev", $local_ver) <= 0) continue;
372
                                if (version_compare("svn-$rev", $local_ver) <= 0) continue;
373
                                $comment = empty($data['msg']) ? _L('No comment') : $data['msg'];
373
                                $comment = empty($data['msg']) ? _L('No comment') : $data['msg'];
374
                                $tex = _L("New revision %1 by %2",$rev,$data['author'])." (".$data['date'].") ";
374
                                $tex = _L("New revision %1 by %2",$rev,$data['author'])." (".$data['date'].") ";
375
                                $content .= trim($tex . str_replace("\n", "\n".str_repeat(' ', strlen($tex)), $comment));
375
                                $content .= trim($tex . str_replace("\n", "\n".str_repeat(' ', strlen($tex)), $comment));
376
                                $content .= "\n";
376
                                $content .= "\n";
377
                        }
377
                        }
378
                        return $content;
378
                        return $content;
379
                } catch (\Exception $e) {
379
                } catch (\Exception $e) {
380
                        return false;
380
                        return false;
381
                }
381
                }
382
 
382
 
383
        }
383
        }
384
 
384
 
385
        /**
385
        /**
386
         * @return false|string
386
         * @return false|string
387
         */
387
         */
388
        private function getLatestRevision() {
388
        private function getLatestRevision() {
389
                try {
389
                try {
390
                        if (is_null($this->releases_ser)) {
390
                        if (is_null($this->releases_ser)) {
391
                                if (function_exists('gzdecode')) {
391
                                if (function_exists('gzdecode')) {
392
                                        $url = OIDplus::getEditionInfo()['revisionlog_gz'];
392
                                        $url = OIDplus::getEditionInfo()['revisionlog_gz'];
393
                                        $cont = url_get_contents($url);
393
                                        $cont = url_get_contents($url);
394
                                        if ($cont !== false) $cont = @gzdecode($cont);
394
                                        if ($cont !== false) $cont = @gzdecode($cont);
395
                                } else {
395
                                } else {
396
                                        $url = OIDplus::getEditionInfo()['revisionlog'];
396
                                        $url = OIDplus::getEditionInfo()['revisionlog'];
397
                                        $cont = url_get_contents($url);
397
                                        $cont = url_get_contents($url);
398
                                }
398
                                }
399
                                if ($cont === false) return false;
399
                                if ($cont === false) return false;
400
                                $this->releases_ser = $cont;
400
                                $this->releases_ser = $cont;
401
                        } else {
401
                        } else {
402
                                $cont = $this->releases_ser;
402
                                $cont = $this->releases_ser;
403
                        }
403
                        }
404
                        $ary = @unserialize($cont);
404
                        $ary = @unserialize($cont);
405
                        if ($ary === false) return false;
405
                        if ($ary === false) return false;
406
                        krsort($ary);
406
                        krsort($ary);
407
                        $max_rev = array_keys($ary)[0];
407
                        $max_rev = array_keys($ary)[0];
408
                        return 'svn-' . $max_rev;
408
                        return 'svn-' . $max_rev;
409
                } catch (\Exception $e) {
409
                } catch (\Exception $e) {
410
                        return false;
410
                        return false;
411
                }
411
                }
412
        }
412
        }
413
 
413
 
414
        /**
414
        /**
415
         * @param string $local_installation
415
         * @param string $local_installation
416
         * @param string $newest_version
416
         * @param string $newest_version
417
         * @return string
417
         * @return string
418
         */
418
         */
419
        private function showPreview(string $local_installation, string $newest_version): string {
419
        private function showPreview(string $local_installation, string $newest_version): string {
420
                $out = '<h2 id="update_header">'._L('Preview of update %1 &rarr; %2',$local_installation,$newest_version).'</h2>';
420
                $out = '<h2 id="update_header">'._L('Preview of update %1 &rarr; %2',$local_installation,$newest_version).'</h2>';
421
 
421
 
422
                ob_start();
422
                ob_start();
423
                try {
423
                try {
424
                        $cont = $this->showChangelog($local_installation);
424
                        $cont = $this->showChangelog($local_installation);
425
                } catch (\Exception $e) {
425
                } catch (\Exception $e) {
426
                        $cont = _L('Error: %1',$e->getMessage());
426
                        $cont = _L('Error: %1',$e->getMessage());
427
                }
427
                }
428
                ob_end_clean();
428
                ob_end_clean();
429
 
429
 
430
                $cont = preg_replace('@!!!(.+)\\n@', '<font color="red">!!!\\1</font>'."\n", "$cont\n");
430
                $cont = preg_replace('@!!!(.+)\\n@', '<font color="red">!!!\\1</font>'."\n", "$cont\n");
431
 
431
 
432
                $out .= '<pre id="update_infobox">'.$cont.'</pre>';
432
                $out .= '<pre id="update_infobox">'.$cont.'</pre>';
433
 
433
 
434
                return $out;
434
                return $out;
435
        }
435
        }
436
 
436
 
437
        /**
437
        /**
438
         * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_8
438
         * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_8
439
         * @param string|null $user
439
         * @param string|null $user
440
         * @return array
440
         * @return array
441
         * @throws OIDplusException
441
         * @throws OIDplusException
442
         */
442
         */
443
        public function getNotifications(string $user=null): array {
443
        public function getNotifications(string $user=null): array {
444
                $notifications = array();
444
                $notifications = array();
445
                if ((!$user || ($user == 'admin')) && OIDplus::authUtils()->isAdminLoggedIn()) {
445
                if ((!$user || ($user == 'admin')) && OIDplus::authUtils()->isAdminLoggedIn()) {
446
 
446
 
447
                        // Following code is based on the VNag plugin (admin 901) code
447
                        // Following code is based on the VNag plugin (admin 901) code
448
 
448
 
449
                        $installType = OIDplus::getInstallType();
449
                        $installType = OIDplus::getInstallType();
450
 
450
 
451
                        if ($installType === 'ambigous') {
451
                        if ($installType === 'ambigous') {
452
                                $out_stat = 'WARN';
452
                                $out_stat = 'WARN';
453
                                $out_msg  = _L('Multiple version files/directories (oidplus_version.txt, .version.php, .git, or .svn) are existing! Therefore, the version is ambiguous!');
453
                                $out_msg  = _L('Multiple version files/directories (oidplus_version.txt, .version.php, .git, or .svn) are existing! Therefore, the version is ambiguous!');
454
                        } else if ($installType === 'unknown') {
454
                        } else if ($installType === 'unknown') {
455
                                $out_stat = 'WARN';
455
                                $out_stat = 'WARN';
456
                                $out_msg  = _L('The version cannot be determined, and the update needs to be applied manually!');
456
                                $out_msg  = _L('The version cannot be determined, and the update needs to be applied manually!');
457
                        } else if (($installType === 'svn-wc') || ($installType === 'git-wc')) {
457
                        } else if (($installType === 'svn-wc') || ($installType === 'git-wc')) {
458
                                $local_installation = OIDplus::getVersion();
458
                                $local_installation = OIDplus::getVersion();
459
                                $newest_version = $this->getLatestRevision();
459
                                $newest_version = $this->getLatestRevision();
460
 
460
 
461
                                $requireInfo = ($installType === 'svn-wc') ? _L('shell access with svn/svnversion tool, or PDO/SQLite3 PHP extension') : _L('shell access with Git client');
461
                                $requireInfo = ($installType === 'svn-wc') ? _L('shell access with svn/svnversion tool, or PDO/SQLite3 PHP extension') : _L('shell access with Git client');
462
                                $updateCommand = ($installType === 'svn-wc') ? 'svn update' : 'git pull';
462
                                $updateCommand = ($installType === 'svn-wc') ? 'svn update' : 'git pull';
463
 
463
 
464
                                if (!$newest_version) {
464
                                if (!$newest_version) {
465
                                        $out_stat = 'WARN';
465
                                        $out_stat = 'WARN';
466
                                        if (!function_exists('curl_init')) {
466
                                        if (!function_exists('curl_init')) {
467
                                                $out_msg  = _L('OIDplus could not determine the latest version.').' '._L('The "%1" PHP extension is not installed at your system. Please enable the PHP extension <code>%2</code>.','CURL','php_curl');
467
                                                $out_msg  = _L('OIDplus could not determine the latest version.').' '._L('The "%1" PHP extension is not installed at your system. Please enable the PHP extension <code>%2</code>.','CURL','php_curl');
468
                                        } else {
468
                                        } else {
469
                                                $out_msg  = _L('OIDplus could not determine the latest version.').' '._L('Probably the ViaThinkSoft server could not be reached.');
469
                                                $out_msg  = _L('OIDplus could not determine the latest version.').' '._L('Probably the ViaThinkSoft server could not be reached.');
470
                                        }
470
                                        }
471
                                } else if (!$local_installation) {
471
                                } else if (!$local_installation) {
472
                                        $out_stat = 'WARN';
472
                                        $out_stat = 'WARN';
473
                                        $out_msg  = _L('OIDplus could not determine its version (Required: %1). Please update your system manually via the "%2" command regularly.', $requireInfo, $updateCommand);
473
                                        $out_msg  = _L('OIDplus could not determine its version (Required: %1). Please update your system manually via the "%2" command regularly.', $requireInfo, $updateCommand);
474
                                } else if (version_compare($local_installation, $newest_version) >= 0) {
474
                                } else if (version_compare($local_installation, $newest_version) >= 0) {
475
                                        $out_stat = 'INFO';
475
                                        $out_stat = 'INFO';
476
                                        $out_msg  = _L('You are using the latest version of OIDplus (%1 local / %2 remote)', $local_installation, $newest_version);
476
                                        $out_msg  = _L('You are using the latest version of OIDplus (%1 local / %2 remote)', $local_installation, $newest_version);
477
                                } else {
477
                                } else {
478
                                        $out_stat = 'WARN';
478
                                        $out_stat = 'WARN';
479
                                        $out_msg  = _L('OIDplus is outdated. (%1 local / %2 remote)', $local_installation, $newest_version);
479
                                        $out_msg  = _L('OIDplus is outdated. (%1 local / %2 remote)', $local_installation, $newest_version);
480
                                }
480
                                }
481
                        } else if ($installType === 'svn-snapshot') {
481
                        } else if ($installType === 'svn-snapshot') {
482
                                $local_installation = OIDplus::getVersion();
482
                                $local_installation = OIDplus::getVersion();
483
                                $newest_version = $this->getLatestRevision();
483
                                $newest_version = $this->getLatestRevision();
484
 
484
 
485
                                if (!$newest_version) {
485
                                if (!$newest_version) {
486
                                        $out_stat = 'WARN';
486
                                        $out_stat = 'WARN';
487
                                        if (!function_exists('curl_init')) {
487
                                        if (!function_exists('curl_init')) {
488
                                                $out_msg  = _L('OIDplus could not determine the latest version.').' '._L('The "%1" PHP extension is not installed at your system. Please enable the PHP extension <code>%2</code>.','CURL','php_curl');
488
                                                $out_msg  = _L('OIDplus could not determine the latest version.').' '._L('The "%1" PHP extension is not installed at your system. Please enable the PHP extension <code>%2</code>.','CURL','php_curl');
489
                                        } else {
489
                                        } else {
490
                                                $out_msg  = _L('OIDplus could not determine the latest version.').' '._L('Probably the ViaThinkSoft server could not be reached.');
490
                                                $out_msg  = _L('OIDplus could not determine the latest version.').' '._L('Probably the ViaThinkSoft server could not be reached.');
491
                                        }
491
                                        }
-
 
492
                                } else if (!$local_installation) {
-
 
493
                                        $out_stat = 'WARN';
-
 
494
                                        $out_msg  = _L('OIDplus could not determine its version. Please update your system manually by downloading the latest archive file from oidplus.com.');
492
                                } else if (version_compare($local_installation, $newest_version) >= 0) {
495
                                } else if (version_compare($local_installation, $newest_version) >= 0) {
493
                                        $out_stat = 'INFO';
496
                                        $out_stat = 'INFO';
494
                                        $out_msg  = _L('You are using the latest version of OIDplus (%1 local / %2 remote)', $local_installation, $newest_version);
497
                                        $out_msg  = _L('You are using the latest version of OIDplus (%1 local / %2 remote)', $local_installation, $newest_version);
495
                                } else {
498
                                } else {
496
                                        $out_stat = 'WARN';
499
                                        $out_stat = 'WARN';
497
                                        $out_msg  = _L('OIDplus is outdated. (%1 local / %2 remote)', $local_installation, $newest_version);
500
                                        $out_msg  = _L('OIDplus is outdated. (%1 local / %2 remote)', $local_installation, $newest_version);
498
                                }
501
                                }
499
                        } else {
502
                        } else {
500
                                assert(false);
503
                                assert(false);
501
                                return $notifications;
504
                                return $notifications;
502
                        }
505
                        }
503
 
506
 
504
                        if ($out_stat != 'INFO') {
507
                        if ($out_stat != 'INFO') {
505
                                $out_msg = '<a '.OIDplus::gui()->link('oidplus:software_update').'>'._L('Software update').'</a>: ' . $out_msg;
508
                                $out_msg = '<a '.OIDplus::gui()->link('oidplus:software_update').'>'._L('Software update').'</a>: ' . $out_msg;
506
 
509
 
507
                                $notifications[] = array($out_stat, $out_msg);
510
                                $notifications[] = array($out_stat, $out_msg);
508
                        }
511
                        }
509
 
512
 
510
                }
513
                }
511
                return $notifications;
514
                return $notifications;
512
        }
515
        }
513
 
516
 
514
}
517
}
515
 
518