Skip to content

Commit cf975e7

Browse files
committed
docker-compose fixes and redirection bug fixed
1 parent 00b5522 commit cf975e7

File tree

7 files changed

+28
-172
lines changed

7 files changed

+28
-172
lines changed

docker-compose.yml

+13-15
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ services:
55
build: .
66
container_name: rtb_gunicorn
77
restart: unless-stopped
8-
ports:
9-
- "80:8000"
108
expose:
11-
- 8000
9+
- "8000"
1210
environment:
1311
- DEBUG=False
1412
- SECRET_KEY=changeme
@@ -41,15 +39,15 @@ services:
4139
- "6379"
4240

4341

44-
# nginx:
45-
# image: library/nginx:1.16.1-alpine
46-
# container_name: rtb_nginx
47-
# restart: unless-stopped
48-
# hostname: nginx
49-
# volumes:
50-
# - ./rtb_nginx_http:/etc/nginx/conf.d/default.conf
51-
# ports:
52-
# - "80:80"
53-
# - "443:443"
54-
# depends_on:
55-
# - rtbctf
42+
nginx:
43+
image: library/nginx:1.16.1-alpine
44+
container_name: rtb_nginx
45+
restart: unless-stopped
46+
hostname: nginx
47+
volumes:
48+
- ./rtb_nginx_http:/etc/nginx/conf.d/default.conf
49+
ports:
50+
- "80:80"
51+
- "443:443"
52+
depends_on:
53+
- rtbctf

rtb_nginx_http

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# the upstream component nginx needs to connect to
22
upstream flask {
3-
server rtbctf:8000 fail_timeout=30s;
3+
server rtbctf:8000 fail_timeout=60s;
44
}
55

66

@@ -10,7 +10,10 @@ server {
1010
server_name rtbctf.com;
1111

1212
location / {
13-
proxy_pass http://localhost:8000/
13+
proxy_pass http://flask;
14+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
15+
proxy_set_header Host $host;
16+
proxy_redirect off;
1417
}
1518

1619
}

src/FlaskRTBCTF/helpers.py

-20
This file was deleted.

src/FlaskRTBCTF/main/routes.py

+1-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from flask import render_template, Blueprint, redirect, url_for, request, flash
1+
from flask import render_template, Blueprint, redirect, url_for, request
22

33
from .models import Notification, Settings, Website
44
from .forms import SettingsForm, WebsiteForm
@@ -7,20 +7,6 @@
77
main = Blueprint("main", __name__)
88

99

10-
""" Before app request processor """
11-
12-
13-
@main.before_app_request
14-
def needs_setup():
15-
settings = Settings.get_settings()
16-
if settings.dummy:
17-
if request.endpoint not in ("main.setup", "users.login", "static"):
18-
flash("Please setup the CTF, before accessing any routes.", "info")
19-
return redirect(url_for("main.setup"))
20-
else:
21-
return
22-
23-
2410
""" Index page """
2511

2612

src/FlaskRTBCTF/models.py

-115
This file was deleted.

src/FlaskRTBCTF/utils/helpers.py

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import secrets
55
from datetime import datetime
66

7+
from flask import flash
8+
79
from .cache import cache
810
from ..main.models import Settings, Website
911

@@ -32,6 +34,8 @@ def handle_admin_email(default="[email protected]"):
3234
def inject_app_context():
3335
settings = Settings.get_settings()
3436
websites = Website.get_websites()
37+
if settings.dummy:
38+
flash("Please setup the CTF by going to /setup.", "info")
3539

3640
return dict(settings=settings, websites=websites)
3741

src/FlaskRTBCTF/utils/login_manager.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ def admin_only(f):
1717

1818
@wraps(f)
1919
def decorated_function(*args, **kwargs):
20-
if current_user.is_authenticated and current_user.isAdmin:
21-
return f(*args, **kwargs)
22-
else:
23-
flash("You are not authorized to perform this operation.", "danger")
24-
return redirect("/")
20+
if current_user:
21+
if current_user.is_authenticated and current_user.isAdmin:
22+
return f(*args, **kwargs)
23+
flash("You are not authorized to perform this operation.", "danger")
24+
return redirect("/login")
2525

2626
return decorated_function

0 commit comments

Comments
 (0)