2 # RootWarn.pl: Warn people about usage of root on IRC.
4 # Version: v0.3 (20000923)
10 use vars qw(%channels %param);
11 use vars qw($dbh $found $ident);
14 my ($nick,$user,$host,$chan) = @_;
16 my $attempt = &dbGet("rootwarn", "attempt", "nick=".&dbQuote($n) ) || 0;
17 my $warnmode = &getChanConf("rootWarnMode");
19 if ($attempt == 0) { # first timer.
20 if (defined $warnmode and $warnmode =~ /quiet/i) {
21 &status("rootwarn: Detected root user; notifying user");
23 &status("rootwarn: Detected root user; notifying nick and channel.");
24 &msg($chan, "ROO".("O" x int(rand 68))."T has landed!");
27 if ($_ = &getFactoid("root")) {
28 &msg($nick, "root is $_");
30 &status("root needs to be defined in database.");
33 } elsif ($attempt < 2) { # 2nd/3rd time occurrance.
34 &status("RootWarn: not first time root user; msg'ing $nick.");
35 if ($_ = &getFactoid("root again")) {
38 &status("root again needs to be defined in database.");
41 } else { # >3rd time occurrance.
43 # disable this for the time being.
44 if (0 and $warnmode =~ /aggressive/i) {
45 if ($channels{$chan}{'o'}{$ident}) {
46 &status("RootWarn: $nick... sigh... bye bye.");
47 rawout("MODE $chan +b *!root\@$host"); # ban
48 &kick($chan,$nick,"bye bye");
54 ### TODO: OPTIMIZE THIS.
55 # ok... don't record the attempt if nick==root.
56 return if ($nick eq "root");
58 &dbSet("rootwarn", { nick => lc($nick) }, {
61 host => $user."\@".$host,
69 # todo: support arguments to get info on a particular nick?
72 my $count = &countKeys("rootwarn");
75 &performReply("no-one has been warned about root, woohoo");
80 $reply = "there ".&fixPlural("has",$count) ." been \002$count\002 ".
81 &fixPlural("rooter",$count) ." warned about root.";
83 if ($param{'DBType'} !~ /^(pg|my)sql$/i) {
84 &FIXME("rootwarn does not yet support non-{my,pg}sql.");
90 my $query = "SELECT attempt FROM rootwarn WHERE attempt > 2";
91 my $sth = $dbh->prepare($query);
94 while (my @row = $sth->fetchrow_array) {
101 $reply .= " Of which, \002$found\002 ".
102 &fixPlural("rooter",$found)." ".
103 &fixPlural("has",$found).
104 " done it at least 3 times.";
107 &performStrictReply($reply);