#!/bin/bash
#
# test_certexpire
#
# Ablaufdatum von Zertifikatsdateien an ULS
#
##################################################
#
unset SETULSHOSTNAME
while getopts h:? op
 do
  case "$op" in
   h) SETULSHOSTNAME="$OPTARG";;
   ?) echo "usage: $(basename $0) [-h <hostname>] <section> <teststep> <certpath> [...]"
      exit 0;;
  esac
done
shift $(( $OPTIND - 1 ))
#
if [[ $# -lt 3 ]]
 then
  echo "usage: $(basename $0) [-h <hostname>] <section> <teststep> <certpath> [...]"
  exit 1
fi
#
if [[ -f /etc/uls/uls.conf ]]
 then
  . /etc/uls/uls.conf
fi
if [[ -z "$DOMAINHOSTNAME" ]]
 then
  DOMAINHOSTNAME="DOMAIN:`hostname -s`"
fi
if [[ -z "$ULSHOSTNAME" ]]
 then
  ULSHOSTNAME=`hostname -s`
fi
#
DT=`date '+%F %T%:z'`
#
( echo "D;$DT;${SETULSHOSTNAME:-$ULSHOSTNAME};$1;$2;"
  shift 2
  while [[ -n "$1" ]]
   do
    EXP=$(date -d "`openssl x509 -enddate -noout -in "$1" | sed -n 's/notAfter=//p'`" '+%F %T')
    if [[ -n "$EXP" ]]
     then
      FN=$(basename "$1")
      echo "V;;;;;$FN;$EXP;{DT};"
    fi
    shift
  done
) | send_test_tab
