[UPDATE] - refact deb + generate

This commit is contained in:
2022-03-17 08:50:36 +01:00
parent 192382c8c2
commit d4300b4ca5
32 changed files with 68 additions and 256 deletions
+6
View File
@@ -0,0 +1,6 @@
Package: monithor-server
Version: 1.0
Architecture: all
Dependsd:netcat,cryptcat
Maintainer: Guillaume Astier <guillaume@gastier.net>
Description: monithor Server (nrpe like in netcat/cryptcat and bash)
+37
View File
@@ -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
@@ -0,0 +1,5 @@
LocalIp=127.0.0.1
LocalPort=8080
#########
Crypted=no
LocalPassword='Evil@MonitoR-666'
@@ -0,0 +1,3 @@
network#ip.sh
file#file-present.sh
+56
View File
@@ -0,0 +1,56 @@
#!/bin/bash
ScriptDir=/usr/local/bin/monithor-server.d/
SondeFile=/etc/monithor-server/sonde.cfg
source /etc/monithor-server/service.cfg
if [[ $(id -u) != "0" ]]
then
echo "Not Root"
exit
fi
[[ "${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
@@ -0,0 +1,9 @@
Exit() {
Val=$(echo $1| cut -d"|" -f1)
Txt=$(echo $1| cut -d"|" -f2)
echo "$Val|$Txt"
exit $Val
}
@@ -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"