Skip to content

Commit c0b7cab

Browse files
committed
Fix interfaces on edit form
1 parent ef3e159 commit c0b7cab

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

main.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,14 @@ func (t *Tui) LoadInterfaces() ([]string, error) {
5252
if err != nil {
5353
log.Printf("error: %v\n", err)
5454
}
55-
return strings.Split(out, "\n"), nil
55+
56+
interfaces := append(strings.Fields(out), "")
57+
58+
return interfaces, nil
5659
}
5760

5861
func (t *Tui) LoadTableData() ([]string, error) {
59-
//err, out, _ := shellout("ufw status | sed '/^$/d' | awk '{$2=$2};1' | tail -n +4 | sed -r 's/(\\w)\\s(\\(v6\\))/\\1/;s/([A-Z]{2,})\\s([A-Z]{2,3})/\\1-\\2/;s/^(.*)\\s([A-Z]{2,}(-[A-Z]{2,3})?)\\s(.*)\\s(on)\\s(.*)#?/\\1_\\5_\\6 - \\2 \\4/;s/^([A-Z][a-z]+\\/[a-z]{3})\\s(([A-Z]+).*)/\\1 - \\2/;s/^([0-9]+)\\s([A-Z]{2,}(-[A-Z]{2,3})?)/- \\1 \\2/;s/^(.*)\\s([0-9]+)\\/([a-z]{3})/\\1\\/\\3 \\2/;s/(\\w+)\\s(on)\\s(\\w+)/\\1-\\2-\\3 -/;s/^([0-9]+)\\/([a-z]{3})/\\2 \\1/;s/^(([0-9]{1,3}\\.){3}[0-9]{1,3})\\s([A-Z]+)/\\1 - \\3/;s/^(\\w+)\\s([A-Z]+)/\\1 - \\2/'")
60-
err, out, _ := shellout("ufw status numbered | sed '/^$/d' | awk '{$2=$2};1' | tail -n +4 | sed -r 's/(\\[(\\s)([0-9]+)\\])/\\[\\3\\] /;s/(\\[([0-9]+)\\])/\\[\\2\\] /;s/\\(out\\)//;s/(\\w)\\s(\\(v6\\))/\\1/;s/([A-Z]{2,})\\s([A-Z]{2,3})/\\1-\\2/;s/^(.*)\\s([A-Z]{2,}(-[A-Z]{2,3})?)\\s(.*)\\s(on)\\s(.*)#?/\\1_\\5_\\6- \\2 \\4/;s/([A-Z][a-z]+\\/[a-z]{3})\\s(([A-Z]+).*)/\\1 - \\2/;s/(\\]\\s+)([0-9]{2,})\\s([A-Z]{2,}(-[A-Z]{2,3})?)/\\1Anywhere \\2 \\3/;s/(\\]\\s+)(([0-9]{1,3}\\.){3}[0-9]{1,3}(\\/[0-9]{1,2})?)\\s([A-Z]{2,}-[A-Z]{2,3})/\\1\\2 - \\5/;s/([A-Z][a-z]+)\\s(([A-Z]+).*)/\\1 - \\2/;s/(\\]\\s+)(.*)\\s([0-9]+)(\\/[a-z]{3})/\\1\\2\\4 \\3/;s/(\\]\\s+)\\/([a-z]{3})\\s/\\1\\2 /;s/^(.*)\\s(on)\\s(.*)\\s([A-Z]{2,}(-[A-Z]{2,3})?)\\s(.*)/\\1_\\2_\\3 - \\4 \\6/'")
62+
err, out, _ := shellout("ufw status numbered | sed '/^$/d' | awk '{$2=$2};1' | tail -n +4 | sed -r 's/(\\[(\\s)([0-9]+)\\])/\\[\\3\\] /;s/(\\[([0-9]+)\\])/\\[\\2\\] /;s/\\(out\\)//;s/(\\w)\\s(\\(v6\\))/\\1/;s/([A-Z]{2,})\\s([A-Z]{2,3})/\\1-\\2/;s/^(.*)\\s([A-Z]{2,}(-[A-Z]{2,3})?)\\s(.*)\\s(on)\\s(.*)\\s(#.*)?/\\1_\\5_\\6 - \\2 \\4 \\7/;s/([A-Z][a-z]+\\/[a-z]{3})\\s(([A-Z]+).*)/\\1 - \\2/;s/(\\]\\s+)([0-9]{2,})\\s([A-Z]{2,}(-[A-Z]{2,3})?)/\\1Anywhere \\2 \\3/;s/(\\]\\s+)(([0-9]{1,3}\\.){3}[0-9]{1,3}(\\/[0-9]{1,2})?)\\s([A-Z]{2,}-[A-Z]{2,3})/\\1\\2 - \\5/;s/([A-Z][a-z]+)\\s(([A-Z]+).*)/\\1 - \\2/;s/(\\]\\s+)(.*)\\s([0-9]+)(\\/[a-z]{3})/\\1\\2\\4 \\3/;s/(\\]\\s+)\\/([a-z]{3})\\s/\\1\\2 /;s/^(.*)\\s(on)\\s(.*)\\s([A-Z]{2,}(-[A-Z]{2,3})?)\\s(.*)/\\1_\\2_\\3 - \\4 \\6/'")
6163

6264
if err != nil {
6365
log.Printf("error: %v\n", err)
@@ -197,17 +199,16 @@ func parsePort(input string) string {
197199
}
198200

199201
func parseInterfaceIndex(input string, interfaces []string) int {
200-
r := regexp.MustCompile(`.* on (.+)`)
201-
matches := r.FindStringSubmatch(input)
202-
index := len(interfaces)
202+
r := regexp.MustCompile(`.+ on (.+)`)
203+
matches := r.FindStringSubmatch(strings.TrimSpace(input))
204+
index := len(interfaces) - 1
203205

204206
if len(matches) == 0 {
205207
return index
206208
}
207209

208210
for i, interfaceValue := range interfaces {
209211
if matches[1] == interfaceValue {
210-
fmt.Println(i)
211212
return i
212213
}
213214
}
@@ -242,7 +243,6 @@ func (t *Tui) EditForm() {
242243
}
243244

244245
portValue := parsePort(t.table.GetCell(row, 2).Text)
245-
246246
interfaceOptionIndex := parseInterfaceIndex(to, interfaces)
247247

248248
actionOptionIndex := 0
@@ -287,9 +287,9 @@ func (t *Tui) EditForm() {
287287
SetFieldBackgroundColor(tcell.ColorDarkCyan).
288288
SetLabelColor(tcell.ColorWhite)
289289

290-
t.secondHelp.SetText("* Mandatory field\n\nPort, To and From fields respectively match any and Anywhere if left empty").
291-
SetTextColor(tcell.ColorDarkCyan).
292-
SetBorderPadding(0, 0, 1, 1)
290+
/*t.secondHelp.SetText("* Mandatory field\n\nPort, To and From fields respectively match any and Anywhere if left empty").
291+
SetTextColor(tcell.ColorDarkCyan).
292+
SetBorderPadding(0, 0, 1, 1)*/
293293

294294
t.app.SetFocus(t.form)
295295
})
@@ -411,7 +411,7 @@ func (t *Tui) CreateMenu() {
411411
t.EditForm()
412412
t.app.SetFocus(t.table)
413413
}).
414-
AddItem("Remove a rule", "", 'd', func() {
414+
AddItem("Delete a rule", "", 'd', func() {
415415
t.RemoveRule()
416416
t.app.SetFocus(t.table)
417417
t.help.SetText("Press <Esc> to go back to the menu selection").SetBorderPadding(1, 0, 1, 0)

0 commit comments

Comments
 (0)