mirror of
https://github.com/bettercap/bettercap
synced 2025-08-14 18:57:17 -07:00
misc: small fix or general refactoring i did not bother commenting
This commit is contained in:
parent
d2f13a3293
commit
209725d623
5 changed files with 43 additions and 2 deletions
|
@ -95,6 +95,27 @@ func jsOnEventFunc(call otto.FunctionCall) otto.Value {
|
|||
return js.NullValue
|
||||
}
|
||||
|
||||
func jsSaveToFileFunc(call otto.FunctionCall) otto.Value {
|
||||
argv := call.ArgumentList
|
||||
argc := len(argv)
|
||||
if argc != 2 {
|
||||
return js.ReportError("saveToFile accepts two string arguments")
|
||||
} else if argv[0].IsString() == false {
|
||||
return js.ReportError("saveToFile accepts two string arguments")
|
||||
} else if argv[1].IsString() == false {
|
||||
return js.ReportError("saveToFile accepts two string arguments")
|
||||
}
|
||||
|
||||
fileName := argv[0].String()
|
||||
data := argv[1].String()
|
||||
|
||||
if err := ioutil.WriteFile(fileName, []byte(data), os.ModePerm); err != nil {
|
||||
return js.ReportError("error writing to '%s': %v", fileName, err)
|
||||
}
|
||||
|
||||
return js.NullValue
|
||||
}
|
||||
|
||||
func jsSaveJSONFunc(call otto.FunctionCall) otto.Value {
|
||||
argv := call.ArgumentList
|
||||
argc := len(argv)
|
||||
|
|
|
@ -328,6 +328,7 @@ func (s *Session) Start() error {
|
|||
plugin.Defines["fileExists"] = jsFileExistsFunc
|
||||
plugin.Defines["loadJSON"] = jsLoadJSONFunc
|
||||
plugin.Defines["saveJSON"] = jsSaveJSONFunc
|
||||
plugin.Defines["saveToFile"] = jsSaveToFileFunc
|
||||
plugin.Defines["onEvent"] = jsOnEventFunc
|
||||
plugin.Defines["session"] = s
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue