#!/bin/bash usage() { printf "%s\n" \ "generate html page for available pocs" \ "usage: $(basename ${0}) -o -p " exit 1 } while getopts "o:p:h" opts; do case "${opts}" in o) output="${OPTARG}";; p) pocs="${OPTARG}";; h) usage;; *) usage;; esac done if test "${output}" && test "${pocs}"; then date=$(date -u "+%Y-%m-%d %H:%M:%S") mkdir -p "${output}" &>/dev/null if test -d pandoc/assets; then cp -r pandoc/assets "${output}" else printf "%s\n" "[err] pandoc/assets/ dir not found" exit 1 fi if command -v pandoc &>/dev/null; then count=$(cat "${pocs}/README.md" | wc -l) size=$(du -sh "${pocs}" | awk '{print $1}') if (tac "${pocs}/README.md" | pandoc \ -s \ --toc \ --metadata "title=cve proof of concepts" \ --metadata "date=${date} utc" \ --metadata "rss_url=https://cve.heqnx.com/feed.xml" \ --metadata "count=${count}" \ --metadata "size=${size}" \ --template pandoc/template.html \ --lua-filter=pandoc/add-target-blank.lua \ -o "${output}/index.html"); then \ printf "%s\n" "[inf] successfully generated html" else printf "%s\n" "[err] error generating html" fi if command -v tidy &>/dev/null; then if tidy --indent yes --wrap 0 -m --quiet yes --indent-spaces 2 --tidy-mark no "${output}/index.html"; then printf "%s\n" "[inf] prettified html" else printf "%s\n" "[err] failed to prettify html" fi else printf "%s\n" "[warn] tidy not found, skipping html prettify" fi else printf "%s\n" "[err] pandoc not found" exit 1 fi else usage fi