#! /bin/sh

. $TS_GLOBAL

case "$1" in  
init)
  if ! pkg_initialized $PACKAGE; then

	WEB=/lib/www/html
	if pkg_initialized ica.init ;  then
	  ICA='<a href="\/cgi-bin\/ICA.cgi">ICA Configuration File<\/a><br>'
	fi
	if pkg_initialized xorg6vnc ; then
	  XORGVNC='<a href="http:\/\/'$CLIENT_IP':5800">Remote Control<\/a><br>'
	fi
	if pkg_initialized x ; then
	  XORG='<a href="\/cgi-bin\/XorgInfo.cgi">Xorg Configuration<\/a><br>
	  <a href="\/cgi-bin\/XorgLog.cgi">Xorg Log File<\/a><br>'
	fi

	echo s\@\$NET_REMOTE_ACCESS_FROM@$NET_REMOTE_ACCESS_FROM@g >> /tmp/script
	cat /etc/wwwadmin.tpl | sed -f /tmp/script > /etc/xinetd.d/wwwadmin
	cat /etc/wwwgeneral.tpl | sed -f /tmp/script > /etc/xinetd.d/wwwgeneral

	echo s/\${CLIENT_NAME}/`/bin/hostname`/g > /tmp/script
	echo s/\${TS_VERSION}/$TS_VERSION/g >> /tmp/script
	echo s/\${ICA}/$ICA/g >> /tmp/script
	echo s/\${XORGVNC}/$XORGVNC/g >> /tmp/script
	echo s/\${XORG}/$XORG/g >> /tmp/script
	cat $WEB/admin/index.html.tpl |sed -f /tmp/script >$WEB/admin/index.html
	cat $WEB/general/index.html.tpl |sed -f /tmp/script >$WEB/general/index.html

	rm /tmp/script

	pkg_set_init_flag $PACKAGE
  fi
  ;;
help)
    echo "Usage: $0 init"
    ;;
  *)
    exit 1
    ;;
esac

exit 0
