diff --git a/lib/bitfields.cpp b/lib/bitfields.cpp index 6813299c..10bc7e3b 100644 --- a/lib/bitfields.cpp +++ b/lib/bitfields.cpp @@ -1,4 +1,5 @@ #include "bitfields.h" +#include /// Takes a pointer, offset bitcount and data bitcount, returning the unsigned int read from the givens. /// offsetBits may be > 7, in which case offsetBits / 8 is added to the pointer automatically. @@ -62,3 +63,18 @@ void Bit::setMSB(char * pointer, unsigned int offsetBits, unsigned int dataBits, }//Loop until we run out of dataBits, then return the result } +/// Parses a string reference to a boolean. +/// Returns true if the string, with whitespace removed and converted to lowercase, prefix-matches any of: "1", "yes", "true", "cont". +/// Returns false otherwise. +bool Util::stringToBool(std::string & str){ + std::string tmp; + tmp.reserve(4); + for (unsigned int i = 0; i < str.size() && tmp.size() < 4; ++i){ + if (!::isspace(str[i])){ + tmp.push_back((char)tolower(str[i])); + } + } + return (strncmp(tmp.c_str(), "1", 1) == 0 || strncmp(tmp.c_str(), "yes", 3) == 0 || strncmp(tmp.c_str(), "true", 4) == 0 || strncmp(tmp.c_str(), "cont", 4) == 0); +} + + diff --git a/lib/bitfields.h b/lib/bitfields.h index 8e6624a8..0ca119a4 100644 --- a/lib/bitfields.h +++ b/lib/bitfields.h @@ -1,5 +1,8 @@ +#include - +namespace Util{ + bool stringToBool(std::string & str); +} namespace Bit{ //bitfield getters diff --git a/lsp/minified.js b/lsp/minified.js index 6d7764b1..1a653a15 100644 --- a/lsp/minified.js +++ b/lsp/minified.js @@ -120,25 +120,26 @@ mist.data.config.limits[p[1]];w="For the entire server";break;case "stream":m=mi "Geo limited"],["host","Host limited"]],pointer:{main:m,index:"name"},LTSonly:!0,validate:["required"],classes:["limit_type"],"function":function(){var a=$(this).getval(),b=$(this).closest(".input_container").find(".limit_value"),c=b.closest("label"),b=b.data("opts");delete b.type;delete b.min;delete b.unit;b.validate=["required"];switch(a){case "kbps_max":b.type="int";b.min=1;b.unit="bytes/s";break;case "users":b.type="int";b.min=1;break;case "geo":b.type="geolimited";break;case "host":b.type="hostlimited"}a= UI.buildUI([b]);c.replaceWith(a.children())}},{type:"buttons",buttons:[{type:"cancel",label:"Cancel","function":function(){UI.navto(UI.returnTab[0],UI.returnTab[1])}},{type:"save",label:"Save","function":function(){var a={};if(k){var b=c.split("^");switch(b[0]){case "server":a={config:{limits:mist.data.config.limits}};break;case "stream":if(mist.data.LTS){a={addstream:{}};a.addstream[b[1]]=mist.data.streams[b[1]]}else a={streams:mist.data.streams}}}else{b=m.applies_to;delete m.applies_to;switch(b[0]){case "server":if(!mist.data.config.limits)mist.data.config.limits= [];mist.data.config.limits.push(m);a={config:{limits:mist.data.config.limits}};break;case "stream":if(typeof mist.data.streams[b[1]].limits=="undefined")mist.data.streams[b[1]].limits=[];mist.data.streams[b[1]].limits.push(m);if(mist.data.LTS){a={addstream:{}};a.addstream[b[1]]=mist.data.streams[b[1]]}else a={streams:mist.data.streams}}}mist.send(function(){UI.navto(UI.returnTab[0],UI.returnTab[1])},a)}}]}]),u=UI.buildUI(i);b.append(u);u.find(".limit_type").closest("label").after(u.find(".limit_value").closest("label")); -u.find(".limit_type").trigger("change");break;case "Triggers":"triggers"in mist.data.config||(mist.data.config.triggers={});h=$("");p=$("").html($("").html($("").html($("");p=$("
").text("Trigger on").attr("data-sort-type","string").addClass("sorting-asc")).append($("").text("Applies to").attr("data-sort-type","string")).append($("").text("Handler").attr("data-sort-type","string")).append($("")))).append(h);b.append(UI.buildUI([{type:"help",help:"Balder verzin iets leuks"}])).append($("
").html($("").html($("").html($("").attr("data-index",q+","+w).append($("").css("font-size","0.9em");b.append($("
").text("Trigger on").attr("data-sort-type","string").addClass("sorting-asc")).append($("").text("Applies to").attr("data-sort-type","string")).append($("").text("Handler").attr("data-sort-type","string")).append($("")))).append(h);b.append(UI.buildUI([{type:"help",help:"Triggers are the system you can use to react to events that occur inside MistServer. These allow you to block specific users, redirect streams, keep tabs on what is being pushed where, etcetera. For full documentation, please refer to the developer documentation section on the MistServer website."}])).append($("
").text(q)).append($("").text(i[q][w][2].join(", "))).append($("").text(i[q][w][0])).append($("").html($("
").append(h));var W=function(a){var b=$("").text(a);switch(a){case "WARN":b.addClass("orange");break;case "ERROR":case "FAIL":b.addClass("red")}return b},U=function(){var a= -mist.data.log;if(a){a.length>=2&&a[0][0]").html($("
").text(UI.format.dateTime(a[b][0],"long")).css("white-space","nowrap")).append($("").html(W(a[b][1])).css("text-align","center")).append($("").text(a[b][2]).css("text-align","left")))}};U();break;case "Statistics":u=$("").text("Loading..");b.append(u);var m={},s=mist.stored.get().graphs?$.extend(!0,{},mist.stored.get().graphs):{},z={};for(q in mist.data.streams)z[q]= -!0;for(q in mist.data.active_streams)z[mist.data.active_streams[q]]=!0;var z=Object.keys(z).sort(),M=[];for(q in mist.data.config.protocols)M.push(mist.data.config.protocols[q].connector);M.sort();mist.send(function(){UI.plot.datatype.templates.cpuload.cores=0;for(var a in mist.data.capabilities.cpu)UI.plot.datatype.templates.cpuload.cores=UI.plot.datatype.templates.cpuload.cores+mist.data.capabilities.cpu[a].cores;u.html(UI.buildUI([{type:"help",help:"Here you will find the MistServer stream statistics, you can select various categories yourself. All statistics are live: up to five minutes are saved."}, -$("

").text("Select the data to display"),{label:"Add to",type:"select",select:[["new","New graph"]],pointer:{main:m,index:"graph"},classes:["graph_ids"],"function":function(){if($(this).val()){var a=u.find(".graph_xaxis"),b=u.find(".graph_id");if($(this).val()=="new"){a.children("option").prop("disabled",false);b.setval("Graph "+(Object.keys(s).length+1)).closest("label").show()}else{var c=s[$(this).val()].xaxis;a.children("option").prop("disabled",true).filter('[value="'+c+'"]').prop("disabled", -false);b.closest("label").hide()}a.children('option[value="'+a.val()+'"]:disabled').length&&a.val(a.children("option:enabled").first().val());a.trigger("change")}}},{label:"Graph id",type:"str",pointer:{main:m,index:"id"},classes:["graph_id"],validate:[function(a){return a in s?{msg:"This graph id has already been used. Please enter something else.",classes:["red"]}:false}]},{label:"Axis type",type:"select",select:[["time","Time line"],["coords","Geographical"]],pointer:{main:m,index:"xaxis"},classes:["graph_xaxis"], -"function":function(){$s=u.find(".graph_datatype");switch($(this).getval()){case "coords":$s.children("option").prop("disabled",true).filter('[value="coords"]').prop("disabled",false);break;case "time":$s.children("option").prop("disabled",false).filter('[value="coords"]').prop("disabled",true)}if(!$s.val()||$s.children('option[value="'+$s.val()+'"]:disabled').length){$s.val($s.children("option:enabled").first().val());$s.trigger("change")}}},{label:"Data type",type:"select",select:[["clients","Connections"], -["upbps","Bandwidth (up)"],["downbps","Bandwidth (down)"],["cpuload","CPU load"],["memload","Memory load"],["coords","Client location"]],pointer:{main:m,index:"datatype"},classes:["graph_datatype"],"function":function(){$s=u.find(".graph_origin");switch($(this).getval()){case "cpuload":case "memload":$s.find("input[type=radio]").not('[value="total"]').prop("disabled",true);$s.find('input[type=radio][value="total"]').prop("checked",true);break;default:$s.find("input[type=radio]").prop("disabled",false)}}}, -{label:"Data origin",type:"radioselect",radioselect:[["total","All"],["stream","The stream:",z],["protocol","The protocol:",M]],pointer:{main:m,index:"origin"},value:["total"],classes:["graph_origin"]},{type:"buttons",buttons:[{label:"Add data set",type:"save","function":function(){var a;if(m.graph=="new"){a=UI.plot.addGraph(m,c);s[a.id]=a;u.find("select.graph_ids").append($("