mirror of
https://github.com/drakkan/sftpgo.git
synced 2024-11-24 16:40:26 +00:00
removed unused methods
these methods were used in the old UIs Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
parent
a957474740
commit
150a338166
3 changed files with 0 additions and 279 deletions
|
@ -20,7 +20,6 @@ import (
|
|||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
|
@ -435,19 +434,6 @@ func (a *Admin) validate() error {
|
|||
return a.validateGroups()
|
||||
}
|
||||
|
||||
// GetGroupsAsString returns the user's groups as a string
|
||||
func (a *Admin) GetGroupsAsString() string {
|
||||
if len(a.Groups) == 0 {
|
||||
return ""
|
||||
}
|
||||
var groups []string
|
||||
for _, g := range a.Groups {
|
||||
groups = append(groups, g.Name)
|
||||
}
|
||||
sort.Strings(groups)
|
||||
return strings.Join(groups, ",")
|
||||
}
|
||||
|
||||
// CheckPassword verifies the admin password
|
||||
func (a *Admin) CheckPassword(password string) (bool, error) {
|
||||
if config.PasswordCaching {
|
||||
|
@ -579,19 +565,6 @@ func (a *Admin) HasPermission(perm string) bool {
|
|||
return util.Contains(a.Permissions, perm)
|
||||
}
|
||||
|
||||
// GetPermissionsAsString returns permission as string
|
||||
func (a *Admin) GetPermissionsAsString() string {
|
||||
return strings.Join(a.Permissions, ", ")
|
||||
}
|
||||
|
||||
// GetLastLoginAsString returns the last login as string
|
||||
func (a *Admin) GetLastLoginAsString() string {
|
||||
if a.LastLogin > 0 {
|
||||
return util.GetTimeFromMsecSinceEpoch(a.LastLogin).UTC().Format(iso8601UTCFormat)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// GetAllowedIPAsString returns the allowed IP as comma separated string
|
||||
func (a *Admin) GetAllowedIPAsString() string {
|
||||
return strings.Join(a.Filters.AllowList, ",")
|
||||
|
|
|
@ -1357,205 +1357,6 @@ func (u *User) GetDataTransferLimits() (int64, int64, int64) {
|
|||
return ul, dl, total
|
||||
}
|
||||
|
||||
// GetQuotaSummary returns used quota and limits if defined
|
||||
func (u *User) GetQuotaSummary() string {
|
||||
var sb strings.Builder
|
||||
|
||||
addSection := func() {
|
||||
if sb.Len() > 0 {
|
||||
sb.WriteString(". ")
|
||||
}
|
||||
}
|
||||
|
||||
if u.UsedQuotaFiles > 0 || u.QuotaFiles > 0 {
|
||||
sb.WriteString(fmt.Sprintf("Files: %v", u.UsedQuotaFiles))
|
||||
if u.QuotaFiles > 0 {
|
||||
sb.WriteString(fmt.Sprintf("/%v", u.QuotaFiles))
|
||||
}
|
||||
}
|
||||
if u.UsedQuotaSize > 0 || u.QuotaSize > 0 {
|
||||
addSection()
|
||||
sb.WriteString(fmt.Sprintf("Size: %v", util.ByteCountIEC(u.UsedQuotaSize)))
|
||||
if u.QuotaSize > 0 {
|
||||
sb.WriteString(fmt.Sprintf("/%v", util.ByteCountIEC(u.QuotaSize)))
|
||||
}
|
||||
}
|
||||
if u.TotalDataTransfer > 0 {
|
||||
addSection()
|
||||
total := u.UsedDownloadDataTransfer + u.UsedUploadDataTransfer
|
||||
sb.WriteString(fmt.Sprintf("Transfer: %v/%v", util.ByteCountIEC(total),
|
||||
util.ByteCountIEC(u.TotalDataTransfer*1048576)))
|
||||
}
|
||||
if u.UploadDataTransfer > 0 {
|
||||
addSection()
|
||||
sb.WriteString(fmt.Sprintf("UL: %v/%v", util.ByteCountIEC(u.UsedUploadDataTransfer),
|
||||
util.ByteCountIEC(u.UploadDataTransfer*1048576)))
|
||||
}
|
||||
if u.DownloadDataTransfer > 0 {
|
||||
addSection()
|
||||
sb.WriteString(fmt.Sprintf("DL: %v/%v", util.ByteCountIEC(u.UsedDownloadDataTransfer),
|
||||
util.ByteCountIEC(u.DownloadDataTransfer*1048576)))
|
||||
}
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
// GetPermissionsAsString returns the user's permissions as comma separated string
|
||||
func (u *User) GetPermissionsAsString() string {
|
||||
result := ""
|
||||
for dir, perms := range u.Permissions {
|
||||
dirPerms := strings.Join(perms, ", ")
|
||||
dp := fmt.Sprintf("%q: %q", dir, dirPerms)
|
||||
if dir == "/" {
|
||||
if result != "" {
|
||||
result = dp + ", " + result
|
||||
} else {
|
||||
result = dp
|
||||
}
|
||||
} else {
|
||||
if result != "" {
|
||||
result += ", "
|
||||
}
|
||||
result += dp
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// GetBandwidthAsString returns bandwidth limits if defines
|
||||
func (u *User) GetBandwidthAsString() string {
|
||||
var sb strings.Builder
|
||||
sb.WriteString("DL: ")
|
||||
if u.DownloadBandwidth > 0 {
|
||||
sb.WriteString(util.ByteCountIEC(u.DownloadBandwidth*1000) + "/s.")
|
||||
} else {
|
||||
sb.WriteString("unlimited.")
|
||||
}
|
||||
sb.WriteString(" UL: ")
|
||||
if u.UploadBandwidth > 0 {
|
||||
sb.WriteString(util.ByteCountIEC(u.UploadBandwidth*1000) + "/s.")
|
||||
} else {
|
||||
sb.WriteString("unlimited.")
|
||||
}
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
// GetMFAStatusAsString returns MFA status
|
||||
func (u *User) GetMFAStatusAsString() string {
|
||||
if u.Filters.TOTPConfig.Enabled {
|
||||
return strings.Join(u.Filters.TOTPConfig.Protocols, ", ")
|
||||
}
|
||||
return "Disabled"
|
||||
}
|
||||
|
||||
// GetLastLoginAsString returns the last login as string
|
||||
func (u *User) GetLastLoginAsString() string {
|
||||
if u.LastLogin > 0 {
|
||||
return util.GetTimeFromMsecSinceEpoch(u.LastLogin).UTC().Format(iso8601UTCFormat)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// GetLastQuotaUpdateAsString returns the last quota update as string
|
||||
func (u *User) GetLastQuotaUpdateAsString() string {
|
||||
if u.LastQuotaUpdate > 0 {
|
||||
return util.GetTimeFromMsecSinceEpoch(u.LastQuotaUpdate).UTC().Format(iso8601UTCFormat)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// GetStorageDescrition returns the storage description
|
||||
func (u *User) GetStorageDescrition() string {
|
||||
switch u.FsConfig.Provider {
|
||||
case sdk.LocalFilesystemProvider:
|
||||
return fmt.Sprintf("Local: %v", u.GetHomeDir())
|
||||
case sdk.S3FilesystemProvider:
|
||||
return fmt.Sprintf("S3: %v", u.FsConfig.S3Config.Bucket)
|
||||
case sdk.GCSFilesystemProvider:
|
||||
return fmt.Sprintf("GCS: %v", u.FsConfig.GCSConfig.Bucket)
|
||||
case sdk.AzureBlobFilesystemProvider:
|
||||
return fmt.Sprintf("AzBlob: %v", u.FsConfig.AzBlobConfig.Container)
|
||||
case sdk.CryptedFilesystemProvider:
|
||||
return fmt.Sprintf("Encrypted: %v", u.GetHomeDir())
|
||||
case sdk.SFTPFilesystemProvider:
|
||||
return fmt.Sprintf("SFTP: %v", u.FsConfig.SFTPConfig.Endpoint)
|
||||
case sdk.HTTPFilesystemProvider:
|
||||
return fmt.Sprintf("HTTP: %v", u.FsConfig.HTTPConfig.Endpoint)
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
// GetGroupsAsString returns the user's groups as a string
|
||||
func (u *User) GetGroupsAsString() string {
|
||||
if len(u.Groups) == 0 {
|
||||
return ""
|
||||
}
|
||||
var groups []string
|
||||
for _, g := range u.Groups {
|
||||
if g.Type == sdk.GroupTypePrimary {
|
||||
groups = append(groups, "")
|
||||
copy(groups[1:], groups)
|
||||
groups[0] = g.Name
|
||||
} else {
|
||||
groups = append(groups, g.Name)
|
||||
}
|
||||
}
|
||||
|
||||
return strings.Join(groups, ",")
|
||||
}
|
||||
|
||||
// GetInfoString returns user's info as string.
|
||||
// Storage provider, number of public keys, max sessions, uid,
|
||||
// gid, denied and allowed IP/Mask are returned
|
||||
func (u *User) GetInfoString() string {
|
||||
var result strings.Builder
|
||||
if len(u.PublicKeys) > 0 {
|
||||
result.WriteString(fmt.Sprintf("Public keys: %v. ", len(u.PublicKeys)))
|
||||
}
|
||||
if u.MaxSessions > 0 {
|
||||
result.WriteString(fmt.Sprintf("Max sessions: %v. ", u.MaxSessions))
|
||||
}
|
||||
if u.UID > 0 {
|
||||
result.WriteString(fmt.Sprintf("UID: %v. ", u.UID))
|
||||
}
|
||||
if u.GID > 0 {
|
||||
result.WriteString(fmt.Sprintf("GID: %v. ", u.GID))
|
||||
}
|
||||
if len(u.Filters.DeniedLoginMethods) > 0 {
|
||||
result.WriteString(fmt.Sprintf("Denied login methods: %v. ", strings.Join(u.Filters.DeniedLoginMethods, ",")))
|
||||
}
|
||||
if len(u.Filters.DeniedProtocols) > 0 {
|
||||
result.WriteString(fmt.Sprintf("Denied protocols: %v. ", strings.Join(u.Filters.DeniedProtocols, ",")))
|
||||
}
|
||||
if len(u.Filters.DeniedIP) > 0 {
|
||||
result.WriteString(fmt.Sprintf("Denied IP/Mask: %v. ", len(u.Filters.DeniedIP)))
|
||||
}
|
||||
if len(u.Filters.AllowedIP) > 0 {
|
||||
result.WriteString(fmt.Sprintf("Allowed IP/Mask: %v", len(u.Filters.AllowedIP)))
|
||||
}
|
||||
return result.String()
|
||||
}
|
||||
|
||||
// GetStatusAsString returns the user status as a string
|
||||
func (u *User) GetStatusAsString() string {
|
||||
if u.ExpirationDate > 0 && u.ExpirationDate < util.GetTimeAsMsSinceEpoch(time.Now()) {
|
||||
return "Expired"
|
||||
}
|
||||
if u.Status == 1 {
|
||||
return "Active"
|
||||
}
|
||||
return "Inactive"
|
||||
}
|
||||
|
||||
// GetExpirationDateAsString returns expiration date formatted as YYYY-MM-DD
|
||||
func (u *User) GetExpirationDateAsString() string {
|
||||
if u.ExpirationDate > 0 {
|
||||
t := util.GetTimeFromMsecSinceEpoch(u.ExpirationDate)
|
||||
return t.Format("2006-01-02")
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// GetAllowedIPAsString returns the allowed IP as comma separated string
|
||||
func (u *User) GetAllowedIPAsString() string {
|
||||
return strings.Join(u.Filters.AllowedIP, ",")
|
||||
|
|
|
@ -17,13 +17,10 @@ package vfs
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/rs/xid"
|
||||
"github.com/sftpgo/sdk"
|
||||
|
||||
"github.com/drakkan/sftpgo/v2/internal/util"
|
||||
)
|
||||
|
||||
// BaseVirtualFolder defines the path for the virtual folder and the used quota limits.
|
||||
|
@ -72,56 +69,6 @@ func (v *BaseVirtualFolder) GetACopy() BaseVirtualFolder {
|
|||
}
|
||||
}
|
||||
|
||||
// GetUsersAsString returns the list of users as comma separated string
|
||||
func (v *BaseVirtualFolder) GetUsersAsString() string {
|
||||
return strings.Join(v.Users, ",")
|
||||
}
|
||||
|
||||
// GetGroupsAsString returns the list of groups as comma separated string
|
||||
func (v *BaseVirtualFolder) GetGroupsAsString() string {
|
||||
return strings.Join(v.Groups, ",")
|
||||
}
|
||||
|
||||
// GetLastQuotaUpdateAsString returns the last quota update as string
|
||||
func (v *BaseVirtualFolder) GetLastQuotaUpdateAsString() string {
|
||||
if v.LastQuotaUpdate > 0 {
|
||||
return util.GetTimeFromMsecSinceEpoch(v.LastQuotaUpdate).UTC().Format("2006-01-02 15:04:05Z")
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// GetQuotaSummary returns used quota and last update as string
|
||||
func (v *BaseVirtualFolder) GetQuotaSummary() string {
|
||||
var result string
|
||||
result = "Files: " + strconv.Itoa(v.UsedQuotaFiles)
|
||||
if v.UsedQuotaSize > 0 {
|
||||
result += ". Size: " + util.ByteCountIEC(v.UsedQuotaSize)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// GetStorageDescrition returns the storage description
|
||||
func (v *BaseVirtualFolder) GetStorageDescrition() string {
|
||||
switch v.FsConfig.Provider {
|
||||
case sdk.LocalFilesystemProvider:
|
||||
return fmt.Sprintf("Local: %s", v.MappedPath)
|
||||
case sdk.S3FilesystemProvider:
|
||||
return fmt.Sprintf("S3: %s", v.FsConfig.S3Config.Bucket)
|
||||
case sdk.GCSFilesystemProvider:
|
||||
return fmt.Sprintf("GCS: %s", v.FsConfig.GCSConfig.Bucket)
|
||||
case sdk.AzureBlobFilesystemProvider:
|
||||
return fmt.Sprintf("AzBlob: %s", v.FsConfig.AzBlobConfig.Container)
|
||||
case sdk.CryptedFilesystemProvider:
|
||||
return fmt.Sprintf("Encrypted: %s", v.MappedPath)
|
||||
case sdk.SFTPFilesystemProvider:
|
||||
return fmt.Sprintf("SFTP: %s", v.FsConfig.SFTPConfig.Endpoint)
|
||||
case sdk.HTTPFilesystemProvider:
|
||||
return fmt.Sprintf("HTTP: %s", v.FsConfig.HTTPConfig.Endpoint)
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
// IsLocalOrLocalCrypted returns true if the folder provider is local or local encrypted
|
||||
func (v *BaseVirtualFolder) IsLocalOrLocalCrypted() bool {
|
||||
return v.FsConfig.Provider == sdk.LocalFilesystemProvider || v.FsConfig.Provider == sdk.CryptedFilesystemProvider
|
||||
|
|
Loading…
Reference in a new issue