sum7/warehost
sum7
/
warehost
Archived
1
0
Fork 0
This repository has been archived on 2020-09-27. You can view files and clone it, but cannot push or open issues or pull requests.
warehost/cmd/warehost-host/pure-ftp-auth/main.go

70 lines
1.7 KiB
Go
Raw Normal View History

2016-09-02 21:32:56 +02:00
package main
import (
"fmt"
"os"
"path"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/postgres"
log "dev.sum7.de/sum7/warehost/lib/log"
libpassword "dev.sum7.de/sum7/warehost/lib/password"
system "dev.sum7.de/sum7/warehost/system"
)
var (
configFile string
config *Config
dbconnection *gorm.DB
)
func main() {
var err error
configFile = os.Getenv("CONFIGFILE")
if len(configFile) > 0 {
configFile = "config.yml"
}
config = ReadConfigFile(configFile)
log.NewSilenceLogger(config.Log.Path)
// Main Databaseconnection
dbconnection, err = gorm.Open("postgres", config.Database)
if err != nil {
log.Log.Fatal("database connection: ", err)
}
defer dbconnection.Close()
dbconnection.SingularTable(true)
dbconnection.LogMode(config.DatabaseDebug)
username := os.Getenv("AUTHD_ACCOUNT")
password := os.Getenv("AUTHD_PASSWORD")
logger := log.Log.WithField("user", username)
login := system.Login{Username: username}
dbconnection.Where("mail = ?", username).First(&login)
if login.ID <= 0 {
logger.Warn("user not found")
fmt.Println("auth_ok:-1")
} else if login.Active {
output, _ := libpassword.Validate(login.Password, password)
if output {
logger.Info("logged in")
fmt.Println("auth_ok:-1")
fmt.Printf("uid:%s\n", config.Userid)
fmt.Printf("gid:%s\n", config.Groupid)
fmt.Printf("dir:%s\n", path.Join(config.Path, fmt.Sprintf("%d", login.ID)))
if len(config.Quote) > 0 && !login.Superadmin {
fmt.Printf("user_quote_size:%s\n", config.Quote)
}
} else {
logger.Warn("wrong password")
fmt.Println("auth_ok:-1")
}
} else {
logger.Warn("not active")
fmt.Println("auth_ok:-1")
}
fmt.Println("end")
}