#!/bin/sh
#
#
#pragma ident "@(#)screeninfo.sh	1.7 00/01/06 Sun Microsystems, Inc."
#
# Get SunScreen 3.1 screen information -- run as root on the screen
#
# Edit this line to set the target screen name and config name
#

POLICY_NAME=""
USAGE="$0 [ -u | policyname ]"

PATH=/opt/SUNWicg/SunScreen/support:/opt/SUNWicg/SunScreen/bin:/usr/sbin:$PATH

# Check to see if user gave config name to check, else default to active
if [ $# -ne 0 ] 
then
  if [ $1 = "-u" ]
  then
    echo $USAGE
    exit 0
  fi
  
  if [ $# -eq 1 ]
  then
    POLICY_NAME=$1
  else
    echo $USAGE
    exit 1
  fi
else
  POLICY_NAME=`ssadm lib/ss_active_config -Z get | /usr/bin/awk '{print $3}' | /usr/bin/nawk -F\" '{print $1}'`
fi

DATE=`date +%y%m%d\%H\%M`

underline(){
        echo
        echo $1 | /usr/bin/awk '{for( num=$1 ; num > 0 ; num--)printf("=")}'
        echo "\n\n"
}
 
header(){
        echo "\n\n**********************************************************\c"
	string=`echo $1 $2 $3 $4 $5 $6`
        echo "\n\n$string\c"
        length=`echo $string | /usr/bin/wc -c`
        underline $length
}

# 1. Start off with the title and date and who this Screen is

for object in \
"echo @(#)screeninfo.sh	1.7 00/01/06" \
"date" \
"/usr/bin/hostname" \
"/sbin/uname -a" \
"ssadm sys_info" \
"ssadm lib/ss_active_config get"

do
  header $object
  $object 
done

# 2. Show the config names and the rules for each

header "ssadm policy -l"
ssadm policy -l

for configs in `ssadm policy -l `
do 
  header "ssadm edit $configs -c \"list Rule\""
  eval ssadm edit $configs -c \"list Rule\"
done

for object in \
"ssadm edit $POLICY_NAME -c \"list Rule\"" \
"ssadm edit $POLICY_NAME -c \"list Screen\"" \
"ssadm edit $POLICY_NAME -c \"list Interface\"" \
"ssadm edit $POLICY_NAME -c \"list AccessLocal\"" \
"ssadm edit $POLICY_NAME -c \"list AccessRemote\"" \
"ssadm edit $POLICY_NAME -c \"list Certificate\"" \
"ssadm edit $POLICY_NAME -c \"list Nat\"" \
"ssadm edit $POLICY_NAME -c \"list Address\"" \
"ssadm edit $POLICY_NAME -c \"list Service\"" \
"ssadm edit $POLICY_NAME -c \"list Time\"" \
"ssadm edit $POLICY_NAME -c \"list VPNNode\"" \
"ssadm ha status 2>&1" \
"skiplocal -l" \
"skipca -l" \
"skipdb -l" \
"skipdb -l -v" \
"ssadm traffic_stats" \
"skipstat -hkm" \
"ssadm lib/statetables" \
"disks" \
"eeprom" \
"findcore" \
"/sbin/ifconfig -a" \
"/usr/bin/netstat -pn" \
"last" \
"packages" \
"procs" \
"config" \
"stats" \
"streams" \
"versions" \
"/usr/bin/netstat -ian" \
"/usr/bin/netstat -rn" \
"/usr/sbin/ndd /dev/ip \?" \
"/usr/sbin/prtconf -p" \
"/usr/sbin/prtconf -pv" \
"/usr/sbin/prtconf -Pv" \
"ssadm logstats"

do
  header $object
  eval $object 
done


# Getting skipd.log and older version
skiplogs=`ls /var/log/skipd.log* 2> /dev/null`
if [ -n "$skiplogs" ] ; then
    for x in $skiplogs
    do
        header $x
        cat $x
    done
else
    header "No skipd.log ($skiplogs)"
    echo "ls /var/log/"
    echo "------------"
    ls /var/log/*
fi

# 4. show the prtdiag stuff

if [ -f "/usr/platform/`/usr/bin/uname -m`/sbin/prtdiag" ] ; then
  header "/usr/platform/`/usr/bin/uname -m`/sbin/prtdiag"
  /usr/platform/`/usr/bin/uname -m`/sbin/prtdiag
else
    header "no prtdiag file"
fi

echo
