mirror of
https://github.com/rembo10/headphones.git
synced 2026-05-11 22:29:36 +01:00
Fixed headphones.API variable, added api key generator, added config option
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -48,23 +48,33 @@
|
||||
<td>
|
||||
<h3>Launch Browser on Startup: <input type="checkbox" name="launch_browser" value="1" ${config['launch_browser']} /></h3>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<h3>Download Scan Interval (mins):</h3>
|
||||
<input type="text" name="download_scan_interval" value="${config['download_scan_interval']}" size="10" maxlength="40">
|
||||
<h3>Enable API: <input type="checkbox" name="api_enabled" id="api_enabled" value="1" ${config['api_enabled']} /></h3>
|
||||
<div id="apioptions">
|
||||
<br>
|
||||
<h3>API key:<input type="text" name="api_key" id="api_key" value="${config['api_key']}" size="30"><input type="button" value="Generate" id="generate_api"></h3><br><br>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
||||
<td>
|
||||
<h3>NZB Search Interval (mins):</h3>
|
||||
<input type="text" name="nzb_search_interval" value="${config['nzb_search_interval']}" size="10" maxlength="40">
|
||||
<input type="text" name="nzb_search_interval" value="${config['nzb_search_interval']}" size="5" maxlength="40">
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<h3>Download Folder Scan Interval (mins):</h3>
|
||||
<input type="text" name="download_scan_interval" value="${config['download_scan_interval']}" size="5" maxlength="40">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<h3>Library Scan Interval (mins):</h3>
|
||||
<input type="text" name="libraryscan_interval" value="${config['libraryscan_interval']}" size="10" maxlength="40">
|
||||
<input type="text" name="libraryscan_interval" value="${config['libraryscan_interval']}" size="5" maxlength="40">
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
@@ -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();
|
||||
|
||||
@@ -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/')
|
||||
|
||||
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user