From 75751f7a17b1087d2ba549d2b8639557a4c116de Mon Sep 17 00:00:00 2001 From: b1ek Date: Sun, 28 Jul 2024 14:52:03 +1000 Subject: [PATCH] feat: pass additional stuff to views --- src/app.module.ts | 5 ++--- src/views.controller.ts | 18 ----------------- src/views/views.controller.ts | 15 ++++++++++++++ src/views/views.module.ts | 11 +++++++++++ src/views/views.provider.ts | 21 ++++++++++++++++++++ views/index.html | 37 ++++++++++++++++++++++++++++++++--- 6 files changed, 83 insertions(+), 24 deletions(-) delete mode 100644 src/views.controller.ts create mode 100644 src/views/views.controller.ts create mode 100644 src/views/views.module.ts create mode 100644 src/views/views.provider.ts diff --git a/src/app.module.ts b/src/app.module.ts index 229c476..62d9eba 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -1,9 +1,8 @@ import { KeysModule } from './keys/keys.module.js' import { Module } from '@nestjs/common' -import { ViewsController } from './views.controller.js' +import { ViewsModule } from './views/views.module.js' @Module({ - controllers: [ViewsController], - imports: [KeysModule], + imports: [KeysModule, ViewsModule], }) export class AppModule {} diff --git a/src/views.controller.ts b/src/views.controller.ts deleted file mode 100644 index 1e6a0cb..0000000 --- a/src/views.controller.ts +++ /dev/null @@ -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+:\/\//, '') })) - } - } -} diff --git a/src/views/views.controller.ts b/src/views/views.controller.ts new file mode 100644 index 0000000..06c72e7 --- /dev/null +++ b/src/views/views.controller.ts @@ -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) + } +} diff --git a/src/views/views.module.ts b/src/views/views.module.ts new file mode 100644 index 0000000..431636e --- /dev/null +++ b/src/views/views.module.ts @@ -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 {} diff --git a/src/views/views.provider.ts b/src/views/views.provider.ts new file mode 100644 index 0000000..dd8aeec --- /dev/null +++ b/src/views/views.provider.ts @@ -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, + } + } +} diff --git a/views/index.html b/views/index.html index dcedf80..594f688 100644 --- a/views/index.html +++ b/views/index.html @@ -2,23 +2,54 @@ - Cupid GPG server + Cupid GPG keyserver

Cupid

- 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:

point is to reduce situations when one keyserver has a key but another one which you use, doesnt

+

compilance

+

+ this proxy implements some methods from the latest (as of july 2024)  OpenPGP HTTP Keyserver Protocol: +

+ + +

usage

+

+ to set this as your keyserver, add this to  ~/.gnupg/gpg.conf  (create if doesnt exist): +

keyserver {{host}}
+

+

+ to search for  someone@example.com +

curl {{protocol}}://{{host}}/pks/lookup\?search\=someone@example.com\&op\=index
+

+

+ to get key with ID  00000000000000000000000000000000000000000 +

curl {{protocol}}://{{host}}/pks/lookup\?search\=00000000000000000000000000000000000000000\&op\=get
+

+

privacy

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 @@

abuse

- this website does not store keys but in temporary cache. refer to upstream servers for that + this website does not store keys but in temporary cache. refer to  upstream servers  for that

\ No newline at end of file