#!/bin/sh
#
# OpenVAS Manager
# $Id$
# Description: Report generator script: ISM Verinice interface.
#
# Authors:
# Andre Heinecke <aheinecke@intevation.de>
#
# Copyright:
# Copyright (C) 2011 Greenbone Networks GmbH
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2,
# or, at your option, any later version as published by the Free
# Software Foundation
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.

TMP=`mktemp -d` || exit 1
STARTDIR=`pwd`
XMLFILE=`readlink -f $1`
DATE=$(date +%F-%H-%M-%S)

SCAN_NAME=`xmlstarlet sel -t -v /report/task/name "$XMLFILE"`

SCAN_NAME=$(echo $SCAN_NAME | sed 's/ /_/g')

mkdir -p  $TMP/files
FILENAME=${SCAN_NAME}_${DATE}.xml
FILELOC=$TMP/files/${FILENAME}
cp "$XMLFILE" "$FILELOC"
HTML_FILELOC=$(echo $FILELOC | sed 's/\.xml/\.html/')
HTML_FILE=$(echo $FILENAME | sed 's/\.xml/\.html/')



xsltproc ./html.xsl $1 > "$HTML_FILELOC"
xsltproc --stringparam filename "$FILENAME" \
         --stringparam htmlfilename "$HTML_FILE" \
         --stringparam filedate `stat -c %Z $XMLFILE` ./gsm_verinice_ism.xsl $1 | \
        sed -e "s/\ xmlns=\"\"//g" | \
        xmlstarlet fo >  $TMP/verinice.xml && \
cd $TMP && zip -r - *
cd $STARTDIR
rm -r $TMP
