ovpn-certman/main.go

52 lines
1 KiB
Go
Raw Normal View History

2018-01-26 08:43:53 +01:00
package main
import (
2018-02-03 18:14:47 +01:00
"errors"
2018-01-26 08:43:53 +01:00
"log"
"net/http"
2018-02-03 18:14:47 +01:00
"os"
"time"
"github.com/zom-bi/ovpn-certman/services"
2018-01-26 08:43:53 +01:00
"github.com/zom-bi/ovpn-certman/router"
"github.com/zom-bi/ovpn-certman/views"
2018-01-26 08:43:53 +01:00
)
func main() {
2018-02-03 18:14:47 +01:00
log.Println("Initializing certman")
if err := checkCAFilesExist(); err != nil {
log.Fatalf("Could not read CA files: %s", err)
}
c := services.Config{
2018-02-03 18:14:47 +01:00
CollectionPath: "./clients.json",
Sessions: &services.SessionsConfig{
2019-05-15 19:08:24 +02:00
HTTPOnly: true,
Lifetime: 24 * time.Hour,
},
}
2018-02-03 18:14:47 +01:00
log.Println(".. services")
serviceProvider := services.NewProvider(&c)
2018-01-26 08:43:53 +01:00
// load and parse template files
2018-02-03 18:14:47 +01:00
log.Println(".. templates")
2018-01-26 08:43:53 +01:00
views.LoadTemplates()
mux := router.HandleRoutes(serviceProvider)
2018-01-26 08:43:53 +01:00
2018-02-03 18:14:47 +01:00
log.Println(".. server")
2018-02-03 19:25:24 +01:00
err := http.ListenAndServe(os.Getenv("APP_LISTEN"), mux)
2018-01-26 08:43:53 +01:00
log.Fatalf(err.Error())
}
2018-02-03 18:14:47 +01:00
func checkCAFilesExist() error {
for _, filename := range []string{"ca.crt", "ca.key"} {
if _, err := os.Stat(filename); os.IsNotExist(err) {
return errors.New(filename + " not readable")
}
}
return nil
}