-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
97 lines (87 loc) · 2.75 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/**
* search for a themed filename or return distribution standard
* @param string $url relative url
* @param array $theme theme name
* @return string
*/
function view_fetch_themed_filename($url, $theme)
{
$search_pattern = array(
"/themes/{$theme}/build/",
"/"
);
foreach ($search_pattern as $pattern) {
$filename = __DIR__ . "{$pattern}{$url}";
if (file_exists($filename)) {
return str_replace("//", "/", "/ui{$pattern}{$url}");
}
}
return $url; // not found, return source
}
/**
* check if file exists, wrapper around file_exists() so services.php can define other implementation for local testing
* @param string $filename to check
* @return boolean
*/
function view_file_exists($filename)
{
return file_exists($filename);
}
/**
* return appended version string with a hash for proper caching for currently installed version
* @param string $url to make cache-safe
* @return string
*/
function view_cache_safe($url)
{
$info = stat('/usr/local/opnsense/www/index.php');
if (!empty($info['mtime'])) {
return "{$url}?v=" . substr(md5($info['mtime']), 0, 16);
}
return $url;
}
/**
* return safe HTML encoded version of input string
* @param string $text to make HTML safe
* @return string
*/
function view_html_safe($text)
{
/* gettext() embedded in JavaScript can cause syntax errors */
return str_replace("\n", ' ', htmlspecialchars($text ?? '', ENT_QUOTES | ENT_HTML401));
}
try {
$config = include __DIR__ . "/../mvc/app/config/config.php";
include __DIR__ . "/../mvc/app/config/loader.php";
$router = new OPNsense\Mvc\Router('/ui/');
$uri = str_replace('/?url=', '', $_SERVER['REQUEST_URI']);
try {
$response = $router->routeRequest($uri, [
'controller' => 'IndexController',
'action' => 'indexAction',
]);
} catch (\OPNsense\Mvc\Exceptions\DispatchException $ex) {
var_dump($ex);
exit();
// unroutable (page not found), present page not found controller
$response = $router->routeRequest('/ui/core/index/index');
}
if (!$response->isSent()) {
$headers = $response->getHeaders()->getHeaders();
foreach ($headers as $key => $header) {
if (count($headers) === 1 && strtolower($key) === 'location') {
if ($header === "/?url=$uri") {
echo 'recursive redirect to "'.$header.'" skipped</br>';
echo 'response object:</br>';
var_dump($response);
exit();
}
}
}
$response->send();
}
} catch (\Error | \Exception $e) {
error_log($e);
header('Location: /crash_reporter.php', true, 303);
}