Module: Radd
- Defined in:
- lib/radd.rb,
lib/radd/ip.rb,
lib/radd/config.rb,
lib/radd/errors.rb,
lib/radd/update.rb,
lib/radd/version.rb
Defined Under Namespace
Modules: Cli
Classes: ConfigurationError, DNS, DNSService, Forbidden, HTTP, HTTPService, InvalidRequest, Nameserver, RaddError, Record, Update, UpdateError, Webserver
Constant Summary
collapse
- IP =
IP address query responder
Proc.new do |env|
[200, {"Content-Type" => "text/plain"}, [env['REMOTE_ADDR']]]
end
- App =
Rack::Builder.app do
map '/ip' do
run Radd::IP
end
map '/update' do
use Rack::Auth::Basic, 'Authorization required' do |user, password|
Radd.authorized?(user, password)
end
run Radd::Update
end
end
- VERSION =
'1.2.0'
Class Method Summary
collapse
Class Method Details
.authorized?(name, password) ⇒ Boolean
Check whether name is authorized with password
33
34
35
36
|
# File 'lib/radd.rb', line 33
def authorized?(name, password)
return false unless record = Record.where(name: name).first
BCrypt::Password.new(record.password_hash) == password
end
|
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/radd/config.rb', line 4
def configure!(file)
file_path = Pathname.new(file || 'radd.yml')
file_path = Radd.root + file_path unless file_path.absolute?
raise Radd::ConfigurationError, "could not open config file #{file_path}" unless file_path.file?
@config = YAML.load(file_path.read).slice(*%w[domain ip host dns_port http_port db])
raise Radd::ConfigurationError, 'domain missing' unless Radd.domain
raise Radd::ConfigurationError, 'invalid IP' unless Radd.valid_ip?(Radd.ip)
db_path = Pathname.new(@config.delete('db') || 'db/radd.sqlite3')
db_path = Radd.root + db_path unless db_path.absolute?
@config['db'] = db_path
raise Radd::ConfigurationError, 'invalid database' unless Radd.db.file?
require_relative 'db'
require_relative 'record'
end
|
.db ⇒ Object
28
29
30
|
# File 'lib/radd/config.rb', line 28
def db
@config['db']
end
|
.dns_port ⇒ Object
36
37
38
|
# File 'lib/radd/config.rb', line 36
def dns_port
@config['dns_port'] || 5300
end
|
.domain ⇒ Object
20
21
22
|
# File 'lib/radd/config.rb', line 20
def domain
@config['domain']
end
|
.host ⇒ Object
32
33
34
|
# File 'lib/radd/config.rb', line 32
def host
@config['host'] || '127.0.0.1'
end
|
.http_port ⇒ Object
40
41
42
|
# File 'lib/radd/config.rb', line 40
def http_port
@config['http_port'] || 3000
end
|
.ip ⇒ Object
24
25
26
|
# File 'lib/radd/config.rb', line 24
def ip
@config['ip']
end
|
.query(fqdn) ⇒ Object
Query the database for fqdn
39
40
41
42
43
44
|
# File 'lib/radd.rb', line 39
def query(fqdn)
return unless fqdn
return unless name = fqdn2name(fqdn)
return unless record = Record.active.where(name: name).first
record.ip
end
|
.root ⇒ Object
28
29
30
|
# File 'lib/radd.rb', line 28
def root
@root ||= Pathname.new(Dir.pwd)
end
|
.root=(path) ⇒ Object
24
25
26
|
# File 'lib/radd.rb', line 24
def root=(path)
@root = Pathname.new(path)
end
|
.valid_ip?(ip) ⇒ Boolean
Check whether ip is a valid IP address string
45
46
47
|
# File 'lib/radd/config.rb', line 45
def valid_ip?(ip)
!!(ip && ip.match(Resolv::IPv4::Regex))
end
|