diff --git a/app/funct.py b/app/funct.py
index ec7bcd8b..36272d2d 100644
--- a/app/funct.py
+++ b/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+"
")
- break
- except Exception:
- print(output)
- break
- else:
- print('success: HAProxy was installed
')
-
+
+ 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+"
")
- break
- except Exception:
- print(output)
- break
- else:
- print('success: Nginx was installed
')
+
+ show_installation_output(error, output, 'Nginx')
os.system("rm -f %s" % script)
sql.update_nginx(serv)
diff --git a/app/options.py b/app/options.py
index 555b6933..a2b0aa12 100644
--- a/app/options.py
+++ b/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 + "
")
- break
- except Exception:
- print(output)
- break
- else:
- print('success: Master Keepalived was installed
')
+ 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 + "
")
- break
- except Exception:
- print(output)
- break
- else:
- print('success: Slave Keepalived was installed
')
+ 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 + "
")
- break
- except:
- print(output)
- break
- else:
- print('success: Master VRRP address has been added
')
+ 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 + "
")
- break
- except:
- print(output)
- break
- else:
- print('success: Slave VRRP address has been added
')
+ 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 + "
")
- break
- except Exception:
- print(output)
- break
- else:
- print('success: HAProxy exporter was installed
')
+ 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 + "
")
- break
- except Exception:
- print(output)
- break
- else:
- print('success: Nginx exporter was installed
')
+ 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))
diff --git a/app/sql.py b/app/sql.py
index 4054d0c9..57342ce1 100644
--- a/app/sql.py
+++ b/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'