#!/bin/bash
# Copyright 2002-2003 by Kai 'Oswald' Seidler, oswald@apachefriends.org, GPL-licensed

if test "x$XAMPP_ROOT" = "x"
then
	echo "Dont call this script directly!"
	exit 1
fi

. $XAMPP_ROOT/share/xampp/xampplib

if test "$1" = "check"
then    
        check="true"
else    
        check="false"
fi

lc="$XAMPP_ROOT/etc/xampp"
f="$XAMPP_ROOT/etc/proftpd.conf"

bon="[1m"
boff="[m"

if egrep "^UserPassword daemon 2TgxE8g184G9c" $f > /dev/null 2>&1
then
    $check && exit 1

	echo "XAMPP: ${bon}" $($GETTEXT "The FTP password for user 'daemon' is still set to 'xampp'.") "${boff}"
	if test ! -f $lc/startftp
	then
		echo "XAMPP: " $($GETTEXT "(But you didn't use ProFTPD so this is not critical.)")
	fi

	q=$($GETTEXT 'Do you want to change the password?')
	ask="asky";
else
    $check && exit 0

	echo "XAMPP: " $($GETTEXT 'ProFTPD has a new FTP password. Great!')
	q=$($GETTEXT 'Do you want to change the password anyway?')
	ask="askn";
fi

if $ask "$q"
then
	word=$(askp "$($GETTEXT 'Password:')" "$($GETTEXT 'Password (again):')")
	$awk -v pw="$word" '
/^UserPassword daemon 2TgxE8g184G9c/ {
		print "# commented out by xampp security"
		print "#"$0
		print "UserPassword daemon "pw
		next
	}
	{
		print
	}
' $f > /tmp/lampp$$
	cp /tmp/lampp$$ $f
	rm /tmp/lampp$$
	$XAMPP_ROOT/xampp reloadftp
fi
