summaryrefslogtreecommitdiffstats
path: root/ogcp/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'ogcp/views.py')
-rw-r--r--ogcp/views.py91
1 files changed, 90 insertions, 1 deletions
diff --git a/ogcp/views.py b/ogcp/views.py
index 4fa14a9..692bef1 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -14,7 +14,8 @@ from ogcp.forms.action_forms import (
RoomForm, DeleteRoomForm, CenterForm, DeleteCenterForm, OgliveForm,
GenericForm, SelectClientForm, ImageUpdateForm, ImportClientsForm,
ServerForm, DeleteRepositoryForm, RepoForm, FolderForm, CacheForm,
- ClientMoveForm, RunScriptForm, ImageConfigForm, ImageFetchForm
+ ClientMoveForm, RunScriptForm, ImageConfigForm, ImageFetchForm,
+ ServerConfigurationForm
)
from flask_login import (
current_user, LoginManager,
@@ -3278,6 +3279,94 @@ def manage_servers():
return render_template('servers.html', servers=servers)
+@app.route('/server/update', methods=['GET'])
+@login_required
+def server_update_get():
+ params = request.args.to_dict()
+ try:
+ selected_server = get_server_from_ip_port(params['selected-server'])
+ except KeyError:
+ flash(_('Please, select one server'), category='error')
+ return redirect(url_for('manage_servers'))
+
+ r = selected_server.get('/server')
+ if not r:
+ return ogserver_down('manage_servers')
+ if r.status_code != requests.codes.ok:
+ return ogserver_error('manage_servers')
+
+ form = ServerConfigurationForm()
+ server_config = r.json()['servers']
+ for c in server_config:
+ form.addr.append_entry(c['address'])
+
+ form.server_addr.data = selected_server.ip + ":" + str(selected_server.port)
+
+ return render_template('actions/server_update.html', form=form,
+ servers=servers)
+
+@app.route('/server/update', methods=['POST'])
+@login_required
+def server_update_post():
+ form = ServerConfigurationForm(request.form)
+ try:
+ server = get_server_from_ip_port(form.server_addr.data)
+ except Exception:
+ flash(_('Server {} does not exist').format(form.server_addr.data),
+ category='error')
+ return redirect(url_for('manage_servers'))
+
+ addr_list = [ip.data.strip() for ip in form.addr]
+ invalid_ips = []
+ for ip in addr_list:
+ if not is_valid_ip(ip):
+ invalid_ips.append('"' + ip + '"')
+
+ if invalid_ips:
+ flash(_(f'The following addresses are invalid: {" ".join(invalid_ips)}'), category='error')
+ return redirect(url_for('manage_servers'))
+
+ r = server.get('/server')
+ if not r:
+ return ogserver_down('manage_servers')
+ if r.status_code != requests.codes.ok:
+ return ogserver_error('manage_servers')
+ server_config = r.json()['servers']
+
+ # Remove
+ for c in server_config:
+ if c['address'] in addr_list:
+ continue
+
+ payload = {'id': c['id']}
+ rd = server.delete('/server', payload=payload)
+ if not rd:
+ return ogserver_down('manage_servers')
+ if rd.status_code != requests.codes.ok:
+ return ogserver_error('manage_servers')
+
+ # Add
+ for ip in addr_list:
+ found = False
+ for c in server_config:
+ if ip == c['address']:
+ found = True
+ break
+
+ if found:
+ continue
+
+ payload = {'address': ip}
+ ra = server.post('/server', payload=payload)
+ if not ra:
+ return ogserver_down('manage_servers')
+ if ra.status_code != requests.codes.ok:
+ return ogserver_error('manage_servers')
+
+ flash(_('Server update request sent successfully'), category='info')
+ return redirect(url_for('manage_servers'))
+
+
@app.route('/server/add', methods=['GET'])
@login_required
def server_add_get():