]>
Commit | Line | Data |
---|---|---|
b263aa79 | 1 | /* |
2 | * chanservdb_updates.c: | |
3 | * Handle all the update requests for the database. | |
4 | */ | |
5 | ||
183b8e2f | 6 | #include "chanserv.h" |
ee8cd7d0 | 7 | #include "../dbapi/dbapi.h" |
183b8e2f P |
8 | #include "../core/config.h" |
9 | #include "../lib/sstring.h" | |
10 | #include "../parser/parser.h" | |
11 | #include "../core/events.h" | |
b263aa79 | 12 | |
13 | #include <string.h> | |
b263aa79 | 14 | #include <stdio.h> |
15 | #include <sys/poll.h> | |
16 | #include <stdarg.h> | |
17 | ||
18 | void csdb_updateauthinfo(reguser *rup) { | |
80d2de64 | 19 | char eschost[2*HOSTLEN+1]; |
b263aa79 | 20 | |
ee8cd7d0 CP |
21 | dbescapestring(eschost,rup->lastuserhost->content,rup->lastuserhost->length); |
22 | dbquery("UPDATE chanserv.users SET lastauth=%lu,lastuserhost='%s' WHERE ID=%u", | |
b263aa79 | 23 | rup->lastauth,eschost,rup->ID); |
24 | } | |
25 | ||
26 | void csdb_updatelastjoin(regchanuser *rcup) { | |
ee8cd7d0 | 27 | dbquery("UPDATE chanserv.chanusers SET usetime=%lu WHERE userID=%u and channelID=%u", |
b263aa79 | 28 | rcup->usetime, rcup->user->ID, rcup->chan->ID); |
29 | } | |
30 | ||
31 | void csdb_updatetopic(regchan *rcp) { | |
32 | char esctopic[TOPICLEN*2+5]; | |
33 | ||
34 | if (rcp->topic) { | |
ee8cd7d0 | 35 | dbescapestring(esctopic,rcp->topic->content,rcp->topic->length); |
b263aa79 | 36 | } else { |
37 | esctopic[0]='\0'; | |
38 | } | |
ee8cd7d0 | 39 | dbquery("UPDATE chanserv.channels SET topic='%s' WHERE ID=%u",esctopic,rcp->ID); |
b263aa79 | 40 | } |
41 | ||
42 | void csdb_updatechannel(regchan *rcp) { | |
80d2de64 P |
43 | char escwelcome[WELCOMELEN*2+1]; |
44 | char esctopic[TOPICLEN*2+1]; | |
b263aa79 | 45 | char esckey[70]; |
46 | char escreason[510]; | |
47 | char esccomment[510]; | |
48 | char escname[1000]; | |
49 | ||
ee8cd7d0 | 50 | dbescapestring(escname, rcp->index->name->content, rcp->index->name->length); |
b263aa79 | 51 | |
52 | if (rcp->welcome) | |
ee8cd7d0 | 53 | dbescapestring(escwelcome, rcp->welcome->content, |
b263aa79 | 54 | rcp->welcome->length); |
55 | else | |
56 | escwelcome[0]='\0'; | |
57 | ||
58 | if (rcp->topic) | |
ee8cd7d0 | 59 | dbescapestring(esctopic, rcp->topic->content, rcp->topic->length); |
b263aa79 | 60 | else |
61 | esctopic[0]='\0'; | |
62 | ||
63 | if (rcp->key) | |
ee8cd7d0 | 64 | dbescapestring(esckey, rcp->key->content, rcp->key->length); |
b263aa79 | 65 | else |
66 | esckey[0]='\0'; | |
67 | ||
68 | if (rcp->suspendreason) | |
ee8cd7d0 | 69 | dbescapestring(escreason, rcp->suspendreason->content, |
b263aa79 | 70 | rcp->suspendreason->length); |
71 | else | |
72 | escreason[0]='\0'; | |
73 | ||
74 | if (rcp->comment) | |
ee8cd7d0 | 75 | dbescapestring(esccomment, rcp->comment->content, |
b263aa79 | 76 | rcp->comment->length); |
77 | else | |
78 | esccomment[0]='\0'; | |
79 | ||
ee8cd7d0 | 80 | dbquery("UPDATE chanserv.channels SET name='%s', flags=%d, forcemodes=%d," |
b263aa79 | 81 | "denymodes=%d, chanlimit=%d, autolimit=%d, banstyle=%d," |
82 | "lastactive=%lu,statsreset=%lu, banduration=%lu, founder=%u," | |
e086bfee | 83 | "addedby=%u, suspendby=%u, suspendtime=%lu, chantype=%d, totaljoins=%u," |
b263aa79 | 84 | "tripjoins=%u, maxusers=%u, tripusers=%u," |
85 | "welcome='%s', topic='%s', chankey='%s', suspendreason='%s'," | |
16739dbe | 86 | "comment='%s', lasttimestamp=%jd WHERE ID=%u",escname,rcp->flags,rcp->forcemodes, |
b263aa79 | 87 | rcp->denymodes,rcp->limit,rcp->autolimit, rcp->banstyle, |
88 | rcp->lastactive,rcp->statsreset,rcp->banduration, | |
88d191e3 | 89 | rcp->founder, rcp->addedby, rcp->suspendby, rcp->suspendtime, |
b263aa79 | 90 | rcp->chantype,rcp->totaljoins,rcp->tripjoins, |
91 | rcp->maxusers,rcp->tripusers, | |
58a4da4a | 92 | escwelcome,esctopic,esckey,escreason,esccomment,(intmax_t)rcp->ltimestamp,rcp->ID); |
b263aa79 | 93 | } |
94 | ||
95 | void csdb_updatechannelcounters(regchan *rcp) { | |
ee8cd7d0 | 96 | dbquery("UPDATE chanserv.channels SET " |
b263aa79 | 97 | "lastactive=%lu, totaljoins=%u," |
98 | "tripjoins=%u, maxusers=%u, tripusers=%u " | |
99 | "WHERE ID=%u", | |
100 | rcp->lastactive, | |
101 | rcp->totaljoins,rcp->tripjoins, | |
102 | rcp->maxusers,rcp->tripusers, | |
103 | rcp->ID); | |
104 | } | |
105 | ||
106 | void csdb_updatechanneltimestamp(regchan *rcp) { | |
ee8cd7d0 | 107 | dbquery("UPDATE chanserv.channels SET " |
16739dbe | 108 | "lasttimestamp=%jd WHERE ID=%u", |
58a4da4a | 109 | (intmax_t)rcp->ltimestamp, rcp->ID); |
b263aa79 | 110 | } |
111 | ||
112 | void csdb_createchannel(regchan *rcp) { | |
80d2de64 P |
113 | char escwelcome[WELCOMELEN*2+1]; |
114 | char esctopic[TOPICLEN*2+1]; | |
b263aa79 | 115 | char esckey[70]; |
116 | char escreason[510]; | |
117 | char esccomment[510]; | |
118 | char escname[510]; | |
119 | ||
ee8cd7d0 | 120 | dbescapestring(escname, rcp->index->name->content, rcp->index->name->length); |
b263aa79 | 121 | |
122 | if (rcp->welcome) | |
ee8cd7d0 | 123 | dbescapestring(escwelcome, rcp->welcome->content, |
b263aa79 | 124 | rcp->welcome->length); |
125 | else | |
126 | escwelcome[0]='\0'; | |
127 | ||
128 | if (rcp->topic) | |
ee8cd7d0 | 129 | dbescapestring(esctopic, rcp->topic->content, rcp->topic->length); |
b263aa79 | 130 | else |
131 | esctopic[0]='\0'; | |
132 | ||
133 | if (rcp->key) | |
ee8cd7d0 | 134 | dbescapestring(esckey, rcp->key->content, rcp->key->length); |
b263aa79 | 135 | else |
136 | esckey[0]='\0'; | |
137 | ||
138 | if (rcp->suspendreason) | |
ee8cd7d0 | 139 | dbescapestring(escreason, rcp->suspendreason->content, |
b263aa79 | 140 | rcp->suspendreason->length); |
141 | else | |
142 | escreason[0]='\0'; | |
143 | ||
144 | if (rcp->comment) | |
ee8cd7d0 | 145 | dbescapestring(esccomment, rcp->comment->content, |
b263aa79 | 146 | rcp->comment->length); |
147 | else | |
148 | esccomment[0]='\0'; | |
149 | ||
ee8cd7d0 | 150 | dbquery("INSERT INTO chanserv.channels (ID, name, flags, forcemodes, denymodes," |
b263aa79 | 151 | "chanlimit, autolimit, banstyle, created, lastactive, statsreset, " |
88d191e3 | 152 | "banduration, founder, addedby, suspendby, suspendtime, chantype, totaljoins, tripjoins," |
b263aa79 | 153 | "maxusers, tripusers, welcome, topic, chankey, suspendreason, " |
154 | "comment, lasttimestamp) VALUES (%u,'%s',%d,%d,%d,%d,%d,%d,%lu,%lu,%lu,%lu,%u," | |
16739dbe | 155 | "%u,%u,%lu,%d,%u,%u,%u,%u,'%s','%s','%s','%s','%s',%jd)", |
b263aa79 | 156 | rcp->ID, escname, rcp->flags,rcp->forcemodes, |
157 | rcp->denymodes,rcp->limit,rcp->autolimit, rcp->banstyle, rcp->created, | |
158 | rcp->lastactive,rcp->statsreset,rcp->banduration, | |
88d191e3 | 159 | rcp->founder, rcp->addedby, rcp->suspendby, rcp->suspendtime, |
b263aa79 | 160 | rcp->chantype,rcp->totaljoins,rcp->tripjoins, |
161 | rcp->maxusers,rcp->tripusers, | |
58a4da4a | 162 | escwelcome,esctopic,esckey,escreason,esccomment,(intmax_t)rcp->ltimestamp); |
b263aa79 | 163 | } |
164 | ||
165 | void csdb_deletechannel(regchan *rcp) { | |
ee8cd7d0 CP |
166 | dbquery("DELETE FROM chanserv.channels WHERE ID=%u",rcp->ID); |
167 | dbquery("DELETE FROM chanserv.chanusers WHERE channelID=%u",rcp->ID); | |
168 | dbquery("DELETE FROM chanserv.bans WHERE channelID=%u",rcp->ID); | |
b263aa79 | 169 | } |
170 | ||
171 | void csdb_deleteuser(reguser *rup) { | |
ee8cd7d0 CP |
172 | dbquery("DELETE FROM chanserv.users WHERE ID=%u",rup->ID); |
173 | dbquery("DELETE FROM chanserv.chanusers WHERE userID=%u",rup->ID); | |
b263aa79 | 174 | } |
175 | ||
176 | void csdb_updateuser(reguser *rup) { | |
177 | char escpassword[25]; | |
b263aa79 | 178 | char escemail[210]; |
179 | char esclastuserhost[160]; | |
180 | char escreason[510]; | |
181 | char esccomment[510]; | |
182 | char escinfo[210]; | |
9708f78f CP |
183 | char esclastemail[210]; |
184 | ||
ee8cd7d0 | 185 | dbescapestring(escpassword, rup->password, strlen(rup->password)); |
b263aa79 | 186 | |
187 | if (rup->email) | |
ee8cd7d0 | 188 | dbescapestring(escemail, rup->email->content, rup->email->length); |
b263aa79 | 189 | else |
190 | escemail[0]='\0'; | |
191 | ||
9708f78f | 192 | if (rup->lastemail) |
ee8cd7d0 | 193 | dbescapestring(esclastemail, rup->lastemail->content, rup->lastemail->length); |
9708f78f CP |
194 | else |
195 | esclastemail[0]='\0'; | |
196 | ||
b263aa79 | 197 | if (rup->lastuserhost) |
ee8cd7d0 | 198 | dbescapestring(esclastuserhost, rup->lastuserhost->content, rup->lastuserhost->length); |
b263aa79 | 199 | else |
200 | esclastuserhost[0]='\0'; | |
201 | ||
202 | if (rup->suspendreason) | |
ee8cd7d0 | 203 | dbescapestring(escreason, rup->suspendreason->content, rup->suspendreason->length); |
b263aa79 | 204 | else |
205 | escreason[0]='\0'; | |
206 | ||
207 | if (rup->comment) | |
ee8cd7d0 | 208 | dbescapestring(esccomment, rup->comment->content, rup->comment->length); |
b263aa79 | 209 | else |
210 | esccomment[0]='\0'; | |
211 | ||
212 | if (rup->info) | |
ee8cd7d0 | 213 | dbescapestring(escinfo, rup->info->content, rup->info->length); |
b263aa79 | 214 | else |
215 | escinfo[0]='\0'; | |
216 | ||
ee8cd7d0 | 217 | dbquery("UPDATE chanserv.users SET lastauth=%lu, lastemailchng=%lu, flags=%u," |
b438f642 | 218 | "language=%u, suspendby=%u, suspendexp=%lu, suspendtime=%lu, lockuntil=%lu, password='%s', email='%s'," |
9708f78f | 219 | "lastuserhost='%s', suspendreason='%s', comment='%s', info='%s', lastemail='%s' WHERE ID=%u", |
b263aa79 | 220 | rup->lastauth, rup->lastemailchange, rup->flags, rup->languageid, rup->suspendby, rup->suspendexp, |
9708f78f | 221 | rup->suspendtime, rup->lockuntil, escpassword, escemail, esclastuserhost, escreason, esccomment, escinfo, esclastemail, |
b263aa79 | 222 | rup->ID); |
223 | } | |
224 | ||
225 | void csdb_createuser(reguser *rup) { | |
226 | char escpassword[25]; | |
b263aa79 | 227 | char escemail[210]; |
228 | char esclastuserhost[160]; | |
229 | char escreason[510]; | |
230 | char esccomment[510]; | |
231 | char escusername[35]; | |
232 | char escinfo[210]; | |
9708f78f | 233 | char esclastemail[210]; |
b263aa79 | 234 | |
ee8cd7d0 CP |
235 | dbescapestring(escusername, rup->username, strlen(rup->username)); |
236 | dbescapestring(escpassword, rup->password, strlen(rup->password)); | |
b263aa79 | 237 | |
238 | if (rup->email) | |
ee8cd7d0 | 239 | dbescapestring(escemail, rup->email->content, rup->email->length); |
b263aa79 | 240 | else |
241 | escemail[0]='\0'; | |
242 | ||
9708f78f | 243 | if (rup->lastemail) |
ee8cd7d0 | 244 | dbescapestring(esclastemail, rup->lastemail->content, rup->lastemail->length); |
9708f78f CP |
245 | else |
246 | esclastemail[0]='\0'; | |
247 | ||
b263aa79 | 248 | if (rup->lastuserhost) |
ee8cd7d0 | 249 | dbescapestring(esclastuserhost, rup->lastuserhost->content, rup->lastuserhost->length); |
b263aa79 | 250 | else |
251 | esclastuserhost[0]='\0'; | |
252 | ||
253 | if (rup->suspendreason) | |
ee8cd7d0 | 254 | dbescapestring(escreason, rup->suspendreason->content, rup->suspendreason->length); |
b263aa79 | 255 | else |
256 | escreason[0]='\0'; | |
257 | ||
258 | if (rup->comment) | |
ee8cd7d0 | 259 | dbescapestring(esccomment, rup->comment->content, rup->comment->length); |
b263aa79 | 260 | else |
261 | esccomment[0]='\0'; | |
262 | ||
263 | if (rup->info) | |
ee8cd7d0 | 264 | dbescapestring(escinfo, rup->info->content, rup->info->length); |
b263aa79 | 265 | else |
266 | escinfo[0]='\0'; | |
267 | ||
ee8cd7d0 | 268 | dbquery("INSERT INTO chanserv.users (ID, username, created, lastauth, lastemailchng, " |
b438f642 | 269 | "flags, language, suspendby, suspendexp, suspendtime, lockuntil, password, email, lastuserhost, " |
f5fd3158 | 270 | "suspendreason, comment, info, lastemail) VALUES (%u,'%s',%lu,%lu,%lu,%u,%u,%u,%lu,%lu,%lu,'%s','%s'," |
9708f78f | 271 | "'%s','%s','%s','%s','%s')", |
b263aa79 | 272 | rup->ID, escusername, rup->created, rup->lastauth, rup->lastemailchange, rup->flags, |
b438f642 | 273 | rup->languageid, rup->suspendby, rup->suspendexp, rup->suspendtime, rup->lockuntil, |
9708f78f | 274 | escpassword, escemail, esclastuserhost, escreason, esccomment, escinfo, esclastemail); |
b263aa79 | 275 | } |
276 | ||
277 | ||
278 | void csdb_updatechanuser(regchanuser *rcup) { | |
279 | char escinfo[210]; | |
280 | ||
281 | if (rcup->info) | |
ee8cd7d0 | 282 | dbescapestring(escinfo, rcup->info->content, rcup->info->length); |
b263aa79 | 283 | else |
284 | escinfo[0]='\0'; | |
285 | ||
ee8cd7d0 | 286 | dbquery("UPDATE chanserv.chanusers SET flags=%u, changetime=%lu, " |
b263aa79 | 287 | "usetime=%lu, info='%s' WHERE channelID=%u and userID=%u", |
288 | rcup->flags, rcup->changetime, rcup->usetime, escinfo, rcup->chan->ID,rcup->user->ID); | |
289 | } | |
290 | ||
291 | void csdb_createchanuser(regchanuser *rcup) { | |
292 | char escinfo[210]; | |
293 | ||
294 | if (rcup->info) | |
ee8cd7d0 | 295 | dbescapestring(escinfo, rcup->info->content, rcup->info->length); |
b263aa79 | 296 | else |
297 | escinfo[0]='\0'; | |
298 | ||
ee8cd7d0 | 299 | dbquery("INSERT INTO chanserv.chanusers VALUES(%u, %u, %u, %lu, %lu, '%s')", |
b263aa79 | 300 | rcup->user->ID, rcup->chan->ID, rcup->flags, rcup->changetime, |
301 | rcup->usetime, escinfo); | |
302 | } | |
303 | ||
304 | void csdb_deletechanuser(regchanuser *rcup) { | |
ee8cd7d0 | 305 | dbquery("DELETE FROM chanserv.chanusers WHERE channelid=%u AND userID=%u", |
b263aa79 | 306 | rcup->chan->ID, rcup->user->ID); |
307 | } | |
308 | ||
309 | void csdb_createban(regchan *rcp, regban *rbp) { | |
310 | char escreason[500]; | |
311 | char banstr[100]; | |
312 | char escban[200]; | |
313 | ||
314 | strcpy(banstr,bantostring(rbp->cbp)); | |
ee8cd7d0 | 315 | dbescapestring(escban,banstr,strlen(banstr)); |
b263aa79 | 316 | |
317 | if (rbp->reason) | |
ee8cd7d0 | 318 | dbescapestring(escreason, rbp->reason->content, rbp->reason->length); |
b263aa79 | 319 | else |
320 | escreason[0]='\0'; | |
321 | ||
ee8cd7d0 | 322 | dbquery("INSERT INTO chanserv.bans (banID, channelID, userID, hostmask, " |
b263aa79 | 323 | "expiry, reason) VALUES (%u,%u,%u,'%s',%lu,'%s')", rbp->ID, rcp->ID, |
324 | rbp->setby, escban, rbp->expiry, escreason); | |
325 | } | |
326 | ||
3fbc2554 CP |
327 | void csdb_updateban(regchan *rcp, regban *rbp) { |
328 | char escreason[500]; | |
329 | char banstr[100]; | |
330 | char escban[200]; | |
331 | ||
332 | strcpy(banstr,bantostring(rbp->cbp)); | |
ee8cd7d0 | 333 | dbescapestring(escban,banstr,strlen(banstr)); |
3fbc2554 CP |
334 | |
335 | if (rbp->reason) | |
ee8cd7d0 | 336 | dbescapestring(escreason, rbp->reason->content, rbp->reason->length); |
3fbc2554 CP |
337 | else |
338 | escreason[0]='\0'; | |
339 | ||
ee8cd7d0 | 340 | dbquery("UPDATE chanserv.bans set channelID=%u, userID=%u, hostmask='%s', expiry=%lu, reason='%s' " |
3fbc2554 CP |
341 | "WHERE banID=%u", rcp->ID, rbp->setby, escban, rbp->expiry, escreason, rbp->ID); |
342 | } | |
343 | ||
b263aa79 | 344 | void csdb_deleteban(regban *rbp) { |
ee8cd7d0 | 345 | dbquery("DELETE FROM chanserv.bans WHERE banID=%u", rbp->ID); |
b263aa79 | 346 | } |
347 | ||
348 | void csdb_createmail(reguser *rup, int type) { | |
349 | char sqlquery[6000]; | |
350 | char escemail[210]; | |
351 | ||
352 | if (type == QMAIL_NEWEMAIL) { | |
353 | if (rup->email) { | |
ee8cd7d0 | 354 | dbescapestring(escemail, rup->email->content, rup->email->length); |
522e2b8c | 355 | sprintf(sqlquery, "INSERT INTO chanserv.email (userID, emailType, prevEmail) " |
b263aa79 | 356 | "VALUES (%u,%u,'%s')", rup->ID, type, escemail); |
357 | } | |
358 | } else { | |
522e2b8c | 359 | sprintf(sqlquery, "INSERT INTO chanserv.email (userID, emailType) VALUES (%u,%u)", rup->ID, type); |
b263aa79 | 360 | } |
361 | ||
ee8cd7d0 | 362 | dbquery("%s", sqlquery); |
183b8e2f P |
363 | } |
364 | ||
365 | void csdb_deletemaildomain(maildomain *mdp) { | |
ee8cd7d0 | 366 | dbquery("DELETE FROM chanserv.maildomain WHERE ID=%u", mdp->ID); |
183b8e2f P |
367 | } |
368 | ||
369 | void csdb_createmaildomain(maildomain *mdp) { | |
370 | char escdomain[210]; | |
ee8cd7d0 | 371 | dbescapestring(escdomain, mdp->name->content, mdp->name->length); |
183b8e2f | 372 | |
ee8cd7d0 | 373 | dbquery("INSERT INTO chanserv.maildomain (id, name, domainlimit, actlimit, flags) VALUES(%u, '%s', %u, %u, %u)", mdp->ID,escdomain,mdp->limit,mdp->actlimit,mdp->flags); |
183b8e2f P |
374 | } |
375 | ||
376 | void csdb_updatemaildomain(maildomain *mdp) { | |
377 | char escdomain[210]; | |
ee8cd7d0 | 378 | dbescapestring(escdomain, mdp->name->content, mdp->name->length); |
183b8e2f | 379 | |
ee8cd7d0 | 380 | dbquery("UPDATE chanserv.maildomain SET domainlimit=%u, actlimit=%u, flags=%u, name='%s' WHERE ID=%u", mdp->limit,mdp->actlimit,mdp->flags,escdomain,mdp->ID); |
183b8e2f P |
381 | } |
382 | ||
183b8e2f P |
383 | void csdb_chanlevhistory_insert(regchan *rcp, nick *np, reguser *trup, flag_t oldflags, flag_t newflags) { |
384 | reguser *rup=getreguserfromnick(np); | |
385 | ||
ee8cd7d0 | 386 | dbquery("INSERT INTO chanserv.chanlevhistory (userID, channelID, targetID, changetime, authtime, " |
183b8e2f P |
387 | "oldflags, newflags) VALUES (%u, %u, %u, %lu, %lu, %u, %u)", rup->ID, rcp->ID, trup->ID, getnettime(), np->accountts, |
388 | oldflags, newflags); | |
389 | } | |
390 | ||
391 | void csdb_accounthistory_insert(nick *np, char *oldpass, char *newpass, sstring *oldemail, sstring *newemail) { | |
392 | reguser *rup=getreguserfromnick(np); | |
393 | char escoldpass[30]; | |
394 | char escnewpass[30]; | |
395 | char escoldemail[130]; | |
396 | char escnewemail[130]; | |
397 | ||
398 | if (!rup || UHasOperPriv(rup)) | |
399 | return; | |
400 | ||
401 | if (oldpass) | |
ee8cd7d0 | 402 | dbescapestring(escoldpass, oldpass, strlen(oldpass)); |
183b8e2f P |
403 | else |
404 | escoldpass[0]='\0'; | |
405 | ||
406 | if (newpass) | |
ee8cd7d0 | 407 | dbescapestring(escnewpass, newpass, strlen(newpass)); |
183b8e2f P |
408 | else |
409 | escnewpass[0]='\0'; | |
410 | ||
411 | if (oldemail) | |
ee8cd7d0 | 412 | dbescapestring(escoldemail, oldemail->content, oldemail->length); |
183b8e2f P |
413 | else |
414 | escoldemail[0]='\0'; | |
415 | if (newemail) | |
ee8cd7d0 | 416 | dbescapestring(escnewemail, newemail->content, newemail->length); |
183b8e2f P |
417 | else |
418 | escnewemail[0]='\0'; | |
419 | ||
ee8cd7d0 | 420 | dbquery("INSERT INTO chanserv.accounthistory (userID, changetime, authtime, oldpassword, newpassword, oldemail, " |
183b8e2f P |
421 | "newemail) VALUES (%u, %lu, %lu, '%s', '%s', '%s', '%s')", rup->ID, getnettime(), np->accountts, escoldpass, escnewpass, |
422 | escoldemail, escnewemail); | |
423 | ||
424 | if (newemail) | |
425 | freesstring(newemail); | |
426 | } | |
427 | ||
428 | void csdb_cleanuphistories() { | |
429 | time_t expire_time=getnettime()-604800; | |
430 | ||
431 | Error("chanserv", ERR_INFO, "Cleaning histories."); | |
ee8cd7d0 CP |
432 | dbquery("DELETE FROM chanserv.authhistory WHERE authtime < %lu", expire_time); |
433 | dbquery("DELETE FROM chanserv.chanlevhistory WHERE changetime < %lu", expire_time); | |
434 | dbquery("DELETE FROM chanserv.accounthistory WHERE changetime < %lu", expire_time); | |
183b8e2f P |
435 | } |
436 | ||
97390b65 | 437 | void csdb_deletemaillock(maillock *mlp) { |
ee8cd7d0 | 438 | dbquery("DELETE FROM chanserv.maillocks WHERE ID=%u", mlp->id); |
97390b65 CP |
439 | } |
440 | ||
441 | void csdb_createmaillock(maillock *mlp) { | |
442 | char escpattern[1024], escreason[1024]; | |
443 | ||
ee8cd7d0 | 444 | dbescapestring(escpattern, mlp->pattern->content, mlp->pattern->length); |
97390b65 CP |
445 | |
446 | if (mlp->reason) | |
ee8cd7d0 | 447 | dbescapestring(escreason, mlp->reason->content, mlp->reason->length); |
97390b65 CP |
448 | else |
449 | escreason[0]='\0'; | |
450 | ||
16739dbe | 451 | dbquery("INSERT INTO chanserv.maillocks (id, pattern, reason, createdby, created) VALUES(%u, '%s', '%s', %u, %jd)", |
58a4da4a | 452 | mlp->id,escpattern,escreason,mlp->createdby,(intmax_t)mlp->created); |
97390b65 CP |
453 | } |
454 | ||
455 | void csdb_updatemaillock(maillock *mlp) { | |
456 | char escpattern[1024], escreason[1024]; | |
457 | ||
ee8cd7d0 | 458 | dbescapestring(escpattern, mlp->pattern->content, mlp->pattern->length); |
97390b65 CP |
459 | |
460 | if (mlp->reason) | |
ee8cd7d0 | 461 | dbescapestring(escreason, mlp->reason->content, mlp->reason->length); |
97390b65 CP |
462 | else |
463 | escreason[0]='\0'; | |
464 | ||
58a4da4a | 465 | dbquery("UPDATE chanserv.maillocks SET pattern='%s', reason='%s', createdby=%u, created=%jd WHERE ID=%u", escpattern, escreason, mlp->createdby, (intmax_t)mlp->created, mlp->id); |
97390b65 CP |
466 | } |
467 |