mirror of
https://github.com/bettercap/bettercap
synced 2025-07-07 13:32:07 -07:00
new: implemented new 'read' session command
This commit is contained in:
parent
6947a22c5c
commit
07f047dff3
1 changed files with 25 additions and 0 deletions
|
@ -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.",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue