Pavel Loginov 2020-08-10 18:01:12 +02:00
parent 3a7e242e4d
commit afa0827d4c
5 changed files with 63 additions and 12 deletions

View File

@ -125,7 +125,7 @@ def create_table(**kwargs):
CREATE TABLE IF NOT EXISTS `token` (`user_id` INTEGER, `token` varchar(64), `exp` timestamp default '0000-00-00 00:00:00'); CREATE TABLE IF NOT EXISTS `token` (`user_id` INTEGER, `token` varchar(64), `exp` timestamp default '0000-00-00 00:00:00');
CREATE TABLE IF NOT EXISTS `telegram` (`id` integer primary key autoincrement, `token` VARCHAR ( 64 ), `chanel_name` INTEGER NOT NULL DEFAULT 1, `groups` INTEGER NOT NULL DEFAULT 1); CREATE TABLE IF NOT EXISTS `telegram` (`id` integer primary key autoincrement, `token` VARCHAR ( 64 ), `chanel_name` INTEGER NOT NULL DEFAULT 1, `groups` INTEGER NOT NULL DEFAULT 1);
CREATE TABLE IF NOT EXISTS `metrics` (`serv` varchar(64), curr_con INTEGER, cur_ssl_con INTEGER, sess_rate INTEGER, max_sess_rate INTEGER,`date` timestamp default '0000-00-00 00:00:00'); CREATE TABLE IF NOT EXISTS `metrics` (`serv` varchar(64), curr_con INTEGER, cur_ssl_con INTEGER, sess_rate INTEGER, max_sess_rate INTEGER,`date` timestamp default '0000-00-00 00:00:00');
CREATE TABLE IF NOT EXISTS `settings` (`param` varchar(64) UNIQUE, value varchar(64), section varchar(64), `desc` varchar(100)); CREATE TABLE IF NOT EXISTS `settings` (`param` varchar(64) UNIQUE, value varchar(64), section varchar(64), `desc` varchar(100), `group` INTEGER NOT NULL DEFAULT 1);
CREATE TABLE IF NOT EXISTS `version` (`version` varchar(64)); CREATE TABLE IF NOT EXISTS `version` (`version` varchar(64));
CREATE TABLE IF NOT EXISTS `options` ( `id` INTEGER NOT NULL, `options` VARCHAR ( 64 ), `groups` VARCHAR ( 120 ), PRIMARY KEY(`id`)); CREATE TABLE IF NOT EXISTS `options` ( `id` INTEGER NOT NULL, `options` VARCHAR ( 64 ), `groups` VARCHAR ( 120 ), PRIMARY KEY(`id`));
CREATE TABLE IF NOT EXISTS `saved_servers` ( `id` INTEGER NOT NULL, `server` VARCHAR ( 64 ), `description` VARCHAR ( 120 ), `groups` VARCHAR ( 120 ), PRIMARY KEY(`id`)); CREATE TABLE IF NOT EXISTS `saved_servers` ( `id` INTEGER NOT NULL, `server` VARCHAR ( 64 ), `description` VARCHAR ( 120 ), `groups` VARCHAR ( 120 ), PRIMARY KEY(`id`));
@ -573,7 +573,7 @@ def update_db_v_4_4(**kwargs):
except sqltool.Error as e: except sqltool.Error as e:
if kwargs.get('silent') != 1: if kwargs.get('silent') != 1:
if e.args[0] == 'duplicate column name: pos' or e == " 1060 (42S21): Duplicate column name 'pos' ": if e.args[0] == 'duplicate column name: pos' or e == " 1060 (42S21): Duplicate column name 'pos' ":
print('Updating... go to version 4.4.2') print('Updating... go to version 4.4.1')
else: else:
print("An error occurred:", e) print("An error occurred:", e)
return False return False
@ -599,14 +599,36 @@ def update_db_v_4_4_2(**kwargs):
except sqltool.Error as e: except sqltool.Error as e:
if kwargs.get('silent') != 1: if kwargs.get('silent') != 1:
if e.args[0] == 'duplicate column name: version' or e == "1060 (42S21): Duplicate column name 'version' ": if e.args[0] == 'duplicate column name: version' or e == "1060 (42S21): Duplicate column name 'version' ":
print('DB was update to 4.4.2') print('Updating... go to version 4.4.1')
else: else:
print("DB was update to 4.4.2") print("Updating... go to version to 4.4.1")
return False return False
else: else:
return True return True
cur.close() cur.close()
con.close() con.close()
def update_db_v_4_4_2_1(**kwargs):
con, cur = get_cur()
sql = """
ALTER TABLE `settings` ADD COLUMN `group` INTEGER NOT NULL DEFAULT 1;
"""
try:
cur.execute(sql)
con.commit()
except sqltool.Error as e:
if kwargs.get('silent') != 1:
if e.args[0] == 'duplicate column name: group' or e == " 1060 (42S21): Duplicate column name 'group' ":
print('Updating... go to version 4.4.2')
else:
print("An error occurred:", e)
return False
else:
print("DB was update to 4.4.2")
return True
cur.close()
con.close()
def update_ver(**kwargs): def update_ver(**kwargs):
@ -642,6 +664,7 @@ def update_all():
update_db_v_4_3_2() update_db_v_4_3_2()
update_db_v_4_4() update_db_v_4_4()
update_db_v_4_4_2() update_db_v_4_4_2()
update_db_v_4_4_2_1()
update_ver() update_ver()
@ -666,10 +689,10 @@ def update_all_silent():
update_db_v_4_3_2(silent=1) update_db_v_4_3_2(silent=1)
update_db_v_4_4(silent=1) update_db_v_4_4(silent=1)
update_db_v_4_4_2(silent=1) update_db_v_4_4_2(silent=1)
update_db_v_4_4_2_1(silent=1)
update_ver() update_ver()
if __name__ == "__main__": if __name__ == "__main__":
create_table() create_table()
update_all() update_all()

View File

@ -14,7 +14,7 @@ CREATE TABLE IF NOT EXISTS `token` (`user_id` INTEGER, `token` varchar(64), `exp
CREATE TABLE IF NOT EXISTS `cred` (`id` integer primary key AUTO_INCREMENT, `name` VARCHAR ( 64 ), `enable` INTEGER NOT NULL DEFAULT 1, `username` VARCHAR ( 64 ) NOT NULL, `password` VARCHAR ( 64 ) NOT NULL, groups INTEGER NOT NULL DEFAULT 1, CREATE TABLE IF NOT EXISTS `cred` (`id` integer primary key AUTO_INCREMENT, `name` VARCHAR ( 64 ), `enable` INTEGER NOT NULL DEFAULT 1, `username` VARCHAR ( 64 ) NOT NULL, `password` VARCHAR ( 64 ) NOT NULL, groups INTEGER NOT NULL DEFAULT 1, UNIQUE(name,groups)); CREATE TABLE IF NOT EXISTS `cred` (`id` integer primary key AUTO_INCREMENT, `name` VARCHAR ( 64 ), `enable` INTEGER NOT NULL DEFAULT 1, `username` VARCHAR ( 64 ) NOT NULL, `password` VARCHAR ( 64 ) NOT NULL, groups INTEGER NOT NULL DEFAULT 1, CREATE TABLE IF NOT EXISTS `cred` (`id` integer primary key AUTO_INCREMENT, `name` VARCHAR ( 64 ), `enable` INTEGER NOT NULL DEFAULT 1, `username` VARCHAR ( 64 ) NOT NULL, `password` VARCHAR ( 64 ) NOT NULL, groups INTEGER NOT NULL DEFAULT 1, UNIQUE(name,groups));
CREATE TABLE IF NOT EXISTS `telegram` (`id` integer primary key auto_increment, `token` VARCHAR ( 64 ), `chanel_name` INTEGER NOT NULL DEFAULT 1, `groups` INTEGER NOT NULL DEFAULT 1); CREATE TABLE IF NOT EXISTS `telegram` (`id` integer primary key auto_increment, `token` VARCHAR ( 64 ), `chanel_name` INTEGER NOT NULL DEFAULT 1, `groups` INTEGER NOT NULL DEFAULT 1);
CREATE TABLE IF NOT EXISTS `metrics` (`serv` varchar(64), curr_con INTEGER, cur_ssl_con INTEGER, sess_rate INTEGER, max_sess_rate INTEGER,`date` DATETIME default '0000-00-00 00:00:00'); CREATE TABLE IF NOT EXISTS `metrics` (`serv` varchar(64), curr_con INTEGER, cur_ssl_con INTEGER, sess_rate INTEGER, max_sess_rate INTEGER,`date` DATETIME default '0000-00-00 00:00:00');
CREATE TABLE IF NOT EXISTS `settings` (`param` varchar(64) UNIQUE, value varchar(64), section varchar(64), `desc` varchar(100)); CREATE TABLE IF NOT EXISTS `settings` (`param` varchar(64) UNIQUE, value varchar(64), section varchar(64), `desc` varchar(100), `group` INTEGER NOT NULL DEFAULT 1);
CREATE TABLE IF NOT EXISTS `version` (`version` varchar(64)); CREATE TABLE IF NOT EXISTS `version` (`version` varchar(64));
CREATE TABLE IF NOT EXISTS `options` ( `id` INTEGER NOT NULL, `options` VARCHAR ( 64 ), `groups` VARCHAR ( 120 ), PRIMARY KEY(`id`)); CREATE TABLE IF NOT EXISTS `options` ( `id` INTEGER NOT NULL, `options` VARCHAR ( 64 ), `groups` VARCHAR ( 120 ), PRIMARY KEY(`id`));
CREATE TABLE IF NOT EXISTS `saved_servers` ( `id` INTEGER NOT NULL, `server` VARCHAR ( 64 ), `description` VARCHAR ( 120 ), `groups` VARCHAR ( 120 ), PRIMARY KEY(`id`)); CREATE TABLE IF NOT EXISTS `saved_servers` ( `id` INTEGER NOT NULL, `server` VARCHAR ( 64 ), `description` VARCHAR ( 120 ), `groups` VARCHAR ( 120 ), PRIMARY KEY(`id`));

View File

@ -37,4 +37,10 @@ listen stats
stats uri /stats stats uri /stats
stats realm HAProxy-04\ Statistics stats realm HAProxy-04\ Statistics
stats auth {{STATS_USER}}:{{STATS_PASS}} stats auth {{STATS_USER}}:{{STATS_PASS}}
stats admin if TRUE stats admin if TRUE
backend per_ip_and_url_rates
stick-table type binary len 8 size 1m expire 24h store http_req_rate(24h)
backend per_ip_rates
stick-table type ip size 1m expire 24h store gpc0,gpc0_rate(30s)

View File

@ -121,6 +121,7 @@ h3 {
{{ checkbox('ddos', title='DDOS atack protect', desc='DDOS') }} {{ checkbox('ddos', title='DDOS atack protect', desc='DDOS') }}
{{ checkbox('blacklist_checkbox', title='Use blacklist', desc='Blacklist') }} {{ checkbox('blacklist_checkbox', title='Use blacklist', desc='Blacklist') }}
{{ checkbox('waf', title='Web application firewall', desc='WAF', value='1') }} {{ checkbox('waf', title='Web application firewall', desc='WAF', value='1') }}
{{ checkbox('antibot', title='Antibot Protection', desc='Antibot', value='1') }}
</span> </span>
<div id="blacklist-hide" style="display: none;"> <div id="blacklist-hide" style="display: none;">
<br /><span class="tooltip tooltipTop">Enter the name of the blacklist, or press down:</span><br /> <br /><span class="tooltip tooltipTop">Enter the name of the blacklist, or press down:</span><br />
@ -207,7 +208,7 @@ h3 {
</tr> </tr>
<tr class="advance-show"> <tr class="advance-show">
<td class="addName">Advanced:</td> <td class="addName">Advanced:</td>
<td class="addOption"><a href="#" title="Show Advanced settings">Show Advanced settings</a></td> <td class="addOption"><span title="Show Advanced settings" style="cursor: pointer">Show Advanced settings</span></td>
</tr> </tr>
<tr> <tr>
<td class="addButton"> <td class="addButton">
@ -307,6 +308,7 @@ h3 {
{{ checkbox('ddos1', title='DDOS atack protect', desc='DDOS') }} {{ checkbox('ddos1', title='DDOS atack protect', desc='DDOS') }}
{{ checkbox('blacklist_checkbox1', title='Use blacklist', desc='Blacklist') }} {{ checkbox('blacklist_checkbox1', title='Use blacklist', desc='Blacklist') }}
{{ checkbox('waf2', name='waf', title='Web application firewall', desc='WAF', value='1') }} {{ checkbox('waf2', name='waf', title='Web application firewall', desc='WAF', value='1') }}
{{ checkbox('antibot1', title='Antibot Protection', desc='Antibot', value='1') }}
</span> </span>
<div id="blacklist-hide1" style="display: none;"> <div id="blacklist-hide1" style="display: none;">
<br /><span class="tooltip tooltipTop">Enter the name of the blacklist, or press down:</span><br /> <br /><span class="tooltip tooltipTop">Enter the name of the blacklist, or press down:</span><br />
@ -351,7 +353,7 @@ h3 {
</tr> </tr>
<tr class="advance-show"> <tr class="advance-show">
<td class="addName">Advanced:</td> <td class="addName">Advanced:</td>
<td class="addOption"><a href="#" title="Show Advanced settings">Show Advanced settings</a></td> <td class="addOption"><span title="Show Advanced settings" style="cursor: pointer">Show Advanced settings</span></td>
</tr> </tr>
<tr> <tr>
<td class="addButton"> <td class="addButton">
@ -511,7 +513,7 @@ h3 {
</tr> </tr>
<tr class="advance-show"> <tr class="advance-show">
<td class="addName">Advanced:</td> <td class="addName">Advanced:</td>
<td class="addOption"><a href="#" title="Show Advanced settings">Show Advanced settings</a></td> <td class="addOption"><span title="Show Advanced settings" style="cursor: pointer">Show Advanced settings</span></td>
</tr> </tr>
<tr> <tr>
<td class="addButton"> <td class="addButton">

View File

@ -603,9 +603,29 @@ $( function() {
} }
} else { } else {
replace_text("#optionsInput1", ddos_var); replace_text("#optionsInput1", ddos_var);
} }
});
var antibot_var = "#Start config for Antibot protection\n"+
"http-request track-sc0 src table per_ip_rates\n" +
"http-request track-sc1 url32+src table per_ip_and_url_rates unless { path_end .css .js .png .jpeg .gif }\n" +
"acl exceeds_limit sc_gpc0_rate(0) gt 15 \n" +
"http-request sc-inc-gpc0(0) if { sc_http_req_rate(1) eq 1 } !exceeds_limit\n" +
"http-request deny if exceeds_limit\n" +
"#End config for Antibot\n";
$('#antibot').click(function() {
if($('#optionsInput').val().indexOf(antibot_var) == '-1') {
$("#optionsInput").append(antibot_var)
} else {
replace_text("#optionsInput", antibot_var);
}
});
$('#antibot1').click(function() {
if($('#optionsInput1').val().indexOf(antibot_var) == '-1') {
$("#optionsInput1").append(antibot_var)
} else {
replace_text("#optionsInput1", antibot_var);
}
}); });
$( "#blacklist_checkbox" ).click( function(){ $( "#blacklist_checkbox" ).click( function(){
if ($('#blacklist_checkbox').is(':checked')) { if ($('#blacklist_checkbox').is(':checked')) {
$( "#blacklist-hide" ).show( "fast" ); $( "#blacklist-hide" ).show( "fast" );