1
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
2
# See LICENSE for details.
5
from twisted.conch.ssh.transport import SSHClientTransport, SSHCiphers
6
from twisted.python import usage
10
class ConchOptions(usage.Options):
12
optParameters = [['user', 'l', None, 'Log in using this user name.'],
13
['identity', 'i', None],
14
['ciphers', 'c', None],
16
['port', 'p', None, 'Connect to this port. Server must be on the same port.'],
17
['option', 'o', None, 'Ignored OpenSSH options'],
18
['host-key-algorithms', '', None],
19
['known-hosts', '', None, 'File to check for host keys'],
20
['user-authentications', '', None, 'Types of user authentications to use.'],
21
['logfile', '', None, 'File to log to, or - for stdout'],
24
optFlags = [['version', 'V', 'Display version number only.'],
25
['compress', 'C', 'Enable compression.'],
26
['log', 'v', 'Enable logging (defaults to stderr)'],
27
['nox11', 'x', 'Disable X11 connection forwarding (default)'],
28
['agent', 'A', 'Enable authentication agent forwarding'],
29
['noagent', 'a', 'Disable authentication agent forwarding (default)'],
30
['reconnect', 'r', 'Reconnect to the server if the connection is lost.'],
32
zsh_altArgDescr = {"connection-usage":"Connection types to use"}
33
#zsh_multiUse = ["foo", "bar"]
34
zsh_mutuallyExclusive = [("agent", "noagent")]
35
zsh_actions = {"user":"_users",
36
"ciphers":"_values -s , 'ciphers to choose from' %s" %
37
" ".join(SSHCiphers.cipherMap.keys()),
38
"macs":"_values -s , 'macs to choose from' %s" %
39
" ".join(SSHCiphers.macMap.keys()),
40
"host-key-algorithms":"_values -s , 'host key algorithms to choose from' %s" %
41
" ".join(SSHClientTransport.supportedPublicKeys),
42
#"user-authentications":"_values -s , 'user authentication types to choose from' %s" %
45
#zsh_actionDescr = {"logfile":"log file name", "random":"random seed"}
46
# user, host, or user@host completion similar to zsh's ssh completion
47
zsh_extras = ['1:host | user@host:{_ssh;if compset -P "*@"; then _wanted hosts expl "remote host name" _ssh_hosts && ret=0 elif compset -S "@*"; then _wanted users expl "login name" _ssh_users -S "" && ret=0 else if (( $+opt_args[-l] )); then tmp=() else tmp=( "users:login name:_ssh_users -qS@" ) fi; _alternative "hosts:remote host name:_ssh_hosts" "$tmp[@]" && ret=0 fi}']
49
def __init__(self, *args, **kw):
50
usage.Options.__init__(self, *args, **kw)
54
def opt_identity(self, i):
55
"""Identity for public-key authentication"""
56
self.identitys.append(i)
58
def opt_ciphers(self, ciphers):
59
"Select encryption algorithms"
60
ciphers = ciphers.split(',')
61
for cipher in ciphers:
62
if not SSHCiphers.cipherMap.has_key(cipher):
63
sys.exit("Unknown cipher type '%s'" % cipher)
64
self['ciphers'] = ciphers
67
def opt_macs(self, macs):
68
"Specify MAC algorithms"
69
macs = macs.split(',')
71
if not SSHCiphers.macMap.has_key(mac):
72
sys.exit("Unknown mac type '%s'" % mac)
75
def opt_host_key_algorithms(self, hkas):
76
"Select host key algorithms"
77
hkas = hkas.split(',')
79
if hka not in SSHClientTransport.supportedPublicKeys:
80
sys.exit("Unknown host key type '%s'" % hka)
81
self['host-key-algorithms'] = hkas
83
def opt_user_authentications(self, uas):
84
"Choose how to authenticate to the remote server"
85
self['user-authentications'] = uas.split(',')
87
# def opt_compress(self):
88
# "Enable compression"
89
# self.enableCompression = 1
90
# SSHClientTransport.supportedCompressions[0:1] = ['zlib']