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

. /opt/lampp/share/lampp/lampplib

de="false"
case $LANG in
        de*) de="true";;
esac

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

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

ma=/opt/lampp/bin/mysqladmin
mm=/opt/lampp/bin/mysql

if test ! -f /opt/lampp/var/mysql/`/bin/hostname`.pid
then
	$check && exit 2
	$de && echo "LAMPP: MySQL mu gestartet sein um die Sicherheit berprfen zu knnen."
	$de || echo "LAMPP: MySQL has to run before I can check the security."
fi

if $ma -u root reload >/dev/null 2>&1
then	
	p=`echo "select Password from user where User='pma'" | /opt/lampp/bin/mysql -uroot -s mysql`
	if test -z "$p"
	then
		$check && exit 1

		$de && echo "LAMPP: ${bon}Der MySQL/phpMyAdmin-Benutzer pma hat kein Passwort gesetzt!!!${boff}"
		$de || echo "LAMPP: ${bon}The MySQL/phpMyAdmin user pma has no password set!!!${boff}"
		$de && q="Mchtest Du ein Pawort setzten?"
		$de || q="Do you want to set a password?"
		if asky "$q"
		then
			$de && q="Pawort:"
			$de || q="Password:"
			$de && q2="Pawort (Wiederholung):"
			$de || q2="Password (again):"
			word=`askp "$q" "$q2" nocrypt`

			$de && echo "LAMPP: MySQL pma-Pawort wird gndert."
			$de || echo "LAMPP: Setting new MySQL pma password."

			echo "update user set Password=password('$word') where User = 'pma';" | $mm -uroot mysql
			$ma -uroot reload

			$de && echo "LAMPP: Passe pma-Pawort-Einstellungen im phpMyAdmin an."
			$de || echo "LAMPP: Setting phpMyAdmin's pma password to the new one."

			f="/opt/lampp/phpmyadmin/config.inc.php"
		        $awk -vpw="$word" '
f==0 && $1 == "$cfg[\047Servers\047][$i][\047controlpass\047]" {
					print "# commented out by lampp security"
					print "#"$0
					print "$cfg[\047Servers\047][$i][\047controlpass\047] = \047"pw"\047;";
					f=1
					next
				}
				{
					print
				}
			' $f > /tmp/lampp$$
			cp /tmp/lampp$$ $f
			rm /tmp/lampp$$ 
		fi
	else
		$check && exit 0

		$de && echo "LAMPP: Der MySQL/phpMyAdmin-Benutzer pma hat ein Passwort. Prima! :)"
		$de || echo "LAMPP: The MySQL/phpMyAdmin user pma has a passwort set. Fine! :)"
	fi
fi
	
