forked from namsral/multipass
/
config.go
56 lines (45 loc) · 1.35 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright 2016 Lars Wiegman. All rights reserved. Use of this source code is
// governed by a BSD-style license that can be found in the LICENSE file.
package multipass
import (
"net/http"
"net/url"
"time"
"github.com/mholt/caddy/caddyhttp/httpserver"
"github.com/namsral/multipass"
)
// Auth wraps a Multipass instance to be used by the caddy web server.
type Auth struct {
*multipass.Multipass
Next httpserver.Handler
}
// ServeHTTP implements the httpserver.ServeHTTP interface from caddy.
func (a *Auth) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
m := a.Multipass
if httpserver.Path(r.URL.Path).Matches(m.Basepath()) {
m.ServeHTTP(w, r)
return 200, nil
}
if _, err := multipass.ResourceHandler(w, r, m); err != nil {
v := url.Values{"next": []string{r.URL.String()}}
u := &url.URL{
Path: m.Basepath(),
RawQuery: v.Encode(),
}
location := u.String()
http.Redirect(w, r, location, http.StatusSeeOther)
return http.StatusSeeOther, nil
}
return a.Next.ServeHTTP(w, r)
}
// Rule holds the directive options parsed from a Caddyfile.
type Rule struct {
Basepath string
Expires time.Duration
Resources []string
Handles []string
SMTPAddr, SMTPUser, SMTPPass string
MailFrom, MailTmpl string
SMTPClientName string // named SMTP client for sending mail message
SMTPClientArgs []string
}