diff --git a/data/interfaces/default/config.html b/data/interfaces/default/config.html index 28c5dd4c..9cea2d58 100644 --- a/data/interfaces/default/config.html +++ b/data/interfaces/default/config.html @@ -1449,6 +1449,17 @@
+
+ +
+
+
+ +
+
+
+
+
@@ -1559,6 +1570,25 @@ $('#api_key').val(data); }); }); + if ($("#customauth").is(":checked")) + { + $("#customauth_options").show(); + } + else + { + $("#customauth_options").hide(); + } + + $("#customauth").click(function(){ + if ($("#customauth").is(":checked")) + { + $("#customauth_options").slideDown(); + } + else + { + $("#customauth_options").slideUp(); + } + }); if ($("#enable_https").is(":checked")) { $("#https_options").show(); @@ -2127,6 +2157,7 @@ initConfigCheckbox("#use_whatcd"); initConfigCheckbox("#api_enabled"); initConfigCheckbox("#enable_https"); + initConfigCheckbox("#customauth"); $('#twitterStep1').click(function () { diff --git a/headphones/config.py b/headphones/config.py index 741ba9cd..5306aa4e 100644 --- a/headphones/config.py +++ b/headphones/config.py @@ -44,9 +44,12 @@ _CONFIG_DEFINITIONS = { 'CUE_SPLIT': (int, 'General', 1), 'CUE_SPLIT_FLAC_PATH': (str, 'General', ''), 'CUE_SPLIT_SHNTOOL_PATH': (str, 'General', ''), + 'CUSTOMAUTH': (int, 'General', 0), 'CUSTOMHOST': (str, 'General', 'localhost'), + 'CUSTOMPASS': (str, 'General', ''), 'CUSTOMPORT': (int, 'General', 5000), 'CUSTOMSLEEP': (int, 'General', 1), + 'CUSTOMUSER': (str, 'General', ''), 'DELETE_LOSSLESS_FILES': (int, 'General', 1), 'DESTINATION_DIR': (str, 'General', ''), 'DETECT_BITRATE': (int, 'General', 0), diff --git a/headphones/mb.py b/headphones/mb.py index 6caf0090..3a150977 100644 --- a/headphones/mb.py +++ b/headphones/mb.py @@ -47,6 +47,8 @@ def startmb(): elif headphones.CONFIG.MIRROR == "custom": mbhost = headphones.CONFIG.CUSTOMHOST mbport = int(headphones.CONFIG.CUSTOMPORT) + mbuser = headphones.CONFIG.CUSTOMUSER + mbpass = headphones.CONFIG.CUSTOMPASS sleepytime = int(headphones.CONFIG.CUSTOMSLEEP) elif headphones.CONFIG.MIRROR == "headphones": mbhost = "144.76.94.239" @@ -69,12 +71,16 @@ def startmb(): mb_lock.minimum_delta = sleepytime # Add headphones credentials - if headphones.CONFIG.MIRROR == "headphones": - if not mbuser and mbpass: - logger.warn("No username or password set for VIP server") + if headphones.CONFIG.MIRROR == "headphones" or headphones.CONFIG.CUSTOMAUTH: + if not mbuser or not mbpass: + logger.warn("No username or password set for MusicBrainz server") else: musicbrainzngs.hpauth(mbuser, mbpass) + # Let us know if we disable custom authentication + if not headphones.CONFIG.CUSTOMAUTH and headphones.CONFIG.MIRROR == "custom": + musicbrainzngs.disable_hpauth() + logger.debug('Using the following server values: MBHost: %s, MBPort: %i, Sleep Interval: %i', mbhost, mbport, sleepytime) return True diff --git a/headphones/webserve.py b/headphones/webserve.py index 04740593..ed1556ee 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -1142,6 +1142,9 @@ class WebInterface(object): "customhost": headphones.CONFIG.CUSTOMHOST, "customport": headphones.CONFIG.CUSTOMPORT, "customsleep": headphones.CONFIG.CUSTOMSLEEP, + "customauth": checked(headphones.CONFIG.CUSTOMAUTH), + "customuser": headphones.CONFIG.CUSTOMUSER, + "custompass": headphones.CONFIG.CUSTOMPASS, "hpuser": headphones.CONFIG.HPUSER, "hppass": headphones.CONFIG.HPPASS, "songkick_enabled": checked(headphones.CONFIG.SONGKICK_ENABLED), @@ -1205,7 +1208,7 @@ class WebInterface(object): "nma_enabled", "nma_onsnatch", "pushalot_enabled", "pushalot_onsnatch", "synoindex_enabled", "pushover_enabled", "pushover_onsnatch", "pushbullet_enabled", "pushbullet_onsnatch", "subsonic_enabled", "twitter_enabled", "twitter_onsnatch", "osx_notify_enabled", "osx_notify_onsnatch", "boxcar_enabled", "boxcar_onsnatch", "songkick_enabled", "songkick_filter_enabled", - "mpc_enabled", "email_enabled", "email_tls", "email_onsnatch" + "mpc_enabled", "email_enabled", "email_tls", "email_onsnatch", "customauth" ] for checked_config in checked_configs: if checked_config not in kwargs: diff --git a/lib/musicbrainzngs/musicbrainz.py b/lib/musicbrainzngs/musicbrainz.py index 875eff6f..d7e5e74f 100644 --- a/lib/musicbrainzngs/musicbrainz.py +++ b/lib/musicbrainzngs/musicbrainz.py @@ -271,6 +271,7 @@ user = password = "" hostname = "musicbrainz.org" _client = "" _useragent = "" +mb_auth = False def auth(u, p): """Set the username and password to be used in subsequent queries to @@ -284,9 +285,16 @@ def hpauth(u, p): """Set the username and password to be used in subsequent queries to the MusicBrainz XML API that require authentication. """ - global hpuser, hppassword + global hpuser, hppassword, mb_auth hpuser = u hppassword = p + mb_auth = True + +def disable_hpauth(): + """Disable the authentication for MusicBrainz XML API + """ + global mb_auth + mb_auth = False def set_useragent(app, version, contact=None): """Set the User-Agent to be used for requests to the MusicBrainz webservice. @@ -635,7 +643,7 @@ def _mb_request(path, method='GET', auth_required=False, client_required=False, req.add_header('User-Agent', _useragent) # Add headphones credentials - if hostname == '144.76.94.239:8181': + if mb_auth: base64string = base64.encodestring('%s:%s' % (hpuser, hppassword)).replace('\n', '') req.add_header("Authorization", "Basic %s" % base64string)