diff --git a/app/main.py b/app/main.py
index c8a3a30cdcb9f2ce89e48b43e26a29b75d49b7a1..9f9aa5b30982b36d23c8a3ba0d4fbeae09c0789c 100644
--- a/app/main.py
+++ b/app/main.py
@@ -26,7 +26,7 @@ domain_to_index = {}
try:
DOMAIN = environ["domains"].split(";") #Get the domains from the enviorement variable. If no enviorement variable is set it will be set to 127.0.0.1:5000 and localhost:5000 (for testing)
-except:
+except KeyError:
DOMAIN = ["localhost:5000", "127.0.0.1:5000"]
try:
@@ -34,7 +34,7 @@ try:
BUILDDATE = open("builddate.txt", "r").read()
else:
BUILDDATE = ""
-except:
+except KeyError:
BUILDDATE = "" #If the enviorement Variable is not set also skip the builddate
try:
@@ -45,7 +45,7 @@ try:
else:
SKIP_CAPTCHA = True
-except:
+except KeyError:
RECAPTCHA_PRIVATE_KEY = ""
RECAPTCHA_PUBLIC_KEY = ""
SKIP_CAPTCHA = True
@@ -55,17 +55,17 @@ try:
PRODUCTION = True
else:
PRODUCTION = False
-except:
+except KeyError:
PRODUCTION = False
try: #If you use https with a proxy afterwards you can set this to https and internal redirects will be https not http. This is to prevent bugs with modern browsers, bacause they block http content if the main page is loaded via https.
URL_SCHEME = environ["url_scheme"]
-except:
+except KeyError:
URL_SCHEME = "http"
try:
HOST=environ["host"]
-except:
+except KeyError:
HOST="127.0.0.1"
@@ -78,7 +78,7 @@ try:
LOGIN_TYPE = environ["login"]
else:
LOGIN_ENABLED = False
-except:
+except KeyError:
pass
try:
@@ -88,7 +88,7 @@ try:
else:
passwordProtected = False
password = ""
-except:
+except KeyError:
passwordProtected = False
password = ""
@@ -104,7 +104,7 @@ if(LOGIN_ENABLED):
if(LOGIN_TYPE == "github"):
GITHUB_CLIENT_ID = environ['GITHUB_CLIENT_ID']
GITHUB_CLIENT_SECRET = environ['GITHUB_CLIENT_SECRET']
- except:
+ except KeyError:
print("please set the oauth keys and run again.")
exit()
@@ -113,18 +113,18 @@ try: #check, if admin wants to show a cookie notice to the user.
cookieNotice = True
else:
cookieNotice = False
-except:
+except KeyError:
cookieNotice = True
try: #The secret key is used to crypt the auth cookie. There will be a seccond key to make the api key.
- secret_key = open("db/secretKey.txt", "r").read()
-except:
+ secret_key = open("db/secretKey.txt", "r", encoding="utf-8").read()
+except FileNotFoundError:
secret_key = ''.join(choice(ascii_lowercase) for i in range(100)) #If we can't find the secret key(first run) we generate it in this step and write it to a file
print("generated secret Key. Key is: " + secret_key)
- f = open("db/secretKey.txt", "w")
+ f = open("db/secretKey.txt", "w", encoding="utf-8")
f.write(secret_key)
f.close()
- secret_key = open("db/secretKey.txt", "r").read()
+ secret_key = open("db/secretKey.txt", "r", encoding="utf-8").read()
s = URLSafeSerializer(secret_key)
sAPI = URLSafeSerializer("api_key_" + secret_key)
@@ -267,6 +267,7 @@ def startup(production):
table_check()# This code checks whether database table is created or not
if production: #Check if production variable is set to true use the waitress webserver, else use the buildin flask webserver, with more debug output
+ print("Starting server in production port.\nPreparing to listen on http://" + HOST + ":5000/")
serve(app, host=HOST, port= 5000, url_scheme=URL_SCHEME) #Start the production Webserver for all users on port 5000
else:
app.run(host=HOST, port=5000, debug=True) #Start the Webserver in Debug mode. This means, if the script runs in an error, it will show the error message in Browser.