Skip to content

Commit

Permalink
updating gologger syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Mzack9999 committed Feb 17, 2021
1 parent fe5a72a commit 1b53bb1
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 86 deletions.
12 changes: 6 additions & 6 deletions cmd/mitmrelay/mitmrelay.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"crypto/tls"
"flag"
"io"
"log"
"net/http"
"strings"
"sync"
"time"

"github.com/projectdiscovery/gologger"
"github.com/projectdiscovery/proxify"
"github.com/projectdiscovery/tinydns"
)
Expand Down Expand Up @@ -92,7 +92,7 @@ func main() {
if options.ClientCert != "" && options.ClientKey != "" {
cert, err := tls.LoadX509KeyPair(options.ClientCert, options.ClientKey)
if err != nil {
log.Fatal(err)
gologger.Fatal().Msgf("%s\n", err)
}
config := tls.Config{Certificates: []tls.Certificate{cert}, InsecureSkipVerify: true}
proxyOpts.TLSClientConfig = &config
Expand All @@ -103,7 +103,7 @@ func main() {
if options.ServerCert != "" && options.ServerKey != "" {
cert, err := tls.LoadX509KeyPair(options.ServerCert, options.ServerKey)
if err != nil {
log.Fatal(err)
gologger.Fatal().Msgf("%s\n", err)
}
config := tls.Config{Certificates: []tls.Certificate{cert}, InsecureSkipVerify: true}
proxyOpts.TLSServerConfig = &config
Expand All @@ -128,14 +128,14 @@ func main() {
defer wgproxies.Done()
addresses := strings.Split(relay, "=>")
if len(addresses) != 2 {
log.Printf("[!] Skipping invalid relay %s", relay)
gologger.Print().Msgf("[!] Skipping invalid relay %s", relay)
return
}
ropts := proxyOpts.Clone()
ropts.ListenAddress, ropts.RemoteAddress = strings.TrimSpace(addresses[0]), strings.TrimSpace(addresses[1])
sproxy := proxify.NewSocketProxy(&ropts)
log.Printf("[+] Relay listening on %s -> %s", ropts.ListenAddress, ropts.RemoteAddress)
log.Print(sproxy.Run())
gologger.Print().Msgf("[+] Relay listening on %s -> %s", ropts.ListenAddress, ropts.RemoteAddress)
gologger.Print().Msgf("%s\n", sproxy.Run())
}(relay)
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/proxify/proxify.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func main() {

proxifyRunner, err := runner.NewRunner(options)
if err != nil {
gologger.Fatalf("Could not create runner: %s\n", err)
gologger.Fatal().Msgf("Could not create runner: %s\n", err)
}

// Setup close handler
Expand All @@ -33,7 +33,7 @@ func main() {

err = proxifyRunner.Run()
if err != nil {
gologger.Fatalf("Could not run proxify: %s\n", err)
gologger.Fatal().Msgf("Could not run proxify: %s\n", err)
}

}
9 changes: 0 additions & 9 deletions cmd/replay/go.mod

This file was deleted.

49 changes: 0 additions & 49 deletions cmd/replay/go.sum

This file was deleted.

7 changes: 4 additions & 3 deletions cmd/replay/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/elazarl/goproxy"
"github.com/projectdiscovery/fastdialer/fastdialer"
"github.com/projectdiscovery/gologger"
"github.com/projectdiscovery/tinydns"
)

Expand Down Expand Up @@ -45,7 +46,7 @@ func main() {
dialerOpts.BaseResolvers = []string{"127.0.0.1" + options.DNSListenerAddress}
dialer, err := fastdialer.NewDialer(dialerOpts)
if err != nil {
log.Fatal(err)
gologger.Fatal().Msgf("%s\n", err)
}

responses = make(map[string]*http.Response)
Expand All @@ -56,7 +57,7 @@ func main() {
// httpproxy.OnRequest().DoFunc(OnRequest)
go func() {
if err := http.ListenAndServe(options.HTTPProxyListenerAddress, httpproxy); err != nil {
log.Fatalf("Could not serve proxy: %s\n", err)
gologger.Fatal().Msgf("Could not serve proxy: %s\n", err)
}
}()

Expand Down Expand Up @@ -85,7 +86,7 @@ func main() {
})
go func() {
if err := http.ListenAndServe(":80", nil); err != nil {
log.Fatalf("Could not listen and serve: %s\n", err)
gologger.Fatal().Msgf("Could not listen and serve: %s\n", err)
}
}()

Expand Down
8 changes: 4 additions & 4 deletions internal/runner/banner.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ const Version = `0.0.3`

// showBanner is used to show the banner to the user
func showBanner() {
gologger.Printf("%s\n", banner)
gologger.Printf("\t\tprojectdiscovery.io\n\n")
gologger.Print().Msgf("%s\n", banner)
gologger.Print().Msgf("\t\tprojectdiscovery.io\n\n")

gologger.Labelf("Use with caution. You are responsible for your actions\n")
gologger.Labelf("Developers assume no liability and are not responsible for any misuse or damage.\n")
gologger.Print().Msgf("Use with caution. You are responsible for your actions\n")
gologger.Print().Msgf("Developers assume no liability and are not responsible for any misuse or damage.\n")
}
12 changes: 7 additions & 5 deletions internal/runner/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"path"

"github.com/projectdiscovery/gologger"
"github.com/projectdiscovery/gologger/formatter"
"github.com/projectdiscovery/gologger/levels"
)

// Options of the internal runner
Expand Down Expand Up @@ -61,13 +63,13 @@ func ParseOptions() *Options {
flag.BoolVar(&options.DumpResponse, "dump-resp", false, "Dump responses in separate files")

flag.Parse()
_ = os.MkdirAll(options.Directory, os.ModePerm)
os.MkdirAll(options.Directory, os.ModePerm) //nolint

// Read the inputs and configure the logging
options.configureOutput()

if options.Version {
gologger.Infof("Current Version: %s\n", Version)
gologger.Info().Msgf("Current Version: %s\n", Version)
os.Exit(0)
}

Expand All @@ -79,12 +81,12 @@ func ParseOptions() *Options {

func (options *Options) configureOutput() {
if options.Verbose {
gologger.MaxLevel = gologger.Verbose
gologger.DefaultLogger.SetMaxLevel(levels.LevelVerbose)
}
if options.NoColor {
gologger.UseColors = false
gologger.DefaultLogger.SetFormatter(formatter.NewCLI(true))
}
if options.Silent {
gologger.MaxLevel = gologger.Silent
gologger.DefaultLogger.SetMaxLevel(levels.LevelSilent)
}
}
12 changes: 6 additions & 6 deletions internal/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,24 @@ func NewRunner(options *Options) (*Runner, error) {
// Run polling and notification
func (r *Runner) Run() error {
// configuration summary
gologger.Printf("Proxy Listening on %s\n", r.options.ListenAddr)
gologger.Print().Msgf("Proxy Listening on %s\n", r.options.ListenAddr)
if r.options.OutputDirectory != "" {
gologger.Printf("Saving traffic to %s\n", r.options.OutputDirectory)
gologger.Print().Msgf("Saving traffic to %s\n", r.options.OutputDirectory)
}

if r.options.UpstreamHTTPProxy != "" {
gologger.Printf("Using upstream HTTP proxy: %s\n", r.options.UpstreamHTTPProxy)
gologger.Print().Msgf("Using upstream HTTP proxy: %s\n", r.options.UpstreamHTTPProxy)
} else if r.options.UpstreamSocks5Proxy != "" {
gologger.Printf("Using upstream SOCKS5 proxy: %s\n", r.options.UpstreamSocks5Proxy)
gologger.Print().Msgf("Using upstream SOCKS5 proxy: %s\n", r.options.UpstreamSocks5Proxy)
}

if r.options.DNSMapping != "" {
for _, v := range strings.Split(r.options.DNSMapping, ",") {
gologger.Printf("Domain => IP: %s\n", v)
gologger.Print().Msgf("Domain => IP: %s\n", v)
}

if r.options.DNSFallbackResolver != "" {
gologger.Printf("Fallback Resolver: %s\n", r.options.DNSFallbackResolver)
gologger.Print().Msgf("Fallback Resolver: %s\n", r.options.DNSFallbackResolver)
}

}
Expand Down
9 changes: 7 additions & 2 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Logger struct {
asyncqueue chan OutputData
}

// NewLogger instance
func NewLogger(options *OptionsLogger) *Logger {
logger := &Logger{
options: options,
Expand All @@ -50,6 +51,7 @@ func (l *Logger) createOutputFolder() error {
return os.MkdirAll(l.options.OutputFolder, 0755)
}

// AsyncWrite data
func (l *Logger) AsyncWrite() {
var (
format string
Expand Down Expand Up @@ -94,6 +96,7 @@ func (l *Logger) AsyncWrite() {
}
}

// LogRequest and user data
func (l *Logger) LogRequest(req *http.Request, userdata UserData) error {
reqdump, err := httputil.DumpRequest(req, true)
if err != nil {
Expand All @@ -104,12 +107,13 @@ func (l *Logger) LogRequest(req *http.Request, userdata UserData) error {
}

if l.options.Verbose {
gologger.Silentf("%s", string(reqdump))
gologger.Silent().Msgf("%s", string(reqdump))
}

return nil
}

// LogResponse and user data
func (l *Logger) LogResponse(resp *http.Response, userdata UserData) error {
if resp == nil {
return nil
Expand All @@ -123,11 +127,12 @@ func (l *Logger) LogResponse(resp *http.Response, userdata UserData) error {
}

if l.options.Verbose {
gologger.Silentf("%s", string(respdump))
gologger.Silent().Msgf("%s", string(respdump))
}
return nil
}

// Close logger instance
func (l *Logger) Close() {
close(l.asyncqueue)
}

0 comments on commit 1b53bb1

Please sign in to comment.