[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [gettor/master] Add checks for email service
commit 98862a5f9e423a4b65a550620858342f72c5dd2c
Author: hiro <hiro@xxxxxxxxxxxxxx>
Date: Thu Sep 26 13:23:35 2019 +0200
Add checks for email service
---
bin/gettor_check | 24 +++++++++
scripts/check_service | 135 ++++++++++++++++++++++++++++++++++++++++++++++++++
scripts/update_files | 4 +-
3 files changed, 162 insertions(+), 1 deletion(-)
diff --git a/bin/gettor_check b/bin/gettor_check
new file mode 100755
index 0000000..55fd1a3
--- /dev/null
+++ b/bin/gettor_check
@@ -0,0 +1,24 @@
+#!/bin/bash
+#
+# This file is part of GetTor, a Tor Browser distribution system.
+#
+# :authors: Hiro <hiro@xxxxxxxxxxxxxx>
+# see also AUTHORS file
+#
+# :copyright: (c) 2008-2019, The Tor Project, Inc.
+#
+# :license: This is Free Software. See LICENSE for license information.
+
+cd ;
+virtualenv gettor/venv
+source gettor/venv/bin/activate
+
+python3 gettor/scripts/check_service $1
+
+# store exit status
+status=$?
+
+if test $status -ne 0
+then
+ ./bin/gettor_service start
+fi
diff --git a/scripts/check_service b/scripts/check_service
new file mode 100644
index 0000000..38bb1a2
--- /dev/null
+++ b/scripts/check_service
@@ -0,0 +1,135 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+#
+# This file is part of GetTor, a Tor Browser distribution system.
+#
+# :authors: hiro <hiro@xxxxxxxxxxxxxx>
+# see also AUTHORS file
+#
+# :license: This is Free Software. See LICENSE for license information.
+
+import sys
+import smtplib
+import time
+import imaplib
+import email
+import time
+
+# Standard Nagios return codes
+OK, WARNING, CRITICAL, UNKNOWN = range(4)
+
+ORG_EMAIL = "@gmail.com"
+FROM_EMAIL = "test.gettor.browser" + ORG_EMAIL
+SMTP_SERVER = "imap.gmail.com"
+SMTP_PORT = 993
+
+MESSAGE_FROM = "gettor@xxxxxxxxxxxxxx"
+MESSAGE_SUBJECT = "[GetTor] Links for your request"
+MESSAGE_BODY = "https://gitlab.com/thetorproject/"
+
+STATUS_FILE = "/srv/gettor.torproject.org/check/status"
+
+# -------------------------------------------------
+#
+# Utility to read email from Gmail Using Python
+#
+# ------------------------------------------------
+
+def test_email_from_gmail(password):
+ try:
+ mail = imaplib.IMAP4_SSL(SMTP_SERVER)
+ mail.login(FROM_EMAIL, password)
+ mail.select('INBOX')
+
+ type, data = mail.search(None, 'ALL')
+ mail_ids = data[0]
+
+ id_list = mail_ids.split()
+ first_email_id = int(str(id_list[0], 'utf-8'))
+ latest_email_id = int(str(id_list[-1], 'utf-8'))
+
+ for i in range(int(latest_email_id), int(first_email_id), -1):
+ typ, data = mail.fetch(str(i), '(RFC822)')
+
+ for response_part in data:
+ if isinstance(response_part, tuple):
+ m = str(response_part[1], 'utf-8')
+ msg = email.message_from_string(m)
+ email_subject = "{}".format(msg['subject'])
+ email_from = "{}".format(msg['from'])
+ email_body = "{}".format(msg.as_string())
+
+ if (MESSAGE_FROM == email_from) and (MESSAGE_SUBJECT == email_subject) and (MESSAGE_BODY in email_body):
+ mail.store(str(i), '+FLAGS', '\\Deleted')
+ return OK, "Found correct gettor email."
+ else:
+ print('if not working')
+ mail.store(str(i), '+FLAGS', '\\Deleted')
+
+
+
+
+ return WARNING, "No emails from gettor found"
+
+ except Exception as e:
+ return CRITICAL, str(e)
+
+def send_email_from_gmail(password):
+ sent_from = FROM_EMAIL
+ sent_to = [MESSAGE_FROM]
+ subject = 'windows en'
+ body = 'windows en'
+
+ email_text = """From: %s\nTo: %s\nSubject: %s\n\n%s
+ """ % (sent_from, ", ".join(sent_to), subject, body)
+
+ try:
+ server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
+ server.ehlo()
+ server.login(sent_from, password)
+ server.sendmail(sent_from, to, email_text)
+ server.close()
+ except Exception as e:
+ return UNKNOWN, str(e)
+
+if __name__ == "__main__":
+ status, message = None, None
+
+ host = None
+ use_https = False
+
+ if len(sys.argv) == 2:
+ password = sys.argv[1]
+ else:
+ password = "yourPassword"
+
+ status_file = open(STATUS_FILE,'w')
+
+ try:
+ status, message = send_email_from_gmail(password)
+ except Exception as e:
+ status = CRITICAL
+ message = repr(e)
+ sys.exit(status)
+
+ time.sleep(180)
+
+ try:
+ status, message = test_email_from_gmail(password)
+ except KeyboardInterrupt:
+ status, message = CRITICAL, "Caught Control-C..."
+ except Exception as e:
+ status = CRITICAL
+ message = repr(e)
+ finally:
+ if status == OK:
+ status_file.write("OK: %s" % message)
+ elif status == WARNING:
+ status_file.write("WARNING: %s" % message)
+ elif status == CRITICAL:
+ status_file.write("CRITICAL: %s" % message)
+ else:
+ status_file.write("UNKNOWN: %s" % message)
+ status = UNKNOWN
+
+ sys.exit(status)
diff --git a/scripts/update_files b/scripts/update_files
index df800d6..dac62e4 100755
--- a/scripts/update_files
+++ b/scripts/update_files
@@ -10,7 +10,7 @@
# :license: This is Free Software. See LICENSE for license information.
cd ~/releases
-git checkout naster
+git checkout master
git branch -D releases
git push origin --delete releases
git branch -D torbrowser-releases
@@ -52,6 +52,8 @@ done
rclone delete gdrive:releases
for f in $(ls); do
+ # Update Google Drive
rclone copy $f gdrive:releases
+ # Update Internet Archive
ia upload <identifier> - --remote-name=$f --metadata="title:New Tor Browser release ${f}."
done
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits