Class: Proxy::Dns::Dnsmasq::Openwrt
- Defined in:
- lib/smart_proxy_dns_dnsmasq/backend/openwrt.rb
Defined Under Namespace
Classes: DSL
Instance Attribute Summary collapse
-
#config_file ⇒ Object
readonly
Returns the value of attribute config_file.
-
#dirty ⇒ Object
readonly
Returns the value of attribute dirty.
-
#reload_cmd ⇒ Object
readonly
Returns the value of attribute reload_cmd.
Instance Method Summary collapse
- #add_cname(name, canonical) ⇒ Object
- #add_entry(type, fqdn, ip) ⇒ Object
-
#initialize(config, reload_cmd, dns_ttl) ⇒ Openwrt
constructor
A new instance of Openwrt.
- #remove_cname(name) ⇒ Object
- #remove_entry(type, fqdn = nil, ip = nil) ⇒ Object
- #update! ⇒ Object
Methods inherited from Record
Constructor Details
#initialize(config, reload_cmd, dns_ttl) ⇒ Openwrt
Returns a new instance of Openwrt.
7 8 9 10 11 12 13 |
# File 'lib/smart_proxy_dns_dnsmasq/backend/openwrt.rb', line 7 def initialize(config, reload_cmd, dns_ttl) @config_file = config @reload_cmd = reload_cmd @dirty = false super(dns_ttl) end |
Instance Attribute Details
#config_file ⇒ Object (readonly)
Returns the value of attribute config_file.
5 6 7 |
# File 'lib/smart_proxy_dns_dnsmasq/backend/openwrt.rb', line 5 def config_file @config_file end |
#dirty ⇒ Object (readonly)
Returns the value of attribute dirty.
5 6 7 |
# File 'lib/smart_proxy_dns_dnsmasq/backend/openwrt.rb', line 5 def dirty @dirty end |
#reload_cmd ⇒ Object (readonly)
Returns the value of attribute reload_cmd.
5 6 7 |
# File 'lib/smart_proxy_dns_dnsmasq/backend/openwrt.rb', line 5 def reload_cmd @reload_cmd end |
Instance Method Details
#add_cname(name, canonical) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/smart_proxy_dns_dnsmasq/backend/openwrt.rb', line 45 def add_cname(name, canonical) found = find_type(:cname, :name, name) return true if found && found.[:target] == canonical c = found c = DSL::Config.new :cname unless c c.[:cname] = name c.[:target] = canonical configuration << c unless found @dirty = true end |
#add_entry(type, fqdn, ip) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/smart_proxy_dns_dnsmasq/backend/openwrt.rb', line 23 def add_entry(type, fqdn, ip) raise Proxy::Dns::Error, "OpenWRT UCI can't manage IPv6 entries" if type == 'AAAA' || type == 'PTR' && IPAddr.new(ip).ipv6? found = find_type(:domain, :name, fqdn) return true if found && found.[:ip] == ip h = found h = DSL::Config.new :domain unless h h.[:name] = fqdn h.[:ip] = ip configuration << h unless found @dirty = true end |
#remove_cname(name) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/smart_proxy_dns_dnsmasq/backend/openwrt.rb', line 58 def remove_cname(name) return true unless c = find_type(:cname, :name, name) configuration.delete c @dirty = true end |
#remove_entry(type, fqdn = nil, ip = nil) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/smart_proxy_dns_dnsmasq/backend/openwrt.rb', line 37 def remove_entry(type, fqdn = nil, ip = nil) raise Proxy::Dns::Error, "OpenWRT UCI can't manage IPv6 entries" if type == 'AAAA' || type == 'PTR' && IPAddr.new(ip).ipv6? return true unless h = find_type(:domain, fqdn && :name || :ip, fqdn || ip) configuration.delete h @dirty = true end |
#update! ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/smart_proxy_dns_dnsmasq/backend/openwrt.rb', line 15 def update! return unless @dirty @dirty = false File.write(@config_file, "\n" + configuration.join("\n") + "\n") system(@reload_cmd) end |