Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
website
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Video AG Infrastruktur
website
Commits
e540dec9
Commit
e540dec9
authored
8 years ago
by
Julian Rother
Browse files
Options
Downloads
Patches
Plain Diff
Implemented configurable authentification
parent
22e98a56
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
db_schema.sql
+9
-0
9 additions, 0 deletions
db_schema.sql
server.py
+34
-15
34 additions, 15 deletions
server.py
with
43 additions
and
15 deletions
db_schema.sql
+
9
−
0
View file @
e540dec9
...
...
@@ -93,6 +93,15 @@ CREATE TABLE IF NOT EXISTS `places` (
`campus_room`
varchar
(
20
)
NOT
NULL
,
`campus_name`
varchar
(
30
)
NOT
NULL
);
CREATE
TABLE
IF
NOT
EXISTS
`auth`
(
`auth_id`
INTEGER
NOT
NULL
PRIMARY
KEY
AUTOINCREMENT
,
`course_id`
INTEGER
,
`lecture_id`
INTEGER
,
`video_id`
INTEGER
,
`type`
varchar
(
10
),
`auth_user`
varchar
(
127
),
`auth_passwd`
varchar
(
127
)
);
CREATE
TABLE
IF
NOT
EXISTS
`site_texts`
(
`key`
varchar
(
64
)
NOT
NULL
PRIMARY
KEY
,
`value`
text
NOT
NULL
,
...
...
This diff is collapsed.
Click to expand it.
server.py
+
34
−
15
View file @
e540dec9
#!/bin/python
from
flask
import
Flask
,
g
,
request
,
url_for
,
redirect
,
session
,
render_template
,
flash
from
flask
import
Flask
,
g
,
request
,
url_for
,
redirect
,
session
,
render_template
,
flash
,
Response
from
werkzeug.routing
import
Rule
from
functools
import
wraps
from
datetime
import
date
,
timedelta
,
datetime
,
time
...
...
@@ -213,22 +212,42 @@ def auth(): # For use with nginx auth_request
return
'
Internal Server Error
'
,
500
url
=
request
.
headers
[
'
X-Original-Uri
'
].
lstrip
(
config
[
'
VIDEOPREFIX
'
])
ip
=
request
.
headers
.
get
(
'
X-Real-IP
'
,
''
)
videos
=
query
(
'''
SELECT videos.path, videos.id
if
url
.
endswith
(
'
jpg
'
):
return
"
OK
"
,
200
videos
=
query
(
'''
SELECT videos.path, videos.id, lectures.id AS lecture_id, courses.id AS course_id, protected.*
FROM videos
JOIN lectures ON (videos.lecture_id = lectures.id)
JOIN courses ON (lectures.course_id = courses.id)
LEFT JOIN protected ON (videos.id = protected.video_id OR lectures.id = protected.lecture_id OR courses.id = protected.course_id)
WHERE videos.path = ?
AND (? OR (courses.visible AND lectures.visible AND videos.visible))
'''
,
AND (? OR (courses.visible AND lectures.visible AND videos.visible))
ORDER BY protected.video_id DESC, protected.lecture_id DESC, protected.course_id DESC
'''
,
url
,
ismod
())
if
videos
and
(
url
.
startswith
(
'
pub
'
)
or
ismod
()):
if
not
videos
:
return
"
Not allowed
"
,
403
first
=
videos
[
0
]
allowed
=
False
types
=
[]
auth
=
request
.
authorization
for
video
in
videos
:
if
first
and
((
first
[
'
video_id
'
]
and
not
video
[
'
video_id
'
])
\
or
(
first
[
'
lecture_id
'
]
and
not
video
[
'
lecture_id
'
])):
break
types
.
append
(
video
[
'
auth_type
'
])
if
video
[
'
auth_type
'
]
==
'
public
'
:
allowed
=
True
break
elif
video
[
'
auth_type
'
]
==
'
password
'
:
if
auth
and
video
[
'
auth_user
'
]
==
auth
.
username
and
video
[
'
auth_passwd
'
]
==
auth
.
password
:
allowed
=
True
break
if
allowed
or
ismod
():
return
'
OK
'
,
200
query
(
'
INSERT INTO log VALUES (?,
""
, ?,
"
video
"
, ?, ?)
'
,
ip
,
datetime
.
now
(),
videos
[
0
][
'
id
'
],
url
)
return
"
OK
"
,
200
elif
url
.
endswith
(
'
jpg
'
):
return
"
OK
"
,
200
else
:
elif
'
password
'
in
types
:
return
Response
(
"
Login required
"
,
401
,
{
'
WWW-Authenticate
'
:
'
Basic realm=
"
Login Required
"'
})
return
"
Not allowed
"
,
403
@app.route
(
'
/schedule
'
)
@register_navbar
(
'
Drehplan
'
,
'
calendar
'
)
@mod_required
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment