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 = &sqlSelect('rootwarn', 'attempt', { nick => $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 8))."T has landed!");
27 if ($_ = &getFactoid('root')) {
28 &msg($nick, "RootWarn: $attempt : $_");
30 &status('"root" needs to be defined in database.');
33 } elsif ($attempt < 2) { # 2nd/3rd time occurrance.
34 if ($_ = &getFactoid('root again')) {
35 &status("RootWarn: not first time root user; msg'ing $nick.");
36 &msg($nick, "RootWarn: $attempt : $_");
38 &status('"root again" needs to be defined in database.');
41 } else { # >3rd time occurrance.
42 # disable this for the time being.
43 if (0 and $warnmode =~ /aggressive/i) {
44 if ($channels{$chan}{'o'}{$ident}) {
45 &status("RootWarn: $nick... sigh... bye bye.");
46 rawout("MODE $chan +b *!root\@$host"); # ban
47 &kick($chan,$nick,'bye bye');
49 } elsif ($_ = &getFactoid('root again')) {
50 &status("RootWarn: $attempt times; msg'ing $nick.");
51 &msg($nick, "RootWarn: $attempt : $_");
53 &status("root again needs to be defined in database.");
58 ### TODO: OPTIMIZE THIS.
59 # ok... don't record the attempt if nick==root.
60 return if ($nick eq "root");
62 &sqlSet('rootwarn', { nick => lc($nick) }, {
65 host => $user."\@".$host,
73 # TODO: support arguments to get info on a particular nick?
76 my $count = &countKeys('rootwarn');
79 &performReply("no-one has been warned about root, woohoo");
84 $reply = "there ".&fixPlural("has",$count) ." been \002$count\002 ".
85 &fixPlural("rooter",$count) ." warned about root.";
87 if ($param{'DBType'} !~ /^(pg|my)sql$/i) {
88 &FIXME("rootwarn does not yet support non-{my,pg}sql.");
94 my $query = "SELECT attempt FROM rootwarn WHERE attempt > 2";
95 my $sth = $dbh->prepare($query);
98 while (my @row = $sth->fetchrow_array) {
105 $reply .= " Of which, \002$found\002 ".
106 &fixPlural("rooter",$found)." ".
107 &fixPlural("has",$found).
108 " done it at least 3 times.";
111 &performStrictReply($reply);