mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2026-01-04 01:56:35 +08:00
增加自动检查系统更新设置
This commit is contained in:
@@ -40,6 +40,11 @@ func (this *IndexAction) RunGet(params struct{}) {
|
||||
}
|
||||
}
|
||||
|
||||
// 版本更新
|
||||
this.Data["currentVersionCode"] = teaconst.Version
|
||||
this.Data["newVersionCode"] = teaconst.NewVersionCode
|
||||
this.Data["newVersionDownloadURL"] = teaconst.NewVersionDownloadURL
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ func (this *PolicyAction) RunGet(params struct {
|
||||
|
||||
// 检查是否有升级
|
||||
var templatePolicy = firewallconfigs.HTTPFirewallTemplate()
|
||||
var upgradeItems = []string{}
|
||||
var upgradeItems = []maps.Map{}
|
||||
if templatePolicy.Inbound != nil {
|
||||
for _, group := range templatePolicy.Inbound.Groups {
|
||||
if len(group.Code) == 0 {
|
||||
@@ -57,7 +57,10 @@ func (this *PolicyAction) RunGet(params struct {
|
||||
}
|
||||
var oldGroup = firewallPolicy.FindRuleGroupWithCode(group.Code)
|
||||
if oldGroup == nil {
|
||||
upgradeItems = append(upgradeItems, group.Name)
|
||||
upgradeItems = append(upgradeItems, maps.Map{
|
||||
"name": group.Name,
|
||||
"isOn": group.IsOn,
|
||||
})
|
||||
continue
|
||||
}
|
||||
for _, set := range group.Sets {
|
||||
@@ -66,7 +69,10 @@ func (this *PolicyAction) RunGet(params struct {
|
||||
}
|
||||
var oldSet = oldGroup.FindRuleSetWithCode(set.Code)
|
||||
if oldSet == nil {
|
||||
upgradeItems = append(upgradeItems, group.Name+" -- "+set.Name)
|
||||
upgradeItems = append(upgradeItems, maps.Map{
|
||||
"name": group.Name + " -- " + set.Name,
|
||||
"isOn": set.IsOn,
|
||||
})
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,11 +6,14 @@ import (
|
||||
"encoding/json"
|
||||
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
stringutil "github.com/iwind/TeaGo/utils/string"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -25,6 +28,22 @@ func (this *IndexAction) Init() {
|
||||
func (this *IndexAction) RunGet(params struct{}) {
|
||||
this.Data["version"] = teaconst.Version
|
||||
|
||||
valueResp, err := this.RPC().SysSettingRPC().ReadSysSetting(this.AdminContext(), &pb.ReadSysSettingRequest{Code: systemconfigs.SettingCodeCheckUpdates})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var valueJSON = valueResp.ValueJSON
|
||||
var config = &systemconfigs.CheckUpdatesConfig{AutoCheck: false}
|
||||
if len(valueJSON) > 0 {
|
||||
err = json.Unmarshal(valueJSON, config)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
this.Data["config"] = config
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
@@ -37,8 +56,8 @@ func (this *IndexAction) RunPost(params struct {
|
||||
}
|
||||
|
||||
var apiURL = teaconst.UpdatesURL
|
||||
apiURL = strings.ReplaceAll(apiURL, "${os}", "linux") //runtime.GOOS)
|
||||
apiURL = strings.ReplaceAll(apiURL, "${arch}", "amd64") // runtime.GOARCH)
|
||||
apiURL = strings.ReplaceAll(apiURL, "${os}", runtime.GOOS)
|
||||
apiURL = strings.ReplaceAll(apiURL, "${arch}", runtime.GOARCH)
|
||||
resp, err := http.Get(apiURL)
|
||||
if err != nil {
|
||||
this.Data["result"] = maps.Map{
|
||||
@@ -109,7 +128,6 @@ func (this *IndexAction) RunPost(params struct {
|
||||
"isOk": false,
|
||||
"message": "找不到更新信息",
|
||||
}
|
||||
this.Success()
|
||||
|
||||
this.Success()
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ func init() {
|
||||
Helper(settingutils.NewHelper("updates")).
|
||||
Prefix("/settings/updates").
|
||||
GetPost("", new(IndexAction)).
|
||||
Post("/update", new(UpdateAction)).
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
|
||||
52
internal/web/actions/default/settings/updates/update.go
Normal file
52
internal/web/actions/default/settings/updates/update.go
Normal file
@@ -0,0 +1,52 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package updates
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
|
||||
)
|
||||
|
||||
type UpdateAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UpdateAction) RunPost(params struct {
|
||||
AutoCheck bool
|
||||
}) {
|
||||
valueResp, err := this.RPC().SysSettingRPC().ReadSysSetting(this.AdminContext(), &pb.ReadSysSettingRequest{Code: systemconfigs.SettingCodeCheckUpdates})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var valueJSON = valueResp.ValueJSON
|
||||
var config = &systemconfigs.CheckUpdatesConfig{AutoCheck: false}
|
||||
if len(valueJSON) > 0 {
|
||||
err = json.Unmarshal(valueJSON, config)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
config.AutoCheck = params.AutoCheck
|
||||
|
||||
configJSON, err := json.Marshal(config)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
_, err = this.RPC().SysSettingRPC().UpdateSysSetting(this.AdminContext(), &pb.UpdateSysSettingRequest{
|
||||
Code: systemconfigs.SettingCodeCheckUpdates,
|
||||
ValueJSON: configJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
Reference in New Issue
Block a user