Make instance configuration saveable

This commit is contained in:
Bofh 2022-11-25 02:09:16 +01:00
parent 4a123a550d
commit 7c940b058d
3 changed files with 32 additions and 1 deletions

View File

@ -0,0 +1,23 @@
<?php chdir('../../../../') ?>
<?php require 'base.php' ?>
<?php
$software = trim($_GET['software']);
if (!in_array($software, $supported_ap_software))
apiresult(['error' => 'software type is not supported'], 400);
$instance = trim($_GET['instance']);
if (!preg_match('/^[a-zA-Z0-9\.\-\_]+$/', $instance))
apiresult(['error' => 'instance parameter is not correctly formatted'], 400);
$string = '';
foreach ($_POST as $k => $v) {
if (trim($v) === '')
continue;
$string .= strtolower(trim($k)).'='.trim($v)."\n";
}
$config_file = $appconf['data_dir'].'/instances/'.$software.'/'.$instance.'/config';
file_put_contents($config_file, $string);
header('Location: '.$_SERVER['HTTP_REFERER']);

View File

@ -46,6 +46,10 @@ body {
border-radius: .5em;
box-shadow: 0px 0px .5em #0000004f;
}
.btn {
padding: .5em 1em;
cursor: pointer;
}
textarea {
max-width: -moz-available;

View File

@ -1,7 +1,9 @@
<div class="flex hmax">
<form class="center card">
<form class="center card" method="POST">
<h3 id="title"></h3>
<div id="config"></div>
<br><input type="submit" class="btn w100"
value="Save configuration"/>
</form>
<div id="config-item">
<label for="{field}">{placeholder}:</label>
@ -13,6 +15,8 @@
<script>
var autofill_fields = {
mastodon: function(hargs, config) {
E.element('#window-instance_config form').setAttribute('action',
`api/v1/config/put/?software=mastodon&instance=${hargs['instance']}`);
const fields = window.consts['instance_config']['mastodon']['musthave'];
for (var i = 0; i < fields.length; i++) {
if (config[fields[i]] !== undefined)