mirror of https://github.com/Aidaho12/haproxy-wi
parent
586f4c626f
commit
729df72f11
|
@ -4,6 +4,7 @@ import http.cookies
|
||||||
|
|
||||||
import modules.db.sql as sql
|
import modules.db.sql as sql
|
||||||
import modules.server.ssh as mod_ssh
|
import modules.server.ssh as mod_ssh
|
||||||
|
import modules.server.server as mod_server
|
||||||
import modules.common.common as common
|
import modules.common.common as common
|
||||||
import modules.roxywi.common as roxywi_common
|
import modules.roxywi.common as roxywi_common
|
||||||
import modules.roxy_wi_tools as roxy_wi_tools
|
import modules.roxy_wi_tools as roxy_wi_tools
|
||||||
|
@ -219,7 +220,7 @@ def upload_and_restart(server_ip: str, cfg: str, **kwargs):
|
||||||
return error
|
return error
|
||||||
|
|
||||||
try:
|
try:
|
||||||
error = mod_ssh.ssh_command(server_ip, commands)
|
error = mod_server.ssh_command(server_ip, commands)
|
||||||
try:
|
try:
|
||||||
if action == 'reload' or action == 'restart':
|
if action == 'reload' or action == 'restart':
|
||||||
roxywi_common.logging(server_ip, f'Service has been {action}ed', login=login, keep_history=1, service=service)
|
roxywi_common.logging(server_ip, f'Service has been {action}ed', login=login, keep_history=1, service=service)
|
||||||
|
@ -327,7 +328,7 @@ def diff_config(oldcfg, cfg, **kwargs):
|
||||||
except Exception:
|
except Exception:
|
||||||
login = ''
|
login = ''
|
||||||
|
|
||||||
output, stderr = mod_ssh.subprocess_execute(cmd)
|
output, stderr = mod_server.subprocess_execute(cmd)
|
||||||
|
|
||||||
if kwargs.get('return_diff'):
|
if kwargs.get('return_diff'):
|
||||||
for line in output:
|
for line in output:
|
||||||
|
@ -382,7 +383,7 @@ def get_ssl_cert(server_ip: str) -> None:
|
||||||
cert_path = sql.get_setting('cert_path')
|
cert_path = sql.get_setting('cert_path')
|
||||||
commands = [f"openssl x509 -in {cert_path}/{cert_id} -text"]
|
commands = [f"openssl x509 -in {cert_path}/{cert_id} -text"]
|
||||||
try:
|
try:
|
||||||
mod_ssh.ssh_command(server_ip, commands, ip="1")
|
mod_server.ssh_command(server_ip, commands, ip="1")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f'error: Cannot connect to the server {e.args[0]}')
|
print(f'error: Cannot connect to the server {e.args[0]}')
|
||||||
|
|
||||||
|
@ -391,7 +392,7 @@ def get_ssl_certs(server_ip: str) -> None:
|
||||||
cert_path = sql.get_setting('cert_path')
|
cert_path = sql.get_setting('cert_path')
|
||||||
commands = [f"sudo ls -1t {cert_path} |grep -E 'pem|crt|key'"]
|
commands = [f"sudo ls -1t {cert_path} |grep -E 'pem|crt|key'"]
|
||||||
try:
|
try:
|
||||||
mod_ssh.ssh_command(server_ip, commands, ip="1")
|
mod_server.ssh_command(server_ip, commands, ip="1")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f'error: Cannot connect to the server: {e.args[0]}')
|
print(f'error: Cannot connect to the server: {e.args[0]}')
|
||||||
|
|
||||||
|
@ -402,7 +403,7 @@ def del_ssl_cert(server_ip: str) -> None:
|
||||||
cert_path = sql.get_setting('cert_path')
|
cert_path = sql.get_setting('cert_path')
|
||||||
commands = [f"sudo rm -f {cert_path}/{cert_id}"]
|
commands = [f"sudo rm -f {cert_path}/{cert_id}"]
|
||||||
try:
|
try:
|
||||||
mod_ssh.ssh_command(server_ip, commands, ip="1")
|
mod_server.ssh_command(server_ip, commands, ip="1")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f'error: Cannot delete the certificate {e.args[0]}')
|
print(f'error: Cannot delete the certificate {e.args[0]}')
|
||||||
|
|
||||||
|
|
|
@ -381,3 +381,30 @@ def update_system_info() -> None:
|
||||||
print(template)
|
print(template)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f'error: Cannot update server info: {e}')
|
print(f'error: Cannot update server info: {e}')
|
||||||
|
|
||||||
|
|
||||||
|
def show_firewalld_rules() -> None:
|
||||||
|
from jinja2 import Environment, FileSystemLoader
|
||||||
|
|
||||||
|
serv = common.checkAjaxInput(form.getvalue('viewFirewallRules'))
|
||||||
|
|
||||||
|
cmd = ["sudo iptables -L INPUT -n --line-numbers|sed 's/ */ /g'|grep -v -E 'Chain|target'"]
|
||||||
|
cmd1 = ["sudo iptables -L IN_public_allow -n --line-numbers|sed 's/ */ /g'|grep -v -E 'Chain|target'"]
|
||||||
|
cmd2 = ["sudo iptables -L OUTPUT -n --line-numbers|sed 's/ */ /g'|grep -v -E 'Chain|target'"]
|
||||||
|
|
||||||
|
input_chain = ssh_command(serv, cmd, raw=1)
|
||||||
|
|
||||||
|
input_chain2 = []
|
||||||
|
for each_line in input_chain:
|
||||||
|
input_chain2.append(each_line.strip('\n'))
|
||||||
|
|
||||||
|
if 'error:' in input_chain:
|
||||||
|
print(input_chain)
|
||||||
|
return
|
||||||
|
|
||||||
|
in_public_allow = ssh_command(serv, cmd1, raw=1)
|
||||||
|
output_chain = ssh_command(serv, cmd2, raw=1)
|
||||||
|
env = Environment(loader=FileSystemLoader('templates'))
|
||||||
|
template = env.get_template('ajax/firewall_rules.html')
|
||||||
|
template = template.render(input=input_chain2, IN_public_allow=in_public_allow, output=output_chain)
|
||||||
|
print(template)
|
||||||
|
|
|
@ -151,7 +151,10 @@ def delete_ssh_key() -> None:
|
||||||
ssh_key_name = f'{lib_path}/keys/{sshs.name}.pem'
|
ssh_key_name = f'{lib_path}/keys/{sshs.name}.pem'
|
||||||
|
|
||||||
if ssh_enable == 1:
|
if ssh_enable == 1:
|
||||||
|
try:
|
||||||
os.remove(ssh_key_name)
|
os.remove(ssh_key_name)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
if sql.delete_ssh(sshdel):
|
if sql.delete_ssh(sshdel):
|
||||||
print("Ok")
|
print("Ok")
|
||||||
roxywi_common.logging('Roxy-WI server', f'The SSH credentials {name} has deleted', roxywi=1, login=1)
|
roxywi_common.logging('Roxy-WI server', f'The SSH credentials {name} has deleted', roxywi=1, login=1)
|
||||||
|
|
|
@ -1558,7 +1558,7 @@ if form.getvalue('telegramdel') is not None:
|
||||||
import modules.alerting.alerting as alerting
|
import modules.alerting.alerting as alerting
|
||||||
|
|
||||||
channel_id = common.checkAjaxInput(form.getvalue('telegramdel'))
|
channel_id = common.checkAjaxInput(form.getvalue('telegramdel'))
|
||||||
telegram = sql.select_telegram(id=telegramdel)
|
telegram = sql.select_telegram(id=channel_id)
|
||||||
|
|
||||||
alerting.delete_telegram_channel(telegram, channel_id)
|
alerting.delete_telegram_channel(telegram, channel_id)
|
||||||
|
|
||||||
|
@ -1568,7 +1568,7 @@ if form.getvalue('slackdel') is not None:
|
||||||
channel_id = common.checkAjaxInput(form.getvalue('slackdel'))
|
channel_id = common.checkAjaxInput(form.getvalue('slackdel'))
|
||||||
slack = sql.select_slack(id=channel_id)
|
slack = sql.select_slack(id=channel_id)
|
||||||
|
|
||||||
alerting.delete_slack_channel(telegram, channel_id)
|
alerting.delete_slack_channel(slack, channel_id)
|
||||||
|
|
||||||
if form.getvalue('updatetoken') is not None:
|
if form.getvalue('updatetoken') is not None:
|
||||||
token = common.checkAjaxInput(form.getvalue('updatetoken'))
|
token = common.checkAjaxInput(form.getvalue('updatetoken'))
|
||||||
|
@ -1979,28 +1979,7 @@ if form.getvalue('scan_ports') is not None:
|
||||||
print(template)
|
print(template)
|
||||||
|
|
||||||
if form.getvalue('viewFirewallRules') is not None:
|
if form.getvalue('viewFirewallRules') is not None:
|
||||||
serv = common.checkAjaxInput(form.getvalue('viewFirewallRules'))
|
server_mod.show_firewalld_rules()
|
||||||
|
|
||||||
cmd = ["sudo iptables -L INPUT -n --line-numbers|sed 's/ */ /g'|grep -v -E 'Chain|target'"]
|
|
||||||
cmd1 = ["sudo iptables -L IN_public_allow -n --line-numbers|sed 's/ */ /g'|grep -v -E 'Chain|target'"]
|
|
||||||
cmd2 = ["sudo iptables -L OUTPUT -n --line-numbers|sed 's/ */ /g'|grep -v -E 'Chain|target'"]
|
|
||||||
|
|
||||||
input_chain = server_mod.ssh_command(serv, cmd, raw=1)
|
|
||||||
|
|
||||||
input_chain2 = []
|
|
||||||
for each_line in input_chain:
|
|
||||||
input_chain2.append(each_line.strip('\n'))
|
|
||||||
|
|
||||||
if 'error:' in input_chain:
|
|
||||||
print(input_chain)
|
|
||||||
sys.exit()
|
|
||||||
|
|
||||||
IN_public_allow = server_mod.ssh_command(serv, cmd1, raw=1)
|
|
||||||
output_chain = server_mod.ssh_command(serv, cmd2, raw=1)
|
|
||||||
env = Environment(loader=FileSystemLoader('templates'))
|
|
||||||
template = env.get_template('ajax/firewall_rules.html')
|
|
||||||
template = template.render(input=input_chain2, IN_public_allow=IN_public_allow, output=output_chain)
|
|
||||||
print(template)
|
|
||||||
|
|
||||||
if form.getvalue('geoipserv') is not None:
|
if form.getvalue('geoipserv') is not None:
|
||||||
serv = common.checkAjaxInput(form.getvalue('geoipserv'))
|
serv = common.checkAjaxInput(form.getvalue('geoipserv'))
|
||||||
|
|
Loading…
Reference in New Issue