soselo/base.php

43 lines
1.1 KiB
PHP
Raw Normal View History

2022-11-21 22:56:44 +00:00
<?php
require 'config/application.php';
2022-11-21 23:57:29 +00:00
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>');
}
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)) {
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;
}
unset($sessions);
if (!file_exists($GLOBALS['appconf']['data_dir']))
mkdir($GLOBALS['appconf']['data_dir']);
// global variables
$GLOBALS['supported_ap_software'] = [
'mastodon',
];
// functions
function apiresult($data, $code=200) {
if (isset($GLOBALS['IS_PHP']) && $GLOBALS['IS_PHP']) {
$GLOBALS['api_data'] = $data;
return false;
}
if ($code !== 200) http_response_code($code);
header('Content-Type: application/json');
echo json_encode($data); die;
}
2022-11-24 22:41:05 +00:00
// classes
require 'classes/PgDatabase.php';