mirror of
https://github.com/IceWhaleTech/CasaOS.git
synced 2025-09-23 19:30:34 +00:00
Compare commits
21 Commits
6ca194c0a6
...
58f3c2f46a
Author | SHA1 | Date | |
---|---|---|---|
|
58f3c2f46a | ||
|
ba285cb8bd | ||
|
87b4f3e0ff | ||
|
9c6c8db784 | ||
|
4591a6c567 | ||
|
7e98f0f563 | ||
|
479a29ef3a | ||
|
601b78d0c8 | ||
|
f39ae50cd9 | ||
|
571ce2c4ac | ||
|
9e7619b481 | ||
|
00e17b5b6c | ||
|
bc97dfa59d | ||
|
c8d542dbe3 | ||
|
21492682c3 | ||
|
8ca900d6f2 | ||
|
6407472a23 | ||
|
ea5d050f41 | ||
|
873e2a5ac7 | ||
|
85a72a6a15 | ||
|
94e545b388 |
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
@ -336,9 +336,16 @@ RestartSMBD(){
|
||||
$sudo_cmd systemctl restart smbd
|
||||
}
|
||||
|
||||
# edit user password $1:username
|
||||
# edit user password
|
||||
EditSmabaUserPassword(){
|
||||
$sudo_cmd smbpasswd $1
|
||||
$sudo_cmd smbpasswd -a $1 <<EOF
|
||||
$2
|
||||
$2
|
||||
EOF
|
||||
}
|
||||
|
||||
ListSambaUsers(){
|
||||
$sudo_cmd pdbedit -L
|
||||
}
|
||||
|
||||
AddSmabaUser(){
|
||||
|
@ -26,6 +26,7 @@ func (d *Onedrive) Config() driver.Config {
|
||||
func (d *Onedrive) GetAddition() driver.Additional {
|
||||
return &d.Addition
|
||||
}
|
||||
|
||||
func (d *Onedrive) Init(ctx context.Context) error {
|
||||
if d.ChunkSize < 1 {
|
||||
d.ChunkSize = 5
|
||||
@ -35,19 +36,20 @@ func (d *Onedrive) Init(ctx context.Context) error {
|
||||
}
|
||||
return d.refreshToken()
|
||||
}
|
||||
|
||||
func (d *Onedrive) GetUserInfo(ctx context.Context) (string, error) {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func (d *Onedrive) GetInfo(ctx context.Context) (string, string, string, error) {
|
||||
url := d.GetMetaUrl(false, "/")
|
||||
user := Info{}
|
||||
resp, err := d.Request(url, http.MethodGet, nil, &user)
|
||||
_, err := d.Request(url, http.MethodGet, nil, &user)
|
||||
if err != nil {
|
||||
return "", "", "", err
|
||||
}
|
||||
|
||||
logger.Info("resp", zap.Any("resp", resp))
|
||||
return user.LastModifiedBy.User.DisplayName, user.ParentReference.DriveID, user.ParentReference.DriveType, nil
|
||||
return user.CreatedBy.User.Email, user.ParentReference.DriveID, user.ParentReference.DriveType, nil
|
||||
}
|
||||
|
||||
func (d *Onedrive) GetSpaceSize(ctx context.Context) (used string, total string, err error) {
|
||||
@ -63,6 +65,7 @@ func (d *Onedrive) GetSpaceSize(ctx context.Context) (used string, total string,
|
||||
total = strconv.Itoa(size.Total)
|
||||
return
|
||||
}
|
||||
|
||||
func (d *Onedrive) Drop(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
@ -43,19 +43,12 @@ type About struct {
|
||||
}
|
||||
|
||||
type Info struct {
|
||||
LastModifiedBy struct {
|
||||
Application struct {
|
||||
DisplayName string `json:"displayName"`
|
||||
ID string `json:"id"`
|
||||
} `json:"application"`
|
||||
Device struct {
|
||||
ID string `json:"id"`
|
||||
} `json:"device"`
|
||||
CreatedBy struct {
|
||||
User struct {
|
||||
Email string `json:"email"`
|
||||
DisplayName string `json:"displayName"`
|
||||
ID string `json:"id"`
|
||||
} `json:"user"`
|
||||
} `json:"lastModifiedBy"`
|
||||
} `json:"createdBy"`
|
||||
ParentReference struct {
|
||||
DriveID string `json:"driveId"`
|
||||
DriveType string `json:"driveType"`
|
||||
|
@ -3,11 +3,10 @@ package onedrive
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS-Common/utils/logger"
|
||||
"github.com/IceWhaleTech/CasaOS/drivers/base"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/utils"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@ -15,6 +14,7 @@ var (
|
||||
client_id = "private build"
|
||||
client_secret = "private build"
|
||||
)
|
||||
|
||||
var onedriveHostMap = map[string]Host{
|
||||
"global": {
|
||||
Oauth: "https://login.microsoftonline.com",
|
||||
@ -34,31 +34,9 @@ var onedriveHostMap = map[string]Host{
|
||||
},
|
||||
}
|
||||
|
||||
func EncodePath(path string, all ...bool) string {
|
||||
seg := strings.Split(path, "/")
|
||||
toReplace := []struct {
|
||||
Src string
|
||||
Dst string
|
||||
}{
|
||||
{Src: "%", Dst: "%25"},
|
||||
{"%", "%25"},
|
||||
{"?", "%3F"},
|
||||
{"#", "%23"},
|
||||
}
|
||||
for i := range seg {
|
||||
if len(all) > 0 && all[0] {
|
||||
seg[i] = url.PathEscape(seg[i])
|
||||
} else {
|
||||
for j := range toReplace {
|
||||
seg[i] = strings.ReplaceAll(seg[i], toReplace[j].Src, toReplace[j].Dst)
|
||||
}
|
||||
}
|
||||
}
|
||||
return strings.Join(seg, "/")
|
||||
}
|
||||
func (d *Onedrive) GetMetaUrl(auth bool, path string) string {
|
||||
host := onedriveHostMap[d.Region]
|
||||
path = EncodePath(path, true)
|
||||
path = utils.EncodePath(path, true)
|
||||
if auth {
|
||||
return host.Oauth
|
||||
}
|
||||
|
2
go.mod
2
go.mod
@ -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
|
||||
)
|
||||
|
||||
|
2
go.sum
2
go.sum
@ -389,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()
|
||||
|
@ -16,23 +16,6 @@ import (
|
||||
)
|
||||
|
||||
func ListStorages(ctx echo.Context) error {
|
||||
// var req model.PageReq
|
||||
// if err := ctx.Bind(&req); err != nil {
|
||||
// return ctx.JSON(common_err.SUCCESS, model.Result{Success: common_err.CLIENT_ERROR, Message: common_err.GetMsg(common_err.CLIENT_ERROR), Data: err.Error()})
|
||||
// return
|
||||
// }
|
||||
// req.Validate()
|
||||
|
||||
// logger.Info("ListStorages", zap.Any("req", req))
|
||||
// storages, total, err := service.MyService.Storage().GetStorages(req.Page, req.PerPage)
|
||||
// if err != nil {
|
||||
// return ctx.JSON(common_err.SUCCESS, model.Result{Success: common_err.SERVICE_ERROR, Message: common_err.GetMsg(common_err.SERVICE_ERROR), Data: err.Error()})
|
||||
// return
|
||||
// }
|
||||
// return ctx.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: model.PageResp{
|
||||
// Content: storages,
|
||||
// Total: total,
|
||||
// }})
|
||||
r, err := service.MyService.Storage().GetStorages()
|
||||
if err != nil {
|
||||
return ctx.JSON(common_err.SUCCESS, model.Result{Success: common_err.SERVICE_ERROR, Message: common_err.GetMsg(common_err.SERVICE_ERROR), Data: err.Error()})
|
||||
@ -58,12 +41,7 @@ func ListStorages(ctx echo.Context) error {
|
||||
list := []httper.MountPoint{}
|
||||
|
||||
for _, v := range r.MountPoints {
|
||||
list = append(list, httper.MountPoint{
|
||||
Fs: v.Fs,
|
||||
Icon: v.Icon,
|
||||
MountPoint: v.MountPoint,
|
||||
Name: v.Name,
|
||||
})
|
||||
list = append(list, httper.MountPoint(v))
|
||||
}
|
||||
|
||||
return ctx.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: list})
|
||||
|
@ -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