From cf99c8befff8cd65ac3580e5684b43f40c82a09a Mon Sep 17 00:00:00 2001
From: Face <69168154+face-hh@users.noreply.github.com>
Date: Wed, 20 Aug 2025 15:06:56 +0300
Subject: [PATCH] change html/css to match standard; update docs
---
docs/docs/gurty-cli.md | 128 ++++++++++++++++--
protocol/cli/README.md | 56 +++++++-
.../cli/{gurty.toml => gurty.template.toml} | 4 +-
protocol/cli/src/handlers.rs | 2 +-
protocol/cli/templates/404.html | 25 ++--
.../templates/directory_content_start.html | 2 +-
.../cli/templates/directory_listing_end.html | 1 -
.../templates/directory_listing_start.html | 40 +-----
.../cli/templates/directory_parent_link.html | 2 +-
protocol/cli/templates/error.html | 24 +---
10 files changed, 193 insertions(+), 91 deletions(-)
rename protocol/cli/{gurty.toml => gurty.template.toml} (94%)
diff --git a/docs/docs/gurty-cli.md b/docs/docs/gurty-cli.md
index a97f034..7ec3a2b 100644
--- a/docs/docs/gurty-cli.md
+++ b/docs/docs/gurty-cli.md
@@ -8,14 +8,83 @@ sidebar_position: 5
## Installation
-Build Gurty from the protocol CLI directory:
+To begin, [install Gurty here](https://gurted.com/download).
+
+## Configuration
+
+Gurty supports configuration through TOML files. Use the provided template to get started:
```bash
cd protocol/cli
-cargo build --release
+cp gurty.template.toml gurty.toml
```
-The binary will be available at `target/release/gurty` (or `gurty.exe` on Windows).
+### Configuration File Structure
+
+The configuration file includes the following sections:
+
+#### Server Settings
+```toml
+[server]
+host = "127.0.0.1"
+port = 4878
+protocol_version = "1.0.0"
+alpn_identifier = "GURT/1.0"
+max_connections = 10
+max_message_size = "10MB"
+
+[server.timeouts]
+handshake = 5
+request = 30
+connection = 10
+pool_idle = 300
+```
+
+#### TLS Configuration
+```toml
+[tls]
+certificate = "localhost+2.pem"
+private_key = "localhost+2-key.pem"
+```
+
+#### Logging Options
+```toml
+[logging]
+level = "info"
+log_requests = true
+log_responses = false
+access_log = "/var/log/gurty/access.log"
+error_log = "/var/log/gurty/error.log"
+```
+
+#### Security Settings
+```toml
+[security]
+deny_files = ["*.env", "*.config", ".git/*", "*.key", "*.pem"]
+allowed_methods = ["GET", "POST", "PUT", "DELETE", "HEAD", "OPTIONS", "PATCH"]
+rate_limit_requests = 100
+rate_limit_connections = 1000
+```
+
+#### Error Pages and Headers
+```toml
+# Custom error page files
+[error_pages]
+"404" = "/errors/404.html"
+"500" = "/errors/500.html"
+
+# Default inline error pages
+[error_pages.default]
+"400" = '''
+
400 Bad Request
+400 - Bad Request
The request could not be understood by the server.
'''
+
+# Custom HTTP headers
+[headers]
+server = "GURT/1.0.0"
+"x-frame-options" = "SAMEORIGIN"
+"x-content-type-options" = "nosniff"
+```
## Quick Start
@@ -46,7 +115,18 @@ The binary will be available at `target/release/gurty` (or `gurty.exe` on Window
- `localhost+2.pem` (certificate)
- `localhost+2-key.pem` (private key)
-4. **Start GURT server**:
+4. **Set up configuration** (optional but recommended):
+ ```bash
+ cd protocol/cli
+ cp gurty.template.toml gurty.toml
+ ```
+ Edit `gurty.toml` to customize settings for development.
+
+5. **Start GURT server**:
+ ```bash
+ cargo run --release serve --config gurty.toml
+ ```
+ Or specify certificates explicitly:
```bash
cargo run --release serve --cert localhost+2.pem --key localhost+2-key.pem
```
@@ -68,9 +148,22 @@ The binary will be available at `target/release/gurty` (or `gurty.exe` on Window
openssl req -x509 -newkey rsa:4096 -keyout gurt-server.key -out gurt-server.crt -days 365 -nodes
```
-2. **Deploy with production certificates**:
+2. **Set up configuration**:
```bash
- cargo run --release serve --cert gurt-server.crt --key gurt-server.key --host 0.0.0.0 --port 4878
+ cp gurty.template.toml gurty.toml
+ # Edit gurty.toml for production:
+ # - Update certificate paths
+ # - Set host to "0.0.0.0" for external access
+ # - Configure logging and security settings
+ ```
+
+3. **Deploy with production certificates**:
+ ```bash
+ cargo run --release serve --config gurty.toml
+ ```
+ Or specify certificates explicitly:
+ ```bash
+ cargo run --release serve --cert gurt-server.crt --key gurt-server.key --config gurty.toml
```
## Commands
@@ -87,19 +180,34 @@ gurty serve [OPTIONS]
| Option | Description | Default |
|--------|-------------|---------|
-| `--cert ` | Path to TLS certificate file | Required |
-| `--key ` | Path to TLS private key file | Required |
+| `--cert ` | Path to TLS certificate file | Required* |
+| `--key ` | Path to TLS private key file | Required* |
+| `--config ` | Path to configuration file | None |
| `--host ` | Host address to bind to | `127.0.0.1` |
| `--port ` | Port number to listen on | `4878` |
| `--dir ` | Directory to serve files from | None |
| `--log-level ` | Logging level (error, warn, info, debug, trace) | `info` |
+*Required unless specified in configuration file
+
#### Examples
+**Using configuration file:**
+```bash
+gurty serve --config gurty.toml
+```
+
+**Explicit certificates with configuration:**
+```bash
+gurty serve --cert localhost+2.pem --key localhost+2-key.pem --config gurty.toml
+```
+
+**Manual setup without configuration file:**
```bash
gurty serve --cert localhost+2.pem --key localhost+2-key.pem --dir ./public
```
-Debug:
+
+**Debug mode with configuration:**
```bash
-gurty serve --cert dev.pem --key dev-key.pem --log-level debug
+gurty serve --config gurty.toml --log-level debug
```
diff --git a/protocol/cli/README.md b/protocol/cli/README.md
index 94f0d96..60d23b3 100644
--- a/protocol/cli/README.md
+++ b/protocol/cli/README.md
@@ -1,5 +1,34 @@
# Gurty - a CLI tool to setup your GURT Protocol server
+Gurty is a command-line interface tool for setting up and managing GURT protocol servers.
+
+## Configuration
+
+Gurty uses a TOML configuration file to manage server settings. The `gurty.template.toml` file provides a complete configuration template with all available options:
+
+### Sections
+
+- **Server**: Basic server settings (host, port, protocol version, connection limits)
+- **TLS**: Certificate and private key configuration for secure connections
+- **Logging**: Logging levels, request/response logging, and log file paths
+- **Security**: File access restrictions, allowed HTTP methods, and rate limiting
+- **Error Pages**: Custom error page templates and default error responses
+- **Headers**: Custom HTTP headers for security and server identification
+
+### Using Configuration Files
+
+1. **Copy the configuration template:**
+ ```bash
+ cp gurty.template.toml gurty.toml
+ ```
+
+2. **Edit the configuration** to match your environment. (optional)
+
+3. **Use the configuration file:**
+ ```bash
+ gurty serve --config gurty.toml
+ ```
+
## Setup for Production
For production deployments, you'll need to generate your own certificates since traditional Certificate Authorities don't support custom protocols:
@@ -19,14 +48,24 @@ For production deployments, you'll need to generate your own certificates since
openssl req -x509 -newkey rsa:4096 -keyout gurt-server.key -out gurt-server.crt -days 365 -nodes
```
-2. **Deploy with production certificates:**
+2. **Copy the configuration template and customize:**
```bash
- cargo run --release serve --cert gurt-server.crt --key gurt-server.key --host 0.0.0.0 --port 4878
+ cp gurty.template.toml gurty.toml
+ ```
+
+3. **Deploy with production certificates and configuration:**
+ ```bash
+ gurty serve --config gurty.toml
+ ```
+ Or specify certificates explicitly:
+ ```bash
+ gurty serve --cert gurt-server.crt --key gurt-server.key --config gurty.toml
```
## Development Environment Setup
To set up a development environment for GURT, follow these steps:
+
1. **Install mkcert:**
```bash
# Windows (with Chocolatey)
@@ -50,7 +89,16 @@ To set up a development environment for GURT, follow these steps:
- `localhost+2.pem` (certificate)
- `localhost+2-key.pem` (private key)
-4. **Start GURT server with certificates:**
+4. **Copy the configuration template and customize:**
```bash
- cargo run --release serve --cert localhost+2.pem --key localhost+2-key.pem
+ cp gurty.template.toml gurty.toml
+ ```
+
+5. **Start GURT server with certificates and configuration:**
+ ```bash
+ gurty serve --config gurty.toml
+ ```
+ Or specify certificates explicitly:
+ ```bash
+ gurty serve --cert localhost+2.pem --key localhost+2-key.pem --config gurty.toml
```
\ No newline at end of file
diff --git a/protocol/cli/gurty.toml b/protocol/cli/gurty.template.toml
similarity index 94%
rename from protocol/cli/gurty.toml
rename to protocol/cli/gurty.template.toml
index e9830c6..ae529d0 100644
--- a/protocol/cli/gurty.toml
+++ b/protocol/cli/gurty.template.toml
@@ -13,8 +13,8 @@ connection = 10
pool_idle = 300
[tls]
-certificate = "/path/to/certificate.pem"
-private_key = "/path/to/private_key.pem"
+certificate = "localhost+2.pem"
+private_key = "localhost+2-key.pem"
[logging]
level = "info"
diff --git a/protocol/cli/src/handlers.rs b/protocol/cli/src/handlers.rs
index 9022907..1e244b2 100644
--- a/protocol/cli/src/handlers.rs
+++ b/protocol/cli/src/handlers.rs
@@ -66,7 +66,7 @@ impl DirectoryHandler for DefaultDirectoryHandler {
let class = if is_dir { "dir" } else { "file" };
listing.push_str(&format!(
- r#" {}"#,
+ r#" {}"#,
name, class, display_name
));
listing.push('\n');
diff --git a/protocol/cli/templates/404.html b/protocol/cli/templates/404.html
index 662f80c..7caa7dc 100644
--- a/protocol/cli/templates/404.html
+++ b/protocol/cli/templates/404.html
@@ -3,22 +3,15 @@
404 Not Found
diff --git a/protocol/cli/templates/directory_content_start.html b/protocol/cli/templates/directory_content_start.html
index f1561d5..7892025 100644
--- a/protocol/cli/templates/directory_content_start.html
+++ b/protocol/cli/templates/directory_content_start.html
@@ -1 +1 @@
-
+
diff --git a/protocol/cli/templates/directory_listing_end.html b/protocol/cli/templates/directory_listing_end.html
index 077a466..ce29789 100644
--- a/protocol/cli/templates/directory_listing_end.html
+++ b/protocol/cli/templates/directory_listing_end.html
@@ -1,4 +1,3 @@
-