2022-11-21 22:56:44 +00:00
|
|
|
<?php
|
2022-11-22 14:25:59 +00:00
|
|
|
require 'config/application.php';
|
2022-11-21 23:57:29 +00:00
|
|
|
|
|
|
|
if (!isset($_COOKIE['_session']) || !file_exists('/tmp/apcontrol-sessions')) {
|
2022-11-22 01:22:58 +00:00
|
|
|
if (substr($_SERVER['REQUEST_URI'],0,5) === '/api/') {
|
|
|
|
http_response_code(403); die('<h3>403, API Forbidden</h3>');
|
|
|
|
}
|
2022-11-21 23:57:29 +00:00
|
|
|
header('Location: login.php'); die;
|
|
|
|
}
|
|
|
|
|
|
|
|
$session = trim($_COOKIE['_session']);
|
|
|
|
$sessions = explode("\n", trim(file_get_contents('/tmp/apcontrol-sessions')));
|
|
|
|
if (!in_array($session, $sessions)) {
|
2022-11-22 01:22:58 +00:00
|
|
|
if (substr($_SERVER['REQUEST_URI'],0,5) === '/api/') {
|
|
|
|
http_response_code(403); die('<h3>403, API Forbidden</h3>');
|
|
|
|
}
|
2022-11-21 23:57:29 +00:00
|
|
|
header('Location: login.php'); die;
|
|
|
|
}
|
2022-11-22 01:22:58 +00:00
|
|
|
unset($sessions);
|
|
|
|
|
2022-11-27 20:18:56 +00:00
|
|
|
if (!file_exists($GLOBALS['appconf']['data_dir']))
|
|
|
|
mkdir($GLOBALS['appconf']['data_dir']);
|
2022-11-22 14:25:59 +00:00
|
|
|
|
|
|
|
|
2022-11-22 01:22:58 +00:00
|
|
|
// global variables
|
2022-11-27 20:18:56 +00:00
|
|
|
$GLOBALS['supported_ap_software'] = [
|
2022-11-22 01:22:58 +00:00
|
|
|
'mastodon',
|
|
|
|
];
|
|
|
|
|
|
|
|
// functions
|
2022-11-22 10:55:58 +00:00
|
|
|
function apiresult($data, $code=200) {
|
2022-11-27 20:18:56 +00:00
|
|
|
if (isset($GLOBALS['IS_PHP']) && $GLOBALS['IS_PHP']) {
|
|
|
|
$GLOBALS['api_data'] = $data;
|
|
|
|
return false;
|
|
|
|
}
|
2022-11-22 10:55:58 +00:00
|
|
|
if ($code !== 200) http_response_code($code);
|
2022-11-22 01:22:58 +00:00
|
|
|
header('Content-Type: application/json');
|
|
|
|
echo json_encode($data); die;
|
|
|
|
}
|
2022-11-24 22:41:05 +00:00
|
|
|
|
|
|
|
// classes
|
|
|
|
require 'classes/PgDatabase.php';
|