-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path__init__.py
More file actions
78 lines (55 loc) · 1.83 KB
/
__init__.py
File metadata and controls
78 lines (55 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from __future__ import annotations
import os
from flask import send_from_directory
from .admin import modules_admin_bp, register_admin_menu
from .api import modules_api_bp
from .hooks import register_plugin_runtime_hooks
from .models import db_init
from .views import modules_bp
def _register_static_route(app):
static_dir = os.path.join(os.path.dirname(__file__), "static")
try:
has_static_rule = any(
rule.rule == "/plugins/ctfd_modules/static/<path:filename>"
for rule in app.url_map.iter_rules()
)
except Exception:
has_static_rule = False
if has_static_rule:
return
@app.route("/plugins/ctfd_modules/static/<path:filename>")
def ctfd_modules_static(filename: str):
return send_from_directory(static_dir, filename)
def _register_blueprints(app):
try:
from CTFd.plugins import register_plugin_blueprint # type: ignore
register_plugin_blueprint(app, modules_bp)
register_plugin_blueprint(app, modules_api_bp)
register_plugin_blueprint(app, modules_admin_bp)
return
except Exception:
pass
app.register_blueprint(modules_bp)
app.register_blueprint(modules_api_bp)
app.register_blueprint(modules_admin_bp)
def _register_user_menu():
try:
from CTFd.plugins import register_user_page_menu_bar
register_user_page_menu_bar(title="Modules", route="/modules")
except Exception:
pass
def _apply_patches(app):
try:
from .patches import apply_patches
apply_patches(app)
except Exception:
pass
def load(app):
"""CTFd plugin entrypoint."""
_register_static_route(app)
_register_blueprints(app)
db_init(app)
register_admin_menu(app)
register_plugin_runtime_hooks(app)
_register_user_menu()
_apply_patches(app)