Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 3 Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Custom Administrator Permissions
Andreas's Avatar
Andreas
Join Date: Jan 2004
Posts: 6,863

 

Germany
Show Printable Version Email this Page Subscription
Andreas Andreas is offline 09-08-2005, 10:00 PM

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
Reply With Quote
  #52  
Old 04-12-2008, 12:50 AM
PinkDaisy's Avatar
PinkDaisy PinkDaisy is offline
 
Join Date: Sep 2006
Posts: 274
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'd like to have it too. (3.6.+)
Reply With Quote
  #53  
Old 11-20-2008, 04:20 PM
RayoVac RayoVac is offline
 
Join Date: Oct 2007
Posts: 4
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I would love to see this packaged up as a installable product. Has anyone revised this for 3.7.x?
Reply With Quote
  #54  
Old 05-14-2009, 03:14 AM
Semere79 Semere79 is offline
 
Join Date: Feb 2006
Posts: 8
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

How do you remove any traces of this from the database? I started working on it quite some time ago and never got it going. Now anytime I try to save anything to define rights to my individual administrators I get the following errors... I think I just need to get rid of it out of the database but not sure exactly what to do...

Code:
Database error in vBulletin 3.8.2:

Invalid SQL:
UPDATE vb_administrator SET
	### Bitfield: vb_administrator.adminpermissions ###
		adminpermissions = IF(adminpermissions & 4, adminpermissions - 4, adminpermissions),
		adminpermissions = IF(adminpermissions & 8, adminpermissions - 8, adminpermissions),
		adminpermissions = IF(adminpermissions & 16, adminpermissions - 16, adminpermissions),
		adminpermissions = IF(adminpermissions & 32, adminpermissions - 32, adminpermissions),
		adminpermissions = IF(adminpermissions & 64, adminpermissions - 64, adminpermissions),
		adminpermissions = IF(adminpermissions & 128, adminpermissions - 128, adminpermissions),
		adminpermissions = IF(adminpermissions & 256, adminpermissions - 256, adminpermissions),
		adminpermissions = IF(adminpermissions & 512, adminpermissions - 512, adminpermissions),
		adminpermissions = IF(adminpermissions & 1024, adminpermissions - 1024, adminpermissions),
		adminpermissions = IF(adminpermissions & 2048, adminpermissions - 2048, adminpermissions),
		adminpermissions = IF(adminpermissions & 4096, adminpermissions - 4096, adminpermissions),
		adminpermissions = IF(adminpermissions & 8192, adminpermissions - 8192, adminpermissions),
		adminpermissions = IF(adminpermissions & 16384, adminpermissions - 16384, adminpermissions),
		adminpermissions = IF(adminpermissions & 65536, adminpermissions - 65536, adminpermissions),
		adminpermissions = IF(adminpermissions & 131072, adminpermissions - 131072, adminpermissions),
		adminpermissions = IF(adminpermissions & 262144, adminpermissions - 262144, adminpermissions),
	blogpermissions = 3,
	### Bitfield: vb_administrator.customadminperms ###
		customadminperms = IF(customadminperms & 1, customadminperms - 1, customadminperms),
	cssprefs = 'vBulletin_3_Default',
	dismissednews = '66,67,70,72,74'
WHERE userid = 1;

MySQL Error   : Unknown column 'adminpermissions' in 'field list'
Error Number  : 1054
Request Date  : Wednesday, May 13th 2009 @ 10:55:58 PM
Error Date    : Wednesday, May 13th 2009 @ 10:55:58 PM
Script        : http://www.myforum.com/forum/admincp/adminpermissions.php?do=update
Referrer      : http://www.myforum.com/forum/admincp/adminpermissions.php?do=edit&u=1
IP Address    : xx.xxx.xx.xx
Username      : Admin
Classname     : vB_Database
MySQL Version : 5.0.67-community
Reply With Quote
  #55  
Old 12-21-2009, 06:45 PM
ZenMastr1968 ZenMastr1968 is offline
 
Join Date: Oct 2008
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm apparently a bit dense - where would one put the install/uninstall code and the bitfield file?? I have an existing set of plugins/modifications that I would like to add a custom admin permission to..

Thanks in advance
Reply With Quote
  #56  
Old 03-31-2010, 12:17 PM
skorcu skorcu is offline
 
Join Date: Nov 2007
Posts: 2
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm using vbulletin 3.7.2. All user groups can not access FlashChat. How do I solve the problem. Standard member groups successful entry. Member group created by my login failed

Thanks
Reply With Quote
  #57  
Old 04-23-2010, 01:36 PM
CheeSie's Avatar
CheeSie CheeSie is offline
 
Join Date: Sep 2006
Location: Denmark
Posts: 65
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Any update for this to work with vB4?
Reply With Quote
  #58  
Old 05-15-2010, 01:07 PM
zapiy zapiy is offline
 
Join Date: Jul 2008
Posts: 139
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This would be awesome if created?
Reply With Quote
  #59  
Old 01-03-2011, 07:53 AM
CvP's Avatar
CvP CvP is offline
 
Join Date: Aug 2006
Posts: 263
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi Andreas. Does this still work on vb4?
Reply With Quote
  #60  
Old 01-10-2011, 02:54 PM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yes, should still work (though I havn't tested that yet).
Reply With Quote
  #61  
Old 08-23-2013, 05:22 PM
gabrielt gabrielt is offline
 
Join Date: Apr 2007
Posts: 89
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Took me forever to undestand that after adding the plugins, creating the bitfield XML file, and adding the new field in the database, you need to REBUILD the bitfields. To do that, you need to use tools.php or to import any product. More information: http://www.vbulletin.com/forum/forum...ding-bitfields
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:10 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04861 seconds
  • Memory Usage 2,327KB
  • Queries Executed 25 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (3)bbcode_code
  • (7)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (3)pagenav_pagelink
  • (11)post_thanks_box
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (11)postbit_onlinestatus
  • (11)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete