Skip to content

Commit

Permalink
feat(system-security): Optimize Route Matching for Secure Entry (#7537)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengkunwang223 authored Dec 23, 2024
1 parent cd266d2 commit da73f26
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 172 deletions.
17 changes: 12 additions & 5 deletions agent/app/service/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,7 @@ func (a AppService) PageApp(req request.AppSearch) (interface{}, error) {
if req.Resource != "" && req.Resource != "all" {
opts = append(opts, appRepo.WithResource(req.Resource))
}
if req.Type == "php" {
info, _ := NewISettingService().GetSettingInfo()
opts = append(opts, appRepo.WithPanelVersion(info.SystemVersion))
}

if req.ShowCurrentArch {
info, err := NewIDashboardService().LoadOsInfo()
if err != nil {
Expand Down Expand Up @@ -101,12 +98,22 @@ func (a AppService) PageApp(req request.AppSearch) (interface{}, error) {
opts = append(opts, commonRepo.WithByIDs(appIds))
}
var res response.AppRes

total, apps, err := appRepo.Page(req.Page, req.PageSize, opts...)
if err != nil {
return nil, err
}
var appDTOs []*response.AppDto
info := &dto.SettingInfo{}
if req.Type == "php" {
info, _ = NewISettingService().GetSettingInfo()
}
for _, ap := range apps {
if req.Type == "php" {
if ap.RequiredPanelVersion == 0 || !common.CompareAppVersion(fmt.Sprintf("%f", ap.RequiredPanelVersion), info.SystemVersion) {
continue
}
}
appDTO := &response.AppDto{
ID: ap.ID,
Name: ap.Name,
Expand Down Expand Up @@ -789,7 +796,7 @@ func (a AppService) GetAppUpdate() (*response.AppUpdateRes, error) {
return res, err
}
if list.Extra.Version != "" && setting.SystemVersion != list.Extra.Version && !common.CompareVersion(setting.SystemVersion, list.Extra.Version) {
global.LOG.Errorf("The current version is too low to synchronize with the App Store. The minimum required version is %s", list.Extra.Version)
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)
return nil, buserr.New("ErrVersionTooLow")
}
res.AppList = list
Expand Down
7 changes: 7 additions & 0 deletions agent/app/service/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ func (r *RuntimeService) Create(create request.RuntimeCreate) (*model.Runtime, e
}
fileOp := files.NewFileOp()

runtimeDir := path.Join(constant.RuntimeDir, create.Type)
if !fileOp.Stat(runtimeDir) {
if err := fileOp.CreateDir(runtimeDir, constant.DirPerm); err != nil {
return nil, err
}
}

switch create.Type {
case constant.RuntimePHP:
if create.Resource == constant.ResourceLocal {
Expand Down
27 changes: 27 additions & 0 deletions agent/utils/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,33 @@ func CompareVersion(version1, version2 string) bool {
return false
}

func CompareAppVersion(version1, version2 string) bool {
v1s := extractNumbers(version1)
v2s := extractNumbers(version2)

maxLen := max(len(v1s), len(v2s))
v1s = append(v1s, make([]string, maxLen-len(v1s))...)
v2s = append(v2s, make([]string, maxLen-len(v2s))...)

for i := 0; i < maxLen; i++ {
v1, err1 := strconv.Atoi(v1s[i])
v2, err2 := strconv.Atoi(v2s[i])
if err1 != nil {
v1 = 0
}
if err2 != nil {
v2 = 0
}
if v1 > v2 {
return true
}
if v1 < v2 {
return false
}
}
return true
}

func ComparePanelVersion(version1, version2 string) bool {
if version1 == version2 {
return false
Expand Down
1 change: 1 addition & 0 deletions core/constant/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ var WebUrlMap = map[string]struct{}{
"/xpack/alert/log": {},
"/xpack/alert/setting": {},
"/xpack/setting": {},
"xpack/node": {},
}

var DynamicRoutes = []string{
Expand Down
2 changes: 1 addition & 1 deletion core/init/viper/viper.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func Init() {
baseDir := "/opt"
port := "9999"
mode := ""
version := "v1.0.0"
version := "v2.0.0"
username, password, entrance := "", "", ""
v := viper.NewWithOptions()
v.SetConfigType("yaml")
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/routers/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const routes: RouteRecordRaw[] = [
{
path: '/:code?',
name: 'entrance',
component: () => import('@/views/login/entrance/index.vue'),
component: () => import('@/views/login/index.vue'),
props: true,
},
...routerArray,
Expand Down
165 changes: 0 additions & 165 deletions frontend/src/views/login/entrance/index.vue

This file was deleted.

11 changes: 11 additions & 0 deletions frontend/src/views/login/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,20 @@ import { getXpackSettingForTheme } from '@/utils/xpack';
const gStore = GlobalStore();
const loading = ref();
const mySafetyCode = defineProps({
code: {
type: String,
default: '',
},
});
const screenWidth = ref(null);
const getStatus = async () => {
let code = mySafetyCode.code;
if (code != '') {
gStore.entrance = code;
}
loading.value = true;
await checkIsSafety(gStore.entrance)
.then((res) => {
Expand Down

0 comments on commit da73f26

Please sign in to comment.