2017-02-16 02:06:26 +00:00
|
|
|
package admin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"git.daplie.com/Daplie/go-rvpn-server/rvpn/connection"
|
|
|
|
)
|
|
|
|
|
|
|
|
//ServerAPI -- Structure to support the server API
|
|
|
|
type ServerAPI struct {
|
2017-02-18 21:21:36 +00:00
|
|
|
ServerName string `json:"server_name"`
|
|
|
|
Domains []*DomainAPI `json:"domains"`
|
|
|
|
Duration float64 `json:"duration"`
|
|
|
|
BytesIn int64 `json:"bytes_in"`
|
|
|
|
BytesOut int64 `json:"bytes_out"`
|
2017-02-16 02:06:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//NewServerAPI - Constructor
|
|
|
|
func NewServerAPI(c *connection.Connection) (s *ServerAPI) {
|
|
|
|
s = new(ServerAPI)
|
|
|
|
s.ServerName = fmt.Sprintf("%p", c)
|
|
|
|
s.Domains = make([]*DomainAPI, 0)
|
|
|
|
s.Duration = time.Since(c.ConnectTime()).Seconds()
|
|
|
|
s.BytesIn = c.BytesIn()
|
|
|
|
s.BytesOut = c.BytesOut()
|
|
|
|
|
|
|
|
for d := range c.DomainTrack {
|
|
|
|
dt := c.DomainTrack[d]
|
|
|
|
domainAPI := NewDomainAPI(dt.DomainName, dt.BytesIn(), dt.BytesOut())
|
|
|
|
s.Domains = append(s.Domains, domainAPI)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
//ServerAPIContainer -- Holder for all the Servers
|
|
|
|
type ServerAPIContainer struct {
|
2017-02-18 21:21:36 +00:00
|
|
|
Servers []*ServerAPI `json:"servers"`
|
2017-02-16 02:06:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//NewServerAPIContainer -- Constructor
|
|
|
|
func NewServerAPIContainer() (p *ServerAPIContainer) {
|
|
|
|
p = new(ServerAPIContainer)
|
|
|
|
p.Servers = make([]*ServerAPI, 0)
|
|
|
|
return p
|
|
|
|
}
|