mirror of https://github.com/Aidaho12/haproxy-wi
parent
6ffbfae981
commit
f81f6d980f
|
@ -28,7 +28,6 @@ $ mv haproxy-wi-master/ haproxy-wi
|
|||
$ pip install -r haproxy-wi/requirements.txt
|
||||
$ cd haproxy-wi/cgi-bin
|
||||
$ chmod +x *.py
|
||||
$ ./create_db.py
|
||||
```
|
||||
|
||||
For Apache do virtualhost with cgi-bin.
|
||||
|
@ -54,14 +53,6 @@ For Runtime API enable state file on HAproxt servers and need install socat on a
|
|||
```
|
||||
![alt text](image/haproxy-wi-logs.jpeg "View logs page")
|
||||
|
||||
# Update DB
|
||||
|
||||
For update db:
|
||||
```
|
||||
$ cd /var/www/haproxy-wi/cgi-bin
|
||||
$ ./create_db.py
|
||||
```
|
||||
|
||||
# Further development and support
|
||||
|
||||
Offer your ideas and wishes, ask questions. All this is [welcomed](https://github.com/Aidaho12/haproxy-wi/issues)
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
#!/usr/bin/env python3
|
||||
import cgi
|
||||
import html
|
||||
import sqlite3 as sqlite
|
||||
import os
|
||||
import sys
|
||||
|
@ -11,10 +13,11 @@ def check_db():
|
|||
with open(db,'r', encoding = "ISO-8859-1") as f:
|
||||
header = f.read(100)
|
||||
if header.startswith('SQLite format 3'):
|
||||
print("SQLite3 database has been detected.")
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
else:
|
||||
return True
|
||||
|
||||
def get_cur():
|
||||
con = sqlite.connect(db, isolation_level=None)
|
||||
|
@ -65,7 +68,23 @@ def create_table():
|
|||
`description` VARCHAR ( 255 ),
|
||||
PRIMARY KEY(`id`)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `groups` (
|
||||
`id` INTEGER NOT NULL,
|
||||
`name` VARCHAR ( 80 ) UNIQUE,
|
||||
`description` VARCHAR ( 255 ),
|
||||
PRIMARY KEY(`id`)
|
||||
);
|
||||
INSERT INTO `groups` (name, description) VALUES ('All','All servers enter in this group');
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `servers` (
|
||||
`id` INTEGER NOT NULL,
|
||||
`hostname` VARCHAR ( 64 ) UNIQUE,
|
||||
`ip` VARCHAR ( 64 ) UNIQUE,
|
||||
`groups` VARCHAR ( 64 ),
|
||||
PRIMARY KEY(`id`)
|
||||
);
|
||||
|
||||
COMMIT;
|
||||
"""
|
||||
|
||||
|
@ -73,18 +92,19 @@ def create_table():
|
|||
cur.executescript(sql)
|
||||
except sqlite.Error as e:
|
||||
print("An error occurred:", e.args[0])
|
||||
return False
|
||||
else:
|
||||
print("DB was created")
|
||||
return True
|
||||
cur.close()
|
||||
con.close()
|
||||
|
||||
def update_db_v_2_0_1():
|
||||
con, cur = get_cur()
|
||||
sql = """
|
||||
ALTER TABLE `servers` ADD COLUMN type_ip INTEGER NOT NULL DEFAULT(0);
|
||||
ALTER TABLE servers ADD COLUMN type_ip INTEGER NOT NULL DEFAULT(0);
|
||||
"""
|
||||
try:
|
||||
cur.executescript(sql)
|
||||
cur.execute(sql)
|
||||
except sqlite.Error as e:
|
||||
if e.args[0] == 'duplicate column name: type_ip':
|
||||
print('Updating... go to version 2.0.1.1')
|
||||
|
@ -118,10 +138,15 @@ def update_db_v_2_0_1_1():
|
|||
cur.close()
|
||||
con.close()
|
||||
|
||||
if check_db():
|
||||
create_table()
|
||||
else:
|
||||
print('DB already exists, try update')
|
||||
if update_db_v_2_0_1():
|
||||
print('DB was property update to version 2.0.1.')
|
||||
def update_all():
|
||||
update_db_v_2_0_1()
|
||||
update_db_v_2_0_1_1()
|
||||
|
||||
#if check_db():
|
||||
# create_table()
|
||||
#else:
|
||||
# print('DB already exists, try update')
|
||||
#update_all()
|
||||
#if update_db_v_2_0_1():
|
||||
# print('DB was property update to version 2.0.1.')
|
||||
#update_db_v_2_0_1_1()
|
|
@ -2,9 +2,11 @@
|
|||
import cgi
|
||||
import html
|
||||
import os
|
||||
import sys
|
||||
import funct
|
||||
import http.cookies
|
||||
import sql
|
||||
import create_db
|
||||
|
||||
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
|
||||
form = cgi.FieldStorage()
|
||||
|
@ -14,16 +16,20 @@ password = form.getvalue('pass')
|
|||
|
||||
def login_page(error):
|
||||
if error == "error":
|
||||
printError = "<b style='color: red'>Somthing wrong :( I'm sad about this, but try again!</b><br /><br />"
|
||||
printError = "<h2>Login page. Enter please</h2><br /><br /><b style='color: red'>Somthing wrong :( I'm sad about this, but try again!</b><br /><br />"
|
||||
else:
|
||||
printError = "<h2>Login page. Enter please</h2><br /><br />"
|
||||
|
||||
if create_db.check_db():
|
||||
if create_db.create_table():
|
||||
print('<div class="alert alert-success">DB was created')
|
||||
create_db.update_all()
|
||||
print('<br />Now you can login, default: admin/admin</div>')
|
||||
|
||||
ref = form.getvalue('ref')
|
||||
if ref is None:
|
||||
ref = "/index.html"
|
||||
|
||||
funct.head("Login page")
|
||||
|
||||
print('<center><form name="auth" action="login.py" class="form-horizontal" method="get">')
|
||||
print(printError)
|
||||
print('<label for="login">Login: </label> <input type="text" name="login" required class="form-control"><br /><br />')
|
||||
|
@ -39,6 +45,7 @@ if form.getvalue('logout') is not None:
|
|||
print('<meta http-equiv="refresh" content="0; url=/">')
|
||||
|
||||
if login is None:
|
||||
funct.head("Login page")
|
||||
login_page("n")
|
||||
|
||||
if login is not None and password is not None:
|
||||
|
@ -68,7 +75,7 @@ if login is not None and password is not None:
|
|||
print('<html><head><title>Redirecting</title><meta charset="UTF-8">')
|
||||
print('<link href="/style.css" rel="stylesheet">')
|
||||
print('<meta http-equiv="refresh" content="0; url=%s">' % ref)
|
||||
break
|
||||
sys.exit()
|
||||
login_page("error")
|
||||
|
||||
funct.footer()
|
||||
|
|
|
@ -26,11 +26,10 @@ os.chdir(log_path)
|
|||
print('<script src="/inc/users.js"></script>'
|
||||
'<a name="top"></a>'
|
||||
'<center><h3>Choose log file</h3><br />'
|
||||
'<select id="viewlogs">')
|
||||
'<select id="viewlogs">'
|
||||
'<option disabled selected>Choose log</option>')
|
||||
|
||||
i = 0
|
||||
for files in sorted(glob.glob('*.log')):
|
||||
i = i + 1
|
||||
if files == viewlog:
|
||||
selected = 'selected'
|
||||
else:
|
||||
|
|
|
@ -538,6 +538,11 @@ a:focus {
|
|||
margin-top: 15px;
|
||||
margin-bottom: -50px;
|
||||
}
|
||||
.alert-success {
|
||||
color: #3c763d;
|
||||
background-color: #dff0d8;
|
||||
border-color: #d6e9c6;
|
||||
}
|
||||
label {
|
||||
display: inline-block;
|
||||
max-width: 100%;
|
||||
|
|
Loading…
Reference in New Issue