bug 1003: Initial version of reset permissions script
authorMichael Tänzer <neo@nhng.de>
Tue, 8 May 2012 14:44:26 +0000 (16:44 +0200)
committerMichael Tänzer <neo@nhng.de>
Tue, 8 May 2012 14:44:26 +0000 (16:44 +0200)
Signed-off-by: Michael Tänzer <neo@nhng.de>
scripts/resetpermissions.php [new file with mode: 0644]

diff --git a/scripts/resetpermissions.php b/scripts/resetpermissions.php
new file mode 100644 (file)
index 0000000..f97ad9d
--- /dev/null
@@ -0,0 +1,57 @@
+#!/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(! $res = mysql_query($query) ) {
+                       echo " NOT RESET!!!\n";
+                       fwrite(STDERR,
+                                       "MySQL query for flag $flag failed:\n".
+                                       "\"$query\"\n".
+                                       mysql_error()
+                       );
+                       
+               } else {
+                       echo " reset.\n";
+               }
+       }
+       
+       echo "\n\n";
+}
\ No newline at end of file