Some more functionalities
This commit is contained in:
43
index.php
43
index.php
@@ -10,6 +10,10 @@ function getWebRoot() {
|
||||
return dirname(__FILE__);
|
||||
}
|
||||
|
||||
function createError($msg) {
|
||||
return json_encode(array("success" => false, "msg" => $msg));
|
||||
}
|
||||
|
||||
spl_autoload_extensions(".php");
|
||||
spl_autoload_register(function($class) {
|
||||
$full_path = getClassPath($class);
|
||||
@@ -27,11 +31,42 @@ $config = new Configuration\Configuration();
|
||||
$installation = (!$config->load());
|
||||
$user = new Objects\User($config);
|
||||
|
||||
if ($installation) {
|
||||
$document = new Documents\Install($user);
|
||||
if(isset($_GET["api"]) && is_string($_GET["api"])) {
|
||||
header("Content-Type: application/json");
|
||||
if($installation) {
|
||||
$response = createError("Not installed");
|
||||
} else {
|
||||
$apiFunction = $_GET["api"];
|
||||
if(empty($apiFunction)) {
|
||||
header("403 Forbidden");
|
||||
$response = "";
|
||||
} else if(!preg_match("/[a-zA-Z]+(\/[a-zA-Z]+)*/", $apiFunction)) {
|
||||
$response = createError("Invalid Method");
|
||||
} else {
|
||||
$apiFunction = strtoupper($apiFunction[0]) . substr($apiFunction, 1);
|
||||
$class = "\\Api\\$apiFunction";
|
||||
$file = getClassPath($class);
|
||||
if(!file_exists($file)) {
|
||||
header("404 Not Found");
|
||||
$response = createError("Not found");
|
||||
} else {
|
||||
$request = new $class($user, true);
|
||||
$success = $request->execute();
|
||||
$msg = $request->getLastError();
|
||||
$response = $request->getJsonResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
print("DON'T INSTALL");
|
||||
if ($installation) {
|
||||
$document = new Documents\Install($user);
|
||||
} else {
|
||||
$document = new Documents\Admin($user);
|
||||
}
|
||||
|
||||
$response = $document->getCode();
|
||||
}
|
||||
|
||||
die($document->getCode());
|
||||
$user->sendCookies();
|
||||
die($response);
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user