#!/bin/sh -f

PLACE=".1.3.6.1.4.1.26934.14"    # NET-SNMP-PASS-MIB::netSnmpPassExamples
REQ="$2"                         # Requested OID

#
#  GETNEXT requests - determine next valid instance
#
if [ "$1" = "-n" ]; then
  case "$REQ" in
    $PLACE.100|		\
    $PLACE.100.*)	RET=$PLACE.100.0 ;; # deviceHWVersion

    $PLACE|	\
    $PLACE.400|	\
    $PLACE.400.*)	RET=$PLACE.400.0 ;; # deviceHWVersion

    *)         	    exit 0 ;;
  esac
else
#
#  GET/SET requests - check for valid instance
#
  case "$REQ" in
    $PLACE.400.*|	\
    $PLACE.100.*)	RET=$REQ ;;
    *)			exit 0 ;;
  esac
fi

#
#  Process SET requests by simply logging the assigned value
#      Note that such "assignments" are not persistent,
#      nor is the syntax or requested value validated
#  
if [ "$1" = "-s" ]; then
  echo $* >> /tmp/passtest.log
  tmp_url4=$(echo "$4" | awk '{print $1}')
  tmp_url5=$(echo "$4" | awk '{print $2}')
  url4=$(/root/snmp/urlencode.sh "$tmp_url4")
  url5=$(/root/snmp/urlencode.sh "$tmp_url5")
  echo $url4 >> /tmp/passtest.log
  echo $url5 >> /tmp/passtest.log
  echo $tmp_url4 >> /tmp/passtest.log
  echo $tmp_url5 >> /tmp/passtest.log
  case "$RET" in
    $PLACE.400.4.*)   echo "string";    /root/snmp/set_brightness.sh $4;	   		           exit 0 ;;
    $PLACE.400.5.*)   echo "string";    if [ $4 -eq "1" ]; then /root/snmp/restart_screen.sh; fi;          exit 0 ;;
    $PLACE.400.6.*)   echo "string";    if [ $4 -eq "1" ]; then /root/snmp/restart_app.sh; fi; 	           exit 0 ;;
    $PLACE.400.7.*)   echo "string";    date -s "$4"; 						           exit 0 ;;
    $PLACE.400.8.*)   echo "string";    /root/snmp/set_browser_addr.sh $url4;                              exit 0 ;;
    $PLACE.400.9.*)   echo "string";    /root/snmp/set_screen_rotation.sh $4;                              exit 0 ;;
    $PLACE.400.10.*)  echo "string";    /root/snmp/set_rsync_pass.sh $4;                                   exit 0 ;;
    $PLACE.400.11.*)  echo "string";    /root/snmp/rsync_update.sh $4;                                     exit 0 ;;
    $PLACE.400.12.*)  echo "string";    /root/snmp/rsync_trigger_update.sh $4;                             exit 0 ;;
    $PLACE.400.13.*)  echo "string";    /root/snmp/set_rsync_user.sh $4;                                   exit 0 ;;
    $PLACE.400.14.*)  echo "string";    /root/snmp/set_hostname.sh $4;                                     exit 0 ;;
    $PLACE.400.15.*)  echo "string";    /root/snmp/change_check_service_params.sh $url4 $url5;             exit 0 ;;
    $PLACE.400.16.*)  echo "string";    /root/snmp/change_ntp_srv_addr.sh $4;				   exit 0 ;;
    $PLACE.400.17.*)  echo "string";    /root/snmp/change_localtime.sh $4;				   exit 0 ;;
    *)                echo "string";    /root/snmp/log_error.sh $*;				  exit 0 ;;  # Should not happen
  esac
fi


#
#  "Process" GET* requests - return hard-coded value
#
echo "$RET"
case "$RET" in
  $PLACE.400.1.*)   echo "string";    echo $(uname -a); 			exit 0 ;;
  $PLACE.400.2.*)   echo "string";    echo "2.15.0";				exit 0 ;;
  $PLACE.400.3.*)   echo "string";    /root/snmp/get_temperature.sh;		exit 0 ;;
  $PLACE.400.4.*)   echo "string";    /root/snmp/get_brightness.sh;		exit 0 ;;
  $PLACE.400.7.*)   echo "string";    date;					exit 0 ;;
  $PLACE.400.8.*)   echo "string";    /root/snmp/get_browser_addr.sh $4;        exit 0 ;;
  $PLACE.400.9.*)   echo "string";    /root/snmp/get_screen_rotation.sh $4;     exit 0 ;;
  $PLACE.400.14.*)  echo "string";    /root/snmp/get_hostname.sh		exit 0 ;;
  *)                echo "string";    echo "invalid request... $RET $REQ";      exit 0 ;;  # Should not happen
esac
