mirror of
https://gitlab.com/erkanisik/yali-rs.git
synced 2026-07-31 03:09:00 +00:00
feat: add hostname sanitization function and integrate it into user step processing
This commit is contained in:
+20
-1
@@ -77,6 +77,24 @@ fn is_valid_hostname(s: &str) -> bool {
|
|||||||
s.chars().all(|c| c.is_ascii_alphanumeric() || c == '-')
|
s.chars().all(|c| c.is_ascii_alphanumeric() || c == '-')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Otomatik hostname üretirken nokta, boşluk ve geçersiz karakterleri kaldırır.
|
||||||
|
fn sanitize_hostname(s: &str) -> String {
|
||||||
|
let mut hostname: String = s
|
||||||
|
.chars()
|
||||||
|
.filter(|c| c.is_ascii_alphanumeric())
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
if hostname.len() > 63 {
|
||||||
|
hostname.truncate(63);
|
||||||
|
}
|
||||||
|
|
||||||
|
if hostname.is_empty() {
|
||||||
|
"host".to_string()
|
||||||
|
} else {
|
||||||
|
hostname
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn password_strength(p: &str) -> (String, egui::Color32) {
|
fn password_strength(p: &str) -> (String, egui::Color32) {
|
||||||
let len = p.len();
|
let len = p.len();
|
||||||
let has_upper = p.chars().any(|c| c.is_uppercase());
|
let has_upper = p.chars().any(|c| c.is_uppercase());
|
||||||
@@ -112,13 +130,14 @@ impl InstallerStep for UsersStep {
|
|||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.trim()
|
.trim()
|
||||||
.to_string();
|
.to_string();
|
||||||
|
let sys_hostname = sanitize_hostname(&sys_hostname);
|
||||||
if !sys_hostname.is_empty() && sys_hostname != "localhost" {
|
if !sys_hostname.is_empty() && sys_hostname != "localhost" {
|
||||||
state.hostname = sys_hostname;
|
state.hostname = sys_hostname;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Hâlâ boşsa ve username varsa username-pc öner
|
// Hâlâ boşsa ve username varsa username-pc öner
|
||||||
if state.hostname.is_empty() && !state.username.is_empty() {
|
if state.hostname.is_empty() && !state.username.is_empty() {
|
||||||
state.hostname = format!("{}-pc", state.username);
|
state.hostname = sanitize_hostname(&format!("{}pc", state.username));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user