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),
25 &VERB( 'Starting schedulers...', 2 );
34 &leakCheck(2); # mandatory
36 &miscCheck2(2); # mandatory
41 &factoidCheck(2); # takes a couple of seconds on a 486. defer it
43 # TODO: convert to new format... or nuke altogether.
47 # 1 for run straight away
51 &netsplitCheck(1); # mandatory
52 &floodLoop(1); # mandatory
53 &ignoreCheck(1); # mandatory
54 &miscCheck(1); # mandatory
55 &shmFlush(1); # mandatory
57 &ircCheck(1); # mandatory
59 # TODO: squeeze this into a one-liner.
60 # my $count = map { exists $sched{$_}{TIME} } keys %sched;
62 foreach ( keys %sched ) {
63 my $time = $sched{$_}{TIME};
64 next unless ( defined $time and $time > time() );
69 &status("Schedulers: $count will be running.");
74 my ( $interval, $codename, @args ) = @_;
76 # Set to supllied value plus a random 0-60 seconds to avoid simultaneous runs
78 &getRandomInt( "$interval-" . ( $interval + &getRandomInt(60) ) );
80 if ( !defined $waittime ) {
81 &WARN("interval == waittime == UNDEF for $codename.");
85 my $time = $sched{$codename}{TIME};
86 if ( defined $time and $time > time() ) {
87 &WARN( "Sched for $codename already exists in "
88 . &Time2String( time() - $time )
94 "Scheduling \&$codename() "
95 . \&$codename . ' for '
96 . &Time2String($waittime),
100 my $retval = $conn->schedule( $waittime, \&$codename, @args );
101 $sched{$codename}{LABEL} = $retval;
102 $sched{$codename}{TIME} = time() + $waittime;
103 $sched{$codename}{LOOP} = 1;
107 #### LET THE FUN BEGIN.
111 my $interval = $param{'rssFeedTime'} || 30;
113 &ScheduleThis( $interval * 60, 'rssFeeds' ); # minutes
114 return if ( $_[0] eq '2' ); # defer.
119 my $line = &RSSFeeds::RSS();
120 return unless ( defined $line );
127 my $interval = &getChanConfDefault( 'randomQuoteInterval', 60, $chan );
129 &ScheduleThis( $interval * 60, 'randomQuote' ); # every hour
130 return if ( $_[0] eq '2' ); # defer.
133 foreach ( &ChanConfList('randomQuote') ) {
134 next unless ( &validChan($_) );
137 &getRandomLineFromFile( $bot_data_dir . '/infobot.randtext' );
138 if ( !defined $line ) {
139 &ERROR('random Quote: weird error?');
143 &status("sending random Quote to $_.");
144 &action( $_, 'Ponders: ' . $line );
146 ### TODO: if there were no channels, don't reschedule until channel
147 ### configuration is modified.
154 my $interval = &getChanConfDefault( 'randomFactoidInterval', 60, $chan );
156 &ScheduleThis( $interval * 60, 'randomFactoid' ); # minutes
157 return if ( $_[0] eq '2' ); # defer.
160 foreach ( &ChanConfList('randomFactoid') ) {
161 next unless ( &validChan($_) );
163 &status("sending random Factoid to $_.");
166 &randKey( 'factoids', 'factoid_key,factoid_value' );
167 &DEBUG("rF: $key, $val");
168 ### $val =~ tr/^[A-Z]/[a-z]/; # blah is Good => blah is good.
170 if ( ( defined $val )
172 and ( $key !~ /\#DEL\#/ )
173 and ( $key !~ /^cmd:/ ) );
177 &ERROR('rF: tried 5 times but failed.');
181 &action( $_, "Thinks: \037$key\037 is $val" );
182 ### FIXME: Use &getReply() on above to format factoid properly?
189 &ScheduleThis( 3600, 'logLoop' ); # 1 hour
190 return if ( $_[0] eq '2' ); # defer.
193 return unless ( defined fileno LOG );
194 return unless ( &IsParam('logfile') );
195 return unless ( &IsParam('maxLogSize') );
197 ### check if current size is too large.
198 if ( -s $file{log} > $param{'maxLogSize'} ) {
199 my $date = sprintf( '%04d%02d%02d', (gmtime)[ 5, 4, 3 ] );
200 $file{log} = $param{'logfile'} . '-' . $date;
201 &status('cycling log file.');
203 if ( -e $file{log} ) {
207 $newlog = $file{log} . '-' . $i;
208 last if ( !-e $newlog );
211 $file{log} = $newlog;
215 CORE::system("/bin/mv '$param{'logfile'}' '$file{log}'");
216 &compress( $file{log} );
218 &status('cycling log file.');
221 ### check if all the logs exceed size.
222 if ( !opendir( LOGS, $bot_log_dir ) ) {
223 &WARN("logLoop: could not open dir '$bot_log_dir'");
229 while ( defined( $_ = readdir LOGS ) ) {
230 my $logfile = "$bot_log_dir/$_";
232 next unless ( -f $logfile );
234 my $size = -s $logfile;
235 my $age = ( stat $logfile )[9];
236 $age{$age} = $logfile;
237 $size{$logfile} = $size;
243 while ( $tsize > $param{'maxLogSize'} ) {
244 &status("LOG: current size > max ($tsize > $param{'maxLogSize'})");
245 my $oldest = ( sort { $a <=> $b } keys %age )[0];
246 &status("LOG: unlinking $age{$oldest}.");
247 unlink $age{$oldest};
252 ### TODO: add how many b,kb,mb removed?
253 &status("LOG: removed $delete logs.") if ($delete);
258 &ScheduleThis( 86400, 'seenFlushOld' ); # 1 day
259 return if ( $_[0] eq '2' ); # defer.
262 # is this global-only?
263 return unless ( &IsChanConf('seen') > 0 );
264 return unless ( &IsChanConf('seenFlushInterval') > 0 );
266 # global setting. does not make sense for per-channel.
268 &getChanConfDefault( 'seenMaxDays', 30, $chan ) * 60 * 60 * 24;
271 if ( $param{'DBType'} =~ /^(pgsql|mysql|sqlite(2)?)$/i ) {
274 if ( $param{'DBType'} =~ /^mysql$/i ) {
276 'SELECT nick,time FROM seen GROUP BY nick HAVING '
277 . "UNIX_TIMESTAMP() - time > $max_time";
279 elsif ( $param{'DBType'} =~ /^sqlite(2)?$/i ) {
281 'SELECT nick,time FROM seen GROUP BY nick HAVING '
282 . "strftime('%s','now','localtime') - time > $max_time";
286 'SELECT nick,time FROM seen WHERE '
287 . "extract(epoch from timestamp 'now') - time > $max_time";
290 my $sth = $dbh->prepare($query);
291 if ( $sth->execute ) {
292 while ( my @row = $sth->fetchrow_array ) {
293 my ( $nick, $time ) = @row;
295 &sqlDelete( 'seen', { nick => $nick } );
302 &FIXME( 'seenFlushOld: for bad DBType:' . $param{'DBType'} . '.' );
304 &VERB( "SEEN deleted $delete seen entries.", 2 );
310 &ScheduleThis( 3600, 'newsFlush' ); # 1 hour
311 return if ( $_[0] eq '2' ); # defer.
314 if ( !&ChanConfList('News') ) {
315 &DEBUG("newsFlush: news disabled? (chan => $chan)");
322 foreach $chan ( keys %::news ) {
324 my $total = scalar( keys %{ $::news{$chan} } );
327 delete $::news{$chan};
331 foreach $item ( keys %{ $::news{$chan} } ) {
332 my $t = $::news{$chan}{$item}{Expire};
334 my $tadd = $::news{$chan}{$item}{Time};
335 $oldest = $tadd if ( $oldest > $tadd );
337 next if ( $t == 0 or $t == -1 );
340 "newsFlush: Fixed Expire time for $chan/$item, should not happen anyway."
342 $::news{$chan}{$item}{Expire} = time() + $t * 60 * 60 * 24;
346 my $delta = $t - time();
348 next unless ( time() > $t );
350 # TODO: show how old it was.
351 delete $::news{$chan}{$item};
352 &status("NEWS: (newsflush) deleted '$item'");
357 &status("NEWS (newsflush) {$chan}: deleted [$i/$total] news entries.")
359 $none{$chan} = 1 if ( $total == $i );
362 # TODO: flush users aswell.
364 foreach $chan ( keys %::newsuser ) {
365 next if ( exists $none{$chan} );
367 foreach ( keys %{ $::newsuser{$chan} } ) {
368 my $t = $::newsuser{$chan}{$_};
369 if ( !defined $t or ( $t > 2 and $t < 1000 ) ) {
370 &DEBUG("something wrong with newsuser{$chan}{$_} => $t");
374 next unless ( $oldest > $t );
376 delete $::newsuser{$chan}{$_};
380 my $i = scalar( keys %{ $::newsuser{$chan} } );
381 delete $::newsuser{$chan} unless ($i);
384 if ( $delete or $duser ) {
385 &status("NewsFlush: deleted: $delete news entries; $duser user cache.");
390 my $interval = &getChanConfDefault( 'chanlimitcheckInterval', 10, $chan );
391 my $mynick = $conn->nick();
394 &ScheduleThis( $interval * 60, 'chanlimitCheck' ); # default 10 minutes
395 return if ( $_[0] eq '2' );
398 my $str = join( ' ', &ChanConfList('chanlimitcheck') );
400 foreach $chan ( &ChanConfList('chanlimitcheck') ) {
401 next unless ( &validChan($chan) );
403 if ( $chan eq '_default' ) {
404 &WARN("chanlimit: we're doing $chan!! HELP ME!");
408 my $limitplus = &getChanConfDefault( 'chanlimitcheckPlus', 5, $chan );
409 my $newlimit = scalar( keys %{ $channels{$chan}{''} } ) + $limitplus;
410 my $limit = $channels{$chan}{'l'};
412 if ( scalar keys %netsplitservers ) {
413 if ( defined $limit ) {
414 &status("chanlimit: netsplit; removing it for $chan.");
415 $conn->mode( $chan, '-l' );
416 $cache{chanlimitChange}{$chan} = time();
417 &status('chanlimit: netsplit; removed.');
423 if ( defined $limit and scalar keys %{ $channels{$chan}{''} } > $limit )
425 &FIXME('LIMIT: set too low!!!');
426 ### run NAMES again and flush it.
429 if ( defined $limit and $limit == $newlimit ) {
430 $cache{chanlimitChange}{$chan} = time();
434 if ( !exists $channels{$chan}{'o'}{$mynick} ) {
435 &status("chanlimit: dont have ops on $chan.")
436 unless ( exists $cache{warn}{chanlimit}{$chan} );
437 $cache{warn}{chanlimit}{$chan} = 1;
438 &chanServCheck($chan);
441 delete $cache{warn}{chanlimit}{$chan};
443 if ( !defined $limit ) {
445 "chanlimit: $chan: setting for first time or from netsplit.");
448 if ( exists $cache{chanlimitChange}{$chan} ) {
449 my $delta = time() - $cache{chanlimitChange}{$chan};
450 if ( $delta < $interval * 60 ) {
452 "chanlimit: not going to change chanlimit! ($delta<$interval*60)"
458 $conn->mode( $chan, '+l', $newlimit );
459 $cache{chanlimitChange}{$chan} = time();
467 &ScheduleThis( 300, 'netsplitCheck' ); # every 5 minutes
468 return if ( $_[0] eq '2' );
471 $cache{'netsplitCache'}++;
473 # &DEBUG("running netsplitCheck... $cache{netsplitCache}");
475 if ( !scalar %netsplit and scalar %netsplitservers ) {
476 &DEBUG('nsC: !hash netsplit but hash netsplitservers <- removing!');
477 undef %netsplitservers;
481 # well... this shouldn't happen since %netsplit code does it anyway.
482 foreach $s1 ( keys %netsplitservers ) {
484 foreach $s2 ( keys %{ $netsplitservers{$s1} } ) {
485 my $delta = time() - $netsplitservers{$s1}{$s2};
487 if ( $delta > 60 * 30 ) {
488 &status("netsplit between $s1 and $s2 appears to be stale.");
489 delete $netsplitservers{$s1}{$s2};
494 my $i = scalar( keys %{ $netsplitservers{$s1} } );
495 delete $netsplitservers{$s1} unless ($i);
498 # %netsplit hash checker.
499 my $count = scalar keys %netsplit;
501 foreach ( keys %netsplit ) {
502 if ( &IsNickInAnyChan($_) ) { # why would this happen?
504 # &DEBUG("nsC: $_ is in some chan; removing from netsplit list.");
505 delete $netsplit{$_};
510 next unless ( time() - $netsplit{$_} > 60 * 15 );
513 delete $netsplit{$_};
517 # FIXED: $ch should be used rather than $chan since it creates NULL channels in the hash
518 foreach my $ch ( keys %channels ) {
519 my $i = $cache{maxpeeps}{$ch} || 0;
520 my $j = scalar( keys %{ $channels{$ch} } );
521 next unless ( $i > 10 and 0.25 * $i > $j );
523 &DEBUG("netsplit: 0.25*max($i) > current($j); possible netsplit?");
527 my $j = scalar( keys %netsplit );
528 &status("nsC: removed from netsplit list: (before: $count; after: $j)");
531 if ( !scalar %netsplit and scalar %netsplitservers ) {
532 &DEBUG('nsC: ok hash netsplit is NULL; purging hash netsplitservers');
533 undef %netsplitservers;
536 if ( $count and !scalar keys %netsplit ) {
537 &DEBUG('nsC: netsplit is hopefully gone. reinstating chanlimit check.');
547 &ScheduleThis( 60, 'floodLoop' ); # 1 minute
548 return if ( $_[0] eq '2' );
552 my $interval = &getChanConfDefault( 'floodCycle', 60, $chan );
554 foreach $who ( keys %flood ) {
555 foreach ( keys %{ $flood{$who} } ) {
556 if ( !exists $flood{$who}{$_} ) {
557 &WARN("flood{$who}{$_} undefined?");
561 if ( $time - $flood{$who}{$_} > $interval ) {
562 delete $flood{$who}{$_};
567 &VERB( "floodLoop: deleted $delete items.", 2 );
572 my $interval = &getChanConfDefault( 'seenFlushInterval', 60, $chan );
573 &ScheduleThis( $interval * 60, 'seenFlush' ); # minutes
574 return if ( $_[0] eq '2' );
580 $stats{'count_old'} = &countKeys('seen') || 0;
584 if ( $param{'DBType'} =~ /^(mysql|pgsql|sqlite(2)?)$/i ) {
585 foreach $nick ( keys %seencache ) {
586 my $retval = &sqlSet(
588 { 'nick' => lc $seencache{$nick}{'nick'} },
590 time => $seencache{$nick}{'time'},
591 host => $seencache{$nick}{'host'},
592 channel => $seencache{$nick}{'chan'},
593 message => $seencache{$nick}{'msg'},
597 delete $seencache{$nick};
602 &DEBUG('seenFlush: NO VALID FACTOID SUPPORT?');
605 &status("Seen: Flushed $flushed entries.") if ($flushed);
608 ' new seen: %03.01f%% (%d/%d)',
609 $stats{'new'} * 100 / ( $stats{'count_old'} || 1 ),
611 ( $stats{'count_old'} || 1 )
614 ) if ( $stats{'new'} );
617 ' now seen: %3.1f%% (%d/%d)',
618 $stats{'old'} * 100 / ( &countKeys('seen') || 1 ), $stats{'old'},
622 ) if ( $stats{'old'} );
624 &WARN('scalar keys seenflush != 0!') if ( scalar keys %seenflush );
628 my ( $blah1, $blah2 );
632 &ScheduleThis( 14400, 'leakCheck' ); # every 4 hours
633 return if ( $_[0] eq '2' );
636 # flood. this is dealt with in floodLoop()
637 foreach $blah1 ( keys %flood ) {
638 foreach $blah2 ( keys %{ $flood{$blah1} } ) {
639 $count += scalar( keys %{ $flood{$blah1}{$blah2} } );
642 &VERB( "leak: hash flood has $count total keys.", 2 );
646 foreach $blah1 ( keys %floodjoin ) {
647 foreach $blah2 ( keys %{ $floodjoin{$blah1} } ) {
648 $count += scalar( keys %{ $floodjoin{$blah1}{$blah2} } );
651 &VERB( "leak: hash floodjoin has $count total keys.", 2 );
654 $count = scalar( keys %floodwarn );
655 &VERB( "leak: hash floodwarn has $count total keys.", 2 );
658 foreach $chan ( grep /[A-Z]/, keys %channels ) {
659 &DEBUG("leak: chan => '$chan'.");
661 foreach $i ( keys %{ $channels{$chan} } ) {
662 foreach ( keys %{ $channels{$chan}{$i} } ) {
663 &DEBUG("leak: \$channels{$chan}{$i}{$_} ...");
669 $count = scalar( keys %chanstats );
670 &VERB( "leak: hash chanstats has $count total keys.", 2 );
674 foreach ( keys %nuh ) {
675 next if ( &IsNickInAnyChan($_) );
676 next if ( exists $dcc{CHAT}{$_} );
683 "leak: $delete nuh{} items deleted; now have " . scalar( keys %nuh ) )
689 &ScheduleThis( 60, 'ignoreCheck' ); # once every minute
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( 300, 'ircCheck' ); # every 5 minutes
718 return if ( $_[0] eq '2' ); # defer.
721 $cache{statusSafe} = 1;
722 foreach ( sort keys %conns ) {
724 my $mynick = $conn->nick();
725 &DEBUG("ircCheck for $_");
726 # Display with min of 900sec delay between redisplay
727 # FIXME: should only use 900sec when we are on the LAST %conns
728 my @join = &getJoinChans(900);
729 if ( scalar @join ) {
730 &FIXME( 'ircCheck: found channels to join! ' . join( ',', @join ) );
734 # TODO: fix on_disconnect()
736 if ( time() - $msgtime > 3600 ) {
738 # TODO: shouldn't we use cache{connect} somewhere?
739 if ( exists $cache{connect} ) {
740 &WARN("ircCheck: no msg for 3600 and disco'd! reconnecting!");
741 $msgtime = time(); # just in case.
743 delete $cache{connect};
746 &status( 'ircCheck: possible lost in space; checking.'
748 &msg( $mynick, 'TEST' );
749 $cache{connect} = time();
754 if ( grep /^\s*$/, keys %channels ) {
755 &WARN('ircCheck: we have a NULL chan in hash channels? removing!');
756 if ( !exists $channels{''} ) {
757 &DEBUG('ircCheck: this should never happen!');
760 if ( $ident !~ /^\Q$param{ircNick}\E$/ ) {
762 # this does not work unfortunately.
763 &WARN("ircCheck: ident($ident) != param{ircNick}($param{ircNick}).");
765 # this check is misleading... perhaps we should do a notify.
766 if ( !&IsNickInAnyChan( $param{ircNick} ) ) {
767 &DEBUG("$param{ircNick} not in use... changing!");
768 &nick( $param{ircNick} );
771 &WARN("$param{ircNick} is still in use...");
775 $cache{statusSafe} = 0;
778 if ( $utime_userfile > $wtime_userfile and time() - $wtime_userfile > 3600 )
781 $wtime_userfile = time();
784 if ( $utime_chanfile > $wtime_chanfile and time() - $wtime_chanfile > 3600 )
787 $wtime_chanfile = time();
793 &ScheduleThis( 7200, 'miscCheck' ); # every 2 hours
794 return if ( $_[0] eq '2' ); # defer.
799 if ( -x '/usr/bin/ipcs' ) {
800 @ipcs = `/usr/bin/ipcs`;
803 &WARN("ircCheck: no 'ipcs' binary.");
807 # make backup of important files.
808 &mkBackup( $bot_state_dir . '/infobot.chan', 60 * 60 * 24 * 3 );
809 &mkBackup( $bot_state_dir . '/infobot.users', 60 * 60 * 24 * 3 );
810 &mkBackup( $bot_base_dir . '/infobot-news.txt', 60 * 60 * 24 * 1 );
812 # flush cache{lobotomy}
813 foreach ( keys %{ $cache{lobotomy} } ) {
814 next unless ( time() - $cache{lobotomy}{$_} > 60 * 60 );
815 delete $cache{lobotomy}{$_};
818 ### check modules if they've been modified. might be evil.
821 # shmid stale remove.
825 # key, shmid, owner, perms, bytes, nattch
826 next unless (/^(0x\d+) (\d+)\s+(\S+)\s+(\d+)\s+(\d+)\s+/);
828 my ( $shmid, $size ) = ( $2, $5 );
829 next unless ( $shmid != $shm and $size == 2000 );
830 my $z = &shmRead($shmid);
831 if ( $z =~ /^(\S+):(\d+):(\d+): / ) {
835 next if ( time() - $time < 60 * 60 );
837 # FIXME remove not-pid shm if parent process dead
838 next if ( $pid == $bot_pid );
840 # don't touch other bots, if they're running.
841 next unless ( $param{ircUser} =~ /^\Q$n\E$/ );
844 &DEBUG("shm: $shmid is not ours or old infobot => ($z)");
848 &status("SHM: nuking shmid $shmid");
849 CORE::system("/usr/bin/ipcrm shm $shmid >/dev/null");
855 &ScheduleThis( 14400, 'miscCheck2' ); # every 4 hours
856 return if ( $_[0] eq '2' ); # defer.
860 opendir( DEBIAN, "$bot_state_dir/debian" );
861 foreach ( grep /gz$/, readdir(DEBIAN) ) {
862 my $exit = CORE::system("gzip -t $bot_state_dir/debian/$_");
865 &status("debian: unlinking file => $_");
866 unlink "$bot_state_dir/debian/$_";
870 # compress logs that should have been compressed.
871 # TODO: use strftime?
872 my ( $day, $month, $year ) = ( gmtime( time() ) )[ 3, 4, 5 ];
873 my $date = sprintf( '%04d%02d%02d', $year + 1900, $month + 1, $day );
875 if ( !opendir( DIR, "$bot_log_dir" ) ) {
876 &ERROR("misccheck2: log dir $bot_log_dir does not exist.");
881 while ( my $f = readdir(DIR) ) {
882 next unless ( -f "$bot_log_dir/$f" );
883 next if ( $f =~ /gz|bz2/ );
884 next unless ( $f =~ /(\d{8})/ );
885 next if ( $date eq $1 );
887 &compress("$bot_log_dir/$f");
892 ### this is semi-scheduled
895 # FIXME: broken for multiple connects
896 # if ($ident eq $param{'ircNick'}) {
897 # &status('okay, got my nick back.');
902 # &ScheduleThis(30, 'getNickInUse');
903 # return if ($_[0] eq '2'); # defer.
906 # &nick( $param{'ircNick'} );
910 return if ( !defined &uptimeWriteFile );
912 # return unless &IsParam('Uptime');
915 &ScheduleThis( 3600, 'uptimeLoop' ); # once per hour
916 return if ( $_[0] eq '2' ); # defer.
925 &ScheduleThis( 3600, 'slashdotLoop' ); # once per hour
926 return if ( $_[0] eq '2' );
929 my @chans = &ChanConfList('slashdotAnnounce');
930 return unless ( scalar @chans );
935 my $line = &Slashdot::slashdotAnnounce();
936 return unless ( defined $line );
939 next unless ( &::validChan($_) );
941 &::status("sending slashdot update to $_.");
942 ¬ice( $_, "Slashdot: $line" );
951 &ScheduleThis( 3600, 'plugLoop' ); # once per hour
952 return if ( $_[0] eq '2' );
955 my @chans = &ChanConfList('plugAnnounce');
956 return unless ( scalar @chans );
961 my $line = &Plug::plugAnnounce();
962 return unless ( defined $line );
965 next unless ( &::validChan($_) );
967 &::status("sending plug update to $_.");
968 ¬ice( $_, "Plug: $line" );
976 &ScheduleThis( 14400, 'kernelLoop' ); # once every 4 hours
977 return if ( $_[0] eq '2' );
980 my @chans = &ChanConfList('kernelAnnounce');
981 return unless ( scalar @chans );
986 my @data = &Kernel::kernelAnnounce();
989 next unless ( &::validChan($_) );
991 &::status("sending kernel update to $_.");
994 ¬ice( $c, "Kernel: $_" );
1002 return unless &IsChanConf('Wingate') > 0;
1004 ### FILE CACHE OF OFFENDING WINGATES.
1005 foreach ( grep /^$host$/, @wingateBad ) {
1006 &status("Wingate: RUNNING ON $host BY $who");
1007 &ban( "*!*\@$host", '' ) if &IsChanConf('wingateBan') > 0;
1009 my $reason = &getChanConf('wingateKick');
1011 next unless ($reason);
1012 &kick( $who, '', $reason );
1015 ### RUN CACHE OF TRIED WINGATES.
1016 if ( grep /^$host$/, @wingateCache ) {
1017 push( @wingateNow, $host ); # per run.
1018 push( @wingateCache, $host ); # cache per run.
1021 &DEBUG("Already scanned $host. good.");
1025 &getChanConfDefault( 'wingateInterval', 60, $chan ); # seconds.
1026 return if ( defined $forked{'Wingate'} );
1027 return if ( time() - $wingaterun <= $interval );
1028 return unless ( scalar( keys %wingateToDo ) );
1030 $wingaterun = time();
1032 &Forker( 'Wingate', sub { &Wingate::Wingates( keys %wingateToDo ); } );
1037 sub wingateWriteFile {
1039 &ScheduleThis( 3600, 'wingateWriteFile' ); # once per hour
1040 return if ( $_[0] eq '2' ); # defer.
1043 return unless ( scalar @wingateCache );
1045 my $file = "$bot_base_dir/$param{'ircUser'}.wingate";
1046 if ( $bot_pid != $$ ) {
1047 &DEBUG('wingateWriteFile: Reorganising!');
1052 push( @wingateNow, $_ );
1057 my %hash = map { $_ => 1 } @wingateNow;
1058 @wingateNow = sort keys %hash;
1061 &DEBUG('wingateWF: writing...');
1062 open( OUT, ">$file" );
1063 foreach (@wingateNow) {
1071 &ScheduleThis( 43200, 'factoidCheck' ); # ever 12 hours
1072 return if ( $_[0] eq '2' ); # defer.
1076 &searchTable( 'factoids', 'factoid_key', 'factoid_key', ' #DEL#' );
1078 &getChanConfDefault( 'factoidDeleteDelay', 14, $chan ) * 60 * 60 * 24;
1081 # disable it since it's 'illegal'.
1088 my $age = &getFactInfo( $_, 'modified_time' );
1090 if ( !defined $age or $age !~ /^\d+$/ ) {
1091 if ( scalar @list > 50 ) {
1092 if ( !$cache{warnDel} ) {
1093 &WARN( 'list is over 50 ('
1095 . '... giving it a miss.' );
1096 $cache{warnDel} = 1;
1101 &WARN("del factoid: old cruft (no time): $_");
1106 next unless ( $time - $age > $stale );
1109 $fix =~ s/ #DEL#$//g;
1110 my $agestr = &Time2String( $time - $age );
1111 &status("safedel: Removing '$_' for good. [$agestr old]");
1118 return unless ( scalar keys %{ $dcc{CHAT} } );
1121 &ScheduleThis( 600, 'dccStatus' ); # every 10 minutes
1122 return if ( $_[0] eq '2' ); # defer.
1125 my $time = strftime( '%H:%M', gmtime( time() ) );
1128 foreach ( keys %channels ) {
1130 my $users = keys %{ $channels{$c}{''} };
1131 my $chops = keys %{ $channels{$c}{o} };
1132 my $bans = keys %{ $channels{$c}{b} };
1134 my $txt = "[$time] $c: $users members ($chops chops), $bans bans";
1135 foreach ( keys %{ $dcc{'CHAT'} } ) {
1136 next unless ( exists $channels{$c}{''}{ lc $_ } );
1137 $conn->privmsg( $dcc{'CHAT'}{$_}, $txt );
1149 my $reply = 'sched:';
1150 foreach ( keys %{ $irc->{_queue} } ) {
1152 my $coderef = $irc->{_queue}->{$q}->[1];
1154 foreach ( keys %sched ) {
1156 next unless defined( \&$schedname );
1157 next unless ( $coderef eq \&$schedname );
1158 $sched = $schedname;
1162 my $time = $irc->{_queue}->{$q}->[0] - time();
1164 if ( defined $sched ) {
1165 $reply = "$reply, $sched($q):" . &Time2String($time);
1168 $reply = "$reply, NULL($q):" . &Time2String($time);
1176 my ( $file, $time ) = @_;
1180 &VERB( "mkB: file '$file' does not exist.", 2 );
1185 if ( -e "$file~" ) {
1186 $backup++ if ( ( stat $file )[9] - ( stat "$file~" )[9] > $time );
1187 my $delta = time() - ( stat "$file~" )[9];
1188 $age = &Time2String($delta);
1194 return unless ($backup);
1196 ### TODO: do internal copying.
1197 &status("Backup: $file ($age)");
1198 CORE::system("/bin/cp $file $file~");
1203 # vim:ts=4:sw=4:expandtab:tw=80