Commit 4eabd056 authored by Valentin Samir's avatar Valentin Samir

[tv] Récupération des crédentials pour la radio juste avant de la jouer

parent af8bbc41
......@@ -6,5 +6,6 @@ urlpatterns = patterns('',
url('^$', views.tv, name="index"),
url('^auth$', views.icecast_auth, name="icecast_auth"),
url('^radio/(?P<radio>.+).m3u$', views.radio_playlist, name="radio_playlist"),
url('^radio/password/(?P<radio>.+)$', views.get_radio_password, name="get_radio_password"),
url('^(?P<tv>.+).m3u$', views.tv_playlist, name="tv_playlist"),
)
......@@ -93,7 +93,7 @@ def tv(request):
user_auth = request.user.is_authenticated()
for (name, params) in tv_config.multicast['Radio'].items():
if user_auth:
userpass = "%s:%s@" % (request.user.username, radio_password(request.user, params[0]))
userpass = "%s@" % (request.user.username,)
else:
userpass = ""
radio.append(
......@@ -132,6 +132,14 @@ def radio_password(user, radio=""):
hash = hashlib.md5("%s~%s~%s~%s" % (user.username, datetime.datetime.now().date(), settings.SECRET_KEY, radio))
return hash.hexdigest()
def get_radio_password(request, radio=""):
if not request.user.is_authenticated():
return HttpResponseForbidden()
elif radio in tv_config.multicast_tag["Radio"]:
return HttpResponse(radio_password(request.user, radio))
else:
return HttpResponseNotFound("Not Found")
@csrf_exempt
def icecast_auth(request):
actions = ["mount_add", "mount_remove", "listener_add", "listener_remove"]
......
......@@ -74,6 +74,41 @@ function unwarn_vlc_plugin(){
document.getElementById("warning_vlc_plugin").remove();
}
}
function get_radio_password(radio) {
password = "";
jQuery.ajax({
url: '/tv/radio/password/'
+ radio.replace(/\//g, ""),
success: function(result) {
if(result.isOk == false)
alert(result.message);
password = result;
},
statusCode: {
// radio qui n'existe pas
404: function() {
alert( "radio not found" );
},
// 403 sir l'utilisateur n'est pas connecté
// on rafraîchissant la page, on va le rediriger vers la page de login
403: function(data) {
location.reload();
},
},
async: false
});
return password;
}
function radio_url(url){
var a = $('<a>', { href:url } )[0];
if(a.username){
url = a.protocol + "//" + a.username + ":" + get_radio_password(a.pathname) + "@" + a.hostname + a.pathname;
}
return url;
}
function play_radio(url){
document.getElementById('player_div').style.visibility="hidden";
if(url==playing){
......@@ -86,7 +121,7 @@ function play_radio(url){
return true;
}
var vlc = document.getElementById("vlc");
add(url, vlc);
add(radio_url(url), vlc);
volume(document.getElementById("volume_slide").value);
volume(document.getElementById("volume_slide").value);
return false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment