Przeglądaj źródła

hostclean working

James Seward 13 lat temu
rodzic
commit
b3255e3fef
1 zmienionych plików z 21 dodań i 12 usunięć
  1. 21 12
      HostClean/hostclean.tcl

+ 21 - 12
HostClean/hostclean.tcl

@@ -1,7 +1,7 @@
 
 set seen_hostnames [list]
 
-proc load_hostnames { filename } {
+proc load_hostnames { handle idx filename } {
 	global seen_hostnames
 
 	set filehandle [open $filename "r"]
@@ -16,28 +16,37 @@ proc load_hostnames { filename } {
 		set line [gets $filehandle]
 	}
 
-	putlog "hostclean: loaded [llength $seen_hostnames] hostnames from cache"
+	putidx $idx "hostclean: loaded [llength $seen_hostnames] hostnames from cache"
 }
 
 
-proc hostclean { user } {
-  	global seen_hostnames
+proc hostclean { handle idx user } {
+	global seen_hostnames
 	set hostnames [getuser $user HOSTS]
 	putlog "hostclean: found [llength $hostnames] hosts for $user"
 	if {[llength $hostnames] > 0} {
-		foreach $hostnames $host {
+		foreach host $hostnames {
+			if [string match "-telnet*" $host] {
+				set seen 1
+				continue
+			}
 			set regexp_hostname [string map { . \\. * .+ ? . } $host]
 			set seen 0
-			foreach $seen_hostnames $seen_host {
-			  if [regexp $regexp_hostname $seen_host] {
-				set seen 1
-				break
-			  }
+			foreach seen_host $seen_hostnames {
+				if [regexp $regexp_hostname $seen_host] {
+					set seen 1
+					break
+				}
 			}
 			if {!$seen} {
-			  # XXX delete this host
-			  putlog "$host is a candidate for deletion from user $user"
+			# XXX delete this host
+				putidx $idx ".-host $user $host"
 			}
 		}
 	}
 }
+
+bind dcc n hostload load_hostnames
+bind dcc n hostclean hostclean
+
+putlog "HostClean loaded; user .hostload <filename> and .hostclean <handle>"