Subversion Repositories oidplus

Rev

Rev 1278 | 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) {
1278 daniel-mar 60
                if ($id == 'oidplus:vnag_version_check') {
635 daniel-mar 61
                        @set_time_limit(0);
62
 
63
 
64
                        $handled = true;
65
                        $out['title'] = _L('VNag version check');
801 daniel-mar 66
                        $out['icon']  = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png';
635 daniel-mar 67
 
68
                        if (!OIDplus::authUtils()->isAdminLoggedIn()) {
1266 daniel-mar 69
                                throw new OIDplusHtmlException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')), $out['title'], 401);
635 daniel-mar 70
                        }
71
 
72
                        if (file_exists(__DIR__ . '/tutorial$'.OIDplus::getCurrentLang().'.html')) {
73
                                $cont = file_get_contents(__DIR__ . '/tutorial$'.OIDplus::getCurrentLang().'.html');
74
                        } else if (file_exists(__DIR__ . '/tutorial.html')) {
75
                                $cont = file_get_contents(__DIR__ . '/tutorial.html');
76
                        } else {
77
                                $cont = '';
78
                        }
79
 
80
                        $cont = str_replace('%%SYSTEM_URL%%',OIDplus::localpath(),$cont);
81
                        $cont = str_replace('%%REL_LOC_PATH%%',OIDplus::localpath(__DIR__,true),$cont);
801 daniel-mar 82
                        $cont = str_replace('%%REL_WEB_PATH%%',OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE),$cont);
635 daniel-mar 83
                        $cont = str_replace('%%ABS_LOC_PATH%%',OIDplus::localpath(__DIR__,false),$cont);
801 daniel-mar 84
                        $cont = str_replace('%%ABS_WEB_PATH%%',OIDplus::webpath(__DIR__,OIDplus::PATH_ABSOLUTE_CANONICAL),$cont);
635 daniel-mar 85
                        if (OIDplus::config()->getValue('vnag_version_check_password_protected','1') == '1') {
86
                                $cont = str_replace('%%WEBREADER_PASSWORD%%',self::vnag_password(),$cont);
87
                        } else {
88
                                $cont = str_replace('%%WEBREADER_PASSWORD%%','',$cont);
89
                        }
90
                        if (OIDplus::getPkiStatus()) {
830 daniel-mar 91
                                $pubkey = trim(OIDplus::getSystemPublicKey());
635 daniel-mar 92
                                $pubkey = str_replace("\\","\\\\",$pubkey);
93
                                $pubkey = str_replace("\r","\\r",$pubkey);
94
                                $pubkey = str_replace("\n","\\n",$pubkey);
95
                        } else {
96
                                $pubkey = "";
97
                        }
98
                        $cont = str_replace('%%WEBREADER_PUBKEY%%',$pubkey,$cont);
99
 
100
                        $out['text'] .= $cont;
101
                } else {
102
                        $handled = false;
103
                }
104
        }
105
 
1116 daniel-mar 106
        /**
107
         * @param array $json
108
         * @param string|null $ra_email
109
         * @param bool $nonjs
110
         * @param string $req_goto
111
         * @return bool
112
         * @throws OIDplusException
113
         */
114
        public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool {
635 daniel-mar 115
                if (!OIDplus::authUtils()->isAdminLoggedIn()) return false;
116
 
800 daniel-mar 117
                if (file_exists(__DIR__.'/img/main_icon16.png')) {
801 daniel-mar 118
                        $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png';
635 daniel-mar 119
                } else {
120
                        $tree_icon = null; // default icon (folder)
121
                }
122
 
123
                $json[] = array(
124
                        'id' => 'oidplus:vnag_version_check',
125
                        'icon' => $tree_icon,
126
                        'text' => _L('VNag version check')
127
                );
128
 
129
                return true;
130
        }
131
 
1116 daniel-mar 132
        /**
133
         * @param string $request
134
         * @return array|false
135
         */
136
        public function tree_search(string $request) {
635 daniel-mar 137
                return false;
138
        }
139
 
1116 daniel-mar 140
        /**
141
         * @return string
142
         * @throws OIDplusException
143
         */
1130 daniel-mar 144
        public static function vnag_password(): string {
1282 daniel-mar 145
                return OIDplus::authUtils()->makeSecret('65d9f488-f4eb-11ed-b67e-3c4a92df8582');
635 daniel-mar 146
        }
147
 
148
}