hagrid-keyserver--hagrid/src/main.rs

85 lines
2.0 KiB
Rust
Raw Normal View History

2018-12-25 21:35:04 +00:00
#![feature(proc_macro_hygiene, plugin, decl_macro)]
2018-08-16 18:35:19 +00:00
#![recursion_limit = "1024"]
#![feature(try_from)]
extern crate failure;
use failure::Fallible as Result;
2018-08-16 18:35:19 +00:00
extern crate serde;
2019-02-07 19:58:31 +00:00
#[macro_use]
extern crate serde_derive;
2018-08-16 18:35:19 +00:00
extern crate serde_json;
extern crate time;
extern crate url;
2018-09-19 20:24:38 +00:00
2019-02-07 19:58:31 +00:00
#[macro_use]
extern crate rocket;
2018-08-16 18:35:19 +00:00
extern crate multipart;
2019-02-07 19:58:31 +00:00
extern crate rocket_contrib;
2018-09-19 20:24:38 +00:00
2018-11-25 14:03:27 +00:00
extern crate sequoia_openpgp;
2019-02-07 19:58:31 +00:00
extern crate handlebars;
extern crate lettre;
extern crate lettre_email;
2019-02-07 19:58:31 +00:00
extern crate structopt;
extern crate tempfile;
2018-08-16 18:35:19 +00:00
#[cfg(test)]
extern crate fs_extra;
#[cfg(test)]
extern crate regex;
extern crate hagrid_database as database;
mod mail;
2019-02-07 19:58:31 +00:00
mod web;
2018-08-16 18:35:19 +00:00
use std::path::PathBuf;
use structopt::StructOpt;
#[derive(Debug, StructOpt)]
2019-02-07 19:58:31 +00:00
#[structopt(
name = "hagrid",
about = "Hagrid - The verifying OpenPGP key server."
2019-02-07 19:58:31 +00:00
)]
2018-09-19 20:24:38 +00:00
pub struct Opt {
/// More verbose output. Disabled when running as daemon.
2018-08-16 18:35:19 +00:00
#[structopt(short = "v", long = "verbose")]
2018-09-19 20:24:38 +00:00
verbose: bool,
/// Daemonize after startup.
2018-08-16 18:35:19 +00:00
#[structopt(short = "d", long = "daemon")]
daemon: bool,
/// Base directory
#[structopt(parse(from_os_str))]
base: PathBuf,
2018-09-19 20:24:38 +00:00
/// Port and address to listen on.
#[structopt(short = "l", long = "listen", default_value = "0.0.0.0:8080")]
2018-08-16 18:35:19 +00:00
listen: String,
/// FQDN of the server. Used in templates.
#[structopt(short = "D", long = "domain", default_value = "localhost")]
domain: String,
2019-02-07 19:58:31 +00:00
#[structopt(
short = "F",
long = "from",
default_value = "noreply@localhost"
)]
from: String,
2019-03-01 11:58:17 +00:00
/// Use NGINX'es X-Accel-Redirect feature.
#[structopt(long = "use-x-accel-redirect")]
x_accel_redirect: bool,
2019-02-07 19:58:31 +00:00
}
2018-08-16 18:35:19 +00:00
fn main() {
2018-09-19 20:24:38 +00:00
use database::{Filesystem, Polymorphic};
2018-08-16 18:35:19 +00:00
let opt = Opt::from_args();
2018-09-19 20:24:38 +00:00
println!("{:#?}", opt);
if !opt.base.is_absolute() {
panic!("Base directory must be absolute");
}
2018-08-16 18:35:19 +00:00
2018-09-19 20:24:38 +00:00
let db = Filesystem::new(opt.base.clone()).unwrap();
web::serve(&opt, Polymorphic::Filesystem(db)).unwrap();
}