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 {
|
if err != nil {
|
||||||
return nil, wrapExecError(err)
|
return nil, wrapExecError(err)
|
||||||
}
|
}
|
||||||
|
rules := listRules()
|
||||||
var devices []Device
|
var devices []Device
|
||||||
for _, line := range strings.Split(strings.TrimSpace(string(out)), "\n") {
|
for _, line := range strings.Split(strings.TrimSpace(string(out)), "\n") {
|
||||||
if line == "" {
|
if line == "" {
|
||||||
@@ -27,12 +28,31 @@ func ListDevices() ([]Device, error) {
|
|||||||
}
|
}
|
||||||
d, err := parseLine(line)
|
d, err := parseLine(line)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
d.Permanent = rules[d.VidPid] == d.Status
|
||||||
devices = append(devices, d)
|
devices = append(devices, d)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return devices, nil
|
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 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 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) }
|
func RejectDevice(id int, permanent bool) error { return applyPolicy("reject-device", id, permanent) }
|
||||||
|
|||||||
@@ -16,10 +16,11 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Device struct {
|
type Device struct {
|
||||||
ID int
|
ID int
|
||||||
Name string
|
Name string
|
||||||
Status Status
|
Status Status
|
||||||
VidPid string
|
VidPid string
|
||||||
|
Permanent bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d Device) Title() string { return d.Name }
|
func (d Device) Title() string { return d.Name }
|
||||||
|
|||||||
@@ -59,9 +59,13 @@ func (d deviceDelegate) Render(w io.Writer, m list.Model, index int, item list.I
|
|||||||
descStyle = lipgloss.NewStyle().Foreground(colorMuted).PaddingLeft(2)
|
descStyle = lipgloss.NewStyle().Foreground(colorMuted).PaddingLeft(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
permIndicator := "○ tmp"
|
||||||
|
if dev.Permanent {
|
||||||
|
permIndicator = "● perm"
|
||||||
|
}
|
||||||
fmt.Fprintf(w, "%s\n%s",
|
fmt.Fprintf(w, "%s\n%s",
|
||||||
nameStyle.Render(dev.Name),
|
nameStyle.Render(dev.Name),
|
||||||
descStyle.Render(fmt.Sprintf("id:%-3d %s %s", dev.ID, dev.VidPid, string(dev.Status))),
|
descStyle.Render(fmt.Sprintf("id:%-3d %s %s %s", dev.ID, dev.VidPid, string(dev.Status), permIndicator)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user