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

+ 6
- 4
irc/rest_api.go View File

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

Loading…
Cancel
Save