#! /bin/sh

EMAIL=`cat emailbanner`

RAWUNKNOWN=`curl --silent --header "X-CS: NOPE" "http://en.m.wikipedia.org/w/api.php?action=zeroconfig&type=config"`
UNKNOWN=`echo $RAWUNKNOWN | grep '{"enabled":false}'`

RAWKNOWN=`curl --silent --header "X-CS: 250-99" http://en.m.wikipedia.org/wiki/Special:ZeroRatedMobileAccess?zcmd=js-banner`
KNOWN=`echo $RAWKNOWN | grep 'enabled":true,' | grep 'zero-rated-banner-text'`

STATUS="OK"

if [ -z "$UNKNOWN" ]
then
	STATUS="FAIL"
	EMAIL=`cat emailbannerfail`
fi

if [ -z "$KNOWN" ]
then
	STATUS="FAIL"
	EMAIL=`cat emailbannerfail`
fi

BODY="UNKNOWN X-CS, should show disabled: $RAWUNKNOWN ... KNOWN X-CS, should show longer JS: $RAWKNOWN"

DATE=`date --rfc-3339=seconds`
echo $BODY| mailx -s "Banner $STATUS $DATE" $EMAIL
