diff --git a/README.md b/README.md index 1eb6263..312ccf2 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,14 @@ A simple web interface(user-frendly web GUI) for managing Haproxy servers. Leave 14. Telegram notification # Install - +The installer will ask you a few questions +``` +$ git clone https://github.com/Aidaho12/haproxy-wi.git /var/www/haproxy-wi +$ chmod +x install +$ cd /var/www/haproxy-wi +$ ./install +``` +## Manual install For install just [dowload](https://github.com/Aidaho12/haproxy-wi/archive/master.zip) archive and untar somewhere: ``` $ cd /var/www/ diff --git a/cgi-bin/add.py b/cgi-bin/add.py index d1f2914..0d33c6e 100644 --- a/cgi-bin/add.py +++ b/cgi-bin/add.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import html import cgi +import cgitb; cgitb.enable() import os import funct import sql @@ -16,9 +17,12 @@ config.read(path_config) funct.page_for_admin(level = 2) hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir') -form = cgi.FieldStorage() +cert_path = config.get('haproxy', 'cert_path') + listhap = sql.get_dick_permit() +form = cgi.FieldStorage() + if form.getvalue('mode') is not None: serv = form.getvalue('serv') port = form.getvalue('port') @@ -46,7 +50,7 @@ if form.getvalue('mode') is not None: backend = "" if form.getvalue('ssl') == "https" and form.getvalue('mode') != "tcp": - ssl = "ssl crt " + form.getvalue('cert') + ssl = "ssl crt " + cert_path + form.getvalue('cert') if form.getvalue('ssl-check') == "ssl-check": ssl_check = " ssl verify none" else: @@ -152,7 +156,7 @@ print('' 'IP and Port:' '' ':' - '' + '' '
IP for bind listner, if empty will be assignet on all IPs. Start typing ip, or press down.
' '' '' @@ -168,8 +172,8 @@ print('' '' '' '' '' @@ -288,8 +292,8 @@ print('' '' '' '' '' '' @@ -336,7 +340,7 @@ print('' '' 'Select server: ' '' - '' '') for i in listhap: @@ -364,8 +368,8 @@ print('' '' '' '' '' diff --git a/cgi-bin/configshow.py b/cgi-bin/configshow.py index 7c49a50..2cb5309 100644 --- a/cgi-bin/configshow.py +++ b/cgi-bin/configshow.py @@ -11,7 +11,7 @@ from pytz import timezone form = cgi.FieldStorage() serv = form.getvalue('serv') -funct.head("Show HAproxy config") +funct.head("Get Running Config") funct.check_config() funct.check_login() diff --git a/cgi-bin/create_db.py b/cgi-bin/create_db.py index 53f5a67..d7c7fbd 100644 --- a/cgi-bin/create_db.py +++ b/cgi-bin/create_db.py @@ -148,13 +148,13 @@ def update_db_v_2_0_1(): cur.execute(sql) except sqltool.Error as e: if e.args[0] == 'duplicate column name: type_ip': - print('Updating... go to version 2.0.1.1') + print('Updating... go to version 2.0.1.1
') return False else: print("An error occurred:", e) return False else: - print("DB was update to 2.0.1") + print("DB was update to 2.0.1
") return True cur.close() con.close() @@ -168,13 +168,13 @@ def update_db_v_2_0_1_1(): cur.execute(sql) except sqltool.Error as e: if e.args[0] == 'duplicate column name: enable' or e == "1060 (42S21): Duplicate column name 'enable' ": - print('Updating... go to version 2.0.5') + print('Updating... go to version 2.0.5
') return False else: print("An error occurred:", e) return False else: - print("DB was update to 2.0.1.1") + print("DB was update to 2.0.1.1
") return True cur.close() con.close() @@ -194,7 +194,7 @@ def update_db_v_2_0_5(): print("An error occurred:", e) return False else: - print("DB was update to 2.0.5") + print("DB was update to 2.0.5
") return True cur.close() con.close() diff --git a/cgi-bin/funct.py b/cgi-bin/funct.py index 0d61dbe..02ac267 100644 --- a/cgi-bin/funct.py +++ b/cgi-bin/funct.py @@ -45,9 +45,13 @@ def logging(serv, action): cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE")) login = cookie.get('login') mess = now_utc.strftime(dateFormat) + " from " + IP + " user: " + login.value + " " + action + " for: " + serv + "\n" - log = open(log_path + "/config_edit-"+get_data('logs')+".log", "a") - log.write(mess) - log.close + try: + log = open(log_path + "/config_edit-"+get_data('logs')+".log", "a") + log.write(mess) + log.close + except IOError: + print('
Can\'t read write log. Please chech log_path in config
') + pass if config.get('telegram', 'enable') == "1": telegram_send_mess(mess) @@ -125,7 +129,7 @@ def head(title): '' '' '' - '' + '' '' '' '' @@ -194,7 +198,7 @@ def links(): '') print('' '' - '' + '' '') def show_login_links(): diff --git a/cgi-bin/haproxy-webintarface.config b/cgi-bin/haproxy-webintarface.config index cb95e9f..1b4fdef 100644 --- a/cgi-bin/haproxy-webintarface.config +++ b/cgi-bin/haproxy-webintarface.config @@ -58,3 +58,4 @@ server_state_file = ${haproxy_dir}/haproxy.state haproxy_sock = /var/run/haproxy.sock #Temp store configs, for haproxy check tmp_config_path = /tmp +cert_path = /etc/ssl/certs/ diff --git a/cgi-bin/login.py b/cgi-bin/login.py index 570b2f2..939887c 100644 --- a/cgi-bin/login.py +++ b/cgi-bin/login.py @@ -22,7 +22,7 @@ def login_page(error): if create_db.check_db(): if create_db.create_table(): - print('
DB was created') + print('
DB was created
') create_db.update_all() print('
Now you can login, default: admin/admin
') diff --git a/cgi-bin/options.py b/cgi-bin/options.py index 6c07b26..f34f90e 100644 --- a/cgi-bin/options.py +++ b/cgi-bin/options.py @@ -7,8 +7,6 @@ import funct import ovw from configparser import ConfigParser, ExtendedInterpolation -options = [ "acl", "http-request", "http-response", "set-uri", "set-url", "set-header", "add-header", "del-header", "replace-header", "path_beg", "url_beg()", "urlp_sub()", "tcpka", "tcplog", "forwardfor", "option" ] - path_config = "haproxy-webintarface.config" config = ConfigParser(interpolation=ExtendedInterpolation()) config.read(path_config) @@ -18,18 +16,15 @@ form = cgi.FieldStorage() req = form.getvalue('req') serv = form.getvalue('serv') act = form.getvalue('act') +backend = form.getvalue('backend') print('Content-type: text/html\n') - -if req is not None: - if req is 1: - for i in options: - if req in i: - print(i) - else: - for i in options: - print(i) - -backend = form.getvalue('backend') + +if form.getvalue('getcert') is not None and serv is not None: + commands = [ "ls -1t /etc/ssl/certs/ |grep pem" ] + funct.ssh_command(serv, commands, ip="1") + + + if backend is not None: cmd='echo "show backend" |nc %s 1999' % serv diff --git a/cgi-bin/settings.py b/cgi-bin/settings.py index 2c71e94..fe6058d 100644 --- a/cgi-bin/settings.py +++ b/cgi-bin/settings.py @@ -23,7 +23,6 @@ print('

Admin area: View settings

' for section_name in config.sections(): print('Section:', section_name) - #print(' Options:', config.options(section_name)) for name, value in config.items(section_name): print(' {} = {}'.format(name, value)) print() diff --git a/cgi-bin/users.py b/cgi-bin/users.py index 3c1cf7f..2f0b260 100644 --- a/cgi-bin/users.py +++ b/cgi-bin/users.py @@ -121,7 +121,7 @@ print('

Virt(?)' '' '' '' diff --git a/inc/script.js b/inc/script.js index 2fc0a4d..0b475f8 100644 --- a/inc/script.js +++ b/inc/script.js @@ -529,12 +529,16 @@ $( function() { serv: $("#serv").val() }, success: function( data ) { - response(data.split("\n")); + data = data.replace(/\s+/g,' '); + response(data.split(" ")); } } ); }, autoFocus: true, - minLength: -1 + minLength: -1, + select: function( event, ui ) { + $('#listen-port').focus(); + } }); $( "#ip1" ).autocomplete({ source: function( request, response ) { @@ -545,10 +549,11 @@ $( function() { url: "options.py", data: { ip: request.term, - serv: $("#serv").val() + serv: $("#serv2").val() }, success: function( data ) { - response(data.split("\n")); + data = data.replace(/\s+/g,' '); + response(data.split(" ")); } } ); }, @@ -599,4 +604,55 @@ $( function() { $("#optionsInput2").append(ui.item.value + " ") } }); + $( "#path-cert-listen" ).autocomplete({ + source: function( request, response ) { + $.ajax( { + url: "options.py", + data: { + getcert:1, + serv: $("#serv").val() + }, + success: function( data ) { + data = data.replace(/\s+/g,' '); + response(data.split(" ")); + } + } ); + }, + autoFocus: true, + minLength: -1 + }); + $( "#path-cert-frontend" ).autocomplete({ + source: function( request, response ) { + $.ajax( { + url: "options.py", + data: { + getcert:1, + serv: $("#serv2").val() + }, + success: function( data ) { + data = data.replace(/\s+/g,' '); + response(data.split(" ")); + } + } ); + }, + autoFocus: true, + minLength: -1 + }); + $( "#path-cert-backend" ).autocomplete({ + source: function( request, response ) { + $.ajax( { + url: "options.py", + data: { + getcert:1, + serv: $("#serv3").val() + }, + success: function( data ) { + data = data.replace(/\s+/g,' '); + response(data.split(" ")); + } + } ); + }, + autoFocus: true, + minLength: -1 + }); }); \ No newline at end of file diff --git a/inc/style.css b/inc/style.css index 40acd0a..970265b 100644 --- a/inc/style.css +++ b/inc/style.css @@ -528,6 +528,7 @@ a:focus { cursor: pointer; font-weight: bold; padding-left: 10px; + margin-bottom: 10px; } .alert-danger { color: #a94442; diff --git a/requirements.txt b/requirements.txt index d2b6394..5e842c0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,4 +10,4 @@ numpy==1.14.0 matplotlib==2.1.2 urllib3==1.22 future==0.13.1 -mysqlclient==1.3.12 \ No newline at end of file +mysql-connector-python==8.0.11 \ No newline at end of file
Slave for (?)