# shellcheck shell=dash

x log init shodan
xrc gx
xrc:mod:lib     shodan  util cfg  argparse  \
                        api/_index          \
                        api/request         \
                        api/ourl            \
                        host/_index         \
                        geo/_index          \
                        alert/_index        \
                        notifier/_index     \
                        query/_index        \
                        scan/_index         \
                        dns/_index          \
                        stream/_index       \
                        entitydb/_index     \
                        trend/_index        \
                        other/_index        \
                        ddgo                \
                        cve/_index          \
                        cpe/_index

___x_cmd_shodan___main(){
    [ "$#" -gt 0 ] ||   set - -h
    local op="$1";      shift
    case "$op" in
        -h|--help)      x help -m shodan                "$@" ;;

        geo)            ___x_cmd_shodan_geo             "$@" ;;

        alert|stream|query|scan|dns|notifier|\
        profile|open)
                        ___x_cmd_shodan_"$op"           "$@" ;;

        stat)           ___x_cmd_shoda_stat             "$@" ;;

        idb|internetdb) ___x_cmd_shodan_internetdb      "$@" ;;
        edb|entitydb)   ___x_cmd_shodan_entitydb        "$@" ;;
        trend)          ___x_cmd_shodan_trend           "$@" ;;

        info)           ___x_cmd_shodan_info            "$@" ;;

        hh|httpheader)  ___x_cmd_shodan_httpheader      "$@" ;;
        ip)             ___x_cmd_shodan_myip            "$@" ;;

        ping)           ___x_cmd_shodan_geo geoping     "$@" ;;

        init)           ___x_cmd_shodan_init            "$@" ;;
        cfg|--cfg)      ___x_cmd_shodan_cfg             "$@" ;;

        # ,)              ;;

        host)           ___x_cmd_shodan_host            "$@" ;;
        # shortcut for host
        count|download|search|parse)
                        ___x_cmd_shodan_host    "$op"   "$@" ;;

        ddgo|:)         ___x_cmd_shodan_ddgo            "$@" ;;
        ddai|::)        ___x_cmd_shodan_ddai            "$@" ;;

        cve)            ___x_cmd_shodan_cve             "$@" ;;
        cpe)            ___x_cmd_shodan_cpe             "$@" ;;

        --)             ___x_cmd_shodan_host_search     "$@" ;;
        *)              ___x_cmd_shodan___nv    "$op"   "$@" ;;
    esac
}


# add x shodan cve
# add x shodan cve CVE ...
___x_cmd_shodan___nv(){
    local IFS=" "
    local argstr="$*"


    local arg1="$1"

    set -- \
        "x shodan search \"$argstr\""   \
        "open shodan.io using 'x shodan open \"$argstr\"'" \
        "x shodan download '$argstr'"    \
        "return 1"

    case "$arg1" in
        cve-*|CVE-*)    set -- "x shodan cve $arg1" "$@" ;;
    esac


    local id
    local content

    x ui select id,content "Next for $argstr" "$@"

    case "$content" in
        "x shodan cve"*)            ___x_cmd shodan cve        "$arg1"      ;;
        "x shodan search"*)         ___x_cmd shodan search     "$argstr"    ;;
        "open shodan.io"*)          ___x_cmd shodan open       "$argstr"    ;;
        "x shodan download"*)       ___x_cmd shodan download   "$argstr"    ;;
        *)                          return 0
    esac
}

