Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poor message server #35

Closed
clach04 opened this issue Jun 5, 2023 · 4 comments
Closed

Poor message server #35

clach04 opened this issue Jun 5, 2023 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@clach04
Copy link
Contributor

clach04 commented Jun 5, 2023

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())
@clach04 clach04 added the enhancement New feature or request label Jun 5, 2023
@9001
Copy link
Owner

9001 commented Jun 5, 2023

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

@EternityForest
Copy link

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 9001 closed this as completed in 4fbd685 Sep 12, 2023
@9001
Copy link
Owner

9001 commented Sep 12, 2023

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 😁 👍

@clach04
Copy link
Contributor Author

clach04 commented Sep 16, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants