1
0
Fork 0
mirror of https://gitlab.com/hagrid-keyserver/hagrid.git synced 2023-02-13 20:55:02 -05:00

Move paths around.

Server new accepts
  /
  /vks/{verify,confirm,delete}
  /pks/{add,lookup}
This commit is contained in:
seu 2018-11-02 11:48:02 +01:00
parent b189bcf127
commit 49f15fd5e0
4 changed files with 49 additions and 29 deletions

View file

@ -16,14 +16,31 @@ http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
root dist;
root dist/public;
location ^~ /static/ {
location ^~ /by-email/ {
default_type application/pgp-keys;
try_files /$request_uri =404;
}
location ~ .* {
location ^~ /by-fpr/ {
default_type application/pgp-keys;
try_files /$request_uri =404;
}
location = / {
proxy_pass http://127.0.0.1:8080;
}
location = /keys {
proxy_pass http://127.0.0.1:8080;
}
location ^~ /vks/ {
proxy_pass http://127.0.0.1:8080;
}
location ^~ /pks/ {
proxy_pass http://127.0.0.1:8080;
}
}

View file

@ -47,8 +47,8 @@ impl Filesystem {
create_dir_all(base.join("verification_tokens"))?;
create_dir_all(base.join("deletion_tokens"))?;
create_dir_all(base.join("scratch_pad"))?;
create_dir_all(base.join("static").join("by-fpr"))?;
create_dir_all(base.join("static").join("by-email"))?;
create_dir_all(base.join("public").join("by-fpr"))?;
create_dir_all(base.join("public").join("by-email"))?;
info!("Opened base dir '{}'", base.display());
Ok(Filesystem{
@ -101,7 +101,7 @@ impl Database for Filesystem {
}
fn compare_and_swap(&self, fpr: &Fingerprint, old: Option<&[u8]>, new: Option<&[u8]>) -> Result<bool> {
let target = self.base.join("static").join("by-fpr").join(fpr.to_string());
let target = self.base.join("public").join("by-fpr").join(fpr.to_string());
let dir = self.base.join("scratch_pad");
match new {
@ -129,8 +129,8 @@ impl Database for Filesystem {
fn link_email(&self, email: &Email, fpr: &Fingerprint) {
let email = url::form_urlencoded::byte_serialize(email.to_string().as_bytes()).collect::<String>();
let target = self.base.join("static").join("by-fpr").join(fpr.to_string());
let link = self.base.join("static").join("by-email").join(email);
let target = self.base.join("public").join("by-fpr").join(fpr.to_string());
let link = self.base.join("public").join("by-email").join(email);
if link.exists() {
let _ = remove_file(link.clone());
@ -141,11 +141,11 @@ impl Database for Filesystem {
fn unlink_email(&self, email: &Email, fpr: &Fingerprint) {
let email = url::form_urlencoded::byte_serialize(email.to_string().as_bytes()).collect::<String>();
let link = self.base.join("static").join("by-email").join(email);
let link = self.base.join("public").join("by-email").join(email);
match read_link(link.clone()) {
Ok(target) => {
let expected = self.base.join("static").join("by-fpr").join(fpr.to_string());
let expected = self.base.join("public").join("by-fpr").join(fpr.to_string());
if target == expected {
let _ = remove_file(link);
@ -174,7 +174,7 @@ impl Database for Filesystem {
// XXX: slow
fn by_fpr(&self, fpr: &Fingerprint) -> Option<Box<[u8]>> {
let target = self.base.join("static").join("by-fpr").join(fpr.to_string());
let target = self.base.join("public").join("by-fpr").join(fpr.to_string());
File::open(target).ok().and_then(|mut fd| {
let mut buf = Vec::default();
@ -191,7 +191,7 @@ impl Database for Filesystem {
use std::fs;
let email = url::form_urlencoded::byte_serialize(email.to_string().as_bytes()).collect::<String>();
let path = self.base.join("static").join("by-email").join(email);
let path = self.base.join("public").join("by-email").join(email);
fs::canonicalize(path).ok()
.and_then(|p| {

View file

@ -109,7 +109,7 @@ fn process_key(bytes: &[u8]) -> result::Result<String, Custom<String>> {
}
}
#[get("/static/by-fpr/<fpr>")]
#[get("/by-fpr/<fpr>")]
fn by_fpr(db: rocket::State<Polymorphic>, fpr: String)
-> result::Result<String, Custom<String>>
{
@ -124,7 +124,7 @@ fn by_fpr(db: rocket::State<Polymorphic>, fpr: String)
}
}
#[get("/static/by-email/<email>")]
#[get("/by-email/<email>")]
fn by_email(db: rocket::State<Polymorphic>, email: String)
-> result::Result<String, Custom<String>>
{
@ -139,7 +139,7 @@ fn by_email(db: rocket::State<Polymorphic>, email: String)
}
}
#[get("/verify/<token>")]
#[get("/vks/verify/<token>")]
fn verify(db: rocket::State<Polymorphic>, token: String)
-> result::Result<Template, Custom<String>>
{
@ -191,7 +191,7 @@ fn delete(db: rocket::State<Polymorphic>, fpr: String)
}
}
#[get("/confirm/<token>")]
#[get("/vks/confirm/<token>")]
fn confirm(db: rocket::State<Polymorphic>, token: String)
-> result::Result<Template, Custom<String>>
{
@ -213,19 +213,18 @@ fn confirm(db: rocket::State<Polymorphic>, token: String)
}
}
#[get("/static/<file..>")]
#[get("/assets/<file..>")]
fn files(file: PathBuf, static_dir: State<StaticDir>) -> Option<NamedFile> {
NamedFile::open(Path::new(&static_dir.0).join(file)).ok()
NamedFile::open(Path::new(&static_dir.0).join("assets").join(file)).ok()
}
#[get("/pks/lookup")]
fn hkp(db: rocket::State<Polymorphic>, key: Option<queries::Hkp>)
fn lookup(db: rocket::State<Polymorphic>, key: Option<queries::Hkp>)
-> result::Result<String, Custom<String>>
{
use std::io::Write;
use openpgp::armor::{Writer, Kind};
eprintln!("{:?}", key);
let maybe_key = match key {
Some(queries::Hkp::Fingerprint(ref fpr)) => db.by_fpr(fpr),
Some(queries::Hkp::Email(ref email)) => db.by_email(email),
@ -284,20 +283,24 @@ pub fn serve(opt: &Opt, db: Polymorphic) -> Result<()> {
.address(addr)
.port(port)
.workers(2)
.root(opt.base.join("static"))
.root(opt.base.clone())
.extra("template_dir", format!("{}/templates", opt.base.display()))
.extra("static_dir", format!("{}/public", opt.base.display()))
.finalize()?;
let routes = routes![
upload::multipart_upload,
// infra
root,
files,
// nginx-supported lookup
by_email,
by_fpr,
// HKP
lookup,
upload::multipart_upload,
// verification & deletion
verify,
delete,
confirm,
root,
files,
hkp,
];
rocket::custom(config, opt.verbose)

View file

@ -8,8 +8,8 @@ module.exports = {
entry: './web/index.js',
output: {
filename: 'site.js',
path: path.resolve(__dirname, 'dist', 'public'),
publicPath: '/static'
path: path.resolve(__dirname, 'dist', 'public', 'assets'),
publicPath: '/assets'
},
module: {
rules: [
@ -37,7 +37,7 @@ module.exports = {
},
plugins: [
new html({
filename: '../templates/layout.html.hbs',
filename: '../../templates/layout.html.hbs',
template: 'web/layout.html.hbs',
}),
new text({
@ -45,7 +45,7 @@ module.exports = {
}),
new copy([
{
from: 'web/*.html.hbs',
from: 'web/*.hbs',
to: path.resolve(__dirname, 'dist', "templates"),
ignore: [ 'layout.html.hbs' ],
flatten: true