mirror of
https://github.com/bettercap/bettercap
synced 2025-07-14 00:53:46 -07:00
misc: small fix or general refactoring i did not bother commenting
This commit is contained in:
parent
c47e3f6195
commit
c9ae0f360e
3 changed files with 18 additions and 9 deletions
|
@ -55,13 +55,13 @@ func (mod *Module) createDot11ApGraph(ap *network.AccessPoint) (*Node, bool, err
|
|||
return node, isNew, nil
|
||||
}
|
||||
|
||||
func (mod *Module) createDot11SSIDGraph(hw string, ssid string) (*Node, bool, error) {
|
||||
node, err := mod.db.FindNode(SSID, hw)
|
||||
func (mod *Module) createDot11SSIDGraph(hex string, ssid string) (*Node, bool, error) {
|
||||
node, err := mod.db.FindNode(SSID, hex)
|
||||
isNew := node == nil
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
} else if isNew {
|
||||
if node, err = mod.db.CreateNode(SSID, hw, ssid, ""); err != nil {
|
||||
if node, err = mod.db.CreateNode(SSID, hex, ssid, ""); err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
} else if err = mod.db.UpdateNode(node); err != nil {
|
||||
|
@ -117,7 +117,7 @@ func (mod *Module) createDot11Graph(ap *network.AccessPoint, station *network.St
|
|||
}
|
||||
|
||||
func (mod *Module) createDot11ProbeGraph(ssid string, station *network.Station) (*Node, bool, *Node, bool, error) {
|
||||
apNode, apIsNew, err := mod.createDot11SSIDGraph(station.HwAddress+fmt.Sprintf(":PROBE:%x", ssid), ssid)
|
||||
ssidNode, ssidIsNew, err := mod.createDot11SSIDGraph(fmt.Sprintf("%x", ssid), ssid)
|
||||
if err != nil {
|
||||
return nil, false, nil, false, err
|
||||
}
|
||||
|
@ -128,15 +128,23 @@ func (mod *Module) createDot11ProbeGraph(ssid string, station *network.Station)
|
|||
}
|
||||
|
||||
// create relations if needed
|
||||
if probes_for, err := mod.db.FindLastRecentEdgeOfType(staNode, apNode, ProbesFor, edgeStaleTime); err != nil {
|
||||
if probes_for, err := mod.db.FindLastRecentEdgeOfType(staNode, ssidNode, ProbesFor, edgeStaleTime); err != nil {
|
||||
return nil, false, nil, false, err
|
||||
} else if probes_for == nil {
|
||||
if probes_for, err = mod.db.CreateEdge(staNode, apNode, ProbesFor); err != nil {
|
||||
if probes_for, err = mod.db.CreateEdge(staNode, ssidNode, ProbesFor); err != nil {
|
||||
return nil, false, nil, false, err
|
||||
}
|
||||
}
|
||||
|
||||
return apNode, apIsNew, staNode, staIsNew, nil
|
||||
if probed_by, err := mod.db.FindLastRecentEdgeOfType(ssidNode, staNode, ProbedBy, edgeStaleTime); err != nil {
|
||||
return nil, false, nil, false, err
|
||||
} else if probed_by == nil {
|
||||
if probed_by, err = mod.db.CreateEdge(ssidNode, staNode, ProbedBy); err != nil {
|
||||
return nil, false, nil, false, err
|
||||
}
|
||||
}
|
||||
|
||||
return ssidNode, ssidIsNew, staNode, staIsNew, nil
|
||||
}
|
||||
|
||||
func (mod *Module) createBLEServerGraph(dev *network.BLEDevice) (*Node, bool, error) {
|
||||
|
|
|
@ -11,6 +11,7 @@ type EdgeType string
|
|||
const (
|
||||
Is EdgeType = "is"
|
||||
ProbesFor EdgeType = "probes_for"
|
||||
ProbedBy EdgeType = "probed_by"
|
||||
ConnectsTo EdgeType = "connects_to"
|
||||
Manages EdgeType = "manages"
|
||||
)
|
||||
|
|
|
@ -170,7 +170,7 @@ func (g *Graph) Dot(filter, layout, name string, disconnected bool) (string, int
|
|||
|
||||
if err := g.Traverse(filter, func(node *Node) {
|
||||
include := false
|
||||
if disconnected || node.Type == SSID { // we don't create backwards edges for SSID
|
||||
if disconnected {
|
||||
include = true
|
||||
} else {
|
||||
include = g.edges.IsConnected(node.String())
|
||||
|
@ -265,7 +265,7 @@ func (g *Graph) JSON(filter string, disconnected bool) (string, int, int, error)
|
|||
|
||||
if err := g.Traverse(filter, func(node *Node) {
|
||||
include := false
|
||||
if disconnected || node.Type == SSID { // we don't create backwards edges for SSID
|
||||
if disconnected {
|
||||
include = true
|
||||
} else {
|
||||
include = g.edges.IsConnected(node.String())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue