Class: Ronin::DNS::Proxy::Rule Private

Inherits:
Object
  • Object
show all
Defined in:
lib/ronin/dns/proxy/rule.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Represents a DNS rule for the DNS Server.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, name, result = nil) {|type, name, transaction| ... } ⇒ Rule

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializes the DNS rule.

Parameters:

  • type (:A, :AAAA, :ANY, :CNAME, :HINFO, :LOC, :MINFO, :MX, :NS, :PTR, :SOA, :SRV, :TXT, :WKS)

    The rule's record type.

  • name (String, Regexp)

    The rule's name to match.

  • result (String, Array<String>, Symbol, #call) (defaults to: nil)

    The result to return.

Yields:

  • (type, name, transaction)

    If no result argument is given, the given block will be passed the DNS query's type, name, and transaction object.

Yield Parameters:

  • type (Symbol)

    The query type.

  • name (String)

    The queried host name.

  • transaction (Async::DNS::Transaction)

    The DNS query transaction object.

Raises:

  • (ArgumentError)

    Must specify a result argument or a block.



74
75
76
77
78
79
80
81
82
# File 'lib/ronin/dns/proxy/rule.rb', line 74

def initialize(type,name,result=nil,&block)
  unless (result || block)
    raise(ArgumentError,"must specify a result value or a block")
  end

  @type   = type
  @name   = name
  @result = result || block
end

Instance Attribute Details

#nameString, Regexp (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The record name or regex to match.

Returns:

  • (String, Regexp)


39
40
41
# File 'lib/ronin/dns/proxy/rule.rb', line 39

def name
  @name
end

#resultString, ... (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The result to return.

Returns:

  • (String, Array<String>, Symbol, #call)


44
45
46
# File 'lib/ronin/dns/proxy/rule.rb', line 44

def result
  @result
end

#type:A, ... (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The record type to match.

Returns:

  • (:A, :AAAA, :ANY, :CNAME, :HINFO, :LOC, :MINFO, :MX, :NS, :PTR, :SOA, :SRV, :TXT, :WKS)


34
35
36
# File 'lib/ronin/dns/proxy/rule.rb', line 34

def type
  @type
end

Instance Method Details

#call(query_type, query_name, transaction) ⇒ Async::DNS::Transaction

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Invokes the rule with the given query type, query name, and DNS transaction object.

Parameters:

  • query_type (:A, :AAAA, :ANY, :CNAME, :HINFO, :LOC, :MINFO, :MX, :NS, :PTR, :SOA, :SRV, :TXT, :WKS)

    The query's type (ex: :A).

  • query_name (String)

    The query's name (ex: 'www.example.com').

Returns:

  • (Async::DNS::Transaction)

    transaction The DNS query transaction.



113
114
115
116
117
118
119
120
121
# File 'lib/ronin/dns/proxy/rule.rb', line 113

def call(query_type,query_name,transaction)
  if @result.respond_to?(:call)
    @result.call(query_type,query_name,transaction)
  elsif @result.kind_of?(Symbol)
    transaction.fail!(@result)
  elsif @result
    transaction.respond!(@result)
  end
end

#matches?(query_type, query_name) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Determines if the rule matches the query type and query name.

Parameters:

  • query_type (:A, :AAAA, :ANY, :CNAME, :HINFO, :LOC, :MINFO, :MX, :NS, :PTR, :SOA, :SRV, :TXT, :WKS)

    The query's type (ex: :A).

  • query_name (String)

    The query's name (ex: 'www.example.com').

Returns:

  • (Boolean)

    Indicates whether the rule matches the query.



96
97
98
# File 'lib/ronin/dns/proxy/rule.rb', line 96

def matches?(query_type,query_name)
  (@type == query_type) && (@name === query_name)
end