summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs36
1 files changed, 29 insertions, 7 deletions
diff --git a/src/main.rs b/src/main.rs
index b25cc07..eed9ca6 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,16 +1,36 @@
+/*
+MORGEMRS :: Morgana's Gemini Rust Server
+Copyright (C) 2026 Morgana <morgana@icolotl.com>
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU Affero General Public License as
+published by the Free Software Foundation, either version 3 of the
+License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Affero General Public License for more details.
+
+You should have received a copy of the GNU Affero General Public License
+along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
use std::fs::{self, DirEntry};
-use std::io::Write;
-use std::net::TcpStream;
+use std::io::{Read, Write};
+use std::net::{Ipv4Addr, TcpListener, TcpStream};
use std::path::{Path, PathBuf};
use std::sync::Arc;
-use std::{io::Read, net::TcpListener};
-use rustls::ServerConnection;
use rustls::{
- ServerConfig, Stream,
+ ServerConfig, ServerConnection, Stream,
pki_types::{CertificateDer, PrivateKeyDer, pem::PemObject},
};
+// Change this to the proper domain and IP as required
+const HOST: Ipv4Addr = Ipv4Addr::new(127, 0, 0, 1);
+const PREFIX: &str = "gemini://localhost";
+
fn main() {
println!("Starting MorGemRS Server...");
@@ -31,7 +51,7 @@ fn main() {
);
// Begin listening for connections
- let listener = TcpListener::bind("127.0.0.1:1965").unwrap();
+ let listener = TcpListener::bind((HOST, 1965)).unwrap();
println!("Successfully Started!");
for mut tcp_stream in listener.incoming().flatten() {
// Connect with TLS
@@ -62,7 +82,7 @@ fn main() {
// Reject proxy requests
let Some(mut uri) = raw_uri
.trim_end_matches(|c: char| c == char::from(0) || c.is_whitespace())
- .strip_prefix("gemini://localhost")
+ .strip_prefix(PREFIX)
else {
let _ = writeln!(tls_stream, "53 Proxy Not Supported\r\n");
continue;
@@ -70,6 +90,8 @@ fn main() {
// Clean up URI
uri = uri.trim_matches('/');
+
+ // Ensure file exists and remove intermediate uri components
let Ok(path) = root.join(uri).canonicalize() else {
let _ = writeln!(tls_stream, "51 Not Found\r\n");
continue;