diff --git a/debs/index.html b/debs/index.html new file mode 100644 index 0000000..a386dce --- /dev/null +++ b/debs/index.html @@ -0,0 +1,10 @@ + + + MoniThor on + + +MONITHOR + +!!!! Initialization !!!! + + diff --git a/debs/monithor-client_1.0-0_noarch.deb b/debs/monithor-client_1.0-0_noarch.deb new file mode 100644 index 0000000..ff44d7c Binary files /dev/null and b/debs/monithor-client_1.0-0_noarch.deb differ diff --git a/debs/monithor-client_1.0-0_noarch/DEBIAN/control b/debs/monithor-client_1.0-0_noarch/DEBIAN/control new file mode 100644 index 0000000..6de64a4 --- /dev/null +++ b/debs/monithor-client_1.0-0_noarch/DEBIAN/control @@ -0,0 +1,6 @@ +Package: monithor-client +Version: 1.0 +Architecture: all +Dependsd:netcat,cryptcat,screen,python,netcat,cryptcat,elinks +Maintainer: Guillaume Astier +Description: monithor client (with simple http server python) diff --git a/debs/monithor-client_1.0-0_noarch/etc/init.d/monithor-c b/debs/monithor-client_1.0-0_noarch/etc/init.d/monithor-c new file mode 100755 index 0000000..4786787 --- /dev/null +++ b/debs/monithor-client_1.0-0_noarch/etc/init.d/monithor-c @@ -0,0 +1,37 @@ +#! /bin/sh + +### BEGIN INIT INFO +# Provides: monithor-c +# Default-Start: 2 3 4 5 +# Default-Stop: +# Short-Description: MoniThor Server +### END INIT INFO + +set -e + +test -x /usr/local/bin/monithor-client || exit 0 + +umask 022 + + +case "$1" in + start) + if [ ! -z $(ps axf| grep monithor-client | grep -v grep) ] + then + logger "monithor-client is running ..." + else + logger "Starting MoniThor Server" + /usr/local/bin/monithor-client start + fi + ;; + stop) + logger "Stoping MoniThor server" "monithor-c" || true + /usr/local/bin/monithor-client stop + ;; + + *) + echo "Usage: /etc/init.d/monithor-c {start|stop|status}" || true + exit 1 +esac + +exit 0 diff --git a/debs/monithor-client_1.0-0_noarch/etc/monithor-client/conf/Card_10.10.10.3-1666.cfg b/debs/monithor-client_1.0-0_noarch/etc/monithor-client/conf/Card_10.10.10.3-1666.cfg new file mode 100644 index 0000000..352b702 --- /dev/null +++ b/debs/monithor-client_1.0-0_noarch/etc/monithor-client/conf/Card_10.10.10.3-1666.cfg @@ -0,0 +1,4 @@ +10.10.10.3:1666#file#/tmp/coucou +10.10.10.3:1666#file#/tmp/nop +10.10.10.3:1666#file# +10.10.10.3:1666#NotRealSondeName#reboot diff --git a/debs/monithor-client_1.0-0_noarch/etc/monithor-client/conf/Card_10.10.10.4-1666.cfg b/debs/monithor-client_1.0-0_noarch/etc/monithor-client/conf/Card_10.10.10.4-1666.cfg new file mode 100644 index 0000000..8b0ba03 --- /dev/null +++ b/debs/monithor-client_1.0-0_noarch/etc/monithor-client/conf/Card_10.10.10.4-1666.cfg @@ -0,0 +1,4 @@ +10.10.10.4:1666#file#/tmp/coucou +10.10.10.4:1666#file#/tmp/nop +10.10.10.4:1666#file# +10.10.10.4:1666#NotRealSondeName#reboot diff --git a/debs/monithor-client_1.0-0_noarch/etc/monithor-client/service.cfg b/debs/monithor-client_1.0-0_noarch/etc/monithor-client/service.cfg new file mode 100644 index 0000000..de5b09b --- /dev/null +++ b/debs/monithor-client_1.0-0_noarch/etc/monithor-client/service.cfg @@ -0,0 +1,7 @@ +RemoteIp=10.10.10.3:1666 +LocalPassword='Evil@MonitoR-666' +Crypted=no +Rotation=1 +TimeOut=2 +WebPort=80 + diff --git a/debs/monithor-client_1.0-0_noarch/etc/monithor-client/sonde.cfg b/debs/monithor-client_1.0-0_noarch/etc/monithor-client/sonde.cfg new file mode 100644 index 0000000..adc506f --- /dev/null +++ b/debs/monithor-client_1.0-0_noarch/etc/monithor-client/sonde.cfg @@ -0,0 +1,8 @@ +10.10.10.3:1666#file#/tmp/coucou +10.10.10.3:1666#file#/tmp/nop +10.10.10.3:1666#file# +10.10.10.3:1666#NotRealSondeName#reboot +10.10.10.4:1666#file#/tmp/coucou +10.10.10.4:1666#file#/tmp/nop +10.10.10.4:1666#file# +10.10.10.4:1666#NotRealSondeName#reboot diff --git a/debs/monithor-client_1.0-0_noarch/usr/local/bin/monithor-client b/debs/monithor-client_1.0-0_noarch/usr/local/bin/monithor-client new file mode 100755 index 0000000..84b1e6f --- /dev/null +++ b/debs/monithor-client_1.0-0_noarch/usr/local/bin/monithor-client @@ -0,0 +1,31 @@ +#!/bin/bash + +source /etc/monithor-client/service.cfg +if [[ $(id -u) != "0" ]] + then + echo "Not Root" + exit +fi + + +if [[ "$1" == "start" ]] + then + [[ -f /tmp/endmonitor ]] && rm -f /tmp/endmonitor + rm /tmp/Monitor* /tmp/webmonithor &> /dev/null + + TotalConfig=$(ls -1 /etc/monithor-client/conf/ | grep Card_.*\.cfg|wc -l) + for Conf in $(ls -1 /etc/monithor-client/conf/ | grep Card_.*\.cfg) + do + screen -dmS ${Conf} bash /usr/local/bin/monithor-client.d/MoniThor ${Conf} + done + screen -dmS webserver bash /usr/local/bin/monithor-client.d/MoniThorWebServer ${WebPort} $TotalConfig +fi + +if [[ "$1" == "stop" ]] +then + killall python &> /dev/null + rm /tmp/Monithor* &> /dev/null + touch /tmp/endmonitor + +fi + diff --git a/debs/monithor-client_1.0-0_noarch/usr/local/bin/monithor-client.d/MoniThor b/debs/monithor-client_1.0-0_noarch/usr/local/bin/monithor-client.d/MoniThor new file mode 100755 index 0000000..805f881 --- /dev/null +++ b/debs/monithor-client_1.0-0_noarch/usr/local/bin/monithor-client.d/MoniThor @@ -0,0 +1,31 @@ +#!/bin/bash + + +SondeFile=/etc/monithor-client/sonde.cfg +source /etc/monithor-client/service.cfg +source /usr/local/bin/monithor-client.d/MoniThorFnct + +ConfFile=$1 + +[[ "${Crypted}" == "yes" ]] && NcCmd="timeout ${TimeOut} cryptcat -k ${LocalPassword} " || NcCmd="timeout ${TimeOut} nc " +while [[ ! -f /tmp/endmonitor ]] + do + if [[ -f /tmp/Monithor_${ConfFile}-tmp ]] + then + GenerateWebEnd /tmp/Monithor_${ConfFile}-tmp + sleep ${Rotation} + else + while read DATA + do + Remote=$(echo $DATA| cut -d"#" -f1| cut -d":" -f1) + Port=$(echo $DATA| cut -d"#" -f1| cut -d":" -f2) + Cmd=$(echo $DATA| cut -d"#" -f2) + Arg=$(echo $DATA| cut -d"#" -f3) + Res=$( echo -e "${Cmd}#${Arg}" | eval ${NcCmd} ${Remote} ${Port} 2> /dev/null) + Ret=$? + GenerateWeb "${Res:-5|No sonde $Cmd on serveur $Remote}" ${Cmd:-Nodata} ${Arg:-Noadata} ${Remote:-Nodata} /tmp/Monithor_${ConfFile}-tmp + done < /etc/monithor-client/conf/${ConfFile} + fi + done + + diff --git a/debs/monithor-client_1.0-0_noarch/usr/local/bin/monithor-client.d/MoniThorFnct b/debs/monithor-client_1.0-0_noarch/usr/local/bin/monithor-client.d/MoniThorFnct new file mode 100644 index 0000000..f8344fe --- /dev/null +++ b/debs/monithor-client_1.0-0_noarch/usr/local/bin/monithor-client.d/MoniThorFnct @@ -0,0 +1,76 @@ +#!/bin/bash +PrintRes() { + + echo "$1" + +} + + +CheckAllEnd() { + + if [[ ! -f /tmp/webmonithor ]] + then + Total=$1 + Actual=0 + for ActualFile in $(find /tmp/ -name Monithor_\*-tmp) + do + [[ ! -z $(tail -n 1 $ActualFile | grep 'End of') ]] && Actual=$((Actual + 1)) + done + + if [[ ${Total} -eq ${Actual} ]] + then + + echo ' + + + MoniThor on '${RemoteIp}' + + +MONITHOR + Date : '$(date +'%Y-%m-%d %H:%M:%S')' + + + + + + + ' > /tmp/webmonithor + + cat /tmp/Monithor_*-tmp >> /tmp/webmonithor + + echo ' + +
MoniThor Result
' >> /tmp/webmonithor + mv /tmp/webmonithor /var/www/html/monithor/index.html + rm /tmp/Monithor_* -f + fi + fi +} + +GenerateWebEnd(){ + echo '' >> $1 + +} + +GenerateWeb(){ + + Val=$(echo $1 | cut -d"|" -f1) + Txt=$(echo $1 | cut -d"|" -f2) + Sonde=$2 + Arg=$3 + Remote=$4 + File=$5 + Color=red + [[ $Val == "0" ]] && Color=green + [[ $Val == "1" ]] && Color=yellow + + echo ' + '$Remote' '$Sonde' '$Arg' '$Val' '$Txt' ' >> ${File} + + + +} + + + + diff --git a/debs/monithor-client_1.0-0_noarch/usr/local/bin/monithor-client.d/MoniThorWebServer b/debs/monithor-client_1.0-0_noarch/usr/local/bin/monithor-client.d/MoniThorWebServer new file mode 100644 index 0000000..ddffe78 --- /dev/null +++ b/debs/monithor-client_1.0-0_noarch/usr/local/bin/monithor-client.d/MoniThorWebServer @@ -0,0 +1,34 @@ +#!/bin/bash +[[ ! -d /var/www/html/monithor ]] && mkdir -p /var/www/html/monithor + +pushd /var/www/html/monithor +source /usr/local/bin/monithor-client.d/MoniThorFnct +python -m SimpleHTTPServer ${1} & + + +echo ' + + MoniThor on '${RemoteIp}' + + +MONITHOR + +!!!! Initialization !!!! + +' > index.html + +while [[ ! -f /tmp/endmonitor ]] + do + if [[ ! -z $(ls -1 /tmp/ | grep Monithor_.*-tmp) ]] + then + CheckAllEnd $2 + echo INSIDE + fi + sleep 1 + + done + + + + + diff --git a/debs/monithor-server_1.0-0_noarch.deb b/debs/monithor-server_1.0-0_noarch.deb new file mode 100644 index 0000000..7676284 Binary files /dev/null and b/debs/monithor-server_1.0-0_noarch.deb differ diff --git a/debs/monithor-server_1.0-0_noarch/DEBIAN/control b/debs/monithor-server_1.0-0_noarch/DEBIAN/control new file mode 100644 index 0000000..e7b9053 --- /dev/null +++ b/debs/monithor-server_1.0-0_noarch/DEBIAN/control @@ -0,0 +1,6 @@ +Package: monithor-server +Version: 1.0 +Architecture: all +Dependsd:netcat,cryptcat +Maintainer: Guillaume Astier +Description: monithor Server (nrpe like in netcat/cryptcat and bash) diff --git a/debs/monithor-server_1.0-0_noarch/etc/init.d/monithor-d b/debs/monithor-server_1.0-0_noarch/etc/init.d/monithor-d new file mode 100755 index 0000000..01635dc --- /dev/null +++ b/debs/monithor-server_1.0-0_noarch/etc/init.d/monithor-d @@ -0,0 +1,37 @@ +#! /bin/sh + +### BEGIN INIT INFO +# Provides: monithor-d +# Default-Start: 2 3 4 5 +# Default-Stop: +# Short-Description: MoniThor Server +### END INIT INFO + +set -e + +test -x /usr/local/bin/monithor-server || exit 0 + +umask 022 + + +case "$1" in + start) + if [ ! -z $(ps axf| grep monithor-server | grep -v grep) ] + then + logger "monithor-server is running ..." + else + logger "Starting MoniThor Server" + /usr/local/bin/monithor-server start + fi + ;; + stop) + logger "Stoping MoniThor server" "monithor-d" || true + /usr/local/bin/monithor-server stop + ;; + + *) + echo "Usage: /etc/init.d/monithor-d {start|stop|status}" || true + exit 1 +esac + +exit 0 diff --git a/debs/monithor-server_1.0-0_noarch/etc/monithor-server/service.cfg b/debs/monithor-server_1.0-0_noarch/etc/monithor-server/service.cfg new file mode 100644 index 0000000..c30893e --- /dev/null +++ b/debs/monithor-server_1.0-0_noarch/etc/monithor-server/service.cfg @@ -0,0 +1,5 @@ +LocalIp=127.0.0.1 +LocalPort=8080 +######### +Crypted=no +LocalPassword='Evil@MonitoR-666' diff --git a/debs/monithor-server_1.0-0_noarch/etc/monithor-server/sonde.cfg b/debs/monithor-server_1.0-0_noarch/etc/monithor-server/sonde.cfg new file mode 100644 index 0000000..187d780 --- /dev/null +++ b/debs/monithor-server_1.0-0_noarch/etc/monithor-server/sonde.cfg @@ -0,0 +1,3 @@ +network#ip.sh +file#file-present.sh + diff --git a/debs/monithor-server_1.0-0_noarch/usr/local/bin/monithor-server b/debs/monithor-server_1.0-0_noarch/usr/local/bin/monithor-server new file mode 100755 index 0000000..c15d295 --- /dev/null +++ b/debs/monithor-server_1.0-0_noarch/usr/local/bin/monithor-server @@ -0,0 +1,48 @@ +#!/bin/bash + + +ScriptDir=/usr/local/bin/monithor-server.d/ +SondeFile=/etc/monithor-server/sonde.cfg +source /etc/monithor-server/service.cfg + +[[ "${Crypted}" == "yes" ]] && NcCmd="cryptcat -k ${LocalPassword} -l ${LocalIp} -p ${LocalPort} " || NcCmd="nc -l ${LocalIp} ${LocalPort}" + +if [[ "${1}" == "start" ]] + then + while true + do + #coproc cryptcat -k ${LocalPassword} -l ${LocalIp} -p ${LocalPort} + coproc eval ${NcCmd} + while read -r cmd; do + logger "Running $cmd" + cpt=0 + while read DATA + do + Sonde=$(echo ${DATA}| cut -d"#" -f1) + Exec=$(echo ${DATA}| cut -d"#" -f2) + RealCmd=$(echo ${cmd} | cut -d"#" -f1) + ArgCmd=$(echo ${cmd} | cut -d"#" -f2) + if [[ "${RealCmd}" == "$Sonde" ]] + then + logger "Exec $Exec $Arg $cpt" + [ "$1" == '-d' ] && echo "############ Exec $Exec $Arg $cpt" 1>&2 + bash ${ScriptDir}/${Exec} $ArgCmd + cpt=$((cpt+1)) + break + fi + done < ${SondeFile} + [[ "${cpt}" -eq 0 ]] && logger "You Failed $Sonde $Exec $Arg" + + done <&"${COPROC[0]}" >&"${COPROC[1]}" + done & +fi + +if [[ "${1}" == "stop" ]] + then + + for Pid in $(ps axf| grep -E 'nc -l|monithor-server' | grep -v grep | awk '{print $1}' | sort ) + do + kill ${Pid} + done +fi + diff --git a/debs/monithor-server_1.0-0_noarch/usr/local/bin/monithor-server.d/FunctionOutput b/debs/monithor-server_1.0-0_noarch/usr/local/bin/monithor-server.d/FunctionOutput new file mode 100755 index 0000000..d642150 --- /dev/null +++ b/debs/monithor-server_1.0-0_noarch/usr/local/bin/monithor-server.d/FunctionOutput @@ -0,0 +1,9 @@ +Exit() { + + + Val=$(echo $1| cut -d"|" -f1) + Txt=$(echo $1| cut -d"|" -f2) + echo "$Val|$Txt" + exit $Val + +} diff --git a/debs/monithor-server_1.0-0_noarch/usr/local/bin/monithor-server.d/file-present.sh b/debs/monithor-server_1.0-0_noarch/usr/local/bin/monithor-server.d/file-present.sh new file mode 100755 index 0000000..1acbbea --- /dev/null +++ b/debs/monithor-server_1.0-0_noarch/usr/local/bin/monithor-server.d/file-present.sh @@ -0,0 +1,12 @@ +#!/bin/bash + + +source $(dirname $0)/FunctionOutput + +File="${1}" + +[[ -z ${File} ]] && Exit "5|no argument" + + +[[ -f ${File} ]] && Exit "0|File $File exist" || Exit "2|File $File is NOT present" +