Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
zu1k committed Aug 11, 2020
0 parents commit d1c539f
Show file tree
Hide file tree
Showing 26 changed files with 1,219 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] ['zu1k']
patreon: zu1k # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: ['https://blog.lgf.im/donate/']# Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
17 changes: 17 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"

- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "daily"

- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "daily"

21 changes: 21 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: docker

on: [push, pull_request]

jobs:
build:
name: Build
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/[email protected]

- name: Build and push Docker images
uses: docker/[email protected]
with:
username: zu1k
password: ${{ secrets.GITHUB_TOKEN }}
registry: docker.pkg.github.com
repository: zu1k/proxypool/proxypool
tag_with_ref: true
50 changes: 50 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Go
on: [push, pull_request]
jobs:

build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.14.x

- name: Check out code into the Go module directory
uses: actions/[email protected]

- name: Cache go module
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Get dependencies and run test
run: |
go test ./...
- name: Build
if: startsWith(github.ref, 'refs/tags/')
env:
NAME: proxypool
BINDIR: bin
run: make -j releases

- name: Upload Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: bin/*
draft: true
prerelease: true

- uses: actions/[email protected]
if: startsWith(github.ref, 'refs/tags/')
with:
name: build
path: bin
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
bin/*

# Test binary, build with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# dep
vendor

# GoLand
.idea/*

# macOS file
.DS_Store

*.exe
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM golang:alpine as builder

RUN apk add --no-cache make git
WORKDIR /proxypool-src
COPY . /proxypool-src
RUN go mod download && \
make docker && \
mv ./bin/proxypool-docker /proxypool

FROM alpine:latest

RUN apk add --no-cache ca-certificates
COPY --from=builder /proxypool /
ENTRYPOINT ["/proxypool"]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright © 2020 zu1k

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.
97 changes: 97 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
NAME=proxypool
BINDIR=bin
VERSION=$(shell git describe --tags || echo "unknown version")
GOBUILD=CGO_ENABLED=0 go build -trimpath -ldflags '-w -s'

PLATFORM_LIST = \
darwin-amd64 \
linux-386 \
linux-amd64 \
linux-armv5 \
linux-armv6 \
linux-armv7 \
linux-armv8 \
linux-mips-softfloat \
linux-mips-hardfloat \
linux-mipsle-softfloat \
linux-mipsle-hardfloat \
linux-mips64 \
linux-mips64le \
freebsd-386 \
freebsd-amd64

WINDOWS_ARCH_LIST = \
windows-386 \
windows-amd64

all: linux-amd64 darwin-amd64 windows-amd64 # Most used

docker:
$(GOBUILD) -o $(BINDIR)/$(NAME)-$@

darwin-amd64:
GOARCH=amd64 GOOS=darwin $(GOBUILD) -o $(BINDIR)/$(NAME)-$@

linux-386:
GOARCH=386 GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@

linux-amd64:
GOARCH=amd64 GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@

linux-armv5:
GOARCH=arm GOOS=linux GOARM=5 $(GOBUILD) -o $(BINDIR)/$(NAME)-$@

linux-armv6:
GOARCH=arm GOOS=linux GOARM=6 $(GOBUILD) -o $(BINDIR)/$(NAME)-$@

linux-armv7:
GOARCH=arm GOOS=linux GOARM=7 $(GOBUILD) -o $(BINDIR)/$(NAME)-$@

linux-armv8:
GOARCH=arm64 GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@

linux-mips-softfloat:
GOARCH=mips GOMIPS=softfloat GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@

linux-mips-hardfloat:
GOARCH=mips GOMIPS=hardfloat GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@

linux-mipsle-softfloat:
GOARCH=mipsle GOMIPS=softfloat GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@

linux-mipsle-hardfloat:
GOARCH=mipsle GOMIPS=hardfloat GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@

linux-mips64:
GOARCH=mips64 GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@

linux-mips64le:
GOARCH=mips64le GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@

freebsd-386:
GOARCH=386 GOOS=freebsd $(GOBUILD) -o $(BINDIR)/$(NAME)-$@

freebsd-amd64:
GOARCH=amd64 GOOS=freebsd $(GOBUILD) -o $(BINDIR)/$(NAME)-$@

windows-386:
GOARCH=386 GOOS=windows $(GOBUILD) -o $(BINDIR)/$(NAME)-$@.exe

windows-amd64:
GOARCH=amd64 GOOS=windows $(GOBUILD) -o $(BINDIR)/$(NAME)-$@.exe

gz_releases=$(addsuffix .gz, $(PLATFORM_LIST))
zip_releases=$(addsuffix .zip, $(WINDOWS_ARCH_LIST))

$(gz_releases): %.gz : %
chmod +x $(BINDIR)/$(NAME)-$(basename $@)
gzip -f -S -$(VERSION).gz $(BINDIR)/$(NAME)-$(basename $@)

$(zip_releases): %.zip : %
zip -m -j $(BINDIR)/$(NAME)-$(basename $@)-$(VERSION).zip $(BINDIR)/$(NAME)-$(basename $@).exe

all-arch: $(PLATFORM_LIST) $(WINDOWS_ARCH_LIST)

releases: $(gz_releases) $(zip_releases)
clean:
rm $(BINDIR)/*
31 changes: 31 additions & 0 deletions api/router.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package api

import (
"os"

"github.com/gin-gonic/gin"
_ "github.com/heroku/x/hmetrics/onload"
"github.com/zu1k/proxypool/app"
"github.com/zu1k/proxypool/provider"
)

var router *gin.Engine

func setupRouter() {
router = gin.Default()

router.GET("/clash/proxies", func(c *gin.Context) {
proxies := app.GetProxies()
clash := provider.Clash{Proxies: proxies}
c.String(200, clash.Provide())
})
}

func Run() {
setupRouter()
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
router.Run(":" + port)
}
23 changes: 23 additions & 0 deletions app/cache.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package app

import (
"time"

"github.com/zu1k/proxypool/proxy"

"github.com/patrickmn/go-cache"
)

var c = cache.New(cache.NoExpiration, 10*time.Minute)

func GetProxies() []proxy.Proxy {
result, found := c.Get("proxies")
if found {
return result.([]proxy.Proxy)
}
return nil
}

func SetProxies(proxies []proxy.Proxy) {
c.Set("proxies", proxies, cache.NoExpiration)
}
11 changes: 11 additions & 0 deletions app/cron.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package app

import (
"github.com/jasonlvhit/gocron"
)

func Cron() {
gocron.Every(10).Minutes().Do(CrawlTGChannel)

<-gocron.Start()
}
21 changes: 21 additions & 0 deletions app/task.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package app

import (
"fmt"

"github.com/zu1k/proxypool/getter"
"github.com/zu1k/proxypool/proxy"
)

func CrawlTGChannel() {
node := make([]proxy.Proxy, 0)
node = append(node, getter.NewTGSsrlistGetter("https://t.me/s/ssrList", 200).Get()...)
node = append(node, getter.NewTGSsrlistGetter("https://t.me/s/SSRSUB", 200).Get()...)
node = append(node, getter.NewTGSsrlistGetter("https://t.me/s/FreeSSRNode", 200).Get()...)
node = append(node, getter.NewTGSsrlistGetter("https://t.me/s/ssrlists", 200).Get()...)

node = append(node, GetProxies()...)
node = proxy.Deduplication(node)
fmt.Println(len(node))
SetProxies(node)
}
42 changes: 42 additions & 0 deletions example/clash-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# port of HTTP
port: 7890

# port of SOCKS5
socks-port: 7891

# (HTTP and SOCKS5 in one port)
# mixed-port: 7890

# redir port for Linux and macOS
# redir-port: 7892

allow-lan: false
mode: rule
log-level: info
external-controller: 127.0.0.1:9090

proxies:

proxy-groups:
- name: free
type: select
use:
- free
proxies:
- DIRECT

proxy-providers:
free:
type: http
url: "http://127.0.0.1:8080/clash/proxies"
interval: 3600
path: ./free.yaml
health-check:
enable: true
interval: 600
url: http://www.gstatic.com/generate_204

rules:
- IP-CIDR,127.0.0.0/8,DIRECT
- IP-CIDR,192.168.0.0/16,DIRECT
- MATCH,free
Loading

0 comments on commit d1c539f

Please sign in to comment.