~chee/partyfingerd

1dad1b6039b62aab7a5f5861dd5dfc72b61ef427 — chee a month ago 9da59c6 main
add rejection for finger forwarding
2 files changed, 13 insertions(+), 12 deletions(-)

M fingerd.ts
M install
M fingerd.ts => fingerd.ts +12 -12
@@ 4,9 4,7 @@ const listener = Deno.listen({ port: 79 })
const encoder = new TextEncoder()
const decoder = new TextDecoder()
const heart = Uint8Array.from([0x3c, 0x33])
const dashes = "\n" + "*".repeat(72) + "\n\n"
const welcome = encoder.encode(dashes)
const goodbye = encoder.encode(dashes + "see more at https://chee.party/")
const denial = encoder.encode("Finger forwarding service denied")

async function getLatestPost(post: string): Promise<Deno.Reader | null> {
	// TODO implement this command in deno


@@ 18,8 16,6 @@ async function getLatestPost(post: string): Promise<Deno.Reader | null> {
	return process.stdout
}

let close = (conn: Deno.Conn) => conn.close()

for await (const conn of listener) {
	try {
		const buffer = new Uint8Array(256)


@@ 27,15 23,19 @@ for await (const conn of listener) {
		const user = decoder.decode(buffer)
			.replace(/\0.*/g,'')
			.trim()
		const stdout = await getLatestPost(user)

		//await conn.write(welcome)
		if (stdout) {
			await copy(stdout, conn)
		if (user.includes("@")) {
			// spec compliance
			// https://www.rfc-editor.org/rfc/rfc1288.html#section-3.2.1
			await conn.write(denial)
		} else {
			await conn.write(heart)
			const stdout = await getLatestPost(user)

			if (stdout) {
				await copy(stdout, conn)
			} else {
				await conn.write(heart)
			}
		}
		//await conn.write(goodbye)
	} finally {
		conn.close()
	}

M install => install +1 -0
@@ 3,5 3,6 @@ deno compile --allow-net --allow-run fingerd.ts
sudo mv fingerd /bin/partyfingerd
sudo cp partyfingerd.service /etc/systemd/system/
sudo systemctl enable --now partyfingerd
sudo systemctl restart partyfingerd
sudo cp grab-post-as-text /bin/
echo ready for fingering