Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
H-NAS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
santosh8
H-NAS
Commits
c18406c3
Commit
c18406c3
authored
2 years ago
by
santosh8
Browse files
Options
Downloads
Patches
Plain Diff
updating logging
parent
bef28cb3
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
app.py
+20
-9
20 additions, 9 deletions
app.py
with
21 additions
and
9 deletions
.gitignore
+
1
−
0
View file @
c18406c3
...
...
@@ -3,3 +3,4 @@ access_data.json
save_mode.json
creds.json
cache/
*.log
\ No newline at end of file
This diff is collapsed.
Click to expand it.
app.py
+
20
−
9
View file @
c18406c3
...
...
@@ -5,13 +5,21 @@ import json
from
constants
import
*
from
utils
import
*
from
lfu_checker
import
LFUChecker
import
logging
logging
.
basicConfig
(
filename
=
'
app.log
'
,
filemode
=
'
w
'
,
format
=
'
%(name)s - %(levelname)s - %(message)s
'
)
import
datetime
app
=
Flask
(
__name__
)
app
.
secret_key
=
'
your_secret_key_here
'
app
.
config
[
"
CACHE_TYPE
"
]
=
"
null
"
@app.route
(
'
/download/<path:filename>
'
,
methods
=
[
'
GET
'
])
def
download_file
(
filename
):
try
:
logging
.
info
(
"
File:
"
+
filename
+
"
downloaded by
"
+
request
.
remote_addr
+
"
at
"
+
str
(
datetime
.
datetime
.
now
())
+
"
with user agent
"
+
request
.
user_agent
.
string
)
except
Exception
as
e
:
logging
.
exception
(
"
Exception occurred: {}
"
.
format
)
if
not
check_login
():
return
redirect
(
url_for
(
'
login
'
))
try
:
local_files
=
get_local_files
()
s3_files
=
get_s3_files
()
...
...
@@ -31,9 +39,11 @@ def download_file(filename):
def
serve_thumb
(
filename
):
return
send_from_directory
(
'
./thumb
'
,
filename
)
# check if user is logged in else redirect to login page
def
check_login
():
try
:
logging
.
info
(
"
User:
"
+
session
[
'
username
'
]
+
"
logged in at
"
+
str
(
datetime
.
datetime
.
now
())
+
"
with user agent
"
+
request
.
user_agent
.
string
)
except
Exception
as
e
:
logging
.
exception
(
"
Exception occurred: {}
"
.
format
)
if
'
username
'
not
in
session
:
return
redirect
(
url_for
(
'
login
'
))
else
:
...
...
@@ -45,19 +55,16 @@ def check_login():
mmisc
=
True
if
len
(
misc
)
>
5
else
False
return
render_template
(
'
index.html
'
,
pdffiles
=
pdfs
[:
5
],
imgfiles
=
images
[:
5
],
videofiles
=
videos
[:
5
],
misc
=
misc
[:
5
],
mpdfs
=
mpdfs
,
mimages
=
mimages
,
mvideos
=
mvideos
,
mmisc
=
mmisc
)
# login page
@app.route
(
'
/login
'
,
methods
=
[
'
GET
'
,
'
POST
'
])
def
login
():
if
request
.
method
==
'
POST
'
:
username
=
request
.
form
[
'
username
'
]
password
=
request
.
form
[
'
password
'
]
if
(
username
==
'
admin
'
)
and
(
password
==
'
admin
'
):
# if user is found, redirect to index page
session
[
'
username
'
]
=
username
return
redirect
(
url_for
(
'
index
'
))
else
:
# if user is not found, redirect to login page
flash
(
'
Invalid username or password
'
)
return
redirect
(
url_for
(
'
login
'
))
...
...
@@ -166,10 +173,9 @@ def misc():
pdfs
,
images
,
videos
,
misc
=
categorize_files
(
files
)
return
render_template
(
'
more_files.html
'
,
files
=
misc
,
content
=
'
Misc.
'
,
fa_content
=
'
icon-sun
'
)
# logout page
@app.route
(
'
/logout
'
)
def
logout
():
# remove the username from the session if it is there
session
.
pop
(
'
username
'
,
None
)
return
redirect
(
url_for
(
'
login
'
))
...
...
@@ -191,6 +197,11 @@ def delete_file():
return
redirect
(
url_for
(
'
login
'
))
filename
=
request
.
form
.
get
(
'
delete-file
'
)
try
:
logging
.
info
(
"
Deletion User: %s, File: %s, Time: %s
"
,
session
[
'
username
'
],
filename
,
datetime
.
datetime
.
now
())
except
Exception
as
e
:
logging
.
exception
(
"
Exception occured:{}
"
.
format
(
e
))
if
filename
:
local_file_path
=
os
.
path
.
join
(
os
.
getcwd
(),
'
cache
'
,
filename
)
s3_file_path
=
filename
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment