Warn about deleting key for active connection

This commit is contained in:
Timotej Lazar 2023-12-10 12:58:20 +01:00
parent bb68978b22
commit 85714f83b9
2 changed files with 6 additions and 5 deletions

View file

@ -111,13 +111,12 @@ function fetch_keys() {
});
var li = document.createElement('li');
li.innerHTML = ' ' + (new Date(key.time*1000).toISOString().split('T')[0]) +
' <code>' + key.key + '</code>' +
(key.active ? '<font color="red"><sup></sup></font> ' : ' ') +
key.name;
' <code>' + key.key + '</code> ' + key.name +
(key.active ? '<font color="red"><sup></sup></font> ' : '');
li.prepend(a);
keys.appendChild(li);
if (key.active)
warning.innerHTML = '<font color="red"><sup></sup></font>Ta ključ uporablja aktivna povezava. Če ga odstranite, bo prekinjena.';
warning.innerHTML = '<font color="red"><sup></sup></font> Ta ključ uporablja trenutna povezava. Če ga odstranite, bo prekinjena.';
}
document.querySelector('section.keys').style.display = (Object.keys(data).length ? 'unset' : 'none');
})

View file

@ -22,7 +22,9 @@ def index():
@flask_login.login_required
def list():
user = flask_login.current_user.get_id()
return flask.jsonify({k: v for k, v in db.load('wireguard').items() if v.get('user') == user})
return flask.jsonify(
{k: v | {'active': flask.request.remote_addr in (v.get('ip'), v.get('ip6'))}
for k, v in db.load('wireguard').items() if v.get('user') == user})
@blueprint.route('/new', methods=('POST',))
@flask_login.login_required