summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-nlbwmon
diff options
context:
space:
mode:
Diffstat (limited to 'applications/luci-app-nlbwmon')
-rw-r--r--applications/luci-app-nlbwmon/Makefile8
-rw-r--r--applications/luci-app-nlbwmon/htdocs/luci-static/resources/nlbw.chart.min.js68
-rw-r--r--applications/luci-app-nlbwmon/luasrc/controller/nlbw.lua225
-rw-r--r--applications/luci-app-nlbwmon/luasrc/model/cbi/nlbw/config.lua215
-rw-r--r--applications/luci-app-nlbwmon/luasrc/view/nlbw/backup.htm34
-rw-r--r--applications/luci-app-nlbwmon/luasrc/view/nlbw/display.htm1052
-rw-r--r--applications/luci-app-nlbwmon/po/ja/nlbwmon.po387
-rw-r--r--applications/luci-app-nlbwmon/po/templates/nlbwmon.pot352
-rw-r--r--applications/luci-app-nlbwmon/root/etc/uci-defaults/40_luci-nlbwmon11
9 files changed, 2352 insertions, 0 deletions
diff --git a/applications/luci-app-nlbwmon/Makefile b/applications/luci-app-nlbwmon/Makefile
new file mode 100644
index 0000000000..a00177f2ca
--- /dev/null
+++ b/applications/luci-app-nlbwmon/Makefile
@@ -0,0 +1,8 @@
+include $(TOPDIR)/rules.mk
+
+LUCI_TITLE:=Netlink based bandwidth accounting
+LUCI_DEPENDS:=+nlbwmon
+
+include ../../luci.mk
+
+# call BuildPackage - OpenWrt buildroot signature
diff --git a/applications/luci-app-nlbwmon/htdocs/luci-static/resources/nlbw.chart.min.js b/applications/luci-app-nlbwmon/htdocs/luci-static/resources/nlbw.chart.min.js
new file mode 100644
index 0000000000..34e3026825
--- /dev/null
+++ b/applications/luci-app-nlbwmon/htdocs/luci-static/resources/nlbw.chart.min.js
@@ -0,0 +1,68 @@
+(function(){var p=this,l=p.Chart,e=function(a){this.canvas=a.canvas;this.ctx=a;var b=function(a,b){return a["offset"+b]?a["offset"+b]:document.defaultView.getComputedStyle(a).getPropertyValue(b)};this.width=b(a.canvas,"Width")||a.canvas.width;this.height=b(a.canvas,"Height")||a.canvas.height;this.width=a.canvas.width;this.height=a.canvas.height;this.aspectRatio=this.width/this.height;d.retinaScale(this);return this};e.defaults={global:{animation:!0,animationSteps:60,animationEasing:"easeOutQuart",
+showScale:!0,scaleOverride:!1,scaleSteps:null,scaleStepWidth:null,scaleStartValue:null,scaleLineColor:"rgba(0,0,0,.1)",scaleLineWidth:1,scaleShowLabels:!0,scaleLabel:"<%=value%>",scaleIntegersOnly:!0,scaleBeginAtZero:!1,scaleFontFamily:"'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",scaleFontSize:12,scaleFontStyle:"normal",scaleFontColor:"#666",responsive:!1,maintainAspectRatio:!0,showTooltips:!0,customTooltips:!1,tooltipEvents:["mousemove","touchstart","touchmove","mouseout"],tooltipFillColor:"rgba(0,0,0,0.8)",
+tooltipFontFamily:"'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",tooltipFontSize:14,tooltipFontStyle:"normal",tooltipFontColor:"#fff",tooltipTitleFontFamily:"'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",tooltipTitleFontSize:14,tooltipTitleFontStyle:"bold",tooltipTitleFontColor:"#fff",tooltipTitleTemplate:"<%= label%>",tooltipYPadding:6,tooltipXPadding:6,tooltipCaretSize:8,tooltipCornerRadius:6,tooltipXOffset:10,tooltipTemplate:"<%if (label){%><%=label%>: <%}%><%= value %>",multiTooltipTemplate:"<%= value %>",
+multiTooltipKeyBackground:"#fff",segmentColorDefault:"#A6CEE3 #1F78B4 #B2DF8A #33A02C #FB9A99 #E31A1C #FDBF6F #FF7F00 #CAB2D6 #6A3D9A #B4B482 #B15928".split(" "),segmentHighlightColorDefaults:"#CEF6FF #47A0DC #DAFFB2 #5BC854 #FFC2C1 #FF4244 #FFE797 #FFA728 #F2DAFE #9265C2 #DCDCAA #D98150".split(" "),onAnimationProgress:function(){},onAnimationComplete:function(){}}};e.types={};var d=e.helpers={},k=d.each=function(a,b,c){var f=Array.prototype.slice.call(arguments,3);if(a)if(a.length===+a.length){var d;
+for(d=0;d<a.length;d++)b.apply(c,[a[d],d].concat(f))}else for(d in a)b.apply(c,[a[d],d].concat(f))},h=d.clone=function(a){var b={};k(a,function(c,f){a.hasOwnProperty(f)&&(b[f]=c)});return b},r=d.extend=function(a){k(Array.prototype.slice.call(arguments,1),function(b){k(b,function(c,f){b.hasOwnProperty(f)&&(a[f]=c)})});return a},I=d.merge=function(a,b){var c=Array.prototype.slice.call(arguments,0);c.unshift({});return r.apply(null,c)},J=d.indexOf=function(a,b){if(Array.prototype.indexOf)return a.indexOf(b);
+for(var c=0;c<a.length;c++)if(a[c]===b)return c;return-1};d.where=function(a,b){var c=[];d.each(a,function(a){b(a)&&c.push(a)});return c};d.findNextWhere=function(a,b,c){c||(c=-1);for(c+=1;c<a.length;c++){var f=a[c];if(b(f))return f}};d.findPreviousWhere=function(a,b,c){c||(c=a.length);for(--c;0<=c;c--){var f=a[c];if(b(f))return f}};var D=d.inherits=function(a){var b=this,c=a&&a.hasOwnProperty("constructor")?a.constructor:function(){return b.apply(this,arguments)},f=function(){this.constructor=c};
+f.prototype=b.prototype;c.prototype=new f;c.extend=D;a&&r(c.prototype,a);c.__super__=b.prototype;return c},A=d.noop=function(){},K=d.uid=function(){var a=0;return function(){return"chart-"+a++}}(),L=d.warn=function(a){window.console&&"function"===typeof window.console.warn&&console.warn(a)},M=d.amd="function"===typeof define&&define.amd,u=d.isNumber=function(a){return!isNaN(parseFloat(a))&&isFinite(a)},y=d.max=function(a){return Math.max.apply(Math,a)},w=d.min=function(a){return Math.min.apply(Math,
+a)};d.cap=function(a,b,c){if(u(b)){if(a>b)return b}else if(u(c)&&a<c)return c;return a};var E=d.getDecimalPlaces=function(a){if(0!==a%1&&u(a)){a=a.toString();if(0>a.indexOf("e-"))return a.split(".")[1].length;if(0>a.indexOf("."))return parseInt(a.split("e-")[1]);a=a.split(".")[1].split("e-");return a[0].length+parseInt(a[1])}return 0},B=d.radians=function(a){return Math.PI/180*a};d.getAngleFromPoint=function(a,b){var c=b.x-a.x,f=b.y-a.y,d=Math.sqrt(c*c+f*f),m=2*Math.PI+Math.atan2(f,c);0>c&&0>f&&(m+=
+2*Math.PI);return{angle:m,distance:d}};var F=d.aliasPixel=function(a){return 0===a%2?0:.5};d.splineCurve=function(a,b,c,f){var d=Math.sqrt(Math.pow(b.x-a.x,2)+Math.pow(b.y-a.y,2)),m=Math.sqrt(Math.pow(c.x-b.x,2)+Math.pow(c.y-b.y,2)),g=f*d/(d+m);f=f*m/(d+m);return{inner:{x:b.x-g*(c.x-a.x),y:b.y-g*(c.y-a.y)},outer:{x:b.x+f*(c.x-a.x),y:b.y+f*(c.y-a.y)}}};var N=d.calculateOrderOfMagnitude=function(a){return Math.floor(Math.log(a)/Math.LN10)};d.calculateScaleRange=function(a,b,c,f,d){b=Math.floor(b/(1.5*
+c));c=2>=b;var m=[];k(a,function(a){null==a||m.push(a)});var g=w(m),e=y(m);e===g&&(e+=.5,.5<=g&&!f?g-=.5:e+=.5);a=N(Math.abs(e-g));f=f?0:Math.floor(g/(1*Math.pow(10,a)))*Math.pow(10,a);for(var e=Math.ceil(e/(1*Math.pow(10,a)))*Math.pow(10,a)-f,g=Math.pow(10,a),n=Math.round(e/g);(n>b||2*n<b)&&!c;)if(n>b)g*=2,n=Math.round(e/g),0!==n%1&&(c=!0);else if(d&&0<=a)if(0===g/2%1)g/=2,n=Math.round(e/g);else break;else g/=2,n=Math.round(e/g);c&&(n=2,g=e/n);return{steps:n,stepValue:g,min:f,max:f+n*g}};var t=d.template=
+function(a,b){if(a instanceof Function)return a(b);var c={},c=/\W/.test(a)?new Function("obj","var p=[],print=function(){p.push.apply(p,arguments);};with(obj){p.push('"+a.replace(/[\r\t\n]/g," ").split("<%").join("\t").replace(/((^|%>)[^\t]*)'/g,"$1\r").replace(/\t=(.*?)%>/g,"',$1,'").split("\t").join("');").split("%>").join("p.push('").split("\r").join("\\'")+"');}return p.join('');"):c[a]=c[a];return b?c(b):c};d.generateLabels=function(a,b,c,f){var d=Array(b);a&&k(d,function(b,e){d[e]=t(a,{value:c+
+f*(e+1)})});return d};var x=d.easingEffects={linear:function(a){return a},easeInQuad:function(a){return a*a},easeOutQuad:function(a){return-1*a*(a-2)},easeInOutQuad:function(a){return 1>(a/=.5)?.5*a*a:-.5*(--a*(a-2)-1)},easeInCubic:function(a){return a*a*a},easeOutCubic:function(a){return 1*((a=a/1-1)*a*a+1)},easeInOutCubic:function(a){return 1>(a/=.5)?.5*a*a*a:.5*((a-=2)*a*a+2)},easeInQuart:function(a){return a*a*a*a},easeOutQuart:function(a){return-1*((a=a/1-1)*a*a*a-1)},easeInOutQuart:function(a){return 1>
+(a/=.5)?.5*a*a*a*a:-.5*((a-=2)*a*a*a-2)},easeInQuint:function(a){return 1*(a/=1)*a*a*a*a},easeOutQuint:function(a){return 1*((a=a/1-1)*a*a*a*a+1)},easeInOutQuint:function(a){return 1>(a/=.5)?.5*a*a*a*a*a:.5*((a-=2)*a*a*a*a+2)},easeInSine:function(a){return-1*Math.cos(a/1*(Math.PI/2))+1},easeOutSine:function(a){return 1*Math.sin(a/1*(Math.PI/2))},easeInOutSine:function(a){return-.5*(Math.cos(Math.PI*a/1)-1)},easeInExpo:function(a){return 0===a?1:1*Math.pow(2,10*(a/1-1))},easeOutExpo:function(a){return 1===
+a?1:1*(-Math.pow(2,-10*a/1)+1)},easeInOutExpo:function(a){return 0===a?0:1===a?1:1>(a/=.5)?.5*Math.pow(2,10*(a-1)):.5*(-Math.pow(2,-10*--a)+2)},easeInCirc:function(a){return 1<=a?a:-1*(Math.sqrt(1-(a/=1)*a)-1)},easeOutCirc:function(a){return 1*Math.sqrt(1-(a=a/1-1)*a)},easeInOutCirc:function(a){return 1>(a/=.5)?-.5*(Math.sqrt(1-a*a)-1):.5*(Math.sqrt(1-(a-=2)*a)+1)},easeInElastic:function(a){var b=1.70158,c=0,f=1;if(0===a)return 0;if(1==(a/=1))return 1;c||(c=.3);f<Math.abs(1)?(f=1,b=c/4):b=c/(2*Math.PI)*
+Math.asin(1/f);return-(f*Math.pow(2,10*--a)*Math.sin(2*(1*a-b)*Math.PI/c))},easeOutElastic:function(a){var b=1.70158,c=0,f=1;if(0===a)return 0;if(1==(a/=1))return 1;c||(c=.3);f<Math.abs(1)?(f=1,b=c/4):b=c/(2*Math.PI)*Math.asin(1/f);return f*Math.pow(2,-10*a)*Math.sin(2*(1*a-b)*Math.PI/c)+1},easeInOutElastic:function(a){var b=1.70158,c=0,f=1;if(0===a)return 0;if(2==(a/=.5))return 1;c||(c=.3*1.5);f<Math.abs(1)?(f=1,b=c/4):b=c/(2*Math.PI)*Math.asin(1/f);return 1>a?-.5*f*Math.pow(2,10*--a)*Math.sin(2*
+(1*a-b)*Math.PI/c):f*Math.pow(2,-10*--a)*Math.sin(2*(1*a-b)*Math.PI/c)*.5+1},easeInBack:function(a){return 1*(a/=1)*a*(2.70158*a-1.70158)},easeOutBack:function(a){return 1*((a=a/1-1)*a*(2.70158*a+1.70158)+1)},easeInOutBack:function(a){var b=1.70158;return 1>(a/=.5)?.5*a*a*(((b*=1.525)+1)*a-b):.5*((a-=2)*a*(((b*=1.525)+1)*a+b)+2)},easeInBounce:function(a){return 1-x.easeOutBounce(1-a)},easeOutBounce:function(a){return(a/=1)<1/2.75?7.5625*a*a:a<2/2.75?1*(7.5625*(a-=1.5/2.75)*a+.75):a<2.5/2.75?1*(7.5625*
+(a-=2.25/2.75)*a+.9375):1*(7.5625*(a-=2.625/2.75)*a+.984375)},easeInOutBounce:function(a){return.5>a?.5*x.easeInBounce(2*a):.5*x.easeOutBounce(2*a-1)+.5}},G=d.requestAnimFrame=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(a){return window.setTimeout(a,1E3/60)}}();d.cancelAnimFrame=function(){return window.cancelAnimationFrame||window.webkitCancelAnimationFrame||
+window.mozCancelAnimationFrame||window.oCancelAnimationFrame||window.msCancelAnimationFrame||function(a){return window.clearTimeout(a,1E3/60)}}();d.animationLoop=function(a,b,c,f,d,e){var g=0,k=x[c]||x.linear,n=function(){g++;var c=g/b,h=k(c);a.call(e,h,c,g);f.call(e,h,c);g<b?e.animationFrame=G(n):d.apply(e)};G(n)};d.getRelativePosition=function(a){var b;b=a.originalEvent||a;var c=(a.currentTarget||a.srcElement).getBoundingClientRect();b.touches?(a=b.touches[0].clientX-c.left,b=b.touches[0].clientY-
+c.top):(a=b.clientX-c.left,b=b.clientY-c.top);return{x:a,y:b}};var O=d.addEvent=function(a,b,c){a.addEventListener?a.addEventListener(b,c):a.attachEvent?a.attachEvent("on"+b,c):a["on"+b]=c},P=d.removeEvent=function(a,b,c){a.removeEventListener?a.removeEventListener(b,c,!1):a.detachEvent?a.detachEvent("on"+b,c):a["on"+b]=A};d.bindEvents=function(a,b,c){a.events||(a.events={});k(b,function(b){a.events[b]=function(){c.apply(a,arguments)};O(a.chart.canvas,b,a.events[b])})};var Q=d.unbindEvents=function(a,
+b){k(b,function(b,f){P(a.chart.canvas,f,b)})},R=d.getMaximumWidth=function(a){a=a.parentNode;var b=parseInt(z(a,"padding-left"))+parseInt(z(a,"padding-right"));return a?a.clientWidth-b:0},S=d.getMaximumHeight=function(a){a=a.parentNode;var b=parseInt(z(a,"padding-bottom"))+parseInt(z(a,"padding-top"));return a?a.clientHeight-b:0},z=d.getStyle=function(a,b){return a.currentStyle?a.currentStyle[b]:document.defaultView.getComputedStyle(a,null).getPropertyValue(b)};d.getMaximumSize=d.getMaximumWidth;
+var T=d.retinaScale=function(a){var b=a.ctx,c=a.canvas.width;a=a.canvas.height;window.devicePixelRatio&&(b.canvas.style.width=c+"px",b.canvas.style.height=a+"px",b.canvas.height=a*window.devicePixelRatio,b.canvas.width=c*window.devicePixelRatio,b.scale(window.devicePixelRatio,window.devicePixelRatio))},U=d.clear=function(a){a.ctx.clearRect(0,0,a.width,a.height)},v=d.fontString=function(a,b,c){return b+" "+a+"px "+c},C=d.longestText=function(a,b,c){a.font=b;var f=0;k(c,function(b){b=a.measureText(b).width;
+f=b>f?b:f});return f},H=d.drawRoundedRectangle=function(a,b,c,f,d,e){a.beginPath();a.moveTo(b+e,c);a.lineTo(b+f-e,c);a.quadraticCurveTo(b+f,c,b+f,c+e);a.lineTo(b+f,c+d-e);a.quadraticCurveTo(b+f,c+d,b+f-e,c+d);a.lineTo(b+e,c+d);a.quadraticCurveTo(b,c+d,b,c+d-e);a.lineTo(b,c+e);a.quadraticCurveTo(b,c,b+e,c);a.closePath()};e.instances={};e.Type=function(a,b,c){this.options=b;this.chart=c;this.id=K();e.instances[this.id]=this;b.responsive&&this.resize();this.initialize.call(this,a)};r(e.Type.prototype,
+{initialize:function(){return this},clear:function(){U(this.chart);return this},stop:function(){e.animationService.cancelAnimation(this);return this},resize:function(a){this.stop();var b=this.chart.canvas,c=R(this.chart.canvas),f=this.options.maintainAspectRatio?c/this.chart.aspectRatio:S(this.chart.canvas);b.width=this.chart.width=c;b.height=this.chart.height=f;T(this.chart);"function"===typeof a&&a.apply(this,Array.prototype.slice.call(arguments,1));return this},reflow:A,render:function(a){a&&this.reflow();
+this.options.animation&&!a?(a=new e.Animation,a.numSteps=this.options.animationSteps,a.easing=this.options.animationEasing,a.render=function(a,c){var f=c.currentStep/c.numSteps,e=(0,d.easingEffects[c.easing])(f);a.draw(e,f,c.currentStep)},a.onAnimationProgress=this.options.onAnimationProgress,a.onAnimationComplete=this.options.onAnimationComplete,e.animationService.addAnimation(this,a)):(this.draw(),this.options.onAnimationComplete.call(this));return this},generateLegend:function(){return t(this.options.legendTemplate,
+this)},destroy:function(){this.clear();Q(this,this.events);var a=this.chart.canvas;a.width=this.chart.width;a.height=this.chart.height;a.style.removeProperty?(a.style.removeProperty("width"),a.style.removeProperty("height")):(a.style.removeAttribute("width"),a.style.removeAttribute("height"));delete e.instances[this.id]},showTooltip:function(a,b){"undefined"===typeof this.activeElements&&(this.activeElements=[]);if(function(a){var b=!1;if(a.length!==this.activeElements.length)return b=!0;k(a,function(a,
+c){a!==this.activeElements[c]&&(b=!0)},this);return b}.call(this,a)||b){this.activeElements=a;this.draw();this.options.customTooltips&&this.options.customTooltips(!1);if(0<a.length)if(this.datasets&&1<this.datasets.length){for(var c,f,q=this.datasets.length-1;0<=q&&(c=this.datasets[q].points||this.datasets[q].bars||this.datasets[q].segments,f=J(c,a[0]),-1===f);q--);var m=[],g=[];c=function(a){var b=[],c,e=[],q=[],k,h,l;d.each(this.datasets,function(a){c=a.points||a.bars||a.segments;c[f]&&c[f].hasValue()&&
+b.push(c[f])});d.each(b,function(a){e.push(a.x);q.push(a.y);m.push(d.template(this.options.multiTooltipTemplate,a));g.push({fill:a._saved.fillColor||a.fillColor,stroke:a._saved.strokeColor||a.strokeColor})},this);l=w(q);k=y(q);h=w(e);a=y(e);return{x:h>this.chart.width/2?h:a,y:(l+k)/2}}.call(this,f);(new e.MultiTooltip({x:c.x,y:c.y,xPadding:this.options.tooltipXPadding,yPadding:this.options.tooltipYPadding,xOffset:this.options.tooltipXOffset,fillColor:this.options.tooltipFillColor,textColor:this.options.tooltipFontColor,
+fontFamily:this.options.tooltipFontFamily,fontStyle:this.options.tooltipFontStyle,fontSize:this.options.tooltipFontSize,titleTextColor:this.options.tooltipTitleFontColor,titleFontFamily:this.options.tooltipTitleFontFamily,titleFontStyle:this.options.tooltipTitleFontStyle,titleFontSize:this.options.tooltipTitleFontSize,cornerRadius:this.options.tooltipCornerRadius,labels:m,legendColors:g,legendColorBackground:this.options.multiTooltipKeyBackground,title:t(this.options.tooltipTitleTemplate,a[0]),chart:this.chart,
+ctx:this.chart.ctx,custom:this.options.customTooltips})).draw()}else k(a,function(a){var b=a.tooltipPosition();(new e.Tooltip({x:Math.round(b.x),y:Math.round(b.y),xPadding:this.options.tooltipXPadding,yPadding:this.options.tooltipYPadding,fillColor:this.options.tooltipFillColor,textColor:this.options.tooltipFontColor,fontFamily:this.options.tooltipFontFamily,fontStyle:this.options.tooltipFontStyle,fontSize:this.options.tooltipFontSize,caretHeight:this.options.tooltipCaretSize,cornerRadius:this.options.tooltipCornerRadius,
+text:t(this.options.tooltipTemplate,a),chart:this.chart,custom:this.options.customTooltips})).draw()},this);return this}},toBase64Image:function(){return this.chart.canvas.toDataURL.apply(this.chart.canvas,arguments)}});e.Type.extend=function(a){var b=this,c=function(){return b.apply(this,arguments)};c.prototype=h(b.prototype);r(c.prototype,a);c.extend=e.Type.extend;if(a.name||b.prototype.name){var f=a.name||b.prototype.name,d=e.defaults[b.prototype.name]?h(e.defaults[b.prototype.name]):{};e.defaults[f]=
+r(d,a.defaults);e.types[f]=c;e.prototype[f]=function(a,b){var d=I(e.defaults.global,e.defaults[f],b||{});return new c(a,d,this)}}else L("Name not provided for this chart, so it hasn't been registered");return b};e.Element=function(a){r(this,a);this.initialize.apply(this,arguments);this.save()};r(e.Element.prototype,{initialize:function(){},restore:function(a){a?k(a,function(a){this[a]=this._saved[a]},this):r(this,this._saved);return this},save:function(){this._saved=h(this);delete this._saved._saved;
+return this},update:function(a){k(a,function(a,c){this._saved[c]=this[c];this[c]=a},this);return this},transition:function(a,b){k(a,function(a,f){this[f]=(a-this._saved[f])*b+this._saved[f]},this);return this},tooltipPosition:function(){return{x:this.x,y:this.y}},hasValue:function(){return u(this.value)}});e.Element.extend=D;e.Point=e.Element.extend({display:!0,inRange:function(a,b){return Math.pow(a-this.x,2)+Math.pow(b-this.y,2)<Math.pow(this.hitDetectionRadius+this.radius,2)},draw:function(){if(this.display){var a=
+this.ctx;a.beginPath();a.arc(this.x,this.y,this.radius,0,2*Math.PI);a.closePath();a.strokeStyle=this.strokeColor;a.lineWidth=this.strokeWidth;a.fillStyle=this.fillColor;a.fill();a.stroke()}}});e.Arc=e.Element.extend({inRange:function(a,b){var c=d.getAngleFromPoint(this,{x:a,y:b}),f=c.angle%(2*Math.PI),e=(2*Math.PI+this.startAngle)%(2*Math.PI),m=(2*Math.PI+this.endAngle)%(2*Math.PI)||360,c=c.distance>=this.innerRadius&&c.distance<=this.outerRadius;return(m<e?f<=m||f>=e:f>=e&&f<=m)&&c},tooltipPosition:function(){var a=
+this.startAngle+(this.endAngle-this.startAngle)/2,b=(this.outerRadius-this.innerRadius)/2+this.innerRadius;return{x:this.x+Math.cos(a)*b,y:this.y+Math.sin(a)*b}},draw:function(a){a=this.ctx;a.beginPath();a.arc(this.x,this.y,0>this.outerRadius?0:this.outerRadius,this.startAngle,this.endAngle);a.arc(this.x,this.y,0>this.innerRadius?0:this.innerRadius,this.endAngle,this.startAngle,!0);a.closePath();a.strokeStyle=this.strokeColor;a.lineWidth=this.strokeWidth;a.fillStyle=this.fillColor;a.fill();a.lineJoin=
+"bevel";this.showStroke&&a.stroke()}});e.Rectangle=e.Element.extend({draw:function(){var a=this.ctx,b=this.width/2,c=this.x-b,b=this.x+b,f=this.base-(this.base-this.y),d=this.strokeWidth/2;this.showStroke&&(c+=d,b-=d,f+=d);a.beginPath();a.fillStyle=this.fillColor;a.strokeStyle=this.strokeColor;a.lineWidth=this.strokeWidth;a.moveTo(c,this.base);a.lineTo(c,f);a.lineTo(b,f);a.lineTo(b,this.base);a.fill();this.showStroke&&a.stroke()},height:function(){return this.base-this.y},inRange:function(a,b){return a>=
+this.x-this.width/2&&a<=this.x+this.width/2&&b>=this.y&&b<=this.base}});e.Animation=e.Element.extend({currentStep:null,numSteps:60,easing:"",render:null,onAnimationProgress:null,onAnimationComplete:null});e.Tooltip=e.Element.extend({draw:function(){var a=this.chart.ctx;a.font=v(this.fontSize,this.fontStyle,this.fontFamily);this.xAlign="center";this.yAlign="above";var b=this.caretPadding=2,c=a.measureText(this.text).width+2*this.xPadding,f=this.fontSize+2*this.yPadding,d=f+this.caretHeight+b;this.x+
+c/2>this.chart.width?this.xAlign="left":0>this.x-c/2&&(this.xAlign="right");0>this.y-d&&(this.yAlign="below");var e=this.x-c/2,d=this.y-d;a.fillStyle=this.fillColor;if(this.custom)this.custom(this);else{switch(this.yAlign){case "above":a.beginPath();a.moveTo(this.x,this.y-b);a.lineTo(this.x+this.caretHeight,this.y-(b+this.caretHeight));a.lineTo(this.x-this.caretHeight,this.y-(b+this.caretHeight));a.closePath();a.fill();break;case "below":d=this.y+b+this.caretHeight,a.beginPath(),a.moveTo(this.x,this.y+
+b),a.lineTo(this.x+this.caretHeight,this.y+b+this.caretHeight),a.lineTo(this.x-this.caretHeight,this.y+b+this.caretHeight),a.closePath(),a.fill()}switch(this.xAlign){case "left":e=this.x-c+(this.cornerRadius+this.caretHeight);break;case "right":e=this.x-(this.cornerRadius+this.caretHeight)}H(a,e,d,c,f,this.cornerRadius);a.fill();a.fillStyle=this.textColor;a.textAlign="center";a.textBaseline="middle";a.fillText(this.text,e+c/2,d+f/2)}}});e.MultiTooltip=e.Element.extend({initialize:function(){this.font=
+v(this.fontSize,this.fontStyle,this.fontFamily);this.titleFont=v(this.titleFontSize,this.titleFontStyle,this.titleFontFamily);this.titleHeight=this.title?1.5*this.titleFontSize:0;this.height=this.labels.length*this.fontSize+this.fontSize/2*(this.labels.length-1)+2*this.yPadding+this.titleHeight;this.ctx.font=this.titleFont;var a=this.ctx.measureText(this.title).width,b=C(this.ctx,this.font,this.labels)+this.fontSize+3;this.width=y([b,a])+2*this.xPadding;a=this.height/2;0>this.y-a?this.y=a:this.y+
+a>this.chart.height&&(this.y=this.chart.height-a);this.x=this.x>this.chart.width/2?this.x-(this.xOffset+this.width):this.x+this.xOffset},getLineHeight:function(a){var b=this.y-this.height/2+this.yPadding;return 0===a?b+this.titleHeight/3:b+(1.5*this.fontSize*(a-1)+this.fontSize/2)+this.titleHeight},draw:function(){if(this.custom)this.custom(this);else{H(this.ctx,this.x,this.y-this.height/2,this.width,this.height,this.cornerRadius);var a=this.ctx;a.fillStyle=this.fillColor;a.fill();a.closePath();a.textAlign=
+"left";a.textBaseline="middle";a.fillStyle=this.titleTextColor;a.font=this.titleFont;a.fillText(this.title,this.x+this.xPadding,this.getLineHeight(0));a.font=this.font;d.each(this.labels,function(b,c){a.fillStyle=this.textColor;a.fillText(b,this.x+this.xPadding+this.fontSize+3,this.getLineHeight(c+1));a.fillStyle=this.legendColorBackground;a.fillRect(this.x+this.xPadding,this.getLineHeight(c+1)-this.fontSize/2,this.fontSize,this.fontSize);a.fillStyle=this.legendColors[c].fill;a.fillRect(this.x+this.xPadding,
+this.getLineHeight(c+1)-this.fontSize/2,this.fontSize,this.fontSize)},this)}}});e.Scale=e.Element.extend({initialize:function(){this.fit()},buildYLabels:function(){this.yLabels=[];for(var a=E(this.stepValue),b=0;b<=this.steps;b++)this.yLabels.push(t(this.templateString,{value:(this.min+b*this.stepValue).toFixed(a)}));this.yLabelWidth=this.display&&this.showLabels?C(this.ctx,this.font,this.yLabels)+10:0},addXLabel:function(a){this.xLabels.push(a);this.valuesCount++;this.fit()},removeXLabel:function(){this.xLabels.shift();
+this.valuesCount--;this.fit()},fit:function(){this.startPoint=this.display?this.fontSize:0;this.endPoint=this.display?this.height-1.5*this.fontSize-5:this.height;this.startPoint+=this.padding;var a=this.endPoint-=this.padding,b=this.endPoint-this.startPoint,c;this.calculateYRange(b);this.buildYLabels();for(this.calculateXLabelRotation();b>this.endPoint-this.startPoint;)b=this.endPoint-this.startPoint,c=this.yLabelWidth,this.calculateYRange(b),this.buildYLabels(),c<this.yLabelWidth&&(this.endPoint=
+a,this.calculateXLabelRotation())},calculateXLabelRotation:function(){this.ctx.font=this.font;var a=this.ctx.measureText(this.xLabels[0]).width,b;this.xScalePaddingRight=this.ctx.measureText(this.xLabels[this.xLabels.length-1]).width/2+3;this.xScalePaddingLeft=a/2>this.yLabelWidth?a/2:this.yLabelWidth;this.xLabelRotation=0;if(this.display){var c=C(this.ctx,this.font,this.xLabels),f;this.xLabelWidth=c;for(var d=Math.floor(this.calculateX(1)-this.calculateX(0))-6;this.xLabelWidth>d&&0===this.xLabelRotation||
+this.xLabelWidth>d&&90>=this.xLabelRotation&&0<this.xLabelRotation;)f=Math.cos(B(this.xLabelRotation)),b=f*a,b+this.fontSize/2>this.yLabelWidth&&(this.xScalePaddingLeft=b+this.fontSize/2),this.xScalePaddingRight=this.fontSize/2,this.xLabelRotation++,this.xLabelWidth=f*c;0<this.xLabelRotation&&(this.endPoint-=Math.sin(B(this.xLabelRotation))*c+3)}else this.xLabelWidth=0,this.xScalePaddingLeft=this.xScalePaddingRight=this.padding},calculateYRange:A,drawingArea:function(){return this.startPoint-this.endPoint},
+calculateY:function(a){var b=this.drawingArea()/(this.min-this.max);return this.endPoint-b*(a-this.min)},calculateX:function(a){var b=(this.width-(this.xScalePaddingLeft+this.xScalePaddingRight))/Math.max(this.valuesCount-(this.offsetGridLines?0:1),1);a=b*a+this.xScalePaddingLeft;this.offsetGridLines&&(a+=b/2);return Math.round(a)},update:function(a){d.extend(this,a);this.fit()},draw:function(){var a=this.ctx,b=(this.endPoint-this.startPoint)/this.steps,c=Math.round(this.xScalePaddingLeft);this.display&&
+(a.fillStyle=this.textColor,a.font=this.font,k(this.yLabels,function(f,e){var k=this.endPoint-b*e,g=Math.round(k),h=this.showHorizontalLines;a.textAlign="right";a.textBaseline="middle";this.showLabels&&a.fillText(f,c-10,k);0!==e||h||(h=!0);h&&a.beginPath();0<e?(a.lineWidth=this.gridLineWidth,a.strokeStyle=this.gridLineColor):(a.lineWidth=this.lineWidth,a.strokeStyle=this.lineColor);g+=d.aliasPixel(a.lineWidth);h&&(a.moveTo(c,g),a.lineTo(this.width,g),a.stroke(),a.closePath());a.lineWidth=this.lineWidth;
+a.strokeStyle=this.lineColor;a.beginPath();a.moveTo(c-5,g);a.lineTo(c,g);a.stroke();a.closePath()},this),k(this.xLabels,function(b,c){var d=this.calculateX(c)+F(this.lineWidth),e=this.calculateX(c-(this.offsetGridLines?.5:0))+F(this.lineWidth),k=0<this.xLabelRotation,h=this.showVerticalLines;0!==c||h||(h=!0);h&&a.beginPath();0<c?(a.lineWidth=this.gridLineWidth,a.strokeStyle=this.gridLineColor):(a.lineWidth=this.lineWidth,a.strokeStyle=this.lineColor);h&&(a.moveTo(e,this.endPoint),a.lineTo(e,this.startPoint-
+3),a.stroke(),a.closePath());a.lineWidth=this.lineWidth;a.strokeStyle=this.lineColor;a.beginPath();a.moveTo(e,this.endPoint);a.lineTo(e,this.endPoint+5);a.stroke();a.closePath();a.save();a.translate(d,k?this.endPoint+12:this.endPoint+8);a.rotate(-1*B(this.xLabelRotation));a.font=this.font;a.textAlign=k?"right":"center";a.textBaseline=k?"middle":"top";a.fillText(b,0,0);a.restore()},this))}});e.RadialScale=e.Element.extend({initialize:function(){this.size=w([this.height,this.width]);this.drawingArea=
+this.display?this.size/2-(this.fontSize/2+this.backdropPaddingY):this.size/2},calculateCenterOffset:function(a){return this.drawingArea/(this.max-this.min)*(a-this.min)},update:function(){this.lineArc?this.drawingArea=this.display?this.size/2-(this.fontSize/2+this.backdropPaddingY):this.size/2:this.setScaleSize();this.buildYLabels()},buildYLabels:function(){this.yLabels=[];for(var a=E(this.stepValue),b=0;b<=this.steps;b++)this.yLabels.push(t(this.templateString,{value:(this.min+b*this.stepValue).toFixed(a)}))},
+getCircumference:function(){return 2*Math.PI/this.valuesCount},setScaleSize:function(){var a=w([this.height/2-this.pointLabelFontSize-5,this.width/2]),b,c,d,e=this.width,k,g=0,h;this.ctx.font=v(this.pointLabelFontSize,this.pointLabelFontStyle,this.pointLabelFontFamily);for(c=0;c<this.valuesCount;c++)b=this.getPointPosition(c,a),d=this.ctx.measureText(t(this.templateString,{value:this.labels[c]})).width+5,0===c||c===this.valuesCount/2?(d/=2,b.x+d>e&&(e=b.x+d,k=c),b.x-d<g&&(g=b.x-d,h=c)):c<this.valuesCount/
+2?b.x+d>e&&(e=b.x+d,k=c):c>this.valuesCount/2&&b.x-d<g&&(g=b.x-d,h=c);b=g;e=Math.ceil(e-this.width);k=this.getIndexAngle(k);h=this.getIndexAngle(h);k=e/Math.sin(k+Math.PI/2);h=b/Math.sin(h+Math.PI/2);k=u(k)?k:0;h=u(h)?h:0;this.drawingArea=a-(h+k)/2;this.setCenterPoint(h,k)},setCenterPoint:function(a,b){this.xCenter=(a+this.drawingArea+(this.width-b-this.drawingArea))/2;this.yCenter=this.height/2},getIndexAngle:function(a){return 2*Math.PI/this.valuesCount*a-Math.PI/2},getPointPosition:function(a,
+b){var c=this.getIndexAngle(a);return{x:Math.cos(c)*b+this.xCenter,y:Math.sin(c)*b+this.yCenter}},draw:function(){if(this.display){var a=this.ctx;k(this.yLabels,function(b,c){if(0<c){var d=this.drawingArea/this.steps*c,e=this.yCenter-d;if(0<this.lineWidth){a.strokeStyle=this.lineColor;a.lineWidth=this.lineWidth;if(this.lineArc)a.beginPath(),a.arc(this.xCenter,this.yCenter,d,0,2*Math.PI);else{a.beginPath();for(var f=0;f<this.valuesCount;f++)d=this.getPointPosition(f,this.calculateCenterOffset(this.min+
+c*this.stepValue)),0===f?a.moveTo(d.x,d.y):a.lineTo(d.x,d.y)}a.closePath();a.stroke()}this.showLabels&&(a.font=v(this.fontSize,this.fontStyle,this.fontFamily),this.showLabelBackdrop&&(d=a.measureText(b).width,a.fillStyle=this.backdropColor,a.fillRect(this.xCenter-d/2-this.backdropPaddingX,e-this.fontSize/2-this.backdropPaddingY,d+2*this.backdropPaddingX,this.fontSize+2*this.backdropPaddingY)),a.textAlign="center",a.textBaseline="middle",a.fillStyle=this.fontColor,a.fillText(b,this.xCenter,e))}},this);
+if(!this.lineArc){a.lineWidth=this.angleLineWidth;a.strokeStyle=this.angleLineColor;for(var b=this.valuesCount-1;0<=b;b--){var c=null,d=null;0<this.angleLineWidth&&(c=this.calculateCenterOffset(this.max),d=this.getPointPosition(b,c),a.beginPath(),a.moveTo(this.xCenter,this.yCenter),a.lineTo(d.x,d.y),a.stroke(),a.closePath());if(this.backgroundColors&&this.backgroundColors.length==this.valuesCount){null==c&&(c=this.calculateCenterOffset(this.max));null==d&&(d=this.getPointPosition(b,c));var e=this.getPointPosition(0===
+b?this.valuesCount-1:b-1,c),h=this.getPointPosition(b===this.valuesCount-1?0:b+1,c),c=(e.x+d.x)/2,e=(e.y+d.y)/2,g=(d.x+h.x)/2,h=(d.y+h.y)/2;a.beginPath();a.moveTo(this.xCenter,this.yCenter);a.lineTo(c,e);a.lineTo(d.x,d.y);a.lineTo(g,h);a.fillStyle=this.backgroundColors[b];a.fill();a.closePath()}d=this.getPointPosition(b,this.calculateCenterOffset(this.max)+5);a.font=v(this.pointLabelFontSize,this.pointLabelFontStyle,this.pointLabelFontFamily);a.fillStyle=this.pointLabelFontColor;e=this.labels.length;
+c=this.labels.length/2;g=c/2;h=b<g||b>e-g;e=b===g||b===e-g;a.textAlign=0===b?"center":b===c?"center":b<c?"left":"right";a.textBaseline=e?"middle":h?"bottom":"top";a.fillText(this.labels[b],d.x,d.y)}}}}});e.animationService={frameDuration:17,animations:[],dropFrames:0,addAnimation:function(a,b){for(var c=0;c<this.animations.length;++c)if(this.animations[c].chartInstance===a){this.animations[c].animationObject=b;return}this.animations.push({chartInstance:a,animationObject:b});1==this.animations.length&&
+d.requestAnimFrame.call(window,this.digestWrapper)},cancelAnimation:function(a){var b=d.findNextWhere(this.animations,function(b){return b.chartInstance===a});b&&this.animations.splice(b,1)},digestWrapper:function(){e.animationService.startDigest.call(e.animationService)},startDigest:function(){var a=Date.now(),b=0;1<this.dropFrames&&(b=Math.floor(this.dropFrames),this.dropFrames-=b);for(var c=0;c<this.animations.length;c++)null===this.animations[c].animationObject.currentStep&&(this.animations[c].animationObject.currentStep=
+0),this.animations[c].animationObject.currentStep+=1+b,this.animations[c].animationObject.currentStep>this.animations[c].animationObject.numSteps&&(this.animations[c].animationObject.currentStep=this.animations[c].animationObject.numSteps),this.animations[c].animationObject.render(this.animations[c].chartInstance,this.animations[c].animationObject),this.animations[c].animationObject.currentStep==this.animations[c].animationObject.numSteps&&(this.animations[c].animationObject.onAnimationComplete.call(this.animations[c].chartInstance),
+this.animations.splice(c,1),c--);a=(Date.now()-a-this.frameDuration)/this.frameDuration;1<a&&(this.dropFrames+=a);0<this.animations.length&&d.requestAnimFrame.call(window,this.digestWrapper)}};d.addEvent(window,"resize",function(){var a;return function(){clearTimeout(a);a=setTimeout(function(){k(e.instances,function(a){a.options.responsive&&a.resize(a.render,!0)})},50)}}());M?define(function(){return e}):"object"===typeof module&&module.exports&&(module.exports=e);p.Chart=e;e.noConflict=function(){p.Chart=
+l;return e}}).call(this);
+(function(){var p=this.Chart,l=p.helpers,e={segmentShowStroke:!0,segmentStrokeColor:"#fff",segmentStrokeWidth:2,percentageInnerCutout:50,animationSteps:100,animationEasing:"easeOutBounce",animateRotate:!0,animateScale:!1,legendTemplate:'<ul class="<%=name.toLowerCase()%>-legend"><% for (var i=0; i<segments.length; i++){%><li><span style="background-color:<%=segments[i].fillColor%>"><%if(segments[i].label){%><%=segments[i].label%><%}%></span></li><%}%></ul>'};p.Type.extend({name:"Doughnut",defaults:e,
+initialize:function(d){this.segments=[];this.outerRadius=(l.min([this.chart.width,this.chart.height])-this.options.segmentStrokeWidth/2)/2;this.SegmentArc=p.Arc.extend({ctx:this.chart.ctx,x:this.chart.width/2,y:this.chart.height/2});this.options.showTooltips&&l.bindEvents(this,this.options.tooltipEvents,function(d){d="mouseout"!==d.type?this.getSegmentsAtEvent(d):[];l.each(this.segments,function(d){d.restore(["fillColor"])});l.each(d,function(d){d.fillColor=d.highlightColor});this.showTooltip(d)});
+this.calculateTotal(d);l.each(d,function(e,h){e.color||(e.color="hsl("+360*h/d.length+", 100%, 50%)");this.addData(e,h,!0)},this);this.render()},getSegmentsAtEvent:function(d){var e=[],h=l.getRelativePosition(d);l.each(this.segments,function(d){d.inRange(h.x,h.y)&&e.push(d)},this);return e},addData:function(d,e,h){e=void 0!==e?e:this.segments.length;"undefined"===typeof d.color&&(d.color=p.defaults.global.segmentColorDefault[e%p.defaults.global.segmentColorDefault.length],d.highlight=p.defaults.global.segmentHighlightColorDefaults[e%
+p.defaults.global.segmentHighlightColorDefaults.length]);this.segments.splice(e,0,new this.SegmentArc({value:d.value,outerRadius:this.options.animateScale?0:this.outerRadius,innerRadius:this.options.animateScale?0:this.outerRadius/100*this.options.percentageInnerCutout,fillColor:d.color,highlightColor:d.highlight||d.color,showStroke:this.options.segmentShowStroke,strokeWidth:this.options.segmentStrokeWidth,strokeColor:this.options.segmentStrokeColor,startAngle:1.5*Math.PI,circumference:this.options.animateRotate?
+0:this.calculateCircumference(d.value),label:d.label}));h||(this.reflow(),this.update())},calculateCircumference:function(d){return 0<this.total?d/this.total*Math.PI*2:0},calculateTotal:function(d){this.total=0;l.each(d,function(d){this.total+=Math.abs(d.value)},this)},update:function(){this.calculateTotal(this.segments);l.each(this.activeElements,function(d){d.restore(["fillColor"])});l.each(this.segments,function(d){d.save()});this.render()},removeData:function(d){d=l.isNumber(d)?d:this.segments.length-
+1;this.segments.splice(d,1);this.reflow();this.update()},reflow:function(){l.extend(this.SegmentArc.prototype,{x:this.chart.width/2,y:this.chart.height/2});this.outerRadius=(l.min([this.chart.width,this.chart.height])-this.options.segmentStrokeWidth/2)/2;l.each(this.segments,function(d){d.update({outerRadius:this.outerRadius,innerRadius:this.outerRadius/100*this.options.percentageInnerCutout})},this)},draw:function(d){var e=d?d:1;this.clear();l.each(this.segments,function(d,l){d.transition({circumference:this.calculateCircumference(d.value),
+outerRadius:this.outerRadius,innerRadius:this.outerRadius/100*this.options.percentageInnerCutout},e);d.endAngle=d.startAngle+d.circumference;d.draw();0===l&&(d.startAngle=1.5*Math.PI);l<this.segments.length-1&&(this.segments[l+1].startAngle=d.endAngle)},this)}});p.types.Doughnut.extend({name:"Pie",defaults:l.merge(e,{percentageInnerCutout:0})})}).call(this);
diff --git a/applications/luci-app-nlbwmon/luasrc/controller/nlbw.lua b/applications/luci-app-nlbwmon/luasrc/controller/nlbw.lua
new file mode 100644
index 0000000000..bb56bc6e6e
--- /dev/null
+++ b/applications/luci-app-nlbwmon/luasrc/controller/nlbw.lua
@@ -0,0 +1,225 @@
+-- Copyright 2017 Jo-Philipp Wich <jo@mein.io>
+-- Licensed to the public under the Apache License 2.0.
+
+module("luci.controller.nlbw", package.seeall)
+
+function index()
+ entry({"admin", "nlbw"}, firstchild(), _("Bandwidth Monitor"), 80)
+ entry({"admin", "nlbw", "display"}, template("nlbw/display"), _("Display"), 1)
+ entry({"admin", "nlbw", "config"}, cbi("nlbw/config"), _("Configuration"), 2)
+ entry({"admin", "nlbw", "backup"}, template("nlbw/backup"), _("Backup"), 3)
+ entry({"admin", "nlbw", "data"}, call("action_data"), nil, 4)
+ entry({"admin", "nlbw", "list"}, call("action_list"), nil, 5)
+ entry({"admin", "nlbw", "ptr"}, call("action_ptr"), nil, 6).leaf = true
+ entry({"admin", "nlbw", "download"}, call("action_download"), nil, 7)
+ entry({"admin", "nlbw", "restore"}, post("action_restore"), nil, 8)
+ entry({"admin", "nlbw", "commit"}, call("action_commit"), nil, 9)
+end
+
+local function exec(cmd, args, writer)
+ local os = require "os"
+ local nixio = require "nixio"
+
+ local fdi, fdo = nixio.pipe()
+ local pid = nixio.fork()
+
+ if pid > 0 then
+ fdo:close()
+
+ while true do
+ local buffer = fdi:read(2048)
+ local wpid, stat, code = nixio.waitpid(pid, "nohang")
+
+ if writer and buffer and #buffer > 0 then
+ writer(buffer)
+ end
+
+ if wpid and stat == "exited" then
+ break
+ end
+ end
+ elseif pid == 0 then
+ nixio.dup(fdo, nixio.stdout)
+ fdi:close()
+ fdo:close()
+ nixio.exece(cmd, args, nil)
+ nixio.stdout:close()
+ os.exit(1)
+ end
+end
+
+function action_data()
+ local http = require "luci.http"
+
+ local types = {
+ csv = "text/csv",
+ json = "application/json"
+ }
+
+ local args = { }
+ local mtype = http.formvalue("type") or "json"
+ local delim = http.formvalue("delim") or ";"
+ local period = http.formvalue("period")
+ local group_by = http.formvalue("group_by")
+ local order_by = http.formvalue("order_by")
+
+ if types[mtype] then
+ args[#args+1] = "-c"
+ args[#args+1] = mtype
+ else
+ http.status(400, "Unsupported type")
+ return
+ end
+
+ if delim and #delim > 0 then
+ args[#args+1] = "-s%s" % delim
+ end
+
+ if period and #period > 0 then
+ args[#args+1] = "-t"
+ args[#args+1] = period
+ end
+
+ if group_by and #group_by > 0 then
+ args[#args+1] = "-g"
+ args[#args+1] = group_by
+ end
+
+ if order_by and #order_by > 0 then
+ args[#args+1] = "-o"
+ args[#args+1] = order_by
+ end
+
+ http.prepare_content(types[mtype])
+ exec("/usr/sbin/nlbw", args, http.write)
+end
+
+function action_list()
+ local http = require "luci.http"
+
+ local fd = io.popen("/usr/sbin/nlbw -c list")
+ local periods = { }
+
+ if fd then
+ while true do
+ local period = fd:read("*l")
+
+ if not period then
+ break
+ end
+
+ periods[#periods+1] = period
+ end
+
+ fd:close()
+ end
+
+ http.prepare_content("application/json")
+ http.write_json(periods)
+end
+
+function action_ptr(...)
+ local http = require "luci.http"
+ local util = require "luci.util"
+
+ http.prepare_content("application/json")
+ http.write_json(util.ubus("network.rrdns", "lookup", {
+ addrs = {...}, timeout = 3000
+ }))
+end
+
+function action_download()
+ local nixio = require "nixio"
+ local http = require "luci.http"
+ local sys = require "luci.sys"
+ local uci = require "luci.model.uci".cursor()
+
+ local dir = uci:get_first("nlbwmon", "nlbwmon", "database_directory")
+ or "/var/lib/nlbwmon"
+
+ if dir and nixio.fs.stat(dir, "type") == "dir" then
+ local n = "nlbwmon-backup-%s-%s.tar.gz"
+ %{ sys.hostname(), os.date("%Y-%m-%d") }
+
+ http.prepare_content("application/octet-stream")
+ http.header("Content-Disposition", "attachment; filename=\"%s\"" % n)
+ exec("/bin/tar", { "-C", dir, "-c", "-z", ".", "-f", "-" }, http.write)
+ else
+ http.status(500, "Unable to find database directory")
+ end
+end
+
+function action_restore()
+ local nixio = require "nixio"
+ local http = require "luci.http"
+ local i18n = require "luci.i18n"
+ local tpl = require "luci.template"
+ local uci = require "luci.model.uci".cursor()
+
+ local tmp = "/tmp/nlbw-restore.tar.gz"
+ local dir = uci:get_first("nlbwmon", "nlbwmon", "database_directory")
+ or "/var/lib/nlbwmon"
+
+ local fp
+ http.setfilehandler(
+ function(meta, chunk, eof)
+ if not fp and meta and meta.name == "archive" then
+ fp = io.open(tmp, "w")
+ end
+ if fp and chunk then
+ fp:write(chunk)
+ end
+ if fp and eof then
+ fp:close()
+ end
+ end)
+
+ local files = { }
+ local tar = io.popen("/bin/tar -tzf %s" % tmp, "r")
+ if tar then
+ while true do
+ local file = tar:read("*l")
+ if not file then
+ break
+ elseif file:match("^%d%d%d%d%d%d%d%d%.db%.gz$") or
+ file:match("^%./%d%d%d%d%d%d%d%d%.db%.gz$") then
+ files[#files+1] = file
+ end
+ end
+ tar:close()
+ end
+
+ if #files == 0 then
+ http.status(500, "Internal Server Error")
+ tpl.render("nlbw/backup", {
+ message = i18n.translate("Invalid or empty backup archive")
+ })
+ return
+ end
+
+
+ local output = { }
+
+ exec("/etc/init.d/nlbwmon", { "stop" })
+ exec("/bin/mkdir", { "-p", dir })
+
+ exec("/bin/tar", { "-C", dir, "-vxzf", tmp, unpack(files) },
+ function(chunk) output[#output+1] = chunk:match("%S+") end)
+
+ exec("/bin/rm", { "-f", tmp })
+ exec("/etc/init.d/nlbwmon", { "start" })
+
+ tpl.render("nlbw/backup", {
+ message = i18n.translatef(
+ "The following database files have been restored: %s",
+ table.concat(output, ", "))
+ })
+end
+
+function action_commit()
+ local http = require "luci.http"
+ local disp = require "luci.dispatcher"
+
+ http.redirect(disp.build_url("admin/nlbw/display"))
+ exec("/usr/sbin/nlbw", { "-c", "commit" })
+end
diff --git a/applications/luci-app-nlbwmon/luasrc/model/cbi/nlbw/config.lua b/applications/luci-app-nlbwmon/luasrc/model/cbi/nlbw/config.lua
new file mode 100644
index 0000000000..71e096c617
--- /dev/null
+++ b/applications/luci-app-nlbwmon/luasrc/model/cbi/nlbw/config.lua
@@ -0,0 +1,215 @@
+-- Copyright 2017 Jo-Philipp Wich <jo@mein.io>
+-- Licensed to the public under the Apache License 2.0.
+
+local utl = require "luci.util"
+local sys = require "luci.sys"
+local fs = require "nixio.fs"
+local ip = require "luci.ip"
+local nw = require "luci.model.network"
+
+local s, m, period, warning, date, days, interval, ifaces, subnets, limit, prealloc, compress, generations, commit, refresh, directory, protocols
+
+m = Map("nlbwmon", translate("Netlink Bandwidth Monitor - Configuration"),
+ translate("The Netlink Bandwidth Monitor (nlbwmon) is a lightweight, efficient traffic accounting program keeping track of bandwidth usage per host and protocol."))
+
+nw.init(luci.model.uci.cursor_state())
+
+s = m:section(TypedSection, "nlbwmon")
+s.anonymous = true
+s.addremove = false
+s:tab("general", translate("General Settings"))
+s:tab("advanced", translate("Advanced Settings"))
+s:tab("protocol", translate("Protocol Mapping"),
+ translate("Protocol mappings to distinguish traffic types per host, one mapping per line. The first value specifies the IP protocol, the second value the port number and the third column is the name of the mapped protocol."))
+
+period = s:taboption("general", ListValue, "_period", translate("Accounting period"),
+ translate("Choose \"Day of month\" to restart the accounting period monthly on a specific date, e.g. every 3rd. Choose \"Fixed interval\" to restart the accounting period exactly every N days, beginning at a given date."))
+
+period:value("relative", translate("Day of month"))
+period:value("absolute", translate("Fixed interval"))
+
+period.write = function(self, cfg, val)
+ if period:formvalue(cfg) == "relative" then
+ m:set(cfg, "database_interval", interval:formvalue(cfg))
+ else
+ m:set(cfg, "database_interval", "%s/%s" %{
+ date:formvalue(cfg),
+ days:formvalue(cfg)
+ })
+ end
+end
+
+period.cfgvalue = function(self, cfg)
+ local val = m:get(cfg, "database_interval") or ""
+ if val:match("^%d%d%d%d%-%d%d%-%d%d/%d+$") then
+ return "absolute"
+ end
+ return "relative"
+end
+
+
+warning = s:taboption("general", DummyValue, "_warning", translate("Warning"))
+warning.default = translatef("Changing the accounting interval type will invalidate existing databases!<br /><strong><a href=\"%s\">Download backup</a></strong>.", luci.dispatcher.build_url("admin/nlbw/backup"))
+warning.rawhtml = true
+
+if (m.uci:get_first("nlbwmon", "nlbwmon", "database_interval") or ""):match("^%d%d%d%d-%d%d-%d%d/%d+$") then
+ warning:depends("_period", "relative")
+else
+ warning:depends("_period", "absolute")
+end
+
+
+interval = s:taboption("general", Value, "_interval", translate("Due date"),
+ translate("Day of month to restart the accounting period. Use negative values to count towards the end of month, e.g. \"-5\" to specify the 27th of July or the 24th of Februrary."))
+
+interval.datatype = "or(range(1,31),range(-31,-1))"
+interval.placeholder = "1"
+interval:value("1", translate("1 - Restart every 1st of month"))
+interval:value("-1", translate("-1 - Restart every last day of month"))
+interval:value("-7", translate("-7 - Restart a week before end of month"))
+interval.rmempty = false
+interval:depends("_period", "relative")
+interval.write = period.write
+
+interval.cfgvalue = function(self, cfg)
+ local val = m:get(cfg, "database_interval")
+ return val and tonumber(val)
+end
+
+
+date = s:taboption("general", Value, "_date", translate("Start date"),
+ translate("Start date of the first accounting period, e.g. begin of ISP contract."))
+
+date.datatype = "dateyyyymmdd"
+date.placeholder = "2016-03-15"
+date.rmempty = false
+date:depends("_period", "absolute")
+date.write = period.write
+
+date.cfgvalue = function(self, cfg)
+ local val = m:get(cfg, "database_interval") or ""
+ return (val:match("^(%d%d%d%d%-%d%d%-%d%d)/%d+$"))
+end
+
+
+days = s:taboption("general", Value, "_days", translate("Interval"),
+ translate("Length of accounting interval in days."))
+
+days.datatype = "min(1)"
+days.placeholder = "30"
+days.rmempty = false
+days:depends("_period", "absolute")
+days.write = period.write
+
+days.cfgvalue = function(self, cfg)
+ local val = m:get(cfg, "database_interval") or ""
+ return (val:match("^%d%d%d%d%-%d%d%-%d%d/(%d+)$"))
+end
+
+
+ifaces = s:taboption("general", Value, "_ifaces", translate("Local interfaces"),
+ translate("Only conntrack streams from or to any of these networks are counted."))
+
+ifaces.template = "cbi/network_netlist"
+ifaces.widget = "checkbox"
+ifaces.nocreate = true
+
+ifaces.cfgvalue = function(self, cfg)
+ return m:get(cfg, "local_network")
+end
+
+ifaces.write = function(self, cfg)
+ local item
+ local items = {}
+ for item in utl.imatch(subnets:formvalue(cfg)) do
+ items[#items+1] = item
+ end
+ for item in utl.imatch(ifaces:formvalue(cfg)) do
+ items[#items+1] = item
+ end
+ m:set(cfg, "local_network", items)
+end
+
+
+subnets = s:taboption("general", DynamicList, "_subnets", translate("Local subnets"),
+ translate("Only conntrack streams from or to any of these subnets are counted."))
+
+subnets.datatype = "ipaddr"
+
+subnets.cfgvalue = function(self, cfg)
+ local subnet
+ local subnets = {}
+ for subnet in utl.imatch(m:get(cfg, "local_network")) do
+ subnet = ip.new(subnet)
+ subnets[#subnets+1] = subnet and subnet:string()
+ end
+ return subnets
+end
+
+subnets.write = ifaces.write
+
+
+limit = s:taboption("advanced", Value, "database_limit", translate("Maximum entries"),
+ translate("The maximum amount of entries that should be put into the database, setting the limit to 0 will allow databases to grow indefinitely."))
+
+limit.datatype = "uinteger"
+limit.placeholder = "10000"
+
+prealloc = s:taboption("advanced", Flag, "database_prealloc", translate("Preallocate database"),
+ translate("Whether to preallocate the maximum possible database size in memory. This is mainly useful for memory constrained systems which might not be able to satisfy memory allocation after longer uptime periods."))
+
+prealloc:depends({["database_limit"] = "0", ["!reverse"] = true })
+
+
+compress = s:taboption("advanced", Flag, "database_compress", translate("Compress database"),
+ translate("Whether to gzip compress archive databases. Compressing the database files makes accessing old data slightly slower but helps to reduce storage requirements."))
+
+compress.default = compress.enabled
+
+
+generations = s:taboption("advanced", Value, "database_generations", translate("Stored periods"),
+ translate("Maximum number of accounting periods to keep, use zero to keep databases forever."))
+
+generations.datatype = "uinteger"
+generations.placeholder = "10"
+
+
+commit = s:taboption("advanced", Value, "commit_interval", translate("Commit interval"),
+ translate("Interval at which the temporary in-memory database is committed to the persistent database directory."))
+
+commit.placeholder = "24h"
+commit:value("24h", translate("24h - least flash wear at the expense of data loss risk"))
+commit:value("12h", translate("12h - compromise between risk of data loss and flash wear"))
+commit:value("10m", translate("10m - frequent commits at the expense of flash wear"))
+commit:value("60s", translate("60s - commit minutely, useful for non-flash storage"))
+
+
+refresh = s:taboption("advanced", Value, "refresh_interval", translate("Refresh interval"),
+ translate("Interval at which traffic counters of still established connections are refreshed from netlink information."))
+
+refresh.placeholder = "30s"
+refresh:value("30s", translate("30s - refresh twice per minute for reasonably current stats"))
+refresh:value("5m", translate("5m - rarely refresh to avoid frequently clearing conntrack counters"))
+
+
+directory = s:taboption("advanced", Value, "database_directory", translate("Database directory"),
+ translate("Database storage directory. One file per accounting period will be placed into this directory."))
+
+directory.placeholder = "/var/lib/nlbwmon"
+
+
+protocols = s:taboption("protocol", TextValue, "_protocols")
+protocols.rows = 50
+
+protocols.cfgvalue = function(self, cfg)
+ return fs.readfile("/usr/share/nlbwmon/protocols")
+end
+
+protocols.write = function(self, cfg, value)
+ fs.writefile("/usr/share/nlbwmon/protocols", (value or ""):gsub("\r\n", "\n"))
+end
+
+protocols.remove = protocols.write
+
+
+return m
diff --git a/applications/luci-app-nlbwmon/luasrc/view/nlbw/backup.htm b/applications/luci-app-nlbwmon/luasrc/view/nlbw/backup.htm
new file mode 100644
index 0000000000..ea2e0f05cf
--- /dev/null
+++ b/applications/luci-app-nlbwmon/luasrc/view/nlbw/backup.htm
@@ -0,0 +1,34 @@
+<%#
+ Copyright 2017 Jo-Philipp Wich <jo@mein.io>
+ Licensed to the public under the Apache License 2.0.
+-%>
+
+<%+header%>
+
+<script type="text/javascript" src="<%=resource%>/cbi.js"></script>
+
+<h2 name="content"><%:Netlink Bandwidth Monitor - Backup / Restore %></h2>
+
+<fieldset class="cbi-section">
+ <legend><%:Restore Database Backup%></legend>
+ <p>
+ <form method="POST" action="<%=url("admin/nlbw/restore")%>" enctype="multipart/form-data">
+ <input type="hidden" name="token" value="<%=token%>" />
+ <input type="file" name="archive" accept="application/gzip,.gz" />
+ <input type="submit" value="<%:Restore%>" class="cbi-button cbi-button-apply" />
+ </form>
+
+ <% if message then %>
+ <div class="alert-message"><%=message%></div>
+ <% end %>
+ </p>
+
+ <legend><%:Download Database Backup%></legend>
+ <p>
+ <form method="GET" action="<%=url("admin/nlbw/download")%>">
+ <input type="submit" value="<%:Generate Backup%>" class="cbi-button cbi-button-link" />
+ </form>
+ </p>
+</fieldset>
+
+<%+footer%>
diff --git a/applications/luci-app-nlbwmon/luasrc/view/nlbw/display.htm b/applications/luci-app-nlbwmon/luasrc/view/nlbw/display.htm
new file mode 100644
index 0000000000..7e85acefb3
--- /dev/null
+++ b/applications/luci-app-nlbwmon/luasrc/view/nlbw/display.htm
@@ -0,0 +1,1052 @@
+<%#
+ Copyright 2017 Jo-Philipp Wich <jo@mein.io>
+ Licensed to the public under the Apache License 2.0.
+-%>
+
+<% css = [[
+
+ #chartjs-tooltip {
+ opacity: 0;
+ position: absolute;
+ background: rgba(0, 0, 0, .7);
+ color: white;
+ padding: 3px;
+ border-radius: 3px;
+ -webkit-transition: all .1s ease;
+ transition: all .1s ease;
+ pointer-events: none;
+ -webkit-transform: translate(-50%, 0);
+ transform: translate(-50%, 0);
+ z-index: 200;
+ }
+
+ #chartjs-tooltip.above {
+ -webkit-transform: translate(-50%, -100%);
+ transform: translate(-50%, -100%);
+ }
+
+ #chartjs-tooltip.above:before {
+ border: solid;
+ border-color: #111 transparent;
+ border-color: rgba(0, 0, 0, .8) transparent;
+ border-width: 8px 8px 0 8px;
+ bottom: 1em;
+ content: "";
+ display: block;
+ left: 50%;
+ top: 100%;
+ position: absolute;
+ z-index: 99;
+ -webkit-transform: translate(-50%, 0);
+ transform: translate(-50%, 0);
+ }
+
+ table {
+ border: 1px solid #999;
+ border-collapse: collapse;
+ margin: 0 0 2px !important;
+ }
+
+ th, td, table table td {
+ border: 1px solid #999;
+ text-align: right;
+ padding: 1px 3px !important;
+ white-space: nowrap;
+ }
+
+ tbody td {
+ border-bottom-color: #ccc;
+ }
+
+ tbody td[rowspan] {
+ border-bottom-color: #999;
+ }
+
+ tbody tr:last-child td {
+ border-bottom-color: #999;
+ }
+
+
+ .pie {
+ width: 200px;
+ display: inline-block;
+ margin: 20px;
+ }
+
+ .pie label {
+ font-weight: bold;
+ font-size: 14px;
+ display: block;
+ margin-bottom: 10px;
+ text-align: center;
+ }
+
+ .kpi {
+ display: inline-block;
+ margin: 80px 20px 20px;
+ vertical-align: top;
+ }
+
+ .kpi ul {
+ list-style: none;
+ }
+
+ .kpi li {
+ margin: 10px;
+ display: none;
+ }
+
+ .kpi big {
+ font-weight: bold;
+ }
+
+ #detail-bubble {
+ position: absolute;
+ opacity: 0;
+ visibility: hidden;
+ }
+
+ #detail-bubble.in {
+ opacity: 1;
+ visibility: visible;
+ transition: opacity 0.5s;
+ }
+
+ #detail-bubble > div {
+ border: 1px solid #ccc;
+ border-radius: 2px;
+ padding: 5px;
+ background: #fcfcfc;
+ }
+
+ #detail-bubble .head {
+ text-align: center;
+ white-space: nowrap;
+ position: relative;
+ }
+
+ #detail-bubble .head .dismiss {
+ top: 0;
+ right: 0;
+ width: 20px;
+ line-height: 20px;
+ text-align: center;
+ text-decoration: none;
+ font-weight: bold;
+ color: #000;
+ position: absolute;
+ font-size: 20px;
+ }
+
+ #detail-bubble .pie {
+ width: 100px;
+ margin: 5px;
+ }
+
+ #detail-bubble .kpi {
+ margin: 40px 5px 5px;
+ font-size: smaller;
+ text-align: left;
+ }
+
+ #detail-bubble .kpi ul {
+ margin: 0;
+ }
+
+ #bubble-arrow {
+ border: 1px solid #ccc;
+ border-width: 1px 0 0 1px;
+ background: #fcfcfc;
+ width: 15px;
+ height: 15px;
+ position: absolute;
+ left: 0;
+ top: -8px;
+ transform: rotate(45deg);
+ margin: 0 0 0 -8px;
+ }
+
+ tr.active > td {
+ border-bottom: 2px solid red;
+ }
+
+ tr.active > td.active {
+ border: 2px solid red;
+ border-bottom: none;
+ }
+
+ td.detail {
+ border: 2px solid red;
+ border-top: none;
+ opacity: 0;
+ transition: opacity 0.5s;
+ }
+
+ td.detail.in {
+ opacity: 1;
+ }
+
+ th.hostname,
+ td.hostname {
+ text-align: left;
+ }
+
+]] -%>
+
+<%+header%>
+
+<script type="text/javascript" src="<%=resource%>/cbi.js"></script>
+<script type="text/javascript" src="<%=resource%>/nlbw.chart.min.js"></script>
+<script type="text/javascript">//<![CDATA[
+
+var chartRegistry = {},
+ trafficPeriods = [],
+ trafficData = { columns: [], data: [] },
+ hostNames = {},
+ hostInfo = <%=luci.util.serialize_json(luci.sys.net.host_hints())%>,
+ ouiData = [];
+
+
+function off(elem)
+{
+ var val = [0, 0];
+ do {
+ if (!isNaN(elem.offsetLeft) && !isNaN(elem.offsetTop)) {
+ val[0] += elem.offsetLeft;
+ val[1] += elem.offsetTop;
+ }
+ }
+ while ((elem = elem.offsetParent) != null);
+ return val;
+}
+
+Chart.defaults.global.customTooltips = function(tooltip) {
+ var tooltipEl = document.getElementById('chartjs-tooltip');
+
+ if (!tooltipEl) {
+ tooltipEl = document.createElement('div');
+ tooltipEl.setAttribute('id', 'chartjs-tooltip');
+ document.body.appendChild(tooltipEl);
+ }
+
+ if (!tooltip) {
+ if (tooltipEl.row)
+ tooltipEl.row.style.backgroundColor = '';
+
+ tooltipEl.style.opacity = 0;
+ return;
+ }
+
+ var pos = off(tooltip.chart.canvas);
+
+ tooltipEl.className = tooltip.yAlign;
+ tooltipEl.innerHTML = tooltip.text[0];
+
+ tooltipEl.style.opacity = 1;
+ tooltipEl.style.left = pos[0] + tooltip.x + 'px';
+ tooltipEl.style.top = pos[1] + tooltip.y - tooltip.caretHeight - tooltip.caretPadding + 'px';
+
+ var row = tooltip.text[1],
+ hue = tooltip.text[2];
+
+ if (row && !isNaN(hue)) {
+ row.style.backgroundColor = 'hsl(%u, 100%%, 80%%)'.format(hue);
+ tooltipEl.row = row;
+ }
+};
+
+Chart.defaults.global.tooltipFontSize = 10;
+Chart.defaults.global.tooltipTemplate = function(tip) {
+ tip.label[0] = tip.label[0].format(tip.value);
+ return tip.label;
+};
+
+function kpi(id, val1, val2, val3)
+{
+ var e = document.getElementById(id);
+
+ if (val1 && val2 && val3)
+ e.innerHTML = '<%:%s, %s and %s%>'.format(val1, val2, val3);
+ else if (val1 && val2)
+ e.innerHTML = '<%:%s and %s%>'.format(val1, val2);
+ else if (val1)
+ e.innerHTML = val1;
+
+ e.parentNode.style.display = val1 ? 'list-item' : '';
+}
+
+function pie(id, data)
+{
+ data.sort(function(a, b) { return b.value - a.value });
+
+ if (data.length === 0 || (data.length === 1 && data[0].value === 0))
+ data[0] = {
+ value: 1,
+ color: '#cccccc',
+ label: [ '<%:no traffic%>' ]
+ };
+
+ for (var i = 0; i < data.length; i++) {
+ if (!data[i].color) {
+ var hue = 120 / (data.length-1) * i;
+ data[i].color = 'hsl(%u, 80%%, 50%%)'.format(hue);
+ data[i].label.push(hue);
+ }
+ }
+
+ var ctx = document.getElementById(id).getContext('2d');
+
+ if (chartRegistry.hasOwnProperty(id))
+ chartRegistry[id].destroy();
+
+ chartRegistry[id] = new Chart(ctx).Doughnut(data, {
+ segmentStrokeWidth: 1,
+ percentageInnerCutout: 30
+ });
+
+ return chartRegistry[id];
+}
+
+function query(filter, group, order)
+{
+ var keys = [], columns = {}, records = {}, result = [];
+
+ if (typeof(group) !== 'function' && typeof(group) !== 'object')
+ group = ['mac'];
+
+ for (var i = 0; i < trafficData.columns.length; i++)
+ columns[trafficData.columns[i]] = i;
+
+ for (var i = 0; i < trafficData.data.length; i++) {
+ var record = trafficData.data[i];
+
+ if (typeof(filter) === 'function' && filter(columns, record) !== true)
+ continue;
+
+ var key;
+
+ if (typeof(group) === 'function') {
+ key = group(columns, record);
+ }
+ else {
+ key = [];
+
+ for (var j = 0; j < group.length; j++)
+ if (columns.hasOwnProperty(group[j]))
+ key.push(record[columns[group[j]]]);
+
+ key = key.join(',');
+ }
+
+ if (!records.hasOwnProperty(key)) {
+ var rec = {};
+
+ for (var col in columns)
+ rec[col] = record[columns[col]];
+
+ records[key] = rec;
+ result.push(rec);
+ }
+ else {
+ records[key].conns += record[columns.conns];
+ records[key].rx_bytes += record[columns.rx_bytes];
+ records[key].rx_pkts += record[columns.rx_pkts];
+ records[key].tx_bytes += record[columns.tx_bytes];
+ records[key].tx_pkts += record[columns.tx_pkts];
+ }
+ }
+
+ if (typeof(order) === 'function')
+ result.sort(order);
+
+ return result;
+}
+
+function oui(mac) {
+ var m, l = 0, r = ouiData.length / 3 - 1;
+ var mac1 = parseInt(mac.replace(/[^a-fA-F0-9]/g, ''), 16);
+
+ while (l <= r) {
+ m = l + Math.floor((r - l) / 2);
+
+ var mask = (0xffffffffffff -
+ (Math.pow(2, 48 - ouiData[m * 3 + 1]) - 1));
+
+ var mac1_hi = ((mac1 / 0x10000) & (mask / 0x10000)) >>> 0;
+ var mac1_lo = ((mac1 & 0xffff) & (mask & 0xffff)) >>> 0;
+
+ var mac2 = parseInt(ouiData[m * 3], 16);
+ var mac2_hi = (mac2 / 0x10000) >>> 0;
+ var mac2_lo = (mac2 & 0xffff) >>> 0;
+
+ if (mac1_hi === mac2_hi && mac1_lo === mac2_lo)
+ return ouiData[m * 3 + 2];
+
+ if (mac2_hi > mac1_hi ||
+ (mac2_hi === mac1_hi && mac2_lo > mac1_lo))
+ r = m - 1;
+ else
+ l = m + 1;
+ }
+
+ return null;
+}
+
+
+function fetchData(period)
+{
+ XHR.get('<%=url("admin/nlbw/data")%>', { period: period, group_by: 'family,mac,ip,layer7', order_by: '-rx_bytes,-tx_bytes' }, function(xhr, res) {
+ if (res !== null && typeof(res) === 'object' && typeof(res.columns) === 'object' && typeof(res.data) === 'object')
+ trafficData = res;
+
+ var addrs = query(null, ['ip'], null);
+ var ipAddrs = [];
+
+ for (var i = 0; i < addrs.length; i++)
+ if (ipAddrs.indexOf(addrs[i].ip) < 0)
+ ipAddrs.push(addrs[i].ip);
+
+ renderHostData();
+ renderLayer7Data();
+ renderIPv6Data();
+
+ XHR.get('<%=url("admin/nlbw/ptr")%>/' + ipAddrs.join('/'), null, function(xhr, res) {
+ if (res !== null && typeof(res) === 'object')
+ hostNames = res;
+ });
+ });
+}
+
+function switchTab(tab)
+{
+ bubbleDismiss();
+
+ return cbi_t_switch('nlbw', tab);
+}
+
+function renderPeriods()
+{
+ var sel = document.getElementById('nlbw.period');
+
+ for (var e, i = trafficPeriods.length - 1; e = trafficPeriods[i]; i--) {
+ var d1 = new Date(e);
+ var d2, pd;
+
+ if (i) {
+ d2 = new Date(trafficPeriods[i - 1]);
+ d2.setDate(d2.getDate() - 1);
+ pd = '%04d-%02d-%02d'.format(d1.getFullYear(), d1.getMonth() + 1, d1.getDate());
+ }
+ else {
+ d2 = new Date();
+ pd = '';
+ }
+
+ var opt = document.createElement('option');
+ opt.setAttribute('data-duration', (d2.getTime() - d1.getTime()) / 1000);
+ opt.value = pd;
+ opt.text = '%04d-%02d-%02d - %04d-%02d-%02d'.format(
+ d1.getFullYear(), d1.getMonth() + 1, d1.getDate(),
+ d2.getFullYear(), d2.getMonth() + 1, d2.getDate());
+
+ sel.appendChild(opt);
+ }
+
+ sel.selectedIndex = sel.childNodes.length - 1;
+ sel.style.display = '';
+
+ sel.onchange = function() {
+ bubbleDismiss();
+ fetchData(sel.options[sel.selectedIndex].value);
+ }
+}
+
+function renderHostDetail()
+{
+ var key = this.getAttribute('href').substr(1),
+ col = this.getAttribute('data-col'),
+ label = this.getAttribute('data-label'),
+ bubble = document.getElementById('detail-bubble'),
+ arrow = document.getElementById('bubble-arrow'),
+ table = document.getElementById('bubble-table');
+
+ bubbleDismiss();
+
+ var detailData = query(
+ function(c, r) {
+ return ((r[c.mac] === key || r[c.ip] === key) &&
+ (r[c.rx_bytes] > 0 || r[c.tx_bytes] > 0));
+ },
+ [col],
+ function(r1, r2) {
+ return ((r2.rx_bytes + r2.tx_bytes) - (r1.rx_bytes + r1.tx_bytes));
+ }
+ );
+
+ var rxData = [], txData = [];
+
+ table.innerHTML = '<tr>' +
+ '<th>%s</th>'.format(label || col) +
+ '<th><%:Conn.%></th>' +
+ '<th colspan="2"><%:Down. (Bytes / Pkts.)%></th>' +
+ '<th colspan="2"><%:Up. (Bytes / Pkts.)%></th>' +
+ '</tr>';
+
+ for (var i = 0; i < detailData.length; i++) {
+ var rec = detailData[i],
+ row = table.insertRow(-1);
+
+ row.insertCell(-1).innerHTML = rec[col] || '<%:other%>';
+ row.insertCell(-1).innerHTML = "%1000.2m".format(rec.conns);
+ row.insertCell(-1).innerHTML = "%1024.2mB".format(rec.rx_bytes);
+ row.insertCell(-1).innerHTML = "%1000.2mP".format(rec.rx_pkts);
+ row.insertCell(-1).innerHTML = "%1024.2mB".format(rec.tx_bytes);
+ row.insertCell(-1).innerHTML = "%1000.2mP".format(rec.tx_pkts);
+
+ rxData.push({
+ label: ['%s: %%1024.2mB'.format(rec[col] || '<%:other%>'), row],
+ value: rec.rx_bytes
+ });
+
+ txData.push({
+ label: ['%s: %%1024.2mB'.format(rec[col] || '<%:other%>'), row],
+ value: rec.tx_bytes
+ });
+ }
+
+ pie('bubble-pie1', rxData);
+ pie('bubble-pie2', txData);
+
+ var mac = key.toUpperCase();
+ var name = hostInfo.hasOwnProperty(mac) ? hostInfo[mac].name : null;
+
+ if (!name)
+ for (var i = 0; i < detailData.length; i++)
+ if ((name = hostNames[detailData[i].ip]) !== undefined)
+ break;
+
+ if (mac !== '00:00:00:00:00:00') {
+ kpi('bubble-hostname', name);
+ kpi('bubble-vendor', oui(mac));
+ }
+ else {
+ kpi('bubble-hostname');
+ kpi('bubble-vendor');
+ }
+
+ var tr = this.parentNode.parentNode,
+ xy = off(tr),
+ xy2 = off(this);
+
+ bubble.style.width = tr.offsetWidth + 'px';
+ bubble.style.left = xy[0] + 'px';
+ bubble.style.top = (xy[1] + tr.offsetHeight) + 'px';
+ arrow.style.left = Math.floor(xy2[0] + this.offsetWidth / 2 - xy[0]) + 'px';
+
+ bubble.className = 'in';
+
+ return false;
+}
+
+function formatHostname(dns)
+{
+ if (dns === undefined || dns === null || dns === '')
+ return '-';
+
+ dns = dns.split('.')[0];
+
+ if (dns.length > 12)
+ return '<span title="%q">%h…</span>'.format(dns, dns.substr(0, 12));
+
+ return '%h'.format(dns);
+}
+
+function renderHostData()
+{
+ var trafData = [], connData = [];
+ var rx_total = 0, tx_total = 0, conn_total = 0;
+ var table = document.getElementById('host-data');
+
+ var hostData = query(
+ function(c, r) {
+ return (r[c.rx_bytes] > 0 || r[c.tx_bytes] > 0);
+ },
+ ['mac'],
+ //function(c, r) {
+ // return (r[c.mac] !== '00:00:00:00:00:00') ? r[c.mac] : r[c.ip];
+ //},
+ function(r1, r2) {
+ return ((r2.rx_bytes + r2.tx_bytes) - (r1.rx_bytes + r1.tx_bytes));
+ }
+ );
+
+ while (table.rows.length > 1)
+ table.deleteRow(1);
+
+ for (var i = 0; i < hostData.length; i++) {
+ var row = table.insertRow(-1),
+ cell = row.insertCell(-1),
+ rec = hostData[i],
+ mac = rec.mac.toUpperCase(),
+ key = (mac !== '00:00:00:00:00:00') ? mac : rec.ip,
+ dns = hostInfo[mac] ? hostInfo[mac].name : null;
+
+ var link1 = document.createElement('a');
+ link1.onclick = renderHostDetail;
+ link1.href = '#' + rec.mac;
+ link1.setAttribute('data-col', 'ip');
+ link1.setAttribute('data-label', '<%:Source IP%>');
+ link1.innerHTML = (mac !== '00:00:00:00:00:00') ? mac : '<%:other%>';
+
+ var link2 = document.createElement('a');
+ link2.onclick = renderHostDetail;
+ link2.href = '#' + rec.mac;
+ link2.setAttribute('data-col', 'layer7');
+ link2.setAttribute('data-label', '<%:Protocol%>');
+ link2.innerHTML = "%1000.2m".format(rec.conns);
+
+ cell.innerHTML = formatHostname(dns);
+ cell.className = 'hostname';
+
+ row.insertCell(-1).appendChild(link1);
+ row.insertCell(-1).appendChild(link2);
+ row.insertCell(-1).innerHTML = "%1024.2mB".format(rec.rx_bytes);
+ row.insertCell(-1).innerHTML = "%1000.2mP".format(rec.rx_pkts);
+ row.insertCell(-1).innerHTML = "%1024.2mB".format(rec.tx_bytes);
+ row.insertCell(-1).innerHTML = "%1000.2mP".format(rec.tx_pkts);
+
+ trafData.push({
+ value: rec.rx_bytes + rec.tx_bytes,
+ label: ["%s: %%.2mB".format(key), row]
+ });
+
+ connData.push({
+ value: rec.conns,
+ label: ["%s: %%.2m".format(key), row]
+ });
+
+ rx_total += rec.rx_bytes;
+ tx_total += rec.tx_bytes;
+ conn_total += rec.conns;
+ }
+
+ if (table.rows.length === 1) {
+ var cell = table.insertRow(-1).insertCell(-1);
+
+ cell.setAttribute('colspan', 6);
+ cell.innerHTML = '<em><%:No data recorded yet.%> <a href="<%=url("admin/nlbw/commit")%>"><%:Force reload…%></a></em>';
+ }
+
+ pie('traf-pie', trafData);
+ pie('conn-pie', connData);
+
+ kpi('rx-total', '%1024.2mB'.format(rx_total));
+ kpi('tx-total', '%1024.2mB'.format(tx_total));
+ kpi('conn-total', '%1000m'.format(conn_total));
+ kpi('host-total', '%u'.format(hostData.length));
+}
+
+function renderLayer7Data()
+{
+ var rxData = [], txData = [];
+ var topConn = [[0],[0],[0]], topRx = [[0],[0],[0]], topTx = [[0],[0],[0]];
+ var table = document.getElementById('layer7-data');
+
+ var layer7Data = query(
+ null, ['layer7'],
+ function(r1, r2) {
+ return ((r2.rx_bytes + r2.tx_bytes) - (r1.rx_bytes + r1.tx_bytes));
+ }
+ );
+
+ while (table.rows.length > 1)
+ table.deleteRow(1);
+
+ for (var i = 0, c = 0; i < layer7Data.length; i++) {
+ var rec = layer7Data[i],
+ row = table.insertRow(-1);
+
+ rxData.push({
+ value: rec.rx_bytes,
+ label: ["%s: %%.2mB".format(rec.layer7 || '<%:other%>'), row]
+ });
+
+ txData.push({
+ value: rec.tx_bytes,
+ label: ["%s: %%.2mB".format(rec.layer7 || '<%:other%>'), row]
+ });
+
+ row.insertCell(-1).innerHTML = rec.layer7 || '<%:other%>';
+ row.insertCell(-1).innerHTML = "%1000m".format(rec.conns);
+ row.insertCell(-1).innerHTML = "%1024.2mB".format(rec.rx_bytes);
+ row.insertCell(-1).innerHTML = "%1000.2mP".format(rec.rx_pkts);
+ row.insertCell(-1).innerHTML = "%1024.2mB".format(rec.tx_bytes);
+ row.insertCell(-1).innerHTML = "%1000.2mP".format(rec.tx_pkts);
+
+ if (rec.layer7) {
+ topRx.push([rec.rx_bytes, rec.layer7]);
+ topTx.push([rec.tx_bytes, rec.layer7]);
+ topConn.push([rec.conns, rec.layer7]);
+ }
+ }
+
+ if (table.rows.length === 1) {
+ var cell = table.insertRow(-1).insertCell(-1);
+
+ cell.setAttribute('colspan', 6);
+ cell.innerHTML = '<em><%:No data recorded yet.%> <a href="<%=url("admin/nlbw/commit")%>"><%:Force reload…%></a></em>';
+ }
+
+ pie('layer7-rx-pie', rxData);
+ pie('layer7-tx-pie', txData);
+
+ topRx.sort(function(a, b) { return b[0] - a[0] });
+ topTx.sort(function(a, b) { return b[0] - a[0] });
+ topConn.sort(function(a, b) { return b[0] - a[0] });
+
+ kpi('layer7-total', layer7Data.length);
+ kpi('layer7-most-rx', topRx[0][1], topRx[1][1], topRx[2][1]);
+ kpi('layer7-most-tx', topTx[0][1], topTx[1][1], topTx[2][1]);
+ kpi('layer7-most-conn', topConn[0][1], topConn[1][1], topConn[2][1]);
+}
+
+function renderIPv6Data()
+{
+ var table = document.getElementById('ipv6-data'),
+ col = { },
+ rx4_total = 0,
+ tx4_total = 0,
+ rx6_total = 0,
+ tx6_total = 0,
+ v4_total = 0,
+ v6_total = 0,
+ ds_total = 0,
+ families = { },
+ records = { };
+
+ ipv6Data = query(
+ null, ['family', 'mac'],
+ function(r1, r2) {
+ return ((r2.rx_bytes + r2.tx_bytes) - (r1.rx_bytes + r1.tx_bytes));
+ }
+ );
+
+ for (var i = 0, c = 0; i < ipv6Data.length; i++) {
+ var rec = ipv6Data[i],
+ mac = rec.mac.toUpperCase(),
+ ip = rec.ip,
+ fam = families[mac] || 0,
+ recs = records[mac] || {};
+
+ if (rec.family == 4) {
+ rx4_total += rec.rx_bytes;
+ tx4_total += rec.tx_bytes;
+ fam |= 1;
+ }
+ else {
+ rx6_total += rec.rx_bytes;
+ tx6_total += rec.tx_bytes;
+ fam |= 2;
+ }
+
+ recs[rec.family] = rec;
+ records[mac] = recs;
+
+ families[mac] = fam;
+ }
+
+ for (var mac in families) {
+ switch (families[mac])
+ {
+ case 3:
+ ds_total++;
+ break;
+
+ case 2:
+ v6_total++;
+ break;
+
+ case 1:
+ v4_total++;
+ break;
+ }
+ }
+
+ while (table.rows.length > 1)
+ table.deleteRow(1);
+
+ for (var mac in records) {
+ if (mac === '00:00:00:00:00:00')
+ continue;
+
+ var row = table.insertRow(-1),
+ cell1 = row.insertCell(-1),
+ cell2 = row.insertCell(-1),
+ dns = hostInfo[mac] ? hostInfo[mac].name : null,
+ rec4 = records[mac][4],
+ rec6 = records[mac][6];
+
+ cell1.setAttribute('rowspan', 2);
+ cell1.innerHTML = formatHostname(dns);
+ cell1.className = 'hostname';
+
+ cell2.setAttribute('rowspan', 2);
+ cell2.innerHTML = mac;
+
+ row.insertCell(-1).innerHTML = 'IPv4';
+ row.insertCell(-1).innerHTML = rec4 ? "%1024.2mB".format(rec4.rx_bytes) : '-';
+ row.insertCell(-1).innerHTML = rec4 ? "%1000.2mP".format(rec4.rx_pkts) : '-';
+ row.insertCell(-1).innerHTML = rec4 ? "%1024.2mB".format(rec4.tx_bytes) : '-';
+ row.insertCell(-1).innerHTML = rec4 ? "%1000.2mP".format(rec4.tx_pkts) : '-';
+
+ row = table.insertRow(-1);
+
+ row.insertCell(-1).innerHTML = 'IPv6';
+ row.insertCell(-1).innerHTML = rec6 ? "%1024.2mB".format(rec6.rx_bytes) : '-';
+ row.insertCell(-1).innerHTML = rec6 ? "%1000.2mP".format(rec6.rx_pkts) : '-';
+ row.insertCell(-1).innerHTML = rec6 ? "%1024.2mB".format(rec6.tx_bytes) : '-';
+ row.insertCell(-1).innerHTML = rec6 ? "%1000.2mP".format(rec6.tx_pkts) : '-';
+ }
+
+ if (table.rows.length === 1) {
+ var cell = table.insertRow(-1).insertCell(-1);
+
+ cell.setAttribute('colspan', 7);
+ cell.innerHTML = '<em><%:No data recorded yet.%> <a href="<%=url("admin/nlbw/commit")%>"><%:Force reload…%></a></em>';
+ }
+
+ var shareData = [], hostsData = [];
+
+ if (rx4_total > 0 || tx4_total > 0)
+ shareData.push({
+ value: rx4_total + tx4_total,
+ label: ["IPv4: %.2mB"],
+ color: 'hsl(140, 100%, 50%)'
+ });
+
+ if (rx6_total > 0 || tx6_total > 0)
+ shareData.push({
+ value: rx6_total + tx6_total,
+ label: ["IPv6: %.2mB"],
+ color: 'hsl(180, 100%, 50%)'
+ });
+
+ if (v4_total > 0)
+ hostsData.push({
+ value: v4_total,
+ label: ["<%:%d IPv4-only hosts%>"],
+ color: 'hsl(140, 100%, 50%)'
+ });
+
+ if (v6_total > 0)
+ hostsData.push({
+ value: v6_total,
+ label: ["<%:%d IPv6-only hosts%>"],
+ color: 'hsl(180, 100%, 50%)'
+ });
+
+ if (ds_total > 0)
+ hostsData.push({
+ value: ds_total,
+ label: ["<%:%d dual-stack hosts%>"],
+ color: 'hsl(50, 100%, 50%)'
+ });
+
+ pie('ipv6-share-pie', shareData);
+ pie('ipv6-hosts-pie', hostsData);
+
+ kpi('ipv6-hosts', '%.2f%%'.format(100 / (ds_total + v4_total + v6_total) * (ds_total + v6_total)));
+ kpi('ipv6-share', '%.2f%%'.format(100 / (rx4_total + rx6_total + tx4_total + tx6_total) * (rx6_total + tx6_total)));
+ kpi('ipv6-rx', '%1024.2mB'.format(rx6_total));
+ kpi('ipv6-tx', '%1024.2mB'.format(tx6_total));
+}
+
+function bubbleDismiss()
+{
+ var bubble = document.getElementById('detail-bubble');
+
+ bubble.className = '';
+ document.body.appendChild(bubble);
+
+ return false;
+}
+
+
+//]]></script>
+
+<h2 name="content"><%:Netlink Bandwidth Monitor%></h2>
+
+<div id="detail-bubble">
+ <span id="bubble-arrow"></span>
+ <div>
+ <div class="head">
+ <a class="dismiss" href="#" onclick="this.blur(); return bubbleDismiss()">×</a>
+ <div class="pie">
+ <label>Download</label>
+ <canvas id="bubble-pie1" width="100" height="100"></canvas>
+ </div>
+ <div class="pie">
+ <label>Upload</label>
+ <canvas id="bubble-pie2" width="100" height="100"></canvas>
+ </div>
+ <div class="kpi">
+ <ul>
+ <li><%_Hostname: <big id="bubble-hostname">example.org</big>%></li>
+ <li><%_Vendor: <big id="bubble-vendor">Example Corp.</big>%></li>
+ </ul>
+ </div>
+ </div>
+ <table id="bubble-table"></table>
+ </div>
+</div>
+
+<hr>
+
+<p>
+ <%:Select accounting period:%>
+ <select id="nlbw.period" style="display:none"></select>
+</p>
+
+<hr>
+
+<ul class="cbi-tabmenu">
+ <li id="tab.nlbw.traffic" class="cbi-tab"><a href="#" onclick="return switchTab('traffic')"><%:Traffic Distribution%></a></li>
+ <li id="tab.nlbw.layer7" class="cbi-tab-disabled"><a href="#" onclick="return switchTab('layer7')"><%:Application Protocols%></a></li>
+ <li id="tab.nlbw.ipv6" class="cbi-tab-disabled"><a href="#" onclick="return switchTab('ipv6')"><%:IPv6%></a></li>
+ <li id="tab.nlbw.export" class="cbi-tab-disabled"><a href="#" onclick="return switchTab('export')"><%:Export%></a></li>
+</ul>
+
+<div class="cbi-section" id="container.nlbw.traffic">
+ <div>
+ <div class="pie">
+ <label><%:Traffic / Host%></label>
+ <canvas id="traf-pie" width="200" height="200"></canvas>
+ </div>
+
+ <div class="pie">
+ <label><%:Connections / Host%></label>
+ <canvas id="conn-pie" width="200" height="200"></canvas>
+ </div>
+
+ <div class="kpi">
+ <ul>
+ <li><%_<big id="host-total">0</big> hosts%></li>
+ <li><%_<big id="rx-total">0</big> download%></li>
+ <li><%_<big id="tx-total">0</big> upload%></li>
+ <li><%_<big id="conn-total">0</big> connections%></li>
+ </ul>
+ </div>
+ </div>
+ <table id="host-data">
+ <tr>
+ <th width="10%" class="hostname"><%:Host%></th>
+ <th width="5%"><%:MAC%></th>
+ <th width="5%"><%:Connections%></th>
+ <th width="30%" colspan="2"><%:Download (Bytes / Packets)%></th>
+ <th width="30%" colspan="2"><%:Upload (Bytes / Packets)%></th>
+ </tr>
+ </table>
+</div>
+
+<div class="cbi-section" id="container.nlbw.layer7" style="display:none">
+ <div>
+ <div class="pie">
+ <label><%:Download / Application%></label>
+ <canvas id="layer7-rx-pie" width="200" height="200"></canvas>
+ </div>
+
+ <div class="pie">
+ <label><%:Upload / Application%></label>
+ <canvas id="layer7-tx-pie" width="200" height="200"></canvas>
+ </div>
+
+ <div class="kpi">
+ <ul>
+ <li><%_<big id="layer7-total">0</big> different application protocols%></li>
+ <li><%_<big id="layer7-most-rx">0</big> cause the most download%></li>
+ <li><%_<big id="layer7-most-tx">0</big> cause the most upload%></li>
+ <li><%_<big id="layer7-most-conn">0</big> cause the most connections%></li>
+ </ul>
+ </div>
+ </div>
+ <table id="layer7-data">
+ <tr>
+ <th width="20%"><%:Application%></th>
+ <th width="10%"><%:Connections%></th>
+ <th width="30%" colspan="2"><%:Download (Bytes / Packets)%></th>
+ <th width="30%" colspan="2"><%:Upload (Bytes / Packets)%></th>
+ </tr>
+ </table>
+</div>
+
+<div class="cbi-section" id="container.nlbw.ipv6" style="display:none">
+ <div>
+ <div class="pie">
+ <label><%:IPv4 vs. IPv6%></label>
+ <canvas id="ipv6-share-pie" width="200" height="200"></canvas>
+ </div>
+
+ <div class="pie">
+ <label><%:Dualstack enabled hosts%></label>
+ <canvas id="ipv6-hosts-pie" width="200" height="200"></canvas>
+ </div>
+
+ <div class="kpi">
+ <ul>
+ <li><%_<big id="ipv6-hosts">0%</big> IPv6 support rate among hosts%></li>
+ <li><%_<big id="ipv6-share">0%</big> of the total traffic is IPv6%></li>
+ <li><%_<big id="ipv6-rx">0B</big> total IPv6 download%></li>
+ <li><%_<big id="ipv6-tx">0B</big> total IPv6 upload%></li>
+ </ul>
+ </div>
+ </div>
+ <table id="ipv6-data">
+ <tr>
+ <th width="10%" class="hostname"><%:Host%></th>
+ <th width="5%"><%:MAC%></th>
+ <th width="5%"><%:Family%></th>
+ <th width="40%" colspan="2"><%:Download (Bytes / Packets)%></th>
+ <th width="40%" colspan="2"><%:Upload (Bytes / Packets)%></th>
+ </tr>
+ </table>
+</div>
+
+<div class="cbi-section" id="container.nlbw.export" style="display:none">
+ <ul>
+ <li><a href="<%=url('admin/nlbw/data')%>?type=csv&#38;group_by=mac&#38;order_by=-rx,-tx"><%:CSV, grouped by MAC%></a></li>
+ <li><a href="<%=url('admin/nlbw/data')%>?type=csv&#38;group_by=ip&#38;order_by=-rx,-tx"><%:CSV, grouped by IP%></a></li>
+ <li><a href="<%=url('admin/nlbw/data')%>?type=csv&#38;group_by=layer7&#38;order_by=-rx,-tx"><%:CSV, grouped by protocol%></a></li>
+ <li><a href="<%=url('admin/nlbw/data')%>?type=json"><%:JSON dump%></a></li>
+ </ul>
+</div>
+
+<script type="text/javascript">//<![CDATA[
+ cbi_t_add('nlbw', 'traffic');
+ cbi_t_add('nlbw', 'layer7');
+ cbi_t_add('nlbw', 'ipv6');
+ cbi_t_add('nlbw', 'export');
+
+ XHR.get('<%=url("admin/nlbw/list")%>', null, function(xhr, res) {
+
+ if (res !== null && typeof(res) === 'object' && res.length > 0) {
+ trafficPeriods = res;
+ renderPeriods();
+ }
+
+ xhr.open('GET', 'https://raw.githubusercontent.com/jow-/oui-database/master/oui.json', true);
+ xhr.onreadystatechange = function() {
+ if (xhr.readyState === 4) {
+ try { res = JSON.parse(xhr.responseText); }
+ catch(e) { res = null; }
+
+ if (res !== null && typeof(res) === 'object' && (res.length % 3) === 0)
+ ouiData = res;
+
+ fetchData('');
+ }
+ };
+ xhr.send(null);
+ });
+//]]></script>
+
+<%+footer%>
diff --git a/applications/luci-app-nlbwmon/po/ja/nlbwmon.po b/applications/luci-app-nlbwmon/po/ja/nlbwmon.po
new file mode 100644
index 0000000000..b5931e0dfe
--- /dev/null
+++ b/applications/luci-app-nlbwmon/po/ja/nlbwmon.po
@@ -0,0 +1,387 @@
+msgid ""
+msgstr ""
+"Content-Type: text/plain; charset=UTF-8\n"
+"Project-Id-Version: \n"
+"POT-Creation-Date: \n"
+"PO-Revision-Date: \n"
+"Last-Translator: INAGAKI Hiroshi <musashino.open@gmail.com>\n"
+"Language-Team: \n"
+"MIME-Version: 1.0\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Language: ja\n"
+"X-Generator: Poedit 2.0.3\n"
+
+msgid "%d IPv4-only hosts"
+msgstr "%d IPv4 限定ホスト"
+
+msgid "%d IPv6-only hosts"
+msgstr "%d IPv6 限定ホスト"
+
+msgid "%d dual-stack hosts"
+msgstr "%d デュアルスタック ホスト"
+
+msgid "%s and %s"
+msgstr "%s, %s"
+
+msgid "%s, %s and %s"
+msgstr "%s, %s, %s"
+
+msgid "-1 - Restart every last day of month"
+msgstr "-1 - 月の最終日"
+
+msgid "-7 - Restart a week before end of month"
+msgstr "-7 - 月の最終日の一週間前"
+
+msgid "1 - Restart every 1st of month"
+msgstr "1 - 毎月1日"
+
+msgid "10m - frequent commits at the expense of flash wear"
+msgstr "10m - フラッシュ媒体への負荷が高い頻繁なコミット(10分)"
+
+msgid "12h - compromise between risk of data loss and flash wear"
+msgstr "12h - データ消失リスクとフラッシュ媒体への負荷の妥協点(12時間)"
+
+msgid "24h - least flash wear at the expense of data loss risk"
+msgstr "24h - データ消失リスクは高いがフラッシュ媒体への負荷は最小(24時間)"
+
+msgid "30s - refresh twice per minute for reasonably current stats"
+msgstr "30s - 現在の状態の把握に適切な1分間に2回のリフレッシュ(30秒)"
+
+msgid "5m - rarely refresh to avoid frequently clearing conntrack counters"
+msgstr ""
+
+msgid "60s - commit minutely, useful for non-flash storage"
+msgstr "60秒 - 1分毎のコミット、非フラッシュ ストレージに有用"
+
+msgid "<big id=\"conn-total\">0</big> connections"
+msgstr "<big id=\"conn-total\">0</big> 接続数"
+
+msgid "<big id=\"host-total\">0</big> hosts"
+msgstr "<big id=\"host-total\">0</big> ホスト数"
+
+msgid "<big id=\"ipv6-hosts\">0%</big> IPv6 support rate among hosts"
+msgstr "<big id=\"ipv6-hosts\">0%</big> 全ホスト中の IPv6 サポート比率"
+
+msgid "<big id=\"ipv6-rx\">0B</big> total IPv6 download"
+msgstr "<big id=\"ipv6-rx\">0B</big> IPv6 総ダウンロード"
+
+msgid "<big id=\"ipv6-share\">0%</big> of the total traffic is IPv6"
+msgstr "<big id=\"ipv6-share\">0%</big> 全トラフィック中の IPv6 の割合"
+
+msgid "<big id=\"ipv6-tx\">0B</big> total IPv6 upload"
+msgstr "<big id=\"ipv6-tx\">0B</big> IPv6 総アップロード"
+
+msgid "<big id=\"layer7-most-conn\">0</big> cause the most connections"
+msgstr "<big id=\"layer7-most-conn\">0</big> 接続数上位"
+
+msgid "<big id=\"layer7-most-rx\">0</big> cause the most download"
+msgstr "<big id=\"layer7-most-rx\">0</big> ダウンロード上位"
+
+msgid "<big id=\"layer7-most-tx\">0</big> cause the most upload"
+msgstr "<big id=\"layer7-most-tx\">0</big> アップロード上位"
+
+msgid "<big id=\"layer7-total\">0</big> different application protocols"
+msgstr "<big id=\"layer7-total\">0</big> アプリケーション プロトコル数"
+
+msgid "<big id=\"rx-total\">0</big> download"
+msgstr "<big id=\"rx-total\">0</big> ダウンロード"
+
+msgid "<big id=\"tx-total\">0</big> upload"
+msgstr "<big id=\"tx-total\">0</big> アップロード"
+
+msgid "Accounting period"
+msgstr "収集期間"
+
+msgid "Advanced Settings"
+msgstr "拡張設定"
+
+msgid "Application"
+msgstr "アプリケーション"
+
+msgid "Application Protocols"
+msgstr "アプリケーション プロトコル"
+
+msgid "Backup"
+msgstr "バックアップ"
+
+msgid "Bandwidth Monitor"
+msgstr "帯域幅モニター"
+
+msgid "CSV, grouped by IP"
+msgstr "CSV(IP によるグループ化)"
+
+msgid "CSV, grouped by MAC"
+msgstr "CSV(MAC によるグループ化)"
+
+msgid "CSV, grouped by protocol"
+msgstr "CSV(プロトコルによるグループ化)"
+
+msgid ""
+"Changing the accounting interval type will invalidate existing databases!"
+"<br /><strong><a href=\"%s\">Download backup</a></strong>."
+msgstr ""
+"既存のデータベースと互換性の無い収集期間の形式が選択されました。<br /"
+"><strong><a href=\"%s\">バックアップのダウンロード</a></strong>"
+
+msgid ""
+"Choose \"Day of month\" to restart the accounting period monthly on a "
+"specific date, e.g. every 3rd. Choose \"Fixed interval\" to restart the "
+"accounting period exactly every N days, beginning at a given date."
+msgstr ""
+"月毎で設定した日付からのデータの計測を行うには、 \"月間\" を選択します(例: "
+"毎月3日)。設定した日数毎にデータの収集を行うには、\"特定の間隔\" を選択しま"
+"す。後者の場合、指定された日付から開始されます。"
+
+msgid "Commit interval"
+msgstr "コミット間隔"
+
+msgid "Compress database"
+msgstr "データベースの圧縮"
+
+msgid "Configuration"
+msgstr "設定"
+
+msgid "Conn."
+msgstr "接続数"
+
+msgid "Connections"
+msgstr "接続数"
+
+msgid "Connections / Host"
+msgstr "ホスト毎の接続数"
+
+msgid "Database directory"
+msgstr "データベース ディレクトリ"
+
+msgid ""
+"Database storage directory. One file per accounting period will be placed "
+"into this directory."
+msgstr ""
+"データベースの保存先ディレクトリです。計測期間あたり 1 つのファイルがこのディ"
+"レクトリに配置されます。"
+
+msgid "Day of month"
+msgstr "月間"
+
+msgid ""
+"Day of month to restart the accounting period. Use negative values to count "
+"towards the end of month, e.g. \"-5\" to specify the 27th of July or the "
+"24th of Februrary."
+msgstr ""
+"月の中で新たな収集期間を開始する日です。月の最終日からの日数をマイナス値で指"
+"定することができます(例: 7月27日または2月24日は \"-5\")。"
+
+msgid "Display"
+msgstr "表示"
+
+msgid "Down. (Bytes / Pkts.)"
+msgstr "ダウンロード(Bytes / Pkts.)"
+
+msgid "Download (Bytes / Packets)"
+msgstr "ダウンロード(Bytes / Packets)"
+
+msgid "Download / Application"
+msgstr "ダウンロード / アプリケーション"
+
+msgid "Download Database Backup"
+msgstr "データベース バックアップのダウンロード"
+
+msgid "Dualstack enabled hosts"
+msgstr "デュアルスタック ホスト"
+
+msgid "Due date"
+msgstr "期日"
+
+msgid "Export"
+msgstr "エクスポート"
+
+msgid "Family"
+msgstr "IP 種別"
+
+msgid "Fixed interval"
+msgstr "特定の間隔"
+
+msgid "Force reload…"
+msgstr "強制リロード..."
+
+msgid "General Settings"
+msgstr "全般設定"
+
+msgid "Generate Backup"
+msgstr "バックアップの作成"
+
+msgid "Host"
+msgstr "ホスト"
+
+msgid "Hostname: <big id=\"bubble-hostname\">example.org</big>"
+msgstr "ホスト名: <big id=\"bubble-hostname\">example.org</big>"
+
+msgid "IPv4 vs. IPv6"
+msgstr "IPv4 及び IPv6"
+
+msgid "IPv6"
+msgstr "IPv6"
+
+msgid "Interval"
+msgstr "間隔"
+
+msgid ""
+"Interval at which the temporary in-memory database is committed to the "
+"persistent database directory."
+msgstr ""
+"メモリー上の一時的なデータベースから、永続的なデータベース ディレクトリへのコ"
+"ミットを実行する間隔です。"
+
+msgid ""
+"Interval at which traffic counters of still established connections are "
+"refreshed from netlink information."
+msgstr ""
+
+msgid "Invalid or empty backup archive"
+msgstr "無効または空のバックアップ アーカイブです。"
+
+msgid "JSON dump"
+msgstr "JSON ダンプ"
+
+msgid "Length of accounting interval in days."
+msgstr "収集期間の日数です。"
+
+msgid "Local interfaces"
+msgstr "ローカル インターフェース"
+
+msgid "Local subnets"
+msgstr "ローカル サブネット"
+
+msgid "MAC"
+msgstr "MAC"
+
+msgid "Maximum entries"
+msgstr "最大件数"
+
+msgid ""
+"Maximum number of accounting periods to keep, use zero to keep databases "
+"forever."
+msgstr ""
+"計測データを保持する、収集期間の最大個数です。 '0' を設定した場合、全データを"
+"保持します。"
+
+msgid "Netlink Bandwidth Monitor"
+msgstr "Netlink Bandwidth Monitor"
+
+msgid "Netlink Bandwidth Monitor - Backup / Restore"
+msgstr "Netlink Bandwidth Monitor - バックアップ / 復元"
+
+msgid "Netlink Bandwidth Monitor - Configuration"
+msgstr "Netlink Bandwidth Monitor - 設定"
+
+msgid "No data recorded yet."
+msgstr "まだデータがありません。"
+
+msgid "Only conntrack streams from or to any of these networks are counted."
+msgstr ""
+"選択されたネットワークにおける conntrack ストリームのみが計測されます。"
+
+msgid "Only conntrack streams from or to any of these subnets are counted."
+msgstr "設定されたサブネットにおける conntrack ストリームのみが計測されます。"
+
+msgid "Preallocate database"
+msgstr "データベースの事前割当"
+
+msgid "Protocol"
+msgstr "プロトコル"
+
+msgid "Protocol Mapping"
+msgstr "プロトコル マッピング"
+
+msgid ""
+"Protocol mappings to distinguish traffic types per host, one mapping per "
+"line. The first value specifies the IP protocol, the second value the port "
+"number and the third column is the name of the mapped protocol."
+msgstr ""
+"ホスト毎のトラフィック形式を区別するためのプロトコル マッピングで、一行あたり"
+"一つのマッピングを追加します。各エントリーの一つ目の値は IP プロトコルを、2つ"
+"目の値はポート番号、3つ目はマッピングされたプロトコルの名前をそれぞれ表しま"
+"す。"
+
+msgid "Refresh interval"
+msgstr "リフレッシュ間隔"
+
+msgid "Restore"
+msgstr "復元"
+
+msgid "Restore Database Backup"
+msgstr "データベースの復元"
+
+msgid "Select accounting period:"
+msgstr "収集期間を選択:"
+
+msgid "Source IP"
+msgstr "アクセス元 IP"
+
+msgid "Start date"
+msgstr "開始日"
+
+msgid "Start date of the first accounting period, e.g. begin of ISP contract."
+msgstr "初回のデータ収集の開始日です(例: ISP 契約の開始日)。"
+
+msgid "Stored periods"
+msgstr "保存期間"
+
+msgid ""
+"The Netlink Bandwidth Monitor (nlbwmon) is a lightweight, efficient traffic "
+"accounting program keeping track of bandwidth usage per host and protocol."
+msgstr ""
+"Netlink Bandwidth Monitor (nlbwmon) は、軽量かつ、ホストやプロトコル毎に帯域"
+"幅使用量の追跡を行う効率的なトラフィック計測プログラムです。"
+
+msgid "The following database files have been restored: %s"
+msgstr "次のデータベース ファイルが復元されました: %s"
+
+msgid ""
+"The maximum amount of entries that should be put into the database, setting "
+"the limit to 0 will allow databases to grow indefinitely."
+msgstr ""
+"データベースに保管される最大件数です。 '0' を設定した場合、制限無しのデータ"
+"ベースの増大を許可します。"
+
+msgid "Traffic / Host"
+msgstr "トラフィック / ホスト"
+
+msgid "Traffic Distribution"
+msgstr "トラフィック内訳"
+
+msgid "Up. (Bytes / Pkts.)"
+msgstr "アップロード(Bytes / Pkts.)"
+
+msgid "Upload (Bytes / Packets)"
+msgstr "アップロード(Bytes / Packets)"
+
+msgid "Upload / Application"
+msgstr "アップロード / アプリケーション"
+
+msgid "Vendor: <big id=\"bubble-vendor\">Example Corp.</big>"
+msgstr "ベンダ: <big id=\"bubble-vendor\">Example Corp.</big>"
+
+msgid "Warning"
+msgstr "警告"
+
+msgid ""
+"Whether to gzip compress archive databases. Compressing the database files "
+"makes accessing old data slightly slower but helps to reduce storage "
+"requirements."
+msgstr ""
+"データベースの gzip 圧縮アーカイブ化です。データベース ファイルを圧縮すると古"
+"いデータへのアクセスが多少遅くなりますが、ストレージ使用量の低減に役立ちま"
+"す。"
+
+msgid ""
+"Whether to preallocate the maximum possible database size in memory. This is "
+"mainly useful for memory constrained systems which might not be able to "
+"satisfy memory allocation after longer uptime periods."
+msgstr ""
+
+msgid "no traffic"
+msgstr "トラフィック無し"
+
+msgid "other"
+msgstr "その他"
diff --git a/applications/luci-app-nlbwmon/po/templates/nlbwmon.pot b/applications/luci-app-nlbwmon/po/templates/nlbwmon.pot
new file mode 100644
index 0000000000..61d2230793
--- /dev/null
+++ b/applications/luci-app-nlbwmon/po/templates/nlbwmon.pot
@@ -0,0 +1,352 @@
+msgid ""
+msgstr "Content-Type: text/plain; charset=UTF-8"
+
+msgid "%d IPv4-only hosts"
+msgstr ""
+
+msgid "%d IPv6-only hosts"
+msgstr ""
+
+msgid "%d dual-stack hosts"
+msgstr ""
+
+msgid "%s and %s"
+msgstr ""
+
+msgid "%s, %s and %s"
+msgstr ""
+
+msgid "-1 - Restart every last day of month"
+msgstr ""
+
+msgid "-7 - Restart a week before end of month"
+msgstr ""
+
+msgid "1 - Restart every 1st of month"
+msgstr ""
+
+msgid "10m - frequent commits at the expense of flash wear"
+msgstr ""
+
+msgid "12h - compromise between risk of data loss and flash wear"
+msgstr ""
+
+msgid "24h - least flash wear at the expense of data loss risk"
+msgstr ""
+
+msgid "30s - refresh twice per minute for reasonably current stats"
+msgstr ""
+
+msgid "5m - rarely refresh to avoid frequently clearing conntrack counters"
+msgstr ""
+
+msgid "60s - commit minutely, useful for non-flash storage"
+msgstr ""
+
+msgid "<big id=\"conn-total\">0</big> connections"
+msgstr ""
+
+msgid "<big id=\"host-total\">0</big> hosts"
+msgstr ""
+
+msgid "<big id=\"ipv6-hosts\">0%</big> IPv6 support rate among hosts"
+msgstr ""
+
+msgid "<big id=\"ipv6-rx\">0B</big> total IPv6 download"
+msgstr ""
+
+msgid "<big id=\"ipv6-share\">0%</big> of the total traffic is IPv6"
+msgstr ""
+
+msgid "<big id=\"ipv6-tx\">0B</big> total IPv6 upload"
+msgstr ""
+
+msgid "<big id=\"layer7-most-conn\">0</big> cause the most connections"
+msgstr ""
+
+msgid "<big id=\"layer7-most-rx\">0</big> cause the most download"
+msgstr ""
+
+msgid "<big id=\"layer7-most-tx\">0</big> cause the most upload"
+msgstr ""
+
+msgid "<big id=\"layer7-total\">0</big> different application protocols"
+msgstr ""
+
+msgid "<big id=\"rx-total\">0</big> download"
+msgstr ""
+
+msgid "<big id=\"tx-total\">0</big> upload"
+msgstr ""
+
+msgid "Accounting period"
+msgstr ""
+
+msgid "Advanced Settings"
+msgstr ""
+
+msgid "Application"
+msgstr ""
+
+msgid "Application Protocols"
+msgstr ""
+
+msgid "Backup"
+msgstr ""
+
+msgid "Bandwidth Monitor"
+msgstr ""
+
+msgid "CSV, grouped by IP"
+msgstr ""
+
+msgid "CSV, grouped by MAC"
+msgstr ""
+
+msgid "CSV, grouped by protocol"
+msgstr ""
+
+msgid ""
+"Changing the accounting interval type will invalidate existing databases!"
+"<br /><strong><a href=\"%s\">Download backup</a></strong>."
+msgstr ""
+
+msgid ""
+"Choose \"Day of month\" to restart the accounting period monthly on a "
+"specific date, e.g. every 3rd. Choose \"Fixed interval\" to restart the "
+"accounting period exactly every N days, beginning at a given date."
+msgstr ""
+
+msgid "Commit interval"
+msgstr ""
+
+msgid "Compress database"
+msgstr ""
+
+msgid "Configuration"
+msgstr ""
+
+msgid "Conn."
+msgstr ""
+
+msgid "Connections"
+msgstr ""
+
+msgid "Connections / Host"
+msgstr ""
+
+msgid "Database directory"
+msgstr ""
+
+msgid ""
+"Database storage directory. One file per accounting period will be placed "
+"into this directory."
+msgstr ""
+
+msgid "Day of month"
+msgstr ""
+
+msgid ""
+"Day of month to restart the accounting period. Use negative values to count "
+"towards the end of month, e.g. \"-5\" to specify the 27th of July or the "
+"24th of Februrary."
+msgstr ""
+
+msgid "Display"
+msgstr ""
+
+msgid "Down. (Bytes / Pkts.)"
+msgstr ""
+
+msgid "Download (Bytes / Packets)"
+msgstr ""
+
+msgid "Download / Application"
+msgstr ""
+
+msgid "Download Database Backup"
+msgstr ""
+
+msgid "Dualstack enabled hosts"
+msgstr ""
+
+msgid "Due date"
+msgstr ""
+
+msgid "Export"
+msgstr ""
+
+msgid "Family"
+msgstr ""
+
+msgid "Fixed interval"
+msgstr ""
+
+msgid "Force reload…"
+msgstr ""
+
+msgid "General Settings"
+msgstr ""
+
+msgid "Generate Backup"
+msgstr ""
+
+msgid "Host"
+msgstr ""
+
+msgid "Hostname: <big id=\"bubble-hostname\">example.org</big>"
+msgstr ""
+
+msgid "IPv4 vs. IPv6"
+msgstr ""
+
+msgid "IPv6"
+msgstr ""
+
+msgid "Interval"
+msgstr ""
+
+msgid ""
+"Interval at which the temporary in-memory database is committed to the "
+"persistent database directory."
+msgstr ""
+
+msgid ""
+"Interval at which traffic counters of still established connections are "
+"refreshed from netlink information."
+msgstr ""
+
+msgid "Invalid or empty backup archive"
+msgstr ""
+
+msgid "JSON dump"
+msgstr ""
+
+msgid "Length of accounting interval in days."
+msgstr ""
+
+msgid "Local interfaces"
+msgstr ""
+
+msgid "Local subnets"
+msgstr ""
+
+msgid "MAC"
+msgstr ""
+
+msgid "Maximum entries"
+msgstr ""
+
+msgid ""
+"Maximum number of accounting periods to keep, use zero to keep databases "
+"forever."
+msgstr ""
+
+msgid "Netlink Bandwidth Monitor"
+msgstr ""
+
+msgid "Netlink Bandwidth Monitor - Backup / Restore"
+msgstr ""
+
+msgid "Netlink Bandwidth Monitor - Configuration"
+msgstr ""
+
+msgid "No data recorded yet."
+msgstr ""
+
+msgid "Only conntrack streams from or to any of these networks are counted."
+msgstr ""
+
+msgid "Only conntrack streams from or to any of these subnets are counted."
+msgstr ""
+
+msgid "Preallocate database"
+msgstr ""
+
+msgid "Protocol"
+msgstr ""
+
+msgid "Protocol Mapping"
+msgstr ""
+
+msgid ""
+"Protocol mappings to distinguish traffic types per host, one mapping per "
+"line. The first value specifies the IP protocol, the second value the port "
+"number and the third column is the name of the mapped protocol."
+msgstr ""
+
+msgid "Refresh interval"
+msgstr ""
+
+msgid "Restore"
+msgstr ""
+
+msgid "Restore Database Backup"
+msgstr ""
+
+msgid "Select accounting period:"
+msgstr ""
+
+msgid "Source IP"
+msgstr ""
+
+msgid "Start date"
+msgstr ""
+
+msgid "Start date of the first accounting period, e.g. begin of ISP contract."
+msgstr ""
+
+msgid "Stored periods"
+msgstr ""
+
+msgid ""
+"The Netlink Bandwidth Monitor (nlbwmon) is a lightweight, efficient traffic "
+"accounting program keeping track of bandwidth usage per host and protocol."
+msgstr ""
+
+msgid "The following database files have been restored: %s"
+msgstr ""
+
+msgid ""
+"The maximum amount of entries that should be put into the database, setting "
+"the limit to 0 will allow databases to grow indefinitely."
+msgstr ""
+
+msgid "Traffic / Host"
+msgstr ""
+
+msgid "Traffic Distribution"
+msgstr ""
+
+msgid "Up. (Bytes / Pkts.)"
+msgstr ""
+
+msgid "Upload (Bytes / Packets)"
+msgstr ""
+
+msgid "Upload / Application"
+msgstr ""
+
+msgid "Vendor: <big id=\"bubble-vendor\">Example Corp.</big>"
+msgstr ""
+
+msgid "Warning"
+msgstr ""
+
+msgid ""
+"Whether to gzip compress archive databases. Compressing the database files "
+"makes accessing old data slightly slower but helps to reduce storage "
+"requirements."
+msgstr ""
+
+msgid ""
+"Whether to preallocate the maximum possible database size in memory. This is "
+"mainly useful for memory constrained systems which might not be able to "
+"satisfy memory allocation after longer uptime periods."
+msgstr ""
+
+msgid "no traffic"
+msgstr ""
+
+msgid "other"
+msgstr ""
diff --git a/applications/luci-app-nlbwmon/root/etc/uci-defaults/40_luci-nlbwmon b/applications/luci-app-nlbwmon/root/etc/uci-defaults/40_luci-nlbwmon
new file mode 100644
index 0000000000..c9771779ee
--- /dev/null
+++ b/applications/luci-app-nlbwmon/root/etc/uci-defaults/40_luci-nlbwmon
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+uci -q batch <<-EOF >/dev/null
+ delete ucitrack.@nlbwmon[-1]
+ add ucitrack nlbwmon
+ set ucitrack.@nlbwmon[-1].init=nlbwmon
+ commit ucitrack
+EOF
+
+rm -f /tmp/luci-indexcache
+exit 0