L* R*
HOME FORUM DOWNLOADS
Content
  Links
     Browse SVN
     SVN Commit log
     Documentation (Wiki)
  Developers
     Taskmanager
User
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 02, 2008, 10:45:53 AM

Login with username, password and session length
Search



Advanced search
Support GoPHP5.org
BeBot - An Anarchy Online/Age Of Conan chat automaton > Forum > Modules > Official modules > Topic: Custom rights management
Pages: [1] 2   Go Down
« previous next »
Print
Author Topic: Custom rights management  (Read 2739 times)
0 Members and 1 Guest are viewing this topic.
Alreadythere
BeBot Maintainer
Administrator
Grandmaster
********
Offline Offline

Posts: 1085


Custom rights management
« on: September 12, 2005, 10:46:20 AM »

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:
@@ -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);
Logged
Khalem
BeBot Founder
Administrator
Grandmaster
********
Offline Offline

Gender: Male
Posts: 670



WWW
Custom rights management
« Reply #1 on: September 19, 2005, 08:35:43 PM »

This is very nice indeed.

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

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

Should be:
Code:

               $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)
Logged

BeBot Founder and Fixer Kingpin
Madman coder and destroyer of good code
Alreadythere
BeBot Maintainer
Administrator
Grandmaster
********
Offline Offline

Posts: 1085


Custom rights management
« Reply #2 on: September 20, 2005, 04: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.
Logged
Alreadythere
BeBot Maintainer
Administrator
Grandmaster
********
Offline Offline

Posts: 1085


Custom rights management
« Reply #3 on: September 21, 2005, 06:18:58 AM »

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.
Logged
Khalem
BeBot Founder
Administrator
Grandmaster
********
Offline Offline

Gender: Male
Posts: 670



WWW
Custom rights management
« Reply #4 on: December 04, 2005, 12:37:48 PM »

Comitted updates to SVN
Logged

BeBot Founder and Fixer Kingpin
Madman coder and destroyer of good code
Khalem
BeBot Founder
Administrator
Grandmaster
********
Offline Offline

Gender: Male
Posts: 670



WWW
Re: Custom rights management
« Reply #5 on: December 13, 2005, 03: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
Logged

BeBot Founder and Fixer Kingpin
Madman coder and destroyer of good code
Alreadythere
BeBot Maintainer
Administrator
Grandmaster
********
Offline Offline

Posts: 1085


Re: Custom rights management
« Reply #6 on: December 14, 2005, 07:14:48 AM »

Quote from: Khalem on December 13, 2005, 03:30:02 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.

Quote from: Khalem on December 13, 2005, 03:30:02 PM
- 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.

Quote from: Khalem on December 13, 2005, 03:30:02 PM
- 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.
Logged
Khalem
BeBot Founder
Administrator
Grandmaster
********
Offline Offline

Gender: Male
Posts: 670



WWW
Re: Custom rights management
« Reply #7 on: December 14, 2005, 02: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.
Logged

BeBot Founder and Fixer Kingpin
Madman coder and destroyer of good code
MatHack
Guest
Re: Custom rights management
« Reply #8 on: February 11, 2006, 09:35:11 AM »

found 3 lines which caused the bot to restart in the module:

Code:
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(".
Logged
MatHack
Guest
Re: Custom rights management
« Reply #9 on: February 27, 2006, 01:12:29 PM »

I saw rightmanagement.php was altered in latest SVN, but this bug is still in it Smiley
Logged
Khalem
BeBot Founder
Administrator
Grandmaster
********
Offline Offline

Gender: Male
Posts: 670



WWW
Re: Custom rights management
« Reply #10 on: February 27, 2006, 01:24:27 PM »

Fixed.
Logged

BeBot Founder and Fixer Kingpin
Madman coder and destroyer of good code
Dabaron
Apprentice
***
Offline Offline

Gender: Male
Posts: 145


Re: Custom rights management
« Reply #11 on: August 22, 2006, 08:38:45 PM »

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.
Logged
Dabaron
Apprentice
***
Offline Offline

Gender: Male
Posts: 145


Re: Custom rights management
« Reply #12 on: August 23, 2006, 03: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.
Logged
Glarawyn
BeBot Developer
Champion
********
Offline Offline

Posts: 414



Re: Custom rights management
« Reply #13 on: August 27, 2006, 02: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. Smiley

Code:
/*
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);
}
Logged
Khalem
BeBot Founder
Administrator
Grandmaster
********
Offline Offline

Gender: Male
Posts: 670



WWW
Re: Custom rights management
« Reply #14 on: August 28, 2006, 08:28:59 AM »

The 0.3 branch will not support spaces in group names. I'll have a look at restricting this in 0.2 aswell.
Logged

BeBot Founder and Fixer Kingpin
Madman coder and destroyer of good code
Pages: [1] 2   Go Up
Print
BeBot - An Anarchy Online/Age Of Conan chat automaton > Forum > Modules > Official modules > Topic: Custom rights management
« previous next »
 
Jump to:  

Recent
Log playtime from buddys ...
by IKShadow
[Today at 06:48:12 AM]

[request] Raid timers
by Elesar1
[December 01, 2008, 04:41:09 PM]

Shared DB online list
by Temar
[December 01, 2008, 01:55:47 AM]

relay colors
by Temar
[December 01, 2008, 01:54:56 AM]

BeBot v0.6.0 released
by Alreadythere
[November 30, 2008, 05:32:00 PM]

Change to Bid.php
by Temar
[November 30, 2008, 11:41:44 AM]

OnlineOrg
by Jiheld
[November 29, 2008, 12:44:27 PM]

Silly Newbie Question.
by Temar
[November 29, 2008, 12:00:02 PM]

massive_pvp_time_table 1
by gerborg
[November 29, 2008, 06:55:35 AM]

Bot not see Guild Chat
by Delvar
[November 28, 2008, 08:30:34 AM]
Stats
Members
Total Members: 1243
Latest: Whackoeng
Stats
Total Posts: 11145
Total Topics: 1505
Online Today: 15
Online Ever: 168
(July 01, 2007, 09:30:02 PM)
Users Online
Users: 5
Guests: 8
Total: 13
Slacklin
Pharexys
gerborg
Jiheld
xlDanek

Powered by SMF 1.1.7 | SMF © 2006-2008, Simple Machines LLC
TinyPortal v0.9.8 © Bloc | NewDef design by Bloc
Page created in 0.565 seconds with 29 queries. (Pretty URLs adds 0.038s, 4q)
Loading...