@@ -52,12 +52,14 @@ func (t *Tui) LoadInterfaces() ([]string, error) {
52
52
if err != nil {
53
53
log .Printf ("error: %v\n " , err )
54
54
}
55
- return strings .Split (out , "\n " ), nil
55
+
56
+ interfaces := append (strings .Fields (out ), "" )
57
+
58
+ return interfaces , nil
56
59
}
57
60
58
61
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})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 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/'" )
61
63
62
64
if err != nil {
63
65
log .Printf ("error: %v\n " , err )
@@ -197,17 +199,16 @@ func parsePort(input string) string {
197
199
}
198
200
199
201
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
203
205
204
206
if len (matches ) == 0 {
205
207
return index
206
208
}
207
209
208
210
for i , interfaceValue := range interfaces {
209
211
if matches [1 ] == interfaceValue {
210
- fmt .Println (i )
211
212
return i
212
213
}
213
214
}
@@ -242,7 +243,6 @@ func (t *Tui) EditForm() {
242
243
}
243
244
244
245
portValue := parsePort (t .table .GetCell (row , 2 ).Text )
245
-
246
246
interfaceOptionIndex := parseInterfaceIndex (to , interfaces )
247
247
248
248
actionOptionIndex := 0
@@ -287,9 +287,9 @@ func (t *Tui) EditForm() {
287
287
SetFieldBackgroundColor (tcell .ColorDarkCyan ).
288
288
SetLabelColor (tcell .ColorWhite )
289
289
290
- t .secondHelp .SetText ("* Mandatory field\n \n Port, 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)*/
293
293
294
294
t .app .SetFocus (t .form )
295
295
})
@@ -411,7 +411,7 @@ func (t *Tui) CreateMenu() {
411
411
t .EditForm ()
412
412
t .app .SetFocus (t .table )
413
413
}).
414
- AddItem ("Remove a rule" , "" , 'd' , func () {
414
+ AddItem ("Delete a rule" , "" , 'd' , func () {
415
415
t .RemoveRule ()
416
416
t .app .SetFocus (t .table )
417
417
t .help .SetText ("Press <Esc> to go back to the menu selection" ).SetBorderPadding (1 , 0 , 1 , 0 )
0 commit comments