mirror of
https://github.com/IceWhaleTech/CasaOS.git
synced 2025-09-23 11:22:24 +00:00
Compare commits
9 Commits
4318a1ea15
...
7e98f0f563
Author | SHA1 | Date | |
---|---|---|---|
|
7e98f0f563 | ||
|
479a29ef3a | ||
|
601b78d0c8 | ||
|
f39ae50cd9 | ||
|
571ce2c4ac | ||
|
9e7619b481 | ||
|
00e17b5b6c | ||
|
bc97dfa59d | ||
|
16e97ec66f |
0
build/scripts/setup/script.d/03-setup-casaos.sh
Executable file → Normal file
0
build/scripts/setup/script.d/03-setup-casaos.sh
Executable file → Normal file
@ -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
|
||||
|
9
go.mod
9
go.mod
@ -4,7 +4,7 @@ go 1.21
|
||||
|
||||
require (
|
||||
github.com/Curtis-Milo/nat-type-identifier-go v0.0.0-20220215191915-18d42168c63d
|
||||
github.com/IceWhaleTech/CasaOS-Common v0.4.9-alpha6
|
||||
github.com/IceWhaleTech/CasaOS-Common v0.4.11-alpha4
|
||||
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf
|
||||
github.com/deckarep/golang-set/v2 v2.3.0
|
||||
github.com/deepmap/oapi-codegen v1.12.4
|
||||
@ -17,7 +17,7 @@ require (
|
||||
github.com/golang/mock v1.6.0
|
||||
github.com/gomodule/redigo v1.8.9
|
||||
github.com/google/go-github/v36 v36.0.0
|
||||
github.com/google/uuid v1.3.0
|
||||
github.com/google/uuid v1.5.0
|
||||
github.com/googollee/go-socket.io v1.7.0
|
||||
github.com/gorilla/websocket v1.5.0
|
||||
github.com/h2non/filetype v1.1.3
|
||||
@ -43,7 +43,7 @@ require (
|
||||
golang.org/x/oauth2 v0.7.0
|
||||
golang.org/x/sync v0.3.0
|
||||
golang.org/x/sys v0.20.0
|
||||
gorm.io/gorm v1.25.0
|
||||
gorm.io/gorm v1.25.12
|
||||
gotest.tools v2.2.0+incompatible
|
||||
)
|
||||
|
||||
@ -66,6 +66,7 @@ require (
|
||||
github.com/godbus/dbus/v5 v5.1.0 // indirect
|
||||
github.com/gofrs/uuid v4.4.0+incompatible // indirect
|
||||
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
|
||||
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
|
||||
github.com/golang-jwt/jwt/v5 v5.0.0 // indirect
|
||||
github.com/golang/geo v0.0.0-20210211234256-740aa86cb551 // indirect
|
||||
github.com/golang/protobuf v1.5.3 // indirect
|
||||
@ -78,7 +79,7 @@ require (
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
github.com/jinzhu/now v1.1.5 // indirect
|
||||
github.com/josharian/intern v1.0.0 // indirect
|
||||
github.com/klauspost/compress v1.16.5 // indirect
|
||||
github.com/klauspost/compress v1.16.7 // indirect
|
||||
github.com/klauspost/pgzip v1.2.5 // indirect
|
||||
github.com/labstack/echo-jwt/v4 v4.2.0 // indirect
|
||||
github.com/labstack/gommon v0.4.2 // indirect
|
||||
|
16
go.sum
16
go.sum
@ -1,7 +1,7 @@
|
||||
github.com/Curtis-Milo/nat-type-identifier-go v0.0.0-20220215191915-18d42168c63d h1:62lEBImTxZ83pgzywgDNIrPPuQ+j4ep9QjqrWBn1hrU=
|
||||
github.com/Curtis-Milo/nat-type-identifier-go v0.0.0-20220215191915-18d42168c63d/go.mod h1:lW9x+yEjqKdPbE3+cf2fGPJXCw/hChX3Omi9QHTLFsQ=
|
||||
github.com/IceWhaleTech/CasaOS-Common v0.4.9-alpha6 h1:ojExdb1fZDieTBYgNwopHAsW4FMGKkat4id8YwyyE0g=
|
||||
github.com/IceWhaleTech/CasaOS-Common v0.4.9-alpha6/go.mod h1:W/768nPd9BJXh+a72y8hUJNcmjDvyMqlXxlT+lOT3t4=
|
||||
github.com/IceWhaleTech/CasaOS-Common v0.4.11-alpha4 h1:W+kOJ3NcWCEAnZdjqmnjnhAG+aLbiVNXnOvV+1bHsB0=
|
||||
github.com/IceWhaleTech/CasaOS-Common v0.4.11-alpha4/go.mod h1:513p+6RXPBFr98GQZbY1TCyt6Q0jWiuK6vh+gBTmNwA=
|
||||
github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk=
|
||||
github.com/andybalholm/brotli v1.0.1/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y=
|
||||
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
|
||||
@ -84,6 +84,8 @@ github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1
|
||||
github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
|
||||
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
|
||||
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
|
||||
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
|
||||
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
|
||||
github.com/golang-jwt/jwt/v5 v5.0.0 h1:1n1XNM9hk7O9mnQoNBGolZvzebBQ7p93ULHRc28XJUE=
|
||||
github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
|
||||
github.com/golang/geo v0.0.0-20190916061304-5b978397cfec/go.mod h1:QZ0nwyI2jOfgRAoBvP+ab5aRr7c9x7lhGEJrKvBwjWI=
|
||||
@ -119,8 +121,8 @@ github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 h1:Xim43kblpZXfIBQsbu
|
||||
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26/go.mod h1:dDKJzRmX4S37WGHujM7tX//fmj1uioxKzKxz3lo4HJo=
|
||||
github.com/google/safetext v0.0.0-20240104143208-7a7d9b3d812f h1:o2yGZLlsOj5H5uvtQNEdi6DeA0GbUP3lm0gWW5RvY0s=
|
||||
github.com/google/safetext v0.0.0-20240104143208-7a7d9b3d812f/go.mod h1:H3K1Iu/utuCfa10JO+GsmKUYSWi7ug57Rk6GaDRHaaQ=
|
||||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
|
||||
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/googollee/go-socket.io v1.7.0 h1:ODcQSAvVIPvKozXtUGuJDV3pLwdpBLDs1Uoq/QHIlY8=
|
||||
github.com/googollee/go-socket.io v1.7.0/go.mod h1:0vGP8/dXR9SZUMMD4+xxaGo/lohOw3YWMh2WRiWeKxg=
|
||||
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
|
||||
@ -148,8 +150,8 @@ github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHm
|
||||
github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d/go.mod h1:2PavIy+JPciBPrBUjwbNvtwB6RQlve+hkpll6QSNmOE=
|
||||
github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
|
||||
github.com/klauspost/compress v1.11.4/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
|
||||
github.com/klauspost/compress v1.16.5 h1:IFV2oUNUzZaz+XyusxpLzpzS8Pt5rh0Z16For/djlyI=
|
||||
github.com/klauspost/compress v1.16.5/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
|
||||
github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I=
|
||||
github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
|
||||
github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
|
||||
github.com/klauspost/pgzip v1.2.5 h1:qnWYvvKqedOF2ulHpMG72XQol4ILEJ8k2wwRl/Km8oE=
|
||||
github.com/klauspost/pgzip v1.2.5/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs=
|
||||
@ -387,6 +389,8 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gorm.io/gorm v1.25.0 h1:+KtYtb2roDz14EQe4bla8CbQlmb9dN3VejSai3lprfU=
|
||||
gorm.io/gorm v1.25.0/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
|
||||
gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8=
|
||||
gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=
|
||||
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
|
||||
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
|
||||
modernc.org/libc v1.22.4 h1:wymSbZb0AlrjdAVX3cjreCHTPCpPARbQXNz6BHPzdwQ=
|
||||
|
@ -11,7 +11,8 @@
|
||||
package model
|
||||
|
||||
type Shares struct {
|
||||
ID uint `json:"id"`
|
||||
Anonymous bool `json:"anonymous"`
|
||||
Path string `json:"path"`
|
||||
ID uint `json:"id"`
|
||||
Anonymous bool `json:"anonymous"`
|
||||
Path string `json:"path"`
|
||||
Valid_users []string `json:"valid_users"`
|
||||
}
|
||||
|
16
model/smb_users.go
Normal file
16
model/smb_users.go
Normal file
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* @Author: Drew Fitzgerald/Sheep26 drew@sheepland.xyz
|
||||
* @Date: 2024-12-03
|
||||
* @LastEditors: Drew Fitzgerald/Sheep26
|
||||
* @LastEditTime: 2024-12-03
|
||||
* @FilePath: /CasaOS/service/model/o_smb_users.go
|
||||
* @Website: https://www.casaos.io
|
||||
* Copyright (c) 2024 by icewhale, All Rights Reserved.
|
||||
*/
|
||||
|
||||
package model
|
||||
|
||||
type SMBUsers struct {
|
||||
Name string "json:name"
|
||||
Password string "json:password"
|
||||
}
|
@ -176,6 +176,12 @@ func InitV1Router() http.Handler {
|
||||
v1SharesGroup.DELETE("/:id", v1.DeleteSambaShares)
|
||||
v1SharesGroup.GET("/status", v1.GetSambaStatus)
|
||||
}
|
||||
v1SharesGroup = v1SambaGroup.Group("/shares")
|
||||
v1SharesGroup.Use()
|
||||
{
|
||||
v1SharesGroup.GET("/list", v1.ListSambaUsers)
|
||||
v1SharesGroup.POST("/add", v1.AddSambaUser)
|
||||
}
|
||||
}
|
||||
v1NotifyGroup := v1Group.Group("/notify")
|
||||
v1NotifyGroup.Use()
|
||||
|
@ -1,12 +1,12 @@
|
||||
/*
|
||||
* @Author: LinkLeong link@icewhale.com
|
||||
* @Date: 2022-07-26 11:08:48
|
||||
* @LastEditors: LinkLeong
|
||||
* @LastEditTime: 2022-08-17 18:25:42
|
||||
* @LastEditors: Drew Fitzgerald/Sheep26
|
||||
* @LastEditTime: 2024-12-03
|
||||
* @FilePath: /CasaOS/route/v1/samba.go
|
||||
* @Description:
|
||||
* @Website: https://www.casaos.io
|
||||
* Copyright (c) 2022 by icewhale, All Rights Reserved.
|
||||
* Copyright (c) 2024 by icewhale, All Rights Reserved.
|
||||
*/
|
||||
package v1
|
||||
|
||||
@ -18,12 +18,14 @@ import (
|
||||
"path/filepath"
|
||||
"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"
|
||||
@ -58,14 +60,45 @@ func GetSambaSharesList(ctx echo.Context) error {
|
||||
shareList := []model.Shares{}
|
||||
for _, v := range shares {
|
||||
shareList = append(shareList, model.Shares{
|
||||
Anonymous: v.Anonymous,
|
||||
Path: v.Path,
|
||||
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 := 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 {
|
||||
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 {
|
||||
if !strings.Contains(out, v.Name) {
|
||||
command.OnlyExec("source " + config.AppInfo.ShellPath + "/helper.sh ;AddSmabaUser " + v.Name + " " + v.Password)
|
||||
}
|
||||
}
|
||||
|
||||
return ctx.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: users})
|
||||
}
|
||||
|
||||
func PostSambaSharesCreate(ctx echo.Context) error {
|
||||
shares := []model.Shares{}
|
||||
ctx.Bind(&shares)
|
||||
@ -85,8 +118,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)
|
||||
|
@ -11,12 +11,13 @@
|
||||
package model
|
||||
|
||||
type SharesDBModel struct {
|
||||
ID uint `gorm:"column:id;primary_key" json:"id"`
|
||||
Anonymous bool `json:"anonymous"`
|
||||
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,16 +79,40 @@ func (s *sharesStruct) UpdateConfigFile() {
|
||||
configStr += `
|
||||
[` + dirName + `]
|
||||
comment = CasaOS share ` + dirName + `
|
||||
public = Yes
|
||||
public = ` + func() string {
|
||||
if share.Anonymous {
|
||||
return "Yes"
|
||||
}
|
||||
return "No"
|
||||
}() + `
|
||||
path = ` + share.Path + `
|
||||
browseable = Yes
|
||||
read only = No
|
||||
guest ok = Yes
|
||||
guest ok = ` + func() string {
|
||||
if share.Anonymous {
|
||||
return "Yes"
|
||||
}
|
||||
return "No"
|
||||
}() + `
|
||||
create mask = 0777
|
||||
directory mask = 0777
|
||||
force user = root
|
||||
|
||||
` + 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