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; include /etc/nginx/mime.types;
default_type application/octet-stream; default_type application/octet-stream;
root dist; root dist/public;
location ^~ /static/ { location ^~ /by-email/ {
default_type application/pgp-keys; default_type application/pgp-keys;
try_files /$request_uri =404; 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; 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("verification_tokens"))?;
create_dir_all(base.join("deletion_tokens"))?; create_dir_all(base.join("deletion_tokens"))?;
create_dir_all(base.join("scratch_pad"))?; create_dir_all(base.join("scratch_pad"))?;
create_dir_all(base.join("static").join("by-fpr"))?; create_dir_all(base.join("public").join("by-fpr"))?;
create_dir_all(base.join("static").join("by-email"))?; create_dir_all(base.join("public").join("by-email"))?;
info!("Opened base dir '{}'", base.display()); info!("Opened base dir '{}'", base.display());
Ok(Filesystem{ 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> { 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"); let dir = self.base.join("scratch_pad");
match new { match new {
@ -129,8 +129,8 @@ impl Database for Filesystem {
fn link_email(&self, email: &Email, fpr: &Fingerprint) { fn link_email(&self, email: &Email, fpr: &Fingerprint) {
let email = url::form_urlencoded::byte_serialize(email.to_string().as_bytes()).collect::<String>(); 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 target = self.base.join("public").join("by-fpr").join(fpr.to_string());
let link = self.base.join("static").join("by-email").join(email); let link = self.base.join("public").join("by-email").join(email);
if link.exists() { if link.exists() {
let _ = remove_file(link.clone()); let _ = remove_file(link.clone());
@ -141,11 +141,11 @@ impl Database for Filesystem {
fn unlink_email(&self, email: &Email, fpr: &Fingerprint) { fn unlink_email(&self, email: &Email, fpr: &Fingerprint) {
let email = url::form_urlencoded::byte_serialize(email.to_string().as_bytes()).collect::<String>(); 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()) { match read_link(link.clone()) {
Ok(target) => { 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 { if target == expected {
let _ = remove_file(link); let _ = remove_file(link);
@ -174,7 +174,7 @@ impl Database for Filesystem {
// XXX: slow // XXX: slow
fn by_fpr(&self, fpr: &Fingerprint) -> Option<Box<[u8]>> { 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| { File::open(target).ok().and_then(|mut fd| {
let mut buf = Vec::default(); let mut buf = Vec::default();
@ -191,7 +191,7 @@ impl Database for Filesystem {
use std::fs; use std::fs;
let email = url::form_urlencoded::byte_serialize(email.to_string().as_bytes()).collect::<String>(); 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() fs::canonicalize(path).ok()
.and_then(|p| { .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) fn by_fpr(db: rocket::State<Polymorphic>, fpr: String)
-> result::Result<String, Custom<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) fn by_email(db: rocket::State<Polymorphic>, email: String)
-> result::Result<String, Custom<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) fn verify(db: rocket::State<Polymorphic>, token: String)
-> result::Result<Template, Custom<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) fn confirm(db: rocket::State<Polymorphic>, token: String)
-> result::Result<Template, Custom<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> { 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")] #[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>> -> result::Result<String, Custom<String>>
{ {
use std::io::Write; use std::io::Write;
use openpgp::armor::{Writer, Kind}; use openpgp::armor::{Writer, Kind};
eprintln!("{:?}", key);
let maybe_key = match key { let maybe_key = match key {
Some(queries::Hkp::Fingerprint(ref fpr)) => db.by_fpr(fpr), Some(queries::Hkp::Fingerprint(ref fpr)) => db.by_fpr(fpr),
Some(queries::Hkp::Email(ref email)) => db.by_email(email), Some(queries::Hkp::Email(ref email)) => db.by_email(email),
@ -284,20 +283,24 @@ pub fn serve(opt: &Opt, db: Polymorphic) -> Result<()> {
.address(addr) .address(addr)
.port(port) .port(port)
.workers(2) .workers(2)
.root(opt.base.join("static")) .root(opt.base.clone())
.extra("template_dir", format!("{}/templates", opt.base.display())) .extra("template_dir", format!("{}/templates", opt.base.display()))
.extra("static_dir", format!("{}/public", opt.base.display())) .extra("static_dir", format!("{}/public", opt.base.display()))
.finalize()?; .finalize()?;
let routes = routes![ let routes = routes![
upload::multipart_upload, // infra
root,
files,
// nginx-supported lookup
by_email, by_email,
by_fpr, by_fpr,
// HKP
lookup,
upload::multipart_upload,
// verification & deletion
verify, verify,
delete, delete,
confirm, confirm,
root,
files,
hkp,
]; ];
rocket::custom(config, opt.verbose) rocket::custom(config, opt.verbose)

View File

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