mistserver/lsp/minified.js

167 lines
87 KiB
JavaScript

var MD5=function(a){function c(a,b){var c,d,f,i,h;f=a&2147483648;i=b&2147483648;c=a&1073741824;d=b&1073741824;h=(a&1073741823)+(b&1073741823);return c&d?h^2147483648^f^i:c|d?h&1073741824?h^3221225472^f^i:h^1073741824^f^i:h^f^i}function b(a,b,d,f,i,h,g){a=c(a,c(c(b&d|~b&f,i),g));return c(a<<h|a>>>32-h,b)}function d(a,b,d,f,i,h,g){a=c(a,c(c(b&f|d&~f,i),g));return c(a<<h|a>>>32-h,b)}function e(a,b,d,f,i,h,g){a=c(a,c(c(b^d^f,i),g));return c(a<<h|a>>>32-h,b)}function j(a,b,d,f,i,h,g){a=c(a,c(c(d^(b|~f),
i),g));return c(a<<h|a>>>32-h,b)}function n(a){var b="",c="",d;for(d=0;3>=d;d++)c=a>>>8*d&255,c="0"+c.toString(16),b+=c.substr(c.length-2,2);return b}var g=[],p,m,h,s,f,i,l,k,g=a.replace(/\r\n/g,"\n"),a="";for(p=0;p<g.length;p++)m=g.charCodeAt(p),128>m?a+=String.fromCharCode(m):(127<m&&2048>m?a+=String.fromCharCode(m>>6|192):(a+=String.fromCharCode(m>>12|224),a+=String.fromCharCode(m>>6&63|128)),a+=String.fromCharCode(m&63|128));g=a;a=g.length;p=a+8;m=16*((p-p%64)/64+1);h=Array(m-1);for(f=s=0;f<a;)p=
(f-f%4)/4,s=8*(f%4),h[p]|=g.charCodeAt(f)<<s,f++;p=(f-f%4)/4;h[p]|=128<<8*(f%4);h[m-2]=a<<3;h[m-1]=a>>>29;g=h;f=1732584193;i=4023233417;l=2562383102;k=271733878;for(a=0;a<g.length;a+=16)p=f,m=i,h=l,s=k,f=b(f,i,l,k,g[a+0],7,3614090360),k=b(k,f,i,l,g[a+1],12,3905402710),l=b(l,k,f,i,g[a+2],17,606105819),i=b(i,l,k,f,g[a+3],22,3250441966),f=b(f,i,l,k,g[a+4],7,4118548399),k=b(k,f,i,l,g[a+5],12,1200080426),l=b(l,k,f,i,g[a+6],17,2821735955),i=b(i,l,k,f,g[a+7],22,4249261313),f=b(f,i,l,k,g[a+8],7,1770035416),
k=b(k,f,i,l,g[a+9],12,2336552879),l=b(l,k,f,i,g[a+10],17,4294925233),i=b(i,l,k,f,g[a+11],22,2304563134),f=b(f,i,l,k,g[a+12],7,1804603682),k=b(k,f,i,l,g[a+13],12,4254626195),l=b(l,k,f,i,g[a+14],17,2792965006),i=b(i,l,k,f,g[a+15],22,1236535329),f=d(f,i,l,k,g[a+1],5,4129170786),k=d(k,f,i,l,g[a+6],9,3225465664),l=d(l,k,f,i,g[a+11],14,643717713),i=d(i,l,k,f,g[a+0],20,3921069994),f=d(f,i,l,k,g[a+5],5,3593408605),k=d(k,f,i,l,g[a+10],9,38016083),l=d(l,k,f,i,g[a+15],14,3634488961),i=d(i,l,k,f,g[a+4],20,3889429448),
f=d(f,i,l,k,g[a+9],5,568446438),k=d(k,f,i,l,g[a+14],9,3275163606),l=d(l,k,f,i,g[a+3],14,4107603335),i=d(i,l,k,f,g[a+8],20,1163531501),f=d(f,i,l,k,g[a+13],5,2850285829),k=d(k,f,i,l,g[a+2],9,4243563512),l=d(l,k,f,i,g[a+7],14,1735328473),i=d(i,l,k,f,g[a+12],20,2368359562),f=e(f,i,l,k,g[a+5],4,4294588738),k=e(k,f,i,l,g[a+8],11,2272392833),l=e(l,k,f,i,g[a+11],16,1839030562),i=e(i,l,k,f,g[a+14],23,4259657740),f=e(f,i,l,k,g[a+1],4,2763975236),k=e(k,f,i,l,g[a+4],11,1272893353),l=e(l,k,f,i,g[a+7],16,4139469664),
i=e(i,l,k,f,g[a+10],23,3200236656),f=e(f,i,l,k,g[a+13],4,681279174),k=e(k,f,i,l,g[a+0],11,3936430074),l=e(l,k,f,i,g[a+3],16,3572445317),i=e(i,l,k,f,g[a+6],23,76029189),f=e(f,i,l,k,g[a+9],4,3654602809),k=e(k,f,i,l,g[a+12],11,3873151461),l=e(l,k,f,i,g[a+15],16,530742520),i=e(i,l,k,f,g[a+2],23,3299628645),f=j(f,i,l,k,g[a+0],6,4096336452),k=j(k,f,i,l,g[a+7],10,1126891415),l=j(l,k,f,i,g[a+14],15,2878612391),i=j(i,l,k,f,g[a+5],21,4237533241),f=j(f,i,l,k,g[a+12],6,1700485571),k=j(k,f,i,l,g[a+3],10,2399980690),
l=j(l,k,f,i,g[a+10],15,4293915773),i=j(i,l,k,f,g[a+1],21,2240044497),f=j(f,i,l,k,g[a+8],6,1873313359),k=j(k,f,i,l,g[a+15],10,4264355552),l=j(l,k,f,i,g[a+6],15,2734768916),i=j(i,l,k,f,g[a+13],21,1309151649),f=j(f,i,l,k,g[a+4],6,4149444226),k=j(k,f,i,l,g[a+11],10,3174756917),l=j(l,k,f,i,g[a+2],15,718787259),i=j(i,l,k,f,g[a+9],21,3951481745),f=c(f,p),i=c(i,m),l=c(l,h),k=c(k,s);return(n(f)+n(i)+n(l)+n(k)).toLowerCase()};(function(a){a.fn.stupidtable=function(){a(this).on("click","thead th",function(){a(this).stupidsort()})};a.fn.stupidsort=function(){function c(b){var c=0,d;a(b).children("td,th").each(function(){if(c==p)return d=a(this),!1;var b=a(this).attr("colspan");c+=b?Number(b):1});b="undefined"!=typeof d.data("sort-value")?d.data("sort-value"):"undefined"!=typeof d.attr("data-sort-value")?d.attr("data-sort-value"):d.text();switch(n){case "string":case "string-ins":b=String(b).toLowerCase();break;case "int":b=
parseInt(Number(b));break;case "float":b=Number(b)}return b}var b=a(this),d=b.closest("table"),e=d.children("tbody"),j=e.children("tr"),n=b.attr("data-sort-type");if(n){var g=!0;b.hasClass("sorting-asc")&&(g=!1);var p=0;b.prevAll().each(function(){var b=a(this).attr("colspan");p+=b?Number(b):1});j.sort(function(a,b){var d=g?1:-1,a=c(a),b=c(b);return a>b?1*d:a<b?-1*d:0});e.append(j);d.find("thead th").removeClass("sorting-asc").removeClass("sorting-desc");b.addClass(g?"sorting-asc":"sorting-desc")}}})(jQuery);$(function(){UI.elements={menu:$("nav > .menu"),secondary_menu:$("nav.secondary_menu"),main:$("main"),connection:{status:$("#connection"),user_and_host:$("#user_and_host"),msg:$("#message")}};UI.buildMenu();UI.stored.getOpts();if(location.hash){var a=decodeURIComponent(location.hash).substring(1).split("@")[0].split("&");mist.user.name=a[0];a[1]&&(mist.user.host=a[1])}mist.send(function(){$(window).trigger("hashchange")},{},{timeout:5,hide:!0})});
$(window).on("hashchange",function(){var a=decodeURIComponent(location.hash).substring(1).split("@");a[1]||(a[1]="");a=a[1].split("&");""==a[0]&&(a[0]="Overview");UI.showTab(a[0],a[1])});
var UI={debug:!1,elements:{},stored:{getOpts:function(){var a=localStorage.stored;a&&(a=JSON.parse(a));$.extend(!0,this.vars,a);return this.vars},saveOpt:function(a,c){this.vars[a]=c;localStorage.stored=JSON.stringify(this.vars);return this.vars},vars:{helpme:!0}},interval:{clear:function(){"undefined"!=typeof this.opts&&(clearInterval(this.opts.id),delete this.opts)},set:function(a,c){this.opts&&log("[interval]","Set called on interval, but an interval is already active.");this.opts={delay:c,callback:a};
this.opts.id=setInterval(a,c)}},returnTab:["Overview"],countrylist:{AF:"Afghanistan",AX:"&Aring;land Islands",AL:"Albania",DZ:"Algeria",AS:"American Samoa",AD:"Andorra",AO:"Angola",AI:"Anguilla",AQ:"Antarctica",AG:"Antigua and Barbuda",AR:"Argentina",AM:"Armenia",AW:"Aruba",AU:"Australia",AT:"Austria",AZ:"Azerbaijan",BS:"Bahamas",BH:"Bahrain",BD:"Bangladesh",BB:"Barbados",BY:"Belarus",BE:"Belgium",BZ:"Belize",BJ:"Benin",BM:"Bermuda",BT:"Bhutan",BO:"Bolivia, Plurinational State of",BQ:"Bonaire, Sint Eustatius and Saba",
BA:"Bosnia and Herzegovina",BW:"Botswana",BV:"Bouvet Island",BR:"Brazil",IO:"British Indian Ocean Territory",BN:"Brunei Darussalam",BG:"Bulgaria",BF:"Burkina Faso",BI:"Burundi",KH:"Cambodia",CM:"Cameroon",CA:"Canada",CV:"Cape Verde",KY:"Cayman Islands",CF:"Central African Republic",TD:"Chad",CL:"Chile",CN:"China",CX:"Christmas Island",CC:"Cocos (Keeling) Islands",CO:"Colombia",KM:"Comoros",CG:"Congo",CD:"Congo, the Democratic Republic of the",CK:"Cook Islands",CR:"Costa Rica",CI:"C&ocirc;te d'Ivoire",
HR:"Croatia",CU:"Cuba",CW:"Cura&ccedil;ao",CY:"Cyprus",CZ:"Czech Republic",DK:"Denmark",DJ:"Djibouti",DM:"Dominica",DO:"Dominican Republic",EC:"Ecuador",EG:"Egypt",SV:"El Salvador",GQ:"Equatorial Guinea",ER:"Eritrea",EE:"Estonia",ET:"Ethiopia",FK:"Falkland Islands (Malvinas)",FO:"Faroe Islands",FJ:"Fiji",FI:"Finland",FR:"France",GF:"French Guiana",PF:"French Polynesia",TF:"French Southern Territories",GA:"Gabon",GM:"Gambia",GE:"Georgia",DE:"Germany",GH:"Ghana",GI:"Gibraltar",GR:"Greece",GL:"Greenland",
GD:"Grenada",GP:"Guadeloupe",GU:"Guam",GT:"Guatemala",GG:"Guernsey",GN:"Guinea",GW:"Guinea-Bissau",GY:"Guyana",HT:"Haiti",HM:"Heard Island and McDonald Islands",VA:"Holy See (Vatican City State)",HN:"Honduras",HK:"Hong Kong",HU:"Hungary",IS:"Iceland",IN:"India",ID:"Indonesia",IR:"Iran, Islamic Republic of",IQ:"Iraq",IE:"Ireland",IM:"Isle of Man",IL:"Israel",IT:"Italy",JM:"Jamaica",JP:"Japan",JE:"Jersey",JO:"Jordan",KZ:"Kazakhstan",KE:"Kenya",KI:"Kiribati",KP:"Korea, Democratic People's Republic of",
KR:"Korea, Republic of",KW:"Kuwait",KG:"Kyrgyzstan",LA:"Lao People's Democratic Republic",LV:"Latvia",LB:"Lebanon",LS:"Lesotho",LR:"Liberia",LY:"Libya",LI:"Liechtenstein",LT:"Lithuania",LU:"Luxembourg",MO:"Macao",MK:"Macedonia, the former Yugoslav Republic of",MG:"Madagascar",MW:"Malawi",MY:"Malaysia",MV:"Maldives",ML:"Mali",MT:"Malta",MH:"Marshall Islands",MQ:"Martinique",MR:"Mauritania",MU:"Mauritius",YT:"Mayotte",MX:"Mexico",FM:"Micronesia, Federated States of",MD:"Moldova, Republic of",MC:"Monaco",
MN:"Mongolia",ME:"Montenegro",MS:"Montserrat",MA:"Morocco",MZ:"Mozambique",MM:"Myanmar",NA:"Namibia",NR:"Nauru",NP:"Nepal",NL:"Netherlands",NC:"New Caledonia",NZ:"New Zealand",NI:"Nicaragua",NE:"Niger",NG:"Nigeria",NU:"Niue",NF:"Norfolk Island",MP:"Northern Mariana Islands",NO:"Norway",OM:"Oman",PK:"Pakistan",PW:"Palau",PS:"Palestine, State of",PA:"Panama",PG:"Papua New Guinea",PY:"Paraguay",PE:"Peru",PH:"Philippines",PN:"Pitcairn",PL:"Poland",PT:"Portugal",PR:"Puerto Rico",QA:"Qatar",RE:"R&eacute;union",
RO:"Romania",RU:"Russian Federation",RW:"Rwanda",BL:"Saint Barth&eacute;lemy",SH:"Saint Helena, Ascension and Tristan da Cunha",KN:"Saint Kitts and Nevis",LC:"Saint Lucia",MF:"Saint Martin (French part)",PM:"Saint Pierre and Miquelon",VC:"Saint Vincent and the Grenadines",WS:"Samoa",SM:"San Marino",ST:"Sao Tome and Principe",SA:"Saudi Arabia",SN:"Senegal",RS:"Serbia",SC:"Seychelles",SL:"Sierra Leone",SG:"Singapore",SX:"Sint Maarten (Dutch part)",SK:"Slovakia",SI:"Slovenia",SB:"Solomon Islands",SO:"Somalia",
ZA:"South Africa",GS:"South Georgia and the South Sandwich Islands",SS:"South Sudan",ES:"Spain",LK:"Sri Lanka",SD:"Sudan",SR:"Suriname",SJ:"Svalbard and Jan Mayen",SZ:"Swaziland",SE:"Sweden",CH:"Switzerland",SY:"Syrian Arab Republic",TW:"Taiwan, Province of China",TJ:"Tajikistan",TZ:"Tanzania, United Republic of",TH:"Thailand",TL:"Timor-Leste",TG:"Togo",TK:"Tokelau",TO:"Tonga",TT:"Trinidad and Tobago",TN:"Tunisia",TR:"Turkey",TM:"Turkmenistan",TC:"Turks and Caicos Islands",TV:"Tuvalu",UG:"Uganda",
UA:"Ukraine",AE:"United Arab Emirates",GB:"United Kingdom",US:"United States",UM:"United States Minor Outlying Islands",UY:"Uruguay",UZ:"Uzbekistan",VU:"Vanuatu",VE:"Venezuela, Bolivarian Republic of",VN:"Viet Nam",VG:"Virgin Islands, British",VI:"Virgin Islands, U.S.",WF:"Wallis and Futuna",EH:"Western Sahara",YE:"Yemen",ZM:"Zambia",ZW:"Zimbabwe"},tooltip:{show:function(a,c){$tooltip=this.element;$.contains(document.body,$tooltip[0])||$("body").append($tooltip);$tooltip.html(c);clearTimeout(this.hiding);
delete this.hiding;var b=$(document).height()-$tooltip.outerHeight(),d=$(document).width()-$tooltip.outerWidth();$tooltip.css("left",Math.min(a.pageX+10,d-10));$tooltip.css("top",Math.min(a.pageY+25,b-10));$tooltip.show().addClass("show")},hide:function(){$tooltip=this.element;$tooltip.removeClass("show");this.hiding=setTimeout(function(){$tooltip.hide()},500)},element:$("<div>").attr("id","tooltip")},popup:{element:null,show:function(a){this.element=$("<div>").attr("id","popup").append($("<button>").text("Close").addClass("close").click(function(){UI.popup.element.fadeOut("fast",
function(){UI.popup.element.remove();UI.popup.element=null})})).append(a);$("body").append(this.element)}},menu:[{Overview:{},Protocols:{},Streams:{},Preview:{},Push:{LTSonly:!0},Triggers:{LTSonly:!1},Logs:{},Statistics:{},"Server Stats":{}},{Disconnect:{classes:["red"]}},{Guides:{link:"http://mistserver.org/documentation#Userdocs"},Tools:{submenu:{"Release notes":{link:"http://mistserver.org/documentation#Devdocs"},"Mist Shop":{link:"http://mistserver.org/products"},"Email for Help":{},"Terms & Conditions":{link:"http://mistserver.org/documentation#Legal"}}}}],
buildMenu:function(){function a(a,b){var c=$("<a>").addClass("button");c.html($("<span>").addClass("plain").text(a)).append($("<span>").addClass("highlighted").text(a));for(var d in b.classes)c.addClass(b.classes[d]);"LTSonly"in b&&c.addClass("LTSonly");"link"in b?c.attr("href",b.link).attr("target","_blank"):"submenu"in b||c.click(function(b){UI.navto(a);b.stopPropagation()});return c}var c=UI.elements.menu,b;for(b in UI.menu){0<b&&c.append($("<br>"));for(var d in UI.menu[b]){var e=UI.menu[b][d],
j=a(d,e);c.append(j);if("submenu"in e){var n=$("<span>").addClass("submenu");j.addClass("arrowdown").append(n);for(var g in e.submenu)n.append(a(g,e.submenu[g]))}}}b=$("<div>").attr("id","ih_button").text("?").click(function(){$("body").toggleClass("helpme");UI.stored.saveOpt("helpme",$("body").hasClass("helpme"))}).attr("title","Click to toggle the display of integrated help");UI.stored.getOpts().helpme&&$("body").addClass("helpme");c.after(b).after($("<div>").addClass("separator"))},buildUI:function(a){var c=
$("<div>").addClass("input_container"),b;for(b in a){var d=a[b];if(d instanceof jQuery)c.append(d);else if("help"==d.type){var e=$("<span>").addClass("text_container").append($("<span>").addClass("description").append(d.help));c.append(e);if("classes"in d)for(var j in d.classes)e.addClass(d.classes[j])}else if("text"==d.type)c.append($("<span>").addClass("text_container").append($("<span>").addClass("text").append(d.text)));else if("custom"==d.type)c.append(d.custom);else if("buttons"==d.type)for(j in e=
$("<span>").addClass("button_container"),"css"in d&&e.css(d.css),c.append(e),d.buttons){var n=d.buttons[j],g=$("<button>").text(n.label).data("opts",n);"css"in n&&g.css(n.css);e.append(g);switch(n.type){case "cancel":g.addClass("cancel").click(n["function"]);break;case "save":g.addClass("save").click(function(){var a=$(this).closest(".input_container"),b=!1;a.find(".hasValidate").each(function(){if(b=$(this).data("validate")(this,!0))return!1});b||(a.find(".isSetting").each(function(){var a=$(this).getval(),
b=$(this).data("pointer");if(""==a)if("default"in $(this).data("opts"))a=$(this).data("opts")["default"];else return delete b.main[b.index],!0;b.main[b.index]=a}),(a=$(this).data("opts")["function"])&&a(this))});break;default:g.click(n["function"])}}else{n=$("<label>").addClass("UIelement");c.append(n);"css"in d&&n.css(d.css);n.append($("<span>").addClass("label").html("label"in d?d.label+":":""));g=$("<span>").addClass("field_container");n.append(g);switch(d.type){case "password":e=$("<input>").attr("type",
"password");break;case "int":e=$("<input>").attr("type","number");"min"in d&&e.attr("min",d.min);"max"in d&&e.attr("max",d.min);"validate"in d?d.validate.push("int"):d.validate=["int"];break;case "span":e=$("<span>");break;case "debug":d.select=[["","Default"],[0,"0 - All debugging messages disabled"],[1,"1 - Messages about failed operations"],[2,"2 - Previous level, and error messages"],[3,"3 - Previous level, and warning messages"],[4,"4 - Previous level, and status messages for development"],[5,
"5 - Previous level, and more status messages for development"],[6,"6 - Previous level, and verbose debugging messages"],[7,"7 - Previous level, and very verbose debugging messages"],[8,"8 - Report everything in extreme detail"],[9,"9 - Report everything in insane detail"],[10,"10 - All messages enabled"]];case "select":e=$("<select>");for(j in d.select){var p=$("<option>");"string"==typeof d.select[j]?p.text(d.select[j]):p.val(d.select[j][0]).text(d.select[j][1]);e.append(p)}break;case "textarea":e=
$("<textarea>").on("keydown",function(a){a.stopPropagation()});break;case "checkbox":e=$("<input>").attr("type","checkbox");break;case "hidden":e=$("<input>").attr("type","hidden");n.hide();break;case "email":e=$("<input>").attr("type","email").attr("autocomplete","on").attr("required","");break;case "browse":e=$("<input>").attr("type","text");"filetypes"in d&&e.data("filetypes",d.filetypes);break;case "geolimited":case "hostlimited":e=$("<input>").attr("type","hidden");break;case "radioselect":e=
$("<div>").addClass("radioselect");for(b in d.radioselect){var m=$("<input>").attr("type","radio").val(d.radioselect[b][0]).attr("name",d.label);("LTSonly"in d&&!mist.data.LTS||d.readonly)&&m.prop("disabled",!0);p=$("<label>").append(m).append($("<span>").html(d.radioselect[b][1]));e.append(p);if(2<d.radioselect[b].length)for(j in m=$("<select>").change(function(){$(this).parent().find("input[type=radio]:enabled").prop("checked","true")}),p.append(m),("LTSonly"in d&&!mist.data.LTS||d.readonly)&&m.prop("disabled",
!0),d.radioselect[b][2])p=$("<option>"),m.append(p),d.radioselect[b][2][j]instanceof Array?p.val(d.radioselect[b][2][j][0]).html(d.radioselect[b][2][j][1]):p.html(d.radioselect[b][2][j])}break;case "checklist":e=$("<div>").addClass("checkcontainer");$controls=$("<div>").addClass("controls");$checklist=$("<div>").addClass("checklist");e.append($controls).append($checklist);$controls.append($("<label>").text("All").prepend($("<input>").attr("type","checkbox").click(function(){$(this).is(":checked")?
$(this).closest(".checkcontainer").find("input[type=checkbox]").prop("checked",!0):$(this).closest(".checkcontainer").find("input[type=checkbox]").prop("checked",!1)})));for(b in d.checklist)"string"==typeof d.checklist[b]&&(d.checklist[b]=[d.checklist[b],d.checklist[b]]),$checklist.append($("<label>").text(d.checklist[b][1]).prepend($("<input>").attr("type","checkbox").attr("name",d.checklist[b][0])));break;case "DOMfield":e=d.DOMfield;break;default:e=$("<input>").attr("type","text")}e.addClass("field").data("opts",
d);"pointer"in d&&e.attr("name",d.pointer.index);g.append(e);if("classes"in d)for(j in d.classes)e.addClass(d.classes[j]);"placeholder"in d&&e.attr("placeholder",d.placeholder);"default"in d&&e.attr("placeholder",d["default"]);"unit"in d&&g.append($("<span>").addClass("unit").html(d.unit));"readonly"in d&&(e.attr("readonly","readonly"),e.click(function(){$(this).select()}));"qrcode"in d&&g.append($("<span>").addClass("unit").html($("<button>").text("QR").click(function(){var a=String($(this).closest(".field_container").find(".field").getval()),
b=$("<div>").addClass("qrcode");UI.popup.show($("<span>").addClass("qr_container").append($("<p>").text(a)).append(b));b.qrcode({text:a,size:Math.min(b.width(),b.height())})})));"rows"in d&&e.attr("rows",d.rows);"LTSonly"in d&&!mist.data.LTS&&(g.addClass("LTSonly"),e.prop("disabled",!0));switch(d.type){case "browse":m=$("<div>").addClass("grouper").append(n);c.append(m);m=$("<button>").text("Browse");g.append(m);m.click(function(){function a(b){j.text("Loading..");mist.send(function(a){e.text(a.browse.path[0]);
j.html(m.clone(true).text("..").attr("title","Folder up"));if(a.browse.subdirectories){a.browse.subdirectories.sort();for(var b in a.browse.subdirectories){var h=a.browse.subdirectories[b];j.append(m.clone(true).attr("title",e.text()+p+h).text(h))}}if(a.browse.files){a.browse.files.sort();for(b in a.browse.files){var h=a.browse.files[b],n=e.text()+p+h,h=$("<a>").text(h).addClass("file").attr("title",n);j.append(h);if(o){var q=true,s;for(s in o)if(typeof o[s]!="undefined"&&mist.inputMatch(o[s],n)){q=
false;break}q&&h.hide()}h.click(function(){var a=$(this).attr("title");d.setval(a);g.show();c.remove()})}}},{browse:b})}var b=$(this).closest(".grouper"),c=$("<div>").addClass("browse_container"),d=b.find(".field"),g=$(this),e=$("<span>").addClass("field"),n=$("<button>").text("Select this folder"),j=$("<div>").addClass("browse_contents"),m=$("<a>").addClass("folder"),o=d.data("filetypes");b.append(c);c.append($("<label>").addClass("UIelement").append($("<span>").addClass("label").text("Current folder:")).append($("<span>").addClass("field_container").append(e).append(n))).append(j);
n.click(function(){var a=e.text()+"/";d.setval(a);g.show();c.remove()});var p="/";mist.data.config.version.indexOf("indows")>-1&&(p="\\");m.click(function(){var b=e.text()+p+$(this).text();a(b)});b=d.getval();b=b.split(p);b.pop();b=b.join(p);g.hide();a(b)});break;case "geolimited":case "hostlimited":m={field:e};m.blackwhite=$("<select>").append($("<option>").val("-").text("Blacklist")).append($("<option>").val("+").text("Whitelist"));m.values=$("<span>").addClass("limit_value_list");switch(d.type){case "geolimited":m.prototype=
$("<select>").append($("<option>").val("").text("[Select a country]"));for(b in UI.countrylist)m.prototype.append($("<option>").val(b).html(UI.countrylist[b]));break;case "hostlimited":m.prototype=$("<input>").attr("type","text").attr("placeholder","type a host")}m.prototype.on("change keyup",function(){$(this).closest(".field_container").data("subUI").blackwhite.trigger("change")});m.blackwhite.change(function(){var a=$(this).closest(".field_container").data("subUI"),b=[],c=false;a.values.children().each(function(){c=
$(this).val();c!=""?b.push(c):$(this).remove()});a.values.append(a.prototype.clone(true));b.length>0?a.field.val($(this).val()+b.join(" ")):a.field.val("");a.field.trigger("change")});"LTSonly"in d&&!mist.data.LTS&&(m.blackwhite.prop("disabled",!0),m.prototype.prop("disabled",!0));m.values.append(m.prototype.clone(!0));g.data("subUI",m).addClass("limit_list").append(m.blackwhite).append(m.values)}"pointer"in d&&(e.data("pointer",d.pointer).addClass("isSetting"),m=d.pointer.main[d.pointer.index],"undefined"!=
m&&e.setval(m));"value"in d&&e.setval(d.value);if("datalist"in d)for(b in m="datalist_"+b+MD5(e[0].outerHTML),e.attr("list",m),m=$("<datalist>").attr("id",m),g.append(m),d.datalist)m.append($("<option>").val(d.datalist[b]));g=$("<span>").addClass("help_container");n.append(g);"help"in d&&(g.append($("<span>").addClass("ih_balloon").html(d.help)),e.on("focus mouseover",function(){$(this).closest("label").addClass("active")}).on("blur mouseout",function(){$(this).closest("label").removeClass("active")}));
if("validate"in d){n=[];for(j in d.validate){m=d.validate[j];if("function"!=typeof m)switch(m){case "required":m=function(a){return a==""?{msg:"This is a required field.",classes:["red"]}:false};break;case "int":m=function(a,b){var c=$(b).data("opts");if(!$(b)[0].validity.valid){var d=[];"min"in c&&d.push(" greater than or equal to "+c.min);"max"in c&&d.push(" smaller than or equal to "+c.max);return{msg:"Please enter an integer"+d.join(" and")+".",classes:["red"]}}if(parseInt(Number(a))!=a)return{msg:"Please enter an integer.",
classes:["red"]}};break;case "streamname":m=function(a,b){if(!isNaN(a.charAt(0)))return{msg:"The first character may not be a number.",classes:["red"]};if(a.toLowerCase()!=a)return{msg:"Uppercase letters are not allowed.",classes:["red"]};if(a.replace(/[^\da-z_]/g,"")!=a)return{msg:"Special characters (except for underscores) are not allowed.",classes:["red"]};if("streams"in mist.data&&a in mist.data.streams&&$(b).data("pointer").main.name!=a)return{msg:"This streamname already exists.<br>If you want to edit an existing stream, please click edit on the the streams tab.",
classes:["red"]}};break;default:m=function(){}}n.push(m)}e.data("validate_functions",n).data("help_container",g).data("validate",function(a,b){var c=$(a).getval(),d=$(a).data("validate_functions"),g=$(a).data("help_container");g.find(".err_balloon").remove();for(var e in d){var n=d[e](c,a);if(n){$err=$("<span>").addClass("err_balloon").html(n.msg);for(var j in n.classes)$err.addClass(n.classes[j]);g.prepend($err);b&&$(a).focus();return true}}return false}).addClass("hasValidate").on("change keyup",
function(){$(this).data("validate")($(this))});""!=e.getval()&&e.trigger("change")}"function"in d&&(e.on("change keyup",d["function"]),e.trigger("change"))}}c.on("keydown",function(a){switch(a.which){case 13:$(this).find("button.save").trigger("click");break;case 27:$(this).find("button.cancel").trigger("click")}});return c},buildVheaderTable:function(a){var c=$("<table>").css("margin","0.2em"),b=$("<tr>").addClass("header").append($("<td>").addClass("vheader").attr("rowspan",a.labels.length+1).append($("<span>").text(a.vheader))),
d=[];b.append($("<td>"));for(var e in a.labels)d.push($("<tr>").append($("<td>").html(""==a.labels[e]?"&nbsp;":a.labels[e]+":")));for(var j in a.content)for(e in b.append($("<td>").html(a.content[j].header)),a.content[j].body)d[e].append($("<td>").html(a.content[j].body[e]));c.append($("<tbody>").append(b).append(d));return c},plot:{addGraph:function(a,c){var b={id:a.id,xaxis:a.xaxis,datasets:[],elements:{cont:$("<div>").addClass("graph"),plot:$("<div>").addClass("plot"),legend:$("<div>").addClass("legend").attr("draggable",
"true")}};UI.draggable(b.elements.legend);b.elements.cont.append(b.elements.plot).append(b.elements.legend);c.append(b.elements.cont);return b},go:function(a){if(!(1>Object.keys(a).length)){var c={totals:[],clients:[]},b;for(b in a)for(var d in a[b].datasets){var e=a[b].datasets[d];switch(e.datatype){case "clients":case "upbps":case "downbps":switch(e.origin[0]){case "total":c.totals.push({fields:[e.datatype],end:-15});break;case "stream":c.totals.push({fields:[e.datatype],streams:[e.origin[1]],end:-15});
break;case "protocol":c.totals.push({fields:[e.datatype],protocols:[e.origin[1]],end:-15})}break;case "cpuload":case "memload":c.capabilities={}}}0==c.totals.length&&delete c.totals;0==c.clients.length&&delete c.clients;mist.send(function(){for(var b in a){var c=a[b];if(1>c.datasets.length){c.elements.plot.html("");c.elements.legend.html("");break}switch(c.xaxis){case "time":var d=[];c.yaxes={};var e=[],m;for(m in c.datasets){var h=c.datasets[m];h.display&&(h.getdata(),h.yaxistype in c.yaxes||(d.push(UI.plot.yaxes[h.yaxistype]),
c.yaxes[h.yaxistype]=d.length),h.yaxis=c.yaxes[h.yaxistype],e.push(h))}d[0]&&(d[0].color=0);c.plot=$.plot(c.elements.plot,e,{legend:{show:!1},xaxis:UI.plot.xaxes[c.xaxis],yaxes:d,grid:{hoverable:!0,borderWidth:{top:0,right:0,bottom:1,left:1},color:"black",backgroundColor:{colors:["rgba(0,0,0,0)","rgba(0,0,0,0.025)"]}},crosshair:{mode:"x"}});d=$("<table>").addClass("legend-list").addClass("nolay").html($("<tr>").html($("<td>").html($("<h3>").text(c.id))).append($("<td>").css("padding-right","2em").css("text-align",
"right").html($("<span>").addClass("value")).append($("<button>").data("opts",c).text("X").addClass("close").click(function(){var b=$(this).data("opts");if(confirm("Are you sure you want to remove "+b.id+"?")){b.elements.cont.remove();var c=$(".graph_ids option:contains("+b.id+")"),d=c.parent();c.remove();UI.plot.del(b.id);delete a[b.id];d.trigger("change");UI.plot.go(a)}}))));c.elements.legend.html(d);var s=function(a){var b=c.elements.legend.find(".value"),d=1;if(typeof a=="undefined")b.eq(0).html("Latest:");
else{var e=c.plot.getXAxes()[0],a=Math.min(e.max,a),a=Math.max(e.min,a);b.eq(0).html(UI.format.time(a/1E3))}for(var g in c.datasets){var f="&nbsp;";if(c.datasets[g].display){var e=UI.plot.yaxes[c.datasets[g].yaxistype].tickFormatter,h=c.datasets[g].data;if(a)for(var j in h){if(h[j][0]==a){f=e(h[j][1]);break}if(h[j][0]>a){if(j!=0){f=h[j];h=h[j-1];f=e(f[1]+(a-f[0])*(h[1]-f[1])/(h[0]-f[0]))}break}}else f=e(c.datasets[g].data[c.datasets[g].data.length-1][1])}b.eq(d).html(f);d++}};c.plot.getOptions();
for(m in c.datasets)e=$("<input>").attr("type","checkbox").data("index",m).data("graph",c).click(function(){var a=$(this).data("graph");$(this).is(":checked")?a.datasets[$(this).data("index")].display=true:a.datasets[$(this).data("index")].display=false;var b={};b[a.id]=a;UI.plot.go(b)}),c.datasets[m].display&&e.attr("checked","checked"),d.append($("<tr>").html($("<td>").html($("<label>").html(e).append($("<div>").addClass("series-color").css("background-color",c.datasets[m].color)).append(c.datasets[m].label))).append($("<td>").css("padding-right",
"2em").css("text-align","right").html($("<span>").addClass("value")).append($("<button>").text("X").addClass("close").data("index",m).data("graph",c).click(function(){var b=$(this).data("index"),c=$(this).data("graph");if(confirm("Are you sure you want to remove "+c.datasets[b].label+" from "+c.id+"?")){c.datasets.splice(b,1);if(c.datasets.length==0){c.elements.cont.remove();var b=$(".graph_ids option:contains("+c.id+")"),d=b.parent();b.remove();d.trigger("change");UI.plot.del(c.id);delete a[c.id];
UI.plot.go(a)}else{UI.plot.save(c);b={};b[c.id]=c;UI.plot.go(b)}}}))));s();var f=!1;c.elements.plot.on("plothover",function(a,b,c){if(b.x!=f){s(b.x);f=b.x}if(c){a=$("<span>").append($("<h3>").text(c.series.label).prepend($("<div>").addClass("series-color").css("background-color",c.series.color))).append($("<table>").addClass("nolay").html($("<tr>").html($("<td>").text("Time:")).append($("<td>").html(UI.format.dateTime(c.datapoint[0]/1E3,"long")))).append($("<tr>").html($("<td>").text("Value:")).append($("<td>").html(c.series.yaxis.tickFormatter(c.datapoint[1],
c.series.yaxis)))));UI.tooltip.show(b,a.children())}else UI.tooltip.hide()}).on("mouseout",function(){s()})}}},c)}},save:function(a){var c={id:a.id,xaxis:a.xaxis,datasets:[]},b;for(b in a.datasets)c.datasets.push({origin:a.datasets[b].origin,datatype:a.datasets[b].datatype});a=mist.stored.get().graphs||{};a[c.id]=c;mist.stored.set("graphs",a)},del:function(a){var c=mist.stored.get().graphs||{};delete c[a];mist.stored.set("graphs",c)},datatype:{getOptions:function(a){var c=$.extend(!0,{},UI.plot.datatype.templates.general),
b=$.extend(!0,{},UI.plot.datatype.templates[a.datatype]),a=$.extend(!0,b,a),a=$.extend(!0,c,a);switch(a.origin[0]){case "total":switch(a.datatype){case "cpuload":case "memload":break;default:a.label+=" (total)"}break;case "stream":case "protocol":a.label+=" ("+a.origin[1]+")"}var c=[],d;for(d in a.basecolor)b=a.basecolor[d],b+=50*(0.5-Math.random()),b=Math.round(b),b=Math.min(255,Math.max(0,b)),c.push(b);a.color="rgb("+c.join(",")+")";return a},templates:{general:{display:!0,datatype:"general",label:"",
yaxistype:"amount",data:[],lines:{show:!0},points:{show:!1},getdata:function(){var a=mist.data.totals["stream"==this.origin[0]?this.origin[1]:"all_streams"]["protocol"==this.origin[0]?this.origin[1]:"all_protocols"][this.datatype];return this.data=a}},cpuload:{label:"CPU use",yaxistype:"percentage",basecolor:[237,194,64],cores:1,getdata:function(){var a=!1,c;for(c in this.data)this.data[c][0]<1E3*(mist.data.config.time-600)&&(a=c);!1!==a&&this.data.splice(0,Number(a)+1);this.data.push([1E3*mist.data.config.time,
mist.data.capabilities.cpu_use/10]);return this.data}},memload:{label:"Memory load",yaxistype:"percentage",basecolor:[175,216,248],getdata:function(){var a=!1,c;for(c in this.data)this.data[c][0]<1E3*(mist.data.config.time-600)&&(a=c);!1!==a&&this.data.splice(0,Number(a)+1);this.data.push([1E3*mist.data.config.time,mist.data.capabilities.load.memory]);return this.data}},clients:{label:"Connections",basecolor:[203,75,75]},upbps:{label:"Bandwidth up",yaxistype:"bytespersec",basecolor:[77,167,77]},downbps:{label:"Bandwidth down",
yaxistype:"bytespersec",basecolor:[148,64,237]}}},yaxes:{percentage:{name:"percentage",color:"black",tickColor:0,tickDecimals:0,tickFormatter:function(a){return UI.format.addUnit(UI.format.number(a),"%")},tickLength:0,min:0,max:100},amount:{name:"amount",color:"black",tickColor:0,tickDecimals:0,tickFormatter:function(a){return UI.format.number(a)},tickLength:0,min:0},bytespersec:{name:"bytespersec",color:"black",tickColor:0,tickDecimals:1,tickFormatter:function(a){return UI.format.bytes(a,!0)},tickLength:0,
ticks:function(a){var c=0.3*Math.sqrt($(".graph").first().height()),c=(a.max-a.min)/c,b=Math.floor(Math.log(Math.abs(c))/Math.log(1024)),d=c/Math.pow(1024,b),e=-Math.floor(Math.log(d)/Math.LN10),j=a.tickDecimals;null!=j&&e>j&&(e=j);var n=Math.pow(10,-e),d=d/n,g;if(1.5>d)g=1;else if(3>d){if(g=2,2.25<d&&(null==j||e+1<=j))g=2.5,++e}else g=7.5>d?5:10;g=g*n*Math.pow(1024,b);null!=a.minTickSize&&g<a.minTickSize&&(g=a.minTickSize);a.delta=c;a.tickDecimals=Math.max(0,null!=j?j:e);a.tickSize=g;c=[];b=a.tickSize*
Math.floor(a.min/a.tickSize);e=0;j=Number.NaN;do n=j,j=b+e*a.tickSize,c.push(j),++e;while(j<a.max&&j!=n);return c},min:0}},xaxes:{time:{name:"time",mode:"time",timezone:"browser",ticks:5}}},draggable:function(a){a.attr("draggable",!0);a.on("dragstart",function(a){$(this).css("opacity",0.4).data("dragstart",{click:{x:a.originalEvent.pageX,y:a.originalEvent.pageY},ele:{x:this.offsetLeft,y:this.offsetTop}})}).on("dragend",function(a){var b=$(this).data("dragstart"),d=b.ele.x-b.click.x+a.originalEvent.pageX,
a=b.ele.y-b.click.y+a.originalEvent.pageY;$(this).css({opacity:1,top:a,left:d,right:"auto",bottom:"auto"})});a.parent().on("dragleave",function(){})},format:{time:function(a,c){var b=new Date(1E3*a),d=[];d.push(("0"+b.getHours()).slice(-2));d.push(("0"+b.getMinutes()).slice(-2));"short"!=c&&d.push(("0"+b.getSeconds()).slice(-2));return d.join(":")},date:function(a,c){var b=new Date(1E3*a),d="Sun Mon Tue Wed Thu Fri Sat".split(" "),e=[];"long"==c&&e.push(d[b.getDay()]);e.push(("0"+b.getDate()).slice(-2));
e.push("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" ")[b.getMonth()]);"short"!=c&&e.push(b.getFullYear());return e.join(" ")},dateTime:function(a,c){return UI.format.date(a,c)+", "+UI.format.time(a,c)},duration:function(a){var c=[0.001,1E3,60,60,24,7,1E9],b="ms sec min hr day week".split(" "),d={},e;for(e in b){var a=a/c[e],j=Math.round(a%c[Number(e)+1]);d[b[e]]=j;a-=j}var n;for(e=b.length-1;0<=e;e--)if(0<d[b[e]]){n=b[e];break}c=$("<span>");switch(n){case "week":c.append(UI.format.addUnit(d.week,
"wks, ")).append(UI.format.addUnit(d.day,"days"));break;case "day":c.append(UI.format.addUnit(d.day,"days, ")).append(UI.format.addUnit(d.hr,"hrs"));break;default:c.append([("0"+d.hr).slice(-2),("0"+d.min).slice(-2),("0"+d.sec).slice(-2)+(d.ms?"."+d.ms:"")].join(":"))}return c[0].innerHTML},number:function(a){if(isNaN(Number(a))||0==a)return a;var c=Math.pow(10,3-Math.floor(Math.log(a)/Math.LN10)-1),a=Math.round(a*c)/c;if(1E4<a){number=a.toString().split(".");for(a=/(\d+)(\d{3})/;a.test(number[0]);)number[0]=
number[0].replace(a,"$1 $2");a=number.join(".")}return a},status:function(a){var c=$("<span>");if("undefined"==typeof a.online)return c.text("Unknown, checking.."),"undefined"!=typeof a.error&&c.text(a.error),c;switch(a.online){case -1:c.text("Enabling");break;case 0:c.text("Unavailable").addClass("red");break;case 1:c.text("Active").addClass("green");break;case 2:c.text("Standby").addClass("orange");break;default:c.text(a.online)}"error"in a&&c.text(a.error);return c},capital:function(a){return a.charAt(0).toUpperCase()+
a.substring(1)},addUnit:function(a,c){var b=$("<span>").html(a);b.append($("<span>").addClass("unit").html(c));return b[0].innerHTML},bytes:function(a,c){var b="bytes KiB MiB GiB TiB PiB".split(" ");if(0==a)unit=b[0];else{var d=Math.floor(Math.log(Math.abs(a))/Math.log(1024));0>d?unit=b[0]:(a/=Math.pow(1024,d),unit=b[d])}return UI.format.addUnit(UI.format.number(a),unit+(c?"/s":""))}},navto:function(a,c){var b=location.hash,d=b.split("@");d[0]=[mist.user.name,mist.user.host].join("&");d[1]=[a,c].join("&");
"undefined"!=typeof screenlog&&screenlog.navto(d[1]);location.hash=d.join("@");location.hash==b&&$(window).trigger("hashchange")},showTab:function(a,c){var b=UI.elements.main;if(mist.user.loggedin&&!("ui_settings"in mist.data))b.html("Loading.."),mist.send(function(){UI.showTab(a,c)},{ui_settings:!0});else{var d=UI.elements.menu.css("opacity","1").find(".button").filter(function(){if($(this).find(".plain").text()==a)return!0});0<d.length&&(UI.elements.menu.find(".button.active").removeClass("active"),
d.addClass("active"));UI.elements.secondary_menu.html("");UI.interval.clear();b.html($("<h2>").text(a));switch(a){case "Login":if(mist.user.loggedin){UI.navto("Overview");break}UI.elements.menu.css("opacity","0");UI.elements.connection.status.text("Disconnected").removeClass("green").addClass("red");b.append(UI.buildUI([{type:"help",help:"Please provide your account details.<br>You were asked to set these when MistController was started for the first time. If you did not yet set any account details, log in with your desired credentials to create a new account."},
{label:"Host",help:"Url location of the MistServer API. Generally located at http://MistServerIP:4242/api","default":"http://localhost:4242/api",pointer:{main:mist.user,index:"host"}},{label:"Username",help:"Please enter your username here.",validate:["required"],pointer:{main:mist.user,index:"name"}},{label:"Password",type:"password",help:"Please enter your password here.",validate:["required"],pointer:{main:mist.user,index:"password"}},{type:"buttons",buttons:[{label:"Login",type:"save","function":function(){mist.send(function(){UI.navto("Overview")})}}]}]));
break;case "Create a new account":UI.elements.menu.css("visibility","hidden");b.append($("<p>").text("No account has been created yet in the MistServer at ").append($("<i>").text(mist.user.host)).append("."));b.append(UI.buildUI([{type:"buttons",buttons:[{label:"Select other host",type:"cancel",css:{"float":"left"},"function":function(){UI.navto("Login")}}]},{type:"custom",custom:$("<br>")},{label:"Desired username",type:"str",validate:["required"],help:"Enter your desired username. In the future, you will need this to access the Management Interface.",
pointer:{main:mist.user,index:"name"}},{label:"Desired password",type:"password",validate:["required",function(a,b){$(".match_password").not($(b)).trigger("change");return false}],help:"Enter your desired password. In the future, you will need this to access the Management Interface.",pointer:{main:mist.user,index:"password"},classes:["match_password"]},{label:"Repeat password",type:"password",validate:["required",function(a,b){return a!=$(".match_password").not($(b)).val()?{msg:'The fields "Desired password" and "Repeat password" do not match.',
classes:["red"]}:false}],help:"Repeat your desired password.",classes:["match_password"]},{type:"buttons",buttons:[{type:"save",label:"Create new account","function":function(){mist.send(function(){UI.navto("Account created")},{authorize:{new_username:mist.user.name,new_password:mist.user.password}})}}]}]));break;case "Account created":UI.elements.menu.css("visibility","hidden");b.append($("<p>").text("Your account has been created succesfully.")).append(UI.buildUI([{type:"text",text:"Would you like to enable all (currently) available protocols with their default settings?"},
{type:"buttons",buttons:[{label:"Enable protocols",type:"save","function":function(){if(mist.data.config.protocols)b.append("Unable to enable all protocols as protocol settings already exist.<br>");else{b.append("Retrieving available protocols..<br>");mist.send(function(a){var c=[],d;for(d in a.capabilities.connectors)if(a.capabilities.connectors[d].required)b.append('Could not enable protocol "'+d+'" because it has required settings.<br>');else{c.push({connector:d});b.append('Enabled protocol "'+
d+'".<br>')}b.append("Saving protocol settings..<br>");mist.send(function(){b.append("Protocols enabled. Redirecting..");setTimeout(function(){UI.navto("Overview")},5E3)},{config:{protocols:c}})},{capabilities:true})}}},{label:"Skip",type:"cancel","function":function(){UI.navto("Overview")}}]}]));break;case "Overview":var e=$("<span>").text("Loading.."),j=$("<span>"),n=$("<span>"),g=$("<span>");b.append(UI.buildUI([{type:"help",help:"You can find most basic information about your MistServer here.<br>You can also set the debug level and force a save to the config.json file that MistServer uses to save your settings. "},
{type:"span",label:"Version",pointer:{main:mist.data.config,index:"version"}},{type:"span",label:"Version check",value:e,LTSonly:!0},{type:"span",label:"Server time",value:g},{type:"span",label:"Current streams",value:j},{type:"span",label:"Current connections",value:n},$("<br>"),{type:"str",label:"Human readable name",pointer:{main:mist.data.config,index:"name"},help:"You can name your MistServer here for personal use. You'll still need to set host name within your network yourself."},{type:"debug",
label:"Debug level",pointer:{main:mist.data.config,index:"debug"},help:"You can set the amount of debug information MistServer saves in the log. A full reboot of MistServer is required before some components of MistServer can post debug information."},{type:"checkbox",label:"Force JSON file save",pointer:{main:mist.data,index:"save"},help:"Tick the box in order to force an immediate save to the config.json MistServer uses to save your settings. Saving will otherwise happen upon closing MistServer. Don't forget to press save after ticking the box."},
{type:"buttons",buttons:[{type:"save",label:"Save","function":function(){var a={config:mist.data.config};if(mist.data.save)a.save=mist.data.save;mist.send(function(){UI.navto("Overview")},a)}}]}]));if(mist.data.LTS){var p=function(){var a=mist.stored.get().update||{};"uptodate"in a?a.error?e.addClass("red").text(a.error):a.uptodate?e.text("Your version is up to date.").addClass("green"):e.addClass("red").text("Version outdated!").append($("<button>").text("Update").css({"font-size":"1em","margin-left":"1em"}).click(function(){confirm("Are you sure you want to execute a rolling update?")&&
mist.send(function(){UI.navto("Overview")},{autoupdate:true})})):e.text("Unknown")};if(!mist.stored.get().update||864E5<(new Date).getTime()-mist.stored.get().update.lastchecked){var m=mist.stored.get().update||{};m.lastchecked=(new Date).getTime();mist.send(function(a){mist.stored.set("update",$.extend(true,m,a.update));p()},{checkupdate:!0})}else p()}else e.text("");var h=function(){mist.send(function(){s()},{totals:{fields:["clients"],start:-10},active_streams:true})},s=function(){j.text(("active_streams"in
mist.data?mist.data.active_streams?mist.data.active_streams.length:0:"?")+" active, "+(mist.data.streams?Object.keys(mist.data.streams).length:0)+" configured");if("totals"in mist.data&&"all_streams"in mist.data.totals)var a=mist.data.totals.all_streams.all_protocols.clients,a=a.length?UI.format.number(a[a.length-1][1]):0;else a="Loading..";n.text(a);g.text(UI.format.dateTime(mist.data.config.time,"long"))};h();s();UI.interval.set(h,3E4);break;case "Protocols":if("undefined"==typeof mist.data.capabilities){mist.send(function(){UI.navto(a)},
{capabilities:!0});b.append("Loading..");break}var f=$("<tbody>");b.append(UI.buildUI([{type:"help",help:"You can find an overview of all the protocols and their relevant information here. You can add, edit or delete protocols."}])).append($("<button>").text("New protocol").click(function(){UI.navto("Edit Protocol")})).append($("<table>").html($("<thead>").html($("<tr>").html($("<th>").text("Protocol")).append($("<th>").text("Status")).append($("<th>").text("Settings")).append($("<th>")))).append(f));
var i=function(){function a(b){var c=mist.data.capabilities.connectors[b.connector];if(!c)return"";var d=[],e=["required","optional"],f;for(f in e)for(var g in c[e[f]])b[g]&&b[g]!=""?d.push(g+": "+b[g]):c[e[f]][g]["default"]&&d.push(g+": "+c[e[f]][g]["default"]);return $("<span>").addClass("description").text(d.join(", "))}f.html("");for(var b in mist.data.config.protocols){var c=mist.data.config.protocols[b];f.append($("<tr>").data("index",b).append($("<td>").text(c.connector)).append($("<td>").html(UI.format.status(c))).append($("<td>").html(a(c))).append($("<td>").css("text-align",
"right").html($("<button>").text("Edit").click(function(){UI.navto("Edit Protocol",$(this).closest("tr").data("index"))})).append($("<button>").text("Delete").click(function(){var a=$(this).closest("tr").data("index");if(confirm('Are you sure you want to delete the protocol "'+mist.data.config.protocols[a].connector+'"?')){mist.data.config.protocols.splice(a,1);mist.send(function(){UI.navto("Protocols")},{config:mist.data.config})}}))))}};i();UI.interval.set(function(){mist.send(function(){i()})},
3E4);break;case "Edit Protocol":if("undefined"==typeof mist.data.capabilities){mist.send(function(){UI.navto(a,c)},{capabilities:!0});b.append("Loading..");break}var l=!1;""!=c&&0<=c&&(l=!0);var k={},q;for(q in mist.data.config.protocols)k[mist.data.config.protocols[q].connector]=1;var T=function(a){var b=mist.data.capabilities.connectors[a],d=mist.convertBuildOptions(b,o);d.push({type:"hidden",pointer:{main:o,index:"connector"},value:a});d.push({type:"buttons",buttons:[{type:"save",label:"Save",
"function":function(){if(l)mist.data.config.protocols[c]=o;else{if(!mist.data.config.protocols)mist.data.config.protocols=[];mist.data.config.protocols.push(o)}mist.send(function(){UI.navto("Protocols")},{config:mist.data.config})}},{type:"cancel",label:"Cancel","function":function(){UI.navto("Protocols")}}]});if("deps"in b&&b.deps!=""){$t=$("<span>").text("Dependencies:");$ul=$("<ul>");$t.append($ul);if(typeof b.deps=="string")b.deps=b.deps.split(", ");for(var e in b.deps){a=$("<li>").text(b.deps[e]+
" ");$ul.append(a);typeof k[b.deps[e]]!="undefined"||typeof k[b.deps[e]+".exe"]!="undefined"?a.append($("<span>").addClass("green").text("(Configured)")):a.append($("<span>").addClass("red").text("(Not yet configured)"))}d.unshift({type:"text",text:$t[0].innerHTML})}return UI.buildUI(d)},k={};for(q in mist.data.config.protocols)k[mist.data.config.protocols[q].connector]=1;if(l){var r=mist.data.config.protocols[c],o=r;b.find("h2").append(' "'+r.connector+'"');b.append(T(r.connector))}else{b.html($("<h2>").text("New Protocol"));
var o={},v=[];for(q in mist.data.capabilities.connectors)v.push([q,q]);var U=$("<span>");b.append(UI.buildUI([{label:"Protocol",type:"select",select:v,"function":function(){U.html(T($(this).getval()))}}])).append(U)}break;case "Streams":if(!("capabilities"in mist.data)){b.html("Loading..");mist.send(function(){UI.navto(a)},{capabilities:!0});break}f=$("<tbody>").append($("<tr>").append("<td>").attr("colspan",6).text("Loading.."));d=$("<table>").html($("<thead>").html($("<tr>").html($("<th>").text("Stream name").attr("data-sort-type",
"string").addClass("sorting-asc")).append($("<th>").text("Source").attr("data-sort-type","string")).append($("<th>").text("Status").attr("data-sort-type","int")).append($("<th>").css("text-align","right").text("Connections").attr("data-sort-type","int")).append($("<th>")).append($("<th>")))).append(f);b.append(UI.buildUI([{type:"help",help:"Here you can create, edit or delete new and existing streams. Immidiately go to the stream preview or view the information available about the stream with the info button."}])).append($("<button>").text("New stream").click(function(){UI.navto("Edit Stream")})).append(d);
d.stupidtable();var E=function(){var a=[],b;for(b in mist.data.active_streams)a.push({streams:[mist.data.active_streams[b]],fields:["clients"],start:-2});mist.send(function(){$.extend(true,x,mist.data.streams);var a=0;f.html("");if(mist.data.LTS)for(a in mist.data.active_streams){var b=mist.data.active_streams[a].split("+");if(!(b.length<2)&&b[0]in mist.data.streams){b=V(mist.data.active_streams[a],mist.data.streams[b[0]]);b.online=1;x[mist.data.active_streams[a]]=b}}b=Object.keys(x);b.sort();for(var c in b){var d=
b[c],e;e=d in mist.data.streams?mist.data.streams[d]:x[d];var g=$("<td>").css("text-align","right").html($("<span>").addClass("description").text("Loading..")),h=0;if(typeof mist.data.totals!="undefined"&&typeof mist.data.totals[d]!="undefined"){var C=mist.data.totals[d].all_protocols.clients,h=0;if(C.length){for(a in C)h=h+C[a][1];h=Math.round(h/C.length)}}g.html(UI.format.number(h));if(h==0&&e.online==1)e.online=2;h=$("<td>").css("text-align","right").css("white-space","nowrap");(!("ischild"in e)||
!e.ischild)&&h.html($("<button>").text("Edit").click(function(){UI.navto("Edit Stream",$(this).closest("tr").data("index"))})).append($("<button>").text("Delete").click(function(){var a=$(this).closest("tr").data("index");if(confirm('Are you sure you want to delete the stream "'+a+'"?')){delete mist.data.streams[a];var b={};mist.data.LTS?b.deletestream=[a]:b.streams=mist.data.streams;mist.send(function(){UI.navto("Streams")},b)}}));C=$("<span>").text(d);e.ischild&&C.css("padding-left","1em");var i=
UI.format.status(e),j=$("<button>").text("Preview").click(function(){UI.navto("Preview",$(this).closest("tr").data("index"))});if(e.filesfound){i.html("");j="";g.html("")}f.append($("<tr>").data("index",d).html($("<td>").html(C).attr("title",d).addClass("overflow_ellipsis")).append($("<td>").text(e.source).attr("title",e.source).addClass("description").addClass("overflow_ellipsis").css("max-width","20em")).append($("<td>").data("sort-value",e.online).html(i)).append(g).append($("<td>").html(j)).append(h));
a++}},{totals:a,active_streams:true})},x=$.extend(!0,{},mist.data.streams),V=function(a,b){var c=$.extend({},b);delete c.meta;delete c.error;c.online=2;c.name=a;c.ischild=true;return c};if(mist.data.LTS){var B=0,F=0;for(h in mist.data.streams)r=mist.data.capabilities.inputs.Folder||mist.data.capabilities.inputs["Folder.exe"],mist.inputMatch(r.source_match,mist.data.streams[h].source)&&(x[h].source+="*",mist.send(function(a,b){var c=b.stream,d;for(d in a.browse.files)for(var e in mist.data.capabilities.inputs)if(!(e.indexOf("Buffer")>=
0||e.indexOf("Folder")>=0)&&mist.inputMatch(mist.data.capabilities.inputs[e].source_match,"/"+a.browse.files[d])){var g=c+"+"+a.browse.files[d];x[g]=V(g,mist.data.streams[c]);x[g].source=mist.data.streams[c].source+a.browse.files[d]}"files"in a.browse&&a.browse.files.length?x[c].filesfound=true:mist.data.streams[c].filesfound=false;F++;if(B==F){mist.send(function(){E()},{active_streams:true});UI.interval.set(function(){E()},1E4)}},{browse:mist.data.streams[h].source},{stream:h}),B++);0==B&&(mist.send(function(){E()},
{active_streams:!0}),UI.interval.set(function(){E()},3E4))}else mist.send(function(){E()},{active_streams:!0}),UI.interval.set(function(){E()},1E4);break;case "Edit Stream":if("undefined"==typeof mist.data.capabilities){mist.send(function(){UI.navto(a,c)},{capabilities:!0});b.append("Loading..");break}l=!1;""!=c&&(l=!0);l?(h=c,o=mist.data.streams[h],b.find("h2").append(' "'+h+'"')):(b.html($("<h2>").text("New Stream")),o={});h=[];for(q in mist.data.capabilities.inputs)h.push(mist.data.capabilities.inputs[q].source_match);
var I=$("<div>");b.append(UI.buildUI([{label:"Stream name",type:"str",validate:["required","streamname"],pointer:{main:o,index:"name"},help:"Set the name this stream will be recognised by for players and/or stream pushing."},{label:"Source",type:"browse",validate:["required"],filetypes:h,pointer:{main:o,index:"source"},help:'Set the stream source.<table><tr><td>VoD:</td><td>You can browse to the file or folder as a source or simply enter the path to the file.</td></tr><tr><td>Live:</td><td>You\'ll need to enter "push://IP" with the IP of the machine pushing towards MistServer.<br>You can use "push://" to accept any source.</td></tr><tr><td>(Pro only)</td><td>Use "push://(IP)@password" to set a password protection for pushes.</td></tr></table>If you\'re unsure how to set the source properly, please view our Live pushing guide at the tools section.',
"function":function(){var a=$(this).val();if(a!=""){var b=null,c;for(c in mist.data.capabilities.inputs)if(typeof mist.data.capabilities.inputs[c].source_match!="undefined"&&mist.inputMatch(mist.data.capabilities.inputs[c].source_match,a)){b=c;break}if(b===null)I.html($("<h3>").text("Unrecognized input").addClass("red")).append($("<span>").text("Please edit the stream source.").addClass("red"));else{a=mist.data.capabilities.inputs[b];I.html($("<h3>").text(a.name+" Input options"));a=mist.convertBuildOptions(a,
o);I.append(UI.buildUI(a))}}}},$("<br>"),{type:"custom",custom:I},$("<br>"),$("<h3>").text("Encryption"),{type:"help",help:"To enable encryption, the licence acquisition url must be entered, as well as either the content key or the key ID and seed.<br>Unsure how you should fill in your encryption or missing your preferred encryption? Please contact us."},{label:"License acquisition url",type:"str",LTSonly:!0,pointer:{main:o,index:"la_url"}},$("<br>"),{label:"Content key",type:"str",LTSonly:!0,pointer:{main:o,
index:"contentkey"}},{type:"text",text:" - or - "},{label:"Key ID",type:"str",LTSonly:!0,pointer:{main:o,index:"keyid"}},{label:"Key seed",type:"str",LTSonly:!0,pointer:{main:o,index:"keyseed"}},{type:"buttons",buttons:[{type:"cancel",label:"Cancel","function":function(){UI.navto("Streams")}},{type:"save",label:"Save","function":function(){if(!mist.data.streams)mist.data.streams={};mist.data.streams[o.name]=o;c!=o.name&&delete mist.data.streams[c];var a={};if(mist.data.LTS){a.addstream={};a.addstream[o.name]=
o;if(c!=o.name)a.deletestream=[c]}else a.streams=mist.data.streams;mist.send(function(){delete mist.data.streams[o.name].online;delete mist.data.streams[o.name].error;UI.navto("Streams")},a)}}]}]));break;case "Preview":if(""==c){b.append("Loading..");var L=function(c){var d={};c.sort();b.html($("<h2>").text(a)).append(UI.buildUI([{label:"Select a stream",type:"select",select:c,pointer:{main:d,index:"stream"}},{type:"buttons",buttons:[{type:"save",label:"Go","function":function(){UI.navto(a,d.stream)}}]}]));
UI.elements.secondary_menu.html("").append($("<a>").addClass("button").addClass("active").text("Choose stream").click(function(){UI.navto("Preview")}));var e=$("<div>").addClass("preview_icons");b.append($("<span>").addClass("description").text("Or, click a stream from the list below.")).append(e);for(var g in c){var f=c[g],h="";if(f.indexOf("+")>-1){h=f.split("+");h=mist.data.streams[h[0]].source+h[1]}else h=mist.data.streams[f].source;e.append($("<button>").append($("<span>").text(f)).append($("<span>").addClass("description").text(h)).attr("title",
f).attr("data-stream",f).click(function(){UI.navto("Preview",$(this).attr("data-stream"))}))}};if(mist.data.LTS){if("undefined"==typeof mist.data.capabilities){mist.send(function(){UI.navto(a,c)},{capabilities:!0});b.append("Loading..");break}F=B=0;v={};for(h in mist.data.streams)r=mist.data.capabilities.inputs.Folder||mist.data.capabilities.inputs["Folder.exe"],mist.inputMatch(r.source_match,mist.data.streams[h].source)&&(mist.send(function(a,b){var c=b.stream,d;for(d in mist.data.browse.files)for(var e in mist.data.capabilities.inputs)e.indexOf("Buffer")>=
0||e.indexOf("Folder")>=0||mist.inputMatch(mist.data.capabilities.inputs[e].source_match,"/"+mist.data.browse.files[d])&&(v[c+"+"+mist.data.browse.files[d]]=true);F++;B==F&&mist.send(function(){for(var a in mist.data.active_streams){var b=mist.data.active_streams[a].split("+");b.length>1&&b[0]in mist.data.streams&&(v[mist.data.active_streams[a]]=true)}v=Object.keys(v);v=v.concat(Object.keys(mist.data.streams));v.sort();L(v)},{active_streams:true})},{browse:mist.data.streams[h].source},{stream:h}),
B++);0==B&&mist.send(function(){var c=[],d;for(d in mist.data.active_streams){var e=mist.data.active_streams[d].split("+");e.length>1&&e[0]in mist.data.streams&&(c[mist.data.active_streams[d]]=true)}mist.data.streams&&(c=c.concat(Object.keys(mist.data.streams)));if(c.length==0)b.html($("<h2>").text(a)).append("Please set up a stream first.");else{c.sort();L(c)}},{active_streams:!0})}else L(Object.keys(mist.data.streams));break}b.find("h2").append(' of "'+c+'"');h=":8080";for(q in mist.data.config.protocols)if(r=
mist.data.config.protocols[q],"HTTP"==r.connector||"HTTP.exe"==r.connector)h=r.port?":"+r.port:":8080";var D={},r=$("<span>").hide();D["Embed urls"]=r;b.append(r);var d="",W=mist.user.host.match(/(https?)\:\/\/([^:\/]+)\:(\d+)?/i);null!=W&&(d=W[2]);var G="http://"+d+h+"/",w={},J=function(a){var b=["div"],d='\n <script src="'+G+"embed_"+c+'.js"><\/script>\n';a.autoplay&&b.push("data-autoplay");a.forceprotocol&&a.forceprotocol!=""&&b.push('data-forcetype="'+a.forceprotocol+'"');a.urlappend&&a.urlappend!=
""&&b.push('data-urlappend="'+a.urlappend.replace(/\"/g,'\\"')+'"');return"<"+b.join(" ")+">"+d+"</div>"},X=$("<span>");r.append($("<h3>").text("Embed urls")).append(UI.buildUI([{label:"Embedable script",type:"str",value:G+"embed_"+c+".js",readonly:!0},{label:"Stream info script",type:"str",value:G+"info_"+c+".js",readonly:!0},{label:"Autodetect player",type:"str",value:G+c+".html",readonly:!0,qrcode:!0},$("<h3>").text("Embed code"),{label:"Embed code",type:"textarea",value:J(w),rows:4,readonly:!0,
classes:["embed_code"]},$("<h4>").text("Embed code options").css("margin-top",0),{label:"Autoplay",type:"checkbox",pointer:{main:w,index:"autoplay"},"function":function(){w.autoplay=$(this).getval();$(".embed_code").setval(J(w))}},{label:"Force protocol",type:"select",select:[["","Automatic"]],pointer:{main:w,index:"protocol"},classes:["embed_code_forceprotocol"],"function":function(){w.forceprotocol=$(this).getval();$(".embed_code").setval(J(w))}},{label:"Video URL addition",type:"str",pointer:{main:w,
index:"urlappend"},help:"The embed script will append this string to the video url, useful for sending through params.",classes:["embed_code_forceprotocol"],"function":function(){w.urlappend=$(this).getval();$(".embed_code").setval(J(w))}},$("<h3>").text("Protocol stream urls"),X]));h=$("<span>").append($("<h3>").text("Meta information")).hide();D["Meta information"]=h;var M=$("<span>");h.append(M);b.append(h);h=$("<span>").hide();D.Preview=h;b.append(h);var z=$("<div>").css("float","left").css("margin-right",
"1em").attr("data-forcesupportcheck",""),Y=$("<div>").css("float","left");h.append(z).append(Y);mist.stored.get().autoplay&&z.attr("data-autoplay","");var K=function(){z.text("Loading..");var a=document.createElement("script");a.src=G+"embed_"+c+".js";a.onerror=function(){z.html('Error loading "'+a.src+'".<br>').append($("<button>").text("Try again").click(function(){K()}))};a.onload=function(){if(typeof mistvideo[c].error!="undefined")z.html(mistvideo[c].error+"<br>").append($("<button>").text("Try again").click(function(){K()}));
else{var a=mistvideo[c],b=UI.buildUI([{label:"Protocol stream url",type:"str",readonly:true,value:a.embedded?a.embedded.url:"",qrcode:true},{label:"Autoplay (from now on)",type:"checkbox",value:mist.stored.get().autoplay,"function":function(){mist.stored.set("autoplay",$(this).getval()?1:0)}}]);b.find(".help_container").remove();z.append(b);var d=$("<table>").css("font-size","0.9em").html($("<thead>").html($("<tr>").html($("<th>")).append($("<th>").text("Type")).append($("<th>").text("Priority")).append($("<th>").text("Simul. tracks")).append($("<th>").html("Your browser<br>support"))));
Y.html(d);b=$("<tbody>");d.append(b);var d=$(".embed_code_forceprotocol"),e=[];d.find(".clear").remove();for(var g in a.source){var f=a.source[g],h=f.type.split("/"),i=h[0];i.length<6&&(i=i.toUpperCase());switch(h.length){case 1:break;case 2:i=UI.format.capital(h[0])+" v"+h[1];if(h[0]=="flash")switch(h[1]){case "7":i="Progressive ("+i+")";break;case "10":i="RTMP ("+i+")";break;case "11":i="HDS ("+i+")"}break;case 3:switch(h[2]){case "vnd.apple.mpegurl":i=i+" HLS";break;case "vnd.ms-ss":i=i+" Smooth";
break;case "mp2t":i=i+" TS";break;default:h[2].length<6&&(h[2]=h[2].toUpperCase());i=i+(" "+h[2]);h[1]!="video"&&(i=i+(" ("+h[1]+")"))}break;default:i=f.type}i=UI.format.capital(i);d.append($("<option>").text(i).val(f.type).addClass("clear"));e.push({label:i,type:"str",value:f.url,readonly:true,qrcode:true});h=$("<tr>");b.append(h);h.html($("<td>").html($("<input>").attr("type","radio").attr("name","protocolforce").change(function(){z.attr("data-forcetype",$(this).val()).html("Loading embed..");K()}).val(f.type))).append($("<td>").text(i)).append($("<td>").text(f.priority)).append($("<td>").text(f.simul_tracks+
"/"+f.total_matches)).append($("<td>").text(f.browser_support?"yes":"no"));if(a.embedded&&a.embedded.type==f.type){h.css("outline","1px solid rgba(0,0,0,0.5)");h.find("input[type=radio]").prop("checked",true)}}X.html(UI.buildUI(e));var j;if(c in mistvideo)j=mistvideo[c].meta;if(j){a=[];a.push({label:"Type",type:"span",value:j.live?"Live":"Pre-recorded (VoD)"});"format"in j&&a.push({label:"Format",type:"span",value:j.format});j.live&&a.push({label:"Buffer window",type:"span",value:UI.format.addUnit(j.buffer_window,
"ms")});b={vheader:"Audio",labels:["Codec","Duration","Peak bitrate","Channels","Samplerate"],content:[]};g={vheader:"Video",labels:["Codec","Duration","Peak bitrate","Size","Framerate"],content:[]};d=Object.keys(j.tracks);d.sort(function(a,b){a=a.split("_").pop();b=b.split("_").pop();return a-b});for(var k in d){e=d[k];f=j.tracks[e];switch(f.type){case "audio":b.content.push({header:"Track "+e.split("_").pop(),body:[f.codec,UI.format.duration((f.lastms-f.firstms)/1E3)+"<br><span class=description>"+
UI.format.duration(f.firstms/1E3)+" to "+UI.format.duration(f.lastms/1E3)+"</span>",UI.format.bytes(f.bps,1),f.channels,UI.format.addUnit(UI.format.number(f.rate),"Hz")]});break;case "video":g.content.push({header:"Track "+e.split("_").pop(),body:[f.codec,UI.format.duration((f.lastms-f.firstms)/1E3)+"<br><span class=description>"+UI.format.duration(f.firstms/1E3)+" to "+UI.format.duration(f.lastms/1E3)+"</span>",UI.format.bytes(f.bps,1),UI.format.addUnit(f.width,"x ")+UI.format.addUnit(f.height,"px"),
UI.format.addUnit(UI.format.number(f.fpks/1E3),"fps")]})}}j=UI.buildVheaderTable(b).css("width","auto");k=UI.buildVheaderTable(g).css("width","auto");a.push($("<span>").text("Tracks:"));a.push($("<div>").css({display:"flex","flex-flow":"row wrap","justify-content":"center","font-size":"0.9em"}).append(j).append(k));M.html(UI.buildUI(a))}else M.html("No meta information available.")}};z.html("")[0].appendChild(a)};K();var N=UI.elements.secondary_menu;N.html("").append($("<a>").addClass("button").text("Choose stream").click(function(){UI.navto("Preview")})).append($("<span>").addClass("separator"));
h=["Preview","Embed urls","Meta information"];k=h[0];for(q in h)r=$("<a>").addClass("button").text(h[q]).click(function(){N.find(".active").removeClass("active");$(this).addClass("active");for(q in D)D[q].hide();D[$(this).text()].show()}),N.append(r),h[q]==k&&(r.addClass("active"),D[k].show());break;case "Push":var y=$("<div>").text("Loading..");b.append(y);mist.send(function(a){function b(a,c){var d=$("<span>");a.length>=4&&a[2]!=a[3]?d.append($("<span>").text(a[2])).append($("<span>").html("&#187").addClass("unit").css("margin",
"0 0.5em")).append($("<span>").text(a[3])):d.append($("<span>").text(a[2]));return $("<tr>").append($("<td>").text(a[1])).append($("<td>").append(d.children())).append($("<td>").append($("<button>").text(c=="Automatic"?"Remove":"Stop").click(function(){if(confirm("Are you sure you want to "+$(this).text().toLowerCase()+" this push?\n"+a[1]+" to "+a[2])){var b=$(this).closest("tr");b.html($("<td colspan=99>").html($("<span>").addClass("red").text(c=="Automatic"?"Removing..":"Stopping..")));c=="Automatic"?
mist.send(function(){b.remove()},{push_auto_remove:{stream:a[1],target:a[2]}}):mist.send(function(){function c(){setTimeout(function(){mist.send(function(d){var f=false;if("push_list"in d&&d.push_list&&d.push_list.length){var f=true,e;for(e in d.push_list)if(d.push_list[e][0]==a[0]){f=false;break}}else f=true;f?b.remove():c()},{push_list:1})},1E3)}c()},{push_stop:[a[0]]})}})))}y.html("");var c=a.push_settings;c||(c={});y.append(UI.buildUI([{type:"help",help:"You can push streams to files or other servers, allowing them to broadcast your stream as well."},
$("<h3>").text("Settings"),{label:"Delay before retry",unit:"s",type:"int",min:0,help:"How long the delay should be before MistServer retries an automatic push.<br>If set to 0, it does not retry.","default":0,pointer:{main:c,index:"wait"}},{label:"Maximum retries",unit:"/s",type:"int",min:0,help:"The maximum amount of retries per second (for all automatic pushes).<br>If set to 0, there is no limit.","default":0,pointer:{main:c,index:"maxspeed"}},{type:"buttons",buttons:[{type:"save",label:"Save",
"function":function(){mist.send(function(){UI.navto("Push")},{push_settings:c})}}]}]));var d=$("<table>").append($("<tr>").append($("<th>").text("Stream")).append($("<th>").text("Target")).append($("<th>"))),e=d.clone();if("push_list"in a)for(var f in a.push_list)d.append(b(a.push_list[f],"Manual"));if("push_auto_list"in a)for(f in a.push_auto_list)e.append(b([-1,a.push_auto_list[f][0],a.push_auto_list[f][1]],"Automatic"));y.append($("<h3>").text("Automatic pushes")).append($("<button>").text("Add an automatic push").click(function(){UI.navto("Start Push",
"auto")}));e.find("tr").length==1?y.append($("<div>").text("No automatic pushes have been configured.").addClass("text").css("margin-top","0.5em")):y.append(e);y.append($("<h3>").text("Pushes")).append($("<button>").text("Start a push").click(function(){UI.navto("Start Push")}));d.find("tr").length==1?y.append($("<div>").text("No pushes are active.").addClass("text").css("margin-top","0.5em")):y.append($("<button>").text("Stop all pushes").click(function(){var b=[],c;for(c in a.push_list)b.push(a.push_list[c][0]);
if(b.length!=0&&confirm("Are you sure you want to stop all pushes?")){mist.send(function(){function a(){setTimeout(function(){mist.send(function(c){var d=false;if("push_list"in c&&c.push_list&&c.push_list.length){var d=true,f;for(f in c.push_list)if(b.indexOf(c.push_list[f][0])==-1){d=false;break}}else d=true;d?UI.navto("Push"):a()},{push_list:1})},1E3)}a()},{push_stop:b});d.find("tr:not(:first-child)").html($("<td colspan=99>").append($("<span>").addClass("red").text("Stopping..")));$(this).remove()}})).append(d)},
{push_settings:1,push_list:1,push_auto_list:1});break;case "Start Push":if(!("capabilities"in mist.data)){b.append("Loading Mist capabilities..");mist.send(function(){UI.navto("Start Push")},{capabilities:1});break}var t,O=function(){var a=[],d;for(d in mist.data.capabilities.connectors){var f=mist.data.capabilities.connectors[d];"push_urls"in f&&(a=a.concat(f.push_urls))}c=="auto"&&b.find("h2").text("Add automatic push");var e={};b.append(UI.buildUI([{label:"Stream name",type:"str",help:"This may either be a full stream name, a partial wildcard stream name, or a full wildcard stream name.<br>For example, given the stream <i>a</i> you can use:<ul><li><i>a</i>: the stream configured as <i>a</i></li><li><i>a+</i>: all streams configured as <i>a</i> with a wildcard behind it, but not <i>a</i> itself</li><li><i>a+b</i>: only the version of stream <i>a</i> that has wildcard <i>b</i></li></ul>",
pointer:{main:e,index:"stream"},validate:["required",function(a){a=a.split("+");a=a[0];return a in mist.data.streams?false:{msg:"'"+a+"' is not a stream name.",classes:["red"]}}],datalist:t},{label:"Target",type:"str",help:"Where the stream will be pushed to.<br>Valid formats:<ul><li>"+a.join("</li><li>")+"</li></ul>",pointer:{main:e,index:"target"},validate:["required",function(b){for(var c in a)if(mist.inputMatch(a[c],b))return false;return{msg:"Does not match a valid target.<br>Valid formats:<ul><li>"+
a.join("</li><li>")+"</li></ul>",classes:["red"]}}]},{type:"buttons",buttons:[{type:"cancel",label:"Cancel","function":function(){UI.navto("Push")}},{type:"save",label:"Save","function":function(){var a={};a[c=="auto"?"push_auto_add":"push_start"]=e;mist.send(function(){UI.navto("Push")},a)}}]}]))};mist.data.LTS?mist.send(function(a){(t=a.active_streams)||(t=[]);var a=[],b;for(b in t)t[b].indexOf("+")!=-1&&a.push(t[b].replace(/\+.*/,"")+"+");t=t.concat(a);var c=0,d=0;for(b in mist.data.streams){t.push(b);
if(mist.inputMatch(mist.data.capabilities.inputs.Folder.source_match,mist.data.streams[b].source)){t.push(b+"+");mist.send(function(a,b){var f=b.stream,e;for(e in a.browse.files)for(var g in mist.data.capabilities.inputs)g.indexOf("Buffer")>=0||g.indexOf("Folder")>=0||mist.inputMatch(mist.data.capabilities.inputs[g].source_match,"/"+a.browse.files[e])&&t.push(f+"+"+a.browse.files[e]);d++;if(c==d){t=t.filter(function(a,b,c){return c.lastIndexOf(a)===b}).sort();O()}},{browse:mist.data.streams[b].source},
{stream:b});c++}}if(c==d){t=t.filter(function(a,b,c){return c.lastIndexOf(a)===b}).sort();O()}},{active_streams:1}):(t=Object.keys(mist.data.streams),O());break;case "Triggers":"triggers"in mist.data.config||(mist.data.config.triggers={});f=$("<tbody>");d=$("<table>").html($("<thead>").html($("<tr>").html($("<th>").text("Trigger on").attr("data-sort-type","string").addClass("sorting-asc")).append($("<th>").text("Applies to").attr("data-sort-type","string")).append($("<th>").text("Handler").attr("data-sort-type",
"string")).append($("<th>")))).append(f);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($("<button>").text("New trigger").click(function(){UI.navto("Edit Trigger")})).append(d);d.stupidtable();h=mist.data.config.triggers;
for(q in h)for(r in h[q])f.append($("<tr>").attr("data-index",q+","+r).append($("<td>").text(q)).append($("<td>").text(h[q][r][2].join(", "))).append($("<td>").text(h[q][r][0])).append($("<td>").html($("<button>").text("Edit").click(function(){UI.navto("Edit Trigger",$(this).closest("tr").attr("data-index"))})).append($("<button>").text("Delete").click(function(){var a=$(this).closest("tr").attr("data-index").split(",");if(confirm("Are you sure you want to delete this "+a[0]+" trigger?")){mist.data.config.triggers[a[0]].splice(a[1],
1);mist.data.config.triggers[a[0]].length==0&&delete mist.data.config.triggers[a[0]];mist.send(function(){UI.navto("Triggers")},{config:mist.data.config})}}))));break;case "Edit Trigger":"triggers"in mist.data.config||(mist.data.config.triggers={});c?(c=c.split(","),h=mist.data.config.triggers[c[0]][c[1]],o={triggeron:c[0],appliesto:h[2],url:h[0],async:h[1],"default":h[3]}):(b.html($("<h2>").text("New Trigger")),o={});b.append(UI.buildUI([{label:"Trigger on",pointer:{main:o,index:"triggeron"},help:"For what event this trigger should activate.",
type:"select",select:[["SYSTEM_START","SYSTEM_START: after MistServer boot"],["SYSTEM_STOP","SYSTEM_STOP: right before MistServer shutdown"],["SYSTEM_CONFIG","SYSTEM_CONFIG: after MistServer configurations have changed"],["OUTPUT_START","OUTPUT_START: right after the start command has been send to a protocol"],["OUTPUT_STOP","OUTPUT_STOP: right after the close command has been send to a protocol "],["STREAM_ADD","STREAM_ADD: right before new stream configured"],["STREAM_CONFIG","STREAM_CONFIG: right before a stream configuration has changed"],
["STREAM_REMOVE","STREAM_REMOVE: right before a stream has been deleted"],["STREAM_SOURCE","STREAM_SOURCE: right before stream source is loaded"],["STREAM_LOAD","STREAM_LOAD: right before stream input is loaded in memory"],["STREAM_READY","STREAM_READY: when the stream input is loaded and ready for playback"],["STREAM_UNLOAD","STREAM_UNLOAD: right before the stream input is removed from memory"],["STREAM_PUSH","STREAM_PUSH: right before an incoming push is accepted"],["STREAM_TRACK_ADD","STREAM_TRACK_ADD: right before a track will be added to a stream; e.g.: additional push received"],
["STREAM_TRACK_REMOVE","STREAM_TRACK_REMOVE: right before a track will be removed track from a stream; e.g.: push timeout"],["STREAM_BUFFER","STREAM_BUFFER: when a buffer changes between mostly full or mostly empty"],["RTMP_PUSH_REWRITE","RTMP_PUSH_REWRITE: allows rewriting of RTMP push URLs from external to internal representation before further parsing"],["PUSH_OUT_START","RECORDING_VALIDATE: before recording/pushing, allow target changes."],["CONN_OPEN","CONN_OPEN: right after a new incoming connection has been received"],
["CONN_CLOSE","CONN_CLOSE: right after a connection has been closed"],["CONN_PLAY","CONN_PLAY: right before a stream playback of a connection"],["USER_NEW","USER_NEW: A new user connects that hasn't been allowed or denied access before"]],LTSonly:!0,"function":function(){switch($(this).getval()){case "SYSTEM_START":case "SYSTEM_STOP":case "SYSTEM_CONFIG":case "OUTPUT_START":case "OUTPUT_STOP":case "RTMP_PUSH_REWRITE":$("[name=appliesto]").setval([]).closest(".UIelement").hide();break;default:$("[name=appliesto]").closest(".UIelement").show()}}},
{label:"Applies to",pointer:{main:o,index:"appliesto"},help:"For triggers that can apply to specific streams, this value decides what streams they are triggered for. (none checked = always triggered)",type:"checklist",checklist:Object.keys(mist.data.streams),LTSonly:!0},$("<br>"),{label:"Handler (URL or executable)",help:"This can be either an HTTP URL or a full path to an executable.",pointer:{main:o,index:"url"},validate:["required"],type:"str",LTSonly:!0},{label:"Blocking",type:"checkbox",help:"If checked, pauses processing and uses the response of the handler. If the response does not start with 1, true, yes or cont, further processing is aborted. If unchecked, processing is never paused and the response is not checked.",
pointer:{main:o,index:"async"},LTSonly:!0},{label:"Default response",type:"str",help:"For blocking requests, the default response in case the handler cannot be executed for any reason.",pointer:{main:o,index:"default"},LTSonly:!0},{type:"buttons",buttons:[{type:"cancel",label:"Cancel","function":function(){UI.navto("Triggers")}},{type:"save",label:"Save","function":function(){c&&mist.data.config.triggers[c[0]].splice(c[1],1);var a=[o.url,o.async?true:false,typeof o.appliesto!="undefined"?o.appliesto:
[]];typeof o["default"]!="undefined"&&a.push(o["default"]);o.triggeron in mist.data.config.triggers||(mist.data.config.triggers[o.triggeron]=[]);mist.data.config.triggers[o.triggeron].push(a);mist.send(function(){UI.navto("Triggers")},{config:mist.data.config})}}]}]));$("[name=triggeron]").trigger("change");break;case "Logs":var Z=$("<button>").text("Refresh now").click(function(){$(this).text("Loading..");mist.send(function(){P();Z.text("Refresh now")})}).css("padding","0.2em 0.5em").css("flex-grow",
0);b.append(UI.buildUI([{type:"help",help:"Here you have an overview of all edited settings within MistServer and possible warnings or errors MistServer has encountered. MistServer stores up to 100 logs at a time."},{label:"Refresh every",type:"select",select:[[10,"10 seconds"],[30,"30 seconds"],[60,"minute"],[300,"5 minutes"]],value:30,"function":function(){UI.interval.clear();UI.interval.set(function(){mist.send(function(){P()})},$(this).val()*1E3)},help:"How often the table below should be updated."},
{label:"..or",type:"DOMfield",DOMfield:Z,help:"Instantly refresh the table below."}]));b.append($("<button>").text("Purge logs").click(function(){mist.send(function(){mist.data.log=[];UI.navto("Logs")},{clearstatlogs:true})}));f=$("<tbody>").css("font-size","0.9em");b.append($("<table>").append(f));var ba=function(a){var b=$("<span>").text(a);switch(a){case "WARN":b.addClass("orange");break;case "ERROR":case "FAIL":b.addClass("red")}return b},P=function(){var a=mist.data.log;if(a){a.length>=2&&a[0][0]<
a[a.length-1][0]&&a.reverse();f.html("");for(var b in a)f.append($("<tr>").html($("<td>").text(UI.format.dateTime(a[b][0],"long")).css("white-space","nowrap")).append($("<td>").html(ba(a[b][1])).css("text-align","center")).append($("<td>").text(a[b][2]).css("text-align","left")))}};P();break;case "Statistics":var A=$("<span>").text("Loading..");b.append(A);var o={},u=mist.stored.get().graphs?$.extend(!0,{},mist.stored.get().graphs):{},H={};for(q in mist.data.streams)H[q]=!0;for(q in mist.data.active_streams)H[mist.data.active_streams[q]]=
!0;var H=Object.keys(H).sort(),Q=[];for(q in mist.data.config.protocols)Q.push(mist.data.config.protocols[q].connector);Q.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;A.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."},
$("<h3>").text("Select the data to display"),{label:"Add to",type:"select",select:[["new","New graph"]],pointer:{main:o,index:"graph"},classes:["graph_ids"],"function":function(){if($(this).val()){var a=A.find(".graph_xaxis"),b=A.find(".graph_id");if($(this).val()=="new"){a.children("option").prop("disabled",false);b.setval("Graph "+(Object.keys(u).length+1)).closest("label").show()}else{var c=u[$(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:o,index:"id"},classes:["graph_id"],validate:[function(a){return a in u?{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:o,index:"xaxis"},classes:["graph_xaxis"],
"function":function(){$s=A.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 use"],["memload","Memory load"],["coords","Client location"]],pointer:{main:o,index:"datatype"},classes:["graph_datatype"],"function":function(){$s=A.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:",H],["protocol","The protocol:",Q]],pointer:{main:o,index:"origin"},value:["total"],classes:["graph_origin"]},{type:"buttons",buttons:[{label:"Add data set",type:"save","function":function(){var a;if(o.graph=="new"){a=UI.plot.addGraph(o,c);u[a.id]=a;A.find("select.graph_ids").append($("<option>").text(a.id)).val(a.id).trigger("change")}else a=u[o.graph];var b=UI.plot.datatype.getOptions({datatype:o.datatype,
origin:o.origin});a.datasets.push(b);UI.plot.save(a);UI.plot.go(u)}}]}]));var c=$("<div>").addClass("graph_container");b.append(c);var d=A.find("select.graph_ids");for(a in u){var f=UI.plot.addGraph(u[a],c);d.append($("<option>").text(f.id)).val(f.id);var e=[],g;for(g in u[a].datasets){var h=UI.plot.datatype.getOptions({datatype:u[a].datasets[g].datatype,origin:u[a].datasets[g].origin});e.push(h)}f.datasets=e;u[f.id]=f}d.trigger("change");UI.plot.go(u);UI.interval.set(function(){UI.plot.go(u)},1E4)},
{active_streams:!0,capabilities:!0});break;case "Server Stats":if("undefined"==typeof mist.data.capabilities){mist.send(function(){UI.navto(a)},{capabilities:!0});b.append("Loading..");break}var R=$("<table>"),S=$("<table>"),h={vheader:"CPUs",labels:["Model","Processor speed","Amount of cores","Amount of threads"],content:[]};for(q in mist.data.capabilities.cpu)r=mist.data.capabilities.cpu[q],h.content.push({header:"CPU #"+(Number(q)+1),body:[r.model,UI.format.addUnit(UI.format.number(r.mhz),"MHz"),
r.cores,r.threads]});var h=UI.buildVheaderTable(h),aa=function(){var a=mist.data.capabilities.mem,b=mist.data.capabilities.load,a={vheader:"Memory",labels:["Used","Cached","Available","Total"],content:[{header:"Physical memory",body:[UI.format.bytes(a.used*1048576)+" ("+UI.format.addUnit(b.memory,"%")+")",UI.format.bytes(a.cached*1048576),UI.format.bytes(a.free*1048576),UI.format.bytes(a.total*1048576)]},{header:"Swap memory",body:[UI.format.bytes((a.swaptotal-a.swapfree)*1048576),UI.format.addUnit("",
"N/A"),UI.format.bytes(a.swapfree*1048576),UI.format.bytes(a.swaptotal*1048576)]}]},a=UI.buildVheaderTable(a);R.replaceWith(a);R=a;b={vheader:"Load average",labels:["CPU use","1 minute","5 minutes","15 minutes"],content:[{header:"&nbsp;",body:[UI.format.addUnit(UI.format.number(mist.data.capabilities.cpu_use/10),"%"),UI.format.number(b.one/100),UI.format.number(b.five/100),UI.format.number(b.fifteen/100)]}]};b=UI.buildVheaderTable(b);S.replaceWith(b);S=b};aa();b.append(UI.buildUI([{type:"help",help:"You can find general server statistics here. Note that memory and CPU usage is for your entire machine, not just MistServer."}])).append($("<table>").css("width",
"auto").addClass("nolay").append($("<tr>").append($("<td>").append(R)).append($("<td>").append(S))).append($("<tr>").append($("<td>").append(h).attr("colspan",2))));UI.interval.set(function(){mist.send(function(){aa()},{capabilities:true})},3E4);break;case "Email for Help":h=$.extend({},mist.data);delete h.statistics;delete h.totals;delete h.clients;delete h.capabilities;h=JSON.stringify(h);h="Version: "+mist.data.config.version+"\n\nConfig:\n"+h;o={};b.append(UI.buildUI([{type:"help",help:"You can use this form to email MistServer support if you're having difficulties.<br>A copy of your server config file will automatically be included."},
{type:"str",label:"Your name",validate:["required"],pointer:{main:o,index:"name"},value:mist.user.name},{type:"email",label:"Your email address",validate:["required"],pointer:{main:o,index:"email"}},{type:"hidden",value:"Integrated Help",pointer:{main:o,index:"subject"}},{type:"hidden",value:"-",pointer:{main:o,index:"company"}},{type:"textarea",rows:20,label:"Your message",validate:["required"],pointer:{main:o,index:"message"}},{type:"textarea",rows:20,label:"Your config file",readonly:!0,value:h,
pointer:{main:o,index:"configfile"}},{type:"buttons",buttons:[{type:"save",label:"Send","function":function(a){$(a).text("Sending..");$.ajax({type:"POST",url:"http://mistserver.org/contact?skin=plain",data:o,success:function(a){a=$("<span>").html(a);a.find("script").remove();b.html(a[0].innerHTML)}})}}]}]));break;case "Disconnect":mist.user.password="";delete mist.user.authstring;delete mist.user.loggedin;UI.navto("Login");break;default:b.append($("<p>").text("This tab does not exist."))}}}};
"origin"in location||(location.origin=location.protocol+"//"+location.hostname+(location.port?":"+location.port:""));
var mist={data:{},user:{name:"",password:"",host:location.origin+location.pathname.replace(/\/+$/,"")+"/api"},send:function(a,c,b){var c=c||{},b=b||{},b=$.extend(true,{timeout:30,sendData:c},b),d={authorize:{password:mist.user.authstring?MD5(MD5(mist.user.password)+mist.user.authstring):"",username:mist.user.name}};$.extend(true,d,c);log("Send",$.extend(true,{},c));d={url:mist.user.host,type:"POST",data:{command:JSON.stringify(d)},dataType:"jsonp",crossDomain:true,timeout:b.timeout*1E3,async:true,
error:function(d,e){delete mist.user.loggedin;if(!b.hide){switch(e){case "timeout":e=$("<i>").text("The connection timed out. ");break;case "abort":e=$("<i>").text("The connection was aborted. ");break;default:e=$("<i>").text(e+". ").css("text-transform","capitalize")}$("#message").addClass("red").text("An error occurred while attempting to communicate with MistServer:").append($("<br>")).append(e).append($("<a>").text("Send server request again").click(function(){mist.send(a,c,b)}))}UI.navto("Login")},
success:function(d){log("Receive",$.extend(true,{},d),"as reply to",b.sendData);delete mist.user.loggedin;switch(d.authorize.status){case "OK":if("streams"in d)if(d.streams)if("incomplete list"in d.streams){delete d.streams["incomplete list"];$.extend(mist.data.streams,d.streams)}else mist.data.streams=d.streams;else mist.data.streams={};var e=$.extend({},d),g=["config","capabilities","ui_settings","LTS","active_streams","browse","log","totals"],p;for(p in e)g.indexOf(p)==-1&&delete e[p];$.extend(true,
mist.data,e);mist.user.loggedin=true;UI.elements.connection.status.text("Connected").removeClass("red").addClass("green");UI.elements.connection.user_and_host.text(mist.user.name+" @ "+mist.user.host);UI.elements.connection.msg.removeClass("red").text("Last communication with the server at "+UI.format.time((new Date).getTime()/1E3));d.LTS&&UI.elements.menu.find(".LTSonly").removeClass("LTSonly");if(d.log){e=d.log[d.log.length-1];UI.elements.connection.msg.append($("<br>")).append("Last log entry: "+
UI.format.time(e[0])+" ["+e[1]+"] "+e[2])}if("totals"in d){e=function(a,b,c){var d;d=function(){for(var a in c.fields)e[c.fields[a]].push([j,0])};var e={},g;for(g in c.fields)e[c.fields[g]]=[];var k=0,j;if(c.data){if(c.start>mist.data.config.time-600){j=(mist.data.config.time-600)*1E3;d();j=c.start*1E3;d()}else j=c.start*1E3;for(g in c.data){if(g==0){j=c.start*1E3;var n=0}else{j=j+c.interval[n][1]*1E3;c.interval[n][0]--;if(c.interval[n][0]<=0){n++;n<c.interval.length-1&&(k=k+2)}}if(k%2==1){d();k--}for(var p in c.data[g])e[c.fields[p]].push([j,
c.data[g][p]]);if(k){d();k--}}if(mist.data.config.time-c.end>20){d();j=(mist.data.config.time-15)*1E3;d()}}else{j=(mist.data.config.time-600)*1E3;d();j=(mist.data.config.time-15)*1E3;d()}d=e;stream=a?a.join(" "):"all_streams";protocol=b?b.join("_"):"all_protocols";stream in mist.data.totals||(mist.data.totals[stream]={});protocol in mist.data.totals[stream]||(mist.data.totals[stream][protocol]={});$.extend(mist.data.totals[stream][protocol],d)};mist.data.totals={};if("fields"in d.totals)e(c.totals.streams,
c.totals.protocols,d.totals);else for(p in d.totals)e(c.totals[p].streams,c.totals[p].protocols,d.totals[p])}a&&a(d,b);break;case "CHALL":if(d.authorize.challenge==mist.user.authstring){mist.user.password!=""&&UI.elements.connection.msg.text("The credentials you provided are incorrect.").addClass("red");UI.navto("Login")}else if(mist.user.password=="")UI.navto("Login");else{mist.user.authstring=d.authorize.challenge;mist.send(a,c,b)}break;case "NOACC":UI.navto("Create a new account");break;case "ACC_MADE":delete c.authorize;
mist.send(a,c,b);break;default:UI.navto("Login")}}};b.hide||UI.elements.connection.msg.removeClass("red").text("Data sent, waiting for a reply..").append($("<br>")).append($("<a>").text("Cancel request").click(function(){e.abort()}));var e=$.ajax(d)},inputMatch:function(a,c){if(typeof a=="undefined")return false;if(typeof a=="string"){var b=a.replace(/[^\w\s]/g,"\\$&"),b=b.replace(/\\\?/g,".").replace(/\\\*/g,"(?:.)*"),b=RegExp("^"+b+"$","i");return b.test(c)}for(var d in a){b=a[d].replace(/[^\w\s]/g,
"\\$&");b=b.replace(/\\\?/g,".").replace(/\\\*/g,"(?:.)*");b=RegExp("^"+b+"$","i");if(b.test(c))return true}return false},convertBuildOptions:function(a,c){var b=[],d=["required","optional"];"desc"in a&&b.push({type:"help",help:a.desc});for(var e in d)if(a[d[e]]){b.push($("<h4>").text(UI.format.capital(d[e])+" parameters"));for(var j in a[d[e]]){var n=a[d[e]][j],g={label:UI.format.capital(n.name),pointer:{main:c,index:j},validate:[]};d[e]=="required"&&!("default"in n)&&g.validate.push("required");
if("default"in n)g.placeholder=n["default"];if("help"in n)g.help=n.help;if("unit"in n)g.unit=n.unit;switch(n.type){case "int":g.type="int";break;case "uint":g.type="int";g.min=0;break;case "debug":g.type="debug";break;case "select":g.type="select";g.select=n.select;break;default:g.type="str"}b.push(g)}}return b},stored:{get:function(){return mist.data.ui_settings||{}},set:function(a,c){var b=this.get();b[a]=c;mist.send(function(){},{ui_settings:b})},del:function(a){delete mist.data.ui_settings[a];
mist.send(function(){},{ui_settings:mist.data.ui_settings})}}};function log(){try{UI.debug&&[].push.call(arguments,Error().stack);[].unshift.call(arguments,"["+UI.format.time((new Date).getTime()/1E3)+"]");console.log.apply(console,arguments)}catch(a){}}
$.fn.getval=function(){var a=$(this).data("opts"),c=$(this).val();if(a&&"type"in a)switch(a.type){case "span":c=$(this).html();break;case "checkbox":c=$(this).prop("checked");break;case "radioselect":a=$(this).find("label > input[type=radio]:checked").parent();if(a.length){c=[];c.push(a.children("input[type=radio]").val());a=a.children("select");a.length&&c.push(a.val())}else c="";break;case "checklist":c=[];$(this).find(".checklist input[type=checkbox]:checked").each(function(){c.push($(this).attr("name"))})}return c};
$.fn.setval=function(a){var c=$(this).data("opts");$(this).val(a);if(c&&"type"in c)switch(c.type){case "span":$(this).html(a);break;case "checkbox":$(this).prop("checked",a);break;case "geolimited":case "hostlimited":c=$(this).closest(".field_container").data("subUI");if(typeof a=="undefined"||a.length==0)a="-";c.blackwhite.val(a.charAt(0));var a=a.substr(1).split(" "),b;for(b in a)c.values.append(c.prototype.clone(true).val(a[b]));c.blackwhite.trigger("change");break;case "radioselect":if(typeof a==
"undefined")return $(this);b=$(this).find('label > input[type=radio][value="'+a[0]+'"]').prop("checked",true).parent();a.length>1&&b.children("select").val(a[1]);break;case "checklist":c=$(this).find(".checklist input[type=checkbox]").prop("checked",false);for(b in a)c.filter('[name="'+a[b]+'"]').prop("checked",true)}$(this).trigger("change");return $(this)};