mirror of
https://github.com/krateng/maloja.git
synced 2025-07-09 03:04:07 -04:00
Moved to new api key handling
This commit is contained in:
parent
a1ba5f58b8
commit
7f650e604e
@ -1,6 +0,0 @@
|
|||||||
# Only the entries in authenticated_machines.tsv are used, this is an example file
|
|
||||||
# It is recommended to have a separate key for every scrobbler application you use,
|
|
||||||
# as well as a key for manual interactions on the website
|
|
||||||
YDzcmp8JpYHCcvJbDOVT7nEDoyCEND6K Chromium Extension on Manjaro
|
|
||||||
correcthorsebatterystaple Pano Scrobbler on Android
|
|
||||||
thingolisthebestking Web Interface
|
|
Can't render this file because it has a wrong number of fields in line 4.
|
@ -10,7 +10,7 @@ from .malojauri import uri_to_internal, internal_to_uri, compose_querystring
|
|||||||
from .thirdparty import proxy_scrobble_all
|
from .thirdparty import proxy_scrobble_all
|
||||||
|
|
||||||
from .__pkginfo__ import version
|
from .__pkginfo__ import version
|
||||||
from .globalconf import data_dir, malojaconfig
|
from .globalconf import data_dir, malojaconfig, apikeystore
|
||||||
|
|
||||||
# doreah toolkit
|
# doreah toolkit
|
||||||
from doreah.logging import log
|
from doreah.logging import log
|
||||||
@ -103,24 +103,14 @@ def add_known_server(url):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
### symmetric keys are fine for now since we hopefully use HTTPS
|
|
||||||
def loadAPIkeys():
|
|
||||||
global clients
|
|
||||||
tsv.create(data_dir['clients']("authenticated_machines.tsv"))
|
|
||||||
#createTSV("clients/authenticated_machines.tsv")
|
|
||||||
clients = tsv.parse(data_dir['clients']("authenticated_machines.tsv"),"string","string")
|
|
||||||
#clients = parseTSV("clients/authenticated_machines.tsv","string","string")
|
|
||||||
log("Authenticated Machines: " + ", ".join([m[1] for m in clients]))
|
|
||||||
|
|
||||||
def checkAPIkey(k):
|
log("Authenticated Machines: " + ", ".join([k for k in apikeystore]))
|
||||||
#return (k in [k for [k,d] in clients])
|
|
||||||
for key, identifier in clients:
|
|
||||||
if key == k: return identifier
|
|
||||||
|
|
||||||
return False
|
def checkAPIkey(key):
|
||||||
|
return any((key == apikeystore[k]) for k in apikeystore)
|
||||||
|
|
||||||
def allAPIkeys():
|
def allAPIkeys():
|
||||||
return [k for [k,d] in clients]
|
return [apikeystore[k] for k in apikeystore]
|
||||||
|
|
||||||
|
|
||||||
####
|
####
|
||||||
@ -706,7 +696,6 @@ def start_db():
|
|||||||
log("Starting database...")
|
log("Starting database...")
|
||||||
global lastsync
|
global lastsync
|
||||||
lastsync = int(datetime.datetime.now(tz=datetime.timezone.utc).timestamp())
|
lastsync = int(datetime.datetime.now(tz=datetime.timezone.utc).timestamp())
|
||||||
loadAPIkeys()
|
|
||||||
build_db()
|
build_db()
|
||||||
#run(dbserver, host='::', port=PORT, server='waitress')
|
#run(dbserver, host='::', port=PORT, server='waitress')
|
||||||
log("Database reachable!")
|
log("Database reachable!")
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
from doreah.configuration import Configuration
|
from doreah.configuration import Configuration
|
||||||
from doreah.configuration import types as tp
|
from doreah.configuration import types as tp
|
||||||
|
from doreah.keystore import KeyStore
|
||||||
|
|
||||||
from .__pkginfo__ import versionstr
|
from .__pkginfo__ import versionstr
|
||||||
|
|
||||||
@ -258,7 +259,7 @@ data_directories = {
|
|||||||
"images":pthj(dir_settings['state'],"images"),
|
"images":pthj(dir_settings['state'],"images"),
|
||||||
"scrobbles":pthj(dir_settings['state'],"scrobbles"),
|
"scrobbles":pthj(dir_settings['state'],"scrobbles"),
|
||||||
"rules":pthj(dir_settings['config'],"rules"),
|
"rules":pthj(dir_settings['config'],"rules"),
|
||||||
"clients":pthj(dir_settings['config'],"clients"),
|
"clients":pthj(dir_settings['config']),
|
||||||
"settings":pthj(dir_settings['config']),
|
"settings":pthj(dir_settings['config']),
|
||||||
"css":pthj(dir_settings['config'],"custom_css"),
|
"css":pthj(dir_settings['config'],"custom_css"),
|
||||||
"logs":pthj(dir_settings['logs']),
|
"logs":pthj(dir_settings['logs']),
|
||||||
@ -305,6 +306,27 @@ config(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### API KEYS
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### symmetric keys are fine for now since we hopefully use HTTPS
|
||||||
|
apikeystore = KeyStore(file=data_dir['clients']("apikeys.yml"),save_endpoint="/apis/mlj_1/api_keys")
|
||||||
|
|
||||||
|
oldfile = pthj(dir_settings['config'],"clients","authenticated_machines.tsv")
|
||||||
|
if os.path.exists(oldfile):
|
||||||
|
try:
|
||||||
|
from doreah import tsv
|
||||||
|
clients = tsv.parse(oldfile,"string","string")
|
||||||
|
for key,identifier in clients:
|
||||||
|
apikeystore[identifier] = key
|
||||||
|
os.remove(oldfile)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
# what the fuck did i just write
|
# what the fuck did i just write
|
||||||
# this spaghetti file is proudly sponsored by the rice crackers i'm eating at the
|
# this spaghetti file is proudly sponsored by the rice crackers i'm eating at the
|
||||||
# moment as well as some cute chinese girl whose asmr i'm listening to in the
|
# moment as well as some cute chinese girl whose asmr i'm listening to in the
|
||||||
|
@ -4,11 +4,11 @@ from doreah.io import col, ask, prompt
|
|||||||
from doreah import auth
|
from doreah import auth
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from ..globalconf import data_dir, dir_settings, malojaconfig
|
from ..globalconf import data_dir, dir_settings, malojaconfig, apikeystore
|
||||||
|
|
||||||
|
|
||||||
# EXTERNAL API KEYS
|
# EXTERNAL API KEYS
|
||||||
apikeys = [
|
ext_apikeys = [
|
||||||
"LASTFM_API_KEY",
|
"LASTFM_API_KEY",
|
||||||
"SPOTIFY_API_ID",
|
"SPOTIFY_API_ID",
|
||||||
"SPOTIFY_API_SECRET",
|
"SPOTIFY_API_SECRET",
|
||||||
@ -33,7 +33,7 @@ def setup():
|
|||||||
SKIP = malojaconfig["SKIP_SETUP"]
|
SKIP = malojaconfig["SKIP_SETUP"]
|
||||||
|
|
||||||
print("Various external services can be used to display images. If not enough of them are set up, only local images will be used.")
|
print("Various external services can be used to display images. If not enough of them are set up, only local images will be used.")
|
||||||
for k in apikeys:
|
for k in ext_apikeys:
|
||||||
keyname = malojaconfig.get_setting_info(k)['name']
|
keyname = malojaconfig.get_setting_info(k)['name']
|
||||||
key = malojaconfig[k]
|
key = malojaconfig[k]
|
||||||
if key is False:
|
if key is False:
|
||||||
@ -47,13 +47,11 @@ def setup():
|
|||||||
|
|
||||||
|
|
||||||
# OWN API KEY
|
# OWN API KEY
|
||||||
if not os.path.exists(data_dir['clients']("authenticated_machines.tsv")):
|
if len(apikeystore) == 0:
|
||||||
answer = ask("Do you want to set up a key to enable scrobbling? Your scrobble extension needs that key so that only you can scrobble tracks to your database.",default=True,skip=SKIP)
|
answer = ask("Do you want to set up a key to enable scrobbling? Your scrobble extension needs that key so that only you can scrobble tracks to your database.",default=True,skip=SKIP)
|
||||||
if answer:
|
if answer:
|
||||||
key = randomstring(64)
|
key = apikeystore.generate_key('default')
|
||||||
print("Your API Key: " + col["yellow"](key))
|
print("Your API Key: " + col["yellow"](key))
|
||||||
with open(data_dir['clients']("authenticated_machines.tsv"),"w") as keyfile:
|
|
||||||
keyfile.write(key + "\t" + "Default Generated Key")
|
|
||||||
|
|
||||||
# PASSWORD
|
# PASSWORD
|
||||||
forcepassword = malojaconfig["FORCE_PASSWORD"]
|
forcepassword = malojaconfig["FORCE_PASSWORD"]
|
||||||
|
@ -21,7 +21,7 @@ from doreah import auth
|
|||||||
from . import database
|
from . import database
|
||||||
from .utilities import resolveImage
|
from .utilities import resolveImage
|
||||||
from .malojauri import uri_to_internal, remove_identical
|
from .malojauri import uri_to_internal, remove_identical
|
||||||
from .globalconf import malojaconfig, data_dir
|
from .globalconf import malojaconfig, apikeystore, data_dir
|
||||||
from .jinjaenv.context import jinja_environment
|
from .jinjaenv.context import jinja_environment
|
||||||
from .apis import init_apis
|
from .apis import init_apis
|
||||||
|
|
||||||
@ -231,6 +231,7 @@ def static_html(name):
|
|||||||
"adminmode":adminmode,
|
"adminmode":adminmode,
|
||||||
"config":malojaconfig,
|
"config":malojaconfig,
|
||||||
"apikey":request.cookies.get("apikey") if adminmode else None,
|
"apikey":request.cookies.get("apikey") if adminmode else None,
|
||||||
|
"apikeys":apikeystore,
|
||||||
"_urikeys":keys, #temporary!
|
"_urikeys":keys, #temporary!
|
||||||
}
|
}
|
||||||
loc_context["filterkeys"], loc_context["limitkeys"], loc_context["delimitkeys"], loc_context["amountkeys"], loc_context["specialkeys"] = uri_to_internal(keys)
|
loc_context["filterkeys"], loc_context["limitkeys"], loc_context["delimitkeys"], loc_context["amountkeys"], loc_context["specialkeys"] = uri_to_internal(keys)
|
||||||
|
@ -36,11 +36,16 @@
|
|||||||
{% else %}
|
{% else %}
|
||||||
<a href="/admin_issues">Database Maintenance</a>
|
<a href="/admin_issues">Database Maintenance</a>
|
||||||
{% endif %} |
|
{% endif %} |
|
||||||
{% if page=='admin_settings' %}
|
{% if page=='admin_settings' %}
|
||||||
<span style="opacity:0.5;">Settings</span>
|
<span style="opacity:0.5;">Settings</span>
|
||||||
{% else %}
|
{% else %}
|
||||||
<a href="/admin_settings">Settings</a>
|
<a href="/admin_settings">Settings</a>
|
||||||
{% endif %}
|
{% endif %} |
|
||||||
|
{% if page=='admin_apikeys' %}
|
||||||
|
<span style="opacity:0.5;">API Keys</span>
|
||||||
|
{% else %}
|
||||||
|
<a href="/admin_apikeys">API Keys</a>
|
||||||
|
{% endif %}
|
||||||
</span>
|
</span>
|
||||||
<br/><br/>
|
<br/><br/>
|
||||||
<span id="notification"></span>
|
<span id="notification"></span>
|
||||||
|
8
maloja/web/jinja/admin_apikeys.jinja
Normal file
8
maloja/web/jinja/admin_apikeys.jinja
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{% set page ='admin_apikeys' %}
|
||||||
|
{% extends "abstracts/admin.jinja" %}
|
||||||
|
{% block title %}Maloja - API Keys{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
{% block maincontent %}
|
||||||
|
{{ apikeys.html() }}
|
||||||
|
{% endblock %}
|
Loading…
x
Reference in New Issue
Block a user