Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: igoogolx/itun2socks
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.3.0
Choose a base ref
...
head repository: igoogolx/itun2socks
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref

Commits on Mar 18, 2024

  1. Copy the full SHA
    4428537 View commit details
  2. feat: upgrade web ui

    igoogolx committed Mar 18, 2024
    Copy the full SHA
    b80e66b View commit details

Commits on Apr 6, 2024

  1. chore: upgrade deps

    igoogolx committed Apr 6, 2024
    Copy the full SHA
    a8aa239 View commit details

Commits on Apr 13, 2024

  1. chore: tid mod

    igoogolx committed Apr 13, 2024
    Copy the full SHA
    008b0e8 View commit details
  2. Revert "chore: tid mod"

    This reverts commit 008b0e8.
    igoogolx committed Apr 13, 2024
    Copy the full SHA
    013b82b View commit details
  3. Revert "chore: upgrade deps"

    This reverts commit a8aa239.
    igoogolx committed Apr 13, 2024
    Copy the full SHA
    8e688f2 View commit details

Commits on May 4, 2024

  1. chore: upgrade deps

    igoogolx committed May 4, 2024
    Copy the full SHA
    cdf6444 View commit details

Commits on May 5, 2024

  1. Copy the full SHA
    f806a71 View commit details

Commits on May 8, 2024

  1. Copy the full SHA
    4eca082 View commit details
  2. Copy the full SHA
    b53b8a5 View commit details

Commits on May 25, 2024

  1. chore: upgrade deps

    igoogolx committed May 25, 2024
    Copy the full SHA
    822701d View commit details
  2. chore: upgrade deps

    igoogolx committed May 25, 2024
    Copy the full SHA
    2c75276 View commit details

Commits on Jun 10, 2024

  1. Copy the full SHA
    6052a90 View commit details

Commits on Jun 11, 2024

  1. chore: upgrade deps

    igoogolx committed Jun 11, 2024
    Copy the full SHA
    346298c View commit details

Commits on Jun 14, 2024

  1. feat(Rule): support process

    igoogolx committed Jun 14, 2024
    Copy the full SHA
    545aa9e View commit details
  2. fix(Rule): invalid process

    igoogolx committed Jun 14, 2024
    Copy the full SHA
    b2abd2d View commit details

Commits on Jun 15, 2024

  1. Copy the full SHA
    842c81b View commit details
  2. feat(Rule): full types

    igoogolx committed Jun 15, 2024
    Copy the full SHA
    757f1a9 View commit details
  3. refactor: remove unused code

    igoogolx committed Jun 15, 2024
    Copy the full SHA
    9143b60 View commit details
  4. Copy the full SHA
    6914412 View commit details
  5. fix(log): unformatted logs

    igoogolx committed Jun 15, 2024
    Copy the full SHA
    fbc52dc View commit details
  6. feat: upgrade dashboard

    igoogolx committed Jun 15, 2024
    Copy the full SHA
    1386bc3 View commit details

Commits on Jun 17, 2024

  1. Copy the full SHA
    d635c93 View commit details
  2. feat: upgrade dashboard

    igoogolx committed Jun 17, 2024
    Copy the full SHA
    84195fc View commit details

Commits on Jun 22, 2024

  1. Copy the full SHA
    68d25f4 View commit details
  2. fix(tunnel): invalid log

    igoogolx committed Jun 22, 2024
    Copy the full SHA
    f37db2d View commit details

Commits on Jun 23, 2024

  1. Copy the full SHA
    bbdf358 View commit details
  2. feat: upgrade third parties

    igoogolx committed Jun 23, 2024
    Copy the full SHA
    b73f910 View commit details
  3. feat: upgrade third parties

    igoogolx committed Jun 23, 2024
    Copy the full SHA
    9011437 View commit details

Commits on Jun 28, 2024

  1. chore: update .gitignore

    igoogolx committed Jun 28, 2024
    Copy the full SHA
    391866e View commit details
  2. chore: upgrade golang-lru

    igoogolx committed Jun 28, 2024
    Copy the full SHA
    9d2e461 View commit details
  3. feat: upgrade golang-lru/v2

    igoogolx committed Jun 28, 2024
    Copy the full SHA
    121c61d View commit details

Commits on Jun 29, 2024

  1. Copy the full SHA
    0394e90 View commit details
  2. chore: upgrade deps

    igoogolx committed Jun 29, 2024
    Copy the full SHA
    1e00fb2 View commit details
  3. feat: upgrade rules

    igoogolx committed Jun 29, 2024
    Copy the full SHA
    4047420 View commit details
  4. test: rule engine

    igoogolx committed Jun 29, 2024
    Copy the full SHA
    e774309 View commit details
  5. fix(rule): invalid dns type

    igoogolx committed Jun 29, 2024
    Copy the full SHA
    e732943 View commit details

Commits on Jul 5, 2024

  1. Copy the full SHA
    3193c72 View commit details
  2. Copy the full SHA
    208c69c View commit details

Commits on Jul 6, 2024

  1. Copy the full SHA
    35453ec View commit details
  2. Copy the full SHA
    d38414c View commit details
  3. Copy the full SHA
    8d8665a View commit details
  4. Copy the full SHA
    d8cf7ac View commit details
  5. Copy the full SHA
    d2c2d84 View commit details
  6. Copy the full SHA
    0e56c49 View commit details
  7. refactor: improve logs

    igoogolx committed Jul 6, 2024
    Copy the full SHA
    0f1c7f0 View commit details
  8. Copy the full SHA
    096ea7a View commit details
  9. refactor: improve logs

    igoogolx committed Jul 6, 2024
    Copy the full SHA
    8aa56a2 View commit details
  10. refactor: improve logs

    igoogolx committed Jul 6, 2024
    Copy the full SHA
    12c6108 View commit details
  11. feat: upgrade dashboard

    igoogolx committed Jul 6, 2024
    Copy the full SHA
    fd1e978 View commit details
Showing with 1,509 additions and 710 deletions.
  1. +4 −4 .github/workflows/build.yml
  2. +20 −0 .github/workflows/test.yml
  3. +19 −0 .github/workflows/virusTotal.yml
  4. +1 −1 .github/workflows/winget.yml
  5. +1 −0 .gitignore
  6. +3 −3 api/hub.go
  7. +61 −0 api/routes/dns.go
  8. +2 −1 api/routes/errors.go
  9. +100 −0 api/routes/heartbeat.go
  10. +57 −17 api/routes/log.go
  11. +69 −29 api/routes/proxy.go
  12. +54 −1 api/routes/routes.go
  13. +23 −1 api/routes/rule.go
  14. +1 −2 api/routes/runtime_detail.go
  15. +14 −0 api/routes/selected.go
  16. +0 −20 api/routes/setting.go
  17. +13 −56 api/routes/traffic.go
  18. +58 −50 go.mod
  19. +128 −97 go.sum
  20. +0 −31 internal/cfg/distribution/cache.go
  21. +13 −16 internal/cfg/distribution/dns.go
  22. +12 −8 internal/cfg/distribution/ruleEngine/base.go
  23. +47 −0 internal/cfg/distribution/ruleEngine/builtIn.go
  24. +16 −5 internal/cfg/distribution/ruleEngine/domain.go
  25. +14 −5 internal/cfg/distribution/ruleEngine/ipcidr.go
  26. +11 −1 internal/cfg/distribution/ruleEngine/parser.go
  27. +57 −0 internal/cfg/distribution/ruleEngine/process.go
  28. +109 −0 internal/cfg/distribution/ruleEngine/rule_engine_test.go
  29. +11 −43 internal/cfg/distribution/system_proxy.go
  30. +23 −53 internal/cfg/distribution/tun.go
  31. +1 −9 internal/cfg/system_proxy.go
  32. +11 −14 internal/cfg/tun.go
  33. +1 −1 internal/cfg/tun/tun.go
  34. +7 −9 internal/configuration/assets/config.json
  35. +5 −3 internal/configuration/config.go
  36. +0 −3 internal/configuration/file.go
  37. +53 −16 internal/configuration/proxy.go
  38. +25 −3 internal/configuration/rule.go
  39. +6 −5 internal/conn/conn.go
  40. +26 −0 internal/conn/matcher.go
  41. +6 −14 internal/conn/tcp.go
  42. +6 −12 internal/conn/udp.go
  43. +21 −4 internal/constants/constants.go
  44. +31 −0 internal/dns/cache.go
  45. +72 −44 internal/dns/client.go
  46. +11 −10 internal/dns/hijack_darwin.go
  47. +3 −3 internal/dns/hijack_others.go
  48. +47 −0 internal/dns/statistic.go
  49. +39 −10 internal/executor/executor.go
  50. +1 −1 internal/executor/sys_proxy.go
  51. +10 −7 internal/executor/tun.go
  52. +0 −3 internal/manager/manager.go
  53. +0 −25 internal/matcher/dns.go
  54. +21 −0 internal/matcher/rule.go
  55. +1 −0 internal/resolver/resolver.go
  56. +41 −3 internal/tunnel/metadata.go
  57. +22 −16 internal/tunnel/statistic/manager.go
  58. +18 −20 internal/tunnel/statistic/tracker.go
  59. +3 −7 internal/tunnel/tcp.go
  60. +51 −16 internal/tunnel/udp.go
  61. +3 −3 main.go
  62. +4 −1 pkg/log/log.go
  63. +16 −2 pkg/network_iface/monitor.go
  64. +6 −2 scripts/generate.go
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -19,17 +19,17 @@ jobs:
with:
fetch-depth: 0
- run: git fetch --force --tags
- uses: actions/setup-go@v3
- uses: actions/setup-go@v5
with:
go-version: '>=1.20.0'
go-version: '>=1.22.5'
cache: true
# More assembly might be required: Docker logins, GPG, etc. It all depends
# on your needs.
- uses: goreleaser/goreleaser-action@v5
- uses: goreleaser/goreleaser-action@v6
with:
# either 'goreleaser' (default) or 'goreleaser-pro':
distribution: goreleaser
version: latest
version: "~> v2"
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20 changes: 20 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Go
on: [push]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '>=1.22.5'
cache: true
- name: Install dependencies
run: go mod tidy
- name: Generate
run: go generate
- name: Test with the Go CLI
run: go test ./...
19 changes: 19 additions & 0 deletions .github/workflows/virusTotal.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: released

on:
release:
types: [published]

jobs:
virustotal:
runs-on: ubuntu-latest
steps:
-
name: VirusTotal Scan
uses: crazy-max/ghaction-virustotal@v4
with:
vt_api_key: ${{ secrets.VT_API_KEY }}
update_release_body: true
files: |
.zip$
.gz$
2 changes: 1 addition & 1 deletion .github/workflows/winget.yml
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ jobs:
# Action can only be run on windows
runs-on: windows-latest
steps:
- uses: vedantmgoyal2009/winget-releaser@v2
- uses: vedantmgoyal9/winget-releaser@main
with:
identifier: igoogolx.itun2socks
max-versions-to-keep: 5 # keep only latest 5 versions
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -9,3 +9,4 @@ geoData
tmp
rules
.Ds_Store
temp
6 changes: 3 additions & 3 deletions api/hub.go
Original file line number Diff line number Diff line change
@@ -6,10 +6,10 @@ import (
"strconv"
)

func Start(port int) {
func Start(port int, secret string) {
go func() {
log.Infoln(log.FormatLog(log.ExecutorPrefix, "hub is running on: http://localhost:%v"), port)
err := routes.Start("localhost:" + strconv.Itoa(port))
log.Infoln(log.FormatLog(log.ExecutorPrefix, "hub is running on: http://localhost:%v?token=%v"), port, secret)
err := routes.Start("localhost:"+strconv.Itoa(port), secret)
if err != nil {
log.Fatalln(log.FormatLog(log.ExecutorPrefix, "fail to start hub: %v"), err)
}
61 changes: 61 additions & 0 deletions api/routes/dns.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package routes

import (
"bytes"
"encoding/json"
"github.com/go-chi/chi/v5"
"github.com/go-chi/render"
"github.com/gorilla/websocket"
"github.com/igoogolx/itun2socks/internal/dns"
"net/http"
"time"
)

func dnsRouter() http.Handler {
r := chi.NewRouter()
r.Get("/statistic", getDnsStatistic)
return r
}

type Dns struct {
Success int32 `json:"success"`
Fail int32 `json:"fail"`
}

func getDnsStatistic(w http.ResponseWriter, r *http.Request) {
var wsConn *websocket.Conn
if websocket.IsWebSocketUpgrade(r) {
var err error
wsConn, err = upgrader.Upgrade(w, r, nil)
if err != nil {
return
}
}

if wsConn == nil {
w.Header().Set("Content-Type", "application/json")
render.Status(r, http.StatusOK)
}

tick := time.NewTicker(time.Second)
defer tick.Stop()
buf := &bytes.Buffer{}
var err error
for range tick.C {
buf.Reset()
if err := json.NewEncoder(buf).Encode(dns.GetStatistic()); err != nil {
break
}

if wsConn == nil {
_, err = w.Write(buf.Bytes())
w.(http.Flusher).Flush()
} else {
err = wsConn.WriteMessage(websocket.TextMessage, buf.Bytes())
}

if err != nil {
break
}
}
}
3 changes: 2 additions & 1 deletion api/routes/errors.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package routes

var (
ErrBadRequest = NewError("Body invalid")
ErrBadRequest = NewError("Body invalid")
ErrUnauthorized = NewError("Unauthorized")
)

// HTTPError is custom HTTP error for API
100 changes: 100 additions & 0 deletions api/routes/heartbeat.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package routes

import (
"encoding/json"
"github.com/go-chi/chi/v5"
"github.com/go-chi/render"
"github.com/gorilla/websocket"
"github.com/igoogolx/itun2socks/internal/manager"
"net/http"
"time"
)

func heartbeatRouter() http.Handler {
r := chi.NewRouter()
r.Get("/ping", ping)
r.Get("/runtime-status", runtimeStatus)
return r
}

func ping(w http.ResponseWriter, r *http.Request) {
var wsConn *websocket.Conn
if websocket.IsWebSocketUpgrade(r) {
var err error
wsConn, err = upgrader.Upgrade(w, r, nil)
if err != nil {
return
}
}

if wsConn == nil {
w.Header().Set("Content-Type", "application/json")
render.Status(r, http.StatusOK)
}

tick := time.NewTicker(time.Second)
defer tick.Stop()
var err error
for range tick.C {
msg := []byte("pong")
if wsConn == nil {
_, err = w.Write(msg)
w.(http.Flusher).Flush()
} else {
err = wsConn.WriteMessage(websocket.TextMessage, msg)
}
if err != nil {
break
}
}
}

func runtimeStatus(w http.ResponseWriter, r *http.Request) {
var wsConn *websocket.Conn
if websocket.IsWebSocketUpgrade(r) {
var err error
wsConn, err = upgrader.Upgrade(w, r, nil)
if err != nil {
return
}
}

if wsConn == nil {
w.Header().Set("Content-Type", "application/json")
render.Status(r, http.StatusOK)
}

tick := time.NewTicker(time.Second)
defer tick.Stop()
for range tick.C {
msg, err := getRuntimeStatus()
if err != nil {
break
}
if wsConn == nil {
msgData, err := json.Marshal(msg)
if err != nil {
break
}
_, err = w.Write(msgData)
w.(http.Flusher).Flush()
} else {
err = wsConn.WriteJSON(msg)
}
if err != nil {
break
}
}
}

type RuntimeStatus struct {
Name string `json:"name"`
Addr string `json:"addr"`
IsStarted bool `json:"isStarted"`
}

func getRuntimeStatus() (*RuntimeStatus, error) {
isStarted := manager.GetIsStarted()
name, addr := getCurProxy()
return &RuntimeStatus{name, addr, isStarted}, nil
}
74 changes: 57 additions & 17 deletions api/routes/log.go
Original file line number Diff line number Diff line change
@@ -10,6 +10,8 @@ import (
"github.com/gorilla/websocket"
"github.com/igoogolx/itun2socks/internal/constants"
"net/http"
"strconv"
"sync"
"time"
)

@@ -28,6 +30,8 @@ func logRouter() http.Handler {
}

func getLogs(w http.ResponseWriter, r *http.Request) {
var mux sync.Mutex
logs := make([]Log, 0)
levelText := r.URL.Query().Get("level")
if levelText == "" {
levelText = "info"
@@ -56,28 +60,42 @@ func getLogs(w http.ResponseWriter, r *http.Request) {

sub := log.Subscribe()
defer log.UnSubscribe(sub)
buf := &bytes.Buffer{}
var err error
for elm := range sub {
buf.Reset()
logEvent, ok := elm.(log.Event)
if !ok {
break
}
if logEvent.LogLevel < level {
continue
go func() {
for elm := range sub {
func() {
mux.Lock()
defer mux.Unlock()
logEvent, ok := elm.(log.Event)
if !ok {
return
}
if logEvent.LogLevel < level {
return
}
uid, _ := uuid.NewV4()
logs = append(logs, Log{
UUID: uid,
Time: time.Now().UnixNano() / int64(time.Millisecond),
Type: logEvent.Type(),
Payload: logEvent.Payload,
})
}()
}
}()

uid, _ := uuid.NewV4()
if err := json.NewEncoder(buf).Encode(Log{
UUID: uid,
Time: time.Now().UnixNano() / int64(time.Millisecond),
Type: logEvent.Type(),
Payload: logEvent.Payload,
}); err != nil {
break
buf := &bytes.Buffer{}
sendLogs := func() error {
mux.Lock()
defer mux.Unlock()

buf.Reset()
if err := json.NewEncoder(buf).Encode(logs); err != nil {
return err
}

logs = make([]Log, 0)

if wsConn == nil {
_, err = w.Write(buf.Bytes())
w.(http.Flusher).Flush()
@@ -86,6 +104,28 @@ func getLogs(w http.ResponseWriter, r *http.Request) {
}

if err != nil {
return err
}
return nil
}

intervalStr := r.URL.Query().Get("interval")
interval := 1000
if intervalStr != "" {
t, err := strconv.Atoi(intervalStr)
if err != nil {
render.Status(r, http.StatusBadRequest)
render.JSON(w, r, ErrBadRequest)
return
}

interval = t
}

tick := time.NewTicker(time.Millisecond * time.Duration(interval))
defer tick.Stop()
for range tick.C {
if err := sendLogs(); err != nil {
break
}
}
Loading