summaryrefslogtreecommitdiffstats
path: root/ogcp/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'ogcp/views.py')
-rw-r--r--ogcp/views.py42
1 files changed, 39 insertions, 3 deletions
diff --git a/ogcp/views.py b/ogcp/views.py
index d6fc67c..a583dfa 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -15,7 +15,7 @@ from ogcp.forms.action_forms import (
GenericForm, SelectClientForm, ImageUpdateForm, ImportClientsForm,
ServerForm, DeleteRepositoryForm, RepoForm, FolderForm, CacheForm,
ClientMoveForm, RunScriptForm, ImageConfigForm, ImageFetchForm,
- ServerConfigurationForm, SetRepoForm
+ ServerConfigurationForm, SetRepoForm, RunCmdForm
)
from flask_login import (
current_user, LoginManager,
@@ -2218,6 +2218,42 @@ def action_client_delete():
else:
return redirect(url_for('scopes'))
+@app.route('/action/cmd/run', methods=['GET', 'POST'])
+@login_required
+def action_run_cmd():
+ form = RunCmdForm(request.form)
+ if request.method == 'POST':
+ ips = form.ips.data.split(' ')
+ if not validate_elements(ips):
+ return redirect(url_for('commands'))
+
+ payload = {
+ 'clients': ips,
+ 'run': form.command.data,
+ 'inline': True
+ }
+ server = get_server_from_clients(ips)
+ r = server.post('/shell/run', payload)
+
+ if not r:
+ return ogserver_down('commands')
+ if r.status_code != requests.codes.ok:
+ return ogserver_error('commands')
+
+ flash(_('Command sent successfully'), category='info')
+ return redirect(url_for('commands'))
+ else:
+ ips = parse_elements(request.args.to_dict())
+ form.ips.data = " ".join(ips)
+ if not validate_elements(ips):
+ return redirect(url_for('commands'))
+
+ scopes, clients = get_scopes(set(ips))
+ selected_clients = list(get_selected_clients(scopes['scope']).items())
+ return render_template('actions/script_run.html', form=form,
+ selected_clients=selected_clients,
+ scopes=scopes)
+
@app.route('/action/script/run', methods=['GET', 'POST'])
@login_required
def action_run_script():
@@ -2232,8 +2268,8 @@ def action_run_script():
payload = {
'clients': ips,
- 'run': ';|\n\r'.join(cmd_elems),
- 'echo': True
+ 'run': ' '.join(cmd_elems),
+ 'inline': False
}
server = get_server_from_clients(ips)
r = server.post('/shell/run', payload)