mirror of
https://github.com/bettercap/bettercap
synced 2025-07-10 23:33:28 -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
30
modules/http_proxy_script_builtins.go
Normal file
30
modules/http_proxy_script_builtins.go
Normal 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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue