Add api/v1 + API to get the instances config
This commit is contained in:
parent
7739b27105
commit
0a65457586
|
@ -0,0 +1,26 @@
|
|||
<?php chdir('../../../../') ?>
|
||||
<?php require 'base.php' ?>
|
||||
<?php
|
||||
|
||||
$json = ['hosts' => []];
|
||||
foreach (scandir('config/usr') as $file) {
|
||||
$file = trim($file);
|
||||
if (strrpos($file,'.php') !== false) {
|
||||
if (strpos($file, '-') === false)
|
||||
continue;
|
||||
$name = substr($file, 0, -4);
|
||||
$hostn = substr($name, strpos($name, '-')+1);
|
||||
$apsoft = strtolower(substr($name, 0, strpos($name, '-')));
|
||||
if (!in_array($apsoft, $supported_ap_software))
|
||||
continue;
|
||||
if (!isset($json['hosts'][$apsoft]))
|
||||
$json['hosts'][$apsoft] = [];
|
||||
require "config/usr/$file";
|
||||
$json['hosts'][$apsoft] []= [
|
||||
'instance' => $hostn,
|
||||
'config' => $config,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
apiresult($json);
|
18
base.php
18
base.php
|
@ -1,11 +1,29 @@
|
|||
<?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);
|
||||
|
||||
// global variables
|
||||
$supported_ap_software = [
|
||||
'mastodon',
|
||||
];
|
||||
|
||||
// functions
|
||||
function apiresult($data) {
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($data); die;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue