[INIT] - add client & server

This commit is contained in:
Prof Isen 2022-03-16 10:02:26 +01:00
commit ec039ce26a
9 changed files with 104 additions and 0 deletions

11
README.md Normal file
View File

@ -0,0 +1,11 @@
# MoniThor
MoniThor is a simple monitoring tools in bash.
It used netcat encrypted version :
```
cryptcat
```

23
client/Client.sh Executable file
View File

@ -0,0 +1,23 @@
#!/bin/bash
cd $(dirname $0)/conf-client/
SondeFile=$(pwd)/sonde.cfg
source service.cfg
while read DATA
do
Cmd=$(echo $DATA| cut -d"#" -f1)
Arg=$(echo $DATA| cut -d"#" -f2)
Res=$(echo -e "${Cmd}#${Arg}" | timeout 0.1 cryptcat -k ${LocalPassword} ${RemoteIp} ${RemotePort} 2> /dev/null)
if [[ -z $Res ]]
then
echo "5|No sonde $Cmd on serveur $RemoteIp"
else
echo "$Res"
fi
done < ${SondeFile}

View File

@ -0,0 +1,4 @@
RemoteIp=127.0.0.1
RemotePort=8080
LocalPassword='Evil@MonitoR-666'

View File

@ -0,0 +1,4 @@
file#/tmp/coucou
file#/tmp/nop
file#
tamere#reboot

35
server/Daemon.sh Executable file
View File

@ -0,0 +1,35 @@
#!/bin/bash
cd $(dirname $0)/conf-server/
ScriptDir=$(pwd)/scripts/
SondeFile=$(pwd)/sonde.cfg
source service.cfg
echo "coproc cryptcat -k "${LocalPassword}" -l ${LocalIp} ${LocalPort}"
while true
do
coproc cryptcat -k ${LocalPassword} -l ${LocalIp} -p ${LocalPort}
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"
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

View File

@ -0,0 +1,9 @@
Exit() {
Val=$(echo $1| cut -d"|" -f1)
Txt=$(echo $1| cut -d"|" -f2)
echo "$Val|$Txt"
exit $Val
}

View File

@ -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"

View File

@ -0,0 +1,3 @@
LocalIp=127.0.0.1
LocalPort=8080
LocalPassword='Evil@MonitoR-666'

View File

@ -0,0 +1,3 @@
network#ip.sh
file#file-present.sh