Skip to content

Commit 00d1aa7

Browse files
authored
Various lockdown fixes (#58)
* Add .swp files to gitignore * Display more helpful lockdown page, move more routes behind lockdown
1 parent 26662f4 commit 00d1aa7

File tree

4 files changed

+52
-11
lines changed

4 files changed

+52
-11
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,6 @@ data.db
9797

9898
# mypy
9999
.mypy_cache
100+
101+
# vim swap files
102+
*.swp

gallery/__init__.py

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@ def view_mkdir(auth_dict: Optional[Dict[str, Any]] = None):
247247
@auth.oidc_auth('default')
248248
@gallery_auth
249249
def view_jumpdir(auth_dict: Optional[Dict[str, Any]] = None):
250+
gallery_lockdown = util.get_lockdown_status()
251+
if gallery_lockdown and (not auth_dict['is_eboard'] and not auth_dict['is_rtp']):
252+
abort(405)
250253
return render_template("jumpdir.html",
251254
auth_dict=auth_dict)
252255

@@ -733,7 +736,12 @@ def tag_file(file_id: int):
733736

734737
@app.route("/api/file/get/<int:file_id>")
735738
@auth.oidc_auth('default')
736-
def display_file(file_id: int):
739+
@gallery_auth
740+
def display_file(file_id: int, auth_dict: Optional[Dict[str, Any]] = None):
741+
gallery_lockdown = util.get_lockdown_status()
742+
if gallery_lockdown and (not auth_dict['is_eboard'] and not auth_dict['is_rtp']):
743+
abort(405)
744+
737745
file_model = File.query.filter(File.id == file_id).first()
738746

739747
if file_model is None:
@@ -745,7 +753,12 @@ def display_file(file_id: int):
745753

746754
@app.route("/api/thumbnail/get/<int:file_id>")
747755
@auth.oidc_auth('default')
748-
def display_thumbnail(file_id: int):
756+
@gallery_auth
757+
def display_thumbnail(file_id: int, auth_dict: Optional[Dict[str, Any]] = None):
758+
gallery_lockdown = util.get_lockdown_status()
759+
if gallery_lockdown and (not auth_dict['is_eboard'] and not auth_dict['is_rtp']):
760+
abort(405)
761+
749762
file_model = File.query.filter(File.id == file_id).first()
750763

751764
link = storage_interface.get_link("thumbnails/{}".format(file_model.s3_id))
@@ -754,7 +767,12 @@ def display_thumbnail(file_id: int):
754767

755768
@app.route("/api/thumbnail/get/dir/<int:dir_id>")
756769
@auth.oidc_auth('default')
757-
def display_dir_thumbnail(dir_id: int):
770+
@gallery_auth
771+
def display_dir_thumbnail(dir_id: int, auth_dict: Optional[Dict[str, Any]] = None):
772+
gallery_lockdown = util.get_lockdown_status()
773+
if gallery_lockdown and (not auth_dict['is_eboard'] and not auth_dict['is_rtp']):
774+
abort(405)
775+
758776
dir_model = Directory.query.filter(Directory.id == dir_id).first()
759777

760778
thumbnail_uuid = dir_model.thumbnail_uuid
@@ -810,7 +828,11 @@ def get_supported_mimetypes():
810828

811829
@app.route("/api/get_dir_tree")
812830
@auth.oidc_auth('default')
813-
def get_dir_tree(internal: bool = False):
831+
@gallery_auth
832+
def get_dir_tree(internal: bool = False, auth_dict: Optional[Dict[str, Any]] = None):
833+
gallery_lockdown = util.get_lockdown_status()
834+
if gallery_lockdown and (not auth_dict['is_eboard'] and not auth_dict['is_rtp']):
835+
abort(405)
814836

815837
# TODO: Convert to iterative tree traversal using a queue to avoid
816838
# recursion issues with large directory structures
@@ -843,7 +865,12 @@ def get_dir_children(dir_id: int) -> Any:
843865

844866
@app.route("/api/directory/get/<int:dir_id>")
845867
@auth.oidc_auth('default')
846-
def display_files(dir_id: int, internal: bool = False):
868+
@gallery_auth
869+
def display_files(dir_id: int, internal: bool = False, auth_dict: Optional[Dict[str, Any]] = None):
870+
gallery_lockdown = util.get_lockdown_status()
871+
if gallery_lockdown and (not auth_dict['is_eboard'] and not auth_dict['is_rtp']):
872+
abort(405)
873+
847874
file_list = [("File", f) for f in File.query.filter(File.parent == dir_id).all()]
848875
dir_list = [("Directory", d) for d in Directory.query.filter(Directory.parent == dir_id).all()]
849876

@@ -995,7 +1022,12 @@ def view_filtered(auth_dict: Optional[Dict[str, Any]] = None):
9951022

9961023
@app.route("/api/memberlist")
9971024
@auth.oidc_auth('default')
998-
def get_member_list():
1025+
@gallery_auth
1026+
def get_member_list(auth_dict: Optional[Dict[str, Any]] = None):
1027+
gallery_lockdown = util.get_lockdown_status()
1028+
if gallery_lockdown and (not auth_dict['is_eboard'] and not auth_dict['is_rtp']):
1029+
abort(405)
1030+
9991031
return jsonify(ldap.get_members())
10001032

10011033

@@ -1014,7 +1046,7 @@ def route_errors(error: Any, auth_dict: Optional[Dict[str, Any]] = None):
10141046
if code == 404:
10151047
error_desc = "Page Not Found"
10161048
elif code == 405:
1017-
error_desc = "Page Not Available"
1049+
error_desc = "Gallery is currently unavailable"
10181050
else:
10191051
error_desc = type(error).__name__
10201052

Lines changed: 1 addition & 0 deletions
Loading

gallery/templates/errors.html

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@
66
{% block body %}
77
<div class="container error-page align-center">
88
<div class="col-xs-12">
9-
<img src="/static/images/material_attention.svg" alt="Attention!">
10-
<h1>Oops!</h1>
11-
<h2>Something has gone terribly wrong!</h2>
12-
<h3>{{ error }}</h3>
9+
{% if error_code == 405 %}
10+
<img src="/static/images/material_lock.svg" alt="Locked" />
11+
<h1>{{ error }}</h1>
12+
{% else %}
13+
<img src="/static/images/material_attention.svg" alt="Attention" />
14+
<h1>Oops!</h1>
15+
<h2>Something has gone terribly wrong!</h2>
16+
<h3>{{ error }}</h3>
17+
{% endif %}
1318
</div>
1419
</div>
1520
{% endblock %}

0 commit comments

Comments
 (0)