mirror of
https://github.com/narkoz/hacker-scripts
synced 2025-08-26 20:37:09 +00:00
parent
a503d242d8
commit
12c4f2dcfd
@ -9,12 +9,21 @@ GMAIL_USERNAME = ENV['GMAIL_USERNAME']
|
|||||||
GMAIL_PASSWORD = ENV['GMAIL_PASSWORD']
|
GMAIL_PASSWORD = ENV['GMAIL_PASSWORD']
|
||||||
|
|
||||||
gmail = Gmail.connect(GMAIL_USERNAME, GMAIL_PASSWORD)
|
gmail = Gmail.connect(GMAIL_USERNAME, GMAIL_PASSWORD)
|
||||||
|
kumars_email = 'kumar.a@example.com'
|
||||||
|
|
||||||
|
DB_NAME_REGEX = /\S+_staging/
|
||||||
KEYWORDS_REGEX = /sorry|help|wrong/i
|
KEYWORDS_REGEX = /sorry|help|wrong/i
|
||||||
|
|
||||||
gmail.inbox.find(:unread, from: 'kumar.a@example.com').each do |email|
|
gmail.inbox.find(:unread, from: kumars_email).each do |email|
|
||||||
if email.body[KEYWORDS_REGEX]
|
if email.body[KEYWORDS_REGEX] && (db_name = email.body[DB_NAME_REGEX])
|
||||||
# Restore DB and send a reply
|
backup_file = "/home/backups/databases/#{db_name}-" + (Date.today - 1).strftime('%Y%m%d') + '.gz'
|
||||||
|
abort 'ERROR: Backup file not found' unless File.exist?(backup_file)
|
||||||
|
|
||||||
|
# Restore DB
|
||||||
|
`gunzip -c #{backup_file} | psql #{db_name}`
|
||||||
|
|
||||||
|
# Mark as read, add label and reply
|
||||||
|
email.read!
|
||||||
email.label('Database fixes')
|
email.label('Database fixes')
|
||||||
reply = create_reply(email.subject)
|
reply = create_reply(email.subject)
|
||||||
gmail.deliver(reply)
|
gmail.deliver(reply)
|
||||||
@ -23,7 +32,7 @@ end
|
|||||||
|
|
||||||
def create_reply(subject)
|
def create_reply(subject)
|
||||||
gmail.compose do
|
gmail.compose do
|
||||||
to "kumar.a@example.com"
|
to kumars_email
|
||||||
subject "RE: #{subject}"
|
subject "RE: #{subject}"
|
||||||
body "No problem. I've fixed it. \n\n Please be careful next time."
|
body "No problem. I've fixed it. \n\n Please be careful next time."
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user