|
10 | 10 | program :help_formatter, Commander::HelpFormatter::Terminal
|
11 | 11 | default_command :help
|
12 | 12 | never_trace!
|
13 |
| -global_option '-c', '--config FILE', 'Specify path to config file. [Default: .ovpnmcgen.rb.yml]' |
14 |
| - |
| 13 | +global_option('-c', '--config FILE', 'Specify path to config file. [Default: .ovpnmcgen.rb.yml]') do |config| |
| 14 | + $config = config |
| 15 | +end |
| 16 | + |
15 | 17 | command :generate do |c|
|
16 | 18 | c.syntax = 'ovpnmcgen.rb generate [options] <user> <device>'
|
17 | 19 | c.summary = 'Generates iOS Configuration Profiles (.mobileconfig)'
|
|
23 | 25 | c.example 'Using OpenSSL to convert from PKCS#12 (.p12) to Key PEM file', 'openssl pkcs12 -in path/to/john-ipad.p12 -out path/to/john-ipad-key.pem -nodes -nocerts'
|
24 | 26 | c.option '--cafile FILE', 'Path to OpenVPN CA file. (Required)'
|
25 | 27 | c.option '--tafile FILE', 'Path to TLS-Auth Key file.'
|
| 28 | + c.option '--tlscryptfile FILE', 'Path to TLS-Crypt Key file.' |
26 | 29 | c.option '--cert FILE', 'Path to Cert file.'
|
27 | 30 | c.option '--key FILE', 'Path to Private Key file.'
|
28 | 31 | c.option '--host HOSTNAME', 'Hostname of OpenVPN server. (Required)'
|
|
34 | 37 | c.option '--v12compat', 'Enable OpenVPN Connect 1.2.x compatibility. When Enabled, use updated `VPNSubType: net.openvpn.connect.app` (changed since OpenVPN Connect 1.2.x). [Default: Disabled]'
|
35 | 38 | c.option '--security-level LEVEL', 'Security level of VPN-On-Demand Behaviour: paranoid, high, medium. [Default: high]'
|
36 | 39 | c.option '--vpn-uuid UUID', 'Override a VPN configuration payload UUID.'
|
| 40 | + c.option '--vpn-name NAME', 'Override a VPN configuration payload name displayed under Settings.app > General > VPN.' |
37 | 41 | c.option '--profile-uuid UUID', 'Override a Profile UUID.'
|
38 | 42 | c.option '--cert-uuid UUID', 'Override a Certificate payload UUID.'
|
39 | 43 | c.option '-t', '--trusted-ssids SSIDS', Array, 'List of comma-separated trusted SSIDs.'
|
40 | 44 | c.option '-u', '--untrusted-ssids SSIDS', Array, 'List of comma-separated untrusted SSIDs.'
|
41 | 45 | c.option '-d', '--domains DOMAINS', Array, 'List of comma-separated domain names requiring VPN service.'
|
42 | 46 | c.option '--domain-probe-url PROBE', String, 'An HTTP(S) URL to probe, using a GET request. If no HTTP response code is received from the server, a VPN connection is established in response.'
|
| 47 | + c.option '--trusted-ssids-probe-url PROBE', String, 'An HTTP(S) URL to probe, using a GET request. If no HTTP response code is received from the server, a VPN connection may be established in response.' |
43 | 48 | c.option '--url-probe URL', 'This URL must return HTTP status 200, without redirection, before the VPN service will try establishing.'
|
44 | 49 | c.option '--remotes REMOTES', Array, 'List of comma-separated alternate remotes: "<host> <port> <proto>".'
|
| 50 | + c.option '--idle-timer TIME', Integer, 'Disconnect from VPN when idle for a certain period of time (in seconds) which is useful for VPN-On-Demand scenarios. Requires disabling "Reconnect On Wakeup" on OpenVPN.app.' |
45 | 51 | c.option '--ovpnconfigfile FILE', 'Path to OpenVPN client config file.'
|
46 | 52 | c.option '-o', '--output FILE', 'Output to file. [Default: stdout]'
|
47 | 53 | c.action do |args, options|
|
48 |
| - raise ArgumentError.new "Invalid arguments. Run '#{File.basename(__FILE__)} help generate' for guidance" if args.nil? or args.length < 2 |
49 |
| - |
50 | 54 | # Set up configuration environment.
|
51 |
| - if options.config |
52 |
| - Ovpnmcgen.configure(options.config) |
| 55 | + if $config |
| 56 | + Ovpnmcgen.configure($config) |
53 | 57 | else
|
54 | 58 | Ovpnmcgen.configure
|
55 | 59 | end
|
56 | 60 | config = Ovpnmcgen.config
|
57 | 61 |
|
| 62 | + user, device = args |
| 63 | + if args.empty? and (options.p12file or config.p12file) |
| 64 | + filename = File.basename((options.p12file or config.p12file), '.p12') |
| 65 | + user, device = filename.split('-') if filename |
| 66 | + end |
| 67 | + |
| 68 | + unless user and device |
| 69 | + raise ArgumentError.new "Invalid arguments. Run '#{File.basename(__FILE__)} help generate' for guidance" |
| 70 | + end |
| 71 | + |
58 | 72 | raise ArgumentError.new "Host is required" unless options.host or config.host
|
59 | 73 | raise ArgumentError.new "cafile is required" unless options.cafile or config.cafile
|
60 | 74 |
|
|
63 | 77 | raise ArgumentError.new "PKCS#12 or cert & key file required"
|
64 | 78 | end
|
65 | 79 |
|
| 80 | + if (options.trusted_ssids_probe_url or config.trusted_ssids_probe_url) and not (options.trusted_ssids or config.trusted_ssids) |
| 81 | + raise ArgumentError.new "cannot set --trusted-ssids-probe-url without --trusted-ssids" |
| 82 | + end |
| 83 | + |
| 84 | + if (config.tafile or options.tafile) and (config.tlscryptfile or options.tlscryptfile) |
| 85 | + raise ArgumentError.new "tafile and tlscryptfile cannot be both set" |
| 86 | + end |
| 87 | + |
66 | 88 | options.default :vod => case
|
67 | 89 | when config.vod == true || config.no_vod == false
|
68 | 90 | true
|
|
75 | 97 | :port => (config.port)? config.port : 1194,
|
76 | 98 | :security_level => (config.security_level)? config.security_level : 'high'
|
77 | 99 |
|
78 |
| - user, device = args |
79 |
| - |
80 | 100 | inputs = {
|
81 | 101 | :user => user,
|
82 | 102 | :device => device,
|
|
87 | 107 | :port => options.port,
|
88 | 108 | :enableVOD => options.vod,
|
89 | 109 | :trusted_ssids => options.trusted_ssids || config.trusted_ssids,
|
| 110 | + :trusted_ssids_probe_url => options.trusted_ssids_probe_url || config.trusted_ssids_probe_url, |
90 | 111 | :untrusted_ssids => options.untrusted_ssids || config.untrusted_ssids,
|
91 | 112 | :profile_uuid => options.profile_uuid || config.profile_uuid,
|
92 | 113 | :vpn_uuid => options.vpn_uuid || config.vpn_uuid,
|
| 114 | + :vpn_name => options.vpn_name || config.vpn_name, |
93 | 115 | :cert_uuid => options.cert_uuid || config.cert_uuid,
|
94 | 116 | :security_level => options.security_level
|
95 | 117 | }
|
96 | 118 | inputs[:ovpnconfigfile] = options.ovpnconfigfile || config.ovpnconfigfile if options.ovpnconfigfile or config.ovpnconfigfile
|
97 | 119 | inputs[:p12file] = options.p12file || config.p12file if options.p12file or config.p12file
|
98 | 120 | inputs[:tafile] = options.tafile || config.tafile if options.tafile or config.tafile
|
| 121 | + inputs[:tlscryptfile] = options.tlscryptfile || config.tlscryptfile if options.tlscryptfile or config.tlscryptfile |
99 | 122 | inputs[:cert] = options.cert || config.cert if options.cert or config.cert
|
100 | 123 | inputs[:key] = options.key || config.key if options.key or config.key
|
101 | 124 | inputs[:url_probe] = options.url_probe || config.url_probe if options.url_probe or config.url_probe
|
102 | 125 | inputs[:remotes] = options.remotes || config.remotes if options.remotes or config.remotes
|
103 | 126 | inputs[:domains] = options.domains || config.domains if options.domains or config.domains
|
104 | 127 | inputs[:domain_probe_url] = options.domain_probe_url || config.domain_probe_url if options.domain_probe_url or config.domain_probe_url
|
105 | 128 | inputs[:v12compat] = options.v12compat || config.v12compat if options.v12compat or config.v12compat
|
| 129 | + inputs[:idle_timer] = options.idle_timer || config.idle_timer if options.idle_timer or config.idle_timer |
106 | 130 |
|
107 | 131 | unless options.output
|
108 | 132 | puts Ovpnmcgen.generate(inputs)
|
|
0 commit comments