fix: an empty string can now be used as an alias in order to remove it

This commit is contained in:
evilsocket 2018-01-30 02:26:48 +01:00
commit 8e8e529744
2 changed files with 8 additions and 3 deletions

View file

@ -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 := args[1]
alias := strings.Trim(args[1], "\r\n\t ")
if s.Targets.SetAliasFor(mac, alias) == true {
return nil
@ -287,7 +287,7 @@ func (s *Session) registerCoreHandlers() {
readline.PcItem("!"))
s.addHandler(NewCommandHandler("alias MAC NAME",
"^alias\\s+([a-fA-F0-9:]{17})\\s+(.+)",
"^alias\\s+([a-fA-F0-9:]{17})\\s*(.*)",
"Assign an alias to a given endpoint given its MAC address.",
s.aliasHandler),
readline.PcItem("alias", readline.PcItemDynamic(func(prefix string) []string {

View file

@ -93,7 +93,12 @@ func (tp *Targets) SetAliasFor(mac, alias string) bool {
defer tp.Unlock()
if t, found := tp.Targets[mac]; found == true {
if alias != "" {
tp.Aliases[mac] = alias
} else {
delete(tp.Aliases, mac)
}
t.Alias = alias
tp.saveAliases()
return true