Testing
This commit is contained in:
parent
bd6c14c8c1
commit
d33b24318a
@ -622,70 +622,42 @@ impl ServiceCollector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn get_nginx_sites(&self) -> Option<Vec<String>> {
|
async fn get_nginx_sites(&self) -> Option<Vec<String>> {
|
||||||
// Check enabled sites in sites-enabled directory
|
// For NixOS and other systems, get the actual running nginx config
|
||||||
let sites_enabled_dir = "/etc/nginx/sites-enabled";
|
let output = Command::new("nginx")
|
||||||
|
.args(["-T"])
|
||||||
let mut entries = match fs::read_dir(sites_enabled_dir).await {
|
.stdout(Stdio::piped())
|
||||||
Ok(entries) => entries,
|
.stderr(Stdio::piped())
|
||||||
Err(_) => return None,
|
.output()
|
||||||
};
|
.await
|
||||||
|
.ok()?;
|
||||||
|
|
||||||
|
if !output.status.success() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
let config = String::from_utf8_lossy(&output.stdout);
|
||||||
let mut sites = Vec::new();
|
let mut sites = Vec::new();
|
||||||
|
|
||||||
while let Ok(Some(entry)) = entries.next_entry().await {
|
for line in config.lines() {
|
||||||
let path = entry.path();
|
let trimmed = line.trim();
|
||||||
|
if trimmed.starts_with("server_name") {
|
||||||
// Skip if it's not a file or is a symlink to default
|
// Extract server names from "server_name example.com www.example.com;"
|
||||||
if !path.is_file() {
|
if let Some(names_part) = trimmed.strip_prefix("server_name") {
|
||||||
continue;
|
let names_clean = names_part.trim().trim_end_matches(';');
|
||||||
}
|
for name in names_clean.split_whitespace() {
|
||||||
|
// Skip default catch-all server names
|
||||||
let filename = path.file_name()?.to_string_lossy();
|
if name != "_" && !name.is_empty() && name.contains('.') && !name.starts_with('$') {
|
||||||
|
sites.push(name.to_string());
|
||||||
// Skip default site unless it's the only one
|
|
||||||
if filename == "default" {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try to extract server names from the config file
|
|
||||||
if let Ok(config_content) = fs::read_to_string(&path).await {
|
|
||||||
let mut server_names = Vec::new();
|
|
||||||
|
|
||||||
for line in config_content.lines() {
|
|
||||||
let trimmed = line.trim();
|
|
||||||
if trimmed.starts_with("server_name") {
|
|
||||||
// Extract server names from "server_name example.com www.example.com;"
|
|
||||||
if let Some(names_part) = trimmed.strip_prefix("server_name") {
|
|
||||||
let names_clean = names_part.trim().trim_end_matches(';');
|
|
||||||
for name in names_clean.split_whitespace() {
|
|
||||||
if name != "_" && !name.is_empty() {
|
|
||||||
server_names.push(name.to_string());
|
|
||||||
break; // Only take the first valid server name
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !server_names.is_empty() {
|
|
||||||
sites.push(server_names[0].clone());
|
|
||||||
} else {
|
|
||||||
// Fallback to filename if no server_name found
|
|
||||||
sites.push(filename.to_string());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Fallback to filename if can't read config
|
|
||||||
sites.push(filename.to_string());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no sites found, check for default
|
// Remove duplicates and limit to reasonable number
|
||||||
if sites.is_empty() {
|
sites.sort();
|
||||||
let default_path = format!("{}/default", sites_enabled_dir);
|
sites.dedup();
|
||||||
if fs::metadata(&default_path).await.is_ok() {
|
sites.truncate(15); // Show max 15 sites to avoid overwhelming the UI
|
||||||
sites.push("default".to_string());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if sites.is_empty() {
|
if sites.is_empty() {
|
||||||
None
|
None
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user