]>
Commit | Line | Data |
---|---|---|
11e72535 | 1 | import md5, os, hmac, time |
f14f0b7b CP |
2 | from rc4 import RC4 |
3 | ||
11e72535 CP |
4 | try: |
5 | import hashlib | |
6 | sha256 = hashlib.sha256 | |
7 | sha256m = hashlib.sha256 | |
8 | except ImportError: | |
9 | import sha256 as __sha256 | |
10 | sha256 = __sha256.sha256 | |
11 | sha256m = __sha256 | |
12 | ||
f14f0b7b CP |
13 | def generate_url(config, obj): |
14 | s = os.urandom(4) | |
15 | r = RC4(md5.md5("%s %s" % (s, config["urlkey"])).hexdigest()) | |
16 | a = r.crypt(obj["user.password"]) | |
17 | b = md5.md5(md5.md5("%s %s %s %s" % (config["urlsecret"], obj["user.username"], a, s)).hexdigest()).hexdigest() | |
18 | obj["url"] = "%s?m=%s&h=%s&u=%s&r=%s" % (config["url"], a.encode("hex"), b, obj["user.username"].encode("hex"), s.encode("hex")) | |
19 | ||
11e72535 | 20 | def generate_resetcode(config, obj): |
dbec52da CP |
21 | if obj["user.lockuntil"] == 0: |
22 | obj["resetline"] = "LOCK UNTIL NOT SET. STAFF ACCOUNT'S CAN'T USE RESET" | |
23 | return | |
24 | ||
11e72535 CP |
25 | if not config.has_key("__codegensecret"): |
26 | config["__codegenhmac"] = hmac.HMAC(key=sha256(sha256("%s:codegenerator" % config["q9secret"]).digest()).hexdigest(), digestmod=sha256m) | |
27 | ||
28 | h = config["__codegenhmac"].copy() | |
29 | h.update(sha256("%s:%d" % (obj["user.username"], obj["user.lockuntil"])).hexdigest()) | |
30 | ||
31 | obj["resetcode"] = h.hexdigest() | |
11e72535 | 32 | obj["lockuntil"] = time.ctime(obj["user.lockuntil"]) |
dbec52da | 33 | obj["resetline"] = "/MSG %(config.bot)s RESET #%(user.username)s %(resetcode)s" % obj |
11e72535 | 34 | |
f14f0b7b CP |
35 | MAILTEMPLATES = { |
36 | "mutators": { | |
37 | 1: generate_url, | |
11e72535 CP |
38 | 3: generate_resetcode, |
39 | 5: generate_resetcode, | |
f14f0b7b | 40 | }, |
58fadfc0 CP |
41 | "sendto": { |
42 | 5: "prevemail", | |
43 | }, | |
f14f0b7b CP |
44 | "languages": { |
45 | "en": { | |
46 | 1: { | |
58fadfc0 | 47 | "subject": "%(config.bot)s account registration", |
f14f0b7b CP |
48 | "body": """ |
49 | Thank you for registering. | |
06c8032a CP |
50 | To get your password please visit: |
51 | %(url)s | |
f14f0b7b | 52 | |
a8a392ba CP |
53 | Note that this URL will not work forever, you should make a note of your password |
54 | or change it (as on the site). | |
55 | ||
06c8032a | 56 | In case you forget your login/password use: |
a8a392ba | 57 | /msg %(config.bot)s REQUESTPASSWORD %(user.email)s |
06c8032a | 58 | |
58fadfc0 | 59 | Make sure you've read the %(config.bot)s FAQ at %(config.siteurl)s for a complete |
06c8032a CP |
60 | reference on Q's commands and usage. |
61 | ||
58fadfc0 | 62 | ** PLEASE READ %(config.securityurl)s -- |
06c8032a CP |
63 | it contains important information about keeping your account secure. |
64 | Note that QuakeNet Operators will not intervene if you fail to read | |
65 | the above URL and your account is compromised as a result. | |
66 | ||
67 | PLEASE REMEMBER THAT UNUSED ACCOUNTS ARE AUTOMATICALLY REMOVED | |
68 | AFTER %(config.cleanup)d DAYS, AND ALL CHANLEVS ARE LOST! | |
69 | ||
70 | NB: Save this email for future reference. | |
f14f0b7b CP |
71 | """, |
72 | }, | |
58fadfc0 CP |
73 | 2: { "subject": "%(config.bot)s password request", "body": """ |
74 | Your username/password is: | |
75 | ||
76 | Username: %(user.username)s | |
77 | Password: %(user.password)s | |
78 | ||
79 | To auth yourself to %(config.bot)s, type the following command | |
80 | ||
81 | /MSG %(config.bot)s@%(config.server)s AUTH %(user.username)s %(user.password)s | |
82 | """, }, | |
11e72535 CP |
83 | 3: { "subject": "%(config.bot)s password change", "body": """ |
84 | Your password has recently changed. If this was not requested by you, | |
85 | please use: | |
dbec52da | 86 | %(resetline)s |
11e72535 CP |
87 | |
88 | You have until %(lockuntil)s to perform this command. | |
89 | """, }, | |
90 | 4: { "subject": "%(config.bot)s account reset", "body": """ | |
91 | Your %(config.bot)s account settings have been restored: | |
92 | E-mail address: %(user.email)s | |
93 | Password: %(user.password)s | |
94 | ||
95 | Make sure you read the %(config.bot)s security FAQ at %(config.securityurl)s. | |
96 | """, }, | |
58fadfc0 | 97 | 5: { "subject": "%(config.bot)s email change", "body": """ |
11e72535 | 98 | Your email address has been changed on %(config.bot)s from %(prevemail)s to %(user.email)s. |
58fadfc0 | 99 | |
11e72535 | 100 | If you did not request this please use: |
dbec52da | 101 | %(resetline)s |
58fadfc0 | 102 | |
11e72535 | 103 | You have until %(lockuntil)s to perform this command. |
58fadfc0 | 104 | """, }, |
f14f0b7b CP |
105 | }, |
106 | }, | |
107 | } |