mirror of
https://github.com/IceWhaleTech/CasaOS.git
synced 2025-09-17 17:15:16 +00:00
syntax fixes
This commit is contained in:
parent
f39ae50cd9
commit
601b78d0c8
@ -341,6 +341,19 @@ EditSmabaUserPassword(){
|
||||
$sudo_cmd smbpasswd $1
|
||||
}
|
||||
|
||||
EditSmabaUserPassword(){
|
||||
$sudo_cmd smbpasswd $1
|
||||
}
|
||||
|
||||
|
||||
EditSambaUserPasswordSTDIN(){
|
||||
$sudo_cmd smbpasswd -s $2 $1
|
||||
}
|
||||
|
||||
ListSambaUsers(){
|
||||
$sudo_cmd pdbedit -L
|
||||
}
|
||||
|
||||
AddSmabaUser(){
|
||||
$sudo_cmd useradd $1
|
||||
$sudo_cmd smbpasswd -a $1 <<EOF
|
||||
|
@ -11,8 +11,8 @@
|
||||
package model
|
||||
|
||||
type Shares struct {
|
||||
ID uint `json:"id"`
|
||||
Anonymous bool `json:"anonymous"`
|
||||
Path string `json:"path"`
|
||||
Valid_users []string{} `json:"valid_users"`
|
||||
ID uint `json:"id"`
|
||||
Anonymous bool `json:"anonymous"`
|
||||
Path string `json:"path"`
|
||||
Valid_users []string `json:"valid_users"`
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ func InitV1Router() http.Handler {
|
||||
v1SharesGroup.DELETE("/:id", v1.DeleteSambaShares)
|
||||
v1SharesGroup.GET("/status", v1.GetSambaStatus)
|
||||
}
|
||||
v1SharesGroup := v1SambaGroup.Group("/users")
|
||||
v1SharesGroup = v1SambaGroup.Group("/shares")
|
||||
v1SharesGroup.Use()
|
||||
{
|
||||
v1SharesGroup.GET("/list", v1.ListSambaUsers)
|
||||
|
@ -17,15 +17,15 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS-Common/utils/command"
|
||||
"github.com/IceWhaleTech/CasaOS-Common/utils/logger"
|
||||
"github.com/IceWhaleTech/CasaOS-Common/utils/systemctl"
|
||||
"github.com/labstack/echo/v4"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS/model"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/config"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/samba"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/utils/common_err"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/utils/file"
|
||||
@ -60,37 +60,39 @@ func GetSambaSharesList(ctx echo.Context) error {
|
||||
shareList := []model.Shares{}
|
||||
for _, v := range shares {
|
||||
shareList = append(shareList, model.Shares{
|
||||
Anonymous: v.Anonymous,
|
||||
Path: v.Path,
|
||||
Valid_users: v.Valid_users,
|
||||
ID: v.ID,
|
||||
Anonymous: v.Anonymous,
|
||||
Path: v.Path,
|
||||
Valid_users: v.Valid_users,
|
||||
ID: v.ID,
|
||||
})
|
||||
}
|
||||
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 := exec.Command("pdbedit -L").Output()
|
||||
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)})
|
||||
}
|
||||
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("\n")
|
||||
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 {
|
||||
users := []mode.SMBUsers{}
|
||||
users := []model.SMBUsers{}
|
||||
ctx.Bind(&users)
|
||||
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)})
|
||||
}
|
||||
|
||||
for _, v := range users {
|
||||
out, err := exec.Command("echo " + v.Password + " | smbpasswd -s -a " + v.User).Output()
|
||||
|
||||
if (err != null) {
|
||||
if (v.User == "" || v.Password == "") return ctx.JSON(common_err.CLIENT_ERROR, model.Result{Success: common_err.CLIENT_ERROR, Message: common_err.GetMsg(common_err.CLIENT_ERROR)})
|
||||
else return ctx.JSON(common_err.SERVICE_ERROR, model.Result{Success: common_err.SERVICE_ERROR, Message: common_err.GetMsg(common_err.SERVICE_ERROR)})
|
||||
if !strings.Contains(out, v.Name) {
|
||||
command.OnlyExec("source " + config.AppInfo.ShellPath + "/helper.sh ;EditSmabaUserPasswordSTDIN " + v.Name + " " + v.Password)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,13 +11,13 @@
|
||||
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"`
|
||||
Created int64 `gorm:"autoCreateTime"`
|
||||
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"`
|
||||
Created int64 `gorm:"autoCreateTime"`
|
||||
}
|
||||
|
||||
func (p *SharesDBModel) TableName() string {
|
||||
|
@ -71,7 +71,7 @@ func (s *sharesStruct) DeleteShare(id string) {
|
||||
|
||||
func (s *sharesStruct) UpdateConfigFile() {
|
||||
shares := []model2.SharesDBModel{}
|
||||
s.db.Select("anonymous,path").Find(&shares)
|
||||
s.db.Select("anonymous,path,valid_users").Find(&shares)
|
||||
// generated config file
|
||||
configStr := ""
|
||||
for _, share := range shares {
|
||||
@ -79,20 +79,40 @@ func (s *sharesStruct) UpdateConfigFile() {
|
||||
configStr += `
|
||||
[` + dirName + `]
|
||||
comment = CasaOS share ` + dirName + `
|
||||
public = ` + if (share.Anonymous){`Yes`} else {`No`} + `
|
||||
public = ` + func() string {
|
||||
if share.Anonymous {
|
||||
return "Yes"
|
||||
}
|
||||
return "No"
|
||||
}() + `
|
||||
path = ` + share.Path + `
|
||||
browseable = Yes
|
||||
read only = No
|
||||
guest ok = ` + if (share.Anonymous){`Yes`} else {`No`} + `
|
||||
guest ok = ` + func() string {
|
||||
if share.Anonymous {
|
||||
return "Yes"
|
||||
}
|
||||
return "No"
|
||||
}() + `
|
||||
create mask = 0777
|
||||
directory mask = 0777
|
||||
` + if (share.Anonymous){`force user = root`} else {`#force user = root`} +
|
||||
if (!share.Anonymous) {`valid users` +
|
||||
for _, user := range share.Valid_users {
|
||||
user
|
||||
}
|
||||
}
|
||||
|
||||
` + func() string {
|
||||
if share.Anonymous {
|
||||
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
|
||||
file.WriteToPath([]byte(configStr), "/etc/samba", "smb.casa.conf")
|
||||
|
Loading…
x
Reference in New Issue
Block a user