Revision 7d701a64
Added by Marc Dequènes over 15 years ago
- ID 7d701a64a9255f47f5679d695a5bd8241d1d3600
bin/postman | ||
---|---|---|
reply_txt += _("Follows the transcript of your commands:") + "\n"
|
||
reply_attachments = []
|
||
result_list.each do |result|
|
||
reply_txt << "> #{result.cmd}\n"
|
||
reply_txt << "#{result.message}\n"
|
||
reply_txt += "> #{result.cmd}\n"
|
||
reply_txt += "#{result.message}\n"
|
||
reply_attachments += result.refs unless result.refs.nil?
|
||
end
|
||
reply_txt << mail_signature()
|
||
reply_txt += "\n" + mail_signature()
|
||
|
||
# create mail
|
||
logger.debug "Preparing mail"
|
||
... | ... | |
def self.run(order)
|
||
result_list = []
|
||
order.commands.each do |cmd|
|
||
result = OpenStruct.new
|
||
result.cmd = cmd.cmdline
|
||
result.ok = false
|
||
|
||
if cmd.valid?
|
||
logger.info "Executing command: #{cmd.cmdline}"
|
||
begin
|
||
result = execute_cmd(order.user, cmd.cmdsplit, order.shared_parameters)
|
||
if result.nil?
|
||
result = OpenStruct.new
|
||
result.cmd = cmd.cmdline
|
||
result.ok = false
|
||
result.message = _("Command not recognized.")
|
||
result.refs = nil
|
||
end
|
||
execute_cmd(order.user, cmd.cmdsplit, order.shared_parameters, result)
|
||
rescue CyberError => e
|
||
result = OpenStruct.new
|
||
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 = cmd.cmdline
|
||
result.ok = false
|
||
result.message = _("Internal error. Administrator is warned.")
|
||
result.refs = nil
|
||
end
|
||
|
||
tag = result.ok ? "SUCCESS" :"FAILURE"
|
||
logger.debug "Command result: [#{tag}] #{result.message}"
|
||
else
|
||
logger.info "Detected invalid command: #{cmd.cmdline}"
|
||
result = OpenStruct.new
|
||
result.cmd = cmd.cmdline
|
||
result.ok = false
|
||
logger.info "Invalid command detected: #{cmd.cmdline}"
|
||
result.message = cmd.parsing_errors.collect{|err| _(err) }.join("\n")
|
||
result.refs = nil
|
||
end
|
||
result_list << result
|
||
end
|
||
... | ... | |
|
||
private
|
||
|
||
def self.execute_cmd(user, cmdline, shared_parameters)
|
||
def self.execute_cmd(user, cmdline, shared_parameters, result)
|
||
subsys = cmdline.shift
|
||
|
||
result = OpenStruct.new
|
||
result.cmd = cmdline
|
||
result.ok = false
|
||
ok = true
|
||
case subsys.upcase
|
||
when "DNS"
|
||
return if cmdline.empty?
|
||
... | ... | |
|
||
if result.message.nil?
|
||
# here fall lost souls
|
||
nil
|
||
else
|
||
result
|
||
result.message = _("Command not recognized.")
|
||
end
|
||
end
|
||
end
|
Also available in: Unified diff
[fix] simplify command result handling and fix result.cmd not properly set