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"
|
2018-01-29 16:52:59 +01:00
|
|
|
"time"
|
|
|
|
|
2018-01-26 14:49:03 +01:00
|
|
|
"git.klink.asia/paul/certman/services"
|
2018-01-26 08:43:53 +01:00
|
|
|
|
|
|
|
"git.klink.asia/paul/certman/router"
|
|
|
|
"git.klink.asia/paul/certman/views"
|
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2018-01-29 16:52:59 +01:00
|
|
|
c := services.Config{
|
2018-02-03 18:14:47 +01:00
|
|
|
CollectionPath: "./clients.json",
|
2018-01-29 16:52:59 +01:00
|
|
|
Sessions: &services.SessionsConfig{
|
|
|
|
SessionName: "_session",
|
2018-02-03 18:14:47 +01:00
|
|
|
CookieKey: os.Getenv("APP_KEY"),
|
2018-01-29 16:52:59 +01:00
|
|
|
HttpOnly: true,
|
|
|
|
Lifetime: 24 * time.Hour,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-02-03 18:14:47 +01:00
|
|
|
log.Println(".. services")
|
2018-01-29 16:52:59 +01:00
|
|
|
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()
|
|
|
|
|
2018-01-29 16:52:59 +01:00
|
|
|
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
|
|
|
|
}
|