feat(core): allow setting server hostname

This commit is contained in:
Aiden McClelland
2026-02-23 13:35:34 -07:00
parent 31352a72c3
commit 0724989792
11 changed files with 202 additions and 82 deletions

View File

@@ -31,6 +31,7 @@ use crate::disk::mount::filesystem::ReadWrite;
use crate::disk::mount::filesystem::cifs::Cifs;
use crate::disk::mount::guard::{GenericMountGuard, TmpMountGuard};
use crate::disk::util::{DiskInfo, StartOsRecoveryInfo, pvscan, recovery_info};
use crate::hostname::Hostname;
use crate::init::{InitPhases, InitResult, init};
use crate::net::ssl::root_ca_start_time;
use crate::prelude::*;
@@ -115,6 +116,7 @@ async fn setup_init(
ctx: &SetupContext,
password: Option<String>,
kiosk: Option<bool>,
hostname: Option<InternedString>,
init_phases: InitPhases,
) -> Result<(AccountInfo, InitResult), Error> {
let init_result = init(&ctx.webserver, &ctx.config.peek(|c| c.clone()), init_phases).await?;
@@ -129,6 +131,9 @@ async fn setup_init(
if let Some(password) = &password {
account.set_password(password)?;
}
if let Some(hostname) = hostname {
account.hostname = Hostname::validate(hostname)?;
}
account.save(m)?;
let info = m.as_public_mut().as_server_info_mut();
info.as_password_hash_mut().ser(&account.password)?;
@@ -171,6 +176,7 @@ pub struct AttachParams {
pub guid: InternedString,
#[ts(optional)]
pub kiosk: Option<bool>,
pub hostname: Option<InternedString>,
}
#[instrument(skip_all)]
@@ -180,6 +186,7 @@ pub async fn attach(
password,
guid: disk_guid,
kiosk,
hostname,
}: AttachParams,
) -> Result<SetupProgress, Error> {
let setup_ctx = ctx.clone();
@@ -233,7 +240,14 @@ pub async fn attach(
}
disk_phase.complete();
let (account, net_ctrl) = setup_init(&setup_ctx, password, kiosk, init_phases).await?;
let (account, net_ctrl) = setup_init(
&setup_ctx,
password,
kiosk,
hostname.filter(|h| !h.is_empty()),
init_phases,
)
.await?;
let rpc_ctx = RpcContext::init(
&setup_ctx.webserver,
@@ -406,6 +420,7 @@ pub struct SetupExecuteParams {
recovery_source: Option<RecoverySource<EncryptedWire>>,
#[ts(optional)]
kiosk: Option<bool>,
hostname: Option<InternedString>,
}
// #[command(rpc_only)]
@@ -416,6 +431,7 @@ pub async fn execute(
password,
recovery_source,
kiosk,
hostname,
}: SetupExecuteParams,
) -> Result<SetupProgress, Error> {
let password = match password.decrypt(&ctx) {
@@ -447,7 +463,16 @@ pub async fn execute(
};
let setup_ctx = ctx.clone();
ctx.run_setup(move || execute_inner(setup_ctx, guid, password, recovery, kiosk))?;
ctx.run_setup(move || {
execute_inner(
setup_ctx,
guid,
password,
recovery,
kiosk,
hostname.filter(|h| !h.is_empty()),
)
})?;
Ok(ctx.progress().await)
}
@@ -536,6 +561,7 @@ pub async fn execute_inner(
password: String,
recovery_source: Option<RecoverySource<String>>,
kiosk: Option<bool>,
hostname: Option<InternedString>,
) -> Result<(SetupResult, RpcContext), Error> {
let progress = &ctx.progress;
let restore_phase = match recovery_source.as_ref() {
@@ -570,14 +596,15 @@ pub async fn execute_inner(
server_id,
recovery_password,
kiosk,
hostname,
progress,
)
.await
}
Some(RecoverySource::Migrate { guid: old_guid }) => {
migrate(&ctx, guid, &old_guid, password, kiosk, progress).await
migrate(&ctx, guid, &old_guid, password, kiosk, hostname, progress).await
}
None => fresh_setup(&ctx, guid, &password, kiosk, progress).await,
None => fresh_setup(&ctx, guid, &password, kiosk, hostname, progress).await,
}
}
@@ -592,13 +619,14 @@ async fn fresh_setup(
guid: InternedString,
password: &str,
kiosk: Option<bool>,
hostname: Option<InternedString>,
SetupExecuteProgress {
init_phases,
rpc_ctx_phases,
..
}: SetupExecuteProgress,
) -> Result<(SetupResult, RpcContext), Error> {
let account = AccountInfo::new(password, root_ca_start_time().await)?;
let account = AccountInfo::new(password, root_ca_start_time().await, hostname)?;
let db = ctx.db().await?;
let kiosk = Some(kiosk.unwrap_or(true)).filter(|_| &*PLATFORM != "raspberrypi");
sync_kiosk(kiosk).await?;
@@ -652,6 +680,7 @@ async fn recover(
server_id: String,
recovery_password: String,
kiosk: Option<bool>,
hostname: Option<InternedString>,
progress: SetupExecuteProgress,
) -> Result<(SetupResult, RpcContext), Error> {
let recovery_source = TmpMountGuard::mount(&recovery_source, ReadWrite).await?;
@@ -663,6 +692,7 @@ async fn recover(
&server_id,
&recovery_password,
kiosk,
hostname,
progress,
)
.await
@@ -675,6 +705,7 @@ async fn migrate(
old_guid: &str,
password: String,
kiosk: Option<bool>,
hostname: Option<InternedString>,
SetupExecuteProgress {
init_phases,
restore_phase,
@@ -753,7 +784,8 @@ async fn migrate(
crate::disk::main::export(&old_guid, "/media/startos/migrate").await?;
restore_phase.complete();
let (account, net_ctrl) = setup_init(&ctx, Some(password), kiosk, init_phases).await?;
let (account, net_ctrl) =
setup_init(&ctx, Some(password), kiosk, hostname, init_phases).await?;
let rpc_ctx = RpcContext::init(
&ctx.webserver,