/* Some or all contents Copyright (c) 2010 Meraki, Inc., all rights reserved */
var scan_results={},extra_nodes_hash={},flex_table,wifi_stumbler_js;function lookup_oui(B){var A=null;if(typeof meraki_oui_data!="undefined"){A=meraki_oui_data[B.substr(0,8)]}return A}function json_pass(json,f){var result;eval("result = "+json);f(result)}function make_mki_scan_results_filter(){if(typeof mki_scan_results_filter!=="undefined"){return }var C=make_smart_filter(),H=/cisco|apple|meraki|linksys|2wire|netgear|d-link|belkin/i;function I(J,L,K,M){J=l3_clean_mac(J);return J?M.propmatch("bssid",J,L,true):"false"}function G(J,L,K,M){var N=J.toLowerCase();if(N=="others"){L.helpers.push(H);return"!helpers["+(L.helpers.length-1)+"].test(x.mfr || '')"}else{return M.propmatch("mfr",J,L,false,true)}}function D(K,M,L,N){var J=split_text_comparison(K);if(/^\d+(?:\s*dBm?)?$/i.test(J[1])){return"((x.signal_db||0)+95)"+J[0]+parseInt(J[1],10)}else{if(/^\d+\s?%$/.test(J[1])){return"(x.signal_pct||0)"+J[0]+parseInt(J[1],10)}else{return"false"}}}function A(J,L,K,M){if(/^2(\.4)?\s*(?:g(?:hz)?)?$/i.test(J)){return"(x.channel||0)>=1&&(x.channel||0)<=14"}else{if(/^5\s*(?:g(?:hz)?)?$/i.test(J)){return"(x.channel||0)>=36&&(x.channel||0)<=165"}else{return"false"}}}function F(K,M,L,N){var J;if((J=K.match(/^(?:(?:802\.?)?11)?([abgn][abgn\/]*)$/i))){return"/["+J[1].replace(/\//g,"").toLowerCase()+"]/.test(x.radio_type||'802.11g')"}else{return"false"}}function E(J,M,L,N){var K=[];K.push(N.getkw("ssid")(J,M,L,N));K.push(N.getkw("bssid")(J,M,L,N));K.push(N.getkw("manufacturer")(J,M,L,N));K.push(N.getkw("is")(J,M,L,N));if(/^802\.?11[abgn\/]+$/){K.push(N.getkw("radio")(J,M,L,N))}return K.join("||")}function B(J,L,K,M){J=J.toLowerCase();if({open:1,wep:1,wpa:1,wpa2:1}[J]){return"x.is_"+J}else{return"false"}}C.addkw({"":E,is:B,ssid:function(J,K){return C.propmatch("ssid",J,K)},bssid:I,mac:I,manufacturer:G,mfr:G,channel:l3_match_channel,signal:D,band:A,radio:F});C.add_checkbox_partition("is:open","is:wep","is:wpa");C.add_checkbox_partition('mfr:"cisco systems"',"mfr:apple","mfr:meraki","mfr:linksys","mfr:2wire","mfr:netgear","mfr:d-link","mfr:belkin","mfr:others");
C.add_checkbox_partition("band:2.4GHz","band:5GHz");C.add_checkbox_partition("radio:bg","radio:a","radio:n");mki_scan_results_filter=C;return true}function make_scan_results_hash_filter(){make_mki_scan_results_filter();var B,C=false,E;function D(){C={count:0};var H,G=["<table><tr><td class='l3filter'><h3>Network encryption</h3></td><td class='l3filter'><h3>Manufacturer</h3></td><td class='l3filter'><h3>Radio type</h3></td><td class='l3filter'><h3>Frequency band</h3></td><td class='l3filter'><h3>Channel</h3></td></tr>"],F=0,I;G.push("<tr><td class='l3filter'>");G.push(B.checkbox_html("is:open","Open")+"<br />");G.push(B.checkbox_html("is:wep","WEP")+"<br />");G.push(B.checkbox_html("is:wpa","WPA")+"</td>");G.push("<td class='l3filter'><select class='filter_select' multiple='multiple' size='5' style='font-size:100%'>");G.push(B.option_html("mfr:2wire","2Wire"));G.push(B.option_html("mfr:apple","Apple"));G.push(B.option_html("mfr:belkin","Belkin"));G.push(B.option_html('mfr:"cisco systems"',"Cisco Systems"));G.push(B.option_html("mfr:linksys","Cisco-Linksys"));G.push(B.option_html("mfr:d-link","D-Link"));G.push(B.option_html("mfr:meraki","Meraki"));G.push(B.option_html("mfr:netgear","Netgear"));G.push(B.option_html("mfr:others","Other manufacturers"));G.push("</select></td>");G.push("<td class='l3filter'>");G.push(B.checkbox_html("radio:bg","802.11b/g")+"<br />");G.push(B.checkbox_html("radio:a","802.11a")+"<br />");G.push(B.checkbox_html("radio:n","802.11n")+"</td>");G.push("<td class='l3filter'>");G.push(B.checkbox_html("band:2.4GHz","2.4&nbsp;GHz")+"<br />");G.push(B.checkbox_html("band:5GHz","5&nbsp;GHz")+"</td>");G.push("<td class='l3filter'><select class='filter_channel_value' style='font-size:100%'><option selected='selected' value=''>&mdash;</option>");for(H=1;H<=14;++H){G.push("<option value='"+H+"'>"+H+"</option>")}for(H=36;H<=64;H+=4){G.push("<option value='"+H+"'>"+H+"</option>")}for(H=100;H<=140;H+=4){G.push("<option value='"+H+"'>"+H+"</option>")}for(H=149;
H<=165;H+=4){G.push("<option value='"+H+"'>"+H+"</option>")}G.push("</option></td>");G.push("</tr></table>");jQuery("#l3filter").html(G.join(""));B.bind_checkbox_click(jQuery("#l3filter .filter_check"));B.bind_multiple_select_change(jQuery("#l3filter .filter_select"));B.bind_value_change(jQuery("#l3filter .filter_channel_value"),"channel")}function A(G,H){var F,I;if(!C){D()}if(C.count!==H.length){F="<span class='result'>"+pluralize(H.length,"result")+"</span> in "+pluralize(C.count,"access point")}else{F="<span class='result'>"+pluralize(C.count,"access point")+"</span>"}jQuery("#node_count").html(F).show();if((I=jQuery("#node3_count")).length){if(C.count!==H.length){F=pluralize(H.length,"match")}else{F=pluralize(C.count,"access point")}I.html("<b>"+F+"</b>")}}B=make_bound_smart_filter(mki_scan_results_filter,scan_results);B.bind(A);D();E=B.setitems;B.setitems=function(F){var G;C.count=0;for(G in F){++C.count}E(F)};B();return B}wifi_stumbler_js=(function(){var M,B=false,N=false,O=false,F=false,S,E=5,R={},I="";ctor=function(){};var J='{"0:25:3c:52:c1:f9":{"bssid":"0:25:3c:52:c1:f9","encryption":"WEP","ssid":"2WIRE706","bitrates":"1 2 5 11 6 9 12 18 24 36 48 54","signal_db":"-71","channel":"3"},"0:25:9c:58:bb:b5":{"bssid":"0:25:9c:58:bb:b5","ssid":"Ritual Roasters","bitrates":"1 2 5 11 18 24 36 54 6 9 12 48","signal_db":"-50","channel":"11"},"0:26:50:d3:fb:c1":{"bssid":"0:26:50:d3:fb:c1","encryption":"WEP","ssid":"2WIRE602","bitrates":"1 2 5 11 6 9 12 18 24 36 48 54","signal_db":"-66","channel":"3"},"0:22:10:9e:b6:d0":{"bssid":"0:22:10:9e:b6:d0","encryption":"WEP","ssid":"JML Office","bitrates":"1 2 5 11 22 6 9 12 18 24 36 48 54","signal_db":"-75","channel":"6"},"0:18:f8:c3:f0:ec":{"bssid":"0:18:f8:c3:f0:ec","encryption":"WEP","ssid":"Fungus","bitrates":"1 2 5 11 18 24 36 54 6 9 12 48","signal_db":"-76","channel":"6"},"0:22:a4:ee:d7:9":{"bssid":"0:22:a4:ee:d7:9","encryption":"WEP","ssid":"2WIRE330","bitrates":"1 2 5 11 6 9 12 18 24 36 48 54","signal_db":"-63","channel":"4"},"0:1e:c7:b:7f:31":{"bssid":"0:1e:c7:b:7f:31","encryption":"WEP","ssid":"2WIRE434","bitrates":"1 2 5 11 6 9 12 18 24 36 48 54","signal_db":"-77","channel":"6"}}';
function D(){var T,U,V={};for(T in scan_results){U=scan_results[T];V[T]=U}scan_results_hash_filter.setitems(V);flex_table.filter(scan_results_hash_filter.results())}function L(T){return function(Y){var U,X,V,W=false;if(I==T){I=""}meraki_oui_data=window.meraki_oui_data||{};jQuery.extend(meraki_oui_data,Y);T=T.split(" ");for(V=T.length-1;V>=0;--V){if(!Y[T[V]]&&T[V]){R[T[V]]=true}}for(U in scan_results){X=scan_results[U];if(X.bssid&&!X.mfr&&(X.mfr=lookup_oui(X.bssid))){W=true}}if(W){D()}}}function P(){var W,U=[],V,Y,T;for(V in scan_results){W=scan_results[V];if(W.ssid==null||W.ssid==""){W["ssid$"]="~~"}else{W["ssid$"]=human_sortable_string(W.ssid)}W.bssid=normalize_mac_address(W.bssid);if(W.bssid&&!(W.mfr=lookup_oui(W.bssid))){T=W.bssid.substr(0,8);if(!R[T]){U.push(T)}}W.auth_encryption="Open";if(W.wpa2){W.auth_encryption="WPA/WPA2"}else{if(W.wpa1){W.auth_encryption="WPA"}else{if(W.wep){W.auth_encryption="WEP"}else{if(W.authentication&&W.authentication.indexOf("WPA")>=0){W.auth_encryption=W.authentication}else{if(W.authentication=="None"||W.authentication=="Open"){if(W.encryption=="WEP"){W.auth_encryption="WEP"}}}}}}W.is_wep=W.auth_encryption=="WEP";W.is_wpa=W.auth_encryption.match(/wpa/i);W.is_wpa2=W.auth_encryption.match(/wpa\s*-?2/i);W.is_open=W.auth_encryption==="Open";if(!W.ssid){W.ssid=""}if(W.channel){W.channel=parseInt(W.channel)}if(W.signal_db){W.signal_db=parseInt(W.signal_db);if(isNaN(W.signal_db)){W.signal_db=-95}if(W.signal_db>100){W.signal_db=0}}if(W.frequency_khz&&!W.channel){if(W.frequency_khz<=2472000){W.channel=(W.frequency_khz-2412000)/5000+1}else{if(W.frequency_khz<=5320000){W.channel=(W.frequency_khz-5180000)/5000+36}else{if(W.frequency_khz<=5825000){W.channel=(W.frequency_khz-5500000)/5000+100}}}}if(!W.radio_type){if(W["radio type"]){W.radio_type=W["radio type"]}else{if(W.ht_caps){W.radio_type="802.11n"}else{if(W.bitrates){var X=W.bitrates.split(/\s+/);var Z=X[X.length-1];if(Z>11){if(W.channel>14){W.radio_type="802.11a"}else{W.radio_type="802.11g"}}else{W.radio_type="802.11b"
}}}}}if(W.signal_pct){N=true;W.signal_pct=parseFloat(W.signal_pct);if(isNaN(W.signal_pct)){W.signal_pct=null}}if(W.authentication){O=true}}if(U.length&&Mkiconf.oui_json_url){try{U=U.join(" ");if(I!=U){I=U;jQuery.getJSON(Mkiconf.oui_json_url,"q="+U,L(U))}}catch(Y){}}}function K(){var U=jQuery("#graph"),T=U.parent().width();if(T!=U.width()){U.empty().width(T);C()}}function C(){var W={},b,X,c,T,Z,d,a,Y,V,U;for(b in scan_results){T=scan_results[b];W[T.channel]=(W[T.channel]||0)+1}X=[];c=[1,2,3,4,5,6,7,8,9,10,11,36,40,44,48,52,56,60,64,100,104,108,112,116,136,140,149,153,157,161,165];d=0;a=[];for(V in c){Z=c[V];if(Z==36||Z==100||Z==136){d+=3}else{if(Z>=36){d+=1.7}else{d+=1.1}}a.push([d+0.4,Z]);Y=W[Z]||0;X.push([d,Y]);if(Y>=E){E=Y+6-(Y%5)}}U=jQuery("#graph");if(U.length==0||U.css("display")==="none"){return }U.width(U.width());jQuery.plot(U,[{data:X,color:"#7ea1b4"}],{bars:{show:true,barWidth:0.8,fillColor:"#dee7ec"},xaxis:{min:0,max:d+2,ticks:a},yaxis:{min:0,max:E},grid:{tickColor:"#ffffff"}});if(!F){F=true;jQuery(window).resize(K)}}var A;function H(){var U,W;if(M){U=J}else{if(typeof (document.meraki_wifi_stumbler)!="undefined"&&typeof (document.meraki_wifi_stumbler.get_scan_results_json)!="undefined"){U=document.meraki_wifi_stumbler.get_scan_results_json()}else{return }}json_pass(U,function(Y){W=Y});var T=0,V=new Date(),X;if(A){T=V-A}A=V;X=V.getTime()/1000;for(bssid in W){scan_results[bssid]=W[bssid];scan_results[bssid].last_seen_at=X}P();if(B){D();C()}}function G(){if(S){clearTimeout(S)}S=null;jQuery("#loading_message, #loading_error").hide();jQuery("#graph_container, #survey_outer_container").show()}ctor.update_applet_state=function(T){if(T=="scanning"){jQuery("#state_div").text("Scanning...")}else{if(T=="paused"){H();if(!B){Q();G();B=true;H()}jQuery("#state_div").text("");scan_countdown_timer=setTimeout(function(){document.meraki_wifi_stumbler.set_scanner_command("scan_once")},3000)}}};function Q(){var T=["row_num","ssid","bssid","radio_type","channel",N?"signal_pct":"signal_db","manufacturer","auth_encryption"];
T.push("last_seen");flex_table=make_flex_table({items:scan_results,container:"#survey_results_table",columns:{ssid:{l:"SSID",render:"[%= item.ssid == '' ? '<i>hidden</i>' : escape(item.ssid) %]",colwidth:"240px",sortprepare:"ssid$"},bssid:{l:"MAC address (BSSID)",render:"[%= item.bssid %]"},radio_type:{l:"Radio type"},channel:{l:"Channel",sorter:"#"},signal_db:{l:"Signal (dB)",render:'[%= item.signal_db ? "<div class=\'signal_bar\' style=\'width:"+((item.signal_db+95)/2)+"px\'>&nbsp;</div>"+(item.signal_db + 95) : "" %]',sorter:"#"},signal_pct:{l:"Signal (%)",render:'[%= item.signal_pct==null ? "" : item.signal_pct.toFixed(0) %]',sortprepare:function(U){return U.signal_pct},sorter:"#"},manufacturer:{l:"Manufacturer",render:"[%= item.mfr ? escape(item.mfr) : '&mdash;' %]",sortprepare:function(U){return human_sortable_string(U.mfr||"~")}},auth_encryption:{l:"Security",render:"[%= item.auth_encryption ? item.auth_encryption : '' %]"},bitrates:{l:"Supported bitrates",render:'[%= item.bitrates ? item.bitrates : item["basic rates (mbps)"]+" "+(item["other rates (mbps)"]||"") %]'},authentication:{l:"Authentication",render:"[%= item.authentication ? item.authentication : '' %]"},last_seen:{l:"Last seen",render:"[%= item.last_seen_at + 20 >= window.flex_table_now ? '' : unparse_interval(window.flex_table_now - item.last_seen_at) + ' ago' %]",sortprepare:"last_seen_at",sorter:"#",revsort:true},__fallback_sorter__:{sorter:function(V,U){return strcmp(V["ssid$"],U["ssid$"])||numcmp(V.channel||0,U.channel||0)||strcmp(V.mac||"~~",U.mac||"~~")}}},selected_fields:T,default_sort:"ssid",row_class_template:"ft[%= index % 2 %][%= item.last_seen_at + 30 < window.flex_table_now ? ' stale_result' : '' %]",row_id_prefix:true,no_items_html:"No networks found.",no_matches_html:"No matching networks.",items_per_page:300});jQuery(history3)}ctor.init=function(T){M=T;S=setTimeout(function(){jQuery("#loading_error").slideDown()},12000);if(M){H();Q();G();B=true;H()}else{document.meraki_wifi_stumbler.set_scanner_command("scan_once")
}};return ctor})();history3.add_mode("s",{filter:function(){if(!window.scan_results_hash_filter){scan_results_hash_filter=make_scan_results_hash_filter()}return scan_results_hash_filter},enter:function(C,A,B){flex_table.filter(scan_results_hash_filter.results())}});