var g_np_init=false,namedpipeobserverfunction=null;
function lpnp_init(){if(!g_is_win&&!g_is_mac&&!g_is_linux)g_np_init=false;else if(g_issafari&&g_is_win)g_np_init=false;else if(g_nplastpass)if(is_chrome_portable())g_np_init=false;else{lpdbg("namedpipes","lpnp_init : initializing named pipe server");namedpipeobserverfunction={observe:function(b,f,a){try{if(f=="lpxpcom"){b="";var e=a.match(/^<([^ \/]+)/);if(e)b=e[1];if(!(LPISLOC&&b!="refresh_local"&&b!="local_pwchange")){lpdbg("namedpipes","received cmd="+b+" data="+a);switch(b){case "pipeinitdone":if(g_nplastpass.NamedPipeNumClients()>
1){var d=[];lpnp_notify("internal_logincheck",d);setTimeout(function(){lp_StartLogin()},500)}else lp_StartLogin();break;case "logout":console_log("LOGGING OFF : namedpipes : logoff");lplogoff(true);break;case "login":var p=a.match(/data0=\"([^\"]*)\"/),g=a.match(/data1=\"([^\"]*)\"/);if(p&&g){var c=lpxmlunescape(p[1]),q=lpxmlunescape(g[1]);c!=""&&q!=""&&lp_loginhelper(c,q,"namedpipes")}break;case "refresh":refresh_windows();break;case "switchidentity":if(g=a.match(/data0=\"([^\"]*)\"/)){var s=lpxmlunescape(g[1]);
switch_identity(s,true,false,true)}break;case "launch":g=a.match(/id=\"([^\"]*)\"/);var t=a.match(/existing=\"([^\"]*)\"/);if(g){var l=lpxmlunescape(g[1]);d=[];d.data0=l;lpnp_notify("launchok",d);t?fillaid(l):launch(l)}break;case "internal_logincheck":if(lploggedin){d=[];d.data0=lp_phpsessid;d.data1=g_username;d.data2=g_identity;lpnp_notify("internal_logincheck_ack",d)}break;case "internal_logincheck_ack":var i=a.match(/data0=\"([^\"]*)\"/);c=a.match(/data1=\"([^\"]*)\"/);var j=a.match(/data2=\"([^\"]*)\"/);
if(!lploggedin&&i&&c){var h=opendb();createSavedLoginsTable(h);h&&h.transaction(function(m){var n=(new Date).getTime();m.executeSql("UPDATE LastPassSavedLogins2 SET last_login = ? WHERE username = ?",[n,lpxmlunescape(c[1])],function(k,o){o.rowsAffected==0&&k.executeSql("INSERT INTO LastPassSavedLogins2 (username, password, last_login) VALUES (?, '', ?)",[lpxmlunescape(c[1]),n])},function(k,o){console_log(o)})});e=g_username_hash;d=g_username;g_username=lpxmlunescape(c[1]);g_username_hash=SHA256(lpxmlunescape(c[1]));
g_identity=""+(j?lpxmlunescape(j[1]):"");lpPutUserPref("identity",j?lpxmlunescape(j[1]):"");g_username=d;g_username_hash=e;lpWriteAllPrefs();lp_phpsessid=lpxmlunescape(i[1]);rsa_setpendingsharests();if(have_nplastpass()&&typeof g_nplastpass.read_file=="function"){a=g_nplastpass.read_file(db_prepend(SHA256(lpxmlunescape(c[1]))+"_lpall.slps"));if(typeof a!="string"||a==""){a=g_nplastpass.read_file(db_prepend(SHA256(lpxmlunescape(c[1]))+"_lpall.lps"));if(typeof a=="string"&&a!=""){var u=protect_data(a,
true);g_nplastpass.write_file(db_prepend(SHA256(lpxmlunescape(c[1]))+"_lpall.slps"),u);g_nplastpass.delete_file(db_prepend(SHA256(lpxmlunescape(c[1]))+"_lpall.lps"))}}else a=unprotect_data(a,true);if(typeof a=="string"&&a!=""){h=opendb();createDataTable(h);h&&h.transaction(function(m){m.executeSql("REPLACE INTO LastPassData (username_hash, type, data) VALUES (?, 'key', ?)",[db_prepend(SHA256(lpxmlunescape(c[1]))),a],function(){lp_StartLogin(true)},function(n,k){console_log(k)})})}}}else if(lploggedin&&
i&&c)if(lp_phpsessid!=null&&lp_phpsessid!=""&&lp_phpsessid!=lpxmlunescape(i[1])||g_username!=lpxmlunescape(c[1])){console_log("LOGGING OFF : namedpipes : different username");lplogoff()}break;case "refresh_local":var r=a.match(/data0=\"([^\"]*)\"/);if(r&&lpxmlunescape(r[1])==g_username_hash){console_log("named_pipes: refresh_local reparsing");get_accts_local()}break;case "local_pwchange":console_log("LOGGING OFF : namedpipes : local_pwchange");lplogoff();break;default:lpdbg("namedpipes","received unknown message. data="+
a)}}}}catch(v){}}}.observe;g_nplastpass.StartNamedPipeServer();g_np_init=true;setTimeout(function(){lpnp_notify("logincheck")},1E3);g_issafari&&g_is_mac&&lpnp_get_javascript_message()}else lpdbg("namedpipes","named pipe server could not be started g_nplastpass="+g_nplastpass)}
function lpnp_get_javascript_message(){if(have_nplastpass()&&typeof g_nplastpass.get_javascript_message=="function"){var b=g_nplastpass.get_javascript_message();b.length>0&&namedpipeobserverfunction(null,"lpxpcom",b);setTimeout("lpnp_get_javascript_message();",b.length==0?2E3:0)}}
function lpnp_notify(b,f){if(!(LPISLOC&&b!="refresh_local"&&b!="local_pwchange"))if(!(!g_nplastpass||!g_np_init||!have_nplastpass()||typeof g_nplastpass.SendNamedPipeMessageToAll!="function")){var a=lpnp_xml_msg(b,f);lpdbg("namedpipes","broadcasting "+a);g_nplastpass.SendNamedPipeMessageToAll(a)}}function lpnp_xml_msg(b,f){var a="<"+b,e;if(typeof f!="undefined")for(e in f)a+=" "+e+'="'+lpxmlescape(f[e])+'"';a+="/>";return a};
