Skip to content

Commit

Permalink
Merge pull request #17 from lbl8603/1.2.x
Browse files Browse the repository at this point in the history
1.2.x
  • Loading branch information
vnt-dev authored Jun 6, 2024
2 parents e0e8e64 + b529abe commit 31389d3
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 15 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,9 @@ jobs:
- TARGET: i686-unknown-linux-musl # test in an alpine container on a mac
OS: ubuntu-latest
FEATURES: normal,web
- TARGET: x86_64-unknown-linux-gnu # tested in a debian container on a mac
OS: ubuntu-latest
FEATURES: ring-cipher,web
- TARGET: x86_64-unknown-linux-musl # test in an alpine container on a mac
OS: ubuntu-latest
FEATURES: ring-cipher,web
- TARGET: aarch64-unknown-linux-gnu # tested on aws t4g.nano
OS: ubuntu-latest
FEATURES: ring-cipher,web
- TARGET: aarch64-unknown-linux-musl # tested on aws t4g.nano in alpine container
OS: ubuntu-latest
FEATURES: normal,web
Expand Down
5 changes: 4 additions & 1 deletion src/core/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ pub async fn start(
);
let tcp_handle = tokio::spawn(tcp::start(TcpListener::from_std(tcp)?, handler.clone()));
let udp_handle = tokio::spawn(udp::start(udp, handler.clone()));
#[cfg(not(feature = "web"))]
let _ = tokio::try_join!(tcp_handle, udp_handle);
#[cfg(feature = "web")]
if let Some(http) = http {
if let Err(e) = web::start(http, cache, config).await {
log::error!("{:?}", e);
}
} else {
let _ = tokio::try_join!(tcp_handle, udp_handle);
}
let _ = tokio::try_join!(tcp_handle, udp_handle);
Ok(())
}
12 changes: 10 additions & 2 deletions src/core/server/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ async fn stream_handle(stream: TcpStream, addr: SocketAddr, handler: PacketHandl
while let Some(data) = receiver.recv().await {
let len = data.len();
if let Err(e) = w
.write_all(&[0, 0, (len >> 8) as u8, (len & 0xFF) as u8])
.write_all(&[
(len >> 24) as u8,
(len >> 16) as u8,
(len >> 8) as u8,
len as u8,
])
.await
{
log::info!("发送失败,链接终止:{:?},{:?}", addr, e);
Expand Down Expand Up @@ -60,7 +65,10 @@ async fn tcp_read(
let sender = Some(sender);
loop {
read.read_exact(&mut head).await?;
let len = ((head[2] as usize) << 8) | head[3] as usize;
let len = ((head[0] as usize) << 24)
| ((head[1] as usize) << 16)
| ((head[2] as usize) << 8)
| head[3] as usize;
if len < 12 || len > buf.len() {
return Err(io::Error::new(
io::ErrorKind::InvalidData,
Expand Down
3 changes: 1 addition & 2 deletions src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ impl<B: AsRef<[u8]>> NetPacket<B> {
"length overflow",
));
}
// 不能大于udp最大载荷长度
if !(12..=65535 - 20 - 8).contains(&data_len) {
if HEAD_LEN > data_len {
return Err(io::Error::new(
io::ErrorKind::InvalidData,
"length overflow",
Expand Down
95 changes: 91 additions & 4 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
position: relative;
margin-left: 240px;
padding-left: 10px;
height: 100%;
}

#container {
Expand All @@ -33,6 +34,29 @@
line-height: 20px;
}

#group_info_show {
max-height: calc(100vh - 200px);
overflow-y: auto;
}

table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
}

table, th, td {
border: 1px solid #ccc;
}

th, td {
padding: 8px;
text-align: left;
}

th {
background-color: #f2f2f2;
}
</style>
</head>
<body>
Expand Down Expand Up @@ -85,13 +109,30 @@
<div class="mask_ip"></div>
<div class="network_ip"></div>
</div>
<div id="container">
<div id="group_info_show">
<div id="container">

</div>
<table id="deviceTable">
<thead>
<tr>
<th>虚拟 IP</th>
<th>名称</th>
<th>版本</th>
<th>在线状态</th>
<th>客户端加密</th>
<th>服务器加密</th>
<th>连接时间</th>
<th>链接地址</th>
<th>设备 ID</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
<div>

</div>
</div>

</body>
Expand Down Expand Up @@ -173,6 +214,51 @@
}
$('.group_len').html('(' + tempArr.length + ')')
}

function displayDeviceInfo(devices) {
const tableBody = document.getElementById('deviceTable').getElementsByTagName('tbody')[0];
devices.forEach(device => {
const row = document.createElement('tr');

const virtualIpCell = document.createElement('td');
virtualIpCell.textContent = device.virtual_ip;
row.appendChild(virtualIpCell);

const nameCell = document.createElement('td');
nameCell.textContent = device.name;
row.appendChild(nameCell);

const versionCell = document.createElement('td');
versionCell.textContent = device.version;
row.appendChild(versionCell);

const onlineCell = document.createElement('td');
onlineCell.textContent = device.online ? '在线' : '离线';
row.appendChild(onlineCell);

const clientSecretCell = document.createElement('td');
clientSecretCell.textContent = device.client_secret ? '是' : '否';
row.appendChild(clientSecretCell);

const serverSecretCell = document.createElement('td');
serverSecretCell.textContent = device.server_secret ? '是' : '否';
row.appendChild(serverSecretCell);

const lastJoinTimeCell = document.createElement('td');
lastJoinTimeCell.textContent = device.last_join_time;
row.appendChild(lastJoinTimeCell);

const addressCell = document.createElement('td');
addressCell.textContent = device.address;
row.appendChild(addressCell);

const deviceIdCell = document.createElement('td');
deviceIdCell.textContent = device.device_id;
row.appendChild(deviceIdCell);

tableBody.appendChild(row);
});
}
</script>
<script>
function formatBytes(bytes) {
Expand Down Expand Up @@ -282,8 +368,9 @@
$('.mask_ip').html(data.mask_ip);
$('.network_ip').html(data.network_ip);
nodeInitFunc(data.gateway_ip, data.clients);
displayDeviceInfo(data.clients);
} else {

window.alert("调用服务失败")
}

})
Expand Down

0 comments on commit 31389d3

Please sign in to comment.