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
|
||||
except Exception:
|
||||
return False
|
||||
pass
|
||||
|
||||
|
||||
def page_for_admin(**kwargs):
|
||||
|
@ -477,7 +476,27 @@ def get_stick_table(table):
|
|||
output, stderr = subprocess_execute(cmd)
|
||||
|
||||
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):
|
||||
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]
|
||||
|
||||
output, error = subprocess_execute(commands[0])
|
||||
|
||||
if 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+"<br>")
|
||||
break
|
||||
except Exception:
|
||||
print(output)
|
||||
break
|
||||
else:
|
||||
print('success: HAProxy was installed<br>')
|
||||
|
||||
|
||||
show_installation_output(error, output, 'HAProxy')
|
||||
|
||||
os.system("rm -f %s" % script)
|
||||
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]
|
||||
|
||||
output, error = subprocess_execute(commands[0])
|
||||
|
||||
if 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+"<br>")
|
||||
break
|
||||
except Exception:
|
||||
print(output)
|
||||
break
|
||||
else:
|
||||
print('success: Nginx was installed<br>')
|
||||
|
||||
show_installation_output(error, output, 'Nginx')
|
||||
|
||||
os.system("rm -f %s" % script)
|
||||
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])
|
||||
|
||||
if error:
|
||||
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>')
|
||||
funct.show_installation_output(error, output, 'Master Keepalived')
|
||||
|
||||
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])
|
||||
|
||||
if error:
|
||||
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>')
|
||||
funct.show_installation_output(error, output, 'Slave Keepalived')
|
||||
|
||||
os.system("rm -f %s" % script)
|
||||
sql.update_server_master(master, slave)
|
||||
|
@ -1045,22 +1015,7 @@ if form.getvalue('masteradd'):
|
|||
|
||||
output, error = funct.subprocess_execute(commands[0])
|
||||
|
||||
if error:
|
||||
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>')
|
||||
funct.show_installation_output(error, output, 'Master VRRP address')
|
||||
|
||||
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])
|
||||
|
||||
if error:
|
||||
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>')
|
||||
funct.show_installation_output(error, output, 'Slave VRRP address')
|
||||
|
||||
os.system("rm -f %s" % script)
|
||||
|
||||
|
@ -1170,22 +1110,7 @@ if form.getvalue('haproxy_exp_install'):
|
|||
|
||||
output, error = funct.subprocess_execute(commands[0])
|
||||
|
||||
if error:
|
||||
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>')
|
||||
funct.show_installation_output(error, output, 'HAProxy exporter')
|
||||
|
||||
os.system("rm -f %s" % script)
|
||||
|
||||
|
@ -1220,22 +1145,7 @@ if form.getvalue('nginx_exp_install'):
|
|||
|
||||
output, error = funct.subprocess_execute(commands[0])
|
||||
|
||||
if error:
|
||||
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>')
|
||||
funct.show_installation_output(error, output, 'Nginx exporter')
|
||||
|
||||
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 = template.render(input=input_chain, IN_public_allow=IN_public_allow, output=output_chain)
|
||||
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):
|
||||
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
|
||||
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:
|
||||
cur.execute(sql)
|
||||
except sqltool.Error as e:
|
||||
|
@ -2324,6 +2328,17 @@ def return_firewall(serv):
|
|||
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
|
||||
error_mess = 'error: All fields must be completed'
|
||||
|
||||
|
|
Loading…
Reference in New Issue