Beispiel #1
0
def unmount_all_drives():
    """
    UnMounts the ssh drives from the computer
    """
    file = module.input_file(MOUNT_FILE)
    for i in range(0, len(file), 3):
        unmount_drive(file[i + 2])
Beispiel #2
0
def remove_drive():
    """
    Prompts the user and removes a drive from MOUNT_FILE
    """
    options = []
    file = module.input_file(MOUNT_FILE)
    for i in range(0, len(file), 3):
        options.append(str(len(options) + 1) + ") " + file[i])

    options.append("A) Exit")

    module.print_menu("Remove SSH Drive", options)

    i = input("Enter Option:")

    if i.lower() != 'a' and int(i) <= len(file) / 3 and int(i) > 0:
        index = (int(i) - 1) * 3

        f = open(MOUNT_FILE, "w")
        for x in range(0, len(file), 3):
            if index != x:
                f.write(file[x] + "\n")
                f.write(file[x + 1] + "\n")
                f.write(file[x + 2] + "\n")
        f.close()
Beispiel #3
0
def socks_ssh_tunnel():
    """
    prints user a menu to select a host to start a socks proxy with
    :return: None
    """
    file = module.input_file(INPUT_FILE)
    cmp = []
    count = 1
    for line in file:
        cmp.append(Computer(line, count))
        count += 1

    menu = []
    for c in cmp:
        menu.append(str(c.menu_id) + ") " + c.host)

    menu.append("A) Exit")
    menu.append("B) Main")
    module.print_menu("Socks Tunnel", menu)

    i = input("Enter option:")
    if i == '' or 'a' == str.lower(i):
        exit_program()
    elif 'b' == str.lower(i):
        main()
    else:
        for c in cmp:
            if int(i) == c.menu_id:
                print_red("Starting socks proxy on " + c.host + ":8123")
                subprocess.call(
                    ["ssh", "-D", "8123", "-C", "-q", "-N", c.host])
                exit_program()
Beispiel #4
0
def remove_host():
    """
    Removes a host name from servers.txt
    :return: None
    """
    file = module.input_file(INPUT_FILE)
    cmp = []
    count = 1
    print(print_red("*" * len(WELCOME_MESSAGE)))
    for line in file:
        cmp.append(Computer(line, count))
        count += 1
    for c in cmp:
        space = " " * (len(WELCOME_MESSAGE) - 3 -
                       len(str(c.menu_id) + ") " + c.host))
        print(
            print_red("*") + str(c.menu_id) + ") " + c.host + space +
            print_red("*"))

    print(print_red("*" * len(WELCOME_MESSAGE)))

    host = input("Enter number of host -1 to exit:")
    if host != '-1':
        for c in cmp:
            if c.menu_id == int(host):
                module.remove_line_from_file(INPUT_FILE, c.host)
Beispiel #5
0
def main():
    """
    This function inputs all the available hosts from a text file and prompts the user to connect to them
    :return:
    """
    print_welcome_message()
    file = module.input_file(INPUT_FILE)

    cmp = []
    count = 1

    for line in file:
        cmp.append(Computer(line, count))
        count += 1

    print("*         SSH manager V 0.1           *")
    for c in cmp:
        print_menu_option(str(c.menue_id) + ") " + c.host)

    print("*" * len(WELCOME_MESSAGE))
    i = input("Enter number of computer to connect to or enter to exit:")

    if i == '':
        subprocess.call(["clear"])
    else:
        for c in cmp:
            if int(i) == c.menue_id:
                subprocess.call(["ssh", c.host])
Beispiel #6
0
def main():
    """
    This function calls the welcome function, then it calls the cowsay function with a random quote.
    :return: None
    """

    quotes = module.input_file(INPUT_FILE)
    #print_cowsay_message(quotes[random.randint(0,(len(quotes) -1))])
    print_roosay_message(quotes[random.randint(0, (len(quotes) - 1))])
Beispiel #7
0
def mount_drives():
    """
    Mounts all the ssh drives in the configuration file
    """
    file = module.input_file(MOUNT_FILE)
    if len(file) == 0:
        print(MOUNT_FILE + " is empty")
    else:
        for i in range(0, len(file), 3):
            mount_drive(file[i], file[i + 1], file[i + 2])
Beispiel #8
0
def view_drives():
    """
    Views the current drives to the user
    """
    drives = []
    file = module.input_file(MOUNT_FILE)
    for i in range(0, len(file), 3):
        drives.append(str(int(int(i) / 3 + 1)) + ") " + file[i])
        drives.append("   " + file[i + 1])
        drives.append("   " + file[i + 2])
    module.print_menu("SSH Drives", drives)
Beispiel #9
0
def main():
    """
    This function inputs all the available hosts from a text file and 
    prompts the user to connect to them
    :return:
    """
    file = module.input_file(INPUT_FILE)

    cmp = []
    count = 1

    for line in file:
        cmp.append(Computer(line, count))
        count += 1

    menu = []

    for c in cmp:
        menu.append(str(c.menu_id) + ") " + c.host)
    menu.append("A) Exit")
    menu.append("B) Manager tools")
    menu.append("C) Socks Tunnel")
    menu.append("D) SSH Drive Manager")

    module.print_menu("SSH manager V 1.0", menu)

    i = input("Enter Option:")

    if i == '' or i == 'A' or i == 'a':
        exit_program()
    elif i == 'b' or i == 'B':
        sub_menu()
    elif "c" == str.lower(i):
        socks_ssh_tunnel()
    elif "d" == str.lower(i):
        mount_ssh_drive.main()
    else:
        for c in cmp:
            if int(i) == c.menu_id:
                subprocess.call(["ssh", c.host])
                exit_program()
Beispiel #10
0
def main():
    """
    This function calls the welcome function, then it calls the cowsay
    function with a random quote.
    :return: None
    """
    if len(sys.argv) > 1:
        if sys.argv[1].lower() == "-h" or sys.argv[1].lower() == "-help":
            print_usage()
        elif sys.argv[1].lower() == "-a":
            if len(sys.argv) > 2:
                add_quote()
            else:
                print("You forgot to enter a quote.")
        else:
            print_usage()
    else:
        quotes = module.input_file(INPUT_FILE)

        if len(quotes) == 0:
            print("Quotes file : " + INPUT_FILE + " is empty.")
        else:
            print_roosay_message(quotes[random.randint(0, (len(quotes) - 1))])
Beispiel #11
0
def copy_ssh_key():
    """
    calls systems ssh-copy-id with host name
    :return: None
    """
    file = module.input_file(INPUT_FILE)
    cmp = []
    count = 1
    for line in file:
        cmp.append(Computer(line, count))
        count += 1

    menu = []
    for c in cmp:
        menu.append(str(c.menu_id) + ") " + c.host)
    menu.append("A) Exit")
    module.print_menu("Copy SSH Key", menu)

    host_id = input("Enter number of host to copy ssh key to:")
    if not (host_id == '-1' or host_id.lower() == 'a'):
        for c in cmp:
            if c.menu_id == int(host_id):
                subprocess.call(["ssh-copy-id", c.host])