#!/bin/bash

# Alias: Host Attachments FTP / TFTP
# Menu: Addons
# Description:
#  Files transfered from hosts via ftp or tftp


case "$1" in
   default)
       echo "on"
   ;;
   choices)
       echo "on: use Host Attachments"
       echo "off: disable Host Attachments"
   ;;
   set)
        LOG_CFG=${OMD_ROOT}/etc/apache/conf.d/files.conf

        if [ "$2" == "on" ]; then

        cat > $LOG_CFG <<EOF
Alias /${OMD_SITE}/files "${OMD_ROOT}/local/share/files"

<Directory "/omd/sites/${OMD_SITE}/local/share/files">
  Options +Indexes +ExecCGI +FollowSymLinks
  AllowOverride None
  DirectoryIndex index.php
    <IfModule mod_access_compat.c>
        Order deny,allow
        Allow from all
    </IfModule>
    <IfModule !mod_access_compat.c>
        Require all granted
    </IfModule>
</Directory>
EOF


        mkdir -p ${OMD_ROOT}/local/share/files
        tar -C ${OMD_ROOT}/local/share/files -xzf /opt/ebs/files/files.tar.gz
	cp /opt/ebs/share/host_files/host_files.py /omd/sites/${OMD_SITE}/local/share/check_mk/web/plugins/icons/
        else
          [ -f $LOG_CFG ] && rm $LOG_CFG
        rm -rf ${OMD_ROOT}/local/share/files
	rm -rf ${OMD_ROOT}/local/share/check_mk/web/plugins/icons/host_files.py
        fi
        ;;
esac

