mirror of
https://github.com/IceWhaleTech/CasaOS.git
synced 2025-09-18 09:31:57 +00:00
refactor the fix issues
This commit is contained in:
parent
636bf62056
commit
7853bf9808
@ -69,22 +69,11 @@ func GetSambaSharesList(ctx echo.Context) error {
|
|||||||
return ctx.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: shareList})
|
return ctx.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: shareList})
|
||||||
}
|
}
|
||||||
|
|
||||||
func ListSambaUsers(ctx echo.Context) error {
|
|
||||||
out, err := command.OnlyExec("source " + config.AppInfo.ShellPath + "/helper.sh ;ListSambaUsers ")
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return ctx.JSON(common_err.SERVICE_ERROR, model.Result{Success: common_err.SERVICE_ERROR, Message: common_err.GetMsg(common_err.SERVICE_ERROR)})
|
|
||||||
}
|
|
||||||
|
|
||||||
users := strings.Split(out, "\n")
|
|
||||||
|
|
||||||
return ctx.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: users})
|
|
||||||
}
|
|
||||||
|
|
||||||
func AddSambaUser(ctx echo.Context) error {
|
func AddSambaUser(ctx echo.Context) error {
|
||||||
|
source := "source " + config.AppInfo.ShellPath
|
||||||
users := []model.SMBUsers{}
|
users := []model.SMBUsers{}
|
||||||
ctx.Bind(&users)
|
ctx.Bind(&users)
|
||||||
out, err := command.OnlyExec("source " + config.AppInfo.ShellPath + "/helper.sh ;ListSambaUsers ")
|
out, err := command.OnlyExec(source + "/helper.sh ;ListSambaUsers ")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ctx.JSON(common_err.SERVICE_ERROR, model.Result{Success: common_err.SERVICE_ERROR, Message: common_err.GetMsg(common_err.SERVICE_ERROR)})
|
return ctx.JSON(common_err.SERVICE_ERROR, model.Result{Success: common_err.SERVICE_ERROR, Message: common_err.GetMsg(common_err.SERVICE_ERROR)})
|
||||||
@ -92,7 +81,7 @@ func AddSambaUser(ctx echo.Context) error {
|
|||||||
|
|
||||||
for _, v := range users {
|
for _, v := range users {
|
||||||
if !strings.Contains(out, v.Name) {
|
if !strings.Contains(out, v.Name) {
|
||||||
command.OnlyExec("source " + config.AppInfo.ShellPath + "/helper.sh ;AddSmabaUser " + v.Name + " " + v.Password)
|
command.OnlyExec(source + "/helper.sh ;AddSmabaUser " + v.Name + " " + v.Password)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,6 +69,31 @@ func (s *sharesStruct) DeleteShare(id string) {
|
|||||||
s.UpdateConfigFile()
|
s.UpdateConfigFile()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getAnonymous(share model2.SharesDBModel) string {
|
||||||
|
if share.Anonymous {
|
||||||
|
return `Yes`
|
||||||
|
}
|
||||||
|
return `No`
|
||||||
|
}
|
||||||
|
|
||||||
|
func forceRoot(share model2.SharesDBModel) string {
|
||||||
|
if share.Anonymous {
|
||||||
|
return `force user = root`
|
||||||
|
}
|
||||||
|
return `#force user = root`
|
||||||
|
}
|
||||||
|
|
||||||
|
func getValidUsers(share model2.SharesDBModel) string {
|
||||||
|
if !share.Anonymous && len(share.Valid_users) > 0 {
|
||||||
|
users := `valid users =`
|
||||||
|
for _, user := range share.Valid_users {
|
||||||
|
users += " " + user
|
||||||
|
}
|
||||||
|
return users + "\n"
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
func (s *sharesStruct) UpdateConfigFile() {
|
func (s *sharesStruct) UpdateConfigFile() {
|
||||||
shares := []model2.SharesDBModel{}
|
shares := []model2.SharesDBModel{}
|
||||||
s.db.Select("anonymous,path,valid_users").Find(&shares)
|
s.db.Select("anonymous,path,valid_users").Find(&shares)
|
||||||
@ -79,41 +104,15 @@ func (s *sharesStruct) UpdateConfigFile() {
|
|||||||
configStr += `
|
configStr += `
|
||||||
[` + dirName + `]
|
[` + dirName + `]
|
||||||
comment = CasaOS share ` + dirName + `
|
comment = CasaOS share ` + dirName + `
|
||||||
public = ` + func() string {
|
public = ` + getAnonymous(share) + `
|
||||||
if share.Anonymous {
|
|
||||||
return "Yes"
|
|
||||||
}
|
|
||||||
return "No"
|
|
||||||
}() + `
|
|
||||||
path = ` + share.Path + `
|
path = ` + share.Path + `
|
||||||
browseable = Yes
|
browseable = Yes
|
||||||
read only = No
|
read only = No
|
||||||
guest ok = ` + func() string {
|
guest ok = ` + getAnonymous(share) + `
|
||||||
if share.Anonymous {
|
|
||||||
return "Yes"
|
|
||||||
}
|
|
||||||
return "No"
|
|
||||||
}() + `
|
|
||||||
create mask = 0777
|
create mask = 0777
|
||||||
directory mask = 0777
|
directory mask = 0777
|
||||||
` + func() string {
|
` + forceRoot(share) + `
|
||||||
if share.Anonymous {
|
` + getValidUsers(share)
|
||||||
return `force user = root
|
|
||||||
`
|
|
||||||
}
|
|
||||||
return `#force user = root
|
|
||||||
`
|
|
||||||
}() + func() string {
|
|
||||||
if !share.Anonymous && len(share.Valid_users) > 0 {
|
|
||||||
users := `valid users =`
|
|
||||||
for _, user := range share.Valid_users {
|
|
||||||
users += " " + user
|
|
||||||
}
|
|
||||||
return users + "\n"
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
// write config file
|
// write config file
|
||||||
file.WriteToPath([]byte(configStr), "/etc/samba", "smb.casa.conf")
|
file.WriteToPath([]byte(configStr), "/etc/samba", "smb.casa.conf")
|
||||||
// restart samba
|
// restart samba
|
||||||
|
Loading…
x
Reference in New Issue
Block a user