diff --git a/admin/dashboard.py b/admin/dashboard.py index 5c577fd..091c81b 100644 --- a/admin/dashboard.py +++ b/admin/dashboard.py @@ -762,6 +762,8 @@ def pastafari2_edit_server(): admin.url_redirect=url_for('.pastafari2_dashboard') + admin.pre_update=pre_update_server + form_admin=admin.show() if type(form_admin).__name__=='str': @@ -770,7 +772,34 @@ def pastafari2_edit_server(): else: return form_admin + +def pre_update_server(admin): + db=g.connection + + ssh_user=config_task.remote_user + ssh_port=request.form.get('ssh_port', 22) + server_host=request.form.get('ip', '') + private_key='./ssh/id_rsa' + private_key='./ssh/id_rsa' + public_key='./ssh/id_rsa.pub' + remote_path='pastafari2' + data={} + task_id=0 + + with SSHTask(server_host, db, remote_user=ssh_user, remote_password='', private_key=private_key, remote_path=remote_path, task_id=task_id, data=data, port=ssh_port) as ssh_task: + if not ssh_task.prepare_connection(): + + admin.model.fields['ssh_port'].txt_error=ssh_task.txt_error + admin.model.fields['ssh_port'].error=True + + return False + #txt_error=ssh_task.txt_error #I18n.lang('pastafari2', 'error_connection', 'Error: cannot connect to server') + #error_form['#server_host_error']=txt_error #I18n.lang('pastafari2', 'error_connection', 'Error: cannot connect to server') + + + return True + @admin_app.route('/pastafari2/edit_update/', methods=['POST', 'GET']) def pastafari2_edit_update(): """Simple function for edit and add extra scripts for update function"""