Class: VPN::Config::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/vpn/config/cli.rb

Instance Method Summary collapse

Instance Method Details

#endpoints(provider = "Private Internet Access") ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/vpn/config/cli.rb', line 70

def endpoints(provider="Private Internet Access")
  generator = VPN::Config::Generator.new(data_file: expand_path(options[:data_file]))
  provider = generator.providers.find {|pr| pr["name"] =~ Regexp.new(provider, Regexp::IGNORECASE) }
  if provider
    provider["endpoints"].each do |e|
      puts "* " + e["name"]
      if options[: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
# File 'lib/vpn/config/cli.rb', line 19

def generate(output_file)
  generator = VPN::Config::Generator.new(
    auth_name: options[:username],
    auth_pass: options[:password],
    identifier: options[:identifier],
    certificate_path: expand_path(options[:certificate_path]),
    certificate_pass: options[:certificate_pass],
    endpoints: options[:endpoints],
    provider: options[:provider],
    data_file: expand_path(options[:data_file])
  )

  plist = if options[: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.expand_path(output_file)
    puts "Writing to: #{out_path}"

    File.open(output_file, "wb") do |f|
      f << plist
    end
  end
end

#providersObject



56
57
58
59
60
61
62
63
64
65
# File 'lib/vpn/config/cli.rb', line 56

def providers
  generator = VPN::Config::Generator.new(data_file: expand_path(options[:data_file]))
  generator.providers.each do |pr|
    puts "* " + pr["name"]
    if options[:verbose]
      puts "  * URL: " + pr["url"]
      puts "  * UUID: " + pr["uuid"]
    end
  end
end