diff --git a/info.py b/info.py index ea23697..e0955e6 100644 --- a/info.py +++ b/info.py @@ -1 +1,10 @@ -version = 1,5,11 +import os + +author = { + "name":"Johannes Krattenmacher", + "email":"maloja@krateng.dev", + "github": "krateng" +} +version = 1,5,12 +versionstr = ".".join(str(n) for n in version) +dev = os.path.exists("./.dev") diff --git a/server.py b/server.py index 9cf7461..361d4cc 100755 --- a/server.py +++ b/server.py @@ -153,12 +153,16 @@ def static_html(name): html_file = os.path.exists("website/" + name + ".html") pyhp_pref = settings.get_settings("USE_PYHP") + adminmode = request.cookies.get("adminmode") == "true" and database.checkAPIkey(request.cookies.get("apikey")) is not False + # if a pyhp file exists, use this if (pyhp_file and pyhp_pref) or (pyhp_file and not html_file): from doreah.pyhp import file environ = {} #things we expose to the pyhp pages + environ["adminmode"] = adminmode + # maloja environ["db"] = database environ["htmlmodules"] = htmlmodules diff --git a/website/admin.pyhp b/website/admin.pyhp index dd4157e..5541499 100644 --- a/website/admin.pyhp +++ b/website/admin.pyhp @@ -31,7 +31,55 @@ } }); }); + + + function activate() { + neo.setCookie("adminmode","true"); + window.location.reload(true); + } + function deactivate() { + neo.setCookie("adminmode","false"); + window.location.reload(true); + } + + function buttonlock() { + button = document.getElementById("adminmodebutton") + if (apikeycorrect) { + button.classList.remove("locked"); + if (button.innerHTML == "Activate") { button.onclick = activate; } + else { button.onclick = deactivate; } + // ugh + } + else { + button.classList.add("locked"); + button.onclick = null; + } + } + + window.addEventListener("load",function(){checkAPIkey(buttonlock)}); + // we do this twice, but this one ensures that the button is correctly locked / unlocked after the api key has been checked + @@ -45,9 +93,10 @@
-

Maloja


+

Admin Panel


+

+ API Key:

-

Welcome to your own Maloja server!

@@ -61,7 +110,9 @@

Admin Mode

- Activate admin mode to manually scrobble from various places on the website (Coming soon) + Admin Mode allows you to manually scrobble from various places on the web interface instead of just the dedicated page.

+ Deactivate + Activate

Links

diff --git a/website/javascript/cookies.js b/website/javascript/cookies.js index aea9084..1af0ae7 100644 --- a/website/javascript/cookies.js +++ b/website/javascript/cookies.js @@ -67,7 +67,7 @@ function saveAPIkey() { -function checkAPIkey() { +function checkAPIkey(extrafunc=null) { url = "/api/test?key=" + APIkey() var xhttp = new XMLHttpRequest(); @@ -81,6 +81,11 @@ function checkAPIkey() { document.getElementById("apikey").style.backgroundColor = "red" apikeycorrect = false } + + if (extrafunc != null) { + extrafunc(); + } + }; try { xhttp.open("GET",url,true); @@ -89,6 +94,9 @@ function checkAPIkey() { catch (e) { document.getElementById("apikey").style.backgroundColor = "red" apikeycorrect = false + if (extrafunc != null) { + extrafunc(); + } } }