1
0
mirror of https://github.com/thebaer/tildes.git synced 2018-07-20 07:15:21 +00:00

Hash user names in cache file

This commit is contained in:
Matt Baer 2015-02-18 17:04:48 -05:00
parent 120562e1d6
commit 606578e123

View File

@ -13,6 +13,9 @@ import (
"flag" "flag"
"time" "time"
"text/template" "text/template"
"crypto/hmac"
"crypto/sha256"
"encoding/base64"
"github.com/thebaer/geo" "github.com/thebaer/geo"
"github.com/thebaer/tildes/store" "github.com/thebaer/tildes/store"
@ -22,12 +25,20 @@ const (
locDataJSON = "/home/bear/public_html/where.json" locDataJSON = "/home/bear/public_html/where.json"
) )
var (
hashKey = "~~~"
)
func main() { func main() {
// Get arguments // Get arguments
outFilePtr := flag.String("f", "where", "Outputted HTML filename (without .html)") outFilePtr := flag.String("f", "where", "Outputted HTML filename (without .html)")
geocodeAPIKeyPtr := flag.String("k", "", "Google Geocoding API key") geocodeAPIKeyPtr := flag.String("k", "", "Google Geocoding API key")
hashKeyPtr := flag.String("s", "", "Secret for hashing usernames")
flag.Parse() flag.Parse()
// Set globals
hashKey = *hashKeyPtr
// Get online users with `who` // Get online users with `who`
users := who() users := who()
@ -158,6 +169,13 @@ func getGeo(u *user) {
} }
} }
func computeHmac256(message string) string {
key := []byte(hashKey)
h := hmac.New(sha256.New, key)
h.Write([]byte(message))
return base64.StdEncoding.EncodeToString(h.Sum(nil))
}
func getFuzzyCoords(u *user, apiKey string) { func getFuzzyCoords(u *user, apiKey string) {
fmt.Printf("Fetching %s fuzzy coordinates...\n", u.Name) fmt.Printf("Fetching %s fuzzy coordinates...\n", u.Name)
@ -183,7 +201,7 @@ func cacheUserLocations(users *[]user) {
// Update user data // Update user data
for i := range *users { for i := range *users {
u := (*users)[i] u := (*users)[i]
(*res)[u.Name] = publicUser{Name: u.Name, Region: u.Region, Country: u.Country, Latitude: u.Latitude, Longitude: u.Longitude} (*res)[computeHmac256(u.Name)] = publicUser{Name: u.Name, Region: u.Region, Country: u.Country, Latitude: u.Latitude, Longitude: u.Longitude}
} }
// Write user data // Write user data