3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-10 22:19:31 +01:00

rest: Expose DLINEs and KLINEs as xlines

This commit is contained in:
Daniel Oaks 2017-03-07 19:55:14 +10:00
parent 1b92f9e93f
commit 8834de5b32
2 changed files with 10 additions and 8 deletions

View File

@ -28,9 +28,9 @@ var (
// IPRestrictTime contains the expiration info about the given IP.
type IPRestrictTime struct {
// Duration is how long this block lasts for.
Duration time.Duration
Duration time.Duration `json:"duration"`
// Expires is when this block expires.
Expires time.Time
Expires time.Time `json:"expires"`
}
// IsExpired returns true if the time has expired.
@ -41,11 +41,11 @@ func (iptime *IPRestrictTime) IsExpired() bool {
// IPBanInfo holds info about an IP/net ban.
type IPBanInfo struct {
// Reason is the ban reason.
Reason string
Reason string `json:"reason"`
// OperReason is an oper ban reason.
OperReason string `json:"oper_reason"`
// Time holds details about the duration, if it exists.
Time *IPRestrictTime
Time *IPRestrictTime `json:"time"`
}
// dLineAddr contains the address itself and expiration time for a given network.

View File

@ -36,8 +36,9 @@ type restStatusResp struct {
Channels int `json:"channels"`
}
type restDLinesResp struct {
type restXLinesResp struct {
DLines map[string]IPBanInfo `json:"dlines"`
KLines map[string]IPBanInfo `json:"klines"`
}
type restAcct struct {
@ -84,9 +85,10 @@ func restStatus(w http.ResponseWriter, r *http.Request) {
}
}
func restGetDLines(w http.ResponseWriter, r *http.Request) {
rs := restDLinesResp{
func restGetXLines(w http.ResponseWriter, r *http.Request) {
rs := restXLinesResp{
DLines: restAPIServer.dlines.AllBans(),
KLines: restAPIServer.klines.AllBans(),
}
b, err := json.Marshal(rs)
if err != nil {
@ -175,7 +177,7 @@ func (s *Server) startRestAPI() {
rg := r.Methods("GET").Subrouter()
rg.HandleFunc("/info", restInfo)
rg.HandleFunc("/status", restStatus)
rg.HandleFunc("/dlines", restGetDLines)
rg.HandleFunc("/xlines", restGetXLines)
rg.HandleFunc("/accounts", restGetAccounts)
// PUT methods