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)]
|
|
|
|
|
2019-02-22 20:29:53 +00:00
|
|
|
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;
|
2018-10-24 17:45:11 +00:00
|
|
|
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;
|
2018-11-02 10:50:57 +00:00
|
|
|
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
|
|
|
|
2019-02-25 17:34:07 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
extern crate fs_extra;
|
2019-03-04 16:57:36 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
extern crate regex;
|
2019-02-25 17:34:07 +00:00
|
|
|
|
2019-03-05 16:30:56 +00:00
|
|
|
extern crate hagrid_database as database;
|
2018-11-02 10:50:57 +00:00
|
|
|
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(
|
2019-02-25 15:34:15 +00:00
|
|
|
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,
|
2018-11-02 10:50:57 +00:00
|
|
|
/// 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"
|
|
|
|
)]
|
2019-01-09 12:35:47 +00:00
|
|
|
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();
|
|
|
|
}
|