add perm/tmp indication

Signed-off-by: Hadi <hadi@example.com>
This commit is contained in:
Hadi
2026-05-04 13:13:29 +02:00
parent 6e3beb44e1
commit 1661ec4f57
3 changed files with 30 additions and 5 deletions
+20
View File
@@ -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) }
+1
View File
@@ -20,6 +20,7 @@ type Device struct {
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 }
+5 -1
View File
@@ -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)),
) )
} }