simple-bpq-telnet-application
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| simple-bpq-telnet-application [2024/11/29 14:56] – kc2ihx | simple-bpq-telnet-application [2026/02/21 20:23] (current) – [Program Code] kc2ihx | ||
|---|---|---|---|
| Line 31: | Line 31: | ||
| < | < | ||
| - | import asyncio, telnetlib3, json | + | import asyncio, telnetlib3, json, sys |
| from optparse import OptionParser | from optparse import OptionParser | ||
| + | # this sets up the command line options, primarily the file to read and the port to open for BPQ | ||
| parser = OptionParser() | parser = OptionParser() | ||
| parser.add_option(" | parser.add_option(" | ||
| Line 39: | Line 40: | ||
| (options, args) = parser.parse_args() | (options, args) = parser.parse_args() | ||
| + | # read file with messages | ||
| messages = json.load(open(options.filename,' | messages = json.load(open(options.filename,' | ||
| + | # logging method to write to stderr for journalctl to pick up | ||
| + | def print_log(*a): | ||
| + | print(*a, file=sys.stderr) | ||
| + | |||
| + | # this is the main function that processes input from user and writes outputs | ||
| async def shell(reader, | async def shell(reader, | ||
| + | # first thing provided is user's callsign | ||
| incall = await reader.readline() | incall = await reader.readline() | ||
| - | | + | |
| writer.write(" | writer.write(" | ||
| writer.write(" | writer.write(" | ||
| + | # make copy of blocks so we can pop 'em | ||
| textblocks = messages[" | textblocks = messages[" | ||
| - | leave = False # | + | |
| + | | ||
| rolled = False | rolled = False | ||
| - | inp = await reader.read(1) | + | |
| + | | ||
| + | text_count = 0 | ||
| + | incall = incall.rstrip() | ||
| + | # loop on inputs until they leave | ||
| while inp and not leave and len(textblocks) > 0: | while inp and not leave and len(textblocks) > 0: | ||
| - | print(" | ||
| writer.write(textblocks.pop(0)) | writer.write(textblocks.pop(0)) | ||
| await writer.drain() | await writer.drain() | ||
| inp = await reader.readline() | inp = await reader.readline() | ||
| - | if not rolled: | + | |
| - | rolled = True | + | |
| + | # log that rolling has happened | ||
| + | print_log("%s rickrolled" | ||
| + | rolled = True | ||
| + | # if they type something starting with Q or B (quit, bye, bye-bye, etc.) let them leave | ||
| leave = inp[0].upper() in [" | leave = inp[0].upper() in [" | ||
| + | # log their input to journalctl via stderr | ||
| + | print_log(" | ||
| writer.close() | writer.close() | ||
| + | # sets up the async process to take inputs | ||
| loop = asyncio.get_event_loop() | loop = asyncio.get_event_loop() | ||
| coro = telnetlib3.create_server(port=options.port, | coro = telnetlib3.create_server(port=options.port, | ||
| Line 88: | Line 108: | ||
| In my '' | In my '' | ||
| < | < | ||
| - | CMDPORT=8005 63001 4565 10001 | + | CMDPORT=8005 63001 10001 |
| </ | </ | ||
| - | and in the application list, I added a new entry, where '' | + | and in the application list, I added a new entry, where '' |
| < | < | ||
| - | APPLICATION | + | APPLICATION |
| </ | </ | ||
| Line 98: | Line 118: | ||
| Next we'll configure a '' | Next we'll configure a '' | ||
| - | I created | + | Put this file in ''/ |
| < | < | ||
| # service for RRoAX25 server | # service for RRoAX25 server | ||
| + | # replace USER with the username under which you created the bpq-apps venv | ||
| [Unit] | [Unit] | ||
| Description=" | Description=" | ||
| After=network.target | After=network.target | ||
| + | # this might be backwards, but I do need linbpq for this to work. | ||
| + | Requires=linbpq.service | ||
| [Service] | [Service] | ||
| Type=simple | Type=simple | ||
| - | WorkingDirectory=/ | + | User=evan |
| - | ExecStart=/ | + | Group=evan |
| + | WorkingDirectory=/ | ||
| + | ExecStart=/ | ||
| Restart=always | Restart=always | ||
| + | RestartSec=3 | ||
| [Install] | [Install] | ||
| Line 119: | Line 145: | ||
| Activate it by running: | Activate it by running: | ||
| < | < | ||
| - | systemctl | + | sudo systemctl enable rick.service |
| - | systemctl | + | sudo systemctl start rick.service |
| </ | </ | ||
| Line 126: | Line 152: | ||
| < | < | ||
| - | systemctl | + | systemctl status rick.service |
| </ | </ | ||
| If you need to edit the service file, reload it with: | If you need to edit the service file, reload it with: | ||
| < | < | ||
| - | systemctl | + | systemctl daemon-reload |
| + | </ | ||
| + | |||
| + | Finally, to see who has used it: | ||
| + | < | ||
| + | journalctl -u rick.service -f | ||
| </ | </ | ||
simple-bpq-telnet-application.1732892162.txt.gz · Last modified: by kc2ihx