Thread script wird jede minute mehrmals gestartet?
(6 answers)
Opened by Trux at 2017-12-10 11:56
so, ich versuchs noch einmal mit dem posten des codes:
Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 #!/usr/bin/perl use Socket; use Time::Local; use Sys::Hostname; use Time::HiRes qw(sleep); use Unicode::String qw(latin1 utf8); use LWP::Simple; use IO::Handle; use URI::URL; use warnings; use threads; use Meteoalarm; open(DATEI, "channels.txt"); $diachans = <DATEI>; $diachans =~ s/##*/#/g; @channels = split(" ",$diachans); my $debug = 1; my $master = 'majo'; my $master2 = 'Master'; my $master3 = 'thom'; my $schan="#sys-thx"; $uptimer=time(); my %conf; $SIG{CHLD} = 'IGNORE'; my $hostname = Sys::Hostname::hostname(); my $nick = "ChannelWatcher"; my $pw = "27742774"; @joininfo=('ChannelWatcher - To Protect and Serve (c) 2017'); my ($remote, $local, $port, $iaddr, $paddr, $proto, $line, $myhost); my $nl = "\015\012"; # You should specify a default server in $remote $remote = shift || '127.0.0.1'; $local = "127.0.0.1"; $port = shift || 6669; my $uptimechan = shift || '#sys-thx'; my %chans; $chans{lc $uptimechan} = 1; if ($port =~ /\D/) { $port = getservbyname($port, 'tcp') } die "No port" unless $port; $iaddr = inet_aton($remote) || die "no host: $remote"; $paddr = sockaddr_in($port, $iaddr); $proto = getprotobyname('tcp'); if (not $debug) { exit if fork(); } close(STDIN) unless $debug; close(STDOUT) unless $debug; socket(IRC, PF_INET, SOCK_STREAM, $proto) || die "socket: $!"; bind(IRC, sockaddr_in(0, inet_aton($local))) unless $local == undef; connect(IRC, $paddr) || die "connect: $!"; #IRC->autoflush(1); { my $ofh = select(IRC); $|=1; select($ofh); } sub gracefully_die { my ($restarting) = @_; if ($restarting) { exec "perl sBot-restarter.pl"; } else { exit; } } ircsend("NICK $nick"); ircsend("USER Cygnus ServerBot $hostname :ServerAdmin / ServerBot"); #handle the first ping. #this one is really important to get right #b/c it is used by the server to make sure you're #not just spoofing (or using certain kinds of blind proxies) while(my $line = <IRC>) { print " >> $line" if $debug; if($line =~ /^PING :(\S+)/ || $line =~ /^PING\s*(\S*)/ || $line =~ /^PING/ || $line=~ /^PING \:(.*)/) { # if($line =~ /^PING\s*(\S*)/i) { ircsend("PONG :$1"); } # if server tells us we're logged in, break loop #els if($line =~ /(376|422) $nick/) { last; } } ircsend("NickServ IDENTIFY"); #timer do "timers.pl"; foreach(@channels){ my @channels=quotemeta($_); $_=utf8($_)->latin1; ircsend("JOIN $_"); privmsg($_, "@joininfo"); } #start the pingtimer and #set the handler for the #alarm signal as the pingtimer $SIG{ALRM} = \&pingtimer; # nee sigalrm alarm 60; irchandle(); #shouldn't ever get here, as irchandle becomes the main loop. close(IRC); sub ircsend { my $a = shift; $a=utf8($a)->latin1; print IRC $a, $nl; print " << ", $a, "\n" if $debug; } sub notice { my $user = shift; $x=utf8($x)->latin1; while(my $x=shift) { ircsend("NOTICE $user :$x");} } sub privmsg { my $user = shift; $x=utf8($x)->latin1; while(my $x=shift) { ircsend("PRIVMSG $user :$x");} } sub writeHash { my $hash = $_[0]; my $file = $_[1]; open HASH, ">$file"; my @keys = keys(%$hash); my @values = values(%$hash); for(my $i=0; $i<@keys; $i++) { if($values[$i][0]) { chomp $keys[$i]; print HASH $keys[$i], " =[ "; foreach my $atom (@{$values[$i]}) { print HASH $atom, ", "; } print HASH "\n"; } else { chomp $keys[$i]; chomp $values[$i]; print HASH $keys[$i], " = ", $values[$i], "\n"; } } close HASH; } sub readHash { my $file = $_[0]; my %hash; open HASH, $file; while(my $line = <HASH>) { if($line =~ / =\[ /) { my ($key, $value) = split(/ =\[ /, $line); chomp $key; chomp $value; $hash{$key} = [ split(/, /, $value) ]; } else { my ($key, $value) = split(/ = /, $line); chomp $key; chomp $value; $hash{$key} = $value; } } close HASH; return (%hash); } sub auth($) { my ($in) = @_; #$in =~ /^:(.+?)\s/; #my $ident = $1; my @ident = split(/\!|\@/, $in); foreach my $x (@auth) { my @x = split(/\!|\@/, $x); my $ok = 1; for(my $i=0; $i<@x; $i++) { if($x[$i] eq "*") { next; } elsif($x[$i] =~ /^\*(.*)/) { $ok=0 unless $ident[$i] =~ /$1$/i; } elsif($x[$i] =~ /(.*)\*$/) { $ok=0 unless $ident[$i] =~ /^$1/i; } else { $ok=0 unless lc $ident[$i] eq lc $x[$i]; } last unless $ok; } return 1 if $ok == 1; } return 0; } $start=time; ######################################### sub irchandle() { my $in = shift; LINE: while(my $in = <IRC>) { chomp $in; $in =~ s/\r//g; print " >> $in\n" if $debug; if ($in =~ /^PING \:(.*)/ || $in =~ /^PING :/) { ircsend("PONG :$1"); } if($in =~ /^:(.*?)!.* NICK :(\S+)/) { if($nick eq $1) { $nick = $2; } next; } $myhost = $1 if($in =~ /^:(\S+) 001 \Q$nick\E/); if($in =~ /:(.*?)!.*(PRIVMSG|NOTICE) $nick\s*:\001(\S+) (.*?)\001?$/i) { my ($user, $op, $msg) = ($1, $3, $4); notice($conf{"Debugger"}, $user, $msg) if $conf{"Debug"}; next LINE; } #diverse scripte do "subs.pl"; #Lastseen saving if($in =~ /:(.*?)!.* JOIN \s*:(.*)/i or $in =~ /:(.*?)!.* PART \s*(.*)/i or $in =~ /:(.*?)!.* QUIT \s*(.*)/i or $in =~ /:(.*?)!.* KICK \s*(.*)/i) { my ($juser, $jchan, $jmsg) = ($1, $2, $3); ($host,$statein,$bchan)=split(/ /,$in); lastseenup("$juser/$jchan/$statein/$host"); } #(#\S+)\s* channel #(.*) oder \s*(.*) user if($in =~ /:(.*?)!.*MODE (#\S+)\s* -o (.*)/i) { my ($user, $chan, $msg, $vict) = ($1, $2, $3, $4); #vict übergabe an script do "reopscript.pl"; } if($in =~ /:(.*?)!.* JOIN \s*:(.*)/i) { do "userstate.pl"; } #if($in =~ /311 $nick \s*(.*) (.*) (.*) :(.*)/i) { # my ($user, $msg, $vict, $reln) = ($1, $2, $3, $4); #vict übergabe an script #privmsg($schan, "[WhoisScript] >> Host $msg $vict"); # } if($in =~ /319 $nick \s*(.*) (.*)/i) { my ($user, $chan, $msg, $vict) = ($1, $2, $3, $4); #vict übergabe an script privmsg($lastchan, "[WhoisScript] >> Channels $user"); } #if($in =~ /312 $nick \s*(.*) (.*)/i) { save wegen zeichen if($in =~ /307 $nick \s*(.*) :(.*)/i) { my ($user, $vict) = ($1, $2, $3, $4); #vict übergabe an script $vict =~ s/is a registered nick/Yes/; privmsg($lastchan, "[WhoisScript] >> Registered? $vict"); } if($in =~ /378 $nick \s*(.*) :(.*)/i) { my ($user, $vict) = ($1, $2, $3, $4); #vict übergabe an script ($host,$statein,$bchan,$hos,$rip)=split(/ /,$vict); privmsg($lastchan, "[WhoisScript] >> Host $host $statein $bchan $hos"); privmsg($lastchan, "[WhoisScript] >> IP $rip"); } if($in =~ /353 $nick = (#\S+)\s* :(.*)/i) { my ($user, $vict) = ($1, $2, $3, $4); #vict übergabe an script if ($lastchan eq ""){ privmsg($schan, "[InfoScript] >> Channel: $user"); privmsg($schan, "[InfoScript] >> Users: $vict"); }else{ privmsg($lastchan, "[InfoScript] >> Channel: $user"); privmsg($lastchan, "[InfoScript] >> Users: $vict"); }} if($in =~ /:(.*?)!.* KICK (#\S+)\s*:(.*)/i) { my ($user, $chan, $msg) = ($1, $2, $3); privmsg($chan, "1.kick"); $kickcount=0; push(@kicked,$jldat[2]); foreach $_ (@kicked){ #if (lc($_) eq lc(@jldat[2])){ if (lc($_) eq lc($jldat[2])){ $kickcount++; privmsg($chan, "2.kick"); }} if ($kickcount == 3){ privmsg($chan, "Floodversuch erkannt! 3x gekickt nun Ban!"); ircsend("KICK $chan $_"); foreach $_ (@kicked){ #if (lc($_) ne lc(@jldat[2])){ if (lc($_) ne lc($jldat[2])){ push(@newkicked,$_); }} @kicked=@newkicked; @newkicked=(); }} ###badworderkennung ######################################################DIA######################################################################################## ############################################################################################################################################## $tes = '#sys-thx'; if($in =~ /:(.*?)!.*PRIVMSG $nick :(.*)/i) { $dia = 1; my ($diauser, $diatext, $msg) = ($1, $2, $3); if ($dia == 1){ privmsg($tes, "(DiaScript) >> ($diauser): $diatext "); } } ######################################################DIA ENDE######################################################################################## ############################################################################################################################################## if($in =~ /:(.*?)!.*PRIVMSG (#\S+)\s*:(.*)/i) { my ($user, $chan, $msg) = ($1, $2, $3); do "badwordscript.pl"; do "floodproscript.pl"; } if($in =~ /:(.*?)!.*PRIVMSG (#\S+)\s*:(.*)/i) { my ($user, $chan, $msg) = ($1, $2, $3); #print "$user, $chan, $msg"; #uscom do 'uscom.pl'; #zugangskontrolle do "zugangskontrolle.pl"; #datenbanken do "datenbanken.pl"; #switches do "switches.pl"; #newsletter #do "newsle.pl"; #versuchsscript #do "versuch.pl"; #normale channelcommands do "chacom.pl"; #wetterscript do "wetter.pl"; #load telegram modul do "telegr.pl"; ####Master-Admin-Befehle if(lc($user) eq lc($master) || lc($user) eq lc($master2)){ if (lc(substr($msg,0,6)) eq "!close" || lc(substr($msg,0,9)) eq "!shutdown" || lc(substr($msg,0,5)) eq "!kill" || lc(substr($msg,0,5)) eq "!quit"){ privmsg($chan, "(ShutDown-System) (Beende alle verbindungen...)"); die "closed by $user"; } if (lc(substr($msg,0,8)) eq "!restart" || lc(substr($msg,0,7)) eq "!reboot"){ privmsg($chan, "(Shutdown-System) (Bot startet neu!)"); sleep(1); privmsg($chan, "(Shutdown-System) (Beende alle aktiven Module...)"); do "sBot-restarter.pl"; die "closed by master"; } }#ende master if(($msg =~ /^lusers/i) or ($msg =~ /^!lusers/i)) { my $users = qx/users/; $users =~ s/\n//; $users = join(' ', unique(split(/ /, $users))); privmsg($chan, "Users logged onto $hostname: ".$users); next; } } # if($in =~ /:$myhost .*(PRIVMSG|NOTICE) $nick\s*:(.*)/i) { if($in =~ /:$remote .*(PRIVMSG|NOTICE) $nick\s*:(.*)/i) { my $msg = $2; } } gracefully_die(1); } sub writeArray { my $array = $_[0]; my $file = $_[1]; open ARRAY, ">$file"; foreach my $x (@$array) { print ARRAY $x . "\n"; } close ARRAY; } sub readArray { my $file = $_[0]; my @array; open ARRAY, $file; while(my $x = <ARRAY>) { chomp $x; push @array, $x; } close ARRAY; return (@array); } sub pingtimer { # nee sigalrm ircsend("PING :$remote"); alarm 60; } #we don't actually call this from anywhere #but the SCnet implementation seems to need #it to handle when the socket is closed on us #due to a kill. sub sigpipe { graceful_die(1); #if $child; } sub unique(@) { my (@input_array) = @_; my %seen; foreach my $item (@input_array) { $seen{$item}++; } #return sort(keys(%seen)); return map("$_($seen{$_})", sort(keys(%seen))); } undef $alv; undef $propthread; mal sehen ob es geklappt hat;) so und das hier ist das timer modul welches vermutlich die forks auslöst Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 #!/usr/bin/perl -w use LWP::Simple; use threads; my ($user, $chan, $msg) = ($1, $2, $3); #my $master = 'majo'; #my $master2 = 'Master'; #my $master3 = 'thom'; #my $time = localtime(time()); #my $clock1 = ''; my $pchan = "#sys-thx"; #my ($wtag,$monat,$tag,$alive,$jeahr)=split(/ /,$time); my $alv = threads->create(sub { &alive;}); my $propthread = threads->create(sub { &propaganda;}); my $aktthread = threads->create(sub { &akt;}); sub akt{ $alv=fork(); while ($alv==0){ sleep 1; if ($end > 2 *60){ foreach(@werb){ my @werb=quotemeta($_); ($delopch,$wer)=split(":",$_); } if ($wer eq "status"){ curtime(); privmsg($delopch, "virtuelle hilfskraft meldet: es ist $curt am $curd!"); } if ($wer eq "on"){ @tiscr = ('ich bin eure persönliche assistentin für den chat!', 'meine befehle kannst du unter !hilfe abrufen', 'party leute, party!!!!!'); privmsg($_, "$tiscr[rand @tiscr]"); } if ($wer eq "off"){ $alti=localtime(); print "-= ChannelWatcher ControlSystem - All systems working fine! $alti =-\n"; } $end=0; } $end++; } } sub alive(){ ret: sleep (10 *60); privmsg($pchan, "Alive Massage"); sleep(1); goto ret; } sub propaganda(){ red: sleep (39 *60); foreach(@channels){ my @channels=quotemeta($_); privmsg($_, "ChannelWatcher v3 out now! The new generation Channel-Control-Bot. For more Informations, contact the Projekt Manager 'majo' on channel '#sys-thx'!"); } sleep(1); goto red; } #privmsg($pchan, "Info: WerbeTest1"); ##$alti=localtime(); ##print "-= Sending Alive... - $alti =-\n"; #goto ret; Last edited: 2017-12-17 10:20:41 +0100 (CET) |