diff --git a/nmap-parse-output b/nmap-parse-output index 969dbf4..a48efe6 100755 --- a/nmap-parse-output +++ b/nmap-parse-output @@ -10,21 +10,25 @@ while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symli done SCRIPT_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" -XSLT_DIR=$SCRIPT_DIR/nmap-parse-output-xslt +XSLT_DIR="$SCRIPT_DIR/nmap-parse-output-xslt" # functions (mostly for help) function xml_node_text() { - xmllint --xpath "//*[local-name()='$2' and namespace-uri()='http://xmlns.sven.to/npo']/text()" $1 2>/dev/null + # $1 = file, $2 = node + xmllint --xpath "//*[local-name()='$2' and namespace-uri()='http://xmlns.sven.to/npo']/text()" "$1" 2>/dev/null } function print_command_category() { echo "$1 Commands:" - for fullf in $XSLT_DIR/*.xslt; do - if [ "$(xml_node_text $fullf category)" == "$2" ] + for fullf in "$XSLT_DIR"/*.xslt; do + # If the glob didn't match any file, it will expand literally; skip in that case. + [ ! -f "$fullf" ] && continue + + if [ "$(xml_node_text "$fullf" category)" == "$2" ] then - f=$(basename $fullf) + f=$(basename "$fullf") echo -e -n " ${f%.*} " - xml_node_text $fullf comment || echo -e "\n\t(No documentation)" + xml_node_text "$fullf" comment || echo -e "\n\t(No documentation)" fi done echo @@ -56,8 +60,6 @@ UNFINISHED_SCAN="" while [ $# -gt 0 ] do - CURRENT_PARAM=$1 - case "$1" in --help|-h) help @@ -76,14 +78,19 @@ done [ $# -lt 2 ] && help # check if input is readable -NMAP_XML_OUTPUT=$1 -[ -f "$NMAP_XML_OUTPUT" -o "$NMAP_XML_OUTPUT" = "-" ] || { echo "Can't read nmap file: $NMAP_XML_OUTPUT. Aborting." >&2; exit 1; } +NMAP_XML_OUTPUT="$1" +if [ -f "$NMAP_XML_OUTPUT" ] || [ "$NMAP_XML_OUTPUT" = "-" ]; then + : +else + echo "Can't read nmap file: $NMAP_XML_OUTPUT. Aborting." >&2 + exit 1 +fi -XSLT=$XSLT_DIR/$2.xslt -[ -f $XSLT ] || { echo "Unknown command: $2. Aborting." >&2; exit 1; } +XSLT="$XSLT_DIR/$2.xslt" +[ -f "$XSLT" ] || { echo "Unknown command: $2. Aborting." >&2; exit 1; } # read post process command from xslt -POST_PIPE=$(xml_node_text $XSLT post-processor) +POST_PIPE=$(xml_node_text "$XSLT" post-processor) if [ -z "$POST_PIPE" ] then POST_PIPE="cat - "