From 744772329248bfff3489215177d3124e35e2f63a Mon Sep 17 00:00:00 2001 From: Ken Kundert Date: Thu, 10 Dec 2015 14:58:55 -0800 Subject: [PATCH] Small tweaks. --- README.rst | 21 +++++++++++++++++---- clean | 2 ++ core.py | 5 +++-- gensshconfig | 8 ++++++-- sshconfig.py | 6 ++++++ 5 files changed, 34 insertions(+), 8 deletions(-) diff --git a/README.rst b/README.rst index 3650adf..a29993c 100644 --- a/README.rst +++ b/README.rst @@ -849,19 +849,32 @@ you would like to use a proxy, you use the --proxy (or -P) command line argument to specify the proxy by name. For example:: PROXIES = { - 'work_proxy': 'proxytunnel -q -p webproxy.ext.workinghard.com:80 -d %h:%p', - 'school_proxy': 'proxytunnel -q -p sproxy.fna.learning.edu:1080 -d %h:%p', + 'work_proxy': 'corkscrew webproxy.ext.workinghard.com 80 %h %p', + 'school_proxy': 'corkscrew sproxy.fna.learning.edu 1080 %h %p', } Two HTTP proxies are described, the first capable of bypassing the corporate -firewall and the second does the same for the school's firewall. If preferred, -you can use socat rather than proxytunnel to accomplish the same thing:: +firewall and the second does the same for the school's firewall. Each is +a command that takes its input from stdin and produces its output on stdout. +The program 'corkscrew' is designed to proxy a TCP connection through an HTTP +proxy. The first two arguments are the host name and port number of the proxy. +corkscrew connects to the proxy and passes the third and fourth arguments, the +host name and port number of desired destination. + +There are many alternatives to corkscrew. One is socat:: PROXIES = { 'work_proxy': 'socat - PROXY:webproxy.ext.workinghard.com:%h:%p,proxyport=80', 'school_proxy': 'socat - PROXY:sproxy.fna.learning.edu:%h:%p,proxyport=1080', } +Another alternative is proxytunnel:: + + PROXIES = { + 'work_proxy': 'proxytunnel -q -p webproxy.ext.workinghard.com:80 -d %h:%p', + 'school_proxy': 'proxytunnel -q -p sproxy.fna.learning.edu:1080 -d %h:%p', + } + When at work, you should generate your ssh config file using:: gensshconfig --proxy=work_proxy diff --git a/clean b/clean index 23ec508..320454b 100755 --- a/clean +++ b/clean @@ -7,6 +7,8 @@ rm -f README.pdf # the rest is common to all python directories rm -f *.pyc *.pyo .test*.sum expected result install.out rm -rf build *.egg-info dist __pycache__ .coverage .coverage-html +rm -f resp*.html + foreach i (*/clean) if ($i == "*/clean") break #echo $i diff --git a/core.py b/core.py index 578df86..97079a7 100644 --- a/core.py +++ b/core.py @@ -1,6 +1,6 @@ # Core Internal Classes for SSHConfig -from sshconfig import NetworkEntry, locations +from sshconfig import NetworkEntry, locations, ports from scripts import join, normpath, head, Run, ScriptError import os @@ -348,7 +348,8 @@ def initializeNetwork(network): script.wait() except AttributeError: pass - except ScriptError as error: + except ScriptError: + # not capturing output, so user should already have error message print("%s network init_script failed (ignored): '%s'" % ( network.name(), str(script) )) diff --git a/gensshconfig b/gensshconfig index 3b8c8e5..9c6f96f 100755 --- a/gensshconfig +++ b/gensshconfig @@ -111,7 +111,7 @@ if unknown: print(' ' + '\n '.join(sorted(unknown))) # Get description of this situation -desc = [network.Name(), 'network'] +desc = [network.Name() if network else 'Unknown', 'network'] if networkDesc: desc += ['(%s)' % networkDesc] if locations.my_location: @@ -150,7 +150,11 @@ body = [] suffix = [] # Output header -header.append('# SSH Configuration for %s network.' % network.Name()) +header.append( + '# SSH Configuration for %s network.' % network.Name() + if network else + 'unknown' +) header.append(time.strftime("# Generated at %-I:%M %p on %d %B %Y.")) header.append(dedent('''\ # diff --git a/sshconfig.py b/sshconfig.py index e840a2c..2747275 100644 --- a/sshconfig.py +++ b/sshconfig.py @@ -21,6 +21,12 @@ def gethostname(): def getusername(): return getpass.getuser() +# is_ip_addr {{{2 +import re +ip_addr_ptn = re.compile(r"\A\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\s*\Z") +def is_ip_addr(addr): + return ip_addr_ptn.match(addr) + # VNC {{{2 # Generates forwards for VNC def VNC(