forked from agentejo/cockpit
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
58 lines (43 loc) · 1.61 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
<?php
define('COCKPIT_ADMIN', 1);
// set default url rewrite setting
if (!isset($_SERVER['COCKPIT_URL_REWRITE'])) {
$_SERVER['COCKPIT_URL_REWRITE'] = 'Off';
}
// set default timezone
date_default_timezone_set('UTC');
// handle php webserver
if (PHP_SAPI == 'cli-server' && is_file(__DIR__.parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))) {
return false;
}
// bootstrap cockpit
require(__DIR__.'/bootstrap.php');
// handle error pages
$cockpit->on("after", function() {
switch ($this->response->status) {
case 500:
if ($this['debug']) {
if ($this->req_is('ajax')) {
$this->response->body = json_encode(['error' => json_decode($this->response->body, true)]);
} else {
$this->response->body = $this->render("cockpit:views/errors/500-debug.php", ['error' => json_decode($this->response->body, true)]);
}
} else {
if ($this->req_is('ajax')) {
$this->response->body = '{"error": "500", "message": "system error"}';
} else {
$this->response->body = $this->view("cockpit:views/errors/500.php");
}
}
break;
case 404:
if ($this->req_is('ajax')) {
$this->response->body = '{"error": "404", "message":"File not found"}';
} else {
$this->response->body = $this->view("cockpit:views/errors/404.php");
}
break;
}
});
// run backend
$cockpit->set('route', COCKPIT_ADMIN_ROUTE)->trigger("admin.init")->run();