Skip to content

Commit 45a1922

Browse files
feat(system-security): Optimize Route Matching for Secure Entry
1 parent d103813 commit 45a1922

File tree

8 files changed

+60
-172
lines changed

8 files changed

+60
-172
lines changed

agent/app/service/app.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,7 @@ func (a AppService) PageApp(req request.AppSearch) (interface{}, error) {
7070
if req.Resource != "" && req.Resource != "all" {
7171
opts = append(opts, appRepo.WithResource(req.Resource))
7272
}
73-
if req.Type == "php" {
74-
info, _ := NewISettingService().GetSettingInfo()
75-
opts = append(opts, appRepo.WithPanelVersion(info.SystemVersion))
76-
}
73+
7774
if req.ShowCurrentArch {
7875
info, err := NewIDashboardService().LoadOsInfo()
7976
if err != nil {
@@ -101,12 +98,22 @@ func (a AppService) PageApp(req request.AppSearch) (interface{}, error) {
10198
opts = append(opts, commonRepo.WithByIDs(appIds))
10299
}
103100
var res response.AppRes
101+
104102
total, apps, err := appRepo.Page(req.Page, req.PageSize, opts...)
105103
if err != nil {
106104
return nil, err
107105
}
108106
var appDTOs []*response.AppDto
107+
info := &dto.SettingInfo{}
108+
if req.Type == "php" {
109+
info, _ = NewISettingService().GetSettingInfo()
110+
}
109111
for _, ap := range apps {
112+
if req.Type == "php" {
113+
if ap.RequiredPanelVersion == 0 || !common.CompareAppVersion(fmt.Sprintf("%f", ap.RequiredPanelVersion), info.SystemVersion) {
114+
continue
115+
}
116+
}
110117
appDTO := &response.AppDto{
111118
ID: ap.ID,
112119
Name: ap.Name,
@@ -789,7 +796,7 @@ func (a AppService) GetAppUpdate() (*response.AppUpdateRes, error) {
789796
return res, err
790797
}
791798
if list.Extra.Version != "" && setting.SystemVersion != list.Extra.Version && !common.CompareVersion(setting.SystemVersion, list.Extra.Version) {
792-
global.LOG.Errorf("The current version is too low to synchronize with the App Store. The minimum required version is %s", list.Extra.Version)
799+
global.LOG.Errorf("The current version %s is too low to synchronize with the App Store. The minimum required version is %s", setting.SystemVersion, list.Extra.Version)
793800
return nil, buserr.New("ErrVersionTooLow")
794801
}
795802
res.AppList = list

agent/app/service/runtime.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ func (r *RuntimeService) Create(create request.RuntimeCreate) (*model.Runtime, e
8686
}
8787
fileOp := files.NewFileOp()
8888

89+
runtimeDir := path.Join(constant.RuntimeDir, create.Type)
90+
if !fileOp.Stat(runtimeDir) {
91+
if err := fileOp.CreateDir(runtimeDir, constant.DirPerm); err != nil {
92+
return nil, err
93+
}
94+
}
95+
8996
switch create.Type {
9097
case constant.RuntimePHP:
9198
if create.Resource == constant.ResourceLocal {

agent/utils/common/common.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,33 @@ func CompareVersion(version1, version2 string) bool {
4747
return false
4848
}
4949

50+
func CompareAppVersion(version1, version2 string) bool {
51+
v1s := extractNumbers(version1)
52+
v2s := extractNumbers(version2)
53+
54+
maxLen := max(len(v1s), len(v2s))
55+
v1s = append(v1s, make([]string, maxLen-len(v1s))...)
56+
v2s = append(v2s, make([]string, maxLen-len(v2s))...)
57+
58+
for i := 0; i < maxLen; i++ {
59+
v1, err1 := strconv.Atoi(v1s[i])
60+
v2, err2 := strconv.Atoi(v2s[i])
61+
if err1 != nil {
62+
v1 = 0
63+
}
64+
if err2 != nil {
65+
v2 = 0
66+
}
67+
if v1 > v2 {
68+
return true
69+
}
70+
if v1 < v2 {
71+
return false
72+
}
73+
}
74+
return true
75+
}
76+
5077
func ComparePanelVersion(version1, version2 string) bool {
5178
if version1 == version2 {
5279
return false

core/constant/common.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ var WebUrlMap = map[string]struct{}{
132132
"/xpack/alert/log": {},
133133
"/xpack/alert/setting": {},
134134
"/xpack/setting": {},
135+
"xpack/node": {},
135136
}
136137

137138
var DynamicRoutes = []string{

core/init/viper/viper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func Init() {
2020
baseDir := "/opt"
2121
port := "9999"
2222
mode := ""
23-
version := "v1.0.0"
23+
version := "v2.0.0"
2424
username, password, entrance := "", "", ""
2525
v := viper.NewWithOptions()
2626
v.SetConfigType("yaml")

frontend/src/routers/router.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export const routes: RouteRecordRaw[] = [
7575
{
7676
path: '/:code?',
7777
name: 'entrance',
78-
component: () => import('@/views/login/entrance/index.vue'),
78+
component: () => import('@/views/login/index.vue'),
7979
props: true,
8080
},
8181
...routerArray,

frontend/src/views/login/entrance/index.vue

Lines changed: 0 additions & 165 deletions
This file was deleted.

frontend/src/views/login/index.vue

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,20 @@ import { getXpackSettingForTheme } from '@/utils/xpack';
2929
const gStore = GlobalStore();
3030
const loading = ref();
3131
32+
const mySafetyCode = defineProps({
33+
code: {
34+
type: String,
35+
default: '',
36+
},
37+
});
38+
3239
const screenWidth = ref(null);
3340
3441
const getStatus = async () => {
42+
let code = mySafetyCode.code;
43+
if (code != '') {
44+
gStore.entrance = code;
45+
}
3546
loading.value = true;
3647
await checkIsSafety(gStore.entrance)
3748
.then((res) => {

0 commit comments

Comments
 (0)