From e686e4d434bb52f3d452df8e9f793c336381a5e3 Mon Sep 17 00:00:00 2001 From: halulu Date: Wed, 28 Nov 2018 12:58:19 +0800 Subject: [PATCH] remove web server --- server/app.go | 94 ------------------- server/login.go | 36 -------- server/mux.go | 89 ------------------ server/web.go | 86 ------------------ templates/base/base.html | 22 ----- templates/client/client.html | 171 ----------------------------------- templates/home.html | 52 ----------- templates/server/login.html | 43 --------- templates/server/server.html | 126 -------------------------- websocks.go | 45 ++------- 10 files changed, 8 insertions(+), 756 deletions(-) delete mode 100644 server/app.go delete mode 100644 server/login.go delete mode 100644 server/mux.go delete mode 100644 server/web.go delete mode 100644 templates/base/base.html delete mode 100644 templates/client/client.html delete mode 100644 templates/home.html delete mode 100644 templates/server/login.html delete mode 100644 templates/server/server.html diff --git a/server/app.go b/server/app.go deleted file mode 100644 index 7738e46..0000000 --- a/server/app.go +++ /dev/null @@ -1,94 +0,0 @@ -package server - -import ( - "crypto/tls" - "net/http" - - "encoding/json" - "io/ioutil" - - "github.com/gorilla/sessions" - "gopkg.in/macaron.v1" -) - -type App struct { - //todo multiple servers - *WebSocksServer - - WebListenAddr string - TLS bool - CertPath string - KeyPath string - - s http.Server - store sessions.Store - m *macaron.Macaron -} - -func LoadApp() (app *App, err error) { - app = &App{} - data, err := ioutil.ReadFile("server.json") - if err != nil { - return - } - - err = json.Unmarshal(data, app) - if err != nil { - return - } - return -} - -func NewApp() (app *App) { - app = &App{ - WebListenAddr: ":23333", - TLS: false, - CertPath: "websocks.cer", - KeyPath: "websocks.key", - } - return -} - -func (app *App) Save() (err error) { - data, err := json.MarshalIndent(app, "", " ") - if err != nil { - return - } - - err = ioutil.WriteFile("server.json", data, 0600) - return -} - -func (app *App) Run() (err error) { - m := app.Macaron() - app.m = m - app.s = http.Server{ - Addr: app.WebListenAddr, - Handler: m, - } - - if !app.TLS { - err = app.s.ListenAndServe() - if err != nil { - return - } - return - } - - app.s.TLSConfig = &tls.Config{ - CipherSuites: []uint16{ - tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305, - tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305, - tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, - tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, - tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, - tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, - }, - } - - err = app.s.ListenAndServeTLS(app.CertPath, app.KeyPath) - if err != nil { - return err - } - return -} diff --git a/server/login.go b/server/login.go deleted file mode 100644 index d4b26fa..0000000 --- a/server/login.go +++ /dev/null @@ -1,36 +0,0 @@ -package server - -import ( - "encoding/json" - "io/ioutil" - - "gopkg.in/macaron.v1" -) - -type Login struct { - Name string - Password string -} - -func (app *App) Login(ctx *macaron.Context) { - l := &Login{} - data, err := ioutil.ReadAll(ctx.Req.Body().ReadCloser()) - if err != nil { - ctx.Error(403, err.Error()) - } - - err = json.Unmarshal(data, l) - if err != nil { - ctx.Error(403, err.Error()) - } - - if l.Name == "halulu" && l.Password == "websocks" { - session, _ := app.store.Get(ctx.Req.Request, "cookie") - session.Values["authenticated"] = true - session.Save(ctx.Req.Request, ctx) - ctx.HTML(200, "ok") - return - } - - ctx.Error(403, "not halulu") -} diff --git a/server/mux.go b/server/mux.go deleted file mode 100644 index 7ba9405..0000000 --- a/server/mux.go +++ /dev/null @@ -1,89 +0,0 @@ -package server - -//import ( -// "errors" -// "fmt" -// "net" -// "time" -//) -// -//func (muxWS *MuxWebSocket) ServerListen() { -// //block and listen -// for { -// m, err := muxWS.ReceiveMessage() -// if err != nil { -// logger.Debugf(err.Error()) -// return -// } -// -// go muxWS.ServerHandleMessage(m) -// } -// return -//} -// -//func (muxWS *MuxWebSocket) ServerHandleMessage(m *Message) { -// //check message -// if m.Data == nil { -// return -// } -// -// //accept new conn -// if m.Method == MessageMethodDial { -// conn, host, err := muxWS.AcceptMuxConn(m) -// if err != nil { -// logger.Debugf(err.Error()) -// return -// } -// -// tcpAddr, err := net.ResolveTCPAddr("tcp", host) -// if err != nil { -// logger.Debugf(err.Error()) -// return -// } -// -// tcpConn, err := net.DialTCP("tcp", nil, tcpAddr) -// if err != nil { -// logger.Debugf(err.Error()) -// return -// } -// -// logger.Debugf("Accepted mux conn %s", host) -// -// conn.Run(tcpConn) -// return -// } -// -// //get conn and send message -// conn := muxWS.GetMuxConn(m.ConnID) -// if conn == nil { -// time.Sleep(time.Second) -// conn = muxWS.GetMuxConn(m.ConnID) -// if conn == nil { -// logger.Debugf("conn %d do not exist", m.ConnID) -// return -// } -// } -// err := conn.HandleMessage(m) -// if err != nil { -// logger.Debugf(err.Error()) -// return -// } -//} -// -//func (muxWS *MuxWebSocket) AcceptMuxConn(m *Message) (conn *MuxConn, host string, err error) { -// if m.Method != MessageMethodDial { -// err = errors.New(fmt.Sprintf("wrong message method %d", m.Method)) -// return -// } -// -// host = string(m.Data) -// -// conn = &MuxConn{ -// ID: m.ConnID, -// MuxWS: muxWS, -// wait: make(chan int), -// sendMessageID: new(uint64), -// } -// muxWS.PutMuxConn(conn) -// return -//} diff --git a/server/web.go b/server/web.go deleted file mode 100644 index 52b2186..0000000 --- a/server/web.go +++ /dev/null @@ -1,86 +0,0 @@ -package server - -import ( - "encoding/json" - "io/ioutil" - "log" - "os/exec" - - "github.com/go-macaron/pongo2" - "github.com/gorilla/sessions" - "gopkg.in/macaron.v1" -) - -func (app *App) Macaron() (m *macaron.Macaron) { - app.store = sessions.NewCookieStore([]byte("just a test")) - - m = macaron.New() - m.Use(pongo2.Pongoer()) - - //login check - m.Use(func(ctx *macaron.Context) { - if ctx.Req.RequestURI != "" { - - } - - session, _ := app.store.Get(ctx.Req.Request, "cookie") - if auth, ok := session.Values["authenticated"].(bool); !ok || !auth { - ctx.Error(403, "not halulu") - return - } - }) - - m.Get("/", func(ctx *macaron.Context) { - ctx.HTML(200, "server/server") - }) - - m.Get("/login", func(ctx *macaron.Context) { - ctx.HTML(200, "server/login") - }) - - //api v0 - m.Group("/api/v0/server", func() { - m.Get("/stats", func(ctx *macaron.Context) { - if app.WebSocksServer == nil { - ctx.Error(403, "websocks server is not running") - return - } - - stats := app.Stats - ctx.JSON(200, stats) - }) - m.Post("/start", app.StartServer) - //m.Post("/stop", app.StopServer) - - m.Post("/login", app.Login) - }) - - go func() { - err := exec.Command("explorer", "http://127.0.0.1:23333").Run() - if err != nil { - log.Println(err.Error()) - return - } - }() - - return -} - -func (app *App) StartServer(ctx *macaron.Context) { - config := &Config{} - data, err := ioutil.ReadAll(ctx.Req.Body().ReadCloser()) - if err != nil { - ctx.Error(403, err.Error()) - } - - err = json.Unmarshal(data, config) - if err != nil { - ctx.Error(403, err.Error()) - } - ctx.JSON(200, config) - - webSocksServer := config.GetServer() - app.WebSocksServer = webSocksServer - app.m.Get(webSocksServer.Pattern, webSocksServer.HandleWebSocket) - return -} diff --git a/templates/base/base.html b/templates/base/base.html deleted file mode 100644 index d4c04c0..0000000 --- a/templates/base/base.html +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - WebSocks - - {% block head %} {% endblock %} - - -{% block body %} {% endblock %} - - - - - \ No newline at end of file diff --git a/templates/client/client.html b/templates/client/client.html deleted file mode 100644 index 17da1aa..0000000 --- a/templates/client/client.html +++ /dev/null @@ -1,171 +0,0 @@ -{% extends "base/base.html" %} -{% block head %} - - - -{% endblock %} -{% block body %} -
-
-

- WebSocks Client -

-

- A secure proxy based on WebSocket. -

- -
-
- -
-
-
-
-
-
- -
- -
-
-
- -
- -
-
- -
- -
- -
-
- -
-
- - -
-
-
-
-
-
-

- -

-
-
-

- -

-
-
-
-
-
- -
-
-
-

Client Stats

-
- - - - - - - - - - - - - - - - - -
- Downloaded - - Uploaded - - DownloadSpeed - - UploadSpeed -
- 0 - - 0 - - 0 - - 0 -
-
-
-
-
-
-
-
-

Logs

- -
-
-
-{% endblock %} \ No newline at end of file diff --git a/templates/home.html b/templates/home.html deleted file mode 100644 index 3d9971f..0000000 --- a/templates/home.html +++ /dev/null @@ -1,52 +0,0 @@ -{% extends "base/base.html" %} -{% block body %} -
-
-

- WebSocks -

-

- A secure proxy based on websocket. -

-

- This project is still working in progress, more features are still in - development. If you are interested in this project, please star this project - in order to support me. Thank you. -

-

- If you have any problems or suggestions, please do not hesitate to submit - issues or contact me - - @halulu - - . We also have a - - telegram group - - (mostly Chinese, English is ok). -

- -
-
-{% endblock %} \ No newline at end of file diff --git a/templates/server/login.html b/templates/server/login.html deleted file mode 100644 index 6b60295..0000000 --- a/templates/server/login.html +++ /dev/null @@ -1,43 +0,0 @@ -{% extends "base/base.html" %} -{% block head %} - - -{% endblock %} -{% block body %} -
-
-
-
-

Login

-

Please login to proceed.

-
-
-
- -
-
- -
-
- -
-
- -
-
-
-
-
-{% endblock %} \ No newline at end of file diff --git a/templates/server/server.html b/templates/server/server.html deleted file mode 100644 index 9a34b74..0000000 --- a/templates/server/server.html +++ /dev/null @@ -1,126 +0,0 @@ -{% extends "base/base.html" %} -{% block head %} - - - -{% endblock %} -{% block body %} -
-
-

- WebSocks Server -

-

- A secure proxy based on WebSocket. -

- -
-
- -
-
-
-
-
-
- -
- -
-
-
-
-
-
-

- -

-
-
-

- -

-
-
-
-
-
- -
-
-
-

Server Stats

-
- - - - - - - - - - - - - - - - - -
- Downloaded - - Uploaded - - DownloadSpeed - - UploadSpeed -
- 0 - - 0 - - 0 - - 0 -
-
-
-
-
-{% endblock %} \ No newline at end of file diff --git a/websocks.go b/websocks.go index 903032b..4128070 100644 --- a/websocks.go +++ b/websocks.go @@ -10,7 +10,6 @@ import ( "log" - "github.com/juju/loggo" "github.com/lzjluzijie/websocks/client" "github.com/lzjluzijie/websocks/core" "github.com/lzjluzijie/websocks/server" @@ -18,12 +17,9 @@ import ( ) func main() { - logger := loggo.GetLogger("websocks") - logger.SetLogLevel(loggo.INFO) - app := cli.App{ Name: "WebSocks", - Version: "0.13.2", + Version: "0.14.0", Usage: "A secure proxy based on WebSocket. Click to start web client.", Description: "websocks.org", Author: "Halulu", @@ -32,7 +28,7 @@ func main() { { Name: "client", Aliases: []string{"c"}, - Usage: "start websocks client(cli)", + Usage: "start websocks client", Flags: []cli.Flag{ cli.StringFlag{ Name: "l", @@ -121,7 +117,6 @@ func main() { }, }, Action: func(c *cli.Context) (err error) { - debug := c.GlobalBool("debug") listenAddr := c.String("l") pattern := c.String("p") tls := c.Bool("tls") @@ -129,12 +124,6 @@ func main() { keyPath := c.String("key") reverseProxy := c.String("reverse-proxy") - if debug { - logger.SetLogLevel(loggo.DEBUG) - } - - logger.Infof("Log level %s", logger.LogLevel().String()) - if pattern[0] != '/' { pattern = "/" + pattern } @@ -149,7 +138,7 @@ func main() { } websocksServer := config.GetServer() - logger.Infof("Listening at %s", listenAddr) + log.Printf("Listening at %s", listenAddr) err = websocksServer.Run() if err != nil { return @@ -180,10 +169,10 @@ func main() { var key, cert []byte if ecdsa { key, cert, err = core.GenP256(hosts) - logger.Infof("Generated ecdsa P-256 key and cert") + log.Printf("Generated ecdsa P-256 key and cert") } else { key, cert, err = core.GenRSA2048(hosts) - logger.Infof("Generated rsa 2048 key and cert") + log.Printf("Generated rsa 2048 key and cert") } err = ioutil.WriteFile("websocks.key", key, 0600) @@ -200,7 +189,7 @@ func main() { { Name: "pac", Aliases: []string{"pac"}, - Usage: "set pac for windows", + Usage: "set pac for windows(test)", Action: func(c *cli.Context) (err error) { if runtime.GOOS != "windows" { err = errors.New("not windows") @@ -211,29 +200,11 @@ func main() { return }, }, - { - Name: "webserver", - Aliases: []string{"w"}, - Usage: "web ui server", - Action: func(c *cli.Context) (err error) { - app, err := server.LoadApp() - if err != nil { - log.Println("can not load server.json, create not one") - app = server.NewApp() - err = app.Save() - if err != nil { - log.Printf("save config: %s", err.Error()) - } - } - - err = app.Run() - return - }, - }, }, } + err := app.Run(os.Args) if err != nil { - logger.Errorf(err.Error()) + log.Printf(err.Error()) } }