docs, gurt:// <a> url

This commit is contained in:
Face
2025-08-15 13:52:01 +03:00
parent c117e602fe
commit 5dae5a4868
25 changed files with 1640 additions and 390 deletions

View File

@@ -299,6 +299,16 @@ dependencies = [
"windows-sys 0.59.0",
]
[[package]]
name = "core-foundation"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2a6cd9ae233e7f62ba4e9353e81a88df7fc8a5987b8d445b4d90c879bd156f6"
dependencies = [
"core-foundation-sys",
"libc",
]
[[package]]
name = "core-foundation-sys"
version = "0.8.7"
@@ -395,6 +405,7 @@ dependencies = [
"base64",
"chrono",
"rustls",
"rustls-native-certs",
"rustls-pemfile",
"serde",
"serde_json",
@@ -772,6 +783,12 @@ version = "1.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad"
[[package]]
name = "openssl-probe"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e"
[[package]]
name = "overload"
version = "0.1.1"
@@ -948,6 +965,18 @@ dependencies = [
"zeroize",
]
[[package]]
name = "rustls-native-certs"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fcff2dd52b58a8d98a70243663a0d234c4e2b79235637849d15913394a247d3"
dependencies = [
"openssl-probe",
"rustls-pki-types",
"schannel",
"security-framework",
]
[[package]]
name = "rustls-pemfile"
version = "2.2.0"
@@ -990,12 +1019,44 @@ version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
[[package]]
name = "schannel"
version = "0.1.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f29ebaa345f945cec9fbbc532eb307f0fdad8161f281b6369539c8d84876b3d"
dependencies = [
"windows-sys 0.59.0",
]
[[package]]
name = "scopeguard"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "security-framework"
version = "3.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80fb1d92c5028aa318b4b8bd7302a5bfcf48be96a37fc6fc790f806b0004ee0c"
dependencies = [
"bitflags",
"core-foundation",
"core-foundation-sys",
"libc",
"security-framework-sys",
]
[[package]]
name = "security-framework-sys"
version = "2.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49db231d56a190491cb4aeda9527f1ad45345af50b0851622a7adb8c03b01c32"
dependencies = [
"core-foundation-sys",
"libc",
]
[[package]]
name = "serde"
version = "1.0.219"

View File

@@ -95,11 +95,10 @@ fn create_file_server(base_dir: PathBuf, cert_path: Option<PathBuf>, key_path: O
let server = server
.get("/", {
let base_dir = base_dir.clone();
move |ctx| {
let client_ip = ctx.client_ip();
move |_| {
let base_dir = base_dir.clone();
async move {
// Try to serve index.html if it exists, otherwise show server info
// Try to serve index.html if it exists
let index_path = base_dir.join("index.html");
if index_path.exists() && index_path.is_file() {
@@ -110,36 +109,54 @@ fn create_file_server(base_dir: PathBuf, cert_path: Option<PathBuf>, key_path: O
.with_string_body(content));
}
Err(_) => {
// Fall through to default page
// Fall through to directory listing
}
}
}
// Default server info page
Ok(GurtResponse::ok()
.with_header("Content-Type", "text/html")
.with_string_body(format!(r#"
// No index.html found, show directory listing
match std::fs::read_dir(base_dir.as_ref()) {
Ok(entries) => {
let mut listing = String::from(r#"
<!DOCTYPE html>
<html>
<head>
<title>GURT Protocol Server</title>
<title>Directory Listing</title>
<style>
body {{ font-sans m-[30px] bg-[#f5f5f5] }}
.header {{ text-[#0066cc] }}
.status {{ text-[#28a745] font-bold }}
body { font-sans m-[40px] }
.dir { font-bold text-[#0066cc] }
</style>
</head>
<body>
<h1 class="header">Welcome to the GURT Protocol!</h1>
<p class="status">This server is successfully running. We couldn't find index.html though :(</p>
<p>Protocol: <strong>GURT/{}</strong></p>
<p>Client IP: <strong>{}</strong></p>
</body>
</html>
"#,
gurt::GURT_VERSION,
client_ip,
)))
<h1>Directory Listing</h1>
<div style="flex flex-col gap-2">
"#);
for entry in entries.flatten() {
let file_name = entry.file_name();
let name = file_name.to_string_lossy();
let is_dir = entry.path().is_dir();
let display_name = if is_dir { format!("{}/", name) } else { name.to_string() };
let class = if is_dir { "style=\"dir\"" } else { "" };
listing.push_str(&format!(
r#" <a {} href="/{}">{}</a>"#,
class, name, display_name
));
listing.push('\n');
}
listing.push_str("</div></body>\n</html>");
Ok(GurtResponse::ok()
.with_header("Content-Type", "text/html")
.with_string_body(listing))
}
Err(_) => {
Ok(GurtResponse::internal_server_error()
.with_header("Content-Type", "text/plain")
.with_string_body("Failed to read directory"))
}
}
}
}
})
@@ -214,7 +231,6 @@ fn create_file_server(base_dir: PathBuf, cert_path: Option<PathBuf>, key_path: O
<title>Directory Listing</title>
<style>
body { font-sans m-[40px] }
.file { my-1 }
.dir { font-bold text-[#0066cc] }
</style>
</head>
@@ -228,10 +244,10 @@ fn create_file_server(base_dir: PathBuf, cert_path: Option<PathBuf>, key_path: O
let name = file_name.to_string_lossy();
let is_dir = entry.path().is_dir();
let display_name = if is_dir { format!("{}/", name) } else { name.to_string() };
let class = if is_dir { "file dir" } else { "file" };
let class = if is_dir { "style=\"dir\"" } else { "" };
listing.push_str(&format!(
r#" <a style={} href="/{}">{}</a>"#,
r#" <a {} href="{}">{}</a>"#,
class, name, display_name
));
listing.push('\n');