Class: VPN::Config::CLI
- Inherits:
-
Thor
- Object
- Thor
- VPN::Config::CLI
- Includes:
- Thor::Actions
- Defined in:
- lib/vpn/config/cli.rb
Instance Method Summary collapse
- #endpoints(provider = "Private Internet Access") ⇒ Object
- #generate(output_file) ⇒ Object
- #providers ⇒ Object
Instance Method Details
#endpoints(provider = "Private Internet Access") ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/vpn/config/cli.rb', line 82 def endpoints(provider="Private Internet Access") datafile = if [:data_file] File.([:data_file]) end generator = VPN::Config::Generator.new(data_file: datafile) provider = generator.providers.find {|pr| pr["name"] =~ Regexp.new(provider, Regexp::IGNORECASE) } if provider provider["endpoints"].each do |e| puts "* " + e["name"] if [:verbose] puts " * Host: " + e["host"] puts " * UUID: " + e["uuid"] puts " * SharedSecret: " + e["shared_secret"] end end else abort "No provider found" end end |
#generate(output_file) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/vpn/config/cli.rb', line 19 def generate(output_file) datafile = if [:data_file] File.([:data_file]) end certificate_path = if [:certificate_path] File.([:certificate_path]) end generator = VPN::Config::Generator.new( auth_name: [:username], auth_pass: [:password], identifier: [:identifier], certificate_path: certificate_path, certificate_pass: [:certificate_pass], endpoints: [:endpoints], provider: [:provider], data_file: datafile ) plist = if [:sign] generator.generate_signed_plist else generator.generate_plist end if output_file.nil? || output_file.empty? puts plist else unless output_file =~ /\.(mobileconfig|plist)\z/i output_file = output_file + ".mobileconfig" end out_path = File.(output_file) puts "Writing to: #{out_path}" File.open(output_file, "wb") do |f| f << plist end end end |
#providers ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/vpn/config/cli.rb', line 64 def providers datafile = if [:data_file] File.([:data_file]) end generator = VPN::Config::Generator.new(data_file: datafile) generator.providers.each do |pr| puts "* " + pr["name"] if [:verbose] puts " * URL: " + pr["url"] puts " * UUID: " + pr["uuid"] end end end |