index.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /**
  3. * Insipid
  4. * Personal web-bookmark-system
  5. *
  6. * Copyright 2016-2023 Johannes Keßler
  7. *
  8. * Development starting from 2011: Johannes Keßler
  9. * https://www.bananas-playground.net/projekt/insipid/
  10. *
  11. * creator:
  12. * Luke Reeves <luke@neuro-tech.net>
  13. *
  14. * This program is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation, either version 3 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program. If not, see http://www.gnu.org/licenses/gpl-3.0.
  26. *
  27. */
  28. mb_http_output('UTF-8');
  29. mb_internal_encoding('UTF-8');
  30. error_reporting(-1); // E_ALL & E_STRICT
  31. require('config.php');
  32. date_default_timezone_set(TIMEZONE);
  33. ## check request
  34. $_urlToParse = filter_var($_SERVER['QUERY_STRING'],FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW);
  35. if(!empty($_urlToParse)) {
  36. # see http://de2.php.net/manual/en/regexp.reference.unicode.php
  37. if(preg_match('/[\p{C}\p{M}\p{Sc}\p{Sk}\p{So}\p{Zl}\p{Zp}]/u',$_urlToParse) === 1) {
  38. die('Malformed request. Make sure you know what you are doing.');
  39. }
  40. }
  41. ## set the error reporting
  42. ini_set('log_errors',true);
  43. if(DEBUG === true) {
  44. ini_set('display_errors',true);
  45. }
  46. else {
  47. ini_set('display_errors',false);
  48. }
  49. require('lib/summoner.class.php');
  50. require('lib/management.class.php');
  51. require('lib/tag.class.php');
  52. require('lib/category.class.php');
  53. require('lib/link.class.php');
  54. require('lib/translation.class.php');
  55. ## main vars
  56. $Summoner = new Summoner();
  57. # the template data as an array
  58. $TemplateData = array();
  59. # translation
  60. $T = new Translation();
  61. # the default view
  62. $View = 'home.php';
  63. # the default script
  64. $ViewScript = 'home.inc.php';
  65. # if the USE_PAGE_AUTH option is set
  66. if(defined("USE_PAGE_AUTH") && USE_PAGE_AUTH === true) {
  67. # very simple security check.
  68. # can/should be extended in the future.
  69. Summoner::simpleAuth();
  70. }
  71. ## DB connection
  72. $DB = new mysqli(DB_HOST, DB_USERNAME,DB_PASSWORD, DB_NAME);
  73. if ($DB->connect_errno) exit('Can not connect to MySQL Server');
  74. $DB->set_charset("utf8mb4");
  75. $DB->query("SET collation_connection = 'utf8mb4_bin'");
  76. $driver = new mysqli_driver();
  77. $driver->report_mode = MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT;;
  78. # management needs the DB object
  79. $Management = new Management($DB);
  80. if($Summoner::simpleAuthCheck() === true) {
  81. $Management->setShowPrivate(true);
  82. }
  83. if(isset($_GET['p']) && !empty($_GET['p'])) {
  84. $_requestPage = trim($_GET['p']);
  85. $_requestPage = Summoner::validate($_requestPage,'nospace') ? $_requestPage : "home";
  86. $ViewScript = $_requestPage.'.inc.php';
  87. $View = $_requestPage.'.php';
  88. }
  89. # now include the script
  90. # this sets information into $Data and can overwrite $View
  91. if(file_exists('view/'.$ViewScript)) {
  92. require 'view/'.$ViewScript;
  93. }
  94. if(!empty($TemplateData['refresh'])) {
  95. header("Location: ".$TemplateData['refresh']);
  96. exit();
  97. }
  98. # header information
  99. header('Content-type: text/html; charset=UTF-8');
  100. if($Summoner::simpleAuthCheck() === true || !empty($TemplateData['nocacheHeader'])) {
  101. header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
  102. header("Cache-Control: post-check=0, pre-check=0", false);
  103. header("Pragma: no-cache");
  104. }
  105. require 'view/_head.php';
  106. require 'view/'.$View;
  107. require 'view/_foot.php';
  108. $DB->close();
  109. # END