]> jfr.im git - irc/quakenet/newserv.git/blob - chanserv/batcher/templates.py
4eedd0a217f2af013d11da3d9d2691fbbf81ce27
[irc/quakenet/newserv.git] / chanserv / batcher / templates.py
1 import md5, os, hmac, time
2 from rc4 import RC4
3
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
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
20 def generate_activation_url(config, obj):
21 r = os.urandom(16).encode("hex")
22 uid = int(obj["user.id"])
23
24 r2 = RC4(sha256("rc4 %s %s" % (r, config["activationkey"])).hexdigest())
25 a = r2.crypt(obj["user.password"]).encode("hex")
26
27 h = hmac.HMAC(sha256("hmac %s %s" % (r, config["activationkey"])).hexdigest())
28 h.update("%d %s %s" % (uid, obj["user.username"], a))
29 hd = h.hexdigest()
30
31 obj["url"] = "%s?id=%d&h=%s&r=%s&u=%s&p=%s" % (config["activationurl"], uid, hd, r, obj["user.username"].encode("hex"), a)
32
33 def generate_resetcode(config, obj):
34 if obj["user.lockuntil"] == 0:
35 obj["resetline"] = "LOCK UNTIL NOT SET. STAFF ACCOUNT'S CAN'T USE RESET"
36 obj["lockuntil"] = "never"
37 return
38
39 if not config.has_key("__codegensecret"):
40 config["__codegenhmac"] = hmac.HMAC(key=sha256(sha256("%s:codegenerator" % config["q9secret"]).digest()).hexdigest(), digestmod=sha256m)
41
42 h = config["__codegenhmac"].copy()
43 h.update(sha256("%s:%d" % (obj["user.username"], obj["user.lockuntil"])).hexdigest())
44
45 obj["resetcode"] = h.hexdigest()
46 obj["lockuntil"] = time.ctime(obj["user.lockuntil"])
47 obj["resetline"] = "/MSG %(config.bot)s RESET #%(user.username)s %(resetcode)s" % obj
48
49 MAILTEMPLATES = {
50 "mutators": {
51 1: generate_url,
52 3: generate_resetcode,
53 5: generate_resetcode,
54 6: generate_activation_url,
55 },
56 "sendto": {
57 5: "prevemail",
58 },
59 "languages": {
60 "en": {
61 1: {
62 "subject": "%(config.bot)s account registration",
63 "body": """
64 Thank you for registering.
65 To get your password please visit:
66 %(url)s
67
68 Note that this URL will not work forever, you should make a note of your password
69 or change it (as on the site).
70
71 In case you forget your login/password use:
72 /msg %(config.bot)s REQUESTPASSWORD %(user.email)s
73
74 Make sure you've read the %(config.bot)s FAQ at %(config.siteurl)s for a complete
75 reference on Q's commands and usage.
76
77 ** PLEASE READ %(config.securityurl)s --
78 it contains important information about keeping your account secure.
79 Note that QuakeNet Operators will not intervene if you fail to read
80 the above URL and your account is compromised as a result.
81
82 PLEASE REMEMBER THAT UNUSED ACCOUNTS ARE AUTOMATICALLY REMOVED
83 AFTER %(config.cleanup)d DAYS, AND ALL CHANLEVS ARE LOST!
84
85 NB: Save this email for future reference.
86 """,
87 },
88 2: { "subject": "%(config.bot)s password request", "body": """
89 Your username/password is:
90
91 Username: %(user.username)s
92 Password: %(user.password)s
93
94 To auth yourself to %(config.bot)s, type the following command
95
96 /MSG %(config.bot)s@%(config.server)s AUTH %(user.username)s %(user.password)s
97 """, },
98 3: { "subject": "%(config.bot)s password change", "body": """
99 Your password has recently changed. If this was not requested by you,
100 please use:
101 %(resetline)s
102
103 You have until %(lockuntil)s to perform this command.
104 """, },
105 4: { "subject": "%(config.bot)s account reset", "body": """
106 Your %(config.bot)s account settings have been restored:
107 E-mail address: %(user.email)s
108 Password: %(user.password)s
109
110 Make sure you read the %(config.bot)s security FAQ at %(config.securityurl)s.
111 """, },
112 5: { "subject": "%(config.bot)s email change", "body": """
113 Your email address has been changed on %(config.bot)s from %(prevemail)s to %(user.email)s.
114
115 If you did not request this please use:
116 %(resetline)s
117
118 You have until %(lockuntil)s to perform this command.
119 """, },
120 6: { "subject": "Please complete your QuakeNet account registration", "body": """
121 Hi %(user.username)s,
122
123 You're just one click away from completing your registration for a QuakeNet account!
124
125 Just visit the link below to complete the process:
126 %(url)s
127
128 For reference, your username/password is:
129
130 Username: %(user.username)s
131 Password: %(user.password)s
132
133 After activation you can auth yourself to QuakeNet by typing the following command:
134
135 /AUTH %(user.username)s %(user.password)s
136 """, },
137 },
138 },
139 }