Sha256: ddd111c4a3fe69a2488985d0cfd1b93542092fa44f43312551bbb478343b3657

Contents?: true

Size: 1.15 KB

Versions: 17

Compression:

Stored size: 1.15 KB

Contents

module DnsOne; class Util
    
  DOM_REGEX = /^[a-z0-9]+([\-\.][a-z0-9]+)*\.[a-z]{2,32}$/i

  class << self
    def die msg
      Log.f msg
      exit 1
    end

    def run cmd
        puts "Running #{cmd}..."
        system cmd
    end

    def has_systemd?
        File.exist?(`which systemctl`.strip) && 
        File.writable?('/lib/systemd/system')
    end

    def ensure_sytemd
        unless has_systemd?
            STDERR.puts "Systemd not available. Aborting." 
            exit 1
        end
    end

    def match_root stat
        stat.uid == 0 && stat.gid == 0
    end

    def last_mod constant
      constant.to_s.split('::').last
    end

    def log_result ip_address, domain_name, res_class, rcode, resp_log, from_cache
      fields = []

      fields << domain_name
      fields << Util.last_mod(res_class)
      fields << rcode
      fields << resp_log.map{ |rec|
          Util.last_mod(rec.res_class) + 
          ':' +
          [rec.val].flatten.join(',')
      }.join(';')
      fields << ip_address
      fields << (from_cache ? '1' : '0')

      fields.map!{|v| v.blank? ? '-' : v}

      Log.i "result: #{ fields.join ' ' }"
    end
  end 

end; end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
dns_one-0.5.2 lib/dns_one/util.rb
dns_one-0.5.1 lib/dns_one/util.rb
dns_one-0.5.0 lib/dns_one/util.rb
dns_one-0.4.66 lib/dns_one/util.rb
dns_one-0.4.666 lib/dns_one/util.rb
dns_one-0.4.65 lib/dns_one/util.rb
dns_one-0.4.64 lib/dns_one/util.rb
dns_one-0.4.63 lib/dns_one/util.rb
dns_one-0.4.62 lib/dns_one/util.rb
dns_one-0.4.61 lib/dns_one/util.rb
dns_one-0.4.60 lib/dns_one/util.rb
dns_one-0.4.59 lib/dns_one/util.rb
dns_one-0.4.58 lib/dns_one/util.rb
dns_one-0.4.57 lib/dns_one/util.rb
dns_one-0.4.56 lib/dns_one/util.rb
dns_one-0.4.55 lib/dns_one/util.rb
dns_one-0.4.54 lib/dns_one/util.rb