diff --git a/.gitignore b/.gitignore index abedf5ce..7bbc71c0 100644 --- a/.gitignore +++ b/.gitignore @@ -99,4 +99,3 @@ ENV/ # mypy .mypy_cache/ -cgi-bin/hap_config/172.28.5.5-2018-01-10.13\:56\:02.cfg diff --git a/README.md b/README.md index 82a9dc48..37798490 100644 --- a/README.md +++ b/README.md @@ -17,10 +17,16 @@ A simple web interface(user-frendly web GUI) for managing Haproxy servers # Install For install just dowload archive and untar somewhere: ``` -$ cd /opt/haproxy-webintarface -$ tar xf haproxy-webintarface-master.zip -$ pip3 -r requirements.txt +$ cd /opt +$ unzip master.zip +$ mv haproxy-web-interface-master/ haproxy +$ pip3 install -r requirements.txt +$ chmod +x server.py +$ chmod +x -R cgi-bin/ +$ chown user:user -R haproxy ``` +Edit listserv.py, add your HAproxy servers. + If foler not /opt/haproxy/, edit server.py: ``` path_config = "/opt/haproxy/haproxy-webintarface.config" @@ -48,7 +54,7 @@ After=syslog.target network.target [Service] Type=simple -User=user +User=user_name ExecStart=/opt/haproxy/server.py >> /opt/haproxy/log/haproxy-webface.log diff --git a/cgi-bin/diff.py b/cgi-bin/diff.py index f6741d83..386ef1fe 100644 --- a/cgi-bin/diff.py +++ b/cgi-bin/diff.py @@ -35,12 +35,12 @@ if form.getvalue('serv') is not None and form.getvalue('open') is not None : print('
') print('

Choose leftChoose right

') - print('

') print('') os.chdir(hap_configs_dir) - for files in sorted(glob.glob('*.cfg')): + for files in glob.glob('*.cfg'): ip = files.split("-") if serv == ip[0]: if left == files: @@ -51,10 +51,10 @@ if form.getvalue('serv') is not None and form.getvalue('open') is not None : print('') - print('') print('') - for files in sorted(glob.glob('*.cfg')): + for files in glob.glob('*.cfg'): ip = files.split("-") if serv == ip[0]: if right == files: @@ -66,11 +66,13 @@ if form.getvalue('serv') is not None and form.getvalue('open') is not None : print('') print('' % serv) print('') - print('

') + print('

') if form.getvalue('serv') is not None and form.getvalue('right') is not None: commands = [ 'diff -ub %s%s %s%s' % (hap_configs_dir, left, hap_configs_dir, right) ] funct.ssh_command(haproxy_configs_server, commands, compare="compare") + print('

UP') + funct.footer() \ No newline at end of file diff --git a/cgi-bin/edit.py b/cgi-bin/edit.py index 1837cf52..7b7f5a22 100644 --- a/cgi-bin/edit.py +++ b/cgi-bin/edit.py @@ -18,7 +18,7 @@ funct.check_login("edit.py") print('

Edit & show HAproxy settings

') print('

Choose server & action: Disable/Enable server or output any information about the server:

') print('
') -print('

') print('') funct.choose_server_with_vip(serv) @@ -44,7 +44,7 @@ else: selected3 = '' print('') -print('') print('') print('' % selected1) print('' % selected2) diff --git a/cgi-bin/funct.py b/cgi-bin/funct.py index d7627ccc..ec86fa1b 100644 --- a/cgi-bin/funct.py +++ b/cgi-bin/funct.py @@ -12,7 +12,8 @@ def check_config(): path_config = "haproxy-webintarface.config" config = configparser.ConfigParser() config.read(path_config) - + + for section in [ 'main', 'configs', 'ssh', 'logs', 'haproxy' ]: if not config.has_section(section): print('Check config file, no %s section' % section) @@ -70,7 +71,6 @@ def mode_admin(button): def links(): print('Home Page ') print('Stats ') - print('Monitoring ') print('Logs') print('Edit settings ') print(' | Configs: ') @@ -82,8 +82,9 @@ def links(): show_login_links() def head(title): - print('Content-type: text/html\n') + print("Content-type: text/html\n") print('%s' % title) +<<<<<<< HEAD print('' '' '' @@ -97,18 +98,18 @@ def head(title): if config.get('main', 'logo_enable') == "1": print('' % config.get('main', 'logo_path')) print('

' - '') continue if "#" in line: - print('
') + print('
') print(i) - print(line + '
') + print(line + '
') continue print('
') print(i) @@ -202,6 +203,7 @@ def upload_and_restart(serv, cfg): return True ssh.close() +<<<<<<< HEAD def compare(stdout): i = 0 @@ -250,6 +252,10 @@ def show_ip(stdout): print(line) def ssh_command(serv, commands, **kwargs): +======= + +def ssh_command(serv, commands): +>>>>>>> parent of fe00260... v1.3 ssh = SSHClient() ssh.load_system_host_keys() k = paramiko.RSAKey.from_private_key_file(ssh_keys) @@ -271,6 +277,7 @@ def ssh_command(serv, commands, **kwargs): for command in commands: stdin , stdout, stderr = ssh.exec_command(command) +<<<<<<< HEAD if ip is 1: show_ip(stdout) @@ -280,13 +287,24 @@ def ssh_command(serv, commands, **kwargs): show_log(stdout) print(stderr.read().decode(encoding='UTF-8')) +======= + print('
') + i = 1 + for line in stdout: + i = i + 1 + if i % 2 == 0: + print('
' + line + '
') + else: + print('
' + line + '
') + print('
') +>>>>>>> parent of fe00260... v1.3 ssh.close() def chooseServer(formName, title, note): print('

' + title + '

') print('

Choose server

') print('') - print('

') print('') form = cgi.FieldStorage() @@ -304,7 +322,7 @@ def chooseServer(formName, title, note): print('') print('

') if note == "y": - print('

Note: If you reconfigure First server, second will reconfigured automatically

') + print('

Note: If you reconfigure First server, second will reconfigured automatically


') def choose_server_with_vip(serv): import listserv as listhap diff --git a/cgi-bin/login.py b/cgi-bin/login.py index 6dfacbc0..35c74724 100644 --- a/cgi-bin/login.py +++ b/cgi-bin/login.py @@ -32,14 +32,19 @@ def login_page(error): ref = "/index.html" funct.head("Login page") +<<<<<<< HEAD print('
') +======= + + print('
') +>>>>>>> parent of fe00260... v1.3 print(printError) print(' ') print(' ') print('' % ref) - print('') - print('
') + print('') + print('
') if form.getvalue('logout') is not None: print("Set-cookie: login=; expires=Wed May 18 03:33:20 2003; path=/cgi-bin/; httponly") diff --git a/cgi-bin/logs.py b/cgi-bin/logs.py index 2a4711cb..27a5f20c 100644 --- a/cgi-bin/logs.py +++ b/cgi-bin/logs.py @@ -21,7 +21,7 @@ config.read(path_config) print('

HAproxy Logs

') print('

Choose server & number rows

') print('
') -print('

') print('') for i in sorted(listhap.listhap): diff --git a/cgi-bin/viewsttats.py b/cgi-bin/viewsttats.py index 4f5b7ad9..193b0fb7 100644 --- a/cgi-bin/viewsttats.py +++ b/cgi-bin/viewsttats.py @@ -25,7 +25,7 @@ serv = form.getvalue('serv') if serv is None: first_serv = list(listhap.list_hap_vip.values()) serv = first_serv[0] - + try: response = requests.get('http://%s:%s/stats' % (serv, stats_port), auth=(haproxy_user, haproxy_pass)) except requests.exceptions.ConnectTimeout: @@ -34,7 +34,6 @@ except requests.exceptions.ReadTimeout: print('Oops. Read timeout occured') print("Content-type: text/html\n") -print('' % (config.get('haproxy', 'refresh_time') ,serv)) for i in listhap.listhap: if listhap.listhap.get(i) == serv: diff --git a/haproxy-webintarface.config b/haproxy-webintarface.config index 9c049ea4..eb23ed11 100644 --- a/haproxy-webintarface.config +++ b/haproxy-webintarface.config @@ -3,15 +3,19 @@ fullpath = /opt/haproxy/ server_bind_ip = 0.0.0.0 server_port = 8000 +#Log for server.py log_path = %(fullpath)s/log/ time_zone = UTC +<<<<<<< HEAD #Enable logo on top menu. Default disable logo_enable = 0 logo_path = /logo.png +======= +>>>>>>> parent of fe00260... v1.3 [configs] #Server for save configs from HAproxy servers -haproxy_configs_server = kz-web14 +haproxy_configs_server = #Dir where configs will be save haproxy_save_configs_dir = /opt/haproxy/cgi-bin/hap_config/ @@ -22,9 +26,9 @@ ssh_keys = /opt/haproxy/cgi-bin/id_rsa.pem ssh_user_name = root [logs] -#Logs save locally, disable by default +#Logs save localy, disable by default local_path_logs = /var/log/haproxy.log -#If exist syslog server for HAproxy logs +# syslog_server_enable = enable syslog_server = 172.28.5.112 @@ -36,7 +40,10 @@ user = admin password = password stats_port = 8085 haproxy_config_path = /etc/haproxy/haproxy.cfg +<<<<<<< HEAD #Temp store configs, for haproxy check tmp_config_path = /tmp #Time in seconds for auto refresh view stats_port -refresh_time = 120 \ No newline at end of file +refresh_time = 120 +======= +>>>>>>> parent of fe00260... v1.3 diff --git a/index.html b/index.html index e9e0f85d..ad06937b 100644 --- a/index.html +++ b/index.html @@ -8,6 +8,7 @@ +<<<<<<< HEAD

Welcome! HAproxy Web Intarface

@@ -25,5 +26,19 @@
+======= +
+

Welcome! HAproxy Web intarface

+

Choose your destiny!

+ View stats
+ Edit settings
+ Logs
+ Compare
+ Show
+ Edit config
+ Upload old config
+ +
+>>>>>>> parent of fe00260... v1.3 diff --git a/requirements.txt b/requirements.txt index f9463b7a..29c5a822 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1,7 @@ -html -cgi -os -http.cookies -configparser -paramiko -pytz -requests -json +configparser==3.5.0 +paramiko==2.4.0 +pytz==2017.3 +requests==2.18.4 +requests_toolbelt==0.8.0 +telegram==0.0.1 +dump==0.0.3 \ No newline at end of file diff --git a/server.py b/server.py index 8d644e5b..7d2b2e3f 100644 --- a/server.py +++ b/server.py @@ -12,9 +12,9 @@ server_port = config.getint('main', 'server_port') from http.server import HTTPServer, CGIHTTPRequestHandler -sys.stderr = open(log_path + '/opt/haproxy/log/haproxy-monitor.log', 'w') +sys.stderr = open(log_path + '/haproxy-monitor.log', 'w') webdir = fullpath os.chdir(webdir) server_address = (server_bind_ip, server_port) httpd = HTTPServer(server_address, CGIHTTPRequestHandler) -httpd.serve_forever() +httpd.serve_forever() \ No newline at end of file diff --git a/style.css b/style.css index df5e1bc6..bf650930 100644 --- a/style.css +++ b/style.css @@ -6,7 +6,7 @@ body { font-size: 14px; line-height: 1.42857143; color: #000; - background-color: #eee; + background-color: #fff; margin: 0; padding: 0; } @@ -18,12 +18,6 @@ body { position: fixed; right: 0; left: 0; - z-index: 1000; -} -.top-menu img { - max-width: 125px; - float: left; - padding-left: 100px; } .top-menu a, .footer a { padding: 10px; @@ -45,79 +39,9 @@ body { margin-left: 35%; } .conteiner { - clear: both; - margin-top: 65px; - min-height: calc(100vh - 115px); - width: 45%; - background-color: #fff; - margin-left: 27%; -} -.configShow, .diff { - margin-left: 16%; - height: 70%; - overflow: auto; - width: 70%; - border: 1px solid #DCDCDC; - border-radius: 5px; -} -.diffHead { - background-color: #F5F5F5; - padding: 10px; -} -.lineDog { - background-color: #dbedff; - margin-bottom: 10px; -} -.lineDiffMinus, .lineDiffPlus { - padding-left: 5px; -} -.lineDiffMinus { - background-color: #ffdce0; -} -.lineDiffPlus { - background-color: #cdffd8; -} -.lineDiff { - padding-left: 5px; -} -.param { - font-weight: bold; - background-color: #DCDCDC; - padding-left: 13px; -} -.numRow { - padding-left: 10px; - padding-right: 20px; -} -.paramInSec { - font-weight: bold; -} -.conteinerIndex { - width: 20%; - background-color: #fff; - padding: 20px; - border-radius: 10px; - margin-top: 2%; -} -.conteinerIndex img { - max-width: 250px; -} -.copyright { - color: #23527c; - margin-left: 15px; -} -.line { - background-color: #eee; - border: 1px solid #000; -} -.line, .line3 { - padding-top:5px; - padding-bottom: 5px; - padding-left: 10px; - padding-right: 10px; -} -.comment { - color: #aaa; + clear: both; + margin-top: 65px; + min-height: calc(100vh - 115px); } .addName { background-color: #eee; @@ -218,9 +142,7 @@ input::-moz-focus-inner { border: 0; } input { - line-height: normal; - border-radius: 4px; - padding: 4px; + line-height: normal; } fieldset { @@ -276,7 +198,6 @@ a:focus { padding-left: 15px; margin-right: auto; margin-left: auto; -} .container-fluid { padding-right: 15px; padding-left: 15px;