From 9fab01ccae13a3274787c34d3094dc1cc84f3b45 Mon Sep 17 00:00:00 2001 From: Morgana Date: Mon, 26 Oct 2026 13:59:50 -0500 Subject: License under the GNU AGPL v3 --- src/main.rs | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) (limited to 'src/main.rs') 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 + +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 . +*/ + 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; -- cgit v1.3.1