|
@ -18,7 +18,7 @@ def print_welcome_message(): |
|
|
Prints defined greeting message to terminal |
|
|
Prints defined greeting message to terminal |
|
|
:return: None |
|
|
:return: None |
|
|
""" |
|
|
""" |
|
|
print(WELCOME_MESSAGE) |
|
|
|
|
|
|
|
|
print(magenta_print(WELCOME_MESSAGE)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def print_menu_option(s): |
|
|
def print_menu_option(s): |
|
@ -28,7 +28,7 @@ def print_menu_option(s): |
|
|
:return: |
|
|
:return: |
|
|
""" |
|
|
""" |
|
|
space = " " * (len(WELCOME_MESSAGE) - 3 - len(s)) |
|
|
space = " " * (len(WELCOME_MESSAGE) - 3 - len(s)) |
|
|
print("* " + s + space + "*") |
|
|
|
|
|
|
|
|
print(magenta_print("*") + s + space + magenta_print("*")) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main(): |
|
|
def main(): |
|
@ -46,73 +46,103 @@ def main(): |
|
|
cmp.append(Computer(line, count)) |
|
|
cmp.append(Computer(line, count)) |
|
|
count += 1 |
|
|
count += 1 |
|
|
|
|
|
|
|
|
print("* SSH manager V 0.2 *") |
|
|
|
|
|
|
|
|
print(magenta_print("*") + " SSH manager V 0.2 " + magenta_print("*")) |
|
|
for c in cmp: |
|
|
for c in cmp: |
|
|
print_menu_option(str(c.menue_id) + ") " + c.host) |
|
|
print_menu_option(str(c.menue_id) + ") " + c.host) |
|
|
|
|
|
|
|
|
print_menu_option("A/' ') Exit") |
|
|
|
|
|
print_menu_option("B/' ') Manager tools") |
|
|
|
|
|
|
|
|
print_menu_option("A) Exit") |
|
|
|
|
|
print_menu_option("B) Manager tools") |
|
|
|
|
|
|
|
|
print("*" * len(WELCOME_MESSAGE)) |
|
|
|
|
|
|
|
|
print(magenta_print("*" * len(WELCOME_MESSAGE))) |
|
|
i = input("Enter number of computer to connect to or enter to exit:") |
|
|
i = input("Enter number of computer to connect to or enter to exit:") |
|
|
|
|
|
|
|
|
if i == '' or i == 'A' or i == 'a': |
|
|
if i == '' or i == 'A' or i == 'a': |
|
|
subprocess.call(["clear"]) |
|
|
|
|
|
|
|
|
exit_program() |
|
|
elif i == 'b' or i == 'B': |
|
|
elif i == 'b' or i == 'B': |
|
|
subMenu() |
|
|
|
|
|
|
|
|
sub_menu() |
|
|
else: |
|
|
else: |
|
|
for c in cmp: |
|
|
for c in cmp: |
|
|
if int(i) == c.menue_id: |
|
|
if int(i) == c.menue_id: |
|
|
subprocess.call(["ssh", c.host]) |
|
|
subprocess.call(["ssh", c.host]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def printSubMenu(): |
|
|
|
|
|
|
|
|
def print_sub_menu(): |
|
|
""" |
|
|
""" |
|
|
prints out a sub help menu for other options |
|
|
prints out a sub help menu for other options |
|
|
:return: None |
|
|
:return: None |
|
|
""" |
|
|
""" |
|
|
print("**************************************") |
|
|
|
|
|
print("* SSH manager V 0.2 Options *") |
|
|
|
|
|
|
|
|
print(magenta_print("**************************************")) |
|
|
|
|
|
print(magenta_print("*") + " SSH manager V 0.2 Options " + magenta_print("*")) |
|
|
print_menu_option("1) Add Host") |
|
|
print_menu_option("1) Add Host") |
|
|
print_menu_option("2) Copy SSH key to server") |
|
|
print_menu_option("2) Copy SSH key to server") |
|
|
print_menu_option("3) Remove host name") |
|
|
print_menu_option("3) Remove host name") |
|
|
print_menu_option("4) Return to ssh manager") |
|
|
print_menu_option("4) Return to ssh manager") |
|
|
print_menu_option("5) Exit") |
|
|
print_menu_option("5) Exit") |
|
|
print("*" * len(WELCOME_MESSAGE)) |
|
|
|
|
|
|
|
|
print(magenta_print("*" * len(WELCOME_MESSAGE))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def subMenu(): |
|
|
|
|
|
|
|
|
def magenta_print(prt): return"\033[95m {}\033[00m" .format(prt) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def sub_menu(): |
|
|
""" |
|
|
""" |
|
|
calls printSubMenu and then gets input from user to make appropriate function calls |
|
|
calls printSubMenu and then gets input from user to make appropriate function calls |
|
|
:return: None |
|
|
:return: None |
|
|
""" |
|
|
""" |
|
|
printSubMenu() |
|
|
|
|
|
input = input("Enter selection:") |
|
|
|
|
|
|
|
|
print_sub_menu() |
|
|
|
|
|
i = input("Enter selection:") |
|
|
|
|
|
|
|
|
|
|
|
if i != '' and int(i) in {1, 2, 3, 4, 5}: |
|
|
|
|
|
options = {1: add_host, |
|
|
|
|
|
2: copy_ssh_key, |
|
|
|
|
|
3: remove_host, |
|
|
|
|
|
4: main, |
|
|
|
|
|
5: exit_program, |
|
|
|
|
|
} |
|
|
|
|
|
options[int(i)]() |
|
|
|
|
|
else: |
|
|
|
|
|
print("Invalid selection!") |
|
|
|
|
|
|
|
|
|
|
|
sub_menu() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def exit_program(): |
|
|
|
|
|
""" |
|
|
|
|
|
Exits the program and clears the screen |
|
|
|
|
|
:return: None |
|
|
|
|
|
""" |
|
|
|
|
|
subprocess.call(["clear"]) |
|
|
|
|
|
exit() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def addHost(): |
|
|
|
|
|
|
|
|
def add_host(): |
|
|
""" |
|
|
""" |
|
|
appends an inputted host name to servers.txt |
|
|
appends an inputted host name to servers.txt |
|
|
:return: None |
|
|
:return: None |
|
|
""" |
|
|
""" |
|
|
pass |
|
|
|
|
|
|
|
|
host = input("enter host name or -1 to exit:") |
|
|
|
|
|
if host != '-1': |
|
|
|
|
|
module.append_file(INPUT_FILE, host) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def copySSHKey(): |
|
|
|
|
|
|
|
|
def copy_ssh_key(): |
|
|
""" |
|
|
""" |
|
|
calls systems ssh-copy-id with host name |
|
|
calls systems ssh-copy-id with host name |
|
|
:return: None |
|
|
:return: None |
|
|
""" |
|
|
""" |
|
|
pass |
|
|
|
|
|
|
|
|
host = input("enter user@host or -1 to exit:") |
|
|
|
|
|
if host != '-1': |
|
|
|
|
|
subprocess.call(["ssh-copy-id " + host]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def removeHost(): |
|
|
|
|
|
|
|
|
def remove_host(): |
|
|
""" |
|
|
""" |
|
|
Removes a host name from servers.txt |
|
|
Removes a host name from servers.txt |
|
|
:return: None |
|
|
:return: None |
|
|
""" |
|
|
""" |
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
host = input("enter host to remove or -1 to exit:") |
|
|
|
|
|
if host != '-1': |
|
|
|
|
|
module.remove_line_from_file(INPUT_FILE, host) |
|
|
|
|
|
|
|
|
""" |
|
|
""" |
|
|
Makes sure that other programs don't execute the main |
|
|
Makes sure that other programs don't execute the main |
|
|