refact: refactored proxy script builtins in separated file.

This commit is contained in:
evilsocket 2018-01-10 19:09:18 +01:00
parent b8dd20ceae
commit 611e3fe078
2 changed files with 35 additions and 16 deletions

View file

@ -0,0 +1,30 @@
package modules
import (
"io/ioutil"
"github.com/evilsocket/bettercap-ng/log"
"github.com/robertkrimen/otto"
)
// define functions available to proxy scripts
func (s *ProxyScript) defineBuiltins() error {
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
})
return nil
}