118 lines
2.5 KiB
Python
118 lines
2.5 KiB
Python
#!/usr/bin/python3
|
|
# -*- mode: python; coding: utf-8 -*-
|
|
|
|
import os
|
|
import sys
|
|
import socket
|
|
|
|
import click
|
|
|
|
kex_algorithms = [
|
|
"diffie-hellman-group1-sha1",
|
|
"diffie-hellman-group-exchange-sha1",
|
|
"diffie-hellman-group14-sha1",
|
|
]
|
|
|
|
ciphers = [
|
|
"aes256-cbc",
|
|
"aes192-cbc",
|
|
"3des-cbc",
|
|
"aes128-cbc",
|
|
"aes256-ctr",
|
|
"aes192-ctr",
|
|
"aes128-ctr",
|
|
]
|
|
|
|
macs = [
|
|
"hmac-md5",
|
|
"hmac-sha1",
|
|
"hmac-sha2-256-etm@openssh.com",
|
|
"hmac-sha2-512-etm@openssh.com",
|
|
"hmac-sha2-256",
|
|
"hmac-sha2-512",
|
|
]
|
|
|
|
options = [
|
|
("Ciphers", f"{','.join(ciphers)}"),
|
|
("ControlMaster", "no"),
|
|
("ControlPath", "none"),
|
|
("ForwardX11", "no"),
|
|
("ForwardX11Trusted", "no"),
|
|
("HostKeyAlgorithms", "+ssh-rsa"),
|
|
("KexAlgorithms", f"{','.join(kex_algorithms)}"),
|
|
("MACs", f"{','.join(macs)}"),
|
|
("PubkeyAcceptedKeyTypes", "+ssh-rsa"),
|
|
]
|
|
|
|
|
|
@click.command()
|
|
@click.option("--ssh-command", default="ssh")
|
|
@click.option("--telnet-command", default="telnet")
|
|
@click.option("--connection-type")
|
|
@click.option("--name")
|
|
@click.option("--username")
|
|
@click.option("--address")
|
|
@click.option("--port")
|
|
def main(
|
|
ssh_command: str,
|
|
telnet_command: str,
|
|
connection_type: str,
|
|
name: str,
|
|
username: str,
|
|
address: str,
|
|
port: int,
|
|
):
|
|
|
|
sys.stdout.write("\033]0;")
|
|
sys.stdout.write(name)
|
|
sys.stdout.write(" - ")
|
|
sys.stdout.write(address)
|
|
sys.stdout.write("\007")
|
|
sys.stdout.flush()
|
|
|
|
# if 'SSH_AUTH_SOCK' in os.environ:
|
|
# journal.send('Removing SSH_AUTH_SOCK from environment')
|
|
# del os.environ['SSH_AUTH_SOCK']
|
|
|
|
command = []
|
|
|
|
match connection_type:
|
|
case "ssh":
|
|
command = [
|
|
ssh_command,
|
|
"ssh",
|
|
"-v",
|
|
"-y",
|
|
]
|
|
|
|
if socket.gethostname() != "pc60929":
|
|
command += ["-o", "ProxyCommand=ssh -W %h:%p jcollie@pc60929"]
|
|
|
|
command += [
|
|
"-i",
|
|
"~/.ssh/id_dmacc_rsa",
|
|
]
|
|
|
|
for k, v in options:
|
|
command += ["-o", f"{k}={v}"]
|
|
|
|
command += [
|
|
"-o",
|
|
f"User={username}",
|
|
address,
|
|
]
|
|
|
|
case "telnet":
|
|
command = [telnet_command, "telnet"]
|
|
|
|
if socket.gethostname() != "pc60929":
|
|
command = [ssh_command, "ssh", "-t", "ssh://jcollie@pc60929", "telnet"]
|
|
|
|
command += [address]
|
|
|
|
os.execlp(*command)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|