Page Menu
Home
GRNET
Search
Configure Global Search
Log In
Files
F904708
No One
Temporary
Actions
View 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
Fri, Aug 29, 12:17 PM
Size
1 KB
Mime Type
text/x-diff
Expires
Sun, Aug 31, 12:17 PM (1 d, 12 h)
Engine
blob
Format
Raw Data
Handle
252006
Attached To
rWEBDNS WebDNS (edet4)
View Options
diff --git a/bin/import-dnssec-policy b/bin/import-dnssec-policy
new file mode 100755
index 0000000..886cbfc
--- /dev/null
+++ b/bin/import-dnssec-policy
@@ -0,0 +1,57 @@
+#!/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