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.

deathemperor 09-22-2005 03:48 PM

thanks, glad to hear that, I'll try it

Alan @ CIT 09-23-2005 12:52 AM

Hi Kirby, just 1 quick question if I may.

Quote:

To use it, create an appropriate Bitfield XML File.
What is an "appropriate Bitfield XML file"? Do you have a template of what one should look like?

Thanks,
Alan.

Dark_Wizard 10-03-2005 05:18 PM

Therer was an apparent restructuring of the file class_dbalter.php changing the class and functions used in Kirby's uninstall example.

fetch_table_info has now changed to fetchTableInfo and drop_field has changed to dropField and lastly table_field_data has changed to fetchFieldInfo.


new coding
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);
    
$dbalter->fetchTableInfo('administrator');
    if (!
$dbalter->fetchFieldInfo['customadminperms'])
    {
        
$dbalter->dropField('customadminperms');
    }


Lastly TABLE_PREFIX is no longer needed...

harmor19 01-04-2006 04:57 PM

I did everything the tutorial said and I can see the radio button in the admin permissions but when I click "yes" and save it, it goes back to "no".

Do I change customadminperms?

Kurisu 02-09-2006 09:22 PM

Quote:

Originally Posted by harmor19
I did everything the tutorial said and I can see the radio button in the admin permissions but when I click "yes" and save it, it goes back to "no".

Yes, same problem for me...

Revan 02-21-2006 12:38 AM

This thing doesn't actually work. (3.5.3)
After the first check of permissions, the static $adminpermissions; takes over, to which the custom permissions are not added.

Therefore an alternative solution is required.
I will look deeper into it tomorrow.

Andreas 02-21-2006 05:36 AM

You're right. Must have missed that issue as I only had one custom navgroup - and it was the first one.

I tweaked the code a bit to get around this.

Revan 02-21-2006 09:59 AM

Allow me to point out two facts:
  1. static doesn't work through eval(). Believe me, I tried. I worked with this for 3 hours straight yesterday XD
  2. You might not actually have to run a new query:
    PHP Code:

    global $admin;

    if (isset(
    $getperms['customadminperms']))
    {
        
    $admin $getperms['customadminperms'];
    }

    if (!isset(
    $admin))
    {
        
    // must get our perms
        
    $getperms $vbulletin->db->query_first("
            SELECT `customadminperms`
            FROM " 
    TABLE_PREFIX "administrator
            WHERE userid = " 
    $vbulletin->userinfo['userid']
        ); 
        
        
    $admin $getperms['customadminperms'];
    }

    foreach (
    $do AS $field)
    {
        if (
    $admin $vbulletin->bf_misc_customadminperms["$field"])
        {
            
    $return_value true;
        }


    I tested this code on localhost yesterday, and it works like a charm, no extra queries involved unless for some reason it won't work like it should without :)

EDIT: This randomly doesn't seem to work for OLD administrators, and only in the ACP menu.
In my custom menu it works fine, it just doesn't work in the cpnav_ menu.
EDIT #2: I fixed it now. Made it so it doesn't query unless for some reason it didn't fetch the permissions properly. Also I replaced the * in the query for a slight load decrease =P

Andreas 02-21-2006 02:58 PM

Well ... as of vBulletin 3.5.4 $admin is there by default :)

The following code might work cross-version?

PHP Code:

if (!isset($admin))
{
    
// this is not vBulletin 3.5.4+
    
global $admin;
}

if (!isset(
$admin))
{
    
// must get our perms
    
$getperms $vbulletin->db->query_first("
        SELECT *
        FROM " 
TABLE_PREFIX "administrator
        WHERE userid = " 
$vbulletin->userinfo['userid']
    ); 
    
    
$admin $getperms;
}

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



Revan 02-21-2006 04:27 PM

It might, but due to the fact that I don't actually use the $admin variable, I don't know if I need to change the code.
I don't really see how changing the variable name would help in solving the original problem, though. I just tested the new plugin with some slight alterations and it works.
I cba to "remake" it into your "customadminperms" format so Ill just give it like I use it:
PHP Code:

global $rpgpermissions;

if (!isset(
$admin))
{
    
// this is not vBulletin 3.5.4+
    
$admin $getperms;
}

if (isset(
$admin['rpgadminperms']))
{
    
$rpgpermissions $admin['rpgadminperms'];
}

if (!isset(
$rpgpermissions))
{
    
// must get our perms
    
$getperms $vbulletin->db->query_first("
        SELECT *
        FROM " 
TABLE_PREFIX "administrator
        WHERE userid = " 
$vbulletin->userinfo['userid']
    ); 
    
    
$rpgpermissions $getperms['rpgadminperms'];
}

foreach (
$do AS $field)
{
    if (
$rpgpermissions  $vbulletin->bf_misc_rpgadminperms["$field"])
    {
        
$return_value true;
    }


Tested to work on 3.5.3 and 3.5.4.
I think that's a pretty efficient way of doing it, as it only runs 1 additional query for ONE admin (out of the ~10 I tested it on, non-superadmins that is).
So yeah, tis odd, but meh =P

Andreas 02-21-2006 04:29 PM

Yeah, that should work without causing any additional queries in 3.5.4 as $admin contains the full row.

Revan 02-21-2006 04:33 PM

Edit: didnt see your edit :p

Andreas 02-21-2006 04:36 PM

So, that means? :)

Revan 02-21-2006 04:43 PM

That means its all good, lol.
Not only will that not cause any extra queries on 3.5.4 in general, it will only cause one extra query for the rare occurrence where for some reason it won't work without re-querying :)

Thanks for going through this with me and for releasing 3.5.4 4h after I had spent ages testing the old code you see in a few posts back (*kicks*) ;)


//peace

Luggruff 02-21-2006 05:19 PM

Nice!
You look like you know your stuff :p

would you be able to make a guide on [How-To] create custom admin or mod type of usergroups

so that we can like make a seperate moderator usergroup that is used for the moderators that are only moderators by forums, and not by usergroup.. and so on?

xlguy 02-27-2006 02:28 AM

Hi, does anyone know how you can have better control over the AdminCP functions for users that are co-admins? For example I want to disable them from the User Ranks area but there is no option for this in Adminstrator Permissions table.

cRaZy-BoY 03-12-2006 06:55 PM

how can i make a new bitfield xml file?

King Kovifor 07-07-2006 02:33 PM

Install and Uninstall for the product code?

KuJoe 07-08-2006 04:03 AM

I'm sorry but I don't understand this:

Quote:

customadminperms[canadminmyhack] must the Name of the Bit(field) you want to use, $vbulletin->bf_misc_customadminperms['canadminmyhack'] the Value of the Bit
I'm also confused about the Bit Field XML...

Nevermind, I'll just wait around for a guide made for a newbie.

King Kovifor 07-28-2006 04:08 PM

can_administer I can't seem to find in my hooks for vB 3.5.4! What header is it under?

Alan @ CIT 07-28-2006 04:11 PM

It is at the bottom of "vBulletin : General Administration"

Thanks,
Alan.

harmor19 08-02-2006 04:03 PM

I'm getting frustrated because I can't get it to work.

This is for vBulletin 3.6.0 RC 3

Install Code
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('hostingadminperms'))
{
    
$dbalter->add_field(array('name' => 'hostingadminperms''type' => 'INT''length' => '10''attributes' => 'UNSIGNED''null' => 'NOT_NULL''default' => '0'));


Uninstall Code
PHP Code:

unset($vbulletin->bf_misc_hostingadminperms['canadminhosting']);
if (empty(
$vbulletin->bf_misc_hostingadminperms))
{
    require_once(
DIR '/includes/class_dbalter.php');
    
$dbalter = new vB_Database_Alter_MySQL($db);
    
$dbalter->fetch_table_info('administrator');
    if (!
$dbalter->fetch_field_info['hostingadminperms'])
    {
        
$dbalter->drop_field('hostingadminperms');
    }


--Hooks--
admindata_start
PHP Code:

$this->validfields['hostingadminperms'] = array(TYPE_UINTREQ_NO);
$this->bitfields['hostingadminperms'] = $this->registry->bf_misc_hostingadminperms

admin_permissions_form
PHP Code:

print_yes_no_row($vbphrase['can_administer_hosting'], 'hostingadminperms[canadminhosting]', ($user['hostingadminperms'] & $vbulletin->bf_misc_hostingadminperms['canadminhosting'])); 

admin_permissions_process
PHP Code:

$vbulletin->input->clean_gpc('p''hostingadminperms'TYPE_ARRAY_INT);
$admindm->set_bitfield('hostingadminperms''canadminhosting'$vbulletin->GPC['hostingadminperms']['canadminhosting']); 

can_administer
PHP Code:

if (!isset($admin))
{
    
// this is not vBulletin 3.5.4+
    
global $admin;
}

if (!isset(
$admin))
{
    
// must get our perms
    
$getperms $vbulletin->db->query_first("
        SELECT *
        FROM " 
TABLE_PREFIX "administrator
        WHERE userid = " 
$vbulletin->userinfo['userid']
    ); 
    
    
$admin $getperms;
}

foreach (
$do AS $field)
{
    if (
$admin['hostingadminperms'] & $vbulletin->bf_misc_hostingadminperms["$field"])
    {
        
$return_value true;
    }


I create a bitfield XML with
PHP Code:

<?xml version="1.0" encoding="ISO-8859-1"?>

<bitfields product="Hosting">
    <bitfielddefs>
        <group name="misc">
            <group name="hostingadminperms">
            <bitfield name="canadminhosting" phrase="can_administer_hosting">1</bitfield>
            </group>
        </group>    
    </bitfielddefs>
</bitfields>

I didn't know what to make bitfield number so I just did the date I created it (m/d/yy).

Dilmah 08-04-2006 06:12 AM

I have this in my custom XML file - the canadminnetwork option works fine, however the canadminrankings part (using your code) returns a value of 2 when Yes, or 0 when No.
Code:

    <bitfielddefs>
        <group name="misc">
            <group name="customadminperms">
                <bitfield name="canadminnetwork">1</bitfield>
                <bitfield name="canadminrankings">2</bitfield>                                                               
            </group>
        </group>
    </bitfielddefs>

Do I have to somehow put things into an array first or something? I tried a few things, but couldn't work it out.

harmor19 08-04-2006 07:21 AM

Quote:

Originally Posted by Dilmah
I have this in my custom XML file - the canadminnetwork option works fine, however the canadminrankings part (using your code) returns a value of 2 when Yes, or 0 when No.
Code:

    <bitfielddefs>
        <group name="misc">
            <group name="customadminperms">
                <bitfield name="canadminnetwork">1</bitfield>
                <bitfield name="canadminrankings">2</bitfield>                                                               
            </group>
        </group>
    </bitfielddefs>

Do I have to somehow put things into an array first or something? I tried a few things, but couldn't work it out.

It's supposed to return a value of 2 when you select "Yes".

Dilmah 08-04-2006 07:23 AM

Yes, but how do I put that into a print_yes_no_row for use in adminpermissions.php

harmor19 08-04-2006 07:26 AM

I have no idea. I need help with it as well.

Buraq 08-07-2006 04:35 PM

This is somewhat unrelated, but where can I get info on how to give my plugin an admincp back-end? I'm working on a small plugin for my forum and this would be very useful.

Surviver 10-27-2006 12:48 PM

Hello, Andreas, I've a problem: The permissions are not stored. When I click save and return to the Permission Overview, The Right i snot saved. (No is ever selected)

I dont know, where the problem is.

Thanks for Help !!!

Surviver

Because of my bed English: http://surviver.bokuv.de/ablage/admi...dminperms.html :D



//All ok, thanx Andreas :)

Gerakus 10-30-2006 04:08 PM

Same problem here.

First, Does this works with 3.6.0? If so what are the right steps to make it work.

Second, Any particular reason why doesnt save the permissions? it just don't do it, I have try in so many ways, but it appears vbulletin for some reason doesnt store the changes.

I am using vbulletin 3.6.0+

Also could you make this hack works with more than one custom permissions?

Thanks on advance.

Surviver 10-30-2006 04:25 PM

Quote:

Originally Posted by Gerakus
Same problem here.

First, Does this works with 3.6.0? If so what are the right steps to make it work.

Second, Any particular reason why doesnt save the permissions? it just don't do it, I have try in so many ways, but it appears vbulletin for some reason doesnt store the changes.


I am using vbulletin 3.6.0+

Also could you make this hack works with more than one custom permissions?

Thanks on advance.

have you created the Bitfield ? :)

Example:
Code:

<?xml version="1.0" encoding="ISO-8859-1"?>
<bitfields>
        <bitfielddefs>
                <group name="misc">
                        <group name="customadminperms">
                                <bitfield name="canadminmyhack">1</bitfield>
                        </group>
                </group>
        </bitfielddefs>
</bitfields>

Then it will work ;)


All times are GMT. The time now is 01:09 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.02656 seconds
  • Memory Usage 1,926KB
  • 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
  • (5)bbcode_code_printable
  • (21)bbcode_php_printable
  • (6)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (40)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