mirror of
https://github.com/anotherhadi/usbguard-tui.git
synced 2026-05-11 22:02:34 +02:00
@@ -20,6 +20,7 @@ func ListDevices() ([]Device, error) {
|
||||
if err != nil {
|
||||
return nil, wrapExecError(err)
|
||||
}
|
||||
rules := listRules()
|
||||
var devices []Device
|
||||
for _, line := range strings.Split(strings.TrimSpace(string(out)), "\n") {
|
||||
if line == "" {
|
||||
@@ -27,12 +28,31 @@ func ListDevices() ([]Device, error) {
|
||||
}
|
||||
d, err := parseLine(line)
|
||||
if err == nil {
|
||||
d.Permanent = rules[d.VidPid] == d.Status
|
||||
devices = append(devices, d)
|
||||
}
|
||||
}
|
||||
return devices, nil
|
||||
}
|
||||
|
||||
func listRules() map[string]Status {
|
||||
out, err := exec.Command("usbguard", "list-rules").Output()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
rules := make(map[string]Status)
|
||||
for _, line := range strings.Split(strings.TrimSpace(string(out)), "\n") {
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
d, err := parseLine(line)
|
||||
if err == nil {
|
||||
rules[d.VidPid] = d.Status
|
||||
}
|
||||
}
|
||||
return rules
|
||||
}
|
||||
|
||||
func AllowDevice(id int, permanent bool) error { return applyPolicy("allow-device", id, permanent) }
|
||||
func BlockDevice(id int, permanent bool) error { return applyPolicy("block-device", id, permanent) }
|
||||
func RejectDevice(id int, permanent bool) error { return applyPolicy("reject-device", id, permanent) }
|
||||
|
||||
@@ -16,10 +16,11 @@ const (
|
||||
)
|
||||
|
||||
type Device struct {
|
||||
ID int
|
||||
Name string
|
||||
Status Status
|
||||
VidPid string
|
||||
ID int
|
||||
Name string
|
||||
Status Status
|
||||
VidPid string
|
||||
Permanent bool
|
||||
}
|
||||
|
||||
func (d Device) Title() string { return d.Name }
|
||||
|
||||
Reference in New Issue
Block a user