Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get config from execution directory #187

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion fakenet/diverters/diverterbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -1040,9 +1040,14 @@ def parse_diverter_config(self):
sys.exit(1)

if self.is_set('dumppackets'):
self.pcap_filename = '%s_%s.pcap' % (self.getconfigval(
pcap_filename = '%s_%s.pcap' % (self.getconfigval(
'dumppacketsfileprefix', 'packets'),
time.strftime('%Y%m%d_%H%M%S'))
if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
out_dir = os.path.dirname(sys.executable)
else:
out_dir = os.path.dirname(__file__)
self.pcap_filename = os.path.join(out_dir, pcap_filename)
self.logger.info('Capturing traffic to %s', self.pcap_filename)
self.pcap = dpkt.pcap.Writer(open(self.pcap_filename, 'wb'),
linktype=dpkt.pcap.DLT_RAW)
Expand Down
2 changes: 1 addition & 1 deletion fakenet/fakenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __init__(self, logging_level = logging.INFO):
def parse_config(self, config_filename):
# Handling Pyinstaller bundle scenario: https://pyinstaller.org/en/stable/runtime-information.html
if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
dir_path = os.getcwd()
dir_path = os.path.dirname(sys.executable)
else:
dir_path = os.path.dirname(__file__)

Expand Down
2 changes: 1 addition & 1 deletion fakenet/listeners/ListenerBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def abs_config_path(path):
return abspath

if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
relpath = os.path.join(os.getcwd(), path)
relpath = os.path.join(os.path.dirname(sys.executable), path)
else:

# Try to locate the location relative to application path
Expand Down
2 changes: 1 addition & 1 deletion fakenet/listeners/TFTPListener.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def handle_data(self, socket, data):
if hasattr(self.server, 'filename_path') and self.server.filename_path:

safe_file = self.server.tftp_file_prefix + "_" + urllib.parse.quote(self.server.filename_path, '')
output_file = ListenerBase.safe_join(os.getcwd(),
output_file = ListenerBase.safe_join(os.path.dirname(sys.executable),
safe_file)
f = open(output_file, 'ab')
f.write(data[4:])
Expand Down