-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: change config path and add extra check for tun mode
- Loading branch information
Showing
7 changed files
with
139 additions
and
105 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package configs | ||
|
||
type ( | ||
Config struct { | ||
ServerAddress string | ||
ServerPort int | ||
Username string | ||
Password string | ||
DisableServerConfig bool | ||
DisableZJUConfig bool | ||
DisableZJUDNS bool | ||
DisableMultiLine bool | ||
ProxyAll bool | ||
SocksBind string | ||
SocksUser string | ||
SocksPasswd string | ||
HTTPBind string | ||
ShadowsocksURL string | ||
TUNMode bool | ||
AddRoute bool | ||
DNSTTL uint64 | ||
DisableKeepAlive bool | ||
ZJUDNSServer string | ||
SecondaryDNSServer string | ||
DNSServerBind string | ||
DNSHijack bool | ||
DebugDump bool | ||
PortForwardingList []SinglePortForwarding | ||
CustomDNSList []SingleCustomDNS | ||
CustomProxyDomain []string | ||
TwfID string | ||
} | ||
|
||
SinglePortForwarding struct { | ||
NetworkType string | ||
BindAddress string | ||
RemoteAddress string | ||
} | ||
|
||
SingleCustomDNS struct { | ||
HostName string `toml:"host_name"` | ||
IP string `toml:"ip"` | ||
} | ||
) | ||
|
||
type ( | ||
ConfigTOML struct { | ||
ServerAddress *string `toml:"server_address"` | ||
ServerPort *int `toml:"server_port"` | ||
Username *string `toml:"username"` | ||
Password *string `toml:"password"` | ||
DisableServerConfig *bool `toml:"disable_server_config"` | ||
DisableZJUConfig *bool `toml:"disable_zju_config"` | ||
DisableZJUDNS *bool `toml:"disable_zju_dns"` | ||
DisableMultiLine *bool `toml:"disable_multi_line"` | ||
ProxyAll *bool `toml:"proxy_all"` | ||
SocksBind *string `toml:"socks_bind"` | ||
SocksUser *string `toml:"socks_user"` | ||
SocksPasswd *string `toml:"socks_passwd"` | ||
HTTPBind *string `toml:"http_bind"` | ||
ShadowsocksURL *string `toml:"shadowsocks_url"` | ||
TUNMode *bool `toml:"tun_mode"` | ||
AddRoute *bool `toml:"add_route"` | ||
DNSTTL *uint64 `toml:"dns_ttl"` | ||
DisableKeepAlive *bool `toml:"disable_keep_alive"` | ||
ZJUDNSServer *string `toml:"zju_dns_server"` | ||
SecondaryDNSServer *string `toml:"secondary_dns_server"` | ||
DNSServerBind *string `toml:"dns_server_bind"` | ||
DNSHijack *bool `toml:"dns_hijack"` | ||
DebugDump *bool `toml:"debug_dump"` | ||
PortForwarding []SinglePortForwardingTOML `toml:"port_forwarding"` | ||
CustomDNS []SingleCustomDNSTOML `toml:"custom_dns"` | ||
CustomProxyDomain []string `toml:"custom_proxy_domain"` | ||
} | ||
|
||
SinglePortForwardingTOML struct { | ||
NetworkType *string `toml:"network_type"` | ||
BindAddress *string `toml:"bind_address"` | ||
RemoteAddress *string `toml:"remote_address"` | ||
} | ||
|
||
SingleCustomDNSTOML struct { | ||
HostName *string `toml:"host_name"` | ||
IP *string `toml:"ip"` | ||
} | ||
) |
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
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,5 +1,21 @@ | ||
package hook_func | ||
|
||
func init() { | ||
import ( | ||
"context" | ||
"github.com/mythologyli/zju-connect/configs" | ||
"github.com/mythologyli/zju-connect/log" | ||
"os/user" | ||
) | ||
|
||
func init() { | ||
RegisterInitialFunc("check tun mode cap", func(ctx context.Context, config configs.Config) error { | ||
// discard error | ||
if config.TUNMode { | ||
current, _ := user.Current() | ||
if current.Uid != "0" { | ||
log.Println("检测到TUN模式,但是当前用户不是root,可能会导致无法使用,如果遇到问题请使用sudo运行") | ||
} | ||
} | ||
return nil | ||
}) | ||
} |
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