openvpn-mgt/main.go

79 lines
2.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"
2019-07-08 23:44:18 +00:00
"strings"
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-08 20:32:12 +00:00
// 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 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"),
otpType: config.GetString(profile+".otp", ""),
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
}