-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
58 lines (50 loc) · 1.54 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
declare(strict_types=1);
namespace OpcachePanel;
use OpcachePanel\Exception\ApiException;
require __DIR__ . '/vendor/autoload.php';
header(NO_CACHE_HEADER);
if (!extension_loaded('Zend OPcache')) {
echo 'Zend OPcache extension is not loaded.';
exit;
}
if (@opcache_get_configuration() === false) {
echo '<p>opcache_get_configuration () function error, check <a href="https://www.php.net/manual/opcache.configuration.php#ini.opcache.restrict-api">opcache.restrict_api</a> configuration items.</p>';
exit;
}
if (file_exists(CONFIG_FILE)) {
@opcache_invalidate(CONFIG_FILE);
require CONFIG_FILE;
}
if (!defined('OPP_DEBUG') || OPP_DEBUG !== true) {
$auth = new Auth();
$auth->logout();
if ($auth->isNeedAuth()) {
$auth->login();
$auth->isAuth();
}
}
$method = strtoupper($_SERVER['REQUEST_METHOD']);
if ($method === 'GET' || $method === 'HEAD') {
require APP_DIR.'/html/main.php';
} elseif ($method === 'POST') {
foreach (AUTH_POST_KEY as $value) {
if (array_key_exists($value, $_POST)) {
require APP_DIR.'/html/main.php';
exit();
}
}
$postData = json_decode(file_get_contents('php://input'), true, 512);
if (json_last_error() !== JSON_ERROR_NONE) {
Helper::errorResult(400, 'POST body not is JSON');
}
try {
$result = API::Run($postData);
header(MIME_JSON);
echo $result;
} catch (ApiException $e) {
Helper::errorResult($e->getCode(), $e->getMessage());
}
} else {
http_response_code(405);
}