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 Permalink 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"
2016-10-11 20:16:24 +02:00
liblog "dev.sum7.eu/sum7/warehost/lib/log"
libpassword "dev.sum7.eu/sum7/warehost/lib/password"
system "dev.sum7.eu/sum7/warehost/system"
2016-09-02 21:32:56 +02:00
)
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)
2016-10-11 20:16:24 +02:00
liblog.NewSilenceLogger(config.Log.Path)
2016-09-02 21:32:56 +02:00
// Main Databaseconnection
dbconnection, err = gorm.Open("postgres", config.Database)
if err != nil {
2016-10-11 20:16:24 +02:00
liblog.Log.Fatal("database connection: ", err)
2016-09-02 21:32:56 +02:00
}
defer dbconnection.Close()
dbconnection.SingularTable(true)
dbconnection.LogMode(config.DatabaseDebug)
username := os.Getenv("AUTHD_ACCOUNT")
password := os.Getenv("AUTHD_PASSWORD")
2016-10-11 20:16:24 +02:00
logger := liblog.Log.WithField("user", username)
2016-09-02 21:32:56 +02:00
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")
}