update log format

This commit is contained in:
xvzc 2022-01-12 03:06:14 +09:00
parent 410dc24eb1
commit 0e11629360
3 changed files with 19 additions and 14 deletions

View File

@ -5,6 +5,7 @@ import (
"os/signal"
"syscall"
"github.com/sirupsen/logrus"
log "github.com/sirupsen/logrus"
"github.com/xvzc/SpoofDPI/doh"
"github.com/xvzc/SpoofDPI/proxy"
@ -22,6 +23,10 @@ func main() {
log.SetLevel(log.InfoLevel)
}
log.SetFormatter(&logrus.TextFormatter{
FullTimestamp: true,
})
util.PrintWelcome(port, dns, debug)
if err := util.SetOsProxy(port); err != nil {

View File

@ -77,7 +77,7 @@ func (lConn *Conn) HandleHttp(p packet.HttpPacket) {
// Create connection to server
rConn, err := Dial("tcp", ip+":80")
if err != nil {
log.Debug(err)
log.Debug("[HTTPS] ", err)
return
}
defer rConn.Close()
@ -98,14 +98,14 @@ func (lConn *Conn) HandleHttp(p packet.HttpPacket) {
func (lConn *Conn) HandleHttps(p packet.HttpPacket) {
ip, err := doh.Lookup(p.Domain())
if err != nil {
log.Debug("[HTTPS] Error looking up for domain: ", err)
log.Debug("[HTTPS] Error looking up for domain: ", p.Domain(), " ", err)
}
log.Debug("[HTTPS] Found ip over HTTPS: ", ip)
// Create a connection to the requested server
rConn, err := Dial("tcp", ip+":443")
if err != nil {
log.Debug(err)
log.Debug("[HTTPS] ", err)
return
}
defer rConn.Close()
@ -122,10 +122,10 @@ func (lConn *Conn) HandleHttps(p packet.HttpPacket) {
clientHello, err := lConn.ReadBytes()
if err != nil {
log.Debug("[HTTPS] Error reading client hello: ", err)
log.Debug("Closing connection: ", lConn.RemoteAddr())
log.Debug("[HTTPS] Closing connection: ", lConn.RemoteAddr())
}
log.Debug(lConn.RemoteAddr(), "[HTTPS] Client sent hello: ", len(clientHello), "bytes")
log.Debug("[HTTPS] Client "+lConn.RemoteAddr().String()+" sent hello: ", len(clientHello), "bytes")
// Generate a go routine that reads from the server
go rConn.Serve(lConn, "HTTPS")
@ -146,17 +146,17 @@ func (from *Conn) Serve(to *Conn, proto string) {
for {
buf, err := from.ReadBytes()
if err != nil {
log.Debug("["+proto+"]"+" Error reading from ", from.RemoteAddr())
log.Debug("["+proto+"]", err)
log.Debug("[" + proto + "]" + " Exiting Serve() method. ")
log.Debug("["+proto+"] "+"Error reading from ", from.RemoteAddr())
log.Debug("["+proto+"] ", err)
log.Debug("[" + proto + "] " + "Exiting Serve() method. ")
break
}
log.Debug(from.RemoteAddr(), " sent data: ", len(buf), "bytes")
log.Debug("["+proto+"] ", from.RemoteAddr(), " sent data: ", len(buf), "bytes")
if _, err := to.Write(buf); err != nil {
log.Debug("["+proto+"]"+"Error Writing to ", to.RemoteAddr())
log.Debug("["+proto+"]", err)
log.Debug("[" + proto + "]" + " Exiting Serve() method. ")
log.Debug("["+proto+"] "+"Error Writing to ", to.RemoteAddr())
log.Debug("["+proto+"] ", err)
log.Debug("[" + proto + "] " + "Exiting Serve() method. ")
break
}
}

View File

@ -58,10 +58,10 @@ func (p *Proxy) Start() {
}
if pkt.IsConnectMethod() {
log.Debug("HTTPS Requested")
log.Debug("[HTTPS] Start")
conn.HandleHttps(pkt)
} else {
log.Debug("HTTP Requested.")
log.Debug("[HTTP] Start")
conn.HandleHttp(pkt)
}
}()