-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
53 changed files
with
7,881 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.