11 "gorm.io/driver/sqlite"
16 var tmpl
*template
.Template
18 func handle_index(w http
.ResponseWriter
, req
*http
.Request
) {
19 tmpl
.ExecuteTemplate(w
, "index", nil)
22 func handle_login(w http
.ResponseWriter
, req
*http
.Request
) {
23 /* TODO: Invalidate current session */
24 openid_authorization_url
:= generate_authorization_url()
25 http
.Redirect(w
, req
, openid_authorization_url
, 303)
30 fbfp_get_config("fbfp.scfg")
32 log
.Printf("Opening database\n")
33 switch config
.Db
.Type
{
35 db
, err
= gorm
.Open(sqlite
.Open(config
.Db
.Conn
), &gorm
.Config
{})
38 e(fmt
.Errorf("Database type %s unsupported", config
.Db
.Type
))
41 log
.Printf("Setting up templates\n")
42 tmpl
, err
= template
.ParseGlob("tmpl/*")
45 log
.Printf("Registering handlers\n")
46 http
.HandleFunc("/{$}", handle_index
)
47 http
.HandleFunc("/login", handle_login
)
48 http
.HandleFunc(config
.Openid
.Redirect
, handle_oidc
)
51 "Establishing listener for net %s, addr %s\n",
55 l
, err
:= net
.Listen(config
.Listen
.Net
, config
.Listen
.Addr
)
58 log
.Printf("Fetching OpenID Connect configuration\n")
59 get_openid_config(config
.Openid
.Endpoint
)
61 if config
.Listen
.Proto
== "http" {
62 log
.Printf("Serving http\n")
63 err
= http
.Serve(l
, nil)
64 } else if config
.Listen
.Proto
== "fcgi" {
65 log
.Printf("Serving fcgi\n")
66 err
= fcgi
.Serve(l
, nil)