-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelliot.py
133 lines (76 loc) · 2.5 KB
/
elliot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import smtplib
import mailbox
import time
import os, pwd
class Elliot :
def __init__(self, guideName, traineeName) :
self.guideName = guideName;
self.traineeName = traineeName;
objectives = [ "passwd", "ls", "cdAndNano", "cpAndRm", "psAndTop", "apt", "done" ]
for objectiveName in objectives :
print "Starting objective "+objectiveName
package = __import__("objectives."+objectiveName, fromlist=[''])
self.makeObjective(package)
def makeObjective(self, package) :
# Init
print "> Initializing"
objective = package.objective(self)
# Send mail
print "> Sending mail"
self.sendMail(self.guideName,
self.traineeName,
objective.title(),
objective.description());
# Wait for mail reply
print "> Waiting for mail reply"
while True :
time.sleep(1)
check = self.checkMail()
if (check == None) : continue
print " > Received a new email"
if (check == "skip") :
print "> Skipping objective"
break
if (objective.checkIfComplete() == True) :
print "> Objective complete"
break
else :
print " > Objective not complete"
self.sendMail(self.guideName,
self.traineeName,
objective.title(),
objective.sorry());
def sendMail(self, from_, to, subject, text) :
server = "localhost"
from_ = from_+"@"+server
to = to+"@"+server
message = """
From: %s
To: %s
Subject: %s
%s
-- %s
""" % (from_, to, subject, text, "Elliot")
# Send the mail
server = smtplib.SMTP(server)
server.sendmail(from_, [ to ], message)
server.quit()
def checkMail(self) :
path = "/var/mail/elliot"
mb = mailbox.mbox(path)
for key, message in mb.iteritems() :
subject = message["Subject"]
mb.lock()
mb.remove(key)
mb.flush()
mb.unlock()
# Dirty hack
uid = pwd.getpwnam("elliot").pw_uid
os.chown(path,uid,-1)
print subject
return subject
return None
def main() :
print "Starting Elliot ..."
Elliot("elliot", "futurenerd")
main()