@@ -99,12 +99,14 @@ def index():
99
99
100
100
@app .after_request
101
101
def add_security_headers (response ):
102
- response .headers .add ('X-Content-Type-Options' , 'nosniff' )
103
- response .headers .add ('X-Frame-Options' , 'SAMEORIGIN' )
104
- response .headers .add ('X-XSS-Protection' , '1; mode=block' )
105
- response .headers .add ('Strict-Transport-Security' , 'max-age=63072000; includeSubDomains; preload' )
106
- response .headers .add ('Referrer-Policy' , 'same-origin' )
107
- response .headers .add ('Cross-Origin-Opener-Policy' , 'same-origin' )
102
+ response .headers .add ("X-Content-Type-Options" , "nosniff" )
103
+ response .headers .add ("X-Frame-Options" , "SAMEORIGIN" )
104
+ response .headers .add ("X-XSS-Protection" , "1; mode=block" )
105
+ response .headers .add (
106
+ "Strict-Transport-Security" , "max-age=63072000; includeSubDomains; preload"
107
+ )
108
+ response .headers .add ("Referrer-Policy" , "same-origin" )
109
+ response .headers .add ("Cross-Origin-Opener-Policy" , "same-origin" )
108
110
return response
109
111
110
112
@@ -150,9 +152,9 @@ def upload_file():
150
152
151
153
# Validate filenames
152
154
if (
153
- not validate_filename (config_file .filename )
154
- or not validate_filename (api_file .filename )
155
- or not validate_filename (csv_file .filename )
155
+ not validate_filename (config_file .filename )
156
+ or not validate_filename (api_file .filename )
157
+ or not validate_filename (csv_file .filename )
156
158
):
157
159
logger .error (
158
160
f"Invalid filename(s). Filename must not contain '..' and must have an allowed extension."
@@ -163,9 +165,9 @@ def upload_file():
163
165
)
164
166
165
167
if (
166
- config_file .filename != ""
167
- and api_file .filename != ""
168
- and csv_file .filename != ""
168
+ config_file .filename != ""
169
+ and api_file .filename != ""
170
+ and csv_file .filename != ""
169
171
):
170
172
171
173
# Get the file names
@@ -187,9 +189,9 @@ def upload_file():
187
189
csv_file .save (csv_filename )
188
190
189
191
if (
190
- os .path .exists ("db.config" )
191
- and os .path .exists ("API.json" )
192
- and os .path .exists ("Test.csv" )
192
+ os .path .exists ("db.config" )
193
+ and os .path .exists ("API.json" )
194
+ and os .path .exists ("Test.csv" )
193
195
):
194
196
# Return an HTML success message
195
197
message = database_thread ()
@@ -208,7 +210,11 @@ def upload_file():
208
210
logger .error (
209
211
f"Invalid message format: { message } with { len (parts )} parts."
210
212
)
211
- return "The message does not match the expected format." , 400
213
+ tempMessage = "The message does not match the expected format."
214
+ return (
215
+ f"<html><body><h1>Error</h1><h2>Error Number: 400</h2><p>{ tempMessage } </p></body></html>" ,
216
+ 400 ,
217
+ )
212
218
213
219
# Checking if the error number exists in err_codes
214
220
if error_number in err_codes :
@@ -247,7 +253,10 @@ def upload_file():
247
253
)
248
254
elif message == "LOG" :
249
255
logger .info (f"Successfully received request to download log" )
250
- return f"<html><body><h1>Success</h1>{ message .replace ('SUCCESS' , '' , 1 )} </body></html>" , 202
256
+ return (
257
+ f"<html><body><h1>Success</h1>{ message .replace ('SUCCESS' , '' , 1 )} </body></html>" ,
258
+ 202 ,
259
+ )
251
260
else :
252
261
logger .info (f"Successfully downloaded exam" )
253
262
return f"<html><body><h1>Success</h1>{ message } </body></html>" , 200
@@ -301,7 +310,10 @@ def download_log():
301
310
if os .path .exists (log_path ):
302
311
return send_from_directory (directory = base_path , path = "Server.log" )
303
312
else :
304
- return f"<html><body><h1>Error</h1><h2>Error Number: 404</h2><p>Server.log does not exist.</p></body></html>" , 404
313
+ return (
314
+ f"<html><body><h1>Error</h1><h2>Error Number: 404</h2><p>Server.log does not exist.</p></body></html>" ,
315
+ 404 ,
316
+ )
305
317
306
318
307
319
if __name__ == "__main__" :
0 commit comments