mirror of
https://github.com/IceWhaleTech/CasaOS.git
synced 2025-06-16 05:55:33 +00:00
Update samba (#1021)
This commit is contained in:
parent
34b4e154a1
commit
af440eac55
@ -16,7 +16,6 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/IceWhaleTech/CasaOS-Common/utils/logger"
|
"github.com/IceWhaleTech/CasaOS-Common/utils/logger"
|
||||||
@ -27,7 +26,6 @@ import (
|
|||||||
"github.com/IceWhaleTech/CasaOS/pkg/samba"
|
"github.com/IceWhaleTech/CasaOS/pkg/samba"
|
||||||
"github.com/IceWhaleTech/CasaOS/pkg/utils/common_err"
|
"github.com/IceWhaleTech/CasaOS/pkg/utils/common_err"
|
||||||
"github.com/IceWhaleTech/CasaOS/pkg/utils/file"
|
"github.com/IceWhaleTech/CasaOS/pkg/utils/file"
|
||||||
"github.com/IceWhaleTech/CasaOS/pkg/utils/ip_helper"
|
|
||||||
"github.com/IceWhaleTech/CasaOS/service"
|
"github.com/IceWhaleTech/CasaOS/service"
|
||||||
model2 "github.com/IceWhaleTech/CasaOS/service/model"
|
model2 "github.com/IceWhaleTech/CasaOS/service/model"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@ -139,22 +137,22 @@ func PostSambaConnectionsCreate(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if ok, _ := regexp.MatchString(`^[\w@#*.]{4,30}$`, connection.Password); !ok {
|
// if ok, _ := regexp.MatchString(`^[\w@#*.]{4,30}$`, connection.Password); !ok {
|
||||||
c.JSON(common_err.CLIENT_ERROR, model.Result{Success: common_err.CHARACTER_LIMIT, Message: common_err.GetMsg(common_err.CHARACTER_LIMIT)})
|
// c.JSON(common_err.CLIENT_ERROR, model.Result{Success: common_err.CHARACTER_LIMIT, Message: common_err.GetMsg(common_err.CHARACTER_LIMIT)})
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
if ok, _ := regexp.MatchString(`^[\w@#*.]{4,30}$`, connection.Username); !ok {
|
// if ok, _ := regexp.MatchString(`^[\w@#*.]{4,30}$`, connection.Username); !ok {
|
||||||
c.JSON(common_err.CLIENT_ERROR, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)})
|
// c.JSON(common_err.CLIENT_ERROR, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)})
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
if !ip_helper.IsIPv4(connection.Host) && !ip_helper.IsIPv6(connection.Host) {
|
// if !ip_helper.IsIPv4(connection.Host) && !ip_helper.IsIPv6(connection.Host) {
|
||||||
c.JSON(common_err.CLIENT_ERROR, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)})
|
// c.JSON(common_err.CLIENT_ERROR, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)})
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
if ok, _ := regexp.MatchString("^[0-9]{1,6}$", connection.Port); !ok {
|
// if ok, _ := regexp.MatchString("^[0-9]{1,6}$", connection.Port); !ok {
|
||||||
c.JSON(common_err.CLIENT_ERROR, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)})
|
// c.JSON(common_err.CLIENT_ERROR, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)})
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
|
|
||||||
connection.Host = strings.Split(connection.Host, "/")[0]
|
connection.Host = strings.Split(connection.Host, "/")[0]
|
||||||
// check is exists
|
// check is exists
|
||||||
|
@ -11,11 +11,12 @@
|
|||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/IceWhaleTech/CasaOS/pkg/config"
|
"fmt"
|
||||||
command2 "github.com/IceWhaleTech/CasaOS/pkg/utils/command"
|
|
||||||
"github.com/IceWhaleTech/CasaOS/service/model"
|
"github.com/IceWhaleTech/CasaOS/service/model"
|
||||||
model2 "github.com/IceWhaleTech/CasaOS/service/model"
|
model2 "github.com/IceWhaleTech/CasaOS/service/model"
|
||||||
"github.com/moby/sys/mount"
|
"github.com/moby/sys/mount"
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -26,7 +27,7 @@ type ConnectionsService interface {
|
|||||||
CreateConnection(connection *model2.ConnectionsDBModel)
|
CreateConnection(connection *model2.ConnectionsDBModel)
|
||||||
DeleteConnection(id string)
|
DeleteConnection(id string)
|
||||||
UpdateConnection(connection *model2.ConnectionsDBModel)
|
UpdateConnection(connection *model2.ConnectionsDBModel)
|
||||||
MountSmaba(username, host, directory, port, mountPoint, password string) string
|
MountSmaba(username, host, directory, port, mountPoint, password string) error
|
||||||
UnmountSmaba(mountPoint string) error
|
UnmountSmaba(mountPoint string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,9 +57,17 @@ func (s *connectionsStruct) DeleteConnection(id string) {
|
|||||||
s.db.Where("id= ?", id).Delete(&model.ConnectionsDBModel{})
|
s.db.Where("id= ?", id).Delete(&model.ConnectionsDBModel{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *connectionsStruct) MountSmaba(username, host, directory, port, mountPoint, password string) string {
|
func (s *connectionsStruct) MountSmaba(username, host, directory, port, mountPoint, password string) error {
|
||||||
str := command2.ExecResultStr("source " + config.AppInfo.ShellPath + "/helper.sh ;MountCIFS " + username + " " + host + " " + directory + " " + port + " " + mountPoint + " " + password)
|
err := unix.Mount(
|
||||||
return str
|
fmt.Sprintf("//%s/%s", host, directory),
|
||||||
|
mountPoint,
|
||||||
|
"cifs",
|
||||||
|
unix.MS_NOATIME|unix.MS_NODEV|unix.MS_NOSUID,
|
||||||
|
fmt.Sprintf("username=%s,password=%s", username, password),
|
||||||
|
)
|
||||||
|
return err
|
||||||
|
//str := command2.ExecResultStr("source " + config.AppInfo.ShellPath + "/helper.sh ;MountCIFS " + username + " " + host + " " + directory + " " + port + " " + mountPoint + " " + password)
|
||||||
|
//return str
|
||||||
}
|
}
|
||||||
func (s *connectionsStruct) UnmountSmaba(mountPoint string) error {
|
func (s *connectionsStruct) UnmountSmaba(mountPoint string) error {
|
||||||
return mount.Unmount(mountPoint)
|
return mount.Unmount(mountPoint)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user