new: new writeFile(path, data) proxy module builtin function

This commit is contained in:
evilsocket 2018-03-19 19:11:35 +01:00
parent 86ba73f5bb
commit 9be87717cc
No known key found for this signature in database
GPG key ID: 1564D7F30393A456

View file

@ -102,6 +102,24 @@ func (s *ProxyScript) defineBuiltins() error {
return v return v
}) })
s.VM.Set("writeFile", func(call otto.FunctionCall) otto.Value {
argv := call.ArgumentList
argc := len(argv)
if argc != 2 {
return errOtto("writeFile: expected 2 arguments, %d given instead.", argc)
}
filename := argv[0].String()
data := argv[1].String()
err := ioutil.WriteFile(filename, []byte(data), 0644)
if err != nil {
return errOtto("Could not write %d bytes to %s: %s", len(data), filename, err)
}
return otto.NullValue()
})
// log something // log something
s.VM.Set("log", func(call otto.FunctionCall) otto.Value { s.VM.Set("log", func(call otto.FunctionCall) otto.Value {
for _, v := range call.ArgumentList { for _, v := range call.ArgumentList {