Subversion Repositories oidplus

Rev

Rev 1020 | 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 - 2022 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. use ViaThinkSoft\OIDplus\OIDplus;
  21. use ViaThinkSoft\OIDplus\OIDplusGui;
  22.  
  23. header('Content-Type:text/html; charset=UTF-8');
  24.  
  25. require_once __DIR__ . '/includes/oidplus.inc.php';
  26.  
  27. set_exception_handler(array(OIDplusGui::class, 'html_exception_handler'));
  28.  
  29. ob_start(); // allow cookie headers to be sent
  30.  
  31. OIDplus::init(true);
  32.  
  33. $static_node_id = isset($_REQUEST['goto']) ? $_REQUEST['goto'] : 'oidplus:system';
  34.  
  35. if (isset($_REQUEST['h404'])) {
  36.         $handled = false;
  37.         $plugins = OIDplus::getPagePlugins();
  38.         foreach ($plugins as $plugin) {
  39.                 if ($plugin->handle404($_REQUEST['h404'])) $handled = true;
  40.         }
  41.         if (!$handled) {
  42.                 header('Location:'.OIDplus::webpath().'?goto='.urlencode('oidplus:err:'.$_REQUEST['h404']));
  43.                 die();
  44.         }
  45. }
  46.  
  47. $static_node_id = OIDplus::prefilterQuery($static_node_id, false);
  48.  
  49. $static = OIDplus::gui()->generateContentPage($static_node_id);
  50. $static_title = $static['title'];
  51. $static_icon = $static['icon'];
  52. $static_content = $static['text'];
  53.  
  54. if (!isset($_COOKIE['csrf_token'])) {
  55.         // This is the main CSRF token used for AJAX.
  56.         $token = OIDplus::authUtils()->genCSRFToken();
  57.         OIDplus::cookieUtils()->setcookie('csrf_token', $token, 0, false);
  58.         unset($token);
  59. }
  60.  
  61. if (!isset($_COOKIE['csrf_token_weak'])) {
  62.         // This CSRF token is created with SameSite=Lax and must be used
  63.         // for OAuth 2.0 redirects or similar purposes.
  64.         $token = OIDplus::authUtils()->genCSRFToken();
  65.         OIDplus::cookieUtils()->setcookie('csrf_token_weak', $token, 0, false, 'Lax');
  66.         unset($token);
  67. }
  68.  
  69. OIDplus::handleLangArgument();
  70.  
  71. function combine_systemtitle_and_pagetitle($systemtitle, $pagetitle) {
  72.         // Please also change the function in oidplus_base.js
  73.         if ($systemtitle == $pagetitle) {
  74.                 return $systemtitle;
  75.         } else {
  76.                 return $pagetitle . ' - ' . $systemtitle;
  77.         }
  78. }
  79.  
  80. // Get theme color (color of title bar)
  81. $design_plugin = OIDplus::getActiveDesignPlugin();
  82. $theme_color = is_null($design_plugin) ? '' : $design_plugin->getThemeColor();
  83.  
  84. $head_elems = array();
  85. $head_elems[] = '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">';
  86. $head_elems[] = '<meta name="OIDplus-SystemTitle" content="'.htmlentities(OIDplus::config()->getValue('system_title')).'">'; // Do not remove. This meta tag is acessed by oidplus_base.js
  87. if ($theme_color != '') $head_elems[] = '<meta name="theme-color" content="'.htmlentities($theme_color).'">';
  88. $head_elems[] = '<meta name="viewport" content="width=device-width, initial-scale=1.0">';
  89. $head_elems[] = '<title>'.htmlentities(combine_systemtitle_and_pagetitle(OIDplus::config()->getValue('system_title'), $static_title)).'</title>';
  90. $head_elems[] = '<script src="polyfill.min.js.php"></script>';
  91. $head_elems[] = '<script src="oidplus.min.js.php"></script>';
  92. $head_elems[] = '<link rel="stylesheet" href="oidplus.min.css.php">';
  93. $head_elems[] = '<link rel="shortcut icon" type="image/x-icon" href="favicon.ico.php">';
  94. if (OIDplus::baseConfig()->exists('CANONICAL_SYSTEM_URL')) {
  95.         $head_elems[] = '<link rel="canonical" href="'.htmlentities(OIDplus::canonicalURL()).'">';
  96. }
  97.  
  98. $plugins = OIDplus::getPagePlugins();
  99. foreach ($plugins as $plugin) {
  100.         $plugin->htmlHeaderUpdate($head_elems);
  101. }
  102.  
  103. // ---
  104.  
  105. echo "<!DOCTYPE html>\n";
  106.  
  107. echo "<html lang=\"".substr(OIDplus::getCurrentLang(),0,2)."\">\n";
  108. echo "<head>\n";
  109. echo "\t".implode("\n\t",$head_elems)."\n";
  110. echo "</head>\n";
  111.  
  112. echo "<body>\n";
  113.  
  114. echo '<div id="loading" style="display:none">Loading&#8230;</div>';
  115.  
  116. echo '<div id="frames">';
  117. echo '<div id="content_window" class="borderbox">';
  118.  
  119. echo '<h1 id="real_title">';
  120. if ($static_icon != '') echo '<img src="'.htmlentities($static_icon).'" width="48" height="48" alt=""> ';
  121. echo htmlentities($static_title).'</h1>';
  122. echo '<div id="real_content">'.$static_content.'</div>';
  123. if ((!isset($_SERVER['REQUEST_METHOD'])) || ($_SERVER['REQUEST_METHOD'] == 'GET')) {
  124.         echo '<br><p><img src="img/share.png" width="15" height="15" alt="'._L('Share').'"> <a href="?goto='.htmlentities($static_node_id).'" id="static_link" class="gray_footer_font">'._L('Static link to this page').'</a>';
  125.         echo '</p>';
  126. }
  127. echo '<br>';
  128.  
  129. echo '</div>';
  130.  
  131. echo '<div id="system_title_bar">';
  132.  
  133. echo '<div id="system_title_menu" onclick="mobileNavButtonClick(this)" onmouseenter="mobileNavButtonHover(this)" onmouseleave="mobileNavButtonHover(this)">';
  134. echo '  <div id="bar1"></div>';
  135. echo '  <div id="bar2"></div>';
  136. echo '  <div id="bar3"></div>';
  137. echo '</div>';
  138.  
  139. echo '<div id="system_title_text">';
  140. echo '  <a '.OIDplus::gui()->link('oidplus:system').' id="system_title_a">';
  141. echo '          <span id="system_title_logo"></span>';
  142. echo '          <span id="system_title_1">'.htmlentities(OIDplus::getEditionInfo()['vendor'].' OIDplus 2.0').'</span><br>';
  143. echo '          <span id="system_title_2">'.htmlentities(OIDplus::config()->getValue('system_title')).'</span>';
  144. echo '  </a>';
  145. echo '</div>';
  146.  
  147. echo '</div>';
  148.  
  149. echo OIDplus::gui()->getLanguageBox($static_node_id, true);
  150.  
  151. echo '<div id="gotobox">';
  152. echo '<input type="text" name="goto" id="gotoedit" value="'.htmlentities($static_node_id).'">';
  153. echo '<input type="button" value="'._L('Go').'" onclick="gotoButtonClicked()" id="gotobutton">';
  154. echo '</div>';
  155.  
  156. echo '<div id="oidtree" class="borderbox">';
  157. //echo '<noscript>';
  158. //echo '<p><b>'._L('Please enable JavaScript to use all features').'</b></p>';
  159. //echo '</noscript>';
  160. OIDplus::menuUtils()->nonjs_menu();
  161. echo '</div>';
  162.  
  163. echo '</div>';
  164.  
  165. echo "\n</body>\n";
  166. echo "</html>\n";
  167.  
  168. $cont = ob_get_contents();
  169. ob_end_clean();
  170.  
  171. $plugins = OIDplus::getPagePlugins();
  172. foreach ($plugins as $plugin) {
  173.         $plugin->htmlPostprocess($cont);
  174. }
  175.  
  176. OIDplus::invoke_shutdown();
  177.  
  178. echo $cont;
  179.