Class: Dyndnsd::Daemon

Inherits:
Object
  • Object
show all
Defined in:
lib/dyndnsd.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, db, updater) ⇒ Daemon

Returns a new instance of Daemon.

Parameters:



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/dyndnsd.rb', line 53

def initialize(config, db, updater)
  @users = config['users']
  @domain = config['domain']
  @db = db
  @updater = updater

  @db.load
  @db['serial'] ||= 1
  @db['hosts'] ||= {}
  @updater.update(@db)
  if @db.changed?
    @db.save
  end
end

Class Method Details

.run!void

This method returns an undefined value.



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/dyndnsd.rb', line 94

def self.run!
  if ARGV.length != 1
    puts 'Usage: dyndnsd config_file'
    exit 1
  end

  config_file = ARGV[0]

  if !File.file?(config_file)
    puts 'Config file not found!'
    exit 1
  end

  puts "DynDNSd version #{Dyndnsd::VERSION}"
  puts "Using config file #{config_file}"

  config = YAML.safe_load_file(config_file)

  setup_logger(config)

  Dyndnsd.logger.info 'Starting...'

  # drop privileges as soon as possible
  # NOTE: first change group than user
  if config['group']
    group = Etc.getgrnam(config['group'])
    Process::Sys.setgid(group.gid) if group
  end
  if config['user']
    user = Etc.getpwnam(config['user'])
    Process::Sys.setuid(user.uid) if user
  end

  setup_traps

  setup_monitoring(config)

  setup_tracing(config)

  setup_rack(config)
end

Instance Method Details

#authorized?(username, password) ⇒ Boolean

Parameters:

  • username (String)
  • password (String)

Returns:

  • (Boolean)


71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/dyndnsd.rb', line 71

def authorized?(username, password)
  Helper.span('check_authorized') do |span|
    span.set_attribute('enduser.id', username)

    allow = Helper.user_allowed?(username, password, @users)
    if !allow
      Dyndnsd.logger.warn "Login failed for #{username}"
      Metriks.meter('requests.auth_failed').mark
    end
    allow
  end
end

#call(env) ⇒ Array{Integer,Hash{String => String},Array<String>}

Parameters:

  • env (Hash{String => String})

Returns:

  • (Array{Integer,Hash{String => String},Array<String>})


86
87
88
89
90
91
# File 'lib/dyndnsd.rb', line 86

def call(env)
  return [422, {'X-DynDNS-Response' => 'method_forbidden'}, []] if env['REQUEST_METHOD'] != 'GET'
  return [422, {'X-DynDNS-Response' => 'not_found'}, []] if env['PATH_INFO'] != '/nic/update'

  handle_dyndns_request(env)
end