2022-11-24 23:21:52 +00:00
|
|
|
<div class="flex hmax">
|
2022-11-25 01:09:16 +00:00
|
|
|
<form class="center card" method="POST">
|
2022-11-25 00:44:03 +00:00
|
|
|
<h3 id="title"></h3>
|
|
|
|
<div id="config"></div>
|
2022-11-28 00:45:53 +00:00
|
|
|
<br>
|
|
|
|
<div class="flex">
|
|
|
|
<button onclick="event.preventDefault();
|
2022-11-28 14:21:46 +00:00
|
|
|
window.history.back()" class="btn"
|
|
|
|
><i class="fa fa-arrow-left fa-fw"></i> Cancel</button>
|
|
|
|
<div style="width:1em"></div>
|
|
|
|
<button class="btn"
|
|
|
|
><i class="fa fa-save fa-fw"></i> Save configuration</button>
|
2022-11-28 00:45:53 +00:00
|
|
|
</div>
|
2022-11-25 00:44:03 +00:00
|
|
|
</form>
|
|
|
|
<div id="config-item">
|
2022-12-19 00:18:37 +00:00
|
|
|
<label for="{field}">{importantMark}{placeholder}:</label>
|
2022-11-25 00:44:03 +00:00
|
|
|
<input id="config_{field}" name="{field}" class="w100"
|
|
|
|
placeholder="{field}" type="text"/>
|
|
|
|
</div>
|
2022-11-24 23:21:52 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<script>
|
2022-11-28 00:45:53 +00:00
|
|
|
window.view.instance_config = {
|
|
|
|
autofill_fields: {
|
|
|
|
mastodon: function(hargs, config) {
|
|
|
|
E.element('#window-instance_config form').setAttribute('action',
|
|
|
|
`api/v1/config/put/?software=mastodon&instance=${hargs['instance']}`);
|
2022-12-19 00:18:37 +00:00
|
|
|
const fields = window.consts['instance_config']['mastodon']['fields'];
|
2022-11-28 00:45:53 +00:00
|
|
|
for (var i = 0; i < fields.length; i++) {
|
2022-12-19 00:18:37 +00:00
|
|
|
const f = fields[i].startsWith('*') ? fields[i].substr(1) : fields[i];
|
|
|
|
if (config[f] !== undefined)
|
|
|
|
E.elemid(`config_${f}`).value = config[f];
|
2022-11-28 00:45:53 +00:00
|
|
|
}
|
|
|
|
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'];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2022-11-25 00:44:03 +00:00
|
|
|
},
|
2022-11-28 00:45:53 +00:00
|
|
|
}
|
2022-11-24 23:21:52 +00:00
|
|
|
function title__instance_config() {}
|
|
|
|
function load__instance_config(args) {
|
2022-11-28 02:03:20 +00:00
|
|
|
const hargs = get_hash_arguments();
|
2022-11-24 23:21:52 +00:00
|
|
|
|
|
|
|
const _error400 = function(msg) {
|
|
|
|
msg = msg || 'Parameters are not correct';
|
2022-12-10 14:15:49 +00:00
|
|
|
toast.error(msg);
|
2022-11-24 23:21:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const _paint = function() {
|
2022-11-25 00:44:03 +00:00
|
|
|
E.template('#window-instance_config #title',
|
|
|
|
capitalize(hargs['software']) + ` (${hargs['instance']})`);
|
|
|
|
E.template('config', function(TPL) {
|
|
|
|
var html = '';
|
2022-12-19 00:18:37 +00:00
|
|
|
const fields = window.consts['instance_config'][hargs['software']]['fields'];
|
2022-11-25 00:44:03 +00:00
|
|
|
for (var i = 0; i < fields.length; i++) {
|
2022-12-19 00:18:37 +00:00
|
|
|
const field = fields[i].startsWith('*') ? fields[i].substr(1) : fields[i];
|
|
|
|
const important = fields[i].startsWith('*');
|
2022-11-25 00:44:03 +00:00
|
|
|
var tpl = TPL;
|
2022-12-19 00:18:37 +00:00
|
|
|
tpl = tpl.replaceAll('{field}', field);
|
|
|
|
tpl = tpl.replaceAll('{placeholder}', human_field_name(field));
|
|
|
|
tpl = tpl.replaceAll('{importantMark}', important ? '*' : '');
|
2022-11-25 00:44:03 +00:00
|
|
|
html += tpl;
|
|
|
|
}
|
|
|
|
return html;
|
|
|
|
});
|
|
|
|
const config = parse_ini_config(window.vars['current_instance']['config']);
|
2022-11-28 00:45:53 +00:00
|
|
|
window.view.instance_config.autofill_fields[hargs['software']](hargs, config);
|
2022-11-24 23:21:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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>
|