From 6e32d1445a7980b0082fed1d86fcd70cff6e244d Mon Sep 17 00:00:00 2001 From: Sean Zeng Date: Sat, 21 Mar 2015 22:43:12 -0700 Subject: [PATCH] add -e/-d support --- src/firewall.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/firewall.py b/src/firewall.py index d18b64e..058aafe 100644 --- a/src/firewall.py +++ b/src/firewall.py @@ -470,7 +470,7 @@ def do_ipfw(port, dnsport, family, subnets, udp): def pfctl(args, stdin = None): argv = ['pfctl'] + list(args.split(" ")) - debug1('>> %s' % ' '.join(argv)) + debug1('>> %s\n' % ' '.join(argv)) p = ssubprocess.Popen(argv, stdin = ssubprocess.PIPE, stdout = ssubprocess.PIPE, @@ -515,10 +515,19 @@ def do_pf(port, dnsport, family, subnets, udp): if not '\nanchor "sshuttle" all\n' in pf_status: pf_add_anchor_rule(PF_PASS, "sshuttle") - o = pfctl('-a sshuttle -f /dev/stdin -E', rules) - _pf_context['Xtoken'] = re.search(r'Token : (.+)', o[1]).group(1) + pfctl('-a sshuttle -f /dev/stdin', rules) + if sys.platform == "darwin": + o = pfctl('-E') + _pf_context['Xtoken'] = re.search(r'Token : (.+)', o[1]).group(1) + elif 'INFO:\nStatus: Disabled' in pf_status: + pfctl('-e') + _pf_context['started_by_sshuttle'] = True else: - pfctl('-a sshuttle -F all -X %s' % _pf_context['Xtoken']) + pfctl('-a sshuttle -F all') + if sys.platform == "darwin": + pfctl('-X %s' % _pf_context['Xtoken']) + elif _pf_context['started_by_sshuttle']: + pfctl('-d') def program_exists(name):