From 0c4c2d63fc9d323615801a7d1355a3f9504627ae Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Tue, 5 Jan 2016 16:49:42 -0500 Subject: [PATCH] Use any IP supplied in `.here` for location --- where/where.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/where/where.go b/where/where.go index 2f24498..6d36e88 100644 --- a/where/where.go +++ b/where/where.go @@ -118,8 +118,24 @@ func who() []user { // Get user permissions, marking if they're not opted-in with a // `.here` file in their $HOME dir. - if _, err := os.Stat("/home/" + name + "/.here"); os.IsNotExist(err) { + f, err := os.Stat("/home/" + name + "/.here") + if os.IsNotExist(err) { users[i].Public = false + } else { + if f.Size() > 0 { + // There's something in the file! Maybe a present? + data, err := ioutil.ReadFile("/home/" + name + "/.here") + if err != nil { + fmt.Printf("Error reading ~/%s/.here: %v\n", name, err) + } else { + fmt.Printf("Read ~/%s/.here: %s\n", name, data) + // Match IP + ipMatch := ipRegex.FindAll(data, 1) + if len(ipMatch) > 0 { + users[i].IP = strings.TrimSpace(string(data)) + } + } + } } if _, err := os.Stat("/home/" + name + "/.somewhere"); err == nil { users[i].Public = true