about summary refs log tree commit diff
path: root/src/printer.go
blob: f36dd99251e852ba162b82cdef1274de343314c3 (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
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

		// hidden defines if the value should be displayed (normally a 200
		// status code) or hidden (gets printed, but the next entry overwrites the
		// line
		var hidden bool

		// hide some of the requests, filter using the status code
		for _, codeToHide := range hide.HideCode {
			if response.StatusCode == codeToHide {
				hidden = true
			} else {
				hidden = false
			}
		}

		for _, linesToHide := range hide.HideLine {
			if response.ResponseLines == linesToHide {
				hidden = true
			} else {
				hidden = false
			}
		}

		for _, wordsToHide := range hide.HideWord {
			if response.ResponseWords == wordsToHide {
				hidden = true
			} else {
				hidden = false
			}
		}

		for _, charsToHide := range hide.HideChar {
			if response.ResponseChars == charsToHide {
				hidden = true
			} else {
				hidden = false
			}
		}

		// show some of the requests, filter using the status code
		for _, codeToShow := range show.ShowCode {
			if response.StatusCode == codeToShow {
				hidden = false
			} else {
				hidden = true
			}
		}

		for _, linesToShow := range show.ShowLine {
			if response.ResponseLines == linesToShow {
				hidden = false
			} else {
				hidden = true
			}
		}

		for _, wordsToShow := range show.ShowWord {
			if response.ResponseWords == wordsToShow {
				hidden = false
			} else {
				hidden = true
			}
		}

		for _, charsToShow := range show.ShowChar {
			if response.ResponseChars == charsToShow {
				hidden = false
			} else {
				hidden = true
			}
		}

		// localColor to display the status code in (either green or red)
		var localColor string

		// set the prefix, postfix and localColor according to the hidden state
		if hidden == true {
			prefix = ""
			postfix = "\033[K\r"
			localColor = "red"
		} else {
			prefix = "\r\033[K"
			postfix = "\n"
			localColor = "green"
		}

		// statusCode string (with ansi escape codes)
		var statusCode string

		// localColor
		if color == true {
			if localColor == "red" {
				statusCode = red(fmt.Sprintf("%d", response.StatusCode))
			} else if localColor == "green" {
				statusCode = green(fmt.Sprintf("%d", response.StatusCode))
			} else {
				statusCode = cyan(fmt.Sprintf("%d", response.StatusCode))
			}
		} else {
			statusCode = 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("[+]"))
}