vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=187)
-   -   Custom Administrator Permissions (https://vborg.vbsupport.ru/showthread.php?t=95918)

Andreas 09-08-2005 10:00 PM

Custom Administrator Permissions
 
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

fly 09-10-2005 09:55 PM

Wow. Thanks man!

I may try doing this when I have a few hours. :P

deathemperor 09-12-2005 07:30 AM

Thanks Kirby !

now do you know how to add permissions for customs categories ?

Like, in vb3.0 I use

PHP Code:

// Defined contants used for category field.
$_CATEGORYOPTIONS = array(
    
'active'            => 1,
    
'allowposting'      => 2,
    
'cancontainthreads' => 4,
    
'canicon' => 8,
    
'moderatenewthread' => 16,
//    'moderateattach'    => 32,
    
'allowbbcode'       => 64,
    
'allowimages'       => 128,
    
'allowhtml'         => 256,
    
'allowsmilies'      => 512,
    
'allowicons'        => 1024,
    
'allowratings'      => 2048,
    
'countposts'        => 4096,
); 

in vb3.5 what should I do to use $_CATEGORYOPTIONS['cancontainthreads'] in my code ?

thanks for any help.

Alan @ CIT 09-18-2005 05:03 AM

Thanks Kirby, this will be very handy.

Andreas 09-18-2005 07:41 AM

@deathemperor
I don't know what you are talking about; $_CATEGORYOPTIONS does not seem to exist in any standard vBulletin 3.0 file.

deathemperor 09-19-2005 03:58 PM

Quote:

Originally Posted by KirbyDE
I don't know what you are talking about; $_CATEGORYOPTIONS does not seem to exist in any standard vBulletin 3.0 file.

you're right, it's not vbulletin default. and I was asking for a custom permissions for custom categories system (like v3article or vbadvanced gallery).

I'm thinking if a bitfield_something.xml file would do the trick.

Revan 09-19-2005 08:30 PM

PHP Code:

$vbulletin->input->clean_gpc('p''customadminpers'TYPE_ARRAY_INT

Should perhaps be something more like
PHP Code:

$vbulletin->input->clean_gpc('p''customadminperms'TYPE_ARRAY_INT); 

eh?
Also, can you please explain what you mean by "Bitfield Usage customadminperms (this will be updated if other Authors use it too)"?

TIA :)

Andreas 09-19-2005 10:18 PM

Yep, the ; is missing.

Well "Bitfield Usage customadminperms" just describes how this Bitfield is used, eg. what the Bits stand for :)

deathemperor 09-22-2005 01:48 AM

so Kirby, is there any solution for my question ?

Andreas 09-22-2005 05:06 AM

Yes, Bitfield XMLs are the way to go.


All times are GMT. The time now is 06:07 PM.

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.01937 seconds
  • Memory Usage 1,779KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (10)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete