Created
August 1, 2012 15:45
-
-
Save ntalbott/3227982 to your computer and use it in GitHub Desktop.
Extends the connection timeout for a particular VPN
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
#!/usr/bin/env ruby | |
def usage(error=nil) | |
puts "Usage: sudo osxvpnfix </var/run/racoon/ip.conf> [lifetime]" | |
puts "Error: #{error}" | |
exit 1 | |
end | |
usage("Must be run as root.") unless(`whoami`.strip == "root") | |
path = ARGV[0] || usage("Path to the VPN's config is required.") | |
period = ARGV[1] || "24 hours" | |
usage("The VPN's config must exist.") unless(File.exist?(path)) | |
config = File.read(path) | |
# Create /etc directory if it doesn't exist | |
remote_config = "/etc/remote" | |
if !File.exist?(remote_config) | |
puts "Creating #{remote_config}" | |
require "fileutils" | |
FileUtils.mkdir_p(remote_config) | |
end | |
# Patch racoon config if needed | |
racoon_config = "/etc/racoon/racoon.conf" | |
if "" == `grep "/etc/remote" #{racoon_config}`.strip | |
puts "Patching #{racoon_config}" | |
File.open(racoon_config, 'a') do |f| | |
f.puts | |
f.puts %(include "/etc/remote/*.conf" ;) | |
end | |
end | |
# Modify and copy vpn config file | |
puts "Writing modified config file." | |
config.gsub!(/lifetime time \d+ \w+/, "lifetime time #{period}") | |
File.open("#{remote_config}/#{File.basename(path)}", "w") do |f| | |
f.write(config) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment