CGI Scripts

clear_log.cgi

#!/bin/sh
rm -f /data/.persistent/.mrwong/boxee.* 2>&1 >/dev/null
echo "Location: /"

get_log.cgi

#!/bin/sh
/opt/local/bin/collect_logs 2>&1 >/dev/null
echo "Location: /"

index.cgi

#!/bin/sh

date=`date -u '+%a, %d %b %Y %H:%M:%S %Z'`
PP_BIN=/opt/local/bin/get_platform_params
DTOOL_BIN=/opt/local/bin/dtool
VERSION="`cat /opt/boxee/VERSION`"

BX_MODEL="`${PP_BIN} 1`"
#BX_HWREV="`${PP_BIN} 3`"
BX_SERIAL="`${PP_BIN} 2`"
BX_RTFIRM="${VERSION}"
#BX_RCFIRM="`${PP_BIN} 4`"
#BX_REGSKU="`${PP_BIN} 5`"
#BX_DTOOLV="`${DTOOL_BIN} 1`"
BX_CPUTMP="`${DTOOL_BIN} 2`"
BX_FANSPD="`${DTOOL_BIN} 3`"

cat << EOF
Content-type: text/html
Expires: $date

<html>
<head>
  <title>Boxee Support Tool</title>
  <style type='text/css'>
  html, body, table, th, td { font: 10pt arial, sans serif; margin: 0px; padding: 0px; }
  th { font-weight: bold; text-align: left; }
  td { padding-left: 5px; }
  </style>
</head>
<body>

EOF
if [ ! -z "$QUERY_STRING" ]; then
  if [ "$QUERY_STRING" = "MAIL_FAIL" -o "$QUERY_STRING" = "MAIL_INVALID" ]; then
    MSG="Failure occured while sending report to Boxee. Please try again later."
    COL="#ff4000"
  elif [ "$QUERY_STRING" = "MAIL_SUCCESS" ]; then
    MSG="Your report has been successfully sent to Boxee."
    COL="#98c35c"
  else
    MSG="Unknown status."
    COL="#ff4000"
  fi
  echo "<div style='margin: 0px; padding: 0px; text-align: center; margin-bottom: 5px; width: 100%; border-bottom: 1px solid black; background-color: ${COL};'>${MSG}</div>"
else
  echo "<div style='margin-top: 1px;'>&nbsp;</div>"
fi

echo "<p style='font-weight: bold; margin-left: 5px;'>BOXEE SUPPORT TOOL</p>"

echo "<table style='margin-left: 10px; padding: 3px; border: 1px solid black;'>"
echo "<tr><td>Hardware Model:</td><td>${BX_MODEL}</td></tr>"
echo "<tr><td>Serial Number:</td><td>${BX_SERIAL}</td></tr>"
echo "<tr><td>Boxee Version:</td><td>${BX_RTFIRM}</td></tr>"
echo "<tr><td>CPU Temperature:</td><td>${BX_CPUTMP} C</td></tr>"
echo "<tr><td>Fan Speed:</td><td>${BX_FANSPD}%</td></tr>"
echo "</table>"

# boxee logs
f=`( cd /data/.persistent/.mrwong; find . -name boxee.\* ) | sort -r | xargs`
c=`echo $f | wc -w`

echo "<br/><br/><p style='border-bottom: 1px solid black;'>Boxee Logs [<a href='/get_log.cgi'>Get latest</a>&nbsp;|&nbsp;<a href='/clear_log.cgi'>Clear all</a>]</p><table>"
echo "<tr><th style='width: 180px;'>Date</th><th style='width: 100px;'>Size</th><th style='width: 400px;'>File</th><th style='width: 200px;'>Action</th></tr>"
if [ $c -gt 0 ]
then
  for r in $f
  do
    t=`stat -c%y $r | sed 's/\.000000000//'`
    s=`stat -c%s $r | awk '{ printf("%.02f kb", $1 / 1024) }'`
    r=`echo $r | sed 's/\.\///'`
    echo "<tr><td>$t</td><td>$s</td><td><a href='/$r'>$r</a></td><td><a href='/send_log.cgi?$r'>Send to Boxee</a></td></tr>"
  done
else
  echo "<tr><td colspan='3' align='center'>None</td></tr>"
fi
echo '</table>'

# error logs
f=`( cd /data/.persistent/.mrwong; find . -name report.\* ) | sort -r | xargs`
c=`echo $f | wc -w`

echo "<br/><br/><p style='border-bottom: 1px solid black;'>Error Logs</p><table>"
echo "<tr><th style='width: 180px;'>Date</th><th style='width: 100px;'>Size</th><th style='width: 400px;'>File</th><th style='width: 200px;'>Action</th></tr>"
if [ $c -gt 0 ]
then
  for r in $f
  do
    t=`stat -c%y $r | sed 's/\.000000000//'`
    s=`stat -c%s $r | awk '{ printf("%.02f kb", $1 / 1024) }'`
    r=`echo $r | sed 's/\.\///'`
    echo "<tr><td>$t</td><td>$s</td><td><a href='/$r'>$r</a></td><td><a href='/send_log.cgi?$r'>Send to Boxee</a></td></tr>"
  done
else
  echo "<tr><td colspan='3' align='center'>None</td></tr>"
fi
echo '</table></body></html>'

send_log.cgi

#!/bin/sh

FILENAME="`basename $QUERY_STRING`"
FILENAME="/data/.persistent/.mrwong/$FILENAME"
IS_VALID=`echo $FILENAME | grep "tar.bz2$" -c`
STATUS="MAIL_INVALID"
if [ -f "$FILENAME" -a $IS_VALID -gt 0 ]; then
  /opt/local/bin/send_mail $FILENAME 2>&1 >/dev/null
  if [ $? != 0 ]; then
    STATUS="MAIL_FAIL"
  else
    STATUS="MAIL_SUCCESS"
  fi
fi
echo "Location: /?${STATUS}"
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License