* Added has_priv() to API::Std.

* Finished the host-based privilege/permission system.
* Fixed some typos.
This commit is contained in:
Elijah Perrault committed 2011-01-30 13:31:16 -07:00
1 parent fe30643e02
commit a22ee16ffb
3 files changed
+83 -1

No files matched your search

+62
View File
@@ -9,6 +9,7 @@ use strict;
use warnings;
use POSIX;
use locale;
use feature qw(switch);
use Mouse;
use IO::Socket;
use IO::Select;
@@ -146,6 +147,55 @@ API::Log::expire_logs();
# Load database.
DB::load();
# Parse privileges.
our (%PRIVILEGES);
# If there are any privsets.
if (conf_get("privset")) {
# Get them.
my %tcprivs = conf_get("privset");
foreach my $tckpriv (keys %tcprivs) {
# For each privset, get the inner values.
my %mcprivs = conf_get("privset:$tckpriv");
# Iterate through them.
foreach my $mckpriv (keys %mcprivs) {
# Switch statement for the values.
given ($mckpriv) {
# If it's 'priv', save it as a privilege.
when ("priv") {
if (defined $PRIVILEGES{$tckpriv}) {
# If this privset exists, push to it.
push(@{ $PRIVILEGES{$tckpriv} }, ($mcprivs{$mckpriv})[0][0]);
}
else {
# Otherwise, create it.
@{ $PRIVILEGES{$tckpriv} } = (($mcprivs{$mckpriv})[0][0]);
}
}
# If it's 'inherit', inherit the privileges of another privset.
when ("inherit") {
# If the privset we're inheriting exists, continue.
if (defined $PRIVILEGES{($mcprivs{$mckpriv})[0][0]}) {
# Iterate through each privilege.
foreach (@{ $PRIVILEGES{($mcprivs{$mckpriv})[0][0]} }) {
# And save them to the privset inheriting them
if (defined $PRIVILEGES{$tckpriv}) {
# If this privset exists, push to it.
push(@{ $PRIVILEGES{$tckpriv} }, $_);
}
else {
# Otherwise, create it.
@{ $PRIVILEGES{$tckpriv} } = ($_);
}
}
}
}
}
}
}
}
# Successful startup.
our $STARTTIME = time;
println "* Auto successfully started at ".POSIX::strftime("%Y-%m-%d %I:%M:%S %p", localtime).".";
@@ -234,6 +284,18 @@ else {
}
undef $it;
### NOTE: REMOVE THIS FROM MAINLINE CODE. IT IS FOR DEVELOPMENT PURPOSES ONLY. ###
sub hw {
my (%data) = @_; my @argv = @{ $data{args} };
if (API::Std::has_priv(API::Std::match_user(%data), "cmd.say")) {
API::IRC::privmsg($data{svr}, $data{chan}, @argv);
}
return 1;
}
cmd_add("SAY", 0, 0, 0, \&Auto::hw) or exit;
### End ###
# Infinite while loop.
while (1) {
# Timer check.
+2
View File
@@ -3,6 +3,8 @@ Auto IRC Bot 3.0: Change Log
3.0 Indev
==================================================================
* Added has_priv() to API::Std.
* Finished the host-based privilege/permission system.
* Added hook on_preconnect, this comes before USER (after PASS).
* Added match_mask() to API::IRC and match_user() to API::Std,
match_user checks config user:mask to find a user block, if
+19 -1
View File
@@ -331,7 +331,7 @@ sub trans
}
}
# Privilege subroutine.
# Match user subroutine.
sub match_user
{
my (%user) = @_;
@@ -359,6 +359,24 @@ sub match_user
return 0;
}
# Privilege subroutine.
sub has_priv
{
my ($cuser, $cpriv) = @_;
if (conf_get("user:$cuser:privs")) {
my $cups = (conf_get("user:$cuser:privs"))[0][0];
if (defined $Auto::PRIVILEGES{$cups}) {
foreach (@{ $Auto::PRIVILEGES{$cups} }) {
return 1 if ($_ eq $cpriv or $_ eq "ALL");
}
}
}
return 0;
}
# Error subroutine.
sub err
{