From e4a53babc57f9093e5f05fe8c5c756e52f5d39da Mon Sep 17 00:00:00 2001 From: rembo10 Date: Mon, 26 Mar 2012 14:57:49 +0100 Subject: [PATCH] Fixed headphones.API variable, added api key generator, added config option --- Headphones.py | 2 +- data/interfaces/default/config.html | 55 +++++++++++++++++++++++++---- headphones/webserve.py | 10 ++++++ headphones/webstart.py | 6 ++-- 4 files changed, 62 insertions(+), 11 deletions(-) diff --git a/Headphones.py b/Headphones.py index 59c234f5..0b7aca50 100644 --- a/Headphones.py +++ b/Headphones.py @@ -109,7 +109,7 @@ def main(): 'http_root': headphones.HTTP_ROOT, 'http_username': headphones.HTTP_USERNAME, 'http_password': headphones.HTTP_PASSWORD, - 'api': headphones.API, + 'api': headphones.API_ENABLED, }) logger.info('Starting Headphones on port: %i' % http_port) diff --git a/data/interfaces/default/config.html b/data/interfaces/default/config.html index d57ca0ed..3829dd66 100644 --- a/data/interfaces/default/config.html +++ b/data/interfaces/default/config.html @@ -48,23 +48,33 @@

Launch Browser on Startup:

+ + -

Download Scan Interval (mins):

- +

Enable API:

+
+
+

API key:



+
-

NZB Search Interval (mins):

- + - + + + +

Download Folder Scan Interval (mins):

+ + + +

Library Scan Interval (mins):

- + - @@ -516,6 +526,37 @@ $(document).ready(function() { + if ($("#api_enabled").is(":checked")) + { + $("#apioptions").show(); + } + else + { + $("#apioptions").hide(); + } + + $("#api_enabled").click(function(){ + if ($("#api_enabled").is(":checked")) + { + $("#apioptions").show("fast"); + } + else + { + $("#apioptions").hide("fast"); + } + }); + + $('#api_key').click(function(){ $('#api_key').select() }); + $("#generate_api").click(function(){ + $.get('generateAPI', + function(data){ + if (data.error != undefined) { + alert(data.error); + return; + } + $('#api_key').val(data); + }); + }); if ($("#encode").is(":checked")) { $("#encoderoptions").show(); diff --git a/headphones/webserve.py b/headphones/webserve.py index e2e525d9..d611a7d2 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -313,6 +313,16 @@ class WebInterface(object): raise cherrypy.HTTPRedirect("history") clearhistory.exposed = True + def generateAPI(self): + + import hashlib, random + + apikey = hashlib.sha224( str(random.getrandbits(256)) ).hexdigest()[0:32] + logger.info("New API generated") + return apikey + + generateAPI.exposed = True + def config(self): interface_dir = os.path.join(headphones.PROG_DIR, 'data/interfaces/') diff --git a/headphones/webstart.py b/headphones/webstart.py index d9810c1e..598bf059 100644 --- a/headphones/webstart.py +++ b/headphones/webstart.py @@ -43,9 +43,9 @@ def initialize(options={}): 'tools.staticfile.filename': "images/favicon.ico" } } - - if options['api']: - conf['/api'] = {'tools.staticdir.on': True, 'tools.staticdir.dir': "api"} + + if options['api']: + conf['/api'] = {'tools.staticdir.on': True, 'tools.staticdir.dir': "api"} if options['http_password'] != "": conf['/'].update({