More cleanup. Well, cleanup using perlre.
This commit is contained in:
1 parent
053bee2f0e
commit
a662c11f06
1 file changed
+124
-122
+124
-122
@@ -25,35 +25,37 @@ sub mod_init
|
|||||||
# Log/debug.
|
# Log/debug.
|
||||||
API::Log::dbug('MODULES: Attempting to load '.$name.' (version '.$version.') by '.$author.'...');
|
API::Log::dbug('MODULES: Attempting to load '.$name.' (version '.$version.') by '.$author.'...');
|
||||||
API::Log::alog('MODULES: Attempting to load '.$name.' (version '.$version.') by '.$author.'...');
|
API::Log::alog('MODULES: Attempting to load '.$name.' (version '.$version.') by '.$author.'...');
|
||||||
|
|
||||||
# Check if this module is compatible with this version of Auto.
|
# Check if this module is compatible with this version of Auto.
|
||||||
if ($autover ne '3.0.0d') {
|
if ($autover ne '3.0.0d') {
|
||||||
API::Log::dbug('MODULES: Failed to load '.$name.': Incompatible with your version of Auto.');
|
API::Log::dbug('MODULES: Failed to load '.$name.': Incompatible with your version of Auto.');
|
||||||
API::Log::alog('MODULES: Failed to load '.$name.': Incompatible with your version of Auto.');
|
API::Log::alog('MODULES: Failed to load '.$name.': Incompatible with your version of Auto.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Run the module's _init sub.
|
# Run the module's _init sub.
|
||||||
my $mi = eval($pkg."::_init();");
|
my $mi = eval {
|
||||||
|
&{ $pkg.'::_init' }();
|
||||||
|
};
|
||||||
|
|
||||||
if ($mi) {
|
if ($mi) {
|
||||||
# If successful, add to hash.
|
# If successful, add to hash.
|
||||||
$MODULE{$name}{name} = $name;
|
$MODULE{$name}{name} = $name;
|
||||||
$MODULE{$name}{version} = $version;
|
$MODULE{$name}{version} = $version;
|
||||||
$MODULE{$name}{author} = $author;
|
$MODULE{$name}{author} = $author;
|
||||||
$MODULE{$name}{pkg} = $pkg;
|
$MODULE{$name}{pkg} = $pkg;
|
||||||
|
|
||||||
API::Log::dbug("MODULES: ".$name." successfully loaded.");
|
API::Log::dbug('MODULES: '.$name.' successfully loaded.');
|
||||||
API::Log::alog("MODULES: ".$name." successfully loaded.");
|
API::Log::alog('MODULES: '.$name.' successfully loaded.');
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
# Otherwise, return a failed to load message.
|
# Otherwise, return a failed to load message.
|
||||||
API::Log::dbug("MODULES: Failed to load ".$name.".");
|
API::Log::dbug('MODULES: Failed to load '.$name.q{.});
|
||||||
API::Log::alog("MODULES: Failed to load ".$name.".");
|
API::Log::alog('MODULES: Failed to load '.$name.q{.});
|
||||||
|
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,43 +63,46 @@ sub mod_init
|
|||||||
sub mod_exists
|
sub mod_exists
|
||||||
{
|
{
|
||||||
my ($name) = @_;
|
my ($name) = @_;
|
||||||
|
|
||||||
return 1 if defined $API::Std::MODULE{$name};
|
if (defined $API::Std::MODULE{$name}) { return 1; }
|
||||||
return 0;
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Void a module.
|
# Void a module.
|
||||||
sub mod_void
|
sub mod_void
|
||||||
{
|
{
|
||||||
my ($module) = @_;
|
my ($module) = @_;
|
||||||
|
|
||||||
# Log/debug.
|
# Log/debug.
|
||||||
API::Log::dbug("MODULES: Attempting to unload module: ".$module."...");
|
API::Log::dbug('MODULES: Attempting to unload module: '.$module.'...');
|
||||||
API::Log::alog("MODULES: Attempting to unload module: ".$module."...");
|
API::Log::alog('MODULES: Attempting to unload module: '.$module.'...');
|
||||||
|
|
||||||
# Check if this module exists.
|
# Check if this module exists.
|
||||||
unless (defined $MODULE{$module}) {
|
unless (defined $MODULE{$module}) {
|
||||||
API::Log::dbug("MODULES: Failed to unload ".$module.". No such module?");
|
API::Log::dbug('MODULES: Failed to unload '.$module.'. No such module?');
|
||||||
API::Log::alog("MODULES: Failed to unload ".$module.". No such module?");
|
API::Log::alog('MODULES: Failed to unload '.$module.'. No such module?');
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Run the module's _void sub.
|
# Run the module's _void sub.
|
||||||
my $mi = eval($MODULE{$module}{pkg}."::_void();");
|
my $mi = eval {
|
||||||
|
&{ $MODULE{$module}{pkg}.'::_void' }();
|
||||||
|
};
|
||||||
|
|
||||||
if ($mi) {
|
if ($mi) {
|
||||||
# If successful, delete class from program and delete module from hash.
|
# If successful, delete class from program and delete module from hash.
|
||||||
Class::Unload->unload($MODULE{$module}{pkg});
|
Class::Unload->unload($MODULE{$module}{pkg});
|
||||||
delete $MODULE{$module};
|
delete $MODULE{$module};
|
||||||
API::Log::dbug("MODULES: Successfully unloaded ".$module.".");
|
API::Log::dbug('MODULES: Successfully unloaded '.$module.q{.});
|
||||||
API::Log::alog("MODULES: Successfully unloaded ".$module.".");
|
API::Log::alog('MODULES: Successfully unloaded '.$module.q{.});
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
# Otherwise, return a failed to unload message.
|
# Otherwise, return a failed to unload message.
|
||||||
API::Log::dbug("MODULES: Failed to unload ".$module.".");
|
API::Log::dbug('MODULES: Failed to unload '.$module.q{.});
|
||||||
API::Log::alog("MODULES: Failed to unload ".$module.".");
|
API::Log::alog('MODULES: Failed to unload '.$module.q{.});
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,16 +110,16 @@ sub mod_void
|
|||||||
sub cmd_add
|
sub cmd_add
|
||||||
{
|
{
|
||||||
my ($cmd, $lvl, $priv, $help, $sub) = @_;
|
my ($cmd, $lvl, $priv, $help, $sub) = @_;
|
||||||
$cmd = uc($cmd);
|
$cmd = uc $cmd;
|
||||||
|
|
||||||
return 0 if (defined $API::Std::CMDS{$cmd});
|
if (defined $API::Std::CMDS{$cmd}) { return; }
|
||||||
return 0 if ($lvl =~ m/[^0-2]/);
|
if ($lvl =~ m/[^0-2]/) { return; }
|
||||||
|
|
||||||
$API::Std::CMDS{$cmd}{lvl} = $lvl;
|
$API::Std::CMDS{$cmd}{lvl} = $lvl;
|
||||||
$API::Std::CMDS{$cmd}{help} = $help;
|
$API::Std::CMDS{$cmd}{help} = $help;
|
||||||
$API::Std::CMDS{$cmd}{priv} = $priv;
|
$API::Std::CMDS{$cmd}{priv} = $priv;
|
||||||
$API::Std::CMDS{$cmd}{sub} = $sub;
|
$API::Std::CMDS{$cmd}{sub} = $sub;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,15 +128,15 @@ sub cmd_add
|
|||||||
sub cmd_del
|
sub cmd_del
|
||||||
{
|
{
|
||||||
my ($cmd) = @_;
|
my ($cmd) = @_;
|
||||||
$cmd = uc($cmd);
|
$cmd = uc $cmd;
|
||||||
|
|
||||||
if (defined $API::Std::CMDS{$cmd}) {
|
if (defined $API::Std::CMDS{$cmd}) {
|
||||||
delete $API::Std::CMDS{$cmd};
|
delete $API::Std::CMDS{$cmd};
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,14 +144,14 @@ sub cmd_del
|
|||||||
sub event_add
|
sub event_add
|
||||||
{
|
{
|
||||||
my ($name) = @_;
|
my ($name) = @_;
|
||||||
|
|
||||||
unless (defined $EVENTS{lc($name)}) {
|
if (!defined $EVENTS{lc($name)}) {
|
||||||
$EVENTS{lc($name)} = 1;
|
$EVENTS{lc($name)} = 1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
API::Log::dbug("DEBUG: Attempt to add a pre-existing event[".lc($name)."]! Ignoring...");
|
API::Log::dbug('DEBUG: Attempt to add a pre-existing event ('.lc $name.')! Ignoring...');
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,15 +159,15 @@ sub event_add
|
|||||||
sub event_del
|
sub event_del
|
||||||
{
|
{
|
||||||
my ($name) = @_;
|
my ($name) = @_;
|
||||||
|
|
||||||
if (defined $EVENTS{lc($name)}) {
|
if (defined $EVENTS{lc($name)}) {
|
||||||
delete $EVENTS{lc($name)};
|
delete $EVENTS{lc($name)};
|
||||||
delete $HOOKS{lc($name)};
|
delete $HOOKS{lc($name)};
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
API::Log::dbug("DEBUG: Attempt to delete a non-existing event[".lc($name)."! Ignoring...");
|
API::Log::dbug('DEBUG: Attempt to delete a non-existing event ('.lc $name.')! Ignoring...');
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,13 +175,13 @@ sub event_del
|
|||||||
sub event_run
|
sub event_run
|
||||||
{
|
{
|
||||||
my ($event, @args) = @_;
|
my ($event, @args) = @_;
|
||||||
|
|
||||||
if (defined $EVENTS{lc($event)} and defined $HOOKS{lc($event)}) {
|
if (defined $EVENTS{lc $event} and defined $HOOKS{lc $event}) {
|
||||||
foreach my $hk (keys %{ $HOOKS{lc($event)} }) {
|
foreach my $hk (keys %{ $HOOKS{lc $event} }) {
|
||||||
&{ $HOOKS{lc($event)}{$hk} }(@args);
|
&{ $HOOKS{lc $event}{$hk} }(@args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,18 +189,18 @@ sub event_run
|
|||||||
sub hook_add
|
sub hook_add
|
||||||
{
|
{
|
||||||
my ($event, $name, $sub) = @_;
|
my ($event, $name, $sub) = @_;
|
||||||
|
|
||||||
if (!defined $API::Std::HOOKS{lc($name)}) {
|
if (!defined $API::Std::HOOKS{lc $name}) {
|
||||||
if (defined $API::Std::EVENTS{lc($event)}) {
|
if (defined $API::Std::EVENTS{lc $event}) {
|
||||||
$API::Std::HOOKS{lc($event)}{lc($name)} = $sub;
|
$API::Std::HOOKS{lc $event}{lc $name} = $sub;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,13 +208,13 @@ sub hook_add
|
|||||||
sub hook_del
|
sub hook_del
|
||||||
{
|
{
|
||||||
my ($event, $name) = @_;
|
my ($event, $name) = @_;
|
||||||
|
|
||||||
if (defined $API::Std::HOOKS{lc($event)}{lc($name)}) {
|
if (defined $API::Std::HOOKS{lc $event}{lc $name}) {
|
||||||
delete $API::Std::HOOKS{lc($event)}{lc($name)};
|
delete $API::Std::HOOKS{lc $event}{lc $name};
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,52 +222,51 @@ sub hook_del
|
|||||||
sub timer_add
|
sub timer_add
|
||||||
{
|
{
|
||||||
my ($name, $type, $time, $sub) = @_;
|
my ($name, $type, $time, $sub) = @_;
|
||||||
$name = lc($name);
|
$name = lc $name;
|
||||||
|
|
||||||
# Check for invalid type/time.
|
# Check for invalid type/time.
|
||||||
if ($type =~ m/[^1-2]/) {
|
if ($type =~ m/[^1-2]/) {
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
if ($time =~ m/[^0-9]/) {
|
if ($time =~ m/[^0-9]/) {
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
unless (defined $Auto::TIMERS{$name}) {
|
if (!defined $Auto::TIMERS{$name}) {
|
||||||
$Auto::TIMERS{$name}{type} = $type;
|
$Auto::TIMERS{$name}{type} = $type;
|
||||||
$Auto::TIMERS{$name}{time} = time + $time;
|
$Auto::TIMERS{$name}{time} = time + $time;
|
||||||
$Auto::TIMERS{$name}{secs} = $time if ($type == 2);
|
if ($type == 2) { $Auto::TIMERS{$name}{secs} = $time; }
|
||||||
$Auto::TIMERS{$name}{sub} = $sub;
|
$Auto::TIMERS{$name}{sub} = $sub;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
return 0;
|
return 1;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Delete a timer from Auto.
|
# Delete a timer from Auto.
|
||||||
sub timer_del
|
sub timer_del
|
||||||
{
|
{
|
||||||
my ($name) = @_;
|
my ($name) = @_;
|
||||||
$name = lc($name);
|
$name = lc $name;
|
||||||
|
|
||||||
if (defined $Auto::TIMERS{$name}) {
|
if (defined $Auto::TIMERS{$name}) {
|
||||||
delete $Auto::TIMERS{$name};
|
delete $Auto::TIMERS{$name};
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Hook onto a raw command.
|
# Hook onto a raw command.
|
||||||
sub rchook_add
|
sub rchook_add
|
||||||
{
|
{
|
||||||
my ($cmd, $sub) = @_;
|
my ($cmd, $sub) = @_;
|
||||||
$cmd = uc($cmd);
|
$cmd = uc $cmd;
|
||||||
|
|
||||||
return 0 if defined $Parser::IRC::RAWC{$cmd};
|
if (defined $Parser::IRC::RAWC{$cmd}) { return; }
|
||||||
|
|
||||||
$Parser::IRC::RAWC{$cmd} = $sub;
|
$Parser::IRC::RAWC{$cmd} = $sub;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -270,12 +274,12 @@ sub rchook_add
|
|||||||
sub rchook_del
|
sub rchook_del
|
||||||
{
|
{
|
||||||
my ($cmd) = @_;
|
my ($cmd) = @_;
|
||||||
$cmd = uc($cmd);
|
$cmd = uc $cmd;
|
||||||
|
|
||||||
return 0 if !defined $Parser::IRC::RAWC{$cmd};
|
if (!defined $Parser::IRC::RAWC{$cmd}) { return; }
|
||||||
|
|
||||||
delete $Parser::IRC::RAWC{$cmd};
|
delete $Parser::IRC::RAWC{$cmd};
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,24 +287,24 @@ sub rchook_del
|
|||||||
sub conf_get
|
sub conf_get
|
||||||
{
|
{
|
||||||
my ($value) = @_;
|
my ($value) = @_;
|
||||||
|
|
||||||
# Create an array out of the value.
|
# Create an array out of the value.
|
||||||
my @val;
|
my @val;
|
||||||
if ($value =~ m/:/) {
|
if ($value =~ m/:/) {
|
||||||
@val = split(':', $value);
|
@val = split ':', $value;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@val = ($value);
|
@val = ($value);
|
||||||
}
|
}
|
||||||
# Undefine this as it's unnecessary now.
|
# Undefine this as it's unnecessary now.
|
||||||
undef $value;
|
undef $value;
|
||||||
|
|
||||||
# Get the count of elements in the array.
|
# Get the count of elements in the array.
|
||||||
my $count = scalar(@val);
|
my $count = scalar(@val);
|
||||||
|
|
||||||
# Return the requested configuration value(s).
|
# Return the requested configuration value(s).
|
||||||
if ($count == 1) {
|
if ($count == 1) {
|
||||||
if (ref($Auto::SETTINGS{$val[0]}) eq 'HASH') {
|
if (ref $Auto::SETTINGS{$val[0]} eq 'HASH') {
|
||||||
return %{ $Auto::SETTINGS{$val[0]} };
|
return %{ $Auto::SETTINGS{$val[0]} };
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -308,7 +312,7 @@ sub conf_get
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
elsif ($count == 2) {
|
elsif ($count == 2) {
|
||||||
if (ref($Auto::SETTINGS{$val[0]}{$val[1]}) eq 'HASH') {
|
if (ref $Auto::SETTINGS{$val[0]}{$val[1]} eq 'HASH') {
|
||||||
return %{ $Auto::SETTINGS{$val[0]}{$val[1]} };
|
return %{ $Auto::SETTINGS{$val[0]}{$val[1]} };
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -316,7 +320,7 @@ sub conf_get
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
elsif ($count == 3) {
|
elsif ($count == 3) {
|
||||||
if (ref($Auto::SETTINGS{$val[0]}{$val[1]}{$val[2]}) eq 'HASH') {
|
if (ref $Auto::SETTINGS{$val[0]}{$val[1]}{$val[2]} eq 'HASH') {
|
||||||
return %{ $Auto::SETTINGS{$val[0]}{$val[1]}{$val[2]} };
|
return %{ $Auto::SETTINGS{$val[0]}{$val[1]}{$val[2]} };
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -324,8 +328,8 @@ sub conf_get
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Translation subroutine.
|
# Translation subroutine.
|
||||||
@@ -333,7 +337,7 @@ sub trans
|
|||||||
{
|
{
|
||||||
my ($id) = @_;
|
my ($id) = @_;
|
||||||
$id =~ s/ /_/g;
|
$id =~ s/ /_/g;
|
||||||
|
|
||||||
if (defined $API::Std::LANGE{$id}) {
|
if (defined $API::Std::LANGE{$id}) {
|
||||||
return $API::Std::LANGE{$id};
|
return $API::Std::LANGE{$id};
|
||||||
}
|
}
|
||||||
@@ -349,9 +353,9 @@ sub match_user
|
|||||||
my (%user) = @_;
|
my (%user) = @_;
|
||||||
|
|
||||||
# Get data from config.
|
# Get data from config.
|
||||||
return 0 if (!conf_get("user"));
|
if (!conf_get("user")) { return; }
|
||||||
my %uhp = conf_get("user");
|
my %uhp = conf_get("user");
|
||||||
|
|
||||||
foreach my $userkey (keys %uhp) {
|
foreach my $userkey (keys %uhp) {
|
||||||
# For each user block.
|
# For each user block.
|
||||||
my %ulhp = %{ $uhp{$userkey} };
|
my %ulhp = %{ $uhp{$userkey} };
|
||||||
@@ -360,7 +364,7 @@ sub match_user
|
|||||||
|
|
||||||
if ($uhk eq "net") {
|
if ($uhk eq "net") {
|
||||||
if (defined $user{svr}) {
|
if (defined $user{svr}) {
|
||||||
if (lc($user{svr}) ne lc(($ulhp{$uhk})[0][0])) {
|
if (lc $user{svr} ne lc ($ulhp{$uhk})[0][0]) {
|
||||||
# config.user:net conflicts with irc.user:svr.
|
# config.user:net conflicts with irc.user:svr.
|
||||||
last;
|
last;
|
||||||
}
|
}
|
||||||
@@ -375,14 +379,14 @@ sub match_user
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
elsif ($uhk eq "chanstatus" and defined $ulhp{'net'}) {
|
elsif ($uhk eq "chanstatus" and defined $ulhp{'net'}) {
|
||||||
my ($ccst, $ccnm) = split(':', ($ulhp{$uhk})[0][0]);
|
my ($ccst, $ccnm) = split ':', ($ulhp{$uhk})[0][0];
|
||||||
my $svr = $ulhp{net}[0];
|
my $svr = $ulhp{net}[0];
|
||||||
if (defined $Auto::SOCKET{$svr}) {
|
if (defined $Auto::SOCKET{$svr}) {
|
||||||
foreach my $bcj (@{ $Parser::IRC::botchans{$svr} }) {
|
foreach my $bcj (@{ $Parser::IRC::botchans{$svr} }) {
|
||||||
if (API::IRC::match_mask($bcj, $ccnm)) {
|
if (API::IRC::match_mask($bcj, $ccnm)) {
|
||||||
API::IRC::names($svr, $bcj);
|
API::IRC::names($svr, $bcj);
|
||||||
if (defined $Parser::IRC::chanusers{$svr}{$bcj}{$user{nick}}) {
|
if (defined $Parser::IRC::chanusers{$svr}{$bcj}{$user{nick}}) {
|
||||||
return $userkey if $Parser::IRC::chanusers{$svr}{$bcj}{$user{nick}} =~ m/($ccst)/;
|
if ($Parser::IRC::chanusers{$svr}{$bcj}{$user{nick}} =~ m/($ccst)/) { return $userkey; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -390,41 +394,41 @@ sub match_user
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Privilege subroutine.
|
# Privilege subroutine.
|
||||||
sub has_priv
|
sub has_priv
|
||||||
{
|
{
|
||||||
my ($cuser, $cpriv) = @_;
|
my ($cuser, $cpriv) = @_;
|
||||||
|
|
||||||
if (conf_get("user:$cuser:privs")) {
|
if (conf_get("user:$cuser:privs")) {
|
||||||
my $cups = (conf_get("user:$cuser:privs"))[0][0];
|
my $cups = (conf_get("user:$cuser:privs"))[0][0];
|
||||||
|
|
||||||
if (defined $Auto::PRIVILEGES{$cups}) {
|
if (defined $Auto::PRIVILEGES{$cups}) {
|
||||||
foreach (@{ $Auto::PRIVILEGES{$cups} }) {
|
foreach (@{ $Auto::PRIVILEGES{$cups} }) {
|
||||||
return 1 if ($_ eq $cpriv or $_ eq "ALL");
|
if ($_ eq $cpriv or $_ eq "ALL") { return 1; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Error subroutine.
|
# Error subroutine.
|
||||||
sub err
|
sub err
|
||||||
{
|
{
|
||||||
my ($lvl, $msg, $fatal) = @_;
|
my ($lvl, $msg, $fatal) = @_;
|
||||||
|
|
||||||
# Check for an invalid level.
|
# Check for an invalid level.
|
||||||
if ($lvl =~ m/[^0-9]/) {
|
if ($lvl =~ m/[^0-9]/) {
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
if ($fatal =~ m/[^0-1]/) {
|
if ($fatal =~ m/[^0-1]/) {
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Level 1: Print to screen.
|
# Level 1: Print to screen.
|
||||||
if ($lvl >= 1) {
|
if ($lvl >= 1) {
|
||||||
API::Log::println("ERROR: $msg");
|
API::Log::println("ERROR: $msg");
|
||||||
@@ -433,12 +437,10 @@ sub err
|
|||||||
if ($lvl >= 2) {
|
if ($lvl >= 2) {
|
||||||
API::Log::alog("ERROR: $msg");
|
API::Log::alog("ERROR: $msg");
|
||||||
}
|
}
|
||||||
|
|
||||||
# If it's a fatal error, exit the program.
|
# If it's a fatal error, exit the program.
|
||||||
if ($fatal) {
|
if ($fatal) { exit; }
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -446,12 +448,12 @@ sub err
|
|||||||
sub awarn
|
sub awarn
|
||||||
{
|
{
|
||||||
my ($lvl, $msg) = @_;
|
my ($lvl, $msg) = @_;
|
||||||
|
|
||||||
# Check for an invalid level.
|
# Check for an invalid level.
|
||||||
if ($lvl =~ m/[^0-9]/) {
|
if ($lvl =~ m/[^0-9]/) {
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Level 1: Print to screen.
|
# Level 1: Print to screen.
|
||||||
if ($lvl >= 1) {
|
if ($lvl >= 1) {
|
||||||
API::Log::println("WARNING: $msg");
|
API::Log::println("WARNING: $msg");
|
||||||
@@ -460,7 +462,7 @@ sub awarn
|
|||||||
if ($lvl >= 2) {
|
if ($lvl >= 2) {
|
||||||
API::Log::alog("WARNING: $msg");
|
API::Log::alog("WARNING: $msg");
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user