index.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * scientia
  4. *
  5. * Copyright 2023 - 2024 Johannes Keßler
  6. *
  7. * https://www.bananas-playground.net/projekt/scientia/
  8. *
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
  12. *
  13. * You should have received a copy of the
  14. * COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
  15. * along with this program. If not, see http://www.sun.com/cddl/cddl.html
  16. */
  17. mb_http_output('UTF-8');
  18. mb_internal_encoding('UTF-8');
  19. ini_set('error_reporting',-1); // E_ALL & E_STRICT
  20. ## check request
  21. $_urlToParse = filter_var($_SERVER['QUERY_STRING'],FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW);
  22. if(!empty($_urlToParse)) {
  23. # see http://de2.php.net/manual/en/regexp.reference.unicode.php
  24. if(preg_match('/[\p{C}\p{M}\p{Sc}\p{Sk}\p{So}\p{Zl}\p{Zp}]/u',$_urlToParse) === 1) {
  25. die('Malformed request. Make sure you know what you are doing.');
  26. }
  27. }
  28. ## config
  29. require_once('config/config.php');
  30. ## set the error reporting
  31. ini_set('log_errors',true);
  32. ini_set('error_log',PATH_SYSTEMOUT.'/error.log');
  33. if(DEBUG === true) {
  34. ini_set('display_errors',true);
  35. }
  36. else {
  37. ini_set('display_errors',false);
  38. }
  39. # time settings
  40. date_default_timezone_set(TIMEZONE);
  41. # required libs
  42. require_once('lib/summoner.class.php');
  43. require_once('lib/i18n.class.php');
  44. Summoner::simpleAuth();
  45. # i18n
  46. $i18n = new I18n();
  47. ## DB connection
  48. $DB = new mysqli(DB_HOST, DB_USERNAME,DB_PASSWORD, DB_NAME);
  49. if ($DB->connect_errno) exit('Can not connect to MySQL Server');
  50. $DB->set_charset("utf8mb4");
  51. $DB->query("SET collation_connection = 'utf8mb4_bin'");
  52. $driver = new mysqli_driver();
  53. $driver->report_mode = MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT;
  54. # default values
  55. $_view = 'list';
  56. $_year = date('Y');
  57. $_month = date('m');
  58. $_day = date('d');
  59. $_id = '';
  60. $_requestDateProvided = '';
  61. $TemplateData = array();
  62. if(isset($_GET['y']) && Summoner::validate($_GET['y'], 'digit')) {
  63. $_year = trim($_GET['y']);
  64. $_requestDateProvided .= 'Y';
  65. }
  66. if(isset($_GET['m']) && Summoner::validate($_GET['m'], 'digit')) {
  67. $_month = trim($_GET['m']);
  68. $_requestDateProvided .= '-m';
  69. }
  70. if(isset($_GET['d']) && Summoner::validate($_GET['d'], 'digit')) {
  71. $_day = trim($_GET['d']);
  72. $_requestDateProvided .= '-d';
  73. }
  74. if(isset($_GET['p']) && Summoner::validate($_GET['p'], 'nospace') && $_GET['p'] == "new") {
  75. $_view = 'entry';
  76. }
  77. if(isset($_GET['id']) && Summoner::validate($_GET['id'], 'shortlink',4)) {
  78. $_id = trim($_GET['id']);
  79. $_view = 'entry';
  80. }
  81. require_once 'view/'.$_view.'/'.$_view.'.php';
  82. # header information
  83. header('Content-type: text/html; charset=UTF-8');
  84. header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
  85. header("Cache-Control: post-check=0, pre-check=0", false);
  86. header("Pragma: no-cache");
  87. if(isset($TemplateData['refresh']) && !empty($TemplateData['refresh'])) {
  88. header('Location: '.PATH_WEBROOT.$TemplateData['refresh']);
  89. exit();
  90. }
  91. require_once 'view/_head.php';
  92. require_once 'view/'.$_view.'/'.$_view.'.html';
  93. require_once 'view/_foot.php';
  94. $DB->close();