Browse Source

rest: Expose DLINEs and KLINEs as xlines

tags/v0.7.0
Daniel Oaks 7 years ago
parent
commit
8834de5b32
2 changed files with 10 additions and 8 deletions
  1. 4
    4
      irc/dline.go
  2. 6
    4
      irc/rest_api.go

+ 4
- 4
irc/dline.go View File

28
 // IPRestrictTime contains the expiration info about the given IP.
28
 // IPRestrictTime contains the expiration info about the given IP.
29
 type IPRestrictTime struct {
29
 type IPRestrictTime struct {
30
 	// Duration is how long this block lasts for.
30
 	// Duration is how long this block lasts for.
31
-	Duration time.Duration
31
+	Duration time.Duration `json:"duration"`
32
 	// Expires is when this block expires.
32
 	// Expires is when this block expires.
33
-	Expires time.Time
33
+	Expires time.Time `json:"expires"`
34
 }
34
 }
35
 
35
 
36
 // IsExpired returns true if the time has expired.
36
 // IsExpired returns true if the time has expired.
41
 // IPBanInfo holds info about an IP/net ban.
41
 // IPBanInfo holds info about an IP/net ban.
42
 type IPBanInfo struct {
42
 type IPBanInfo struct {
43
 	// Reason is the ban reason.
43
 	// Reason is the ban reason.
44
-	Reason string
44
+	Reason string `json:"reason"`
45
 	// OperReason is an oper ban reason.
45
 	// OperReason is an oper ban reason.
46
 	OperReason string `json:"oper_reason"`
46
 	OperReason string `json:"oper_reason"`
47
 	// Time holds details about the duration, if it exists.
47
 	// Time holds details about the duration, if it exists.
48
-	Time *IPRestrictTime
48
+	Time *IPRestrictTime `json:"time"`
49
 }
49
 }
50
 
50
 
51
 // dLineAddr contains the address itself and expiration time for a given network.
51
 // dLineAddr contains the address itself and expiration time for a given network.

+ 6
- 4
irc/rest_api.go View File

36
 	Channels int `json:"channels"`
36
 	Channels int `json:"channels"`
37
 }
37
 }
38
 
38
 
39
-type restDLinesResp struct {
39
+type restXLinesResp struct {
40
 	DLines map[string]IPBanInfo `json:"dlines"`
40
 	DLines map[string]IPBanInfo `json:"dlines"`
41
+	KLines map[string]IPBanInfo `json:"klines"`
41
 }
42
 }
42
 
43
 
43
 type restAcct struct {
44
 type restAcct struct {
84
 	}
85
 	}
85
 }
86
 }
86
 
87
 
87
-func restGetDLines(w http.ResponseWriter, r *http.Request) {
88
-	rs := restDLinesResp{
88
+func restGetXLines(w http.ResponseWriter, r *http.Request) {
89
+	rs := restXLinesResp{
89
 		DLines: restAPIServer.dlines.AllBans(),
90
 		DLines: restAPIServer.dlines.AllBans(),
91
+		KLines: restAPIServer.klines.AllBans(),
90
 	}
92
 	}
91
 	b, err := json.Marshal(rs)
93
 	b, err := json.Marshal(rs)
92
 	if err != nil {
94
 	if err != nil {
175
 	rg := r.Methods("GET").Subrouter()
177
 	rg := r.Methods("GET").Subrouter()
176
 	rg.HandleFunc("/info", restInfo)
178
 	rg.HandleFunc("/info", restInfo)
177
 	rg.HandleFunc("/status", restStatus)
179
 	rg.HandleFunc("/status", restStatus)
178
-	rg.HandleFunc("/dlines", restGetDLines)
180
+	rg.HandleFunc("/xlines", restGetXLines)
179
 	rg.HandleFunc("/accounts", restGetAccounts)
181
 	rg.HandleFunc("/accounts", restGetAccounts)
180
 
182
 
181
 	// PUT methods
183
 	// PUT methods

Loading…
Cancel
Save