add templater

This commit is contained in:
idk
2022-01-22 00:42:10 -05:00
parent 239aef0bba
commit 1071b0e774
3 changed files with 21 additions and 8 deletions

View File

@ -33,7 +33,7 @@ func main() {
if err != nil { if err != nil {
log.Fatal("Couldn't create client", err) log.Fatal("Couldn't create client", err)
} }
if err := client.TBS.RunI2PBWithLang(); err != nil { if err := client.Serve(); err != nil {
log.Fatal(err) log.Fatal(err)
} }
} }

View File

@ -38,13 +38,17 @@ func NewClient(hostname string, lang string, os string, arch string) (*Client, e
return m, nil return m, nil
} }
func (m *Client) ServeHTTP(rw http.ResponseWriter, rq http.Request) { func (m *Client) ServeHTTP(rw http.ResponseWriter, rq *http.Request) {
path := rq.URL.Path path := rq.URL.Path
switch path { switch path {
case "/start-tor-browser": case "/start-tor-browser":
m.TBS.RunTBWithLang()
case "/start-i2p-browser": case "/start-i2p-browser":
m.TBS.RunI2PBWithLang()
case "/start-tor": case "/start-tor":
m.TBS.RunTorWithLang()
case "/stop-tor": case "/stop-tor":
m.TBS.StopTor()
default: default:
b, e := m.Page() b, e := m.Page()
if e != nil { if e != nil {
@ -55,6 +59,11 @@ func (m *Client) ServeHTTP(rw http.ResponseWriter, rq http.Request) {
rw.Write([]byte("Hello, world!")) rw.Write([]byte("Hello, world!"))
} }
func (m *Client) Serve() error {
//http.Handle("/", m)
return http.ListenAndServe("127.0.0.1:7695", m)
}
func (m *Client) generateMirrorJSON() (map[string]interface{}, error) { func (m *Client) generateMirrorJSON() (map[string]interface{}, error) {
if !strings.HasSuffix(m.hostname, "/") { if !strings.HasSuffix(m.hostname, "/") {
m.hostname += "/" m.hostname += "/"

View File

@ -145,19 +145,23 @@ func (s *Supervisor) RunTorWithLang() error {
return fmt.Errorf("tor not found at %s", s.TorPath()) return fmt.Errorf("tor not found at %s", s.TorPath())
} }
case "darwin": case "darwin":
cmd := exec.Command("/usr/bin/env", "open", "-a", "\"Tor Browser.app\"") s.cmd = exec.Command("/usr/bin/env", "open", "-a", "\"Tor Browser.app\"")
cmd.Dir = s.TBDirectory() s.cmd.Dir = s.TBDirectory()
return cmd.Run() return s.cmd.Run()
case "windows": case "windows":
cmd := exec.Command("cmd", "/c", "start", "\""+s.TBDirectory()+"\"", "\"Tor Browser.exe\"") s.cmd = exec.Command("cmd", "/c", "start", "\""+s.TBDirectory()+"\"", "\"Tor Browser.exe\"")
cmd.Dir = s.TBDirectory() s.cmd.Dir = s.TBDirectory()
return cmd.Run() return s.cmd.Run()
default: default:
} }
return nil return nil
} }
func (s *Supervisor) StopTor() error {
return s.cmd.Process.Kill()
}
func NewSupervisor(tbPath, lang string) *Supervisor { func NewSupervisor(tbPath, lang string) *Supervisor {
return &Supervisor{ return &Supervisor{
UnpackPath: tbPath, UnpackPath: tbPath,