aIRC — File Browser

aIRCv0.8.69 / aIRCv0.8.69 / script / weed.mrc

weed.mrc — 11.47 KB — Download this file

;/**********************************************************************
; *
; * aIRC
; * Weed
; *
; **********************************************************************/
;
;;
;
; /weed [options]
; (ported-from/based-in the weed tcl written by Robey Pointer for the eggdrop bot)
; Possible options:
;   -<handle>      exempt this user from weeding
;   ^o             exempt ops
;   ^m             exempt masters
;   ^f             exempt friends
;   ^co            exempt chanops
;   ^cm            exempt chanmasters
;   ^cf            exempt chanfriends
;   ^cn            exempt chanowner
;   ^p             exempt party-line users
;   ^x             exempt file-area users
;   ^b             exempt botnet master
;   +<days>        weed: haven't been seen in N days
;   :n             weed: haven't EVER been seen
;   :o             weed: ops with no password set
;   :m             weed: masters with no password set
;   :a             weed: anyone with no pasword set
;   :f             weed: users selfadded using the file server
;   :k             weed: autokick users
;   o              unop: ops with no pass.
;   m              unmaster: masters with no pass.
;   =<#chan>       weed: channels nolonger supported
;
alias _weed {
  __weed $1-
  if ($result) { return }
  _weedunload
}
alias __weed {
  var %total = 0,%chanrem,%exempt,%exemptops = 0,%exemptmasters = 0,%exemptfriends = 0,%exemptparty = 0,%exemptfile = 0,%exemptchanm = 0,%exemptbotm = 0,%exemptchann = 0,%exemptchanf = 0,%exemptchano = 0,%maxlast = 0,%weedops = 0,%weedmasters = 0,%weednopw = 0,%stripops = 0,%stripmasters = 0,%weedlurkers = 0,%weedfserve = 0,%weedakick = 0,%echo
  var %args = $1-,%i = 1,%n = $numtok(%args,32),%carg
  if (%args == $null) {
    _dialog -m _weed _weed
    return 1
  }
  while (%i <= %n) {
    %carg = $gettok(%args,%i,32)
    if (%carg == :n)       { %weedlurkers = 1 }
    elseif (%carg == :o)   { var %weedops = 1,%stripops = 0,%weednopw = 0 }
    elseif (%carg == :m)   { var %weedmasters = 1,%stripmasters = 0,%weednopw = 0 }
    elseif (%carg == :a)   { var %weednopw = 1,%weedops = 0,%weedmasters = 0,%stripops = 0,%stripmasters = 0 }
    elseif (%carg == :f)   { %weedfserve = 1 }
    elseif (%carg == :k)   { %weedakick = 1 }
    elseif (%carg == o)    { var %stripops = 1,%weedops = 0,%weednopw = 0 }
    elseif (%carg == m)    { var %stripmasters = 1,%weedmasters = 0,%weednopw = 0 }
    elseif (%carg == ^m)   { %exemptmasters = 1 }
    elseif (%carg == ^o)   { %exemptops = 1 }
    elseif (%carg == ^f)   { %exemptfriends = 1 }
    elseif (%carg == ^p)   { %exemptparty = 1 }
    elseif (%carg == ^x)   { %exemptfile = 1 }
    elseif (%carg == ^cf)  { %exemptchanf = 1 }
    elseif (%carg == ^cm)  { %exemptchanm = 1 }
    elseif (%carg == ^cn)  { %exemptchann = 1 }
    elseif (%carg == ^b)   { %exemptbotm = 1 }
    elseif (%carg == ^co)  { %exemptchano = 1 }
    elseif (-* iswm %carg) { %exempt = $addtok(%exempt,$right(%carg,-1),44) }
    elseif (+* iswm %carg) { %maxlast = $calc($round($right(%carg,-1),0) * 60 * 60 * 24) }
    elseif (=* iswm %carg) { %chanrem = $addtok(%chanrem,$right(%carg,-1),44) }
    else {
      error.a Weed: UNKNOWN OPTION: ' $+ %carg $+ '
      return
    }
    inc %i
  }
  if (%weedlurkers == 0) && (%weedops == 0) && (%weedmasters == 0) && (%weednopw == 0) && (%stripops == 0) && (%stripmasters == 0) && (%maxlast == 0) && (%chanrem == $null) && (%weedfserve == 0) && (%weedakick == 0) {
    error.a Weed: You didn't specify anything to weed out.
    return
  }

  var %weeding,%strip,%exempting

  if ({%weedlurkers)     { %weeding = %weeding lurkers }
  if (%weedops)          { %weeding = %weeding pwdless-ops }
  if (%weedmasters)      { %weeding = %weeding pwdless-masters }
  if (%weednopw)         { %weeding = %weeding pwdless-users }
  if (%weedfserve)       { %weeding = %weeding fserve-users }
  if (%weedakick)        { %weeding = %weeding akick-losers }
  if (%chanrem != $null) { %weeding = %weeding unwanted-channel }
  if (%maxlast)          { %weeding = %weeding > $+ $calc(%maxlast /(60*60*24)) $+ -days }
  if (%weeding != $null) { %echo = %echo Weeding: %weeding }

  if (%stripops)       { %strip = %strip pwdless-ops }
  if (%stripmasters)   { %strip = %strip pwdless-masters }
  if (%strip != $null) { %echo = %echo Stripping: %strip }

  if (%exemptops)       { %exempting = %exempting (ops) }
  if (%exemptmasters)   { %exempting = %exempting (masters) }
  if (%exemptfriends)   { %exempting = %exempting (friends) }
  if (%exemptparty)     { %exempting = %exempting (party-line) }
  if (%exemptfile)      { %exempting = %exempting (file-area) }
  if (%exemptchann)     { %exempting = %exempting (channel-owners) }
  if (%exemptchanm)     { %exempting = %exempting (channel-masters) }
  if (%exemptchano)     { %exempting = %exempting (channel-ops) }
  if (%exemptchanf)     { %exempting = %exempting (channel-friends) }
  if (%exemptbotm)      { %exempting = %exempting (botnet masters) }
  if (%exempt != $null) { %exempting = %exempting %exempt }
  if (%exempting != $null) { %echo = %echo Exempt: %exempting }

  info.a %echo

  var %weeded = 0,%chrec = 0,%file = $_userinifile,%"file" = " $+ %file $+ ",%total = $ini(%file,0),%i = %total,%handle,%remove,%chans,%pass = 0,%laston = 0
  while (%i)  {
    var %remove = 0,%handle = $ini(%file,%i)
    if ($_readini(%file,%handle,handle) == %handle) {
      var %attr = $_readini(%file,%handle,global),%chanlist = $_readini(%file,%handle,channels),%chanattr,%j = $numtok(%chanlist,32),%pass = 0,%laston = 0
      while (%j) {
        %chanattr = %chanattr $_readini(%file,%handle,$gettok(%chanlist,%j,32))
        dec %j
      }
      if ($istok(%exempt,%handle,44)) && ((o isincs %attr) || (%exemptops == 0)) && ((m isincs %attr) || (%exemptmasters == 0)) && ((f isincs %attr) || (%exemptfriends == 0)) && ((p isincs %attr) || (%exemptparty == 0)) && ((x isincs %attr) || (%exemptfile == 0)) && ((t isincs %attr) || (%exemptbotm == 0)) && ((f isincs %chanattr) || (%exemptchanf == 0)) && ((m isincs %chanattr) || (%exemptchanm == 0)) && ((n isincs %chanattr) || (%exemptchann == 0)) && ((o isincs %chanattr) || (%exemptchano == 0)) {
        if ($_readini(%file,%handle,__pass) != $null) { %pass = 1 }
        if ($gettok($_readini(%file,%handle,__laston),1,32) != $null) { %laston = 1 }
        if (%pass == $null) && (b !isincs %attr) {
          if (%weednopw) || ((o isincs %attr) && (%weedops)) || ((m isincs %attr) && (%weedmasters)) {
            info.a Weeding %handle (pwd)
            %remove = 1
          }
        }
        else {
          if (m isincs %attr) && (%stripmasters) {
            info.a -m %handle (nopass)
            .chattr %handle -m
          }
          if (o isincs %attr) && (%stripops)     {
            info.a -o %handle (nopass)
            .chattr %handle -o
          }
        }
      }
      if (%remove == 0) {
        if (%laston == 0) && (%weedlurkers) && (b !isincs %attr) {
          info.a Weeding %handle (lurker)
          %remove = 1
        }
        elseif (%laston) && (%maxlast) && ($calc($ctime - %laston - %maxlast) > 0) {
          info.a Weeding %handle (exp)
          %remove = 1
        }
        elseif (F isincs %attr) && (%weedfserve) {
          info.a Weeding %handle (fserve)
          %remove = 1
        }
        elseif (k isincs %attr) && (%weedakick) {
          info.a Weeding %handle (akick)
          %remove = 1
        }
        elseif (%chanrem != $null) && (%chanlist != $null) {
          var %j = $numtok(%chanlist,32),%tc
          while (%j) {
            %tc = $gettok(%chanlist,%j,32)
            if ($istok(%chanrem,%tc,44)) {
              info.a Removing channel entry: %handle %tc
              .-chrec %handle %tc
              inc %chrec
            }
            dec %j
          }
        }
      }
    }
    else {
      info.a Weeding %handle (invalid)
      %remove = 1
    }
    if (%remove) {
      .-user %handle
      inc %weeded
    }
    dec %i
  }
  if (%weeded == 0) && (%chrec == 0) { info.a uNF... Nothing to weed! }

  flushini %"file"
  info.a Finished scan. Original total ( $+ %total $+ ), new total ( $+ $ini(%file,0) $+ ), zapped ( $+ %weeded $+ ) Wrote %"file"
}
dialog _weed {
  title "Userlist weed"
  size -1 -1 203 159
  option dbu
  box "Weed",1002, 5 5 96 134,
  check "Ops with no password set",1003, 10 15 83 10,
  check "Masters with no password set",1004, 10 25 83 10,
  check "Anyone with no password set",1005, 10 35 83 10,
  check "Self added in the Fserve",1006, 10 45 84 10,
  check "+k losers",1007, 10 55 84 10,
  check "Never seen users",1008, 10 65 84 10,
  check "Not seen in X days",1009, 10 75 61 10,
  edit "",1010, 70 75 24 10, AutoHs

  box "Exempt",1011, 105 5 96 134,
  check "Ops (+o)",1012, 110 15 83 10,
  check "Masters (+m)",1013, 110 25 83 10,
  check "Friends (+f)",1014, 110 35 83 10,
  check "Chanops",1015, 110 45 83 10,
  check "Chanmasters",1016, 110 55 83 10,
  check "Chanfriends",1017, 110 65 83 10,
  check "Chanowner",1018, 110 75 83 10,
  check "Partyline users (+p)",1019, 110 85 83 10,
  check "File area users (+x)",1020, 110 95 83 10,
  check "Botnet Masters (+t)",1021, 110 105 83 10,
  check "Exempt these users:",1022, 110 115 83 10,
  edit "",1023, 120 125 74 10, AutoHs
  check "Unop +o without pass",1024, 10 95 83 10,
  check "Unmaster +m without pass",1025, 10 105 83 10,
  check "-chrec these channels",1026, 10 115 83 10,
  edit "",1027, 20 125 74 10, AutoHs
  button "&Ok",2990, 105 145 45 11, Ok
  button "&Cancel",2991, 155 145 45 11, Cancel
}
;Compiled by the Leprechaun Dialog creator on Sat Feb 10 10:29:56 2001 (www.leprechaunscript.cjb.net)
;modified by tabo

ON *:DIALOG:_weed:init:0:{
  _mdx.init
  _dummy $_lang.loaddialog($dname,$dname,00086969,main.lang,$scriptdir)
}
ON *:DIALOG:_weed:sclick:2990:{
  var %d = $dname,%options
  if ($did(%d,1003).state) { %options = %options :o }
  if ($did(%d,1004).state) { %options = %options :m }
  if ($did(%d,1005).state) { %options = %options :a }
  if ($did(%d,1006).state) { %options = %options :f }
  if ($did(%d,1007).state) { %options = %options :k }
  if ($did(%d,1008).state) { %options = %options :n }
  if ($did(%d,1009).state) && ($_isint($round($did(%d,1010,1),0))) { %options = %options + $+ $ifmatch }
  if ($did(%d,1012).state) { %options = %options ^o }
  if ($did(%d,1013).state) { %options = %options ^m }
  if ($did(%d,1014).state) { %options = %options ^f }
  if ($did(%d,1015).state) { %options = %options ^co }
  if ($did(%d,1016).state) { %options = %options ^cm }
  if ($did(%d,1017).state) { %options = %options ^cf }
  if ($did(%d,1018).state) { %options = %options ^cn }
  if ($did(%d,1019).state) { %options = %options ^p }
  if ($did(%d,1020).state) { %options = %options ^x }
  if ($did(%d,1021).state) { %options = %options ^b }
  if ($did(%d,1022).state) {
    var %tmp = $replace($did(%d,1023),$chr(32),$chr(44)),%i = $numtok(%tmp,44)
    while (%i) {
      %options = %options - $+ $gettok(%tmp,%i,44)
      dec %i
    }
  }

  if ($did(%d,1024).state) { %options = %options o }
  if ($did(%d,1025).state) { %options = %options m }
  if ($did(%d,1026).state) {
    var %tmp = $_fixchans($did(%d,1027)),%i = $numtok(%tmp,44)
    while (%i) {
      %options = %options = $+ $gettok(%tmp,%i,44)
      dec %i
    }
  }
  if (%options == $null) { halt }
  weed %options
  _weedunload
}
ON *:DIALOG:_weed:sclick:2991:{ _weedunload }
alias -l _weedunload { _quickunload _weed $script }