mirror of https://github.com/Aidaho12/haproxy-wi
parent
2aaa1c3169
commit
669794a5a8
63
app/funct.py
63
app/funct.py
|
@ -186,7 +186,6 @@ def is_admin(**kwargs):
|
||||||
return True if role <= level else False
|
return True if role <= level else False
|
||||||
except Exception:
|
except Exception:
|
||||||
return False
|
return False
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def page_for_admin(**kwargs):
|
def page_for_admin(**kwargs):
|
||||||
|
@ -477,7 +476,27 @@ def get_stick_table(table):
|
||||||
output, stderr = subprocess_execute(cmd)
|
output, stderr = subprocess_execute(cmd)
|
||||||
|
|
||||||
return tables_head, output
|
return tables_head, output
|
||||||
|
|
||||||
|
|
||||||
|
def show_installation_output(error, output, service):
|
||||||
|
if error:
|
||||||
|
if "WARNING" not in error:
|
||||||
|
logging('localhost', error, haproxywi=1)
|
||||||
|
print('error: '+error)
|
||||||
|
else:
|
||||||
|
for l in output:
|
||||||
|
if "msg" in l or "FAILED" in l:
|
||||||
|
try:
|
||||||
|
l = l.split(':')[1]
|
||||||
|
l = l.split('"')[1]
|
||||||
|
print(l)
|
||||||
|
break
|
||||||
|
except Exception:
|
||||||
|
print(output)
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
print('success: ' + service + ' has been installed')
|
||||||
|
|
||||||
|
|
||||||
def install_haproxy(serv, **kwargs):
|
def install_haproxy(serv, **kwargs):
|
||||||
import sql
|
import sql
|
||||||
|
@ -518,24 +537,9 @@ def install_haproxy(serv, **kwargs):
|
||||||
" HOST=" + serv + " USER=" + ssh_user_name + " PASS=" + ssh_user_password + " KEY=" + ssh_key_name]
|
" HOST=" + serv + " USER=" + ssh_user_name + " PASS=" + ssh_user_password + " KEY=" + ssh_key_name]
|
||||||
|
|
||||||
output, error = subprocess_execute(commands[0])
|
output, error = subprocess_execute(commands[0])
|
||||||
|
|
||||||
if error:
|
show_installation_output(error, output, 'HAProxy')
|
||||||
logging('localhost', error, haproxywi=1)
|
|
||||||
print('error: '+error)
|
|
||||||
else:
|
|
||||||
for l in output:
|
|
||||||
if "msg" in l or "FAILED" in l:
|
|
||||||
try:
|
|
||||||
l = l.split(':')[1]
|
|
||||||
l = l.split('"')[1]
|
|
||||||
print(l+"<br>")
|
|
||||||
break
|
|
||||||
except Exception:
|
|
||||||
print(output)
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
print('success: HAProxy was installed<br>')
|
|
||||||
|
|
||||||
os.system("rm -f %s" % script)
|
os.system("rm -f %s" % script)
|
||||||
sql.update_haproxy(serv)
|
sql.update_haproxy(serv)
|
||||||
|
|
||||||
|
@ -603,23 +607,8 @@ def install_nginx(serv):
|
||||||
" HOST=" + serv + " USER=" + ssh_user_name + " PASS=" + ssh_user_password + " KEY=" + ssh_key_name]
|
" HOST=" + serv + " USER=" + ssh_user_name + " PASS=" + ssh_user_password + " KEY=" + ssh_key_name]
|
||||||
|
|
||||||
output, error = subprocess_execute(commands[0])
|
output, error = subprocess_execute(commands[0])
|
||||||
|
|
||||||
if error:
|
show_installation_output(error, output, 'Nginx')
|
||||||
logging('localhost', error, haproxywi=1)
|
|
||||||
print('error: '+error)
|
|
||||||
else:
|
|
||||||
for l in output:
|
|
||||||
if "msg" in l or "FAILED" in l:
|
|
||||||
try:
|
|
||||||
l = l.split(':')[1]
|
|
||||||
l = l.split('"')[1]
|
|
||||||
print(l+"<br>")
|
|
||||||
break
|
|
||||||
except Exception:
|
|
||||||
print(output)
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
print('success: Nginx was installed<br>')
|
|
||||||
|
|
||||||
os.system("rm -f %s" % script)
|
os.system("rm -f %s" % script)
|
||||||
sql.update_nginx(serv)
|
sql.update_nginx(serv)
|
||||||
|
|
109
app/options.py
109
app/options.py
|
@ -960,22 +960,7 @@ if form.getvalue('master'):
|
||||||
|
|
||||||
output, error = funct.subprocess_execute(commands[0])
|
output, error = funct.subprocess_execute(commands[0])
|
||||||
|
|
||||||
if error:
|
funct.show_installation_output(error, output, 'Master Keepalived')
|
||||||
funct.logging('localhost', error, haproxywi=1)
|
|
||||||
print('error: ' + error)
|
|
||||||
else:
|
|
||||||
for l in output:
|
|
||||||
if "msg" in l or "FAILED" in l:
|
|
||||||
try:
|
|
||||||
l = l.split(':')[1]
|
|
||||||
l = l.split('"')[1]
|
|
||||||
print(l + "<br>")
|
|
||||||
break
|
|
||||||
except Exception:
|
|
||||||
print(output)
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
print('success: Master Keepalived was installed<br>')
|
|
||||||
|
|
||||||
ssh_enable, ssh_user_name, ssh_user_password, ssh_key_name = funct.return_ssh_keys_path(slave)
|
ssh_enable, ssh_user_name, ssh_user_password, ssh_key_name = funct.return_ssh_keys_path(slave)
|
||||||
|
|
||||||
|
@ -992,22 +977,7 @@ if form.getvalue('master'):
|
||||||
|
|
||||||
output, error = funct.subprocess_execute(commands[0])
|
output, error = funct.subprocess_execute(commands[0])
|
||||||
|
|
||||||
if error:
|
funct.show_installation_output(error, output, 'Slave Keepalived')
|
||||||
funct.logging('localhost', error, haproxywi=1)
|
|
||||||
print('error: ' + error)
|
|
||||||
else:
|
|
||||||
for l in output:
|
|
||||||
if "msg" in l or "FAILED" in l:
|
|
||||||
try:
|
|
||||||
l = l.split(':')[1]
|
|
||||||
l = l.split('"')[1]
|
|
||||||
print(l + "<br>")
|
|
||||||
break
|
|
||||||
except Exception:
|
|
||||||
print(output)
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
print('success: Slave Keepalived was installed<br>')
|
|
||||||
|
|
||||||
os.system("rm -f %s" % script)
|
os.system("rm -f %s" % script)
|
||||||
sql.update_server_master(master, slave)
|
sql.update_server_master(master, slave)
|
||||||
|
@ -1045,22 +1015,7 @@ if form.getvalue('masteradd'):
|
||||||
|
|
||||||
output, error = funct.subprocess_execute(commands[0])
|
output, error = funct.subprocess_execute(commands[0])
|
||||||
|
|
||||||
if error:
|
funct.show_installation_output(error, output, 'Master VRRP address')
|
||||||
funct.logging('localhost', error, haproxywi=1)
|
|
||||||
print('error: ' + error)
|
|
||||||
else:
|
|
||||||
for l in output:
|
|
||||||
if "msg" in l or "FAILED" in l:
|
|
||||||
try:
|
|
||||||
l = l.split(':')[1]
|
|
||||||
l = l.split('"')[1]
|
|
||||||
print(l + "<br>")
|
|
||||||
break
|
|
||||||
except:
|
|
||||||
print(output)
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
print('success: Master VRRP address has been added<br>')
|
|
||||||
|
|
||||||
ssh_enable, ssh_user_name, ssh_user_password, ssh_key_name = funct.return_ssh_keys_path(slave)
|
ssh_enable, ssh_user_name, ssh_user_password, ssh_key_name = funct.return_ssh_keys_path(slave)
|
||||||
|
|
||||||
|
@ -1078,22 +1033,7 @@ if form.getvalue('masteradd'):
|
||||||
|
|
||||||
output, error = funct.subprocess_execute(commands[0])
|
output, error = funct.subprocess_execute(commands[0])
|
||||||
|
|
||||||
if error:
|
funct.show_installation_output(error, output, 'Slave VRRP address')
|
||||||
funct.logging('localhost', error, haproxywi=1)
|
|
||||||
print('error: ' + error)
|
|
||||||
else:
|
|
||||||
for l in output:
|
|
||||||
if "msg" in l or "FAILED" in l:
|
|
||||||
try:
|
|
||||||
l = l.split(':')[1]
|
|
||||||
l = l.split('"')[1]
|
|
||||||
print(l + "<br>")
|
|
||||||
break
|
|
||||||
except:
|
|
||||||
print(output)
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
print('success: Slave VRRP address has been added<br>')
|
|
||||||
|
|
||||||
os.system("rm -f %s" % script)
|
os.system("rm -f %s" % script)
|
||||||
|
|
||||||
|
@ -1170,22 +1110,7 @@ if form.getvalue('haproxy_exp_install'):
|
||||||
|
|
||||||
output, error = funct.subprocess_execute(commands[0])
|
output, error = funct.subprocess_execute(commands[0])
|
||||||
|
|
||||||
if error:
|
funct.show_installation_output(error, output, 'HAProxy exporter')
|
||||||
funct.logging('localhost', error, haproxywi=1)
|
|
||||||
print('error: ' + error)
|
|
||||||
else:
|
|
||||||
for l in output:
|
|
||||||
if "msg" in l or "FAILED" in l:
|
|
||||||
try:
|
|
||||||
l = l.split(':')[1]
|
|
||||||
l = l.split('"')[1]
|
|
||||||
print(l + "<br>")
|
|
||||||
break
|
|
||||||
except Exception:
|
|
||||||
print(output)
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
print('success: HAProxy exporter was installed<br>')
|
|
||||||
|
|
||||||
os.system("rm -f %s" % script)
|
os.system("rm -f %s" % script)
|
||||||
|
|
||||||
|
@ -1220,22 +1145,7 @@ if form.getvalue('nginx_exp_install'):
|
||||||
|
|
||||||
output, error = funct.subprocess_execute(commands[0])
|
output, error = funct.subprocess_execute(commands[0])
|
||||||
|
|
||||||
if error:
|
funct.show_installation_output(error, output, 'Nginx exporter')
|
||||||
funct.logging('localhost', error, haproxywi=1)
|
|
||||||
print('error: ' + error)
|
|
||||||
else:
|
|
||||||
for l in output:
|
|
||||||
if "msg" in l or "FAILED" in l:
|
|
||||||
try:
|
|
||||||
l = l.split(':')[1]
|
|
||||||
l = l.split('"')[1]
|
|
||||||
print(l + "<br>")
|
|
||||||
break
|
|
||||||
except Exception:
|
|
||||||
print(output)
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
print('success: Nginx exporter was installed<br>')
|
|
||||||
|
|
||||||
os.system("rm -f %s" % script)
|
os.system("rm -f %s" % script)
|
||||||
|
|
||||||
|
@ -2311,3 +2221,10 @@ if form.getvalue('viewFirewallRules') is not None:
|
||||||
template = env.get_template('ajax/firewall_rules.html')
|
template = env.get_template('ajax/firewall_rules.html')
|
||||||
template = template.render(input=input_chain, IN_public_allow=IN_public_allow, output=output_chain)
|
template = template.render(input=input_chain, IN_public_allow=IN_public_allow, output=output_chain)
|
||||||
print(template)
|
print(template)
|
||||||
|
|
||||||
|
if form.getvalue('geoipserv') is not None:
|
||||||
|
serv = form.getvalue('geoipserv')
|
||||||
|
haproxy_dir = sql.get_setting('haproxy_dir')
|
||||||
|
|
||||||
|
cmd = ["ls " + haproxy_dir + "/geoip/"]
|
||||||
|
print(funct.ssh_command(serv, cmd))
|
||||||
|
|
17
app/sql.py
17
app/sql.py
|
@ -2081,8 +2081,12 @@ def update_smon(id, ip, port, body, telegram, group, desc, en):
|
||||||
|
|
||||||
def alerts_history(service, user_group):
|
def alerts_history(service, user_group):
|
||||||
con, cur = get_cur()
|
con, cur = get_cur()
|
||||||
|
if user_group == 1:
|
||||||
|
sql_user_group = ""
|
||||||
|
else:
|
||||||
|
sql_user_group = "and user_group = '" + str(user_group) + "'"
|
||||||
sql = """ select message, level, ip, port, date from alerts
|
sql = """ select message, level, ip, port, date from alerts
|
||||||
where service = '%s' and user_group = '%s' order by date desc; """ % (service, user_group)
|
where service = '%s' %s order by date desc; """ % (service, sql_user_group)
|
||||||
try:
|
try:
|
||||||
cur.execute(sql)
|
cur.execute(sql)
|
||||||
except sqltool.Error as e:
|
except sqltool.Error as e:
|
||||||
|
@ -2324,6 +2328,17 @@ def return_firewall(serv):
|
||||||
return True if firewall == 1 else False
|
return True if firewall == 1 else False
|
||||||
|
|
||||||
|
|
||||||
|
def select_geoip_country_codes():
|
||||||
|
con, cur = get_cur()
|
||||||
|
sql = """ select * from geoip_codes"""
|
||||||
|
try:
|
||||||
|
cur.execute(sql)
|
||||||
|
except sqltool.Error as e:
|
||||||
|
funct.out_error(e)
|
||||||
|
else:
|
||||||
|
return cur.fetchall()
|
||||||
|
|
||||||
|
|
||||||
form = funct.form
|
form = funct.form
|
||||||
error_mess = 'error: All fields must be completed'
|
error_mess = 'error: All fields must be completed'
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue