Last active
March 21, 2024 00:59
-
-
Save chrisboulton/5957284 to your computer and use it in GitHub Desktop.
Quickly convert all of your Viscosity connections into OVPN configuration files for OpenVPN for iOS (bundles certificates and keys in the files too)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
config_files = Dir.glob("#{ENV['HOME']}/Library/Application Support/Viscosity/OpenVPN/*/config.conf") | |
config_files.each do |file| | |
certificate_files = ['ca', 'cert', 'key', 'tls-auth'] | |
config_dir = File.dirname(file) | |
connection_name = nil | |
new_config = [] | |
File.read(file).each do |line| | |
line.strip! | |
if line.start_with?('#viscosity name') | |
connection_name = line.match(/^#viscosity name (.*)/)[1] | |
next | |
end | |
next if line.start_with?('#') | |
(key, value) = line.split(/\s+/, 2) | |
if certificate_files.include?(key) | |
# Special case for tls-auth which is "key direction" | |
if key == 'tls-auth' | |
# add direction to config | |
(value, direction) = value.split(/\s+/) | |
new_config << "key-direction #{direction}" unless direction.nil? | |
end | |
certificate = File.read("#{config_dir}/#{value}") | |
new_config << "<#{key}>" | |
new_config << certificate | |
new_config << "</#{key}>" | |
next | |
end | |
new_config << line | |
end | |
raise "Unable to find connection name in #{file}. Aborting." if connection_name.nil? | |
new_config.unshift("# OpenVPN Config for #{connection_name}") | |
out_file = "#{connection_name}.ovpn" | |
File.open(out_file, 'w') { |f| f.write(new_config.join("\n") + "\n") } | |
puts "wrote #{out_file}" | |
end |
awesome!! this worked on a mac with the change above, thanks for the script!
Fixed the error on line 8 https://gist.github.com/iMerica/dfb1be6e2f664c716756
Worked perfectly after the change in line 8 on mac! @chrisboulton & Abder88. . Kudos ! !
Worked on my Windows machine to create an .ovpn file for the OpenVPN Connect app on my Android phone. Thanks!
Thank you very much! Allowed me to import a client VPN config into OpenVPn on ipad pro. Total lifesaver before a long flight!
Thank you, still works great with the line edit.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
change line 8 from: File.read(file).each do |line| to File.read(file).each_line do |line|