openvpn-mgt/main.go

95 lines
3.1 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"
2019-07-10 16:40:15 +00:00
"math/rand"
2019-07-08 20:32:12 +00:00
"os"
2019-07-08 23:44:18 +00:00
"strings"
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
configFile := flag.String("config", "/etc/openvpn/dm-mgt-server.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-07-08 20:32:12 +00:00
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.cacheDir = config.GetString("config.cacheDir", "")
server.authCa = config.GetString("config.authCa", "")
2019-07-09 10:34:45 +00:00
server.otpMasterSecrets = parseConfigArray(config, "config.masterSecrets")
2019-07-11 06:14:38 +00:00
server.ipRouteScript = config.GetString("config.ipRouteScript", "/bin/ip")
2019-07-09 10:34:45 +00:00
if len(server.otpMasterSecrets) == 0 {
server.otpMasterSecrets = append(server.otpMasterSecrets, "*******************")
}
2019-07-08 20:32:12 +00:00
server.syslog = false
if *logToSyslog {
log.SetFlags(0)
server.syslog = true
logWriter, e := syslog.New(syslog.LOG_NOTICE, "vpnauth")
2019-07-08 20:32:12 +00:00
if e == nil {
log.SetOutput(logWriter)
defer logWriter.Close()
}
}
2019-07-11 06:14:38 +00:00
server.debug = false
if *debug {
server.debug = true
}
2019-07-08 23:44:18 +00:00
for _, profile := range config.GetPaths("config.profiles") {
profileName := strings.Split(profile, ".")[2]
ldapConf := ldapConfig{
servers: parseConfigArray(config, profile+".servers"),
baseDN: config.GetString(profile+".baseDN", ""),
bindCn: config.GetString(profile+".bindCn", ""),
bindPw: config.GetString(profile+".bindPw", ""),
searchFilter: config.GetString(profile+".searchFilter", ""),
primaryAttribute: config.GetString(profile+".primaryAttribute", ""),
secondaryAttribute: config.GetString(profile+".secondaryAttribute", ""),
validGroups: parseConfigArray(config, profile+".validGroups"),
routes: parseConfigArray(config, profile+".routes"),
mfaType: config.GetString(profile+".mfa", ""),
2019-07-08 23:44:18 +00:00
certAuth: config.GetString(profile+".cert", "optionnal"),
upgradeFrom: config.GetString(profile+".upgradeFrom", ""),
}
ldapConf.addIPRange(config.GetString(profile+".IPRange", ""))
server.ldap[profileName] = ldapConf
}
// time to start the listeners
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
}