Project

General

Profile

« Previous | Next » 

Revision 7d9d434c

Added by Marc Dequènes about 14 years ago

  • ID 7d9d434c136ed48c8e96e9e0f3a0cef7d82f499b

[cleanup] moved CommandRunner out of 'bin/postman' and associated L10N strings

View differences:

bin/postman
require 'cyborghood/imap'
require 'cyborghood/mail'
require 'cyborghood/mail_order'
require 'cyborghood/objects'
require 'cyborghood/services/dns'
require 'cyborghood/command_runner'
#Socket.gethostname
......
s
end
end
class CommandRunner
include I18nTranslation
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
execute_cmd(order.user, cmd.cmdsplit, order.shared_parameters, result)
rescue CyberError => e
result.message = e.message.capitalize + "."
rescue
logger.error "Command crashed: " + $!
logger.error "Crash trace: " + $!.backtrace.join("\n")
result.message = _("Internal error. Administrator is warned.")
end
tag = result.ok ? "SUCCESS" : "FAILURE"
logger.debug "Command result: [#{tag}] #{result.message.untranslated}"
else
logger.info "Invalid command detected: #{cmd.cmdline}"
cmd.parsing_errors.collect{|err| logger.debug "Invalid command detected - reason: " + err.untranslated }
result.message = cmd.parsing_errors.collect{|err| err.to_s }.join("\n")
end
result_list << result
end
result_list
end
private
def self.execute_cmd(user, cmdline, shared_parameters, result)
subsys = cmdline.shift
case subsys.upcase
when "DNS"
return if cmdline.empty?
case cmdline.shift.upcase
when "INFO"
return unless cmdline.empty?
list = CyborgHood::DnsDomain.find_by_manager(user)
txt_list = list.collect{|z| z.cn }.sort.join(", ")
result.ok = true
result.message = _("You are manager of the following zones: %{zone_list}.", :zone_list => txt_list)
when "GET"
return if cmdline.empty?
case cmdline.shift.upcase
when "ZONE"
return if cmdline.empty?
zone = cmdline.shift.downcase
dom = CyborgHood::DnsDomain.new(zone)
unless dom.hosted?
result.message = _("This zone is not hosted here.")
return result
end
unless dom.managed_by? user
result.message = _("You are not allowed to manage this zone.")
return result
end
srv_dns = CyborgHood::Services::DNS.new(zone)
result.ok = true
result.message = _("Requested zone content attached.")
zone_ref = {:content => srv_dns.read_zone, :filename => "dnszone_#{zone}.txt"}.to_ostruct
result.refs = [zone_ref]
end
when "SET"
return if cmdline.empty?
case cmdline.shift.upcase
when "ZONE"
return if cmdline.empty?
zone = cmdline.shift.downcase
dom = CyborgHood::DnsDomain.new(zone)
unless dom.hosted?
result.message = _("This zone is not hosted here.")
return result
end
unless dom.managed_by? user
result.message = _("You are not allowed to manage this zone.")
return result
end
srv_dns = CyborgHood::Services::DNS.new(zone)
return if cmdline.empty?
content_ref = cmdline.shift
part = shared_parameters[content_ref]
unless part.type == "text/plain"
result.message = _("Attachment has wrong content-type.")
return result
end
f = Tempfile.new(zone)
f.write(part.content)
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}"
dns_result = srv_dns.check_zone_file(f.path)
unless dns_result.ok
result.message = _("Invalid zone data.")
f.close!
return result
end
logger.debug "New serial: #{dns_result.serial}"
# allow new serial or missing serial (to allow creating a new zone or replacing a broken zone)
unless current_serial.nil? or dns_result.serial > current_serial
result.message = _("Zone serial is not superior to current serial.")
f.close!
return result
end
begin
srv_dns.write_zone_from_file(f.path)
logger.debug "zone changed"
if srv_dns.reload_zone
logger.debug "zone reloaded"
result.ok = true
result.message = _("Zone updated.")
else
logger.warn "zone reload failed, replacing old content"
srv_dns.replace_zone_with_backup
result.message = _("Internal error. Administrator is warned.")
end
rescue
logger.warn "Writing zone file failed"
raise
ensure
f.close!
end
end
end
end
if result.message.nil?
# here fall lost souls
result.message = _("Command not recognized.")
end
end
end
end
end
lib/cyborghood/command_runner.rb
#--
# CyborgHood, a distributed system management software.
# Copyright (c) 2009 Marc Dequènes (Duck) <Duck@DuckCorp.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#++
require 'tempfile'
require 'shellwords'
require 'cyborghood/order'
require 'cyborghood/objects'
require 'cyborghood/services/dns'
module CyborgHood
class CommandRunner
include I18nTranslation
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
execute_cmd(order.user, cmd.cmdsplit, order.shared_parameters, result)
rescue CyberError => e
result.message = e.message.capitalize + "."
rescue
logger.error "Command crashed: " + $!
logger.error "Crash trace: " + $!.backtrace.join("\n")
result.message = _("Internal error. Administrator is warned.")
end
tag = result.ok ? "SUCCESS" : "FAILURE"
logger.debug "Command result: [#{tag}] #{result.message.untranslated}"
else
logger.info "Invalid command detected: #{cmd.cmdline}"
cmd.parsing_errors.collect{|err| logger.debug "Invalid command detected - reason: " + err.untranslated }
result.message = cmd.parsing_errors.collect{|err| err.to_s }.join("\n")
end
result_list << result
end
result_list
end
private
def self.execute_cmd(user, cmdline, shared_parameters, result)
subsys = cmdline.shift
case subsys.upcase
when "DNS"
return if cmdline.empty?
case cmdline.shift.upcase
when "INFO"
return unless cmdline.empty?
list = DnsDomain.find_by_manager(user)
txt_list = list.collect{|z| z.cn }.sort.join(", ")
result.ok = true
result.message = _("You are manager of the following zones: %{zone_list}.", :zone_list => txt_list)
when "GET"
return if cmdline.empty?
case cmdline.shift.upcase
when "ZONE"
return if cmdline.empty?
zone = cmdline.shift.downcase
dom = DnsDomain.new(zone)
unless dom.hosted?
result.message = _("This zone is not hosted here.")
return result
end
unless dom.managed_by? user
result.message = _("You are not allowed to manage this zone.")
return result
end
srv_dns = Services::DNS.new(zone)
result.ok = true
result.message = _("Requested zone content attached.")
zone_ref = {:content => srv_dns.read_zone, :filename => "dnszone_#{zone}.txt"}.to_ostruct
result.refs = [zone_ref]
end
when "SET"
return if cmdline.empty?
case cmdline.shift.upcase
when "ZONE"
return if cmdline.empty?
zone = cmdline.shift.downcase
dom = DnsDomain.new(zone)
unless dom.hosted?
result.message = _("This zone is not hosted here.")
return result
end
unless dom.managed_by? user
result.message = _("You are not allowed to manage this zone.")
return result
end
srv_dns = Services::DNS.new(zone)
return if cmdline.empty?
content_ref = cmdline.shift
part = shared_parameters[content_ref]
unless part.type == "text/plain"
result.message = _("Attachment has wrong content-type.")
return result
end
f = Tempfile.new(zone)
f.write(part.content)
f.close
logger.debug "Created temporary zone file '#{f.path}'"
srv_dns = Services::DNS.new(zone)
current_serial = srv_dns.serial
logger.debug "Current serial: #{current_serial}"
dns_result = srv_dns.check_zone_file(f.path)
unless dns_result.ok
result.message = _("Invalid zone data.")
f.close!
return result
end
logger.debug "New serial: #{dns_result.serial}"
# allow new serial or missing serial (to allow creating a new zone or replacing a broken zone)
unless current_serial.nil? or dns_result.serial > current_serial
result.message = _("Zone serial is not superior to current serial.")
f.close!
return result
end
begin
srv_dns.write_zone_from_file(f.path)
logger.debug "zone changed"
if srv_dns.reload_zone
logger.debug "zone reloaded"
result.ok = true
result.message = _("Zone updated.")
else
logger.warn "zone reload failed, replacing old content"
srv_dns.replace_zone_with_backup
result.message = _("Internal error. Administrator is warned.")
end
rescue
logger.warn "Writing zone file failed"
raise
ensure
f.close!
end
end
end
end
if result.message.nil?
# here fall lost souls
result.message = _("Command not recognized.")
end
end
end
end
po/cyborghood.pot
msgid ""
msgstr ""
"Project-Id-Version: CyborgHood 0.2.0~dev\n"
"POT-Creation-Date: 2010-04-04 02:19+0200\n"
"POT-Creation-Date: 2010-04-04 17:32+0200\n"
"PO-Revision-Date: 2009-03-07 21:38+0100\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
......
msgid "Syntax error in command."
msgstr ""
#: lib/cyborghood/mail.rb:93
#: lib/cyborghood/mail.rb:92
msgid "Replay detected."
msgstr ""
#: lib/cyborghood/mail.rb:99
#: lib/cyborghood/mail.rb:98
msgid "Mail not RFC3156 compliant."
msgstr ""
#: lib/cyborghood/mail.rb:173
#: lib/cyborghood/mail.rb:172
msgid "Mail not formatted correctly (signed part)."
msgstr ""
#: lib/cyborghood/mail.rb:176
#: lib/cyborghood/mail.rb:175
msgid "Mail content tampered or badly signed: %{sig_err}"
msgstr ""
#: lib/cyborghood/mail.rb:180
#: lib/cyborghood/mail.rb:179
msgid "Mail is from an unknown person."
msgstr ""
#: lib/cyborghood/mail.rb:189
#: lib/cyborghood/mail.rb:188
msgid ""
"The signature was made too long ago (check your system clock). Rejected "
"message to avoid replay attacks."
msgstr ""
#: lib/cyborghood/mail.rb:193
#: lib/cyborghood/mail.rb:192
msgid ""
"The signature was made in the future (check your system clock). Rejected "
"message to avoid replay attacks."
msgstr ""
#: lib/cyborghood/mail.rb:238
#: lib/cyborghood/mail.rb:237
msgid "Mail not formatted correctly (encrypted part)."
msgstr ""
......
#: lib/cyborghood/mail_order.rb:38
msgid "Attachment '%{ref}' not found."
msgstr ""
#: lib/cyborghood/command_runner.rb:47 lib/cyborghood/command_runner.rb:157
msgid "Internal error. Administrator is warned."
msgstr ""
#: lib/cyborghood/command_runner.rb:75
msgid "You are manager of the following zones: %{zone_list}."
msgstr ""
#: lib/cyborghood/command_runner.rb:85 lib/cyborghood/command_runner.rb:107
msgid "This zone is not hosted here."
msgstr ""
#: lib/cyborghood/command_runner.rb:89 lib/cyborghood/command_runner.rb:111
msgid "You are not allowed to manage this zone."
msgstr ""
#: lib/cyborghood/command_runner.rb:95
msgid "Requested zone content attached."
msgstr ""
#: lib/cyborghood/command_runner.rb:120
msgid "Attachment has wrong content-type."
msgstr ""
#: lib/cyborghood/command_runner.rb:135
msgid "Invalid zone data."
msgstr ""
#: lib/cyborghood/command_runner.rb:142
msgid "Zone serial is not superior to current serial."
msgstr ""
#: lib/cyborghood/command_runner.rb:153
msgid "Zone updated."
msgstr ""
#: lib/cyborghood/command_runner.rb:171
msgid "Command not recognized."
msgstr ""
po/cyborghood_postman.pot
msgid ""
msgstr ""
"Project-Id-Version: CyborgHood 0.2.0~dev\n"
"POT-Creation-Date: 2010-04-04 02:19+0200\n"
"POT-Creation-Date: 2010-04-04 17:32+0200\n"
"PO-Revision-Date: 2009-03-07 21:38+0100\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
......
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
#: /opt/cyborghood-dev/bin/postman:146 /opt/cyborghood-dev/bin/postman:162
#: /opt/cyborghood-dev/bin/postman:145 /opt/cyborghood-dev/bin/postman:161
msgid "Hello %{cn},"
msgstr ""
#: /opt/cyborghood-dev/bin/postman:146
#: /opt/cyborghood-dev/bin/postman:145
msgid "Hello,"
msgstr ""
#: /opt/cyborghood-dev/bin/postman:148
#: /opt/cyborghood-dev/bin/postman:147
msgid ""
"A message (ID: %{id}), apparently from you, was rejected for the following "
"reason:"
msgstr ""
#: /opt/cyborghood-dev/bin/postman:167
#: /opt/cyborghood-dev/bin/postman:166
msgid ""
"An order, in a message (ID: %{id}) from you, was rejected for the following "
"reason:"
msgstr ""
#: /opt/cyborghood-dev/bin/postman:181
#: /opt/cyborghood-dev/bin/postman:180
msgid "Follows the transcript of your commands:"
msgstr ""
#: /opt/cyborghood-dev/bin/postman:230
#: /opt/cyborghood-dev/bin/postman:229
msgid "Contact eMail:"
msgstr ""
#: /opt/cyborghood-dev/bin/postman:231
#: /opt/cyborghood-dev/bin/postman:230
msgid "Contact URL:"
msgstr ""
#: /opt/cyborghood-dev/bin/postman:255 /opt/cyborghood-dev/bin/postman:365
msgid "Internal error. Administrator is warned."
msgstr ""
#: /opt/cyborghood-dev/bin/postman:283
msgid "You are manager of the following zones: %{zone_list}."
msgstr ""
#: /opt/cyborghood-dev/bin/postman:293 /opt/cyborghood-dev/bin/postman:315
msgid "This zone is not hosted here."
msgstr ""
#: /opt/cyborghood-dev/bin/postman:297 /opt/cyborghood-dev/bin/postman:319
msgid "You are not allowed to manage this zone."
msgstr ""
#: /opt/cyborghood-dev/bin/postman:303
msgid "Requested zone content attached."
msgstr ""
#: /opt/cyborghood-dev/bin/postman:328
msgid "Attachment has wrong content-type."
msgstr ""
#: /opt/cyborghood-dev/bin/postman:343
msgid "Invalid zone data."
msgstr ""
#: /opt/cyborghood-dev/bin/postman:350
msgid "Zone serial is not superior to current serial."
msgstr ""
#: /opt/cyborghood-dev/bin/postman:361
msgid "Zone updated."
msgstr ""
#: /opt/cyborghood-dev/bin/postman:379
msgid "Command not recognized."
msgstr ""
po/fr/cyborghood.po
msgid ""
msgstr ""
"Project-Id-Version: CyborgHood 0.2.0~dev\n"
"POT-Creation-Date: 2010-04-04 02:19+0200\n"
"POT-Creation-Date: 2010-04-04 17:32+0200\n"
"PO-Revision-Date: 2010-04-04 20:59+0100\n"
"Last-Translator: Marc Dequènes (Duck) <Duck@DuckCorp.org>\n"
"MIME-Version: 1.0\n"
......
msgid "Syntax error in command."
msgstr "Erreur de syntaxe dans la commande."
#: lib/cyborghood/mail.rb:93
#: lib/cyborghood/mail.rb:92
msgid "Replay detected."
msgstr "Rejeu détecté."
#: lib/cyborghood/mail.rb:99
#: lib/cyborghood/mail.rb:98
msgid "Mail not RFC3156 compliant."
msgstr "Mail ne respectant pas la RFC3156."
#: lib/cyborghood/mail.rb:173
#: lib/cyborghood/mail.rb:172
msgid "Mail not formatted correctly (signed part)."
msgstr "Mail formaté incorrectement (partie signée)."
#: lib/cyborghood/mail.rb:176
#: lib/cyborghood/mail.rb:175
msgid "Mail content tampered or badly signed: %{sig_err}"
msgstr "Contenu du mail altéré ou mal signé: %{sig_err}"
#: lib/cyborghood/mail.rb:180
#: lib/cyborghood/mail.rb:179
msgid "Mail is from an unknown person."
msgstr "Mail provenant d'une personne inconnue"
#: lib/cyborghood/mail.rb:189
#: lib/cyborghood/mail.rb:188
msgid ""
"The signature was made too long ago (check your system clock). Rejected "
"message to avoid replay attacks."
......
"La signature a été faite depuis trop longtemps (vérifiez votre horloge "
"système. Message rejeté pour éviter les attaques par rejeux."
#: lib/cyborghood/mail.rb:193
#: lib/cyborghood/mail.rb:192
msgid ""
"The signature was made in the future (check your system clock). Rejected "
"message to avoid replay attacks."
......
"La signature a été faite dans le futur (vérifiez votre horloge système. "
"Message rejeté pour éviter les attaques par rejeux."
#: lib/cyborghood/mail.rb:238
#: lib/cyborghood/mail.rb:237
msgid "Mail not formatted correctly (encrypted part)."
msgstr "Mail formaté incorrectement (partie chiffrée)."
......
#: lib/cyborghood/mail_order.rb:38
msgid "Attachment '%{ref}' not found."
msgstr "La pièce jointe '%{ref}' n'a pas été trouvée."
#: lib/cyborghood/command_runner.rb:47 lib/cyborghood/command_runner.rb:157
msgid "Internal error. Administrator is warned."
msgstr "Erreur interne. L'administrateur a été prévenu."
#: lib/cyborghood/command_runner.rb:75
msgid "You are manager of the following zones: %{zone_list}."
msgstr "Vous gérez les zones suivantes : %{zone_list}."
#: lib/cyborghood/command_runner.rb:85 lib/cyborghood/command_runner.rb:107
msgid "This zone is not hosted here."
msgstr "Cette zone n'est pas hébergée ici."
#: lib/cyborghood/command_runner.rb:89 lib/cyborghood/command_runner.rb:111
msgid "You are not allowed to manage this zone."
msgstr "Vous n'êtes pas autorisé à gérer cette zone."
#: lib/cyborghood/command_runner.rb:95
msgid "Requested zone content attached."
msgstr "Le contenu de la zone demandée est en pièce jointe."
#: lib/cyborghood/command_runner.rb:120
msgid "Attachment has wrong content-type."
msgstr "La pièce jointe a un mauvais type de contenu (content-type)."
#: lib/cyborghood/command_runner.rb:135
msgid "Invalid zone data."
msgstr "Données pour la zone invalides."
#: lib/cyborghood/command_runner.rb:142
msgid "Zone serial is not superior to current serial."
msgstr "Le numéro de série de la zone n'est pas supèrieur à celui actuel."
#: lib/cyborghood/command_runner.rb:153
msgid "Zone updated."
msgstr "Zone mise à jour."
#: lib/cyborghood/command_runner.rb:171
msgid "Command not recognized."
msgstr "Commande non reconnue."
po/fr/cyborghood_postman.po
msgid ""
msgstr ""
"Project-Id-Version: CyborgHood 0.2.0~dev\n"
"POT-Creation-Date: 2010-04-04 02:19+0200\n"
"POT-Creation-Date: 2010-04-04 17:32+0200\n"
"PO-Revision-Date: 2010-04-04 21:27+0100\n"
"Last-Translator: Marc Dequènes (Duck) <Duck@DuckCorp.org>\n"
"MIME-Version: 1.0\n"
......
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=(n > 1);\n"
#: /opt/cyborghood-dev/bin/postman:146 /opt/cyborghood-dev/bin/postman:162
#: /opt/cyborghood-dev/bin/postman:145 /opt/cyborghood-dev/bin/postman:161
msgid "Hello %{cn},"
msgstr "Bonjour %{cn},"
#: /opt/cyborghood-dev/bin/postman:146
#: /opt/cyborghood-dev/bin/postman:145
msgid "Hello,"
msgstr "Bonjour,"
#: /opt/cyborghood-dev/bin/postman:148
#: /opt/cyborghood-dev/bin/postman:147
msgid ""
"A message (ID: %{id}), apparently from you, was rejected for the following "
"reason:"
......
"Un message (ID: %{id}), provenant apparemment de vous, a été rejeté pour la "
"raison suivante :"
#: /opt/cyborghood-dev/bin/postman:167
#: /opt/cyborghood-dev/bin/postman:166
msgid ""
"An order, in a message (ID: %{id}) from you, was rejected for the following "
"reason:"
......
"Un order, dans in message (ID: %{id}) venant de vous, a été rejeté pour la "
"raison suivante :"
#: /opt/cyborghood-dev/bin/postman:181
#: /opt/cyborghood-dev/bin/postman:180
msgid "Follows the transcript of your commands:"
msgstr "La retranscription des commandes suit :"
#: /opt/cyborghood-dev/bin/postman:230
#: /opt/cyborghood-dev/bin/postman:229
msgid "Contact eMail:"
msgstr "eMail de Contact :"
#: /opt/cyborghood-dev/bin/postman:231
#: /opt/cyborghood-dev/bin/postman:230
msgid "Contact URL:"
msgstr "URL de Contact :"
#: /opt/cyborghood-dev/bin/postman:255 /opt/cyborghood-dev/bin/postman:365
msgid "Internal error. Administrator is warned."
msgstr "Erreur interne. L'administrateur a été prévenu."
#: /opt/cyborghood-dev/bin/postman:283
msgid "You are manager of the following zones: %{zone_list}."
msgstr "Vous gérez les zones suivantes : %{zone_list}."
#: /opt/cyborghood-dev/bin/postman:293 /opt/cyborghood-dev/bin/postman:315
msgid "This zone is not hosted here."
msgstr "Cette zone n'est pas hébergée ici."
#: /opt/cyborghood-dev/bin/postman:297 /opt/cyborghood-dev/bin/postman:319
msgid "You are not allowed to manage this zone."
msgstr "Vous n'êtes pas autorisé à gérer cette zone."
#: /opt/cyborghood-dev/bin/postman:303
msgid "Requested zone content attached."
msgstr "Le contenu de la zone demandée est en pièce jointe."
#: /opt/cyborghood-dev/bin/postman:328
msgid "Attachment has wrong content-type."
msgstr "La pièce jointe a un mauvais type de contenu (content-type)."
#: /opt/cyborghood-dev/bin/postman:343
msgid "Invalid zone data."
msgstr "Données pour la zone invalides."
#: /opt/cyborghood-dev/bin/postman:350
msgid "Zone serial is not superior to current serial."
msgstr "Le numéro de série de la zone n'est pas supèrieur à celui actuel."
#: /opt/cyborghood-dev/bin/postman:361
msgid "Zone updated."
msgstr "Zone mise à jour."
#: /opt/cyborghood-dev/bin/postman:379
msgid "Command not recognized."
msgstr "Commande non reconnue."

Also available in: Unified diff