add stats and kill http calls
This commit is contained in:
24
vpnserver.go
24
vpnserver.go
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
@@ -117,6 +118,22 @@ func (s *OpenVpnMgt) sendCommand(msg []string, remote string) (error, []string)
|
||||
return nil, ret
|
||||
}
|
||||
|
||||
// send the list of all connected clients
|
||||
func (s *OpenVpnMgt) Stats() map[string]map[int]*vpnSession {
|
||||
return s.clients
|
||||
}
|
||||
|
||||
func (s *OpenVpnMgt) Kill(session string, id int) error {
|
||||
if _, ok := s.clients[session]; !ok {
|
||||
return errors.New("unknown session")
|
||||
}
|
||||
if _, ok := s.clients[session][id]; !ok {
|
||||
return errors.New("unknown session id")
|
||||
}
|
||||
err, msg := s.sendCommand([]string{fmt.Sprintf("client-kill %d", id)}, session)
|
||||
return err
|
||||
}
|
||||
|
||||
// send the help command on all vpn servers. Kind of useless
|
||||
func (s *OpenVpnMgt) Help() (error, map[string]map[string]string) {
|
||||
ret := make(map[string]map[string]string)
|
||||
@@ -139,7 +156,7 @@ func (s *OpenVpnMgt) Help() (error, map[string]map[string]string) {
|
||||
return nil, ret
|
||||
}
|
||||
|
||||
// send the verson command on all vpn servers. Kind of useless
|
||||
// send the version command on all vpn servers. Kind of useless
|
||||
func (s *OpenVpnMgt) Version() (error, map[string][]string) {
|
||||
ret := make(map[string][]string)
|
||||
for remote := range s.buf {
|
||||
@@ -295,7 +312,7 @@ func (s *OpenVpnMgt) handleConn(conn net.Conn) {
|
||||
}
|
||||
|
||||
// ask for statistics
|
||||
if _, err := s.buf[remote].WriteString("bytecount 10\r\n"); err != nil {
|
||||
if _, err := s.buf[remote].WriteString("bytecount 30\r\n"); err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
@@ -334,7 +351,7 @@ func (s *OpenVpnMgt) handleConn(conn net.Conn) {
|
||||
}
|
||||
|
||||
// manage all "terminator" lines
|
||||
for _, terminator := range []string{"END", ">CLIENT:ENV,END", "SUCCESS"} {
|
||||
for _, terminator := range []string{"END", ">CLIENT:ENV,END", "SUCCESS", "ERROR"} {
|
||||
if strings.HasPrefix(line, terminator) {
|
||||
s.ret <- response
|
||||
response = nil
|
||||
@@ -359,6 +376,7 @@ func (s *OpenVpnMgt) handleConn(conn net.Conn) {
|
||||
// new bloc for a connect event.
|
||||
// We start the receiving handler, which will wait for the Channel message
|
||||
case strings.HasPrefix(line, ">CLIENT:ADDRESS"):
|
||||
case strings.HasPrefix(line, ">CLIENT:ESTABLISHED"):
|
||||
go s.ClientValidated(line, remote)
|
||||
|
||||
case strings.HasPrefix(line, ">CLIENT:CONNECT"):
|
||||
|
||||
Reference in New Issue
Block a user