diff --git a/Makefile b/Makefile index e655e3c..5b557d8 100644 --- a/Makefile +++ b/Makefile @@ -141,6 +141,12 @@ index: @echo "" >> index.html @echo "" >> index.html +tor-browser/unpack/i2p.firefox: + @echo "TODO" + +tor-browser/unpack/i2p.firefox.config: + @echo "TODO" + refresh-tor-keys: clean-tor-keys tor-browser/TPO-signing-key.pub tor-keys: tor-browser/TPO-signing-key.pub diff --git a/main.go b/main.go index d5bfa25..20641c4 100644 --- a/main.go +++ b/main.go @@ -15,6 +15,7 @@ import ( ) //go:embed tor-browser/unpack/i2p.firefox/* +//go:embed tor-browser/unpack/i2p.firefox.config/* //go:embed tor-browser/TPO-signing-key.pub //go:embed garliconion.png //go:embed onion.png @@ -51,6 +52,7 @@ var ( system = flag.String("os", OS(), "OS/arch to download") arch = flag.String("arch", ARCH(), "OS/arch to download") i2pbrowser = flag.Bool("i2pbrowser", false, "Open I2P in Tor Browser") + i2pconfig = flag.Bool("i2pconfig", false, "Open I2P routerconsole in Tor Browser with javscript enabled and non-routerconsole sites disabled") torbrowser = flag.Bool("torbrowser", false, "Open Tor Browser") verbose = flag.Bool("verbose", false, "Verbose output") directory = flag.String("directory", "", "Directory operate in") @@ -140,8 +142,12 @@ func main() { client.Host = *host client.Port = *port client.TBS.Profile = &content + client.TBS.PassThroughArgs = flag.Args() + // log.Fatalf("%s", client.TBS.PassThroughArgs) if *i2pbrowser { client.TBS.RunI2PBWithLang() + } else if *i2pconfig { + client.TBS.RunI2PBAppWithLang() } else if *torbrowser { client.TBS.RunTBWithLang() } else { diff --git a/supervise/supervise.go b/supervise/supervise.go index 60e3431..86cf49a 100644 --- a/supervise/supervise.go +++ b/supervise/supervise.go @@ -30,12 +30,31 @@ func ARCH() string { } type Supervisor struct { - UnpackPath string - Lang string - torcmd *exec.Cmd - tbcmd *exec.Cmd - ibcmd *exec.Cmd - Profile *embed.FS + UnpackPath string + Lang string + torcmd *exec.Cmd + tbcmd *exec.Cmd + ibcmd *exec.Cmd + Profile *embed.FS + PassThroughArgs []string +} + +func (s *Supervisor) PTAS() []string { + // loop over the arguments and make sure that we remove any --profile, -P args + // and blank them out. + var args []string + for index, arg := range s.PassThroughArgs { + if arg == "--profile" || arg == "-P" { + continue + } + if index > 0 { + if s.PassThroughArgs[index-1] == "--profile" || s.PassThroughArgs[index-1] == "-P" { + continue + } + } + args = append(args, arg) + } + return args } func (s *Supervisor) TBPath() string { @@ -118,6 +137,46 @@ func (s *Supervisor) UnpackI2PData() error { }) } +func (s *Supervisor) I2PAppDataPath() string { + fp := s.I2PProfilePath() + up := filepath.Join(filepath.Dir(s.UnpackPath), "i2p.firefox.config") + if tbget.FileExists(up) { + return up + } else { + log.Printf("i2p workdir not found at %s, copying", up) + if s.Profile != nil { + if err := cp.Copy(fp, up); err != nil { + log.Fatal(err) + } + } + return up + } +} + +func (s *Supervisor) UnpackI2PAppData() error { + return fs.WalkDir(s.Profile, ".", func(embedpath string, d fs.DirEntry, err error) error { + fp := filepath.Join(filepath.Dir(s.UnpackPath), ".i2p.firefox.config") + if err != nil { + log.Fatal(err) + } + fmt.Println(embedpath, filepath.Join(fp, strings.Replace(embedpath, "tor-browser/unpack/i2p.firefox.config", "", -1))) + if d.IsDir() { + os.MkdirAll(filepath.Join(fp, strings.Replace(embedpath, "tor-browser/unpack/i2p.firefox.config", "", -1)), 0755) + } else { + fullpath := path.Join(embedpath) + bytes, err := s.Profile.ReadFile(fullpath) + if err != nil { + return err + } + unpack := filepath.Join(fp, strings.Replace(embedpath, "tor-browser/unpack/i2p.firefox.config", "", -1)) + if err := ioutil.WriteFile(unpack, bytes, 0644); err != nil { + return err + } + } + return nil + }) +} + func (s *Supervisor) tbbail() error { if s.tbcmd != nil && s.tbcmd.Process != nil && s.tbcmd.ProcessState != nil { if s.tbcmd.ProcessState.Exited() { @@ -146,7 +205,9 @@ func (s *Supervisor) RunTBWithLang() error { case "linux": if tbget.FileExists(s.UnpackPath) { log.Println("running tor browser with lang", s.Lang, s.UnpackPath) - s.tbcmd = exec.Command(s.TBPath()) + args := []string{} + args = append(args, s.PTAS()...) + s.tbcmd = exec.Command(s.TBPath(), args...) s.tbcmd.Stdout = os.Stdout s.tbcmd.Stderr = os.Stderr return s.tbcmd.Run() @@ -160,7 +221,9 @@ func (s *Supervisor) RunTBWithLang() error { return s.tbcmd.Run() case "win": log.Println("Running Windows EXE", s.TBDirectory(), "firefox.exe") - s.tbcmd = exec.Command(filepath.Join(s.TBDirectory(), "firefox.exe")) + args := []string{} + args = append(args, s.PTAS()...) + s.tbcmd = exec.Command(filepath.Join(s.TBDirectory(), "firefox.exe"), args...) s.tbcmd.Dir = s.TBDirectory() return s.tbcmd.Run() default: @@ -197,7 +260,9 @@ func (s *Supervisor) RunI2PBWithLang() error { case "linux": if tbget.FileExists(s.UnpackPath) { log.Println("running Tor browser with lang and I2P Profile", s.Lang, s.UnpackPath, s.FirefoxPath(), "--profile", s.I2PDataPath()) - s.ibcmd = exec.Command(s.FirefoxPath(), "--profile", s.I2PDataPath()) + args := []string{"--profile", s.I2PDataPath()} + args = append(args, s.PTAS()...) + s.ibcmd = exec.Command(s.FirefoxPath(), args...) s.ibcmd.Stdout = os.Stdout s.ibcmd.Stderr = os.Stderr return s.ibcmd.Run() @@ -211,7 +276,9 @@ func (s *Supervisor) RunI2PBWithLang() error { return s.ibcmd.Run() case "win": log.Println("Running Windows EXE", filepath.Join(s.TBDirectory(), "firefox.exe"), "--profile", s.I2PDataPath()) - s.ibcmd = exec.Command(filepath.Join(s.TBDirectory(), "firefox.exe"), "--profile", ".") + args := []string{"--profile", "."} + args = append(args, s.PTAS()...) + s.ibcmd = exec.Command(filepath.Join(s.TBDirectory(), "firefox.exe"), args...) s.ibcmd.Dir = s.I2PDataPath() s.ibcmd.Stdout = os.Stdout s.ibcmd.Stderr = os.Stderr @@ -222,6 +289,53 @@ func (s *Supervisor) RunI2PBWithLang() error { return nil } +func (s *Supervisor) RunI2PBAppWithLang() error { + tbget.ARCH = ARCH() + if s.Lang == "" { + s.Lang = DEFAULT_TB_LANG + } + if s.UnpackPath == "" { + s.UnpackPath = UNPACK_URL() + } + + if s.ibbail() != nil { + return nil + } + + log.Println("running i2p in tor browser with lang", s.Lang, s.UnpackPath, OS()) + switch OS() { + case "linux": + if tbget.FileExists(s.UnpackPath) { + log.Println("running Tor browser with lang and I2P Profile", s.Lang, s.UnpackPath, s.FirefoxPath(), "--profile", s.I2PAppDataPath()) + args := []string{"--profile", s.I2PAppDataPath()} + args = append(args, s.PTAS()...) + s.ibcmd = exec.Command(s.FirefoxPath(), args...) + s.ibcmd.Stdout = os.Stdout + s.ibcmd.Stderr = os.Stderr + return s.ibcmd.Run() + } else { + log.Println("tor browser not found at", s.FirefoxPath()) + return fmt.Errorf("tor browser not found at %s", s.FirefoxPath()) + } + case "darwin": + s.ibcmd = exec.Command("/usr/bin/env", "open", "-a", "\"Tor Browser.app\"") + s.ibcmd.Dir = s.TBDirectory() + return s.ibcmd.Run() + case "win": + log.Println("Running Windows EXE", filepath.Join(s.TBDirectory(), "firefox.exe"), "--profile", s.I2PAppDataPath()) + args := []string{"--profile", "."} + args = append(args, s.PTAS()...) + s.ibcmd = exec.Command(filepath.Join(s.TBDirectory(), "firefox.exe"), args...) + s.ibcmd.Dir = s.I2PAppDataPath() + s.ibcmd.Stdout = os.Stdout + s.ibcmd.Stderr = os.Stderr + return s.ibcmd.Run() + default: + } + + return nil +} + func (s *Supervisor) torbail() error { _, err := net.Listen("tcp", "127.0.0.1:9050") if err != nil {