mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Updated admin mode
This commit is contained in:
parent
ba701a2317
commit
c44e14d0a6
@ -25,7 +25,7 @@ from doreah import settings
|
|||||||
from doreah.logging import log
|
from doreah.logging import log
|
||||||
from doreah.timing import Clock
|
from doreah.timing import Clock
|
||||||
from doreah.pyhp import file as pyhpfile
|
from doreah.pyhp import file as pyhpfile
|
||||||
from doreah.auth import get_login_page, authapi, authenticated
|
from doreah import auth
|
||||||
# technical
|
# technical
|
||||||
#from importlib.machinery import SourceFileLoader
|
#from importlib.machinery import SourceFileLoader
|
||||||
import importlib
|
import importlib
|
||||||
@ -56,7 +56,7 @@ STATICFOLDER = pkg_resources.resource_filename(__name__,"static")
|
|||||||
DATAFOLDER = DATA_DIR
|
DATAFOLDER = DATA_DIR
|
||||||
|
|
||||||
webserver = Bottle()
|
webserver = Bottle()
|
||||||
authapi.mount(server=webserver)
|
auth.authapi.mount(server=webserver)
|
||||||
|
|
||||||
pthjoin = os.path.join
|
pthjoin = os.path.join
|
||||||
|
|
||||||
@ -162,7 +162,7 @@ def get_css():
|
|||||||
|
|
||||||
@webserver.route("/login")
|
@webserver.route("/login")
|
||||||
def login():
|
def login():
|
||||||
return get_login_page()
|
return auth.get_login_page()
|
||||||
|
|
||||||
@webserver.route("/<name>.<ext>")
|
@webserver.route("/<name>.<ext>")
|
||||||
def static(name,ext):
|
def static(name,ext):
|
||||||
@ -223,7 +223,7 @@ jinjaenv.globals.update(JINJA_CONTEXT)
|
|||||||
|
|
||||||
|
|
||||||
@webserver.route("/<name:re:(issues|manual|setup|admin)>")
|
@webserver.route("/<name:re:(issues|manual|setup|admin)>")
|
||||||
@authenticated
|
@auth.authenticated
|
||||||
def static_html_private(name):
|
def static_html_private(name):
|
||||||
return static_html(name)
|
return static_html(name)
|
||||||
|
|
||||||
@ -242,7 +242,7 @@ def static_html(name):
|
|||||||
pyhp_pref = settings.get_settings("USE_PYHP")
|
pyhp_pref = settings.get_settings("USE_PYHP")
|
||||||
jinja_pref = settings.get_settings("USE_JINJA")
|
jinja_pref = settings.get_settings("USE_JINJA")
|
||||||
|
|
||||||
adminmode = request.cookies.get("adminmode") == "true" and database.checkAPIkey(request.cookies.get("apikey")) is not False
|
adminmode = request.cookies.get("adminmode") == "true" and auth.check(request)
|
||||||
|
|
||||||
clock = Clock()
|
clock = Clock()
|
||||||
clock.start()
|
clock.start()
|
||||||
|
98
maloja/web/jinja/admin.jinja
Normal file
98
maloja/web/jinja/admin.jinja
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
{% extends "base.jinja" %}
|
||||||
|
{% block title %}Maloja - Admin Panel{% endblock %}
|
||||||
|
|
||||||
|
{% block scripts %}
|
||||||
|
<script src="/cookies.js"></script>
|
||||||
|
<script>
|
||||||
|
|
||||||
|
function versioncompare(a,b) {
|
||||||
|
for (var pos=0;pos<3;pos++) {
|
||||||
|
var v1 = parseInt(a[pos]) || 0;
|
||||||
|
var v2 = parseInt(b[pos]) || 0;
|
||||||
|
if (v1 > v2) { return 1;}
|
||||||
|
if (v1 < v2) { return -1;}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
neo.xhttprequest("https://pypi.org/pypi/malojaserver/json",{},"GET",json=true).then((response)=>{
|
||||||
|
result = JSON.parse(response.responseText);
|
||||||
|
latestvers = result.info.version.split(".");
|
||||||
|
|
||||||
|
neo.xhttprequest("/api/serverinfo",{},"GET",json=true).then((response)=>{
|
||||||
|
|
||||||
|
result = JSON.parse(response.responseText);
|
||||||
|
thisvers = result.version;
|
||||||
|
|
||||||
|
document.getElementById("latestversion").innerHTML = latestvers.join(".");
|
||||||
|
document.getElementById("currentversion").innerHTML = thisvers.join(".");
|
||||||
|
|
||||||
|
if (versioncompare(latestvers,thisvers) <= 0) {
|
||||||
|
document.getElementById("currentversion").style.color = "green";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
document.getElementById("currentversion").style.color = "red";
|
||||||
|
document.getElementById("updatestatus").innerHTML = "Consider updating to take advantage of new features";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
function activate() {
|
||||||
|
neo.setCookie("adminmode","true");
|
||||||
|
window.location.reload(true);
|
||||||
|
}
|
||||||
|
function deactivate() {
|
||||||
|
neo.setCookie("adminmode","false");
|
||||||
|
window.location.reload(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<table class="top_info">
|
||||||
|
<tr>
|
||||||
|
<td class="image">
|
||||||
|
<div style="background-image:url('/favicon.png')"></div>
|
||||||
|
</td>
|
||||||
|
<td class="text">
|
||||||
|
<h1>Admin Panel</h1>
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<h2>Update</h2>
|
||||||
|
|
||||||
|
Currently installed Maloja version: <span id="currentversion">Loading...</span><br/>
|
||||||
|
Latest recommended Maloja version: <span id="latestversion">Loading...</span><br/>
|
||||||
|
<span id="updatestatus"></span>
|
||||||
|
|
||||||
|
|
||||||
|
<h2>Admin Mode</h2>
|
||||||
|
|
||||||
|
Admin Mode allows you to manually scrobble from various places on the web interface instead of just the dedicated page.<br/><br/>
|
||||||
|
{% if adminmode %}
|
||||||
|
<span id="adminmodebutton" class="button" onclick="deactivate()">Deactivate</span>
|
||||||
|
{% else %}
|
||||||
|
<span id="adminmodebutton" class="button" onclick="activate()">Activate</span>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<h2>Links</h2>
|
||||||
|
|
||||||
|
<a class="textlink" href="/setup">Server Setup</a><br/>
|
||||||
|
<a class="textlink" href="/manual">Manual Scrobbling</a><br/>
|
||||||
|
<a class="textlink" href="/issues">Database Maintenance</a>
|
||||||
|
|
||||||
|
<h2>External</h2>
|
||||||
|
|
||||||
|
<a class="textlink" target="_blank" rel="noopener noreferrer" href="https://github.com/krateng/maloja/issues/new">Report Issue</a><br/>
|
||||||
|
|
||||||
|
|
||||||
|
{% endblock %}
|
@ -4,8 +4,8 @@
|
|||||||
{% block scripts %}
|
{% block scripts %}
|
||||||
<script src="/rangeselect.js"></script>
|
<script src="/rangeselect.js"></script>
|
||||||
<script>
|
<script>
|
||||||
function scrobble(encodedtrack,apikey) {
|
function scrobble(encodedtrack) {
|
||||||
neo.xhttprequest('/api/newscrobble?' + encodedtrack + "key=" + apikey).then(response=>{window.location.reload()});
|
neo.xhttprequest('/api/newscrobble?' + encodedtrack).then(response=>{window.location.reload()});
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@ -45,7 +45,10 @@
|
|||||||
<span class="rank"><a href="/charts_tracks?max=100">#{{ info.position }}</a></span>
|
<span class="rank"><a href="/charts_tracks?max=100">#{{ info.position }}</a></span>
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
<p class="stats"><a href="/scrobbles?{{ encodedtrack }}">{{ info['scrobbles'] }} Scrobbles</a></p>
|
<p class="stats">
|
||||||
|
{% if adminmode %}<span onclick="scrobble('{{ encodedtrack }}')" class="button">Scrobble now</span>{% endif %}
|
||||||
|
<a href="/scrobbles?{{ encodedtrack }}">{{ info['scrobbles'] }} Scrobbles</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,101 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
|
|
||||||
<html>
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8" />
|
|
||||||
<title>Maloja</title>
|
|
||||||
<script src="/cookies.js"></script>
|
|
||||||
|
|
||||||
<pyhp include="common/header.html" />
|
|
||||||
|
|
||||||
<script>
|
|
||||||
|
|
||||||
function versioncompare(a,b) {
|
|
||||||
for (var pos=0;pos<3;pos++) {
|
|
||||||
var v1 = parseInt(a[pos]) || 0;
|
|
||||||
var v2 = parseInt(b[pos]) || 0;
|
|
||||||
if (v1 > v2) { return 1;}
|
|
||||||
if (v1 < v2) { return -1;}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
neo.xhttprequest("https://pypi.org/pypi/malojaserver/json",{},"GET",json=true).then((response)=>{
|
|
||||||
result = JSON.parse(response.responseText);
|
|
||||||
latestvers = result.info.version.split(".");
|
|
||||||
|
|
||||||
neo.xhttprequest("/api/serverinfo",{},"GET",json=true).then((response)=>{
|
|
||||||
|
|
||||||
result = JSON.parse(response.responseText);
|
|
||||||
thisvers = result.version;
|
|
||||||
|
|
||||||
document.getElementById("latestversion").innerHTML = latestvers.join(".");
|
|
||||||
document.getElementById("currentversion").innerHTML = thisvers.join(".");
|
|
||||||
|
|
||||||
if (versioncompare(latestvers,thisvers) <= 0) {
|
|
||||||
document.getElementById("currentversion").style.color = "green";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
document.getElementById("currentversion").style.color = "red";
|
|
||||||
document.getElementById("updatestatus").innerHTML = "Consider updating to take advantage of new features";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
function activate() {
|
|
||||||
neo.setCookie("adminmode","true");
|
|
||||||
window.location.reload(true);
|
|
||||||
}
|
|
||||||
function deactivate() {
|
|
||||||
neo.setCookie("adminmode","false");
|
|
||||||
window.location.reload(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
</script>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<table class="top_info">
|
|
||||||
<tr>
|
|
||||||
<td class="image">
|
|
||||||
<div style="background-image:url('/favicon.png')"></div>
|
|
||||||
</td>
|
|
||||||
<td class="text">
|
|
||||||
<h1>Admin Panel</h1>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
<h2>Update</h2>
|
|
||||||
|
|
||||||
Currently installed Maloja version: <span id="currentversion">Loading...</span><br/>
|
|
||||||
Latest recommended Maloja version: <span id="latestversion">Loading...</span><br/>
|
|
||||||
<span id="updatestatus"></span>
|
|
||||||
|
|
||||||
|
|
||||||
<h2>Admin Mode</h2>
|
|
||||||
|
|
||||||
Admin Mode allows you to manually scrobble from various places on the web interface instead of just the dedicated page.<br/><br/>
|
|
||||||
<pyhp if="adminmode"><span id="adminmodebutton" class="button">Deactivate</span></pyhp>
|
|
||||||
<pyhp if="not adminmode"><span id="adminmodebutton" class="button">Activate</span></pyhp>
|
|
||||||
|
|
||||||
<h2>Links</h2>
|
|
||||||
|
|
||||||
<a class="textlink" href="/setup">Server Setup</a><br/>
|
|
||||||
<a class="textlink" href="/manual">Manual Scrobbling</a><br/>
|
|
||||||
<a class="textlink" href="/issues">Database Maintenance</a>
|
|
||||||
|
|
||||||
<h2>External</h2>
|
|
||||||
|
|
||||||
<a class="textlink" target="_blank" rel="noopener noreferrer" href="https://github.com/krateng/maloja/issues/new">Report Issue</a><br/>
|
|
||||||
|
|
||||||
<pyhp include="common/footer.html" />
|
|
||||||
</body>
|
|
||||||
</html>
|
|
Loading…
Reference in New Issue
Block a user