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 # 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 # Donate
Support the project Support the project

View File

@ -35,7 +35,7 @@ output_from_parsed_template = template.render(title = "Add",
print(output_from_parsed_template) print(output_from_parsed_template)
hap_configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir') 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: if form.getvalue('mode') is not None:
serv = form.getvalue('serv') serv = form.getvalue('serv')

View File

@ -15,7 +15,6 @@ if mysql_enable == '1':
from mysql.connector import errorcode from mysql.connector import errorcode
import mysql.connector as sqltool import mysql.connector as sqltool
else: else:
fullpath = funct.get_config_var('main', 'fullpath')
db = funct.get_app_dir()+"/haproxy-wi.db" db = funct.get_app_dir()+"/haproxy-wi.db"
import sqlite3 as sqltool import sqlite3 as sqltool
@ -498,16 +497,71 @@ def update_db_v_2_91(**kwargs):
except sqltool.Error as e: except sqltool.Error as e:
if kwargs.get('silent') != 1: if kwargs.get('silent') != 1:
if e.args[0] == 'column param is not unique' or e == "1060 (42S21): Duplicate column name 'cred' ": 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: else:
print("An error occurred:", e) print("An error occurred:", e)
return False return False
else: else:
print("DB was update to 2.9 It\' last version<br />") print("Updating... go to version 3.0<br />")
return True return True
cur.close() cur.close()
con.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(): def update_all():
update_db_v_2_0_1() update_db_v_2_0_1()
update_db_v_2_0_1_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_8_2()
update_db_v_2_9() update_db_v_2_9()
update_db_v_2_91() update_db_v_2_91()
update_db_v_3()
def update_all_silent(): def update_all_silent():
update_db_v_2_0_1(silent=1) 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_8_2(silent=1)
update_db_v_2_9(silent=1) update_db_v_2_9(silent=1)
update_db_v_2_91(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)) print('<center><div class="alert alert-danger">Check the config file. Presence section %s and parameter %s</div>' % (sec, var))
def get_data(type): 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': if type == 'config':
fmt = "%Y-%m-%d.%H:%M:%S" fmt = "%Y-%m-%d.%H:%M:%S"
if type == 'logs': if type == 'logs':
@ -85,7 +86,7 @@ def telegram_send_mess(mess, **kwargs):
token_bot = telegram[1] token_bot = telegram[1]
channel_name = telegram[2] channel_name = telegram[2]
proxy = get_config_var('main', 'proxy') proxy = sql.get_setting('proxy')
if proxy is not None: if proxy is not None:
apihelper.proxy = {'https': proxy} apihelper.proxy = {'https': proxy}
@ -213,11 +214,12 @@ def ssh_connect(serv, **kwargs):
return error return error
def get_config(serv, cfg, **kwargs): def get_config(serv, cfg, **kwargs):
import sql
error = "" error = ""
if kwargs.get("keepalived"): if kwargs.get("keepalived"):
config_path = "/etc/keepalived/keepalived.conf" config_path = "/etc/keepalived/keepalived.conf"
else: else:
config_path = get_config_var('haproxy', 'haproxy_config_path') config_path = sql.get_setting('haproxy_config_path')
ssh = ssh_connect(serv) ssh = ssh_connect(serv)
try: try:
@ -296,15 +298,23 @@ def diff_config(oldcfg, cfg):
pass pass
def install_haproxy(serv, **kwargs): def install_haproxy(serv, **kwargs):
import sql
script = "install_haproxy.sh" script = "install_haproxy.sh"
tmp_config_path = get_config_var('haproxy', 'tmp_config_path') tmp_config_path = sql.get_setting('tmp_config_path')
proxy = get_config_var('main', 'proxy') 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) os.system("cp scripts/%s ." % script)
if proxy is not None: if proxy is not None:
proxy_serv = proxy proxy_serv = proxy
else: else:
proxy_serv = "" 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) upload(serv, tmp_config_path, script)
ssh_command(serv, commands) ssh_command(serv, commands)
@ -315,8 +325,9 @@ def install_haproxy(serv, **kwargs):
os.system("rm -f %s" % script) os.system("rm -f %s" % script)
def syn_flood_protect(serv, **kwargs): def syn_flood_protect(serv, **kwargs):
import sql
script = "syn_flood_protect.sh" 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": if kwargs.get('enable') == "0":
enable = "disable" enable = "disable"
@ -348,7 +359,8 @@ def upload(serv, path, file, **kwargs):
print('<div class="alert alert-danger">Upload fail: %s</div>' % e) print('<div class="alert alert-danger">Upload fail: %s</div>' % e)
def upload_and_restart(serv, cfg, **kwargs): 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 = "" error = ""
try: 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" ] commands = [ "sudo mv -f " + tmp_file + " /etc/keepalived/keepalived.conf", "sudo systemctl restart keepalived" ]
else: else:
if kwargs.get("just_save") == "save": 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: 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: try:
if get_config_var('haproxy', 'firewall_enable') == "1": if sql.get_setting('firewall_enable') == "1":
commands.extend(open_port_firewalld(cfg)) commands.extend(open_port_firewalld(cfg))
except: except:
return 'Please check the config for the presence of the parameter - "firewall_enable". Mast be: "0" or "1". Firewalld configure not working now' 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 return firewalld_commands
def check_haproxy_config(serv): 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) ssh = ssh_connect(serv)
for command in commands: for command in commands:
stdin , stdout, stderr = ssh.exec_command(command) stdin , stdout, stderr = ssh.exec_command(command)

View File

@ -4,12 +4,6 @@ fullpath = /var/www/haproxy-wi
cgi_path = ${fullpath}/app/ cgi_path = ${fullpath}/app/
log_path = ${fullpath}/log/ log_path = ${fullpath}/log/
cert_local_dir = ${cgi_path}/certs/ 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] [configs]
#Dir where configs will be save #Dir where configs will be save
@ -23,39 +17,3 @@ mysql_user = haproxy-wi
mysql_password = haproxy-wi mysql_password = haproxy-wi
mysql_db = haproxywi mysql_db = haproxywi
mysql_host = 127.0.0.1 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 create_db
import datetime import datetime
import uuid import uuid
from configparser import ConfigParser, ExtendedInterpolation
from jinja2 import Environment, FileSystemLoader from jinja2 import Environment, FileSystemLoader
env = Environment(loader=FileSystemLoader('templates/')) env = Environment(loader=FileSystemLoader('templates/'))
template = env.get_template('login.html') template = env.get_template('login.html')
@ -24,10 +23,6 @@ db_create = ""
error_log = "" error_log = ""
error = "" error = ""
path_config = "haproxy-webintarface.config"
config = ConfigParser(interpolation=ExtendedInterpolation())
config.read(path_config)
if ref is None: if ref is None:
ref = "/index.html" 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 />' error_log = '<div class="alert alert-danger">Somthing wrong :( I\'m sad about this, but try again!</div><br /><br />'
try: try:
if config.get('main', 'session_ttl'): if sql.get_setting('session_ttl'):
session_ttl = config.getint('main', 'session_ttl') session_ttl = sql.get_setting('session_ttl')
except: 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 pass
try: try:
@ -61,8 +56,11 @@ if form.getvalue('logout'):
if login is not None and password is not None: if login is not None and password is not None:
USERS = sql.select_users() USERS = sql.select_users()
session_ttl = config.getint('main', 'session_ttl') session_ttl = int()
expires = datetime.datetime.utcnow() + datetime.timedelta(days=session_ttl) 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_uuid = str(uuid.uuid4())
user_token = str(uuid.uuid4()) user_token = str(uuid.uuid4())

View File

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

View File

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

View File

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

View File

@ -1,39 +1,31 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import html, http import html
import cgi import cgi
import sys
import os import os
import funct, sql import funct
from configparser import ConfigParser, ExtendedInterpolation import sql
import http
from jinja2 import Environment, FileSystemLoader from jinja2 import Environment, FileSystemLoader
env = Environment(loader=FileSystemLoader('templates/')) env = Environment(loader=FileSystemLoader('templates/'))
template = env.get_template('viewsettings.html') template = env.get_template('settings.html')
form = cgi.FieldStorage()
path_config = "haproxy-webintarface.config"
config = ConfigParser(interpolation=ExtendedInterpolation())
config.read(path_config)
fullpath = config.get('main', 'fullpath')
print('Content-type: text/html\n') print('Content-type: text/html\n')
funct.check_login() funct.check_login()
funct.page_for_admin() funct.page_for_admin()
try: try:
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE")) cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
user_id = cookie.get('uuid') user_id = cookie.get('uuid')
user = sql.get_user_name_by_uuid(user_id.value) 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: except:
pass 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", template = template.render(h2 = 1, title = "Settings",
role = sql.get_user_role_by_uuid(user_id.value), role = sql.get_user_role_by_uuid(user_id.value),
user = user, user = user,
fullpath = fullpath, settings = settings,
config_items_section_name = config_items_section_name) token = token)
print(output_from_parsed_template) print(template)

View File

@ -285,7 +285,7 @@ def get_enable_checkbox(id, **kwargs):
def write_user_uuid(login, user_uuid): def write_user_uuid(login, user_uuid):
con, cur = create_db.get_cur() 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) session_ttl = int(session_ttl)
sql = """ select id from user where username = '%s' """ % login sql = """ select id from user where username = '%s' """ % login
try: try:
@ -308,7 +308,7 @@ def write_user_uuid(login, user_uuid):
def write_user_token(login, user_token): def write_user_token(login, user_token):
con, cur = create_db.get_cur() 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 sql = """ select id from user where username = '%s' """ % login
try: try:
cur.execute(sql) cur.execute(sql)
@ -374,7 +374,7 @@ def delete_old_uuid():
def update_last_act_user(uuid): def update_last_act_user(uuid):
con, cur = create_db.get_cur() 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': if mysql_enable == '1':
sql = """ update uuid set exp = now()+ INTERVAL %s day where uuid = '%s' """ % (session_ttl, uuid) 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() cur.close()
con.close() con.close()
def get_setting(param): def get_setting(param, **kwargs):
con, cur = create_db.get_cur() con, cur = create_db.get_cur()
sql = """select value from `settings` where param='%s' """ % param sql = """select value from `settings` where param='%s' """ % param
if kwargs.get('all'):
sql = """select * from `settings` order by section desc"""
try: try:
cur.execute(sql) cur.execute(sql)
except sqltool.Error as e: 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>') print('<span class="alert alert-danger" id="error">An error occurred: ' + e + ' <a title="Close" id="errorMess"><b>X</b></a></span>')
else: else:
for value in cur.fetchone(): if kwargs.get('all'):
return value return cur
else:
for value in cur.fetchone():
return value
cur.close() cur.close()
con.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): def show_update_telegram(token, page):
from jinja2 import Environment, FileSystemLoader from jinja2 import Environment, FileSystemLoader
env = Environment(loader=FileSystemLoader('templates/ajax')) env = Environment(loader=FileSystemLoader('templates/ajax'))
@ -1135,4 +1152,8 @@ if form.getvalue('updatetoken') is not None:
print(error_mess) print(error_mess)
else: else:
print('Content-type: text/html\n') 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#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#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/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><a href=/app/viewlogs.py title="View internal logs" class="logs head-submenu">Internal logs</a></li>
</li> </li>
{% endif %} {% endif %}
@ -98,12 +98,13 @@
</ul> </ul>
</nav> </nav>
<div class="copyright-menu"> <div class="copyright-menu">
HAproxy-WI v2.9 HAproxy-WI v3.0
<br> <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> <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>
</div> </div>
<div id="cover"></div>
<div class="container"> <div class="container">
{% if h2 %} {% if h2 %}
<h2> <h2>

View File

@ -2,7 +2,7 @@
{% block content %} {% block content %}
<script src="/inc/users.js"></script> <script src="/inc/users.js"></script>
<table class="overview"> <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"> <tr class="overviewHead">
<td class="padding10 first-collumn">Master</td> <td class="padding10 first-collumn">Master</td>
<td>Slave</td> <td>Slave</td>
@ -48,7 +48,7 @@
</table> </table>
<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"> <tr class="overviewHead">
<td class="padding10 first-collumn">Master</td> <td class="padding10 first-collumn">Master</td>
<td>Slave</td> <td>Slave</td>
@ -66,7 +66,7 @@
{% endfor %} {% endfor %}
</select> </select>
</td> </td>
<td> <td style="width: 23%;">
<select id="slave-add"> <select id="slave-add">
<option disable selected>Choose master</option> <option disable selected>Choose master</option>
{% for select in selects %} {% for select in selects %}
@ -74,13 +74,13 @@
{% endfor %} {% endfor %}
</select> </select>
</td> </td>
<td> <td style="width: 15%;">
<input type="text" id="interface-add" class="form-control"> <input type="text" id="interface-add" class="form-control">
</td> </td>
<td> <td style="width: 16%;">
<input type="text" id="vrrp-ip-add" class="form-control"> <input type="text" id="vrrp-ip-add" class="form-control">
</td> </td>
<td> <td style="width: 25%;">
<label for="kp"></label><input type="checkbox" id="kp"> <label for="kp"></label><input type="checkbox" id="kp">
</td> </td>
<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) start_worker(serv)
def 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) cmd = "tools/checker_worker.py %s --port %s &" % (serv, port)
os.system(cmd) os.system(cmd)
funct.logging("localhost", " Masrer started new worker for: "+serv, alerting=1) funct.logging("localhost", " Masrer started new worker for: "+serv, alerting=1)

View File

@ -39,7 +39,7 @@ def main():
start_worker(serv) start_worker(serv)
def 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) cmd = "tools/metrics_worker.py %s --port %s &" % (serv, port)
os.system(cmd) os.system(cmd)
funct.logging("localhost", " Masrer started new metrics worker for: "+serv, metrics=1) 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() form = cgi.FieldStorage()
print('Content-type: text/html\n') print('Content-type: text/html\n')
funct.check_login() funct.check_login()
funct.page_for_admin() funct.page_for_admin()
try: try:

View File

@ -25,7 +25,7 @@ funct.check_login()
funct.page_for_admin() funct.page_for_admin()
log_path = funct.get_config_var('main', 'log_path') 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) time_storage = int(time_storage)
try: try:

View File

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

View File

@ -72,13 +72,23 @@ pre {
} }
.container { .container {
min-height: calc(100vh - 115px); min-height: calc(100vh - 0px);
max-width: 91%; max-width: 91%;
min-width: 40%; min-width: 40%;
background-color: #fff; background-color: #fff;
margin-left: 207px; margin-left: 207px;
padding-bottom: 10px; 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 { .login {
float: right; float: right;
margin-top: 5px; margin-top: 5px;

View File

@ -360,6 +360,13 @@ $( function() {
updateSSH(id[1]) updateSSH(id[1])
sshKeyEnableShow(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() { $('#new-ssh_enable').click(function() {
if ($('#new-ssh_enable').is(':checked')) { if ($('#new-ssh_enable').is(':checked')) {
$('#ssh_pass').css('display', 'none'); $('#ssh_pass').css('display', 'none');
@ -381,6 +388,30 @@ $( function() {
updateTelegram(id[1]) 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) { function sshKeyEnableShow(id) {
$('#ssh_enable-'+id).click(function() { $('#ssh_enable-'+id).click(function() {
if ($('#ssh_enable-'+id).is(':checked')) { if ($('#ssh_enable-'+id).is(':checked')) {

View File

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