Added init script. Cleaned up imports
This commit is contained in:
11
Cargo.toml
11
Cargo.toml
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "gemserv"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
authors = ["int 80h <int@80h.dev>"]
|
||||
edition = "2018"
|
||||
|
||||
@@ -11,11 +11,10 @@ tokio = { version = "0.2", features = [ "net", "io-util", "rt-threaded" ] }
|
||||
openssl = "0.10"
|
||||
tokio-openssl = "0.4"
|
||||
futures-util = "0.3"
|
||||
toml = "*"
|
||||
serde = "*"
|
||||
serde_derive = "*"
|
||||
url = "*"
|
||||
chrono = "0.4"
|
||||
toml = "0.5"
|
||||
serde = "1"
|
||||
serde_derive = "1"
|
||||
url = "2"
|
||||
mime_guess = "2.0.3"
|
||||
mime = "0.3.16"
|
||||
log = "0.4"
|
||||
|
||||
1
README
1
README
@@ -23,6 +23,7 @@ A gemini server written in rust.
|
||||
- GEMINI_URL
|
||||
- SERVER_NAME
|
||||
- SERVER_PROTOCOL
|
||||
- SERVER_SOFTWARE
|
||||
- SCRIPT_NAME
|
||||
- REMOTE_ADDR
|
||||
- REMOTE_HOST
|
||||
|
||||
14
init-scripts/gemserv.service
Normal file
14
init-scripts/gemserv.service
Normal file
@@ -0,0 +1,14 @@
|
||||
[Unit]
|
||||
Description=gemserv
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
Restart=always
|
||||
RestartSec=5
|
||||
User=gemini
|
||||
ExecStart=/path/to/bin /path/to/config
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
10
src/cgi.rs
10
src/cgi.rs
@@ -1,19 +1,16 @@
|
||||
use std::collections::HashMap;
|
||||
use std::io::{self, BufReader};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::io;
|
||||
use std::path::{PathBuf};
|
||||
use std::process::Command;
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
use tokio::net::TcpStream;
|
||||
use tokio_openssl::SslStream;
|
||||
use url::Url;
|
||||
|
||||
use crate::config;
|
||||
use crate::status::Status;
|
||||
use crate::conn;
|
||||
use crate::logger;
|
||||
|
||||
pub async fn cgi(mut con: conn::Connection, path: PathBuf, url: Url) -> Result<(), io::Error> {
|
||||
let mut envs = HashMap::new();
|
||||
envs.insert("GATEWAY_INTERFACE", "CGI/1.1");
|
||||
envs.insert("GEMINI_URL", url.as_str());
|
||||
envs.insert("SERVER_NAME", url.host_str().unwrap());
|
||||
envs.insert("SCRIPT_NAME", path.file_name().unwrap().to_str().unwrap());
|
||||
@@ -23,6 +20,7 @@ pub async fn cgi(mut con: conn::Connection, path: PathBuf, url: Url) -> Result<(
|
||||
envs.insert("REMOTE_HOST", &addr);
|
||||
let port = con.peer_addr.port().to_string();
|
||||
envs.insert("REMOTE_PORT", &port);
|
||||
envs.insert("SERVER_SOFTWARE", env!("CARGO_PKG_NAME"));
|
||||
|
||||
if let Some(q) = url.query() {
|
||||
envs.insert("QUERY_STRING", q);
|
||||
|
||||
@@ -2,7 +2,6 @@ extern crate serde_derive;
|
||||
extern crate toml;
|
||||
use std::collections::HashMap;
|
||||
use toml::de::Error;
|
||||
use std::io;
|
||||
use std::path::Path;
|
||||
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use std::net::SocketAddr;
|
||||
use log::{info, warn};
|
||||
use crate::conn;
|
||||
use crate::status;
|
||||
|
||||
pub fn logger(addr: SocketAddr, stat: status::Status, req: &str) {
|
||||
|
||||
12
src/main.rs
12
src/main.rs
@@ -1,34 +1,22 @@
|
||||
#![allow(unused_imports)]
|
||||
#![allow(dead_code)]
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
use futures_util::future::TryFutureExt;
|
||||
use std::collections::HashMap;
|
||||
use std::error::Error;
|
||||
use std::fs;
|
||||
use std::fs::File;
|
||||
use std::io::{self, BufReader, BufRead};
|
||||
use std::io::prelude::*;
|
||||
use std::net::SocketAddr;
|
||||
use std::net::ToSocketAddrs;
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
use std::sync::Arc;
|
||||
use std::env;
|
||||
use tokio::io::AsyncWriteExt;
|
||||
use tokio::net::TcpListener;
|
||||
use tokio::net::TcpStream;
|
||||
use tokio::prelude::*;
|
||||
use tokio::runtime;
|
||||
use tokio_openssl::SslStream;
|
||||
use openssl::ssl::NameType;
|
||||
use url::Url;
|
||||
use chrono::{DateTime, Utc};
|
||||
use mime_guess;
|
||||
use mime;
|
||||
use log::{info, warn};
|
||||
|
||||
mod cgi;
|
||||
mod config;
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
use futures_util::future;
|
||||
use std::fs::File;
|
||||
use std::io;
|
||||
use std::io::Read;
|
||||
use std::io::BufReader;
|
||||
use std::net::ToSocketAddrs;
|
||||
use std::sync::Arc;
|
||||
use tokio::io::{copy, split, AsyncReadExt, AsyncWriteExt};
|
||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||
use tokio::net::TcpStream;
|
||||
use openssl::ssl::{SslConnector, SslMethod};
|
||||
use url::Url;
|
||||
|
||||
use crate::conn;
|
||||
use crate::status::Status;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use std::fmt;
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[repr(u8)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub enum Status {
|
||||
|
||||
@@ -1,18 +1,13 @@
|
||||
extern crate openssl;
|
||||
extern crate tokio_openssl;
|
||||
use std::collections::HashMap;
|
||||
use std::fs::File;
|
||||
use std::io::{self, BufReader};
|
||||
use std::sync::Arc;
|
||||
|
||||
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
|
||||
use openssl::ssl::SslAcceptorBuilder;
|
||||
use openssl::ssl::SniError;
|
||||
use openssl::error::ErrorStack;
|
||||
use openssl::ssl::SslContextBuilder;
|
||||
use openssl::ssl::SslVersion;
|
||||
use openssl::ssl::NameType;
|
||||
use tokio_openssl::SslStream;
|
||||
|
||||
use crate::config;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user