From 6e2a56b4c66a6ad9ee541ba2e7eb991506b42ef8 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Fri, 31 Jan 2020 17:12:24 +0530 Subject: [PATCH] Added support for static site along with tunnel api, re-organized readme content --- README.md | 140 +++++++++++++++++++++++++++++------------------------- tunnel.go | 8 +++- 2 files changed, 81 insertions(+), 67 deletions(-) diff --git a/README.md b/README.md index 3489621..448495e 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,10 @@ It establishes a bridge between system and web for performing task on system via web. -### For end-user -Download the app from [releases](https://github.com/isurfer21/tunnel/releases) section of the [repository](https://github.com/isurfer21/tunnel). +## Setup +Please follow the below instruction to install the `tunnel` on target system. #### Install latest version - With *Shell*: ```bash @@ -20,60 +19,101 @@ iwr https://isurfer21.github.io/tunnel/install.ps1 -useb | iex ``` #### Install specific version - With *Shell*: ```bash -curl -fsSL https://isurfer21.github.io/tunnel/install.sh | sh -s v1.0.1 +curl -fsSL https://isurfer21.github.io/tunnel/install.sh | sh -s v2.0.0 ``` With *PowerShell*: ```powershell -iwr https://isurfer21.github.io/tunnel/install.ps1 -useb -outf install.ps1; .\install.ps1 v1.0.1 +iwr https://isurfer21.github.io/tunnel/install.ps1 -useb -outf install.ps1; .\install.ps1 v2.0.0 ``` +#### Manual setup + +1. Download the app from [releases](https://github.com/isurfer21/tunnel/releases) section of the [repository](https://github.com/isurfer21/tunnel). +2. Access it from anywhere by adding the app path in the system path. + + +## Usage +Below mentioned switches can be shuffled based on requirement, so explore it via help + + tunnel -h + #### Default or local Accessible on host system at default port, i.e., 9999; without credentials so it uses default credentials -```bash -$ tunnel -``` + tunnel #### Authenticative Accessible at default host & port, i.e., localhost:9999 but APIs will become accessible only using credentials -```bash -$ tunnel -i admin -c 123456 -``` + tunnel -i admin -c 123456 #### Custom host & port Accessible on all systems over network at custom port -```bash -$ tunnel -u 192.168.0.100 -p 8080 + tunnel -u 192.168.0.100 -p 8080 + +#### Serve cross domain request +Serve cross-site incoming request from host system only + + tunnel -x + +Serve cross-site request from any systems + + tunnel -x -u 192.168.0.100 -p 8080 + +#### Custom host & port +Serve along with static site at `./` location + + tunnel -d + +Serve along with static site at `./app` location + + tunnel -d=./app + + +## API +The API Key can be generated using `tunnel.genApiKey(username, password)` that can be kept separate, so as to avoid disclosing the credentials. + +#### Example: Basic + +```js +(function main() { + console.log('main'); + let tunnel = new Tunnel(); + let failure = (options, status, error) => { + console.log('[1] main.failure', status, error); + }; + tunnel.login('admin', '123456'); + tunnel.authenticate((result) => { + console.log('[1] main.authenticate.success', result); + tunnel.terminal('ls', (result) => { + console.log('[2] main.terminal.success', result); + }, failure); + }, failure); +}()); ``` -### For developer +## Development #### Compile/Run To directly compile and run the source code, -```bash -$ cd tunnel -$ go run tunnel.go -``` + cd tunnel + go run tunnel.go it will start the tunnel #### Build To build the executable from source code, -```bash -$ cd tunnel -$ go build tunnel.go -``` + cd tunnel + go build tunnel.go it will create the tunnel executable file for current OS @@ -82,61 +122,31 @@ To build the cross-platform executable from source code, on **macOS**, -```bash -$ cd tunnel -$ sh build.sh -``` + cd tunnel + sh build.sh on **Windows**, -```bash -$ cd tunnel -$ build.bat -``` + cd tunnel + build.bat it will generate the tunnel executable files for all supported OS - -#### For tester +## Testing The APIs can be tested using python3 on command-line or using an standalone html page at browser that is being served via default embedded static web server in the app. -##### Python -```bash -$ tunnel -$ python3 ./test/test.py -``` - -##### HTML+JS -```bash -$ tunnel -$ open http://127.0.0.1:9999/test/demo.html -``` - +#### Python -#### Using API -The API Key can be generated using `tunnel.genApiKey(username, password)` that can be kept separate, so as to avoid disclosing the credentials. + tunnel + python3 ./test/test.py -##### Example: Basic +#### HTML+JS -```js -(function main() { - console.log('main'); - let tunnel = new Tunnel(); - let failure = (options, status, error) => { - console.log('[1] main.failure', status, error); - }; - tunnel.login('admin', '123456'); - tunnel.authenticate((result) => { - console.log('[1] main.authenticate.success', result); - tunnel.terminal('ls', (result) => { - console.log('[2] main.terminal.success', result); - }, failure); - }, failure); -}()); -``` + tunnel + open http://127.0.0.1:9999/test/demo.html -### References +## References 1. [isurfer21/Suxm](https://github.com/isurfer21/Suxm) \ No newline at end of file diff --git a/tunnel.go b/tunnel.go index 155e82a..169ec98 100644 --- a/tunnel.go +++ b/tunnel.go @@ -248,7 +248,11 @@ func (s Server) initialize() { }() ws := WebService{} - http.HandleFunc("/", ws.handShake) + if docPath != "" { + http.Handle("/", http.FileServer(http.Dir(s.docRoot))) + } else { + http.HandleFunc("/", ws.handShake) + } http.HandleFunc("/authenticate", ws.authenticate) http.HandleFunc("/terminal", ws.terminal) http.ListenAndServe(httpAddr, nil) @@ -256,7 +260,7 @@ func (s Server) initialize() { var ( appName = "Tunnel" - version = "2.0.0" + version = "2.0.1" docPath = "" hostIP = "127.0.0.1" portNum = 9999