����JFIF��� ( %"1"%)+...383,7(-.- 404 Not Found
Sh3ll
OdayForums


Server : Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.20
System : Linux st2.domain.com 3.10.0-1127.10.1.el7.x86_64 #1 SMP Wed Jun 3 14:28:03 UTC 2020 x86_64
User : apache ( 48)
PHP Version : 7.4.20
Disable Function : NONE
Directory :  /proc/self/root/usr/local/FlashphonerWebCallServer/tools/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //proc/self/root/usr/local/FlashphonerWebCallServer/tools/report.sh
#!/usr/bin/env bash
#
# Make a report for further debug
#

function init_vars() {
 WCS_DIR="/usr/local/FlashphonerWebCallServer"

 PID=""
 PID_FILE=""
 PID_FILE_ROOT="/var/run/FlashphonerMainWebCallServer.pid"
 PID_FILE_NON_ROOT="$WCS_DIR/bin/FlashphonerMainWebCallServer.pid"

 FLASHPHONER_USER='flashphoner'
 USER_EXISTS=true
 RUNNING_FROM=$FLASHPHONER_USER
 RUN_AS_USER=false

 # Interval for gather logs
 HOURS_AGO=$1
 DATE_FROM=`date "+%Y-%m-%d %H" -d "$HOURS_AGO hour ago"`
 DATE_TO=`date "+%Y-%m-%d %H" -d "1 hour"`

 REPORT_DATE=`date +%Y-%m-%d-%H-%M-%S`
 REPORT_DIR="$WCS_DIR/report/report-$REPORT_DATE"
 
 JAVA_VERSION=0
 RUNNING_AS_SERVICE=false
 DAEMON_TYPE=`ps --no-headers -o comm 1`
}

function usage() {
 echo "Usage: $(basename $0) [OPTIONS]"
 echo "Default report will include netstat, lsof, logs between now and 3 hours ago, pmap, jstack"
 echo -e "  --conf\t\t copy configuration"
 echo -e "  --dump\t\t make heap dump"
 echo -e "  --sysinfo\t\t gather system info"
 echo -e "  --tar\t\t\t tar report"
 echo -e "  --hours <hours>\t hours count to collect lates logs (3 by default)"
 echo -e "  --help\t\t help"
 exit 0
}

function error() {
 echo "Error: $1"
}

function check_user {
 if [[ $(getent passwd $FLASHPHONER_USER) == "" ]]; then
  USER_EXISTS=false
 else
  USER_EXISTS=true
 fi
 if [[ "$(whoami)" != "root" ]]; then
  echo -e "$(basename $0) must be run as root:\n sudo $(basename $0)"
  exit 1
 fi
}

function check_java_version() {
 JDK_VERSION=`java -version 2>&1`
 java_ver=`echo $JDK_VERSION | head -1 | cut -d" " -f 3 | tr -d \"`
 java_ver_major=`echo $java_ver | cut -d \. -f 1`
 JAVA_VERSION=0

 if [[ $java_ver_major -eq 1 ]]; then
  java_ver_minor=`echo $java_ver | cut -d \. -f 2`
  if [[ $java_ver_minor -ge 8  ]]; then
   JAVA_VERSION=$java_ver_minor
  fi
 elif [[ $java_ver_major -ge 8 ]]; then
  JAVA_VERSION=$java_ver_major
 fi
}

function check_service() {
 RUNNING_AS_SERVICE=false
 # Check service only if systemd used #WCS-3034
 if [[ $DAEMON_TYPE == 'systemd' ]]; then
  if systemctl is-active --quiet webcallserver.service; then
   RUNNING_AS_SERVICE=true
  fi
 fi 
}

function do_init() {
 init_vars $@
 if [ -f $PID_FILE_ROOT ]; then
  PID_FILE=$PID_FILE_ROOT
 elif [ -f $PID_FILE_NON_ROOT ]; then
  PID_FILE=$PID_FILE_NON_ROOT
 else
  error "Server not running"
  exit 1
 fi
 PID=$(cat $PID_FILE)
 if ! ps -p $PID > /dev/null 2>&1; then
  error "Process $PID does not exist"
  exit 1
 fi
 check_user
 RUNNING_FROM=`ps -o uname= -p "$PID"`
 if [[ $USER_EXISTS == true && $RUNNING_FROM == $FLASHPHONER_USER ]]; then
  RUN_AS_USER=true
 fi
 check_java_version
 check_service
 mkdir -p "$REPORT_DIR"
}

function set_dir_owner() {
 if [[ $RUN_AS_USER == true ]]; then
  chown -R $FLASHPHONER_USER "$1"
 fi
}

function get_logs() {
 mkdir -p $REPORT_DIR/logs/server_logs
 mkdir -p $REPORT_DIR/logs/client_logs
 cd $WCS_DIR/logs
 find . -newermt "$DATE_FROM" ! -newermt "$DATE_TO" -exec cp --parents -t $REPORT_DIR/logs {} + > /dev/null 2>&1
 return 0
}

function get_netstat() {
 netstat -antpul > "$REPORT_DIR/netstat.log"
}

function get_lsof() {
 if command -v lsof > /dev/null 2>&1; then
  lsof -P -p $PID > "$REPORT_DIR/lsof.log"
 else
  error "'lsof' not found"
  return 1
 fi
}

function get_pmap() {
 if command -v pmap > /dev/null 2>&1; then
  CMD=pmap
  if pmap -h | grep -e "^[[:space:]]\-X" > /dev/null; then
   CMD="$CMD -X"
  else
   CMD="$CMD -x"
  fi
  $CMD $PID > "$REPORT_DIR/pmap.log"
 else
  error "'pmap' not found"
  return 1
 fi
}

function run_jstack_as() {
 USER=$1
 if [[ $USER == $FLASHPHONER_USER ]]; then
  chown $FLASHPHONER_USER "$REPORT_DIR"
  if [[ $JAVA_VERSION -gt 8 && $RUNNING_AS_SERVICE ]]; then
   run_jstack_as root
  else
   sudo -u $FLASHPHONER_USER $CMD $PID > "$REPORT_DIR/jstack.log"
  fi
 else
  $CMD $PID > "$REPORT_DIR/jstack.log" 
 fi
}

function get_jstack() {
 CMD=`command -v jstack 2>/dev/null`
 if [[ $CMD != "" ]]; then
  if [[ $RUN_AS_USER == true ]]; then
   run_jstack_as $FLASHPHONER_USER
  else
   run_jstack_as root
  fi
 else
  error "'jstack' not found. Skip thread dumping."
  return 1
 fi
}

function get_conf() {
 mkdir $REPORT_DIR/conf
 cp $WCS_DIR/conf/flashphoner.properties $REPORT_DIR/conf
 cp $WCS_DIR/conf/wcs-core.properties $REPORT_DIR/conf
 cp $WCS_DIR/conf/log4j.properties $REPORT_DIR/conf
 cp $WCS_DIR/conf/WCS.version $REPORT_DIR/conf
 cp $WCS_DIR/conf/*.yml $REPORT_DIR/conf
 if [[ "$(echo $WCS_DIR/conf/*.sdp)" != "$WCS_DIR/conf/*.sdp" ]]; then
  cp $WCS_DIR/conf/*.sdp $REPORT_DIR/conf
 fi
}

function run_gc_as() {
 USER=$1
 if [[ $USER == $FLASHPHONER_USER ]]; then
  if [[ $JAVA_VERSION -gt 8 && $RUNNING_AS_SERVICE ]]; then
   run_gc_as root
  else
   sudo -u $FLASHPHONER_USER $CMD $PID GC.run > /dev/null 2>&1
  fi
 else
  $CMD $PID GC.run > /dev/null 2>&1
 fi
}

function run_jmap_as() {
 USER=$1
 if [[ $USER == $FLASHPHONER_USER ]]; then
  chown $FLASHPHONER_USER "$REPORT_DIR/dump"
  if [[ $JAVA_VERSION -gt 8 && $RUNNING_AS_SERVICE ]]; then
   run_jmap_as root
  else
   sudo -u $FLASHPHONER_USER $CMD -dump:format=b,file=$REPORT_DIR/dump/$PID.hprof $PID > /dev/null 2>&1
  fi
 else
  $CMD -dump:format=b,file=$REPORT_DIR/dump/$PID.hprof $PID > /dev/null 2>&1
 fi
}

function get_dump() {
 CMD=`command -v jcmd 2>/dev/null`
 if [[ $CMD != "" ]]; then
  if [[ $RUN_AS_USER == true ]]; then
   run_gc_as $FLASHPHONER_USER
  else
   run_gc_as root
  fi
 else
  error "'jcmd' not found. Skip exec GC.run"
 fi
 CMD=`command -v jmap 2>/dev/null`
 if [[ $CMD != "" ]]; then
  mkdir $REPORT_DIR/dump
  if [[ $RUN_AS_USER == true ]]; then
   run_jmap_as $FLASHPHONER_USER
  else
   run_jmap_as root
  fi
 else
  error "'jmap' not found. Skip heap dumping."
  return 1
 fi
}

function get_sysinfo() {
 mkdir $REPORT_DIR/sysinfo
 cat /proc/cpuinfo > "$REPORT_DIR/sysinfo/cpuinfo.log"
 cat /proc/meminfo > "$REPORT_DIR/sysinfo/meminfo.log"
 df -h > "$REPORT_DIR/sysinfo/df.log"
 ifconfig > "$REPORT_DIR/sysinfo/ifcfg.log"
 iptables -nvL > "$REPORT_DIR/sysinfo/iptables.log"
}

function get_tar() {
 TAR_FILE="report_$REPORT_DATE.tar.gz"
 cd $WCS_DIR/report
 tar -zcf $TAR_FILE report-$REPORT_DATE > /dev/null 2>&1
}

function show_schedule() {
 echo -e "Scheduled report:\n"
 for report in $1; do
  if [[ "$report" == "dump" ]]; then
   dump_size=$(grep -e "^-Xmx" $WCS_DIR/conf/wcs-core.properties | cut -f2 -d"x")
   echo "* $report [estimated $dump_size]"
  else 
   echo "* $report"
  fi
 done
}

function main() {
 start_time=$(date +%s)
 scheduled_report="logs netstat lsof pmap jstack"
 hours="3"
 while [[ $# -gt 0 ]]; do
  case "$1" in
   --help)
     usage;;
   --dump)
     scheduled_report="$scheduled_report dump";;
   --sysinfo)
     scheduled_report="$scheduled_report sysinfo";;
   --conf)
     scheduled_report="$scheduled_report conf";;
   --tar)
     scheduled_report="$scheduled_report tar";;
   --hours)
     shift
     hours=$1
     ;;
  esac
  shift 
 done
 do_init "$hours"
 show_schedule "$scheduled_report"
 echo -e "\nProgress: \n"
 for task in $scheduled_report; do
  echo "[PROGRESS] $task"
  tput cuu1
  if get_$task; then
   tput el
   echo "[DONE] $task"
  else
   tput el
   echo "[FAILED] $task"
  fi
 done
 end_time=$(date +%s)
 echo "Report complete in $((end_time - start_time)) seconds. Check $REPORT_DIR"
}

main "$@"

exit 0

ZeroDay Forums Mini