Subversion Repositories oidplus

Rev

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