2 # ProcessExtra.pl: Extensions to Process.pl
4 # Version: v0.5 (20010124)
10 use POSIX qw(strftime);
11 use vars qw(%sched %schedule);
13 # format: function name = (
14 # str chanconfdefault,
15 # int internaldefault,
17 # int next run, (optional)
21 # uptimeLoop => ("", 60, 1),
24 sub setupSchedulersII {
25 foreach (keys %schedule) {
26 &queueTask($_, @{ $schedule{$_} });
31 my($codename, $chanconfdef, $intervaldef, $defer) = @_;
32 my $t = &getChanConfDefault($chanconfdef, $intervaldef);
33 my $waittime = &getRandomInt($t);
35 if (!defined $waittime) {
36 &WARN("interval == waittime == UNDEF for $codename.");
40 my $time = $schedule{$codename}[3];
41 if (defined $time and $time > time()) {
42 &WARN("Sched for $codename already exists.");
46 # &VERB("Scheduling \&$codename() for ".&Time2String($waittime),3);
48 my $retval = $conn->schedule($waittime, sub {
54 &VERB("Starting schedulers...",2);
59 # 1 for run straight away, 2 for on next-run.
66 &netsplitCheck(1); # mandatory
67 &floodLoop(1); # mandatory
69 &leakCheck(2); # mandatory
70 &ignoreCheck(1); # mandatory
72 &ircCheck(1); # mandatory
73 &miscCheck(1); # mandatory
74 &miscCheck2(2); # mandatory
75 &shmFlush(1); # mandatory
81 &factoidCheck(2); # takes a couple of seconds on a 486. defer it
82 # todo: convert to new format... or nuke altogether.
85 # todo: squeeze this into a one-liner.
86 # my $count = map { exists $sched{$_}{TIME} } keys %sched;
88 foreach (keys %sched) {
89 my $time = $sched{$_}{TIME};
90 next unless (defined $time and $time > time());
95 &status("Schedulers: $count will be running.");
100 my ($interval, $codename, @args) = @_;
101 my $waittime = &getRandomInt($interval);
103 if (!defined $waittime) {
104 &WARN("interval == waittime == UNDEF for $codename.");
108 my $time = $sched{$codename}{TIME};
109 if (defined $time and $time > time()) {
110 &WARN("Sched for $codename already exists.");
114 # &VERB("Scheduling \&$codename() for ".&Time2String($waittime),3);
116 my $retval = $conn->schedule($waittime, \&$codename, @args);
117 $sched{$codename}{LABEL} = $retval;
118 $sched{$codename}{TIME} = time()+$waittime;
119 $sched{$codename}{LOOP} = 1;
123 #### LET THE FUN BEGIN.
127 my $interval = &getChanConfDefault("randomQuoteInterval", 60);
129 &ScheduleThis($interval, "randomQuote");
130 return if ($_[0] eq "2"); # defer.
133 my $line = &getRandomLineFromFile($bot_data_dir. "/blootbot.randtext");
134 if (!defined $line) {
135 &ERROR("random Quote: weird error?");
139 foreach ( &ChanConfList("randomQuote") ) {
140 next unless (&validChan($_));
142 &status("sending random Quote to $_.");
143 &action($_, "Ponders: ".$line);
145 ### TODO: if there were no channels, don't reschedule until channel
146 ### configuration is modified.
153 my $interval = &getChanConfDefault("randomFactoidInterval", 60);
155 &ScheduleThis($interval, "randomFactoid");
156 return if ($_[0] eq "2"); # defer.
160 ($key,$val) = &randKey("factoids","factoid_key,factoid_value");
161 ### $val =~ tr/^[A-Z]/[a-z]/; # blah is Good => blah is good.
162 last if (defined $val and $val !~ /^</);
166 &ERROR("rF: tried 5 times but failed.");
171 foreach ( &ChanConfList("randomFactoid") ) {
172 next unless (&validChan($_));
174 &status("sending random Factoid to $_.");
175 &action($_, "Thinks: \037$key\037 is $val");
176 ### FIXME: Use &getReply() on above to format factoid properly?
181 sub randomFreshmeat {
182 my $interval = &getChanConfDefault("randomFreshmeatInterval", 60);
185 &ScheduleThis($interval, "randomFreshmeat");
186 return if ($_[0] eq "2"); # defer.
189 my @chans = &ChanConfList("randomFreshmeat");
190 return unless (scalar @chans);
192 &Forker("freshmeat", sub {
193 my $retval = &Freshmeat::randPackage();
196 next unless (&validChan($_));
198 &status("sending random Freshmeat to $_.");
206 &ScheduleThis(60, "logLoop");
207 return if ($_[0] eq "2"); # defer.
210 return unless (defined fileno LOG);
211 return unless (&IsParam("logfile"));
212 return unless (&IsParam("maxLogSize"));
214 ### check if current size is too large.
215 if ( -s $file{log} > $param{'maxLogSize'}) {
216 my $date = sprintf("%04d%02d%02d", (gmtime)[5,4,3]);
217 $file{log} = $param{'logfile'} ."-". $date;
218 &status("cycling log file.");
220 if ( -e $file{log}) {
224 $newlog = $file{log}."-".$i;
225 last if (! -e $newlog);
228 $file{log} = $newlog;
232 CORE::system("/bin/mv '$param{'logfile'}' '$file{log}'");
233 &compress($file{log});
235 &status("cycling log file.");
238 ### check if all the logs exceed size.
239 if (!opendir(LOGS, $bot_log_dir)) {
240 &WARN("logLoop: could not open dir '$bot_log_dir'");
246 while (defined($_ = readdir LOGS)) {
247 my $logfile = "$bot_log_dir/$_";
249 next unless ( -f $logfile);
251 my $size = -s $logfile;
252 my $age = (stat $logfile)[9];
253 $age{$age} = $logfile;
254 $size{$logfile} = $size;
260 while ($tsize > $param{'maxLogSize'}) {
261 &status("LOG: current size > max ($tsize > $param{'maxLogSize'})");
262 my $oldest = (sort {$a <=> $b} keys %age)[0];
263 &status("LOG: unlinking $age{$oldest}.");
264 unlink $age{$oldest};
269 ### TODO: add how many b,kb,mb removed?
270 &status("LOG: removed $delete logs.") if ($delete);
275 &ScheduleThis(1440, "seenFlushOld");
276 return if ($_[0] eq "2"); # defer.
279 # is this global-only?
280 return unless (&IsChanConf("seen") > 0);
281 return unless (&IsChanConf("seenFlushInterval") > 0);
283 # global setting. does not make sense for per-channel.
284 my $max_time = &getChanConfDefault("seenMaxDays", 30) *60*60*24;
287 if ($param{'DBType'} =~ /^(pgsql|mysql|sqlite)/i) {
290 if ($param{'DBType'} =~ /^mysql|sqlite$/i) {
291 $query = "SELECT nick,time FROM seen GROUP BY nick HAVING ".
292 "UNIX_TIMESTAMP() - time > $max_time";
294 $query = "SELECT nick,time FROM seen WHERE ".
295 "extract(epoch from timestamp 'now') - time > $max_time";
298 my $sth = $dbh->prepare($query);
300 while (my @row = $sth->fetchrow_array) {
301 my ($nick,$time) = @row;
303 &sqlDelete("seen", { nick => $nick } );
308 } elsif ($param{'DBType'} =~ /^dbm/i) {
311 foreach (keys %seen) {
312 my $t2 = &sqlSelect("seen", "time", { nick => $_ }) || 0;
313 my $delta_time = $time - $t2;
314 next unless ($delta_time > $max_time);
316 &DEBUG("seenFlushOld: ".&Time2String($delta_time) );
321 &FIXME("seenFlushOld: for PG/NO-DB.");
323 &VERB("SEEN deleted $delete seen entries.",2);
329 &ScheduleThis(60, "newsFlush");
330 return if ($_[0] eq "2"); # defer.
333 if (!&ChanConfList("news")) {
334 &DEBUG("newsFlush: news disabled? (chan => $chan)");
341 foreach $chan (keys %::news) {
343 my $total = scalar(keys %{ $::news{$chan} });
346 delete $::news{$chan};
350 foreach $item (keys %{ $::news{$chan} }) {
351 my $t = $::news{$chan}{$item}{Expire};
353 my $tadd = $::news{$chan}{$item}{Time};
354 $oldest = $tadd if ($oldest > $tadd);
356 next if ($t == 0 or $t == -1);
358 &status("newsFlush: Fixed Expire time for $chan/$item, should not happen anyway.");
359 $::news{$chan}{$item}{Expire} = time() + $t*60*60*24;
363 my $delta = $t - time();
365 next unless (time() > $t);
367 # todo: show how old it was.
368 delete $::news{$chan}{$item};
369 &status("NEWS: (newsflush) deleted '$item'");
374 &status("NEWS (newsflush) {$chan}: deleted [$i/$total] news entries.") if ($i);
375 $none{$chan} = 1 if ($total == $i);
378 # todo: flush users aswell.
380 foreach $chan (keys %::newsuser) {
381 next if (exists $none{$chan});
383 foreach (keys %{ $::newsuser{$chan} }) {
384 my $t = $::newsuser{$chan}{$_};
385 if (!defined $t or ($t > 2 and $t < 1000)) {
386 &DEBUG("something wrong with newsuser{$chan}{$_} => $t");
390 next unless ($oldest > $t);
392 delete $::newsuser{$chan}{$_};
396 my $i = scalar(keys %{ $::newsuser{$chan} });
397 delete $::newsuser{$chan} unless ($i);
400 if ($delete or $duser) {
401 &status("NewsFlush: deleted: $delete news entries; $duser user cache.");
406 my $interval = &getChanConfDefault("chanlimitcheckInterval", 10);
409 &ScheduleThis($interval, "chanlimitCheck");
410 return if ($_[0] eq "2");
413 my $str = join(' ', &ChanConfList("chanlimitcheck") );
415 foreach $chan ( &ChanConfList("chanlimitcheck") ) {
416 next unless (&validChan($chan));
418 if ($chan eq "_default") {
419 &WARN("chanlimit: we're doing $chan!! HELP ME!");
423 my $limitplus = &getChanConfDefault("chanlimitcheckPlus", 5, $chan);
424 my $newlimit = scalar(keys %{ $channels{$chan}{''} }) + $limitplus;
425 my $limit = $channels{$chan}{'l'};
427 if (scalar keys %netsplitservers) {
428 if (defined $limit) {
429 &status("chanlimit: netsplit; removing it for $chan.");
430 $conn->mode($chan, "-l");
431 $cache{chanlimitChange}{$chan} = time();
432 &status("chanlimit: netsplit; removed.");
438 if (defined $limit and scalar keys %{ $channels{$chan}{''} } > $limit) {
439 &FIXME("LIMIT: set too low!!! FIXME");
440 ### run NAMES again and flush it.
443 if (defined $limit and $limit == $newlimit) {
444 $cache{chanlimitChange}{$chan} = time();
448 if (!exists $channels{$chan}{'o'}{$ident}) {
449 &status("chanlimit: dont have ops on $chan.") unless (exists $cache{warn}{chanlimit}{$chan});
450 $cache{warn}{chanlimit}{$chan} = 1;
451 &chanServCheck($chan);
454 delete $cache{warn}{chanlimit}{$chan};
456 if (!defined $limit) {
457 &status("chanlimit: setting for first time or from netsplit, for $chan");
460 if (exists $cache{chanlimitChange}{$chan}) {
461 my $delta = time() - $cache{chanlimitChange}{$chan};
462 if ($delta < $interval*60) {
463 &DEBUG("chanlimit: not going to change chanlimit! ($delta<$interval*60)");
468 $conn->mode($chan, "+l", $newlimit);
469 $cache{chanlimitChange}{$chan} = time();
477 &ScheduleThis(15, "netsplitCheck");
478 return if ($_[0] eq "2");
481 $cache{'netsplitCache'}++;
482 # &DEBUG("running netsplitCheck... $cache{netsplitCache}");
484 if (!scalar %netsplit and scalar %netsplitservers) {
485 &DEBUG("nsC: !hash netsplit but hash netsplitservers <- removing!");
486 undef %netsplitservers;
490 # well... this shouldn't happen since %netsplit code does it anyway.
491 foreach $s1 (keys %netsplitservers) {
493 foreach $s2 (keys %{ $netsplitservers{$s1} }) {
494 my $delta = time() - $netsplitservers{$s1}{$s2};
496 if ($delta > 60*30) {
497 &status("netsplit between $s1 and $s2 appears to be stale.");
498 delete $netsplitservers{$s1}{$s2};
503 my $i = scalar(keys %{ $netsplitservers{$s1} });
504 delete $netsplitservers{$s1} unless ($i);
507 # %netsplit hash checker.
508 my $count = scalar keys %netsplit;
510 foreach (keys %netsplit) {
511 if (&IsNickInAnyChan($_)) { # why would this happen?
512 # &DEBUG("nsC: $_ is in some chan; removing from netsplit list.");
513 delete $netsplit{$_};
518 next unless (time() - $netsplit{$_} > 60*15);
521 delete $netsplit{$_};
525 foreach (keys %channels) {
526 my $i = $cache{maxpeeps}{$chan} || 0;
527 my $j = scalar(keys %{ $channels{$chan} });
528 next unless ($i > 10 and 0.25*$i > $j);
530 &DEBUG("netsplit: 0.25*max($i) > current($j); possible netsplit?");
534 my $j = scalar(keys %netsplit);
535 &status("nsC: removed from netsplit list: (before: $count; after: $j)");
538 if (!scalar %netsplit and scalar %netsplitservers) {
539 &DEBUG("nsC: ok hash netsplit is NULL; purging hash netsplitservers");
540 undef %netsplitservers;
543 if ($count and !scalar keys %netsplit) {
544 &DEBUG("nsC: netsplit is hopefully gone. reinstating chanlimit check.");
554 &ScheduleThis(60, "floodLoop"); # minutes.
555 return if ($_[0] eq "2");
559 my $interval = &getChanConfDefault("floodCycle",60);
561 foreach $who (keys %flood) {
562 foreach (keys %{ $flood{$who} }) {
563 if (!exists $flood{$who}{$_}) {
564 &WARN("flood{$who}{$_} undefined?");
568 if ($time - $flood{$who}{$_} > $interval) {
569 delete $flood{$who}{$_};
574 &VERB("floodLoop: deleted $delete items.",2);
579 my $interval = &getChanConfDefault("seenFlushInterval", 60);
580 &ScheduleThis($interval, "seenFlush");
581 return if ($_[0] eq "2");
587 $stats{'count_old'} = &countKeys("seen") || 0;
591 if ($param{'DBType'} =~ /^(mysql|pgsql|sqlite|dbm)$/i) {
592 foreach $nick (keys %seencache) {
593 my $retval = &sqlReplace("seen", {
594 nick => lc $seencache{$nick}{'nick'},
595 time => $seencache{$nick}{'time'},
596 host => $seencache{$nick}{'host'},
597 channel => $seencache{$nick}{'chan'},
598 message => $seencache{$nick}{'msg'},
601 delete $seencache{$nick};
605 &DEBUG("seenFlush: NO VALID FACTOID SUPPORT?");
608 &status("Seen: Flushed $flushed entries.") if ($flushed);
609 &VERB(sprintf(" new seen: %03.01f%% (%d/%d)",
610 $stats{'new'}*100/($stats{'count_old'} || 1),
611 $stats{'new'}, ( $stats{'count_old'} || 1) ), 2) if ($stats{'new'});
612 &VERB(sprintf(" now seen: %3.1f%% (%d/%d)",
613 $stats{'old'}*100 / ( &countKeys("seen") || 1),
614 $stats{'old'}, &countKeys("seen") ), 2) if ($stats{'old'});
616 &WARN("scalar keys seenflush != 0!") if (scalar keys %seenflush);
624 &ScheduleThis(240, "leakCheck");
625 return if ($_[0] eq "2");
628 # flood. this is dealt with in floodLoop()
629 foreach $blah1 (keys %flood) {
630 foreach $blah2 (keys %{ $flood{$blah1} }) {
631 $count += scalar(keys %{ $flood{$blah1}{$blah2} });
634 &VERB("leak: hash flood has $count total keys.",2);
638 foreach $blah1 (keys %floodjoin) {
639 foreach $blah2 (keys %{ $floodjoin{$blah1} }) {
640 $count += scalar(keys %{ $floodjoin{$blah1}{$blah2} });
643 &VERB("leak: hash floodjoin has $count total keys.",2);
646 $count = scalar(keys %floodwarn);
647 &VERB("leak: hash floodwarn has $count total keys.",2);
650 foreach $chan (grep /[A-Z]/, keys %channels) {
651 &DEBUG("leak: chan => '$chan'.");
653 foreach $i (keys %{ $channels{$chan} }) {
654 foreach (keys %{ $channels{$chan}{$i} }) {
655 &DEBUG("leak: \$channels{$chan}{$i}{$_} ...");
661 $count = scalar(keys %chanstats);
662 &VERB("leak: hash chanstats has $count total keys.",2);
666 foreach (keys %nuh) {
667 next if (&IsNickInAnyChan($_));
668 next if (exists $dcc{CHAT}{$_});
674 &status("leak: $delete nuh{} items deleted; now have ".
675 scalar(keys %nuh) ) if ($delete);
680 &ScheduleThis(60, "ignoreCheck");
681 return if ($_[0] eq "2"); # defer.
687 foreach (keys %ignore) {
690 foreach (keys %{ $ignore{$chan} }) {
691 my @array = @{ $ignore{$chan}{$_} };
693 next unless ($array[0] and $time > $array[0]);
695 delete $ignore{$chan}{$_};
696 &status("ignore: $_/$chan has expired.");
701 $cache{ignoreCheckTime} = time();
703 &VERB("ignore: $count items deleted.",2);
708 &ScheduleThis(15, "ircCheck");
709 return if ($_[0] eq "2"); # defer.
712 $cache{statusSafe} = 1;
714 my @x = &getJoinChans();
715 my $iconf = scalar( @x );
716 my $inow = scalar( keys %channels );
717 if ($iconf > 2 and $inow * 2 <= $iconf) {
718 &FIXME("ircCheck: current channels * 2 <= config channels. FIXME.");
719 &FIXME("ircCheck: iconf = $iconf");
720 &FIXME("ircCheck: inow = $inow");
725 if (!$conn->connected or time() - $msgtime > 3600) {
726 # todo: shouldn't we use cache{connect} somewhere?
727 if (exists $cache{connect}) {
728 &WARN("ircCheck: no msg for 3600 and disco'd! reconnecting!");
729 $msgtime = time(); # just in case.
731 delete $cache{connect};
733 &status("IRCTEST: possible lost in space; checking. ".
735 &msg($ident, "TEST");
736 $cache{connect} = time();
740 if ($ident !~ /^\Q$param{ircNick}\E$/) {
741 # this does not work unfortunately.
742 &WARN("ircCheck: ident($ident) != param{ircNick}($param{ircNick}).");
744 # this check is misleading... perhaps we should do a notify.
745 if (! &IsNickInAnyChan( $param{ircNick} ) ) {
746 &DEBUG("$param{ircNick} not in use... changing!");
747 &nick( $param{ircNick} );
749 &WARN("$param{ircNick} is still in use...");
753 if (grep /^\s*$/, keys %channels) {
754 &WARN("ircCheck: we have a NULL chan in hash channels? removing!");
755 if (!exists $channels{''}) {
756 &DEBUG("ircCheck: this should never happen!");
759 delete $channels{''};
762 $cache{statusSafe} = 0;
765 if ($utime_userfile > $wtime_userfile and time() - $wtime_userfile > 3600) {
767 $wtime_userfile = time();
770 if ($utime_chanfile > $wtime_chanfile and time() - $wtime_chanfile > 3600) {
772 $wtime_chanfile = time();
778 &ScheduleThis(120, "miscCheck");
779 return if ($_[0] eq "2"); # defer.
784 if ( -x "/usr/bin/ipcs") {
785 @ipcs = `/usr/bin/ipcs`;
787 &WARN("ircCheck: no 'ipcs' binary.");
791 # shmid stale remove.
795 # key, shmid, owner, perms, bytes, nattch
796 next unless (/^(0x\d+) (\d+)\s+(\S+)\s+(\d+)\s+(\d+)\s+/);
798 my ($shmid, $size) = ($2,$5);
799 next unless ($shmid != $shm and $size == 2000);
800 my $z = &shmRead($shmid);
801 if ($z =~ /^(\d+): /) {
803 next if (time() - $time < 60*60);
806 # &DEBUG("shm: $shmid is not ours or old blootbot => ($z)");
810 &status("SHM: nuking shmid $shmid");
811 CORE::system("/usr/bin/ipcrm shm $shmid >/dev/null");
814 # make backup of important files.
815 &mkBackup( $bot_state_dir."/blootbot.chan", 60*60*24*3);
816 &mkBackup( $bot_state_dir."/blootbot.users", 60*60*24*3);
817 &mkBackup( $bot_base_dir."/blootbot-news.txt", 60*60*24*1);
819 # flush cache{lobotomy}
820 foreach (keys %{ $cache{lobotomy} }) {
821 next unless (time() - $cache{lobotomy}{$_} > 60*60);
822 delete $cache{lobotomy}{$_};
825 ### check modules if they've been modified. might be evil.
831 &ScheduleThis(240, "miscCheck2");
832 return if ($_[0] eq "2"); # defer.
836 opendir(DEBIAN, "$bot_state_dir/debian");
837 foreach ( grep /gz$/, readdir(DEBIAN) ) {
838 my $exit = CORE::system("gzip -t $bot_state_dir/debian/$_");
841 &status("debian: unlinking file => $_");
842 unlink "$bot_state_dir/debian/$_";
846 # compress logs that should have been compressed.
847 # todo: use strftime?
848 my ($day,$month,$year) = (gmtime(time()))[3,4,5];
849 my $date = sprintf("%04d%02d%02d",$year+1900,$month+1,$day);
851 if (!opendir(DIR,"$bot_log_dir")) {
852 &ERROR("misccheck2: log dir $bot_log_dir does not exist.");
857 while (my $f = readdir(DIR)) {
858 next unless ( -f "$bot_log_dir/$f");
859 next if ($f =~ /gz|bz2/);
860 next unless ($f =~ /(\d{8})/);
861 next if ($date eq $1);
863 &compress("$bot_log_dir/$f");
868 ### this is semi-scheduled
870 if ($ident eq $param{'ircNick'}) {
871 &status("okay, got my nick back.");
876 &ScheduleThis(30, "getNickInUse");
877 return if ($_[0] eq "2"); # defer.
880 &nick( $param{'ircNick'} );
884 return if (!defined &uptimeWriteFile);
885 # return unless &IsChanConf("uptime");
888 &ScheduleThis(60, "uptimeLoop");
889 return if ($_[0] eq "2"); # defer.
898 &ScheduleThis(60, "slashdotLoop");
899 return if ($_[0] eq "2");
902 my @chans = &ChanConfList("slashdotAnnounce");
903 return unless (scalar @chans);
905 &Forker("slashdot", sub {
906 my $line = &Slashdot::slashdotAnnounce();
907 return unless (defined $line);
910 next unless (&::validChan($_));
912 &::status("sending slashdot update to $_.");
913 ¬ice($_, "Slashdot: $line");
921 &ScheduleThis(60, "plugLoop");
922 return if ($_[0] eq "2");
925 my @chans = &ChanConfList("plugAnnounce");
926 return unless (scalar @chans);
928 &Forker("plug", sub {
929 my $line = &Plug::plugAnnounce();
930 return unless (defined $line);
933 next unless (&::validChan($_));
935 &::status("sending plug update to $_.");
936 ¬ice($_, "Plug: $line");
943 &ScheduleThis(60, "freshmeatLoop");
944 return if ($_[0] eq "2");
947 my @chans = &ChanConfList("freshmeatAnnounce");
948 return unless (scalar @chans);
950 &Forker("freshmeat", sub {
951 my $data = &Freshmeat::freshmeatAnnounce();
954 next unless (&::validChan($_));
956 &::status("sending freshmeat update to $_.");
964 &ScheduleThis(240, "kernelLoop");
965 return if ($_[0] eq "2");
968 my @chans = &ChanConfList("kernelAnnounce");
969 return unless (scalar @chans);
971 &Forker("kernel", sub {
972 my @data = &Kernel::kernelAnnounce();
975 next unless (&::validChan($_));
977 &::status("sending kernel update to $_.");
980 ¬ice($c, "Kernel: $_");
987 return unless &IsChanConf("wingate");
989 ### FILE CACHE OF OFFENDING WINGATES.
990 foreach (grep /^$host$/, @wingateBad) {
991 &status("Wingate: RUNNING ON $host BY $who");
992 &ban("*!*\@$host", "") if &IsChanConf("wingateBan");
994 my $reason = &getChanConf("wingateKick");
996 next unless ($reason);
997 &kick($who, "", $reason)
1000 ### RUN CACHE OF TRIED WINGATES.
1001 if (grep /^$host$/, @wingateCache) {
1002 push(@wingateNow, $host); # per run.
1003 push(@wingateCache, $host); # cache per run.
1005 &DEBUG("Already scanned $host. good.");
1008 my $interval = &getChanConfDefault("wingateInterval", 60); # seconds.
1009 return if (defined $forked{'wingate'});
1010 return if (time() - $wingaterun <= $interval);
1011 return unless (scalar(keys %wingateToDo));
1013 $wingaterun = time();
1015 &Forker("wingate", sub { &Wingate::Wingates(keys %wingateToDo); } );
1020 sub wingateWriteFile {
1022 &ScheduleThis(60, "wingateWriteFile");
1023 return if ($_[0] eq "2"); # defer.
1026 return unless (scalar @wingateCache);
1028 my $file = "$bot_base_dir/$param{'ircUser'}.wingate";
1029 if ($bot_pid != $$) {
1030 &DEBUG("wingateWriteFile: Reorganising!");
1035 push(@wingateNow, $_);
1040 my %hash = map { $_ => 1 } @wingateNow;
1041 @wingateNow = sort keys %hash;
1044 &DEBUG("wingateWF: writing...");
1045 open(OUT, ">$file");
1046 foreach (@wingateNow) {
1054 &ScheduleThis(720, "factoidCheck");
1055 return if ($_[0] eq "2"); # defer.
1058 my @list = &searchTable("factoids", "factoid_key", "factoid_key", " #DEL#");
1059 my $stale = &getChanConfDefault("factoidDeleteDelay", 14) *60*60*24;
1061 # disable it since it's "illegal".
1068 my $age = &getFactInfo($_, "modified_time");
1070 if (!defined $age or $age !~ /^\d+$/) {
1071 if (scalar @list > 50) {
1072 if (!$cache{warnDel}) {
1073 &WARN("list is over 50 (".scalar(@list)."... giving it a miss.");
1074 $cache{warnDel} = 1;
1079 &WARN("del factoid: old cruft (no time): $_");
1084 next unless ($time - $age > $stale);
1087 $fix =~ s/ #DEL#$//g;
1088 my $agestr = &Time2String($time - $age);
1089 &status("safedel: Removing '$_' for good. [$agestr old]");
1096 return unless (scalar keys %{ $dcc{CHAT} });
1099 &ScheduleThis(10, "dccStatus");
1100 return if ($_[0] eq "2"); # defer.
1103 my $time = strftime("%H:%M", gmtime(time()) );
1106 foreach (keys %channels) {
1108 my $users = keys %{ $channels{$c}{''} };
1109 my $chops = keys %{ $channels{$c}{o} };
1110 my $bans = keys %{ $channels{$c}{b} };
1112 my $txt = "[$time] $c: $users members ($chops chops), $bans bans";
1113 foreach (keys %{ $dcc{'CHAT'} }) {
1114 next unless (exists $channels{$c}{''}{lc $_});
1115 $conn->privmsg($dcc{'CHAT'}{$_}, $txt);
1128 foreach (keys %{ $irc->{_queue} }) {
1132 foreach (keys %sched) {
1133 next unless ($q eq $sched{$_});
1138 my $time = $irc->{_queue}->{$q}->[0] - time();
1140 if (defined $sched) {
1141 &DEBUG(" $sched($q): ".&Time2String($time) );
1143 &DEBUG(" NULL($q): ".&Time2String($time) );
1147 &DEBUG("end of sList.");
1151 my($file, $time) = @_;
1155 &VERB("mkB: file '$file' does not exist.",2);
1160 if ( -e "$file~" ) {
1161 $backup++ if ((stat $file)[9] - (stat "$file~")[9] > $time);
1162 my $delta = time() - (stat "$file~")[9];
1163 $age = &Time2String($delta);
1168 return unless ($backup);
1170 ### TODO: do internal copying.
1171 &status("Backup: $file ($age)");
1172 CORE::system("/bin/cp $file $file~");