Subversion Repositories oidplus

Rev

Rev 1086 | Rev 1130 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1086 Rev 1116
Line 23... Line 23...
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
 
27
 
-
 
28
        /**
-
 
29
         * @param bool $html
-
 
30
         * @return void
-
 
31
         */
28
        public function init($html=true) {
32
        public function init(bool $html=true) {
29
        }
33
        }
30
 
34
 
-
 
35
        /**
-
 
36
         * @return string
-
 
37
         */
31
        private function getGitCommand() {
38
        private function getGitCommand(): string {
32
                return 'git --git-dir='.escapeshellarg(OIDplus::findGitFolder().'/').' --work-tree='.escapeshellarg(OIDplus::localpath()).' -C "" pull origin master -s recursive -X theirs';
39
                return 'git --git-dir='.escapeshellarg(OIDplus::findGitFolder().'/').' --work-tree='.escapeshellarg(OIDplus::localpath()).' -C "" pull origin master -s recursive -X theirs';
33
        }
40
        }
34
 
41
 
-
 
42
        /**
-
 
43
         * @return string
-
 
44
         */
35
        private function getSvnCommand() {
45
        private function getSvnCommand(): string {
36
                return 'svn update --accept theirs-full';
46
                return 'svn update --accept theirs-full';
37
        }
47
        }
38
 
48
 
-
 
49
        /**
-
 
50
         * @param string $actionID
-
 
51
         * @param array $params
-
 
52
         * @return array
-
 
53
         * @throws OIDplusException
-
 
54
         */
39
        public function action($actionID, $params) {
55
        public function action(string $actionID, array $params): array {
40
                if ($actionID == 'update_now') {
56
                if ($actionID == 'update_now') {
41
                        @set_time_limit(0);
57
                        @set_time_limit(0);
42
 
58
 
43
                        if (!OIDplus::authUtils()->isAdminLoggedIn()) {
59
                        if (!OIDplus::authUtils()->isAdminLoggedIn()) {
44
                                throw new OIDplusException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')));
60
                                throw new OIDplusException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')));
Line 146... Line 162...
146
                                        return array("status" => 0, "content" => $res, "rev" => $rev);
162
                                        return array("status" => 0, "content" => $res, "rev" => $rev);
147
                                } else if ($update_version == 2) {
163
                                } else if ($update_version == 2) {
148
                                        // In this version, the client will call the web-update file.
164
                                        // In this version, the client will call the web-update file.
149
                                        // 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
150
                                        return array("status" => 0, "update_file" => $tmp_filename, "rev" => $rev);
166
                                        return array("status" => 0, "update_file" => $tmp_filename, "rev" => $rev);
-
 
167
                                } else {
-
 
168
                                        throw new OIDplusException(_L("Unexpected update version"));
151
                                }
169
                                }
152
                        }
170
                        }
153
                        else {
171
                        else {
154
                                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!'));
155
                        }
173
                        }
-
 
174
                } else {
-
 
175
                        return parent::action($actionID, $params);
156
                }
176
                }
157
        }
177
        }
158
 
178
 
-
 
179
        /**
-
 
180
         * @param string $id
-
 
181
         * @param array $out
-
 
182
         * @param bool $handled
-
 
183
         * @return void
-
 
184
         * @throws OIDplusException
-
 
185
         */
159
        public function gui($id, &$out, &$handled) {
186
        public function gui(string $id, array &$out, bool &$handled) {
160
                $parts = explode('.',$id,2);
187
                $parts = explode('.',$id,2);
161
                if (!isset($parts[1])) $parts[1] = '';
188
                if (!isset($parts[1])) $parts[1] = '';
162
                if ($parts[0] == 'oidplus:software_update') {
189
                if ($parts[0] == 'oidplus:software_update') {
163
                        @set_time_limit(0);
190
                        @set_time_limit(0);
164
 
191
 
Line 271... Line 298...
271
                } else {
298
                } else {
272
                        $handled = false;
299
                        $handled = false;
273
                }
300
                }
274
        }
301
        }
275
 
302
 
-
 
303
        /**
-
 
304
         * @param array $json
-
 
305
         * @param string|null $ra_email
-
 
306
         * @param bool $nonjs
-
 
307
         * @param string $req_goto
-
 
308
         * @return bool
-
 
309
         * @throws OIDplusException
-
 
310
         */
276
        public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
311
        public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool {
277
                if (!OIDplus::authUtils()->isAdminLoggedIn()) return false;
312
                if (!OIDplus::authUtils()->isAdminLoggedIn()) return false;
278
 
313
 
279
                if (file_exists(__DIR__.'/img/main_icon16.png')) {
314
                if (file_exists(__DIR__.'/img/main_icon16.png')) {
280
                        $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png';
315
                        $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png';
281
                } else {
316
                } else {
Line 289... Line 324...
289
                );
324
                );
290
 
325
 
291
                return true;
326
                return true;
292
        }
327
        }
293
 
328
 
-
 
329
        /**
-
 
330
         * @param string $request
-
 
331
         * @return array|false
-
 
332
         */
294
        public function tree_search($request) {
333
        public function tree_search(string $request) {
295
                return false;
334
                return false;
296
        }
335
        }
297
 
336
 
-
 
337
        /**
-
 
338
         * @var null
-
 
339
         */
298
        private $releases_ser = null;
340
        private $releases_ser = null;
299
 
341
 
-
 
342
        /**
-
 
343
         * @param $local_ver
-
 
344
         * @return false|string
-
 
345
         */
300
        private function showChangelog($local_ver) {
346
        private function showChangelog($local_ver) {
301
 
347
 
302
                try {
348
                try {
303
                        if (is_null($this->releases_ser)) {
349
                        if (is_null($this->releases_ser)) {
304
                                if (function_exists('gzdecode')) {
350
                                if (function_exists('gzdecode')) {
Line 330... Line 376...
330
                        return false;
376
                        return false;
331
                }
377
                }
332
 
378
 
333
        }
379
        }
334
 
380
 
-
 
381
        /**
-
 
382
         * @return false|string
-
 
383
         */
335
        private function getLatestRevision() {
384
        private function getLatestRevision() {
336
                try {
385
                try {
337
                        if (is_null($this->releases_ser)) {
386
                        if (is_null($this->releases_ser)) {
338
                                if (function_exists('gzdecode')) {
387
                                if (function_exists('gzdecode')) {
339
                                        $url = OIDplus::getEditionInfo()['revisionlog_gz'];
388
                                        $url = OIDplus::getEditionInfo()['revisionlog_gz'];
Line 357... Line 406...
357
                } catch (\Exception $e) {
406
                } catch (\Exception $e) {
358
                        return false;
407
                        return false;
359
                }
408
                }
360
        }
409
        }
361
 
410
 
-
 
411
        /**
-
 
412
         * @param $local_installation
-
 
413
         * @param $newest_version
-
 
414
         * @return string
-
 
415
         */
362
        private function showPreview($local_installation, $newest_version) {
416
        private function showPreview($local_installation, $newest_version) {
363
                $out = '<h2 id="update_header">'._L('Preview of update %1 &rarr; %2',$local_installation,$newest_version).'</h2>';
417
                $out = '<h2 id="update_header">'._L('Preview of update %1 &rarr; %2',$local_installation,$newest_version).'</h2>';
364
 
418
 
365
                ob_start();
419
                ob_start();
366
                try {
420
                try {
Line 375... Line 429...
375
                $out .= '<pre id="update_infobox">'.$cont.'</pre>';
429
                $out .= '<pre id="update_infobox">'.$cont.'</pre>';
376
 
430
 
377
                return $out;
431
                return $out;
378
        }
432
        }
379
 
433
 
-
 
434
        /**
-
 
435
         * @param string $id
-
 
436
         * @return bool
-
 
437
         */
380
        public function implementsFeature($id) {
438
        public function implementsFeature(string $id): bool {
381
                if (strtolower($id) == '1.3.6.1.4.1.37476.2.5.2.3.8') return true; // getNotifications()
439
                if (strtolower($id) == '1.3.6.1.4.1.37476.2.5.2.3.8') return true; // getNotifications()
382
                return false;
440
                return false;
383
        }
441
        }
384
 
442
 
-
 
443
        /**
-
 
444
         * Implements interface 1.3.6.1.4.1.37476.2.5.2.3.8
-
 
445
         * @param $user
-
 
446
         * @return array
-
 
447
         * @throws OIDplusException
-
 
448
         */
385
        public function getNotifications($user=null): array {
449
        public function getNotifications($user=null): array {
386
                // Interface 1.3.6.1.4.1.37476.2.5.2.3.8
-
 
387
                $notifications = array();
450
                $notifications = array();
388
                if ((!$user || ($user == 'admin')) && OIDplus::authUtils()->isAdminLoggedIn()) {
451
                if ((!$user || ($user == 'admin')) && OIDplus::authUtils()->isAdminLoggedIn()) {
389
 
452
 
390
                        // Following code is based on the VNag plugin (admin 901) code
453
                        // Following code is based on the VNag plugin (admin 901) code
391
 
454