Debian Codegraph @

modules/caplets/caplets.go

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 package caplets
2
3 import (
4 "fmt"
5
6 "github.com/bettercap/bettercap/caplets"
7 "github.com/bettercap/bettercap/session"
8
9 "github.com/dustin/go-humanize"
10
11 "github.com/evilsocket/islazy/tui"
12 )
13
14 type CapletsModule struct {
15 session.SessionModule
16 }
17
18 func NewCapletsModule(s *session.Session) *CapletsModule {
19 mod := &CapletsModule{
20 SessionModule: session.NewSessionModule("caplets", s),
21 }
22
23 mod.AddHandler(session.NewModuleHandler("caplets.show", "",
24 "Show a list of installed caplets.",
25 func(args []string) error {
26 return mod.Show()
27 }))
28
29 mod.AddHandler(session.NewModuleHandler("caplets.paths", "",
30 "Show a list caplet search paths.",
31 func(args []string) error {
32 return mod.Paths()
33 }))
34 mod.AddHandler(session.NewModuleHandler("caplets.update", "",
•35 "Install/updates the caplets.",
36 func(args []string) error {
37 return mod.Update()
38 }))
39
40 return mod
41 }
42
43 func (mod *CapletsModule) Name() string {
44 return "caplets"
45 }
46
47 func (mod *CapletsModule) Description() string {
•48 return "A module to list caplets."
49 }
50
51 func (mod *CapletsModule) Author() string {
52 return "Simone Margaritelli <[email protected]>"
53 }
54
55 func (mod *CapletsModule) Configure() error {
56 return nil
57 }
58
59 func (mod *CapletsModule) Stop() error {
60 return nil
61 }
62
63 func (mod *CapletsModule) Start() error {
64 return nil
65 }
66
67 func (mod *CapletsModule) Show() error {
68 caplets := caplets.List()
69 if len(caplets) == 0 {
•70 return fmt.Errorf("no installed caplets on this system, in Debian install bettercap-caplets package")
71 }
72
73 colNames := []string{
74 "Name",
75 "Path",
76 "Size",
77 }
78 rows := [][]string{}
79
80 for _, caplet := range caplets {
81 rows = append(rows, []string{
82 tui.Bold(caplet.Name),
83 caplet.Path,
84 tui.Dim(humanize.Bytes(uint64(caplet.Size))),
85 })
86 }
87
88 tui.Table(mod.Session.Events.Stdout, colNames, rows)
89
90 return nil
91 }
92
93 func (mod *CapletsModule) Paths() error {
94 colNames := []string{
95 "Path",
96 }
97 rows := [][]string{}
98
99 for _, path := range caplets.LoadPaths {
100 rows = append(rows, []string{path})
101 }
102
103 tui.Table(mod.Session.Events.Stdout, colNames, rows)
104 mod.Printf("(paths can be customized by defining the %s environment variable)\n", tui.Bold(caplets.EnvVarName))
105
106 return nil
107 }
108
109 func (mod *CapletsModule) Update() error {
•110 mod.Info("this command is inactive in Debian. Install the Debian package bettercap-caplets to get the caplets")
111 return nil
112 }