From 3188b690e8a8260d3864cc528da46dda64744a60 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Fri, 3 Jan 2020 21:39:22 -0800 Subject: [PATCH] BotAdmins: admin hostmasks are no longer treated as regex. They support the normal * and ? wildcards. Removed stdin admin from data/admins. --- PBot/BotAdmins.pm | 10 ++++------ PBot/PBot.pm | 2 +- data/admins | 10 ---------- 3 files changed, 5 insertions(+), 17 deletions(-) diff --git a/PBot/BotAdmins.pm b/PBot/BotAdmins.pm index 3df06fac..cecd0d54 100644 --- a/PBot/BotAdmins.pm +++ b/PBot/BotAdmins.pm @@ -120,13 +120,11 @@ sub find_admin { foreach my $channel_regex (keys %{ $self->{admins}->hash }) { if ($from !~ m/^#/ or $from =~ m/^$channel_regex$/i) { foreach my $hostmask_regex (keys %{ $self->{admins}->hash->{$channel_regex} }) { - if ($hostmask_regex =~ m/\.\*/) { - # contains .* so it's considered a regex - return $self->{admins}->hash->{$channel_regex}->{$hostmask_regex} if $hostmask =~ m/^$hostmask_regex$/i; - } elsif ($hostmask_regex =~ m/\*/) { - # contains * so it's converted to a regex + if ($hostmask_regex =~ m/[*?]/) { + # contains * or ? so it's converted to a regex my $hostmask_quoted = quotemeta $hostmask_regex; - $hostmask_quoted =~ s/\\\*/.*/g; + $hostmask_quoted =~ s/\\\*/.*?/g; + $hostmask_quoted =~ s/\\\?/./g; return $self->{admins}->hash->{$channel_regex}->{$hostmask_regex} if $hostmask =~ m/^$hostmask_quoted$/i; } else { # direct comparison diff --git a/PBot/PBot.pm b/PBot/PBot.pm index 9fa6a0c4..6cdcdc65 100644 --- a/PBot/PBot.pm +++ b/PBot/PBot.pm @@ -212,7 +212,7 @@ sub initialize { # create implicit bot-admin account for bot my $botnick = $self->{registry}->get_value('irc', 'botnick'); - $self->{admins}->add_admin($botnick, '.*', ".*!stdin\@pbot", 100, 'notused', 1); + $self->{admins}->add_admin($botnick, '.*', "*!stdin\@pbot", 100, 'notused', 1); $self->{admins}->login($botnick, "$botnick!stdin\@pbot", 'notused'); # start timer diff --git a/data/admins b/data/admins index c9227027..e69de29b 100644 --- a/data/admins +++ b/data/admins @@ -1,10 +0,0 @@ -{ - ".*" : { - "pbot3!stdin@localhost" : { - "password" : "admin", - "level" : "90", - "name" : "pbot3" - } - } -} -