Beispiel #1
0
def common_commands(command: str):
    if '' == command:
        pass

    elif 'clear' == command:
        services.core.clear_console()

    else:
        print(Messages.command_not_defined)
Beispiel #2
0
def run_admin_commands(command: str, other_command: str) -> bool:
    global aliases

    if command in ('G', 'get'):
        val = get_from_server(other_command)
        print(val)

    elif command in ('S', 'send'):
        send_to_server(other_command)

    elif command in ('E', 'exec'):
        services.tunnel.send(ev.execute, other_command)
        res = services.tunnel.wait_for(ev.execute_result)

        print(f'result: {res}')

    # alias <alias> = <command>
    elif command in ('A', 'alias'):

        try:
            alias, command = [w.strip() for w in other_command.split('=')]
        except:
            print('cannot parse')
        else:
            aliases[alias] = command
            print(f'alias {alias} saved successfully')

    elif command in ('CA', 'call-alias'):
        alias = other_command

        command = first_word(aliases[alias])
        other_command = remove_first_word(aliases[alias])

        run_admin_commands(command, other_command)

    elif command in ('AL', 'alias-list'):
        print(aliases)

    else:
        # it means that the command is not defined in this function
        return False

    return True
Beispiel #3
0
def admin_input():
    while states.is_admin:
        # get user input
        inp = input('Client>').strip()
        command = first_word(inp)
        other_command = remove_first_word(inp)

        if run_admin_commands(command, other_command):
            pass

        elif command in ('quit', 'Q'):
            states.is_admin = False
            print(Messages.exiting_admin)

            return client_input()

        elif 'help' == inp:
            print(Messages.admin_help)

        else:
            common_commands(inp)
Beispiel #4
0
def auth():
    # check if user has admin privillages
    if states.is_admin:
        print(Messages.you_are_admin)

    else:
        tries = 0

        while tries < 3:
            # input server's password
            entered_pass = input(Messages.enter_pass)
            services.tunnel.send(ev.auth, entered_pass)

            # admin permission
            admin_per = services.tunnel.wait_for(ev.auth_check)

            if admin_per:
                print(Messages.admin_granted)
                states.is_admin = True

                return admin_input()

            # if entered password was wrong
            else:
                print(Messages.wrong_pass)
                tries += 1

        return client_input()
Beispiel #5
0
def client_input():

    while True:
        inp = input(Messages.app_name)

        # print connection status
        if 'status' == inp:
            if states.is_connected:
                print(Messages.yconnected)

            else:
                print(Messages.ynotconnected)

        # authenticate
        elif 'auth' == inp:
            return auth()

        elif 'help' == inp:
            print(Messages.client_help)

        else:
            common_commands(inp)
Beispiel #6
0
def connect(data):
    print(Messages.connected)
Beispiel #7
0
def hello(data=None):
    print(Messages.hello_from_server)
Beispiel #8
0
def disconnect(data):
    print(Messages.disconnected)