Skip to content

Commit

Permalink
Update code to enable skipping security checks if credentials are pro…
Browse files Browse the repository at this point in the history
…vided
  • Loading branch information
mario872 committed Feb 4, 2025
1 parent 9db86b1 commit d23d8f3
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

FROM python:3.11-slim-bullseye
LABEL maintainer="jamesaglynn10@gmail.com"
LABEL version="0.37"
LABEL version="0.38"
LABEL description="This is the docker image for Class Forge"

ENV IN_DOCKER=true
Expand Down
2 changes: 1 addition & 1 deletion UPDATE
Original file line number Diff line number Diff line change
@@ -1 +1 @@
UPDATE OR ELSE
UPDATED
25 changes: 24 additions & 1 deletion functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,30 @@
import json
import zlib

from main import in_docker, headless, fake_user # Risky move, but imports variables from main
headless = False
in_docker = os.environ.get('IN_DOCKER', False) # Detects if we are testing, or in a production docker container
override = False # Whether to override to test the production version
skip_login_check = os.environ.get('DISABLE_SECURITY', False) # Skip checking login for offline testing

auto_off = 600 # Whether to automatically turn off the server after a certain period of time, currently 10 minutes (600)

if in_docker or override:
auto_off = None
headless = True

if auto_off != None:
auto_off_timer = threading.Timer(auto_off, lambda: os._exit(1))
auto_off_timer.daemon = True
auto_off_timer.start()

if override:
in_docker = True

fake_user = {'username': 'your.name',
'password': 'your_password',
'state': 'nsw',
'base_url': 'caringbahhs',
'photo_path': 'static/Rick Astley.jpg'}

timers = {}

Expand Down
51 changes: 27 additions & 24 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import pytz
import zlib
from functools import wraps
from json import JSONDecodeError

from functions import *

Expand All @@ -34,35 +35,11 @@

users = [] # THIS IS THE VARIABLE FOR ALL USERS SAVED IN CODE, SO NOT AVAILABLE UPON RESTART

headless = False
in_docker = os.environ.get('IN_DOCKER', False) # Detects if we are testing, or in a production docker container
override = False # Whether to override to test the production version
skip_login_check = os.environ.get('DISABLE_SECURITY', False) # Skip checking login for offline testing

auto_off = 600 # Whether to automatically turn off the server after a certain period of time, currently 10 minutes (600)

if in_docker or override:
auto_off = None
headless = True

if auto_off != None:
auto_off_timer = threading.Timer(auto_off, lambda: os._exit(1))
auto_off_timer.daemon = True
auto_off_timer.start()

if override:
in_docker = True

timezone_hours_ahead = 10

login_manager = LoginManager()

# A template user to use, when the user is not signed in, used on login screen, tos, etc.
fake_user = {'username': 'your.name',
'password': 'your_password',
'state': 'nsw',
'base_url': 'caringbahhs',
'photo_path': 'static/Rick Astley.jpg'}

app = Flask(__name__)

Expand Down Expand Up @@ -116,10 +93,32 @@ def one():

@app.route('/login')
def login():
global skip_login_check

try:
message = request.args.get('message')
except KeyError:
message = ''

if skip_login_check:
username = os.environ.get('CF_USERNAME')
password = os.environ.get('CF_PASSWORD')
state = os.environ.get('CF_STATE')
base_url = os.environ.get('CF_BASE_URL')

if not username or not password or not state or not base_url:
print("COULD NOT GET USER DETAILS FOR OFFLINE TESTING.\nMAKE SURE TO SET THE ENVIRONMENT VARIABLES 'CF_USERNAME', 'CF_PASSWORD', 'CF_STATE', AND 'CF_BASE_URL")
skip_login_check = False
else:
user = User(username, password, state, base_url)
user_dict = user_to_dict(user)
users.append(user_dict)
login_user(user, remember=True)

with open(f'users/{zlib.adler32(user.username.encode())}.json', 'w') as f:
f.write('')

return redirect("/dashboard")

return render_template('login.jinja', user=fake_user, message=message, weather=get_weather())

Expand Down Expand Up @@ -175,6 +174,10 @@ def home():
data = load_user_data(user)
except AttributeError:
return redirect('/login')
except JSONDecodeError:
user = current_user
repeat_reload(user=user, http_request=request)
data = load_user_data(user)

three_day_timetable = []
if not datetime.now().weekday() in [0, 4, 5, 6]:
Expand Down
2 changes: 1 addition & 1 deletion templates/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.37
0.38

0 comments on commit d23d8f3

Please sign in to comment.