#!/usr/bin/env python3
import os,sys
from urllib.parse import urlparse
args=sys.argv[1:]
if args and args[0]=='serve':
    targets=[a for a in args if a.startswith('http://')]
    if targets:
        with open(os.environ['EVIDENCE_CALLS'],'a') as f: f.write('tailscale '+' '.join(args)+'\n')
        if urlparse(targets[-1]).hostname not in ('127.0.0.1','localhost','::1'):
            print("Warning: the MacOS extension doesn't support connecting to remote destinations from non-default route",file=sys.stderr)
            sys.exit(1)
os.execv('/usr/bin/tailscale',['tailscale']+args)
