about summary refs log tree commit diff
path: root/src/printer.go
blob: f02957b81f0a525f63b98d0b169fde576a52a8aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main

import (
	"fmt"
	"log"
)

// printResponse reads a response from the printChannel, formats it and prints it
func printResponses(channels channels) {
	var i int
	for {
		// read a response from the printChannel for further usage
		response := <-channels.printChannel

		// define a postfix: a string attached to the end of all printed
		// string set in the section filtering the status code cases
		var postfix string
		var prefix string

		// define what color should be used to print the individual status
		// codes
		var statusCode string

		var color string

		// default values: clear the line, print, newline, green
		prefix = "\r\033[K"
		postfix = "\n"
		color = "green"

		// hide some of the requests, filter using the status code
		for _, codeToHide := range hide.HideCode {
			if response.StatusCode == codeToHide {
				prefix = ""
				postfix = "\033[K\r"
				color = "red"
			}
		}

		for _, linesToHide := range hide.HideLine {
			if response.ResponseLines == linesToHide {
				prefix = ""
				postfix = "\033[K\r"
				color = "red"
			}
		}

		for _, wordsToHide := range hide.HideWord {
			if response.ResponseWords == wordsToHide {
				prefix = ""
				postfix = "\033[K\r"
				color = "red"
			}
		}

		for _, charsToHide := range hide.HideChar {
			if response.ResponseChars == charsToHide {
				prefix = ""
				postfix = "\033[K\r"
				color = "red"
			}
		}

		// color
		if color == "red" {
			statusCode = red(fmt.Sprintf("%d", response.StatusCode))
		} else if color == "green" {
			statusCode = green(fmt.Sprintf("%d", response.StatusCode))
		}

		// print the requests
		fmt.Printf("%s%.7d:   %s | %7d L | %7d W | %7d Ch |    %s%s", prefix, i, statusCode, response.ResponseLines, response.ResponseWords, response.ResponseChars, response.FuzzWord, postfix)

		i++
	}
	log.Printf("%s Done printing the responses", green("[+]"))
}