Subversion Repositories oidplus

Rev

Rev 1116 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. /*
  4.  * OIDplus 2.0
  5.  * Copyright 2019 - 2023 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.  
  20. namespace ViaThinkSoft\OIDplus;
  21.  
  22. // phpcs:disable PSR1.Files.SideEffects
  23. \defined('INSIDE_OIDPLUS') or die;
  24. // phpcs:enable PSR1.Files.SideEffects
  25.  
  26. class OIDplusPageAdminOOBE extends OIDplusPagePluginAdmin {
  27.  
  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) {
  35.                 // Nothing
  36.         }
  37.  
  38.         /**
  39.          * @return bool
  40.          * @throws OIDplusException
  41.          */
  42.         public function oobeRequired(): bool {
  43.                 $oobe_done = OIDplus::config()->getValue('oobe_main_done') == '1';
  44.  
  45.                 foreach (OIDplus::getAllPlugins() as $plugin) {
  46.                         if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_1) {
  47.                                 if ($plugin->oobeRequested()) {
  48.                                         $oobe_done = false;
  49.                                         break;
  50.                                 }
  51.                         }
  52.                 }
  53.  
  54.                 return !$oobe_done;
  55.         }
  56.  
  57.         /**
  58.          * @param bool $html
  59.          * @return void
  60.          * @throws OIDplusException
  61.          */
  62.         public function init(bool $html=true) {
  63.                 OIDplus::config()->delete('reg_wizard_done'); // deprecated name
  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) {
  68.                                 // Show registration/configuration wizard once
  69.                                 if (basename($_SERVER['SCRIPT_NAME']) != 'oobe.php') {
  70.                                         header('Location:'.OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'oobe.php');
  71.                                         die(_L('Redirecting to Out-Of-Box-Experience wizard...'));
  72.                                 }
  73.                         } else {
  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.  
  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.  
  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 {
  105.                 return true;
  106.         }
  107.  
  108.         /**
  109.          * @param string $request
  110.          * @return array|false
  111.          */
  112.         public function tree_search(string $request) {
  113.                 return false;
  114.         }
  115. }
  116.