#!/bin/bash

# Puts in place safer configdaemon.conf if finds old version of file allowing something it shouldn't


#New installs should be safe
if [ "$1" == "new" ]; then
    exit 0;
fi

#Handle updating configs here
grep "bwctl-server.conf" /etc/perfsonar/toolkit/configdaemon.conf > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Replacing /etc/perfsonar/toolkit/configdaemon.conf"
cat > /etc/perfsonar/toolkit/configdaemon.conf <<- EOF
address     localhost
port        9000
firewall_script /usr/lib/perfsonar/scripts/system_environment/configure_firewall

<access>
    <service yum_cron> 
        restart     1 
        start       1 
        stop        1 
    </service>
    <service regular_testing>
        restart     1
        start       1
        stop        1
    </service>
    <service ndt>
        restart     1
        start       1
        stop        1
    </service>
    <service npad>
        restart     1
        start       1
        stop        1
    </service>
    <service owamp>
        restart     1
        start       1
        stop        1
    </service>
    <service bwctl>
        restart     1
        start       1
        stop        1
    </service>
    <service ls_registration_daemon>
        restart     1
        start       1
        stop        1
    </service>
    <service ntp>
        start       1
        stop        1
        restart     1
    </service>
    <file "/etc/ntp.conf">
        read    1
        write   1
    </file>
    <file "/etc/perfsonar/lsregistrationdaemon.conf">
        read    1
        write   1
    </file>
    <file "/usr/ndt/tcpbw100.html">
        read    1
        write   1
    </file>
    <file "/var/lib/npad/diag_form.html">
        read    1
        write   1
    </file>
    <file "/etc/perfsonar/toolkit/ntp_known_servers">
        read    1
        write   1
    </file>
    <file "/etc/ntp/step-tickers">
            read    1
            write   1
    </file>
    <file "/etc/perfsonar/regulartesting.conf">
            read    1
            write   1
    </file>
</access>
EOF

#centos 7 should not need this
/sbin/service perfsonar-configdaemon restart
fi
