Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Cecylia Bocovich
gettor
Commits
98862a5f
Commit
98862a5f
authored
Sep 26, 2019
by
Hiro
🏄
Browse files
Add checks for email service
parent
8bd76e10
Changes
3
Hide whitespace changes
Inline
Side-by-side
bin/gettor_check
0 → 100755
View file @
98862a5f
#!/bin/bash
#
# This file is part of GetTor, a Tor Browser distribution system.
#
# :authors: Hiro <hiro@torproject.org>
# 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
scripts/check_service
0 → 100644
View file @
98862a5f
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# This file is part of GetTor, a Tor Browser distribution system.
#
# :authors: hiro <hiro@torproject.org>
# 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@torproject.org"
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
\n
To: %s
\n
Subject: %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
)
scripts/update_files
View file @
98862a5f
...
...
@@ -10,7 +10,7 @@
# :license: This is Free Software. See LICENSE for license information.
cd
~/releases
git checkout
n
aster
git checkout
m
aster
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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment