mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-06 22:30:56 +03:00
external auth: add example HTTP server to use as authentication hook
The server authenticate against an LDAP server.
This commit is contained in:
28
examples/ldapauthserver/utils/utils.go
Normal file
28
examples/ldapauthserver/utils/utils.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// IsFileInputValid returns true this is a valid file name.
|
||||
// This method must be used before joining a file name, generally provided as
|
||||
// user input, with a directory
|
||||
func IsFileInputValid(fileInput string) bool {
|
||||
cleanInput := filepath.Clean(fileInput)
|
||||
if cleanInput == "." || cleanInput == ".." {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// IsStringPrefixInSlice searches a string prefix in a slice and returns true
|
||||
// if a matching prefix is found
|
||||
func IsStringPrefixInSlice(obj string, list []string) bool {
|
||||
for _, v := range list {
|
||||
if strings.HasPrefix(obj, v) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
41
examples/ldapauthserver/utils/version.go
Normal file
41
examples/ldapauthserver/utils/version.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package utils
|
||||
|
||||
const version = "0.1.0-dev"
|
||||
|
||||
var (
|
||||
commit = ""
|
||||
date = ""
|
||||
versionInfo VersionInfo
|
||||
)
|
||||
|
||||
// VersionInfo defines version details
|
||||
type VersionInfo struct {
|
||||
Version string `json:"version"`
|
||||
BuildDate string `json:"build_date"`
|
||||
CommitHash string `json:"commit_hash"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
versionInfo = VersionInfo{
|
||||
Version: version,
|
||||
CommitHash: commit,
|
||||
BuildDate: date,
|
||||
}
|
||||
}
|
||||
|
||||
// GetVersionAsString returns the string representation of the VersionInfo struct
|
||||
func (v *VersionInfo) GetVersionAsString() string {
|
||||
versionString := v.Version
|
||||
if len(v.CommitHash) > 0 {
|
||||
versionString += "-" + v.CommitHash
|
||||
}
|
||||
if len(v.BuildDate) > 0 {
|
||||
versionString += "-" + v.BuildDate
|
||||
}
|
||||
return versionString
|
||||
}
|
||||
|
||||
// GetAppVersion returns VersionInfo struct
|
||||
func GetAppVersion() VersionInfo {
|
||||
return versionInfo
|
||||
}
|
||||
Reference in New Issue
Block a user