Class: SiriProxy::Dns
- Inherits:
-
Object
- Object
- SiriProxy::Dns
- Defined in:
- lib/siriproxy/dns.rb
Instance Attribute Summary collapse
-
#interfaces ⇒ Object
Returns the value of attribute interfaces.
-
#thread ⇒ Object
Returns the value of attribute thread.
-
#upstream ⇒ Object
Returns the value of attribute upstream.
Instance Method Summary collapse
-
#initialize ⇒ Dns
constructor
A new instance of Dns.
- #run(log_level = Logger::WARN, server_ip = $APP_CONFIG.server_ip) ⇒ Object
- #start(log_level = Logger::WARN) ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize ⇒ Dns
Returns a new instance of Dns.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/siriproxy/dns.rb', line 6 def initialize @interfaces = [ [:tcp, "0.0.0.0", 53], [:udp, "0.0.0.0", 53] ] servers = [] $APP_CONFIG.upstream_dns.each { |dns_addr| servers << [:udp, dns_addr, 53] servers << [:tcp, dns_addr, 53] } @upstream = RubyDNS::Resolver.new(servers) end |
Instance Attribute Details
#interfaces ⇒ Object
Returns the value of attribute interfaces.
4 5 6 |
# File 'lib/siriproxy/dns.rb', line 4 def interfaces @interfaces end |
#thread ⇒ Object
Returns the value of attribute thread.
4 5 6 |
# File 'lib/siriproxy/dns.rb', line 4 def thread @thread end |
#upstream ⇒ Object
Returns the value of attribute upstream.
4 5 6 |
# File 'lib/siriproxy/dns.rb', line 4 def upstream @upstream end |
Instance Method Details
#run(log_level = Logger::WARN, server_ip = $APP_CONFIG.server_ip) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/siriproxy/dns.rb', line 48 def run(log_level=Logger::WARN,server_ip=$APP_CONFIG.server_ip) if server_ip upstream = @upstream # Start the RubyDNS server RubyDNS::run_server(:listen => @interfaces) do @logger.level = log_level match(/guzzoni.apple.com/, Resolv::DNS::Resource::IN::A) do |transaction| transaction.respond!(server_ip) end # Default DNS handler otherwise do |transaction| transaction.passthrough!(upstream) end end puts "[Info - Server] DNS Server started, tainting 'guzzoni.apple.com' with #{server_ip}" end end |
#start(log_level = Logger::WARN) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/siriproxy/dns.rb', line 22 def start(log_level=Logger::WARN) @thread = Thread.new { begin self.run(log_level) $SP_DNS_STARTED = true rescue RuntimeError => e if e..match /^no acceptor/ puts "[Error - Server] Either you're not root or tcp/udp port 53 is in use. DNS server is disabled" $SP_DNS_STARTED = true #Yeah, it didn't start, but we don't want to sit around and wait for it. else puts "[Error - Server] DNS Error: #{e.}" puts "[Error - Server] DNS Server has crashed. Terminating SiriProxy" exit 1 end rescue Exception => e puts "[Error - Server] DNS Error: #{e.}" puts "[Error - Server] DNS Server has crashed. Terminating SiriProxy" exit 1 end } end |
#stop ⇒ Object
44 45 46 |
# File 'lib/siriproxy/dns.rb', line 44 def stop Thread.kill(@thread) end |