2017-12-17 20:40:04 +00:00
|
|
|
<?php
|
2017-12-31 18:34:33 +00:00
|
|
|
/**
|
2018-04-13 05:38:16 +00:00
|
|
|
* @file index.php
|
2020-01-17 04:09:22 +00:00
|
|
|
* @created_on 2018-05-27
|
|
|
|
* @updated_on 2020-01-17
|
2017-12-31 18:34:33 +00:00
|
|
|
* @author Go Namhyeon <gnh1201@gmail.com>
|
2018-04-13 05:38:16 +00:00
|
|
|
* @brief ReasonableFramework
|
2019-06-04 06:36:02 +00:00
|
|
|
* @cvs https://github.com/gnh1201/reasonableframework
|
2019-11-15 01:39:49 +00:00
|
|
|
* @sponsor https://patreon.com/catswords (with advanced security)
|
2017-12-17 20:40:04 +00:00
|
|
|
*/
|
|
|
|
|
2018-08-24 14:49:15 +00:00
|
|
|
define("_DEF_VSPF_", true); // compatible to VSPF
|
|
|
|
define("_DEF_RSF_", true); // compatible to RSF
|
2019-05-24 07:34:04 +00:00
|
|
|
define("APP_DEVELOPMENT", false); // set the status of development
|
2020-01-28 04:39:54 +00:00
|
|
|
define("DOC_EOL", "\r\n"); // set the 'end of line'
|
2019-07-16 06:33:43 +00:00
|
|
|
define("CORS_DOMAINS", false); // common security: allow origin domains (e.g. example.org,*.example.org)
|
2020-01-28 04:39:54 +00:00
|
|
|
define("PHP_FIREWALL_REQUEST_URI", strip_tags($_SERVER['REQUEST_URI'])); // advanced security
|
|
|
|
define("PHP_FIREWALL_ACTIVATION", false); // advanced security
|
|
|
|
define("PHP_DDOS_PROTECTION", false); // advanced security
|
2019-02-19 16:17:33 +00:00
|
|
|
|
2019-10-13 13:04:34 +00:00
|
|
|
// development mode
|
2019-02-19 16:17:33 +00:00
|
|
|
if(APP_DEVELOPMENT == true) {
|
2019-05-20 08:19:05 +00:00
|
|
|
error_reporting(E_ALL);
|
2020-01-17 04:09:22 +00:00
|
|
|
@ini_set("log_errors", 1);
|
|
|
|
@ini_set("error_log", sprintf("%s/storage/sandbox/logs/error.log", getcwd()));
|
2019-07-16 06:31:43 +00:00
|
|
|
} else {
|
|
|
|
error_reporting(E_ERROR | E_PARSE);
|
2019-02-19 16:17:33 +00:00
|
|
|
}
|
2020-01-17 04:09:22 +00:00
|
|
|
@ini_set("display_errors", 1);
|
2017-12-31 18:31:24 +00:00
|
|
|
|
2019-05-23 15:18:34 +00:00
|
|
|
// CORS Security (https or http)
|
2019-07-16 06:33:43 +00:00
|
|
|
if(CORS_DOMAINS !== false) {
|
|
|
|
$domains = explode(",", CORS_DOMAINS);
|
2019-05-24 07:34:04 +00:00
|
|
|
$_origin = array_key_exists("HTTP_ORIGIN", $_SERVER) ? $_SERVER['HTTP_ORIGIN'] : "";
|
2019-05-23 15:18:34 +00:00
|
|
|
$origins = array();
|
|
|
|
if(!in_array("*", $domains)) {
|
|
|
|
foreach($domains as $domain) {
|
2019-05-23 15:35:54 +00:00
|
|
|
if(!empty($domain)) {
|
2019-05-23 16:58:50 +00:00
|
|
|
if(substr($domain, 0, 2) == "*.") { // support wildcard
|
|
|
|
$needle = substr($domain, 1);
|
|
|
|
$length = strlen($needle);
|
|
|
|
if(substr($_origin, -$length) === $needle) {
|
|
|
|
$origins[] = $_origin;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$origins[] = sprintf("https://%s", $domain);
|
|
|
|
$origins[] = sprintf("http://%s", $domain);
|
|
|
|
}
|
2019-05-23 15:35:54 +00:00
|
|
|
}
|
2019-05-23 15:18:34 +00:00
|
|
|
}
|
|
|
|
if(count($origins) > 0) {
|
|
|
|
if(in_array($_origin, $origins)) {
|
|
|
|
header(sprintf("Access-Control-Allow-Origin: %s", $_origin));
|
|
|
|
} else {
|
2019-05-23 15:22:03 +00:00
|
|
|
header(sprintf("Access-Control-Allow-Origin: %s", $origins[0]));
|
2019-05-23 15:18:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
header("Access-Control-Allow-Origin: *");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-28 04:39:54 +00:00
|
|
|
// set shared vars
|
|
|
|
$shared_vars = array();
|
2019-02-22 14:37:01 +00:00
|
|
|
|
2018-04-13 05:38:16 +00:00
|
|
|
// define system modules
|
2019-03-07 02:09:43 +00:00
|
|
|
$load_systems = array("base", "storage", "config", "security", "database", "uri", "logger");
|
2018-02-26 04:20:46 +00:00
|
|
|
|
2018-04-13 05:38:16 +00:00
|
|
|
// load system modules
|
|
|
|
foreach($load_systems as $system_name) {
|
2019-05-20 08:19:05 +00:00
|
|
|
$system_inc_file = "./system/" . $system_name . ".php";
|
|
|
|
if(file_exists($system_inc_file)) {
|
|
|
|
if($system_name == "base") {
|
|
|
|
include($system_inc_file);
|
|
|
|
register_loaded("system", $system_inc_file);
|
|
|
|
} else {
|
|
|
|
loadModule($system_name);
|
2019-05-03 04:33:40 +00:00
|
|
|
}
|
2019-05-20 08:19:05 +00:00
|
|
|
} else {
|
|
|
|
echo "ERROR: Dose not exists " . $system_inc_file;
|
|
|
|
exit;
|
|
|
|
}
|
2017-12-25 10:19:42 +00:00
|
|
|
}
|
2019-02-22 14:37:01 +00:00
|
|
|
|
|
|
|
// get config
|
2019-10-13 11:36:55 +00:00
|
|
|
$config = get_config();
|
2020-01-29 11:46:18 +00:00
|
|
|
$requests = get_requests();
|
2018-04-13 05:37:28 +00:00
|
|
|
|
2020-01-29 11:44:01 +00:00
|
|
|
// set shared vars
|
2020-01-28 04:39:54 +00:00
|
|
|
set_shared_var("dbc", get_db_connect());
|
2019-10-13 12:07:07 +00:00
|
|
|
|
2018-04-13 05:38:16 +00:00
|
|
|
// set max_execution_time
|
|
|
|
$max_execution_time = get_value_in_array("max_execution_time", $config, 0);
|
|
|
|
@ini_set("max_execution_time", $max_execution_time);
|
2020-01-28 04:39:54 +00:00
|
|
|
//@set_time_limit($max_execution_time);
|
2018-04-13 05:37:28 +00:00
|
|
|
|
2020-01-17 04:09:22 +00:00
|
|
|
// set memory limit
|
|
|
|
$memory_limit = get_value_in_array("memory_limit", $config, "");
|
|
|
|
if(!empty($memory_limit)) {
|
|
|
|
@ini_set("memory_limit", $memory_limit);
|
|
|
|
@ini_set("suhosin.memory_limit", $memory_limit);
|
|
|
|
}
|
|
|
|
|
2019-10-11 08:02:23 +00:00
|
|
|
// start session
|
|
|
|
start_isolated_session();
|
|
|
|
|
2018-12-29 04:23:07 +00:00
|
|
|
// set autoloader
|
2018-04-13 05:38:16 +00:00
|
|
|
if(!array_key_empty("enable_autoload", $config)) {
|
2019-05-20 08:19:05 +00:00
|
|
|
set_autoloader();
|
2018-04-13 05:37:28 +00:00
|
|
|
}
|
|
|
|
|
2018-04-13 05:38:16 +00:00
|
|
|
// set timezone
|
|
|
|
$default_timezone = get_value_in_array("timezone", $config, "UTC");
|
|
|
|
date_default_timezone_set($default_timezone);
|
2018-04-13 05:37:28 +00:00
|
|
|
|
2018-05-26 17:43:47 +00:00
|
|
|
// write visit log
|
|
|
|
write_visit_log();
|
|
|
|
|
2019-02-22 14:37:01 +00:00
|
|
|
// get requested route
|
2019-02-22 14:35:58 +00:00
|
|
|
$route = read_route();
|
2018-04-13 05:37:28 +00:00
|
|
|
|
2020-01-28 04:39:54 +00:00
|
|
|
// advanced security: PHP firewall
|
2019-07-16 06:40:57 +00:00
|
|
|
if(PHP_FIREWALL_ACTIVATION !== false) {
|
|
|
|
loadHelper("php-firewall.lnk");
|
|
|
|
}
|
|
|
|
|
2020-01-28 04:39:54 +00:00
|
|
|
// advanced security: DDOS protection
|
2019-11-15 02:12:21 +00:00
|
|
|
if(PHP_DDOS_PROTECTION !== false) {
|
2019-07-16 06:40:57 +00:00
|
|
|
loadHelper("php-ddos.lnk");
|
|
|
|
}
|
|
|
|
|
2020-01-28 04:39:54 +00:00
|
|
|
// load route
|
|
|
|
if(!loadRoute($route, $shared_vars)) {
|
|
|
|
loadRoute("errors/404", $shared_vars);
|
2018-04-13 05:37:28 +00:00
|
|
|
}
|
2019-11-15 01:47:41 +00:00
|
|
|
|
|
|
|
// EOF
|