diff --git a/api/v1/config/get/index.php b/api/v1/config/get/index.php index efdb6f8..8199ced 100644 --- a/api/v1/config/get/index.php +++ b/api/v1/config/get/index.php @@ -1,35 +1,3 @@ - [], - '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); + diff --git a/api/v1/config/get/mod.php b/api/v1/config/get/mod.php new file mode 100644 index 0000000..19b6d19 --- /dev/null +++ b/api/v1/config/get/mod.php @@ -0,0 +1,33 @@ + [], + '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); diff --git a/api/v1/config/put/index.php b/api/v1/config/put/index.php index 5860d6e..3154c94 100644 --- a/api/v1/config/put/index.php +++ b/api/v1/config/put/index.php @@ -3,7 +3,7 @@ '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']); diff --git a/api/v1/database/mastodon/get-pending-users/index.php b/api/v1/database/mastodon/get-pending-users/index.php new file mode 100644 index 0000000..6761a88 --- /dev/null +++ b/api/v1/database/mastodon/get-pending-users/index.php @@ -0,0 +1,12 @@ + + +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); diff --git a/base.php b/base.php index 760f5f9..17ead07 100644 --- a/base.php +++ b/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; diff --git a/config/application.php b/config/application.php index f82d29b..010beb1 100644 --- a/config/application.php +++ b/config/application.php @@ -1,5 +1,5 @@ '/var/tmp/apub-ctpanel', ];