add parameters for answerback-email -e,--email email_addr: add email address -s,--ssh-pubkey pub_key: add a ssh login pub_key -f,--raw-email mail_file: add email address[, pub_key] via email file
why: easier for administrator to manully assign jumper account for user with the parameters
Signed-off-by: Luan Shengde luanshengde2@huawei.com --- container/assign-account/answerback-email.rb | 42 ++++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-)
diff --git a/container/assign-account/answerback-email.rb b/container/assign-account/answerback-email.rb index 5a5234c..a3108cb 100755 --- a/container/assign-account/answerback-email.rb +++ b/container/assign-account/answerback-email.rb @@ -16,48 +16,48 @@ require_relative '../defconfig' names = Set.new %w[ JUMPER_HOST JUMPER_PORT - CRYSTAL_INTRANET - SEND_MAIL_PORT + SEND_MAIL_HOST + SEND_INTERNET_MAIL_PORT ]
defaults = relevant_defaults(names)
JUMPER_HOST = defaults['JUMPER_HOST'] || '183.134.196.212' JUMPER_PORT = defaults['JUMPER_PORT'] || 29999 -CRYSTAL_INTRANET = defaults['CRYSTAL_INTRANET'] || localhost -SEND_MAIL_PORT = defaults['SEND_MAIL_PORT'] || 11312 +SEND_MAIL_HOST = defaults['SEND_MAIL_HOST'] || localhost +SEND_MAIL_PORT = defaults['SEND_INTERNET_MAIL_PORT'] || 11312
apply_info = { - 'email_addr' => nil, - 'pub_key' => nil + 'my_email' => nil, + 'my_pub_key' => nil }
def init_info(email_file, apply_info) mail_content = Mail.read(email_file)
- email_addr = mail_content.from[0] - pub_key = mail_content.part[1].body.decoded.gsub(/\r|\n/, '') if mail_content.part[1].filename == 'id_rsa.pub' + my_email = mail_content.from[0] + my_pub_key = mail_content.part[1].body.decoded.gsub(/\r|\n/, '') if mail_content.part[1].filename == 'id_rsa.pub'
- apply_info['email_addr'] = email_addr - apply_info['pub_key'] = pub_key + apply_info['my_email'] = my_email + apply_info['my_pub_key'] = my_pub_key
apply_info end
options = OptionParser.new do |opts| - opts.banner = "Usage: answerback-mail.rb [--email email] [--ssh-pubkey pub_key] [--raw-email email_file]\n" + opts.banner = "Usage: answerback-mail.rb [--email email] [--ssh-pubkey pub_key_file] [--raw-email email_file]\n" opts.banner += " -e or -f is required\n" opts.banner += ' -s is optional when use -e'
opts.separator '' opts.separator 'options:'
- opts.on('-e email_addr', '--email email_addr', 'appoint email address') do |email_addr| - apply_info['email_addr'] = email_addr + opts.on('-e email_address', '--email email_address', 'appoint email address') do |email_address| + apply_info['my_email'] = email_address end
- opts.on('-s pub_key', '--ssh-pubkey pub_key', 'ssh pub_key to enable keyless login') do |pub_key| - apply_info['pub_key'] = pub_key + opts.on('-s pub_key_file', '--ssh-pubkey pub_key_file', 'ssh pub_key file, enable keyless login') do |pub_key_file| + apply_info['my_pub_key'] = File.read(pub_key_file) end
opts.on('-f email_file', '--raw-email email_file', 'email file') do |email_file| @@ -106,15 +106,15 @@ end
def send_account(apply_info) message = "No email address specified\n" - message += "use -e email_addr add a email address\n" - message += 'or use -f to add a mail file' - raise message if apply_info['email_addr'].nil? + message += "use -e email_address add a email address\n" + message += 'or use -f to add a email file' + raise message if apply_info['my_email'].nil?
- acct_info = account_info(apply_info['pub_key']) + acct_info = account_info(apply_info['my_pub_key'])
- message = build_message(apply_info['email_addr'], acct_info) + message = build_message(apply_info['my_email'], acct_info)
- %x(curl -XPOST '#{CRYSTAL_INTRANET}:#{SEND_MAIL_PORT}/send_mail_text' -d "#{message}") + %x(curl -XPOST '#{SEND_MAIL_HOST}:#{SEND_MAIL_PORT}/send_mail_text' -d "#{message}") end
send_account(apply_info)