#!/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"


f="/opt/lampp/etc/my.cnf"

p=`awk '
/^\[mysqld\]/,/^\[mysqldump\]/ { 
		if($1=="port")
		{
			print $3
		}
	}
' $f`

if test "$p" -gt 0
then
        $check && exit 1

	$de && echo "LAMPP: ${bon}MySQL ist ber's Netzwerk erreichbar.${boff}"
	$de || echo "LAMPP: ${bon}MySQL is accessable via network.${boff}"
        $de && q="Normalerweise wird dies nicht bentigt. Soll ich es abschalten?"
        $de || q="Normaly that's not recommended. Do you want me to turn it off?"
        if asky "$q"
	then
		$awk '
		/^\[mysqld\]/,/^\[mysqldump\]/ { 
				if($1=="port")
				{
					print "# commented out by lampp security"
					print "#"$0
					print "port = 0"
					next
				}
			}
			{
				print
			}
		' $f > /tmp/lampp$$
		cp /tmp/lampp$$ $f
		rm /tmp/lampp$$ 
		$de && echo "LAMPP: Abgeschaltet!"
		$de || echo "LAMPP: Turned off."
		if test -f /opt/lampp/var/mysql/`/bin/hostname`.pid
		then
			/opt/lampp/lampp stopmysql
			sleep 2
			/opt/lampp/lampp startmysql
			sleep 5
		fi
	fi
else
        $check && exit 0

	$de && echo "LAMPP: MySQL ist nicht ber's Netzwerk erreichbar. Gut!"
	$de || echo "LAMPP: MySQL is not accessable via network. Good."
fi

