From cf96c640330045e9d4ebca1129d2b868f42f8581 Mon Sep 17 00:00:00 2001 From: Bruno Ribas Date: Thu, 17 Aug 2017 23:16:18 -0300 Subject: Install logroot Also renames tools/cron-logroot.sh -> tools/boca-submit-logroot Signed-off-by: Bruno Ribas --- Makefile | 2 ++ tools/boca-submit-logroot | 61 +++++++++++++++++++++++++++++++++++++++++++++++ tools/cron-logroot | 1 + tools/cron-logroot.sh | 61 ----------------------------------------------- 4 files changed, 64 insertions(+), 61 deletions(-) create mode 100644 tools/boca-submit-logroot create mode 100644 tools/cron-logroot delete mode 100644 tools/cron-logroot.sh diff --git a/Makefile b/Makefile index d6aff30..586ba2a 100644 --- a/Makefile +++ b/Makefile @@ -40,6 +40,8 @@ install-submission-tools: tools/boca-submit-run-root-wrapper install tools/boca-submit-run-cron $(DESTDIR)/usr/bin/ install tools/boca-submit-run-aux $(DESTDIR)/usr/bin/ install tools/boca-submit-run-root $(DESTDIR)/usr/bin/ + install tools/boca-submit-logroot $(DESTDIR)/usr/sbin/boca-submit-logroot install tools/cron-submit $(DESTDIR)/etc/cron.d/ + install tools/cron-logroot $(DESTDIR)/etc/cron.d/ install tools/boca-submit-run-root-wrapper $(DESTDIR)/usr/bin/ chmod 4555 $(DESTDIR)/usr/bin/boca-submit-run-root-wrapper diff --git a/tools/boca-submit-logroot b/tools/boca-submit-logroot new file mode 100644 index 0000000..1199288 --- /dev/null +++ b/tools/boca-submit-logroot @@ -0,0 +1,61 @@ +#!/bin/bash + +if [ "`id -u`" != "0" ]; then + echo "Must be run as root" + exit 1 +fi +if [[ ! -e /etc/bocaip ]] ; then + BOCASERVER=50.116.19.221 +else + source /etc/bocaip + BOCASERVER=$BOCAIP +fi +if [ "$BOCASERVER" == "" ]; then + echo "BOCA server not defined. Aborting" + exit 1 +fi + +grep "session opened for user root" /var/log/auth.log |grep -v cron:session | grep -v systemd:session | tail -n 100 > /root/.logroot.tmp +[ -f /root/.logroot ] || touch /root/.logroot +diff /root/.logroot /root/.logroot.tmp > /root/.logroot.diff 2>/dev/null +res=$? +mv /root/.logroot.tmp /root/.logroot +if [ "$res" != "0" ]; then + for i in uuencode wget tr perl sha256sum cut; do + p=`which $i` + if [ -x "$p" ]; then + echo -n "" + else + echo "$i" not found + exit 1 + fi + done + temp=/root/.temp.`date +%s%N`.txt + md=`wget --no-check-certificate -t 2 -T 5 -S https://$BOCASERVER/boca/logexternal.php -O /dev/null --save-cookies ${temp}.cookie.txt --keep-session-cookies 2>&1 | grep PHPSESS | tail -n1` + echo "$md" | grep -q PHPSESS + if [ "$?" == "0" ]; then + md=`echo $md | cut -f2 -d'=' | cut -f1 -d';'` + res=`cat /root/submissions/code 2>/dev/null` + res=`echo -n "${res}${md}" | sha256sum - | cut -f1 -d' '` + + echo -n "comp=`cat /root/submissions/comp`" > $temp + echo -n "&code=$res" >> $temp + echo -n "&data=" >> $temp + grep "^>" /root/.logroot.diff | uuencode -m zzzzzzzzzz | grep -v "begin-base64.*zzzzzzzzzz" | perl -MURI::Escape -lne 'print uri_escape($_)' >> $temp + + wget --no-check-certificate -t 2 -T 5 "https://$BOCASERVER/boca/logexternal.php" --load-cookies ${temp}.cookie.txt --keep-session-cookies --save-cookies ${temp}.cookie.txt -O ${temp}.out --post-file=$temp >/dev/null 2>/dev/null + rm -f $temp + rm -f ${temp}.cookie.txt + grep -qi incorrect ${temp}.out + res=$? + rm ${temp}.out + if [ "$res" == "0" ]; then + echo "$BOCASERVER: User or password incorrect" + exit 3 + fi + else + echo "$BOCASERVER: connection failed" + exit 2 + fi +fi +exit 0 diff --git a/tools/cron-logroot b/tools/cron-logroot new file mode 100644 index 0000000..25816a9 --- /dev/null +++ b/tools/cron-logroot @@ -0,0 +1 @@ +* * * * * root /usr/sbin/boca-submit-logroot * >>/var/log/boca-submit-logroot.out 2>>/var/log/boca-submit-logroot.err diff --git a/tools/cron-logroot.sh b/tools/cron-logroot.sh deleted file mode 100644 index 1199288..0000000 --- a/tools/cron-logroot.sh +++ /dev/null @@ -1,61 +0,0 @@ -#!/bin/bash - -if [ "`id -u`" != "0" ]; then - echo "Must be run as root" - exit 1 -fi -if [[ ! -e /etc/bocaip ]] ; then - BOCASERVER=50.116.19.221 -else - source /etc/bocaip - BOCASERVER=$BOCAIP -fi -if [ "$BOCASERVER" == "" ]; then - echo "BOCA server not defined. Aborting" - exit 1 -fi - -grep "session opened for user root" /var/log/auth.log |grep -v cron:session | grep -v systemd:session | tail -n 100 > /root/.logroot.tmp -[ -f /root/.logroot ] || touch /root/.logroot -diff /root/.logroot /root/.logroot.tmp > /root/.logroot.diff 2>/dev/null -res=$? -mv /root/.logroot.tmp /root/.logroot -if [ "$res" != "0" ]; then - for i in uuencode wget tr perl sha256sum cut; do - p=`which $i` - if [ -x "$p" ]; then - echo -n "" - else - echo "$i" not found - exit 1 - fi - done - temp=/root/.temp.`date +%s%N`.txt - md=`wget --no-check-certificate -t 2 -T 5 -S https://$BOCASERVER/boca/logexternal.php -O /dev/null --save-cookies ${temp}.cookie.txt --keep-session-cookies 2>&1 | grep PHPSESS | tail -n1` - echo "$md" | grep -q PHPSESS - if [ "$?" == "0" ]; then - md=`echo $md | cut -f2 -d'=' | cut -f1 -d';'` - res=`cat /root/submissions/code 2>/dev/null` - res=`echo -n "${res}${md}" | sha256sum - | cut -f1 -d' '` - - echo -n "comp=`cat /root/submissions/comp`" > $temp - echo -n "&code=$res" >> $temp - echo -n "&data=" >> $temp - grep "^>" /root/.logroot.diff | uuencode -m zzzzzzzzzz | grep -v "begin-base64.*zzzzzzzzzz" | perl -MURI::Escape -lne 'print uri_escape($_)' >> $temp - - wget --no-check-certificate -t 2 -T 5 "https://$BOCASERVER/boca/logexternal.php" --load-cookies ${temp}.cookie.txt --keep-session-cookies --save-cookies ${temp}.cookie.txt -O ${temp}.out --post-file=$temp >/dev/null 2>/dev/null - rm -f $temp - rm -f ${temp}.cookie.txt - grep -qi incorrect ${temp}.out - res=$? - rm ${temp}.out - if [ "$res" == "0" ]; then - echo "$BOCASERVER: User or password incorrect" - exit 3 - fi - else - echo "$BOCASERVER: connection failed" - exit 2 - fi -fi -exit 0 -- cgit v1.2.3