2 # ProcessExtra.pl: Extensions to Process.pl
4 # Version: v0.5 (20010124)
8 if (&IsParam("useStrict")) { use strict; }
10 use POSIX qw(strftime);
14 &VERB("Starting schedulers...",2);
19 # 1 for run straight away, 2 for on next-run.
26 &netsplitCheck(1); # mandatory
27 &floodLoop(1); # mandatory
29 &leakCheck(2); # mandatory
30 &ignoreCheck(1); # mandatory
32 &ircCheck(1); # mandatory
33 &miscCheck(1); # mandatory
34 &miscCheck2(2); # mandatory
35 &shmFlush(1); # mandatory
41 &factoidCheck(2); # takes a couple of seconds on a 486. defer it
44 # my $count = map { exists $sched{$_}{TIME} } keys %sched;
46 foreach (keys %sched) {
47 # next unless (exists $sched{$_}{TIME});
48 my $time = $sched{$_}{TIME};
49 next unless (defined $time and $time > time());
54 &status("Schedulers: $count will be running.");
59 my ($interval, $codename, @args) = @_;
60 my $waittime = &getRandomInt($interval);
62 if (!defined $waittime) {
63 &WARN("interval == waittime == UNDEF for $codename.");
67 my $time = $sched{$codename}{TIME};
68 if (defined $time and $time > time()) {
69 &WARN("Sched for $codename already exists.");
73 # &VERB("Scheduling \&$codename() for ".&Time2String($waittime),3);
75 my $retval = $conn->schedule($waittime, \&$codename, @args);
76 $sched{$codename}{LABEL} = $retval;
77 $sched{$codename}{TIME} = time()+$waittime;
78 $sched{$codename}{LOOP} = 1;
82 #### LET THE FUN BEGIN.
86 my $interval = &getChanConfDefault("randomQuoteInterval", 60);
88 &ScheduleThis($interval, "randomQuote");
89 return if ($_[0] eq "2"); # defer.
92 my $line = &getRandomLineFromFile($bot_data_dir. "/blootbot.randtext");
94 &ERROR("random Quote: weird error?");
98 foreach ( &ChanConfList("randomQuote") ) {
99 next unless (&validChan($_));
101 &status("sending random Quote to $_.");
102 &action($_, "Ponders: ".$line);
104 ### TODO: if there were no channels, don't reschedule until channel
105 ### configuration is modified.
112 my $interval = &getChanConfDefault("randomFactoidInterval", 60);
114 &ScheduleThis($interval, "randomFactoid");
115 return if ($_[0] eq "2"); # defer.
119 ($key,$val) = &randKey("factoids","factoid_key,factoid_value");
120 ### $val =~ tr/^[A-Z]/[a-z]/; # blah is Good => blah is good.
121 last if (defined $val and $val !~ /^</);
125 &ERROR("rF: tried 5 times but failed.");
130 foreach ( &ChanConfList("randomFactoid") ) {
131 next unless (&validChan($_));
133 &status("sending random Factoid to $_.");
134 &action($_, "Thinks: \037$key\037 is $val");
135 ### FIXME: Use &getReply() on above to format factoid properly?
140 sub randomFreshmeat {
141 my $interval = &getChanConfDefault("randomFresheatInterval", 60);
144 &ScheduleThis($interval, "randomFreshmeat");
145 return if ($_[0] eq "2"); # defer.
148 my @chans = &ChanConfList("randomFreshmeat");
149 return unless (scalar @chans);
151 &Forker("freshmeat", sub {
152 my $retval = &Freshmeat::randPackage();
155 next unless (&validChan($_));
157 &status("sending random Freshmeat to $_.");
165 &ScheduleThis(60, "logLoop");
166 return if ($_[0] eq "2"); # defer.
169 return unless (defined fileno LOG);
170 return unless (&IsParam("logfile"));
171 return unless (&IsParam("maxLogSize"));
173 ### check if current size is too large.
174 if ( -s $file{log} > $param{'maxLogSize'}) {
175 my $date = sprintf("%04d%02d%02d", (localtime)[5,4,3]);
176 $file{log} = $param{'logfile'} ."-". $date;
177 &status("cycling log file.");
179 if ( -e $file{log}) {
183 $newlog = $file{log}."-".$i;
184 last if (! -e $newlog);
187 $file{log} = $newlog;
191 CORE::system("/bin/mv '$param{'logfile'}' '$file{log}'");
192 &compress($file{log});
194 &status("cycling log file.");
197 ### check if all the logs exceed size.
198 if (!opendir(LOGS, $bot_log_dir)) {
199 &WARN("logLoop: could not open dir '$bot_log_dir'");
205 while (defined($_ = readdir LOGS)) {
206 my $logfile = "$bot_log_dir/$_";
208 next unless ( -f $logfile);
210 my $size = -s $logfile;
211 my $age = (stat $logfile)[9];
212 $age{$age} = $logfile;
213 $size{$logfile} = $size;
219 while ($tsize > $param{'maxLogSize'}) {
220 &status("LOG: current size > max ($tsize > $param{'maxLogSize'})");
221 my $oldest = (sort {$a <=> $b} keys %age)[0];
222 &status("LOG: unlinking $age{$oldest}.");
223 unlink $age{$oldest};
228 ### TODO: add how many b,kb,mb removed?
229 &status("LOG: removed $delete logs.") if ($delete);
234 &ScheduleThis(1440, "seenFlushOld");
235 return if ($_[0] eq "2"); # defer.
238 # is this global-only?
239 return unless (&IsChanConf("seen") > 0);
240 return unless (&IsChanConf("seenFlushInterval") > 0);
242 # global setting. does not make sense for per-channel.
243 my $max_time = &getChanConfDefault("seenMaxDays", 30) *60*60*24;
246 if ($param{'DBType'} =~ /^pgsql|mysql|sqlite/i) {
249 if ($param{'DBType'} =~ /^mysql|sqlite$/i) {
250 $query = "SELECT nick,time FROM seen GROUP BY nick HAVING ".
251 "UNIX_TIMESTAMP() - time > $max_time";
253 $query = "SELECT nick,time FROM seen WHERE ".
254 "extract(epoch from timestamp 'now') - time > $max_time";
257 my $sth = $dbh->prepare($query);
260 while (my @row = $sth->fetchrow_array) {
261 my ($nick,$time) = @row;
263 &dbDel("seen","nick",$nick);
267 } elsif ($param{'DBType'} =~ /^dbm/i) {
270 foreach (keys %seen) {
271 my $delta_time = $time - &dbGet("seen", "time", "nick", $_);
272 next unless ($delta_time > $max_time);
274 &DEBUG("seenFlushOld: ".&Time2String($delta_time) );
279 &FIXME("seenFlushOld: for PG/NO-DB.");
281 &VERB("SEEN deleted $delete seen entries.",2);
287 &ScheduleThis(60, "newsFlush");
288 return if ($_[0] eq "2"); # defer.
291 if (!&ChanConfList("news")) {
292 &DEBUG("newsFlush: news disabled? (chan => $chan)");
299 foreach $chan (keys %::news) {
301 my $total = scalar(keys %{ $::news{$chan} });
304 delete $::news{$chan};
308 foreach $item (keys %{ $::news{$chan} }) {
309 my $t = $::news{$chan}{$item}{Expire};
311 my $tadd = $::news{$chan}{$item}{Time};
312 $oldest = $tadd if ($oldest > $tadd);
314 next if ($t == 0 or $t == -1);
316 &status("newsFlush: Fixed Expire time for $chan/$item, should not happen anyway.");
317 $::news{$chan}{$item}{Expire} = time() + $t*60*60*24;
321 my $delta = $t - time();
323 next unless (time() > $t);
325 # todo: show how old it was.
326 delete $::news{$chan}{$item};
327 &status("NEWS: (newsflush) deleted '$item'");
332 &status("NEWS (newsflush) {$chan}: deleted [$i/$total] news entries.") if ($i);
333 $none{$chan} = 1 if ($total == $i);
336 # todo: flush users aswell.
338 foreach $chan (keys %::newsuser) {
339 next if (exists $none{$chan});
341 foreach (keys %{ $::newsuser{$chan} }) {
342 my $t = $::newsuser{$chan}{$_};
343 if (!defined $t or ($t > 2 and $t < 1000)) {
344 &DEBUG("something wrong with newsuser{$chan}{$_} => $t");
348 next unless ($oldest > $t);
350 delete $::newsuser{$chan}{$_};
354 my $i = scalar(keys %{ $::newsuser{$chan} });
355 delete $::newsuser{$chan} unless ($i);
358 if ($delete or $duser) {
360 &status("NewsFlush: deleted: $delete news entries; $duser user cache.");
365 my $interval = &getChanConfDefault("chanlimitcheckInterval", 10);
368 &ScheduleThis($interval, "chanlimitCheck");
369 return if ($_[0] eq "2");
372 my $str = join(' ', &ChanConfList("chanlimitcheck") );
374 foreach $chan ( &ChanConfList("chanlimitcheck") ) {
375 next unless (&validChan($chan));
377 if ($chan eq "_default") {
378 &WARN("chanlimit: we're doing $chan!! HELP ME!");
382 my $limitplus = &getChanConfDefault("chanlimitcheckPlus", 5, $chan);
383 my $newlimit = scalar(keys %{ $channels{$chan}{''} }) + $limitplus;
384 my $limit = $channels{$chan}{'l'};
386 if (scalar keys %netsplitservers) {
387 if (defined $limit) {
388 &status("chanlimit: netsplit; removing it for $chan.");
389 $conn->mode($chan, "-l");
390 $cache{chanlimitChange}{$chan} = time();
391 &status("chanlimit: netsplit; removed.");
397 if (defined $limit and scalar keys %{ $channels{$chan}{''} } > $limit) {
398 &FIXME("LIMIT: set too low!!! FIXME");
399 ### run NAMES again and flush it.
402 if (defined $limit and $limit == $newlimit) {
403 $cache{chanlimitChange}{$chan} = time();
407 if (!exists $channels{$chan}{'o'}{$ident}) {
408 &status("chanlimit: dont have ops on $chan.") unless (exists $cache{warn}{chanlimit}{$chan});
409 $cache{warn}{chanlimit}{$chan} = 1;
410 &chanServCheck($chan);
413 delete $cache{warn}{chanlimit}{$chan};
415 if (!defined $limit) {
416 &status("chanlimit: setting for first time or from netsplit, for $chan");
419 if (exists $cache{chanlimitChange}{$chan}) {
420 my $delta = time() - $cache{chanlimitChange}{$chan};
421 if ($delta < $interval*60) {
422 &DEBUG("chanlimit: not going to change chanlimit! ($delta<$interval*60)");
427 $conn->mode($chan, "+l", $newlimit);
428 $cache{chanlimitChange}{$chan} = time();
436 &ScheduleThis(15, "netsplitCheck");
437 return if ($_[0] eq "2");
440 $cache{'netsplitCache'}++;
441 # &DEBUG("running netsplitCheck... $cache{netsplitCache}");
443 if (!scalar %netsplit and scalar %netsplitservers) {
444 &DEBUG("nsC: !hash netsplit but hash netsplitservers <- removing!");
445 undef %netsplitservers;
449 # well... this shouldn't happen since %netsplit code does it anyway.
450 foreach $s1 (keys %netsplitservers) {
452 foreach $s2 (keys %{ $netsplitservers{$s1} }) {
453 my $delta = time() - $netsplitservers{$s1}{$s2};
455 if ($delta > 60*30) {
456 &status("netsplit between $s1 and $s2 appears to be stale.");
457 delete $netsplitservers{$s1}{$s2};
462 my $i = scalar(keys %{ $netsplitservers{$s1} });
463 delete $netsplitservers{$s1} unless ($i);
466 # %netsplit hash checker.
467 my $count = scalar keys %netsplit;
469 foreach (keys %netsplit) {
470 if (&IsNickInAnyChan($_)) { # why would this happen?
471 # &DEBUG("nsC: $_ is in some chan; removing from netsplit list.");
472 delete $netsplit{$_};
477 next unless (time() - $netsplit{$_} > 60*15);
480 delete $netsplit{$_};
484 foreach (keys %channels) {
485 my $i = $cache{maxpeeps}{$chan} || 0;
486 my $j = scalar(keys %{ $channels{$chan} });
487 next unless ($i > 10 and 0.25*$i > $j);
489 &DEBUG("netsplit: 0.25*max($i) > current($j); possible netsplit?");
493 my $j = scalar(keys %netsplit);
494 &status("nsC: removed from netsplit list: (before: $count; after: $j)");
497 if (!scalar %netsplit and scalar %netsplitservers) {
498 &DEBUG("nsC: ok hash netsplit is NULL; purging hash netsplitservers");
499 undef %netsplitservers;
502 if ($count and !scalar keys %netsplit) {
503 &DEBUG("nsC: netsplit is hopefully gone. reinstating chanlimit check.");
513 &ScheduleThis(60, "floodLoop"); # minutes.
514 return if ($_[0] eq "2");
518 my $interval = &getChanConfDefault("floodCycle",60);
520 foreach $who (keys %flood) {
521 foreach (keys %{ $flood{$who} }) {
522 if (!exists $flood{$who}{$_}) {
523 &WARN("flood{$who}{$_} undefined?");
527 if ($time - $flood{$who}{$_} > $interval) {
528 delete $flood{$who}{$_};
533 &VERB("floodLoop: deleted $delete items.",2);
538 my $interval = &getChanConfDefault("seenFlushInterval", 60);
539 &ScheduleThis($interval, "seenFlush");
540 return if ($_[0] eq "2");
546 $stats{'count_old'} = &countKeys("seen") || 0;
550 if ($param{'DBType'} =~ /^(mysql|pgsql|sqlite)$/i) {
551 foreach $nick (keys %seencache) {
552 my $retval = &dbReplace("seen", "nick", (
553 "nick" => lc $seencache{$nick}{'nick'},
554 "time" => $seencache{$nick}{'time'},
555 "host" => $seencache{$nick}{'host'},
556 "channel" => $seencache{$nick}{'chan'},
557 "message" => $seencache{$nick}{'msg'},
559 delete $seencache{$nick};
568 my $exists = &dbGet("seen", "nick", "nick=".&dbQuote($nick) );
570 if (defined $exists and $exists) {
571 &dbUpdate("seen", "nick", $nick, (
572 "time" => $seencache{$nick}{'time'},
573 "host" => $seencache{$nick}{'host'},
574 "channel" => $seencache{$nick}{'chan'},
575 "message" => $seencache{$nick}{'msg'},
579 my $retval = &dbInsert("seen", $nick, (
580 "nick" => $seencache{$nick}{'nick'},
581 "time" => $seencache{$nick}{'time'},
582 "host" => $seencache{$nick}{'host'},
583 "channel" => $seencache{$nick}{'chan'},
584 "message" => $seencache{$nick}{'msg'},
588 ### TODO: put bad nick into a list and don't do it again!
589 &FIXME("Should never happen! (nick => $nick)") if !$retval;
592 delete $seencache{$nick};
596 } elsif ($param{'DBType'} =~ /^dbm/i) {
598 foreach $nick (keys %seencache) {
599 my $retval = &dbInsert("seen", $nick, (
600 "nick" => $seencache{$nick}{'nick'},
601 "time" => $seencache{$nick}{'time'},
602 "host" => $seencache{$nick}{'host'},
603 "channel" => $seencache{$nick}{'chan'},
604 "message" => $seencache{$nick}{'msg'},
607 ### TODO: put bad nick into a list and don't do it again!
608 &FIXME("Should never happen! (nick => $nick)") if !$retval;
610 delete $seencache{$nick};
614 &DEBUG("seenFlush: NO VALID FACTOID SUPPORT?");
617 &status("Seen: Flushed $flushed entries.") if ($flushed);
618 &VERB(sprintf(" new seen: %03.01f%% (%d/%d)",
619 $stats{'new'}*100/($stats{'count_old'} || 1),
620 $stats{'new'}, ( $stats{'count_old'} || 1) ), 2) if ($stats{'new'});
621 &VERB(sprintf(" now seen: %3.1f%% (%d/%d)",
622 $stats{'old'}*100 / ( &countKeys("seen") || 1),
623 $stats{'old'}, &countKeys("seen") ), 2) if ($stats{'old'});
625 &WARN("scalar keys seenflush != 0!") if (scalar keys %seenflush);
633 &ScheduleThis(240, "leakCheck");
634 return if ($_[0] eq "2");
637 # flood. this is dealt with in floodLoop()
638 foreach $blah1 (keys %flood) {
639 foreach $blah2 (keys %{ $flood{$blah1} }) {
640 $count += scalar(keys %{ $flood{$blah1}{$blah2} });
643 &VERB("leak: hash flood has $count total keys.",2);
647 foreach $blah1 (keys %floodjoin) {
648 foreach $blah2 (keys %{ $floodjoin{$blah1} }) {
649 $count += scalar(keys %{ $floodjoin{$blah1}{$blah2} });
652 &VERB("leak: hash floodjoin has $count total keys.",2);
655 $count = scalar(keys %floodwarn);
656 &VERB("leak: hash floodwarn has $count total keys.",2);
659 foreach $chan (grep /[A-Z]/, keys %channels) {
660 &DEBUG("leak: chan => '$chan'.");
662 foreach $i (keys %{ $channels{$chan} }) {
663 foreach (keys %{ $channels{$chan}{$i} }) {
664 &DEBUG("leak: \$channels{$chan}{$i}{$_} ...");
670 $count = scalar(keys %chanstats);
671 &VERB("leak: hash chanstats has $count total keys.",2);
675 foreach (keys %nuh) {
676 next if (&IsNickInAnyChan($_));
677 next if (exists $dcc{CHAT}{$_});
683 &status("leak: $delete nuh{} items deleted; now have ".
684 scalar(keys %nuh) ) if ($delete);
689 &ScheduleThis(60, "ignoreCheck");
690 return if ($_[0] eq "2"); # defer.
696 foreach (keys %ignore) {
699 foreach (keys %{ $ignore{$chan} }) {
700 my @array = @{ $ignore{$chan}{$_} };
702 next unless ($array[0] and $time > $array[0]);
704 delete $ignore{$chan}{$_};
705 &status("ignore: $_/$chan has expired.");
710 $cache{ignoreCheckTime} = time();
712 &VERB("ignore: $count items deleted.",2);
717 &ScheduleThis(15, "ircCheck");
718 return if ($_[0] eq "2"); # defer.
721 $cache{statusSafe} = 1;
723 my @x = &getJoinChans();
724 my $iconf = scalar( @x );
725 my $inow = scalar( keys %channels );
726 if ($iconf > 2 and $inow * 2 <= $iconf) {
727 &FIXME("ircCheck: current channels * 2 <= config channels. FIXME.");
728 &FIXME("ircCheck: iconf = $iconf");
729 &FIXME("ircCheck: inow = $inow");
734 if (!$conn->connected or time() - $msgtime > 3600) {
735 # todo: shouldn't we use cache{connect} somewhere?
736 if (exists $cache{connect}) {
737 &WARN("ircCheck: no msg for 3600 and disco'd! reconnecting!");
738 $msgtime = time(); # just in case.
740 delete $cache{connect};
742 &status("IRCTEST: possible lost in space; checking. ".
744 &msg($ident, "TEST");
745 $cache{connect} = time();
749 if ($ident !~ /^\Q$param{ircNick}\E$/) {
750 # this does not work unfortunately.
751 &WARN("ircCheck: ident($ident) != param{ircNick}($param{IrcNick}).");
753 # this check is misleading... perhaps we should do a notify.
754 if (! &IsNickInAnyChan( $param{ircNick} ) ) {
755 &DEBUG("$param{ircNick} not in use... changing!");
756 &nick( $param{ircNick} );
758 &WARN("$param{ircNick} is still in use...");
762 if (grep /^\s*$/, keys %channels) {
763 &WARN("ircCheck: we have a NULL chan in hash channels? removing!");
764 if (!exists $channels{''}) {
765 &DEBUG("ircCheck: this should never happen!");
768 delete $channels{''};
771 $cache{statusSafe} = 0;
774 if ($utime_userfile > $wtime_userfile and time() - $wtime_userfile > 3600) {
776 $wtime_userfile = time();
779 if ($utime_chanfile > $wtime_chanfile and time() - $wtime_chanfile > 3600) {
781 $wtime_chanfile = time();
787 &ScheduleThis(120, "miscCheck");
788 return if ($_[0] eq "2"); # defer.
793 if ( -x "/usr/bin/ipcs") {
794 @ipcs = `/usr/bin/ipcs`;
796 &WARN("ircCheck: no 'ipcs' binary.");
800 # shmid stale remove.
804 # key, shmid, owner, perms, bytes, nattch
805 next unless (/^(0x\d+) (\d+)\s+(\S+)\s+(\d+)\s+(\d+)\s+/);
807 my ($shmid, $size) = ($2,$5);
808 next unless ($shmid != $shm and $size == 2000);
809 my $z = &shmRead($shmid);
810 if ($z =~ /^(\d+): /) {
812 next if (time() - $time < 60*60);
815 # &DEBUG("shm: $shmid is not ours or old blootbot => ($z)");
819 &status("SHM: nuking shmid $shmid");
820 CORE::system("/usr/bin/ipcrm shm $shmid >/dev/null");
823 # make backup of important files.
824 &mkBackup( $bot_state_dir."/blootbot.chan", 60*60*24*3);
825 &mkBackup( $bot_state_dir."/blootbot.users", 60*60*24*3);
826 &mkBackup( $bot_base_dir."/blootbot-news.txt", 60*60*24*1);
828 # flush cache{lobotomy}
829 foreach (keys %{ $cache{lobotomy} }) {
830 next unless (time() - $cache{lobotomy}{$_} > 60*60);
831 delete $cache{lobotomy}{$_};
834 ### check modules if they've been modified. might be evil.
840 &ScheduleThis(240, "miscCheck2");
841 return if ($_[0] eq "2"); # defer.
845 opendir(DEBIAN, "$bot_state_dir/debian");
846 foreach ( grep /gz$/, readdir(DEBIAN) ) {
847 my $exit = CORE::system("gzip -t $bot_state_dir/debian/$_");
850 &status("debian: unlinking file => $_");
851 unlink "$bot_state_dir/debian/$_";
855 # compress logs that should have been compressed.
856 # todo: use strftime?
857 my ($day,$month,$year) = (localtime(time()))[3,4,5];
858 my $date = sprintf("%04d%02d%02d",$year+1900,$month+1,$day);
860 if (!opendir(DIR,"$bot_log_dir")) {
861 &ERROR("misccheck2: log dir $bot_log_dir does not exist.");
866 while (my $f = readdir(DIR)) {
867 next unless ( -f "$bot_log_dir/$f");
868 next if ($f =~ /gz|bz2/);
869 next unless ($f =~ /(\d{8})/);
870 next if ($date eq $1);
872 &compress("$bot_log_dir/$f");
877 ### this is semi-scheduled
879 if ($ident eq $param{'ircNick'}) {
880 &status("okay, got my nick back.");
885 &ScheduleThis(30, "getNickInUse");
886 return if ($_[0] eq "2"); # defer.
889 &nick( $param{'ircNick'} );
893 return unless &IsChanConf("uptime");
896 &ScheduleThis(60, "uptimeLoop");
897 return if ($_[0] eq "2"); # defer.
906 &ScheduleThis(60, "slashdotLoop");
907 return if ($_[0] eq "2");
910 my @chans = &ChanConfList("slashdotAnnounce");
911 return unless (scalar @chans);
913 &Forker("slashdot", sub {
914 my $line = &Slashdot::slashdotAnnounce();
915 return unless (defined $line);
918 next unless (&::validChan($_));
920 &::status("sending slashdot update to $_.");
921 ¬ice($_, "Slashdot: $line");
929 &ScheduleThis(60, "plugLoop");
930 return if ($_[0] eq "2");
933 my @chans = &ChanConfList("plugAnnounce");
934 return unless (scalar @chans);
936 &Forker("plug", sub {
937 my $line = &Plug::plugAnnounce();
938 return unless (defined $line);
941 next unless (&::validChan($_));
943 &::status("sending plug update to $_.");
944 ¬ice($_, "Plug: $line");
951 &ScheduleThis(60, "freshmeatLoop");
952 return if ($_[0] eq "2");
955 my @chans = &ChanConfList("freshmeatAnnounce");
956 return unless (scalar @chans);
958 &Forker("freshmeat", sub {
959 my $data = &Freshmeat::freshmeatAnnounce();
962 next unless (&::validChan($_));
964 &::status("sending freshmeat update to $_.");
972 &ScheduleThis(240, "kernelLoop");
973 return if ($_[0] eq "2");
976 my @chans = &ChanConfList("kernelAnnounce");
977 return unless (scalar @chans);
979 &Forker("kernel", sub {
980 my @data = &Kernel::kernelAnnounce();
983 next unless (&::validChan($_));
985 &::status("sending kernel update to $_.");
988 ¬ice($c, "Kernel: $_");
995 return unless &IsChanConf("wingate");
997 ### FILE CACHE OF OFFENDING WINGATES.
998 foreach (grep /^$host$/, @wingateBad) {
999 &status("Wingate: RUNNING ON $host BY $who");
1000 &ban("*!*\@$host", "") if &IsChanConf("wingateBan");
1002 my $reason = &getChanConf("wingateKick");
1004 next unless ($reason);
1005 &kick($who, "", $reason)
1008 ### RUN CACHE OF TRIED WINGATES.
1009 if (grep /^$host$/, @wingateCache) {
1010 push(@wingateNow, $host); # per run.
1011 push(@wingateCache, $host); # cache per run.
1013 &DEBUG("Already scanned $host. good.");
1016 my $interval = &getChanConfDefault("wingateInterval", 60); # seconds.
1017 return if (defined $forked{'wingate'});
1018 return if (time() - $wingaterun <= $interval);
1019 return unless (scalar(keys %wingateToDo));
1021 $wingaterun = time();
1023 &Forker("wingate", sub { &Wingate::Wingates(keys %wingateToDo); } );
1028 sub wingateWriteFile {
1030 &ScheduleThis(60, "wingateWriteFile");
1031 return if ($_[0] eq "2"); # defer.
1034 return unless (scalar @wingateCache);
1036 my $file = "$bot_base_dir/$param{'ircUser'}.wingate";
1037 if ($bot_pid != $$) {
1038 &DEBUG("wingateWriteFile: Reorganising!");
1043 push(@wingateNow, $_);
1048 my %hash = map { $_ => 1 } @wingateNow;
1049 @wingateNow = sort keys %hash;
1052 &DEBUG("wingateWF: writing...");
1053 open(OUT, ">$file");
1054 foreach (@wingateNow) {
1062 &ScheduleThis(720, "factoidCheck");
1063 return if ($_[0] eq "2"); # defer.
1066 my @list = &searchTable("factoids", "factoid_key", "factoid_key", " #DEL#");
1067 my $stale = &getChanConfDefault("factoidDeleteDelay", 14) *60*60*24;
1069 # disable it since it's "illegal".
1076 my $age = &getFactInfo($_, "modified_time");
1078 if (!defined $age or $age !~ /^\d+$/) {
1079 if (scalar @list > 50) {
1080 if (!$cache{warnDel}) {
1081 &WARN("list is over 50 (".scalar(@list)."... giving it a miss.");
1082 $cache{warnDel} = 1;
1087 &WARN("del factoid: old cruft (no time): $_");
1092 next unless ($time - $age > $stale);
1095 $fix =~ s/ #DEL#$//g;
1096 my $agestr = &Time2String($time - $age);
1097 &status("safedel: Removing '$_' for good. [$agestr old]");
1104 return unless (scalar keys %{ $dcc{CHAT} });
1107 &ScheduleThis(10, "dccStatus");
1108 return if ($_[0] eq "2"); # defer.
1111 my $time = strftime("%H:%M", localtime(time()) );
1114 foreach (keys %channels) {
1116 my $users = keys %{ $channels{$c}{''} };
1117 my $chops = keys %{ $channels{$c}{o} };
1118 my $bans = keys %{ $channels{$c}{b} };
1120 my $txt = "[$time] $c: $users members ($chops chops), $bans bans";
1121 foreach (keys %{ $dcc{'CHAT'} }) {
1122 next unless (exists $channels{$c}{''}{lc $_});
1123 $conn->privmsg($dcc{'CHAT'}{$_}, $txt);
1136 foreach (keys %{ $irc->{_queue} }) {
1140 foreach (keys %sched) {
1141 next unless ($q eq $sched{$_});
1146 my $time = $irc->{_queue}->{$q}->[0] - time();
1148 if (defined $sched) {
1149 &DEBUG(" $sched($q): ".&Time2String($time) );
1151 &DEBUG(" NULL($q): ".&Time2String($time) );
1155 &DEBUG("end of sList.");
1159 my($file, $time) = @_;
1163 &VERB("mkB: file '$file' does not exist.",2);
1168 if ( -e "$file~" ) {
1169 $backup++ if ((stat $file)[9] - (stat "$file~")[9] > $time);
1170 my $delta = time() - (stat "$file~")[9];
1171 $age = &Time2String($delta);
1176 return unless ($backup);
1178 ### TODO: do internal copying.
1179 &status("Backup: $file ($age)");
1180 CORE::system("/bin/cp $file $file~");