feat: pass additional stuff to views

This commit is contained in:
b1ek 2024-07-28 14:52:03 +10:00
parent b50649b454
commit 75751f7a17
Signed by: blek
GPG Key ID: 14546221E3595D0C
6 changed files with 83 additions and 24 deletions

View File

@ -1,9 +1,8 @@
import { KeysModule } from './keys/keys.module.js' import { KeysModule } from './keys/keys.module.js'
import { Module } from '@nestjs/common' import { Module } from '@nestjs/common'
import { ViewsController } from './views.controller.js' import { ViewsModule } from './views/views.module.js'
@Module({ @Module({
controllers: [ViewsController], imports: [KeysModule, ViewsModule],
imports: [KeysModule],
}) })
export class AppModule {} export class AppModule {}

View File

@ -1,18 +0,0 @@
import { Controller, Get, Render } from '@nestjs/common'
import { AllKeysProvider } from './keys/providers/all.provider.js'
@Controller()
export class ViewsController {
constructor(private allKeysProvider: AllKeysProvider) {}
@Get()
@Render('index.html')
index() {
return {
keys: this.allKeysProvider.getAll()
.map(x => x.url)
.map(x => ({ url: x, domain: x.replace(/^\S+:\/\//, '') }))
}
}
}

View File

@ -0,0 +1,15 @@
import { Controller, Get, Render, Req } from '@nestjs/common'
import type { FastifyRequest } from 'fastify'
import { ViewsProvider } from './views.provider.js'
@Controller()
export class ViewsController {
constructor(private viewsProvider: ViewsProvider) {}
@Get()
@Render('index.html')
index(@Req() req: FastifyRequest) {
return this.viewsProvider.getData(req)
}
}

11
src/views/views.module.ts Normal file
View File

@ -0,0 +1,11 @@
import { Module } from '@nestjs/common'
import { ViewsController } from './views.controller.js'
import { ViewsProvider } from './views.provider.js'
import { KeysModule } from 'src/keys/keys.module.js'
@Module({
controllers: [ViewsController],
providers: [ViewsProvider],
imports: [KeysModule],
})
export class ViewsModule {}

View File

@ -0,0 +1,21 @@
import { Get, Injectable, Req } from '@nestjs/common'
import type { FastifyRequest } from 'fastify'
import { AllKeysProvider } from 'src/keys/providers/all.provider.js'
@Injectable({})
export class ViewsProvider {
constructor(private allKeysProvider: AllKeysProvider) {}
@Get()
getData(@Req() req: FastifyRequest) {
return {
keys: this.allKeysProvider
.getAll()
.map((x) => x.url)
.map((x) => ({ url: x, domain: x.replace(/^\S+:\/\//, '') })),
host: req.hostname,
protocol: req.protocol,
}
}
}

View File

@ -2,23 +2,54 @@
<html> <html>
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>Cupid GPG server</title> <title>Cupid GPG keyserver</title>
</head> </head>
<body> <body>
<h1>Cupid</h1> <h1>Cupid</h1>
<p> <p>
this is a GPG keyserver that serves keys from all the following servers combined: this is a GPG keyserver proxy that serves keys from all the following servers combined:
</p> </p>
<ul id="keyservers"> <ul id="keyservers">
{{#each keys}} {{#each keys}}
<li><a href="{{ url }}">{{ domain }}</a></li> <li><a href="{{ url }}">{{ domain }}</a></li>
{{/each}} {{/each}}
<li>this list is dynamic - it differs with different Cupid versions that implement different keyservers</li>
</ul> </ul>
<p> <p>
point is to reduce situations when one keyserver has a key but another one which you use, doesnt point is to reduce situations when one keyserver has a key but another one which you use, doesnt
</p> </p>
<h2>compilance</h2>
<p>
this proxy implements some methods from the latest (as of july 2024) &nbsp;<a target='_blank' href='https://www.ietf.org/archive/id/draft-gallagher-openpgp-hkp-05.html'>OpenPGP HTTP Keyserver Protocol</a>:
</p>
<ul>
<li>
<a href="https://www.ietf.org/archive/id/draft-gallagher-openpgp-hkp-05.html#name-legacy-request-format">Legacy request format</a>
</li>
<li>
<a href="https://www.ietf.org/archive/id/draft-gallagher-openpgp-hkp-05.html#name-the-get-operation">"get" operation</a>
</li>
<li>
<a href="https://www.ietf.org/archive/id/draft-gallagher-openpgp-hkp-05.html#name-the-index-operation">"index" operation</a>
</li>
</ul>
<h2>usage</h2>
<p>
to set this as your keyserver, add this to &nbsp;<code>~/.gnupg/gpg.conf</code>&nbsp; (create if doesnt exist):
<pre>keyserver {{host}}</pre>
</p>
<p>
to search for &nbsp;<code>someone@example.com</code>
<pre>curl {{protocol}}://{{host}}/pks/lookup\?search\=someone@example.com\&op\=index</pre>
</p>
<p>
to get key with ID &nbsp;<code>00000000000000000000000000000000000000000</code>
<pre>curl {{protocol}}://{{host}}/pks/lookup\?search\=00000000000000000000000000000000000000000\&op\=get</pre>
</p>
<h2>privacy</h2> <h2>privacy</h2>
<p> <p>
your requests are fairly private as nothing but your IP is exposed to keyservers to circumvent DoS attacks via this service. you can use an http proxy if that concerns you your requests are fairly private as nothing but your IP is exposed to keyservers to circumvent DoS attacks via this service. you can use an http proxy if that concerns you
@ -26,7 +57,7 @@
<h2>abuse</h2> <h2>abuse</h2>
<p> <p>
this website does not store keys but in temporary cache. refer to&nbsp;<a href='#keyservers'>upstream servers</a>&nbsp;for that this website does not store keys but in temporary cache. refer to &nbsp;<a href='#keyservers'>upstream servers</a> &nbsp;for that
</p> </p>
</body> </body>
</html> </html>