xecho -b Leech killer loaded. # todo # # Fix that if you enter a wrong server name it 'dies' # Add a way to back out of a failed run, call a cleanup or something # oddity: after a check, I whoised and got a "no users would be axed" and cleanup # loop through the list of servers, rather than gu * # Log names of users who are banned. While banning, look up each nick, # if they've been banned > 3 times, perminately ban them. # done # # fix leechstat stuff for levels 0-2 ** # for leechstat 0-2, make killmaxstat = 0 to indicate there was no killing ** # fix variables in leechstat so the don't interfere? ** # add checkserver and skipped to leechstat logging (and change mrtg to match) ** # clean up vars at ending timer ** # level 4, kill and tban for 24. Leech Ban: 5/22/02 14:20 Shared N files. ** # You might change these two variables. # minonlinetimetmp is minimum time online in minutes. # killmaxtmp is the maximum number of users killed at a time. # leechlog/leechusers are two log files for stats. # skipserver is a space-separated list of servers not to kill users on ^assign minonlinetimetmp 10 ^assign killmaxtmp 75 ^assign leechlog ~/.TekNap/leechstats.log ^assign leechusers ~/.TekNap/leechusers.log ^assign skipserver vip shadoe SpyderWeb green someserver someotherserver #^assign statustest2 04C1410[16%T10][15%h%N10]%A%D [%C:%c%+%W] %Q %H%B%F%G[%L][%5] # # Shouldn't need to fiddle around below here. # ^assign leechversion .5 ^assign leechkillrunning 0 ^alias leechkill (checkserver, minfilestmp, doittmp) { xecho -b leechkill ^assign skipcounter 0 ^assign cancelkill 0 ^assign -doit if ( killgoing ) { # The killing is on a 10 second delay after started, if called again we cancel the kills. timer -delete leechkill ^assign cancelkill 1 wall 10Leech 11kill10 has been canceled.-1 } if ( leechkillrunning ) { xecho -b 11Leech Killer loop is already running.-1 } { if ( checkserver == [] || minfilestmp == [] ) { xecho 11/leechkill server minfiles -1 to see how many leeches there are. xecho 11/leechkill server minfiles 1 -1will check and wallop the results. xecho 11/leechkill server minfiles 2 -1to warn them. xecho 11/leechkill server minfiles 3 -1to really kill them. xecho 11Example: /leechkill blackmoor 0 -1Will only tell you how many users are sharing 0 files on blackmoor. xecho 11Example: /leechkill blackmoor 5 1 -1Will only wallop to tell how many users sharing 5 or less files on server blackmoor. xecho 11Example: /leechkill * 15 2 -1Will only warn all users sharing 15 or less files on server blackmoor. xecho 11Example: /leechkill spikes 25 3 -1Will kill all users sharing 25 or less files on server spikes. xecho xecho 11To cancel a kill, just run /leechkill again within 10 seconds and it won't continue. xecho 11Online Time Minimum: $minonlinetimetmp Minutes. Max Kill: $killmaxtmp users. Version: $leechversion-1 } { # Based on the level, and if the killing is on a timer, we wall or echo, then call the killing code. xecho -b check doit if ( doittmp == [] ) ^assign doittmp 0 if ( doittmp == 0 ) { xecho -b 10Starting a 11$minfilestmp file10 leech 11check10 on 11${checkserver}10.-1 leechuserspre ^set status_user5 10Leech Check on 11$checkserver killemleech 0 $minfilestmp $minonlinetimetmp $killmaxtmp $checkserver } if ( doittmp == 1 ) { if ( !leechtimerrunning ) { wall 10Starting a 11$minfilestmp file10 leech 11check10 on 11${checkserver}10.-1 } { xecho -b 10Starting a 11$minfilestmp file10 leech 11check10 on 11${checkserver}10.-1 } leechuserspre ^set status_user5 10Leech Check on 11$checkserver killemleech $doittmp $minfilestmp $minonlinetimetmp $killmaxtmp $checkserver } if ( doittmp == 2 ) { if ( !leechtimerrunning ) { wall 10Starting a 11$minfilestmp file10 leech 11warn10 on 11${checkserver}10.-1 } { xecho -b 10Starting a 11$minfilestmp file10 leech 11warn10 on 11${checkserver}10.-1 } leechuserspre ^set status_user5 10Leech Wall Check on 11$checkserver killemleech $doittmp $minfilestmp $minonlinetimetmp $killmaxtmp $checkserver } if ( doittmp == 3 && !cancelkill ) { if ( !leechtimerrunning ) { wall 10Starting a 11$minfilestmp file10 leech 11kill10 on 11${checkserver}10 in 10 seconds.-1 } { xecho -b 10Starting a 11$minfilestmp file10 leech 11kill10 on 11${checkserver}10 in 10 seconds.-1 } ^assign killgoing 1 leechuserspre ^set status_user5 10Leech 07Kill 10on 11$checkserver timer -ref leechkill 10 killemleech $doittmp $minfilestmp $minonlinetimetmp $killmaxtmp $checkserver } if ( doittmp == 4 && !cancelkill ) { if ( !leechtimerrunning ) { wall 10Starting a 11$minfilestmp file10 leech 11kill/tban10 on 11${checkserver}10 in 10 seconds.-1 } { xecho -b 10Starting a 11$minfilestmp file10 leech 11kill/tban10 on 11${checkserver}10 in 10 seconds.-1 } ^assign killgoing 1 leechuserspre ^set status_user5 10Leech 07Kill/Ban10 on 11$checkserver timer -ref leechkill 10 killemleech $doittmp $minfilestmp $minonlinetimetmp $killmaxtmp $checkserver } # After the killing has started, reset the variables that allow us to cancel it. timer 12 @ killgoing = cancelkill = [] } } } ^alias killemleech (doittmp, minfilestmp, minonlinetimetmp, killmaxtmp, checkservertmp) { xecho killemleech: $doittmp $minfilestmp $minonlinetimetmp $killmaxtmp $checkservertmp # The actual alias that does the killing. ^assign doit $doittmp ^assign minfiles $minfilestmp ^assign minonlinetime ${minonlinetimetmp * 60} ^assign killmax $killmaxtmp ^assign leechkillrunning 1 ^assign checkserver $checkservertmp # ^eval set status_user5 $leechstatustext ^assign statusformat $status_format1 ^set status_format1 $statusformat 10[%510] timer 120 ^assign leechkillrunning 0 msgmute ^on ^831 "*" if ( logipon ) ^on ^832 - timer 1 //gusers $checkserver -cmd { ^assign counted 0 ^assign limitcounted 0 //whois -cmd { ^assign username $0 ^assign onlinetime $2 ^assign filesshared $5 ^assign roomsjoined $3 ^assign onserver $16 ^assign leechclienttmp $tr(/"//$9)) ^assign leechclient $tr(/\)//$leechclienttmp) timer -delete killem timer -ref killem 2 { if ( counted ) { # Depending on if we skipped users or not, what level was called, and if the maximum kill count was reached, we output an appropriate summary message. if ( skipcounter && skipserver != "" ) { if ( doit == 0 ) { xecho -b 11${counted}10 users should be axed with 11$skipcounter10 skipped \(11${counted + skipcounter}10 total) on 11${checkserver}10.-1 } if ( doit == 1 && counted <= killmax ) { wall 11${counted}10 users would be axed with 11$skipcounter10 skipped \(11${counted + skipcounter}10 total) on 11${checkserver}10.-1 } if ( doit == 1 && counted > killmax ) { wall 10Maximum limit of 11$killmax10 users would be axed, 11$skipcounter10 skipped, and 11${counted - killmax}10 remaining \(11${counted + skipcounter}10 total) on 11${checkserver}10.-1 } if ( doit == 2 ) { wall 11$counted10 users warned, 11$skipcounter10 skipped \(11${counted + skipcounter}10 total) on 11${checkserver}10.-1 } if ( doit == 3 && !limitcounted ) { wall 11$counted10 users axed and 11$skipcounter10 users skipped \(11${counted + skipcounter}10 total) on 11${checkserver}10.-1 } if ( doit == 3 && limitcounted > 0 ) { wall 10Maximum limit of 11$killmax10 users axed, 11$skipcounter10 skipped, and 11$limitcounted10 remaining \(11${counted + skipcounter}10 total) on 11${checkserver}10.-1 } if ( doit == 4 && !limitcounted ) { wall 11$counted10 users axed/banned, and 11$skipcounter10 users skipped \(11${counted + skipcounter}10 total) on 11${checkserver}10.-1 } if ( doit == 4 && limitcounted > 0 ) { wall 10Maximum limit of 11$killmax10 users axed/banned, 11$skipcounter10 skipped, and 11$limitcounted10 remaining \(11${counted + skipcounter}10 total) on 11${checkserver}10.-1 } } { if ( doit == 0 ) { xecho -b 11$counted10 users would be axed on 11${checkserver}10.-1 } if ( doit == 1 && counted <= killmax ) { wall 11$counted10 users would be axed on 11${checkserver}10.-1 } if ( doit == 1 && counted > killmax ) { wall 10Maximum limit of 11$killmax10 users would be axed with 11${counted - killmax}10 remaining \(11$counted10 total) on 11${checkserver}10.-1 } if ( doit == 2 ) { wall 11$counted10 users warned on 11${checkserver}10.-1 } if ( doit == 3 && !limitcounted ) { wall 11$counted10 users axed on 11${checkserver}10.-1 } if ( doit == 3 && limitcounted > 0 ) { wall 10Maximum limit of 11$killmax10 users axed with 11$limitcounted10 remaining \(11$counted10 total) on 11${checkserver}10.-1 } if ( doit == 4 && !limitcounted ) { wall 11$counted10 users axed/banned on 11${checkserver}10.-1 } if ( doit == 4 && limitcounted > 0 ) { wall 10Maximum limit of 11$killmax10 users axed/banned with 11$limitcounted10 remaining \(11$counted10 total) on 11${checkserver}10.-1 } } } { if (doit > 0) wall 11No users axed!-1 if (doit == 0) xecho -b 11No users would be axed!-1 } } timer -delete statlog timer -ref statlog 4 { xecho cleanup # This is the last thing in the script to run, put clean-up here. Do the leechusers stats, clean up the gu call, and wipe out variables. msgunmute if ( logipon && doit > 1 ) { # For me, I only want to log on levels 2 and above. leechusers } if ( !logipon ) { # For everyone else, log and return 831 to normal. leechusers ^on ^831 - } ^set status_format1 $statusformat ^set -status_user5 @ leechkillrunning = counted = doit = files = filesshared = killmax = killmaxstat = leechclient = lib = minfiles = cancelkill = [] @ leechclienttmp = leechtotal = limitcounted = minonlinetime = onlinetime = onserver = roomsjoined = skipcounter = users = leechstatustext = [] } if ( onlinetime > minonlinetime && onlinetime < 1728000 && filesshared <= minfiles && strlen($roomsjoined) < 4 && match($onserver $skipserver)) { # We just count users skipped as leeches, no under or over max kill necessary since this user is on a server to be skipped. @ skipcounter++ } if ( onlinetime > minonlinetime && onlinetime < 1728000 && filesshared <= minfiles && strlen($roomsjoined) < 4 && !match($onserver $skipserver)) { # If the user meet the criteria of being a leech and isn't on a skipped server, go to town on them! @ counted++ if ( doit == 2 ) { msg $0 "Please share more than $minfiles files or be killed. \(${leechclient}\)" logclient $leechlog leechlist $leechclient } if ( doit >= 3 && counted <= killmax) { # We haven't killed our maximum amount yet. # xecho -b $filesshared # xecho Nick: $0 Time: $2 Shared: $5 # xecho ${username} using $leechclient: Online ${onlinetime / 60} minutes sharing $filesshared files. # xecho raw 610 $0 "Please share more than $minfiles files. \(${leechclient}\)" raw 610 $0 "Please share more than $minfiles files. \(${leechclient}\)" if ( doit == 4 ) { tban $0 1d 24 Hour Leech Kill Ban: You were sharing $minfiles files on $strftime(%D at %H:%M) } logclient $leechlog leechlist $leechclient } if ( doit >= 3 && counted > killmax) { # We've now killed our maximum amount, just count how many are left. # xecho -b $filesshared # xecho Nick: $0 Time: $2 Shared: $5 @ limitcounted++ if ( doit == 4 ) { tban $0 1d 24 Hour Leech Kill Ban: You were sharing $minfiles files on $strftime(%D at %H:%M) } logclient $leechlog leechlist $leechclient } } } $0 } -leech -users } alias leechuserspre { xecho leechuserspre # Get users, files, lib size ahead of time for leechuser logging. ^on ^10115 '*' { ^assign users $2 ^assign files $3 ^assign lib $4 } timer 1 admin stats timer 3 ^on ^10115 - } alias leechusers { # Write the leechuser file. First we have to tally the counters appropriately. # If we have chat-only servers, we don't want to count them as leeches in logs. :( if ( doit < 3 ) { ^assign killmaxstat 0 # ^assign leechtotal ${counted + skipcounter} ^assign leechtotal ${counted} } if ( doit >= 3 && !limitcounted ) { ^assign killmaxstat $counted # ^assign leechtotal ${counted + skipcounter} ^assign leechtotal ${counted} } if ( doit >= 3 && limitcounted ) { ^assign killmaxstat $killmax # ^assign leechtotal ${limitcounted + skipcounter + killmax} ^assign leechtotal ${limitcounted + killmax} } if (fexist($leechusers) == -1) { @ sl = open($leechusers w) @ write($sl server users files lib killmax skipcounter leechtotal) @ write($sl $checkserver $users $files $lib $killmaxstat $skipcounter $leechtotal) @ close($sl) } { @ sl = open($leechusers w) @ write($sl $checkserver $users $files $lib $killmaxstat $skipcounter $leechtotal) @ close($sl) } } alias logclient (logfile, dataarray, logdata) { # Write the leech client stats. if (numitems($dataarray $logdata) > 1) { ^assign logtmp 1 if (finditem($dataarray $logdata) < -1) { ^assign logtmptoo $numitems($dataarray) @ setitem($dataarray $logtmptoo $logdata) @ logtmptoo++ @ setitem($dataarray $logtmptoo 1) ^assign logtmp 0 } if (logtmp) { if (finditem($dataarray $logdata) > -1) { ^assign logtmptoo $finditem($dataarray $logdata) @ logtmptoo++ ^assign logtmpthree $getitem($dataarray $logtmptoo) @ logtmpthree++ @ setitem($dataarray $logtmptoo $logtmpthree) } } @ logtmp = logtmptoo = logtmpthree = [] } if (numitems($dataarray) < 1) { @ setitem($dataarray $numitems($dataarray) $logdata) @ setitem($dataarray 1 1) } if (numitems($dataarray) > 1) { ^assign return = $unlink($logfile) @ sl = open($logfile w) ^assign logtmp 0 while ( logtmp < numitems($dataarray) ) { @ write($sl $getitem($dataarray ${logtmp})) @ logtmp++ } @ close($sl) @ logtmp = [] } } alias leechload (logfile, dataarray) { # Load the leech client stats. if ( logfile == [] ) { xecho -b No logfile specified! } { if (fexist($logfile)) { @ delarray($dataarray) @ line = 0 @ sr = open($logfile r) while (!eof($sr)) { @ ugh = read($sr) if (eof($sr)) { # done reading logfile } { @ setitem($dataarray $line $ugh) @ line++ } } @ close($sr) } { exec touch $logfile } } } alias leechstats (clientmin, nick) { # Report leech client statistics, if you don't supply a minimum count it defaults to 15. if (clientmin == "") { ^assign clientmin 15 } ^assign cmd msg $nick if (nick == "") { ^assign cmd xecho -b } ^assign logtmp $numitems(leechlist) if ( !logtmp ) { $cmd No leeches in the list. } $cmd Showing Leech Clients with $clientmin minimum of occurrences. while ( logtmp > 0 ) { @ logtmp-- if ( getitem(leechlist ${logtmp}) > clientmin ) { $cmd Server $getitem(leechlist ${logtmp-1}) has been a leech client $getitem(leechlist ${logtmp}) times. } @ logtmp-- } timer 1 @ clientmin = nick = logtmp = [] } alias leechtimer (delay, checkserver, minfilestmp, doittmp) { # Set up a timer to periodically run the leech killer. if ( leechtimerrunning ) { xecho -b 11Leechtimer canceled.-1 timer -del lechtime timer -del lechrung @ leechtimerrunning = [] } { if (delay == [] || checkserver == [] || minfilestmp == {} || delay < 5) { xecho -b 07***11 Leechtimer takes four arguments, first is the delay in minutes, and the regular arguments below.-1 leechkill xecho -b 10Example: 11/leechtimer 15 * 0 310 kills every 15 minutes. Minimum delay is 5 minutes. Repeats for one day by default.-1 } { xecho -b 10Starting leechkill every 11$delay10 minutes for 11$checkserver $minfilestmp $doittmp-1 timer -ref lechtime -repeat ${2880 / delay} ${delay * 60} leechkill $checkserver $minfilestmp $doittmp # timer -ref lechrung 86400 @ leechtimerunning = [] ^assign leechtimerrunning 1 } } } on #^msg 422 "% !leechstats*" { # Allow people to message us with !leechstats, and optionally give a minimum count, again defaults to 15 otherwise. @ clientmin = nick = [] xecho -window public $cparse($TIME %B* RELINK: %wUser %B<%W$0%B> %whas requested Leech statistics.) ^assign clientmin $2 ^assign nick $0 if ( clientmin == "" ) { ^assign clientmin 15 } leechstats $clientmin $nick } alias msgmute { ^on ^404 "User is not currently online*" {} ^on ^404 "user * is not a known user" {} ^on ^404 "kill failed: no such user" {} ^on ^404 "% banned *You were sharing*" {} } alias msgunmute { # ^on ^404 "User is not currently online*" {xecho $cparse($stime %c$0-)} ^on ^404 "user * is not a known user" {eval xecho $cparse($stime %c$0-)} ^on ^404 "kill failed: no such user" {xecho $cparse($stime %c$0-)} ^on ^404 "% banned *You were sharing*" {xecho $cparse($stime %C$0-)} } # Load the leech client stats leechload $leechlog leechlist # Some whois data so we know what fields are where.. This can be wiped out when we're done. :) # 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 # nick level secs joined status shared curd curu ? client totd totup ip port ? con server # ac3tyl "User" 65480 " #mainroom " "Active" 4507 1 2 6 "..." 49 130 45.0.32.13 62868 6802 unknown blah # Dataviz "User" 1404 " #mainroom " "Active" 0 0 0 5 "TekNap" 0 0 87.53.23.52 1150 0 unknown blah