Subversion Repositories oidplus

Rev

Rev 1278 | 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 OIDplusPageAdminVNagVersionCheck extends OIDplusPagePluginAdmin {
  27.  
  28.         /**
  29.          * @param bool $html
  30.          * @return void
  31.          * @throws OIDplusException
  32.          */
  33.         public function init(bool $html=true) {
  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.  
  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);
  49.         }
  50.  
  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) {
  60.                 if ($id == 'oidplus:vnag_version_check') {
  61.                         @set_time_limit(0);
  62.  
  63.  
  64.                         $handled = true;
  65.                         $out['title'] = _L('VNag version check');
  66.                         $out['icon']  = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png';
  67.  
  68.                         if (!OIDplus::authUtils()->isAdminLoggedIn()) {
  69.                                 throw new OIDplusHtmlException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')), $out['title'], 401);
  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);
  82.                         $cont = str_replace('%%REL_WEB_PATH%%',OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE),$cont);
  83.                         $cont = str_replace('%%ABS_LOC_PATH%%',OIDplus::localpath(__DIR__,false),$cont);
  84.                         $cont = str_replace('%%ABS_WEB_PATH%%',OIDplus::webpath(__DIR__,OIDplus::PATH_ABSOLUTE_CANONICAL),$cont);
  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()) {
  91.                                 $pubkey = trim(OIDplus::getSystemPublicKey());
  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.  
  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 {
  115.                 if (!OIDplus::authUtils()->isAdminLoggedIn()) return false;
  116.  
  117.                 if (file_exists(__DIR__.'/img/main_icon16.png')) {
  118.                         $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png';
  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.  
  132.         /**
  133.          * @param string $request
  134.          * @return array|false
  135.          */
  136.         public function tree_search(string $request) {
  137.                 return false;
  138.         }
  139.  
  140.         /**
  141.          * @return string
  142.          * @throws OIDplusException
  143.          */
  144.         public static function vnag_password(): string {
  145.                 return OIDplus::authUtils()->makeSecret('65d9f488-f4eb-11ed-b67e-3c4a92df8582');
  146.         }
  147.  
  148. }
  149.