[UPDATE] add web server python

This commit is contained in:
Prof Isen 2022-03-16 12:56:20 +01:00
parent 852c50002d
commit 9b2ae01b4a
9 changed files with 228 additions and 8 deletions

View File

@ -1,12 +1,13 @@
#!/bin/bash #!/bin/bash
cd $(dirname $0)/conf-client/ cd $(dirname $0)
SondeFile=$(pwd)/sonde.cfg SondeFile=$(pwd)/sonde.cfg
source service.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 while read DATA
@ -14,12 +15,10 @@ while read DATA
Cmd=$(echo $DATA| cut -d"#" -f1) Cmd=$(echo $DATA| cut -d"#" -f1)
Arg=$(echo $DATA| cut -d"#" -f2) Arg=$(echo $DATA| cut -d"#" -f2)
Res=$( echo -e "${Cmd}#${Arg}" | eval ${NcCmd} 2> /dev/null) Res=$( echo -e "${Cmd}#${Arg}" | eval ${NcCmd} 2> /dev/null)
if [[ -z $Res ]] Ret=$?
then PrintRes "${Res:-5|No sonde $Cmd on serveur $RemoteIp}"
echo "5|No sonde $Cmd on serveur $RemoteIp" PrintWeb "${Res:-5|No sonde $Cmd on serveur $RemoteIp}" $Cmd $Arg
else
echo "$Res"
fi
done < ${SondeFile} done < ${SondeFile}
PrintWeb END_DNE

View File

@ -0,0 +1,59 @@
#!/bin/bash
PrintRes() {
echo "$1"
}
PrintWeb() {
if [ ! -f /tmp/webmonithor ]
then
echo '
<html>
<head>
<title>MoniThor on '${RemoteIp}' </title>
<meta http-equiv="refresh" content="'${Rotation}'" />
</head>
Date : '$(date +'%Y-%m-%d %H:%M:%S')'
<table border="1" color="#FFFFFF">
<thead>
<tr>
<th colspan="4">MoniThor Result</th>
</tr>
</thead>
<tbody>
' > /tmp/webmonithor
fi
if [ "$1" == "END_DNE" ]
then
echo '
</tbody>
</table> ' >> /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 '
<tr>
<td>'$Sonde'</td>
<td>'$Arg'</td>
<td style="background-color:'${Color}';" > '$Val' </td>
<td> '$Txt'</td>
</tr>' >> /tmp/webmonithor
fi
}

View File

@ -2,5 +2,7 @@ RemoteIp=127.0.0.1
RemotePort=8080 RemotePort=8080
LocalPassword='Evil@MonitoR-666' LocalPassword='Evil@MonitoR-666'
Crypted=no Crypted=no
Rotation=1
WebPort=8888

View File

@ -0,0 +1,44 @@
Date : 2022-03-16 12:27:19
<table>
<thead>
<tr>
<th colspan="2">MoniThor Result</th>
</tr>
</thead>
<tbody>
<tr>
<td>file</td>
<td>/tmp/coucou</td>
<td> 0 </td>
<td> 0</td>
</tr>
<tr>
<td>file</td>
<td>/tmp/nop</td>
<td> 0 </td>
<td> 0</td>
</tr>
<tr>
<td>file</td>
<td></td>
<td> 5 </td>
<td> 5</td>
</tr>
<tr>
<td>tamere</td>
<td>reboot</td>
<td> 5 </td>
<td> 5</td>
</tr>
</tbody>
</table>

View File

@ -0,0 +1,5 @@
#!/bin/bash
pushd $(dirname $0)/../web/
python -m SimpleHTTPServer ${1}

17
client/service.sh Executable file
View File

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

49
client/web/index.html Normal file
View File

@ -0,0 +1,49 @@
<html>
<head>
<title>MoniThor on 127.0.0.1 </title>
<meta http-equiv="refresh" content="1" />
</head>
Date : 2022-03-16 12:55:53
<table border="1" color="#FFFFFF">
<thead>
<tr>
<th colspan="4">MoniThor Result</th>
</tr>
</thead>
<tbody>
<tr>
<td>file</td>
<td>/tmp/coucou</td>
<td style="background-color:green;" > 0 </td>
<td> File /tmp/coucou exist</td>
</tr>
<tr>
<td>file</td>
<td>/tmp/nop</td>
<td style="background-color:red;" > 2 </td>
<td> File /tmp/nop is NOT present</td>
</tr>
<tr>
<td>file</td>
<td></td>
<td style="background-color:red;" > 5 </td>
<td> no argument</td>
</tr>
<tr>
<td>tamere</td>
<td>reboot</td>
<td style="background-color:red;" > 5 </td>
<td> No sonde tamere on serveur 127.0.0.1</td>
</tr>
</tbody>
</table>

View File

@ -0,0 +1,44 @@
Date : 2022-03-16 12:29:16
<table border="1" color='#FFFFFF' >
<thead>
<tr>
<th colspan="4">MoniThor Result</th>
</tr>
</thead>
<tbody>
<tr>
<td>file</td>
<td>/tmp/coucou</td>
<td> 0 </td>
<td> 0</td>
</tr>
<tr>
<td>file</td>
<td>/tmp/nop</td>
<td> 0 </td>
<td> 0</td>
</tr>
<tr>
<td>file</td>
<td></td>
<td style="background-color:red;" > 5 </td>
<td> 5</td>
</tr>
<tr>
<td>tamere</td>
<td>reboot</td>
<td> 5 </td>
<td> 5</td>
</tr>
</tbody>
</table>

View File

@ -24,6 +24,7 @@ while true
if [[ "${RealCmd}" == "$Sonde" ]] if [[ "${RealCmd}" == "$Sonde" ]]
then then
logger "Exec $Exec $Arg $cpt" logger "Exec $Exec $Arg $cpt"
[ "$1" == '-d' ] && echo "############ Exec $Exec $Arg $cpt" 1>&2
bash ${ScriptDir}/${Exec} $ArgCmd bash ${ScriptDir}/${Exec} $ArgCmd
cpt=$((cpt+1)) cpt=$((cpt+1))
break break