Most settings migrate into DB, improved install script, and haproxy install script
pull/30/head
Aidaho12 2018-08-11 20:47:47 +06:00
parent ccd67c8c68
commit c0dbf08f23
23 changed files with 296 additions and 174 deletions

View File

@ -1,5 +1,5 @@
# Haproxy web interface
Web interface(user-frendly web GUI) for managing Haproxy servers. Leave your [feedback](https://github.com/Aidaho12/haproxy-wi/issues)
Web interface(user-friendly web GUI) for managing Haproxy servers. Leave your [feedback](https://github.com/Aidaho12/haproxy-wi/issues)
# Donate
Support the project

View File

@ -35,7 +35,7 @@ output_from_parsed_template = template.render(title = "Add",
print(output_from_parsed_template)
hap_configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir')
cert_path = funct.get_config_var('haproxy', 'cert_path')
cert_path = sql.get_setting('cert_path')
if form.getvalue('mode') is not None:
serv = form.getvalue('serv')

View File

@ -15,7 +15,6 @@ if mysql_enable == '1':
from mysql.connector import errorcode
import mysql.connector as sqltool
else:
fullpath = funct.get_config_var('main', 'fullpath')
db = funct.get_app_dir()+"/haproxy-wi.db"
import sqlite3 as sqltool
@ -498,16 +497,71 @@ def update_db_v_2_91(**kwargs):
except sqltool.Error as e:
if kwargs.get('silent') != 1:
if e.args[0] == 'column param is not unique' or e == "1060 (42S21): Duplicate column name 'cred' ":
print('DB was update to 2.9 It\' last version')
print('Updating... go to version 3.0')
else:
print("An error occurred:", e)
return False
else:
print("DB was update to 2.9 It\' last version<br />")
print("Updating... go to version 3.0<br />")
return True
cur.close()
con.close()
def update_db_v_3(**kwargs):
con, cur = get_cur()
sql = """
ALTER TABLE `settings` ADD COLUMN section varchar(64);
"""
try:
cur.execute(sql)
con.commit()
except sqltool.Error as e:
if kwargs.get('silent') != 1:
if e.args[0] == 'duplicate column name: section' or e == " 1060 (42S21): Duplicate column name 'section' ":
print('DB was update to 3.0 It\' last version')
else:
print("An error occurred:", e)
return False
else:
sql = [ "ALTER TABLE `settings` ADD COLUMN desc varchar(128); ",
"INSERT INTO settings (param, value, section, desc) values('time_zone', 'UTC', 'main', 'Time Zone');",
"INSERT INTO settings (param, value, section, desc) values('proxy', '', 'main', 'Proxy server. Use proto://ip:port');",
"INSERT INTO settings (param, value, section, desc) values('session_ttl', '5', 'main', 'Time to live users sessions. In days');",
"INSERT INTO settings (param, value, section, desc) values('token_ttl', '5', 'main', 'Time to live users tokens. In days');",
"INSERT INTO settings (param, value, section, desc) values('local_path_logs', '/var/log/haproxy.log', 'logs', 'Logs save locally, disable by default');",
"INSERT INTO settings (param, value, section, desc) values('syslog_server_enable', '0', 'logs', 'If exist syslog server for HAproxy logs, enable this option');",
"INSERT INTO settings (param, value, section, desc) values('syslog_server', '0', 'logs', 'IP address syslog server');",
"INSERT INTO settings (param, value, section, desc) values('log_time_storage', '14', 'logs', 'Time of storage of logs of user activity, in days');",
"INSERT INTO settings (param, value, section, desc) values('restart_command', 'systemctl restart haproxy', 'haproxy', 'Command for restart HAproxy service');",
"INSERT INTO settings (param, value, section, desc) values('status_command', 'systemctl status haproxy', 'haproxy', 'Command for status check HAproxy service');",
"INSERT INTO settings (param, value, section, desc) values('stats_user', 'admin', 'haproxy', 'Username for Stats web page HAproxy');",
"INSERT INTO settings (param, value, section, desc) values('stats_password', 'password', 'haproxy', 'Password for Stats web page HAproxy');",
"INSERT INTO settings (param, value, section, desc) values('stats_port', '8085', 'haproxy', 'Port Stats web page HAproxy');",
"INSERT INTO settings (param, value, section, desc) values('stats_page', 'stats', 'haproxy', 'URI Stats web page HAproxy');",
"INSERT INTO settings (param, value, section, desc) values('haproxy_dir', '/etc/haproxy/', 'haproxy', 'Path to HAProxy dir');",
"INSERT INTO settings (param, value, section, desc) values('haproxy_config_path', '/etc/haproxy/haproxy.cfg', 'haproxy', 'Path to HAProxy config');",
"INSERT INTO settings (param, value, section, desc) values('server_state_file', '/etc/haproxy/haproxy.state', 'haproxy', 'Path to HAProxy state file');",
"INSERT INTO settings (param, value, section, desc) values('haproxy_sock', '/var/run/haproxy.sock', 'haproxy', 'Path to HAProxy sock file');",
"INSERT INTO settings (param, value, section, desc) values('haproxy_sock_port', '1999', 'haproxy', 'HAProxy sock port');",
"INSERT INTO settings (param, value, section, desc) values('tmp_config_path', '/tmp/', 'haproxy', 'Temp store configs, for haproxy check');",
"INSERT INTO settings (param, value, section, desc) values('cert_path', '/etc/ssl/certs/', 'haproxy', 'Path to SSL dir');",
"INSERT INTO settings (param, value, section, desc) values('firewall_enable', '0', 'haproxy', 'If enable this option Haproxy-wi will be configure firewalld based on config port');" ]
try:
for i in sql:
cur.execute(i)
except sqltool.Error as e:
if kwargs.get('silent') != 1:
if e.args[0] == 'duplicate column name: id' or e == "1060 (42S21): Duplicate column name 'id' ":
print('DB was update to 3.0 It\' last version')
else:
print("An error occurred:", e)
return False
else:
pass
return True
cur.close()
con.close()
def update_all():
update_db_v_2_0_1()
update_db_v_2_0_1_1()
@ -524,6 +578,7 @@ def update_all():
update_db_v_2_8_2()
update_db_v_2_9()
update_db_v_2_91()
update_db_v_3()
def update_all_silent():
update_db_v_2_0_1(silent=1)
@ -541,4 +596,5 @@ def update_all_silent():
update_db_v_2_8_2(silent=1)
update_db_v_2_9(silent=1)
update_db_v_2_91(silent=1)
update_db_v_3(silent=1)

View File

@ -36,7 +36,8 @@ def get_config_var(sec, var):
print('<center><div class="alert alert-danger">Check the config file. Presence section %s and parameter %s</div>' % (sec, var))
def get_data(type):
now_utc = datetime.now(timezone(get_config_var('main', 'time_zone')))
import sql
now_utc = datetime.now(timezone(sql.get_setting('time_zone')))
if type == 'config':
fmt = "%Y-%m-%d.%H:%M:%S"
if type == 'logs':
@ -85,7 +86,7 @@ def telegram_send_mess(mess, **kwargs):
token_bot = telegram[1]
channel_name = telegram[2]
proxy = get_config_var('main', 'proxy')
proxy = sql.get_setting('proxy')
if proxy is not None:
apihelper.proxy = {'https': proxy}
@ -213,11 +214,12 @@ def ssh_connect(serv, **kwargs):
return error
def get_config(serv, cfg, **kwargs):
import sql
error = ""
if kwargs.get("keepalived"):
config_path = "/etc/keepalived/keepalived.conf"
else:
config_path = get_config_var('haproxy', 'haproxy_config_path')
config_path = sql.get_setting('haproxy_config_path')
ssh = ssh_connect(serv)
try:
@ -296,15 +298,23 @@ def diff_config(oldcfg, cfg):
pass
def install_haproxy(serv, **kwargs):
import sql
script = "install_haproxy.sh"
tmp_config_path = get_config_var('haproxy', 'tmp_config_path')
proxy = get_config_var('main', 'proxy')
tmp_config_path = sql.get_setting('tmp_config_path')
haproxy_sock_port = sql.get_setting('haproxy_sock_port')
stats_port = sql.get_setting('stats_port')
server_state_file = sql.get_setting('server_state_file')
stats_user = sql.get_setting('stats_user')
stats_password = sql.get_setting('stats_password')
proxy = sql.get_setting('proxy')
os.system("cp scripts/%s ." % script)
if proxy is not None:
proxy_serv = proxy
else:
proxy_serv = ""
commands = [ "chmod +x "+tmp_config_path+script+" && " +tmp_config_path+"/"+script +" " + proxy_serv]
commands = [ "chmod +x "+tmp_config_path+script+" && " +tmp_config_path+"/"+script +" PROXY=" + proxy_serv+
" SOCK_PORT="+haproxy_sock_port+" STAT_PORT="+stats_port+" STAT_FILE="+server_state_file+
" STATS_USER="+stats_user+" STATS_PASS="+stats_password ]
upload(serv, tmp_config_path, script)
ssh_command(serv, commands)
@ -315,8 +325,9 @@ def install_haproxy(serv, **kwargs):
os.system("rm -f %s" % script)
def syn_flood_protect(serv, **kwargs):
import sql
script = "syn_flood_protect.sh"
tmp_config_path = get_config_var('haproxy', 'tmp_config_path')
tmp_config_path = sql.get_setting('tmp_config_path')
if kwargs.get('enable') == "0":
enable = "disable"
@ -348,7 +359,8 @@ def upload(serv, path, file, **kwargs):
print('<div class="alert alert-danger">Upload fail: %s</div>' % e)
def upload_and_restart(serv, cfg, **kwargs):
tmp_file = get_config_var('haproxy', 'tmp_config_path') + "/" + get_data('config') + ".cfg"
import sql
tmp_file = sql.get_setting('tmp_config_path') + "/" + get_data('config') + ".cfg"
error = ""
try:
@ -371,11 +383,11 @@ def upload_and_restart(serv, cfg, **kwargs):
commands = [ "sudo mv -f " + tmp_file + " /etc/keepalived/keepalived.conf", "sudo systemctl restart keepalived" ]
else:
if kwargs.get("just_save") == "save":
commands = [ "sudo /sbin/haproxy -q -c -f " + tmp_file + "&& sudo mv -f " + tmp_file + " " + get_config_var('haproxy', 'haproxy_config_path') ]
commands = [ "sudo /sbin/haproxy -q -c -f " + tmp_file + "&& sudo mv -f " + tmp_file + " " + sql.get_setting('haproxy_config_path') ]
else:
commands = [ "sudo /sbin/haproxy -q -c -f " + tmp_file + "&& sudo mv -f " + tmp_file + " " + get_config_var('haproxy', 'haproxy_config_path') + " && sudo " + get_config_var('haproxy', 'restart_command') ]
commands = [ "sudo /sbin/haproxy -q -c -f " + tmp_file + "&& sudo mv -f " + tmp_file + " " + sql.get_setting('haproxy_config_path') + " && sudo " + sql.get_setting('restart_command') ]
try:
if get_config_var('haproxy', 'firewall_enable') == "1":
if sql.get_setting('firewall_enable') == "1":
commands.extend(open_port_firewalld(cfg))
except:
return 'Please check the config for the presence of the parameter - "firewall_enable". Mast be: "0" or "1". Firewalld configure not working now'
@ -406,7 +418,8 @@ def open_port_firewalld(cfg):
return firewalld_commands
def check_haproxy_config(serv):
commands = [ "/sbin/haproxy -q -c -f %s" % get_config_var('haproxy', 'haproxy_config_path') ]
import sql
commands = [ "/sbin/haproxy -q -c -f %s" % sql.get_setting('haproxy_config_path') ]
ssh = ssh_connect(serv)
for command in commands:
stdin , stdout, stderr = ssh.exec_command(command)

View File

@ -4,12 +4,6 @@ fullpath = /var/www/haproxy-wi
cgi_path = ${fullpath}/app/
log_path = ${fullpath}/log/
cert_local_dir = ${cgi_path}/certs/
time_zone = UTC
proxy =
#Time to live users sessions. In days
session_ttl = 5
#Time to live users tokens. In days
token_ttl = 5
[configs]
#Dir where configs will be save
@ -23,39 +17,3 @@ mysql_user = haproxy-wi
mysql_password = haproxy-wi
mysql_db = haproxywi
mysql_host = 127.0.0.1
[logs]
#Logs save locally, enable by default
local_path_logs = /var/log/haproxy.log
#If exist syslog server for HAproxy logs
syslog_server_enable = 0
syslog_server =
#Time of storage of logs of user activity, in days
log_time_storage = 14
[telegram]
#Send log message to telegram channel
#Default bot send message disable
enable = 0
token =
channel_name =
[haproxy]
#Command for restart HAproxy service
restart_command = systemctl restart haproxy
status_command = systemctl status haproxy
#Username and password for Stats web page HAproxy
stats_user = admin
stats_password = password
stats_port = 8085
stats_page = stats
haproxy_dir = /etc/haproxy
haproxy_config_path = ${haproxy_dir}/haproxy.cfg
server_state_file = ${haproxy_dir}/haproxy.state
haproxy_sock = /var/run/haproxy.sock
haproxy_sock_port = 1999
#Temp store configs, for haproxy check
tmp_config_path = /tmp/
cert_path = /etc/ssl/certs/
#If enable this option Haproxy-wi will be configure firewalld based on config port
firewall_enable = 1

View File

@ -9,7 +9,6 @@ import sql
import create_db
import datetime
import uuid
from configparser import ConfigParser, ExtendedInterpolation
from jinja2 import Environment, FileSystemLoader
env = Environment(loader=FileSystemLoader('templates/'))
template = env.get_template('login.html')
@ -24,10 +23,6 @@ db_create = ""
error_log = ""
error = ""
path_config = "haproxy-webintarface.config"
config = ConfigParser(interpolation=ExtendedInterpolation())
config.read(path_config)
if ref is None:
ref = "/index.html"
@ -35,10 +30,10 @@ if form.getvalue('error'):
error_log = '<div class="alert alert-danger">Somthing wrong :( I\'m sad about this, but try again!</div><br /><br />'
try:
if config.get('main', 'session_ttl'):
session_ttl = config.getint('main', 'session_ttl')
if sql.get_setting('session_ttl'):
session_ttl = sql.get_setting('session_ttl')
except:
error = '<center><div class="alert alert-danger">Can not find "session_ttl" parametr. Check into config, "main" section</div>'
error = '<center><div class="alert alert-danger">Can not find "session_ttl" parametr. Check into settings, "main" section</div>'
pass
try:
@ -61,8 +56,11 @@ if form.getvalue('logout'):
if login is not None and password is not None:
USERS = sql.select_users()
session_ttl = config.getint('main', 'session_ttl')
expires = datetime.datetime.utcnow() + datetime.timedelta(days=session_ttl)
session_ttl = int()
session_ttl = sql.get_setting('session_ttl')
session_ttl = int(session_ttl)
expires = datetime.datetime.utcnow() + datetime.timedelta(days=session_ttl)
user_uuid = str(uuid.uuid4())
user_token = str(uuid.uuid4())

View File

@ -20,8 +20,8 @@ if form.getvalue('token') is None:
sys.exit()
if form.getvalue('getcerts') is not None and serv is not None:
cert_path = funct.get_config_var('haproxy', 'cert_path')
commands = [ "ls -1t /etc/ssl/certs/ |grep pem" ]
cert_path = sql.get_setting('cert_path')
commands = [ "ls -1t "+cert_path+" |grep pem" ]
try:
funct.ssh_command(serv, commands, ip="1")
except:
@ -29,7 +29,7 @@ if form.getvalue('getcerts') is not None and serv is not None:
if form.getvalue('getcert') is not None and serv is not None:
id = form.getvalue('getcert')
cert_path = funct.get_config_var('haproxy', 'cert_path')
cert_path = sql.get_setting('cert_path')
commands = [ "cat "+cert_path+"/"+id ]
try:
funct.ssh_command(serv, commands, ip="1")
@ -37,9 +37,8 @@ if form.getvalue('getcert') is not None and serv is not None:
print('<div class="alert alert-danger" style="margin:0">Can not connect to the server</div>')
if form.getvalue('ssh_cert'):
fullpath = funct.get_config_var('main', 'fullpath')
name = form.getvalue('name')
ssh_keys = fullpath+'/keys/'+name+'.pem'
ssh_keys = os.path.dirname(os.getcwd())+'/keys/'+name+'.pem'
try:
with open(ssh_keys, "w") as conf:
@ -55,7 +54,7 @@ if form.getvalue('ssh_cert'):
if serv and form.getvalue('ssl_cert'):
cert_local_dir = funct.get_config_var('main', 'cert_local_dir')
cert_path = funct.get_config_var('haproxy', 'cert_path')
cert_path = sql.get_setting('cert_path')
if form.getvalue('ssl_name') is None:
print('<div class="alert alert-danger">Please enter desired name</div>')
@ -114,10 +113,10 @@ if form.getvalue('action'):
import requests
from requests_toolbelt.utils import dump
haproxy_user = funct.get_config_var('haproxy', 'stats_user')
haproxy_pass = funct.get_config_var('haproxy', 'stats_password')
stats_port = funct.get_config_var('haproxy', 'stats_port')
stats_page = funct.get_config_var('haproxy', 'stats_page')
haproxy_user = sql.get_setting('stats_user')
haproxy_pass = sql.get_setting('stats_password')
stats_port = sql.get_setting('stats_port')
stats_page = sql.get_setting('stats_page')
postdata = {
'action' : form.getvalue('action'),
@ -138,10 +137,10 @@ if serv is not None and act == "stats":
import requests
from requests_toolbelt.utils import dump
haproxy_user = funct.get_config_var('haproxy', 'stats_user')
haproxy_pass = funct.get_config_var('haproxy', 'stats_password')
stats_port = funct.get_config_var('haproxy', 'stats_port')
stats_page = funct.get_config_var('haproxy', 'stats_page')
haproxy_user = sql.get_setting('stats_user')
haproxy_pass = sql.get_setting('stats_password')
stats_port = sql.get_setting('stats_port')
stats_page = sql.get_setting('stats_page')
try:
response = requests.get('http://%s:%s/%s' % (serv, stats_port, stats_page), auth=(haproxy_user, haproxy_pass))
except requests.exceptions.ConnectTimeout:
@ -176,14 +175,14 @@ if serv is not None and form.getvalue('rows') is not None:
grep_act = ''
grep = ''
syslog_server_enable = funct.get_config_var('logs', 'syslog_server_enable')
syslog_server_enable = sql.get_setting('syslog_server_enable')
if syslog_server_enable is None or syslog_server_enable == "0":
local_path_logs = funct.get_config_var('logs', 'local_path_logs')
local_path_logs = sql.get_setting('local_path_logs')
syslog_server = serv
commands = [ "sudo cat %s| awk '$3>\"%s:00\" && $3<\"%s:00\"' |tail -%s %s %s" % (local_path_logs, date, date1, rows, grep_act, grep) ]
else:
commands = [ "sudo cat /var/log/%s/syslog.log | sed '/ %s:00/,/ %s:00/! d' |tail -%s %s %s" % (serv, date, date1, rows, grep_act, grep) ]
syslog_server = funct.get_config_var('logs', 'syslog_server')
syslog_server = sql.get_setting('syslog_server')
funct.ssh_command(syslog_server, commands, show_log="1")
@ -241,8 +240,8 @@ if serv is not None and act == "showMap":
ovw.get_map(serv)
if form.getvalue('servaction') is not None:
server_state_file = funct.get_config_var('haproxy', 'server_state_file')
haproxy_sock = funct.get_config_var('haproxy', 'haproxy_sock')
server_state_file = sql.get_setting('server_state_file')
haproxy_sock = sql.get_setting('haproxy_sock')
enable = form.getvalue('servaction')
backend = form.getvalue('servbackend')
@ -304,7 +303,7 @@ if form.getvalue('master'):
vrrpip = form.getvalue('vrrpip')
hap = form.getvalue('hap')
syn_flood = form.getvalue('syn_flood')
tmp_config_path = funct.get_config_var('haproxy', 'tmp_config_path')
tmp_config_path = sql.get_setting('tmp_config_path')
script = "install_keepalived.sh"
if hap == "1":
@ -335,7 +334,7 @@ if form.getvalue('masteradd'):
interface = form.getvalue('interfaceadd')
vrrpip = form.getvalue('vrrpipadd')
kp = form.getvalue('kp')
tmp_config_path = funct.get_config_var('haproxy', 'tmp_config_path')
tmp_config_path = sql.get_setting('tmp_config_path')
script = "add_vrrp.sh"
os.system("cp scripts/%s ." % script)
@ -486,7 +485,7 @@ if form.getvalue('bwlists_save'):
print('<div class="alert alert-danger" style="margin:0">Cat\'n save '+form.getvalue('color')+' list. %s </div>' % e)
servers = sql.get_dick_permit()
path = funct.get_config_var('haproxy', 'haproxy_dir')+"/"+form.getvalue('color')
path = sql.get_setting('haproxy_dir')+"/"+form.getvalue('color')
for server in servers:
commands = [ "sudo mkdir "+path ]
@ -507,7 +506,7 @@ if form.getvalue('bwlists_save'):
print('<div class="alert alert-danger">Upload fail: %s</div>' % e)
if form.getvalue('bwlists_restart') == 'restart':
commands = [ "sudo " + funct.get_config_var('haproxy', 'restart_command') ]
commands = [ "sudo " + sql.get_setting('restart_command') ]
funct.ssh_command(server[2], commands)
if form.getvalue('get_lists'):

View File

@ -10,9 +10,10 @@ def get_overview():
from jinja2 import Environment, FileSystemLoader
env = Environment(loader=FileSystemLoader('templates/ajax'))
template = env.get_template('overview.html')
haproxy_config_path = funct.get_config_var('haproxy', 'haproxy_config_path')
haproxy_config_path = sql.get_setting('haproxy_config_path')
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
user_id = cookie.get('uuid')
haproxy_sock_port = sql.get_setting('haproxy_sock_port')
listhap = sql.get_dick_permit()
commands = [ "ls -l %s |awk '{ print $6\" \"$7\" \"$8}'" % haproxy_config_path ]
@ -20,7 +21,7 @@ def get_overview():
for server in listhap:
server_status = ()
cmd = 'echo "show info" |nc %s 1999 |grep -e "Process_num"' % server[2]
cmd = 'echo "show info" |nc %s %s |grep -e "Process_num"' % (server[2], haproxy_sock_port)
server_status = (server[1],server[2], funct.server_status(funct.subprocess_execute(cmd)), funct.ssh_command(server[2], commands))
servers.append(server_status)
@ -34,6 +35,7 @@ def get_overviewServers():
template = env.get_template('overviewServers.html')
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
user_id = cookie.get('uuid')
haproxy_sock_port = sql.get_setting('haproxy_sock_port')
listhap = sql.get_dick_permit()
commands = [ "top -u haproxy -b -n 1" ]
@ -41,7 +43,7 @@ def get_overviewServers():
for server in sorted(listhap):
server_status = ()
cmd = 'echo "show info" |nc %s 1999 |grep -e "Ver\|CurrConns\|SessRate\|Maxco\|MB\|Uptime:"' % server[2]
cmd = 'echo "show info" |nc %s %s |grep -e "Ver\|CurrConns\|SessRate\|Maxco\|MB\|Uptime:"' % (server[2], haproxy_sock_port)
out = funct.subprocess_execute(cmd)
out1 = ""
for k in out:
@ -66,10 +68,8 @@ def get_map(serv):
matplotlib.use('Agg')
import matplotlib.pyplot as plt
cgi_path = funct.get_config_var('main', 'cgi_path')
fullpath = funct.get_config_var('main', 'fullpath')
stats_port= funct.get_config_var('haproxy', 'stats_port')
haproxy_config_path = funct.get_config_var('haproxy', 'haproxy_config_path')
stats_port= sql.get_setting('stats_port')
haproxy_config_path = sql.get_setting('haproxy_config_path')
hap_configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir')
date = funct.get_data('config')
cfg = hap_configs_dir + serv + "-" + date + ".cfg"
@ -141,7 +141,6 @@ def get_map(serv):
G.add_edge(node,line_new[0])
os.system("/bin/rm -f " + cfg)
os.chdir(cgi_path)
pos=nx.get_node_attributes(G,'pos')
pos_label=nx.get_node_attributes(G,'label_pos')
@ -160,7 +159,7 @@ def get_map(serv):
except Exception as e:
print('<div class="alert alert-danger">' + str(e) + '</div>')
cmd = "rm -f "+fullpath+"/map*.png && mv "+cgi_path+"/map.png "+fullpath+"/map"+date+".png"
cmd = "rm -f "+os.path.dirname(os.getcwd())+"/map*.png && mv map.png "+os.path.dirname(os.getcwd())+"/map"+date+".png"
output, stderr = funct.subprocess_execute(cmd)
print(stderr)

View File

@ -1,9 +1,29 @@
#!/bin/bash
if [[ $1 != "" ]]
for ARGUMENT in "$@"
do
KEY=$(echo $ARGUMENT | cut -f1 -d=)
VALUE=$(echo $ARGUMENT | cut -f2 -d=)
case "$KEY" in
PROXY) PROXY=${VALUE} ;;
SOCK_PORT) SOCK_PORT=${VALUE} ;;
STAT_PORT) STAT_PORT=${VALUE} ;;
STAT_FILE) STAT_FILE=${VALUE} ;;
STATS_USER) STATS_USER=${VALUE} ;;
STATS_PASS) STATS_PASS=${VALUE} ;;
STAT_FILE) STAT_FILE=${VALUE} ;;
*)
esac
done
if [[ $PROXY != "" ]]
then
export http_proxy="$1"
export https_proxy="$1"
export http_proxy="$PROXY"
export https_proxy="$PROXY"
echo "Exporting proxy"
fi
@ -15,14 +35,14 @@ fi
if hash apt-get 2>/dev/null; then
sudo apt-get install haproxy socat -y
else
wget http://cbs.centos.org/kojifiles/packages/haproxy/1.8.1/4.el7/x86_64/haproxy18-1.8.1-4.el7.x86_64.rpm
sudo wget http://cbs.centos.org/kojifiles/packages/haproxy/1.8.1/5.el7/x86_64/haproxy18-1.8.1-5.el7.x86_64.rpm
sudo yum install haproxy18-1.8.1-5.el7.x86_64.rpm -y
fi
if [ $? -eq 1 ]
then
sudo yum install wget socat -y > /dev/null
wget http://cbs.centos.org/kojifiles/packages/haproxy/1.8.1/4.el7/x86_64/haproxy18-1.8.1-4.el7.x86_64.rpm
sudo wget http://cbs.centos.org/kojifiles/packages/haproxy/1.8.1/5.el7/x86_64/haproxy18-1.8.1-5.el7.x86_64.rpm
sudo yum install haproxy18-1.8.1-5.el7.x86_64.rpm -y
fi
if [ $? -eq 1 ]
@ -45,8 +65,9 @@ global
group haproxy
daemon
stats socket /var/lib/haproxy/stats
stats socket *:1999 level admin
stats socket /var/run/haproxy.sock mode 600 level admin
stats socket *:$SOCK_PORT level admin
stats socket /var/run/haproxy.sock mode 600 level admin
server-state-file $STAT_FILE
defaults
mode http
@ -67,11 +88,11 @@ defaults
maxconn 3000
listen stats
bind *:8085
bind *:$STAT_PORT
stats enable
stats uri /stats
stats realm HAProxy-04\ Statistics
stats auth admin:password
stats auth $STATS_USER:$STATS_PASS
stats admin if TRUE
EOF
sudo bash -c cat << EOF > /etc/rsyslog.d/haproxy.conf

View File

@ -1,39 +1,31 @@
#!/usr/bin/env python3
import html, http
import html
import cgi
import sys
import os
import funct, sql
from configparser import ConfigParser, ExtendedInterpolation
import funct
import sql
import http
from jinja2 import Environment, FileSystemLoader
env = Environment(loader=FileSystemLoader('templates/'))
template = env.get_template('viewsettings.html')
path_config = "haproxy-webintarface.config"
config = ConfigParser(interpolation=ExtendedInterpolation())
config.read(path_config)
fullpath = config.get('main', 'fullpath')
template = env.get_template('settings.html')
form = cgi.FieldStorage()
print('Content-type: text/html\n')
funct.check_login()
funct.page_for_admin()
try:
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
user_id = cookie.get('uuid')
user = sql.get_user_name_by_uuid(user_id.value)
servers = sql.get_dick_permit()
settings = sql.get_setting('', all=1)
token = sql.get_token(user_id.value)
except:
pass
config_items_section_name = {}
for section_name in config.sections():
config_items_section_name[section_name] = {}
for name, value in config.items(section_name):
config_items_section_name[section_name][name] = value
output_from_parsed_template = template.render(h2 = 1, title = "Admin area: View settings",
role = sql.get_user_role_by_uuid(user_id.value),
user = user,
fullpath = fullpath,
config_items_section_name = config_items_section_name)
print(output_from_parsed_template)
template = template.render(h2 = 1, title = "Settings",
role = sql.get_user_role_by_uuid(user_id.value),
user = user,
settings = settings,
token = token)
print(template)

View File

@ -285,7 +285,7 @@ def get_enable_checkbox(id, **kwargs):
def write_user_uuid(login, user_uuid):
con, cur = create_db.get_cur()
session_ttl = funct.get_config_var('main', 'session_ttl')
session_ttl = get_setting('session_ttl')
session_ttl = int(session_ttl)
sql = """ select id from user where username = '%s' """ % login
try:
@ -308,7 +308,7 @@ def write_user_uuid(login, user_uuid):
def write_user_token(login, user_token):
con, cur = create_db.get_cur()
token_ttl = funct.get_config_var('main', 'token_ttl')
token_ttl = get_setting('token_ttl')
sql = """ select id from user where username = '%s' """ % login
try:
cur.execute(sql)
@ -374,7 +374,7 @@ def delete_old_uuid():
def update_last_act_user(uuid):
con, cur = create_db.get_cur()
session_ttl = funct.get_config_var('main', 'session_ttl')
session_ttl = get_setting('session_ttl')
if mysql_enable == '1':
sql = """ update uuid set exp = now()+ INTERVAL %s day where uuid = '%s' """ % (session_ttl, uuid)
@ -839,19 +839,36 @@ def select_table_metrics(uuid):
cur.close()
con.close()
def get_setting(param):
def get_setting(param, **kwargs):
con, cur = create_db.get_cur()
sql = """select value from `settings` where param='%s' """ % param
if kwargs.get('all'):
sql = """select * from `settings` order by section desc"""
try:
cur.execute(sql)
except sqltool.Error as e:
print('<span class="alert alert-danger" id="error">An error occurred: ' + e + ' <a title="Close" id="errorMess"><b>X</b></a></span>')
else:
for value in cur.fetchone():
return value
if kwargs.get('all'):
return cur
else:
for value in cur.fetchone():
return value
cur.close()
con.close()
def update_setting(param, val):
con, cur = create_db.get_cur()
sql = """update `settings` set `value` = '%s' where param = '%s' """ % (val, param)
try:
cur.execute(sql)
con.commit()
except sqltool.Error as e:
print('<span class="alert alert-danger" id="error">An error occurred: ' + e.args[0] + ' <a title="Close" id="errorMess"><b>X</b></a></span>')
con.rollback()
cur.close()
con.close()
def show_update_telegram(token, page):
from jinja2 import Environment, FileSystemLoader
env = Environment(loader=FileSystemLoader('templates/ajax'))
@ -1135,4 +1152,8 @@ if form.getvalue('updatetoken') is not None:
print(error_mess)
else:
print('Content-type: text/html\n')
update_telegram(token, chanel, group, id)
update_telegram(token, chanel, group, id)
if form.getvalue('updatesettings') is not None:
print('Content-type: text/html\n')
update_setting(form.getvalue('updatesettings'), form.getvalue('val') )

View File

@ -90,7 +90,7 @@
<li><a href=/app/users.py#servers title="Actions with servers" class="runtime head-submenu">Servers</a></li>
<li><a href=/app/users.py#roles title="Users roles" class="role head-submenu">Roles</a></li>
<li><a href=/app/users.py#ssh title="Manage SSH credentials" class="admin head-submenu">SSH credentials</a></li>
<li><a href=/app/settings.py title="View settings" class="settings head-submenu">View settings</a></li>
<li><a href=/app/settings.py title="HAproxy-WI settings" class="settings head-submenu">Settings</a></li>
<li><a href=/app/viewlogs.py title="View internal logs" class="logs head-submenu">Internal logs</a></li>
</li>
{% endif %}
@ -98,12 +98,13 @@
</ul>
</nav>
<div class="copyright-menu">
HAproxy-WI v2.9
HAproxy-WI v3.0
<br>
<a href="https://www.patreon.com/haproxy_wi" title="Donate" target="_blank" style="color: #fff; margin-left: 30px; color: red;" class="patreon"> Patreon</a>
</div>
</div>
</div>
<div id="cover"></div>
<div class="container">
{% if h2 %}
<h2>

View File

@ -2,7 +2,7 @@
{% block content %}
<script src="/inc/users.js"></script>
<table class="overview">
<caption class="overviewHead"><h3 style="margin-left: 20px; margin-bottom: 10px;">Create new HA cluster</h3></caption>
<caption><h3 style="margin-left: 20px; margin-bottom: 10px;">Create new HA cluster</h3></caption>
<tr class="overviewHead">
<td class="padding10 first-collumn">Master</td>
<td>Slave</td>
@ -48,7 +48,7 @@
</table>
<table>
<caption class="overviewHead"><h3 style="margin-left: 20px; margin-bottom: 10px;">Or add VRRP to exist</h3></caption>
<caption><h3 style="margin-left: 20px; margin-bottom: 10px;">Or add VRRP to exist</h3></caption>
<tr class="overviewHead">
<td class="padding10 first-collumn">Master</td>
<td>Slave</td>
@ -66,7 +66,7 @@
{% endfor %}
</select>
</td>
<td>
<td style="width: 23%;">
<select id="slave-add">
<option disable selected>Choose master</option>
{% for select in selects %}
@ -74,13 +74,13 @@
{% endfor %}
</select>
</td>
<td>
<td style="width: 15%;">
<input type="text" id="interface-add" class="form-control">
</td>
<td>
<td style="width: 16%;">
<input type="text" id="vrrp-ip-add" class="form-control">
</td>
<td>
<td style="width: 25%;">
<label for="kp"></label><input type="checkbox" id="kp">
</td>
<td>

View File

@ -0,0 +1,35 @@
{% extends "base.html" %}
{% block content %}
<script src="/inc/users.js"></script>
<div id="ajax"></div>
<table id="settings">
<tr class="overviewHead">
<td class="padding10 first-collumn" style="width: 10%;">
Parameter
</td>
<td>
Value
</td>
<td>
Description
</td>
</tr>
{% set section = namespace(section='') %}
{% for set in settings %}
{% if section.section|string() != set.2|string() %}
<th><h3 style="margin-left: 20px; margin-bottom: 10px;">{{ set.2 }} section</h3></th>
{% endif %}
{% set section.section = set.2 %}
<tr class="{{ loop.cycle('odd', 'even') }}">
<td class="addName">{{set.0}}</td>
<td class="addOption">
<input type="text" name="{{set.0}}" id="{{set.0}}" value="{{set.1}}" title="" size="25" class="form-control">
</td>
<td class="addOption">
{{set.3}}
</td>
</tr>
{% endfor %}
</table>
{% endblock %}

View File

@ -1,15 +0,0 @@
{% extends "base.html" %}
{% block content %}
<h3 style="padding-left: 30px; width:inherit; margin: 0" class="overviewHead padding10">Only view, edit you can here: {{ fullpath }}/haproxy-webintarface.config</h3>
<div style="padding-left: 40px;">
{% for name, value in config_items_section_name|dictsort(false) %}
<br><b>Section: {{name}}</b> <br>
<div style="padding-left:30px;">
{% for param, value2 in value|dictsort(false) %}
<br>{{param}} = {{value2}}
{% endfor %}
</div>
{% endfor %}
</div>
{% endblock %}

View File

@ -38,7 +38,7 @@ def main():
start_worker(serv)
def start_worker(serv):
port = funct.get_config_var('haproxy', 'haproxy_sock_port')
port = sql.get_setting('haproxy_sock_port')
cmd = "tools/checker_worker.py %s --port %s &" % (serv, port)
os.system(cmd)
funct.logging("localhost", " Masrer started new worker for: "+serv, alerting=1)

View File

@ -39,7 +39,7 @@ def main():
start_worker(serv)
def start_worker(serv):
port = funct.get_config_var('haproxy', 'haproxy_sock_port')
port = sql.get_setting('haproxy_sock_port')
cmd = "tools/metrics_worker.py %s --port %s &" % (serv, port)
os.system(cmd)
funct.logging("localhost", " Masrer started new metrics worker for: "+serv, metrics=1)

View File

@ -11,6 +11,7 @@ template = env.get_template('admin.html')
form = cgi.FieldStorage()
print('Content-type: text/html\n')
funct.check_login()
funct.page_for_admin()
try:

View File

@ -25,7 +25,7 @@ funct.check_login()
funct.page_for_admin()
log_path = funct.get_config_var('main', 'log_path')
time_storage = funct.get_config_var('logs', 'log_time_storage')
time_storage = sql.get_setting('log_time_storage')
time_storage = int(time_storage)
try:

View File

@ -130,9 +130,11 @@ function hideAutoRefreshDiv() {
});
}
$( document ).ajaxSend(function( event, request, settings ) {
$('#cover').fadeIn('fast');
NProgress.start();
});
$( document ).ajaxComplete(function( event, request, settings ) {
$('#cover').fadeOut('fast');
NProgress.done();
});

View File

@ -72,13 +72,23 @@ pre {
}
.container {
min-height: calc(100vh - 115px);
min-height: calc(100vh - 0px);
max-width: 91%;
min-width: 40%;
background-color: #fff;
margin-left: 207px;
padding-bottom: 10px;
}
#cover {
position: absolute;
display: none;
top:0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0,0,0,.1);
z-index: 500;
}
.login {
float: right;
margin-top: 5px;

View File

@ -360,6 +360,13 @@ $( function() {
updateSSH(id[1])
sshKeyEnableShow(id[1])
});
$( "#settings input" ).change(function() {
var id = $(this).attr('id');
var val = $(this).val();
console.log(id)
console.log(val)
updateSettings(id, val);
});
$('#new-ssh_enable').click(function() {
if ($('#new-ssh_enable').is(':checked')) {
$('#ssh_pass').css('display', 'none');
@ -381,6 +388,30 @@ $( function() {
updateTelegram(id[1])
});
} );
function updateSettings(param, val) {
$('.alert-danger').remove();
$.ajax( {
url: "sql.py",
data: {
updatesettings: param,
val: val
},
type: "GET",
success: function( data ) {
data = data.replace(/\s+/g,' ');
if (data.indexOf('error') != '-1') {
$("#ajax").append(data);
$.getScript(users);
} else {
$('.alert-danger').remove();
$("#"+param).parent().parent().addClass( "update", 1000 );
setTimeout(function() {
$( "#"+param ).parent().parent().removeClass( "update" );
}, 2500 );
}
}
} );
}
function sshKeyEnableShow(id) {
$('#ssh_enable-'+id).click(function() {
if ($('#ssh_enable-'+id).is(':checked')) {

View File

@ -408,14 +408,14 @@ echo ""
echo ""
echo "################################"
mkdir /var/www/$HOME_HAPROXY_WI/app/certs
mkdir /var/www/$HOME_HAPROXY_WI/keys
chmod +x /var/www/$HOME_HAPROXY_WI/app/*.py
chmod +x /var/www/$HOME_HAPROXY_WI/app/tools/*.py
rm -f /var/www/$HOME_HAPROXY_WI/log/config_edit.log
sudo mkdir /var/www/$HOME_HAPROXY_WI/app/certs
sudo mkdir /var/www/$HOME_HAPROXY_WI/keys
sudo sudo chmod +x /var/www/$HOME_HAPROXY_WI/app/*.py
sudo chmod +x /var/www/$HOME_HAPROXY_WI/app/tools/*.py
sudo rm -f /var/www/$HOME_HAPROXY_WI/log/config_edit.log
cd /var/www/$HOME_HAPROXY_WI/app
./update_db.py
chown -R apache:apache /var/www/$HOME_HAPROXY_WI/
chown -R apache:apache /var/log/httpd/
sudo chown -R apache:apache /var/www/$HOME_HAPROXY_WI/
sudo chown -R apache:apache /var/log/httpd/
exit 0