Use .sshwot/*.sshwot by default in sshwot-filter
This commit is contained in:
parent
013d588537
commit
7754f17cc9
2
Makefile
2
Makefile
|
@ -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_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_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)
|
all: $(BINS)
|
||||||
|
|
||||||
|
|
|
@ -3,11 +3,11 @@ import sys
|
||||||
|
|
||||||
import entry
|
import entry
|
||||||
import hashing
|
import hashing
|
||||||
|
import open_default_files
|
||||||
import read_file
|
import read_file
|
||||||
import write_file
|
import write_file
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# TODO: Default location to search
|
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description = """Search sshwot file(s) for given host and/or
|
description = """Search sshwot file(s) for given host and/or
|
||||||
fingerprint.""",
|
fingerprint.""",
|
||||||
|
@ -94,8 +94,14 @@ def main():
|
||||||
else:
|
else:
|
||||||
fingerprint = None
|
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 = []
|
matches = []
|
||||||
for infile in args.infiles:
|
for infile in infiles:
|
||||||
entries, file_comment = read_file.read(infile)
|
entries, file_comment = read_file.read(infile)
|
||||||
|
|
||||||
# Filter by host if it's present
|
# Filter by host if it's present
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue