}
-# FIXME: implement this function
+# is_nick_allowed_admin_command()
+#
+# verify if a user (nick name) is allowed to execute admin commands
+#
+# parameter:
+# - nick name
+# return:
+# - 0/1 (1 = allowed)
sub is_nick_allowed_admin_command {
my $nick = shift;
- if ($nick eq 'ads') {
+ my $query = "SELECT 1
+ FROM docbot_user
+ WHERE LOWER(u_nick) = LOWER(?)
+ AND u_role = 'admin'";
+ my $st = $main::db->query($query, $nick);
+ if (!defined($st)) {
+ print_msg("Database error", ERROR);
+ return 0;
+ }
+
+ my $rows = $st->rows;
+ $st->finish;
+
+ if ($rows > 0) {
+ # user is authorized as admin
+ print_msg("User '$nick' is authed as admin", DEBUG);
return 1;
}
+ print_msg("User '$nick' is not authed as admin", DEBUG);
+
return 0;
}
-# FIXME: implement this function
+# is_nick_allowed_operator_command()
+#
+# verify if a user (nick name) is allowed to execute operator commands
+#
+# parameter:
+# - nick name
+# return:
+# - 0/1 (1 = allowed)
sub is_nick_allowed_operator_command {
my $nick = shift;
- if ($nick eq 'ads') {
+ my $query = "SELECT 1
+ FROM docbot_user
+ WHERE LOWER(u_nick) = LOWER(?)
+ AND (u_role = 'op' OR u_role = 'admin')";
+ my $st = $main::db->query($query, $nick);
+ if (!defined($st)) {
+ print_msg("Database error", ERROR);
+ return 0;
+ }
+
+ my $rows = $st->rows;
+ $st->finish;
+
+ if ($rows > 0) {
+ # user is authorized as operator
+ print_msg("User '$nick' is authed as operator", DEBUG);
return 1;
}
+ print_msg("User '$nick' is not authed as operator", DEBUG);
+
return 0;
}