def instructions(keys): authenticated = False if "Cookie" in request.headers: cookies = request.headers["Cookie"].split(";") for c in cookies: if c.strip().startswith("apikey="): authenticated = checkAPIkey(c.strip()[7:]) if "token" in keys and authenticated: token = keys.get("token") parameters = { "method": "auth.getSession", "token": token, "api_key": get_settings("LASTFM_API_KEY") } response = urllib.request.urlopen( "http://ws.audioscrobbler.com/2.0/?" + lfmbuild(parameters)) xml = response.read() data = ET.fromstring(xml) if data.attrib.get("status") == "ok": username = data.find("session").find("name").text sessionkey = data.find("session").find("key").text update_settings("settings/settings.ini", { "LASTFM_API_SK": sessionkey, "LASTFM_USERNAME": username }, create_new=True) return "/proxy" else: key, secret, sessionkey, name = get_settings("LASTFM_API_KEY", "LASTFM_API_SECRET", "LASTFM_API_SK", "LASTFM_USERNAME") if key is None: lastfm = "<td>No Last.fm key provided</td>" elif secret is None: lastfm = "<td>No Last.fm secret provided</td>" elif sessionkey is None and authenticated: url = "http://www.last.fm/api/auth/?api_key=" + key + "&cb=" lastfm = "<td class='button'><a id='lastfmlink' href='" + url + "'><div>Connect</div></a></td>" elif sessionkey is None: lastfm = "<td>Not active</td>" else: lastfm = "<td>Account: " + name + "</td>" return {"KEY_STATUS_LASTFM": lastfm}, []
def setpw(password): pw = str.encode(password).hex() pw1 = combine(hex(GENERATOR),pw) pub = combine(pw1,COMMON) update_settings("settings.ini",{"PUBLIC_KEY":pub})
def setup(): copy_initial_local_files() SKIP = settings.get_settings("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.") for k in apikeys: key = settings.get_settings(k) if key is None: print("\t" + "Currently not using a " + apikeys[k] + " for image display.") elif key == "ASK": print("\t" + "Please enter your " + apikeys[k] + ". If you do not want to use one at this moment, simply leave this empty and press Enter.") key = prompt("",types=(str,),default=None,skip=SKIP) settings.update_settings(data_dir['settings']("settings.ini"),{k:key},create_new=True) else: print("\t" + apikeys[k] + " found.") # OWN API KEY if os.path.exists(data_dir['clients']("authenticated_machines.tsv")): pass else: 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: key = randomstring(64) 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") else: pass # PASSWORD defaultpassword = settings.get_settings("DEFAULT_PASSWORD") forcepassword = settings.get_settings("FORCE_PASSWORD") # this is mainly meant for docker, supply password via environment variable if forcepassword is not None: # user has specified to force the pw, nothing else matters auth.defaultuser.setpw(forcepassword) print("Password has been set.") elif auth.defaultuser.checkpw("admin"): # if the actual pw is admin, it means we've never set this up properly (eg first start after update) if defaultpassword is None: # non-docker installation or user didn't set environment variable defaultpassword = randomstring(32) newpw = prompt("Please set a password for web backend access. Leave this empty to generate a random password.",skip=SKIP,secret=True) if newpw is None: newpw = defaultpassword print("Generated password:"******"Please set a password for web backend access. Leave this empty to use the default password.",skip=SKIP,default=defaultpassword,secret=True) auth.defaultuser.setpw(newpw) if settings.get_settings("NAME") is None: name = prompt("Please enter your name. This will be displayed e.g. when comparing your charts to another user. Leave this empty if you would not like to specify a name right now.",default="Generic Maloja User",skip=SKIP) settings.update_settings(data_dir['settings']("settings.ini"),{"NAME":name},create_new=True) if settings.get_settings("SEND_STATS") is None: answer = ask("I would like to know how many people use Maloja. Would it be okay to send a daily ping to my server (this contains no data that isn't accessible via your web interface already)?",default=True,skip=SKIP) if answer: settings.update_settings(data_dir['settings']("settings.ini"),{"SEND_STATS":True,"PUBLIC_URL":None},create_new=True) else: settings.update_settings(data_dir['settings']("settings.ini"),{"SEND_STATS":False},create_new=True)
def setup(): copy_initial_local_files() from doreah import settings # EXTERNAL API KEYS apikeys = { "LASTFM_API_KEY": "Last.fm API Key", "FANARTTV_API_KEY": "Fanart.tv API Key", "SPOTIFY_API_ID": "Spotify Client ID", "SPOTIFY_API_SECRET": "Spotify Client Secret" } 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: key = settings.get_settings(k) if key is None: print("\t" + "Currently not using a " + apikeys[k] + " for image display.") elif key == "ASK": print( "\t" + "Please enter your " + apikeys[k] + ". If you do not want to use one at this moment, simply leave this empty and press Enter." ) key = input() if key == "": key = None settings.update_settings(datadir("settings/settings.ini"), {k: key}, create_new=True) else: print("\t" + apikeys[k] + " found.") # OWN API KEY if os.path.exists(datadir("clients/authenticated_machines.tsv")): pass else: print( "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. [Y/n]" ) answer = input() if answer.lower() in ["y", "yes", "yea", "1", "positive", "true", ""]: import random key = "" for i in range(64): key += str( random.choice( list(range(10)) + list("abcdefghijklmnopqrstuvwxyz") + list("ABCDEFGHIJKLMNOPQRSTUVWXYZ"))) print("Your API Key: " + col["yellow"](key)) with open(datadir("clients/authenticated_machines.tsv"), "w") as keyfile: keyfile.write(key + "\t" + "Default Generated Key") elif answer.lower() in ["n", "no", "nay", "0", "negative", "false"]: pass if settings.get_settings("NAME") is None: print( "Please enter your name. This will be displayed e.g. when comparing your charts to another user. Leave this empty if you would not like to specify a name right now." ) name = input() if name == "": name = "Generic Maloja User" settings.update_settings(datadir("settings/settings.ini"), {"NAME": name}, create_new=True) if settings.get_settings("SEND_STATS") is None: print( "I would like to know how many people use Maloja. Would it be okay to send a daily ping to my server (this contains no data that isn't accessible via your web interface already)? [Y/n]" ) answer = input() if answer.lower() in ["y", "yes", "yea", "1", "positive", "true", ""]: settings.update_settings(datadir("settings/settings.ini"), { "SEND_STATS": True, "PUBLIC_URL": None }, create_new=True) else: settings.update_settings(datadir("settings/settings.ini"), {"SEND_STATS": False}, create_new=True)
def setup(): copy_initial_local_files() SKIP = settings.get_settings("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." ) for k in apikeys: key = settings.get_settings(k) if key is None: print("\t" + "Currently not using a " + apikeys[k] + " for image display.") elif key == "ASK": print( "\t" + "Please enter your " + apikeys[k] + ". If you do not want to use one at this moment, simply leave this empty and press Enter." ) key = prompt("", types=(str, ), default=None, skip=SKIP) settings.update_settings(datadir("settings/settings.ini"), {k: key}, create_new=True) else: print("\t" + apikeys[k] + " found.") # OWN API KEY if os.path.exists(datadir("clients/authenticated_machines.tsv")): pass else: 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: import random key = "" for i in range(64): key += str( random.choice( list(range(10)) + list("abcdefghijklmnopqrstuvwxyz") + list("ABCDEFGHIJKLMNOPQRSTUVWXYZ"))) print("Your API Key: " + col["yellow"](key)) with open(datadir("clients/authenticated_machines.tsv"), "w") as keyfile: keyfile.write(key + "\t" + "Default Generated Key") else: pass if settings.get_settings("NAME") is None: name = prompt( "Please enter your name. This will be displayed e.g. when comparing your charts to another user. Leave this empty if you would not like to specify a name right now.", default="Generic Maloja User", skip=SKIP) settings.update_settings(datadir("settings/settings.ini"), {"NAME": name}, create_new=True) if settings.get_settings("SEND_STATS") is None: answer = ask( "I would like to know how many people use Maloja. Would it be okay to send a daily ping to my server (this contains no data that isn't accessible via your web interface already)?", default=True, skip=SKIP) if answer: settings.update_settings(datadir("settings/settings.ini"), { "SEND_STATS": True, "PUBLIC_URL": None }, create_new=True) else: settings.update_settings(datadir("settings/settings.ini"), {"SEND_STATS": False}, create_new=True)