36 lines
929 B
PHP
36 lines
929 B
PHP
<?php
|
|
require 'config/application.php';
|
|
|
|
if (!isset($_COOKIE['_session']) || !file_exists('/tmp/apcontrol-sessions')) {
|
|
if (substr($_SERVER['REQUEST_URI'],0,5) === '/api/') {
|
|
http_response_code(403); die('<h3>403, API Forbidden</h3>');
|
|
}
|
|
header('Location: login.php'); die;
|
|
}
|
|
|
|
$session = trim($_COOKIE['_session']);
|
|
$sessions = explode("\n", trim(file_get_contents('/tmp/apcontrol-sessions')));
|
|
if (!in_array($session, $sessions)) {
|
|
if (substr($_SERVER['REQUEST_URI'],0,5) === '/api/') {
|
|
http_response_code(403); die('<h3>403, API Forbidden</h3>');
|
|
}
|
|
header('Location: login.php'); die;
|
|
}
|
|
unset($sessions);
|
|
|
|
if (!file_exists($appconf['data_dir']))
|
|
mkdir($appconf['data_dir']);
|
|
|
|
|
|
// global variables
|
|
$supported_ap_software = [
|
|
'mastodon',
|
|
];
|
|
|
|
// functions
|
|
function apiresult($data, $code=200) {
|
|
if ($code !== 200) http_response_code($code);
|
|
header('Content-Type: application/json');
|
|
echo json_encode($data); die;
|
|
}
|