Browse Source

v6.3.1.0

Changelog: https://roxy-wi.org/changelog#6_3_1
pull/355/head
Pavel Loginov 2 years ago
parent
commit
d67dd351d5
  1. 70
      app/add.py
  2. 9
      app/modules/alerting/alerting.py
  3. 22
      app/modules/config/runtime.py
  4. 32
      app/options.py

70
app/add.py

@ -19,7 +19,7 @@ get_config_var = roxy_wi_tools.GetConfigVar()
env = Environment(loader=FileSystemLoader('templates/'), autoescape=True) env = Environment(loader=FileSystemLoader('templates/'), autoescape=True)
template = env.get_template('add.html') template = env.get_template('add.html')
form = common.form form = common.form
serv = form.getvalue('serv') serv = common.is_ip_or_dns(form.getvalue('serv'))
print('Content-type: text/html\n') print('Content-type: text/html\n')
@ -75,7 +75,7 @@ elif form.getvalue('mode') is not None:
ip = "" ip = ""
force_close = form.getvalue('force_close') force_close = form.getvalue('force_close')
balance = "" balance = ""
mode = " mode " + form.getvalue('mode') + "\n" mode = f" mode {form.getvalue('mode')}\n"
maxconn = "" maxconn = ""
options_split = "" options_split = ""
ssl = "" ssl = ""
@ -94,34 +94,34 @@ elif form.getvalue('mode') is not None:
health_check = form.getvalue('health_check') health_check = form.getvalue('health_check')
if health_check == 'option httpchk' and form.getvalue('checks_http_domain') is not None: if health_check == 'option httpchk' and form.getvalue('checks_http_domain') is not None:
health_check = health_check + ' GET ' + form.getvalue('checks_http_path') + ' "HTTP/1.0\\r\\nHost: ' + form.getvalue('checks_http_domain') + '"' health_check = health_check + ' GET ' + form.getvalue('checks_http_path') + ' "HTTP/1.0\\r\\nHost: ' + form.getvalue('checks_http_domain') + '"'
balance += " " + health_check + "\n" balance += f" {health_check}\n"
if form.getvalue('ip') is not None: if form.getvalue('ip') is not None:
ip = form.getlist('ip') ip = form.getlist('ip')
if new_listener is not None: if new_listener is not None:
name = "listen " + new_listener name = f"listen {new_listener}"
end_name = new_listener end_name = new_listener
elif new_frontend is not None: elif new_frontend is not None:
name = "frontend " + new_frontend name = f"frontend {new_frontend}"
end_name = new_frontend end_name = new_frontend
elif new_backend is not None: elif new_backend is not None:
name = "backend " + new_backend name = f"backend {new_backend}"
end_name = new_backend end_name = new_backend
else: else:
print('error: The name cannot be empty') print('error: The name cannot be empty')
sys.exit() sys.exit()
if form.getvalue('backends') is not None: if form.getvalue('backends') is not None:
backend = " default_backend " + form.getvalue('backends') + "\n" backend = f" default_backend { form.getvalue('backends')}\n"
if form.getvalue('maxconn'): if form.getvalue('maxconn'):
maxconn = " maxconn " + form.getvalue('maxconn') + "\n" maxconn = f" maxconn {form.getvalue('maxconn')}\n"
if form.getvalue('ssl') == "https" and form.getvalue('mode') != "tcp": if form.getvalue('ssl') == "https" and form.getvalue('mode') != "tcp":
cert_path = sql.get_setting('cert_path') cert_path = sql.get_setting('cert_path')
if form.getvalue('cert') is not None: if form.getvalue('cert') is not None:
ssl = "ssl crt " + cert_path + form.getvalue('cert') ssl = f"ssl crt {cert_path}{form.getvalue('cert')}"
if form.getvalue('ssl-dis-check') is None: if form.getvalue('ssl-dis-check') is None:
if form.getvalue('ssl-check') == "ssl-check": if form.getvalue('ssl-check') == "ssl-check":
ssl_check = " ssl verify none" ssl_check = " ssl verify none"
@ -138,32 +138,32 @@ elif form.getvalue('mode') is not None:
continue continue
else: else:
port_value = port[i] port_value = port[i]
bind += " bind *:" + port_value + " " + ssl + "\n" bind += f" bind *:{port_value} {ssl}\n"
else: else:
if port[i] == 'IsEmptY': if port[i] == 'IsEmptY':
print('error: IP cannot be bind without a port') print('error: IP cannot be bind without a port')
sys.exit() sys.exit()
else: else:
port_value = port[i] port_value = port[i]
bind += " bind " + ip[i] + ":" + port_value + " " + ssl + "\n" bind += f" bind {ip[i]}:{port_value} {ssl}\n"
i += 1 i += 1
if form.getvalue('default-check') == "1": if form.getvalue('default-check') == "1":
if form.getvalue('check-servers') == "1": if form.getvalue('check-servers') == "1":
check = " check inter " + form.getvalue('inter') + " rise " + form.getvalue('rise') + " fall " + form.getvalue('fall') + ssl_check check = f" check inter {form.getvalue('inter')} rise {form.getvalue('rise')} fall {form.getvalue('fall')}{ssl_check}"
else: else:
check = "" check = ""
else: else:
if form.getvalue('check-servers') != "1": if form.getvalue('check-servers') != "1":
check = "" check = ""
else: else:
check = " check" + ssl_check check = f" check{ssl_check}"
if form.getvalue('option') is not None: if form.getvalue('option') is not None:
options = form.getvalue('option') options = form.getvalue('option')
i = options.split("\n") i = options.split("\n")
for j in i: for j in i:
options_split += " " + j + "\n" options_split += f" {j}\n"
if force_close == "1": if force_close == "1":
options_split += " option http-server-close\n" options_split += " option http-server-close\n"
@ -181,9 +181,9 @@ elif form.getvalue('mode') is not None:
'blacklist') + " }\n" 'blacklist') + " }\n"
if form.getvalue('cookie'): if form.getvalue('cookie'):
cookie = " cookie " + form.getvalue('cookie_name') cookie = f" cookie {form.getvalue('cookie_name')}"
if form.getvalue('cookie_domain'): if form.getvalue('cookie_domain'):
cookie += " domain " + form.getvalue('cookie_domain') cookie += f" domain {form.getvalue('cookie_domain')}"
if form.getvalue('rewrite'): if form.getvalue('rewrite'):
rewrite = form.getvalue('rewrite') rewrite = form.getvalue('rewrite')
else: else:
@ -204,10 +204,10 @@ elif form.getvalue('mode') is not None:
dynamic = form.getvalue('dynamic') dynamic = form.getvalue('dynamic')
else: else:
dynamic = "" dynamic = ""
cookie += " " + rewrite + " " + prefix + " " + nocache + " " + postonly + " " + dynamic + "\n" cookie += f" {rewrite} {prefix} {nocache} {postonly} {dynamic}\n"
options_split += cookie options_split += cookie
if form.getvalue('dynamic'): if form.getvalue('dynamic'):
options_split += " dynamic-cookie-key " + form.getvalue('dynamic-cookie-key') + "\n" options_split += f" dynamic-cookie-key {form.getvalue('dynamic-cookie-key')}\n"
if form.getvalue('acl_if'): if form.getvalue('acl_if'):
acl_if = form.getlist('acl_if') acl_if = form.getlist('acl_if')
@ -324,27 +324,27 @@ elif form.getvalue('mode') is not None:
if compression == "1" or cache == "2": if compression == "1" or cache == "2":
filter_com = " filter compression\n" filter_com = " filter compression\n"
if cache == "2": if cache == "2":
cache_s = " http-request cache-use " + end_name + "\n http-response cache-store " + end_name + "\n" cache_s = f" http-request cache-use {end_name}\n http-response cache-store {end_name}\n"
cache_set = "cache " + end_name + "\n total-max-size 4\n max-age 240\n" cache_set = f"cache {end_name}\n total-max-size 4\n max-age 240\n"
if compression == "1": if compression == "1":
compression_s = " compression algo gzip\n compression type text/html text/plain text/css\n" compression_s = " compression algo gzip\n compression type text/html text/plain text/css\n"
waf = "" waf = ""
if form.getvalue('waf') is not None: if form.getvalue('waf') is not None:
waf = " filter spoe engine modsecurity config " + haproxy_dir + "/waf.conf\n" waf = f" filter spoe engine modsecurity config {haproxy_dir}/waf.conf\n"
waf += " http-request deny if { var(txn.modsec.code) -m int gt 0 }\n" waf += " http-request deny if { var(txn.modsec.code) -m int gt 0 }\n"
config_add = "\n" + name + "\n" + bind + mode + maxconn + balance + options_split + cache_s + filter_com + \ config_add = f"\n{name}\n{bind}{mode}{maxconn}{balance}{options_split}{cache_s}{filter_com}{compression_s}" \
compression_s + waf + acl + backend + servers_split + "\n" + cache_set + "\n" f"{waf}{acl}{backend}{servers_split}\n{cache_set}\n"
if form.getvalue('new_userlist') is not None: if form.getvalue('new_userlist') is not None:
name = "userlist " + form.getvalue('new_userlist') + "\n" name = f"userlist {form.getvalue('new_userlist')}\n"
new_userlist_groups = "" new_userlist_groups = ""
if form.getvalue('userlist-group') is not None: if form.getvalue('userlist-group') is not None:
groups = form.getlist('userlist-group') groups = form.getlist('userlist-group')
for group in groups: for group in groups:
new_userlist_groups += " group " + group + "\n" new_userlist_groups += f" group {group}\n"
new_users_list = "" new_users_list = ""
if form.getvalue('userlist-user') is not None: if form.getvalue('userlist-user') is not None:
@ -355,10 +355,10 @@ if form.getvalue('new_userlist') is not None:
for user in users: for user in users:
try: try:
group = ' groups ' + userlist_user_group[i] group = f' groups {userlist_user_group[i]}'
except Exception: except Exception:
group = '' group = ''
new_users_list += " user " + user + " insecure-password " + passwords[i] + group + "\n" new_users_list += f" user {user} insecure-password { passwords[i]} {group}\n"
i += 1 i += 1
config_add = "\n" + name + new_userlist_groups + new_users_list config_add = "\n" + name + new_userlist_groups + new_users_list
@ -396,18 +396,22 @@ if form.getvalue('generateconfig') is None and serv is not None:
try: try:
with open(cfg, "a") as conf: with open(cfg, "a") as conf:
conf.write(config_add) conf.write(config_add)
except IOError: except IOError as e:
print("error: Can't read import config file") print(f"error: Can't read import config file {e}")
roxywi_common.logging(serv, "add.py add new %s" % name)
output = config_mod.master_slave_upload_and_restart(serv, cfg, just_save="save") output = config_mod.master_slave_upload_and_restart(serv, cfg, just_save="save")
try:
roxywi_common.logging(serv, f"add.py add new {name}")
except Exception:
pass
if output: if output:
print(output) print(output)
else: else:
print(name) print(name)
except Exception: except Exception as e:
pass print(e)
else: else:
print(config_add) print(config_add)

9
app/modules/alerting/alerting.py

@ -246,16 +246,17 @@ def add_slack_channel(token: str, channel: str, group: str, page: str) -> None:
login=1) login=1)
def delete_telegram_channel(telegram, channel_id) -> None: def delete_telegram_channel(channel_id) -> None:
telegram = sql.select_telegram(id=channel_id)
for t in telegram: for t in telegram:
telegram_name = t.token telegram_name = t.token
if sql.delete_telegram(channel_id): if sql.delete_telegram(channel_id):
print("Ok") print("Ok")
roxywi_common.logging('Roxy-WI server', f'The Telegram channel {telegram_name} has been deleted ', roxywi=1, roxywi_common.logging('Roxy-WI server', f'The Telegram channel {telegram_name} has been deleted ', roxywi=1, login=1)
login=1)
def delete_slack_channel(slack, channel_id) -> None: def delete_slack_channel(channel_id) -> None:
slack = sql.select_slack(id=channel_id)
for t in slack: for t in slack:
slack_name = t.chanel_name slack_name = t.chanel_name
if sql.delete_slack(channel_id): if sql.delete_slack(channel_id):

22
app/modules/config/runtime.py

@ -14,6 +14,28 @@ get_date = roxy_wi_tools.GetDate(time_zone)
get_config_var = roxy_wi_tools.GetConfigVar() get_config_var = roxy_wi_tools.GetConfigVar()
def show_frontend_backend() -> None:
haproxy_sock_port = int(sql.get_setting('haproxy_sock_port'))
backend = common.checkAjaxInput(form.getvalue('ipbackend'))
cmd = 'echo "show servers state"|nc %s %s |grep "%s" |awk \'{print $4}\'' % (serv, haproxy_sock_port, backend)
output, stderr = server_mod.subprocess_execute(cmd)
for i in output:
if i == ' ':
continue
i = i.strip()
print(i + '<br>')
def show_server() -> None:
haproxy_sock_port = int(sql.get_setting('haproxy_sock_port'))
backend = common.checkAjaxInput(form.getvalue('ipbackend'))
backend_server = common.checkAjaxInput(form.getvalue('backend_server'))
cmd = 'echo "show servers state"|nc %s %s |grep "%s" |grep "%s" |awk \'{print $5":"$19}\' |head -1' % (
serv, haproxy_sock_port, backend, backend_server)
output, stderr = server_mod.subprocess_execute(cmd)
print(output[0])
def get_all_stick_table(): def get_all_stick_table():
hap_sock_p = sql.get_setting('haproxy_sock_port') hap_sock_p = sql.get_setting('haproxy_sock_port')
cmd = 'echo "show table"|nc %s %s |awk \'{print $3}\' | tr -d \'\n\' | tr -d \'[:space:]\'' % (serv, hap_sock_p) cmd = 'echo "show table"|nc %s %s |awk \'{print $3}\' | tr -d \'\n\' | tr -d \'[:space:]\'' % (serv, hap_sock_p)

32
app/options.py

@ -91,24 +91,14 @@ if form.getvalue('ip_select') is not None:
runtime.show_backends(serv) runtime.show_backends(serv)
if form.getvalue('ipbackend') is not None and form.getvalue('backend_server') is None: if form.getvalue('ipbackend') is not None and form.getvalue('backend_server') is None:
haproxy_sock_port = int(sql.get_setting('haproxy_sock_port')) import modules.config.runtime as runtime
backend = common.checkAjaxInput(form.getvalue('ipbackend'))
cmd = 'echo "show servers state"|nc %s %s |grep "%s" |awk \'{print $4}\'' % (serv, haproxy_sock_port, backend) runtime.show_frontend_backend()
output, stderr = server_mod.subprocess_execute(cmd)
for i in output:
if i == ' ':
continue
i = i.strip()
print(i + '<br>')
if form.getvalue('ipbackend') is not None and form.getvalue('backend_server') is not None: if form.getvalue('ipbackend') is not None and form.getvalue('backend_server') is not None:
haproxy_sock_port = int(sql.get_setting('haproxy_sock_port')) import modules.config.runtime as runtime
backend = common.checkAjaxInput(form.getvalue('ipbackend'))
backend_server = common.checkAjaxInput(form.getvalue('backend_server')) runtime.show_server()
cmd = 'echo "show servers state"|nc %s %s |grep "%s" |grep "%s" |awk \'{print $5":"$19}\' |head -1' % (
serv, haproxy_sock_port, backend, backend_server)
output, stderr = server_mod.subprocess_execute(cmd)
print(output[0])
if form.getvalue('backend_ip') is not None: if form.getvalue('backend_ip') is not None:
import modules.config.runtime as runtime import modules.config.runtime as runtime
@ -180,8 +170,8 @@ if form.getvalue('session_delete_id') is not None:
runtime.delete_session() runtime.delete_session()
if form.getvalue("change_pos") is not None: if form.getvalue("change_pos") is not None:
pos = form.getvalue('change_pos') pos = common.checkAjaxInput(form.getvalue('change_pos'))
server_id = form.getvalue('pos_server_id') server_id = common.checkAjaxInput(form.getvalue('pos_server_id'))
sql.update_server_pos(pos, server_id) sql.update_server_pos(pos, server_id)
if form.getvalue('show_ip') is not None and serv is not None: if form.getvalue('show_ip') is not None and serv is not None:
@ -1558,17 +1548,15 @@ 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=channel_id)
alerting.delete_telegram_channel(telegram, channel_id) alerting.delete_telegram_channel(channel_id)
if form.getvalue('slackdel') is not None: if form.getvalue('slackdel') is not None:
import modules.alerting.alerting as alerting import modules.alerting.alerting as alerting
channel_id = common.checkAjaxInput(form.getvalue('slackdel')) channel_id = common.checkAjaxInput(form.getvalue('slackdel'))
slack = sql.select_slack(id=channel_id)
alerting.delete_slack_channel(slack, channel_id) alerting.delete_slack_channel(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'))

Loading…
Cancel
Save