mirror of
https://github.com/bettercap/bettercap
synced 2025-07-14 00:53:46 -07:00
new: new writeFile(path, data) proxy module builtin function
This commit is contained in:
parent
86ba73f5bb
commit
9be87717cc
1 changed files with 18 additions and 0 deletions
|
@ -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 {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue