Rev 1206 | 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) { |
||
1183 | daniel-mar | 60 | $parts = explode('$',$id,2); |
635 | daniel-mar | 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()) { |
||
1266 | daniel-mar | 71 | 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 | 72 | } |
73 | |||
74 | if (file_exists(__DIR__ . '/tutorial$'.OIDplus::getCurrentLang().'.html')) { |
||
75 | $cont = file_get_contents(__DIR__ . '/tutorial$'.OIDplus::getCurrentLang().'.html'); |
||
76 | } else if (file_exists(__DIR__ . '/tutorial.html')) { |
||
77 | $cont = file_get_contents(__DIR__ . '/tutorial.html'); |
||
78 | } else { |
||
79 | $cont = ''; |
||
80 | } |
||
81 | |||
82 | $cont = str_replace('%%SYSTEM_URL%%',OIDplus::localpath(),$cont); |
||
83 | $cont = str_replace('%%REL_LOC_PATH%%',OIDplus::localpath(__DIR__,true),$cont); |
||
801 | daniel-mar | 84 | $cont = str_replace('%%REL_WEB_PATH%%',OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE),$cont); |
635 | daniel-mar | 85 | $cont = str_replace('%%ABS_LOC_PATH%%',OIDplus::localpath(__DIR__,false),$cont); |
801 | daniel-mar | 86 | $cont = str_replace('%%ABS_WEB_PATH%%',OIDplus::webpath(__DIR__,OIDplus::PATH_ABSOLUTE_CANONICAL),$cont); |
635 | daniel-mar | 87 | if (OIDplus::config()->getValue('vnag_version_check_password_protected','1') == '1') { |
88 | $cont = str_replace('%%WEBREADER_PASSWORD%%',self::vnag_password(),$cont); |
||
89 | } else { |
||
90 | $cont = str_replace('%%WEBREADER_PASSWORD%%','',$cont); |
||
91 | } |
||
92 | if (OIDplus::getPkiStatus()) { |
||
830 | daniel-mar | 93 | $pubkey = trim(OIDplus::getSystemPublicKey()); |
635 | daniel-mar | 94 | $pubkey = str_replace("\\","\\\\",$pubkey); |
95 | $pubkey = str_replace("\r","\\r",$pubkey); |
||
96 | $pubkey = str_replace("\n","\\n",$pubkey); |
||
97 | } else { |
||
98 | $pubkey = ""; |
||
99 | } |
||
100 | $cont = str_replace('%%WEBREADER_PUBKEY%%',$pubkey,$cont); |
||
101 | |||
102 | $out['text'] .= $cont; |
||
103 | } else { |
||
104 | $handled = false; |
||
105 | } |
||
106 | } |
||
107 | |||
1116 | daniel-mar | 108 | /** |
109 | * @param array $json |
||
110 | * @param string|null $ra_email |
||
111 | * @param bool $nonjs |
||
112 | * @param string $req_goto |
||
113 | * @return bool |
||
114 | * @throws OIDplusException |
||
115 | */ |
||
116 | public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool { |
||
635 | daniel-mar | 117 | if (!OIDplus::authUtils()->isAdminLoggedIn()) return false; |
118 | |||
800 | daniel-mar | 119 | if (file_exists(__DIR__.'/img/main_icon16.png')) { |
801 | daniel-mar | 120 | $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png'; |
635 | daniel-mar | 121 | } else { |
122 | $tree_icon = null; // default icon (folder) |
||
123 | } |
||
124 | |||
125 | $json[] = array( |
||
126 | 'id' => 'oidplus:vnag_version_check', |
||
127 | 'icon' => $tree_icon, |
||
128 | 'text' => _L('VNag version check') |
||
129 | ); |
||
130 | |||
131 | return true; |
||
132 | } |
||
133 | |||
1116 | daniel-mar | 134 | /** |
135 | * @param string $request |
||
136 | * @return array|false |
||
137 | */ |
||
138 | public function tree_search(string $request) { |
||
635 | daniel-mar | 139 | return false; |
140 | } |
||
141 | |||
1116 | daniel-mar | 142 | /** |
143 | * @return string |
||
144 | * @throws OIDplusException |
||
145 | */ |
||
1130 | daniel-mar | 146 | public static function vnag_password(): string { |
635 | daniel-mar | 147 | return sha3_512(OIDplus::baseConfig()->getValue('SERVER_SECRET').'/VNAG'); |
148 | } |
||
149 | |||
150 | } |