Page Menu
Home
GRNET
Search
Configure Global Search
Log In
Files
F906854
worker.rb
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Aug 30, 10:55 AM
Size
2 KB
Mime Type
text/x-ruby
Expires
Mon, Sep 1, 10:55 AM (19 h, 20 m)
Engine
blob
Format
Raw Data
Handle
253365
Attached To
rWEBDNS WebDNS (edet4)
worker.rb
View Options
require
'json'
require
'net/http'
require
'uri'
require
'pp'
require
'rack/utils'
require
'dnsworker'
require
'dnsworker/base_worker'
require
'dnsworker/pushers/base'
require
'dnsworker/pushers/papaki'
require
'dnsworker/pushers/webdns'
class
DNSWorker
::
Worker
include
DNSWorker
::
BaseWorker
Pushers
=
Hash
[
:papaki
,
DNSWorker
::
Pushers
::
Papaki
,
:webdns
,
DNSWorker
::
Pushers
::
Webdns
,
]
def
initialize
(
cfg
)
@cfg
=
cfg
super
(
cfg
[
'mysql'
]
)
end
def
add_domain
(
params
)
params
[
:master
]
=
cfg
[
'hidden_master'
]
cmd
(
cfg
[
'bind_add'
]
%
params
)
end
def
remove_domain
(
params
)
cmd
(
cfg
[
'bind_del'
]
%
params
)
end
def
opendnssec_add
(
params
)
cmd
(
cfg
[
'ods_add'
]
%
params
)
end
def
opendnssec_remove
(
params
)
cmd
(
cfg
[
'ods_del'
]
%
params
)
end
def
bind_convert_to_dnssec
(
params
)
fail
Retry
if
!
File
.
exist?
File
.
join
(
cfg
[
'zone_root'
]
,
'signed'
,
params
[
:zone
]
)
# Remove zone and re-add it as a master zone
remove_domain
(
params
)
cmd
(
cfg
[
'bind_add_dnssec'
]
%
params
)
end
# The zone is signed, waiting for the ksk to become ready
def
wait_for_ready_to_push_ds
(
params
)
out
,
_err
=
cmd
(
cfg
[
'ready_to_push_ds'
]
%
params
)
fail
Retry
unless
out
[
'ds-seen'
]
end
def
publish_ds
(
params
)
pub_cls
=
Pushers
[
params
[
:dnssec_parent_authority
].
to_sym
]
fail
JobFailed
unless
pub_cls
pub
=
pub_cls
.
new
(
cfg
)
fail
JobFailed
unless
pub
.
replace_ds
(
params
[
:dnssec_parent
]
,
params
[
:zone
]
,
params
[
:dss
]
)
end
def
wait_for_active
(
params
)
keytag
=
params
[
:keytag
]
out
,
_err
=
cmd
(
cfg
[
'key_activated'
]
%
params
)
key_lines
=
out
.
each_line
.
select
{
|
line
|
line
.
start_with?
(
params
[
:zone
]
)
}
# Check if the key is activated
return
if
key_lines
.
any?
{
|
kl
|
# example
# <domain> KSK active 2016-12-12 18:41:33 (retire) 2048 8 b70042f966e5f01deb2e988607ad67ba SoftHSM 60076
kl
.
strip!
_domain
,
_type
,
status
,
_rest
=
kl
.
split
(
/\s+/
,
4
)
status
==
'active'
and
_rest
.
end_with?
(
keytag
)
}
fail
Retry
end
def
trigger_event
(
params
)
query
=
Rack
::
Utils
.
build_query
(
domain
:
params
[
:zone
]
,
event
:
params
[
:event
]
)
uri
=
URI
(
cfg
.
values_at
(
'webdns_base'
,
'update_state'
)
.
join
%
{
query
:
query
})
Net
::
HTTP
.
start
(
uri
.
host
,
uri
.
port
)
do
|
http
|
resp
=
http
.
request
Net
::
HTTP
::
Put
.
new
(
uri
.
request_uri
)
fail
JobFailed
if
resp
.
code
!=
'200'
ok
=
JSON
.
parse
(
resp
.
body
)
[
'ok'
]
fail
JobFailed
if
!
ok
end
end
private
def
cmdline
(
jtype
,
jargs
)
if
jargs
send
(
jtype
,
jargs
)
else
send
(
jtype
)
end
end
end
Event Timeline
Log In to Comment