non anonymous samba shares

This commit is contained in:
Sheep26 2024-12-03 16:30:25 +13:00
parent 7da0f0d49e
commit 94e545b388
4 changed files with 12 additions and 5 deletions

View File

@ -14,4 +14,5 @@ type Shares struct {
ID uint `json:"id"`
Anonymous bool `json:"anonymous"`
Path string `json:"path"`
Valid_users []string{} `json:"valid_users"`
}

View File

@ -85,8 +85,9 @@ func PostSambaSharesCreate(ctx echo.Context) error {
}
for _, v := range shares {
shareDBModel := model2.SharesDBModel{}
shareDBModel.Anonymous = true
shareDBModel.Anonymous = v.Anonymous
shareDBModel.Path = v.Path
shareDBModel.Valid_users = v.Valid_users
shareDBModel.Name = filepath.Base(v.Path)
os.Chmod(v.Path, 0o777)
service.MyService.Shares().CreateShare(shareDBModel)

View File

@ -13,6 +13,7 @@ package model
type SharesDBModel struct {
ID uint `gorm:"column:id;primary_key" json:"id"`
Anonymous bool `json:"anonymous"`
Valid_users []string {} `json:"valid_users"`
Path string `json:"path"`
Name string `json:"name"`
Updated int64 `gorm:"autoUpdateTime"`

View File

@ -79,16 +79,20 @@ func (s *sharesStruct) UpdateConfigFile() {
configStr += `
[` + dirName + `]
comment = CasaOS share ` + dirName + `
public = Yes
public = ` + if (share.Anonymous){`Yes`} else {`No`} + `
path = ` + share.Path + `
browseable = Yes
read only = No
guest ok = Yes
guest ok = ` + if (share.Anonymous){`Yes`} else {`No`} + `
create mask = 0777
directory mask = 0777
force user = root
` + if (share.Anonymous){`force user = root`} else {`#force user = root`} +
if (!share.Anonymous) {`valid users` +
for _, user := range share.Valid_users {
user
}
}
`
}
// write config file
file.WriteToPath([]byte(configStr), "/etc/samba", "smb.casa.conf")