/
widgets.go
130 lines (121 loc) · 3.22 KB
/
widgets.go
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
129
130
package gui
import (
"time"
"github.com/mum4k/termdash/cell"
"github.com/mum4k/termdash/linestyle"
"github.com/mum4k/termdash/widgets/gauge"
"github.com/mum4k/termdash/widgets/linechart"
"github.com/mum4k/termdash/widgets/text"
"github.com/mum4k/termdash/widgets/textinput"
)
// redrawInterval is how often termdash redraws the screen.
const (
redrawInterval = 250 * time.Millisecond
)
type widgets struct {
urlInput *textinput.TextInput
rateLimitInput *textinput.TextInput
durationInput *textinput.TextInput
methodInput *textinput.TextInput
bodyInput *textinput.TextInput
headerInput *textinput.TextInput
timeoutInput *textinput.TextInput
latencyChart *linechart.LineChart
reportText *text.Text
progressGauge *gauge.Gauge
navi *text.Text
}
func newWidgets() (*widgets, error) {
latencyChart, err := newLineChart()
if err != nil {
return nil, err
}
reportText, err := newText("Give the target URL and press Enter, then the attack will be launched.")
if err != nil {
return nil, err
}
navi, err := newText("Ctrl-c: quit, Enter: attack")
if err != nil {
return nil, err
}
urlInput, err := newTextInput("Target URL: ", "http://", 80)
if err != nil {
return nil, err
}
rateLimitInput, err := newTextInput("Rate limit: ", "50", 30)
if err != nil {
return nil, err
}
durationInput, err := newTextInput("Duration: ", "10s", 30)
if err != nil {
return nil, err
}
methodInput, err := newTextInput("Method: ", "GET", 30)
if err != nil {
return nil, err
}
bodyInput, err := newTextInput("Body: ", "", 30)
if err != nil {
return nil, err
}
headerInput, err := newTextInput("Header: ", "", 30)
if err != nil {
return nil, err
}
timeoutInput, err := newTextInput("Timeout: ", "30s", 30)
if err != nil {
return nil, err
}
progressGauge, err := newGauge()
if err != nil {
return nil, err
}
return &widgets{
urlInput: urlInput,
rateLimitInput: rateLimitInput,
durationInput: durationInput,
methodInput: methodInput,
bodyInput: bodyInput,
headerInput: headerInput,
timeoutInput: timeoutInput,
latencyChart: latencyChart,
reportText: reportText,
progressGauge: progressGauge,
navi: navi,
}, nil
}
func newLineChart() (*linechart.LineChart, error) {
return linechart.New(
linechart.AxesCellOpts(cell.FgColor(cell.ColorRed)),
linechart.YLabelCellOpts(cell.FgColor(cell.ColorGreen)),
linechart.XLabelCellOpts(cell.FgColor(cell.ColorGreen)),
)
}
func newText(s string) (*text.Text, error) {
t, err := text.New(text.RollContent(), text.WrapAtWords())
if err != nil {
return nil, err
}
if err := t.Write(s); err != nil {
return nil, err
}
return t, nil
}
func newTextInput(label, placeHolder string, cells int) (*textinput.TextInput, error) {
return textinput.New(
//textinput.Label(label, cell.FgColor(cell.ColorWhite)),
textinput.Border(linestyle.Double),
textinput.BorderColor(cell.ColorGreen),
textinput.FillColor(cell.ColorDefault),
textinput.MaxWidthCells(cells),
textinput.PlaceHolder(placeHolder),
textinput.PlaceHolderColor(cell.ColorDefault),
)
}
func newGauge() (*gauge.Gauge, error) {
return gauge.New(
gauge.Height(1),
gauge.Border(linestyle.Light),
gauge.BorderTitle("Progress"),
)
}