mirror of
https://github.com/IceWhaleTech/CasaOS.git
synced 2025-09-17 17:15:16 +00:00
smb_users
This commit is contained in:
parent
873e2a5ac7
commit
ea5d050f41
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"
|
||||
}
|
@ -179,7 +179,8 @@ func InitV1Router() http.Handler {
|
||||
v1SharesGroup := v1SambaGroup.Group("/users")
|
||||
v1SharesGroup.Use()
|
||||
{
|
||||
v1SharesGroup.GET("", v1.ListSambaUsers)
|
||||
v1SharesGroup.GET("/list", v1.ListSambaUsers)
|
||||
v1SharesGroup.POST("/add", v1.AddSambaUser)
|
||||
}
|
||||
}
|
||||
v1NotifyGroup := v1Group.Group("/notify")
|
||||
|
@ -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
|
||||
|
||||
@ -73,7 +73,7 @@ func ListSambaUsers(ctx echo.Context) error {
|
||||
out, err := exec.Command("pdbedit -L").Output()
|
||||
|
||||
if err != nil {
|
||||
return ctx.JSON(common_err.SERVICE_ERROR, model.Result{Success: common_err.Failed, Message: common_err.GetMsg(common_err.Failed)})
|
||||
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")
|
||||
@ -81,6 +81,22 @@ func ListSambaUsers(ctx echo.Context) error {
|
||||
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{}
|
||||
ctx.Bind(&users)
|
||||
|
||||
for _, v := range users {
|
||||
out, err := exec.Command("echo " + v.Password + " | smbpasswd -a -s " + 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)})
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user