Project

General

Profile

« Previous | Next » 

Revision f0a75e9c

Added by Marc Dequènes over 15 years ago

  • ID f0a75e9c7874167708380ded63640b0f3f0229ea

[evol] commands management rework #1: moved command parsing into the Mail class, so the CommandParser is now a CommandRunner, and does not have to understand mail parts at all

View differences:

bin/postman
end
logger.debug "Message accepted, processing orders..."
result_list = CommandParser.run(order)
result_list = CommandRunner.run(order)
# create transcript
logger.debug "Preparing reply"
......
end
end
class CommandParser
class CommandRunner
include GetText
def self.run(order)
result_list = []
order.commands.each do |cmdstr|
logger.info "Executing command: #{cmdstr}"
order.commands.each do |cmd|
logger.info "Executing command: #{cmd.cmdline}"
begin
result = execute_cmd(order.user, cmdstr, order.references)
result = execute_cmd(order.user, cmd.cmdsplit, order.shared_params)
if result.nil?
result = OpenStruct.new
result.cmd = cmdstr
result.cmd = cmd.cmdline
result.ok = false
result.message = _("Command not recognized.")
result.refs = nil
end
rescue CyberError => e
result = OpenStruct.new
result.cmd = cmdstr
result.cmd = cmd.cmdline
result.ok = false
result.message = e.message.capitalize + "."
result.refs = nil
rescue
logger.warn "Command crashed: " + $!
result = OpenStruct.new
result.cmd = cmdstr
result.cmd = cmd.cmdline
result.ok = false
result.message = _("Internal error. Administrator is warned.")
result.refs = nil
......
private
def self.execute_cmd(user, cmdstr, refs)
cmdline = Shellwords.shellwords(cmdstr)
def self.execute_cmd(user, cmdline, shared_params)
subsys = cmdline.shift
result = OpenStruct.new
......
srv_dns = CyborgHood::Services::DNS.new(zone)
return if cmdline.empty?
content_ref = cmdline.shift.downcase
return unless content_ref =~ /^@(\d+)$/
part_ref = $1.to_i
unless (1..refs.size).include? part_ref
content_ref = cmdline.shift
if content_ref.nil?
result.message = _("Attachment number not found.")
return result
end
part = refs[part_ref]
unless part.content_type == "text/plain"
part = shared_params[content_ref]
unless part.type == "text/plain"
result.message = _("Attachment has wrong content-type.")
return result
end
f = Tempfile.new(zone)
f.write(part.body)
f.write(part.content)
f.close
logger.debug "Created temporary zone file '#{f.path}'"

Also available in: Unified diff