diff --git a/client/Client.sh b/client/conf-client/exec.sh similarity index 51% rename from client/Client.sh rename to client/conf-client/exec.sh index f969161..2622eaf 100755 --- a/client/Client.sh +++ b/client/conf-client/exec.sh @@ -1,12 +1,13 @@ #!/bin/bash -cd $(dirname $0)/conf-client/ +cd $(dirname $0) SondeFile=$(pwd)/sonde.cfg source service.cfg +source functions -[[ "${Crypted}" == "yes" ]] && NcCmd="timeout 0.1 cryptcat -k ${LocalPassword} ${RemoteIp} ${RemotePort} ${Udp}" || NcCmd="timeout 0.1 nc ${RemoteIp} ${RemotePort}" +[[ "${Crypted}" == "yes" ]] && NcCmd="timeout 0.1 cryptcat -k ${LocalPassword} ${RemoteIp} ${RemotePort} " || NcCmd="timeout 0.1 nc ${RemoteIp} ${RemotePort}" while read DATA @@ -14,12 +15,10 @@ while read DATA Cmd=$(echo $DATA| cut -d"#" -f1) Arg=$(echo $DATA| cut -d"#" -f2) Res=$( echo -e "${Cmd}#${Arg}" | eval ${NcCmd} 2> /dev/null) - if [[ -z $Res ]] - then - echo "5|No sonde $Cmd on serveur $RemoteIp" - else - echo "$Res" - fi + Ret=$? + PrintRes "${Res:-5|No sonde $Cmd on serveur $RemoteIp}" + PrintWeb "${Res:-5|No sonde $Cmd on serveur $RemoteIp}" $Cmd $Arg done < ${SondeFile} +PrintWeb END_DNE diff --git a/client/conf-client/functions b/client/conf-client/functions new file mode 100644 index 0000000..743dabc --- /dev/null +++ b/client/conf-client/functions @@ -0,0 +1,59 @@ +#!/bin/bash +PrintRes() { + + echo "$1" + +} + +PrintWeb() { + + if [ ! -f /tmp/webmonithor ] + then + echo ' + + + MoniThor on '${RemoteIp}' + + + + Date : '$(date +'%Y-%m-%d %H:%M:%S')' + + + + + + + + +' > /tmp/webmonithor + + fi + + if [ "$1" == "END_DNE" ] + then + echo ' + + +
MoniThor Result
' >> /tmp/webmonithor + mv /tmp/webmonithor ../web/index.html + + else + + Val=$(echo $1 | cut -d"|" -f1) + Txt=$(echo $1 | cut -d"|" -f2) + Sonde=$2 + Arg=$3 + Color=red + [[ $Val == "0" ]] && Color=green + [[ $Val == "1" ]] && Color=yellow + + echo ' + + '$Sonde' + '$Arg' + '$Val' + '$Txt' +' >> /tmp/webmonithor + fi + +} diff --git a/client/conf-client/service.cfg b/client/conf-client/service.cfg index 37b6fd4..c184160 100644 --- a/client/conf-client/service.cfg +++ b/client/conf-client/service.cfg @@ -2,5 +2,7 @@ RemoteIp=127.0.0.1 RemotePort=8080 LocalPassword='Evil@MonitoR-666' Crypted=no +Rotation=1 +WebPort=8888 diff --git a/client/conf-client/webmonithor.html b/client/conf-client/webmonithor.html new file mode 100644 index 0000000..0152752 --- /dev/null +++ b/client/conf-client/webmonithor.html @@ -0,0 +1,44 @@ + + + Date : 2022-03-16 12:27:19 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
MoniThor Result
file/tmp/coucou 0 0
file/tmp/nop 0 0
file 5 5
tamerereboot 5 5
diff --git a/client/conf-client/webserver.sh b/client/conf-client/webserver.sh new file mode 100644 index 0000000..9fc07bf --- /dev/null +++ b/client/conf-client/webserver.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +pushd $(dirname $0)/../web/ +python -m SimpleHTTPServer ${1} + diff --git a/client/service.sh b/client/service.sh new file mode 100755 index 0000000..0bd280b --- /dev/null +++ b/client/service.sh @@ -0,0 +1,17 @@ +#!/bin/bash + + +source $(dirname $0)/conf-client/service.cfg + +if [[ -z $(ps axf| grep pyhton | grep ${WebPort}) ]] + then + bash ./conf-client/webserver.sh ${WebPort} & + fi + +while true + do + ./conf-client/exec.sh + sleep $Rotation + done + + diff --git a/client/web/index.html b/client/web/index.html new file mode 100644 index 0000000..72138ec --- /dev/null +++ b/client/web/index.html @@ -0,0 +1,49 @@ + + + + MoniThor on 127.0.0.1 + + + + Date : 2022-03-16 12:55:53 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
MoniThor Result
file/tmp/coucou 0 File /tmp/coucou exist
file/tmp/nop 2 File /tmp/nop is NOT present
file 5 no argument
tamerereboot 5 No sonde tamere on serveur 127.0.0.1
diff --git a/client/web/webmonithor.html b/client/web/webmonithor.html new file mode 100644 index 0000000..5015a96 --- /dev/null +++ b/client/web/webmonithor.html @@ -0,0 +1,44 @@ + + + Date : 2022-03-16 12:29:16 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
MoniThor Result
file/tmp/coucou 0 0
file/tmp/nop 0 0
file 5 5
tamerereboot 5 5
diff --git a/server/Daemon.sh b/server/Daemon.sh index 25feaaf..3140c06 100755 --- a/server/Daemon.sh +++ b/server/Daemon.sh @@ -24,6 +24,7 @@ while true 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