add stats + map

This commit is contained in:
Martin Geno 2017-05-15 21:59:48 +02:00
parent 2a5ab5c1f5
commit 7a4a6c66e9
No known key found for this signature in database
GPG Key ID: F0D39A37E925E941
20 changed files with 1152 additions and 120 deletions

View File

@ -8,6 +8,7 @@ import (
"syscall"
"time"
runtimeYanic "github.com/FreifunkBremen/yanic/runtime"
"github.com/NYTimes/gziphandler"
configPackage "github.com/FreifunkBremen/freifunkmanager/config"
@ -25,6 +26,7 @@ var (
config *configPackage.Config
nodes *runtime.Nodes
yanicDialer *yanic.Dialer
stats *runtimeYanic.GlobalStats
)
func main() {
@ -43,19 +45,27 @@ func main() {
go nodesUpdateWorker.Start()
go nodesSaveWorker.Start()
websocket.Start(nodes)
if config.Yanic.Enable {
yanicDialer := yanic.Dial(config.Yanic.Type, config.Yanic.Address)
yanicDialer.NodeHandler = nodes.AddNode
yanicDialer.GlobalsHandler = func(data *runtimeYanic.GlobalStats) {
stats = data
websocket.NotifyStats(data)
}
yanicDialer.Start()
}
websocket.Start(nodes)
// Startwebserver
http.HandleFunc("/nodes", func(w http.ResponseWriter, r *http.Request) {
httpLib.Write(w, nodes)
log.HTTP(r).Info("done")
})
http.HandleFunc("/stats", func(w http.ResponseWriter, r *http.Request) {
httpLib.Write(w, stats)
log.HTTP(r).Info("done")
})
http.Handle("/", gziphandler.GzipHandler(http.FileServer(http.Dir(config.Webroot))))
srv := &http.Server{

View File

@ -7,6 +7,6 @@ ssh_key = "/etc/id_rsa"
ssh_interface = "wlp4s0"
[yanic]
enable = false
enable = true
type = "unix"
address = "/tmp/yanic-database.socket"

View File

@ -14,8 +14,8 @@ import (
const (
SSHUpdateHostname = "uci set system.@system[0].hostname='%s';uci commit system;echo $(uci get system.@system[0].hostname) > /proc/sys/kernel/hostname"
SSHUpdateOwner = "uci set gluon-node-info.@owner[0].contact='%s';uci commit gluon-node-info;"
SSHUpdateLocation = "uci set gluon-node-info.@location[0].latitude='%d';uci set gluon-node-info.@location[0].longitude='%d';uci set gluon-node-info.@location[0].share_location=1;uci commit gluon-node-info;"
SSHUpdateWifiFreq = "uci set gluon-node-info.@location[0].latitude='%d';uci set gluon-node-info.@location[0].longitude='%d';uci set gluon-node-info.@location[0].share_location=1;uci commit gluon-node-info;wifi"
SSHUpdateLocation = "uci set gluon-node-info.@location[0].latitude='%f';uci set gluon-node-info.@location[0].longitude='%f';uci set gluon-node-info.@location[0].share_location=1;uci commit gluon-node-info;"
SSHUpdateWifiFreq = "wifi"
)
type Node struct {

624
webroot/css/leaflet.css Normal file
View File

@ -0,0 +1,624 @@
/* required styles */
.leaflet-pane,
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile-container,
.leaflet-pane > svg,
.leaflet-pane > canvas,
.leaflet-zoom-box,
.leaflet-image-layer,
.leaflet-layer {
position: absolute;
left: 0;
top: 0;
}
.leaflet-container {
overflow: hidden;
}
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow {
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
-webkit-user-drag: none;
}
/* Safari renders non-retina tile on retina better with this, but Chrome is worse */
.leaflet-safari .leaflet-tile {
image-rendering: -webkit-optimize-contrast;
}
/* hack that prevents hw layers "stretching" when loading new tiles */
.leaflet-safari .leaflet-tile-container {
width: 1600px;
height: 1600px;
-webkit-transform-origin: 0 0;
}
.leaflet-marker-icon,
.leaflet-marker-shadow {
display: block;
}
/* .leaflet-container svg: reset svg max-width decleration shipped in Joomla! (joomla.org) 3.x */
/* .leaflet-container img: map is broken in FF if you have max-width: 100% on tiles */
.leaflet-container .leaflet-overlay-pane svg,
.leaflet-container .leaflet-marker-pane img,
.leaflet-container .leaflet-shadow-pane img,
.leaflet-container .leaflet-tile-pane img,
.leaflet-container img.leaflet-image-layer {
max-width: none !important;
}
.leaflet-container.leaflet-touch-zoom {
-ms-touch-action: pan-x pan-y;
touch-action: pan-x pan-y;
}
.leaflet-container.leaflet-touch-drag {
-ms-touch-action: pinch-zoom;
}
.leaflet-container.leaflet-touch-drag.leaflet-touch-zoom {
-ms-touch-action: none;
touch-action: none;
}
.leaflet-tile {
filter: inherit;
visibility: hidden;
}
.leaflet-tile-loaded {
visibility: inherit;
}
.leaflet-zoom-box {
width: 0;
height: 0;
-moz-box-sizing: border-box;
box-sizing: border-box;
z-index: 800;
}
/* workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=888319 */
.leaflet-overlay-pane svg {
-moz-user-select: none;
}
.leaflet-pane { z-index: 400; }
.leaflet-tile-pane { z-index: 200; }
.leaflet-overlay-pane { z-index: 400; }
.leaflet-shadow-pane { z-index: 500; }
.leaflet-marker-pane { z-index: 600; }
.leaflet-tooltip-pane { z-index: 650; }
.leaflet-popup-pane { z-index: 700; }
.leaflet-map-pane canvas { z-index: 100; }
.leaflet-map-pane svg { z-index: 200; }
.leaflet-vml-shape {
width: 1px;
height: 1px;
}
.lvml {
behavior: url(#default#VML);
display: inline-block;
position: absolute;
}
/* control positioning */
.leaflet-control {
position: relative;
z-index: 800;
pointer-events: visiblePainted; /* IE 9-10 doesn't have auto */
pointer-events: auto;
}
.leaflet-top,
.leaflet-bottom {
position: absolute;
z-index: 1000;
pointer-events: none;
}
.leaflet-top {
top: 0;
}
.leaflet-right {
right: 0;
}
.leaflet-bottom {
bottom: 0;
}
.leaflet-left {
left: 0;
}
.leaflet-control {
float: left;
clear: both;
}
.leaflet-right .leaflet-control {
float: right;
}
.leaflet-top .leaflet-control {
margin-top: 10px;
}
.leaflet-bottom .leaflet-control {
margin-bottom: 10px;
}
.leaflet-left .leaflet-control {
margin-left: 10px;
}
.leaflet-right .leaflet-control {
margin-right: 10px;
}
/* zoom and fade animations */
.leaflet-fade-anim .leaflet-tile {
will-change: opacity;
}
.leaflet-fade-anim .leaflet-popup {
opacity: 0;
-webkit-transition: opacity 0.2s linear;
-moz-transition: opacity 0.2s linear;
-o-transition: opacity 0.2s linear;
transition: opacity 0.2s linear;
}
.leaflet-fade-anim .leaflet-map-pane .leaflet-popup {
opacity: 1;
}
.leaflet-zoom-animated {
-webkit-transform-origin: 0 0;
-ms-transform-origin: 0 0;
transform-origin: 0 0;
}
.leaflet-zoom-anim .leaflet-zoom-animated {
will-change: transform;
}
.leaflet-zoom-anim .leaflet-zoom-animated {
-webkit-transition: -webkit-transform 0.25s cubic-bezier(0,0,0.25,1);
-moz-transition: -moz-transform 0.25s cubic-bezier(0,0,0.25,1);
-o-transition: -o-transform 0.25s cubic-bezier(0,0,0.25,1);
transition: transform 0.25s cubic-bezier(0,0,0.25,1);
}
.leaflet-zoom-anim .leaflet-tile,
.leaflet-pan-anim .leaflet-tile {
-webkit-transition: none;
-moz-transition: none;
-o-transition: none;
transition: none;
}
.leaflet-zoom-anim .leaflet-zoom-hide {
visibility: hidden;
}
/* cursors */
.leaflet-interactive {
cursor: pointer;
}
.leaflet-grab {
cursor: -webkit-grab;
cursor: -moz-grab;
}
.leaflet-crosshair,
.leaflet-crosshair .leaflet-interactive {
cursor: crosshair;
}
.leaflet-popup-pane,
.leaflet-control {
cursor: auto;
}
.leaflet-dragging .leaflet-grab,
.leaflet-dragging .leaflet-grab .leaflet-interactive,
.leaflet-dragging .leaflet-marker-draggable {
cursor: move;
cursor: -webkit-grabbing;
cursor: -moz-grabbing;
}
/* marker & overlays interactivity */
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-image-layer,
.leaflet-pane > svg path,
.leaflet-tile-container {
pointer-events: none;
}
.leaflet-marker-icon.leaflet-interactive,
.leaflet-image-layer.leaflet-interactive,
.leaflet-pane > svg path.leaflet-interactive {
pointer-events: visiblePainted; /* IE 9-10 doesn't have auto */
pointer-events: auto;
}
/* visual tweaks */
.leaflet-container {
background: #ddd;
outline: 0;
}
.leaflet-container a {
color: #0078A8;
}
.leaflet-container a.leaflet-active {
outline: 2px solid orange;
}
.leaflet-zoom-box {
border: 2px dotted #38f;
background: rgba(255,255,255,0.5);
}
/* general typography */
.leaflet-container {
font: 12px/1.5 "Helvetica Neue", Arial, Helvetica, sans-serif;
}
/* general toolbar styles */
.leaflet-bar {
box-shadow: 0 1px 5px rgba(0,0,0,0.65);
border-radius: 4px;
}
.leaflet-bar a,
.leaflet-bar a:hover {
background-color: #fff;
border-bottom: 1px solid #ccc;
width: 26px;
height: 26px;
line-height: 26px;
display: block;
text-align: center;
text-decoration: none;
color: black;
}
.leaflet-bar a,
.leaflet-control-layers-toggle {
background-position: 50% 50%;
background-repeat: no-repeat;
display: block;
}
.leaflet-bar a:hover {
background-color: #f4f4f4;
}
.leaflet-bar a:first-child {
border-top-left-radius: 4px;
border-top-right-radius: 4px;
}
.leaflet-bar a:last-child {
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border-bottom: none;
}
.leaflet-bar a.leaflet-disabled {
cursor: default;
background-color: #f4f4f4;
color: #bbb;
}
.leaflet-touch .leaflet-bar a {
width: 30px;
height: 30px;
line-height: 30px;
}
/* zoom control */
.leaflet-control-zoom-in,
.leaflet-control-zoom-out {
font: bold 18px 'Lucida Console', Monaco, monospace;
text-indent: 1px;
}
.leaflet-control-zoom-out {
font-size: 20px;
}
.leaflet-touch .leaflet-control-zoom-in {
font-size: 22px;
}
.leaflet-touch .leaflet-control-zoom-out {
font-size: 24px;
}
/* layers control */
.leaflet-control-layers {
box-shadow: 0 1px 5px rgba(0,0,0,0.4);
background: #fff;
border-radius: 5px;
}
.leaflet-control-layers-toggle {
background-image: url(images/layers.png);
width: 36px;
height: 36px;
}
.leaflet-retina .leaflet-control-layers-toggle {
background-image: url(images/layers-2x.png);
background-size: 26px 26px;
}
.leaflet-touch .leaflet-control-layers-toggle {
width: 44px;
height: 44px;
}
.leaflet-control-layers .leaflet-control-layers-list,
.leaflet-control-layers-expanded .leaflet-control-layers-toggle {
display: none;
}
.leaflet-control-layers-expanded .leaflet-control-layers-list {
display: block;
position: relative;
}
.leaflet-control-layers-expanded {
padding: 6px 10px 6px 6px;
color: #333;
background: #fff;
}
.leaflet-control-layers-scrollbar {
overflow-y: scroll;
padding-right: 5px;
}
.leaflet-control-layers-selector {
margin-top: 2px;
position: relative;
top: 1px;
}
.leaflet-control-layers label {
display: block;
}
.leaflet-control-layers-separator {
height: 0;
border-top: 1px solid #ddd;
margin: 5px -10px 5px -6px;
}
/* Default icon URLs */
.leaflet-default-icon-path {
background-image: url(images/marker-icon.png);
}
/* attribution and scale controls */
.leaflet-container .leaflet-control-attribution {
background: #fff;
background: rgba(255, 255, 255, 0.7);
margin: 0;
}
.leaflet-control-attribution,
.leaflet-control-scale-line {
padding: 0 5px;
color: #333;
}
.leaflet-control-attribution a {
text-decoration: none;
}
.leaflet-control-attribution a:hover {
text-decoration: underline;
}
.leaflet-container .leaflet-control-attribution,
.leaflet-container .leaflet-control-scale {
font-size: 11px;
}
.leaflet-left .leaflet-control-scale {
margin-left: 5px;
}
.leaflet-bottom .leaflet-control-scale {
margin-bottom: 5px;
}
.leaflet-control-scale-line {
border: 2px solid #777;
border-top: none;
line-height: 1.1;
padding: 2px 5px 1px;
font-size: 11px;
white-space: nowrap;
overflow: hidden;
-moz-box-sizing: border-box;
box-sizing: border-box;
background: #fff;
background: rgba(255, 255, 255, 0.5);
}
.leaflet-control-scale-line:not(:first-child) {
border-top: 2px solid #777;
border-bottom: none;
margin-top: -2px;
}
.leaflet-control-scale-line:not(:first-child):not(:last-child) {
border-bottom: 2px solid #777;
}
.leaflet-touch .leaflet-control-attribution,
.leaflet-touch .leaflet-control-layers,
.leaflet-touch .leaflet-bar {
box-shadow: none;
}
.leaflet-touch .leaflet-control-layers,
.leaflet-touch .leaflet-bar {
border: 2px solid rgba(0,0,0,0.2);
background-clip: padding-box;
}
/* popup */
.leaflet-popup {
position: absolute;
text-align: center;
margin-bottom: 20px;
}
.leaflet-popup-content-wrapper {
padding: 1px;
text-align: left;
border-radius: 12px;
}
.leaflet-popup-content {
margin: 13px 19px;
line-height: 1.4;
}
.leaflet-popup-content p {
margin: 18px 0;
}
.leaflet-popup-tip-container {
width: 40px;
height: 20px;
position: absolute;
left: 50%;
margin-left: -20px;
overflow: hidden;
pointer-events: none;
}
.leaflet-popup-tip {
width: 17px;
height: 17px;
padding: 1px;
margin: -10px auto 0;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
}
.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
background: white;
color: #333;
box-shadow: 0 3px 14px rgba(0,0,0,0.4);
}
.leaflet-container a.leaflet-popup-close-button {
position: absolute;
top: 0;
right: 0;
padding: 4px 4px 0 0;
border: none;
text-align: center;
width: 18px;
height: 14px;
font: 16px/14px Tahoma, Verdana, sans-serif;
color: #c3c3c3;
text-decoration: none;
font-weight: bold;
background: transparent;
}
.leaflet-container a.leaflet-popup-close-button:hover {
color: #999;
}
.leaflet-popup-scrolled {
overflow: auto;
border-bottom: 1px solid #ddd;
border-top: 1px solid #ddd;
}
.leaflet-oldie .leaflet-popup-content-wrapper {
zoom: 1;
}
.leaflet-oldie .leaflet-popup-tip {
width: 24px;
margin: 0 auto;
-ms-filter: "progid:DXImageTransform.Microsoft.Matrix(M11=0.70710678, M12=0.70710678, M21=-0.70710678, M22=0.70710678)";
filter: progid:DXImageTransform.Microsoft.Matrix(M11=0.70710678, M12=0.70710678, M21=-0.70710678, M22=0.70710678);
}
.leaflet-oldie .leaflet-popup-tip-container {
margin-top: -1px;
}
.leaflet-oldie .leaflet-control-zoom,
.leaflet-oldie .leaflet-control-layers,
.leaflet-oldie .leaflet-popup-content-wrapper,
.leaflet-oldie .leaflet-popup-tip {
border: 1px solid #999;
}
/* div icon */
.leaflet-div-icon {
background: #fff;
border: 1px solid #666;
}
/* Tooltip */
/* Base styles for the element that has a tooltip */
.leaflet-tooltip {
position: absolute;
padding: 6px;
background-color: #fff;
border: 1px solid #fff;
border-radius: 3px;
color: #222;
white-space: nowrap;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
pointer-events: none;
box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}
.leaflet-tooltip.leaflet-clickable {
cursor: pointer;
pointer-events: auto;
}
.leaflet-tooltip-top:before,
.leaflet-tooltip-bottom:before,
.leaflet-tooltip-left:before,
.leaflet-tooltip-right:before {
position: absolute;
pointer-events: none;
border: 6px solid transparent;
background: transparent;
content: "";
}
/* Directions */
.leaflet-tooltip-bottom {
margin-top: 6px;
}
.leaflet-tooltip-top {
margin-top: -6px;
}
.leaflet-tooltip-bottom:before,
.leaflet-tooltip-top:before {
left: 50%;
margin-left: -6px;
}
.leaflet-tooltip-top:before {
bottom: 0;
margin-bottom: -12px;
border-top-color: #fff;
}
.leaflet-tooltip-bottom:before {
top: 0;
margin-top: -12px;
margin-left: -6px;
border-bottom-color: #fff;
}
.leaflet-tooltip-left {
margin-left: -6px;
}
.leaflet-tooltip-right {
margin-left: 6px;
}
.leaflet-tooltip-left:before,
.leaflet-tooltip-right:before {
top: 50%;
margin-top: -6px;
}
.leaflet-tooltip-left:before {
right: 0;
margin-right: -12px;
border-left-color: #fff;
}
.leaflet-tooltip-right:before {
left: 0;
margin-left: -12px;
border-right-color: #fff;
}

View File

@ -18,6 +18,9 @@ body {
.status.offline {
background: #dc0067;
}
h1 {
border-bottom: 4px solid #dc0067;
}
header {
background-color: #373636;
max-width: 100%;
@ -119,7 +122,7 @@ table th.sortable.sort-up:after {
table th.sortable:not(.sort-down):not(.sort-up):after {
content: " \25B4\25BE";
}
table.nodes {
table.nodes, table.stats {
width: 100%;
}
@ -142,6 +145,13 @@ table.nodes tbody tr.offline:hover{
background: #dc0067;
}
table tr.line td,table tr.line th {
border-bottom: 1px solid #ffb400;
}
table.stats td {
text-align: center;
}
.btn {
display: inline-block;
padding: .3em .5em;

42
webroot/css/map.css Normal file
View File

@ -0,0 +1,42 @@
.leaflet-container .node {
width: 3px;
height: 3px;
background-color: rgba(0,0,255,0.5);
border: 2px solid white;
border-radius: 10px;
}
.leaflet-container .node.offline {
background-color rgba(255,0,0,0.5)
}
.leaflet-container .node.client24 {
border-left: 3px solid green;
}
.leaflet-container .node.client5 {
border-border: 3px solid green;
}
.leaflet-container .node.client24-warn {
border-left: 3px solid yellow;
}
.leaflet-container .node.client5-warn {
border-border: 3px solid yellow;
}
.leaflet-container .node.client24-crit {
border-left: 3px solid red;
}
.leaflet-container .node.client5-crit {
border-border: 3px solid red;
}
.leaflet-container .nodeicon-label {
font-size: 12px;
font-weight: lighter;
}
.leaflet-container .nodeicon-label table {
width: 100%;
}
.leaflet-container .nodeicon-label td {
border-top: 1px solid #999;
text-align: right;
}
.leaflet-container .nodeicon-label td:first-child {
text-align: left;
}

View File

@ -4,14 +4,20 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<title>FreifunkManager</title>
<link rel="stylesheet" href="/css/leaflet.css">
<link rel="stylesheet" href="/css/main.css">
<link rel="stylesheet" href="/css/map.css">
<script src="/js/moment.js"></script>
<script src="/js/navigo.js"></script>
<script src="/js/leaflet.js"></script>
<script src="/js/config.js"></script>
<script src="/js/domlib.js"></script>
<script src="/js/store.js"></script>
<script src="/js/notify.js"></script>
<script src="/js/gui_list.js"></script>
<script src="/js/gui_map.js"></script>
<script src="/js/gui_node.js"></script>
<script src="/js/gui_stats.js"></script>
<script src="/js/gui.js"></script>
<script src="/js/socket.js"></script>
<script src="/js/app.js"></script>

View File

@ -1,4 +1,47 @@
var config = {
title: 'FreifunkManager - Breminale',
backend: 'ws://'+location.host+'/websocket'
backend: 'ws://'+location.host+'/websocket',
map: {
view: {bound: [53.07093, 8.79464], zoom: 17},
maxZoom: 20,
tileLayer: '//tiles.bremen.freifunk.net/{z}/{x}/{y}.png',
heatMax: {
wifi24: 15,
wifi5: 50
},
icon:{
warn:{wifi24:20,wifi5:20},
crit:{wifi24:30,wifi5:30}
},
geojson: {
pointToLayer: function (feature, latlng){
feature.properties.radius = 10;
return L.circleMarker(latlng, feature.properties);
},
onEachFeature: function(feature, layer) {
if(feature.properties.name.length >0){
layer.bindLabel(feature.properties.name);
}
},
style: function(feature){
if(feature.geometry.type === 'LineString' || feature.geometry.type === 'Polygon'){
return {color: feature.properties.stroke,
opacity:feature.properties['stroke-opacity'],
fillColor: feature.properties.fill,
fillOpacity:feature.properties['fill-opacity'],
stroke: true,
weight: feature.properties['stroke-width'],
lineCap: 'round',
lineJoin: 'round'};
}
return {
color: feature.properties['marker-color'],
fillColor: feature.properties['marker-color'],
fillOpacity: 0.2,
weight: 2,
stroke: true
};
}
}
}
};

View File

@ -2,42 +2,13 @@ var gui = {};
var router = new Navigo(null, true, '#');
(function(){
function clean(){
domlib.removeChildren(document.querySelector('main'));
}
router.on({
'/list': function () {
clean();
guiList.bind(document.querySelector('main'));
guiList.render();
},
'/map':function(){
clean();
domlib.newAt(main,"div").innerHTML = "Map";
},
'/statistics':function(){
clean();
domlib.newAt(document.querySelector('main'),"div").innerHTML = "Stats";
},
'/n/:nodeID': {
as: 'node',
uses: function (params) {
clean();
console.log("node view");
var nodeid = params['nodeID'].toLowerCase();
domlib.newAt(document.querySelector('main'),"div").innerHTML = "Nodeid: "+nodeid;
}
},
});
router.on(function () {
router.navigate('/list');
});
var currentView = {bind:function(){},render:function(){}};
gui.render = function render(){
main = document.querySelector('main');
function render() {
var status = document.getElementsByClassName('status')[0];
if (status === undefined){
console.log("unable to render");
console.log("unable to render, render later");
setTimeout(render,100);
return;
}
status.classList.remove('connecting','offline');
@ -47,9 +18,55 @@ var router = new Navigo(null, true, '#');
notify.bind(document.getElementsByClassName('notifications')[0]);
guiList.render();
currentView.render();
router.resolve();
};
}
function setView(c){
currentView = c;
var main = document.querySelector('main')
domlib.removeChildren(main);
currentView.bind(main);
currentView.render();
}
router.on({
'/list': function () {
setView(guiList);
},
'/map':function(){
setView(guiMap);
},
'/statistics':function(){
setView(guiStats);
},
'/n/:nodeID': {
as: 'node',
uses: function (params) {
guiNode.current_node_id = params['nodeID'].toLowerCase();
setView(guiNode);
}
},
});
router.on(function () {
router.navigate('/list');
});
gui.render = function () {
var timeout;
function reset () {
timeout = null;
}
if (timeout){
console("skip rendering, because to often");
clearTimeout(timeout);
} else {
render();
}
timeout = setTimeout(reset, 100);
}
gui.render();
})();

View File

@ -1,12 +1,14 @@
var guiList = {};
(function(){
var container;
var view = guiList;
var container, el;
var tbody;
var sortReverse = false;
var sortIndex;
var hostnameFilter,nodeidFilter;
var hostnameFilter, nodeidFilter;
function sort(a,b){
function sortNumber(a,b){
@ -48,50 +50,50 @@ var guiList = {};
}
}
function renderRow(data){
function renderRow(node){
var tr = document.createElement('tr');
var startdate = new Date();
startdate.setMinutes(startdate.getMinutes() - 1);
if(new Date(data.lastseen) < startdate)
if(new Date(node.lastseen) < startdate)
tr.classList.add('offline')
var td;
domlib.newAt(tr,'td').innerHTML = moment(data.lastseen).fromNow(true);
domlib.newAt(tr,'td').innerHTML = data.node_id;
domlib.newAt(tr,'td').innerHTML = moment(node.lastseen).fromNow(true);
domlib.newAt(tr,'td').innerHTML = node.node_id;
domlib.newAt(tr,'td').innerHTML = data.hostname;
domlib.newAt(tr,'td').innerHTML = node.hostname;
var freq = domlib.newAt(tr,'td');
domlib.newAt(freq,'span').innerHTML = '2.4 Ghz';
domlib.newAt(freq,'span').innerHTML = '5 Ghz';
var curchannel = domlib.newAt(tr,'td');
domlib.newAt(curchannel,'span').innerHTML = data._wireless.channel24||'-';
domlib.newAt(curchannel,'span').innerHTML = data._wireless.channel5||'-';
domlib.newAt(curchannel,'span').innerHTML = node._wireless.channel24||'-';
domlib.newAt(curchannel,'span').innerHTML = node._wireless.channel5||'-';
var channel = domlib.newAt(tr,'td');
domlib.newAt(channel,'span').innerHTML = data.wireless.channel24||'-';
domlib.newAt(channel,'span').innerHTML = data.wireless.channel5||'-';
domlib.newAt(channel,'span').innerHTML = node.wireless.channel24||'-';
domlib.newAt(channel,'span').innerHTML = node.wireless.channel5||'-';
var curpower = domlib.newAt(tr,'td');
domlib.newAt(curpower,'span').innerHTML = data._wireless.txpower24||'-';
domlib.newAt(curpower,'span').innerHTML = data._wireless.txpower5||'-';
domlib.newAt(curpower,'span').innerHTML = node._wireless.txpower24||'-';
domlib.newAt(curpower,'span').innerHTML = node._wireless.txpower5||'-';
var power = domlib.newAt(tr,'td');
domlib.newAt(power,'span').innerHTML = data.wireless.txpower24||'-';
domlib.newAt(power,'span').innerHTML = data.wireless.txpower5||'-';
domlib.newAt(power,'span').innerHTML = node.wireless.txpower24||'-';
domlib.newAt(power,'span').innerHTML = node.wireless.txpower5||'-';
var client = domlib.newAt(tr,'td');
domlib.newAt(client,'span').innerHTML = data.statistics.clients.wifi24;
domlib.newAt(client,'span').innerHTML = data.statistics.clients.wifi5;
domlib.newAt(client,'span').innerHTML = node.statistics.clients.wifi24;
domlib.newAt(client,'span').innerHTML = node.statistics.clients.wifi5;
var chanUtil = domlib.newAt(tr,'td');
var chanUtil24 = data.statistics.wireless.filter(function(d){
var chanUtil24 = node.statistics.wireless.filter(function(d){
return d.frequency < 5000;
})[0];
var chanUtil5 = data.statistics.wireless.filter(function(d){
})[0] || {};
var chanUtil5 = node.statistics.wireless.filter(function(d){
return d.frequency > 5000;
})[0];
})[0] || {};
domlib.newAt(chanUtil,'span').innerHTML = chanUtil24.ChanUtil||'-';
domlib.newAt(chanUtil,'span').innerHTML = chanUtil5.ChanUtil||'-';
@ -100,32 +102,32 @@ var guiList = {};
edit.classList.add('btn');
edit.innerHTML = 'Edit';
edit.addEventListener('click',function(){
router.navigate(router.generate('node', { nodeID: data.node_id }));
router.navigate(router.generate('node', { nodeID: node.node_id }));
});
return tr;
}
function updateTable(){
function update(){
domlib.removeChildren(tbody);
var data = store.will();
var nodes = store.getNodes();
if(hostnameFilter && hostnameFilter.value != "")
data = data.filter(function(d){
nodes = nodes.filter(function(d){
return d.hostname.toLowerCase().indexOf(hostnameFilter.value) > -1;
})
if(nodeidFilter && nodeidFilter.value != "")
data = data.filter(function(d){
nodes = nodes.filter(function(d){
return d.node_id.indexOf(nodeidFilter.value) > -1;
})
data = data.sort(sort);
nodes = nodes.sort(sort);
if(sortReverse)
data = data.reverse();
nodes = nodes.reverse();
for(var i=0; i<data.length; i++){
var row = renderRow(data[i]);
for(var i=0; i<nodes.length; i++){
var row = renderRow(nodes[i]);
tbody.appendChild(row);
}
}
@ -137,23 +139,25 @@ var guiList = {};
sortIndex = head;
sortIndex.classList.add(sortReverse ? 'sort-up' : 'sort-down');
updateTable();
update();
}
guiList.bind = function(el) {
view.bind = function(el) {
container = el;
};
guiList.render = function render(){
view.render = function(){
if (container === undefined){
return;
} else if (tbody !== undefined){
container.appendChild(tbody.parentNode);
updateTable();
} else if (el !== undefined){
container.appendChild(el);
update();
return;
}
domlib.removeChildren(container);
var table = domlib.newAt(container,'table');
console.log("generate new view for list");
el = domlib.newAt(container,'div');
var table = domlib.newAt(el,'table');
var thead = domlib.newAt(table,'thead');
tbody = domlib.newAt(table,'tbody');
@ -170,7 +174,7 @@ var guiList = {};
nodeidFilter = domlib.newAt(cell2,'input');
nodeidFilter.setAttribute("placeholder","NodeID");
nodeidFilter.setAttribute("size","9");
nodeidFilter.addEventListener('keyup', updateTable);
nodeidFilter.addEventListener('keyup', update);
cell2.addEventListener('dblclick', function(){
sortTable(cell2);
});
@ -179,7 +183,7 @@ var guiList = {};
cell3.classList.add('sortable');
hostnameFilter = domlib.newAt(cell3,'input');
hostnameFilter.setAttribute("placeholder","Hostname");
hostnameFilter.addEventListener('keyup', updateTable);
hostnameFilter.addEventListener('keyup', update);
cell3.addEventListener('dblclick', function(){
sortTable(cell3);
});
@ -228,6 +232,6 @@ var guiList = {};
table.classList.add('nodes');
updateTable();
update();
};
})();

111
webroot/js/gui_map.js Normal file
View File

@ -0,0 +1,111 @@
var guiMap = {};
(function(){
var view = guiMap;
var container, el;
var nodeLayer;
function addNode (node){
if(node.location === undefined || node.location.latitude === undefined || node.location.longitude === undefined) {
return;
}
var className = 'node';
var startdate = new Date();
startdate.setMinutes(startdate.getMinutes() - 1);
if(new Date(node.lastseen) < startdate) {
className += ' offline';
}
var wifi24='-',wifi5='-',ch24='-',ch5='-',tx24='-',tx5='-';
if(node.statistics && node.statistics.clients){
wifi24 = node.statistics.clients.wifi24;
if(wifi24 < config.map.icon.warn.wifi24 && wifi24 > 0){
className += ' client24';
} else if(wifi24 < config.map.icon.crit.wifi24 && wifi24 >= config.map.icon.warn.wifi24){
className += ' client24-warn';
} else if(wifi24 >= config.map.icon.crit.wifi24){
className += ' client24-crit';
}
wifi5 = node.statistics.clients.wifi5;
if(config.map.icon.warn.wifi5 < 20 && wifi5 > 0){
className += ' client5';
} else if(wifi5 < config.map.icon.crit.wifi5 && wifi5 >= config.map.icon.warn.wifi5){
className += ' client5-warn';
} else if(wifi5 >= config.map.icon.crit.wifi5){
className += ' client5-crit';
}
}
var nodemarker = L.marker([node.location.latitude, node.location.longitude], {
icon: L.divIcon({className: className}),
draggable: true
});
nodemarker.bindTooltip(node.hostname+' <div class=\'nodeicon-label\'>('+node.node_id+')'+
'<table>'+
'<tr><th></th><th>Cl</th><th>Ch</th><th>Tx</th></tr>'+
'<tr><td>2.4G</td><td>'+wifi24+'</td><td>'+ch24+'</td><td>'+tx24+'</td></tr>'+
'<tr><td>5G</td><td>'+wifi5+'</td><td>'+ch5+'</td><td>'+tx5+'</td></tr>'+
'</table>'+
'</div>'
);
nodemarker.on('dragend',function(){
var pos = nodemarker.getLatLng();
node.location = {
'latitude': pos.lat,
'longitude': pos.lng
};
socket.sendnode(node);
});
nodeLayer.addLayer(nodemarker);
}
function update() {
nodeLayer.clearLayers();
var nodes = store.getNodes();
for(var i=0; i<nodes.length; i++){
addNode(nodes[i]);
}
}
view.bind = function(el) {
container = el;
};
view.render = function render(){
if (container === undefined){
return;
} else if (el !== undefined){
container.appendChild(el);
update();
return;
}
console.log("generate new view for map");
el = domlib.newAt(container,'div');
el.style.height = (window.innerHeight - 50 )+"px";
var map = L.map(el).setView(config.map.view.bound, config.map.view.zoom);
L.tileLayer(config.map.tileLayer, {
maxZoom: config.map.maxZoom,
}).addTo(map);
layerControl = L.control.layers().addTo(map);
nodeLayer = L.layerGroup();
layerControl.addOverlay(nodeLayer,'Nodes');
nodeLayer.addTo(map);
window.addEventListener("resize",function(){
el.style.height = (window.innerHeight - 50 )+"px";
map.invalidateSize();
});
update();
}
})()

40
webroot/js/gui_node.js Normal file
View File

@ -0,0 +1,40 @@
var guiNode = {current_node_id:"-"};
(function(){
var view = guiNode;
var container, el;
var titleName,titleID;
function update(){
titleID.innerHTML = view.current_node_id;
var node = store.getNode(view.current_node_id);
if(node === undefined){
console.log("node not found: "+view.current_node_id);
return;
}
titleName.innerHTML = node.hostname;
}
view.bind = function(el) {
container = el;
};
view.render = function render(){
if (container === undefined){
return;
} else if (el !== undefined){
container.appendChild(el);
update();
return;
}
console.log("generate new view for node");
el = domlib.newAt(container,'div');
var title = domlib.newAt(el,'h1');
titleName = domlib.newAt(title,'span');
title.appendChild(document.createTextNode(" - "))
titleID = domlib.newAt(title,'i');
update();
}
})()

View File

@ -0,0 +1,26 @@
var guiSkel = {};
(function(){
var view = guiSkel;
var container, el;
function update(){
}
view.bind = function(el) {
container = el;
};
view.render = function render(){
if (container === undefined){
return;
} else if (el !== undefined){
container.appendChild(el);
update();
return;
}
console.log("generate new view for skel");
el = domlib.newAt(container,'div');
update();
}
})()

62
webroot/js/gui_stats.js Normal file
View File

@ -0,0 +1,62 @@
var guiStats = {};
(function(){
var view = guiStats;
var container, el;
var nodes, clients, clientsWifi,clientsWifi24, clientsWifi5;
function update(){
nodes.innerHTML = store.stats.Nodes;
clients.innerHTML = store.stats.Clients;
clientsWifi.innerHTML = store.stats.ClientsWifi;
clientsWifi24.innerHTML = store.stats.ClientsWifi24;
clientsWifi5.innerHTML = store.stats.ClientsWifi5;
}
view.bind = function(el) {
container = el;
};
view.render = function(){
if (container === undefined){
return;
} else if (el !== undefined){
container.appendChild(el);
update();
return;
}
console.log("generate new view for stats");
el = domlib.newAt(container,'div');
domlib.newAt(el,'h1').innerHTML = "Statistics";
var table = domlib.newAt(el,'table');
table.classList.add("stats");
var tr,title;
tr = domlib.newAt(table,'tr');
title = domlib.newAt(tr,'th')
title.innerHTML = "Nodes";
title.setAttribute("colspan","2");
nodes = domlib.newAt(tr,'td');
tr = domlib.newAt(table,'tr');
title = domlib.newAt(tr,'th')
title.innerHTML = "Clients";
title.setAttribute("colspan","2");
clients = domlib.newAt(tr,'td');
tr = domlib.newAt(table,'tr');
tr.classList.add("line");
domlib.newAt(tr,'th').innerHTML = "Wifi";
domlib.newAt(tr,'th').innerHTML = "2.4 Ghz";
domlib.newAt(tr,'th').innerHTML = "5 Ghz";
tr = domlib.newAt(table,'tr');
clientsWifi = domlib.newAt(tr,'td');
clientsWifi24 = domlib.newAt(tr,'td');
clientsWifi5 = domlib.newAt(tr,'td');
update();
}
})()

9
webroot/js/leaflet.js Normal file

File diff suppressed because one or more lines are too long

View File

@ -16,13 +16,21 @@ var socket = {readyState:0};
function onmessage(e) {
var msg = JSON.parse(e.data);
if(msg.type === "current") {
store.updateReal(msg.node);
} else if (msg.type === "to-update") {
store.update(msg.node);
} else {
gui.disable(e);
switch (msg.type) {
case "current":
store.updateNode(msg.node,true);
break;
case "to-update":
store.updateNode(msg.node);
break;
case "stats":
if(msg.body) {
store.stats = msg.body;
}
break;
default:
notify.send("warn","unable to identify message: "+e);
break;
}
gui.render();
}
@ -35,13 +43,10 @@ var socket = {readyState:0};
}
function sendnode(node) {
var msg = {node:node};
var msg = {type:"to-update",node:node};
var string = JSON.stringify(msg);
if(socket.send(string)){
notify.send("success","Node '"+node.node_id+"' mit neuen Werten wurde gespeichert.");
}else{
notify.send("error","Node '"+node.node_id+"' konnte nicht gespeichert werden!");
}
socket.send(string)
notify.send("success","Node '"+node.node_id+"' mit neuen Werten wurde übermittelt.");
}
function connect() {

View File

@ -1,25 +1,36 @@
var store = {
list:{},
toupdate:{}
_list:{},
_toupdate:{},
stats:{"Clients":0,"ClientsWifi":0,"ClientsWifi24":0,"ClientsWifi5":0,"Gateways":0,"Nodes":0,"Firmwares":{},"Models":{}}
};
(function(){
store.updateReal = function updateReal(node){
store.list[node.node_id] = node;
};
store.update = function update(node){
store.toupdate[node.node_id] = node;
};
store.will = function() {
return Object.keys(store.list).map(function(nodeid){
function getNode(nodeid){
var node;
if (store.toupdate[nodeid]) {
node = store.toupdate[nodeid];
} else{
node = store.list[nodeid];
if (store._toupdate[nodeid]) {
node = store._toupdate[nodeid];
} else if (store._list[nodeid]){
node = store._list[nodeid];
}else{
return;
}
node._wireless = store.list[nodeid].wireless;
node._wireless = store._list[nodeid].wireless;
return node;
});
}
store.updateNode = function updateReal(node, real){
if(real){
store._list[node.node_id] = node;
}else{
store._toupdate[node.node_id] = node;
}
};
store.getNode = getNode;
store.getNodes = function() {
return Object.keys(store._list).map(getNode);
};
})();

View File

@ -53,6 +53,7 @@ func (c *Client) Close() {
// Listen Write and Read request via chanel
func (c *Client) Listen() {
go c.listenWrite()
c.Write(&Message{Type: MessageTypeStats, Body: stats})
c.allNodes()
c.listenRead()
}
@ -66,7 +67,7 @@ func (c *Client) allNodes() {
}
}
func (c *Client) handleMassage(msg *Message) {
func (c *Client) handleMessage(msg *Message) {
switch msg.Type {
case MessageTypeUpdateNode:
nodes.UpdateNode(msg.Node)
@ -113,7 +114,7 @@ func (c *Client) listenRead() {
} else if err != nil {
log.HTTP(c.ws.Request()).Error(err)
} else {
c.handleMassage(&msg)
c.handleMessage(&msg)
}
}
}

View File

@ -4,10 +4,12 @@ import "github.com/FreifunkBremen/freifunkmanager/runtime"
type Message struct {
Type string `json:"type"`
Node *runtime.Node `json:"node"`
Body interface{} `json:"body,omitempty"`
Node *runtime.Node `json:"node,omitempty"`
}
const (
MessageTypeUpdateNode = "to-update"
MessageTypeCurrentNode = "current"
MessageTypeStats = "stats"
)

View File

@ -4,6 +4,7 @@ import (
"net/http"
"sync"
runtimeYanic "github.com/FreifunkBremen/yanic/runtime"
"golang.org/x/net/websocket"
httpLib "github.com/FreifunkBremen/freifunkmanager/lib/http"
@ -14,6 +15,7 @@ import (
var nodes *runtime.Nodes
var clients map[string]*Client
var clientsMutex sync.Mutex
var stats *runtimeYanic.GlobalStats
func Start(nodeBind *runtime.Nodes) {
nodes = nodeBind
@ -41,17 +43,24 @@ func Start(nodeBind *runtime.Nodes) {
}))
nodes.AddNotify(Notify)
nodes.AddNotify(NotifyNode)
}
func Notify(node *runtime.Node, real bool) {
func NotifyNode(node *runtime.Node, real bool) {
msgType := MessageTypeUpdateNode
if real {
msgType = MessageTypeCurrentNode
}
SendAll(Message{Type: msgType, Node: node})
}
func NotifyStats(data *runtimeYanic.GlobalStats) {
stats = data
SendAll(Message{Type: MessageTypeStats, Body: data})
}
func SendAll(msg Message) {
clientsMutex.Lock()
for _, c := range clients {
c.Write(&Message{Type: msgType, Node: node})
c.Write(&msg)
}
clientsMutex.Unlock()
}