|
|
@ -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) |
|
|
|