openvpn-mgt/main.go

58 lines
1.6 KiB
Go
Raw Normal View History

2019-07-08 14:36:56 +00:00
package main
2019-07-08 20:32:12 +00:00
import (
"flag"
"log"
"log/syslog"
"os"
"github.com/pyke369/golang-support/uconfig"
)
var config *uconfig.UConfig
2019-07-08 14:36:56 +00:00
func main() {
2019-07-08 20:32:12 +00:00
var err error
// default configuration file is ./openvpn-dm-mgt-server.conf
configFile := flag.String("config", "openvpn-dm-mgt-server.conf", "configuration file")
logToSyslog := flag.Bool("syslog", false, "Log to syslog")
flag.Parse()
// parseconfig
if config, err = uconfig.New(*configFile); err != nil {
log.Println(err)
os.Exit(1)
}
server := NewVPNServer(config.GetString("config.openvpnPort", "127.0.0.01:5000"))
server.vpnlogUrl = config.GetString("config.vpnLogUrl", "")
server.mailRelay = config.GetString("config.mailRelay", "")
server.MailFrom = config.GetString("config.mailFrom", "")
server.CcPwnPassword = config.GetString("config.ccPwnPassword", "")
server.pwnTemplate = config.GetString("config.pwnTemplate", "")
server.newAsTemplate = config.GetString("config.newAsTemplate", "")
server.slackTemplate = config.GetString("config.slackTemplate", "")
server.slackTemplate2 = config.GetString("config.slackTemplate2", "")
server.cacheDir = config.GetString("config.cacheDir", "")
server.authCa = config.GetString("config.authCa", "")
server.syslog = false
if *logToSyslog {
log.SetFlags(0)
server.syslog = true
logWriter, e := syslog.New(syslog.LOG_NOTICE, "")
if e == nil {
log.SetOutput(logWriter)
defer logWriter.Close()
}
}
2019-07-08 14:36:56 +00:00
go server.Run()
2019-07-08 20:32:12 +00:00
NewHTTPServer(
config.GetString("config.httpPort", "127.0.0.01:8080"),
config.GetString("config.httpKey", ""),
config.GetString("config.httpCert", ""),
config.GetString("config.httpCa", ""),
server)
2019-07-08 14:36:56 +00:00
}