0
0
Fork 0
mirror of https://github.com/boltgolt/howdy.git synced 2024-09-19 09:51:19 +02:00

Change snapshot location per #649

This commit is contained in:
boltgolt 2023-02-19 13:45:34 +01:00
parent 27f3a73c9f
commit 568a5734d4
No known key found for this signature in database
GPG key ID: BECEC9937E1AAE26
2 changed files with 13 additions and 8 deletions

View file

@ -94,7 +94,7 @@ rotate = 0
[snapshots] [snapshots]
# Capture snapshots of failed login attempts and save them to disk with metadata # Capture snapshots of failed login attempts and save them to disk with metadata
# Snapshots are saved to the "snapshots" folder # Snapshots are saved to /var/log/howdy/snapshots
save_failed = false save_failed = false
# Do the same as the option above but for successful attempts # Do the same as the option above but for successful attempts

View file

@ -8,14 +8,14 @@ import numpy as np
def generate(frames, text_lines): def generate(frames, text_lines):
"""Generate a shapshot from given frames""" """Generate a snapshot from given frames"""
# Don't execute if no frames were given # Don't execute if no frames were given
if len(frames) == 0: if len(frames) == 0:
return return
# Get the path to the containing folder # Get the path to the containing folder
abpath = os.path.dirname(os.path.abspath(__file__)) core_path = os.path.dirname(os.path.abspath(__file__))
# Get frame dimensions # Get frame dimensions
frame_height, frame_width, cc = frames[0].shape frame_height, frame_width, cc = frames[0].shape
# Spread the given frames out horizontally # Spread the given frames out horizontally
@ -31,7 +31,7 @@ def generate(frames, text_lines):
# Add the Howdy logo if there's space to do so # Add the Howdy logo if there's space to do so
if len(frames) > 1: if len(frames) > 1:
# Load the logo from file # Load the logo from file
logo = cv2.imread(abpath + "/logo.png") logo = cv2.imread(core_path + "/logo.png")
# Calculate the position of the logo # Calculate the position of the logo
logo_y = frame_height + 20 logo_y = frame_height + 20
logo_x = frame_width * len(frames) - 210 logo_x = frame_width * len(frames) - 210
@ -49,14 +49,19 @@ def generate(frames, text_lines):
line_number += 1 line_number += 1
# Define path to any howdy logs
log_path = "/var/log/howdy"
# Made sure a snapshot folder exist # Made sure a snapshot folder exist
if not os.path.exists(abpath + "/snapshots"): if not os.path.exists(log_path):
os.makedirs(abpath + "/snapshots") os.makedirs(log_path)
if not os.path.exists(log_path + "/snapshots"):
os.makedirs(log_path + "/snapshots")
# Generate a filename based on the current time # Generate a filename based on the current time
filename = datetime.datetime.utcnow().strftime("%Y%m%dT%H%M%S.jpg") filename = datetime.datetime.utcnow().strftime("%Y%m%dT%H%M%S.jpg")
# Write the image to that file # Write the image to that file
cv2.imwrite(abpath + "/snapshots/" + filename, snap) cv2.imwrite(log_path + "/snapshots/" + filename, snap)
# Return the saved file location # Return the saved file location
return abpath + "/snapshots/" + filename return log_path + "/snapshots/" + filename