Add API for getting pending users + API base modifications
This commit is contained in:
parent
c4efc9a21d
commit
13505f5346
|
@ -1,35 +1,3 @@
|
|||
<?php chdir('../../../../') ?>
|
||||
<?php require 'base.php' ?>
|
||||
<?php
|
||||
|
||||
$json = [
|
||||
'hosts' => [],
|
||||
'supported_ap_software' => $supported_ap_software,
|
||||
];
|
||||
|
||||
$instances_path = $appconf['data_dir'].'/instances';
|
||||
if (!file_exists($instances_path)) {
|
||||
mkdir($instances_path);
|
||||
apiresult($json);
|
||||
}
|
||||
|
||||
foreach ($supported_ap_software as $apsoft) {
|
||||
$json['hosts'][$apsoft] = [];
|
||||
$apsoft_path = $instances_path.'/'.$apsoft;
|
||||
if (!file_exists($apsoft_path)) {
|
||||
mkdir($apsoft_path);
|
||||
continue;
|
||||
}
|
||||
foreach (scandir($apsoft_path) as $file) {
|
||||
if (in_array($file,['.','..']))
|
||||
continue;
|
||||
$instance_path = $apsoft_path.'/'.$file;
|
||||
$json['hosts'][$apsoft] [] = [
|
||||
'instance' => $file,
|
||||
'config' => trim(
|
||||
file_get_contents($instance_path.'/config')),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
apiresult($json);
|
||||
<?php require 'api/v1/config/get/mod.php' ?>
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
$json = [
|
||||
'hosts' => [],
|
||||
'supported_ap_software' => $GLOBALS['supported_ap_software'],
|
||||
];
|
||||
|
||||
$instances_path = $GLOBALS['appconf']['data_dir'].'/instances';
|
||||
if (!file_exists($instances_path)) {
|
||||
mkdir($instances_path);
|
||||
apiresult($json);
|
||||
}
|
||||
|
||||
foreach ($GLOBALS['supported_ap_software'] as $apsoft) {
|
||||
$json['hosts'][$apsoft] = [];
|
||||
$apsoft_path = $instances_path.'/'.$apsoft;
|
||||
if (!file_exists($apsoft_path)) {
|
||||
mkdir($apsoft_path);
|
||||
continue;
|
||||
}
|
||||
foreach (scandir($apsoft_path) as $file) {
|
||||
if (in_array($file,['.','..']))
|
||||
continue;
|
||||
$instance_path = $apsoft_path.'/'.$file;
|
||||
$json['hosts'][$apsoft] [] = [
|
||||
'instance' => $file,
|
||||
'config' => trim(
|
||||
file_get_contents($instance_path.'/config')),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
apiresult($json);
|
|
@ -3,7 +3,7 @@
|
|||
<?php
|
||||
|
||||
$software = trim($_GET['software']);
|
||||
if (!in_array($software, $supported_ap_software))
|
||||
if (!in_array($software, $GLOBALS['supported_ap_software']))
|
||||
apiresult(['error' => 'software type is not supported'], 400);
|
||||
|
||||
$instance = trim($_GET['instance']);
|
||||
|
@ -17,7 +17,7 @@ foreach ($_POST as $k => $v) {
|
|||
$string .= strtolower(trim($k)).'='.trim($v)."\n";
|
||||
}
|
||||
|
||||
$config_file = $appconf['data_dir'].'/instances/'.$software.'/'.$instance.'/config';
|
||||
$config_file = $GLOBALS['appconf']['data_dir'].'/instances/'.$software.'/'.$instance.'/config';
|
||||
file_put_contents($config_file, $string);
|
||||
|
||||
header('Location: '.$_SERVER['HTTP_REFERER']);
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
<?php chdir('../../../../../') ?>
|
||||
<?php require 'base.php' ?>
|
||||
<?php
|
||||
|
||||
$pg = new PgDatabase();
|
||||
if ($pg->is_ok()) {
|
||||
$result = $pg->fetch_all('SELECT a.id, a.username, u.sign_up_ip, u.email, ui.text FROM users AS u INNER JOIN user_invite_requests AS ui ON ui.user_id = u.id INNER JOIN accounts AS a ON a.id = u.account_id WHERE NOT confirmed_at IS NULL AND approved = false ORDER BY ui.id ASC');
|
||||
$pg->close();
|
||||
apiresult($result);
|
||||
}
|
||||
|
||||
apiresult(['error' => 'Server has failed connecting to database'], 503);
|
10
base.php
10
base.php
|
@ -18,17 +18,21 @@ if (!in_array($session, $sessions)) {
|
|||
}
|
||||
unset($sessions);
|
||||
|
||||
if (!file_exists($appconf['data_dir']))
|
||||
mkdir($appconf['data_dir']);
|
||||
if (!file_exists($GLOBALS['appconf']['data_dir']))
|
||||
mkdir($GLOBALS['appconf']['data_dir']);
|
||||
|
||||
|
||||
// global variables
|
||||
$supported_ap_software = [
|
||||
$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;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
|
||||
$appconf = [
|
||||
$GLOBALS['appconf'] = [
|
||||
'data_dir' => '/var/tmp/apub-ctpanel',
|
||||
];
|
||||
|
|
Loading…
Reference in New Issue