lib/application.rb in torrific-0.0.2 vs lib/application.rb in torrific-0.9.0
- old
+ new
@@ -2,33 +2,58 @@
require 'torrific'
module Torrific
class Application
class << self
- attr_accessor :password, :port, :host
+ attr_accessor :password, :port, :host, :interval, :daemonize, :tor_controller
def run
self.parse_options
+
+ Process.daemon if self.daemonize
- tor = TorControl.new(host: self.host, port: self.port, password: self.password)
- tor.change_ip
+ trap('SIGINT') do
+ puts "Bye Bye!"
+ exit
+ end
+
+ self.tor_controller = TorControl.new(host: self.host, port: self.port, password: self.password)
+
+ while true
+ self.tor_controller.change_ip
+ puts "Your identity has been changed."
+ if(self.interval && self.interval > 0)
+ sleep self.interval
+ else
+ break
+ end
+ end
end
def parse_options
options = OptionParser.new do |opts|
opts.banner = "Usage: torrific [options]"
opts.on("--password PASSWORD",
- "Sets the authentication password(default is nil)") do |pass=nil|
+ "Sets the authentication password(default is nil)") do |pass|
self.password = pass
end
- opts.on("--host HOST", "Tor Control host(default is localhost)") do |host='127.0.0.1'|
+ opts.on("--host HOST", "Tor Control host(default is localhost)") do |host|
self.host = host
end
opts.on("--port PORT",
- "Tor Control port(default is 9051).") do |port=9051|
+ "Tor Control port(default is 9051).") do |port|
self.port = port
+ end
+
+ opts.on("--interval INT",
+ "Changes identity each INT seconds.(default is only once)") do |seconds|
+ self.interval = seconds.to_i
+ end
+
+ opts.on("-d", "Daemonize the process") do
+ self.daemonize = true
end
end
options.parse!
end
\ No newline at end of file