Subversion Repositories oidplus

Rev

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