index.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /**
  3. * Insipid
  4. * Personal web-bookmark-system
  5. *
  6. * Copyright 2016-2019 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. ini_set('error_reporting',-1); // E_ALL & E_STRICT
  31. # time settings
  32. date_default_timezone_set('Europe/Berlin');
  33. define('DEBUG',false);
  34. ## check request
  35. $_urlToParse = filter_var($_SERVER['QUERY_STRING'],FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
  36. if(!empty($_urlToParse)) {
  37. # see http://de2.php.net/manual/en/regexp.reference.unicode.php
  38. if(preg_match('/[\p{C}\p{M}\p{Sc}\p{Sk}\p{So}\p{Zl}\p{Zp}]/u',$_urlToParse) === 1) {
  39. die('Malformed request. Make sure you know what you are doing.');
  40. }
  41. }
  42. ## set the error reporting
  43. ini_set('log_errors',true);
  44. ini_set('error_log','error.log');
  45. if(DEBUG === true) {
  46. ini_set('display_errors',true);
  47. }
  48. else {
  49. ini_set('display_errors',false);
  50. }
  51. require('config.php');
  52. require('lib/summoner.class.php');
  53. require('lib/management.class.php');
  54. require('lib/tag.class.php');
  55. require('lib/category.class.php');
  56. require('lib/link.class.php');
  57. ## main vars
  58. $Summoner = new Summoner();
  59. # database object
  60. $DB = false;
  61. # the template data as an array
  62. $TemplateData = array();
  63. # the default view
  64. $View = 'home.php';
  65. # the default script
  66. $ViewScript = 'home.inc.php';
  67. # if the USE_PAGE_AUTH option is set
  68. if(defined("USE_PAGE_AUTH") && USE_PAGE_AUTH === true) {
  69. # very simple security check.
  70. # can/should be extended in the future.
  71. Summoner::simpleAuth();
  72. }
  73. ## DB connection
  74. $DB = new mysqli(DB_HOST, DB_USERNAME,DB_PASSWORD, DB_NAME);
  75. if ($DB->connect_errno) exit('Can not connect to MySQL Server');
  76. $DB->set_charset("utf8mb4");
  77. $DB->query("SET collation_connection = 'utf8mb4_bin'");
  78. $driver = new mysqli_driver();
  79. $driver->report_mode = MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT;;
  80. # management needs the DB object
  81. $Management = new Management($DB);
  82. if($Summoner::simpleAuthCheck() === true) {
  83. $Management->setShowPrivate(true);
  84. }
  85. if(isset($_GET['p']) && !empty($_GET['p'])) {
  86. $_requestPage = trim($_GET['p']);
  87. $_requestPage = Summoner::validate($_requestPage,'nospace') ? $_requestPage : "home";
  88. $ViewScript = $_requestPage.'.inc.php';
  89. $View = $_requestPage.'.php';
  90. }
  91. # now include the script
  92. # this sets information into $Data and can overwrite $View
  93. if(file_exists('view/'.$ViewScript)) {
  94. require 'view/'.$ViewScript;
  95. }
  96. if(!empty($TemplateData['refresh'])) {
  97. header("Location: ".$TemplateData['refresh']);
  98. }
  99. # header information
  100. header('Content-type: text/html; charset=UTF-8');
  101. require 'view/_head.php';
  102. require 'view/'.$View;
  103. require 'view/_foot.php';
  104. $DB->close();
  105. # END