####################################################################################
#### Pig1.00 by pete@undernet
####################################################################################
#
# No alterations are necessary to this script.
#
# Pig is a set of utilities for managing your bots userfiles. 
# The four commands it supports  are:
# 
# gammon : find users(but not bots) who have no password set. 
# bacon : show users who havent been seen in X number of days.
# pork : show bots with 'bad' hostmasks.
# sausage : show users with bad hostmasks.

# Comments, Suggestions, Bugs ?
# Find me in #mp3uk_chat on Undernet, or mail pete@p-smith.co.uk



bind dcc * pig pig
bind dcc * gammon gammon
bind dcc * bacon bacon
bind dcc * pork pork
bind dcc * sausage sausage



####################################################################################
#### Pig
####################################################################################

proc pig {h idx arg} {
  if {$arg == ""} { 
       putdcc $idx "pig is a collection of tools for monitoring and managing userfiles."
       putdcc $idx "current version is 1.00. Available Commands are :" 
       putdcc $idx ".gammon - checks for users with no password set"
       putdcc $idx ".bacon - find users who havent been seen recently"
       putdcc $idx ".sausage - checks for users with 'bad' hostmasks"
       putdcc $idx ".pork - checks for bots with 'bad' hostmasks"
       putdcc $idx "For more help on a specific command, type the command with no arguements"
       putdcc $idx "The only command which actually alters user entries is gammon, which strips the victim of his ops flag for security. The output from the other commands are merely suggestions."
   }
}

####################################################################################
#### Gammon
####################################################################################

proc gammon {h idx arg} {
  if {$arg == ""} { 
     putdcc $idx "Syntax is .gammon <minimum flag>. eg .gammon +o|+o . If a user(but not a bot) is found without a password, his ops will be removed, a warning comment written, and a +L flag used to identify him in future." 
     putdcc $idx "Remember to differentiate between global and channel specific flags,by using (eg) +v|+v"

} else {
 set gimp [userlist $arg]
 foreach tart  $gimp {
     if {([passwdok $tart ""] == 1) && (![matchattr $tart b]) && (![matchattr $tart L])} {
		 putdcc $idx "->$tart : has no password" 
             chattr $tart -nmopa+dL
             setuser $tart comment "Pig.tcl : flags removed (no password)"
		 putdcc $idx "--> chattr $tart -mnopa+d ........ whoops:P"
     } elseif {([passwdok $tart ""] == 1) && ([matchattr $tart L]) && (![matchattr $tart b])} {
		 putdcc $idx "---> User $tart still has a bad entry" 
  }
}
set lgimp [llength $gimp]
   putdcc $idx "End of results ($lgimp gimps matched)"

 }
}

####################################################################################
#### Bacon
####################################################################################

proc bacon {h idx arg} {
   if {$arg == ""} { 
     putdcc $idx "Syntax is .bacon <days elapsed>. eg .bacon 14 will show all users who havent been seen in over 14 days (including those not seen at all)"
     putdcc $idx "No alterations are made to users/flags."

} else {  
set muppet [userlist]
 foreach womble  $muppet {
     set ltime [unixtime]
     set lon [getuser $womble laston]
     set ltime1 [lindex $lon 0 ]
      set lchan [lindex $lon 1 ]   
     if {[regexp -nocase $ltime1 never] != 0} { putdcc $idx " -> $womble has never been seen by me!" 
          } else {
     set lst [expr $ltime - $ltime1]
     set days [expr $lst/86400]
     if { [expr $days - $arg] > 2 } {putdcc $idx "-> $womble last seen $days days ago ($lchan) "} 
  }
 }
 }
}

####################################################################################
#### Pork
####################################################################################

proc pork {h idx arg} {
   
set muppet [userlist]
 foreach tart $muppet {
     if { [matchattr $tart b] } { putdcc $idx "$tart:" }
     if { ([matchattr $tart b]) && (![matchattr $tart f])} { putdcc $idx "--> no +f flag" }
     if { ([matchattr $tart b]) && (![matchattr $tart o])} { putdcc $idx "--> no +o flag" }
     if { ([matchattr $tart b]) && ([matchattr $tart a])} { putdcc $idx "--> +a flag ... is this needed?" }
     if { ([matchattr $tart b]) && ([matchattr $tart d])} { putdcc $idx "--> +d flag found" }
     if { ([matchattr $tart b]) && ([matchattr $tart k])} { putdcc $idx "--> +k flag found" }
      
     set hostlist [getuser $tart hosts]
     foreach gimp $hostlist {
           if { ([matchattr $tart b]) && ([regexp {\*!\*} $gimp ] != 0)}  { putdcc $idx "--> $gimp - bad mask (try *!ident@ and *!?ident@)" }
           }
           if { ([matchattr $tart b]) && ([regexp {^!\*} $gimp ] != 0)}  { putdcc $idx "--> $gimp - bot never has a nick?" }
           if { ([matchattr $tart b]) && ([regexp {\*!*@} $gimp ] != 0)}  { putdcc $idx "-->$gimp - urm, u really dont want an ident ?" }
           if { ([matchattr $tart b]) && ([regexp {@*\*} $gimp ] != 0)}  { putdcc $idx "--> $gimp - Dont use wild cards in vhosts mmkay" }


}
}


####################################################################################
#### Sausage
####################################################################################

proc sausage {h idx arg} {
   
set muppet [userlist]
 foreach tart $muppet {
     if { ([matchattr $tart o]) && (![matchattr $tart b]) && (![matchattr $tart f])} { putdcc $idx "--> $tart : +o but no +f flag" }
     if { ([matchattr $tart o]) && (![matchattr $tart b]) && ([matchattr $tart d])} { putdcc $idx "--> $tart has +o and +d flags" }
     if { ([matchattr $tart a]) && (![matchattr $tart b])} { putdcc $idx "--> $tart has +a flag ... is this needed?" }

     set hostlist [getuser $tart hosts]
     foreach gimp $hostlist {
           if { (![matchattr $tart b]) && ([regexp {@\*(.com|.net|.org|.co.uk|.il|.nz|.au|.ca|.nl|.br|.dk|.fr|.ro|.no)$} $gimp ] != 0)}  { putdcc $idx "-->$tart : $gimp - lazy hostmask." }
           }
           if { (![matchattr $tart b]) && ([regexp {\*!\*@} $gimp ] != 0)}  { putdcc $idx "-->$tart : $gimp - no ident .. static ip ?" }



}
}




putlog "pig.tcl by Pete"
