Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authentication for custom MusicBrainz servers #2124

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions data/interfaces/default/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -1416,6 +1416,17 @@ <h3>MPC</h3>
<div class="row">
<label>Port</label><input type="text" name="customport" value="${config['customport']}" size="8">
</div>
<div class="row checkbox">
<input type="checkbox" name="customauth" id="customauth" value="1" ${config['customauth']} /><label>Requires Authentication</label>
</div>
<div id="customauth_options">
<div class="row">
<label>Username</label><input type="text" class="customuser" name="customuser" value="${config['customuser']}" size="20">
</div>
<div class="row">
<label>Password</label><input type="password" class="custompass" name="custompass" value="${config['custompass']}" size="15"><br>
</div>
</div>
<div class="row">
<label>Sleep Interval</label><input type="text" name="customsleep" value="${config['customsleep']}" size="4">
</div>
Expand Down Expand Up @@ -1526,6 +1537,25 @@ <h3>MPC</h3>
$('#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();
Expand Down Expand Up @@ -2074,6 +2104,7 @@ <h3>MPC</h3>
initConfigCheckbox("#use_whatcd");
initConfigCheckbox("#api_enabled");
initConfigCheckbox("#enable_https");
initConfigCheckbox("#customauth");


$('#twitterStep1').click(function () {
Expand Down
3 changes: 3 additions & 0 deletions headphones/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ def bool_int(value):
'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),
Expand Down
12 changes: 9 additions & 3 deletions headphones/mb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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:
musicbrainzngs.disable_hpauth();

logger.debug('Using the following server values: MBHost: %s, MBPort: %i, Sleep Interval: %i', mbhost, mbport, sleepytime)

return True
Expand Down
5 changes: 4 additions & 1 deletion headphones/webserve.py
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,9 @@ def config(self):
"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),
Expand Down Expand Up @@ -1196,7 +1199,7 @@ def configUpdate(self, **kwargs):
"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"
"mpc_enabled", "customauth"
]
for checked_config in checked_configs:
if checked_config not in kwargs:
Expand Down
12 changes: 10 additions & 2 deletions lib/musicbrainzngs/musicbrainz.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ def _decorator(func):
hostname = "musicbrainz.org"
_client = ""
_useragent = ""
mb_auth = False

def auth(u, p):
"""Set the username and password to be used in subsequent queries to
Expand All @@ -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.
Expand Down Expand Up @@ -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)

Expand Down