From b16b9cea714b66a689880a4439d0a1a29bd73d2d Mon Sep 17 00:00:00 2001 From: idk Date: Mon, 28 Feb 2022 19:59:47 -0500 Subject: [PATCH] early-run tor, enable onion site --- Makefile | 21 +++++++++++++++++++++ ONION.md | 26 ++++++++++++++++++++++++++ main.go | 5 ++++- onion/onion.go | 44 ++++++++++++++++++++++++++++++++++++++++++-- onion/www/index.html | 29 ++++++++++++++++++++++++++++- serve/serve.go | 5 +++++ 6 files changed, 126 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 3e1dda7..5de9fd4 100644 --- a/Makefile +++ b/Makefile @@ -185,6 +185,27 @@ index-offline: @echo "" >> offline.html @echo "" >> offline.html +index-onion: + @echo "" > onion/www/index.html + @echo "" >> onion/www/index.html + @echo "" >> onion/www/index.html + @echo " $(BINARY) - $(CONSOLEPOSTNAME)" >> onion/www/index.html + @echo " " >> onion/www/index.html + @echo " " >> onion/www/index.html + @echo " " >> onion/www/index.html + @echo " " >> onion/www/index.html + @echo " " >> onion/www/index.html + @echo " " >> onion/www/index.html + @echo " " >> onion/www/index.html + @echo " " >> onion/www/index.html + @echo " " >> onion/www/index.html + @echo " " >> onion/www/index.html + @echo "" >> onion/www/index.html + @echo "" >> onion/www/index.html + pandoc ONION.md >> onion/www/index.html + @echo "" >> onion/www/index.html + @echo "" >> onion/www/index.html + tor-browser/unpack/i2p.firefox: @echo "TODO" diff --git a/ONION.md b/ONION.md index e69de29..f280d4b 100644 --- a/ONION.md +++ b/ONION.md @@ -0,0 +1,26 @@ +Hello from I2P, OnionSpace! Thought I'd try to do something we'd both enjoy +=========================================================================== + +This `.onion` site corresponds to an I2P user who is helping to distribute +the Tor Browser bundle in a somewhat unique way. These users have downloaded +the Tor Browser for their platform, and they have chosen to share it over +I2P, using both the I2P Web and I2P Bittorrent. The goal is twofold, to provide +a large number of ad-hoc mirrors of the latest offical Tor Browser Bundle, and +provide a means for I2P users to download and configure the Tor Browser without +initially retrieving Tor over the clearnet. + +I2P is another anonymous network, it works slightly differently than Tor, it's +designed in such a way that every router in the network is also a relay. This +has advantages and disadvantages, which is why we try to encourage people to +consider I2P and Tor separate, complementary, and not necessarily competitive +tools. I2P can be quite good at distributing Tor and Tor Browser, and Tor Browser +can be an effective tool for browsing I2P. + +[Want to learn more about I2P? Visit our website(Clearnet link)](https://geti2p.net) +------------------------------------------------------------------------------------ + +- The author of this software is an I2P developer, `idk`. [You can see some of his other projects here(I2P Link)](http://idk.i2p) +- I2P has many applications. One of the most popular is MuWire, by zlatinb. [MuWire is available here(Clearnet link)](https://muwire.com) + and [here(I2P Link)](http://muwire.i2p). +- Want to discuss I2P? Join us on [Reddit](https://old.reddit.com/r/i2p), [Our community forums](http://i2pforum.i2p), or our [Developer forums](http://zzz.i2p). +- Want to work on I2P or use I2P in your application? Join us at [i2pgit.org](https://i2pgit.org), [git.idk.i2p](http://git.idk.i2p), or [our Github](https://github.com/i2p) diff --git a/main.go b/main.go index c1bfb3d..d593e8e 100644 --- a/main.go +++ b/main.go @@ -246,7 +246,7 @@ func main() { log.Fatal(err) } } - + client.TBS.RunTorWithLang() if *i2pbrowser { if err := client.TBS.RunI2PBWithLang(); err != nil { log.Fatal(err) @@ -273,6 +273,9 @@ func main() { if *bemirror { go client.TBD.Serve() } + if *solidarity { + go client.Onion.ListenAndServe() + } go runSysTray(false) if err := client.Serve(); err != nil { log.Fatal(err) diff --git a/onion/onion.go b/onion/onion.go index 285ceff..02b9952 100644 --- a/onion/onion.go +++ b/onion/onion.go @@ -2,27 +2,36 @@ package i2pdotonion import ( "context" + "embed" "fmt" + "io/fs" + "io/ioutil" "log" "net" "net/http" "os" "path" "path/filepath" + "strings" "time" "github.com/cretz/bine/tor" ) //go:embded www/* +var content embed.FS type I2POnionService struct { OnionService net.Listener ServeDir string } -func NewOnionService(dir string) *I2POnionService { - return &I2POnionService{ServeDir: dir} +func NewOnionService(dir string) (*I2POnionService, error) { + ios := &I2POnionService{ServeDir: dir} + if err := ios.UnpackSite(); err != nil { + return nil, err + } + return ios, nil } func (ios *I2POnionService) ServeHTTP(w http.ResponseWriter, r *http.Request) { @@ -80,3 +89,34 @@ func (ios *I2POnionService) ListenAndServe() error { } return http.Serve(ios.OnionService, ios) } + +func (ios *I2POnionService) UnpackSite() error { + docroot := filepath.Join(ios.ServeDir, "www") + os.MkdirAll(docroot, 0755) + if dir, err := os.Stat(docroot); err == nil && dir.IsDir() { + return nil + } + //unpack the contents to the docroot + return fs.WalkDir(content, ".", func(embedpath string, d fs.DirEntry, err error) error { + fp := filepath.Join(docroot) + if err != nil { + log.Fatal(err) + } + fmt.Println(embedpath, filepath.Join(fp, strings.Replace(embedpath, "tor-browser/unpack/i2p.firefox", "", -1))) + if d.IsDir() { + os.MkdirAll(filepath.Join(fp, strings.Replace(embedpath, "tor-browser/unpack/i2p.firefox", "", -1)), 0755) + } else { + fullpath := path.Join(embedpath) + bytes, err := content.ReadFile(fullpath) + if err != nil { + return err + } + unpack := filepath.Join(fp, strings.Replace(embedpath, "tor-browser/unpack/i2p.firefox", "", -1)) + if err := ioutil.WriteFile(unpack, bytes, 0644); err != nil { + return err + } + } + return nil + }) + +} diff --git a/onion/www/index.html b/onion/www/index.html index d039ef0..e7c6564 100644 --- a/onion/www/index.html +++ b/onion/www/index.html @@ -1 +1,28 @@ -Hello from I2P, OnionSpace! Thought I'd try to do something we'd both enjoy. \ No newline at end of file + + + + i2p.plugins.tor-manager - Tor Binary Manager + + + + + + + + + + + + +

Hello from I2P, OnionSpace! Thought I’d try to do something we’d both enjoy

+

This .onion site corresponds to an I2P user who is helping to distribute the Tor Browser bundle in a somewhat unique way. These users have downloaded the Tor Browser for their platform, and they have chosen to share it over I2P, using both the I2P Web and I2P Bittorrent. The goal is twofold, to provide a large number of ad-hoc mirrors of the latest offical Tor Browser Bundle, and provide a means for I2P users to download and configure the Tor Browser without initially retrieving Tor over the clearnet.

+

I2P is another anonymous network, it works slightly differently than Tor, it’s designed in such a way that every router in the network is also a relay. This has advantages and disadvantages, which is why we try to encourage people to consider I2P and Tor separate, complementary, and not necessarily competitive tools. I2P can be quite good at distributing Tor and Tor Browser, and Tor Browser can be an effective tool for browsing I2P.

+ + + + diff --git a/serve/serve.go b/serve/serve.go index abe1611..9f01a18 100644 --- a/serve/serve.go +++ b/serve/serve.go @@ -38,6 +38,11 @@ func NewClient(verbose bool, lang, os, arch, mirror string, content *embed.FS) ( m.TBD.Mirror = mirror m.TBD.Verbose = verbose m.TBD.MakeTBDirectory() + var err error + m.Onion, err = i2pdotonion.NewOnionService(m.TBD.DownloadPath) + if err != nil { + return nil, err + } tgz, sig, err := m.TBD.DownloadUpdaterForLang(lang) if err != nil { panic(err)