mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-28 16:41:52 +08:00
feat!: 移除内置公共服务器
- 移除公共 RustDesk ID 服务器 (用户需自行配置) - 移除公共 TURN 服务器 (仅保留 Google STUN) - 清理废弃代码: PublicServerInfo, is_using_public_server 等 - 更新前端 UI 和国际化文本 - 重新生成 TypeScript 类型 破坏性变更: 不再提供内置公共服务器。用户必须配置自己的 RustDesk 服务器和 TURN 服务器才能在生产环境中使用。
This commit is contained in:
143
build.rs
143
build.rs
@@ -20,14 +20,13 @@ fn main() {
|
||||
// Compile protobuf files for RustDesk protocol
|
||||
compile_protos();
|
||||
|
||||
// Generate secrets module from secrets.toml
|
||||
// Generate minimal secrets module
|
||||
generate_secrets();
|
||||
|
||||
// Rerun if the script itself changes
|
||||
println!("cargo:rerun-if-changed=build.rs");
|
||||
println!("cargo:rerun-if-changed=protos/rendezvous.proto");
|
||||
println!("cargo:rerun-if-changed=protos/message.proto");
|
||||
println!("cargo:rerun-if-changed=secrets.toml");
|
||||
}
|
||||
|
||||
/// Compile protobuf files using protobuf-codegen (same as RustDesk server)
|
||||
@@ -52,123 +51,59 @@ pub mod message;
|
||||
std::fs::write(protos_dir.join("mod.rs"), mod_content).unwrap();
|
||||
}
|
||||
|
||||
/// Generate secrets module from secrets.toml
|
||||
///
|
||||
/// This reads the secrets.toml file and generates a Rust module with
|
||||
/// compile-time constants for sensitive configuration values.
|
||||
/// Generate minimal secrets module with Google STUN server hardcoded
|
||||
fn generate_secrets() {
|
||||
let out_dir = std::env::var("OUT_DIR").unwrap();
|
||||
let dest_path = Path::new(&out_dir).join("secrets_generated.rs");
|
||||
|
||||
// Default values if secrets.toml doesn't exist
|
||||
let mut rustdesk_public_server = String::new();
|
||||
let mut rustdesk_public_key = String::new();
|
||||
let mut rustdesk_relay_key = String::new();
|
||||
let mut ice_stun_server = String::new();
|
||||
let mut ice_turn_urls = String::new();
|
||||
let mut ice_turn_username = String::new();
|
||||
let mut ice_turn_password = String::new();
|
||||
|
||||
// Try to read secrets.toml
|
||||
if let Ok(content) = fs::read_to_string("secrets.toml") {
|
||||
if let Ok(value) = content.parse::<toml::Value>() {
|
||||
// RustDesk section
|
||||
if let Some(rustdesk) = value.get("rustdesk") {
|
||||
if let Some(v) = rustdesk.get("public_server").and_then(|v| v.as_str()) {
|
||||
rustdesk_public_server = v.to_string();
|
||||
}
|
||||
if let Some(v) = rustdesk.get("public_key").and_then(|v| v.as_str()) {
|
||||
rustdesk_public_key = v.to_string();
|
||||
}
|
||||
if let Some(v) = rustdesk.get("relay_key").and_then(|v| v.as_str()) {
|
||||
rustdesk_relay_key = v.to_string();
|
||||
}
|
||||
}
|
||||
|
||||
// ICE section (for WebRTC)
|
||||
if let Some(ice) = value.get("ice") {
|
||||
if let Some(v) = ice.get("stun_server").and_then(|v| v.as_str()) {
|
||||
ice_stun_server = v.to_string();
|
||||
}
|
||||
if let Some(v) = ice.get("turn_urls").and_then(|v| v.as_str()) {
|
||||
ice_turn_urls = v.to_string();
|
||||
}
|
||||
if let Some(v) = ice.get("turn_username").and_then(|v| v.as_str()) {
|
||||
ice_turn_username = v.to_string();
|
||||
}
|
||||
if let Some(v) = ice.get("turn_password").and_then(|v| v.as_str()) {
|
||||
ice_turn_password = v.to_string();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
println!("cargo:warning=Failed to parse secrets.toml");
|
||||
}
|
||||
} else {
|
||||
println!("cargo:warning=secrets.toml not found, using empty defaults");
|
||||
}
|
||||
|
||||
// Generate the secrets module
|
||||
let code = format!(
|
||||
r#"// Auto-generated secrets module
|
||||
// DO NOT EDIT - This file is generated by build.rs from secrets.toml
|
||||
|
||||
/// RustDesk public server configuration
|
||||
pub mod rustdesk {{
|
||||
/// Public RustDesk ID server address (used when user leaves field empty)
|
||||
pub const PUBLIC_SERVER: &str = "{}";
|
||||
|
||||
/// Public key for the RustDesk server (for client connection)
|
||||
pub const PUBLIC_KEY: &str = "{}";
|
||||
|
||||
/// Relay server authentication key (licence_key for relay server)
|
||||
pub const RELAY_KEY: &str = "{}";
|
||||
|
||||
/// Check if public server is configured
|
||||
pub const fn has_public_server() -> bool {{
|
||||
!PUBLIC_SERVER.is_empty()
|
||||
}}
|
||||
}}
|
||||
// Generate the secrets module - no public servers provided
|
||||
let code = r#"// Auto-generated secrets module
|
||||
// DO NOT EDIT - This file is generated by build.rs
|
||||
|
||||
/// ICE server configuration (for WebRTC NAT traversal)
|
||||
pub mod ice {{
|
||||
/// Public STUN server URL
|
||||
pub const STUN_SERVER: &str = "{}";
|
||||
pub mod ice {
|
||||
/// Google public STUN server URL (hardcoded)
|
||||
pub const STUN_SERVER: &str = "stun:stun.l.google.com:19302";
|
||||
|
||||
/// Public TURN server URLs (comma-separated)
|
||||
pub const TURN_URLS: &str = "{}";
|
||||
/// TURN server URLs - not provided, users must configure their own
|
||||
pub const TURN_URLS: &str = "";
|
||||
|
||||
/// TURN authentication username
|
||||
pub const TURN_USERNAME: &str = "{}";
|
||||
pub const TURN_USERNAME: &str = "";
|
||||
|
||||
/// TURN authentication password
|
||||
pub const TURN_PASSWORD: &str = "{}";
|
||||
pub const TURN_PASSWORD: &str = "";
|
||||
|
||||
/// Check if public ICE servers are configured
|
||||
pub const fn is_configured() -> bool {{
|
||||
!STUN_SERVER.is_empty() || !TURN_URLS.is_empty()
|
||||
}}
|
||||
/// Always returns true since we have STUN
|
||||
pub const fn is_configured() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
/// Check if TURN servers are configured (requires credentials)
|
||||
pub const fn has_turn() -> bool {{
|
||||
!TURN_URLS.is_empty() && !TURN_USERNAME.is_empty() && !TURN_PASSWORD.is_empty()
|
||||
}}
|
||||
}}
|
||||
"#,
|
||||
escape_string(&rustdesk_public_server),
|
||||
escape_string(&rustdesk_public_key),
|
||||
escape_string(&rustdesk_relay_key),
|
||||
escape_string(&ice_stun_server),
|
||||
escape_string(&ice_turn_urls),
|
||||
escape_string(&ice_turn_username),
|
||||
escape_string(&ice_turn_password),
|
||||
);
|
||||
|
||||
fs::write(&dest_path, code).expect("Failed to write secrets_generated.rs");
|
||||
/// Always returns false since TURN is not provided
|
||||
pub const fn has_turn() -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/// Escape special characters in a string for use in Rust string literals
|
||||
fn escape_string(s: &str) -> String {
|
||||
s.replace('\\', "\\\\").replace('"', "\\\"")
|
||||
/// RustDesk public server configuration - NOT PROVIDED
|
||||
pub mod rustdesk {
|
||||
/// Public RustDesk ID server - NOT PROVIDED
|
||||
pub const PUBLIC_SERVER: &str = "";
|
||||
|
||||
/// Public key for the RustDesk server - NOT PROVIDED
|
||||
pub const PUBLIC_KEY: &str = "";
|
||||
|
||||
/// Relay server authentication key - NOT PROVIDED
|
||||
pub const RELAY_KEY: &str = "";
|
||||
|
||||
/// Always returns false
|
||||
pub const fn has_public_server() -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
"#;
|
||||
|
||||
fs::write(&dest_path, code).expect("Failed to write secrets_generated.rs");
|
||||
}
|
||||
|
||||
/// Convert days since Unix epoch to year-month-day
|
||||
|
||||
Reference in New Issue
Block a user