Class: Sheepsafe::Installer
- Inherits:
-
Object
- Object
- Sheepsafe::Installer
- Defined in:
- lib/sheepsafe/installer.rb
Constant Summary collapse
- PLIST_FILE =
File.("~/Library/LaunchAgents/sheepsafe.plist")
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
-
#network ⇒ Object
readonly
Returns the value of attribute network.
Instance Method Summary collapse
- #add ⇒ Object
- #announce_done ⇒ Object
- #config_prompts ⇒ Object
-
#initialize(config = nil, network = nil, controller = nil) ⇒ Installer
constructor
A new instance of Installer.
- #install ⇒ Object
- #intro_message ⇒ Object
- #list ⇒ Object
-
#register_launchd_task ⇒ Object
Register the task with launchd.
- #setup_network_location ⇒ Object
- #uninstall ⇒ Object
- #update ⇒ Object
- #write_config ⇒ Object
-
#write_launchd_plist ⇒ Object
Write a launchd plist file to .~/Library/LaunchAgents/sheepsafe.plist.
Constructor Details
#initialize(config = nil, network = nil, controller = nil) ⇒ Installer
Returns a new instance of Installer.
7 8 9 10 11 12 13 |
# File 'lib/sheepsafe/installer.rb', line 7 def initialize(config = nil, network = nil, controller = nil) require 'highline/import' @config = config || (File.readable?(Sheepsafe::Config::FILE) ? Sheepsafe::Config.new : Sheepsafe::Config.new({})) @network = network || Sheepsafe::Network.new(@config) @controller = controller || Sheepsafe::Controller.new(@config, @network, Logger.new(Sheepsafe::Controller::LOG_FILE)) update_config_with_network end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'lib/sheepsafe/installer.rb', line 5 def config @config end |
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
5 6 7 |
# File 'lib/sheepsafe/installer.rb', line 5 def controller @controller end |
#network ⇒ Object (readonly)
Returns the value of attribute network.
5 6 7 |
# File 'lib/sheepsafe/installer.rb', line 5 def network @network end |
Instance Method Details
#add ⇒ Object
146 147 148 149 150 151 152 |
# File 'lib/sheepsafe/installer.rb', line 146 def add @config.trusted_names << @network.ssid @config.last_network = nil say "Adding #{config.trusted_names[num]} to your trusted locations" write_config @controller.run end |
#announce_done ⇒ Object
121 122 123 124 |
# File 'lib/sheepsafe/installer.rb', line 121 def announce_done controller.run # Choose the right network and get things going say("Sheepsafe installation done!") end |
#config_prompts ⇒ Object
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 60 61 62 |
# File 'lib/sheepsafe/installer.rb', line 34 def config_prompts say "First thing we need is the name of a server you can reach via SSH." config.ssh_host = ask "SSH connection (server name or user@server) >\n" do |q| q.default = config.ssh_host end config.ssh_port = ask "SSH Port >\n" do |q| q.default = config.ssh_port || 22 end say "Testing connectivitity to #{config.ssh_host}..." system "ssh -p #{config.ssh_port} #{config.ssh_host} true" unless $?.success? abort "Sorry! that ssh host was no good." end config.socks_port = ask "Ok, next we need to pick a port on localhost where the proxy runs >\n" do |q| q.default = config.socks_port || 9999 end config.trusted_location = ask "Next, a name for the \"trusted\" network location >\n" do |q| q.default = config.trusted_location end config.trusted_names = ask "Next, one or more trusted network names/SSIDs (comma-separated) >\n" do |q| q.default = @names.join(',') end.split(",").map(&:strip) end |
#install ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/sheepsafe/installer.rb', line 15 def install config_prompts setup_network_location write_config write_launchd_plist register_launchd_task announce_done end |
#intro_message ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/sheepsafe/installer.rb', line 25 def say(<<-MSG) Welcome to Sheepsafe! So you want to protect yourself from FireSheep snoopers like me, eh? Follow the prompts to get started. MSG end |
#list ⇒ Object
154 155 156 157 |
# File 'lib/sheepsafe/installer.rb', line 154 def list say "Currently trusted locations:" puts @config.trusted_names end |
#register_launchd_task ⇒ Object
Register the task with launchd.
116 117 118 119 |
# File 'lib/sheepsafe/installer.rb', line 116 def register_launchd_task say "Registering #{PLIST_FILE}" system "launchctl load #{PLIST_FILE}" end |
#setup_network_location ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/sheepsafe/installer.rb', line 64 def setup_network_location if `networksetup -listlocations` !~ /Untrusted/m && agree("Next, I'll create and switch to the \"Untrusted\" location in Network Preferences. OK\? (yes/no)\n") system "networksetup -createlocation Untrusted populate" end if agree "Next, I'll set up the SOCKS proxy in the \"Untrusted\" location for you. OK\? (yes/no)\n" system "networksetup -switchtolocation Untrusted" system "networksetup -setsocksfirewallproxy AirPort localhost #{config.socks_port}" end end |
#uninstall ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/sheepsafe/installer.rb', line 126 def uninstall if controller.proxy_running? say "Shutting down SOCKS proxy..." controller.bring_socks_proxy 'down' end if File.exist?(PLIST_FILE) say "Uninstalling Sheepsafe from launchd..." system "launchctl unload #{PLIST_FILE}" File.unlink PLIST_FILE rescue nil end Dir['~/.sheepsafe.*'].each {|f| File.unlink f rescue nil} say "Uninstall finished." end |
#update ⇒ Object
140 141 142 143 144 |
# File 'lib/sheepsafe/installer.rb', line 140 def update system "launchctl unload #{PLIST_FILE}" write_launchd_plist register_launchd_task end |
#write_config ⇒ Object
76 77 78 79 |
# File 'lib/sheepsafe/installer.rb', line 76 def write_config say "Saving configuration to #{Sheepsafe::Config::FILE}..." config.write end |
#write_launchd_plist ⇒ Object
Write a launchd plist file to .~/Library/LaunchAgents/sheepsafe.plist.
For details see tech.inhelsinki.nl/locationchanger/
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/sheepsafe/installer.rb', line 84 def write_launchd_plist say "Setting up launchd configuration file #{PLIST_FILE}..." Dir.mkdir(File.dirname(PLIST_FILE)) unless File.directory?(File.dirname(PLIST_FILE)) plist = <<-PLIST <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>org.rubygems.sheepsafe</string> <key>ProgramArguments</key> <array> <string>#{sheepsafe_bin_path}</string> </array> <key>WatchPaths</key> <array> <string>/Library/Preferences/SystemConfiguration</string> </array> <!-- We specify PATH here because /usr/local/bin, where grownotify --> <!-- is usually installed, is not in the script path by default. --> <key>EnvironmentVariables</key> <dict> <key>PATH</key><string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/bin</string> </dict> </dict> </plist> PLIST File.open(PLIST_FILE, "w") {|f| f << plist } end |