mirror of https://github.com/Aidaho12/haproxy-wi
parent
8734ac10aa
commit
d84a6f531b
|
@ -123,6 +123,9 @@ Do this:
|
||||||
$ cd /var/www/haproxy-wi/app
|
$ cd /var/www/haproxy-wi/app
|
||||||
$ ./update_db.py
|
$ ./update_db.py
|
||||||
```
|
```
|
||||||
|
and check executeble py files
|
||||||
|
|
||||||
|
If you see plain text, check section "Directory" in httpd conf
|
||||||
|
|
||||||
# Further development and support
|
# Further development and support
|
||||||
|
|
||||||
|
|
14
app/add.py
14
app/add.py
|
@ -2,9 +2,9 @@
|
||||||
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
|
||||||
from configparser import ConfigParser, ExtendedInterpolation
|
|
||||||
|
|
||||||
funct.head("Add")
|
funct.head("Add")
|
||||||
funct.check_config()
|
funct.check_config()
|
||||||
|
@ -18,7 +18,7 @@ funct.page_for_admin(level = 2)
|
||||||
hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir')
|
hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir')
|
||||||
cert_path = config.get('haproxy', 'cert_path')
|
cert_path = config.get('haproxy', 'cert_path')
|
||||||
listhap = sql.get_dick_permit()
|
listhap = sql.get_dick_permit()
|
||||||
form = cgi.FieldStorage()
|
form = cgi.FieldStorage()
|
||||||
|
|
||||||
if form.getvalue('mode') is not None:
|
if form.getvalue('mode') is not None:
|
||||||
serv = form.getvalue('serv')
|
serv = form.getvalue('serv')
|
||||||
|
@ -95,9 +95,6 @@ if form.getvalue('mode') is not None:
|
||||||
servers_split = ""
|
servers_split = ""
|
||||||
|
|
||||||
config_add = name + "\n" + bind + mode + "\n" + balance + options_split + backend + servers_split + "\n"
|
config_add = name + "\n" + bind + mode + "\n" + balance + options_split + backend + servers_split + "\n"
|
||||||
|
|
||||||
os.chdir(config.get('configs', 'haproxy_save_configs_dir'))
|
|
||||||
|
|
||||||
cfg = hap_configs_dir + serv + "-" + funct.get_data('config') + ".cfg"
|
cfg = hap_configs_dir + serv + "-" + funct.get_data('config') + ".cfg"
|
||||||
|
|
||||||
funct.get_config(serv, cfg)
|
funct.get_config(serv, cfg)
|
||||||
|
@ -114,16 +111,17 @@ if form.getvalue('mode') is not None:
|
||||||
for master in MASTERS:
|
for master in MASTERS:
|
||||||
if master[0] != None:
|
if master[0] != None:
|
||||||
funct.upload_and_restart(master[0], cfg)
|
funct.upload_and_restart(master[0], cfg)
|
||||||
|
|
||||||
if funct.upload_and_restart(serv, cfg):
|
if funct.upload_and_restart(serv, cfg):
|
||||||
print('<meta http-equiv="refresh" content="30; url=add.py?add=%s&conf=%s">' % (name, config_add))
|
print('<meta http-equiv="refresh" content="5; url=add.py?add=%s&conf=%s">' % (name, config_add))
|
||||||
|
|
||||||
print('</div>')
|
print('</div>')
|
||||||
|
|
||||||
if form.getvalue('add') is not None:
|
if form.getvalue('add') is not None:
|
||||||
print('<h3 class="addSuc"> ' + form.getvalue('add') + ' was successfully added</h3>')
|
print('<div class="added"><h3 class="addSuc"> ' + form.getvalue('add') + ' was successfully added</h3>')
|
||||||
print('<div class="line3">')
|
print('<div class="line3">')
|
||||||
print(form.getvalue('conf'))
|
print(form.getvalue('conf'))
|
||||||
print('</div>')
|
print('</div></div>')
|
||||||
|
|
||||||
print('<div id="tabs">'
|
print('<div id="tabs">'
|
||||||
'<ul>'
|
'<ul>'
|
||||||
|
|
|
@ -10,6 +10,7 @@ config = ConfigParser(interpolation=ExtendedInterpolation())
|
||||||
config.read(path_config)
|
config.read(path_config)
|
||||||
|
|
||||||
mysql_enable = config.get('mysql', 'enable')
|
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 = config.get('mysql', 'mysql_user')
|
||||||
|
@ -19,7 +20,7 @@ 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:
|
||||||
db = "haproxy-wi.db"
|
db = fullpath+"/app/haproxy-wi.db"
|
||||||
import sqlite3 as sqltool
|
import sqlite3 as sqltool
|
||||||
|
|
||||||
def check_db():
|
def check_db():
|
||||||
|
@ -54,14 +55,18 @@ def check_db():
|
||||||
con.close()
|
con.close()
|
||||||
|
|
||||||
def get_cur():
|
def get_cur():
|
||||||
if mysql_enable == '0':
|
try:
|
||||||
con = sqltool.connect(db, isolation_level=None)
|
if mysql_enable == '0':
|
||||||
|
con = sqltool.connect(db, isolation_level=None)
|
||||||
|
else:
|
||||||
|
con = sqltool.connect(user=mysql_user, password=mysql_password,
|
||||||
|
host=mysql_host,
|
||||||
|
database=mysql_db)
|
||||||
|
cur = con.cursor()
|
||||||
|
except sqltool.Error as e:
|
||||||
|
print("An error occurred:", e)
|
||||||
else:
|
else:
|
||||||
con = sqltool.connect(user=mysql_user, password=mysql_password,
|
return con, cur
|
||||||
host=mysql_host,
|
|
||||||
database=mysql_db)
|
|
||||||
cur = con.cursor()
|
|
||||||
return con, cur
|
|
||||||
|
|
||||||
def create_table():
|
def create_table():
|
||||||
con, cur = get_cur()
|
con, cur = get_cur()
|
||||||
|
|
10
app/funct.py
10
app/funct.py
|
@ -7,7 +7,6 @@ from paramiko import SSHClient
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pytz import timezone
|
from pytz import timezone
|
||||||
from configparser import ConfigParser, ExtendedInterpolation
|
from configparser import ConfigParser, ExtendedInterpolation
|
||||||
import sql
|
|
||||||
|
|
||||||
path_config = "haproxy-webintarface.config"
|
path_config = "haproxy-webintarface.config"
|
||||||
config = ConfigParser(interpolation=ExtendedInterpolation())
|
config = ConfigParser(interpolation=ExtendedInterpolation())
|
||||||
|
@ -299,7 +298,7 @@ def get_auto_refresh(h2):
|
||||||
'</div>'
|
'</div>'
|
||||||
'</div>')
|
'</div>')
|
||||||
|
|
||||||
def ssh_connect(serv):
|
def ssh_connect(serv, **kwargs):
|
||||||
ssh = SSHClient()
|
ssh = SSHClient()
|
||||||
ssh.load_system_host_keys()
|
ssh.load_system_host_keys()
|
||||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||||
|
@ -309,7 +308,10 @@ def ssh_connect(serv):
|
||||||
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 = config.get('ssh', 'ssh_pass'))
|
ssh.connect(hostname = serv, username = ssh_user_name, password = config.get('ssh', 'ssh_pass'))
|
||||||
return ssh
|
if kwargs.get('check'):
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return ssh
|
||||||
except paramiko.AuthenticationException:
|
except paramiko.AuthenticationException:
|
||||||
print('<div class="alert alert-danger">Authentication failed, please verify your credentials</div>')
|
print('<div class="alert alert-danger">Authentication failed, please verify your credentials</div>')
|
||||||
return False
|
return False
|
||||||
|
@ -426,7 +428,6 @@ def upload_and_restart(serv, cfg, **kwargs):
|
||||||
sftp.put(cfg, tmp_file)
|
sftp.put(cfg, tmp_file)
|
||||||
sftp.close()
|
sftp.close()
|
||||||
if kwargs.get("keepalived") == 1:
|
if kwargs.get("keepalived") == 1:
|
||||||
print("123")
|
|
||||||
if kwargs.get("just_save") == "save":
|
if kwargs.get("just_save") == "save":
|
||||||
commands = [ "mv -f " + tmp_file + " /etc/keepalived/keepalived.conf" ]
|
commands = [ "mv -f " + tmp_file + " /etc/keepalived/keepalived.conf" ]
|
||||||
else:
|
else:
|
||||||
|
@ -577,6 +578,7 @@ def ssh_command(serv, commands, **kwargs):
|
||||||
ssh.close()
|
ssh.close()
|
||||||
|
|
||||||
def choose_only_select(serv, **kwargs):
|
def choose_only_select(serv, **kwargs):
|
||||||
|
import sql
|
||||||
if kwargs.get("virt"):
|
if kwargs.get("virt"):
|
||||||
listhap = sql.get_dick_permit(virt=1)
|
listhap = sql.get_dick_permit(virt=1)
|
||||||
else:
|
else:
|
||||||
|
|
18
app/sql.py
18
app/sql.py
|
@ -1,8 +1,8 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# -*- coding: utf-8 -*-"
|
# -*- coding: utf-8 -*-"
|
||||||
import cgi
|
import cgi
|
||||||
import create_db
|
|
||||||
from configparser import ConfigParser, ExtendedInterpolation
|
from configparser import ConfigParser, ExtendedInterpolation
|
||||||
|
import create_db
|
||||||
|
|
||||||
path_config = "haproxy-webintarface.config"
|
path_config = "haproxy-webintarface.config"
|
||||||
config = ConfigParser(interpolation=ExtendedInterpolation())
|
config = ConfigParser(interpolation=ExtendedInterpolation())
|
||||||
|
@ -14,7 +14,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:
|
||||||
db = "haproxy-wi.db"
|
|
||||||
import sqlite3 as sqltool
|
import sqlite3 as sqltool
|
||||||
|
|
||||||
def add_user(user, email, password, role, group):
|
def add_user(user, email, password, role, group):
|
||||||
|
@ -93,6 +92,7 @@ def delete_group(id):
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
cur.close()
|
cur.close()
|
||||||
|
con.close()
|
||||||
|
|
||||||
def update_group(name, descript, id):
|
def update_group(name, descript, id):
|
||||||
con, cur = create_db.get_cur()
|
con, cur = create_db.get_cur()
|
||||||
|
@ -321,15 +321,17 @@ def get_dick_permit(**kwargs):
|
||||||
|
|
||||||
def is_master(ip, **kwargs):
|
def is_master(ip, **kwargs):
|
||||||
con, cur = create_db.get_cur()
|
con, cur = create_db.get_cur()
|
||||||
sql = """ select slave.ip from servers left join servers as slave on servers.id = slave.master where servers.ip = '%s' """ % ip
|
sql = """ select slave.ip from servers as master left join servers as slave on master.id = slave.master where master.ip = '%s' """ % ip
|
||||||
if kwargs.get('master_slave'):
|
if kwargs.get('master_slave'):
|
||||||
sql = """ select master.hostname, master.ip, slave.hostname, slave.ip from servers as master left join servers as slave on master.id = slave.master where slave.master > 0 """
|
sql = """ select master.hostname, master.ip, slave.hostname, slave.ip from servers as master left join servers as slave on master.id = slave.master where slave.master > 0 """
|
||||||
try:
|
try:
|
||||||
cur.execute(sql)
|
cur.execute(sql)
|
||||||
except sqltool.Error as e:
|
except sqltool.Error as e:
|
||||||
return False
|
print("An error occurred:", e)
|
||||||
else:
|
else:
|
||||||
return cur.fetchall()
|
return cur.fetchall()
|
||||||
|
cur.close()
|
||||||
|
con.close()
|
||||||
|
|
||||||
def show_update_servers():
|
def show_update_servers():
|
||||||
SERVERS = select_servers()
|
SERVERS = select_servers()
|
||||||
|
@ -490,6 +492,7 @@ if form.getvalue('userdel') is not None:
|
||||||
print("Ok")
|
print("Ok")
|
||||||
|
|
||||||
if form.getvalue('newserver') is not None:
|
if form.getvalue('newserver') is not None:
|
||||||
|
import funct
|
||||||
hostname = form.getvalue('newserver')
|
hostname = form.getvalue('newserver')
|
||||||
ip = form.getvalue('newip')
|
ip = form.getvalue('newip')
|
||||||
group = form.getvalue('newservergroup')
|
group = form.getvalue('newservergroup')
|
||||||
|
@ -501,8 +504,11 @@ if form.getvalue('newserver') is not None:
|
||||||
print(error_mess)
|
print(error_mess)
|
||||||
else:
|
else:
|
||||||
print('Content-type: text/html\n')
|
print('Content-type: text/html\n')
|
||||||
if add_server(hostname, ip, group, typeip, enable, master):
|
if funct.ssh_connect(ip, check=1):
|
||||||
show_update_server(hostname)
|
if add_server(hostname, ip, group, typeip, enable, master):
|
||||||
|
show_update_server(hostname)
|
||||||
|
else:
|
||||||
|
print('<span class="alert alert-danger" id="error"><a title="Close" id="errorMess"><b>X</b></a></span>')
|
||||||
|
|
||||||
if form.getvalue('serverdel') is not None:
|
if form.getvalue('serverdel') is not None:
|
||||||
print('Content-type: text/html\n')
|
print('Content-type: text/html\n')
|
||||||
|
|
|
@ -530,7 +530,7 @@ a:focus {
|
||||||
padding-left: 10px;
|
padding-left: 10px;
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
}
|
}
|
||||||
.alert-danger, .alert-info, .alert-success, .alert-warning {
|
.alert-danger, .alert-info, .alert-success, .alert-warning, .added {
|
||||||
width: 400px;
|
width: 400px;
|
||||||
margin-left: 15px;
|
margin-left: 15px;
|
||||||
}
|
}
|
||||||
|
@ -543,11 +543,10 @@ a:focus {
|
||||||
margin-top: 15px;
|
margin-top: 15px;
|
||||||
margin-bottom: -50px;
|
margin-bottom: -50px;
|
||||||
}
|
}
|
||||||
.alert-success {
|
.alert-success, .added{
|
||||||
color: #3c763d;
|
color: #3c763d;
|
||||||
background-color: #dff0d8;
|
background-color: #dff0d8;
|
||||||
border-color: #d6e9c6;
|
border-color: #d6e9c6;
|
||||||
|
|
||||||
}
|
}
|
||||||
.alert-info {
|
.alert-info {
|
||||||
color: #0c5460;
|
color: #0c5460;
|
||||||
|
@ -559,6 +558,14 @@ a:focus {
|
||||||
background-color: #fff3cd;
|
background-color: #fff3cd;
|
||||||
border-color: #ffeeba;
|
border-color: #ffeeba;
|
||||||
}
|
}
|
||||||
|
.added {
|
||||||
|
position: absolute;
|
||||||
|
margin-left: 30px;
|
||||||
|
margin-top: 790px;
|
||||||
|
padding-bottom: 20px;
|
||||||
|
padding-right: 20px;
|
||||||
|
padding-left: 10px;
|
||||||
|
}
|
||||||
label {
|
label {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
|
|
Loading…
Reference in New Issue