Subversion Repositories oidplus

Rev

Rev 830 | Rev 1086 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
635 daniel-mar 1
<?php
2
 
3
/*
4
 * OIDplus 2.0
5
 * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft
6
 *
7
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with the License.
9
 * You may obtain a copy of the License at
10
 *
11
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
18
 */
19
 
1050 daniel-mar 20
namespace ViaThinkSoft\OIDplus;
635 daniel-mar 21
 
22
class OIDplusPageAdminVNagVersionCheck extends OIDplusPagePluginAdmin {
23
 
24
        public function init($html=true) {
25
                OIDplus::config()->prepareConfigKey('vnag_version_check_password_protected', 'If set to 1 ("on"), the VNag version check is password protected', '1', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
26
                        if (($value != '0') && ($value != '1')) {
27
                                throw new OIDplusException(_L('Please enter either 0 ("off") or 1 ("on").'));
28
                        }
29
                });
30
        }
31
 
32
        public function action($actionID, $params) {
33
        }
34
 
35
        public function gui($id, &$out, &$handled) {
36
                $parts = explode('.',$id,2);
37
                if (!isset($parts[1])) $parts[1] = '';
38
                if ($parts[0] == 'oidplus:vnag_version_check') {
39
                        @set_time_limit(0);
40
 
41
 
42
                        $handled = true;
43
                        $out['title'] = _L('VNag version check');
801 daniel-mar 44
                        $out['icon']  = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png';
635 daniel-mar 45
 
46
                        if (!OIDplus::authUtils()->isAdminLoggedIn()) {
800 daniel-mar 47
                                $out['icon'] = 'img/error.png';
635 daniel-mar 48
                                $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')).'</p>';
49
                                return;
50
                        }
51
 
52
                        if (file_exists(__DIR__ . '/tutorial$'.OIDplus::getCurrentLang().'.html')) {
53
                                $cont = file_get_contents(__DIR__ . '/tutorial$'.OIDplus::getCurrentLang().'.html');
54
                        } else if (file_exists(__DIR__ . '/tutorial.html')) {
55
                                $cont = file_get_contents(__DIR__ . '/tutorial.html');
56
                        } else {
57
                                $cont = '';
58
                        }
59
 
60
                        $cont = str_replace('%%SYSTEM_URL%%',OIDplus::localpath(),$cont);
61
                        $cont = str_replace('%%REL_LOC_PATH%%',OIDplus::localpath(__DIR__,true),$cont);
801 daniel-mar 62
                        $cont = str_replace('%%REL_WEB_PATH%%',OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE),$cont);
635 daniel-mar 63
                        $cont = str_replace('%%ABS_LOC_PATH%%',OIDplus::localpath(__DIR__,false),$cont);
801 daniel-mar 64
                        $cont = str_replace('%%ABS_WEB_PATH%%',OIDplus::webpath(__DIR__,OIDplus::PATH_ABSOLUTE_CANONICAL),$cont);
635 daniel-mar 65
                        if (OIDplus::config()->getValue('vnag_version_check_password_protected','1') == '1') {
66
                                $cont = str_replace('%%WEBREADER_PASSWORD%%',self::vnag_password(),$cont);
67
                        } else {
68
                                $cont = str_replace('%%WEBREADER_PASSWORD%%','',$cont);
69
                        }
70
                        if (OIDplus::getPkiStatus()) {
830 daniel-mar 71
                                $pubkey = trim(OIDplus::getSystemPublicKey());
635 daniel-mar 72
                                $pubkey = str_replace("\\","\\\\",$pubkey);
73
                                $pubkey = str_replace("\r","\\r",$pubkey);
74
                                $pubkey = str_replace("\n","\\n",$pubkey);
75
                        } else {
76
                                $pubkey = "";
77
                        }
78
                        $cont = str_replace('%%WEBREADER_PUBKEY%%',$pubkey,$cont);
79
 
80
                        $out['text'] .= $cont;
81
                } else {
82
                        $handled = false;
83
                }
84
        }
85
 
86
        public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
87
                if (!OIDplus::authUtils()->isAdminLoggedIn()) return false;
88
 
800 daniel-mar 89
                if (file_exists(__DIR__.'/img/main_icon16.png')) {
801 daniel-mar 90
                        $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png';
635 daniel-mar 91
                } else {
92
                        $tree_icon = null; // default icon (folder)
93
                }
94
 
95
                $json[] = array(
96
                        'id' => 'oidplus:vnag_version_check',
97
                        'icon' => $tree_icon,
98
                        'text' => _L('VNag version check')
99
                );
100
 
101
                return true;
102
        }
103
 
104
        public function tree_search($request) {
105
                return false;
106
        }
107
 
108
        public static function vnag_password() {
109
                return sha3_512(OIDplus::baseConfig()->getValue('SERVER_SECRET').'/VNAG');
110
        }
111
 
112
}