class CfnVpn::Actions::Share
Public Class Methods
source_root()
click to toggle source
# File lib/cfnvpn/actions/share.rb, line 19 def self.source_root File.dirname(__FILE__) end
Public Instance Methods
add_routes()
click to toggle source
# File lib/cfnvpn/actions/share.rb, line 36 def add_routes if @options['ignore_routes'] CfnVpn::Log.logger.debug "Ignoring routes pushed by the client vpn" @config.concat("\nroute-nopull\n") vpn = CfnVpn::ClientVpn.new(@name,@options['region']) routes = vpn.get_route_with_mask CfnVpn::Log.logger.debug "Found routes #{routes}" routes.each do |r| @config.concat("route #{r[:route]} #{r[:mask]}\n") end dns_servers = vpn.get_dns_servers() if dns_servers.any? CfnVpn::Log.logger.debug "Found DNS servers #{dns_servers.join(' ')}" @config.concat("dhcp-option DNS #{dns_servers.first}\n") end end end
copy_config_to_s3()
click to toggle source
# File lib/cfnvpn/actions/share.rb, line 27 def copy_config_to_s3 vpn = CfnVpn::ClientVpn.new(@name,@options['region']) @endpoint_id = vpn.get_endpoint_id() CfnVpn::Log.logger.debug "downloading client config for #{@endpoint_id}" @config = vpn.get_config(@endpoint_id) string = (0...8).map { (65 + rand(26)).chr.downcase }.join @config.sub!(@endpoint_id, "#{string}.#{@endpoint_id}") end
display_instructions()
click to toggle source
# File lib/cfnvpn/actions/share.rb, line 69 def display_instructions CfnVpn::Log.logger.info "Share the bellow instruction with the user..." say "\nDownload the certificates and config from the bellow presigned URLs which will expire in 1 hour." say "\nCertificate:" say "\tcurl #{@certificate_url} > #{@options['client_cn']}.tar.gz", :cyan say "\nConfig:\n" say "\tcurl #{@config_url} > #{@name}.config.ovpn", :cyan say "\nExtract the certificates from the tar and place into a safe location." say "\ttar xzfv #{@options['client_cn']}.tar.gz -C <path> --strip 2", :cyan say "\nModify #{@name}.config.ovpn to include the full location of your extracted certificates" say "\techo \"key /<path>/#{@options['client_cn']}.key\" >> #{@name}.config.ovpn", :cyan say "\techo \"cert /<path>/#{@options['client_cn']}.crt\" >> #{@name}.config.ovpn", :cyan say "\nOpen #{@name}.config.ovpn with your favourite openvpn client." end
get_certificate_url()
click to toggle source
# File lib/cfnvpn/actions/share.rb, line 59 def get_certificate_url @certificate_url = @s3.get_url("#{@options['client_cn']}.tar.gz") CfnVpn::Log.logger.debug "Certificate presigned url: #{@certificate_url}" end
get_config_url()
click to toggle source
# File lib/cfnvpn/actions/share.rb, line 64 def get_config_url @config_url = @s3.get_url("#{@name}.config.ovpn") CfnVpn::Log.logger.debug "Config presigned url: #{@config_url}" end
set_loglevel()
click to toggle source
# File lib/cfnvpn/actions/share.rb, line 23 def set_loglevel CfnVpn::Log.logger.level = Logger::DEBUG if @options['verbose'] end
upload_config()
click to toggle source
# File lib/cfnvpn/actions/share.rb, line 54 def upload_config @s3 = CfnVpn::S3.new(@options['region'],@options['bucket'],@name) @s3.store_config(@config) end