Pavel Loginov 2021-06-15 13:25:30 +06:00
parent 4a74ce394d
commit adbec8a967
3 changed files with 97 additions and 23 deletions

View File

@ -14,7 +14,12 @@ print('Content-type: text/html\n')
funct.check_login() funct.check_login()
funct.page_for_admin(level=3) funct.page_for_admin(level=3)
if form.getvalue('mode') is None and form.getvalue('new_userlist') is None: if (
form.getvalue('mode') is None and
form.getvalue('new_userlist') is None and
form.getvalue('peers-name') is None and
form.getvalue('generateconfig') is None
):
try: try:
user, user_id, role, token, servers = funct.get_users_params() user, user_id, role, token, servers = funct.get_users_params()
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE")) cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
@ -54,7 +59,6 @@ if form.getvalue('mode') is None and form.getvalue('new_userlist') is None:
print(template) print(template)
elif form.getvalue('mode') is not None: elif form.getvalue('mode') is not None:
cert_path = sql.get_setting('cert_path')
haproxy_dir = sql.get_setting('haproxy_dir') haproxy_dir = sql.get_setting('haproxy_dir')
port = form.getvalue('port') port = form.getvalue('port')
bind = "" bind = ""
@ -69,7 +73,7 @@ elif form.getvalue('mode') is not None:
backend = "" backend = ""
acl = "" acl = ""
servers_split = "" servers_split = ""
if form.getvalue('balance') is not None: if form.getvalue('balance') is not None:
balance = " balance " + form.getvalue('balance') + "\n" balance = " balance " + form.getvalue('balance') + "\n"
@ -94,22 +98,25 @@ elif form.getvalue('mode') is not None:
if form.getvalue('backends') is not None: if form.getvalue('backends') is not None:
backend = " default_backend " + form.getvalue('backends') + "\n" backend = " default_backend " + form.getvalue('backends') + "\n"
if form.getvalue('maxconn'): if form.getvalue('maxconn'):
maxconn = " maxconn " + form.getvalue('maxconn') + "\n" maxconn = " 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":
ssl = "ssl crt " + cert_path + form.getvalue('cert') cert_path = sql.get_setting('cert_path')
if form.getvalue('ssl-check') == "ssl-check": if form.getvalue('cert') is not None:
ssl_check = " ssl verify none" ssl = "ssl crt " + cert_path + form.getvalue('cert')
else: if form.getvalue('ssl-dis-check') is None:
ssl_check = " ssl verify" if form.getvalue('ssl-check') == "ssl-check":
ssl_check = " ssl verify none"
else:
ssl_check = " ssl verify"
if not ip and port is not None: if not ip and port is not None:
bind = " bind *:" + port + " " + ssl + "\n" bind = " bind *:" + port + " " + ssl + "\n"
elif port is not None: elif port is not None:
bind = " bind " + ip + ":" + port + " " + ssl + "\n" bind = " bind " + ip + ":" + port + " " + ssl + "\n"
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 = " check inter " + form.getvalue('inter') + " rise " + form.getvalue('rise') + " fall " + form.getvalue('fall') + ssl_check
@ -120,13 +127,13 @@ elif form.getvalue('mode') is not None:
check = "" check = ""
else: else:
check = " check" + ssl_check check = " 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 += " " + j + "\n"
if force_close == "1": if force_close == "1":
options_split += " option http-server-close\n" options_split += " option http-server-close\n"
elif force_close == "2": elif force_close == "2":
@ -275,7 +282,7 @@ elif form.getvalue('mode') is not None:
server_port[i], server_port[i],
check) check)
i += 1 i += 1
compression = form.getvalue("compression") compression = form.getvalue("compression")
cache = form.getvalue("cache") cache = form.getvalue("cache")
compression_s = "" compression_s = ""
@ -289,23 +296,23 @@ elif form.getvalue('mode') is not None:
cache_set = "cache "+end_name+"\n total-max-size 4\n max-age 240\n" cache_set = "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 = " 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 + compression_s + waf + acl + backend + servers_split + "\n" + cache_set + "\n" config_add = "\n" + name + "\n" + bind + mode + maxconn + balance + options_split + cache_s + filter_com + compression_s + 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 = "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 += " 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:
users = form.getlist('userlist-user') users = form.getlist('userlist-user')
@ -323,6 +330,22 @@ if form.getvalue('new_userlist') is not None:
config_add = "\n" + name + new_userlist_groups + new_users_list config_add = "\n" + name + new_userlist_groups + new_users_list
if form.getvalue('peers-name') is not None:
name = "peers " + form.getvalue('peers-name') + "\n"
servers_split = ''
if form.getvalue('servers') is not None:
servers = form.getlist('servers')
server_port = form.getlist('server_port')
servers_name = form.getlist('servers_name')
i = 0
for server in servers:
servers_split += " peer {0} {1}:{2} \n".format(servers_name[i], server, server_port[i])
i += 1
config_add = "\n" + name + servers_split
if form.getvalue('generateconfig') is None: if form.getvalue('generateconfig') is None:
try: try:
funct.check_is_server_in_group(serv) funct.check_is_server_in_group(serv)

View File

@ -1251,9 +1251,26 @@ def update_db_v_5_1_3(**kwargs):
con.close() con.close()
def update_db_v_5_2_0(**kwargs):
con, cur = get_cur()
sql = list()
sql.append("INSERT INTO settings (param, value, section, `desc`) values('portscanner_keep_history_range', '14', 'monitoring', 'How many days to keep the history for the Port scanner service')")
for i in sql:
try:
cur.execute(i)
con.commit()
except sqltool.Error as e:
pass
else:
if kwargs.get('silent') != 1:
print('Updating... DB has been updated to version 5.2.0')
cur.close()
con.close()
def update_ver(): def update_ver():
con, cur = get_cur() con, cur = get_cur()
sql = """update version set version = '5.1.4.0'; """ sql = """update version set version = '5.2.0.0'; """
try: try:
cur.execute(sql) cur.execute(sql)
con.commit() con.commit()
@ -1296,6 +1313,7 @@ def update_all():
update_db_v_5_1_1() update_db_v_5_1_1()
update_db_v_5_1_2() update_db_v_5_1_2()
update_db_v_5_1_3() update_db_v_5_1_3()
update_db_v_5_2_0()
update_ver() update_ver()
@ -1332,6 +1350,7 @@ def update_all_silent():
update_db_v_5_1_1(silent=1) update_db_v_5_1_1(silent=1)
update_db_v_5_1_2(silent=1) update_db_v_5_1_2(silent=1)
update_db_v_5_1_3(silent=1) update_db_v_5_1_3(silent=1)
update_db_v_5_2_0(silent=1)
update_ver() update_ver()

View File

@ -82,7 +82,29 @@ $( function() {
} else { } else {
$( "#https-hide-backend" ).hide( "fast" ); $( "#https-hide-backend" ).hide( "fast" );
} }
}); });
$( "#ssl-dis-check-listen" ).click( function(){
if ($('#ssl-dis-check-listen').is(':checked')) {
$( "#ssl-check-listen" ).checkboxradio( "disable" );
$( "#ssl-check-listen" ).prop( "checked", false );
$( "#ssl-check-listen" ).checkboxradio("refresh");
} else {
$( "#ssl-check-listen" ).checkboxradio( "enable" );
$( "#ssl-check-listen" ).prop( "checked", true );
$( "#ssl-check-listen" ).checkboxradio("refresh");
}
});
$( "#ssl-dis-check-backend" ).click( function(){
if ($('#ssl-dis-check-backend').is(':checked')) {
$( "#ssl-check-backend" ).checkboxradio( "disable" );
$( "#ssl-check-backend" ).prop( "checked", false );
$( "#ssl-check-backend" ).checkboxradio("refresh");
} else {
$( "#ssl-check-backend" ).checkboxradio( "enable" );
$( "#ssl-check-backend" ).prop( "checked", true );
$( "#ssl-check-backend" ).checkboxradio("refresh");
}
});
$( "#options-listen-show" ).click( function(){ $( "#options-listen-show" ).click( function(){
if ($('#options-listen-show').is(':checked')) { if ($('#options-listen-show').is(':checked')) {
$( "#options-listen-show-div" ).show( "fast" ); $( "#options-listen-show-div" ).show( "fast" );
@ -967,7 +989,7 @@ $( function() {
} }
}); });
var add_server_var = '<br /><input name="servers" title="Backend IP" size=14 placeholder="xxx.xxx.xxx.xxx" class="form-control second-server">: ' + var add_server_var = '<br /><input name="servers" title="Backend IP" size=14 placeholder="xxx.xxx.xxx.xxx" class="form-control second-server">: ' +
'<input name="server_port" required title="Backend IP" size=3 placeholder="yyy" class="form-control second-server add_server_number" type="number">' + '<input name="server_port" required title="Backend port" size=3 placeholder="yyy" class="form-control second-server add_server_number" type="number">' +
'<input name="server_maxconn" required title="Maxconn. Default 200" size=5 value="200" class="form-control add_server_number" type="number">' '<input name="server_maxconn" required title="Maxconn. Default 200" size=5 value="200" class="form-control add_server_number" type="number">'
$('[name=add-server-input]').click(function() { $('[name=add-server-input]').click(function() {
$("[name=add_servers]").append(add_server_var); $("[name=add_servers]").append(add_server_var);
@ -980,6 +1002,12 @@ $( function() {
$('#add-userlist-group').click(function() { $('#add-userlist-group').click(function() {
$('#userlist-groups').append(add_userlist_group_var); $('#userlist-groups').append(add_userlist_group_var);
}); });
var add_peer_var = '<br /><input name="servers_name" required title="Peer name" size=14 placeholder="haproxyN" class="form-control">' +
'<input name="servers" title="Backend IP" size=14 placeholder="xxx.xxx.xxx.xxx" class="form-control second-server">: ' +
'<input name="server_port" required title="Backend port" size=3 placeholder="yyy" class="form-control second-server add_server_number" type="number">'
$('[name=add-peer-input]').click(function() {
$("[name=add_peers]").append(add_peer_var);
});
$('.advance-show-button').click(function() { $('.advance-show-button').click(function() {
$('.advance').fadeIn(); $('.advance').fadeIn();
$('.advance-show-button').css('display', 'none'); $('.advance-show-button').css('display', 'none');
@ -1206,6 +1234,7 @@ function resetProxySettings() {
$('[name=server_port]').val(''); $('[name=server_port]').val('');
$('input:checkbox').prop( "checked", false ); $('input:checkbox').prop( "checked", false );
$('[name=ssl-check]').prop( "checked", true ); $('[name=ssl-check]').prop( "checked", true );
$('[name=ssl-dis-check]').prop( "checked", false );
$('[name=check-servers]').prop( "checked", true ); $('[name=check-servers]').prop( "checked", true );
$('input:checkbox').checkboxradio("refresh"); $('input:checkbox').checkboxradio("refresh");
$('.advance-show').fadeIn(); $('.advance-show').fadeIn();
@ -1237,7 +1266,10 @@ function createSsl(TabId, proxy) {
$( "#tabs" ).tabs( "option", "active", TabId ); $( "#tabs" ).tabs( "option", "active", TabId );
$( "#https-hide-"+proxy).show("fast"); $( "#https-hide-"+proxy).show("fast");
$('#https-'+proxy).prop( "checked", true ); $('#https-'+proxy).prop( "checked", true );
$('#https-'+proxy).checkboxradio("refresh"); $('#ssl-dis-check-'+proxy).prop( "checked", true );
$('#ssl-check-'+proxy).prop( "checked", false );
$('#ssl-check-'+proxy).checkboxradio('disable');
$('input:checkbox').checkboxradio("refresh");
$("#path-cert-"+proxy ).attr('required',true); $("#path-cert-"+proxy ).attr('required',true);
if (TabId == 1) { if (TabId == 1) {
TabId = ''; TabId = '';