supakeen / pinnwand

A Python pastebin that tries to keep it simple.
MIT License
181 stars 43 forks source link

netcat api #32

Open supakeen opened 4 years ago

supakeen commented 4 years ago

A netcat API would be neat, much like https://termbin.com/ and as mentioned by @altendky in #31 .

Looking at what they do is accept the connection wait until they don't receive data for some interval then return the paste data (could be the same as the /curl endpoint which then could be generalized).

While this is 'straightforward' to implement with tornado's tcpserver that I'm well familiar with this ticket is to explore options on how to pass metadata. If I'd implement it straight up pinnwand would always paste as text with an expiry of 1day.

We could have inline (say, separated by null bytes, if the last value is a valid lexer, use that) or meta information (mostly... different port numbers...). If we want to get really fancy we could do something with TLS and ALPN (or even SNI, I guess).

None of these seem particularly appealing except doing the straightforward thing.

supakeen commented 4 years ago

While not directly through nc there's some options for providing metadata with or other things, here are some ideas:

  1. nc python-1day.paste.com -> requires either ipv6 or a lot of ips.
  2. nc paste.com 2001 -> requires a port per combination and is not discoverable.
  3. (echo -n "python"; echo -ne "\x00"; cat foo) | nc ... -> unclean api and easy to mix up.
  4. cat foo | openssl s_client -connect bla:bla -alpn python,1day -> alpn is a bit weird and it's not nc.
  5. cat foo | openssl s_client -connect python-1day.paste.com:bla -> sni but still not nc.
supakeen commented 4 years ago

I forgot one option: interactive. The current idea is to wait until no data has been received for a certain timeout, it's possible to then ask the user for expiry/lexer to use and if none is supplied default them.

supakeen commented 4 years ago

Or, I could just not overcomplicate this and always provide 1 day, plaintext pastes. Paste gets created on timeout. If people disconnect earlier they won't get a response?

mweinelt commented 3 years ago

I would've expected an EOF to finish the request.