Added handler for rate cards
This commit is contained in:
parent
738f25ba16
commit
1e1cc54208
124
chatops/bash/handler_ratecard
Normal file
124
chatops/bash/handler_ratecard
Normal file
@ -0,0 +1,124 @@
|
||||
#!/bin/bash
|
||||
|
||||
# handler_ratecard - builds PDF ratecards from thin air (using client_info.xml)
|
||||
#
|
||||
# This script is part of the PenText framework
|
||||
# https://pentext.org
|
||||
#
|
||||
# Copyright (C) 2016 Radically Open Security
|
||||
# https://www.radicallyopensecurity.com
|
||||
#
|
||||
# Author(s): Peter Mosmans
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
|
||||
|
||||
VERSION=0.1
|
||||
DOCBUILDER=/usr/local/bin/docbuilder.py
|
||||
TEMPLOC=$(mktemp -d)
|
||||
|
||||
# These variables should be set environment-specific
|
||||
[ -z $GITSERVER ] && GITSERVER=gitlab.local
|
||||
[ -z $GITWEB ] && GITWEB=https://${GITSERVER}
|
||||
[ -z $NAMESPACE ] && NAMESPACE=ros
|
||||
BRANCH=master
|
||||
TARGET=snippets/ratecard/ratecard
|
||||
|
||||
# Read standard 'command line' variables
|
||||
[[ ! -z $1 ]] && REPO=$1
|
||||
[[ ! -z $2 ]] && RATECARD=$2
|
||||
|
||||
# Reading positional parms is a bit ugly, shifting parms or getopt would be nicer
|
||||
if [[ ! -z $3 ]]; then
|
||||
if [[ ! $3 == -* ]]; then
|
||||
NAMESPACE=$3
|
||||
else
|
||||
PARMS=$3
|
||||
fi
|
||||
fi
|
||||
if [[ ! -z $4 ]]; then
|
||||
if [[ ! $3 == -* ]]; then
|
||||
BRANCH=$4
|
||||
else
|
||||
PARMS="$PARMS $4"
|
||||
fi
|
||||
fi
|
||||
if [[ $# -ge 5 ]]; then
|
||||
shift 4
|
||||
PARMS="$PARMS $@"
|
||||
fi
|
||||
trap cleanup EXIT QUIT
|
||||
|
||||
# Make sure that the temporary files are always removed
|
||||
cleanup() {
|
||||
trap '' EXIT INT QUIT
|
||||
[ -d $TEMPLOC ] && rm -rf $TEMPLOC &>/dev/null
|
||||
exit
|
||||
}
|
||||
|
||||
# As quote used to be called offerte or offer,
|
||||
# this function retains backward compatibility - v0.2
|
||||
backwards_compatible() {
|
||||
if [[ $TARGET == "quote" ]] && [ ! -f $TARGET.xml ]; then
|
||||
TARGET="offerte"
|
||||
fi
|
||||
}
|
||||
|
||||
# Clones repo using global (!) variables - v0.2
|
||||
clone_repo() {
|
||||
pushd $TEMPLOC 1>/dev/null
|
||||
git clone -b $BRANCH --depth=1 -q ssh://git@${GITSERVER}/${NAMESPACE}/${REPO}.git &>/dev/null
|
||||
if [ ! -d $TEMPLOC/$REPO ]; then
|
||||
echo "[-] could not clone repo ${NAMESPACE}/${REPO}"
|
||||
exit 1
|
||||
else
|
||||
cd $REPO
|
||||
fi
|
||||
}
|
||||
|
||||
# Preflight checks using global (!) variables - v0.2
|
||||
preflight_checks() {
|
||||
if [ -z $REPO ]; then
|
||||
echo "Usage: ratecard REPOSITORY [NAMESPACE [BRANCH]] [-v]"
|
||||
exit
|
||||
fi
|
||||
if [ ! -f $DOCBUILDER ]; then
|
||||
echo "[-] this script needs docbuilder.py ($DOCBUILDER)"
|
||||
fi
|
||||
}
|
||||
|
||||
build() {
|
||||
if [ ! -d source ]; then
|
||||
echo "[-] missing necessary pentext framework files"
|
||||
exit 1
|
||||
fi
|
||||
pushd source &>/dev/null
|
||||
backwards_compatible
|
||||
targetpdf=target/ratecard-latest.pdf
|
||||
$DOCBUILDER -c -i $TARGET.xml -o ../$targetpdf -x ../xslt/generate_ratecard.xsl --fop ../target/ratecard.fo $PARMS
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo "[-] Sorry, failed to generate $targetpdf"
|
||||
exit 1
|
||||
fi
|
||||
popd &>/dev/null
|
||||
if [ ! -f target/ratecard-latest.pdf ]; then
|
||||
echo "[-] hmmm... failed to build PDF file (could not find $targetpdf)"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
add_to_repo() {
|
||||
git add target/ratecard-latest.pdf
|
||||
git commit -q -m "Ratecard automatically generated using ChatOps" &>/dev/null
|
||||
git push -q >/dev/null
|
||||
}
|
||||
|
||||
preflight_checks
|
||||
echo "Ratecard v$VERSION - Congrats, another project from conception to ka-CHING"
|
||||
clone_repo
|
||||
build
|
||||
add_to_repo
|
||||
echo "[+] listo! Check out $GITWEB/$NAMESPACE/$REPO/raw/$BRANCH/$targetpdf"
|
||||
@ -192,6 +192,13 @@ module.exports = (robot) ->
|
||||
cmd = "bash/handler_invoice";
|
||||
run_cmd cmd, args, (text) -> msg.send text.replace("\n","");
|
||||
|
||||
robot.respond /ratecard (.*)/i, id:'chatops.ratecard', (msg) ->
|
||||
msg.match[0] = msg.match[0].replace(/^[a-z0-9]+$/i);
|
||||
msg.match.shift();
|
||||
args = msg.match[0].split(" ");
|
||||
cmd = "bash/handler_ratecard";
|
||||
run_cmd cmd, args, (text) -> msg.send text.replace("\n","");
|
||||
|
||||
robot.respond /quickscope (.*)/i, id:'chatops.quickscope', (msg) ->
|
||||
msg.match[0] = msg.match[0].replace(/^[a-z0-9]+$/i);
|
||||
msg.match.shift();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user