summaryrefslogtreecommitdiffstats
path: root/ogcp/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'ogcp/views.py')
-rw-r--r--ogcp/views.py63
1 files changed, 62 insertions, 1 deletions
diff --git a/ogcp/views.py b/ogcp/views.py
index af65ddf..0133954 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -13,7 +13,8 @@ from ogcp.forms.action_forms import (
SessionForm, ImageRestoreForm, ImageCreateForm, SoftwareForm, BootModeForm,
RoomForm, DeleteRoomForm, CenterForm, DeleteCenterForm, OgliveForm,
GenericForm, SelectClientForm, ImageUpdateForm, ImportClientsForm,
- ServerForm, DeleteRepositoryForm, RepoForm, FolderForm, CacheForm
+ ServerForm, DeleteRepositoryForm, RepoForm, FolderForm, CacheForm,
+ ClientMoveForm
)
from flask_login import (
current_user, LoginManager,
@@ -1574,6 +1575,66 @@ def action_client_add():
return render_template('actions/client_add.html', form=form,
parent="scopes.html", scopes=scopes)
+def build_client_move_choices(scopes, choices, path):
+ for scope in scopes.get('scope'):
+ new_path = f'{path}{scope.get("name")}/'
+
+ if scope.get('type') == 'room':
+ choices.append((f'{scope["id"]} 0', new_path))
+
+ for room_child in scope.get('scope'):
+ if room_child.get('type') == 'folder':
+ choices.append(
+ (f'{scope["id"]} {room_child["id"]}',
+ f'{new_path}{room_child.get("name")}/')
+ )
+ else:
+ build_client_move_choices(scope, choices, new_path)
+
+def get_client_move_choices(scopes):
+ choices = []
+ build_client_move_choices(scopes, choices, '')
+ return choices
+
+@app.route('/action/client/move', methods=['GET', 'POST'])
+@login_required
+def action_client_move():
+ form = ClientMoveForm(request.form)
+ if request.method == 'POST':
+ ips = form.ips.data.split(' ')
+ if not validate_elements(ips):
+ return redirect(url_for('scopes'))
+
+ room_id, folder_id = form.scopes.data.split(' ')
+
+ payload = {"clients": ips,
+ "room": int(room_id),
+ "folder_id": int(folder_id)}
+ server = get_server_from_clients(ips)
+ r = server.post('/client/move', payload)
+ if r.status_code != requests.codes.ok:
+ flash(_('ogServer: error moving client'),
+ category='error')
+ else:
+ flash(_('Client moved successfully'),
+ category='info')
+ return redirect(url_for('scopes'))
+ else:
+ ips = parse_elements(request.args.to_dict())
+ form.ips.data = " ".join(ips)
+
+ if not validate_elements(ips):
+ return redirect(url_for('scopes'))
+
+ scopes, clients = get_scopes(set(ips))
+ form.scopes.choices = get_client_move_choices(scopes)
+ selected_clients = list(get_selected_clients(scopes['scope']).items())
+
+ return render_template('actions/client_move.html', form=form,
+ selected_clients=selected_clients,
+ scopes=scopes)
+
+
PLACEHOLDER_TEXT = '''host example1 { hardware ethernet 94:c6:91:a6:25:1a; fixed-address 10.141.10.100; }
host example2 { hardware ethernet 94:c6:91:a6:25:1b; fixed-address 10.141.10.101; }
host example3 { hardware ethernet 94:c6:91:a6:25:1c; fixed-address 10.141.10.102; }