new: implemented new 'read' session command

This commit is contained in:
evilsocket 2018-03-29 13:04:47 +02:00
parent 6947a22c5c
commit 07f047dff3
No known key found for this signature in database
GPG key ID: 1564D7F30393A456

View file

@ -1,7 +1,9 @@
package session package session
import ( import (
"bufio"
"fmt" "fmt"
"os"
"path/filepath" "path/filepath"
"strconv" "strconv"
"strings" "strings"
@ -199,6 +201,23 @@ func (s *Session) setHandler(args []string, sess *Session) error {
return nil return nil
} }
func (s *Session) readHandler(args []string, sess *Session) error {
key := args[0]
prompt := args[1]
reader := bufio.NewReader(os.Stdin)
fmt.Printf("%s ", prompt)
value, _ := reader.ReadString('\n')
value = core.Trim(value)
if value == "\"\"" {
value = ""
}
s.Env.Set(key, value)
return nil
}
func (s *Session) clsHandler(args []string, sess *Session) error { func (s *Session) clsHandler(args []string, sess *Session) error {
// fixes a weird bug which causes the screen not to be fully // fixes a weird bug which causes the screen not to be fully
// cleared if a "clear; net.show" commands chain is executed // cleared if a "clear; net.show" commands chain is executed
@ -302,6 +321,12 @@ func (s *Session) registerCoreHandlers() {
return varNames return varNames
}))) })))
s.addHandler(NewCommandHandler("read VARIABLE PROMPT",
`^read\s+([^\s]+)\s+(.+)$`,
"Show a PROMPT to ask the user for input that will be saved inside VARIABLE.",
s.readHandler),
readline.PcItem("read"))
s.addHandler(NewCommandHandler("clear", s.addHandler(NewCommandHandler("clear",
"^(clear|cls)$", "^(clear|cls)$",
"Clear the screen.", "Clear the screen.",