Changelog: https://roxy-wi.org/changelog#6_3_1
pull/355/head
Pavel Loginov 2022-12-07 10:16:07 +03:00
parent 43efd1587e
commit 0b804af5d9
5 changed files with 14 additions and 114 deletions

View File

@ -6,8 +6,11 @@ import pika
from jinja2 import Environment, FileSystemLoader
import modules.db.sql as sql
import modules.common.common as common
import modules.roxywi.common as roxywi_common
error_mess = common.error_mess
def send_message_to_rabbit(message: str, **kwargs) -> None:
rabbit_user = sql.get_setting('rabbitmq_user')
@ -215,9 +218,6 @@ def check_email_alert() -> None:
print(f'error: Cannot send a message {e}')
error_mess = 'error: All fields must be completed'
def add_telegram_channel(token: str, channel: str, group: str, page: str) -> None:
if token is None or channel is None or group is None:
print(error_mess)

View File

@ -2,7 +2,7 @@ import re
import cgi
form = cgi.FieldStorage()
error_mess = 'error: All fields must be completed'
def is_ip_or_dns(server_from_request: str) -> str:
ip_regex = "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"

View File

@ -10,6 +10,7 @@ import modules.roxywi.common as roxywi_common
form = common.form
def waf_overview(serv, waf_service) -> None:
env = Environment(
loader=FileSystemLoader('templates/ajax'), autoescape=True,

View File

@ -79,8 +79,7 @@ def ssh_command(server_ip: str, commands: list, **kwargs):
except Exception as e:
roxywi_common.logging('Roxy-WI server', f' Something wrong with SSH connection. Probably sudo with password {e}', roxywi=1)
except Exception as e:
roxywi_common.logging('Roxy-WI server',
f' Something wrong with SSH connection: {e}', roxywi=1)
roxywi_common.logging('Roxy-WI server', f' Something wrong with SSH connection: {e}', roxywi=1)
raise Exception(f'error: {e}')

View File

@ -1657,124 +1657,24 @@ if form.getvalue('updategroup') is not None:
print('error: ' + str(e))
if form.getvalue('new_ssh'):
user_group = roxywi_common.get_user_group()
name = common.checkAjaxInput(form.getvalue('new_ssh'))
name = f'{name}{user_group}'
enable = common.checkAjaxInput(form.getvalue('ssh_enable'))
group = common.checkAjaxInput(form.getvalue('new_group'))
username = common.checkAjaxInput(form.getvalue('ssh_user'))
password = common.checkAjaxInput(form.getvalue('ssh_pass'))
page = common.checkAjaxInput(form.getvalue('page'))
page = page.split("#")[0]
import modules.server.ssh as ssh_mod
if username is None or name is None:
print(error_mess)
else:
if sql.insert_new_ssh(name, enable, group, username, password):
env = Environment(loader=FileSystemLoader('templates/ajax'), autoescape=True)
template = env.get_template('/new_ssh.html')
output_from_parsed_template = template.render(groups=sql.select_groups(), sshs=sql.select_ssh(name=name),
page=page)
print(output_from_parsed_template)
roxywi_common.logging('Roxy-WI server', 'A new SSH credentials ' + name + ' has created', roxywi=1, login=1)
ssh_mod.create_ssh_cred()
if form.getvalue('sshdel') is not None:
lib_path = get_config.get_config_var('main', 'lib_path')
sshdel = common.checkAjaxInput(form.getvalue('sshdel'))
name = ''
ssh_enable = 0
ssh_key_name = ''
import modules.server.ssh as ssh_mod
for sshs in sql.select_ssh(id=sshdel):
ssh_enable = sshs.enable
name = sshs.name
ssh_key_name = f'{lib_path}/keys/{sshs.name}.pem'
if ssh_enable == 1:
cmd = f'rm -f {ssh_key_name}'
try:
server_mod.subprocess_execute(cmd)
except Exception:
pass
if sql.delete_ssh(sshdel):
print("Ok")
roxywi_common.logging('Roxy-WI server', f'The SSH credentials {name} has deleted', roxywi=1, login=1)
ssh_mod.delete_ssh_key()
if form.getvalue('updatessh'):
ssh_id = common.checkAjaxInput(form.getvalue('id'))
name = common.checkAjaxInput(form.getvalue('name'))
enable = common.checkAjaxInput(form.getvalue('ssh_enable'))
group = common.checkAjaxInput(form.getvalue('group'))
username = common.checkAjaxInput(form.getvalue('ssh_user'))
password = common.checkAjaxInput(form.getvalue('ssh_pass'))
new_ssh_key_name = ''
import modules.server.ssh as ssh_mod
if username is None:
print(error_mess)
else:
lib_path = get_config.get_config_var('main', 'lib_path')
for sshs in sql.select_ssh(id=ssh_id):
ssh_enable = sshs.enable
ssh_key_name = f'{lib_path}/keys/{sshs.name}.pem'
new_ssh_key_name = f'{lib_path}/keys/{name}.pem'
if ssh_enable == 1:
cmd = f'mv {ssh_key_name} {new_ssh_key_name}'
cmd1 = f'chmod 600 {new_ssh_key_name}'
try:
server_mod.subprocess_execute(cmd)
server_mod.subprocess_execute(cmd1)
except Exception:
pass
sql.update_ssh(ssh_id, name, enable, group, username, password)
roxywi_common.logging('Roxy-WI server', f'The SSH credentials {name} has been updated ', roxywi=1, login=1)
ssh_mod.update_ssh_key()
if form.getvalue('ssh_cert'):
import paramiko
import modules.server.ssh as ssh_mod
user_group = roxywi_common.get_user_group()
name = common.checkAjaxInput(form.getvalue('name'))
try:
key = paramiko.pkey.load_private_key(form.getvalue('ssh_cert'))
except Exception as e:
print(f'error: Cannot save SSH key file: {e}')
sys.exit()
lib_path = get_config.get_config_var('main', 'lib_path')
full_dir = f'{lib_path}/keys/'
ssh_keys = f'{name}.pem'
try:
check_split = name.split('_')[1]
split_name = True
except Exception:
split_name = False
if not os.path.isfile(ssh_keys) and not split_name:
name = f'{name}_{user_group}'
if not os.path.exists(full_dir):
os.makedirs(full_dir)
ssh_keys = f'{full_dir}{name}.pem'
try:
key.write_private_key_file(ssh_keys)
except Exception as e:
print(f'error: Cannot save SSH key file: {e}')
sys.exit()
else:
print(f'success: SSH key has been saved into: {ssh_keys}')
try:
cmd = f'chmod 600 {ssh_keys}'
server_mod.subprocess_execute(cmd)
except IOError as e:
roxywi_common.logging('Roxy-WI server', e.args[0], roxywi=1)
roxywi_common.logging("Roxy-WI server", f"A new SSH cert has been uploaded {ssh_keys}", roxywi=1, login=1)
ssh_mod.upload_ssh_key()
if form.getvalue('newtelegram'):
import modules.alerting.alerting as alerting