feat: When creating files/folders, use the parent directory's user an… (#8419)

Refs https://github.com/1Panel-dev/1Panel/issues/6332
This commit is contained in:
ChengPlay 2025-04-18 16:52:27 +08:00 committed by GitHub
parent 66aeb38419
commit c29c00f4b7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 71 additions and 37 deletions

View file

@ -204,15 +204,25 @@ func (f *FileService) Create(op request.FileCreate) error {
} }
} }
if op.IsDir { if op.IsDir {
return fo.CreateDirWithMode(op.Path, fs.FileMode(mode)) if err := fo.CreateDirWithMode(op.Path, fs.FileMode(mode)); err != nil {
return err
}
handleDefaultOwn(op.Path)
return nil
} }
if op.IsLink { if op.IsLink {
if !fo.Stat(op.LinkPath) { if !fo.Stat(op.LinkPath) {
return buserr.New("ErrLinkPathNotFound") return buserr.New("ErrLinkPathNotFound")
} }
return fo.LinkFile(op.LinkPath, op.Path, op.IsSymlink) if err := fo.LinkFile(op.LinkPath, op.Path, op.IsSymlink); err != nil {
return err
}
} }
return fo.CreateFileWithMode(op.Path, fs.FileMode(mode)) if err := fo.CreateFileWithMode(op.Path, fs.FileMode(mode)); err != nil {
return err
}
handleDefaultOwn(op.Path)
return nil
} }
func (f *FileService) Delete(op request.FileDelete) error { func (f *FileService) Delete(op request.FileDelete) error {

View file

@ -10,6 +10,7 @@ import (
"path/filepath" "path/filepath"
"strconv" "strconv"
"strings" "strings"
"syscall"
"time" "time"
"github.com/1Panel-dev/1Panel/agent/app/repo" "github.com/1Panel-dev/1Panel/agent/app/repo"
@ -1357,3 +1358,17 @@ func ConfigAIProxy(website model.Website) error {
} }
return nil return nil
} }
func handleDefaultOwn(dir string) {
parentDir := path.Dir(dir)
info, err := os.Stat(parentDir)
if err != nil {
return
}
stat, ok := info.Sys().(*syscall.Stat_t)
uid, gid := -1, -1
if ok {
uid, gid = int(stat.Uid), int(stat.Gid)
}
_ = os.Chown(dir, uid, gid)
}

View file

@ -47,7 +47,7 @@ func (b *BaseApi) RefreshToken(c *gin.Context) {
helper.InternalServer(c, err) helper.InternalServer(c, err)
return return
} }
helper.SuccessWithOutData(c) helper.Success(c)
} }
// @Tags Backup Account // @Tags Backup Account
@ -112,7 +112,7 @@ func (b *BaseApi) DeleteBackup(c *gin.Context) {
helper.InternalServer(c, err) helper.InternalServer(c, err)
return return
} }
helper.SuccessWithOutData(c) helper.Success(c)
} }
// @Tags Backup Account // @Tags Backup Account
@ -134,5 +134,5 @@ func (b *BaseApi) UpdateBackup(c *gin.Context) {
helper.InternalServer(c, err) helper.InternalServer(c, err)
return return
} }
helper.SuccessWithOutData(c) helper.Success(c)
} }

View file

@ -25,7 +25,7 @@ func (b *BaseApi) CreateCommand(c *gin.Context) {
helper.InternalServer(c, err) helper.InternalServer(c, err)
return return
} }
helper.SuccessWithOutData(c) helper.Success(c)
} }
// @Tags Command // @Tags Command
@ -119,7 +119,7 @@ func (b *BaseApi) DeleteCommand(c *gin.Context) {
helper.InternalServer(c, err) helper.InternalServer(c, err)
return return
} }
helper.SuccessWithOutData(c) helper.Success(c)
} }
// @Tags Command // @Tags Command
@ -141,5 +141,5 @@ func (b *BaseApi) UpdateCommand(c *gin.Context) {
helper.InternalServer(c, err) helper.InternalServer(c, err)
return return
} }
helper.SuccessWithOutData(c) helper.Success(c)
} }

View file

@ -25,7 +25,7 @@ func (b *BaseApi) CreateGroup(c *gin.Context) {
helper.InternalServer(c, err) helper.InternalServer(c, err)
return return
} }
helper.SuccessWithOutData(c) helper.Success(c)
} }
// @Tags System Group // @Tags System Group
@ -47,7 +47,7 @@ func (b *BaseApi) DeleteGroup(c *gin.Context) {
helper.InternalServer(c, err) helper.InternalServer(c, err)
return return
} }
helper.SuccessWithOutData(c) helper.Success(c)
} }
// @Tags System Group // @Tags System Group
@ -69,7 +69,7 @@ func (b *BaseApi) UpdateGroup(c *gin.Context) {
helper.InternalServer(c, err) helper.InternalServer(c, err)
return return
} }
helper.SuccessWithOutData(c) helper.Success(c)
} }
// @Tags System Group // @Tags System Group

View file

@ -47,7 +47,7 @@ func SuccessWithData(ctx *gin.Context, data interface{}) {
ctx.Abort() ctx.Abort()
} }
func SuccessWithOutData(ctx *gin.Context) { func Success(ctx *gin.Context) {
res := dto.Response{ res := dto.Response{
Code: http.StatusOK, Code: http.StatusOK,
Message: "success", Message: "success",

View file

@ -153,7 +153,7 @@ func (b *BaseApi) DeleteHost(c *gin.Context) {
helper.InternalServer(c, err) helper.InternalServer(c, err)
return return
} }
helper.SuccessWithOutData(c) helper.Success(c)
} }
// @Tags Host // @Tags Host
@ -244,7 +244,7 @@ func (b *BaseApi) UpdateHostGroup(c *gin.Context) {
helper.InternalServer(c, err) helper.InternalServer(c, err)
return return
} }
helper.SuccessWithOutData(c) helper.Success(c)
} }
// @Tags Host // @Tags Host

View file

@ -78,5 +78,5 @@ func (b *BaseApi) CleanLogs(c *gin.Context) {
return return
} }
helper.SuccessWithOutData(c) helper.Success(c)
} }

View file

@ -36,7 +36,7 @@ func (b *BaseApi) CreateScript(c *gin.Context) {
helper.InternalServer(c, err) helper.InternalServer(c, err)
return return
} }
helper.SuccessWithOutData(c) helper.Success(c)
} }
// @Tags ScriptLibrary // @Tags ScriptLibrary
@ -84,7 +84,7 @@ func (b *BaseApi) DeleteScript(c *gin.Context) {
helper.InternalServer(c, err) helper.InternalServer(c, err)
return return
} }
helper.SuccessWithOutData(c) helper.Success(c)
} }
// @Tags ScriptLibrary // @Tags ScriptLibrary
@ -99,7 +99,7 @@ func (b *BaseApi) SyncScript(c *gin.Context) {
helper.InternalServer(c, err) helper.InternalServer(c, err)
return return
} }
helper.SuccessWithOutData(c) helper.Success(c)
} }
// @Tags ScriptLibrary // @Tags ScriptLibrary
@ -121,7 +121,7 @@ func (b *BaseApi) UpdateScript(c *gin.Context) {
helper.InternalServer(c, err) helper.InternalServer(c, err)
return return
} }
helper.SuccessWithOutData(c) helper.Success(c)
} }
func (b *BaseApi) RunScript(c *gin.Context) { func (b *BaseApi) RunScript(c *gin.Context) {

View file

@ -54,7 +54,7 @@ func (b *BaseApi) GetTerminalSettingInfo(c *gin.Context) {
// @Security Timestamp // @Security Timestamp
// @Router /core/settings/search/available [get] // @Router /core/settings/search/available [get]
func (b *BaseApi) GetSystemAvailable(c *gin.Context) { func (b *BaseApi) GetSystemAvailable(c *gin.Context) {
helper.SuccessWithOutData(c) helper.Success(c)
} }
// @Tags System Setting // @Tags System Setting
@ -86,7 +86,7 @@ func (b *BaseApi) UpdateSetting(c *gin.Context) {
entranceValue := base64.StdEncoding.EncodeToString([]byte(req.Value)) entranceValue := base64.StdEncoding.EncodeToString([]byte(req.Value))
c.SetCookie("SecurityEntrance", entranceValue, 0, "", "", false, true) c.SetCookie("SecurityEntrance", entranceValue, 0, "", "", false, true)
} }
helper.SuccessWithOutData(c) helper.Success(c)
} }
// @Tags System Setting // @Tags System Setting
@ -108,7 +108,7 @@ func (b *BaseApi) UpdateTerminalSetting(c *gin.Context) {
helper.InternalServer(c, err) helper.InternalServer(c, err)
return return
} }
helper.SuccessWithOutData(c) helper.Success(c)
} }
// @Tags System Setting // @Tags System Setting
@ -139,7 +139,7 @@ func (b *BaseApi) UpdateProxy(c *gin.Context) {
helper.InternalServer(c, err) helper.InternalServer(c, err)
return return
} }
helper.SuccessWithOutData(c) helper.Success(c)
} }
// @Tags System Setting // @Tags System Setting
@ -161,7 +161,7 @@ func (b *BaseApi) UpdateMenu(c *gin.Context) {
helper.InternalServer(c, err) helper.InternalServer(c, err)
return return
} }
helper.SuccessWithOutData(c) helper.Success(c)
} }
// @Tags System Setting // @Tags System Setting
@ -183,7 +183,7 @@ func (b *BaseApi) UpdatePassword(c *gin.Context) {
helper.InternalServer(c, err) helper.InternalServer(c, err)
return return
} }
helper.SuccessWithOutData(c) helper.Success(c)
} }
// @Tags System Setting // @Tags System Setting
@ -205,7 +205,7 @@ func (b *BaseApi) UpdateSSL(c *gin.Context) {
helper.InternalServer(c, err) helper.InternalServer(c, err)
return return
} }
helper.SuccessWithOutData(c) helper.Success(c)
} }
// @Tags System Setting // @Tags System Setting
@ -274,7 +274,7 @@ func (b *BaseApi) UpdateBindInfo(c *gin.Context) {
helper.InternalServer(c, err) helper.InternalServer(c, err)
return return
} }
helper.SuccessWithOutData(c) helper.Success(c)
} }
// @Tags System Setting // @Tags System Setting
@ -296,7 +296,7 @@ func (b *BaseApi) UpdatePort(c *gin.Context) {
helper.InternalServer(c, err) helper.InternalServer(c, err)
return return
} }
helper.SuccessWithOutData(c) helper.Success(c)
} }
// @Tags System Setting // @Tags System Setting
@ -318,7 +318,7 @@ func (b *BaseApi) HandlePasswordExpired(c *gin.Context) {
helper.InternalServer(c, err) helper.InternalServer(c, err)
return return
} }
helper.SuccessWithOutData(c) helper.Success(c)
} }
// @Tags System Setting // @Tags System Setting
@ -380,7 +380,7 @@ func (b *BaseApi) MFABind(c *gin.Context) {
return return
} }
helper.SuccessWithOutData(c) helper.Success(c)
} }
func (b *BaseApi) ReloadSSL(c *gin.Context) { func (b *BaseApi) ReloadSSL(c *gin.Context) {
@ -393,7 +393,7 @@ func (b *BaseApi) ReloadSSL(c *gin.Context) {
helper.InternalServer(c, err) helper.InternalServer(c, err)
return return
} }
helper.SuccessWithOutData(c) helper.Success(c)
} }
// @Tags System Setting // @Tags System Setting
@ -442,7 +442,7 @@ func (b *BaseApi) UpdateApiConfig(c *gin.Context) {
helper.InternalServer(c, err) helper.InternalServer(c, err)
return return
} }
helper.SuccessWithOutData(c) helper.Success(c)
} }
func checkEntrancePattern(val string) bool { func checkEntrancePattern(val string) bool {

View file

@ -62,7 +62,7 @@ func (b *BaseApi) Upgrade(c *gin.Context) {
helper.InternalServer(c, err) helper.InternalServer(c, err)
return return
} }
helper.SuccessWithOutData(c) helper.Success(c)
} }
// @Tags System Setting // @Tags System Setting
@ -84,5 +84,5 @@ func (b *BaseApi) Rollback(c *gin.Context) {
helper.InternalServer(c, err) helper.InternalServer(c, err)
return return
} }
helper.SuccessWithOutData(c) helper.Success(c)
} }

View file

@ -31,8 +31,9 @@ func Proxy() gin.HandlerFunc {
return return
} }
var currentNode string var currentNode string
if c.Query("operateNode") != "" { queryNode := c.Query("operateNode")
currentNode = c.Query("operateNode") if queryNode != "" && queryNode != "undefined" {
currentNode = queryNode
} else { } else {
currentNode = c.Request.Header.Get("CurrentNode") currentNode = c.Request.Header.Get("CurrentNode")
} }

View file

@ -3116,6 +3116,7 @@ const message = {
websites: 'Website List', websites: 'Website List',
trend: 'Trend Statistics', trend: 'Trend Statistics',
reqCount: 'Request Count', reqCount: 'Request Count',
uriHelper: 'You can use /test/* or /*/index.php to exclude Uri',
}, },
tamper: { tamper: {
tamper: 'Website Tamper Protection', tamper: 'Website Tamper Protection',

View file

@ -2974,6 +2974,7 @@ const message = {
websites: 'ウェブサイトリスト', websites: 'ウェブサイトリスト',
trend: 'トレンド統計', trend: 'トレンド統計',
reqCount: 'リクエスト数', reqCount: 'リクエスト数',
uriHelper: '/test/* や /*/index.php を使用して Uri を除外できます',
}, },
tamper: { tamper: {
tamper: 'ウェブサイトの改ざん防止', tamper: 'ウェブサイトの改ざん防止',

View file

@ -2930,6 +2930,7 @@ const message = {
websites: '웹사이트 목록', websites: '웹사이트 목록',
trend: '추세 통계', trend: '추세 통계',
reqCount: '요청 ', reqCount: '요청 ',
uriHelper: '/test/* 또는 /*/index.php를 사용하여 Uri를 제외할 있습니다',
}, },
tamper: { tamper: {
tamper: '웹사이트 변조 방지', tamper: '웹사이트 변조 방지',

View file

@ -3041,6 +3041,7 @@ const message = {
websites: 'Senarai Laman Web', websites: 'Senarai Laman Web',
trend: 'Statistik Trend', trend: 'Statistik Trend',
reqCount: 'Jumlah Permintaan', reqCount: 'Jumlah Permintaan',
uriHelper: 'Anda boleh menggunakan /test/* atau /*/index.php untuk mengecualikan Uri',
}, },
tamper: { tamper: {
tamper: 'Perlindungan daripada peng篡改 laman web', tamper: 'Perlindungan daripada peng篡改 laman web',

View file

@ -3043,6 +3043,7 @@ const message = {
websites: 'Lista de Sites', websites: 'Lista de Sites',
trend: 'Estatísticas de Tendência', trend: 'Estatísticas de Tendência',
reqCount: 'Contagem de Solicitações', reqCount: 'Contagem de Solicitações',
uriHelper: 'Você pode usar /test/* ou /*/index.php para excluir Uri',
}, },
tamper: { tamper: {
tamper: 'Proteção contra adulteração do site', tamper: 'Proteção contra adulteração do site',

View file

@ -3034,6 +3034,7 @@ const message = {
websites: 'Список веб-сайтов', websites: 'Список веб-сайтов',
trend: 'Статистика тренда', trend: 'Статистика тренда',
reqCount: 'Количество запросов', reqCount: 'Количество запросов',
uriHelper: 'Вы можете использовать /test/* или /*/index.php для исключения Uri',
}, },
tamper: { tamper: {
tamper: 'Защита от подделки сайта', tamper: 'Защита от подделки сайта',

View file

@ -2894,6 +2894,7 @@ const message = {
websites: '網站列表', websites: '網站列表',
trend: '趨勢統計', trend: '趨勢統計',
reqCount: '請求數', reqCount: '請求數',
uriHelper: '可以使用 /test/* 或者 /*/index.php 來排除 Uri',
}, },
tamper: { tamper: {
tamper: '網站防篡改', tamper: '網站防篡改',

View file

@ -2877,6 +2877,7 @@ const message = {
websites: '网站列表', websites: '网站列表',
trend: '趋势统计', trend: '趋势统计',
reqCount: '请求数', reqCount: '请求数',
uriHelper: '可以使用 /test/* 或者 /*/index.php 来排除 Uri',
}, },
tamper: { tamper: {
tamper: '网站防篡改', tamper: '网站防篡改',