mirror of
https://github.com/Sean-Der/fail2rest.git
synced 2024-12-22 05:32:20 +01:00
Implement endpoint for running WHOIS queries
This commit is contained in:
parent
c59cb07298
commit
05ec165128
2 changed files with 24 additions and 0 deletions
|
@ -41,6 +41,9 @@ func main() {
|
|||
|
||||
globalHandler(r.PathPrefix("/global").Subrouter(), fail2goConn)
|
||||
jailHandler(r.PathPrefix("/jail").Subrouter(), fail2goConn)
|
||||
r.HandleFunc("/whois/{object}", func(res http.ResponseWriter, req *http.Request) {
|
||||
whoisHandler(res, req, fail2goConn)
|
||||
}).Methods("GET")
|
||||
|
||||
http.Handle("/", r)
|
||||
fmt.Println(http.ListenAndServe(configuration.Addr, nil))
|
||||
|
|
21
whois.go
Normal file
21
whois.go
Normal file
|
@ -0,0 +1,21 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/Sean-Der/fail2go"
|
||||
"github.com/Sean-Der/goWHOIS"
|
||||
"github.com/gorilla/mux"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func whoisHandler(res http.ResponseWriter, req *http.Request, fail2goConn *fail2go.Conn) {
|
||||
goWHOISReq := goWHOIS.NewReq(mux.Vars(req)["object"])
|
||||
WHOIS, err := goWHOISReq.Raw()
|
||||
if err != nil {
|
||||
writeHTTPError(res, err)
|
||||
return
|
||||
}
|
||||
|
||||
encodedOutput, _ := json.Marshal(map[string]string{"WHOIS": WHOIS})
|
||||
res.Write(encodedOutput)
|
||||
}
|
Loading…
Reference in a new issue