2019-07-08 14:36:56 +00:00
|
|
|
package main
|
|
|
|
|
2019-07-08 20:32:12 +00:00
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"log"
|
|
|
|
"log/syslog"
|
2019-07-10 16:40:15 +00:00
|
|
|
"math/rand"
|
2019-07-08 20:32:12 +00:00
|
|
|
"os"
|
2019-07-10 16:40:15 +00:00
|
|
|
"time"
|
2019-07-08 20:32:12 +00:00
|
|
|
|
|
|
|
"github.com/pyke369/golang-support/uconfig"
|
|
|
|
)
|
|
|
|
|
2019-07-08 14:36:56 +00:00
|
|
|
func main() {
|
2019-07-08 20:32:12 +00:00
|
|
|
var err error
|
2019-07-08 23:44:18 +00:00
|
|
|
var config *uconfig.UConfig
|
2019-07-11 06:14:38 +00:00
|
|
|
// default configuration file is /etc/openvpn/dm-mgt-server.conf
|
2019-08-16 15:23:19 +00:00
|
|
|
configFile := flag.String("config", "/etc/openvpn/vpn-mgt.conf", "configuration file")
|
2019-07-08 20:32:12 +00:00
|
|
|
logToSyslog := flag.Bool("syslog", false, "Log to syslog")
|
2019-07-11 06:14:38 +00:00
|
|
|
debug := flag.Bool("debug", false, "log every message received")
|
2019-07-08 20:32:12 +00:00
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
// parseconfig
|
|
|
|
if config, err = uconfig.New(*configFile); err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
2019-07-10 16:40:15 +00:00
|
|
|
// seed the prng
|
|
|
|
rand.Seed(time.Now().UnixNano())
|
|
|
|
|
2019-08-15 09:19:40 +00:00
|
|
|
server := NewVPNServer(config.GetString("config.openvpnPort", "127.0.0.01:5000"), *debug)
|
2019-07-08 20:32:12 +00:00
|
|
|
|
|
|
|
if *logToSyslog {
|
|
|
|
log.SetFlags(0)
|
2019-08-15 09:19:40 +00:00
|
|
|
logWriter, e := syslog.New(syslog.LOG_NOTICE, "vpncontrol")
|
2019-07-08 20:32:12 +00:00
|
|
|
if e == nil {
|
|
|
|
log.SetOutput(logWriter)
|
|
|
|
defer logWriter.Close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-08 23:44:18 +00:00
|
|
|
// time to start the listeners
|
2019-08-15 09:19:40 +00:00
|
|
|
go NewHTTPServer(
|
2019-07-11 10:20:08 +00:00
|
|
|
config.GetString("config.http.port", "127.0.0.01:8080"),
|
2019-08-17 09:00:45 +00:00
|
|
|
config.GetString("config.http.key", ""),
|
|
|
|
config.GetString("config.http.cert", ""),
|
2019-07-08 20:32:12 +00:00
|
|
|
server)
|
2019-08-15 09:19:40 +00:00
|
|
|
server.Run()
|
|
|
|
|
|
|
|
// server.Run() should never end
|
|
|
|
os.Exit(1)
|
2019-07-08 14:36:56 +00:00
|
|
|
}
|