summaryrefslogtreecommitdiff
path: root/scripts/resetpermissions.php
blob: 0bfdaa38207d2c3cb68f9f559bf7523a0e536bf8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/php -q
<?php
/*
LibreSSL - CAcert web application
Copyright (C) 2004-2012  CAcert Inc.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

require_once(dirname(__FILE__).'/../includes/mysql.php');

$flags = array('board', 'tverify');

foreach ($flags as $flag) {
	echo "Resetting $flag flag:\n";
	$query = "select `id`, `fname`, `lname`, `email` from `users`
			where `$flag` = 1";
	if(! $res = mysql_query($query) ) {
		fwrite(STDERR,
				"MySQL query for flag $flag failed:\n".
				"\"$query\"\n".
				mysql_error()
		);
	
		continue;
	}
	
	while ($row = mysql_fetch_assoc($res)) {
		echo "$row[fname] $row[lname] $row[email]";
		
		$update = "update `users` set `$flag` = 0 where `id` = $row[id]";
		if(! $res2 = mysql_query($update) ) {
			echo " NOT RESET!!!\n";
			fwrite(STDERR,
					"MySQL query for $flag flag reset on user $row[id] failed:\n".
					"\"$update\"\n".
					mysql_error()
			);
			
		} else {
			
			$message = <<<EOF
Hi $row[fname],

As per Arbitration a20110118.1 [1] the $flag permission has been removed
from your account.

[1] https://wiki.cacert.org/Arbitrations/a20110118.1

Best Regards,
CAcert Support
EOF;
			sendmail($row['email'], "Permissions have been reset", $message, 'support@cacert.org');
			
			echo " reset.\n";
		}
	}
	
	echo "\n\n";
}