Add ability to create custom user/permissions groups
This commit is contained in:
@@ -1162,18 +1162,28 @@
|
||||
* ====================
|
||||
*/
|
||||
|
||||
// Probably best not to change these:
|
||||
if (!defined('JANITOR')) {
|
||||
define('JANITOR', 0, true);
|
||||
define('MOD', 1, true);
|
||||
define('ADMIN', 2, true);
|
||||
define('DISABLED', 3, true);
|
||||
}
|
||||
// Probably best not to change this unless you are smart enough to figure out what you're doing. If you
|
||||
// decide to change it, remember that it is impossible to redefinite/overwrite groups; you may only add
|
||||
// new ones.
|
||||
$config['mod']['groups'] = array(
|
||||
10 => 'Janitor',
|
||||
20 => 'Mod',
|
||||
30 => 'Admin',
|
||||
// 98 => 'God',
|
||||
99 => 'Disabled'
|
||||
);
|
||||
|
||||
// If you add stuff to the above, you'll need to call this function immediately after.
|
||||
define_groups();
|
||||
|
||||
// Example: Adding a new permissions group.
|
||||
// $config['mod']['groups'][0] = 'NearlyPowerless';
|
||||
// define_groups();
|
||||
|
||||
// Capcode permissions.
|
||||
$config['mod']['capcode'] = array(
|
||||
// JANITOR => array('Janitor'),
|
||||
MOD => array('Mod'),
|
||||
MOD => array('Mod'),
|
||||
ADMIN => true
|
||||
);
|
||||
|
||||
@@ -1312,18 +1322,14 @@
|
||||
$config['mod']['edit_config'] = ADMIN;
|
||||
|
||||
// Config editor permissions
|
||||
$config['mod']['config'] = array(
|
||||
JANITOR => false,
|
||||
MOD => false,
|
||||
ADMIN => false,
|
||||
DISABLED => false,
|
||||
);
|
||||
$config['mod']['config'] = array();
|
||||
|
||||
// Disable the following configuration variables from being changed via ?/config. The following default
|
||||
// banned variables are considered somewhat dangerous.
|
||||
$config['mod']['config'][DISABLED] = array(
|
||||
'mod>config',
|
||||
'mod>config_editor_php',
|
||||
'mod>groups',
|
||||
'convert_args',
|
||||
'db>password',
|
||||
);
|
||||
|
@@ -265,6 +265,15 @@ function verbose_error_handler($errno, $errstr, $errfile, $errline) {
|
||||
));
|
||||
}
|
||||
|
||||
function define_groups() {
|
||||
global $config;
|
||||
|
||||
foreach ($config['mod']['groups'] as $group_value => $group_name)
|
||||
defined($group_name) or define($group_name, $group_value, true);
|
||||
|
||||
ksort($config['mod']['groups']);
|
||||
}
|
||||
|
||||
function create_antibot($board, $thread = null) {
|
||||
require_once dirname(__FILE__) . '/anti-bot.php';
|
||||
|
||||
|
@@ -3,7 +3,7 @@
|
||||
function permission_to_edit_config_var($varname) {
|
||||
global $config, $mod;
|
||||
|
||||
if (is_array($config['mod']['config'][DISABLED])) {
|
||||
if (isset($config['mod']['config'][DISABLED])) {
|
||||
foreach ($config['mod']['config'][DISABLED] as $disabled_var_name) {
|
||||
$disabled_var_name = explode('>', $disabled_var_name);
|
||||
if (count($disabled_var_name) == 1)
|
||||
@@ -14,10 +14,11 @@ function permission_to_edit_config_var($varname) {
|
||||
}
|
||||
|
||||
$allow_only = false;
|
||||
// for ($perm = (int)$mod['type']; $perm >= JANITOR; $perm --) {
|
||||
for ($perm = JANITOR; $perm <= (int)$mod['type']; $perm ++) {
|
||||
foreach ($config['mod']['groups'] as $perm => $perm_name) {
|
||||
if ($perm > $mod['type'])
|
||||
break;
|
||||
$allow_only = false;
|
||||
if (is_array($config['mod']['config'][$perm])) {
|
||||
if (isset($config['mod']['config'][$perm]) && is_array($config['mod']['config'][$perm])) {
|
||||
foreach ($config['mod']['config'][$perm] as $perm_var_name) {
|
||||
if ($perm_var_name == '!') {
|
||||
$allow_only = true;
|
||||
@@ -92,7 +93,7 @@ function config_vars() {
|
||||
continue; // This is just an alias.
|
||||
if (!preg_match('/^array|\[\]|function/', $var['default']) && !preg_match('/^Example: /', trim(implode(' ', $var['comment'])))) {
|
||||
$syntax_error = true;
|
||||
$temp = eval('$syntax_error = false;return ' . $var['default'] . ';');
|
||||
$temp = eval('$syntax_error = false;return @' . $var['default'] . ';');
|
||||
if ($syntax_error && $temp === false) {
|
||||
error('Error parsing config.php (line ' . $line_no . ')!', null, $var);
|
||||
} elseif (!isset($temp)) {
|
||||
|
@@ -1674,11 +1674,39 @@ function mod_user_promote($uid, $action) {
|
||||
if (!hasPermission($config['mod']['promoteusers']))
|
||||
error($config['error']['noaccess']);
|
||||
|
||||
$query = prepare("UPDATE ``mods`` SET `type` = `type` " . ($action == 'promote' ? "+1 WHERE `type` < " . (int)ADMIN : "-1 WHERE `type` > " . (int)JANITOR) . " AND `id` = :id");
|
||||
$query = prepare("SELECT `type`, `username` FROM ``mods`` WHERE `id` = :id");
|
||||
$query->bindValue(':id', $uid);
|
||||
$query->execute() or error(db_error($query));
|
||||
|
||||
modLog(($action == 'promote' ? 'Promoted' : 'Demoted') . " user #{$uid}");
|
||||
if (!$mod = $query->fetch(PDO::FETCH_ASSOC))
|
||||
error($config['error']['404']);
|
||||
|
||||
$new_group = false;
|
||||
|
||||
$groups = $config['mod']['groups'];
|
||||
if ($action == 'demote')
|
||||
$groups = array_reverse($groups, true);
|
||||
|
||||
foreach ($groups as $group_value => $group_name) {
|
||||
if ($action == 'promote' && $group_value > $mod['type']) {
|
||||
$new_group = $group_value;
|
||||
break;
|
||||
} elseif ($action == 'demote' && $group_value < $mod['type']) {
|
||||
$new_group = $group_value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($new_group === false || $new_group == DISABLED)
|
||||
error(_('Impossible to promote/demote user.'));
|
||||
|
||||
$query = prepare("UPDATE ``mods`` SET `type` = :group_value WHERE `id` = :id");
|
||||
$query->bindValue(':id', $uid);
|
||||
$query->bindValue(':group_value', $new_group);
|
||||
$query->execute() or error(db_error($query));
|
||||
|
||||
modLog(($action == 'promote' ? 'Promoted' : 'Demoted') . ' user "' .
|
||||
utf8tohtml($mod['username']) . '" to ' . $config['mod']['groups'][$new_group]);
|
||||
|
||||
header('Location: ?/users', true, $config['redirect_http']);
|
||||
}
|
||||
@@ -2069,14 +2097,8 @@ function mod_config($board_config = false) {
|
||||
|
||||
|
||||
$config_append .= ' = ';
|
||||
if (@$var['permissions'] && in_array($value, array(JANITOR, MOD, ADMIN, DISABLED))) {
|
||||
$perm_array = array(
|
||||
JANITOR => 'JANITOR',
|
||||
MOD => 'MOD',
|
||||
ADMIN => 'ADMIN',
|
||||
DISABLED => 'DISABLED'
|
||||
);
|
||||
$config_append .= $perm_array[$value];
|
||||
if (@$var['permissions'] && isset($config['mod']['groups'][$value])) {
|
||||
$config_append .= $config['mod']['groups'][$value];
|
||||
} else {
|
||||
$config_append .= var_export($value, true);
|
||||
}
|
||||
|
Reference in New Issue
Block a user