log web access
This commit is contained in:
parent
e4c5718f6d
commit
0d918b7540
7
httpd.go
7
httpd.go
|
@ -118,12 +118,13 @@ func (h *HttpServer) ajaxHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
profile, _, _ := h.ovpn.AuthLoop(h.minProfile,
|
webuser := strings.Replace(r.TLS.PeerCertificates[0].Subject.CommonName, " ", "", -1)
|
||||||
strings.Replace(r.TLS.PeerCertificates[0].Subject.CommonName, " ", "", -1), "", false)
|
profile, _, _ := h.ovpn.AuthLoop(h.minProfile, webuser, "", false)
|
||||||
if profile != h.neededProfile {
|
if profile != h.neededProfile {
|
||||||
http.Error(w, fmt.Sprintf("You need the %s profile", h.neededProfile), 403)
|
http.Error(w, fmt.Sprintf("You need the %s profile", h.neededProfile), 403)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
log.Printf("%s is connected via the web interfaces\n", webuser)
|
||||||
|
|
||||||
req, err := parseJsonQuery(r)
|
req, err := parseJsonQuery(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -141,7 +142,7 @@ func (h *HttpServer) ajaxHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
fmt.Fprintf(w, "%s", jsonStr)
|
fmt.Fprintf(w, "%s", jsonStr)
|
||||||
|
|
||||||
case "kill":
|
case "kill":
|
||||||
if err := h.ovpn.Kill(req.Params.Session, req.Params.Id); err != nil {
|
if err := h.ovpn.Kill(req.Params.Session, req.Params.Id, webuser); err != nil {
|
||||||
http.Error(w, fmt.Sprintf("%s", err), 500)
|
http.Error(w, fmt.Sprintf("%s", err), 500)
|
||||||
}
|
}
|
||||||
fmt.Fprintf(w, "{}")
|
fmt.Fprintf(w, "{}")
|
||||||
|
|
|
@ -122,13 +122,14 @@ func (s *OpenVpnMgt) Stats() map[string]map[int]*vpnSession {
|
||||||
return s.clients
|
return s.clients
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *OpenVpnMgt) Kill(session string, id int) error {
|
func (s *OpenVpnMgt) Kill(session string, id int, killer string) error {
|
||||||
if _, ok := s.clients[session]; !ok {
|
if _, ok := s.clients[session]; !ok {
|
||||||
return errors.New("unknown session")
|
return errors.New("unknown session")
|
||||||
}
|
}
|
||||||
if _, ok := s.clients[session][id]; !ok {
|
if _, ok := s.clients[session][id]; !ok {
|
||||||
return errors.New("unknown session id")
|
return errors.New("unknown session id")
|
||||||
}
|
}
|
||||||
|
log.Printf("user %s's session killed from the web by %s\n", s.clients[session][id].Login, killer)
|
||||||
err, _ := s.sendCommand([]string{fmt.Sprintf("client-kill %d", id)}, session)
|
err, _ := s.sendCommand([]string{fmt.Sprintf("client-kill %d", id)}, session)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue