-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from Crazybus/box_me_in_real_virtual_life
Add cmdProxy client to allow running commands on the host machine
- Loading branch information
Showing
7 changed files
with
110 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Ignore everything | ||
* | ||
|
||
# But not these files... | ||
!.gitignore | ||
!cmdProxy.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
type lopeCmd struct { | ||
Command string `json:"command"` | ||
Args []string `json:"args"` | ||
} | ||
|
||
func run(cmd string, args []string, url string) { | ||
|
||
lopeCmd := lopeCmd{ | ||
Command: cmd, | ||
Args: args, | ||
} | ||
|
||
b, err := json.Marshal(lopeCmd) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
req, err := http.NewRequest("POST", url, bytes.NewBuffer(b)) | ||
req.Header.Set("Content-Type", "application/json") | ||
|
||
client := &http.Client{} | ||
resp, err := client.Do(req) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer resp.Body.Close() | ||
|
||
body, _ := ioutil.ReadAll(resp.Body) | ||
fmt.Print(string(body)) | ||
} | ||
|
||
func main() { | ||
cmd := filepath.Base(os.Args[0]) | ||
args := os.Args[1:] | ||
|
||
url, ok := os.LookupEnv("LOPE_PROXY_ADDR") | ||
if !ok { | ||
fmt.Println("Please set the 'LOPE_PROXY_ADDR' environment variable") | ||
os.Exit(1) | ||
} | ||
run(cmd, args, url) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters