From aafd430cb2c4526797162d9d0a21921d32928a0f Mon Sep 17 00:00:00 2001 From: Aidaho12 Date: Sat, 28 Apr 2018 13:34:45 +0600 Subject: [PATCH] v2.2 Bugs fixed --- README.md | 26 +++++++++++++++++++++++--- cgi-bin/create_db.py | 14 +++++++------- cgi-bin/funct.py | 2 +- cgi-bin/ha.py | 2 +- cgi-bin/haproxy-webintarface.config | 1 + cgi-bin/keepalivedconfig.py | 4 ++-- cgi-bin/scripts/install_haproxy.sh | 7 ++++++- cgi-bin/scripts/install_keepalived.sh | 5 +++++ cgi-bin/update_db.py | 1 + 9 files changed, 47 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 557d6e9d..cf2f67be 100644 --- a/README.md +++ b/README.md @@ -76,16 +76,17 @@ MariaDB [(none)]> grant all on haproxywi.* to 'haproxy-wi'@'localhost' IDENTIFIE ``` Edit $HOME_HAPROXY-WI/cgi-bin/haproxy-webintarface.config with your env ``` +Copy ssh key on all HAproxy servers + Login http://haproxy-wi-server/users.py, and add: users, groups and servers. Default: admin/admin ![alt text](image/haproxy-wi-admin-area.jpeg "Admin area") -Copy ssh key on all HAproxy servers - -For Runtime API enable state file on HAproxt servers and need install socat on all haproxy servers: +For Runtime API enable state file on HAproxt servers and need install socat on all haproxy servers, and configre HAProxy: ``` global stats socket *:1999 level admin + stats socket /var/run/haproxy.sock mode 600 level admin server-state-file /etc/haproxy/haproxy/haproxy.state defaults load-server-state-from-file global @@ -97,6 +98,25 @@ For Runtime API enable state file on HAproxt servers and need install socat on a $ cd /var/www/haproxy-wi/cgi-bin $ ./update_db.py ``` +# Troubleshooting +If you have error: +``` +Forbidden +You don't have permission to access /cgi-bin/overview.py on this server. +``` + +Check owner(must be apache, or another user for apache) + +If at first login you have: +``` +Internal Server Error +``` + +Do this: +``` +$ cd /var/www/haproxy-wi +$ ./update_db.py +``` # Further development and support diff --git a/cgi-bin/create_db.py b/cgi-bin/create_db.py index d7c7fbda..379bf8a9 100644 --- a/cgi-bin/create_db.py +++ b/cgi-bin/create_db.py @@ -40,13 +40,13 @@ def check_db(): try: cur.execute(sql) except sqltool.Error as err: - #print('
') - #if err.errno == errorcode.ER_ACCESS_DENIED_ERROR: - # print("Something is wrong with your user name or password") - #elif err.errno == errorcode.ER_BAD_DB_ERROR: - # print("Database does not exist") - #else: - # print(err) + print('
') + if err.errno == errorcode.ER_ACCESS_DENIED_ERROR: + print("Something is wrong with your user name or password") + elif err.errno == errorcode.ER_BAD_DB_ERROR: + print("Database does not exist") + else: + print(err) print('
') return True else: diff --git a/cgi-bin/funct.py b/cgi-bin/funct.py index 05fb6ad5..283e9d9d 100644 --- a/cgi-bin/funct.py +++ b/cgi-bin/funct.py @@ -319,7 +319,7 @@ def ssh_connect(serv): def get_config(serv, cfg, **kwargs): if kwargs.get("keepalived"): os.chdir("/var/www/haproxy-wi/cgi-bin/kp_config/") - config_path = "/etc/keepalived/keepalived.conf" + config_path = config.get('configs', 'kp_save_configs_dir') else: os.chdir(hap_configs_dir) config_path = haproxy_config_path diff --git a/cgi-bin/ha.py b/cgi-bin/ha.py index 4812f8f4..e22a1614 100644 --- a/cgi-bin/ha.py +++ b/cgi-bin/ha.py @@ -45,7 +45,7 @@ print('' '' '' '' - '' + '' '' '' 'Create' diff --git a/cgi-bin/haproxy-webintarface.config b/cgi-bin/haproxy-webintarface.config index 553497ab..6b9eba41 100644 --- a/cgi-bin/haproxy-webintarface.config +++ b/cgi-bin/haproxy-webintarface.config @@ -11,6 +11,7 @@ time_zone = UTC haproxy_configs_server = localhost #Dir where configs will be save haproxy_save_configs_dir = ${main:fullpath}/cgi-bin/hap_config/ +kp_save_configs_dir = ${main:fullpath}/cgi-bin/kp_config/ [mysql] #Enable MySQL DB. If default will be used Sqlite DB. Default disable diff --git a/cgi-bin/keepalivedconfig.py b/cgi-bin/keepalivedconfig.py index a336d729..4eaf3b08 100644 --- a/cgi-bin/keepalivedconfig.py +++ b/cgi-bin/keepalivedconfig.py @@ -23,7 +23,7 @@ config = ConfigParser(interpolation=ExtendedInterpolation()) config.read(path_config) log_path = config.get('main', 'log_path') -hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir') +kp_save_configs_dir = config.get('configs', 'kp_save_configs_dir') print('

Edit Running Keepalived config

' '
' @@ -49,7 +49,7 @@ funct.get_button("Open", value="open") print('') if serv is not None: - cfg = '/var/www/haproxy-wi/cgi-bin/kp_config/'+ serv + '-' + funct.get_data('config') + '.conf' + cfg = kp_save_configs_dir+ serv + '-' + funct.get_data('config') + '.conf' if form.getvalue('serv') is not None and form.getvalue('open') is not None : diff --git a/cgi-bin/scripts/install_haproxy.sh b/cgi-bin/scripts/install_haproxy.sh index c13fa072..39a8b9ff 100644 --- a/cgi-bin/scripts/install_haproxy.sh +++ b/cgi-bin/scripts/install_haproxy.sh @@ -1,6 +1,10 @@ #!/bin/bash -yum install haproxy -y > /dev/null +yum install haproxy socat -y > /dev/null +if [ -f /etc/haproxy/haproxy.cfg ];then + echo -e "error: Haproxy alredy installed" + exit 1 +fi echo "" > /etc/haproxy/haproxy.cfg cat << EOF > /etc/haproxy/haproxy.cfg global @@ -13,6 +17,7 @@ global daemon stats socket /var/lib/haproxy/stats stats socket *:1999 level admin + stats socket /var/run/haproxy.sock mode 600 level admin defaults mode http diff --git a/cgi-bin/scripts/install_keepalived.sh b/cgi-bin/scripts/install_keepalived.sh index 10b6cedf..667325de 100644 --- a/cgi-bin/scripts/install_keepalived.sh +++ b/cgi-bin/scripts/install_keepalived.sh @@ -1,6 +1,11 @@ #!/bin/bash CONF=/etc/keepalived/keepalived.conf +if [ -f $CONF ];then + echo -e "error: Keepalived alredy installed" + exit 1 +fi + yum install keepalived -y > /dev/null if [ $? -eq 1 ] then diff --git a/cgi-bin/update_db.py b/cgi-bin/update_db.py index 27fa4955..a15815a4 100644 --- a/cgi-bin/update_db.py +++ b/cgi-bin/update_db.py @@ -16,4 +16,5 @@ else: db = "haproxy-wi.db" import sqlite3 as sqltool +create_db.create_table() create_db.update_all() \ No newline at end of file