mirror of
https://github.com/bettercap/bettercap
synced 2025-08-20 21:43:18 -07:00
refact: refactored several strings.Trim calls to core.Trim
This commit is contained in:
parent
5189068cd3
commit
ca9f4f0945
10 changed files with 35 additions and 23 deletions
|
@ -4,6 +4,8 @@ import (
|
|||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/evilsocket/bettercap-ng/core"
|
||||
)
|
||||
|
||||
type Module interface {
|
||||
|
@ -62,7 +64,7 @@ func (m SessionModule) ListParam(name string) (err error, values []string) {
|
|||
} else {
|
||||
parts := strings.Split(list, ",")
|
||||
for _, part := range parts {
|
||||
part = strings.Trim(part, "\t\n\r ")
|
||||
part = core.Trim(part)
|
||||
if part != "" {
|
||||
values = append(values, part)
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ type Session struct {
|
|||
func ParseCommands(buffer string) []string {
|
||||
cmds := make([]string, 0)
|
||||
for _, cmd := range strings.Split(buffer, ";") {
|
||||
cmd = strings.Trim(cmd, "\r\n\t ")
|
||||
cmd = core.Trim(cmd)
|
||||
if cmd != "" || (len(cmd) > 0 && cmd[0] != '#') {
|
||||
cmds = append(cmds, cmd)
|
||||
}
|
||||
|
@ -338,7 +338,7 @@ func (s *Session) RunCaplet(filename string) error {
|
|||
}
|
||||
|
||||
func (s *Session) Run(line string) error {
|
||||
line = strings.TrimRight(line, " ")
|
||||
line = core.TrimRight(line)
|
||||
for _, h := range s.CoreHandlers {
|
||||
if parsed, args := h.Parse(line); parsed == true {
|
||||
return h.Exec(args, s)
|
||||
|
|
|
@ -15,7 +15,7 @@ import (
|
|||
func (s *Session) helpHandler(args []string, sess *Session) error {
|
||||
filter := ""
|
||||
if len(args) == 2 {
|
||||
filter = strings.Trim(args[1], "\r\n\t ")
|
||||
filter = core.Trim(args[1])
|
||||
}
|
||||
|
||||
if filter == "" {
|
||||
|
@ -181,7 +181,7 @@ func (s *Session) shHandler(args []string, sess *Session) error {
|
|||
|
||||
func (s *Session) aliasHandler(args []string, sess *Session) error {
|
||||
mac := args[0]
|
||||
alias := strings.Trim(args[1], "\r\n\t ")
|
||||
alias := core.Trim(args[1])
|
||||
|
||||
if s.Targets.SetAliasFor(mac, alias) == true {
|
||||
return nil
|
||||
|
@ -201,7 +201,7 @@ func (s *Session) registerCoreHandlers() {
|
|||
"List available commands or show module specific help if no module name is provided.",
|
||||
s.helpHandler),
|
||||
readline.PcItem("help", readline.PcItemDynamic(func(prefix string) []string {
|
||||
prefix = strings.Trim(prefix[4:], "\t\r\n ")
|
||||
prefix = core.Trim(prefix[4:])
|
||||
modNames := []string{""}
|
||||
for _, m := range s.Modules {
|
||||
if prefix == "" || strings.HasPrefix(m.Name(), prefix) == true {
|
||||
|
@ -234,7 +234,7 @@ func (s *Session) registerCoreHandlers() {
|
|||
"Get the value of variable NAME, use * for all.",
|
||||
s.getHandler),
|
||||
readline.PcItem("get", readline.PcItemDynamic(func(prefix string) []string {
|
||||
prefix = strings.Trim(prefix[3:], "\t\r\n ")
|
||||
prefix = core.Trim(prefix[3:])
|
||||
varNames := []string{""}
|
||||
for key := range s.Env.Storage {
|
||||
if prefix == "" || strings.HasPrefix(key, prefix) == true {
|
||||
|
@ -249,7 +249,7 @@ func (s *Session) registerCoreHandlers() {
|
|||
"Set the VALUE of variable NAME.",
|
||||
s.setHandler),
|
||||
readline.PcItem("set", readline.PcItemDynamic(func(prefix string) []string {
|
||||
prefix = strings.Trim(prefix[3:], "\t\r\n ")
|
||||
prefix = core.Trim(prefix[3:])
|
||||
varNames := []string{""}
|
||||
for key, _ := range s.Env.Storage {
|
||||
if prefix == "" || strings.HasPrefix(key, prefix) == true {
|
||||
|
@ -270,7 +270,7 @@ func (s *Session) registerCoreHandlers() {
|
|||
"Load and run this caplet in the current session.",
|
||||
s.includeHandler),
|
||||
readline.PcItem("include", readline.PcItemDynamic(func(prefix string) []string {
|
||||
prefix = strings.Trim(prefix[8:], "\t\r\n ")
|
||||
prefix = core.Trim(prefix[8:])
|
||||
if prefix == "" {
|
||||
prefix = "."
|
||||
}
|
||||
|
@ -291,7 +291,7 @@ func (s *Session) registerCoreHandlers() {
|
|||
"Assign an alias to a given endpoint given its MAC address.",
|
||||
s.aliasHandler),
|
||||
readline.PcItem("alias", readline.PcItemDynamic(func(prefix string) []string {
|
||||
prefix = strings.Trim(prefix[5:], "\t\r\n ")
|
||||
prefix = core.Trim(prefix[5:])
|
||||
macs := []string{""}
|
||||
for mac, _ := range s.Targets.Targets {
|
||||
if prefix == "" || strings.HasPrefix(mac, prefix) == true {
|
||||
|
|
|
@ -71,8 +71,8 @@ func (tp *Targets) loadAliases() error {
|
|||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
parts := strings.SplitN(line, " ", 2)
|
||||
mac := strings.Trim(parts[0], "\r\n\t ")
|
||||
alias := strings.Trim(parts[1], "\r\n\t ")
|
||||
mac := core.Trim(parts[0])
|
||||
alias := core.Trim(parts[1])
|
||||
tp.Session.Events.Log(core.DEBUG, " aliases[%s] = '%s'", mac, alias)
|
||||
tp.Aliases[mac] = alias
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue