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 |
||
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 OIDplusPageAdminOOBE extends OIDplusPagePluginAdmin { |
27 | |||
1116 | daniel-mar | 28 | /** |
29 | * @param string $id |
||
30 | * @param array $out |
||
31 | * @param bool $handled |
||
32 | * @return void |
||
33 | */ |
||
34 | public function gui(string $id, array &$out, bool &$handled) { |
||
635 | daniel-mar | 35 | // Nothing |
36 | } |
||
37 | |||
1116 | daniel-mar | 38 | /** |
39 | * @return bool |
||
40 | * @throws OIDplusException |
||
41 | */ |
||
42 | public function oobeRequired(): bool { |
||
635 | daniel-mar | 43 | $oobe_done = OIDplus::config()->getValue('oobe_main_done') == '1'; |
44 | |||
1005 | daniel-mar | 45 | foreach (OIDplus::getAllPlugins() as $plugin) { |
635 | daniel-mar | 46 | if ($plugin->implementsFeature('1.3.6.1.4.1.37476.2.5.2.3.1')) { |
1116 | daniel-mar | 47 | if ($plugin->oobeRequested()) { /** @phpstan-ignore-line */ |
635 | daniel-mar | 48 | $oobe_done = false; |
49 | break; |
||
50 | } |
||
51 | } |
||
52 | } |
||
53 | |||
54 | return !$oobe_done; |
||
55 | } |
||
56 | |||
1116 | daniel-mar | 57 | /** |
58 | * @param bool $html |
||
59 | * @return void |
||
60 | * @throws OIDplusException |
||
61 | */ |
||
62 | public function init(bool $html=true) { |
||
1029 | daniel-mar | 63 | OIDplus::config()->delete('reg_wizard_done'); // deprecated name |
635 | daniel-mar | 64 | OIDplus::config()->prepareConfigKey('oobe_main_done', '"Out Of Box Experience" wizard for the system settings done once?', '0', OIDplusConfig::PROTECTION_HIDDEN, function($value) {}); |
65 | |||
66 | if ($this->oobeRequired()) { |
||
67 | if ($html) { |
||
1029 | daniel-mar | 68 | // Show registration/configuration wizard once |
635 | daniel-mar | 69 | if (basename($_SERVER['SCRIPT_NAME']) != 'oobe.php') { |
801 | daniel-mar | 70 | header('Location:'.OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'oobe.php'); |
635 | daniel-mar | 71 | die(_L('Redirecting to Out-Of-Box-Experience wizard...')); |
72 | } |
||
73 | } else { |
||
1029 | daniel-mar | 74 | // In the OOBE, "get_challenge" of the ViaThinkSoft Captcha will raise the error: |
75 | // "A plugin has requested that the initialization wizard (OOBE) is shown. Please reload the page." |
||
76 | // So we must not continue if the referrer is OOBE. |
||
77 | if (isset($_SERVER['HTTP_REFERER']) && (strpos($_SERVER['HTTP_REFERER'],'050_oobe/oobe.php') !== false)) return; |
||
78 | |||
79 | // This is another very special case... |
||
80 | // When the Registration OOBE is saved, the 'reg_privacy" setting will be |
||
81 | // set, which will call the ViaThinkSoft server. The ViaThinkSoft server |
||
82 | // then calls the "verify pubkey" action, but this fails because |
||
83 | // the system is still in OOBE mode! |
||
84 | if (basename($_SERVER['SCRIPT_NAME']) == 'ajax.php') { |
||
85 | $req = array_merge($_POST,$_GET); |
||
86 | if (($req['plugin'] == '1.3.6.1.4.1.37476.2.5.2.4.3.120') && ($req['action'] = 'verify_pubkey')) { |
||
87 | return; |
||
88 | } |
||
89 | } |
||
90 | |||
635 | daniel-mar | 91 | // We cannot guarantee that everything works correctly if OOBE never ran once. So abort AJAX and co. |
92 | throw new OIDplusException(_L('A plugin has requested that the initialization wizard (OOBE) is shown. Please reload the page.')); |
||
93 | } |
||
94 | } |
||
95 | } |
||
96 | |||
1116 | daniel-mar | 97 | /** |
98 | * @param array $json |
||
99 | * @param string|null $ra_email |
||
100 | * @param bool $nonjs |
||
101 | * @param string $req_goto |
||
102 | * @return bool |
||
103 | */ |
||
104 | public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool { |
||
635 | daniel-mar | 105 | return true; |
106 | } |
||
107 | |||
1116 | daniel-mar | 108 | /** |
109 | * @param string $request |
||
110 | * @return array|false |
||
111 | */ |
||
112 | public function tree_search(string $request) { |
||
635 | daniel-mar | 113 | return false; |
114 | } |
||
115 | } |