Class: Unitard
- Inherits:
-
Thor
- Object
- Thor
- Unitard
- Defined in:
- lib/unitard.rb
Constant Summary collapse
- RULE_NUM =
4242
- PIPE_NUM =
7777
Instance Method Summary collapse
Instance Method Details
#status ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/unitard.rb', line 24 def status pipe_line = `sudo ipfw pipe show #{PIPE_NUM} 2>/dev/null`.split(/\n/).first iface_line = `sudo ipfw show #{RULE_NUM} 2>/dev/null`.split(/\n/).first if pipe_line && iface_line speed_limit = pipe_line.scan(/\d+\.\d+/).join iface = iface_line.scan(/^.*\s+([a-z]{2,3}\d+)$/).join say "Current limit is set to #{speed_limit} Kbits/sec via interface #{iface}", :green else say 'No matching rule found. Probably no limit was set by Unitard', :red end end |
#unzip(silent = false) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/unitard.rb', line 40 def unzip(silent=false) `sudo ipfw pipe delete #{PIPE_NUM} 2>&1 > /dev/null` and `sudo ipfw delete #{RULE_NUM} 2>&1 > /dev/null` unless silent say 'Phew! That was very skintight Unitard.', :green say '...all created by Unitard rules are deleted.', :blue end end |
#zip ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/unitard.rb', line 10 def zip unzip(true) if system("sudo ipfw pipe #{PIPE_NUM} config bw #{[:bw]}Kbit/s delay 30 plr 0 2>&1 > /dev/null") && system("sudo ipfw add #{RULE_NUM} pipe #{PIPE_NUM} ip from any to any via #{[:iface]} 2>&1 > /dev/null") say "speed throttled. Your skintight Unitard is ready. Really tight :) only #{[:bw]} Kbit/sec", :green else say "error - exit status #{$?.exitstatus}", :red end end |