Skip to content

Commit

Permalink
Add Admin.exec function so that loaded scripts can run curl or other …
Browse files Browse the repository at this point in the history
…cmd (#9)
  • Loading branch information
TuitionCoin authored Jun 30, 2018
1 parent a322f42 commit 50217e2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/web3ext/web3ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
12 changes: 12 additions & 0 deletions node/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"strings"
"time"
"os/exec"

"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 50217e2

Please sign in to comment.