-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
82 lines (60 loc) · 2 KB
/
Copy pathindex.php
File metadata and controls
82 lines (60 loc) · 2 KB
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
<?php
// Application entrypoint. Can serve as a catch-all for running the
// builtin PHP webserver, with the bundled .htaccess file in production.
$_ENV = getenv("ENV") ?: 'prod';
$_NOW = hrtime(true);
ob_start();
if($_ENV == 'dev') {
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
}
require_once __DIR__ . "/core.php";
require_once __DIR__ . "/router.php";
$_SHARED = route('^/shared/([a-f0-9]{64})\.ics$');
$_MCP = route('^/mcp/([a-f0-9]{64})$');
$_PUBLIC = route('^/\.well-known/oauth') || $path == "/register";
if(!$_SHARED && !$_MCP && !$_PUBLIC) {
require_once __DIR__ . "/auth.php";
}
$requested_file = path_join(__DIR__, "public", $path);
if(is_file($requested_file) and is_builtin()) {
// Serve file as-is. Only applies to the development server,
// in production this will be handled by Apache directly.
serve_file($requested_file);
}
if(!is_https() and FORCE_HTTPS) {
http_response_code(301);
header("Location: https://" . HOST . $_SERVER['REQUEST_URI']);
exit;
}
if($_PUBLIC) fail("Not found.", status: 404);
$deferred_requests = ['/notes/sync'];
if(!in_array($method, ['GET', 'HEAD', 'OPTIONS', 'PROPFIND', 'REPORT'])
&& !in_array($path, $deferred_requests)) {
begin_request();
}
// TODO(robin): improve this routing
if($_SHARED) {
include __DIR__ . "/app/shared.php"; exit;
}
if($_MCP) {
include __DIR__ . "/app/mcp.php"; exit;
}
if($path == "/caldav" || str_starts_with($path, "/caldav/")) {
include __DIR__ . "/app/caldav.php"; exit;
}
if($path == "/carddav" || str_starts_with($path, "/carddav/")) {
include __DIR__ . "/app/carddav.php"; exit;
}
if($path == "/") $path = "/" . UI_DEFAULT_APPLICATION;
$controller = path_join(__DIR__, "app", "$path.php");
if(file_exists($controller)) {
include $controller; exit;
}
$controller = path_join(__DIR__, "app", $path, "index.php");
if(file_exists($controller)) {
include $controller; exit;
}
// If no response has been served yet, the requested resource
// does not exist.
fail("Not found.", status: 404);