Skip to content

"Match" implementation inside SSH Config File #794

Description

@isontheline

Tasks for complete implementation

  • Ability to use a mashREPL command (or at least a Swift WebSSH Command) inside a MATCH
  • Ability to "match" a connection by its TAGS or GROUP

Describe the feature
I would like to suggest a new subnet detection feature that dynamically chooses a hostname/IP to connect to based on which network the app is running from, configured for each connection.

e.g. if I'm on my home network and the app detects I'm on a specified subnet such as 192.168.0.x, I would like the app to connect to a local IP address. If I'm connecting from a network other than the specified one (ie roaming on my iPhone), it uses another hostname such as an external URL (my.homenet.com).

I can illustrate this based on a method I use with .ssh/config (which as it happens also uses another feature request - ProxyJump)

Match exec "/Users/user1/onsubnet 192.168.1." host raspi1
 Hostname 192.168.1.100
 Port 22
 User pi

Match exec "/Users/user1/onsubnet --not 192.168.1." host raspi1
 ProxyJump proxypi
 Hostname 192.168.1.100
 User pi
 Port 22

Host proxypi
 HostName my.homenet.com
 Port 8700
 User pi

The file /Users/user1/onsubnet is a script I found that helps determine your subnet on a Mac. I realise it couldn't be used in the app like this, but I'm including it here in case it helps.

if [[ "$1" == "--help" ]] || [[ "$1" == "-h" ]]  || [[ "$1" == "" ]] ; then
  printf "Usage:\n\tonsubnet [ --not ] partial-ip-address\n\n"
  printf "Example:\n\tonsubnet 10.10.\n\tonsubnet --not 192.168.0.\n\n"
  printf "Note:\n\tThe partial-ip-address must match starting at the first\n"
  printf "\tcharacter of the ip-address, therefore the first example\n"
  printf "\tabove will match 10.10.10.1 but not 110.10.10.1\n"
  exit 0
fi

on=0
off=1
if [[ "$1" == "--not" ]] ; then
  shift
  on=1
  off=0
fi

regexp="^$(sed 's/\./\\./g' <<<"$1")"

if [[ "$(uname)" == "Darwin" ]] ; then
  ifconfig | fgrep 'inet ' | fgrep -v 127.0.0. | cut -d ' ' -f 2 | egrep "$regexp" >/dev/null
else
  hostname -I | tr -s " " "\012" | fgrep -v 127.0.0. | egrep "$regexp" >/dev/null
fi

if [[ $? == 0 ]]; then
  exit $on
else
  exit $off
fi

In the absence of this feature I could always specify the external URL, but I'm not sure if that would work with ProxyJump where a connection to an internal device would keep having to hop via my proxypi to its destination when I'm at home.

Hope this makes sense.
Thanks.

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions