"use strict";exports.id=2506,exports.ids=[2506],exports.modules={12506:(a,b,c)=>{c.d(b,{A1:()=>J,Kp:()=>F,LC:()=>S,OZ:()=>P,PZ:()=>U,S3:()=>T,Z2:()=>t,a$:()=>E,c$:()=>R,hp:()=>G,xh:()=>C});var d=c(29021),e=c.n(d),f=c(33873),g=c.n(f),h=c(21820),i=c.n(h),j=c(79646),k=c(28354),l=c(66936);c(85567);var m=c(49120);let n=(0,k.promisify)(j.exec),o=g().join(m.n,"bin"),p="darwin"===i().platform();i().platform();let q="win32"===i().platform(),r=g().join(o,q?"tailscale.exe":"tailscale"),s=g().join(m.n,"tailscale"),t=g().join(s,"tailscaled.sock"),u=q?[]:["--socket",t],v="C:\\Program Files\\Tailscale\\tailscale.exe",w=["/usr/local/bin/tailscale","/opt/homebrew/bin/tailscale","/usr/bin/tailscale"],x={value:void 0,fetchedAt:0,refreshing:!1},y={value:!1,fetchedAt:0,refreshing:!1},z={value:null,port:null,fetchedAt:0,refreshing:!1};function A(){return e().existsSync(r)?r:q&&e().existsSync(v)?v:!q&&w.find(a=>e().existsSync(a))||null}function B(){return Date.now()-x.fetchedAt>1e4&&(x.refreshing||(x.refreshing=!0,n("which tailscale 2>/dev/null || where tailscale 2>nul",{windowsHide:!0,timeout:1500}).then(({stdout:a})=>{x.value=a.trim()||A()}).catch(()=>{x.value=A()}).finally(()=>{x.fetchedAt=Date.now(),x.refreshing=!1}))),void 0===x.value&&(e().existsSync(r)?x.value=r:q&&e().existsSync(v)?x.value=v:q?x.value=null:x.value=w.find(a=>e().existsSync(a))||null),x.value}function C(){return null!==B()}function D(...a){return[...u,...a]}function E(){let a=B();if(!a)return!1;try{let b=(0,j.execSync)(`"${a}" ${u.join(" ")} status --json`,{encoding:"utf8",windowsHide:!0,env:{...process.env,PATH:K},timeout:5e3}),c=JSON.parse(b);return"Running"===c.BackendState&&c.Self?.Online===!0}catch(a){return!1}}function F(){return Date.now()-y.fetchedAt>1e4&&function(){if(y.refreshing)return;let a=B();if(!a){y.value=!1,y.fetchedAt=Date.now();return}y.refreshing=!0,n(`"${a}" ${u.join(" ")} funnel status --json`,{windowsHide:!0,timeout:1500}).then(({stdout:a})=>{try{let b=JSON.parse(a);y.value=Object.keys(b.AllowFunnel||{}).length>0}catch{y.value=!1}}).catch(()=>{y.value=!1}).finally(()=>{y.fetchedAt=Date.now(),y.refreshing=!1})}(),y.value}function G(){let a=B();if(!a)return!1;try{let b=(0,j.execSync)(`"${a}" ${u.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 y.value=d,y.fetchedAt=Date.now(),d}catch{return!1}}function H(){let a=B();if(!a)return null;try{let b=(0,j.execSync)(`"${a}" ${u.join(" ")} status --json`,{encoding:"utf8",windowsHide:!0,env:{...process.env,PATH:K},timeout:5e3}),c=JSON.parse(b),d=c.Self?.DNSName?.replace(/\.$/,"");return d?`https://${d}`:null}catch{return null}}function I(a){return(Date.now()-z.fetchedAt>1e4||z.port!==a)&&function(a){if(z.refreshing)return;let b=B();b&&(z.refreshing=!0,n(`"${b}" ${u.join(" ")} status --json`,{windowsHide:!0,timeout:1500}).then(({stdout:a})=>{try{let b=JSON.parse(a),c=b.Self?.DNSName?.replace(/\.$/,"");z.value=c?`https://${c}`:null}catch{}}).catch(()=>{}).finally(()=>{z.port=a,z.fetchedAt=Date.now(),z.refreshing=!1}))}(a),z.value}async function J(a,b,c){let d=c||(()=>{});return q?(await N(d),{success:!0}):(p?await L(a,d):await M(a,d),d("Starting daemon..."),await P(a),d("Logging in..."),R(b))}let K=`/usr/local/bin:/opt/homebrew/bin:/usr/bin:/bin:${process.env.PATH||""}`;async function L(a,b){if(function(){try{return(0,j.execSync)("which brew",{stdio:"ignore",windowsHide:!0,env:{...process.env,PATH:K}}),!0}catch{return!1}}()){b("Installing via Homebrew..."),await new Promise((a,c)=>{let d=(0,j.spawn)("brew",["install","tailscale"],{stdio:["ignore","pipe","pipe"],windowsHide:!0,env:{...process.env,PATH:K}});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,j.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,j.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,j.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 M(a,b){return b("Downloading install script..."),new Promise((c,d)=>{let e=(0,j.spawn)("curl",["-fsSL","https://tailscale.com/install.sh"],{stdio:["ignore","pipe","pipe"],windowsHide:!0}),f="",g="";e.stdout.on("data",a=>{f+=a.toString()}),e.stderr.on("data",a=>{g+=a.toString()}),e.on("exit",e=>{if(0!==e)return d(Error(`Failed to download install script: ${g}`));b("Running install script...");let h=(0,j.spawn)("sudo",["-S","sh"],{stdio:["pipe","pipe","pipe"],windowsHide:!0}),i="";h.stdout.on("data",a=>{let c=a.toString().trim();c&&b(c)}),h.stderr.on("data",a=>{i+=a.toString()}),h.on("close",a=>{0===a?c():d(Error(i.includes("incorrect password")||i.includes("Sorry")?"Wrong sudo password":i||`Exit code ${a}`))}),h.on("error",d),h.stdin.write(`${a}
`),h.stdin.write(f),h.stdin.end()}),e.on("error",d)})}async function N(a){let b=g().join(i().tmpdir(),"tailscale-setup.msi");a("Downloading Tailscale installer..."),await new Promise((c,d)=>{let e=(0,j.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,j.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(v))return void a("Installation complete.");await new Promise(a=>setTimeout(a,1e3))}throw Error("Installation finished but tailscale.exe not found")}async function O(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,j.execSync)(`chown -R ${b}:${c} "${a}"`,{stdio:"ignore",timeout:3e3})}catch{try{(0,j.execSync)(`sudo -n chown -R ${b}:${c} "${a}"`,{stdio:"ignore",timeout:3e3})}catch{}}}catch{}}async function P(a){if(q){let a=B();console.log("[Tailscale] win: net start Tailscale");try{(0,j.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,j.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,j.execSync)(`pgrep -af "tailscaled.*${t}"`,{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=B()||"tailscale";(0,j.execSync)(`"${a}" ${u.join(" ")} status --json`,{stdio:"ignore",windowsHide:!0,env:{...process.env,PATH:K},timeout:3e3});return}catch{}try{(0,j.execSync)(`pkill -9 -f "tailscaled.*${t}"`,{stdio:"ignore",timeout:3e3})}catch{}if(a)try{await (0,l.execWithPassword)(`pkill -9 -f "tailscaled.*${t}"`,a)}catch{}else try{(0,j.execSync)(`sudo -n pkill -9 -f "tailscaled.*${t}"`,{stdio:"ignore",timeout:3e3})}catch{}await new Promise(a=>setTimeout(a,1500)),await O(s);let d=p?"/usr/local/bin/tailscaled":"tailscaled",e=[`--socket=${t}`,`--statedir=${s}`];if(b||e.push("--tun=userspace-networking"),b){let b=(0,j.spawn)("sudo",["-S",d,...e],{detached:!0,stdio:["pipe","ignore","ignore"],cwd:i().tmpdir(),env:{...process.env,PATH:K}});b.stdin.write(`${a}
`),b.stdin.end(),b.unref()}else(0,j.spawn)(d,e,{detached:!0,stdio:"ignore",cwd:i().tmpdir(),env:{...process.env,PATH:K}}).unref();await new Promise(a=>setTimeout(a,3e3))}function Q(){let a=B();if(!a)return null;try{let b=(0,j.execSync)(`"${a}" ${u.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 R(a){let b=B();return b?new Promise((c,d)=>{if(P("").catch(()=>{}),E())return void c({alreadyLoggedIn:!0});let e=D("up","--accept-routes");a&&e.push(`--hostname=${a}`);let f=(0,j.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},k=(a,b)=>{g||(g=!0,clearTimeout(m),clearInterval(l),console.log(`[Tailscale] login authUrl detected (${b})`),f.unref(),c({authUrl:a}))},l=setInterval(()=>{if(g)return;let a=Q();a&&k(a,"status")},500),m=setTimeout(()=>{if(g)return;g=!0,clearInterval(l),f.unref();let a=i(h)||Q();a?c({authUrl:a}):d(Error("tailscale up timed out without auth URL"))},15e3),n=a=>{let b=i(h+=a.toString());b&&k(b,"stdout")};f.stdout.on("data",n),f.stderr.on("data",n),f.on("error",a=>{g||(g=!0,clearTimeout(m),clearInterval(l),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)||Q();if(b)return void k(b,"exit");if(E()){g=!0,clearTimeout(m),clearInterval(l),c({alreadyLoggedIn:!0});return}})}):Promise.reject(Error("Tailscale not installed"))}async function S(a){let b=B();if(!b)throw Error("Tailscale not installed");try{(0,j.execSync)(`"${b}" ${u.join(" ")} funnel --bg reset`,{stdio:"ignore",windowsHide:!0})}catch(a){}return new Promise((c,d)=>{let e=(0,j.spawn)(b,D("funnel","--bg",`${a}`),{stdio:["ignore","pipe","pipe"],windowsHide:!0}),f=!1,g="",h=setTimeout(()=>{if(f)return;f=!0;let b=H()||I(a);b?c({tunnelUrl:b}):d(Error(`Tailscale funnel timed out: ${g.trim()||"no output"}`))},3e4),i=!1,k=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=H();b&&!f&&(f=!0,clearTimeout(h),c({tunnelUrl:b}))};e.stdout.on("data",k),e.stderr.on("data",k),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=H()||I(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 T(a){let b=B();if(!b||!a)return;let c=g().join(s,"certs");e().mkdirSync(c,{recursive:!0});let d=g().join(c,`${a}.crt`),f=g().join(c,`${a}.key`);try{await n(`"${b}" ${u.join(" ")} cert --cert-file "${d}" --key-file "${f}" "${a}"`,{windowsHide:!0,env:{...process.env,PATH:K},timeout:3e4}),console.log(`[Tailscale] cert provisioned for ${a}`)}catch(a){console.warn(`[Tailscale] cert provision failed (non-fatal): ${a.message}`)}}function U(){let a=B();if(a)try{(0,j.execSync)(`"${a}" ${u.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.n,"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}}};