collapse collapse
* User Info
 
 
Welcome, Guest. Please login or register.
* Search

* Board Stats
  • stats Total Members: 989
  • stats Total Posts: 18366
  • stats Total Topics: 2501
  • stats Total Categories: 7
  • stats Total Boards: 35
  • stats Most Online: 1144

Author Topic: Custom rights management  (Read 25632 times)

0 Members and 3 Guests are viewing this topic.

Offline Alreadythere

  • BeBot Maintainer
  • BeBot Hero
  • ******
  • Posts: 1288
  • Karma: +0/-0
Custom rights management
« on: September 12, 2005, 05:46:20 pm »
Files as tgz

I've written a customizable rights management for the bot. It allows to set access rights to commands based on group membership (Guests, Members, all admin groups). All those rights can be changed online, without restarting the bot. If a rule exists for a channel/command combination for a single group, it defaults to false for all other groups. If no rule exists, it defaults to the setting command_default.

To set the rights, just use the !commands, only adding 2 rights on first start (!member for SA, !commands for SA). Hit
  • to enable, [-] to disable a command for a specific group.


The following is the diff of Bot.php, basically just add the var, and modify all lines containing if ($this -> is_command as shown below. If you have done some adds there, just doing it from hand is prolly easier.
+ in diff means new line, - remove line.
Code: [Select]
@@ -69,6 +69,7 @@
     var $crontimer;
     var $lasttell;

+    var $rightsmanagement;


     /*
@@ -347,7 +348,7 @@
               $comms = array_keys($this -> commands["tell"]);
               for ($i = 0; $i < count($comms); $i++)
               {
-                if ($this -> is_command($comms[$i], $args[1]))
+               if ($this -> is_command($comms[$i], $args[1]) && $this -> rightsmanagement -> check_rights($user, $comms[$i], "tell"))
                 {
                   $this -> commands["tell"][$comms[$i]] -> tell ($user, $args[1]);
                   $i = count($comms);
@@ -363,7 +364,7 @@
               $comms = array_keys($this -> commands["tell2"]);
               for ($i = 0; $i < count($comms); $i++)
               {
-                if ($this -> is_command($comms[$i], $args[1]))
+               if ($this -> is_command($comms[$i], $args[1]) && $this -> rightsmanagement -> check_rights($user, $comms[$i], "tell2"))
                 {
                   $this -> commands["tell2"][$comms[$i]] -> tell2 ($user, $args[1]);
                   $i = count($comms);
@@ -484,7 +485,7 @@
           $comms = array_keys($this -> commands["pgmsg"]);
           for ($i = 0; $i < count($comms); $i++)
           {
-            if ($this -> is_command($comms[$i], $args[2]))
+            if ($this -> is_command($comms[$i], $args[2]) && $this -> rightsmanagement -> check_rights($user, $comms[$i], "pgmsg"))
             {
               $this -> commands["pgmsg"][$comms[$i]] -> pgmsg ($user, $args[2]);
               $i = count($comms);
@@ -539,7 +540,7 @@
             $comms = array_keys($this -> commands["gc"]);
             for ($i = 0; $i < count($comms); $i++)
             {
-              if ($this -> is_command($comms[$i], $args[2]))
+              if ($this -> is_command($comms[$i], $args[2]) && $this -> rightsmanagement -> check_rights($user, $comms[$i], "gc"))
               {
                 $this -> commands["gc"][$comms[$i]] -> gc ($user, $args[2]);
                 $i = count($comms);

Offline Khalem

  • BeBot Founder
  • Administrator
  • ********
  • Posts: 1169
  • Karma: +0/-0
    • http://www.ancarim.com
Custom rights management
« Reply #1 on: September 20, 2005, 03:35:43 am »
This is very nice indeed.

Small comment. Error on line 101 of RightsManagement.php
Code: [Select]

               $res = $this -> db -> select("SELECT * FROM settings WHERE setting = '" . $set . "'");

Should be:
Code: [Select]

               $res = $this -> bot -> db -> select("SELECT * FROM settings WHERE setting = '" . $set . "'");


Some small comments/questions (i havent had time to look into it much yet)
Does setting something as Guest also include if you are a member or admin? Or do you have to specifically set for each different group, regardless of if they are "higher" than the lowest access level set?

Also, it would be nice to allow members default access to at least normal commands when the bot is started for the first time (module started for the first time)
BeBot Founder and Fixer Kingpin

Offline Alreadythere

  • BeBot Maintainer
  • BeBot Hero
  • ******
  • Posts: 1288
  • Karma: +0/-0
Custom rights management
« Reply #2 on: September 20, 2005, 11:08:57 am »
Oh - got the get_settings function in my Bot class, must have forgotten to modify it when copying it. Sorry about that.

Guests are all people (includes members, and any admin group).
Members are all that result in an is_member($name) == true.
For admin groups it's in_group(groupname, charname) == true.
I'm not quite sure if Guests has any sense for commands outside of the tell2 group, I haven't tested it that much with non-members myself.

Default rights are possible, sure.
I'll use cron like in Admin.php for it, and set all commands without any rights to true for a default groups. Will put that into settings, not everyone may want all new commands as members right away.
Will try to do it later today.

Offline Alreadythere

  • BeBot Maintainer
  • BeBot Hero
  • ******
  • Posts: 1288
  • Karma: +0/-0
Custom rights management
« Reply #3 on: September 21, 2005, 01:18:58 pm »
Added a cron function for default access rights after startup.
Adds default rights for all new commands if wished.

Just set $defaultgroup to the group you want, or "None" if you don't want any default rights.
It's a paramtere at the top of the file.

Added !commanlist, shows for all groups which commands they are allowed to use.

Old link still works, file updated, and error corrected.

Offline Khalem

  • BeBot Founder
  • Administrator
  • ********
  • Posts: 1169
  • Karma: +0/-0
    • http://www.ancarim.com
Custom rights management
« Reply #4 on: December 04, 2005, 06:37:48 pm »
Comitted updates to SVN
BeBot Founder and Fixer Kingpin

Offline Khalem

  • BeBot Founder
  • Administrator
  • ********
  • Posts: 1169
  • Karma: +0/-0
    • http://www.ancarim.com
Re: Custom rights management
« Reply #5 on: December 13, 2005, 09:30:02 pm »
Not sure if you want to look at this or if i should mess with it Alreadythere.

- The cronjob isnt correctly iterating over the channels. So only default modes for one channel appears to get set.
- If access level defaults to Members, all higher should also recieve permissions, either by explicit setting in the table or by logic in the actualy check
- When access is manually granted to a lower level, it would make sense to automatically also grant access to higher levels, unless the logic is updated in the actual check
BeBot Founder and Fixer Kingpin

Offline Alreadythere

  • BeBot Maintainer
  • BeBot Hero
  • ******
  • Posts: 1288
  • Karma: +0/-0
Re: Custom rights management
« Reply #6 on: December 14, 2005, 01:14:48 pm »
- The cronjob isnt correctly iterating over the channels. So only default modes for one channel appears to get set.
Noticed something like that, but as it didn't bother me too much I haven't gotten around to test it - and prolly won't get around to it in the near future. Studies are a pain atm.

- If access level defaults to Members, all higher should also recieve permissions, either by explicit setting in the table or by logic in the actualy check
You have to decide where to check for this really. Personally I have modified my is_member() function to automatically include all members of admin groups as members of the bot (return 1). And that's exactly the function I check in my rights management. You could move that check to the rights management too, not sure what's better.

- When access is manually granted to a lower level, it would make sense to automatically also grant access to higher levels, unless the logic is updated in the actual check
Like members vs admin, or guest vs members? For first see above, second should be done in the current version.
And I'm not sure it would be helpfull for admin groups. Sure, Admin and SA should always be included, but what about other custom groups? You can't really make any general assumptions there, there are too many different cases for possible uses.

Offline Khalem

  • BeBot Founder
  • Administrator
  • ********
  • Posts: 1169
  • Karma: +0/-0
    • http://www.ancarim.com
Re: Custom rights management
« Reply #7 on: December 14, 2005, 08:41:26 pm »
Okies. I'll have a look at it later.

Good point about the is_member check, that would solve a few other outstanding issues too.

And yes, custom groups aside from the 3 default (superadmin, admin and raidleader) should never be included in default handeling/granting as such.
BeBot Founder and Fixer Kingpin

MatHack

  • Guest
Re: Custom rights management
« Reply #8 on: February 11, 2006, 03:35:11 pm »
found 3 lines which caused the bot to restart in the module:

Code: [Select]
function show_commandslist($name)
{
$grey = $this -> bot -> get_setting("color_grey");
$lightgrey = $this -> bot -> get_setting("color_lightgrey");
$lightblue = $this -> bot -> get_setting("color_lightblue");
...

"$this -> bot -> get_setting(" should be "$this -> get_setting(".

MatHack

  • Guest
Re: Custom rights management
« Reply #9 on: February 27, 2006, 07:12:29 pm »
I saw rightmanagement.php was altered in latest SVN, but this bug is still in it :)

Offline Khalem

  • BeBot Founder
  • Administrator
  • ********
  • Posts: 1169
  • Karma: +0/-0
    • http://www.ancarim.com
Re: Custom rights management
« Reply #10 on: February 27, 2006, 07:24:27 pm »
Fixed.
BeBot Founder and Fixer Kingpin

Offline Dabaron

  • BeBot Apprentice
  • ***
  • Posts: 163
  • Karma: +0/-0
Re: Custom rights management
« Reply #11 on: August 23, 2006, 03:38:45 am »
Not sure why but after setting this up (and giving guests access to the commands I want them to be able to use) the guests still can't access help.  If they do /tell botname !help it just sends back the message /tell botname !help.

Don't see help listed in the !commands thing so not sure how to get them access to it.

Offline Dabaron

  • BeBot Apprentice
  • ***
  • Posts: 163
  • Karma: +0/-0
Re: Custom rights management
« Reply #12 on: August 23, 2006, 10:24:25 pm »
Nevermind, I found the problem.  help isn't listed on the panel in game but it is in the MySQL database... just had to manually add Guests to tell via channel tell and it works.

Offline Glarawyn

  • BeBot Hero
  • ******
  • Posts: 521
  • Karma: +0/-0
Re: Custom rights management
« Reply #13 on: August 27, 2006, 09:13:30 pm »
They way you take inputs doesn't support security groups with spaces, so I modified your regular expressions and removed the explode. My regular expressions probally aren't the best, so anyone who is beter than I with regexp is welcome to make more improvments. :)

Code: [Select]
/*
This gets called on a tell with the command
*/
function tell($name, $msg)
{
if (preg_match("/^" . $this -> bot -> commpre . "commands enable (tell|tell2|pgmsg|gc) (\b[A-Za-z0-9]{1,50}\b) (.+)$/i", $msg, $info))
{
$this -> bot -> send_tell($name, $this -> enable_command($info[1], $info[2], $info[3]));
}
elseif (preg_match("/^" . $this -> bot -> commpre . "commands disable (tell|tell2|pgmsg|gc) (\b[A-Za-z0-9]{1,50}\b) (.+)$/i", $msg))
{
$this -> bot -> send_tell($name, $this -> disable_command($info[1], $info[2], $info[3]));
}
elseif (preg_match("/^" . $this -> bot -> commpre . "commands (.+)$/i", $msg, $info))
{
if ($info[1] == 'gc')
{
if ($this -> bot -> guildbot)
$this -> showcommands($name, "gc");
}
else
$this -> showcommands($name, $info[1]);
}
elseif (preg_match("/^" . $this -> bot -> commpre . "commands$/i", $msg))
{
$blob = $this -> get_setting("color_grey") . "Please choose a channel:\n";
$blob .= "<a href='chatcmd:///tell <botname> <pre>commands tell2>tell2 (";
$blob .= $this -> get_channelname("tell2") . ")</a>\n";
$blob .= "<a href='chatcmd:///tell <botname> <pre>commands tell>tell</a>\n";
$blob .= "<a href='chatcmd:///tell <botname> <pre>commands pgmsg>pgmsg (";
$blob .= $this -> get_channelname("pgmsg") . ")</a>\n";
if ($this -> bot -> guildbot)
{
$blob .= "<a href='chatcmd:///tell <botname> <pre>commands gc>gc (";
$blob .= $this -> get_channelname("gc") . ")</a>";
}

$this -> bot -> send_tell($name, $this -> bot -> make_blob("Please choose a channel!", $blob));
}
elseif (preg_match("/^" . $this -> bot -> commpre . "commandlist$/i", $msg))
{
$this -> show_commandslist($name);
}
else
$this -> bot -> send_help($name);
}

Offline Khalem

  • BeBot Founder
  • Administrator
  • ********
  • Posts: 1169
  • Karma: +0/-0
    • http://www.ancarim.com
Re: Custom rights management
« Reply #14 on: August 28, 2006, 03:28:59 pm »
The 0.3 branch will not support spaces in group names. I'll have a look at restricting this in 0.2 aswell.
BeBot Founder and Fixer Kingpin

 

* Recent Posts
Com bot module by bitnykk
[November 25, 2024, 05:36:11 pm ]


0.8.x updates for AO by bitnykk
[June 23, 2024, 03:19:47 pm ]


0.8.x updates for AoC by bitnykk
[June 23, 2024, 03:19:44 pm ]


[AoC] special char for items module by bitnykk
[February 09, 2024, 09:41:18 pm ]


BeBot still alive & kicking ! by bitnykk
[December 17, 2023, 12:58:44 am ]

* Who's Online
  • Dot Guests: 124
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.
* Forum Staff
bitnykk admin bitnykk
Administrator
Khalem admin Khalem
Administrator
WeZoN gmod WeZoN
Global Moderator
SimplePortal 2.3.7 © 2008-2024, SimplePortal