Skip expired leases. #230.

pull/257/head
Christopher Young 2016-02-15 22:21:15 -05:00
rodzic 02bf2251d8
commit 279a810db0
1 zmienionych plików z 11 dodań i 0 usunięć

Wyświetl plik

@ -82,6 +82,17 @@ func getDHCPLeases() (map[string]string, error) {
hostname := strings.TrimRight(strings.TrimLeft(strings.Join(spaced[3:], " "), "\""), "\";")
ret[block_ip] = hostname
open_block = false
} else if open_block && len(spaced) >= 4 && spaced[2] == "ends" {
end_time := spaced[4] + " " + strings.TrimRight(spaced[5], ";")
// Mon Jan 2 15:04:05 -0700 MST 2006.
// 2016/02/02 00:39:59.
t, err := time.Parse("2006/01/02 15:04:05", end_time) // "In the absence of a time zone indicator, Parse returns a time in UTC."
if err == nil && t.Before(time.Now()) {
log.Printf("lease expired for %s (%s) - skipping.\n", block_ip, end_time)
open_block = false
delete(ret, block_ip)
block_ip = ""
}
} else if open_block && strings.HasPrefix(spaced[0], "}") { // No hostname.
open_block = false
ret[block_ip] = ""