Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Reset modules and permissions to the standard set for phpBB 3.1.x. May be useful if upgrading from 3.0.x and there is an error about a missing module, or language keys, such as, ACP_SOME_MOD, are visible in a control panel. Does not remove all database changes from MODs, it is not a database cleaner, it just removes non standard permissions and…
* Usage: Download and unzip the file, upload it to your Board's root (i.e.:
* Point your browser to i.e.: and follow instructions.
* Version 2.2.6 (3Di in 17-Jul-2017 for phpBB 3.1.11) - Oyabun1 2015
* This script is free software. It comes without any warranty.
* license GNU General Public License v2.
* 3Di side note: make sure you have a backup of your Database before to run this tool
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
// Start session management
/* If ANONYMOUS = login box */
if ((int) $user->data['user_id'] == ANONYMOUS)
login_box(request_var('redirect', "modission_reset_3110.$phpEx"));
// Limit this to founders or admins
if ((int) $user->data['user_type'] !== USER_FOUNDER || !$auth->acl_get('a_'))
trigger_error('You don\'t have permission to alter the database.
You need to be logged in as a founder or administrator.');
$ascraeus = isset($request) && ($request instanceof \phpbb\request\request_interface) ? true : false;
// Check if any extensions are installed, used later to control available options
$ext_exists = false;
$sql = "SHOW TABLES LIKE '" . EXT_TABLE . "'";
$result = $db->sql_query($sql);
if($result->num_rows > 0)
$sql = 'SELECT ext_name FROM ' . EXT_TABLE;
$result = $db->sql_query($sql);
if($result->num_rows > 0)
$ext_exists = true;
// Create a HTML5 page to add some form elements and display stuff
echo '<!DOCTYPE html>';
echo '<html>';
echo '<head>';
echo '<meta http-equiv="content-type" content="text/html; charset=UTF-8" />';
echo '<title>' . basename(__FILE__) . '</title>';
echo '<style type="text/css">
body {
font-size: 1em;
background-color: #C0C0C0 ;
width: 600px;
margin: 2em auto 0;
form {
text-align: center;
line-height: 230%;
fieldset {
border-radius: 7px;
-webkit-border-radius: 7px;
h3 {
text-align: center;
label {
cursor: pointer;
background-color: #FFD700;
border-style: outset;
border-width; 1px;
border-radius: 7px;
border-color: #808080;
font-size: 1.1em;
padding: 2px;
margin: 2px;
input[type="checkbox"]:disabled {
cursor: pointer;
img.mid {
display: block;
margin-top: 1em;
margin-left: auto;
margin-right: auto
/* Buttons based on Pressable CSS Buttons by Joshua Hibbert */
.button {
background-image: -webkit-linear-gradient(hsla(0,0%,100%,.05), hsla(0,0%,0%,.1));
background-image: -moz-linear-gradient(hsla(0,0%,100%,.05), hsla(0,0%,0%,.1));
background-image: -ms-linear-gradient(hsla(0,0%,100%,.05), hsla(0,0%,0%,.1));
background-image: -o-linear-gradient(hsla(0,0%,100%,.05), hsla(0,0%,0%,.1));
background-image: linear-gradient(hsla(0,0%,100%,.05), hsla(0,0%,0%,.1));
border: none;
border-radius: 1.25em;
box-shadow: inset 0 0 0 1px hsla(0,0%,0%,.25),
inset 0 2px 0 hsla(0,0%,100%,.1),
inset 0 1.2em 0 hsla(0,0%,100%,.05),
inset 0 -.2em 0 hsla(0,0%,100%,.1),
inset 0 -.25em 0 hsla(0,0%,0%,.5),
0 .25em .25em hsla(0,0%,0%,.1);
color: #fff;
text-shadow: 0 -1px 1px hsla(0,0%,0%,.25);
cursor: pointer;
display: inline-block;
font-family: sans-serif;
font-size: 1.1em;
font-weight: bold;
line-height: 150%;
margin: 0 .5em;
padding: .25em .75em .5em;
position: relative;
text-decoration: none;
vertical-align: middle;
.button:hover {
outline: none;
.button:focus {
box-shadow: inset 0 0 0 1px hsla(0,0%,0%,.25),
inset 0 2px 0 hsla(0,0%,100%,.1),
inset 0 1.2em 0 hsla(0,0%,100%,.05),
inset 0 -.2em 0 hsla(0,0%,100%,.1),
inset 0 -.25em 0 hsla(0,0%,0%,.5),
inset 0 0 0 3em hsla(0,0%,100%,.2),
0 .25em .25em hsla(0,0%,0%,.1);
.button:active {
box-shadow: inset 0 0 0 1px hsla(0,0%,0%,.25),
inset 0 2px 0 hsla(0,0%,100%,.1),
inset 0 1.2em 0 hsla(0,0%,100%,.05),
inset 0 0 0 3em hsla(0,0%,100%,.2),
inset 0 .25em .5em hsla(0,0%,0%,.05),
0 -1px 1px hsla(0,0%,0%,.1),
0 1px 1px hsla(0,0%,100%,.25);
margin-top: .25em;
outline: none;
padding-bottom: .5em;
.green {
background-color: #228B22;
.remove_me {
color: #FFFFFF;
width: 560px;
margin: 2em auto 0;
padding: .5em;
font-size: 1.1em;
background-color: #8B0000;
echo '</head>';
echo '<body>';
// Create a form with some checkboxes
echo '<h3>Delete Non-standard Modules and Permissions, and AutoMOD</h3>';
echo '<fieldset><legend><strong>Check selection(s) and click the Run button.</strong></legend>';
echo '<form action="' . basename(__FILE__) . '" method="post" onsubmit="return confirm(\'Make sure you first have a database backup. \n If you click OK there is no going back.\')">';
if(!$ext_exists && $ascraeus)
echo '<label title="Remove non-standard modules"><input type="checkbox" name="chkModules" value="Yes" checked />
if(!$ext_exists && $ascraeus)
echo '<label title="Remove non-standard permissions"><input type="checkbox" name="chkPerms"
value="Yes" checked />Permissions&nbsp;</label>&nbsp;';
echo '<label title="Remove AutoMOD database changes"><input type="checkbox" name="chkAmod"
value="Yes" checked />AutoMOD&nbsp;</label>&nbsp;';
echo '<p><button type="submit" class="button green";>Run</button></p>';
echo '</form>';
echo '</fieldset><br>';
echo '<fieldset style="background-color:#F5FCFF; border-color:#00CC00; border-style: solid;"><legend>
// Try to delete this file
function remove_me()
@unlink(__FILE__); // Eat any errors
// Windows IIS servers may have a problem with unlinking recently created files.
// So check if file exists and give a message
if (file_exists(__FILE__))
echo '<p class="remove_me">File could not be deleted. You will
need to manually delete the ' . basename(__FILE__) . ' file from the server.</p>';
// Use request_var() to get the returned values of selections
$chk_modules = (request_var('chkModules', ''));
$chk_perms = (request_var('chkPerms', ''));
$chk_autom = (request_var('chkAmod', ''));
// Some version checking
// includes/constants.php
$version = PHPBB_VERSION;
// config table
$sql = 'SELECT config_value FROM ' . CONFIG_TABLE . ' WHERE config_name = "version"';
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db_vers = $row['config_value'];
// First check if versions are the same
if ($version == $db_vers)
// AutoMOD stuff
// Remove database changes from AutoMOD install
if($chk_autom == 'Yes')
// Drop modules if not already cleaned
if (!$chk_modules == 'Yes')
$sql = 'DELETE FROM ' . MODULES_TABLE . ' WHERE module_langname IN (
$result = $db->sql_query($sql);
$num_mods_deleted = $db->sql_affectedrows();
echo 'Modules deleted: ' . $num_mods_deleted . '<br>';
// Drop permission if not already cleaned
if (!$chk_perms == 'Yes')
$sql = 'DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option IN (
$result = $db->sql_query($sql);
$num_perms_deleted = $db->sql_affectedrows();
echo 'Permissions deleted: ' . $num_perms_deleted . '<br>';
// Drop the rows from the config table
$sql = 'DELETE FROM ' . CONFIG_TABLE . ' WHERE config_name IN (
$result = $db->sql_query($sql);
$num_config_deleted = $db->sql_affectedrows();
echo 'Config values deleted: ' . $num_config_deleted . '<br>';
// Drop the mods table
define('MODS_TABLE', $table_prefix . 'mods');
$result = $db->sql_query('SHOW TABLE STATUS LIKE \'' . MODS_TABLE . '\'');
if($result->num_rows > 0)
$db->sql_query('DROP TABLE IF EXISTS ' . MODS_TABLE);
$table_drop = '<code>' . MODS_TABLE . '</code> table dropped<br>';
$table_drop = '<code>' . MODS_TABLE . '</code> table not found<br>';
echo $table_drop;
// Config values, permissions, and modules are cached so we'll do a purge
// We'll also clear the cached user permissions
// And throw in a log entry
add_log('admin', 'LOG_PURGE_CACHE');
// We need to be more careful in removing other modules and permissions, so check the version is in the verified range
if ( version_compare(PHPBB_VERSION, "3.1.11", "=") )
// Remove non standard modules
if($chk_modules == 'Yes' && !$ext_exists)
// If modules aren't in the list they are deleted otherwise they are ignored
$sql = 'DELETE FROM ' . MODULES_TABLE . ' WHERE module_langname NOT IN (
$result = $db->sql_query($sql);
$num_mods_deleted = $db->sql_affectedrows();
echo 'Modules deleted: ' . $num_mods_deleted . '<br>';
// Modules are cached so we'll spifflicate that
if (!$chk_autom == 'Yes')
$cache->destroy('_modules_acp', '_modules_mcp', '_modules_ucp');
// Remove non standard permissions
if($chk_perms == 'Yes')
// If permissions aren't in the list they are deleted otherwise they are ignored
// 3Di add "m_pm_report", added in 3.1.7-RC1
$sql = 'DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option NOT IN (
$result = $db->sql_query($sql);
$num_perms_deleted = $db->sql_affectedrows();
echo 'Permissions deleted: ' . $num_perms_deleted . '<br>';
// Now to clear cached permissions
if(!$chk_autom == 'Yes')
phpbb_cache_moderators($db, $cache, $auth);
echo '<form action="" method="post" target="_top"><input type="hidden" name="cmd" value="_s-xclick"><input type="hidden" name="hosted_button_id" value="ZLN6KTV2WQSRN"><input type="image" src="" border="0" name="submit" alt="PayPal – The safer, easier way to pay online."><img alt="" border="0" src="" width="1" height="1"><font color="darkred"> Help the development and maintainment of this Tool by a donation of your choice.</font></form>';
// If not correct version tell them
if (!$ascraeus)
echo 'Version is not 3.1.11 so only the AutoMOD option is available<br>';
elseif (version_compare(PHPBB_VERSION, "3.1.11", "<>"))
echo 'Version is ' . PHPBB_VERSION . ', since this file has not been fully verified to
work correctly with that only the AutoMOD option is available<br>';
echo 'phpBB version inappropriate so nothing can be deleted<br>';
if($chk_modules == 'Yes' || $chk_perms == 'Yes' || $chk_autom == 'Yes')
// If versions don't match we could trash the database, but we'll be nice and just tell them
echo 'Version mismatch:<br>/includes/constants.php ' . $version .
'<br>config table ' . $db_vers . '<br>Since the version isn\'t
clear nothing will be deleted<br>';
echo '</form>';
echo '</fieldset>';
echo '</body>';
echo '</html>';

This comment has been minimized.

Copy link
Owner Author

@3D-I 3D-I commented Jul 20, 2016

Just for the latest version of phpBB 3.1, now 3.1.9.


This comment has been minimized.

Copy link

@Leinad4Mind Leinad4Mind commented Sep 29, 2017

login_box(request_var('redirect', "modission_reset_3110.$phpEx"));

Should be 3111 ;)

Thanks for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment