Skip to content

Commit 93b9bd3

Browse files
author
zhaochengyu
committed
first commit
0 parents  commit 93b9bd3

File tree

5 files changed

+85
-0
lines changed

5 files changed

+85
-0
lines changed

Dockerfile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM alpine:3.5
2+
3+
RUN apk add --no-cache --virtual .build-deps ca-certificates curl unzip
4+
5+
ADD configure.sh /configure.sh
6+
RUN chmod +x /configure.sh
7+
CMD /configure.sh

app.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "PortFwd",
3+
"description": "Deploy PortFwd on Heroku.",
4+
"keywords": ["PortFwd"],
5+
"env": {
6+
"TARGET": {
7+
"description": "PortFwd target ipaddress:port",
8+
"value": "baidu.com:443"
9+
}
10+
},
11+
"website": "",
12+
"repository": "",
13+
"stack": "container"
14+
}

configure.sh

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/sh
2+
3+
# Download and install V2Ray
4+
mkdir /tmp/portfwd
5+
curl -L -H "Cache-Control: no-cache" -o /tmp/portfwd/portfwd.zip https://github.com/FunnyWolf/portfwd-heroku/releases/download/v1.0/releases.zip
6+
unzip /tmp/portfwd/portfwd.zip -d /tmp/portfwd
7+
install -m 755 /tmp/portfwd/portfwd /usr/local/bin/portfwd
8+
9+
# Remove temporary directory
10+
rm -rf /tmp/portfwd
11+
12+
# Run portfwd
13+
/usr/local/bin/portfwd -target "$UUID"

heroku.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build:
2+
docker:
3+
web: Dockerfile

main.go

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
"io"
7+
"net"
8+
)
9+
func main() {
10+
target := flag.String("target", "baidu.com:443", "The relay server (the connect-back address)")
11+
flag.Parse()
12+
locallistener, err :=net.Listen("tcp", "0.0.0.0:443")
13+
if err != nil {
14+
fmt.Errorf("Could not bind to port : %v\n", err)
15+
return
16+
}
17+
defer locallistener.Close()
18+
fmt.Printf("PortFwd to : %s\n", *target)
19+
for {
20+
stream, err := locallistener.Accept()
21+
if err != nil {
22+
return
23+
}
24+
proxyConn, err := net.Dial("tcp", *target)
25+
if err != nil {
26+
fmt.Errorf("Error creating Proxy TCP connection ! Error : %s\n", err)
27+
return
28+
}
29+
go handleRelay(stream, proxyConn)
30+
}
31+
}
32+
func handleRelay(src net.Conn, dst net.Conn) {
33+
stop := make(chan bool, 2)
34+
go relay(src, dst, stop)
35+
go relay(dst, src, stop)
36+
select {
37+
case <-stop:
38+
return
39+
}
40+
}
41+
42+
func relay(src net.Conn, dst net.Conn, stop chan bool) {
43+
io.Copy(dst, src)
44+
dst.Close()
45+
src.Close()
46+
stop <- true
47+
return
48+
}

0 commit comments

Comments
 (0)