Source code taken from cacert-20120329.tar.bz2
[cacert.git] / scripts / cron / removedead.php
1 #!/usr/bin/php -q
2 <? /*
3 LibreSSL - CAcert web application
4 Copyright (C) 2004-2008 CAcert Inc.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; version 2 of the License.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 require_once(dirname(__FILE__).'/../../includes/mysql.php');
21 require_once(dirname(__FILE__).'/../../includes/lib/l10n.php');
22
23 $query = "select * from `users` where `users`.`verified`=0 and
24 (UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(`users`.`created`)) >= 172800";
25 $res = mysql_query($query);
26 while($row = mysql_fetch_assoc($res))
27 {
28 mysql_query("delete from `email` where `memid`='".$row['id']."'");
29 mysql_query("delete from `users` where `id`='".$row['id']."'");
30 }
31
32 $query = "delete from `domains` where `hash`!='' and
33 (UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(`created`)) >= 172800";
34 mysql_query($query);
35
36 $query = "delete from `email` where `hash`!='' and
37 (UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(`created`)) >= 172800";
38 mysql_query($query);
39
40 $query = "delete from `disputedomain` where `hash`!='' and
41 (UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(`created`)) >= 21600";
42 mysql_query($query);
43
44 $query = "delete from `disputeemail` where `hash`!='' and
45 (UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(`created`)) >= 21600";
46 mysql_query($query);
47
48 $query = "select * from `notary` where `expire`!=0 and `expire`<NOW()";
49 $res = mysql_query($query);
50 while($row = mysql_fetch_assoc($res))
51 {
52 $query = "select sum(`points`) as `points` from `notary` where `to`='$row[to]' and `expire`=0 group by `to`";
53 $dres = mysql_query($query);
54 $drow = mysql_fetch_assoc($dres);
55 if($drow['points'] >= 150)
56 {
57 $query = "update `notary` set `expire`=0, `points`='0' where `to`='$row[to]' and `from`='$row[from]' and `expire`='$row[expire]'";
58 } else {
59 $newpoints = 150 - $drow['points'];
60 $query = "update `notary` set `expire`=0, `points`='0' where `to`='$row[to]' and `from`='$row[from]' and `expire`='$row[expire]'";
61 mysql_query($query);
62 $query = "insert into `notary` set `expire`=0, `points`='$newpoints', `to`='$row[to]', `from`='$row[from]', `when`=NOW(), `method`='Administrative Increase', `date`=NOW()";
63 }
64
65 $data = mysql_fetch_assoc(mysql_query("select * from `users` where `id`='$row[to]'"));
66 $body = sprintf("%s %s (%s) had a temporary increase, but this has just expired and they have been reduced to 150 points.", $data['fname'], $data['lname'], $data['email'])."\n\n";
67 sendmail("cacert-board@lists.cacert.org", "[CAcert.org] Temporary Increase Expired.", $body, "website@cacert.org", "", "", "CAcert Website");
68
69 if($data['language'] != "")
70 {
71 L10n::set_translation($data['language']);
72 }
73
74 $body = _("You are receiving this email because you had a temporary increase to 200 points. This has since expired and you have been reduced to 150 points.")."\n\n";
75 $body = _("If you needed more time or any other extenuating circumstances you should contact us immediately so this situation can be dealt with immediately.")."\n\n";
76
77 $body .= _("Best regards")."\n";
78 $body .= _("CAcert Support Team");
79
80 sendmail($data['email'], "[CAcert.org] "._("Temporary points increase has expired."), $body, "support@cacert.org", "", "", "CAcert Website");
81
82 mysql_query($query);
83 fix_assurer_flag($row[to]);
84 }
85 ?>