sandboxer 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/README.md +2 -0
  2. data/lib/sandbox.rb +22 -4
  3. metadata +4 -4
data/README.md CHANGED
@@ -12,6 +12,8 @@ Available commands:
12
12
  * `sandbox on` — enables all saved entries
13
13
  * `sandbox off` — disables all saved entries
14
14
  * `sandbox status` — shows the current status of the tool (on/off status and current default destination IP)
15
+ * `sandbox list` — lists the sandboxed domains
16
+ * `sandbox view {domain}` - shows information on a sandboxed domain
15
17
 
16
18
  Note: if sandbox development is on, `add`, `remove`, and `clear` commands will immediately update the hosts file and trigger a DNS flush.
17
19
 
@@ -26,7 +26,7 @@ require 'digest/md5'
26
26
 
27
27
 
28
28
  class Sandbox
29
- VERSION = '0.1.3'
29
+ VERSION = '0.1.4'
30
30
  def initialize
31
31
  @debug = false
32
32
  @sandbox = '/etc/hosts-sandbox'
@@ -35,7 +35,7 @@ class Sandbox
35
35
  @default_destination = '127.0.0.1'
36
36
  @start = '#==SANDBOX==#'
37
37
  @end = '#/==SANDBOX==#'
38
- if !ARGV.first.nil? && [:on, :off, :add, :remove, :destination, :clear].include?( ARGV.first.to_sym )
38
+ if !ARGV.first.nil? && [:on, :off, :add, :remove, :destination, :clear, :list, :view].include?( ARGV.first.to_sym )
39
39
  require_sudo
40
40
  ensure_sandbox_exists
41
41
  end
@@ -46,8 +46,10 @@ class Sandbox
46
46
  case command
47
47
  when :"--v", :"--version"
48
48
  info
49
- when :on, :off, :status, :clear
49
+ when :on, :off, :status, :clear, :list
50
50
  send command
51
+ when :view
52
+ send command, object
51
53
  when :add
52
54
  require_sudo
53
55
  object.nil? && exit_error_message("'sandbox add' requires you to provide a domain. optionally you can provide an IP/destination.")
@@ -209,7 +211,6 @@ class Sandbox
209
211
  end
210
212
 
211
213
  def get_status
212
- # do magic
213
214
  status = :off
214
215
  return status unless File.readable? @hosts
215
216
  File.open( @hosts, 'r' ) do |file|
@@ -223,6 +224,23 @@ class Sandbox
223
224
  return status
224
225
  end
225
226
 
227
+ def list
228
+ File.open( @sandbox, 'r' ) do |file|
229
+ puts file.read
230
+ end
231
+ end
232
+
233
+ def view domain
234
+ entry = nil
235
+ File.open( @sandbox, 'r' ) do |entries|
236
+ if entries.read.find { |entry| /^#{domain}/ =~ entry }
237
+ puts "#{entry}"
238
+ else
239
+ puts "There is no entry matching '#{domain}'"
240
+ end
241
+ end
242
+ end
243
+
226
244
  def clear
227
245
  File.open( @sandbox, 'w' ) do |file|
228
246
  file.truncate(0)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sandboxer
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 3
10
- version: 0.1.3
9
+ - 4
10
+ version: 0.1.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Justin Shreve
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-01 00:00:00 Z
18
+ date: 2011-07-10 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: Sandbox manages part of your hosts file and lets you specify domains sandbox to point locally or remotely to. You can quickly enable or disable sandboxing of those domains.