Skip to content

Commit

Permalink
代码同步至1.4.10
Browse files Browse the repository at this point in the history
发布1.5.1
  • Loading branch information
gdy666 committed Oct 26, 2022
1 parent 5e820e6 commit 24b820e
Show file tree
Hide file tree
Showing 67 changed files with 5,820 additions and 3,550 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ lucky
*.out
*.log
*.upx
*.pem
*.crt
*.key
lucky.conf

# Dependency directories (remove the comment below to include it)
Expand Down
33 changes: 17 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
- [后台界面](#后台界面)

- [开发编译](#开发编译)
- [更新日志](#更新日志)
- [使用注意与常见问题](#使用注意与常见问题)

<!-- /TOC -->


Expand Down Expand Up @@ -42,14 +40,22 @@
- 支持的DNS服务商和DDNS-GO一样,有Alidns(阿里云),百度云,Cloudflare,Dnspod(腾讯云),华为云.自定义(Callback)内置有每步,No-IP,Dynv6,Dynu模版,一键填充,仅需修改相应用户密码或者token即可快速接入.
- 3.http/https反向代理
- 特点
- SSL证书管理简单
- 设置简单
- 支持HttpBasic认证
- 支持IP黑白名单
- 支持UserAgent黑白名单
- 日志记录最近访问情况
- 一键开关子规则
- 前端域名与后端地址 支持一对一,一对多(均衡负载),多对多(下一级反向代理)
- 4.网络唤醒
- 特点
- 支持远程控制唤醒和关机操作
- 远程唤醒需要 待唤醒端所在局域网内有开启中继唤醒指令的lucky唤醒客户端
- 远程关机需要 待关机端运行有luck唤醒客户端
- 支持接入第三方物联网平台(点灯科技 巴法云),可通过各大平台的语音助手控制设备唤醒和关机.
- 点灯科技支持 小爱同学 小度 天猫精灵
- 巴法云支持小爱同学 小度 天猫精灵 google语音 AmazonAlexa
- 具备但一般用不上的功能:支持一个设备设置多组网卡mac和多个广播地址,实现批量控制设备.

- 将要实现的功能
- 有建议可联系作者.
Expand Down Expand Up @@ -135,29 +141,26 @@
#### Http反向代理
![](./previews/reverseproxy.png)

#### 网络唤醒

![](./previews/wol001.png)

![](./previews/wol002.png)




# 开发编译
#开发编译


```bash
go build -v -tags "adminweb nomsgpack" -ldflags="-s -w"
```


# 更新日志

2022-10-08 版本1.4.9
1.反向代理新增https支持。
2.加入SSL证书管理模块
3.后台接口支持HTTPS
4.端口转发模块重构优化,移除命令行配置功能,注意使用此版本后原来的端口转发配置会全部消失。
5.修复已知BUG.
6.源码不再和二进制版本同时发布.
2022-10-14 v1.4.10
1.修复特定情况下反向代理规则添加后无法编辑删除的bug.





Expand All @@ -171,5 +174,3 @@

- 转发规则启用异常,端口转发没有生效时请登录后台查看日志.

- 开启外网访问可以直接修改配置文件中的"AllowInternetaccess": false, 将false改为true

144 changes: 93 additions & 51 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,30 @@ func FlushLoginRandomKey() {
loginRandomkey = stringsp.GetRandomString(16)
}

type ConfigureRelayRule struct {
Name string `json:"Name"`
Configurestr string `json:"Configurestr"`
Enable bool `json:"Enable"`
Options socketproxy.RelayRuleOptions `json:"Options"`
}

type BaseConfigure struct {
AdminWebListenPort int `json:"AdminWebListenPort"` //管理后台端口
ProxyCountLimit int64 `json:"ProxyCountLimit"` //全局代理数量限制
AdminAccount string `json:"AdminAccount"` //登录账号
AdminPassword string `json:"AdminPassword"` //登录密码
AllowInternetaccess bool `json:"AllowInternetaccess"` //允许外网访问
GlobalMaxConnections int64 `json:"GlobalMaxConnections"` //全局最大连接数
LogMaxSize int `json:"LogMaxSize"` //日志记录最大条数
AdminWebListenPort int `json:"AdminWebListenPort"` //管理后台端口
AdminWebListenTLS bool `json:"AdminWebListenTLS"` //启用TLS监听端口
AdminWebListenHttpsPort int `json:"AdminWebListenHttpsPort"` //管理后台Https端口

//ProxyCountLimit int64 `json:"ProxyCountLimit"` //全局代理数量限制
AdminAccount string `json:"AdminAccount"` //登录账号
AdminPassword string `json:"AdminPassword"` //登录密码
AllowInternetaccess bool `json:"AllowInternetaccess"` //允许外网访问
//GlobalMaxConnections int64 `json:"GlobalMaxConnections"` //全局最大连接数
LogMaxSize int `json:"LogMaxSize"` //日志记录最大条数
}

type ProgramConfigure struct {
BaseConfigure BaseConfigure `json:"BaseConfigure"`
RelayRuleList []ConfigureRelayRule `json:"RelayRuleList"`
WhiteListConfigure WhiteListConfigure `json:"WhiteListConfigure"`
BlackListConfigure BlackListConfigure `json:"BlackListConfigure"`
DDNSConfigure DDNSConfigure `json:"DDNSConfigure"` //DDNS 参数设置
DDNSTaskList []DDNSTask `json:"DDNSTaskList"` //DDNS任务列表
ReverseProxyRuleList []ReverseProxyRule `json:"ReverseProxyRuleList"` //反向代理规则列表
BaseConfigure BaseConfigure `json:"BaseConfigure"`
WhiteListConfigure WhiteListConfigure `json:"WhiteListConfigure"`
BlackListConfigure BlackListConfigure `json:"BlackListConfigure"`
DDNSConfigure DDNSConfigure `json:"DDNSConfigure"` //DDNS 参数设置
DDNSTaskList []DDNSTask `json:"DDNSTaskList"` //DDNS任务列表
ReverseProxyRuleList []ReverseProxyRule `json:"ReverseProxyRuleList"` //反向代理规则列表
SSLCertficateList []SSLCertficate `json:"SSLCertficateList"` //SSL证书列表
PortForwardsRuleList []PortForwardsRule `json:"PortForwardsRuleList"` //端口转发规则列表
PortForwardsConfigure PortForwardsConfigure `json:"PortForwardsConfigure"` //端口转发设置
WOLDeviceList []WOLDevice `json:"WOLDeviceList"` //网络唤醒设备列表
}

var programConfigureMutex sync.RWMutex
Expand All @@ -90,12 +89,6 @@ func GetAuthAccount() map[string]string {
return accountInfo
}

func SetConfigRuleList(ruleList *[]ConfigureRelayRule) {
programConfigureMutex.Lock()
defer programConfigureMutex.Unlock()
programConfigure.RelayRuleList = *ruleList
}

func GetRunMode() string {
return runMode
}
Expand Down Expand Up @@ -146,14 +139,51 @@ func GetDDNSConfigure() DDNSConfigure {
return conf
}

func GetPortForwardsConfigure() PortForwardsConfigure {
programConfigureMutex.RLock()
defer programConfigureMutex.RUnlock()
conf := programConfigure.PortForwardsConfigure
return conf
}

func SetPortForwardsConfigure(conf *PortForwardsConfigure) error {
programConfigureMutex.Lock()
defer programConfigureMutex.Unlock()

if conf.PortForwardsLimit < 0 {
conf.PortForwardsLimit = 0
} else if conf.PortForwardsLimit > 1024 {
conf.PortForwardsLimit = 1024
}

if conf.TCPPortforwardMaxConnections < 0 {
conf.TCPPortforwardMaxConnections = 0
} else if conf.TCPPortforwardMaxConnections > 4096 {
conf.TCPPortforwardMaxConnections = 4096
}

if conf.UDPReadTargetDataMaxgoroutineCount < 0 {
conf.UDPReadTargetDataMaxgoroutineCount = 0
} else if conf.UDPReadTargetDataMaxgoroutineCount > 4096 {
conf.UDPReadTargetDataMaxgoroutineCount = 4096
}

programConfigure.PortForwardsConfigure = *conf

socketproxy.SetGlobalMaxPortForwardsCountLimit(conf.PortForwardsLimit)
socketproxy.SetGlobalTCPPortforwardMaxConnections(conf.TCPPortforwardMaxConnections)
socketproxy.SetGlobalUDPReadTargetDataMaxgoroutineCountLimit(conf.UDPReadTargetDataMaxgoroutineCount)
return Save()
}

// 保存基础配置
func SetBaseConfigure(conf *BaseConfigure) error {
programConfigureMutex.Lock()
defer programConfigureMutex.Unlock()
programConfigure.BaseConfigure = *conf

socketproxy.SetGlobalMaxConnections(conf.GlobalMaxConnections)
socketproxy.SetGlobalMaxProxyCount(conf.ProxyCountLimit)
//socketproxy.SetGlobalMaxConnections(conf.GlobalMaxConnections)
//socketproxy.SetGlobalMaxPortForwardsCount(conf.ProxyCountLimit)

if conf.LogMaxSize < minLogSize {
conf.LogMaxSize = minLogSize
Expand Down Expand Up @@ -200,18 +230,29 @@ func Read(filePath string) (err error) {
return err
}

if pc.BaseConfigure.GlobalMaxConnections <= 0 {
pc.BaseConfigure.GlobalMaxConnections = socketproxy.DEFAULT_GLOBAL_MAX_CONNECTIONS
if pc.PortForwardsConfigure.PortForwardsLimit <= 0 {
pc.PortForwardsConfigure.PortForwardsLimit = socketproxy.DEFAULT_MAX_PORTFORWARDS_LIMIT
}
if pc.PortForwardsConfigure.TCPPortforwardMaxConnections <= 0 {
pc.PortForwardsConfigure.TCPPortforwardMaxConnections = socketproxy.DEFAULT_GLOBAL_MAX_CONNECTIONS
}

if pc.BaseConfigure.ProxyCountLimit <= 0 {
pc.BaseConfigure.ProxyCountLimit = socketproxy.DEFAULT_MAX_PROXY_COUNT
if pc.PortForwardsConfigure.UDPReadTargetDataMaxgoroutineCount <= 0 {
pc.PortForwardsConfigure.UDPReadTargetDataMaxgoroutineCount = socketproxy.DEFAULT_GLOBAL_UDPReadTargetDataMaxgoroutineCount
}

socketproxy.SetGlobalMaxPortForwardsCountLimit(pc.PortForwardsConfigure.PortForwardsLimit)
socketproxy.SetGlobalTCPPortforwardMaxConnections(pc.PortForwardsConfigure.TCPPortforwardMaxConnections)
socketproxy.SetGlobalUDPReadTargetDataMaxgoroutineCountLimit(pc.PortForwardsConfigure.UDPReadTargetDataMaxgoroutineCount)

if pc.BaseConfigure.AdminWebListenPort <= 0 {
pc.BaseConfigure.AdminWebListenPort = 16601
}

if pc.BaseConfigure.AdminWebListenHttpsPort <= 0 {
pc.BaseConfigure.AdminWebListenHttpsPort = 16626
}

if pc.BaseConfigure.LogMaxSize < minLogSize {
pc.BaseConfigure.LogMaxSize = minLogSize
} else if pc.BaseConfigure.LogMaxSize > maxLogSize {
Expand All @@ -223,11 +264,8 @@ func Read(filePath string) (err error) {
return nil
}

func LoadDefault(proxyCountLimit int64,
adminWebListenPort int,
globalMaxConnections int64) {

programConfigure = loadDefaultConfigure(proxyCountLimit, adminWebListenPort, globalMaxConnections)
func LoadDefault(adminWebListenPort int) {
programConfigure = loadDefaultConfigure(adminWebListenPort)
}

func Save() (err error) {
Expand Down Expand Up @@ -281,32 +319,36 @@ func readProgramConfigure(filePath string) (conf *ProgramConfigure, err error) {
}

func loadDefaultConfigure(
proxyCountLimit int64,
adminWebListenPort int,
globalMaxConnections int64) *ProgramConfigure {
adminWebListenPort int) *ProgramConfigure {

baseConfigure := BaseConfigure{AdminWebListenPort: adminWebListenPort,
GlobalMaxConnections: globalMaxConnections,
AdminAccount: defaultAdminAccount,
AdminPassword: defaultAdminPassword,
ProxyCountLimit: proxyCountLimit,
AllowInternetaccess: false,
LogMaxSize: defaultLogSize}
AdminAccount: defaultAdminAccount,
AdminPassword: defaultAdminPassword,
AllowInternetaccess: false,
LogMaxSize: defaultLogSize}

whiteListConfigure := WhiteListConfigure{BaseConfigure: WhiteListBaseConfigure{ActivelifeDuration: 36, BasicAccount: defaultAdminAccount, BasicPassword: defaultAdminPassword}}

var pc ProgramConfigure
pc.BaseConfigure = baseConfigure
pc.WhiteListConfigure = whiteListConfigure

if pc.BaseConfigure.GlobalMaxConnections <= 0 {
pc.BaseConfigure.GlobalMaxConnections = socketproxy.DEFAULT_GLOBAL_MAX_CONNECTIONS
if pc.PortForwardsConfigure.PortForwardsLimit <= 0 {
pc.PortForwardsConfigure.PortForwardsLimit = socketproxy.DEFAULT_MAX_PORTFORWARDS_LIMIT
}
socketproxy.SetGlobalMaxPortForwardsCountLimit(pc.PortForwardsConfigure.PortForwardsLimit)

if pc.PortForwardsConfigure.TCPPortforwardMaxConnections <= 0 {
pc.PortForwardsConfigure.TCPPortforwardMaxConnections = socketproxy.TCPUDP_DEFAULT_SINGLE_PROXY_MAX_CONNECTIONS
}
socketproxy.SetGlobalTCPPortforwardMaxConnections(pc.PortForwardsConfigure.TCPPortforwardMaxConnections)

if pc.BaseConfigure.ProxyCountLimit <= 0 {
pc.BaseConfigure.ProxyCountLimit = socketproxy.DEFAULT_MAX_PROXY_COUNT
if pc.PortForwardsConfigure.UDPReadTargetDataMaxgoroutineCount <= 0 {
pc.PortForwardsConfigure.UDPReadTargetDataMaxgoroutineCount = socketproxy.DEFAULT_GLOBAL_UDPReadTargetDataMaxgoroutineCount
}

socketproxy.SetGlobalUDPReadTargetDataMaxgoroutineCountLimit(pc.PortForwardsConfigure.UDPReadTargetDataMaxgoroutineCount)

if pc.BaseConfigure.AdminWebListenPort <= 0 {
pc.BaseConfigure.AdminWebListenPort = defaultAdminListenPort
}
Expand Down
14 changes: 12 additions & 2 deletions config/ddns.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,23 @@ type DNSConfig struct {
ForceInterval int `json:"ForceInterval"` //(秒)即使IP没有变化,到一定时间后依然强制更新或先DNS解析比较IP再更新
ResolverDoaminCheck bool `json:"ResolverDoaminCheck"` //调用callback同步前先解析一次域名,如果IP相同就不同步
DNSServerList []string `json:"DNSServerList"` //DNS服务器列表
CallAPINetwork string `json:"CallAPINetwork"` //空代理tcp, tcp4,tcp6
Callback DNSCallback `json:"Callback"`
HttpClientProxyType string `json:"HttpClientProxyType"` //http client代理服务器设置
HttpClientProxyAddr string `json:"HttpClientProxyAddr"` //代理服务器IP
HttpClientProxyUser string `json:"HttpClientProxyUser"` //代理用户
HttpClientProxyPassword string `json:"HttpClientProxyPassword"` //代理密码
}

func (d *DNSConfig) GetCallAPINetwork() string {
switch d.CallAPINetwork {
case "tcp4", "tcp6":
return d.CallAPINetwork
default:
return "tcp"
}
}

type DNSCallback struct {
URL string `json:"URL"` //请求地址
Method string `json:"Method"` //请求方法
Expand Down Expand Up @@ -179,8 +189,8 @@ func GetDDNSTaskConfigureList() []*DDNSTask {
}

func GetDDNSTaskByKey(taskKey string) *DDNSTask {
programConfigureMutex.Lock()
defer programConfigureMutex.Unlock()
programConfigureMutex.RLock()
defer programConfigureMutex.RUnlock()
taskIndex := -1

for i := range programConfigure.DDNSTaskList {
Expand Down
Loading

0 comments on commit 24b820e

Please sign in to comment.