diff --git a/README.md b/README.md index 8a33aee1..8a9654e6 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/cgi-bin/create_db.py b/cgi-bin/create_db.py index e70a9634..814bd008 100644 --- a/cgi-bin/create_db.py +++ b/cgi-bin/create_db.py @@ -1,4 +1,6 @@ #!/usr/bin/env python3 +import cgi +import html import sqlite3 as sqlite import os import sys @@ -11,11 +13,12 @@ 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) cur = con.cursor() @@ -65,7 +68,23 @@ def create_table(): `description` VARCHAR ( 255 ), PRIMARY KEY(`id`) ); - INSERT INTO `groups` (name, description) VALUES ('All','All servers enter in this group'); + + 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.') -update_db_v_2_0_1_1() \ No newline at end of file +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() \ No newline at end of file diff --git a/cgi-bin/login.py b/cgi-bin/login.py index 0c077026..7834b589 100644 --- a/cgi-bin/login.py +++ b/cgi-bin/login.py @@ -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 = "Somthing wrong :( I'm sad about this, but try again!

" + printError = "

Login page. Enter please



Somthing wrong :( I'm sad about this, but try again!

" else: printError = "

Login page. Enter please



" + + if create_db.check_db(): + if create_db.create_table(): + print('
DB was created') + create_db.update_all() + print('
Now you can login, default: admin/admin
') ref = form.getvalue('ref') if ref is None: ref = "/index.html" - - funct.head("Login page") - + print('
') print(printError) print('

') @@ -39,6 +45,7 @@ if form.getvalue('logout') is not None: print('') 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('Redirecting') print('') print('' % ref) - break + sys.exit() login_page("error") funct.footer() diff --git a/cgi-bin/viewlogs.py b/cgi-bin/viewlogs.py index e226e10a..924bf8d6 100644 --- a/cgi-bin/viewlogs.py +++ b/cgi-bin/viewlogs.py @@ -26,11 +26,10 @@ os.chdir(log_path) print('' '' '

Choose log file


' - '' + '') -i = 0 for files in sorted(glob.glob('*.log')): - i = i + 1 if files == viewlog: selected = 'selected' else: diff --git a/inc/style.css b/inc/style.css index ca472af4..40acd0a9 100644 --- a/inc/style.css +++ b/inc/style.css @@ -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%;