#!/usr/bin/wsrunxslt /config/wsxmlconf/system.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
	Script for starting load sharing
	Copyright (C) 2004 Networks Associates Technology Inc.
	All rights reserved.
-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:param name="param_0">start</xsl:param>

<xsl:template match="/">
    <xsl:choose>
        <xsl:when test="$param_0='start'">
	    <xsl:call-template name="start"/>
        </xsl:when>
        <xsl:when test="$param_0='stop'">
	    <xsl:call-template name="stop"/>
        </xsl:when>
        <xsl:when test="$param_0='restart' or $param_0='reload'">
	    <xsl:call-template name="stop"/>
	    <xsl:call-template name="start"/>
        </xsl:when>
	<xsl:otherwise>
	    echo "invalid option:<xsl:value-of select='$param_0'/>"
	    echo "valid options: start|stop|restart|reload"
	</xsl:otherwise>
     </xsl:choose>
     exit 0
</xsl:template>

<xsl:template name="stop">
<xsl:text>
    /usr/bin/killall -q -HUP wsstatd 
    /bin/rm -f /tmp/cpunifo 
    /bin/rm -f /tmp/realtime.txt
    sleep 1
    /usr/bin/killall -q wsstatd 
</xsl:text>
</xsl:template>

<xsl:template name="start">
    <xsl:for-each select="/PolicySet/GlobalSettings[@name='system']/Policy[@name='system_variables']/PolicyStatement/Settings[@name='realtime-monitor-settings']">
       <xsl:call-template name="realtime-monitor-settings"/>
    </xsl:for-each>
</xsl:template>

<xsl:template name="realtime-monitor-settings">
    
    <xsl:choose>
	<xsl:when test="Attr[@name='Enabled']/@value='1'">
            <xsl:call-template name="run-monitoring"/>
        </xsl:when>
    </xsl:choose>
</xsl:template>

<xsl:template name="run-monitoring">
<xsl:text>. /var/NAIENV/.profile.vars&#10;</xsl:text>
<xsl:text>PROXY_MONITOR=&#10;</xsl:text>

<xsl:call-template name="monitor-proxy">
    <xsl:with-param name="proxy">ftp</xsl:with-param>
</xsl:call-template>

<xsl:call-template name="monitor-proxy">
    <xsl:with-param name="proxy">http</xsl:with-param>
</xsl:call-template>

<xsl:call-template name="monitor-proxy">
    <xsl:with-param name="proxy">smtp</xsl:with-param>
</xsl:call-template>

<xsl:call-template name="monitor-proxy">
    <xsl:with-param name="proxy">pop3</xsl:with-param>
</xsl:call-template>
<xsl:text>/usr/sbin/webshield disk_settings.xsl|</xsl:text>
<xsl:text>/usr/sbin/webshield wsstatd ${PROXY_MONITOR}</xsl:text>
<xsl:text> --logdir </xsl:text>
<xsl:value-of select="Attr[@name='Directory']/@value"/><xsl:text> </xsl:text>
<xsl:text> --history </xsl:text>
<xsl:value-of select="Attr[@name='MaxAge']/@value"/><xsl:text> </xsl:text>
<xsl:text> --interval </xsl:text>
<xsl:value-of select="Attr[@name='FileInterval']/@value"/><xsl:text> </xsl:text>
<xsl:text> --proxydowntime </xsl:text>
<xsl:value-of select="Attr[@name='ProxyDownTime']/@value"/><xsl:text> </xsl:text>
<xsl:text>&#10;</xsl:text>
</xsl:template>

<xsl:template name="monitor-proxy">
<xsl:param name="proxy"/>
<xsl:text>STATUS=`xsltproc --stringparam proxy </xsl:text>
<xsl:value-of select="$proxy"/>
<xsl:text> ${WSMGMT}/proxy_cf.xsl ${XMLCONFDIR}/</xsl:text>
<xsl:value-of select="$proxy"/>
<xsl:text>.xml`&#10;</xsl:text>
<xsl:text>PROXY_MONITOR=&quot;${PROXY_MONITOR} $STATUS&quot;&#10;</xsl:text>
</xsl:template>


</xsl:stylesheet>
