Compare commits
10 Commits
e1c7e2bcfd
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
41540fd7a2 | ||
|
|
57ef20a6f1 | ||
|
|
e5503f4691 | ||
|
|
75a65cecd2 | ||
|
|
81782bb794 | ||
|
|
839706b226 | ||
|
|
750c9d07ed | ||
|
|
6f5f38a309 | ||
|
|
625a9b03c8 | ||
|
|
6d1ebe9265 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -2,9 +2,9 @@
|
|||||||
*.crt
|
*.crt
|
||||||
*.pem
|
*.pem
|
||||||
*.swp
|
*.swp
|
||||||
vendor
|
|
||||||
*.swo
|
*.swo
|
||||||
*.pub
|
*.pub
|
||||||
|
private
|
||||||
cli-keys
|
cli-keys
|
||||||
fake-ssh
|
fake-ssh
|
||||||
gcpkeys
|
gcpkeys
|
||||||
|
|||||||
99
main.go
99
main.go
@@ -1,12 +1,18 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/binary"
|
||||||
|
"encoding/csv"
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"sort"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"google.golang.org/appengine"
|
"google.golang.org/appengine"
|
||||||
@@ -22,7 +28,16 @@ func main() {
|
|||||||
directory := flag.String("d", path.Join(exePath, "public"), "the directory of static file to host")
|
directory := flag.String("d", path.Join(exePath, "public"), "the directory of static file to host")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
getIPs()
|
||||||
|
|
||||||
http.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
http.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
/*
|
||||||
|
remoteIP := strings.Split(r.RemoteAddr, ":")[0]
|
||||||
|
if notUSA(remoteIP) {
|
||||||
|
fmt.Println(remoteIP, "NOT USA")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
*/
|
||||||
if r.URL.Scheme == "http" || strings.HasPrefix(r.Host, "http:") {
|
if r.URL.Scheme == "http" || strings.HasPrefix(r.Host, "http:") {
|
||||||
r.URL.Scheme = "https"
|
r.URL.Scheme = "https"
|
||||||
http.Redirect(w, r, r.URL.String(), http.StatusTemporaryRedirect)
|
http.Redirect(w, r, r.URL.String(), http.StatusTemporaryRedirect)
|
||||||
@@ -35,3 +50,87 @@ func main() {
|
|||||||
|
|
||||||
appengine.Main()
|
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)
|
||||||
|
}
|
||||||
|
fmt.Println("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)
|
||||||
|
}
|
||||||
|
fmt.Println("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
|
||||||
|
})
|
||||||
|
fmt.Println(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))
|
||||||
|
}
|
||||||
|
|||||||
33
main_test.go
Normal file
33
main_test.go
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
1
private/ipv4.csv
Executable file
1
private/ipv4.csv
Executable file
@@ -0,0 +1 @@
|
|||||||
|
|
||||||
|
|
1
private/ipv6.csv
Executable file
1
private/ipv6.csv
Executable file
@@ -0,0 +1 @@
|
|||||||
|
|
||||||
|
|
@@ -34,8 +34,8 @@
|
|||||||
<tr><th>Location</th>
|
<tr><th>Location</th>
|
||||||
<td>Provo, UT</td></tr>
|
<td>Provo, UT</td></tr>
|
||||||
<tr><th>Web</th>
|
<tr><th>Web</th>
|
||||||
<td><a href="https://www.blapointe.me">
|
<td><a href="https://www.blapointe.com">
|
||||||
blapointe.me</a></td></tr>
|
blapointe.com</a></td></tr>
|
||||||
<tr><th>LinkedIn</th>
|
<tr><th>LinkedIn</th>
|
||||||
<td><a href="https://www.linkedin.com/in/lapoba16">
|
<td><a href="https://www.linkedin.com/in/lapoba16">
|
||||||
lapoba16</a></td></tr>
|
lapoba16</a></td></tr>
|
||||||
@@ -106,20 +106,15 @@
|
|||||||
<h4>Projects</h4>
|
<h4>Projects</h4>
|
||||||
</div>
|
</div>
|
||||||
<div class="two-thirds column">
|
<div class="two-thirds column">
|
||||||
<div class="timeline-item">
|
|
||||||
<h5>Working Directory</h5>
|
|
||||||
<div class="timeline-item-span">Aug 2018 - Present</div>
|
|
||||||
<p>Synchronizes projects with a remote copy encrypted both at rest and on the wire with concern for bandwidth and authorized access.</p>
|
|
||||||
</div>
|
|
||||||
<div class="timeline-item">
|
<div class="timeline-item">
|
||||||
<h5>RSS Monitor</h5>
|
<h5>RSS Monitor</h5>
|
||||||
<div class="timeline-item-span">May 2018 - Present</div>
|
<div class="timeline-item-span">May 2018 - Aug 2018</div>
|
||||||
<p>Monitors multiple RSS feeds and filters stories by feed. Synchronizes read status and updates feeds via HTTP API.</p>
|
<p>RSS feed aggregator with item and content filtering managed via a RESTful API.</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="timeline-item">
|
<div class="timeline-item">
|
||||||
<h5>"A BCHC genetic algorithm model of cotemporal hierarchical Arabidopsis thaliana gene interactions"</h5>
|
<h5>"A BCHC genetic algorithm model of cotemporal hierarchical Arabidopsis thaliana gene interactions"</h5>
|
||||||
<div class="timeline-item-span">Jan 2017 - Dec 2017</div>
|
<div class="timeline-item-span">Jan 2017 - Dec 2017</div>
|
||||||
<p>Co-authored paper pending publication in IEEE International Conference on Bioinformatics and Biomedicine.</p>
|
<p><a href=https://www.computer.org/csdl/proceedings/bibm/2018/5488/00/08621198-abs.html">Published in 2018 IEEE International Conference on Bioinformatics and Biomedicine.</a></p>
|
||||||
</div>
|
</div>
|
||||||
<div class="timeline-item">
|
<div class="timeline-item">
|
||||||
<h5>Knapsack Problem Genetic Algorithm</h5>
|
<h5>Knapsack Problem Genetic Algorithm</h5>
|
||||||
|
|||||||
Reference in New Issue
Block a user