forked from palark/ovpn-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
router-client-conf.go
52 lines (48 loc) · 1.41 KB
/
router-client-conf.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
package main
import (
"errors"
"log"
"net/http"
"rpiadm/backend/auth"
"rpiadm/backend/openvpn"
)
func (app *OvpnAdmin) buildClientOvpnConfigFile(w http.ResponseWriter, r *http.Request, username string) {
//for name, values := range r.Header {
// for _, value := range values {
// fmt.Printf("%s: %s\n", name, value)
// }
// //log.Printf("header %v", values)
//}
if !auth.HasReadRole(app.applicationPreferences.JwtData, r) {
credentials := getBasicAuth(r)
if apiKey := auth.HasValidApiKey(app.applicationPreferences.ApiKeys, credentials); apiKey == nil {
if len(credentials) != 0 {
w.WriteHeader(http.StatusForbidden)
} else {
w.Header().Set("WWW-Authenticate", "Basic realm=\"Please login or provide api-key\"")
w.WriteHeader(http.StatusUnauthorized)
}
return
} else {
log.Printf("use api key '%s'", apiKey.Comment)
}
}
device := app.getDevice(username)
if device == nil {
returnErrorMessage(w, http.StatusNotFound, errors.New("User "+username+" not found"))
return
}
w.Write(openvpn.RenderClientConfig(
*openvpnServer,
app.serverConf,
app.applicationPreferences.Preferences.ExplicitExitNotify,
app.applicationPreferences.Preferences.AuthNocache,
app.applicationPreferences.Preferences.Address,
app.applicationPreferences.Preferences.VerifyX509Name,
app.outboundIp.String(),
app.serverConf.MasterCn,
app.easyrsa.EasyrsaDirPath,
*authByPassword,
username,
))
}