2017-02-12 04:13:29 +00:00
|
|
|
package main
|
|
|
|
|
2017-03-04 18:18:08 +00:00
|
|
|
import (
|
|
|
|
"crypto/tls"
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"time"
|
2017-02-12 04:13:29 +00:00
|
|
|
|
2017-03-11 20:28:49 +00:00
|
|
|
"github.com/spf13/viper"
|
|
|
|
|
2017-03-04 18:18:08 +00:00
|
|
|
"context"
|
2017-02-12 04:13:29 +00:00
|
|
|
|
2017-03-04 18:18:08 +00:00
|
|
|
"git.daplie.com/Daplie/go-rvpn-server/rvpn/genericlistener"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
loginfo *log.Logger
|
|
|
|
logdebug *log.Logger
|
|
|
|
logFlags = log.Ldate | log.Lmicroseconds | log.Lshortfile
|
|
|
|
argWssClientListener string
|
2017-03-11 20:28:49 +00:00
|
|
|
argGenericBinding int
|
2017-03-04 18:18:08 +00:00
|
|
|
argServerBinding string
|
|
|
|
argServerAdminBinding string
|
|
|
|
argServerExternalBinding string
|
|
|
|
argDeadTime int
|
|
|
|
connectionTable *genericlistener.Table
|
|
|
|
secretKey = "abc123"
|
2017-03-11 05:36:42 +00:00
|
|
|
wssHostName = "localhost.daplie.me"
|
2017-03-11 20:28:49 +00:00
|
|
|
adminHostName = "rvpn.daplie.invalid"
|
|
|
|
idle int
|
|
|
|
dwell int
|
|
|
|
cancelcheck int
|
2017-03-04 18:18:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2017-03-11 20:28:49 +00:00
|
|
|
|
2017-03-04 18:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Main -- main entry point
|
2017-02-12 04:13:29 +00:00
|
|
|
func main() {
|
2017-03-04 18:18:08 +00:00
|
|
|
flag.Parse()
|
2017-03-11 20:28:49 +00:00
|
|
|
loginfo = log.New(os.Stdout, "INFO: main: ", logFlags)
|
|
|
|
logdebug = log.New(os.Stdout, "DEBUG: main:", logFlags)
|
|
|
|
viper.SetConfigName("go-rvpn-server")
|
|
|
|
viper.AddConfigPath("./")
|
|
|
|
err := viper.ReadInConfig()
|
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Errorf("Fatal error config file: %s \n", err))
|
|
|
|
}
|
|
|
|
|
|
|
|
flag.IntVar(&argDeadTime, "dead-time-counter", 5, "deadtime counter in seconds")
|
2017-03-04 18:18:08 +00:00
|
|
|
|
2017-03-11 20:28:49 +00:00
|
|
|
wssHostName = viper.Get("rvpn.wssdomain").(string)
|
|
|
|
adminHostName = viper.Get("rvpn.admindomain").(string)
|
|
|
|
argGenericBinding = viper.GetInt("rvpn.genericlistener")
|
|
|
|
deadtime := viper.Get("rvpn.deadtime")
|
|
|
|
idle = deadtime.(map[string]interface{})["idle"].(int)
|
|
|
|
dwell = deadtime.(map[string]interface{})["dwell"].(int)
|
|
|
|
cancelcheck = deadtime.(map[string]interface{})["cancelcheck"].(int)
|
2017-03-04 18:18:08 +00:00
|
|
|
|
|
|
|
loginfo.Println("startup")
|
|
|
|
|
2017-03-11 20:28:49 +00:00
|
|
|
loginfo.Println(viper.Get("rvpn.genericlisteners"))
|
|
|
|
loginfo.Println(viper.Get("rvpn.domains"))
|
|
|
|
|
2017-03-04 18:18:08 +00:00
|
|
|
fmt.Println("-=-=-=-=-=-=-=-=-=-=")
|
|
|
|
|
|
|
|
certbundle, err := tls.LoadX509KeyPair("certs/fullchain.pem", "certs/privkey.pem")
|
|
|
|
if err != nil {
|
|
|
|
loginfo.Println(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx, cancelContext := context.WithCancel(context.Background())
|
|
|
|
defer cancelContext()
|
|
|
|
|
|
|
|
// Setup for GenericListenServe.
|
|
|
|
// - establish context for the generic listener
|
|
|
|
// - startup listener
|
|
|
|
// - accept with peek buffer.
|
|
|
|
// - peek at the 1st 30 bytes.
|
|
|
|
// - check for tls
|
|
|
|
// - if tls, establish, protocol peek buffer, else decrypted
|
|
|
|
// - match protocol
|
|
|
|
|
|
|
|
connectionTracking := genericlistener.NewTracking()
|
|
|
|
go connectionTracking.Run(ctx)
|
|
|
|
|
2017-03-11 20:28:49 +00:00
|
|
|
connectionTable = genericlistener.NewTable(dwell, idle)
|
2017-03-04 18:18:08 +00:00
|
|
|
go connectionTable.Run(ctx)
|
|
|
|
|
2017-03-11 20:28:49 +00:00
|
|
|
genericListeners := genericlistener.NewGenerListeners(ctx, connectionTable, connectionTracking, secretKey, certbundle, wssHostName, adminHostName, cancelcheck)
|
|
|
|
go genericListeners.Run(ctx, argGenericBinding)
|
2017-03-04 18:18:08 +00:00
|
|
|
|
|
|
|
//Run for 10 minutes and then shutdown cleanly
|
2017-03-18 19:28:54 +00:00
|
|
|
time.Sleep(6000 * time.Second)
|
2017-03-04 18:18:08 +00:00
|
|
|
cancelContext()
|
2017-02-12 04:13:29 +00:00
|
|
|
}
|