Skip to content

Commit

Permalink
0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
zhyonc committed Feb 26, 2024
1 parent 941f05f commit 9036279
Show file tree
Hide file tree
Showing 53 changed files with 7,881 additions and 1 deletion.
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,19 @@

# Go workspace file
go.work

# Temp file
config.toml
/resources/user_rule.txt
/resources/Hierarchy.vsdx
gfwlist.txt
user_rule.txt
pac.js
pac_temp.js

# Vscode
.vs
.vscode

# Dependencies
!liblcl.dll
43 changes: 42 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,43 @@
# sysproxy
<img src="/resources/icon.png" alt="[logo]" width="48"/> sysproxy
=======================
### What it is
Windows system proxy forward tool that display as tray menu

### Features
- Support system proxy protocol is pac/http/socks5
- Extend forward protocol is http/socks5
- Customize domain rules to pac file

### Download
Download the compiled version from [release page](https://github.com/zhyonc/sysproxy/releases)

### How to use
#### Inbound
- If you don't want to use system proxy, not need to set inbound
- Click Setting menu item to open inbound form
- Input and add inbound info that controls system proxy
- After modified inbound list, don't forget to click update button
- Click Inbound menu item to select inbound tag
- After the tag was selected, call win+R and enter inetcpl.cpl to see the LAN changes
![Inbound](/resources/Inbound.png)
#### Outbound
- Click Setting menu item to open outbound form
- Input and add outbound info that forward inbound or other proxy chain
- After modified outbound list, don't forget to click update button
- Click Outbound menu item to select outbound tag
- Click Log menu item to open log form
- If everything is ok, you can see the connection status in the log form
![Outbound](/resources/Outbound.png)
### Build
- Upgrade go version to above 1.9.2
- Download package tool from [rsrc](https://github.com/akavel/rsrc/releases)
- Package manifest and icon to syso file:
- ```rsrc.exe -manifest sysproxy.manifest -ico ./resources/icon.ico -o resources.syso```
- To get rid of the cmd window:
- ```go build -ldflags="-s -w -H windowsgui"```

### Thanks
[Govcl](https://github.com/ying32/govcl) is Cross-platform Golang GUI library binding [liblcl](https://github.com/ying32/liblcl)

### License
[MIT](LICENSE)
85 changes: 85 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package config

import (
"log"
"os"

"github.com/BurntSushi/toml"
)

const (
appName string = "sysproxy"
version string = "0.1.1"
)

var path string = "config.toml"

type Config struct {
OutboundList []Outbound
InboundList []Inbound
Menu *Menu
}

func NewConfig() *Config {
conf := &Config{}
_, err := toml.DecodeFile(path, conf)
if err != nil {
log.Printf("Error load config from %s\n", path)
conf = defualtConfig()
if !conf.Save() {
return nil
}
}
if conf.Menu.Version < version {
upgradeConfig(conf)
}
return conf
}

func defualtConfig() *Config {
conf := &Config{
OutboundList: make([]Outbound, 0),
InboundList: make([]Inbound, 0),
Menu: &Menu{
AppName: appName,
Version: version,
InboundCheckedIndex: 0,
OutboundCheckedIndex: 0,
AutoStart: false,
AutoProxy: false,
},
}
return conf
}

func upgradeConfig(oldConf *Config) *Config {
newConf := defualtConfig()
newConf.OutboundList = oldConf.OutboundList
newConf.InboundList = oldConf.InboundList
newConf.Menu.AutoStart = oldConf.Menu.AutoStart
newConf.Menu.AutoProxy = oldConf.Menu.AutoProxy
ok := newConf.Save()
if !ok {
log.Println("update config failed")
return oldConf
}
log.Println("upgrade config successful")
return newConf
}

func (c *Config) Save() bool {
file, err := os.Create(path)
if err != nil {
log.Printf("Error create config to %s\n", path)
return false
}
defer file.Close()
encoder := toml.NewEncoder(file)
err = encoder.Encode(c)
if err != nil {
log.Printf("Error encode config: %v\n", err)
return false
}
log.Println("Save config successful")
return true
}
8 changes: 8 additions & 0 deletions config/inbound.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package config

type Inbound struct {
Tag string
DstProto string
DstIP string
DstPort string
}
10 changes: 10 additions & 0 deletions config/menu.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package config

type Menu struct {
AppName string
Version string
OutboundCheckedIndex int
InboundCheckedIndex int
AutoProxy bool
AutoStart bool
}
11 changes: 11 additions & 0 deletions config/outbound.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package config

type Outbound struct {
Tag string
SrcProto string
SrcIP string
SrcPort string
DstProto string
DstIP string
DstPort string
}
38 changes: 38 additions & 0 deletions controller/controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package controller

import (
"sysproxy/config"
)

type MenuController interface {
GetMenu() *config.Menu
GetOutboundTags() []string
GetInboundTags() []string
SwitchOutbound(index int) error
SwitchInbound(index int) error
ToggleAutoStart() error
OpenAboutURL()
Exit() string
}

type LogController interface {
GetLogInfo() string
}

type RuleController interface {
GetUserRule() []string
SaveUserRule(rules string) error
}

type BoundController interface {
GetInProtoList() []string
GetOutProtoList() []string
GetBoundList() [][]string
GetBoundTags() []string
AddBound(bound []string)
UpdateBound(index int, bound []string)
DeleteBound(index int)
PageUp(index int)
PageDown(index int)
SaveConfig() bool
}
106 changes: 106 additions & 0 deletions controller/inbound_controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package controller

import (
"sysproxy/config"
"sysproxy/service"
)

type inboundController struct {
conf *config.Config
}

func NewInboundController(conf *config.Config) BoundController {
c := &inboundController{
conf: conf,
}
return c
}

// GetInProtoList implements BoundController.
func (c *inboundController) GetInProtoList() []string {
return service.InProtoList
}

// GetOutProtoList implements BoundController.
func (c *inboundController) GetOutProtoList() []string {
return nil
}

// GetBoundList implements BoundController.
func (c *inboundController) GetBoundList() [][]string {
bounds := make([][]string, 0)
for _, inbound := range c.conf.InboundList {
cols := []string{
inbound.Tag,
inbound.DstProto,
inbound.DstIP,
inbound.DstPort,
}
bounds = append(bounds, cols)
}
return bounds
}

// GetBoundTags implements BoundController.
func (c *inboundController) GetBoundTags() []string {
tags := make([]string, 0)
for _, inbound := range c.conf.InboundList {
tags = append(tags, inbound.Tag)
}
return tags
}

// AddBound implements BoundController.
func (c *inboundController) AddBound(bound []string) {
inbound := config.Inbound{
Tag: bound[0],
DstProto: bound[1],
DstIP: bound[2],
DstPort: bound[3],
}
c.conf.InboundList = append(c.conf.InboundList, inbound)
}

// UpdateBound implements BoundController.
func (c *inboundController) UpdateBound(index int, bound []string) {
c.conf.InboundList[index].Tag = bound[0]
c.conf.InboundList[index].DstProto = bound[1]
c.conf.InboundList[index].DstIP = bound[2]
c.conf.InboundList[index].DstPort = bound[3]
}

// DeleteBound implements BoundController.
func (c *inboundController) DeleteBound(index int) {
if index+1 == len(c.conf.InboundList) {
c.conf.InboundList = c.conf.InboundList[:index]
} else {
c.conf.InboundList = append(c.conf.InboundList[:index], c.conf.InboundList[index+1:]...)
}
}

// PageUp implements BoundController.
func (c *inboundController) PageUp(index int) {
if index-1 < 0 {
return
}
upper := c.conf.InboundList[index-1]
current := c.conf.InboundList[index]
c.conf.InboundList[index-1] = current
c.conf.InboundList[index] = upper
}

// PageDown implements BoundController.
func (c *inboundController) PageDown(index int) {
if index >= len(c.conf.InboundList)-1 {
return
}
lower := c.conf.InboundList[index+1]
current := c.conf.InboundList[index]
c.conf.InboundList[index+1] = current
c.conf.InboundList[index] = lower
}

// SaveConfig implements BoundController.
func (c *inboundController) SaveConfig() bool {
return c.conf.Save()
}
22 changes: 22 additions & 0 deletions controller/log_controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package controller

import (
"bytes"
"log"
)

type logController struct {
Buffer *bytes.Buffer
}

func NewLogController() LogController {
c := &logController{Buffer: new(bytes.Buffer)}
log.SetOutput(c.Buffer)
return c
}

func (c *logController) GetLogInfo() string {
msg := c.Buffer.String()
c.Buffer.Reset()
return msg
}
Loading

0 comments on commit 9036279

Please sign in to comment.