Project

General

Profile

« Previous | Next » 

Revision 157c68c9

Added by Marc Dequènes about 15 years ago

  • ID 157c68c922e40f82f4bf567b4139c48cb7eda82a

[evol] implement changing a zone

View differences:

postman
$: << "./lib"
#require 'socket'
#require 'fileutils'
#require 'tempfile'
require 'tempfile'
require 'shellwords'
require 'cyborghood/imap'
require 'cyborghood/mail'
......
ok = false
end
when "SET"
result.message = "Command not yet implemented."
case cmdline.shift.upcase
when "ZONE"
zone = cmdline.shift.downcase
dom = CyborgHood::DnsDomain.new(zone)
logger.info "User requesting zone content for '#{zone}'"
if dom.hosted?
if dom.managed_by? user
logger.info "User is manager of the zone"
srv_dns = CyborgHood::Services::DNS.new(zone)
content_ref = cmdline.shift.downcase
if content_ref =~ /^@(\d+)$/
part_ref = $1.to_i
if (1..refs.size).include? part_ref
part = refs[part_ref]
if part.content_type == "text/plain"
f = Tempfile.new(zone)
f.write(part.body)
f.close
logger.debug "Created temporary zone file '#{f.path}'"
srv_dns = CyborgHood::Services::DNS.new(zone)
current_serial = srv_dns.serial
logger.debug "Current serial: #{current_serial}"
result = srv_dns.check_zone_file(f.path)
if result.ok
logger.debug "New serial: #{result.serial}"
# allow new serial or missing serial (to allow creating a new zone or replacing a broken zone)
if current_serial.nil? or result.serial > current_serial
begin
srv_dns.write_zone_from_file(f.path)
logger.info "zone changed"
rescue
logger.debug "Writing zone file failed"
raise
ensure
f.close!
end
else
logger.info "zone serial is not superior to current serial"
result.message = "Zone serial is not superior to current serial."
f.close!
return result
end
else
logger.info "new zone file is invalid"
result.message = "invalid zone data"
f.close!
return result
end
f.close!
else
logger.info "attachment for zone is not plain text"
result.message = "Attachment has wrong type."
return result
end
else
logger.info "attachement for zone not found"
result.message = "Attachment number not found."
return result
end
else
ok = false
end
else
logger.info "User is not allowed to manage the zone"
result.message = "You are not allowed to manage this zone."
end
else
logger.info "Zone not hosted"
result.message "This zone is not hosted here."
end
else
ok = false
end
else
ok = false
end

Also available in: Unified diff