fix
This commit is contained in:
@@ -8,84 +8,95 @@ main_bp = Blueprint('main', __name__)
|
|||||||
@requires_auth
|
@requires_auth
|
||||||
def index():
|
def index():
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
frontend_name = request.form['frontend_name']
|
f = request.form.get
|
||||||
frontend_ip = request.form['frontend_ip']
|
gl = request.form.getlist
|
||||||
frontend_port = request.form['frontend_port']
|
has = lambda k: k in request.form
|
||||||
lb_method = request.form['lb_method']
|
|
||||||
protocol = request.form['protocol']
|
|
||||||
backend_name = request.form['backend_name']
|
|
||||||
add_header = 'add_header' in request.form if 'add_header' in request.form else ''
|
|
||||||
header_name = request.form['header_name']
|
|
||||||
header_value = request.form['header_value']
|
|
||||||
|
|
||||||
# Get all backend servers data
|
frontend_name = (f('frontend_name', '') or '').strip()
|
||||||
backend_server_names = request.form.getlist('backend_server_names[]')
|
frontend_ip = (f('frontend_ip', '') or '').strip()
|
||||||
backend_server_ips = request.form.getlist('backend_server_ips[]')
|
frontend_port = (f('frontend_port', '') or '').strip()
|
||||||
backend_server_ports = request.form.getlist('backend_server_ports[]')
|
lb_method = f('lb_method', 'roundrobin')
|
||||||
backend_server_maxconns = request.form.getlist('backend_server_maxconns[]')
|
protocol = f('protocol', '') # 'http' / 'tcp'
|
||||||
|
|
||||||
is_acl = 'add_acl' in request.form
|
backend_name = (f('backend_name', '') or '').strip()
|
||||||
acl_name = request.form['acl'] if 'acl' in request.form else ''
|
|
||||||
acl_action = request.form['acl_action'] if 'acl_action' in request.form else ''
|
|
||||||
acl_backend_name = request.form['backend_name_acl'] if 'backend_name_acl' in request.form else ''
|
|
||||||
use_ssl = 'ssl_checkbox' in request.form
|
|
||||||
ssl_cert_path = request.form['ssl_cert_path']
|
|
||||||
https_redirect = 'ssl_redirect_checkbox' in request.form
|
|
||||||
is_dos = 'add_dos' in request.form if 'add_dos' in request.form else ''
|
|
||||||
ban_duration = request.form["ban_duration"]
|
|
||||||
limit_requests = request.form["limit_requests"]
|
|
||||||
forward_for = 'forward_for_check' in request.form
|
|
||||||
|
|
||||||
is_forbidden_path = 'add_acl_path' in request.form
|
add_header = has('add_header')
|
||||||
forbidden_name = request.form["forbidden_name"]
|
header_name = (f('header_name', '') or '').strip() if add_header else ''
|
||||||
allowed_ip = request.form["allowed_ip"]
|
header_value= (f('header_value', '') or '').strip() if add_header else ''
|
||||||
forbidden_path = request.form["forbidden_path"]
|
|
||||||
|
|
||||||
sql_injection_check = 'sql_injection_check' in request.form if 'sql_injection_check' in request.form else ''
|
backend_server_names = gl('backend_server_names[]')
|
||||||
is_xss = 'xss_check' in request.form if 'xss_check' in request.form else ''
|
backend_server_ips = gl('backend_server_ips[]')
|
||||||
is_remote_upload = 'remote_uploads_check' in request.form if 'remote_uploads_check' in request.form else ''
|
backend_server_ports = gl('backend_server_ports[]')
|
||||||
|
backend_server_maxconns= gl('backend_server_maxconns[]')
|
||||||
|
|
||||||
add_path_based = 'add_path_based' in request.form
|
is_acl = has('add_acl')
|
||||||
redirect_domain_name = request.form["redirect_domain_name"]
|
acl_name = (f('acl', '') or '').strip() if is_acl else ''
|
||||||
root_redirect = request.form["root_redirect"]
|
acl_action = (f('acl_action', '') or '').strip() if is_acl else ''
|
||||||
redirect_to = request.form["redirect_to"]
|
acl_backend_name= (f('backend_name_acl', '') or '').strip() if is_acl else ''
|
||||||
is_webshells = 'webshells_check' in request.form if 'webshells_check' in request.form else ''
|
|
||||||
|
use_ssl = has('ssl_checkbox')
|
||||||
|
ssl_cert_path = (f('ssl_cert_path', '') or '').strip() if use_ssl else ''
|
||||||
|
https_redirect= has('ssl_redirect_checkbox') and use_ssl
|
||||||
|
|
||||||
|
is_dos = has('add_dos')
|
||||||
|
ban_duration = (f('ban_duration', '') or '').strip() if is_dos else ''
|
||||||
|
limit_requests= (f('limit_requests', '') or '').strip() if is_dos else ''
|
||||||
|
|
||||||
|
forward_for = has('forward_for_check') and protocol == 'http'
|
||||||
|
|
||||||
|
is_forbidden_path = has('add_acl_path') and protocol == 'http'
|
||||||
|
forbidden_name = (f('forbidden_name', '') or '').strip() if is_forbidden_path else ''
|
||||||
|
allowed_ip = (f('allowed_ip', '') or '').strip() if is_forbidden_path else ''
|
||||||
|
forbidden_path = (f('forbidden_path', '') or '').strip() if is_forbidden_path else ''
|
||||||
|
|
||||||
|
if protocol == 'http':
|
||||||
|
sql_injection_check = has('sql_injection_check')
|
||||||
|
is_xss = has('xss_check')
|
||||||
|
is_remote_upload = has('remote_uploads_check')
|
||||||
|
is_webshells = has('webshells_check')
|
||||||
|
else:
|
||||||
|
sql_injection_check = False
|
||||||
|
is_xss = False
|
||||||
|
is_remote_upload = False
|
||||||
|
is_webshells = False
|
||||||
|
|
||||||
|
add_path_based = has('add_path_based') and protocol == 'http'
|
||||||
|
redirect_domain_name = (f('redirect_domain_name', '') or '').strip() if add_path_based else ''
|
||||||
|
root_redirect = (f('root_redirect', '/') or '/').strip() if add_path_based else ''
|
||||||
|
redirect_to = (f('redirect_to', '') or '').strip() if add_path_based else ''
|
||||||
|
|
||||||
|
if protocol == 'http':
|
||||||
|
health_check = has('health_check')
|
||||||
|
health_check_link = (f('health_check_link', '') or '').strip() if health_check else ''
|
||||||
|
health_check_tcp = False
|
||||||
|
elif protocol == 'tcp':
|
||||||
|
health_check = False
|
||||||
|
health_check_link = ""
|
||||||
|
health_check_tcp = has('health_check2')
|
||||||
|
else:
|
||||||
|
health_check = False
|
||||||
|
health_check_link = ""
|
||||||
|
health_check_tcp = False
|
||||||
|
|
||||||
|
sticky_session = has('sticky_session')
|
||||||
|
sticky_session_type = (f('sticky_session_type', '') or '').strip() if sticky_session else ''
|
||||||
|
|
||||||
# Combine backend server info into a list of tuples (name, ip, port, maxconns)
|
|
||||||
backend_servers = []
|
backend_servers = []
|
||||||
for i in range(len(backend_server_ips)):
|
max_len = max(len(backend_server_ips), len(backend_server_ports), len(backend_server_names), len(backend_server_maxconns))
|
||||||
name = backend_server_names[i] if i < len(backend_server_names) else f"server{i+1}"
|
for i in range(max_len):
|
||||||
ip = backend_server_ips[i] if i < len(backend_server_ips) else ''
|
name = backend_server_names[i] if i < len(backend_server_names) else f"server{i+1}"
|
||||||
port = backend_server_ports[i] if i < len(backend_server_ports) else ''
|
ip = backend_server_ips[i] if i < len(backend_server_ips) else ''
|
||||||
maxconn = backend_server_maxconns[i] if i < len(backend_server_maxconns) else None
|
port = backend_server_ports[i] if i < len(backend_server_ports) else ''
|
||||||
|
maxc = backend_server_maxconns[i] if i < len(backend_server_maxconns) else None
|
||||||
|
if ip and port:
|
||||||
|
backend_servers.append((name, ip, port, maxc))
|
||||||
|
|
||||||
if ip and port: # Only add if we have IP and port
|
if not frontend_name or not frontend_ip or not frontend_port or not backend_name:
|
||||||
backend_servers.append((name, ip, port, maxconn))
|
return render_template('index.html', message="Brak wymaganych pól (nazwa/IP/port frontendu, nazwa backendu).")
|
||||||
|
|
||||||
# Check if frontend or port already exists
|
|
||||||
if is_frontend_exist(frontend_name, frontend_ip, frontend_port):
|
if is_frontend_exist(frontend_name, frontend_ip, frontend_port):
|
||||||
return render_template('index.html', message="Frontend or Port already exists. Cannot add duplicate.")
|
return render_template('index.html', message="Frontend or Port already exists. Cannot add duplicate.")
|
||||||
|
|
||||||
# Get health check related fields if the protocol is HTTP
|
|
||||||
health_check = False
|
|
||||||
health_check_link = ""
|
|
||||||
if protocol == 'http':
|
|
||||||
health_check = 'health_check' in request.form
|
|
||||||
if health_check:
|
|
||||||
health_check_link = request.form['health_check_link']
|
|
||||||
|
|
||||||
health_check_tcp = False
|
|
||||||
if protocol == 'tcp':
|
|
||||||
health_check_tcp = 'health_check2' in request.form
|
|
||||||
|
|
||||||
# Get sticky session related fields
|
|
||||||
sticky_session = False
|
|
||||||
sticky_session_type = ""
|
|
||||||
if 'sticky_session' in request.form:
|
|
||||||
sticky_session = True
|
|
||||||
sticky_session_type = request.form['sticky_session_type']
|
|
||||||
|
|
||||||
# Update the HAProxy config file
|
|
||||||
message = update_haproxy_config(
|
message = update_haproxy_config(
|
||||||
frontend_name, frontend_ip, frontend_port, lb_method, protocol, backend_name,
|
frontend_name, frontend_ip, frontend_port, lb_method, protocol, backend_name,
|
||||||
backend_servers, health_check, health_check_tcp, health_check_link, sticky_session,
|
backend_servers, health_check, health_check_tcp, health_check_link, sticky_session,
|
||||||
@@ -98,14 +109,3 @@ def index():
|
|||||||
return render_template('index.html', message=message)
|
return render_template('index.html', message=message)
|
||||||
|
|
||||||
return render_template('index.html')
|
return render_template('index.html')
|
||||||
|
|
||||||
@main_bp.route('/home')
|
|
||||||
@requires_auth
|
|
||||||
def home():
|
|
||||||
frontend_count, backend_count, acl_count, layer7_count, layer4_count = count_frontends_and_backends()
|
|
||||||
return render_template('home.html',
|
|
||||||
frontend_count=frontend_count,
|
|
||||||
backend_count=backend_count,
|
|
||||||
acl_count=acl_count,
|
|
||||||
layer7_count=layer7_count,
|
|
||||||
layer4_count=layer4_count)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user