Skip to content
Snippets Groups Projects
Commit 8a16eca8 authored by Robert Anderson's avatar Robert Anderson
Browse files

Added isBoolean function

Check if user is disabled
parent 9b5c7145
No related branches found
No related tags found
No related merge requests found
......@@ -68,7 +68,7 @@ sub init
# Default configs...
$config->{'userdb_find_query'} = '
SELECT
ID
ID, Disabled
FROM
@TP@users
WHERE
......@@ -172,6 +172,13 @@ sub find
# Grab record data
my $row = $sth->fetchrow_hashref();
# Dont use disabled user
my $res = isBoolean($row->{'disabled'});
if ($res) {
$server->log(LOG_DEBUG,"[MOD_USERDB_SQL] User '".$user->{'Username'}."' is disabled");
return MOD_RES_SKIP;
}
DBFreeRes($sth);
return (MOD_RES_ACK,$row);
......
......@@ -30,6 +30,7 @@ our (@ISA,@EXPORT);
@EXPORT = qw(
niceUndef
templateReplace
isBoolean
);
......@@ -80,6 +81,38 @@ sub templateReplace
}
## @fn isBoolean($var)
# Check if a variable is boolean
#
# @param var Variable to check
#
# @return 1, 0 or undef
sub isBoolean
{
my $var = shift;
# Check if we're defined
if (!defined($var)) {
return undef;
}
# Nuke whitespaces
$var =~ s/\s//g;
# Allow true, on, set, enabled, 1, false, off, unset, disabled, 0
if ($var =~ /^(?:true|on|set|enabled|1)$/i) {
return 1;
}
if ($var =~ /^(?:false|off|unset|disabled|0)$/i) {
return 0;
}
# Invalid or unknown
return undef;
}
1;
# vim: ts=4
......@@ -387,7 +387,7 @@ EOT
userdb_find_query=<<EOT
SELECT
ID
ID, Disabled
FROM
@TP@users
WHERE
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment