Page Menu
Home
GRNET
Search
Configure Global Search
Log In
Files
F449081
import-dnssec-policy
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
Thu, Apr 24, 2:24 PM
Size
1 KB
Mime Type
text/x-ruby
Expires
Sat, Apr 26, 2:24 PM (1 d, 21 h)
Engine
blob
Format
Raw Data
Handle
212279
Attached To
rWEBDNS WebDNS (edet4)
import-dnssec-policy
View Options
#!/usr/bin/env ruby
require
'optparse'
require
'nokogiri'
options
=
{}
parser
=
OptionParser
.
new
do
|
opts
|
opts
.
on
(
'-l'
,
'--list'
,
'List policies'
)
do
|
v
|
options
[
:list
]
=
v
end
opts
.
on
(
'-s'
,
'--set POLICY'
,
'Create/Update policy (stdin)'
)
do
|
v
|
options
[
:policy
]
=
v
end
end
parser
.
parse!
if
options
.
empty?
$stderr
.
puts
parser
.
help
exit
1
end
if
options
[
:list
]
DnssecPolicy
.
all
.
each
{
|
policy
|
puts
"Policy:
#{
policy
.
name
}
"
puts
policy
.
policy
puts
}
elsif
policy
=
options
[
:policy
]
puts
"Reading from stdin (Output from `ods-ksmutil policy export --policy
#{
policy
}
`)"
policy_xml
=
ARGF
.
read
begin
Nokogiri
::
XML
(
policy_xml
)
{
|
config
|
config
.
strict
}
rescue
Nokogiri
::
XML
::
SyntaxError
$stderr
.
puts
"Error parsing XML..."
exit
1
end
policy
=
DnssecPolicy
.
find_or_initialize_by
(
name
:
policy
)
policy
.
policy
=
policy_xml
puts
if
policy
.
new_record?
puts
"Creating new policy '
#{
policy
.
name
}
'"
else
puts
"Updating existing policy '
#{
policy
.
name
}
'"
end
puts
'Are you sure you want to continue? (y/N)'
answer
=
gets
.
chomp
if
[
'y'
,
'Y'
].
include?
answer
policy
.
save!
puts
"Saved"
else
puts
"Not saved"
end
end
Event Timeline
Log In to Comment