reasonableframework/route/webapp.php

104 lines
2.5 KiB
PHP
Raw Normal View History

2019-02-22 18:15:06 +00:00
<?php
2019-02-22 21:37:33 +00:00
/**
* @file webapp.php
* @date 2019-02-23
2022-11-25 14:15:20 +00:00
* @author Go Namhyeon <abuse@catswords.net>
2019-04-01 02:12:23 +00:00
* @brief Isolator(Compatibility mode) for legacy application
2019-02-22 21:37:33 +00:00
*/
2019-02-22 21:49:43 +00:00
loadHelper("isemail.lnk");
2019-02-22 20:07:04 +00:00
if(!defined("_DEF_RSF_")) set_error_exit("do not allow access");
2019-02-22 21:37:33 +00:00
// Protect GET method
foreach($_GET as $k=>$v) {
2019-05-20 08:19:05 +00:00
$_GET[$k] = get_requested_value($k, "_GET");
2019-02-22 21:37:33 +00:00
}
// Protect POST method
foreach($_POST as $k=>$v) {
2019-05-20 08:19:05 +00:00
$_POST[$k] = get_requested_value($k, "_POST");
2019-02-22 21:37:33 +00:00
}
// Protect REQUEST(ALL) method
foreach($_REQUEST as $k=>$v) {
2019-05-20 08:19:05 +00:00
$_REQUEST[$k] = get_requested_value($k, "_ALL");
2019-02-22 21:37:33 +00:00
}
2019-02-22 22:36:14 +00:00
// get self filename
$self_filename = "";
2019-02-22 21:49:43 +00:00
2019-02-22 21:37:33 +00:00
// get routes
2019-02-22 18:15:06 +00:00
$routes = read_route_all();
2019-02-22 21:37:33 +00:00
// set path and URL
2019-03-07 16:37:13 +00:00
$webapp_root = $_SERVER["DOCUMENT_ROOT"] . "/webapp";
2019-02-22 21:37:33 +00:00
$webapp_url = base_url() . "webapp";
// set DOCUMENT_ROOT forcely
$_SERVER["DOCUMENT_ROOT"] = $webapp_root;
// set file path
$appfile = $webapp_root . "/" . implode("/", $routes);
2019-03-07 16:37:13 +00:00
2019-02-22 21:37:33 +00:00
$appfile_path = $appfile . ".php";
// get end of routes
$is_static_file = false;
$is_redirect_to_index = false;
$end_route = end($routes);
$end_routes_attributes = explode(".", $end_route);
2019-02-22 22:36:14 +00:00
$end_fra = $end_routes_attributes[0];
2019-02-22 21:37:33 +00:00
$end_era = end($end_routes_attributes);
if($end_era == "php" || file_exists($appfile_path)) {
2019-05-20 08:19:05 +00:00
$appfile_path = str_replace(".php.php", ".php", $appfile_path);
if(file_exists($appfile_path)) {
include($appfile_path);
$self_filename = $end_fra . ".php";
} else {
set_error("Webapp 404 Not Found");
show_errors();
}
2019-02-22 20:07:04 +00:00
} else {
2019-05-20 08:19:05 +00:00
if(file_exists($appfile . "/index.php")) {
$appfile .= "/index.php";
if(empty($end_era)) {
include($appfile);
} else {
$is_redirect_to_index = true;
}
} elseif(file_exists($appfile . "/index.html")) {
$is_static_file = true;
$appfile .= "/index.html";
if(empty($end_era)) {
$end_era = "html";
} else {
$is_redirect_to_index = true;
}
} else {
$is_static_file = true;
}
2019-02-22 21:37:33 +00:00
}
2019-02-22 20:30:35 +00:00
2019-02-22 21:37:33 +00:00
if($is_redirect_to_index == true) {
2019-05-20 08:19:05 +00:00
redirect_uri(base_url() . implode("/", $routes) . "/");
exit;
2019-02-22 21:37:33 +00:00
}
if($is_static_file == true) {
2019-05-20 08:19:05 +00:00
if(file_exists($appfile)) {
set_header_content_type($end_era);
header("Cache-Control: max-age=86400");
$fp = fopen($appfile, "r") or die("404 Not Found");
while(!feof($fp)) {
echo fread($fp, 8192);
}
fclose($fp);
} else {
set_error("404 Not Found");
show_errors();
}
2019-02-22 18:15:06 +00:00
}