Meet version 2.5.4.4! Improved reading of the config and output of errors!
pull/19/head
Aidaho12 2018-05-17 14:13:54 +06:00
parent 26793bc197
commit c270d5d144
20 changed files with 114 additions and 171 deletions

View File

@ -2,7 +2,6 @@
import html import html
import cgi import cgi
import os import os
from configparser import ConfigParser, ExtendedInterpolation
import funct import funct
import sql import sql
import http import http
@ -31,11 +30,8 @@ output_from_parsed_template = template.render(title = "Add",
conf_add = form.getvalue('conf')) conf_add = form.getvalue('conf'))
print(output_from_parsed_template) print(output_from_parsed_template)
path_config = "haproxy-webintarface.config" hap_configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir')
config = ConfigParser(interpolation=ExtendedInterpolation()) cert_path = funct.get_config_var('haproxy', 'cert_path')
config.read(path_config)
hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir')
cert_path = config.get('haproxy', '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

@ -31,8 +31,6 @@ try:
except: except:
pass pass
#print(sql.get_dick_permit())
output_from_parsed_template = template.render(h2 = 1, output_from_parsed_template = template.render(h2 = 1,
autorefresh = 1, autorefresh = 1,
title = "Show Apache logs", title = "Show Apache logs",

View File

@ -3,15 +3,16 @@ import html
import cgi import cgi
import os import os
import http.cookies import http.cookies
from configparser import ConfigParser, ExtendedInterpolation
import funct import funct
import sql import sql
from jinja2 import Environment, FileSystemLoader from jinja2 import Environment, FileSystemLoader
env = Environment(loader=FileSystemLoader('templates/')) env = Environment(loader=FileSystemLoader('templates/'))
template = env.get_template('config.html') template = env.get_template('config.html')
print('Content-type: text/html\n') print('Content-type: text/html\n')
funct.check_login() funct.check_login()
funct.page_for_admin(level = 2) funct.page_for_admin(level = 2)
form = cgi.FieldStorage() form = cgi.FieldStorage()
serv = form.getvalue('serv') serv = form.getvalue('serv')
config_read = "" config_read = ""
@ -28,12 +29,8 @@ try:
except: except:
pass pass
path_config = "haproxy-webintarface.config" log_path = funct.get_config_var('main', 'log_path')
config = ConfigParser(interpolation=ExtendedInterpolation()) hap_configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir')
config.read(path_config)
log_path = config.get('main', 'log_path')
hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir')
if serv is not None: if serv is not None:
cfg = hap_configs_dir + serv + "-" + funct.get_data('config') + ".cfg" cfg = hap_configs_dir + serv + "-" + funct.get_data('config') + ".cfg"

View File

@ -4,17 +4,19 @@ import cgi
import os, http.cookies import os, http.cookies
import funct import funct
import sql import sql
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('configver.html') template = env.get_template('configver.html')
print('Content-type: text/html\n') print('Content-type: text/html\n')
funct.check_login() funct.check_login()
funct.page_for_admin(level = 2) funct.page_for_admin(level = 2)
form = cgi.FieldStorage() form = cgi.FieldStorage()
serv = form.getvalue('serv') serv = form.getvalue('serv')
configver = form.getvalue('configver')
hap_configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir')
config_read = "" config_read = ""
configver = ""
stderr = "" stderr = ""
aftersave = "" aftersave = ""
error = "" error = ""
@ -27,14 +29,6 @@ try:
except: except:
pass pass
path_config = "haproxy-webintarface.config"
config = ConfigParser(interpolation=ExtendedInterpolation())
config.read(path_config)
form = cgi.FieldStorage()
serv = form.getvalue('serv')
configver = form.getvalue('configver')
hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir')
def get_files(): def get_files():
import glob import glob
file = set() file = set()

View File

@ -3,23 +3,19 @@ import cgi
import html import html
import os import os
import sys import sys
from configparser import ConfigParser, ExtendedInterpolation import funct
path_config = "haproxy-webintarface.config" mysql_enable = funct.get_config_var('mysql', 'enable')
config = ConfigParser(interpolation=ExtendedInterpolation())
config.read(path_config)
mysql_enable = config.get('mysql', 'enable')
fullpath = config.get('main', 'fullpath')
if mysql_enable == '1': if mysql_enable == '1':
mysql_user = config.get('mysql', 'mysql_user') mysql_user = funct.get_config_var('mysql', 'mysql_user')
mysql_password = config.get('mysql', 'mysql_password') mysql_password = funct.get_config_var('mysql', 'mysql_password')
mysql_db = config.get('mysql', 'mysql_db') mysql_db = funct.get_config_var('mysql', 'mysql_db')
mysql_host = config.get('mysql', 'mysql_host') mysql_host = funct.get_config_var('mysql', 'mysql_host')
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 = fullpath+"/app/haproxy-wi.db" db = fullpath+"/app/haproxy-wi.db"
import sqlite3 as sqltool import sqlite3 as sqltool

View File

@ -3,15 +3,15 @@ import html, http.cookies
import cgi import cgi
import os import os
import funct, sql import funct, sql
from configparser import ConfigParser, ExtendedInterpolation
import glob import glob
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('delver.html') template = env.get_template('delver.html')
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()
form = cgi.FieldStorage() form = cgi.FieldStorage()
serv = form.getvalue('serv') serv = form.getvalue('serv')
stderr = "" stderr = ""
@ -26,13 +26,10 @@ try:
except: except:
pass pass
path_config = "haproxy-webintarface.config"
config = ConfigParser(interpolation=ExtendedInterpolation())
config.read(path_config)
form = cgi.FieldStorage() form = cgi.FieldStorage()
serv = form.getvalue('serv') serv = form.getvalue('serv')
Select = form.getvalue('del') Select = form.getvalue('del')
hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir') hap_configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir')
def get_files(): def get_files():
import glob import glob

View File

@ -8,29 +8,25 @@ from datetime import datetime
from pytz import timezone from pytz import timezone
from configparser import ConfigParser, ExtendedInterpolation from configparser import ConfigParser, ExtendedInterpolation
path_config = "haproxy-webintarface.config"
config = ConfigParser(interpolation=ExtendedInterpolation())
config.read(path_config)
form = cgi.FieldStorage() form = cgi.FieldStorage()
serv = form.getvalue('serv') serv = form.getvalue('serv')
fullpath = config.get('main', 'fullpath')
time_zone = config.get('main', 'time_zone')
proxy = config.get('main', 'proxy')
ssh_keys = config.get('ssh', 'ssh_keys')
haproxy_configs_server = config.get('configs', 'haproxy_configs_server')
hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir')
haproxy_config_path = config.get('haproxy', 'haproxy_config_path')
tmp_config_path = config.get('haproxy', 'tmp_config_path')
restart_command = config.get('haproxy', 'restart_command')
def check_config(): def get_config_var(sec, var):
for section in [ 'main', 'configs', 'ssh', 'logs', 'haproxy' ]: try:
if not config.has_section(section): path_config = "haproxy-webintarface.config"
print('<center><div class="alert alert-danger">Check config file, no %s section</div>' % section) config = ConfigParser(interpolation=ExtendedInterpolation())
config.read(path_config)
except:
print('<center><div class="alert alert-danger">Check the config file, whether it exists and the path. Must be in: app/haproxy-webintarface.config</div>')
try:
var = config.get(sec, var)
return var
except:
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(time_zone)) now_utc = datetime.now(timezone(get_config_var('main', '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':
@ -40,13 +36,13 @@ def get_data(type):
def logging(serv, action): def logging(serv, action):
import sql import sql
dateFormat = "%b %d %H:%M:%S" dateFormat = "%b %d %H:%M:%S"
now_utc = datetime.now(timezone(time_zone)) now_utc = datetime.now(timezone(get_config_var('main', 'time_zone')))
IP = cgi.escape(os.environ["REMOTE_ADDR"]) IP = cgi.escape(os.environ["REMOTE_ADDR"])
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE")) cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
user_uuid = cookie.get('uuid') user_uuid = cookie.get('uuid')
login = sql.get_user_name_by_uuid(user_uuid.value) login = sql.get_user_name_by_uuid(user_uuid.value)
mess = now_utc.strftime(dateFormat) + " from " + IP + " user: " + login + " " + action + " for: " + serv + "\n" mess = now_utc.strftime(dateFormat) + " from " + IP + " user: " + login + " " + action + " for: " + serv + "\n"
log_path = config.get('main', 'log_path') log_path = get_config_var('main', 'log_path')
try: try:
log = open(log_path + "/config_edit-"+get_data('logs')+".log", "a") log = open(log_path + "/config_edit-"+get_data('logs')+".log", "a")
@ -56,12 +52,13 @@ def logging(serv, action):
print('<center><div class="alert alert-danger">Can\'t read write log. Please chech log_path in config</div></center>') print('<center><div class="alert alert-danger">Can\'t read write log. Please chech log_path in config</div></center>')
pass pass
if config.get('telegram', 'enable') == "1": telegram_send_mess(mess) if get_config_var('telegram', 'enable') == "1": telegram_send_mess(mess)
def telegram_send_mess(mess): def telegram_send_mess(mess):
import telegram import telegram
token_bot = config.get('telegram', 'token') token_bot = get_config_var('telegram', 'token')
channel_name = config.get('telegram', 'channel_name') channel_name = get_config_var('telegram', 'channel_name')
proxy = get_config_var('main', 'proxy')
if proxy is not None: if proxy is not None:
pp = telegram.utils.request.Request(proxy_url=proxy) pp = telegram.utils.request.Request(proxy_url=proxy)
@ -130,7 +127,7 @@ def ssh_connect(serv, **kwargs):
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try: try:
if ssh_enable == 1: if ssh_enable == 1:
k = paramiko.RSAKey.from_private_key_file(ssh_keys) k = paramiko.RSAKey.from_private_key_file(get_config_var('ssh', 'ssh_keys'))
ssh.connect(hostname = serv, username = ssh_user_name, pkey = k ) ssh.connect(hostname = serv, username = ssh_user_name, pkey = k )
else: else:
ssh.connect(hostname = serv, username = ssh_user_name, password = sql.select_ssh_password()) ssh.connect(hostname = serv, username = ssh_user_name, password = sql.select_ssh_password())
@ -188,7 +185,7 @@ def get_config(serv, cfg, **kwargs):
if kwargs.get("keepalived"): if kwargs.get("keepalived"):
config_path = "/etc/keepalived/keepalived.conf" config_path = "/etc/keepalived/keepalived.conf"
else: else:
config_path = haproxy_config_path config_path = get_config_var('haproxy', 'haproxy_config_path')
ssh = ssh_connect(serv) ssh = ssh_connect(serv)
try: try:
@ -246,6 +243,8 @@ def show_config(cfg):
def install_haproxy(serv): def install_haproxy(serv):
script = "install_haproxy.sh" script = "install_haproxy.sh"
tmp_config_path = get_config_var('haproxy', 'tmp_config_path')
proxy = get_config_var('main', '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
@ -274,7 +273,7 @@ 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 = tmp_config_path + "/" + get_data('config') + ".cfg" tmp_file = get_config_var('haproxy', 'tmp_config_path') + "/" + get_data('config') + ".cfg"
error = "" error = ""
try: try:
@ -297,11 +296,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 + " " + haproxy_config_path ] commands = [ "sudo /sbin/haproxy -q -c -f " + tmp_file + "&& sudo mv -f " + tmp_file + " " + get_config_var('haproxy', 'haproxy_config_path') ]
else: else:
commands = [ "sudo /sbin/haproxy -q -c -f " + tmp_file + "&& sudo mv -f " + tmp_file + " " + haproxy_config_path + " && sudo " + restart_command ] 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') ]
try: try:
if config.get('haproxy', 'firewall_enable') == "1": if get_config_var('haproxy', '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'
@ -332,7 +331,7 @@ 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" % haproxy_config_path ] commands = [ "/sbin/haproxy -q -c -f %s" % get_config_var('haproxy', '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

@ -3,13 +3,14 @@ import html, http.cookies
import cgi import cgi
import os import os
import funct, sql import funct, sql
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('ha.html') template = env.get_template('ha.html')
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()
form = cgi.FieldStorage() form = cgi.FieldStorage()
serv = form.getvalue('serv') serv = form.getvalue('serv')

View File

@ -3,14 +3,13 @@ import html, http.cookies
import cgi import cgi
import os import os
import funct, sql import funct, sql
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('ihap.html') template = env.get_template('ihap.html')
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()
form = cgi.FieldStorage()
try: try:
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE")) cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))

View File

@ -3,17 +3,20 @@ import html
import cgi import cgi
import os import os
import http.cookies import http.cookies
from configparser import ConfigParser, ExtendedInterpolation
import funct import funct
import sql import sql
from jinja2 import Environment, FileSystemLoader from jinja2 import Environment, FileSystemLoader
env = Environment(loader=FileSystemLoader('templates/')) env = Environment(loader=FileSystemLoader('templates/'))
template = env.get_template('config.html') template = env.get_template('config.html')
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()
form = cgi.FieldStorage() form = cgi.FieldStorage()
serv = form.getvalue('serv') serv = form.getvalue('serv')
log_path = funct.get_config_var('main', 'log_path')
kp_save_configs_dir = funct.get_config_var('configs', 'kp_save_configs_dir')
config_read = "" config_read = ""
cfg = "" cfg = ""
stderr = "" stderr = ""
@ -28,13 +31,6 @@ try:
except: except:
pass pass
path_config = "haproxy-webintarface.config"
config = ConfigParser(interpolation=ExtendedInterpolation())
config.read(path_config)
log_path = config.get('main', 'log_path')
kp_save_configs_dir = config.get('configs', 'kp_save_configs_dir')
if serv is not None: if serv is not None:
cfg = kp_save_configs_dir+ serv + '-' + funct.get_data('config') + '.conf' cfg = kp_save_configs_dir+ serv + '-' + funct.get_data('config') + '.conf'

View File

@ -8,13 +8,6 @@ import subprocess
import funct import funct
import sql import sql
import ovw import ovw
from configparser import ConfigParser, ExtendedInterpolation
path_config = "haproxy-webintarface.config"
config = ConfigParser(interpolation=ExtendedInterpolation())
config.read(path_config)
funct.check_config()
form = cgi.FieldStorage() form = cgi.FieldStorage()
req = form.getvalue('req') req = form.getvalue('req')
@ -31,7 +24,7 @@ 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'):
ssh_keys = config.get('ssh', 'ssh_keys') ssh_keys = funct.get_config_var('ssh', 'ssh_keys')
try: try:
with open(ssh_keys, "w") as conf: with open(ssh_keys, "w") as conf:
@ -46,8 +39,8 @@ if form.getvalue('ssh_cert'):
pass pass
if serv and form.getvalue('ssl_cert'): if serv and form.getvalue('ssl_cert'):
cert_local_dir = config.get('main', 'cert_local_dir') cert_local_dir = funct.get_config_var('main', 'cert_local_dir')
cert_path = config.get('haproxy', 'cert_path') cert_path = funct.get_config_var('haproxy', '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>')
@ -121,10 +114,10 @@ if form.getvalue('action'):
import requests import requests
from requests_toolbelt.utils import dump from requests_toolbelt.utils import dump
haproxy_user = config.get('haproxy', 'stats_user') haproxy_user = funct.get_config_var('haproxy', 'stats_user')
haproxy_pass = config.get('haproxy', 'stats_password') haproxy_pass = funct.get_config_var('haproxy', 'stats_password')
stats_port = config.get('haproxy', 'stats_port') stats_port = funct.get_config_var('haproxy', 'stats_port')
stats_page = config.get('haproxy', 'stats_page') stats_page = funct.get_config_var('haproxy', 'stats_page')
postdata = { postdata = {
'action' : form.getvalue('action'), 'action' : form.getvalue('action'),
@ -145,10 +138,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 = config.get('haproxy', 'stats_user') haproxy_user = funct.get_config_var('haproxy', 'stats_user')
haproxy_pass = config.get('haproxy', 'stats_password') haproxy_pass = funct.get_config_var('haproxy', 'stats_password')
stats_port = config.get('haproxy', 'stats_port') stats_port = funct.get_config_var('haproxy', 'stats_port')
stats_page = config.get('haproxy', 'stats_page') stats_page = funct.get_config_var('haproxy', '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:
@ -177,14 +170,14 @@ if serv is not None and form.getvalue('rows') is not None:
grep_act = '' grep_act = ''
grep = '' grep = ''
syslog_server_enable = config.get('logs', 'syslog_server_enable') syslog_server_enable = funct.get_config_var('logs', '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 = config.get('logs', 'local_path_logs') local_path_logs = funct.get_config_var('logs', 'local_path_logs')
syslog_server = serv syslog_server = serv
commands = [ 'sudo tail -%s %s %s %s' % (rows, local_path_logs, grep_act, grep) ] commands = [ 'sudo tail -%s %s %s %s' % (rows, local_path_logs, grep_act, grep) ]
else: else:
commands = [ 'sudo tail -%s /var/log/%s/syslog.log %s %s' % (rows, serv, grep_act, grep) ] commands = [ 'sudo tail -%s /var/log/%s/syslog.log %s %s' % (rows, serv, grep_act, grep) ]
syslog_server = config.get('logs', 'syslog_server') syslog_server = funct.get_config_var('logs', 'syslog_server')
print('<div id="logs">') print('<div id="logs">')
funct.ssh_command(syslog_server, commands, show_log="1") funct.ssh_command(syslog_server, commands, show_log="1")
print('</div>') print('</div>')
@ -211,8 +204,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 = config.get('haproxy', 'server_state_file') server_state_file = funct.get_config_var('haproxy', 'server_state_file')
haproxy_sock = config.get('haproxy', 'haproxy_sock') haproxy_sock = funct.get_config_var('haproxy', 'haproxy_sock')
enable = form.getvalue('servaction') enable = form.getvalue('servaction')
backend = form.getvalue('servbackend') backend = form.getvalue('servbackend')
@ -241,7 +234,7 @@ if serv is not None and act == "configShow":
import os import os
from datetime import datetime from datetime import datetime
from pytz import timezone from pytz import timezone
hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir') hap_configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir')
if form.getvalue('configver') is None: if form.getvalue('configver') is None:
cfg = hap_configs_dir + serv + "-" + funct.get_data('config') + ".cfg" cfg = hap_configs_dir + serv + "-" + funct.get_data('config') + ".cfg"
@ -272,10 +265,7 @@ if serv is not None and act == "configShow":
if form.getvalue('viewlogs') is not None: if form.getvalue('viewlogs') is not None:
viewlog = form.getvalue('viewlogs') viewlog = form.getvalue('viewlogs')
try: log_path = funct.get_config_var('main', 'log_path')
log_path = config.get('main', 'log_path')
except:
print('<div class="alert alert-warning">Please check the config for the presence of the parameter - "log_path". </div>')
try: try:
log = open(log_path + viewlog, "r",encoding='utf-8', errors='ignore') log = open(log_path + viewlog, "r",encoding='utf-8', errors='ignore')
@ -298,7 +288,7 @@ if form.getvalue('master'):
interface = form.getvalue('interface') interface = form.getvalue('interface')
vrrpip = form.getvalue('vrrpip') vrrpip = form.getvalue('vrrpip')
hap = form.getvalue('hap') hap = form.getvalue('hap')
tmp_config_path = config.get('haproxy', 'tmp_config_path') tmp_config_path = funct.get_config_var('haproxy', 'tmp_config_path')
script = "install_keepalived.sh" script = "install_keepalived.sh"
if hap == "1": if hap == "1":
@ -325,7 +315,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 = config.get('haproxy', 'tmp_config_path') tmp_config_path = funct.get_config_var('haproxy', 'tmp_config_path')
script = "add_vrrp.sh" script = "add_vrrp.sh"
os.system("cp scripts/%s ." % script) os.system("cp scripts/%s ." % script)

View File

@ -1,20 +1,14 @@
import funct import funct
from configparser import ConfigParser, ExtendedInterpolation
import os import os
import cgi import cgi
import sql import sql
path_config = "haproxy-webintarface.config" cgi_path = funct.get_config_var('main', 'cgi_path')
config = ConfigParser(interpolation=ExtendedInterpolation()) fullpath = funct.get_config_var('main', 'fullpath')
config.read(path_config) stats_port= funct.get_config_var('haproxy', 'stats_port')
haproxy_config_path = funct.get_config_var('haproxy', 'haproxy_config_path')
time_zone = config.get('main', 'time_zone') status_command = funct.get_config_var('haproxy', 'status_command')
cgi_path = config.get('main', 'cgi_path') hap_configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir')
fullpath = config.get('main', 'fullpath')
stats_port= config.get('haproxy', 'stats_port')
haproxy_config_path = config.get('haproxy', 'haproxy_config_path')
status_command = config.get('haproxy', 'status_command')
hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir')
form = cgi.FieldStorage() form = cgi.FieldStorage()
def get_overview(): def get_overview():
@ -160,7 +154,7 @@ def show_compare_configs(serv):
import glob import glob
left = form.getvalue('left') left = form.getvalue('left')
right = form.getvalue('right') right = form.getvalue('right')
haproxy_configs_server = config.get('configs', 'haproxy_configs_server') haproxy_configs_server = funct.get_config_var('configs', 'haproxy_configs_server')
print('<form action="diff.py#diff" method="get">') print('<form action="diff.py#diff" method="get">')
print('<center><h3><span style="padding: 20px;">Choose left</span><span style="padding: 110px;">Choose right</span></h3>') print('<center><h3><span style="padding: 20px;">Choose left</span><span style="padding: 110px;">Choose right</span></h3>')
@ -201,8 +195,7 @@ def show_compare_configs(serv):
def comapre_show(): def comapre_show():
left = form.getvalue('left') left = form.getvalue('left')
right = form.getvalue('right') right = form.getvalue('right')
haproxy_configs_server = config.get('configs', 'haproxy_configs_server') haproxy_configs_server = funct.get_config_var('configs', 'haproxy_configs_server')
hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir')
commands = [ 'diff -ub %s%s %s%s' % (hap_configs_dir, left, hap_configs_dir, right) ] commands = [ 'diff -ub %s%s %s%s' % (hap_configs_dir, left, hap_configs_dir, right) ]
funct.ssh_command(haproxy_configs_server, commands, compare="1") funct.ssh_command(haproxy_configs_server, commands, compare="1")

View File

@ -2,8 +2,8 @@
if [[ $1 != "" ]] if [[ $1 != "" ]]
then then
sudo export http_proxy="$1" export http_proxy="$1"
sudo export https_proxy="$1" export https_proxy="$1"
echo "Exporting proxy" echo "Exporting proxy"
fi fi

View File

@ -8,7 +8,9 @@ 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('viewsettings.html') template = env.get_template('viewsettings.html')
form = cgi.FieldStorage() form = cgi.FieldStorage()
path_config = "haproxy-webintarface.config" path_config = "haproxy-webintarface.config"
config = ConfigParser(interpolation=ExtendedInterpolation()) config = ConfigParser(interpolation=ExtendedInterpolation())
config.read(path_config) config.read(path_config)
@ -31,8 +33,6 @@ for section_name in config.sections():
for name, value in config.items(section_name): for name, value in config.items(section_name):
config_items_section_name[section_name][name] = value config_items_section_name[section_name][name] = value
output_from_parsed_template = template.render(h2 = 1, title = "Admin area: View settings", output_from_parsed_template = template.render(h2 = 1, title = "Admin area: View 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,

View File

@ -1,14 +1,10 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*-" # -*- coding: utf-8 -*-"
import cgi import cgi
from configparser import ConfigParser, ExtendedInterpolation
import create_db import create_db
import funct
path_config = "haproxy-webintarface.config" mysql_enable = funct.get_config_var('mysql', 'enable')
config = ConfigParser(interpolation=ExtendedInterpolation())
config.read(path_config)
mysql_enable = config.get('mysql', 'enable')
if mysql_enable == '1': if mysql_enable == '1':
from mysql.connector import errorcode from mysql.connector import errorcode

View File

@ -98,7 +98,11 @@
{% endif %} {% endif %}
</ul> </ul>
</nav> </nav>
<div class="copyright-menu">HAproxy-WI v2.5.4.3</div> <div class="copyright-menu">
HAproxy-WI v2.5.4.4
<br>
<a href="https://www.patreon.com/haproxy_wi" title="Donate" style="color: #fff; margin-left: 40px;">Patreon</a>
</div>
</div> </div>
</div> </div>
<div class="container"> <div class="container">

View File

@ -31,17 +31,16 @@
await sleep(2000); await sleep(2000);
$("form").submit(function() { $("form").submit(function() {
$.ajax({ $.ajax({
type: "get", type: "get",
url: "options.py", url: "options.py",
dataType: "text", dataType: "text",
data: $(this).serialize(), data: $(this).serialize(),
success: function( data ) { success: function( data ) {
//$("#ajax").html(data); showStats();
showStats(); }
}
}); });
return false; return false;
}); });
} }
</script> </script>

View File

@ -1,13 +1,9 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*-" # -*- coding: utf-8 -*-"
import create_db import create_db
from configparser import ConfigParser, ExtendedInterpolation import funct
path_config = "haproxy-webintarface.config" mysql_enable = funct.get_config_var('mysql', 'enable')
config = ConfigParser(interpolation=ExtendedInterpolation())
config.read(path_config)
mysql_enable = config.get('mysql', 'enable')
if mysql_enable == '1': if mysql_enable == '1':
from mysql.connector import errorcode from mysql.connector import errorcode

View File

@ -6,27 +6,19 @@ import funct
import sql import sql
import glob import glob
import datetime import datetime
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('viewlogs.html') template = env.get_template('viewlogs.html')
form = cgi.FieldStorage() form = cgi.FieldStorage()
path_config = "haproxy-webintarface.config"
config = ConfigParser(interpolation=ExtendedInterpolation())
config.read(path_config)
print('Content-type: text/html\n') print('Content-type: text/html\n')
try:
if config.get('main', 'log_path'):
log_path = config.get('main', 'log_path')
time_storage = config.getint('logs', 'log_time_storage')
except:
print('<center><div class="alert alert-danger">Can not find "log_path" and "log_time_storage" parametrs. Check into config</div>')
funct.check_login() funct.check_login()
funct.page_for_admin() 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 = int(time_storage)
try: try:
time_storage_hours = time_storage * 24 time_storage_hours = time_storage * 24
for dirpath, dirnames, filenames in os.walk(log_path): for dirpath, dirnames, filenames in os.walk(log_path):
@ -36,7 +28,7 @@ try:
if datetime.datetime.now() - file_modified > datetime.timedelta(hours=time_storage_hours): if datetime.datetime.now() - file_modified > datetime.timedelta(hours=time_storage_hours):
os.remove(curpath) os.remove(curpath)
except: except:
print('<center><div class="alert alert-danger" style="margin: 0; margin-bottom: 10px;">Can\'t delete old logs file. <br> Please check "log_time_storage" in config and <br>exist directory </div>') print('<center><div class="alert alert-danger" style="margin: 0; margin-bottom: 10px;">Can\'t delete old logs file. <br> Please check "log_time_storage" in config and <br>exist directory </div></center>')
pass pass
try: try:

View File

@ -321,7 +321,7 @@ pre {
.menu { .menu {
font-weight: bold; font-weight: bold;
font-style: italic; font-style: italic;
min-height: calc(100vh - 70px); min-height: calc(100vh - 95px);
} }
.menu ul li{ .menu ul li{
padding: 3px; padding: 3px;