Revision 3b98303f vncauthproxy/client.py
b/vncauthproxy/client.py | ||
---|---|---|
59 | 59 |
help=("Use source port PORT for incoming connections " |
60 | 60 |
"(default: allocate a port automatically)")) |
61 | 61 |
parser.add_option("-d", "--dest", |
62 |
default=None, dest="daddr",
|
|
62 |
dest="daddr", |
|
63 | 63 |
metavar="HOST", |
64 | 64 |
help="Proxy connection to destination host HOST") |
65 | 65 |
parser.add_option("-p", "--dport", dest="dport", |
66 |
default=None, type="int",
|
|
66 |
type="int", |
|
67 | 67 |
metavar="PORT", |
68 | 68 |
help="Proxy connection to destination port PORT") |
69 | 69 |
parser.add_option("-P", "--password", dest="password", |
70 |
default=None, |
|
71 | 70 |
metavar="PASSWORD", |
72 | 71 |
help=("Use password PASSWD to authenticate incoming " |
73 | 72 |
"VNC connections")) |
74 | 73 |
parser.add_option("--auth-user", dest="auth_user", |
75 |
default=None, |
|
76 | 74 |
metavar="AUTH_USER", |
77 | 75 |
help=("User to authenticate as, for the control " |
78 | 76 |
"connection")) |
79 | 77 |
parser.add_option("--auth-password", dest="auth_password", |
80 |
default=None, |
|
81 | 78 |
metavar="AUTH_PASSWORD", |
82 | 79 |
help=("User password for the control connection " |
83 | 80 |
"authentication")) |
... | ... | |
105 | 102 |
server_address=DEFAULT_SERVER_ADDRESS, |
106 | 103 |
server_port=DEFAULT_SERVER_PORT, enable_ssl=False, |
107 | 104 |
ca_cert=None, strict=False): |
108 |
"""Connect to vncauthproxy and request a VNC forwarding.""" |
|
109 |
|
|
110 |
# Mandatory arguments |
|
111 |
if not password: |
|
112 |
raise Exception("The password argument is mandatory.") |
|
113 |
if not daddr: |
|
114 |
raise Exception("The daddr argument is mandatory.") |
|
115 |
if not dport: |
|
116 |
raise Exception("The dport argument is mandatory.") |
|
117 |
if not auth_user: |
|
118 |
raise Exception("The auth_user argument is mandatory.") |
|
119 |
if not auth_password: |
|
120 |
raise Exception("The auth_password argument is mandatory.") |
|
105 |
""" Connect to vncauthproxy and request a VNC forwarding. |
|
106 |
|
|
107 |
@type sport: int |
|
108 |
@param sport: Source port for incoming connections |
|
109 |
(0 for automatic allocation)" |
|
110 |
@type daddr: str |
|
111 |
@param daddr: Destination address for the forwarding |
|
112 |
@type dport: int |
|
113 |
@param dport: Destination port for the forwarding |
|
114 |
@type password: str |
|
115 |
@param password: VNC server auth password |
|
116 |
@type auth_user: str |
|
117 |
@param auth_user: vncauthproxy user |
|
118 |
@type auth_password: str |
|
119 |
@param auth_password: vncauthproxy password |
|
120 |
@type server_address: str |
|
121 |
@param server_address: Listening address for the vncauthproxy daemon |
|
122 |
(default: 127.0.0.1) |
|
123 |
@type server_port: int |
|
124 |
@param server_port: Listening port for the vncauthproxy daemon |
|
125 |
(default: 24999) |
|
126 |
@type enable_ssl: bool |
|
127 |
@param enable_ssl: Enable / disable SSL on the control socket |
|
128 |
@type ca_cert: str |
|
129 |
@param ca_cert: Path to the CA cert file |
|
130 |
@type strict: bool |
|
131 |
@param strict: Enable strict cert checking for SSL |
|
132 |
@rtype: dict |
|
133 |
@return: Server response in dict / JSON format |
|
134 |
|
|
135 |
""" |
|
121 | 136 |
|
122 | 137 |
# Sanity check |
123 | 138 |
if strict and not ca_cert: |
124 | 139 |
raise Exception("strict requires ca-cert to be set") |
125 | 140 |
if not enable_ssl and (strict or ca_cert): |
126 |
logger.warning("strict or ca_cert set, but ssl not enabled")
|
|
141 |
logger.warning("strict or ca-cert set, but ssl not enabled")
|
|
127 | 142 |
|
128 | 143 |
req = { |
129 | 144 |
"source_port": int(sport), |
... | ... | |
192 | 207 |
|
193 | 208 |
(opts, args) = parse_arguments(sys.argv[1:]) |
194 | 209 |
|
210 |
# Mandatory arguments |
|
211 |
if opts.password is None: |
|
212 |
sys.stderr.write("The password argument is mandatory.\n") |
|
213 |
sys.exit(1) |
|
214 |
if opts.daddr is None: |
|
215 |
sys.stderr.write("The daddr argument is mandatory.\n") |
|
216 |
if opts.dport is None: |
|
217 |
sys.stderr.write("The dport argument is mandatory.\n") |
|
218 |
if opts.auth_user is None: |
|
219 |
sys.stderr.write("The auth_user argument is mandatory.\n") |
|
220 |
if opts.auth_password is None: |
|
221 |
sys.stderr.write("The auth_password argument is mandatory.\n") |
|
222 |
|
|
195 | 223 |
res = request_forwarding(sport=opts.sport, daddr=opts.daddr, |
196 | 224 |
dport=opts.dport, password=opts.password, |
197 | 225 |
auth_user=opts.auth_user, |
Also available in: Unified diff