Use .sshwot/*.sshwot by default in sshwot-filter

This commit is contained in:
Juhani Krekelä 2018-09-01 21:55:09 +03:00
parent 013d588537
commit 7754f17cc9
3 changed files with 33 additions and 3 deletions

View File

@ -4,7 +4,7 @@ SSHWOT_EXPORT_KNOWN_HOSTS_MAIN:=src/main-export-known-hosts.py
SSHWOT_EXPORT_KNOWN_HOSTS_DEPS:=src/entry.py src/hashing.py src/process_known_hosts.py src/write_file.py
SSHWOT_FILTER_MAIN:=src/main-filter.py
SSHWOT_FILTER_DEPS:=src/entry.py src/hashing.py src/read_file.py src/write_file.py
SSHWOT_FILTER_DEPS:=src/entry.py src/hashing.py src/open_default_files.py src/read_file.py src/write_file.py
all: $(BINS)

View File

@ -3,11 +3,11 @@ import sys
import entry
import hashing
import open_default_files
import read_file
import write_file
def main():
# TODO: Default location to search
parser = argparse.ArgumentParser(
description = """Search sshwot file(s) for given host and/or
fingerprint.""",
@ -94,8 +94,14 @@ def main():
else:
fingerprint = None
# Use the default files if no input files were specified
if len(args.infiles) == 0:
infiles = open_default_files.open_all()
else:
infiles = args.infiles
matches = []
for infile in args.infiles:
for infile in infiles:
entries, file_comment = read_file.read(infile)
# Filter by host if it's present

24
src/open_default_files.py Normal file
View File

@ -0,0 +1,24 @@
import os
def open_all():
"""open_all() → [file(rb)]
Open the default sshwot files"""
try:
homedir = os.environ['HOME']
except KeyError as err:
raise KeyError('$HOME is not set') from err
# If the directory doesn't exist, just return empty
try:
sshwot_dir = os.listdir(os.path.join(homedir, '.sshwot'))
except FileNotFoundError:
return []
# Read all the .sshwot files from /.sshwot by default
files = []
for dir_entry in sshwot_dir:
if dir_entry.split('.')[-1] == 'sshwot':
files.append(open(dir_entry, 'rb'))
return files