|
@@ -14,8 +14,9 @@ import (
|
|
|
)
|
|
|
|
|
|
type ScanRequest struct {
|
|
|
- IpAddress string `json:"ip_address"`
|
|
|
- FqdnPattern string `json:"fqdn_pattern"`
|
|
|
+ IpAddress string `json:"ip_address"`
|
|
|
+ NetworkAddress string `json:"network_address"`
|
|
|
+ FqdnPattern string `json:"fqdn_pattern"`
|
|
|
}
|
|
|
|
|
|
// Holding all static web server resources
|
|
@@ -38,7 +39,7 @@ func RunHttpServer(port int, dbhook TopologyDatabaseIO, portmap []int, logStream
|
|
|
if err != nil {
|
|
|
log.Fatal(err)
|
|
|
}
|
|
|
- htmlHndl := &HtmlHandler{Home: tmpl, TableEntry: iptable, DbHook: dbhook}
|
|
|
+ htmlHndl := &HtmlHandler{Home: tmpl, TableEntry: iptable, DbHook: dbhook, stream: logStream}
|
|
|
execHndl := &ExecutionHandler{DbHook: dbhook, PortMap: portmap, TableEntry: iptable, stream: logStream}
|
|
|
http.Handle("/static/", assets)
|
|
|
http.Handle("/home", htmlHndl)
|
|
@@ -58,7 +59,7 @@ type ExecutionHandler struct {
|
|
|
}
|
|
|
|
|
|
func (e *ExecutionHandler) Log(vals ...string) {
|
|
|
- e.stream.Write([]byte("KYOKETSU-WEB LOG ||| " + strings.Join(vals, " ||| ")))
|
|
|
+ e.stream.Write([]byte("KYOKETSU-WEB LOG ||| " + strings.Join(vals, " ||| ") + "\n"))
|
|
|
|
|
|
}
|
|
|
|
|
@@ -69,11 +70,13 @@ Top level function to be routed to, this will spawn a suite of goroutines that w
|
|
|
:param r: a pointer to the request coming in from the client
|
|
|
*/
|
|
|
func (e *ExecutionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
|
+ e.Log("Recieved: " + r.Method + " on path: " + r.RequestURI)
|
|
|
input, err := e.parseRequest(r)
|
|
|
if err != nil {
|
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
return
|
|
|
}
|
|
|
+ e.Log(fmt.Sprintf("Parsed request struct: %+v", input))
|
|
|
|
|
|
subnetMap, err := GetNetworkAddresses(input.IpAddress)
|
|
|
if err != nil {
|
|
@@ -81,17 +84,19 @@ func (e *ExecutionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- scanned := make(chan Host)
|
|
|
+ scanned := make(chan Host, 1000)
|
|
|
var wg sync.WaitGroup
|
|
|
var mu sync.Mutex
|
|
|
var errorRaised bool
|
|
|
|
|
|
wg.Add(1)
|
|
|
+
|
|
|
go e.processScannedData(w, e.TableEntry, scanned, &wg, &mu, &errorRaised)
|
|
|
|
|
|
NetSweep(subnetMap.Ipv4s, subnetMap.Mask, RetrieveScanDirectives(), scanned)
|
|
|
- close(scanned)
|
|
|
+ e.Log("Waiting for execution group to return finish.")
|
|
|
wg.Wait()
|
|
|
+ e.Log("Execution group finished scanning.")
|
|
|
|
|
|
if errorRaised {
|
|
|
http.Error(w, "Error during scan processing. Check logs for details.", http.StatusInternalServerError)
|
|
@@ -170,17 +175,22 @@ type HtmlHandler struct {
|
|
|
Home *template.Template // pointer to the HTML homepage
|
|
|
TableEntry *template.Template // pointer to the table entry html template
|
|
|
DbHook TopologyDatabaseIO
|
|
|
+ stream io.Writer
|
|
|
}
|
|
|
|
|
|
-func (h *HtmlHandler) handleHome(w http.ResponseWriter, r *http.Request) {
|
|
|
- if r.RequestURI == "/home" {
|
|
|
- data, err := h.DbHook.All()
|
|
|
- if err != nil {
|
|
|
- http.Error(w, "There was an error reading from the database: "+err.Error(), http.StatusInternalServerError)
|
|
|
- }
|
|
|
- h.Home.Execute(w, data)
|
|
|
- return
|
|
|
+func (h *HtmlHandler) Log(vals ...string) {
|
|
|
+ h.stream.Write([]byte("KYOKETSU-WEB LOG ||| " + strings.Join(vals, " ||| ") + "\n"))
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+func (h *HtmlHandler) handleHome(w http.ResponseWriter) {
|
|
|
+ data, err := h.DbHook.All()
|
|
|
+ if err != nil {
|
|
|
+ h.Log("Error reading from database: " + err.Error())
|
|
|
+ http.Error(w, "There was an error reading from the database: "+err.Error(), http.StatusInternalServerError)
|
|
|
}
|
|
|
+ h.Home.Execute(w, data)
|
|
|
+ return
|
|
|
|
|
|
}
|
|
|
|
|
@@ -197,7 +207,7 @@ func (h *HtmlHandler) subnetQueryHandler(w http.ResponseWriter, r *http.Request)
|
|
|
http.Error(w, "There was an error reading the request: "+err.Error(), http.StatusBadRequest)
|
|
|
return
|
|
|
}
|
|
|
- data, err := h.DbHook.GetByNetwork(req.IpAddress)
|
|
|
+ data, err := h.DbHook.GetByNetwork(req.NetworkAddress)
|
|
|
if err != nil {
|
|
|
http.Error(w, "There was an error reading the request: "+err.Error(), http.StatusBadRequest)
|
|
|
return
|
|
@@ -222,7 +232,15 @@ func (h *HtmlHandler) fqdnQueryHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
return
|
|
|
}
|
|
|
dnsList := strings.Split(req.FqdnPattern, ",")
|
|
|
- data, err := h.DbHook.FilterDnsPattern(dnsList)
|
|
|
+ var ntwrk string
|
|
|
+ if req.NetworkAddress == "" {
|
|
|
+ ntwrk = "%"
|
|
|
+ } else {
|
|
|
+ ntwrk = req.NetworkAddress
|
|
|
+ }
|
|
|
+ h.Log("Query Arguments: " + ntwrk + " " + req.FqdnPattern)
|
|
|
+
|
|
|
+ data, err := h.DbHook.FilterDnsPattern(ntwrk, dnsList)
|
|
|
if err != nil {
|
|
|
http.Error(w, "There was an error reading the request: "+err.Error(), http.StatusBadRequest)
|
|
|
return
|
|
@@ -240,9 +258,10 @@ Handler function for HTML serving
|
|
|
:param r: pointer to the http.Request coming in
|
|
|
*/
|
|
|
func (h *HtmlHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
|
+ h.Log("Recieved " + r.Method + " on path: " + r.RequestURI)
|
|
|
switch r.RequestURI {
|
|
|
case "/home":
|
|
|
- h.handleHome(w, r)
|
|
|
+ h.handleHome(w)
|
|
|
case "/subnets":
|
|
|
h.subnetQueryHandler(w, r)
|
|
|
case "/excludefqdn":
|