https://github.com/coljac/home-terminal

Tool to expose an SSH server as a home page

https://github.com/coljac/home-terminal

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.1%) to scientific vocabulary
Last synced: 10 months ago · JSON representation

Repository

Tool to expose an SSH server as a home page

Basic Info
  • Host: GitHub
  • Owner: coljac
  • License: mit
  • Language: Python
  • Default Branch: main
  • Size: 677 KB
Statistics
  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • Open Issues: 1
  • Releases: 0
Created almost 2 years ago · Last pushed about 1 year ago
Metadata Files
Readme License

README.md

Home Terminal

Shamelessly copied from https://github.com/gleich/terminal and implemented in python.

This code sets up a server that listens for SSH connections and then makes available a menu of commands to serve out whatever information you wish. Think of it like a home page for the extra nerdy.

example

Deployment

Can be done with or without a container - container is probably easiest, especially given the presumably less than military grade security this afternoon's python coding has ensured.

  • Clone the repo.
  • Define the commands you want, as below.
  • Install extra python dependencies if required for your commands.
  • Run term.py, specifying SSH_PORT (default: 22) and TERM_COMMANDS_DIR (default: ./commands) in the environment. Optionally, add a TERM_WELCOME var that points to a file to be sent on login.
  • It also needs a key pair to run, generate with ssh-keygen -t rsa -f ./id_rsa. You can override the default with the TERM_KEYFILE env var.

With docker:

docker build -t hometerm . docker run hometerm -p 22:22 hometerm

This will make a key too.

Commands

Apart from the default help and exit commands, the rest of the options are defined at runtime from a commands directory (specified with the TERM_COMMANDS_DIR environment variable, default: ./commands):

  • In a commands() method, which returns an array of Command objects;
  • In any number of hometerm.command.Command subclasses found.

The subclasses should initialize with a name and description, and override the execute method to return some text or Rich Text. The should have a constructor that takes no arguments.

For example, in the commands/ directory you might have commands.py: ```python from hometerm.command import TextCommand, ImageCommand

def commands(): return [ TextCommand("about", "Some info about me", "commands/about.md"), ImageCommand("pic", "See what I look like", "commands/col.png", size=[42, 64]), ] ```

and/or some class defintions like mycommand.py:

```python from hometerm.command import Command

class MessageCommand(Command): def init(self): super().init("message", "Send me a message")

def execute(self, terminal):
    terminal.send_rich("Enter your message (Press enter when done):")
    terminal.console.print("\r\n> ", style="bold yellow", end=None)
    # rest of the execution here 

```

see command.py for details. The main thing is to either return the output, or operate on the terminal object passed in, which allows extra interactivity.

Owner

  • Name: Colin Jacobs
  • Login: coljac
  • Kind: user
  • Location: Melbourne, Australia
  • Company: PoliQ

Python, astrophysics, ML/data stuff, and a bunch of hobby projects.

GitHub Events

Total
  • Watch event: 1
  • Push event: 1
Last Year
  • Watch event: 1
  • Push event: 1

Dependencies

Dockerfile docker
  • python 3.11-slim build
requirements.txt pypi
  • paramiko *
  • prompt-toolkit *
  • python_dotenv *
  • requests *
  • rich *
  • tabulate *
  • termcolor *