#!/bin/bash

cliHandleSshCommands()
{
    local action="$initial_command2"
    local arg="$initial_command3"

    case "$action" in
        ""|help)
            cliShowSshHelp
            ;;
        status)
            local pw="off"; hostSshPasswordAuthEnabled && pw="on"
            echo "user=$(hostSshUser) password_login=$pw authorized_keys=$(hostSshKeyCount)"
            ;;
        key-add)
            [[ -z "$arg" ]] && { isNotice "Usage: ssh key-add <base64-public-key>"; cliShowSshHelp; return; }
            hostSshKeyAdd "$arg"
            ;;
        key-remove)
            [[ -z "$arg" ]] && { isNotice "Usage: ssh key-remove <fingerprint>"; cliShowSshHelp; return; }
            hostSshKeyRemove "$arg"
            ;;
        password-auth)
            [[ -z "$arg" ]] && { isNotice "Usage: ssh password-auth <on|off>"; cliShowSshHelp; return; }
            hostSshSetPasswordAuth "$arg"
            ;;
        generate)
            webuiGenerateSshAccess
            ;;
        *)
            isNotice "Unknown ssh action: $action"
            cliShowSshHelp
            ;;
    esac
}
