#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# ssh_show_techsupport - Show tech-support script for ssh 
#
# Copyright (c) 2017-2018 by cisco Systems, Inc.
# All rights reserved.
#--------------------------------------------------------------------

# This script fragment contains the code for the following functions
# - print_main_heading
# - print_command_heading
# - run_single_command
# - run_commands
# - run_single_command_on_all_nodes
# - run_commands_on_all_nodes
# - default_parser_function
. /pkg/bin/show_tech_main_fragment

# List each set of show commands to be run. Each set must finish with an empty
# string. Note that it is important to use single quotes rather than double
# quotes for the strings containing your commands.

__cardtype="unspecified"
os_kernel=`uname -s`

# Set the default values of the file name for which show tech-support ssh 
# is to run and the file it is to write to.
# Read in the arguments to the script, setting node_required and filename
# according to these arguments.
# Note that it is important for security reasons that users can only enter
# alphanumeric filenames and nodes and that anywhere calling this script must
# enforce this.
while [ "$#" -gt "0" ]; do
    case "$1" in
        -t) __cardtype="$2"; shift 2;;
        *)  default_parser_function "$@"; shift $#;;
    esac
done

if [ "$__cardtype" == "unspecified" ]; then
    __cardtype=`node_type`
fi

 # global commands on RP


###############################################################################
# Show commands that run once per LR                                          #
###############################################################################

sys_exec[1]='show install active'
if [[ "$platform" == "panini" ]]; then
sys__ksh[1]='sdr_instcmd show install active'
else
sys__ksh[1]='instcmd show install active'
fi

if [[ "$platform" == "panini" ]]; then
sys_exec[2]='show install repository'
sys__ksh[2]='sdr_instcmd show install repository'
else
sys_exec[2]='show install inactive'
sys__ksh[2]='instcmd show install inactive'
fi

sys_exec[3]='show version'
if [[ "$platform" == "panini" ]]; then
sys__ksh[3]='ng_show_version'
else
sys__ksh[3]='show_version'
fi

sys_exec[4]='show platform'
if [[ "$platform" == "panini" ]]; then
sys__ksh[4]='show_platform_sysdb'
else
sys__ksh[4]='show_platform_vkg'
fi

sys_exec[5]='show process blocked'
if [[ "$platform" == "panini" ]]; then
sys__ksh[5]='sh_proc_ng_blocked'
else
sys__ksh[5]='show_processes -b'
fi

###############################################################################
# Show commands that run on every RP                                          #
###############################################################################

rp_exec[1]='show logging'
rp__ksh[1]='show_logging'

rp_exec[2]='show context location all'
if [[ "$platform" == "panini" ]]; then
      rp__ksh[2]='corehelper_context -c 0x1 -n all'
else 
      rp__ksh[2]='dumper_context -c 0x1 -n all'
fi

rp_exec[3]='show running-config'
rp__ksh[3]='nvgen -c -l 1 -t 1 -o 1'

rp_exec[4]='show ip int brief'
rp__ksh[4]='show_ip_interface -b -v all'

rp_exec[5]='show ssh'
rp__ksh[5]='show_ssh_session'

rp_exec[6]='show ssh session details'
rp__ksh[6]='show_ssh_alginfo'

rp_exec[7]='show ssh rekey'
rp__ksh[7]='show_ssh_rekey'

rp_exec[8]='show ssh history'
rp__ksh[8]='show_ssh_history'

rp_exec[9]='show tty trace info all all'
rp__ksh[9]='show_tty_trace -Z -A -M'

rp_exec[10]='show tty trace error all all'
rp__ksh[10]='show_tty_trace -X -A -M'

rp_exec[11]='show ssh history details'
rp__ksh[11]='show_ssh_history_details'

rp_exec[12]='show ssh trace all'
rp__ksh[12]='show_ssh_ltrace -O'

rp_exec[13]='show processes ssh_server'
rp__ksh[13]='sysmgr_show -o -p ssh_server'

rp_exec[14]='show mgmt-plane trace client ssh_server both'
rp__ksh[14]='show_ltrace_mpp -C ssh_server -W -U'

rp_exec[15]='show aaa locald trace'
rp__ksh[15]='show_locald_ltrace'

rp_exec[16]='show aaa trace errors'
rp__ksh[16]='show_aaa_ltrace -I'

rp_exec[17]='show tacacs trace'
rp__ksh[17]='tacacs_show_ltrace'

rp_exec[18]='show processes cepki'
rp__ksh[18]='sysmgr_show -o -p cepki'

rp_exec[19]='show processes mpp_srvr'
rp__ksh[19]='sysmgr_show -o -p mpp_srvr'

rp_exec[20]='show ipv6 interface brief'
rp__ksh[20]='show_ipv6_interface -b -v default'

rp_exec[21]='show lpts binding brief'
rp__ksh[21]='show_lpts_pa -a -B'

rp_exec[22]='show crypto key mypubkey dsa'
rp__ksh[22]='ce_cmd show key mydsa nooption'

rp_exec[23]='show crypto key mypubkey rsa'
rp__ksh[23]='ce_cmd show key myrsa nooption'

rp_exec[24]='show crypto key mypubkey ecdsa'
rp__ksh[24]='ce_cmd show key myecdsa nooption all'

rp_exec[25]='show crypto key authentication rsa'
rp__ksh[25]='ce_cmd show key rsapubauth one'

rp_exec[26]='show socket trace process ssh_server'
rp__ksh[26]='socket_show_ltrace -P ssh_server'

if [[ "$os_kernel" == "QNX" ]]; then
      rp_exec[27]='show processes sshd_child_handler detail'
      rp__ksh[27]='sysmgr_show -o -p sshd_child_handler -D'
else
      rp_exec[27]='run ps -fC sshd_child_handler'
      rp__ksh[27]='ps -fC sshd_child_handler'
fi

rp_exec[28]='show system statistics component ssh'
rp__ksh[28]='ship_show -c ssh'

rp_exec[29]=''
rp__ksh[29]=''

ssh_interface_clis() {
   check_platform_type=`get_platform_type`
}


# Parse the arguments to the script.
# Usage:
#
#sys.exit()
# A function called display() must be provided that calls the functions to
# Print the output heading
do_show_command() {
     print_main_heading "show tech-support ssh"

     if [ "$__cardtype" == "SYS" ]; then
         exec_commands sys
     else
         case "$__cardtype" in
         "RP"|"DRP")
             exec_commands rp
             ssh_interface_clis
             ;;
         esac
     fi


     # Print the closing heading.
     print_main_heading "show tech-support ssh complete"
}
# The display function.
display() {
        do_show_command
}

  # This function calls the display() function and sends the output to file if
  # the file option has been set.
. /pkg/bin/show_tech_file_fragment
