make it possible to just import it and use it in another app

This commit is contained in:
idk
2020-09-06 16:55:22 -04:00
parent 3d5c7fe9c1
commit d7055ec1f4
9 changed files with 155 additions and 111 deletions

View File

@ -2,6 +2,8 @@
export GO111MODULE=on
GO111MODULE=on
BIN_NAME=i2pbrowser
EXT_VERSION=0.73
SNOW_VERSION=0.2.2
UMAT_VERSION=1.25.2

2
go.mod
View File

@ -4,7 +4,7 @@ go 1.14
require (
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
github.com/eyedeekay/GingerShrew v0.0.0-20200824044622-7e8d465550e5
github.com/eyedeekay/GingerShrew v0.0.0-20200828154258-d799f84952aa
github.com/eyedeekay/I2P-Configuration-for-Chromium v0.0.0-20200802063209-8973270c836e
github.com/eyedeekay/go-fpw v0.0.0-20200805184710-5435dc443213
github.com/eyedeekay/httptunnel v0.0.0-20200116022455-631ab90f707d

4
go.sum
View File

@ -107,6 +107,10 @@ github.com/eyedeekay/GingerShrew v0.0.0-20200702210346-bb2ed34c11fb h1:tUfxSHBVa
github.com/eyedeekay/GingerShrew v0.0.0-20200702210346-bb2ed34c11fb/go.mod h1:PY7znvZ1ZF1QG5/4j9u769EX49l49z2rCdE0o4z8fMw=
github.com/eyedeekay/GingerShrew v0.0.0-20200823015403-11c67f550c33 h1:VD2HttHlFt6wfTjkbJMt/M/pmQT8Iq0I7CmEG81dwVM=
github.com/eyedeekay/GingerShrew v0.0.0-20200823015403-11c67f550c33/go.mod h1:kDfSkqEyzswi8r4m6U0Q9jD4PJqOzKXVCX4XbYhBJCs=
github.com/eyedeekay/GingerShrew v0.0.0-20200824044622-7e8d465550e5 h1:vUDYV/R8RNo7cxVN4ftdrXa9zsGQ74Bot5E/LMndhv0=
github.com/eyedeekay/GingerShrew v0.0.0-20200824044622-7e8d465550e5/go.mod h1:kDfSkqEyzswi8r4m6U0Q9jD4PJqOzKXVCX4XbYhBJCs=
github.com/eyedeekay/GingerShrew v0.0.0-20200828154258-d799f84952aa h1:wqjB9kcYjAMrw92QxZnbAbdMsfF0FSPq9vsKx98XWrU=
github.com/eyedeekay/GingerShrew v0.0.0-20200828154258-d799f84952aa/go.mod h1:kDfSkqEyzswi8r4m6U0Q9jD4PJqOzKXVCX4XbYhBJCs=
github.com/eyedeekay/I2P-Configuration-for-Chromium v0.0.0-20200802063209-8973270c836e h1:oEoiXkil4L/ahtVlljDwz5LXbE1qBsJqvC3/utNrKe4=
github.com/eyedeekay/I2P-Configuration-for-Chromium v0.0.0-20200802063209-8973270c836e/go.mod h1:XchhjbeZKhEszN64SHavfaLGP2lFhWeO0ipH4cyBq5o=
github.com/eyedeekay/checki2cp v0.0.15 h1:Vlwp9opuQJSgp139VVrLkKXRwLYYrXiBkqed35ZbqzY=

View File

@ -1,4 +1,4 @@
package main
package i2pbrowser
/*
Released under the The MIT License (MIT)

View File

@ -1,6 +1,6 @@
//+build generate
package main
package i2pbrowser
/*
Released under the The MIT License (MIT)

View File

@ -1,4 +1,4 @@
package main
package i2pbrowser
/*
Released under the The MIT License (MIT)

View File

@ -1,4 +1,4 @@
package main
package i2pbrowser
/*
Released under the The MIT License (MIT)

142
import/import.go Normal file
View File

@ -0,0 +1,142 @@
//go:generate go run -tags generate gen.go extensions.go
/*
Released under the The MIT License (MIT)
see ./LICENSE
*/
package i2pbrowser
import (
"context"
"flag"
"fmt"
"log"
"net"
"net/http"
"os"
"path/filepath"
"runtime"
"time"
"github.com/eyedeekay/GingerShrew/import"
. "github.com/eyedeekay/go-fpw"
. "github.com/eyedeekay/i2pbrowser/lib"
"github.com/eyedeekay/zerobundle"
)
type handler struct {
}
func (h *handler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
fmt.Fprintf(w, "hello\n")
/*In the future, we may use this as a sort of loopback for privately testing the browser
fingerprint. At first this will be 100% user-initiated, but it may be useful to query such
a service periodically, in order to inform the user when a fingerprint change has occurred
and prompt them to potentially re-set their browser to it's original state.
for name, headers := range req.Header {
for _, h := range headers {
fmt.Fprintf(w, "%v: %v\n", name, h)
}
}*/
}
func hello() error {
server := &http.Server{Addr: "localhost:", Handler: &handler{}}
go func() {
if err := server.ListenAndServe(); err != nil {
log.Println(err)
}
}()
// Setting up signal capturing
// stop := make(chan os.Signal, 1)
// signal.Notify(stop, os.Interrupt)
// Waiting for SIGINT (pkill -2)
// <-stop
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := server.Shutdown(ctx); err != nil {
log.Println(err)
}
return nil
}
func proxyCheck() bool {
conn, err := net.Dial("tcp4", "localhost:4444")
log.Println("Doing dial check")
if err != nil {
return false
}
log.Println("Dial check true, proxy is up")
defer conn.Close()
return true
}
func Main() {
if err := hello(); err != nil {
log.Fatal(err)
}
chromium := flag.Bool("chromium", false, "use a chromium-based browser instead of a firefox-based browser.")
flag.Parse()
ARGS = append(ARGS, flag.Args()...)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
if runtime.GOOS == "linux" {
if !*chromium {
if os.Getenv("FIREFOX_BIN") == "" {
if err := gingershrew.UnpackTBZ(GingerDir); err != nil {
log.Fatal("Error unpacking embedded browser")
} else {
os.Setenv("LD_LIBRARY_PATH", filepath.Join(GingerDir, "lib/x86_64-linux-gnu")+","+filepath.Join(GingerDir, "usr/lib/x86_64-linux-gnu"))
log.Println("LD_LIBRARY_PATH", filepath.Join(GingerDir, "lib/x86_64-linux-gnu")+","+filepath.Join(GingerDir, "usr/lib/x86_64-linux-gnu"))
os.Setenv("FIREFOX_BIN", filepath.Join(GingerDir, "gingershrew", "gingershrew"))
}
}
}
} else {
if LocateFirefox() == "" {
*chromium = true
}
}
if err := WriteI2CPConf(); err != nil {
log.Println(err)
}
if err := zerobundle.ZeroMain(); err != nil {
log.Println(err)
}
time.Sleep(time.Second * 2)
if !proxyCheck() {
go proxyMain(ctx)
}
if !*chromium {
firefoxMain()
} else {
chromiumMain()
}
}
func MainNoEmbeddedStuff() {
if err := hello(); err != nil {
log.Fatal(err)
}
chromium := false
ARGS = append(ARGS, flag.Args()...)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
if LocateFirefox() == "" {
chromium = true
}
if !proxyCheck() {
go proxyMain(ctx)
}
if !chromium {
firefoxMain()
} else {
chromiumMain()
}
}

108
main.go
View File

@ -8,113 +8,9 @@ see ./LICENSE
package main
import (
"context"
"flag"
"fmt"
"log"
"net"
"net/http"
"os"
"path/filepath"
"runtime"
"time"
"github.com/eyedeekay/GingerShrew/import"
. "github.com/eyedeekay/go-fpw"
. "github.com/eyedeekay/i2pbrowser/lib"
"github.com/eyedeekay/zerobundle"
. "github.com/eyedeekay/i2pbrowser/import"
)
type handler struct {
}
func (h *handler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
fmt.Fprintf(w, "hello\n")
/*In the future, we may use this as a sort of loopback for privately testing the browser
fingerprint. At first this will be 100% user-initiated, but it may be useful to query such
a service periodically, in order to inform the user when a fingerprint change has occurred
and prompt them to potentially re-set their browser to it's original state.
for name, headers := range req.Header {
for _, h := range headers {
fmt.Fprintf(w, "%v: %v\n", name, h)
}
}*/
}
func hello() error {
server := &http.Server{Addr: "localhost:", Handler: &handler{}}
go func() {
if err := server.ListenAndServe(); err != nil {
log.Println(err)
}
}()
// Setting up signal capturing
// stop := make(chan os.Signal, 1)
// signal.Notify(stop, os.Interrupt)
// Waiting for SIGINT (pkill -2)
// <-stop
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := server.Shutdown(ctx); err != nil {
log.Println(err)
}
return nil
}
func proxyCheck() bool {
conn, err := net.Dial("tcp4", "localhost:4444")
log.Println("Doing dial check")
if err != nil {
return false
}
log.Println("Dial check true, proxy is up")
defer conn.Close()
return true
}
func main() {
if err := hello(); err != nil {
log.Fatal(err)
}
chromium := flag.Bool("chromium", false, "use a chromium-based browser instead of a firefox-based browser.")
flag.Parse()
ARGS = append(ARGS, flag.Args()...)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
if runtime.GOOS == "linux" {
if !*chromium {
if os.Getenv("FIREFOX_BIN") == "" {
if err := gingershrew.UnpackTBZ(GingerDir); err != nil {
log.Fatal("Error unpacking embedded browser")
} else {
os.Setenv("LD_LIBRARY_PATH", filepath.Join(GingerDir, "x86_64-linux-gnu"))
log.Println("LD_LIBRARY_PATH", filepath.Join(GingerDir, "x86_64-linux-gnu"))
os.Setenv("FIREFOX_BIN", filepath.Join(GingerDir, "gingershrew", "gingershrew"))
}
}
}
} else {
if LocateFirefox() == "" {
*chromium = true
}
}
if err := WriteI2CPConf(); err != nil {
log.Println(err)
}
if err := zerobundle.ZeroMain(); err != nil {
log.Println(err)
}
time.Sleep(time.Second * 2)
if !proxyCheck() {
go proxyMain(ctx)
}
if !*chromium {
firefoxMain()
} else {
chromiumMain()
}
Main()
}