Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ RUN wget -O /tmp/host-tools.tar.gz https://sophon-file.sophon.cn/sophon-prod-s3/
FROM base_apt AS golang

USER root
RUN bash -c 'wget -O /tmp/go.tar.gz https://go.dev/dl/go1.25.0.linux-$([ `uname -m` == "x86_64" ] && echo "amd64" || uname -m).tar.gz' \
RUN bash -c 'wget -O /tmp/go.tar.gz https://go.dev/dl/go1.23.4.linux-$([ `uname -m` == "x86_64" ] && echo "amd64" || echo "arm64").tar.gz' \
&& tar -C /usr/local -zxvf /tmp/go.tar.gz \
&& export PATH=$PATH:/usr/local/go/bin \
&& echo "Installed golang" && go version
Expand Down
24 changes: 24 additions & 0 deletions server/proto/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,27 @@ type ConnectWifiReq struct {
Ssid string `validate:"required"`
Password string `valid:"required"`
}

// Ethernet configuration
type EthernetConfig struct {
DHCP bool `json:"dhcp"`
IP string `json:"ip"`
Netmask string `json:"netmask"` // 点分十进制格式:255.255.255.0
Gateway string `json:"gateway"`
DNS1 string `json:"dns1"`
DNS2 string `json:"dns2"`
}

type GetEthernetConfigRsp struct {
Config EthernetConfig `json:"config"`
Current EthernetConfig `json:"current"` // 当前实际生效的配置
}

type SetEthernetConfigReq struct {
DHCP bool `form:"dhcp"`
IP string `form:"ip"`
Netmask string `form:"netmask"`
Gateway string `form:"gateway"`
DNS1 string `form:"dns1"`
DNS2 string `form:"dns2"`
}
4 changes: 4 additions & 0 deletions server/proto/tailscale.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ type GetTailscaleStatusRsp struct {
type LoginTailscaleRsp struct {
Url string `json:"url"`
}

type SetAutoUpdateReq struct {
Enable bool `form:"enable"`
}
6 changes: 4 additions & 2 deletions server/router/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ func extensionsRouter(r *gin.Engine) {
api.POST("/tailscale/login", ts.Login) // tailscale login
api.POST("/tailscale/logout", ts.Logout) // tailscale logout
api.POST("/tailscale/start", ts.Start) // tailscale start
api.POST("/tailscale/stop", ts.Stop) // tailscale stop
api.POST("/tailscale/restart", ts.Restart) // tailscale restart
api.POST("/tailscale/stop", ts.Stop) // tailscale stop
api.POST("/tailscale/restart", ts.Restart) // tailscale restart
api.GET("/tailscale/auto-update", ts.GetAutoUpdate) // get auto-update status
api.POST("/tailscale/auto-update", ts.SetAutoUpdate) // set auto-update
}
3 changes: 3 additions & 0 deletions server/router/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ func networkRouter(r *gin.Engine) {
api.GET("/network/wifi", service.GetWifi) // get Wi-Fi information
api.POST("/network/wifi/connect", service.ConnectWifi) // connect Wi-Fi
api.POST("/network/wifi/disconnect", service.DisconnectWifi) // disconnect Wi-Fi

api.GET("/network/ethernet", service.GetEthernetConfig) // get ethernet configuration
api.POST("/network/ethernet", service.SetEthernetConfig) // set ethernet configuration
}
33 changes: 33 additions & 0 deletions server/service/extensions/tailscale/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,36 @@ func (c *Cli) Logout() error {
command := "tailscale logout"
return exec.Command("sh", "-c", command).Run()
}

func (c *Cli) SetAutoUpdate(enable bool) error {
arg := "false"
if enable {
arg = "true"
}
command := fmt.Sprintf("tailscale set --auto-update=%s", arg)
return exec.Command("sh", "-c", command).Run()
}

func (c *Cli) GetAutoUpdate() (bool, error) {
command := "tailscale debug prefs"
cmd := exec.Command("sh", "-c", command)

output, err := cmd.CombinedOutput()
if err != nil {
return false, err
}

// 解析 JSON 输出,查找 AutoUpdate.Apply 字段
var prefs struct {
AutoUpdate struct {
Check bool `json:"Check"`
Apply bool `json:"Apply"`
} `json:"AutoUpdate"`
}

if err := json.Unmarshal(output, &prefs); err != nil {
return false, err
}

return prefs.AutoUpdate.Apply, nil
}
44 changes: 44 additions & 0 deletions server/service/extensions/tailscale/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,47 @@ func (s *Service) GetStatus(c *gin.Context) {
rsp.OkRspWithData(c, &data)
log.Debugf("get tailscale status successfully")
}

func (s *Service) GetAutoUpdate(c *gin.Context) {
var rsp proto.Response

if !isInstalled() {
rsp.ErrRsp(c, -1, "tailscale not installed")
return
}

enabled, err := NewCli().GetAutoUpdate()
if err != nil {
log.Errorf("failed to get auto-update status: %s", err)
rsp.ErrRsp(c, -2, "failed to get status")
return
}

rsp.OkRspWithData(c, map[string]bool{"enabled": enabled})
log.Debugf("get tailscale auto-update status: %v", enabled)
}

func (s *Service) SetAutoUpdate(c *gin.Context) {
var rsp proto.Response

if !isInstalled() {
rsp.ErrRsp(c, -1, "tailscale not installed")
return
}

var req proto.SetAutoUpdateReq
if err := proto.ParseFormRequest(c, &req); err != nil {
rsp.ErrRsp(c, -2, "invalid parameters")
return
}

err := NewCli().SetAutoUpdate(req.Enable)
if err != nil {
log.Errorf("failed to set auto-update: %s", err)
rsp.ErrRsp(c, -3, "failed to set auto-update")
return
}

rsp.OkRsp(c)
log.Debugf("set tailscale auto-update: %v", req.Enable)
}
Loading