Pavel Loginov 5 years ago
parent 548d61db59
commit 85acd08eae

@ -385,6 +385,8 @@ def update_db_v_3_13(**kwargs):
def update_db_v_4(**kwargs):
con, cur = get_cur()
sql = list()
sql.append("update settings set section = 'main', `desc` = 'Temp store configs, for check' where param = 'tmp_config_path';")
sql.append("update settings set section = 'main' where param = 'cert_path';")
sql.append("INSERT INTO settings (param, value, section, `desc`) values('nginx_path_error_logs', '/var/log/nginx/error.log', 'nginx', 'Nginx error log');")
sql.append("INSERT INTO settings (param, value, section, `desc`) values('nginx_stats_user', 'admin', 'nginx', 'Username for Stats web page Nginx');")
sql.append("INSERT INTO settings (param, value, section, `desc`) values('nginx_stats_password', 'password', 'nginx', 'Password for Stats web page Nginx');")
@ -395,6 +397,7 @@ def update_db_v_4(**kwargs):
sql.append("INSERT INTO settings (param, value, section, `desc`) values('nginx_status_command', 'systemctl status nginx', 'nginx', 'Command for status check Nginx service');")
sql.append("INSERT INTO settings (param, value, section, `desc`) values('nginx_dir', '/etc/nginx/conf.d/', 'nginx', 'Path to Nginx dir');")
sql.append("INSERT INTO settings (param, value, section, `desc`) values('nginx_config_path', '/etc/nginx/conf.d/default.conf', 'nginx', 'Path to Nginx config');")
sql.append("update `servers` set `haproxy` = '1';")
for i in sql:
try:
cur.execute(i)
@ -411,27 +414,30 @@ def update_db_v_4(**kwargs):
def update_db_v_41(**kwargs):
con, cur = get_cur()
sql = list()
sql.append("update settings set section = 'main', `desc` = 'Temp store configs, for check' where param = 'tmp_config_path';")
sql.append("update settings set section = 'main' where param = 'cert_path';")
for i in sql:
try:
cur.execute(i)
con.commit()
except sqltool.Error as e:
pass
else:
sql = """
ALTER TABLE `servers` ADD COLUMN nginx INTEGER NOT NULL DEFAULT 0;
"""
try:
cur.execute(sql)
con.commit()
except sqltool.Error as e:
if kwargs.get('silent') != 1:
print('Updating... one more for version 4.0.0')
if e.args[0] == 'duplicate column name: nginx' or e == " 1060 (42S21): Duplicate column name 'nginx' ":
print('Updating... one more for version 4.0.0')
else:
print("An error occurred:", e)
return False
else:
print("Updating... one more for version 4.0.0")
return True
cur.close()
con.close()
def update_db_v_42(**kwargs):
con, cur = get_cur()
sql = """
ALTER TABLE `servers` ADD COLUMN nginx INTEGER NOT NULL DEFAULT 0;
ALTER TABLE `servers` ADD COLUMN haproxy INTEGER NOT NULL DEFAULT 0;
"""
try:
cur.execute(sql)

@ -415,6 +415,7 @@ def install_haproxy(serv, **kwargs):
print('success: HAProxy was installed<br>')
os.system("rm -f %s" % script)
sql.update_haproxy(serv)
def waf_install(serv, **kwargs):
@ -446,7 +447,8 @@ def waf_install(serv, **kwargs):
sql.insert_waf_metrics_enable(serv, "0")
def install_nginx():
def install_nginx(serv):
import sql
script = "install_nginx.sh"
stats_user = sql.get_setting('nginx_stats_user')
stats_password = sql.get_setting('nginx_stats_password')

@ -39,7 +39,7 @@ else:
servers = sql.select_servers(server=serv)
autorefresh = 1
else:
servers = sql.get_dick_permit(virt=1)
servers = sql.get_dick_permit(virt=1, haproxy=1)
haproxy_sock_port = sql.get_setting('haproxy_sock_port')
servers_with_status1 = []

@ -534,6 +534,7 @@ def get_dick_permit(**kwargs):
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
user_id = cookie.get('uuid')
disable = ''
haproxy = ''
nginx = ''
ip = ''
@ -550,6 +551,8 @@ def get_dick_permit(**kwargs):
disable = 'or enable = 0'
if kwargs.get('ip'):
ip = "and ip = '%s'" % kwargs.get('ip')
if kwargs.get('haproxy'):
haproxy = "and haproxy = 1"
if kwargs.get('nginx'):
nginx = "and nginx = 1"
@ -562,13 +565,15 @@ def get_dick_permit(**kwargs):
if group[5] == '1':
sql = """ select * from servers where enable = 1 %s %s %s """ % (disable, type_ip, nginx)
else:
sql = """ select * from servers where groups like '%{group}%' and (enable = 1 {disable}) {type_ip} {ip} {nginx} """.format(group=group[5], disable=disable, type_ip=type_ip, ip=ip, nginx=nginx)
sql = """ select * from servers where groups like '%{group}%' and (enable = 1 {disable}) {type_ip} {ip} {haproxy} {nginx}
""".format(group=group[5], disable=disable, type_ip=type_ip, ip=ip, haproxy=haproxy, nginx=nginx)
try:
cur.execute(sql)
except sqltool.Error as e:
out_error(e)
else:
return cur.fetchall()
cur.close()
con.close()
@ -1550,6 +1555,21 @@ def update_nginx(serv):
con.close()
def update_haproxy(serv):
con, cur = get_cur()
sql = """update `servers` set `haproxy` = '1' where ip = '%s' """ % serv
try:
cur.execute(sql)
con.commit()
return True
except sqltool.Error as e:
out_error(e)
con.rollback()
return False
cur.close()
con.close()
def check_token_exists(token):
try:
import http.cookies

Loading…
Cancel
Save