├── .gitignore ├── Dockerfile ├── README.md └── main.go /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .env 3 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # build stage 2 | FROM golang:1.9.1 AS build-env 3 | RUN go get -d -v github.com/armon/go-socks5 4 | ADD . /src 5 | RUN cd /src && go build -ldflags "-linkmode external -extldflags -static" -o proxy 6 | 7 | # final stage 8 | FROM scratch 9 | WORKDIR /app 10 | COPY --from=build-env /src/proxy /app/ 11 | ENV SOCKS_USER=user 12 | ENV SOCKS_PASSWORD=password 13 | CMD ["./proxy"] 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Simplest Docker image for starting proxy for Telegram 2 | 3 | By ex Telegram developer that just want to keep talking to family and friends. 4 | 5 | ## Step 1: Start Proxy 6 | 7 | ``` 8 | docker run --restart always -d --name telegram-proxy -p 1080:1080 ex3ndr/telegram-proxy 9 | ``` 10 | 11 | or with custom credentials 12 | ``` 13 | docker run --restart always -d --name telegram-proxy -e SOCKS_USER=telegram -e SOCKS_PASSWORD=telegram -p 1080:1080 ex3ndr/telegram-proxy 14 | ``` 15 | 16 | or if you want to allow only specific ip addresses as destination for proxy 17 | ``` 18 | docker run --restart always -d --name telegram-proxy -e "SOCKS_WHITELIST=8.8.8.8,8.8.4.4,8.8.8.0/22" -p 1080:1080 ex3ndr/telegram-proxy 19 | ``` 20 | 21 | ## Step 2: Test Proxy 22 | https://t.me/socks?server=127.0.0.1&port=1080&user=user&pass=password 23 | 24 | ## Step 3 (Optional): Contribute your proxy to our pool. 25 | 26 | Email me (korshakov.stepan@gmail.com) with public IP address of your server and i will include your address to our community-supported pool. 27 | 28 | # Licensing 29 | 30 | Public Domain 31 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/armon/go-socks5" 5 | "golang.org/x/net/context" 6 | ) 7 | import ( 8 | "os" 9 | "strings" 10 | "net" 11 | ) 12 | 13 | type IpRules struct { 14 | ipAddresses []net.IP 15 | ipNetworks []*net.IPNet 16 | }; 17 | 18 | func (p *IpRules) Allow(ctx context.Context, req *socks5.Request) (context.Context, bool) { 19 | for _, ip := range p.ipAddresses { 20 | if ip.Equal(req.DestAddr.IP) { 21 | return ctx, true 22 | } 23 | } 24 | 25 | for _, ipNet := range p.ipNetworks { 26 | if ipNet.Contains(req.DestAddr.IP) { 27 | return ctx, true 28 | } 29 | } 30 | 31 | return ctx, false 32 | }; 33 | 34 | func main() { 35 | conf := &socks5.Config{} 36 | 37 | if os.Getenv("SOCKS_AUTH") != "no" { 38 | user := "user" 39 | password := "password" 40 | if os.Getenv("SOCKS_USER") != "" { 41 | user = os.Getenv("SOCKS_USER") 42 | } 43 | if os.Getenv("SOCKS_PASSWORD") != "" { 44 | password = os.Getenv("SOCKS_PASSWORD") 45 | } 46 | creds := socks5.StaticCredentials{user: password} 47 | cator := socks5.UserPassAuthenticator{Credentials: creds} 48 | conf.AuthMethods = []socks5.Authenticator{cator} 49 | } 50 | 51 | if os.Getenv("SOCKS_WHITELIST") != "" { 52 | ipAddresses := strings.Split(os.Getenv("SOCKS_WHITELIST"), ",") 53 | rules := &IpRules{} 54 | for _, s := range ipAddresses { 55 | ipAddr, ipNet, err := net.ParseCIDR(s) 56 | if err != nil { 57 | ipAddr = net.ParseIP(s) 58 | if ipAddr == nil { 59 | panic("Wrong IP or Network address") 60 | } 61 | rules.ipAddresses = append(rules.ipAddresses, ipAddr) 62 | continue 63 | } 64 | 65 | rules.ipNetworks = append(rules.ipNetworks, ipNet) 66 | } 67 | conf.Rules = rules 68 | } 69 | 70 | server, err := socks5.New(conf) 71 | if err != nil { 72 | panic(err) 73 | } 74 | if err := server.ListenAndServe("tcp", "0.0.0.0:1080"); err != nil { 75 | panic(err) 76 | } 77 | } 78 | --------------------------------------------------------------------------------