From 724625523c2ac1bb9e334ec4d8602cfadfffe2ca Mon Sep 17 00:00:00 2001 From: Aidaho12 Date: Mon, 26 Mar 2018 17:48:48 +0600 Subject: [PATCH] v1.9 Improved design --- cgi-bin/funct.py | 76 ++++++++--------- inc/js-cookie.js | 166 +++++++++++++++++++++++++++++++++++++ script.js => inc/script.js | 33 +++++--- style.css => inc/style.css | 10 +-- index.html | 2 +- 5 files changed, 233 insertions(+), 54 deletions(-) create mode 100644 inc/js-cookie.js rename script.js => inc/script.js (91%) rename style.css => inc/style.css (98%) diff --git a/cgi-bin/funct.py b/cgi-bin/funct.py index 207ecc8d..4f6b8634 100644 --- a/cgi-bin/funct.py +++ b/cgi-bin/funct.py @@ -102,7 +102,43 @@ def mode_admin(button, **kwargs): print('' % button) elif role.value == "admin" or role.value == "editor" and level == "editor": print('' % button) - + +def head(title): + print('Content-type: text/html\n') + print('%s' % title) + print('' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
' + '
' + 'HAproxy-WI' + '' + '' + '' + '' + '' + '
') + if config.get('main', 'logo_enable') == "1": + print('
' % config.get('main', 'logo_path')) + print('
') + def links(): print('') - -def head(title): - print('Content-type: text/html\n') - print('%s' % title) - print('' - '' - '' - '' - '' - '' - '' - '' - '' - '' - '' - '
' - '
' - 'HAproxy-WI' - '' - '' - '' - '' - '' - '
') - if config.get('main', 'logo_enable') == "1": - print('
' % config.get('main', 'logo_path')) - print('
') - def footer(): print('
' '
' @@ -185,7 +185,7 @@ def footer(): '' - '
-->') + '-->') def ssh_connect(serv): ssh = SSHClient() diff --git a/inc/js-cookie.js b/inc/js-cookie.js new file mode 100644 index 00000000..2fbadde9 --- /dev/null +++ b/inc/js-cookie.js @@ -0,0 +1,166 @@ +/*! + * JavaScript Cookie v2.2.0 + * https://github.com/js-cookie/js-cookie + * + * Copyright 2006, 2015 Klaus Hartl & Fagner Brack + * Released under the MIT license + */ +;(function (factory) { + var registeredInModuleLoader = false; + if (typeof define === 'function' && define.amd) { + define(factory); + registeredInModuleLoader = true; + } + if (typeof exports === 'object') { + module.exports = factory(); + registeredInModuleLoader = true; + } + if (!registeredInModuleLoader) { + var OldCookies = window.Cookies; + var api = window.Cookies = factory(); + api.noConflict = function () { + window.Cookies = OldCookies; + return api; + }; + } +}(function () { + function extend () { + var i = 0; + var result = {}; + for (; i < arguments.length; i++) { + var attributes = arguments[ i ]; + for (var key in attributes) { + result[key] = attributes[key]; + } + } + return result; + } + + function init (converter) { + function api (key, value, attributes) { + var result; + if (typeof document === 'undefined') { + return; + } + + // Write + + if (arguments.length > 1) { + attributes = extend({ + path: '/' + }, api.defaults, attributes); + + if (typeof attributes.expires === 'number') { + var expires = new Date(); + expires.setMilliseconds(expires.getMilliseconds() + attributes.expires * 864e+5); + attributes.expires = expires; + } + + // We're using "expires" because "max-age" is not supported by IE + attributes.expires = attributes.expires ? attributes.expires.toUTCString() : ''; + + try { + result = JSON.stringify(value); + if (/^[\{\[]/.test(result)) { + value = result; + } + } catch (e) {} + + if (!converter.write) { + value = encodeURIComponent(String(value)) + .replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent); + } else { + value = converter.write(value, key); + } + + key = encodeURIComponent(String(key)); + key = key.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent); + key = key.replace(/[\(\)]/g, escape); + + var stringifiedAttributes = ''; + + for (var attributeName in attributes) { + if (!attributes[attributeName]) { + continue; + } + stringifiedAttributes += '; ' + attributeName; + if (attributes[attributeName] === true) { + continue; + } + stringifiedAttributes += '=' + attributes[attributeName]; + } + return (document.cookie = key + '=' + value + stringifiedAttributes); + } + + // Read + + if (!key) { + result = {}; + } + + // To prevent the for loop in the first place assign an empty array + // in case there are no cookies at all. Also prevents odd result when + // calling "get()" + var cookies = document.cookie ? document.cookie.split('; ') : []; + var rdecode = /(%[0-9A-Z]{2})+/g; + var i = 0; + + for (; i < cookies.length; i++) { + var parts = cookies[i].split('='); + var cookie = parts.slice(1).join('='); + + if (!this.json && cookie.charAt(0) === '"') { + cookie = cookie.slice(1, -1); + } + + try { + var name = parts[0].replace(rdecode, decodeURIComponent); + cookie = converter.read ? + converter.read(cookie, name) : converter(cookie, name) || + cookie.replace(rdecode, decodeURIComponent); + + if (this.json) { + try { + cookie = JSON.parse(cookie); + } catch (e) {} + } + + if (key === name) { + result = cookie; + break; + } + + if (!key) { + result[name] = cookie; + } + } catch (e) {} + } + + return result; + } + + api.set = api; + api.get = function (key) { + return api.call(api, key); + }; + api.getJSON = function () { + return api.apply({ + json: true + }, [].slice.call(arguments)); + }; + api.defaults = {}; + + api.remove = function (key, attributes) { + api(key, '', extend(attributes, { + expires: -1 + })); + }; + + api.withConverter = init; + + return api; + } + + return init(function () {}); +})); + diff --git a/script.js b/inc/script.js similarity index 91% rename from script.js rename to inc/script.js index 325f7898..e410694e 100644 --- a/script.js +++ b/inc/script.js @@ -176,20 +176,33 @@ $( function() { } }); $( "#hide_menu" ).click(function() { - if ($(".top_menu").css("display", "block")) { - $(".top-menu").hide( "drop", "slow" ); - $(".container").css("max-width", "98%"); - $(".container").css("margin-left", "1%"); - $(".show_menu").show(); - } + $(".top-menu").hide( "drop", "fast" ); + $(".container").css("max-width", "98%"); + $(".container").css("margin-left", "1%"); + $(".show_menu").show(); + Cookies.set('hide_menu', 'hide', { expires: 365 }); }); $( "#show_menu" ).click(function() { - $(".top-menu").show( "drop", "slow" ); - $(".container").css("max-width", "88%"); - $(".container").css("margin-left", "307px"); - $(".show_menu").hide(); + $(".top-menu").show( "drop", "fast" ); + $(".container").css("max-width", "91%"); + $(".container").css("margin-left", "207px"); + $(".show_menu").hide(); + Cookies.set('hide_menu', 'show', { expires: 365 }); }); + var hideMenu = Cookies.get('hide_menu'); + if (hideMenu == "show") { + $(".top-menu").show( "drop", "fast" ); + $(".container").css("max-width", "91%"); + $(".container").css("margin-left", "207px"); + } + if (hideMenu == "hide") { + $(".top-menu").hide(); + $(".container").css("max-width", "98%"); + $(".container").css("margin-left", "1%"); + $(".show_menu").show(); + } + var availableTags = [ "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" ]; diff --git a/style.css b/inc/style.css similarity index 98% rename from style.css rename to inc/style.css index 28207800..e41eca30 100644 --- a/style.css +++ b/inc/style.css @@ -37,7 +37,7 @@ iframe { .top-menu { position: fixed; height: 100%; - width: 307px; + width: 207px; float: left; margin-bottom: 20px; top: 0; @@ -79,14 +79,15 @@ iframe { } .container { min-height: calc(100vh - 115px); - max-width: 88%; + max-width: 91%; min-width: 40%; background-color: #fff; - margin-left: 307px; + margin-left: 207px; + padding-bottom: 10px; } .configShow, .diff { margin-left: 16%; - height: 70%; + height: 78%; overflow: auto; width: 70%; border: 1px solid #DCDCDC; @@ -255,7 +256,6 @@ iframe { border-radius: 3px; } .menu { - margin-left: 13%; font-weight: bold; font-style: italic; } diff --git a/index.html b/index.html index 3c2c547f..98228fc2 100644 --- a/index.html +++ b/index.html @@ -5,7 +5,7 @@ HAProxy web manager - +