9001/copyparty

Poor message server

clach04 opened this issue ยท 4 comments

is your feature request related to a problem? Please describe.

I want to share "stuff" from my Android phone. Files, but also snippets, calendar entrires, and links.

I'd like a way to "see" these on a PC (in one place).

Describe the idea / solution you'd like

A crappy chat program :-p

Describe any alternatives you've considered

Full chat, which I do NOT want/need.

Additional context

I put together the following which works well enough for me. Any value in me contributing this?

#!/usr/bin/env python
# -*- coding: us-ascii -*-
# vim:ts=4:sw=4:softtabstop=4:smarttab:expandtab

import locale
import os
import sys
import json

"""
use copyparty as a dumb IRC messaging server
Sample usage:

    mkdir -p upload_here
    python dist/copyparty-sfx.py -v upload_here::rw --xm f,j,t10,bin/hooks/dumb_message_logger.py


Where:

    xm = execute on message-to-server-log
    f = fork so it doesn't block uploads
    j = provide message information as json; not just the text - this script REQUIRES json
    t10 = timeout and kill download after 10 secs

"""


def main(argv=None):
    if argv is None:
        argv = sys.argv

    message_info = json.loads(sys.argv[1])
    message_filename = os.environ.get('COPYPARTY_MESSAGE_FILENAME', 'messages.txt')  # .log gets downloaded, but .txt gets displayed in CopyParty web UI. Avoid .md to avoid being edited with Makrdown editor? (and .hist updates)
    # basic string template, works with (almost) any old version of Python
    message_logging_template = """
------
%(at)s  TODO ISO datetime format (or even datetime.now - either local time or UTC)
User: %(user)s
Client machine: %(ip)s  # TODO option for reverse DNS name lookup
%(txt)s
"""

    message_filename = os.path.join(message_info['ap'], message_filename)  # filename is actual shared file system shared
    f = open(message_filename, 'a')  # options binary and force write in ut8f, or use a codec
    try:
        f.write(message_logging_template % message_info)
    finally:
        f.close()

    #print(message_logging_template % message_info)  # assume output encoding is going to work fine (TODO force utf-8 - will do so for file output)

    return 0


if __name__ == "__main__":
    sys.exit(main())
9001 commented

This is great! Vaguely similar to the guestbook plugin so it definitely fits :-) and if you have a usecase for it then probably someone else does as well, so go for it ๐Ÿ‘

Just to note that there might be usecases for this where the .log file extension would be a better choice, since that enables copyparty's built-in rendering of ansi colors if you open the file by clicking the -txt- link next to the filename. But txt is the better default, and anyone who wants that behavior can just change it :-)

What about reverse engineering Kouchat's protocol, so it could chat with the Kouchat app and with other instances on the LAN P2P style?

9001 commented

that's so ridiculously overkill and way out of scope that I kinda like it :p
buuut let's hurry up and keep it simple before we get any more ideas ๐Ÿ˜ ๐Ÿ‘

What about reverse engineering Kouchat's protocol, so it could chat with the Kouchat app and with other instances on the LAN P2P style?

Kouchat looks like an interesting project but it's not a reliable protocol blurpy/kouchat#15 there are plans/ideas to address that but no updates in a few years.

An alternative to implementing Kouchat protocol in Python would be to wrap/scape the (java) console version. Potentially less work whilst also being future proof to any protocol changes should they take place.

For my use (or rather abuse) case, likely not going to work for me as I'm very much misusing CopyParty by hosting on WAN rather than LAN.