add portforward config to gui (#1198)

* Added port forwarding to the GUI interface
* Separated port forwarding into a separate drop-down menu
This commit is contained in:
FuturePrayer
2025-08-09 09:50:09 +08:00
committed by GitHub
parent 8cdb27d43d
commit 37b24164b6
6 changed files with 164 additions and 2 deletions
+40 -1
View File
@@ -2,7 +2,7 @@ use std::{
collections::VecDeque,
sync::{atomic::AtomicBool, Arc, RwLock},
};
use std::net::SocketAddr;
use crate::{
common::{
config::{
@@ -20,6 +20,8 @@ use crate::{
use anyhow::Context;
use chrono::{DateTime, Local};
use tokio::{sync::broadcast, task::JoinSet};
use crate::common::config::PortForwardConfig;
use crate::proto::web;
pub type MyNodeInfo = crate::proto::web::MyNodeInfo;
@@ -588,6 +590,28 @@ impl NetworkConfig {
));
}
if !self.port_forwards.is_empty() {
cfg.set_port_forwards(
self.port_forwards
.iter()
.filter(|pf| !pf.bind_ip.is_empty() && !pf.dst_ip.is_empty())
.filter_map(|pf| {
let bind_addr = format!("{}:{}", pf.bind_ip, pf.bind_port).parse::<SocketAddr>();
let dst_addr = format!("{}:{}", pf.dst_ip, pf.dst_port).parse::<SocketAddr>();
match (bind_addr, dst_addr) {
(Ok(bind_addr), Ok(dst_addr)) => Some(PortForwardConfig {
bind_addr,
dst_addr,
proto: pf.proto.clone(),
}),
_ => None,
}
})
.collect::<Vec<_>>()
);
}
if self.enable_vpn_portal.unwrap_or_default() {
let cidr = format!(
"{}/{}",
@@ -820,6 +844,21 @@ impl NetworkConfig {
result.rpc_portal_whitelists = whitelist.iter().map(|w| w.to_string()).collect();
}
let port_forwards = config.get_port_forwards();
if !port_forwards.is_empty() {
result.port_forwards = port_forwards.iter()
.map(|f| {
web::PortForwardConfig {
proto: f.proto.clone(),
bind_ip: f.bind_addr.ip().to_string(),
bind_port: f.bind_addr.port() as u32,
dst_ip: f.dst_addr.ip().to_string(),
dst_port: f.dst_addr.port() as u32,
}
}).
collect();
}
if let Some(vpn_config) = config.get_vpn_portal_config() {
result.enable_vpn_portal = Some(true);
+9
View File
@@ -72,6 +72,15 @@ message NetworkConfig {
optional bool enable_quic_proxy = 45;
optional bool disable_quic_input = 46;
repeated PortForwardConfig port_forwards = 48;
}
message PortForwardConfig {
string bind_ip = 1;
uint32 bind_port = 2;
string dst_ip = 3;
uint32 dst_port = 4;
string proto = 5;
}
message MyNodeInfo {