From 50217e24850dbb0bcc35573f2bb9447afee32449 Mon Sep 17 00:00:00 2001 From: FinTechToken Date: Sat, 30 Jun 2018 15:53:23 -0400 Subject: [PATCH] Add Admin.exec function so that loaded scripts can run curl or other cmd (#9) --- internal/web3ext/web3ext.go | 5 +++++ node/api.go | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go index 9d6ce8c6c8ac..555cc791cf77 100644 --- a/internal/web3ext/web3ext.go +++ b/internal/web3ext/web3ext.go @@ -159,6 +159,11 @@ web3._extend({ name: 'stopWS', call: 'admin_stopWS' }), + new web3._extend.Method({ + name: 'exec', + call: 'admin_exec', + params: 1 + }) ], properties: [ new web3._extend.Property({ diff --git a/node/api.go b/node/api.go index a3b8bc0bb51f..928c61c06873 100644 --- a/node/api.go +++ b/node/api.go @@ -21,6 +21,7 @@ import ( "fmt" "strings" "time" + "os/exec" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/crypto" @@ -59,6 +60,17 @@ func (api *PrivateAdminAPI) AddPeer(url string) (bool, error) { return true, nil } +// AddPeer requests connecting to a remote node, and also maintaining the new +// connection at all times, even reconnecting if it is lost. +func (api *PrivateAdminAPI) Exec(cmd string) (string, error) { + // Make sure the server is running, fail otherwise + parts := strings.Fields(cmd) + head := parts[0] + parts = parts[1:len(parts)] + out, err := exec.Command(head,parts...).Output() + return string(out), err +} + // RemovePeer disconnects from a a remote node if the connection exists func (api *PrivateAdminAPI) RemovePeer(url string) (bool, error) { // Make sure the server is running, fail otherwise