Subversion Repositories oidplus

Rev

Rev 1086 | Rev 1130 | 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
1086 daniel-mar 5
 * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft
635 daniel-mar 6
 *
7
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with the License.
9
 * You may obtain a copy of the License at
10
 *
11
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
18
 */
19
 
1050 daniel-mar 20
namespace ViaThinkSoft\OIDplus;
635 daniel-mar 21
 
1086 daniel-mar 22
// phpcs:disable PSR1.Files.SideEffects
23
\defined('INSIDE_OIDPLUS') or die;
24
// phpcs:enable PSR1.Files.SideEffects
25
 
635 daniel-mar 26
class OIDplusPageAdminVNagVersionCheck extends OIDplusPagePluginAdmin {
27
 
1116 daniel-mar 28
        /**
29
         * @param bool $html
30
         * @return void
31
         * @throws OIDplusException
32
         */
33
        public function init(bool $html=true) {
635 daniel-mar 34
                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) {
35
                        if (($value != '0') && ($value != '1')) {
36
                                throw new OIDplusException(_L('Please enter either 0 ("off") or 1 ("on").'));
37
                        }
38
                });
39
        }
40
 
1116 daniel-mar 41
        /**
42
         * @param string $actionID
43
         * @param array $params
44
         * @return array
45
         * @throws OIDplusException
46
         */
47
        public function action(string $actionID, array $params): array {
48
                return parent::action($actionID, $params);
635 daniel-mar 49
        }
50
 
1116 daniel-mar 51
        /**
52
         * @param string $id
53
         * @param array $out
54
         * @param bool $handled
55
         * @return void
56
         * @throws OIDplusConfigInitializationException
57
         * @throws OIDplusException
58
         */
59
        public function gui(string $id, array &$out, bool &$handled) {
635 daniel-mar 60
                $parts = explode('.',$id,2);
61
                if (!isset($parts[1])) $parts[1] = '';
62
                if ($parts[0] == 'oidplus:vnag_version_check') {
63
                        @set_time_limit(0);
64
 
65
 
66
                        $handled = true;
67
                        $out['title'] = _L('VNag version check');
801 daniel-mar 68
                        $out['icon']  = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png';
635 daniel-mar 69
 
70
                        if (!OIDplus::authUtils()->isAdminLoggedIn()) {
800 daniel-mar 71
                                $out['icon'] = 'img/error.png';
635 daniel-mar 72
                                $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')).'</p>';
73
                                return;
74
                        }
75
 
76
                        if (file_exists(__DIR__ . '/tutorial$'.OIDplus::getCurrentLang().'.html')) {
77
                                $cont = file_get_contents(__DIR__ . '/tutorial$'.OIDplus::getCurrentLang().'.html');
78
                        } else if (file_exists(__DIR__ . '/tutorial.html')) {
79
                                $cont = file_get_contents(__DIR__ . '/tutorial.html');
80
                        } else {
81
                                $cont = '';
82
                        }
83
 
84
                        $cont = str_replace('%%SYSTEM_URL%%',OIDplus::localpath(),$cont);
85
                        $cont = str_replace('%%REL_LOC_PATH%%',OIDplus::localpath(__DIR__,true),$cont);
801 daniel-mar 86
                        $cont = str_replace('%%REL_WEB_PATH%%',OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE),$cont);
635 daniel-mar 87
                        $cont = str_replace('%%ABS_LOC_PATH%%',OIDplus::localpath(__DIR__,false),$cont);
801 daniel-mar 88
                        $cont = str_replace('%%ABS_WEB_PATH%%',OIDplus::webpath(__DIR__,OIDplus::PATH_ABSOLUTE_CANONICAL),$cont);
635 daniel-mar 89
                        if (OIDplus::config()->getValue('vnag_version_check_password_protected','1') == '1') {
90
                                $cont = str_replace('%%WEBREADER_PASSWORD%%',self::vnag_password(),$cont);
91
                        } else {
92
                                $cont = str_replace('%%WEBREADER_PASSWORD%%','',$cont);
93
                        }
94
                        if (OIDplus::getPkiStatus()) {
830 daniel-mar 95
                                $pubkey = trim(OIDplus::getSystemPublicKey());
635 daniel-mar 96
                                $pubkey = str_replace("\\","\\\\",$pubkey);
97
                                $pubkey = str_replace("\r","\\r",$pubkey);
98
                                $pubkey = str_replace("\n","\\n",$pubkey);
99
                        } else {
100
                                $pubkey = "";
101
                        }
102
                        $cont = str_replace('%%WEBREADER_PUBKEY%%',$pubkey,$cont);
103
 
104
                        $out['text'] .= $cont;
105
                } else {
106
                        $handled = false;
107
                }
108
        }
109
 
1116 daniel-mar 110
        /**
111
         * @param array $json
112
         * @param string|null $ra_email
113
         * @param bool $nonjs
114
         * @param string $req_goto
115
         * @return bool
116
         * @throws OIDplusException
117
         */
118
        public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool {
635 daniel-mar 119
                if (!OIDplus::authUtils()->isAdminLoggedIn()) return false;
120
 
800 daniel-mar 121
                if (file_exists(__DIR__.'/img/main_icon16.png')) {
801 daniel-mar 122
                        $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png';
635 daniel-mar 123
                } else {
124
                        $tree_icon = null; // default icon (folder)
125
                }
126
 
127
                $json[] = array(
128
                        'id' => 'oidplus:vnag_version_check',
129
                        'icon' => $tree_icon,
130
                        'text' => _L('VNag version check')
131
                );
132
 
133
                return true;
134
        }
135
 
1116 daniel-mar 136
        /**
137
         * @param string $request
138
         * @return array|false
139
         */
140
        public function tree_search(string $request) {
635 daniel-mar 141
                return false;
142
        }
143
 
1116 daniel-mar 144
        /**
145
         * @return string
146
         * @throws OIDplusException
147
         */
635 daniel-mar 148
        public static function vnag_password() {
149
                return sha3_512(OIDplus::baseConfig()->getValue('SERVER_SECRET').'/VNAG');
150
        }
151
 
152
}