Pavel Loginov 2020-10-06 11:34:22 +06:00
parent 8d22fe5087
commit 05e3009d86
2 changed files with 24 additions and 24 deletions

View File

@ -78,9 +78,9 @@ def logging(serv, action, **kwargs):
os.makedirs(log_path)
try:
IP = cgi.escape(os.environ["REMOTE_ADDR"])
ip = cgi.escape(os.environ["REMOTE_ADDR"])
except:
IP = ''
ip = ''
try:
user_uuid = cookie.get('uuid')
@ -99,14 +99,14 @@ def logging(serv, action, **kwargs):
log = open(log_path + "/keep_alive-"+get_data('logs')+".log", "a")
elif kwargs.get('haproxywi') == 1:
if kwargs.get('login'):
mess = get_data('date_in_log') + " from " + IP + " user: " + login + ", group: " +user_group + ", " + \
action + " for: " + serv + "\n"
mess = get_data('date_in_log') + " from " + ip + " user: " + login + ", group: " + user_group + ", " + \
action + " for: " + serv + "\n"
else:
mess = get_data('date_in_log') + " " + action + " from " + IP + "\n"
mess = get_data('date_in_log') + " " + action + " from " + ip + "\n"
log = open(log_path + "/haproxy-wi-"+get_data('logs')+".log", "a")
else:
mess = get_data('date_in_log') + " from " + IP + " user: " + login + ", group: " +user_group + ", " + \
action + " for: " + serv + "\n"
mess = get_data('date_in_log') + " from " + ip + " user: " + login + ", group: " + user_group + ", " + \
action + " for: " + serv + "\n"
log = open(log_path + "/config_edit-"+get_data('logs')+".log", "a")
try:
log.write(mess)
@ -349,8 +349,8 @@ def get_sections(config, **kwargs):
line.startswith('resolvers') or
line.startswith('userlist')
):
line = line.strip()
return_config.append(line)
line = line.strip()
return_config.append(line)
return return_config
@ -382,9 +382,9 @@ def get_section_from_config(config, section):
line.startswith('resolvers') or
line.startswith('userlist')
):
record = False
end_line = index
end_line = end_line - 1
record = False
end_line = index
end_line = end_line - 1
else:
return_config += line
@ -589,9 +589,9 @@ def install_nginx(serv):
syn_flood_protect = '1' if form.getvalue('syn_flood') == "1" else ''
commands = ["chmod +x " + script + " && ./" + script + " PROXY=" + proxy_serv + " STATS_USER=" + stats_user +
" STATS_PASS=" + stats_password + " SSH_PORT="+ ssh_port + " CONFIG_PATH=" + config_path +
" STAT_PORT=" + stats_port +" STAT_PAGE=" + stats_page+" SYN_FLOOD=" + syn_flood_protect +
" HOST="+ serv + " USER=" + ssh_user_name + " PASS=" + ssh_user_password + " KEY=" + ssh_key_name]
" STATS_PASS=" + stats_password + " SSH_PORT=" + ssh_port + " CONFIG_PATH=" + config_path +
" STAT_PORT=" + stats_port + " STAT_PAGE=" + stats_page+" SYN_FLOOD=" + syn_flood_protect +
" HOST=" + serv + " USER=" + ssh_user_name + " PASS=" + ssh_user_password + " KEY=" + ssh_key_name]
output, error = subprocess_execute(commands[0])
@ -618,7 +618,7 @@ def install_nginx(serv):
def update_haproxy_wi(service):
if service != 'haproxy-wi':
service = 'haprxoy-wi-'+service
service = 'haproxy-wi-'+service
cmd = 'sudo -S yum -y update '+service
output, stderr = subprocess_execute(cmd)
print(output)
@ -743,7 +743,7 @@ def master_slave_upload_and_restart(serv, cfg, just_save, **kwargs):
masters = sql.is_master(serv)
error = ""
for master in masters:
if master[0] != None:
if master[0] is not None:
error += upload_and_restart(master[0], cfg, just_save=just_save, nginx=kwargs.get('nginx'))
error += upload_and_restart(serv, cfg, just_save=just_save, nginx=kwargs.get('nginx'))
@ -927,7 +927,7 @@ def haproxy_wi_log(**kwargs):
user_group_id = get_user_group(id=1)
if user_group_id != 1:
user_group = get_user_group()
group_grep = '|grep "group: '+ user_group +'"'
group_grep = '|grep "group: ' + user_group + '"'
else:
group_grep = ''
cmd = "find "+log_path+"/haproxy-wi-* -type f -exec stat --format '%Y :%y %n' '{}' \; | sort -nr | cut -d: -f2- | head -1 |awk '{print $4}' |xargs tail"+group_grep+"|sort -r"
@ -973,7 +973,7 @@ def ssh_command(serv, commands, **kwargs):
elif kwargs.get('print_out'):
print(stdout.read().decode(encoding='UTF-8'))
return stdout.read().decode(encoding='UTF-8')
elif kwargs.get('retunr_err') == 1:
elif kwargs.get('return_err') == 1:
return stderr.read().decode(encoding='UTF-8')
else:
return stdout.read().decode(encoding='UTF-8')
@ -1111,7 +1111,7 @@ def versions():
new_ver_without_dots = new_ver.split('.')
new_ver_without_dots = ''.join(new_ver_without_dots)
new_ver_without_dots = new_ver_without_dots.replace('\n', '')
if len(new_ver_without_dots) == 2:
if len(new_ver_without_dots) == 2:
new_ver_without_dots += '00'
if len(new_ver_without_dots) == 3:
new_ver_without_dots += '0'

View File

@ -1,7 +1,7 @@
CREATE TABLE IF NOT EXISTS `user` (`id` INTEGER NOT NULL AUTO_INCREMENT,`username` VARCHAR ( 64 ) UNIQUE,`email` VARCHAR ( 120 ) UNIQUE, `password` VARCHAR ( 128 ),`role` VARCHAR ( 128 ),`groups` VARCHAR ( 120 ), ldap_user INTEGER NOT NULL DEFAULT 0, activeuser INTEGER NOT NULL DEFAULT 1, PRIMARY KEY(`id`) );
INSERT INTO `user` (username, email, password, role, groups) VALUES ('admin','admin@localhost','21232f297a57a5a743894a0e4a801fc3','admin','1');
INSERT INTO `user` (username, email, password, role, groups) VALUES ('editor','editor@localhost','5aee9dbd2a188839105073571bee1b1f','editor','1');
INSERT INTO `user` (username, email, password, role, groups) VALUES ('guest','guest@localhost','084e0343a0486ff05530df6c705c8bb4','guest','1');
INSERT INTO `user` (username, email, password, role, `groups`) VALUES ('admin','admin@localhost','21232f297a57a5a743894a0e4a801fc3','admin','1');
INSERT INTO `user` (username, email, password, role, `groups`) VALUES ('editor','editor@localhost','5aee9dbd2a188839105073571bee1b1f','editor','1');
INSERT INTO `user` (username, email, password, role, `groups`) VALUES ('guest','guest@localhost','084e0343a0486ff05530df6c705c8bb4','guest','1');
CREATE TABLE IF NOT EXISTS `servers` (`id` INTEGER NOT NULL AUTO_INCREMENT,`hostname` VARCHAR ( 64 ),`ip` VARCHAR ( 64 ) UNIQUE,`groups` VARCHAR ( 64 ), type_ip INTEGER NOT NULL DEFAULT 0, enable INTEGER NOT NULL DEFAULT 1, master INTEGER NOT NULL DEFAULT 0, cred INTEGER NOT NULL DEFAULT 1, alert INTEGER NOT NULL DEFAULT 0, metrics INTEGER NOT NULL DEFAULT 0, port INTEGER NOT NULL DEFAULT 22, `desc` varchar(64), active INTEGER NOT NULL DEFAULT 0,PRIMARY KEY(`id`) );
CREATE TABLE IF NOT EXISTS `role` (`id` INTEGER NOT NULL AUTO_INCREMENT,`name` VARCHAR ( 80 ) UNIQUE,`description` VARCHAR ( 255 ),PRIMARY KEY(`id`) );
INSERT INTO `role` (name, description) VALUES ('admin','Can do everything');
@ -11,7 +11,7 @@ CREATE TABLE IF NOT EXISTS `groups` (`id` INTEGER NOT NULL AUTO_INCREMENT,`name`
INSERT INTO `groups` (name, description) VALUES ('All','All servers enter in this group');
CREATE TABLE IF NOT EXISTS `uuid` (`user_id` INTEGER NOT NULL, `uuid` varchar ( 64 ),`exp` DATETIME default CURRENT_TIMESTAMP);
CREATE TABLE IF NOT EXISTS `token` (`user_id` INTEGER, `token` varchar(64), `exp` timestamp default CURRENT_TIMESTAMP);
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, 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 `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), value varchar(64), section varchar(64), `desc` varchar(100), `group` INTEGER NOT NULL DEFAULT 1, UNIQUE(param, `group`));