diff --git a/src/dashboard.py b/src/dashboard.py index 7380c35..c934d0e 100644 --- a/src/dashboard.py +++ b/src/dashboard.py @@ -674,7 +674,11 @@ def auth_req(): else: session['message'] = "" conf.clear() - return redirect("/signin?redirect=" + str(request.url)) + + redirectURL = str(request.url) + redirectURL = redirectURL.replace("http://", "") + redirectURL = redirectURL.replace("https://", "") + return redirect("/signin?redirect=" + redirectURL) else: if request.endpoint in ['signin', 'signout', 'auth', 'settings', 'update_acct', 'update_pwd', 'update_app_ip_port', 'update_wg_conf_path']: @@ -1533,7 +1537,6 @@ def switch_display_mode(mode): @app.route('/api/togglePeerAccess', methods=['POST']) def togglePeerAccess(): data = request.get_json() - print(data['peerID']) returnData = {"status": True, "reason": ""} required = ['peerID', 'config'] if checkJSONAllParameter(required, data): @@ -1572,7 +1575,26 @@ def togglePeerAccess(): return jsonify(returnData) - +@app.route('/api/addConfigurationAddressCheck', methods=['POST']) +def addConfigurationAddressCheck(): + data = request.get_json() + returnData = {"status": True, "reason": ""} + required = ['address'] + if checkJSONAllParameter(required, data): + try: + ips = list(ipaddress.ip_network(data['address'], False).hosts()) + amount = len(ips) - 1 + if amount >= 1: + returnData = {"status": True, "reason":"", "data":f"Total of {amount} IPs"} + else: + returnData = {"status": True, "reason":"", "data":f"0 IP available for peers"} + + except ValueError as e: + returnData = {"status": False, "reason": str(e)} + else: + returnData = {"status": False, "reason": "Please provide all required parameters."} + return jsonify(returnData) + """ Dashboard Tools Related @@ -1789,5 +1811,4 @@ if __name__ == "__main__": app_port = config.get("Server", "app_port") WG_CONF_PATH = config.get("Server", "wg_conf_path") config.clear() - socketio.run(app, host=app_ip, debug=False, port=int(app_port)) - # app.run(host=app_ip, debug=False, port=app_port) + app.run(host=app_ip, debug=False, port=app_port) diff --git a/src/static/css/dashboard.css b/src/static/css/dashboard.css index 0c425e0..1db3560 100644 --- a/src/static/css/dashboard.css +++ b/src/static/css/dashboard.css @@ -3,6 +3,10 @@ body { /*font-family: 'Poppins', sans-serif;*/ } +.codeFont{ + font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; +} + .feather { width: 16px; height: 16px; @@ -307,7 +311,7 @@ main { right: 0; box-shadow: 0 10px 20px rgb(0 0 0 / 19%), 0 6px 6px rgb(0 0 0 / 23%); border-radius: 10px; - min-width: 200px; + min-width: 250px; display: none; transform: translateY(-30px); opacity: 0; @@ -760,4 +764,12 @@ pre.index-alert { height: 4px; background-color: #007bff; border-bottom-left-radius: .25rem; +} + +.addConfigurationAvailableIPs{ + margin-bottom: 0; +} + +.input-feedback{ + display: none; } \ No newline at end of file diff --git a/src/static/js/configuration.js b/src/static/js/configuration.js index 09ff7a6..a557cb2 100644 --- a/src/static/js/configuration.js +++ b/src/static/js/configuration.js @@ -4,12 +4,11 @@ */ - +let peers = []; (function() { /** * Definitions - */ - let peers = []; + */ let configuration_name; let configuration_interval; let configuration_timeout = window.localStorage.getItem("configurationTimeout"); diff --git a/src/static/js/index.js b/src/static/js/index.js new file mode 100644 index 0000000..2f23bf7 --- /dev/null +++ b/src/static/js/index.js @@ -0,0 +1,118 @@ +let numberToast = 0; +let addConfigurationModal = new bootstrap.Modal(document.getElementById('addConfigurationModal'), { + keyboard: false, + backdrop: 'static' +}); + +function showToast(msg){ + $(".toastContainer").append( + `` ) + $(`#${numberToast}-toast`).toast('show'); + $(`#${numberToast}-toast .toast-body`).html(msg); + $(`#${numberToast}-toast .toast-progressbar`).css("transition", `width ${$(`#${numberToast}-toast .toast-progressbar`).parent().data('delay')}ms cubic-bezier(0, 0, 0, 0)`); + $(`#${numberToast}-toast .toast-progressbar`).css("width", "0px"); + numberToast++; +} + +$(".toggle--switch").on("change", function(){ + $(this).addClass("waiting").attr("disabled", "disabled"); + let id = $(this).data("conf-id"); + let status = $(this).prop("checked"); + let ele = $(this); + let label = $(this).siblings("label"); + $.ajax({ + url: `/switch/${id}` + }).done(function(res){ + let dot = $(`div[data-conf-id="${id}"] .dot`); + console.log(); + if (res){ + if (status){ + dot.removeClass("dot-stopped").addClass("dot-running"); + dot.siblings().text("Running"); + showToast(`${id} is running.`) + }else{ + dot.removeClass("dot-running").addClass("dot-stopped"); + showToast(`${id} is stopped.`) + } + ele.removeClass("waiting"); + ele.removeAttr("disabled"); + }else{ + if (status){ + $(this).prop("checked", false) + }else{ + $(this).prop("checked", true) + } + } + + }) +}); + +$('.switch').on("click", function() { + $(this).siblings($(".spinner-border")).css("display", "inline-block") + $(this).remove() + location.replace("/switch/"+$(this).attr('id')) +}); +$(".sb-home-url").addClass("active"); + +$(".card-body").on("click", function(handle){ + if ($(handle.target).attr("class") !== "toggleLabel" && $(handle.target).attr("class") !== "toggle--switch") { + window.open($(this).find("a").attr("href"), "_self"); + } +}); + +function genKeyPair(){ + let keyPair = window.wireguard.generateKeypair(); + $("#addConfigurationPrivateKey").val(keyPair.privateKey); + $("#addConfigurationPublicKey").attr("disabled", "disabled").val(keyPair.publicKey); +} + +$("#reGeneratePrivateKey").on("click", function() { + genKeyPair(); +}); + +$("#toggleAddConfiguration").on("click", function(){ + addConfigurationModal.toggle(); + genKeyPair() +}); + +$("#addConfigurationPrivateKey").on("change", function() { + let $publicKey = $("#addConfigurationPublicKey"); + if ($(this).val().length === 44) { + $publicKey.attr("disabled", "disabled").val(window.wireguard.generatePublicKey($(this).val())); + } else { + $publicKey.removeAttr("disabled").val(""); + } +}); + +$("#addConfigurationAddress").on("change", function(){ + let address = $("#addConfigurationAddress"); + let addressFeedback = $("#addConfigurationAddressFeedback"); + let availableIPs = $(".addConfigurationAvailableIPs"); + $.ajax({ + url: "/api/addConfigurationAddressCheck", + method: "POST", + headers: {"Content-Type": "application/json"}, + data: JSON.stringify({ + "address": $(this).val() + }) + }).done(function(res){ + console.log(res) + if (res.status){ + availableIPs.html(`${res.data}`); + address.removeClass("is-invalid").addClass("is-valid"); + }else{ + address.addClass("is-invalid"); + addressFeedback.addClass("invalid-feedback").text(res.reason); + availableIPs.html(`N/A`); + } + }) +}); \ No newline at end of file diff --git a/src/templates/configuration.html b/src/templates/configuration.html index 70c5b67..06ac027 100644 --- a/src/templates/configuration.html +++ b/src/templates/configuration.html @@ -142,6 +142,7 @@
+ Configration Settings Delete Peers Download All Peers
diff --git a/src/templates/index.html b/src/templates/index.html index 98ef287..3b4f0fe 100644 --- a/src/templates/index.html +++ b/src/templates/index.html @@ -63,81 +63,111 @@ {%endfor%} -
- -
-{% include "tools.html" %} - -{% include "footer.html" %} - + + + + + +{% include "tools.html" %} + +{% include "footer.html" %} + + \ No newline at end of file diff --git a/src/templates/signin.html b/src/templates/signin.html index 16e5e1b..0a49285 100644 --- a/src/templates/signin.html +++ b/src/templates/signin.html @@ -67,7 +67,11 @@ if (res.status === true){ const urlParams = new URLSearchParams(window.location.search); if (urlParams.get("redirect")){ - window.location.replace(urlParams.get("redirect")) + if (document.URL.substring(0, 5) == "http:"){ + window.location.replace(`http://${urlParams.get("redirect")}`) + }else if (document.URL.substring(0, 5) == "https"){ + window.location.replace(`https://${urlParams.get("redirect")}`) + } }else{ window.location.replace("/"); }