93 lines
2.8 KiB
PHP
93 lines
2.8 KiB
PHP
<div class="flex hmax">
|
|
<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>
|
|
<input id="config_{field}" name="{field}" class="w100"
|
|
placeholder="{field}" type="text"/>
|
|
</div>
|
|
</div>
|
|
|
|
<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)
|
|
E.elemid(`config_${fields[i]}`).value = config[fields[i]];
|
|
}
|
|
if (config['instance_url'] === undefined) {
|
|
http.get('api/v1/network/resolve-instance?hostname='+hargs['instance'],
|
|
{}, function(js) {
|
|
if (js['instance'] !== undefined)
|
|
E.elemid('config_instance_url').value = js['instance'];
|
|
});
|
|
}
|
|
},
|
|
};
|
|
function title__instance_config() {}
|
|
function load__instance_config(args) {
|
|
const hargs = parse_hash_arguments(args[1]);
|
|
|
|
const _error400 = function(msg) {
|
|
msg = msg || 'Parameters are not correct';
|
|
console.log('TODO: handle error correctly');
|
|
};
|
|
|
|
const _paint = function() {
|
|
E.template('#window-instance_config #title',
|
|
capitalize(hargs['software']) + ` (${hargs['instance']})`);
|
|
E.template('config', function(TPL) {
|
|
var html = '';
|
|
const fields = window.consts['instance_config'][hargs['software']]['musthave'];
|
|
for (var i = 0; i < fields.length; i++) {
|
|
var tpl = TPL;
|
|
tpl = tpl.replaceAll('{field}', fields[i]);
|
|
tpl = tpl.replaceAll('{placeholder}', human_field_name(fields[i]));
|
|
html += tpl;
|
|
}
|
|
return html;
|
|
});
|
|
const config = parse_ini_config(window.vars['current_instance']['config']);
|
|
window.autofill_fields[hargs['software']](hargs, config);
|
|
};
|
|
|
|
const _main = function() {
|
|
if (hargs['software'] === undefined ||
|
|
!window.vars['instance_config']['supported_ap_software']
|
|
.includes(hargs['software']))
|
|
return _error400();
|
|
if (hargs['instance'] === undefined)
|
|
return _error400();
|
|
var found = false;
|
|
for (var i = 0; i < window.vars['instance_config']['hosts'][hargs['software']].length; i++)
|
|
{
|
|
const item = window.vars['instance_config']['hosts'][hargs['software']][i];
|
|
if (item['instance'] === hargs['instance']) {
|
|
window.vars['current_instance'] = item;
|
|
found = true;
|
|
break;
|
|
}
|
|
}
|
|
if (!found)
|
|
return _error400();
|
|
|
|
apcontrol_title(`Config (${hargs['instance']})`);
|
|
return _paint();
|
|
};
|
|
|
|
if (window.vars['instance_config'] === undefined) {
|
|
http.get('api/v1/config/get',{},function(data) {
|
|
window.vars['instance_config'] = JSON.parse(data);
|
|
_main();
|
|
});
|
|
} else { _main() }
|
|
}
|
|
</script>
|