Use new autoconfiguration instead of settings dialog
This commit is contained in:
parent
2ede0b1214
commit
c5efb90123
64
index.html
64
index.html
@ -40,34 +40,54 @@
|
|||||||
window.networkInterface = {};
|
window.networkInterface = {};
|
||||||
</script>
|
</script>
|
||||||
<script type="module">
|
<script type="module">
|
||||||
import { init } from "/tun/tailscale_tun.js";
|
import { State } from "/tun/tailscale_tun.js";
|
||||||
import {createUi} from "/tun/tailscale_tun_ui.js";
|
import { autoConf } from "/tun/tailscale_tun_auto.js";
|
||||||
|
|
||||||
let listen,connect,bind,parseIP,up,down,login,logout = null;
|
const loginUrlCb = (url) => {
|
||||||
const upCb = (conf) => {
|
const a = document.getElementById("loginLink");
|
||||||
up(conf);
|
a.href = url;
|
||||||
};
|
};
|
||||||
const downCb = () => {
|
const stateUpdateCb = (state) => {
|
||||||
down();
|
switch(state)
|
||||||
|
{
|
||||||
|
case State.NeedsLogin:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case State.Running:
|
||||||
|
{
|
||||||
|
const a = document.getElementById("loginLink");
|
||||||
|
a.href = "#";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case State.Starting:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case State.Stopped:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case State.NoState:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
const loginCb = () => {
|
const netmapUpdateCb = (map) => {
|
||||||
login();
|
const ip = map.self.addresses[0];
|
||||||
|
const status = document.getElementById("networkStatus");
|
||||||
|
status.innerHTML = "Ip: "+ip;
|
||||||
};
|
};
|
||||||
const logoutCb = () => {
|
const { listen, connect, bind, parseIP } = await autoConf({
|
||||||
logout();
|
loginUrlCb,
|
||||||
};
|
stateUpdateCb,
|
||||||
const { showModal, updateState, updatePeers, setLoginUrl } = createUi(document.body,{upCb,downCb,loginCb,logoutCb});
|
netmapUpdateCb,
|
||||||
|
});
|
||||||
({ listen, connect, bind, parseIP, up, down, login, logout } = await init({
|
|
||||||
netMapCb: updatePeers,
|
|
||||||
stateUpdateCb: updateState,
|
|
||||||
loginUrlCb: setLoginUrl,
|
|
||||||
}));
|
|
||||||
window.networkInterface.bind = bind;
|
window.networkInterface.bind = bind;
|
||||||
window.networkInterface.connect = connect;
|
window.networkInterface.connect = connect;
|
||||||
window.networkInterface.listen = listen;
|
window.networkInterface.listen = listen;
|
||||||
window.parseIP = parseIP;
|
window.parseIP = parseIP;
|
||||||
window.showModal = showModal;
|
|
||||||
</script>
|
</script>
|
||||||
<script src="./xterm/xterm.js"></script>
|
<script src="./xterm/xterm.js"></script>
|
||||||
<script src="./xterm/xterm-addon-fit.js"></script>
|
<script src="./xterm/xterm-addon-fit.js"></script>
|
||||||
@ -106,8 +126,8 @@
|
|||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li style=" margin-right: 50px; height: 100%; display: flex; align-items: center;">
|
<li style=" margin-right: 50px; height: 100%; display: flex; align-items: center;">
|
||||||
<a href="#" onclick="showModal()">
|
<a id="loginLink" href="#">
|
||||||
<div style="color: white; font-family: montserrat; font-weight: 700; font-size: large;">Network Settings</div>
|
<div id="networkStatus" style="color: white; font-family: montserrat; font-weight: 700; font-size: large;">Tailscale Login</div>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
</div>
|
</div>
|
||||||
|
29
tun/index.js
29
tun/index.js
@ -1,29 +0,0 @@
|
|||||||
import { init } from "./tailscale_tun.js";
|
|
||||||
import { showPeers, showLoginURL } from "./ui.js";
|
|
||||||
|
|
||||||
const { loginURL, ipStack } = await init({ netMapCallback: showPeers });
|
|
||||||
showLoginURL(loginURL);
|
|
||||||
const { connect, parseIP } = await ipStack;
|
|
||||||
|
|
||||||
async function testTcp()
|
|
||||||
{
|
|
||||||
let p = await connect(parseIP("100.84.181.36"), 6666);
|
|
||||||
if (!p)
|
|
||||||
throw "cannot connect";
|
|
||||||
p.onmessage = (ev) => {
|
|
||||||
let str = "";
|
|
||||||
if (ev.data == null)
|
|
||||||
str = "CLOSED";
|
|
||||||
else
|
|
||||||
{
|
|
||||||
let decoder = new TextDecoder();
|
|
||||||
str = decoder.decode(ev.data)
|
|
||||||
}
|
|
||||||
console.log("received", str);
|
|
||||||
};
|
|
||||||
let encoder = new TextEncoder();
|
|
||||||
let data = encoder.encode("hi from browser");
|
|
||||||
p.postMessage(data, [data.buffer]);
|
|
||||||
}
|
|
||||||
|
|
||||||
testTcp();
|
|
137
tun/ipstack.js
137
tun/ipstack.js
@ -13,10 +13,10 @@ function fetchBuffer(p){
|
|||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function ___cxx_global_var_init$p3(){
|
function ___cxx_global_var_init$p2(){
|
||||||
__ZN7IpStackL7chanMapE=_cheerpCreate_ZN6client4TMapIiPNS_14MessageChannelEEC2Ev();
|
__ZN7IpStackL7chanMapE=_cheerpCreate_ZN6client4TMapIiPNS_14MessageChannelEEC2Ev();
|
||||||
}
|
}
|
||||||
function ___cxx_global_var_init$p4(){
|
function ___cxx_global_var_init$p3(){
|
||||||
__ZN7IpStackL11listenerMapE=_cheerpCreate_ZN6client4TMapIiPNS_13EventListenerEEC2Ev();
|
__ZN7IpStackL11listenerMapE=_cheerpCreate_ZN6client4TMapIiPNS_13EventListenerEEC2Ev();
|
||||||
}
|
}
|
||||||
function _cheerpCreate_ZN6client4TMapIiPNS_13EventListenerEEC2Ev(){
|
function _cheerpCreate_ZN6client4TMapIiPNS_13EventListenerEEC2Ev(){
|
||||||
@ -58,7 +58,7 @@ function __ZN6cheerp14MakeTypedArrayIhN6client10Uint8ArrayEEEPT0_PKT_j(Lptr,Mptr
|
|||||||
return tmp1.subarray((+(tmp0>>>0)));
|
return tmp1.subarray((+(tmp0>>>0)));
|
||||||
}
|
}
|
||||||
function __Z14start_timeoutsv(){
|
function __Z14start_timeoutsv(){
|
||||||
+setInterval(__ZN6cheerp8CallbackIZ14start_timeoutsvE3$_0EEPN6client13EventListenerEOT_(),100);
|
+setInterval(__ZN6cheerp8CallbackIZ14start_timeoutsvE3$_0EEPN6client13EventListenerEOT_(),10);
|
||||||
}
|
}
|
||||||
function __ZN6cheerp8CallbackIZ14start_timeoutsvE3$_0EEPN6client13EventListenerEOT_(){
|
function __ZN6cheerp8CallbackIZ14start_timeoutsvE3$_0EEPN6client13EventListenerEOT_(){
|
||||||
var Lref$ptmp=null,Lcall1=null;
|
var Lref$ptmp=null,Lcall1=null;
|
||||||
@ -177,20 +177,15 @@ function __ZN7IpStack4downEv(){
|
|||||||
__Z4downv();
|
__Z4downv();
|
||||||
}
|
}
|
||||||
function __ZN7IpStack5inputEPN6client10Uint8ArrayE(Lpkt){
|
function __ZN7IpStack5inputEPN6client10Uint8ArrayE(Lpkt){
|
||||||
var LsavedStack=null,Ldata=0,Lcall1=null,Lcall1o=0,Lconv=0;
|
var Lconv=0,Lcall2=0,tmp2=null,tmp2o=0;
|
||||||
LsavedStack=___getStackPtr();
|
|
||||||
Lcall1=-16+LsavedStack|0;
|
|
||||||
___setStackPtr(Lcall1);
|
|
||||||
Lconv=~~ +Lpkt.length;
|
Lconv=~~ +Lpkt.length;
|
||||||
Ldata=Lcall1|0;
|
Lcall2=_pbuf_alloc(0,Lconv)|0;
|
||||||
__ZNSt6vectorIhSaIhEEC2Ej(Ldata,Lconv);
|
if((Lcall2|0)!=(0|0)){
|
||||||
Lcall1=HEAP8;
|
tmp2o=HEAP32[4+Lcall2>>2];
|
||||||
Lcall1o=__ZNSt6vectorIhSaIhEEixEj(Ldata,0)|0;
|
tmp2=HEAP8;
|
||||||
__ZN6cheerp14MakeTypedArrayIhN6client10Uint8ArrayEEEPT0_PKT_j(Lcall1,Lcall1o,Lconv).set(Lpkt);
|
__ZN6cheerp14MakeTypedArrayIhN6client10Uint8ArrayEEEPT0_PKT_j(tmp2,tmp2o,Lconv).set(Lpkt);
|
||||||
Lconv=_pbuf_alloc(0,Lconv,386)|0;
|
__ZN7IpStackL7doInputEP4pbuf(Lcall2);
|
||||||
if((Lconv|0)!=(0|0))__Z22copy_to_pbuf_and_inputP4pbufRKSt6vectorIhSaIhEE(Lconv,Ldata);
|
}
|
||||||
__ZNSt6vectorIhSaIhEED2Ev(Ldata);
|
|
||||||
___setStackPtr(LsavedStack);
|
|
||||||
}
|
}
|
||||||
function __ZN7IpStack6outputEPFvPN6client10Uint8ArrayEE(Lcallback){
|
function __ZN7IpStack6outputEPFvPN6client10Uint8ArrayEE(Lcallback){
|
||||||
__ZL9output_cb=Lcallback;
|
__ZL9output_cb=Lcallback;
|
||||||
@ -199,10 +194,7 @@ function __ZN7IpStack11recvAdapterEPN3tcp6SocketEPhj(Ls,Ldata,Mdata,Llen){
|
|||||||
var Lcall1=null;
|
var Lcall1=null;
|
||||||
Lcall1=__ZN6client4TMapIiPNS_14MessageChannelEE3getEi(__ZN7IpStackL7chanMapE,((Ls|0)|0)).port2;
|
Lcall1=__ZN6client4TMapIiPNS_14MessageChannelEE3getEi(__ZN7IpStackL7chanMapE,((Ls|0)|0)).port2;
|
||||||
if(__ZN7IpStack10isWasmNullIhEEbPT_(Ldata,Mdata)|0){
|
if(__ZN7IpStack10isWasmNullIhEEbPT_(Ldata,Mdata)|0){
|
||||||
console.warn(_cheerpCreate_ZN6client6StringC2EPKc(HEAP8,1052568>>0));
|
|
||||||
__ZN3tcp6Socket5closeEv(Ls|0);
|
__ZN3tcp6Socket5closeEv(Ls|0);
|
||||||
__ZN3tcp6SocketD2Ev(Ls|0);
|
|
||||||
_free(Ls|0);
|
|
||||||
Lcall1.postMessage(null);
|
Lcall1.postMessage(null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -220,24 +212,6 @@ function __ZN7IpStack10isWasmNullIhEEbPT_(Lp,Mp){
|
|||||||
}
|
}
|
||||||
return 0|0;
|
return 0|0;
|
||||||
}
|
}
|
||||||
function _cheerpCreate_ZN6client6StringC2EPKc(Larg0,Marg0){
|
|
||||||
return String(__ZN6client6String11fromCharPtrIcEEPS0_PKT_(Larg0,Marg0));
|
|
||||||
}
|
|
||||||
function __ZN6client6String11fromCharPtrIcEEPS0_PKT_(Ls,Ms){
|
|
||||||
var LretConstructor=null,tmp1=0,Lgeptoindexphi=0;
|
|
||||||
LretConstructor=String();
|
|
||||||
tmp1=Ls[Ms]|0;
|
|
||||||
if((tmp1&255)===0)return LretConstructor;
|
|
||||||
Lgeptoindexphi=0;
|
|
||||||
while(1){
|
|
||||||
LretConstructor=LretConstructor.concat(String.fromCharCode(tmp1<<24>>24));
|
|
||||||
Lgeptoindexphi=Lgeptoindexphi+1|0;
|
|
||||||
tmp1=Ls[Ms+Lgeptoindexphi|0]|0;
|
|
||||||
if((tmp1&255)!==0)continue;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return LretConstructor;
|
|
||||||
}
|
|
||||||
function __ZN7IpStack11connAdapterEPN3tcp6SocketEi(Ls,Lerr){
|
function __ZN7IpStack11connAdapterEPN3tcp6SocketEi(Ls,Lerr){
|
||||||
var tmp0=0,Lcall=null,Lcall2=null;
|
var tmp0=0,Lcall=null,Lcall2=null;
|
||||||
tmp0=((Ls|0)|0);
|
tmp0=((Ls|0)|0);
|
||||||
@ -284,8 +258,9 @@ function __ZN7IpStackL12setupChannelEPN3tcp6SocketE(Ls){
|
|||||||
Lcall1=LretConstructor.port2;
|
Lcall1=LretConstructor.port2;
|
||||||
__ZN6client4TMapIiPNS_14MessageChannelEE3setEiS2_(__ZN7IpStackL7chanMapE,((Ls|0)|0),LretConstructor);
|
__ZN6client4TMapIiPNS_14MessageChannelEE3setEiS2_(__ZN7IpStackL7chanMapE,((Ls|0)|0),LretConstructor);
|
||||||
__ZN7IpStack8recvWasmEPN3tcp6SocketE(Ls|0);
|
__ZN7IpStack8recvWasmEPN3tcp6SocketE(Ls|0);
|
||||||
LretConstructor={a0:0};
|
LretConstructor={a0:null,a1:0};
|
||||||
LretConstructor.a0=(Ls|0);
|
LretConstructor.a0=Lcall1;
|
||||||
|
LretConstructor.a1=(Ls|0);
|
||||||
Lcall1.onmessage=__ZN6cheerp8CallbackIZN7IpStackL12setupChannelEPN3tcp6SocketEE3$_7EEPN6client13EventListenerEOT_(LretConstructor);
|
Lcall1.onmessage=__ZN6cheerp8CallbackIZN7IpStackL12setupChannelEPN3tcp6SocketEE3$_7EEPN6client13EventListenerEOT_(LretConstructor);
|
||||||
}
|
}
|
||||||
function __ZN6client4TMapIiPNS_13EventListenerEE3setEiS2_(Lthis,Lk,Lv){
|
function __ZN6client4TMapIiPNS_13EventListenerEE3setEiS2_(Lthis,Lk,Lv){
|
||||||
@ -330,8 +305,9 @@ function __ZN6cheerp13ClosureHelperIZN7IpStackL12setupChannelEPN3tcp6SocketEE3$_
|
|||||||
}
|
}
|
||||||
function __ZN6cheerp7ClosureIFvPN6client12MessageEventEEEC2IZN7IpStackL12setupChannelEPN3tcp6SocketEE3$_7EEOT_PNSt9enable_ifIXntsr3std14is_convertibleISC_PS4_EE5valueEvE4typeEPNSE_IXntsrNS5_13_must_destroyISC_EE5valueEvE4typeE(Lthis,Lf){
|
function __ZN6cheerp7ClosureIFvPN6client12MessageEventEEEC2IZN7IpStackL12setupChannelEPN3tcp6SocketEE3$_7EEOT_PNSt9enable_ifIXntsr3std14is_convertibleISC_PS4_EE5valueEvE4typeEPNSE_IXntsrNS5_13_must_destroyISC_EE5valueEvE4typeE(Lthis,Lf){
|
||||||
var tmp0=null,tmp1=null;
|
var tmp0=null,tmp1=null;
|
||||||
tmp0=[{a0:0}];
|
tmp0=[{a0:null,a1:0}];
|
||||||
tmp0[0].a0=(Lf.a0|0);
|
tmp0[0].a0=Lf.a0;
|
||||||
|
tmp0[0].a1=(Lf.a1|0);
|
||||||
tmp1=cheerpCreateClosure(__ZN6cheerp12InvokeHelperIvE6invokeIZN7IpStackL12setupChannelEPN3tcp6SocketEE3$_7JPN6client12MessageEventEEEEvPT_DpT0_,tmp0[0]);
|
tmp1=cheerpCreateClosure(__ZN6cheerp12InvokeHelperIvE6invokeIZN7IpStackL12setupChannelEPN3tcp6SocketEE3$_7JPN6client12MessageEventEEEEvPT_DpT0_,tmp0[0]);
|
||||||
Lthis.a0=tmp1;
|
Lthis.a0=tmp1;
|
||||||
Lthis.a1=null;
|
Lthis.a1=null;
|
||||||
@ -341,7 +317,7 @@ function __ZN6cheerp12InvokeHelperIvE6invokeIZN7IpStackL12setupChannelEPN3tcp6So
|
|||||||
__ZZN7IpStackL12setupChannelEPN3tcp6SocketEENK3$_7clEPN6client12MessageEventE(Lfunc,Largs);
|
__ZZN7IpStackL12setupChannelEPN3tcp6SocketEENK3$_7clEPN6client12MessageEventE(Lfunc,Largs);
|
||||||
}
|
}
|
||||||
function __ZZN7IpStackL12setupChannelEPN3tcp6SocketEENK3$_7clEPN6client12MessageEventE(Lthis,Lev){
|
function __ZZN7IpStackL12setupChannelEPN3tcp6SocketEENK3$_7clEPN6client12MessageEventE(Lthis,Lev){
|
||||||
var LsavedStack=null,Lcall=null,Lcall8=null,Lcall8o=0,Lcall7=null,Lcall7o=0,Lbuf=0,Li$p04=0;
|
var LsavedStack=null,Lcall=null,Lbuf=0,Lcall8=null,Lcall8o=0,Lcall7=null,Lcall7o=0,Li$p03=0;
|
||||||
LsavedStack=___getStackPtr();
|
LsavedStack=___getStackPtr();
|
||||||
Lcall7=-16+LsavedStack|0;
|
Lcall7=-16+LsavedStack|0;
|
||||||
___setStackPtr(Lcall7);
|
___setStackPtr(Lcall7);
|
||||||
@ -350,27 +326,23 @@ function __ZZN7IpStackL12setupChannelEPN3tcp6SocketEENK3$_7clEPN6client12Message
|
|||||||
Lbuf=Lcall7|0;
|
Lbuf=Lcall7|0;
|
||||||
__ZNSt6vectorIhSaIhEEC2Ej(Lbuf,~~ +Lcall.length);
|
__ZNSt6vectorIhSaIhEEC2Ej(Lbuf,~~ +Lcall.length);
|
||||||
if( +Lcall.length>0){
|
if( +Lcall.length>0){
|
||||||
Li$p04=0;
|
Li$p03=0;
|
||||||
while(1){
|
while(1){
|
||||||
Lcall7=__ZN6client10Uint8ArrayixEi(Lcall,Li$p04);
|
Lcall7=__ZN6client10Uint8ArrayixEi(Lcall,Li$p03);
|
||||||
Lcall7o=oSlot;
|
Lcall7o=oSlot;
|
||||||
Lcall8=HEAP8;
|
Lcall8=HEAP8;
|
||||||
Lcall8o=__ZNSt6vectorIhSaIhEEixEj(Lbuf,Li$p04)|0;
|
Lcall8o=__ZNSt6vectorIhSaIhEEixEj(Lbuf,Li$p03)|0;
|
||||||
Lcall8[Lcall8o]=Lcall7[Lcall7o]|0;
|
Lcall8[Lcall8o]=Lcall7[Lcall7o]|0;
|
||||||
Li$p04=Li$p04+1|0;
|
Li$p03=Li$p03+1|0;
|
||||||
if( +Lcall.length>(+(Li$p04|0)))continue;
|
if( +Lcall.length>(+(Li$p03|0)))continue;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
__ZN7IpStack8sendWasmEPN3tcp6SocketERKSt6vectorIhSaIhEE(Lthis.a0|0,Lbuf);
|
__ZN7IpStack8sendWasmEPN3tcp6SocketERKSt6vectorIhSaIhEE(Lthis.a1|0,Lbuf);
|
||||||
__ZNSt6vectorIhSaIhEED2Ev(Lbuf);
|
__ZNSt6vectorIhSaIhEED2Ev(Lbuf);
|
||||||
}else{
|
}else{
|
||||||
__ZN3tcp6Socket5closeEv(Lthis.a0|0);
|
__ZN3tcp6Socket5closeEv(Lthis.a1|0);
|
||||||
Lbuf=Lthis.a0|0;
|
Lthis.a0.onmessage=null;
|
||||||
if((Lbuf|0)!=(0|0)){
|
|
||||||
__ZN3tcp6SocketD2Ev(Lbuf);
|
|
||||||
_free(Lbuf|0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
___setStackPtr(LsavedStack);
|
___setStackPtr(LsavedStack);
|
||||||
}
|
}
|
||||||
@ -430,6 +402,10 @@ function __ZN6cheerp7ClosureIFvPN6client12MessageEventEEEC2IZN7IpStack6listenEiE
|
|||||||
Lthis.a2=tmp0[0];
|
Lthis.a2=tmp0[0];
|
||||||
}
|
}
|
||||||
function __ZN6cheerp12InvokeHelperIvE6invokeIZN7IpStack6listenEiE3$_4JPN6client12MessageEventEEEEvPT_DpT0_(Lfunc,Largs){
|
function __ZN6cheerp12InvokeHelperIvE6invokeIZN7IpStack6listenEiE3$_4JPN6client12MessageEventEEEEvPT_DpT0_(Lfunc,Largs){
|
||||||
|
__ZZN7IpStack6listenEiENK3$_4clEPN6client12MessageEventE(Lfunc);
|
||||||
|
}
|
||||||
|
function __ZZN7IpStack6listenEiENK3$_4clEPN6client12MessageEventE(Lthis){
|
||||||
|
__ZN3tcp6Socket5closeEv(Lthis.a0|0);
|
||||||
}
|
}
|
||||||
function __ZN7IpStack14recvAdapterUdpEPN3udp6SocketEPhjii(Ls,Ldata,Mdata,Llen,Laddr,Lport){
|
function __ZN7IpStack14recvAdapterUdpEPN3udp6SocketEPhjii(Ls,Ldata,Mdata,Llen,Laddr,Lport){
|
||||||
var Lcall=0,Lcall2=null;
|
var Lcall=0,Lcall2=null;
|
||||||
@ -483,7 +459,7 @@ function __ZN6cheerp12InvokeHelperIvE6invokeIZN7IpStack4bindEiE3$_6JPN6client12M
|
|||||||
__ZZN7IpStack4bindEiENK3$_6clEPN6client12MessageEventE(Lfunc,Largs);
|
__ZZN7IpStack4bindEiENK3$_6clEPN6client12MessageEventE(Lfunc,Largs);
|
||||||
}
|
}
|
||||||
function __ZZN7IpStack4bindEiENK3$_6clEPN6client12MessageEventE(Lthis,Lev){
|
function __ZZN7IpStack4bindEiENK3$_6clEPN6client12MessageEventE(Lthis,Lev){
|
||||||
var LsavedStack=null,Lcall=null,Lcall3=null,Lcall9=null,Lcall9o=0,Lcall11=0,Lcall8=null,Lcall8o=0,Lbuf=0,Li$p04=0;
|
var LsavedStack=null,Lcall=null,Lcall3=null,Lbuf=0,Lcall9=null,Lcall9o=0,Lcall11=0,Lcall8=null,Lcall8o=0,Li$p03=0;
|
||||||
LsavedStack=___getStackPtr();
|
LsavedStack=___getStackPtr();
|
||||||
Lcall8=-16+LsavedStack|0;
|
Lcall8=-16+LsavedStack|0;
|
||||||
___setStackPtr(Lcall8);
|
___setStackPtr(Lcall8);
|
||||||
@ -493,38 +469,31 @@ function __ZZN7IpStack4bindEiENK3$_6clEPN6client12MessageEventE(Lthis,Lev){
|
|||||||
Lbuf=Lcall8|0;
|
Lbuf=Lcall8|0;
|
||||||
__ZNSt6vectorIhSaIhEEC2Ej(Lbuf,~~ +Lcall3.length);
|
__ZNSt6vectorIhSaIhEEC2Ej(Lbuf,~~ +Lcall3.length);
|
||||||
if( +Lcall3.length>0){
|
if( +Lcall3.length>0){
|
||||||
Li$p04=0;
|
Li$p03=0;
|
||||||
while(1){
|
while(1){
|
||||||
Lcall8=__ZN6client10Uint8ArrayixEi(Lcall3,Li$p04);
|
Lcall8=__ZN6client10Uint8ArrayixEi(Lcall3,Li$p03);
|
||||||
Lcall8o=oSlot;
|
Lcall8o=oSlot;
|
||||||
Lcall9=HEAP8;
|
Lcall9=HEAP8;
|
||||||
Lcall9o=__ZNSt6vectorIhSaIhEEixEj(Lbuf,Li$p04)|0;
|
Lcall9o=__ZNSt6vectorIhSaIhEEixEj(Lbuf,Li$p03)|0;
|
||||||
Lcall9[Lcall9o]=Lcall8[Lcall8o]|0;
|
Lcall9[Lcall9o]=Lcall8[Lcall8o]|0;
|
||||||
Li$p04=Li$p04+1|0;
|
Li$p03=Li$p03+1|0;
|
||||||
if( +Lcall3.length>(+(Li$p04|0)))continue;
|
if( +Lcall3.length>(+(Li$p03|0)))continue;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Li$p04=Lcall.addr;
|
Li$p03=Lcall.addr;
|
||||||
Lcall11=Lcall.port;
|
Lcall11=Lcall.port;
|
||||||
__ZN7IpStack11sendWasmUdpEPN3udp6SocketERKSt6vectorIhSaIhEEjj(Lthis.a0|0,Lbuf,Li$p04,Lcall11);
|
__ZN7IpStack11sendWasmUdpEPN3udp6SocketERKSt6vectorIhSaIhEEjj(Lthis.a0|0,Lbuf,Li$p03,Lcall11);
|
||||||
__ZNSt6vectorIhSaIhEED2Ev(Lbuf);
|
__ZNSt6vectorIhSaIhEED2Ev(Lbuf);
|
||||||
}else{
|
}else __ZN3udp6Socket5closeEv(Lthis.a0|0);
|
||||||
__ZN3udp6Socket5closeEv(Lthis.a0|0);
|
|
||||||
Lbuf=Lthis.a0|0;
|
|
||||||
if((Lbuf|0)!=(0|0)){
|
|
||||||
__ZN3udp6SocketD2Ev(Lbuf);
|
|
||||||
_free(Lbuf|0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
___setStackPtr(LsavedStack);
|
___setStackPtr(LsavedStack);
|
||||||
}
|
}
|
||||||
function __ZN10__cxxabiv1L24__cxa_throw_wasm_adapterEjPSt9type_infoj(Lthrown_object){
|
function __ZN10__cxxabiv1L24__cxa_throw_wasm_adapterEjPSt9type_infoj(Lthrown_object){
|
||||||
var Ldest$paddr=null,Lref$ptmp=null,Ltinfo$paddr=null;
|
var Ldest$paddr=null,Lref$ptmp=null,Ltinfo$paddr=null;
|
||||||
Ltinfo$paddr=[0];
|
Ltinfo$paddr=[0];
|
||||||
Ltinfo$paddr[0]=(1048752|0);
|
Ltinfo$paddr[0]=(1048880|0);
|
||||||
Ldest$paddr=[0];
|
Ldest$paddr=[0];
|
||||||
Ldest$paddr[0]=((58|0)|0);
|
Ldest$paddr[0]=((59|0)|0);
|
||||||
Lref$ptmp=[nullObj];
|
Lref$ptmp=[nullObj];
|
||||||
Lref$ptmp[0]={d:null,o:Lthrown_object};
|
Lref$ptmp[0]={d:null,o:Lthrown_object};
|
||||||
Ltinfo$paddr=__ZN10__cxxabiv19Exception8allocateIJPvRPSt9type_infoRjEEEPS0_DpOT_(Lref$ptmp,0,Ltinfo$paddr,0,Ldest$paddr,0);
|
Ltinfo$paddr=__ZN10__cxxabiv19Exception8allocateIJPvRPSt9type_infoRjEEEPS0_DpOT_(Lref$ptmp,0,Ltinfo$paddr,0,Ldest$paddr,0);
|
||||||
@ -598,6 +567,20 @@ function __ZN10__cxxabiv1L8do_throwEPNS_9ExceptionE(Lex){
|
|||||||
throw LretConstructor8;
|
throw LretConstructor8;
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
function _cheerpCreate_ZN6client6StringC2EPKc(Larg0,Marg0){
|
||||||
|
var LretConstructor$pi=null,Lgeptoindexphi=0,LcheerpPtrAlloca$p07$pi=null;
|
||||||
|
LretConstructor$pi=String();
|
||||||
|
if((Larg0[Marg0]&255)===0)return String(LretConstructor$pi);
|
||||||
|
Lgeptoindexphi=0;
|
||||||
|
while(1){
|
||||||
|
LcheerpPtrAlloca$p07$pi=String.fromCharCode(Larg0[Marg0+Lgeptoindexphi|0]<<24>>24);
|
||||||
|
LretConstructor$pi=LretConstructor$pi.concat(LcheerpPtrAlloca$p07$pi);
|
||||||
|
Lgeptoindexphi=Lgeptoindexphi+1|0;
|
||||||
|
if((Larg0[Marg0+Lgeptoindexphi|0]&255)!==0)continue;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return String(LretConstructor$pi);
|
||||||
|
}
|
||||||
function _print(Lbuf,Mbuf,Llen){
|
function _print(Lbuf,Mbuf,Llen){
|
||||||
var Lcall=null,Lsub=0;
|
var Lcall=null,Lsub=0;
|
||||||
Lcall=__ZN6client6String8fromUtf8EPKcj(Lbuf,Mbuf,Llen);
|
Lcall=__ZN6client6String8fromUtf8EPKcj(Lbuf,Mbuf,Llen);
|
||||||
@ -652,8 +635,8 @@ function __ZN6client6String8fromUtf8EPKcj(Lin,Min,Llen){
|
|||||||
}
|
}
|
||||||
function __start(){
|
function __start(){
|
||||||
___cxx_global_var_init();
|
___cxx_global_var_init();
|
||||||
|
___cxx_global_var_init$p2();
|
||||||
___cxx_global_var_init$p3();
|
___cxx_global_var_init$p3();
|
||||||
___cxx_global_var_init$p4();
|
|
||||||
}
|
}
|
||||||
function ___wrapper__print(Larg0,Larg1){
|
function ___wrapper__print(Larg0,Larg1){
|
||||||
_print(HEAP8,Larg0>>0,Larg1);
|
_print(HEAP8,Larg0>>0,Larg1);
|
||||||
@ -752,8 +735,8 @@ var __ZN3tcp6Socket4bindEii=null;
|
|||||||
var __ZN3tcp6Socket6listenEv=null;
|
var __ZN3tcp6Socket6listenEv=null;
|
||||||
var __ZN7IpStack10acceptWasmEPN3tcp6SocketE=null;
|
var __ZN7IpStack10acceptWasmEPN3tcp6SocketE=null;
|
||||||
var __ZN3tcp6SocketD2Ev=null;
|
var __ZN3tcp6SocketD2Ev=null;
|
||||||
var __ZN7IpStack8recvWasmEPN3tcp6SocketE=null;
|
|
||||||
var __ZN3tcp6Socket5closeEv=null;
|
var __ZN3tcp6Socket5closeEv=null;
|
||||||
|
var __ZN7IpStack8recvWasmEPN3tcp6SocketE=null;
|
||||||
var __ZN7IpStack8sendWasmEPN3tcp6SocketERKSt6vectorIhSaIhEE=null;
|
var __ZN7IpStack8sendWasmEPN3tcp6SocketERKSt6vectorIhSaIhEE=null;
|
||||||
var __ZN7IpStack11connectWasmEPN3tcp6SocketEii=null;
|
var __ZN7IpStack11connectWasmEPN3tcp6SocketEii=null;
|
||||||
var __ZN2ip4stonERKSs=null;
|
var __ZN2ip4stonERKSs=null;
|
||||||
@ -762,7 +745,7 @@ var __ZNSsC2Ev=null;
|
|||||||
var __ZNSs6resizeEj=null;
|
var __ZNSs6resizeEj=null;
|
||||||
var __ZNSsixEj_icf=null;
|
var __ZNSsixEj_icf=null;
|
||||||
var _pbuf_alloc=null;
|
var _pbuf_alloc=null;
|
||||||
var __Z22copy_to_pbuf_and_inputP4pbufRKSt6vectorIhSaIhEE=null;
|
var __ZN7IpStackL7doInputEP4pbuf=null;
|
||||||
var __Z4downv=null;
|
var __Z4downv=null;
|
||||||
var __ZNSt13unordered_mapISsSsSt4hashISsESt8equal_toISsESaISt4pairIKSsSsEEEC2Ev=null;
|
var __ZNSt13unordered_mapISsSsSt4hashISsESt8equal_toISsESaISt4pairIKSsSsEEEC2Ev=null;
|
||||||
var __ZNSt13unordered_mapISsSsSt4hashISsESt8equal_toISsESaISt4pairIKSsSsEEE7emplaceIJSsSsEEES4_ISt19__hash_map_iteratorISt15__hash_iteratorIPSt11__hash_nodeISt17__hash_value_typeISsSsEPvEEEbEDpOT_=null;
|
var __ZNSt13unordered_mapISsSsSt4hashISsESt8equal_toISsESaISt4pairIKSsSsEEE7emplaceIJSsSsEEES4_ISt19__hash_map_iteratorISt15__hash_iteratorIPSt11__hash_nodeISt17__hash_value_typeISsSsEPvEEEbEDpOT_=null;
|
||||||
@ -821,8 +804,8 @@ export default function(Lh){
|
|||||||
__ZN3tcp6Socket6listenEv=__asm.__ZN3tcp6Socket6listenEv;
|
__ZN3tcp6Socket6listenEv=__asm.__ZN3tcp6Socket6listenEv;
|
||||||
__ZN7IpStack10acceptWasmEPN3tcp6SocketE=__asm.__ZN7IpStack10acceptWasmEPN3tcp6SocketE;
|
__ZN7IpStack10acceptWasmEPN3tcp6SocketE=__asm.__ZN7IpStack10acceptWasmEPN3tcp6SocketE;
|
||||||
__ZN3tcp6SocketD2Ev=__asm.__ZN3tcp6SocketD2Ev;
|
__ZN3tcp6SocketD2Ev=__asm.__ZN3tcp6SocketD2Ev;
|
||||||
__ZN7IpStack8recvWasmEPN3tcp6SocketE=__asm.__ZN7IpStack8recvWasmEPN3tcp6SocketE;
|
|
||||||
__ZN3tcp6Socket5closeEv=__asm.__ZN3tcp6Socket5closeEv;
|
__ZN3tcp6Socket5closeEv=__asm.__ZN3tcp6Socket5closeEv;
|
||||||
|
__ZN7IpStack8recvWasmEPN3tcp6SocketE=__asm.__ZN7IpStack8recvWasmEPN3tcp6SocketE;
|
||||||
__ZN7IpStack8sendWasmEPN3tcp6SocketERKSt6vectorIhSaIhEE=__asm.__ZN7IpStack8sendWasmEPN3tcp6SocketERKSt6vectorIhSaIhEE;
|
__ZN7IpStack8sendWasmEPN3tcp6SocketERKSt6vectorIhSaIhEE=__asm.__ZN7IpStack8sendWasmEPN3tcp6SocketERKSt6vectorIhSaIhEE;
|
||||||
__ZN7IpStack11connectWasmEPN3tcp6SocketEii=__asm.__ZN7IpStack11connectWasmEPN3tcp6SocketEii;
|
__ZN7IpStack11connectWasmEPN3tcp6SocketEii=__asm.__ZN7IpStack11connectWasmEPN3tcp6SocketEii;
|
||||||
__ZN2ip4stonERKSs=__asm.__ZN2ip4stonERKSs;
|
__ZN2ip4stonERKSs=__asm.__ZN2ip4stonERKSs;
|
||||||
@ -831,7 +814,7 @@ export default function(Lh){
|
|||||||
__ZNSs6resizeEj=__asm.__ZNSs6resizeEj;
|
__ZNSs6resizeEj=__asm.__ZNSs6resizeEj;
|
||||||
__ZNSsixEj_icf=__asm.__ZNSsixEj_icf;
|
__ZNSsixEj_icf=__asm.__ZNSsixEj_icf;
|
||||||
_pbuf_alloc=__asm._pbuf_alloc;
|
_pbuf_alloc=__asm._pbuf_alloc;
|
||||||
__Z22copy_to_pbuf_and_inputP4pbufRKSt6vectorIhSaIhEE=__asm.__Z22copy_to_pbuf_and_inputP4pbufRKSt6vectorIhSaIhEE;
|
__ZN7IpStackL7doInputEP4pbuf=__asm.__ZN7IpStackL7doInputEP4pbuf;
|
||||||
__Z4downv=__asm.__Z4downv;
|
__Z4downv=__asm.__Z4downv;
|
||||||
__ZNSt13unordered_mapISsSsSt4hashISsESt8equal_toISsESaISt4pairIKSsSsEEEC2Ev=__asm.__ZNSt13unordered_mapISsSsSt4hashISsESt8equal_toISsESaISt4pairIKSsSsEEEC2Ev;
|
__ZNSt13unordered_mapISsSsSt4hashISsESt8equal_toISsESaISt4pairIKSsSsEEEC2Ev=__asm.__ZNSt13unordered_mapISsSsSt4hashISsESt8equal_toISsESaISt4pairIKSsSsEEEC2Ev;
|
||||||
__ZNSt13unordered_mapISsSsSt4hashISsESt8equal_toISsESaISt4pairIKSsSsEEE7emplaceIJSsSsEEES4_ISt19__hash_map_iteratorISt15__hash_iteratorIPSt11__hash_nodeISt17__hash_value_typeISsSsEPvEEEbEDpOT_=__asm.__ZNSt13unordered_mapISsSsSt4hashISsESt8equal_toISsESaISt4pairIKSsSsEEE7emplaceIJSsSsEEES4_ISt19__hash_map_iteratorISt15__hash_iteratorIPSt11__hash_nodeISt17__hash_value_typeISsSsEPvEEEbEDpOT_;
|
__ZNSt13unordered_mapISsSsSt4hashISsESt8equal_toISsESaISt4pairIKSsSsEEE7emplaceIJSsSsEEES4_ISt19__hash_map_iteratorISt15__hash_iteratorIPSt11__hash_nodeISt17__hash_value_typeISsSsEPvEEEbEDpOT_=__asm.__ZNSt13unordered_mapISsSsSt4hashISsESt8equal_toISsESaISt4pairIKSsSsEEE7emplaceIJSsSsEEES4_ISt19__hash_map_iteratorISt15__hash_iteratorIPSt11__hash_nodeISt17__hash_value_typeISsSsEPvEEEbEDpOT_;
|
||||||
|
BIN
tun/ipstack.wasm
BIN
tun/ipstack.wasm
Binary file not shown.
Binary file not shown.
@ -2,8 +2,17 @@ import "./wasm_exec.js";
|
|||||||
|
|
||||||
import ipStackAwait from "./ipstack.js";
|
import ipStackAwait from "./ipstack.js";
|
||||||
|
|
||||||
export async function init({ stateUpdateCb, netMapCb, loginUrlCb })
|
export const State = {
|
||||||
{
|
NoState: 0,
|
||||||
|
InUseOtherUser: 1,
|
||||||
|
NeedsLogin: 2,
|
||||||
|
NeedsMachineAuth: 3,
|
||||||
|
Stopped: 4,
|
||||||
|
Starting: 5,
|
||||||
|
Running: 6,
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function init() {
|
||||||
const {IpStack} = await ipStackAwait();
|
const {IpStack} = await ipStackAwait();
|
||||||
|
|
||||||
const wasmUrl = new URL("tailscale.wasm", import.meta.url);
|
const wasmUrl = new URL("tailscale.wasm", import.meta.url);
|
||||||
@ -11,16 +20,11 @@ export async function init({ stateUpdateCb, netMapCb, loginUrlCb })
|
|||||||
let {instance} = await WebAssembly.instantiateStreaming(fetch(wasmUrl),go.importObject);
|
let {instance} = await WebAssembly.instantiateStreaming(fetch(wasmUrl),go.importObject);
|
||||||
go.run(instance);
|
go.run(instance);
|
||||||
|
|
||||||
const State = {
|
const listeners = {
|
||||||
NoState: 0,
|
onstateupdate: () => {},
|
||||||
InUseOtherUser: 1,
|
onnetmap: () => {},
|
||||||
NeedsLogin: 2,
|
onloginurl: () => {},
|
||||||
NeedsMachineAuth: 3,
|
}
|
||||||
Stopped: 4,
|
|
||||||
Starting: 5,
|
|
||||||
Running: 6,
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
const sessionStateStorage = {
|
const sessionStateStorage = {
|
||||||
setState(id, value) {
|
setState(id, value) {
|
||||||
@ -54,11 +58,10 @@ export async function init({ stateUpdateCb, netMapCb, loginUrlCb })
|
|||||||
let dnsIp = null;
|
let dnsIp = null;
|
||||||
|
|
||||||
ipn.run({
|
ipn.run({
|
||||||
notifyState: stateUpdateCb,
|
notifyState: (s) => listeners.onstateupdate(s),
|
||||||
notifyNetMap: (s) => {
|
notifyNetMap: (s) => {
|
||||||
const netMap = JSON.parse(s);
|
const netMap = JSON.parse(s);
|
||||||
if (netMapCb)
|
listeners.onnetmap(netMap);
|
||||||
netMapCb(netMap);
|
|
||||||
const newLocalIp = netMap.self.addresses[0];
|
const newLocalIp = netMap.self.addresses[0];
|
||||||
if (localIp != newLocalIp)
|
if (localIp != newLocalIp)
|
||||||
{
|
{
|
||||||
@ -69,7 +72,7 @@ export async function init({ stateUpdateCb, netMapCb, loginUrlCb })
|
|||||||
}});
|
}});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
notifyBrowseToURL: loginUrlCb,
|
notifyBrowseToURL: (l) => listeners.onloginurl(l),
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -88,6 +91,7 @@ export async function init({ stateUpdateCb, netMapCb, loginUrlCb })
|
|||||||
},
|
},
|
||||||
login: () => ipn.login(),
|
login: () => ipn.login(),
|
||||||
logout: () => ipn.logout(),
|
logout: () => ipn.logout(),
|
||||||
|
listeners
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
82
tun/tailscale_tun_auto.js
Normal file
82
tun/tailscale_tun_auto.js
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
import {State, init} from "./tailscale_tun.js";
|
||||||
|
|
||||||
|
export async function autoConf({loginUrlCb, stateUpdateCb, netmapUpdateCb}) {
|
||||||
|
const { listen, connect, bind, parseIP, up, down, login, logout, listeners } = await init();
|
||||||
|
|
||||||
|
const getSettings = () => {
|
||||||
|
settings.controlUrl = null;
|
||||||
|
settings.exitNodeIp = null;
|
||||||
|
settings.dnsIp = null;
|
||||||
|
settings.wantsRunning = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const settings = {
|
||||||
|
controlUrl: undefined,
|
||||||
|
exitNodeIp: undefined,
|
||||||
|
dnsIp: undefined,
|
||||||
|
wantsRunning: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
listeners.onstateupdate = (state) => {
|
||||||
|
stateUpdateCb(state);
|
||||||
|
switch(state)
|
||||||
|
{
|
||||||
|
case State.NeedsLogin:
|
||||||
|
{
|
||||||
|
login();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case State.Running:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case State.Starting:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case State.Stopped:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case State.NoState:
|
||||||
|
{
|
||||||
|
up(settings);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
console.log(state);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
listeners.onloginurl = (login) => {
|
||||||
|
console.log("login url:",login);
|
||||||
|
loginUrlCb(login);
|
||||||
|
};
|
||||||
|
|
||||||
|
listeners.onnetmap = (map) => {
|
||||||
|
netmapUpdateCb(map);
|
||||||
|
if (!settings.exitNodeIp) {
|
||||||
|
for (let p of map.peers) {
|
||||||
|
if (p.online && p.exitNode) {
|
||||||
|
settings.exitNodeIp = p.addresses[0];
|
||||||
|
settings.dnsIp = "8.8.8.8";
|
||||||
|
up(settings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
up(settings);
|
||||||
|
|
||||||
|
return {
|
||||||
|
bind,
|
||||||
|
connect,
|
||||||
|
listen,
|
||||||
|
parseIP,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user