Skip to content

Commit 1aa2a13

Browse files
author
Cedric BAIL
committed
Add ability to copy IP address easily.
1 parent b08b886 commit 1aa2a13

File tree

2 files changed

+141
-121
lines changed

2 files changed

+141
-121
lines changed

routeros.go

+88-87
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ type RouterOSHeader struct {
44
title string
55
path string
66
mac bool
7+
copy bool
78
}
89

910
type RouterOSView struct {
@@ -24,15 +25,15 @@ var routerOSCommands = map[string][]RouterOSView{
2425
title: "Interfaces",
2526
path: "/caps-man/interface",
2627
headers: []RouterOSHeader{
27-
{"Disabled", "disabled", false},
28-
{"Inactive", "inactive", false},
29-
{"State", "current-state", false},
30-
{"Name", "name", false},
31-
{"Channel", "current-channel", false},
32-
{"Current Authorized Clients", "current-authorized-clients", false},
33-
{"L2 MTU", "l2mtu", false},
34-
{"Radio MAC", "radio-mac", false},
35-
{"Radio Name", "radio-name", false},
28+
{"Disabled", "disabled", false, false},
29+
{"Inactive", "inactive", false, false},
30+
{"State", "current-state", false, false},
31+
{"Name", "name", false, false},
32+
{"Channel", "current-channel", false, false},
33+
{"Current Authorized Clients", "current-authorized-clients", false, false},
34+
{"L2 MTU", "l2mtu", false, false},
35+
{"Radio MAC", "radio-mac", false, false},
36+
{"Radio Name", "radio-name", false, false},
3637
},
3738
},
3839
{
@@ -44,98 +45,98 @@ var routerOSCommands = map[string][]RouterOSView{
4445
title: "Configuration",
4546
path: "/caps-man/configuration",
4647
headers: []RouterOSHeader{
47-
{"Name", "name", false},
48-
{"Mode", "mode", false},
49-
{"SSID", "ssid", false},
50-
{"TX Chains", "tx-chains", false},
51-
{"RX Chains", "rx-chains", false},
52-
{"Country", "country", false},
53-
{"Installation", "installation", false},
54-
{"Security", "security", false},
55-
{"Datapath", "datapath", false},
56-
{"Channel", "channel", false},
48+
{"Name", "name", false, false},
49+
{"Mode", "mode", false, false},
50+
{"SSID", "ssid", false, false},
51+
{"TX Chains", "tx-chains", false, false},
52+
{"RX Chains", "rx-chains", false, false},
53+
{"Country", "country", false, false},
54+
{"Installation", "installation", false, false},
55+
{"Security", "security", false, false},
56+
{"Datapath", "datapath", false, false},
57+
{"Channel", "channel", false, false},
5758
},
5859
},
5960
{
6061
title: "Channel",
6162
path: "/caps-man/channel",
6263
headers: []RouterOSHeader{
63-
{"Name", "name", false},
64-
{"Frequency", "frequency", false},
65-
{"Control Channel Width", "control-channel-width", false},
66-
{"TX Power", "tx-power", false},
64+
{"Name", "name", false, false},
65+
{"Frequency", "frequency", false, false},
66+
{"Control Channel Width", "control-channel-width", false, false},
67+
{"TX Power", "tx-power", false, false},
6768
},
6869
},
6970
{
7071
title: "Datapath",
7172
path: "/caps-man/datapath",
7273
headers: []RouterOSHeader{
73-
{"Name", "name", false},
74-
{"Client to Client forwarding", "client-to-client-forwarding", false},
75-
{"Bridge", "bridge", false},
76-
{"Local forwarding", "local-forwarding", false},
74+
{"Name", "name", false, false},
75+
{"Client to Client forwarding", "client-to-client-forwarding", false, false},
76+
{"Bridge", "bridge", false, false},
77+
{"Local forwarding", "local-forwarding", false, false},
7778
},
7879
},
7980
{
8081
title: "Security configuration",
8182
path: "/caps-man/security",
8283
headers: []RouterOSHeader{
83-
{"Name", "name", false},
84-
{"Authentication Types", "authentication-types", false},
85-
{"Encryption", "encryption", false},
86-
{"Group Encryption", "group-encryption", false},
87-
{"Group Key Update", "group-key-update", false},
84+
{"Name", "name", false, false},
85+
{"Authentication Types", "authentication-types", false, false},
86+
{"Encryption", "encryption", false, false},
87+
{"Group Encryption", "group-encryption", false, false},
88+
{"Group Key Update", "group-key-update", false, false},
8889
},
8990
},
9091
{
9192
title: "Access List",
9293
path: "/caps-man/access-list",
9394
headers: []RouterOSHeader{
94-
{"Interface", "interface", false},
95-
{"Signal Range", "signal-range", false},
96-
{"Client To Client Forwarding", "client-to-client-forwarding", false},
95+
{"Interface", "interface", false, false},
96+
{"Signal Range", "signal-range", false, false},
97+
{"Client To Client Forwarding", "client-to-client-forwarding", false, false},
9798
},
9899
},
99100
{
100101
title: "Remote Cap",
101102
path: "/caps-man/remote-cap",
102103
headers: []RouterOSHeader{
103-
{"Address", "address", true},
104-
{"Name", "name", false},
105-
{"Board", "board", false},
106-
{"Serial", "serial", false},
107-
{"Version", "version", false},
108-
{"Identity", "identity", false},
109-
{"Base Mac", "base-mac", true},
110-
{"State", "state", false},
111-
{"Radios", "radios", false},
104+
{"Address", "address", true, false},
105+
{"Name", "name", false, false},
106+
{"Board", "board", false, false},
107+
{"Serial", "serial", false, false},
108+
{"Version", "version", false, false},
109+
{"Identity", "identity", false, false},
110+
{"Base Mac", "base-mac", true, false},
111+
{"State", "state", false, false},
112+
{"Radios", "radios", false, false},
112113
},
113114
},
114115
{
115116
title: "Radio",
116117
path: "/caps-man/radio",
117118
headers: []RouterOSHeader{
118-
{"Radio Max", "radio-mac", false},
119-
{"Remote Cap Name", "remote-cap-name", false},
120-
{"Remote Cap Identity", "remote-cap-identity", false},
121-
{"Interface", "interface", false},
119+
{"Radio Max", "radio-mac", false, false},
120+
{"Remote Cap Name", "remote-cap-name", false, false},
121+
{"Remote Cap Identity", "remote-cap-identity", false, false},
122+
{"Interface", "interface", false, false},
122123
},
123124
},
124125
{
125126
title: "Registration Table",
126127
path: "/caps-man/registration-table",
127128
headers: []RouterOSHeader{
128-
{"Interface", "interface", false},
129-
{"SSID", "ssid", false},
130-
{"Mac-Address", "mac-address", true},
131-
{"EAP Identity", "eap-identity", false},
132-
{"Tx Rate", "tx-rate", false},
133-
{"Tx signal", "tx-rate-set", false},
134-
{"Rx Rate", "rx-rate", false},
135-
{"Rx signal", "rx-signal", false},
136-
{"Uptime", "uptime", false},
137-
{"Tx/Rx Packets", "packets", false},
138-
{"Tx/Rx Bytes", "bytes", false},
129+
{"Interface", "interface", false, false},
130+
{"SSID", "ssid", false, false},
131+
{"Mac-Address", "mac-address", true, false},
132+
{"EAP Identity", "eap-identity", false, false},
133+
{"Tx Rate", "tx-rate", false, false},
134+
{"Tx signal", "tx-rate-set", false, false},
135+
{"Rx Rate", "rx-rate", false, false},
136+
{"Rx signal", "rx-signal", false, false},
137+
{"Uptime", "uptime", false, false},
138+
{"Tx/Rx Packets", "packets", false, false},
139+
{"Tx/Rx Bytes", "bytes", false, false},
139140
},
140141
},
141142
},
@@ -144,11 +145,11 @@ var routerOSCommands = map[string][]RouterOSView{
144145
title: "Interface",
145146
path: "/interface/ethernet",
146147
headers: []RouterOSHeader{
147-
{"Name", "name", false},
148-
{"Actual MTU", "mtu", false},
149-
{"L2 MTU", "l2mtu", false},
150-
{"TX", "tx-bytes", false},
151-
{"RX", "rx-bytes", false},
148+
{"Name", "name", false, false},
149+
{"Actual MTU", "mtu", false, false},
150+
{"L2 MTU", "l2mtu", false, false},
151+
{"TX", "tx-bytes", false, false},
152+
{"RX", "rx-bytes", false, false},
152153
},
153154
},
154155
},
@@ -157,15 +158,15 @@ var routerOSCommands = map[string][]RouterOSView{
157158
title: "WiFi Interfaces",
158159
path: "/interface/wireless",
159160
headers: []RouterOSHeader{
160-
{"Name", "name", false},
161-
{"Actual MTU", "mtu", false},
162-
{"MAC Address", "mac-address", true},
163-
{"ARP", "arp", false},
164-
{"Mode", "mode", false},
165-
{"Band", "band", false},
166-
{"Channel Width", "channel-width", false},
167-
{"Frequency", "frequency", false},
168-
{"SSID", "ssid", false},
161+
{"Name", "name", false, false},
162+
{"Actual MTU", "mtu", false, false},
163+
{"MAC Address", "mac-address", true, false},
164+
{"ARP", "arp", false, false},
165+
{"Mode", "mode", false, false},
166+
{"Band", "band", false, false},
167+
{"Channel Width", "channel-width", false, false},
168+
{"Frequency", "frequency", false, false},
169+
{"SSID", "ssid", false, false},
169170
},
170171
},
171172
},
@@ -174,9 +175,9 @@ var routerOSCommands = map[string][]RouterOSView{
174175
title: "Host",
175176
path: "/interface/bridge/host",
176177
headers: []RouterOSHeader{
177-
{"MAC Address", "mac-address", true},
178-
{"On Interface", "on-interface", false},
179-
{"Bridge", "bridge", false},
178+
{"MAC Address", "mac-address", true, false},
179+
{"On Interface", "on-interface", false, false},
180+
{"Bridge", "bridge", false, false},
180181
},
181182
},
182183
},
@@ -185,9 +186,9 @@ var routerOSCommands = map[string][]RouterOSView{
185186
title: "ARP Table",
186187
path: "/ip/arp",
187188
headers: []RouterOSHeader{
188-
{"IP Address", "address", false},
189-
{"MAC Address", "mac-address", true},
190-
{"Interface", "interface", false},
189+
{"IP Address", "address", false, true},
190+
{"MAC Address", "mac-address", true, false},
191+
{"Interface", "interface", false, false},
191192
},
192193
},
193194
},
@@ -196,14 +197,14 @@ var routerOSCommands = map[string][]RouterOSView{
196197
title: "Leases",
197198
path: "/ip/dhcp-server/lease",
198199
headers: []RouterOSHeader{
199-
{"Address", "address", false},
200-
{"MAC Address", "mac-address", true},
201-
{"Client ID", "active-client-id", false},
202-
{"Server", "server", false},
203-
{"Active Address", "active-address", false},
204-
{"Active MAC Address", "active-mac-address", true},
205-
{"Host Name", "host-name", false},
206-
{"Expires After", "expires-after", false},
200+
{"Address", "address", false, true},
201+
{"MAC Address", "mac-address", true, false},
202+
{"Client ID", "active-client-id", false, false},
203+
{"Server", "server", false, false},
204+
{"Active Address", "active-address", false, true},
205+
{"Active MAC Address", "active-mac-address", true, false},
206+
{"Host Name", "host-name", false, false},
207+
{"Expires After", "expires-after", false, false},
207208
},
208209
},
209210
},

table.go

+53-34
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fyne.io/fyne/v2/container"
88
"fyne.io/fyne/v2/data/binding"
99
"fyne.io/fyne/v2/dialog"
10+
"fyne.io/fyne/v2/theme"
1011
"fyne.io/fyne/v2/widget"
1112
)
1213

@@ -15,39 +16,7 @@ func (a *appData) NewTableWithDataColumn(column []RouterOSHeader, data *Mikrotik
1516
return data.Length(), len(column)
1617
}, func() fyne.CanvasObject {
1718
var button *Button
18-
button = NewButton("MAC Address", func() {
19-
msg := ""
20-
21-
for _, router := range a.routers {
22-
if router.leaseBinding == nil {
23-
continue
24-
}
25-
lookups, err := router.leaseBinding.Search("mac-address", button.Text)
26-
if err != nil {
27-
continue
28-
}
29-
30-
for _, lookup := range lookups {
31-
ipString, _ := lookup.GetValue("active-address")
32-
hostnameString, _ := lookup.GetValue("host-name")
33-
34-
if len(hostnameString) > 0 {
35-
if len(ipString) > 0 {
36-
msg += fmt.Sprintf("%s (%s)\n", hostnameString, ipString)
37-
} else {
38-
msg += fmt.Sprintf("%s (-)\n", hostnameString)
39-
}
40-
} else if len(ipString) > 0 {
41-
msg += fmt.Sprintf("%s\n", ipString)
42-
}
43-
}
44-
}
45-
if len(msg) == 0 {
46-
return
47-
}
48-
49-
dialog.ShowInformation("Matching information for "+button.Text, msg, a.win)
50-
})
19+
button = NewButton("MAC Address", a.lookupIP(button))
5120
button.Hide()
5221
button.Importance = widget.LowImportance
5322

@@ -90,8 +59,16 @@ func (a *appData) NewTableWithDataColumn(column []RouterOSHeader, data *Mikrotik
9059

9160
exist = append(exist, router.leaseBinding.Exist("mac-address", button.Text))
9261
}
62+
button.Icon = nil
63+
button.OnTapped = a.lookupIP(button)
9364
button.BindDisable(NewNot(NewOr(exist...)))
94-
65+
} else if column[i.Col].copy {
66+
button.Icon = theme.ContentCopyIcon()
67+
button.OnTapped = a.copy(button)
68+
button.Bind(col)
69+
button.Enable()
70+
button.Show()
71+
label.Hide()
9572
} else {
9673
button.Hide()
9774
label.Show()
@@ -110,3 +87,45 @@ func (a *appData) NewTableWithDataColumn(column []RouterOSHeader, data *Mikrotik
11087

11188
return t
11289
}
90+
91+
func (a *appData) lookupIP(button *Button) func() {
92+
return func() {
93+
msg := ""
94+
95+
for _, router := range a.routers {
96+
if router.leaseBinding == nil {
97+
continue
98+
}
99+
lookups, err := router.leaseBinding.Search("mac-address", button.Text)
100+
if err != nil {
101+
continue
102+
}
103+
104+
for _, lookup := range lookups {
105+
ipString, _ := lookup.GetValue("active-address")
106+
hostnameString, _ := lookup.GetValue("host-name")
107+
108+
if len(hostnameString) > 0 {
109+
if len(ipString) > 0 {
110+
msg += fmt.Sprintf("%s (%s)\n", hostnameString, ipString)
111+
} else {
112+
msg += fmt.Sprintf("%s (-)\n", hostnameString)
113+
}
114+
} else if len(ipString) > 0 {
115+
msg += fmt.Sprintf("%s\n", ipString)
116+
}
117+
}
118+
}
119+
if len(msg) == 0 {
120+
return
121+
}
122+
123+
dialog.ShowInformation("Matching information for "+button.Text, msg, a.win)
124+
}
125+
}
126+
127+
func (a *appData) copy(button *Button) func() {
128+
return func() {
129+
a.win.Clipboard().SetContent(button.Text)
130+
}
131+
}

0 commit comments

Comments
 (0)