mirror of
https://github.com/bettercap/bettercap
synced 2025-07-12 16:13:48 -07:00
refact: refactored proxy script builtins in separated file.
This commit is contained in:
parent
b8dd20ceae
commit
611e3fe078
2 changed files with 35 additions and 16 deletions
|
@ -58,22 +58,11 @@ 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 {
|
||||
log.Error("Could not read %s: %s", filename, err)
|
||||
return otto.Value{}
|
||||
}
|
||||
|
||||
v, err := s.VM.ToValue(string(raw))
|
||||
if err != nil {
|
||||
log.Error("Could not convert to string: %s", err)
|
||||
return otto.Value{}
|
||||
}
|
||||
return v
|
||||
})
|
||||
err = s.defineBuiltins()
|
||||
if err != nil {
|
||||
log.Error("Error while defining builtin functions: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
// run onLoad if defined
|
||||
if s.hasCallback("onLoad") {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue