Skip to content

Commit

Permalink
Added support for static site along with tunnel api, re-organized rea…
Browse files Browse the repository at this point in the history
…dme content
  • Loading branch information
isurfer21 committed Jan 31, 2020
1 parent fe819d1 commit 6e2a56b
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 67 deletions.
140 changes: 75 additions & 65 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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)
8 changes: 6 additions & 2 deletions tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,19 @@ 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)
}

var (
appName = "Tunnel"
version = "2.0.0"
version = "2.0.1"
docPath = ""
hostIP = "127.0.0.1"
portNum = 9999
Expand Down

0 comments on commit 6e2a56b

Please sign in to comment.