bug-1341: Restrict to 1 login per 5 seconds
[cacert-devel.git] / scripts / notify.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 include_once("../includes/mysql.php");
21
22 $query = "select `users`.`fname` as `fname`, `email`.`id` as `id`, `email`.`email` as `email` from `users`,`email`
23 where `users`.`verified`=0 and
24 (UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(`users`.`created`)) >= 300 and
25 `users`.`id`=`email`.`memid` and `users`.`email`=`email`.`email`";
26 $res = mysql_query($query);
27 while($row = mysql_fetch_assoc($res))
28 {
29 $rnd = fopen("/dev/urandom", "r");
30 $hash = md5(fgets($rnd, 64));
31 fclose($rnd);
32
33 mysql_query("update `email` set `hash`='$hash' where `id`='".$row['id']."'");
34
35 $body = "Hi ".$row['fname']."\n\n";
36 $body .= "Due to some bugs with the new website we initially had issues with emails being sent out. This email is being sent to those effected so they can be re-sent their email probe to over come earlier issues. We apologise for any inconvenience this may have cause. To verify your account, simply click on the link below.\n\n";
37 $body .= "http://www.cacert.org/verify.php?type=email&emailid=".$row['id']."&hash=$hash\n\n";
38 $body .= "Best Regards\nCAcert Support Team";
39 echo $row['email']."\n";
40 sendmail($row['email'], "[CAcert.org] Email Probe", $body, "support@cacert.org", "", "", "CAcert Support");
41 }
42 ?>