Compare commits
2 commits
Author | SHA1 | Date | |
---|---|---|---|
|
c4321d1bbd | ||
|
8571e380a6 |
5 changed files with 54 additions and 34 deletions
21
LICENSE
21
LICENSE
|
@ -1,21 +0,0 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2020 Anders Pitman
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
13
README.md
13
README.md
|
@ -20,7 +20,7 @@ And you run the following command on your laptop:
|
|||
ssh -tR 9001:localhost:8080 example.com sirtunnel.py sub1.example.com 9001
|
||||
```
|
||||
|
||||
Now any requests to `https://sub1.example.com` will be proxied to your local
|
||||
Now any requests to `https://sub.example.com` will be proxied to your local
|
||||
webserver.
|
||||
|
||||
|
||||
|
@ -77,17 +77,6 @@ recommended), setting the `CAP_NET_BIND_SERVICE` capability on the Caddy binary
|
|||
to a different port (say 9000) and using something like iptables to forward
|
||||
to that port.
|
||||
|
||||
# Future Features
|
||||
|
||||
SirTunnel is intended to be a minimal tool. As such, I'm unlikely to add many
|
||||
features moving forward. However, the simplicity makes it easier to modify
|
||||
for your needs. If you find a feature missing, maybe one of the forks below
|
||||
has what you need or gives you some ideas:
|
||||
|
||||
* https://github.com/matiboy/SirTunnel adds functionality to help multiple
|
||||
users avoid overwriting each others' tunnels.
|
||||
* https://github.com/daps94/SirTunnel implements tunnel checking and auto
|
||||
cleanup to address issue with stale tunnels.
|
||||
|
||||
|
||||
[0]: https://github.com/anderspitman/awesome-tunneling
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#/bin/bash
|
||||
|
||||
caddyVersion=2.1.1
|
||||
sirtunnelVersion=0.1.0
|
||||
|
||||
echo Download Caddy
|
||||
caddyGz=caddy_${caddyVersion}_linux_amd64.tar.gz
|
||||
|
|
51
sirtunnel.go
Normal file
51
sirtunnel.go
Normal file
|
@ -0,0 +1,51 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"net/http"
|
||||
"bytes"
|
||||
)
|
||||
|
||||
|
||||
func main() {
|
||||
|
||||
args := os.Args[1:]
|
||||
tunnelSpecParts := strings.Split(args[0], ":")
|
||||
tunnelId := args[0]
|
||||
host := tunnelSpecParts[0]
|
||||
port := tunnelSpecParts[1]
|
||||
|
||||
client := &http.Client{}
|
||||
|
||||
caddyAddRouteStr := fmt.Sprintf("{\"@id\":\"%s\",\"match\":[{\"host\":[\"%s\"]}],\"handle\":[{\"handler\":\"reverse_proxy\",\"upstreams\":[{\"dial\":\":%s\"}]}]}", tunnelId, host, port);
|
||||
|
||||
resp, err := http.Post("http://127.0.0.1:2019/config/apps/http/servers/sirtunnel/routes", "application/json", bytes.NewBuffer([]byte(caddyAddRouteStr)))
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("Tunnel creation failed")
|
||||
panic(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
fmt.Println("Tunnel created successfully")
|
||||
|
||||
// wait for CTRL-C
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, os.Interrupt)
|
||||
<-c
|
||||
|
||||
fmt.Println("Cleaning up tunnel")
|
||||
|
||||
req, err := http.NewRequest("DELETE", fmt.Sprintf("http://127.0.0.1:2019/id/%s", tunnelId), nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
req.Header.Add("Content-Type", "application/json")
|
||||
_, err = client.Do(req)
|
||||
|
||||
fmt.Println("Exiting")
|
||||
}
|
|
@ -4,4 +4,4 @@ domain=$1
|
|||
serverPort=$2
|
||||
localPort=$3
|
||||
|
||||
ssh -t -R $serverPort:localhost:$localPort $domain sirtunnel $domain $serverPort
|
||||
ssh -t -R $serverPort:localhost:$localPort $domain sirtunnel $domain:$serverPort
|
Loading…
Reference in a new issue