2016-11-27 10:46:50 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
"flag"
|
|
|
|
|
|
|
|
ftpd "github.com/goftp/server"
|
|
|
|
"github.com/jinzhu/gorm"
|
|
|
|
_ "github.com/jinzhu/gorm/dialects/postgres"
|
|
|
|
|
|
|
|
liblog "dev.sum7.eu/sum7/warehost/lib/log"
|
|
|
|
host "dev.sum7.eu/sum7/warehost/modul/host"
|
|
|
|
web "dev.sum7.eu/sum7/warehost/modul/web"
|
|
|
|
system "dev.sum7.eu/sum7/warehost/system"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
configFile string
|
|
|
|
dbconnection *gorm.DB
|
|
|
|
dbDB *sql.DB
|
|
|
|
config *Config
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
var err error
|
|
|
|
flag.StringVar(&configFile, "c", "config.yml", "path of configuration file")
|
|
|
|
flag.Parse()
|
|
|
|
config = ReadConfigFile(configFile)
|
|
|
|
liblog.NewLogger(config.Log.Path)
|
|
|
|
|
|
|
|
// Main Databaseconnection
|
|
|
|
dbconnection, err = gorm.Open("postgres", config.Database)
|
|
|
|
if err != nil {
|
|
|
|
liblog.Log.Fatal("database connection: ", err)
|
|
|
|
}
|
|
|
|
defer dbconnection.Close()
|
|
|
|
dbconnection.Callback().Create().Remove("gorm:update_time_stamp")
|
|
|
|
dbconnection.Callback().Update().Remove("gorm:update_time_stamp")
|
|
|
|
dbconnection.SingularTable(true)
|
|
|
|
dbconnection.LogMode(config.DatabaseDebug)
|
|
|
|
|
|
|
|
//load system Models to database
|
|
|
|
system.SyncModels(dbconnection)
|
|
|
|
host.SyncModels(dbconnection)
|
|
|
|
web.SyncModels(dbconnection)
|
|
|
|
|
|
|
|
opt := &ftpd.ServerOpts{
|
|
|
|
Name: "",
|
2016-12-19 12:52:43 +01:00
|
|
|
Factory: &FileDriverFactory{config: config, db: dbconnection, Perm: ftpd.NewSimplePerm("warehost", "http")},
|
2016-11-27 10:46:50 +01:00
|
|
|
Port: config.Port,
|
|
|
|
Auth: WarehostAuth{db: dbconnection},
|
|
|
|
}
|
2017-05-05 23:03:42 +02:00
|
|
|
if config.WelcomeMessage != "" {
|
|
|
|
opt.WelcomeMessage = config.WelcomeMessage
|
|
|
|
}
|
|
|
|
if config.SSL.Private != "" && config.SSL.Public != "" {
|
|
|
|
opt.TLS = true
|
|
|
|
opt.CertFile = config.SSL.Public
|
|
|
|
opt.KeyFile = config.SSL.Private
|
|
|
|
}
|
2016-11-27 10:46:50 +01:00
|
|
|
|
|
|
|
// start ftp server
|
|
|
|
ftpServer := ftpd.NewServer(opt)
|
|
|
|
liblog.Log.Info("warehost-ftp")
|
|
|
|
err = ftpServer.ListenAndServe()
|
|
|
|
if err != nil {
|
|
|
|
liblog.Log.Fatal("Error starting server:", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|