"use strict";exports.id=2506,exports.ids=[2506],exports.modules={12506:(a,b,c)=>{c.d(b,{A1:()=>L,Kp:()=>H,LC:()=>U,OZ:()=>R,PZ:()=>W,S3:()=>V,Z2:()=>v,a$:()=>G,c$:()=>T,hp:()=>I,xh:()=>E});var d=c(29021),e=c.n(d),f=c(33873),g=c.n(f),h=c(21820),i=c.n(h),j=c(55511),k=c.n(j),l=c(79646),m=c(28354),n=c(66936);c(85567);var o=c(49120);let p=(0,m.promisify)(l.exec),q=g().join(o.DATA_DIR,"bin"),r="darwin"===i().platform();i().platform();let s="win32"===i().platform(),t=g().join(q,s?"tailscale.exe":"tailscale"),u=g().join(o.DATA_DIR,"tailscale"),v=g().join(u,"tailscaled.sock"),w=s?[]:["--socket",v],x="C:\\Program Files\\Tailscale\\tailscale.exe",y=["/usr/local/bin/tailscale","/opt/homebrew/bin/tailscale","/usr/bin/tailscale"],z={value:void 0,fetchedAt:0,refreshing:!1},A={value:!1,fetchedAt:0,refreshing:!1},B={value:null,port:null,fetchedAt:0,refreshing:!1};function C(){return e().existsSync(t)?t:s&&e().existsSync(x)?x:!s&&y.find(a=>e().existsSync(a))||null}function D(){return Date.now()-z.fetchedAt>1e4&&(z.refreshing||(z.refreshing=!0,p("which tailscale 2>/dev/null || where tailscale 2>nul",{windowsHide:!0,timeout:1500}).then(({stdout:a})=>{z.value=a.trim()||C()}).catch(()=>{z.value=C()}).finally(()=>{z.fetchedAt=Date.now(),z.refreshing=!1}))),void 0===z.value&&(e().existsSync(t)?z.value=t:s&&e().existsSync(x)?z.value=x:s?z.value=null:z.value=y.find(a=>e().existsSync(a))||null),z.value}function E(){return null!==D()}function F(...a){return[...w,...a]}function G(){let a=D();if(!a)return!1;try{let b=(0,l.execSync)(`"${a}" ${w.join(" ")} status --json`,{encoding:"utf8",windowsHide:!0,env:{...process.env,PATH:M},timeout:5e3}),c=JSON.parse(b);return"Running"===c.BackendState&&c.Self?.Online===!0}catch(a){return!1}}function H(){return Date.now()-A.fetchedAt>1e4&&function(){if(A.refreshing)return;let a=D();if(!a){A.value=!1,A.fetchedAt=Date.now();return}A.refreshing=!0,p(`"${a}" ${w.join(" ")} funnel status --json`,{windowsHide:!0,timeout:1500}).then(({stdout:a})=>{try{let b=JSON.parse(a);A.value=Object.keys(b.AllowFunnel||{}).length>0}catch{A.value=!1}}).catch(()=>{A.value=!1}).finally(()=>{A.fetchedAt=Date.now(),A.refreshing=!1})}(),A.value}function I(){let a=D();if(!a)return!1;try{let b=(0,l.execSync)(`"${a}" ${w.join(" ")} funnel status --json 2>/dev/null`,{encoding:"utf8",windowsHide:!0,timeout:1500}),c=JSON.parse(b),d=Object.keys(c.AllowFunnel||{}).length>0;return A.value=d,A.fetchedAt=Date.now(),d}catch{return!1}}function J(){let a=D();if(!a)return null;try{let b=(0,l.execSync)(`"${a}" ${w.join(" ")} status --json`,{encoding:"utf8",windowsHide:!0,env:{...process.env,PATH:M},timeout:5e3}),c=JSON.parse(b),d=c.Self?.DNSName?.replace(/\.$/,"");return d?`https://${d}`:null}catch{return null}}function K(a){return(Date.now()-B.fetchedAt>1e4||B.port!==a)&&function(a){if(B.refreshing)return;let b=D();b&&(B.refreshing=!0,p(`"${b}" ${w.join(" ")} status --json`,{windowsHide:!0,timeout:1500}).then(({stdout:a})=>{try{let b=JSON.parse(a),c=b.Self?.DNSName?.replace(/\.$/,"");B.value=c?`https://${c}`:null}catch{}}).catch(()=>{}).finally(()=>{B.port=a,B.fetchedAt=Date.now(),B.refreshing=!1}))}(a),B.value}async function L(a,b,c){let d=c||(()=>{});return s?(await P(d),{success:!0}):(r?await N(a,d):await O(a,d),d("Starting daemon..."),await R(a),d("Logging in..."),T(b))}let M=`/usr/local/bin:/opt/homebrew/bin:/usr/bin:/bin:${process.env.PATH||""}`;async function N(a,b){if(function(){try{return(0,l.execSync)("which brew",{stdio:"ignore",windowsHide:!0,env:{...process.env,PATH:M}}),!0}catch{return!1}}()){b("Installing via Homebrew..."),await new Promise((a,c)=>{let d=(0,l.spawn)("brew",["install","tailscale"],{stdio:["ignore","pipe","pipe"],windowsHide:!0,env:{...process.env,PATH:M}});d.stdout.on("data",a=>{let c=a.toString().trim();c&&b(c)}),d.stderr.on("data",a=>{let c=a.toString().trim();c&&b(c)}),d.on("close",b=>{0===b?a():c(Error(`brew install failed (code ${b})`))}),d.on("error",c)});return}let c=g().join(i().tmpdir(),"tailscale.pkg");b("Downloading Tailscale package..."),await new Promise((a,d)=>{let e=(0,l.spawn)("curl",["-fL","--progress-bar","https://pkgs.tailscale.com/stable/tailscale-latest.pkg","-o",c],{stdio:["ignore","pipe","pipe"],windowsHide:!0});e.stderr.on("data",a=>{let c=a.toString().trim();c&&b(c)}),e.on("close",b=>{0===b?a():d(Error("Download failed"))}),e.on("error",d)}),b("Installing package..."),await new Promise((d,e)=>{let f=(0,l.spawn)("sudo",["-S","installer","-pkg",c,"-target","/"],{stdio:["pipe","pipe","pipe"],windowsHide:!0}),g="";f.stderr.on("data",a=>{g+=a.toString()}),f.stdout.on("data",a=>{let c=a.toString().trim();c&&b(c)}),f.on("close",a=>{try{(0,l.execSync)(`rm -f ${c}`,{stdio:"ignore",windowsHide:!0})}catch{}0===a?d():e(Error(g.includes("incorrect password")||g.includes("Sorry")?"Wrong sudo password":g||`Exit code ${a}`))}),f.on("error",e),f.stdin.write(`${a}
`),f.stdin.end()})}async function O(a,b){if("string"!=typeof a||a.includes("\n"))throw Error("Invalid sudo password");return b("Downloading install script..."),new Promise((c,d)=>{let f=(0,l.spawn)("curl",["-fsSL","https://tailscale.com/install.sh"],{stdio:["ignore","pipe","pipe"],windowsHide:!0}),h="",j="";f.stdout.on("data",a=>{h+=a.toString()}),f.stderr.on("data",a=>{j+=a.toString()}),f.on("exit",f=>{if(0!==f)return d(Error(`Failed to download install script: ${j}`));b("Running install script...");let m=g().join(i().tmpdir(),`tailscale-install-${k().randomBytes(8).toString("hex")}.sh`);try{e().writeFileSync(m,h,{mode:448})}catch(a){return d(Error(`Failed to write install script: ${a.message}`))}let n=()=>{try{e().unlinkSync(m)}catch{}},o=(0,l.spawn)("sudo",["-S","sh",m],{stdio:["pipe","pipe","pipe"],windowsHide:!0}),p="";o.stdout.on("data",a=>{let c=a.toString().trim();c&&b(c)}),o.stderr.on("data",a=>{p+=a.toString()}),o.on("close",a=>{n(),0===a?c():d(Error(p.includes("incorrect password")||p.includes("Sorry")?"Wrong sudo password":p||`Exit code ${a}`))}),o.on("error",a=>{n(),d(a)}),o.stdin.write(`${a}
`),o.stdin.end()}),f.on("error",d)})}async function P(a){let b=g().join(i().tmpdir(),"tailscale-setup.msi");a("Downloading Tailscale installer..."),await new Promise((c,d)=>{let e=(0,l.spawn)("curl.exe",["-L","-#","-o",b,"https://pkgs.tailscale.com/stable/tailscale-setup-latest-amd64.msi"],{stdio:["ignore","pipe","pipe"],windowsHide:!0}),f="";e.stderr.on("data",b=>{let c=b.toString().match(/(\d+\.\d)%/);c&&c[1]!==f&&(f=c[1],a(`Downloading... ${f}%`))}),e.on("close",a=>0===a?c():d(Error("Download failed"))),e.on("error",d)}),a("Installing Tailscale (UAC prompt may appear)..."),await new Promise((c,d)=>{let f=`'/i','${b}','TS_NOLAUNCH=true','/quiet','/norestart'`,g=(0,l.spawn)("powershell",["-NoProfile","-NonInteractive","-Command",`Start-Process msiexec -ArgumentList ${f} -Verb RunAs -Wait`],{stdio:["ignore","pipe","pipe"],windowsHide:!0});g.stderr.on("data",b=>{let c=b.toString().trim();c&&a(c)}),g.on("close",a=>{try{e().unlinkSync(b)}catch{}0===a?c():d(Error(`msiexec failed (code ${a})`))}),g.on("error",d)}),a("Verifying installation...");let c=Date.now();for(;Date.now()-c<1e4;){if(e().existsSync(x))return void a("Installation complete.");await new Promise(a=>setTimeout(a,1e3))}throw Error("Installation finished but tailscale.exe not found")}async function Q(a){try{if(!e().existsSync(a))return void e().mkdirSync(a,{recursive:!0});let b=process.getuid(),c=process.getgid();if(!(()=>{let c=[a];for(;c.length;){let a=c.pop();try{let d=e().statSync(a);if(d.uid!==b)return!0;if(d.isDirectory())for(let b of e().readdirSync(a))c.push(g().join(a,b))}catch{}}return!1})())return;try{(0,l.execSync)(`chown -R ${b}:${c} "${a}"`,{stdio:"ignore",timeout:3e3})}catch{try{(0,l.execSync)(`sudo -n chown -R ${b}:${c} "${a}"`,{stdio:"ignore",timeout:3e3})}catch{}}}catch{}}async function R(a){if(s){let a=D();console.log("[Tailscale] win: net start Tailscale");try{(0,l.execSync)("net start Tailscale",{stdio:"ignore",windowsHide:!0,timeout:1e4})}catch{}if(!a)return;for(let b=0;b<20;b++){try{let c=(0,l.execSync)(`"${a}" status --json`,{encoding:"utf8",windowsHide:!0,timeout:2e3}),d=JSON.parse(c);if(d.BackendState&&"NoState"!==d.BackendState)return void console.log(`[Tailscale] win: BackendState=${d.BackendState} after ${500*b}ms`)}catch{}await new Promise(a=>setTimeout(a,500))}console.log("[Tailscale] win: BackendState still NoState after poll");return}let b=!!a,c=function(){try{let a=(0,l.execSync)(`pgrep -af "tailscaled.*${v}"`,{encoding:"utf8",timeout:2e3}).trim();if(!a)return null;return!a.includes("--tun=userspace-networking")}catch{return null}}();if(null!==c&&c===b)try{let a=D()||"tailscale";(0,l.execSync)(`"${a}" ${w.join(" ")} status --json`,{stdio:"ignore",windowsHide:!0,env:{...process.env,PATH:M},timeout:3e3});return}catch{}try{(0,l.execSync)(`pkill -9 -f "tailscaled.*${v}"`,{stdio:"ignore",timeout:3e3})}catch{}if(a)try{await (0,n.execWithPassword)(`pkill -9 -f "tailscaled.*${v}"`,a)}catch{}else try{(0,l.execSync)(`sudo -n pkill -9 -f "tailscaled.*${v}"`,{stdio:"ignore",timeout:3e3})}catch{}await new Promise(a=>setTimeout(a,1500)),await Q(u);let d=r?"/usr/local/bin/tailscaled":"tailscaled",e=[`--socket=${v}`,`--statedir=${u}`];if(b||e.push("--tun=userspace-networking"),b){let b=(0,l.spawn)("sudo",["-S",d,...e],{detached:!0,stdio:["pipe","ignore","ignore"],cwd:i().tmpdir(),env:{...process.env,PATH:M}});b.stdin.write(`${a}
`),b.stdin.end(),b.unref()}else(0,l.spawn)(d,e,{detached:!0,stdio:"ignore",cwd:i().tmpdir(),env:{...process.env,PATH:M}}).unref();await new Promise(a=>setTimeout(a,3e3))}function S(){let a=D();if(!a)return null;try{let b=(0,l.execSync)(`"${a}" ${w.join(" ")} status --json`,{encoding:"utf8",windowsHide:!0,timeout:2e3}),c=JSON.parse(b);if(c.AuthURL)return c.AuthURL;return null}catch{return null}}function T(a){let b=D();return b?new Promise((c,d)=>{if(R("").catch(()=>{}),G())return void c({alreadyLoggedIn:!0});let e=F("up","--accept-routes");a&&e.push(`--hostname=${a}`);let f=(0,l.spawn)(b,e,{stdio:["ignore","pipe","pipe"],detached:!0,windowsHide:!0}),g=!1,h="",i=a=>{let b=a.match(/https:\/\/login\.tailscale\.com\/a\/[a-zA-Z0-9]+/);return b?b[0]:null},j=(a,b)=>{g||(g=!0,clearTimeout(m),clearInterval(k),console.log(`[Tailscale] login authUrl detected (${b})`),f.unref(),c({authUrl:a}))},k=setInterval(()=>{if(g)return;let a=S();a&&j(a,"status")},500),m=setTimeout(()=>{if(g)return;g=!0,clearInterval(k),f.unref();let a=i(h)||S();a?c({authUrl:a}):d(Error("tailscale up timed out without auth URL"))},15e3),n=a=>{let b=i(h+=a.toString());b&&j(b,"stdout")};f.stdout.on("data",n),f.stderr.on("data",n),f.on("error",a=>{g||(g=!0,clearTimeout(m),clearInterval(k),console.error(`[Tailscale] login spawn error: ${a.message}`),d(a))}),f.on("exit",a=>{if(g)return;console.log(`[Tailscale] login exit code=${a}`);let b=i(h)||S();if(b)return void j(b,"exit");if(G()){g=!0,clearTimeout(m),clearInterval(k),c({alreadyLoggedIn:!0});return}})}):Promise.reject(Error("Tailscale not installed"))}async function U(a){let b=D();if(!b)throw Error("Tailscale not installed");try{(0,l.execSync)(`"${b}" ${w.join(" ")} funnel --bg reset`,{stdio:"ignore",windowsHide:!0})}catch(a){}return new Promise((c,d)=>{let e=(0,l.spawn)(b,F("funnel","--bg",`${a}`),{stdio:["ignore","pipe","pipe"],windowsHide:!0}),f=!1,g="",h=setTimeout(()=>{if(f)return;f=!0;let b=J()||K(a);b?c({tunnelUrl:b}):d(Error(`Tailscale funnel timed out: ${g.trim()||"no output"}`))},3e4),i=!1,j=a=>{if((g+=a.toString()).includes("Funnel is not enabled")&&(i=!0),i&&!f){let a=g.match(/https:\/\/login\.tailscale\.com\/[^\s]+/);if(a){f=!0,clearTimeout(h),e.kill(),c({funnelNotEnabled:!0,enableUrl:a[0]});return}}let b=J();b&&!f&&(f=!0,clearTimeout(h),c({tunnelUrl:b}))};e.stdout.on("data",j),e.stderr.on("data",j),e.on("exit",b=>{if(f)return;f=!0,clearTimeout(h),console.log(`[Tailscale] funnel exit code=${b} output="${g.trim().slice(0,200)}"`);let e=J()||K(a);e?c({tunnelUrl:e}):d(Error(`tailscale funnel failed (code ${b}): ${g.trim()}`))}),e.on("error",a=>{f||(f=!0,clearTimeout(h),d(a))})})}async function V(a){let b=D();if(!b||!a)return;let c=g().join(u,"certs");e().mkdirSync(c,{recursive:!0});let d=g().join(c,`${a}.crt`),f=g().join(c,`${a}.key`);try{await p(`"${b}" ${w.join(" ")} cert --cert-file "${d}" --key-file "${f}" "${a}"`,{windowsHide:!0,env:{...process.env,PATH:M},timeout:3e4}),console.log(`[Tailscale] cert provisioned for ${a}`)}catch(a){console.warn(`[Tailscale] cert provision failed (non-fatal): ${a.message}`)}}function W(){let a=D();if(a)try{(0,l.execSync)(`"${a}" ${w.join(" ")} funnel --bg reset`,{stdio:"ignore",windowsHide:!0})}catch(a){}}},85567:(a,b,c)=>{c.d(b,{C7:()=>m,Cr:()=>p,LZ:()=>n,jd:()=>s,r4:()=>q,xS:()=>o});var d=c(29021),e=c.n(d),f=c(33873),g=c.n(f),h=c(49120);let i=g().join(h.DATA_DIR,"tunnel"),j=g().join(i,"state.json"),k=g().join(i,"cloudflared.pid");function l(){e().existsSync(i)||e().mkdirSync(i,{recursive:!0})}function m(){try{if(e().existsSync(j))return JSON.parse(e().readFileSync(j,"utf8"))}catch(a){}return null}function n(a){l(),e().writeFileSync(j,JSON.stringify(a,null,2))}function o(a){l(),e().writeFileSync(k,a.toString())}function p(){try{if(e().existsSync(k))return parseInt(e().readFileSync(k,"utf8"))}catch(a){}return null}function q(){try{e().existsSync(k)&&e().unlinkSync(k)}catch(a){}}g().join(i,"tailscale.pid");let r="abcdefghijklmnpqrstuvwxyz23456789";function s(){let a="";for(let b=0;b<6;b++)a+=r.charAt(Math.floor(Math.random()*r.length));return a}}};