From 75a65cecd2c3b74c0a119d448c6d6f493b4aaa39 Mon Sep 17 00:00:00 2001 From: Bel LaPointe Date: Sat, 9 Feb 2019 11:03:36 -0700 Subject: [PATCH] Fix vendor --- vendor/local/logger/logger.go | 98 -------------------- vendor/local/resumesite/app.yaml | 6 -- vendor/local/resumesite/main.go | 134 --------------------------- vendor/local/resumesite/main_test.go | 33 ------- 4 files changed, 271 deletions(-) delete mode 100755 vendor/local/logger/logger.go delete mode 100644 vendor/local/resumesite/app.yaml delete mode 100644 vendor/local/resumesite/main.go delete mode 100644 vendor/local/resumesite/main_test.go diff --git a/vendor/local/logger/logger.go b/vendor/local/logger/logger.go deleted file mode 100755 index 97a20ea..0000000 --- a/vendor/local/logger/logger.go +++ /dev/null @@ -1,98 +0,0 @@ -package logger - -import ( - "errors" - "fmt" - "os" - "time" -) - -var outfile *os.File -var outfileB *os.File - -var lastWasReturn = false - -var ErrCantConfigLog = errors.New("cannot configure log") - -func Config(path string) error { - if path == "" { - return nil - } - f, err := os.OpenFile(path, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600) - if err != nil { - return ErrCantConfigLog - } - outfile = f - return nil -} - -func Logf(args ...interface{}) { - if outfile == nil { - outfile = os.Stderr - } - defer outfile.Sync() - if len(args) == 0 { - fmt.Fprintln(outfile, "") - return - } - v := fmt.Sprintf(args[0].(string), args[1:]...) - if v[len(v)-1] == '\n' { - v = v[:len(v)-1] - } - thisWasReturn := v[0] == '\r' - if lastWasReturn && !thisWasReturn { - fmt.Println() - } - if thisWasReturn { - fmt.Fprintf(outfile, "\r%s%v", prefix(), v[1:]) - } else { - fmt.Fprintf(outfile, "%s%v\n", prefix(), v) - } - lastWasReturn = thisWasReturn -} - -func Fatalf(args ...interface{}) { - Logf(args...) - if len(args) > 0 { - panic(args[0]) - } else { - panic("Panic from logger.fatal()") - } -} - -func Fatal(args ...interface{}) { - Log(args...) - if len(args) > 0 { - panic(args[0]) - } else { - panic("Panic from logger.fatal()") - } -} - -func Log(args ...interface{}) { - if lastWasReturn { - fmt.Println() - } - if outfile == nil { - outfile = os.Stderr - } - v := fmt.Sprintf("%v", args) - v = v[1 : len(v)-1] - fmt.Fprintf(outfile, "%s%v\n", prefix(), v) - outfile.Sync() - lastWasReturn = false -} - -func LogB(args ...interface{}) { - if outfileB == nil { - outfileB = os.Stderr - } - v := fmt.Sprintf("%v", args) - v = v[1 : len(v)-1] - fmt.Fprintf(outfileB, "%s%v\n", prefix(), v) - outfileB.Sync() -} - -func prefix() string { - return time.Now().Format("20060102-150405") + " : " -} diff --git a/vendor/local/resumesite/app.yaml b/vendor/local/resumesite/app.yaml deleted file mode 100644 index 2f96561..0000000 --- a/vendor/local/resumesite/app.yaml +++ /dev/null @@ -1,6 +0,0 @@ -runtime: go -api_version: go1 -handlers: -- url: /.* - script: _go_app - secure: always diff --git a/vendor/local/resumesite/main.go b/vendor/local/resumesite/main.go deleted file mode 100644 index cb89304..0000000 --- a/vendor/local/resumesite/main.go +++ /dev/null @@ -1,134 +0,0 @@ -package main - -import ( - "encoding/binary" - "encoding/csv" - "flag" - "local/logger" - "log" - "net" - "net/http" - "os" - "path" - "path/filepath" - "sort" - "strconv" - "strings" - - "google.golang.org/appengine" -) - -func main() { - exePath, err := filepath.Abs(filepath.Dir(os.Args[0])) - if err != nil { - panic(err) - } - exePath = "." - - directory := flag.String("d", path.Join(exePath, "public"), "the directory of static file to host") - flag.Parse() - - getIPs() - - http.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - remoteIP := strings.Split(r.RemoteAddr, ":")[0] - if notUSA(remoteIP) { - logger.Log(remoteIP, "NOT USA") - return - } - if r.URL.Scheme == "http" || strings.HasPrefix(r.Host, "http:") { - r.URL.Scheme = "https" - http.Redirect(w, r, r.URL.String(), http.StatusTemporaryRedirect) - return - } - http.FileServer(http.Dir(*directory)).ServeHTTP(w, r) - })) - - log.Printf("Serving %s\n", *directory) - - appengine.Main() -} - -var globalIPs []uint64 - -func getIPs() []uint64 { - if globalIPs != nil { - return globalIPs - } - - globalIPs = make([]uint64, 0) - - f, err := os.Open("private/ipv4.csv") - if err != nil { - panic(err) - } - ipv4r := csv.NewReader(f) - ipv4all, err := ipv4r.ReadAll() - if err != nil { - panic(err) - } - logger.Log("IPV4s") - for i := range ipv4all { - if ipv4all[i][2] == "US" || ipv4all[i][2] == "-" { - start, err := strconv.ParseUint(ipv4all[i][0], 10, 64) - if err != nil { - panic(err) - } - stop, err := strconv.ParseUint(ipv4all[i][1], 10, 64) - if err != nil { - panic(err) - } - globalIPs = append(globalIPs, uint64(start), uint64(stop)) - } - } - - g, err := os.Open("private/ipv6.csv") - if err != nil { - panic(err) - } - - ipv6r := csv.NewReader(g) - ipv6all, err := ipv6r.ReadAll() - if err != nil { - panic(err) - } - logger.Log("IPV6s") - for i := range ipv6all { - if ipv6all[i][2] == "US" { - start, err := strconv.ParseUint(ipv6all[i][0], 10, 64) - if err != nil { - continue - } - stop, err := strconv.ParseUint(ipv6all[i][1], 10, 64) - if err != nil { - continue - } - globalIPs = append(globalIPs, uint64(start), uint64(stop)) - } - } - sort.Slice(globalIPs, func(i, j int) bool { - return globalIPs[i] > globalIPs[j] - }) - return globalIPs -} - -func notUSA(ip string) bool { - dec := toDec(ip) - ips := getIPs() - n := sort.Search(len(ips), func(i int) bool { - return ips[i] > dec - }) - logger.Log(ip, dec, ips[0], n, len(ips)) - return n%2 == 1 -} - -func toDec(ips string) uint64 { - ip := net.ParseIP(ips) - if ip == nil { - return uint64(0) - } - if len(ip) == 16 { - return uint64(binary.BigEndian.Uint32(ip[12:16])) - } - return uint64(binary.BigEndian.Uint32(ip)) -} diff --git a/vendor/local/resumesite/main_test.go b/vendor/local/resumesite/main_test.go deleted file mode 100644 index a2db503..0000000 --- a/vendor/local/resumesite/main_test.go +++ /dev/null @@ -1,33 +0,0 @@ -package main - -import "testing" - -func Test_notUSA(t *testing.T) { - cases := []struct { - ip string - ok bool - }{ - { - ip: "8.8.8.8", - ok: false, - }, - { - ip: "192.168.0.86", - ok: false, - }, - { - ip: "127.0.0.1", - ok: false, - }, - { - ip: "223.144.0.0", - ok: true, - }, - } - - for _, c := range cases { - if notUSA(c.ip) != c.ok { - t.Errorf("WRONG VALIDATION for %v, expected %v", c.ip, c.ok) - } - } -}