@@ -88,13 +88,12 @@ def admin_home():
8888 )
8989
9090# -- View and import (admin only) --
91- @app .route ('/view/<filename>' , methods = ['GET' , 'POST' ])
91+ @app .route ('/view/<path: filename>' , methods = ['GET' , 'POST' ])
9292def view_table (filename ):
93- if not session .get ('admin' ):
94- return redirect (url_for ('login' ))
93+ admin = session .get ('admin' , False )
9594 filepath = os .path .join (app .config ['UPLOAD_FOLDER' ], filename )
9695 ext = filename .rsplit ('.' , 1 )[1 ].lower ()
97- table_name = filename .replace ('.' , '_' ).replace ('-' , '_' )
96+ table_name = filename .replace ('.' , '_' ).replace ('-' , '_' ). replace ( '/' , '_' ). replace ( ' \\ ' , '_' )
9897
9998 try :
10099 if ext == 'csv' :
@@ -115,16 +114,19 @@ def view_table(filename):
115114 except Exception as e :
116115 return f"Could not read file: { e } "
117116
118- if request .method == 'POST' and 'import_sql' in request .form :
117+ # Only allow import if admin
118+ if admin and request .method == 'POST' and 'import_sql' in request .form :
119119 with sqlite3 .connect (DB_NAME ) as conn :
120120 df .to_sql (table_name , conn , if_exists = 'replace' , index = False )
121121 flash (f"Table '{ table_name } ' imported to SQLite." )
122+
122123 return render_template ('view_table.html' ,
123124 tables = [df .to_html (classes = 'data' )],
124125 titles = df .columns .values ,
125126 filename = filename ,
126127 imported_table = table_name ,
127- admin = True )
128+ admin = admin )
129+
128130
129131# -- SQL query tool (admin only) --
130132@app .route ('/query' , methods = ['GET' , 'POST' ])
0 commit comments