| Index: test/connect-vpn
|
| diff --git a/test/connect-vpn b/test/connect-vpn
|
| index 2055cc0bd7834bf7ff26df9200f3a35cba180d23..d507e8d936f9c3b5f93e62527573aa17e1148769 100755
|
| --- a/test/connect-vpn
|
| +++ b/test/connect-vpn
|
| @@ -7,34 +7,41 @@ import optparse
|
| import pprint, sys
|
| import dbus, flimflam
|
|
|
| +def show_usage(parser, vpn_type):
|
| + parser.error("Incorrect number of parameters provided for %s" % vpn_type)
|
| +
|
| def main(argv):
|
| - parser = optparse.OptionParser('%prog [options]... (VPN)\n\n'
|
| - ' VPN := openvpn <vpn-name> '
|
| - '<remote-host-ip> <vpn-domain>\n '
|
| - ' <ca-file> <client-cert-file> '
|
| - '<client-key-file>')
|
| - parser.add_option('--verbose',
|
| - dest = 'verbose',
|
| - action = 'store_true',
|
| + parser = optparse.OptionParser(
|
| + "%prog [options]... (VPN)\n"
|
| + "\n"
|
| + " VPN := openvpn <vpn-name> <remote-host-ip> <vpn-domain>\n"
|
| + " <ca-file> <client-cert-file> <client-key-file>\n"
|
| + " | l2tpipsec <vpn-name> <remote-host-ip> <vpn-domain>\n"
|
| + " <ca-file> <client-cert-file> <client-key-file>\n"
|
| + " <ipsec-psk> <username> <password>")
|
| + parser.add_option("--verbose",
|
| + dest = "verbose",
|
| + action = "store_true",
|
| default = False,
|
| help = "Output diagnostic information during run.")
|
| - parser.add_option('--complzo',
|
| - dest = 'complzo',
|
| - action = 'store_true',
|
| + parser.add_option("--complzo",
|
| + dest = "complzo",
|
| + action = "store_true",
|
| default = True,
|
| - help = "Enables the OpenVPN option 'complzo' (default).")
|
| - parser.add_option('--no-complzo',
|
| - dest = 'complzo',
|
| - action = 'store_false',
|
| + help = ("Enables the OpenVPN option 'complzo' "
|
| + "(default)"))
|
| + parser.add_option("--no-complzo",
|
| + dest = "complzo",
|
| + action = "store_false",
|
| help = "Disables the OpenVPN option 'complzo'.")
|
| - parser.add_option('--remote-cert-tls',
|
| - dest = 'remote_cert_tls',
|
| - action = 'store',
|
| - default = 'server',
|
| - type = 'string',
|
| - metavar = '(server | client | none)',
|
| - help = "This is passed through to OpenVPN when "
|
| - "not 'none'.")
|
| + parser.add_option("--remote-cert-tls",
|
| + dest = "remote_cert_tls",
|
| + action = "store",
|
| + default = "server",
|
| + type = "string",
|
| + metavar = "(server | client | none)",
|
| + help = ("This is passed through to OpenVPN when "
|
| + "not 'none'."))
|
|
|
| (options, args) = parser.parse_args(argv[1:])
|
|
|
| @@ -50,20 +57,32 @@ def main(argv):
|
| params["OpenVPN.Cert"] = args[5]
|
| params["OpenVPN.Key"] = args[6]
|
|
|
| - if options.complzo: # 'complzo' can only be enabled.
|
| - params["OpenVPN.CompLZO"] = 'true'
|
| + if options.complzo: # "complzo" can only be enabled.
|
| + params["OpenVPN.CompLZO"] = "true"
|
|
|
| - if options.remote_cert_tls != 'server' and \
|
| - options.remote_cert_tls != 'client' and \
|
| - options.remote_cert_tls != 'none':
|
| - print "\n--remote-cert-tls argument ('%s') " \
|
| - "is invalid.\n" % options.remote_cert_tls
|
| + if (options.remote_cert_tls != "server" and
|
| + options.remote_cert_tls != "client" and
|
| + options.remote_cert_tls != "none"):
|
| + print("\n--remote-cert-tls argument ('%s') "
|
| + "is invalid.\n" % options.remote_cert_tls)
|
| sys.exit(1)
|
|
|
| params["OpenVPN.RemoteCertTLS"] = options.remote_cert_tls
|
| else:
|
| - parser.error("Incorrect number of parameters "
|
| - "provided for 'openvpn'")
|
| + show_usage(parser, params["Type"])
|
| + elif params["Type"] == "l2tpipsec":
|
| + if len(args) == 10:
|
| + params["Name"] = args[1]
|
| + params["Host"] = args[2]
|
| + params["VPN.Domain"] = args[3]
|
| + params["L2TPIPsec.CACert"] = args[4]
|
| + params["L2TPIPsec.Cert"] = args[5]
|
| + params["L2TPIPsec.Key"] = args[6]
|
| + params["L2TPIPsec.PSK"] = args[7]
|
| + params["L2TPIPsec.User"] = args[8]
|
| + params["L2TPIPsec.Password"] = args[9]
|
| + else:
|
| + show_usage(parser, params["Type"])
|
| else:
|
| print "Unknown VPN type: '%s'" % params["Type"]
|
| sys.exit(1)
|
| @@ -77,13 +96,13 @@ def main(argv):
|
| flim = flimflam.FlimFlam(dbus.SystemBus())
|
| service = flim.GetVPNService(params)
|
|
|
| - if options.verbose == 'true':
|
| + if options.verbose == "true":
|
| print "VPN is %s, connecting..." % service.object_path
|
|
|
| - (success, diagnostics) = flim.ConnectService(service_type = 'vpn',
|
| + (success, diagnostics) = flim.ConnectService(service_type = "vpn",
|
| service = service)
|
| if not success or options.verbose:
|
| - print 'Success:', success
|
| + print "Success:", success
|
| pprint.pprint(diagnostics)
|
| else:
|
| parser.print_help()
|
|
|