Merge branch 'bug-1339' into release
[cacert-devel.git] / scripts / resetpermissions.php
1 #!/usr/bin/php -q
2 <?php
3 /*
4 LibreSSL - CAcert web application
5 Copyright (C) 2004-2012 CAcert Inc.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; version 2 of the License.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 require_once(dirname(__FILE__).'/../includes/mysql.php');
22
23 $flags = array('board', 'tverify');
24
25 foreach ($flags as $flag) {
26 echo "Resetting $flag flag:\n";
27 $query = "select `id`, `fname`, `lname`, `email` from `users`
28 where `$flag` = 1";
29 if(! $res = mysql_query($query) ) {
30 fwrite(STDERR,
31 "MySQL query for flag $flag failed:\n".
32 "\"$query\"\n".
33 mysql_error()
34 );
35
36 continue;
37 }
38
39 while ($row = mysql_fetch_assoc($res)) {
40 echo "$row[fname] $row[lname] $row[email]";
41
42 $update = "update `users` set `$flag` = 0 where `id` = $row[id]";
43 if(! $res2 = mysql_query($update) ) {
44 echo " NOT RESET!!!\n";
45 fwrite(STDERR,
46 "MySQL query for $flag flag reset on user $row[id] failed:\n".
47 "\"$update\"\n".
48 mysql_error()
49 );
50
51 } else {
52
53 $message = <<<EOF
54 Hi $row[fname],
55
56 As per Arbitration a20110118.1 [1] the $flag permission has been removed
57 from your account.
58
59 [1] https://wiki.cacert.org/Arbitrations/a20110118.1
60
61 Best Regards,
62 CAcert Support
63 EOF;
64 sendmail($row['email'], "Permissions have been reset", $message, 'support@cacert.org');
65
66 echo " reset.\n";
67 }
68 }
69
70 echo "\n\n";
71 }