#!/bin/sh -e
#
# Test if the webmin server is working.

if test -r /etc/debian-edu/config ; then
    . /etc/debian-edu/config
fi

# Only main-server profile run webmin
if echo "$PROFILE" | grep -q 'Main-Server' ; then
    :
else
    exit 0
fi

retval=0

if grep -q "^allow=$" /etc/webmin/miniserv.conf ; then
    echo "success: Correct allow line in /etc/webmin/miniserv.conf."
else
    echo "error: Incorrect allow line in /etc/webmin/miniserv.conf."
    retval=1
fi

port=10000
proto=tcp

if netstat -a 2>&1 | grep ":$port " | grep -q "^$proto" ; then
    echo "success: $0: webmin server is listening on $port/$proto."
else
    echo "error: $0: webmin server is not listening on $port/$proto."
    retval=1
fi

exit $retval
