Back to vBulletin 3 Articles

Custom Administrator Permissions
by Andreas 09 Sep 2005

Your Hack has an Admin Backend?
Then you should consider protecting it with custom Admin Permissions - not every Admin has to be able to control everything.

First of all, you have to decide on a uniqe Key for your Admin Permission, just like your Product ID.
In this example I will use canadminmyhack.

Go to your ACP File(s) and place the following Code below the Back-End requirement:

PHP Code:
// ######################## CHECK ADMIN PERMISSIONS #######################
if (!can_administer('canadminmyhack'))
{
    
print_cp_no_permission();

In your ACP Navigation XML Files, add the Parameter permissions to your Navgroup:
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<navgroups product="myhack">
	<navgroup phrase="myhack_settings" hr="true" permissions="canadminmyhack">
		<navoption>
			<phrase>demohack_foo</phrase>
			<link>demohack.php?do=foo</link>
		</navoption>
		<navoption>
			<phrase>demohack_modcp</phrase>
			<link>../{$vbulletin->config[Misc][modcpdir]}/foobar.php</link>
		</navoption>
	</navgroup>
</navgroups>
In order to display Text in the Admin Permissions Editor, you must create a Phrase in Phrasegroup Permissions:
Code:
Varname: can_administer_myhack
Text: Can Administer Myhack
Make sure that it is attached to your Product and inserted into GLOBAL Language!

As the Permissions Editor only takes care of standard Permissions, you must create 4 Plugins:

admin_permissions_form
PHP Code:
print_yes_no_row($vbphrase['can_administer_myhack'], 'customadminperms[canadminmyhack]', ($user['customadminperms'] & $vbulletin->bf_misc_customadminperms['canadminmyhack'])); 
customadminperms[canadminmyhack] must the Name of the Bit(field) you want to use, $vbulletin->bf_misc_customadminperms['canadminmyhack'] the Value of the Bit

You must also create a Plugin for the Administrator Datamanager
admindata_start
PHP Code:
$this->validfields['customadminperms'] = array(TYPE_UINTREQ_NO);
$this->bitfields['customadminperms'] = $this->registry->bf_misc_customadminperms
Now we need a Plugin to save our Permission setting after editing it:

admin_permissions_process
PHP Code:
$vbulletin->input->clean_gpc('p''customadminperms'TYPE_ARRAY_INT);
$admindm->set_bitfield('customadminperms''canadminmyhack'$vbulletin->GPC['customadminperms']['canadminmyhack']); 
Now, finally, we need a Plugin to actually check this Permission

can_administer
PHP Code:
foreach($do AS $field)
{
    if (
$admin['customadminperms']  & $vbulletin->bf_misc_customadminperms["$field"])
    {
        
$return_value true;
        return;
    }

Here again, $vbulletin->bf_misc_customadminperms['canadminmyhack'] must be the Value of your Bit.

As you can see, I used customadminperms as the Bitfield.
This is the Bitfield I will use for my Hacks, Bit 1 is already in use.
If others want to use it too (to avoid having to create there own (Bit)fields) - feel free to do so.
But please, first post here and state which Bit you are going to use and wait for an Okay so there won't be conflicts.

To use it, create an appropriate Bitfield XML File.

The following Install Code should be used then:
PHP Code:
require_once(DIR '/includes/class_dbalter.php');
$dbalter = new vB_Database_Alter_MySQL($db);
$dbalter->fetch_table_info('administrator');
if (!
$dbalter->fetch_field_info('customadminperms'))
{
    
$dbalter->add_field(array('name' => 'customadminperms''type' => 'INT''length' => '10''attributes' => 'UNSIGNED''null' => false'default' => '0'));
    }

And this Uninstall-Code
PHP Code:
unset($vbulletin->bf_misc_customadminperms['canadminmyhack']);
if (empty(
$vbulletin->bf_misc_customadminperms))
{
    require_once(
DIR '/includes/class_dbalter.php');
    
$dbalter = new vB_Database_Alter_MySQL($db);
    
// Using 3.5.1+ calls
    
$dbalter->fetch_table_info('administrator');
    if (
$dbalter->fetch_field_info('customadminperms'))
    {
        
$dbalter->drop_field('customadminperms');
    }

Bitfield Usage customadminperms (this will be updated if other Authors use it too)
1 - KirbyDE

vblts.ru supports vBulletin®, 2022-2024