Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions crates/tw-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,12 @@ pub struct ConfigText {
pub version: String,
}

/// 一把刚生成、还没写进配置的网关密钥(`GET /keys/new`)。
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NewKey {
pub key: String,
}

/// 这台机器上的一张网卡(`GET /interfaces`)。
///
/// **界面上「绑在哪张网卡」那个选单要的就是它。**没有它,用户只能自己
Expand Down
12 changes: 12 additions & 0 deletions crates/tw-control/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ pub fn router(state: ControlState) -> Router {
Router::new()
.route("/status", get(status))
.route("/interfaces", get(interfaces))
.route("/keys/new", get(new_key))
.route("/events", get(events))
.route("/overview", get(overview))
.route("/probe", post(probe))
Expand Down Expand Up @@ -140,6 +141,17 @@ pub fn router(state: ControlState) -> Router {
.with_state(state)
}

/// 生成一把新的网关密钥。**不写进配置** —— 只是给界面一个值去填。
///
/// **在这里生成,不在界面里。**字母表(去掉了 0/O、1/I/l 这些抄错的
/// 字符)和长度是安全相关的决定,而用户要把这串东西读出来、抄进另一个
/// 配置文件。两处各写一份的话,迟早只有一处被改。
async fn new_key() -> Json<tw_api::NewKey> {
Json(tw_api::NewKey {
key: tw_config::generate_key(),
})
}

/// 这台机器上有哪些网卡。
///
/// 不带任何状态 —— 每次现问系统。**网卡是会变的**:插拔网线、连上另一
Expand Down
Loading