mirror of
https://github.com/bettercap/bettercap
synced 2025-08-19 21:13:18 -07:00
refact: exposing readFile builtin function to proxy scripts.
This commit is contained in:
parent
17bbae48a3
commit
493867be6b
3 changed files with 95 additions and 60 deletions
|
@ -57,6 +57,23 @@ func LoadProxyScript(path string, sess *session.Session) (err error, s *ProxyScr
|
|||
return
|
||||
}
|
||||
|
||||
// define builtins
|
||||
s.VM.Set("readFile", func(call otto.FunctionCall) otto.Value {
|
||||
filename := call.Argument(0).String()
|
||||
raw, err := ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
s.sess.Events.Log(session.ERROR, "Could not read %s: %s", filename, err)
|
||||
return otto.Value{}
|
||||
}
|
||||
|
||||
v, err := s.VM.ToValue(string(raw))
|
||||
if err != nil {
|
||||
s.sess.Events.Log(session.ERROR, "Could not convert to string: %s", err)
|
||||
return otto.Value{}
|
||||
}
|
||||
return v
|
||||
})
|
||||
|
||||
// run onLoad if defined
|
||||
if s.hasCallback("onLoad") {
|
||||
_, err = s.VM.Run("onLoad()")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue