Skip to content
Snippets Groups Projects
Commit 477eea23 authored by Julian Rother's avatar Julian Rother
Browse files

Implement permission checking for livestreams

parent ef00c21e
No related branches found
No related tags found
No related merge requests found
...@@ -559,8 +559,19 @@ def auth(): # For use with nginx auth_request ...@@ -559,8 +559,19 @@ def auth(): # For use with nginx auth_request
cookie = int(request.cookies['tracking']) cookie = int(request.cookies['tracking'])
else: else:
cookie = random.getrandbits(8*8-1) cookie = random.getrandbits(8*8-1)
if url.endswith('jpg') or ismod() or url.startswith('pub/hls/'): if url.endswith('jpg') or ismod():
return "OK", 200 return "OK", 200
if url.startswith('pub/hls/'):
handle = url[len('pub/hls/'):].split('_')[0].split('.')[0]
perms = query('''SELECT perm.*
FROM streams
JOIN lectures ON (streams.lecture_id = lectures.id)
JOIN courses ON (lectures.course_id = courses.id)
LEFT JOIN perm ON ((lectures.id = perm.lecture_id OR courses.id = perm.course_id) AND NOT perm.deleted)
WHERE streams.handle = ?
AND (courses.visible AND lectures.visible AND streams.visible)
ORDER BY perm.video_id DESC, perm.lecture_id DESC, perm.course_id DESC''', handle)
else:
perms = query('''SELECT videos.path, videos.id AS vid, perm.* perms = query('''SELECT videos.path, videos.id AS vid, perm.*
FROM videos FROM videos
JOIN lectures ON (videos.lecture_id = lectures.id) JOIN lectures ON (videos.lecture_id = lectures.id)
...@@ -579,6 +590,7 @@ def auth(): # For use with nginx auth_request ...@@ -579,6 +590,7 @@ def auth(): # For use with nginx auth_request
password = auth.password password = auth.password
if checkperm(perms, username=username, password=password): if checkperm(perms, username=username, password=password):
try: try:
if not url.startswith('pub/hls/'):
modify('INSERT INTO log (id, `time`, `date`, video, source) VALUES (?, ?, ?, ?, 1)', cookie, datetime.now(), datetime.combine(date.today(), time()), perms[0]['vid']) modify('INSERT INTO log (id, `time`, `date`, video, source) VALUES (?, ?, ?, ?, 1)', cookie, datetime.now(), datetime.combine(date.today(), time()), perms[0]['vid'])
except: except:
pass pass
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment