#!/bin/sh

quit()
{
	echo ""
	echo "Your Plesk is not affected by 'phppath' vulnerability."
	echo ""
	exit 0
}

parse_conf()
{
	conffile="/etc/psa/psa.conf"

	[ ! -f "$conffile" ] && die "File not found: '$conffile'"

	eval `cat $conffile | \
		grep -v '^ ' | grep -v '^$' | grep -v '^#' | \
		awk '{print $1"="$2}'`

	[ -z "$HTTPD_VHOSTS_D" ] && die "Unable to read the conf file: '$conffile'"
}

check_install()
{
	count=0
	for f in `find $HTTPD_INCLUDE_D -type f`; do
		grep -q '^scriptAlias' $f || continue

		exists="`cat $f | awk '{if (($1 ~ /^scriptAlias/) && ($2 ~ /phppath/)) {print $3; next;}}'`"

		[ -n "$exists" ] && count="`expr $count + 1`" || continue

		echo $exists | grep -q '/usr/bin' && return 1
		echo $exists | grep -v wrapper | grep -q '/srv/www/cgi-bin' && return 1
        done

	return 0
}

parse_conf
check_install && quit

echo ""
echo "Your Plesk is affected by 'phppath' vulnerability."
echo ""
echo "Please apply fix from KB article http://kb.parallels.com/116241 if you have Parallels Plesk Panel 9.0-9.2.3 or Parallels Small Business Panel 10.x version."
echo "Contact Parallels Support Team if you have other Plesk version."
echo ""
exit 1
