|
|
@ -8,7 +8,6 @@ import (
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/gorilla/websocket"
|
|
|
|
"github.com/gorilla/websocket"
|
|
|
|
"github.com/lqqyt2423/go-mitmproxy/flow"
|
|
|
|
"github.com/lqqyt2423/go-mitmproxy/flow"
|
|
|
|
uuid "github.com/satori/go.uuid"
|
|
|
|
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
@ -56,6 +55,18 @@ type WebAddon struct {
|
|
|
|
connsMu sync.RWMutex
|
|
|
|
connsMu sync.RWMutex
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type message struct {
|
|
|
|
|
|
|
|
On string `json:"on"`
|
|
|
|
|
|
|
|
Flow *flow.Flow `json:"flow"`
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func newMessage(on string, f *flow.Flow) *message {
|
|
|
|
|
|
|
|
return &message{
|
|
|
|
|
|
|
|
On: on,
|
|
|
|
|
|
|
|
Flow: f,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewWebAddon() *WebAddon {
|
|
|
|
func NewWebAddon() *WebAddon {
|
|
|
|
web := new(WebAddon)
|
|
|
|
web := new(WebAddon)
|
|
|
|
web.addr = ":9081"
|
|
|
|
web.addr = ":9081"
|
|
|
@ -102,27 +113,32 @@ func (web *WebAddon) removeConn(conn *websocket.Conn) {
|
|
|
|
web.conns = append(web.conns[:index], web.conns[index+1:]...)
|
|
|
|
web.conns = append(web.conns[:index], web.conns[index+1:]...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (web *WebAddon) Request(f *flow.Flow) {
|
|
|
|
func (web *WebAddon) sendFlow(on string, f *flow.Flow) {
|
|
|
|
b, err := json.Marshal(f)
|
|
|
|
web.connsMu.RLock()
|
|
|
|
if err != nil {
|
|
|
|
conns := web.conns
|
|
|
|
web.log.Error(err)
|
|
|
|
web.connsMu.RUnlock()
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
id := uuid.NewV4()
|
|
|
|
if len(conns) == 0 {
|
|
|
|
f.State["id"] = id
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
web.log.Infof("id: %s, request: %s\n", id, b)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (web *WebAddon) Response(f *flow.Flow) {
|
|
|
|
msg := newMessage(on, f)
|
|
|
|
b, err := json.Marshal(f)
|
|
|
|
b, err := json.Marshal(msg)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
web.log.Error(err)
|
|
|
|
web.log.Error(err)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, c := range conns {
|
|
|
|
|
|
|
|
c.WriteMessage(websocket.TextMessage, b)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
web.log.Infof("id: %s, response: %s\n", f.State["id"], b)
|
|
|
|
func (web *WebAddon) Request(f *flow.Flow) {
|
|
|
|
|
|
|
|
web.sendFlow("request", f)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (web *WebAddon) Response(f *flow.Flow) {
|
|
|
|
|
|
|
|
web.sendFlow("response", f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var homeTemplate = template.Must(template.New("").Parse(`
|
|
|
|
var homeTemplate = template.Must(template.New("").Parse(`
|
|
|
|