-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
689 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
function ffhbCurrentStats(data) { | ||
$("#freifunk").html(" | ||
<h1><a href="https://bremen.freifunk.net/" style="color: #444;">bremen.freifunk.net</a></h1> | ||
<p> | ||
Nutzer: <span id="freifunk_clients">0</span><br> | ||
<i style="font-style: italic;">(auf <span id="freifunk_nodes">0</span> Geräte verteilt)</i> | ||
</p> | ||
<p style="text-align: right;"> | ||
<a href="https://events.ffhb.de/meshviewer">mehr</a> | ||
</p>"); | ||
|
||
$("#freifunk_clients").html(data.Clients); | ||
$("#freifunk_nodes").html(data.Nodes); | ||
}; | ||
|
||
ffhbCurrentStats({{json .GlobalStatistic}}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package all | ||
|
||
import ( | ||
"github.com/FreifunkBremen/yanic/output" | ||
"github.com/FreifunkBremen/yanic/runtime" | ||
) | ||
|
||
type Output struct { | ||
output.Output | ||
nodes *runtime.Nodes | ||
list []output.Output | ||
} | ||
|
||
func Register(nodes *runtime.Nodes, configuration interface{}) (output.Output, error) { | ||
var list []output.Output | ||
allOutputs := configuration.(map[string][]interface{}) | ||
for outputType, outputRegister := range output.Adapters { | ||
outputConfigs := allOutputs[outputType] | ||
for _, config := range outputConfigs { | ||
output, err := outputRegister(nodes, config) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if output == nil { | ||
continue | ||
} | ||
list = append(list, output) | ||
} | ||
} | ||
return &Output{list: list, nodes: nodes}, nil | ||
} | ||
|
||
func (o *Output) Save() { | ||
for _, item := range o.list { | ||
item.Save() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package all | ||
|
||
import ( | ||
_ "github.com/FreifunkBremen/yanic/output/meshviewer" | ||
_ "github.com/FreifunkBremen/yanic/output/template" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package output | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/FreifunkBremen/yanic/runtime" | ||
) | ||
|
||
var quit chan struct{} | ||
|
||
// Start workers of database | ||
// WARNING: Do not override this function | ||
// you should use New() | ||
func Start(output Output, config *runtime.Config) { | ||
quit = make(chan struct{}) | ||
go saveWorker(output, config.Nodes.SaveInterval.Duration) | ||
} | ||
|
||
func Close() { | ||
if quit != nil { | ||
close(quit) | ||
} | ||
} | ||
|
||
// save periodically to output | ||
func saveWorker(output Output, saveInterval time.Duration) { | ||
ticker := time.NewTicker(saveInterval) | ||
for { | ||
select { | ||
case <-ticker.C: | ||
output.Save() | ||
case <-quit: | ||
ticker.Stop() | ||
return | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
package meshviewer | ||
|
||
import ( | ||
"github.com/FreifunkBremen/yanic/data" | ||
"github.com/FreifunkBremen/yanic/runtime" | ||
) | ||
|
||
type filter func(node *runtime.Node) *runtime.Node | ||
|
||
// Config Filter | ||
type filterConfig map[string]interface{} | ||
|
||
func (f filterConfig) Blacklist() *map[string]interface{} { | ||
if v, ok := f["blacklist"]; ok { | ||
list := make(map[string]interface{}) | ||
for _, nodeid := range v.([]interface{}) { | ||
list[nodeid.(string)] = true | ||
} | ||
return &list | ||
} | ||
return nil | ||
} | ||
|
||
func (f filterConfig) NoOwner() bool { | ||
if v, ok := f["no_owner"]; ok { | ||
return v.(bool) | ||
} | ||
return true | ||
} | ||
func (f filterConfig) HasLocation() *bool { | ||
if v, ok := f["has_location"].(bool); ok { | ||
return &v | ||
} | ||
return nil | ||
} | ||
|
||
type area struct { | ||
xA float64 | ||
xB float64 | ||
yA float64 | ||
yB float64 | ||
} | ||
|
||
func (f filterConfig) InArea() *area { | ||
if areaConfigInt, ok := f["in_area"]; ok { | ||
areaConfig := areaConfigInt.(map[string]interface{}) | ||
a := area{} | ||
if v, ok := areaConfig["latitude_min"]; ok { | ||
a.xA = v.(float64) | ||
} | ||
if v, ok := areaConfig["latitude_max"]; ok { | ||
a.xB = v.(float64) | ||
} | ||
if v, ok := areaConfig["longitude_min"]; ok { | ||
a.yA = v.(float64) | ||
} | ||
if v, ok := areaConfig["longitude_max"]; ok { | ||
a.yB = v.(float64) | ||
} | ||
return &a | ||
} | ||
return nil | ||
} | ||
|
||
// Create Filter | ||
func createFilter(config filterConfig) filter { | ||
return func(n *runtime.Node) *runtime.Node { | ||
//maybe cloning of this object is better? | ||
node := n | ||
|
||
if config.NoOwner() { | ||
node = filterNoOwner(node) | ||
} | ||
if ok := config.HasLocation(); ok != nil { | ||
node = filterHasLocation(node, *ok) | ||
} | ||
if area := config.InArea(); area != nil { | ||
node = filterLocationInArea(node, *area) | ||
} | ||
if list := config.Blacklist(); list != nil { | ||
node = filterBlacklist(node, *list) | ||
} | ||
|
||
return node | ||
} | ||
} | ||
|
||
func filterBlacklist(node *runtime.Node, list map[string]interface{}) *runtime.Node { | ||
if node != nil { | ||
if nodeinfo := node.Nodeinfo; nodeinfo != nil { | ||
if _, ok := list[nodeinfo.NodeID]; !ok { | ||
return node | ||
} | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func filterNoOwner(node *runtime.Node) *runtime.Node { | ||
if node == nil { | ||
return nil | ||
} | ||
return &runtime.Node{ | ||
Address: node.Address, | ||
Firstseen: node.Firstseen, | ||
Lastseen: node.Lastseen, | ||
Online: node.Online, | ||
Statistics: node.Statistics, | ||
Nodeinfo: &data.NodeInfo{ | ||
NodeID: node.Nodeinfo.NodeID, | ||
Network: node.Nodeinfo.Network, | ||
System: node.Nodeinfo.System, | ||
Owner: nil, | ||
Hostname: node.Nodeinfo.Hostname, | ||
Location: node.Nodeinfo.Location, | ||
Software: node.Nodeinfo.Software, | ||
Hardware: node.Nodeinfo.Hardware, | ||
VPN: node.Nodeinfo.VPN, | ||
Wireless: node.Nodeinfo.Wireless, | ||
}, | ||
Neighbours: node.Neighbours, | ||
} | ||
} | ||
|
||
func filterHasLocation(node *runtime.Node, withLocation bool) *runtime.Node { | ||
if node != nil { | ||
if nodeinfo := node.Nodeinfo; nodeinfo != nil { | ||
if withLocation { | ||
if location := nodeinfo.Location; location != nil { | ||
return node | ||
} | ||
} else { | ||
if location := nodeinfo.Location; location == nil { | ||
return node | ||
} | ||
} | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func filterLocationInArea(node *runtime.Node, a area) *runtime.Node { | ||
if node != nil { | ||
if nodeinfo := node.Nodeinfo; nodeinfo != nil { | ||
if location := nodeinfo.Location; location != nil { | ||
if location.Latitude >= a.xA && location.Latitude <= a.xB { | ||
if location.Longtitude >= a.yA && location.Longtitude <= a.yB { | ||
return node | ||
} | ||
} | ||
} else { | ||
return node | ||
} | ||
} | ||
} | ||
return nil | ||
} |
File renamed without changes.
Oops, something went wrong.