openvpn-mgt/main.go

61 lines
1.4 KiB
Go

package main
import (
"flag"
"log"
"log/syslog"
"math/rand"
"os"
"time"
"github.com/pyke369/golang-support/uconfig"
)
func main() {
var err error
var config *uconfig.UConfig
// default configuration file is /etc/openvpn/dm-mgt-server.conf
configFile := flag.String("config", "/etc/openvpn/dm-mgt-server.conf", "configuration file")
logToSyslog := flag.Bool("syslog", false, "Log to syslog")
debug := flag.Bool("debug", false, "log every message received")
flag.Parse()
// parseconfig
if config, err = uconfig.New(*configFile); err != nil {
log.Println(err)
os.Exit(1)
}
// seed the prng
rand.Seed(time.Now().UnixNano())
server := NewVPNServer(config.GetString("config.openvpnPort", "127.0.0.01:5000"))
server.syslog = false
if *logToSyslog {
log.SetFlags(0)
server.syslog = true
logWriter, e := syslog.New(syslog.LOG_NOTICE, "vpnauth")
if e == nil {
log.SetOutput(logWriter)
defer logWriter.Close()
}
}
server.debug = false
if *debug {
server.debug = true
}
// time to start the listeners
go server.Run()
NewHTTPServer(
config.GetString("config.http.port", "127.0.0.01:8080"),
config.GetString("config.http.key", ""),
config.GetString("config.http.cert", ""),
config.GetString("config.http.ca", ""),
config.GetString("config.http.startAuth", "CORP"),
parseConfigArray(config, "config.http.reqAuth"),
server)
}