nixos-config/static/send-netinfo.rb

33 lines
712 B
Ruby
Executable File

#!/usr/bin/env ruby
# coding: utf-8
require 'net/smtp'
error "usage: #{$0} <smtp-server> <smtp-user>" if not (ARGV[0] and ARGV[1])
server = ARGV[0]
user = ARGV[1]
error "NETINFO_SMTP_PASSWD not set!" if not ENV['NETINFO_SMTP_PASSWD']
passwd = ENV['NETINFO_SMTP_PASSWD']
hostname = `hostname -f`.strip
date = `date +%Y-%m-%d`.strip
email_date = `date`
ipinfo = `ip addr`
message = <<EOM
From: #{user}@fudo.org
To: network-info@fudo.link
Subject: #{hostname} network info for #{date}
Date: #{email_date}
#{ipinfo}
EOM
smtp = Net::SMTP.new(server, 587)
smtp.enable_starttls
smtp.start('localhost', user, passwd) do |server|
server.send_message(message, "#{user}@fudo.org", ["network-info@fudo.link"])
end