Changelog: https://roxy-wi.org/changelog#6_3_11
pull/364/head v6.3.11.0
Aidaho 2 years ago
parent c1a4daa5a6
commit 9be5ce07f5

@ -793,11 +793,12 @@ def upload_ssh_key():
groups = sql.select_groups(id=group_id) groups = sql.select_groups(id=group_id)
for group in groups: for group in groups:
user_group = group.name user_group = group.name
if ssh_mod.upload_ssh_key(name, user_group, key): try:
ssh_mod.upload_ssh_key(f'{name}_{user_group}', user_group, key)
data = {'status': 'done'} data = {'status': 'done'}
return dict(data) return dict(data)
else: except Exception as e:
data = {'status': 'error: check all fields'} data = {'status': f'{e}'}
return dict(data) return dict(data)
@ -815,7 +816,7 @@ def create_server():
login, group_id, role_id = sql.get_username_groupid_from_api_token(token) login, group_id, role_id = sql.get_username_groupid_from_api_token(token)
try: try:
if server_mod.create_server(hostname, ip, group_id, virt, 1, master_id, cred_id, port, desc, 0, 0, 0, 0, '1', role_id=role_id, token=token): if server_mod.create_server(hostname, ip, group_id, virt, 1, master_id, cred_id, port, desc, 0, 0, 0, 0, role_id=role_id, token=token):
data = {'status': 'done'} data = {'status': 'done'}
roxywi_common.logging(ip, f'A new server {hostname} has been created', roxywi=1, keep_history=1, service='server') roxywi_common.logging(ip, f'A new server {hostname} has been created', roxywi=1, keep_history=1, service='server')
return dict(data) return dict(data)

@ -92,18 +92,15 @@ def create_ssh_cread_api(name: str, enable: str, group: str, username: str, pass
def upload_ssh_key(name: str, user_group: str, key: str) -> bool: def upload_ssh_key(name: str, user_group: str, key: str) -> bool:
if '..' in name: if '..' in name:
print('error: nice try') raise Exception('error: nice try')
return False
if name == '': if name == '':
print('error: please select credentials first') raise Exception('error: please select credentials first')
return False
try: try:
key = paramiko.pkey.load_private_key(key) key = paramiko.pkey.load_private_key(key)
except Exception as e: except Exception as e:
print(f'error: Cannot save SSH key file: {e}') raise Exception(f'error: Cannot save SSH key file: {e}')
return False
lib_path = get_config.get_config_var('main', 'lib_path') lib_path = get_config.get_config_var('main', 'lib_path')
full_dir = f'{lib_path}/keys/' full_dir = f'{lib_path}/keys/'
@ -126,8 +123,7 @@ def upload_ssh_key(name: str, user_group: str, key: str) -> bool:
try: try:
key.write_private_key_file(ssh_keys) key.write_private_key_file(ssh_keys)
except Exception as e: except Exception as e:
print(f'error: Cannot save SSH key file: {e}') raise Exception(f'error: Cannot save SSH key file: {e}')
return False
else: else:
print(f'success: SSH key has been saved into: {ssh_keys}') print(f'success: SSH key has been saved into: {ssh_keys}')
@ -135,10 +131,9 @@ def upload_ssh_key(name: str, user_group: str, key: str) -> bool:
os.chmod(ssh_keys, 0o600) os.chmod(ssh_keys, 0o600)
except IOError as e: except IOError as e:
roxywi_common.logging('Roxy-WI server', e.args[0], roxywi=1) roxywi_common.logging('Roxy-WI server', e.args[0], roxywi=1)
return False raise Exception(f'error: something went wrong: {e}')
roxywi_common.logging("Roxy-WI server", f"A new SSH cert has been uploaded {ssh_keys}", roxywi=1, login=1) roxywi_common.logging("Roxy-WI server", f"A new SSH cert has been uploaded {ssh_keys}", roxywi=1, login=1)
return True
def update_ssh_key() -> None: def update_ssh_key() -> None:

@ -847,7 +847,10 @@ if form.getvalue('ssh_cert'):
name = common.checkAjaxInput(form.getvalue('name')) name = common.checkAjaxInput(form.getvalue('name'))
key = form.getvalue('ssh_cert') key = form.getvalue('ssh_cert')
ssh_mod.upload_ssh_key(name, user_group, key) try:
ssh_mod.upload_ssh_key(name, user_group, key)
except Exception as e:
print(e)
if form.getvalue('new_receiver'): if form.getvalue('new_receiver'):
import modules.alerting.alerting as alerting import modules.alerting.alerting as alerting

Loading…
Cancel
Save