#!/usr/bin/python

import argparse
import os

from proxy_negotiate import shim_proxy, __version__

parser = argparse.ArgumentParser(description='Tunnels TCP traffic through a secure corporate HTTP proxy, supporting HTTP Negotiate (SPNEGO) authentication')
parser.add_argument('proxy_host', help='Hostname or IP of the proxy to tunnel connection through', nargs='?',
    default=os.environ['http_proxy'].replace('http://', '').rsplit(':', 1)[0])
parser.add_argument('proxy_port', help='Port of the proxy to tunnel connection through', nargs='?', type=int,
    default=int(os.environ['http_proxy'].replace('http://', '').rsplit(':', 1)[1]))
parser.add_argument('host', help='Hostname or IP to tunnel a connection to', nargs='?', default='localhost')
parser.add_argument('port', help='Port to tunnel a connection to', type=int, nargs='?', default=8080)
parser.add_argument('--version', '-V', action='version', version='%(prog)s ' + __version__)
args = parser.parse_args()

shim_proxy(args.proxy_host, args.proxy_port, args.host, args.port)
