Commit 7e19a60f authored by Julian Rother's avatar Julian Rother
Browse files

Implemented legacy stream handler, closes #253

parent f9a8cd41
......@@ -7,3 +7,37 @@ def livestream_thumbnail():
for v in genlive(livestreams):
sorter.schedule_thumbnail(v['lecture_id'], v['path'])
@app.route('/internal/streaming/legacy_auth', methods=['GET', 'POST'])
def streamauth():
internal = False
for net in config.get('FSMPI_IP_RANGES', []):
if ip_address(request.headers['X-Real-IP']) in ip_network(net):
internal = True
if request.values['app'] != 'live':
return 'Bad request', 400
if not internal:
return 'Forbidden', 403
if request.values['pass'] != 'caisoh8aht0wuSu':
return 'Forbidden', 403
if request.values['call'] == 'publish':
matches = query("SELECT lectures.* FROM lectures JOIN courses ON lectures.course_id = courses.id WHERE courses.handle = ? ORDER BY lectures.time DESC", request.values['name'])
now = datetime.now()
match = {'id': -1}
for lecture in matches:
if lecture['time']-timedelta(minutes=30) <= now and \
now <= lecture['time']+timedelta(minutes=lecture['duration']):
match = lecture
break
if 'lecture' in request.values:
match = {'id': request.values['lecture']}
try:
modify("INSERT INTO streams (handle, active, visible, lecture_id, description, poster) VALUES (?, 0, 1, -1, "", "")", request.values['name'])
except:
pass
modify("UPDATE streams SET active = 1, lecture_id = ? WHERE handle = ?", match['id'], request.values['name'])
elif request.values['call'] == 'publish_done':
modify("UPDATE streams SET active = 0 WHERE handle = ?", request.values['name'])
else:
return 'Bad request', 400
return 'OK', 200
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