Commit 5ddcbed0 authored by Julian Rother's avatar Julian Rother
Browse files

Parameterised video url prefix and implemented handler for nginx auth_request

parent 5a885893
...@@ -15,10 +15,12 @@ config['SQLITE_DB'] = 'db.sqlite' ...@@ -15,10 +15,12 @@ config['SQLITE_DB'] = 'db.sqlite'
config['SQLITE_INIT_SCHEMA'] = True config['SQLITE_INIT_SCHEMA'] = True
config['SQLITE_INIT_DATA'] = False config['SQLITE_INIT_DATA'] = False
config['DEBUG'] = False config['DEBUG'] = False
config['VIDEOPREFIX'] = 'https://videoag.fsmpi.rwth-aachen.de'
if __name__ == '__main__': if __name__ == '__main__':
config['SQLITE_INIT_DATA'] = True config['SQLITE_INIT_DATA'] = True
config['DEBUG'] = True config['DEBUG'] = True
config.from_pyfile('config.py', silent=True) config.from_pyfile('config.py', silent=True)
app.jinja_env.globals['videoprefix'] = config['VIDEOPREFIX']
if config['DB_ENGINE'] == 'sqlite': if config['DB_ENGINE'] == 'sqlite':
created = not os.path.exists(config['SQLITE_DB']) created = not os.path.exists(config['SQLITE_DB'])
...@@ -251,5 +253,24 @@ def edit(): ...@@ -251,5 +253,24 @@ def edit():
tabs[table][1]), val, id) tabs[table][1]), val, id)
query('COMMIT TRANSACTION') query('COMMIT TRANSACTION')
@app.route('/auth')
def auth(): # For use with nginx auth_request
if 'X-Original-Uri' not in request.headers:
return 'Internal Server Error', 500
url = request.headers['X-Original-Uri'].lstrip(config['VIDEOPREFIX'])
videos = query('''SELECT videos.path
FROM videos
JOIN lectures ON (videos.lecture_id = lectures.id)
JOIN courses ON (lectures.course_id = courses.id)
WHERE videos.path = ?
AND (? OR (courses.visible AND lectures.visible AND videos.visible))''',
url, ismod())
if videos and url.startswith('pub'):
return "OK", 200
elif videos and ismod():
return "OK", 200
else:
return "Not allowed", 403
if __name__ == '__main__': if __name__ == '__main__':
app.run() app.run(threaded=True)
...@@ -58,7 +58,7 @@ ...@@ -58,7 +58,7 @@
</li> </li>
{% endfor %} {% endfor %}
<li class="navbar-right"> <li class="navbar-right">
{% if not session.user is defined %} {% if not ismod() %}
<a id="loginpopover" data-container="body" data-toggle="popover" data-placement="bottom"> <a id="loginpopover" data-container="body" data-toggle="popover" data-placement="bottom">
<span class="glyphicon glyphicon-log-in"></span> <span class="glyphicon glyphicon-log-in"></span>
</a> </a>
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<li class="list-group-item"> <li class="list-group-item">
<a class="hidden-xs" href="/play?lectureid={{ lecture['id'] }}" title="{{ lecture['coursetitle'] }}"> <a class="hidden-xs" href="/play?lectureid={{ lecture['id'] }}" title="{{ lecture['coursetitle'] }}">
<div class="row"> <div class="row">
<img class="col-xs-4" src="https://videoag.fsmpi.rwth-aachen.de/{{ lecture['titlefile'] }}" alt="Vorschaubild"> <img class="col-xs-4" src="{{ videoprefix }}/{{ lecture['titlefile'] }}" alt="Vorschaubild">
<div class="col-xs-4"> <div class="col-xs-4">
<span style="color: #000;"><strong>{{ lecture['short'] }}</strong></span><br> <span style="color: #000;"><strong>{{ lecture['short'] }}</strong></span><br>
<span style="color: #000;">{{ lecture['time'] }}</span> <span style="color: #000;">{{ lecture['time'] }}</span>
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
</a> </a>
<a class="visible-xs" href="/play?lectureid={{ lecture['id'] }}" title="{{ lecture['coursetitle'] }}"> <a class="visible-xs" href="/play?lectureid={{ lecture['id'] }}" title="{{ lecture['coursetitle'] }}">
<div class="row"> <div class="row">
<img class="col-xs-12" src="https://videoag.fsmpi.rwth-aachen.de/{{ lecture['titlefile'] }}" alt="Vorschaubild"> <img class="col-xs-12" src="{{ videoprefix }}/{{ lecture['titlefile'] }}" alt="Vorschaubild">
</div> </div>
<div class="row"> <div class="row">
<div class="col-xs-12"> <div class="col-xs-12">
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
<link rel="stylesheet" href="static/mediaelementjs/mediaelementplayer.css" /> <link rel="stylesheet" href="static/mediaelementjs/mediaelementplayer.css" />
<video class="mejs-player" width="640" height="360" style="width: 100%; height: 100%;"> <video class="mejs-player" width="640" height="360" style="width: 100%; height: 100%;">
{% for v in videos %} {% for v in videos %}
<source type="video/mp4" src="https://videoag.fsmpi.rwth-aachen.de/{{ v.path }}" /> <source type="video/mp4" src="{{ videoprefix }}/{{ v.path }}" />
{% endfor %} {% endfor %}
</video> </video>
<script> <script>
...@@ -94,13 +94,13 @@ ...@@ -94,13 +94,13 @@
<button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">Download <span class="caret"></span></button> <button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">Download <span class="caret"></span></button>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
{% for v in videos %} {% for v in videos %}
<li><a href="https://video.fsmpi.rwth-aachen.de/{{v.path}}">{{v.format_description}} ({{v.file_size|filesizeformat(true)}})</a></li> <li><a href="{{ videoprefix }}/{{v.path}}">{{v.format_description}} ({{v.file_size|filesizeformat(true)}})</a></li>
{% endfor %} {% endfor %}
</ul> </ul>
<noscript> <noscript>
<ul class="pull-right list-unstyled" style="margin-left:10px;"> <ul class="pull-right list-unstyled" style="margin-left:10px;">
{% for v in videos %} {% for v in videos %}
<li><a href="https://video.fsmpi.rwth-aachen.de/{{v.path}}">{{v.format_description}} ({{v.file_size|filesizeformat(true)}})</a></li> <li><a href="{{ videoprefix }}/{{v.path}}">{{v.format_description}} ({{v.file_size|filesizeformat(true)}})</a></li>
{% endfor %} {% endfor %}
</ul> </ul>
</noscript> </noscript>
......
Supports Markdown
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