diff options
| author | cassio <cassiopc@gmail.com> | 2015-08-30 22:11:57 +0000 |
|---|---|---|
| committer | cassio <cassiopc@gmail.com> | 2015-08-30 22:11:57 +0000 |
| commit | dd3152be0442e577692067c5523da4f5ab9d9957 (patch) | |
| tree | dd11e8e3bd71404dd7675b8bc8d49f3655a0df61 /tools | |
| parent | 9a3077369831bc66fd51bc9c5c276980dd74e046 (diff) | |
| download | boca-dd3152be0442e577692067c5523da4f5ab9d9957.tar.gz boca-dd3152be0442e577692067c5523da4f5ab9d9957.zip | |
multiple bugs to make submission by command line
Diffstat (limited to 'tools')
| -rwxr-xr-x | tools/boca-submit-run | 29 | ||||
| -rwxr-xr-x | tools/boca-submit-run-aux | 53 | ||||
| -rwxr-xr-x | tools/boca-submit-run-cron | 8 | ||||
| -rwxr-xr-x | tools/boca-submit-run-root | 22 | ||||
| -rwxr-xr-x | tools/etc/icpc/bocaserver.sh | 1 | ||||
| -rwxr-xr-x | tools/etc/icpc/installboca.sh | 39 | ||||
| -rwxr-xr-x | tools/etc/icpc/setup.sh | 3 | ||||
| -rw-r--r-- | tools/etc/icpc/update.sh.tmp | 40 | ||||
| -rw-r--r-- | tools/etc/network/if-pre-up.d/boca | 2 | ||||
| -rwxr-xr-x | tools/install_14_04_3.sh | 3 | ||||
| -rwxr-xr-x | tools/installv2.sh | 3 |
11 files changed, 115 insertions, 88 deletions
diff --git a/tools/boca-submit-run b/tools/boca-submit-run index 78e79bd..d67c83f 100755 --- a/tools/boca-submit-run +++ b/tools/boca-submit-run @@ -42,30 +42,33 @@ fi runaux=`which boca-submit-run-aux` if [ "$runaux" == "" ]; then - runaux=/var/www/boca/tools/boca-submit-run-aux + runaux=/usr/bin/boca-submit-run-aux fi -runroot=`which boca-submit-run-root` +runroot=`which boca-submit-run-root-wrapper` if [ "$runroot" == "" ]; then - runroot=/var/www/boca/tools/boca-submit-run-root + runroot=/usr/bin/boca-submit-run-root-wrapper fi if [ -r "$5" ]; then nom=`echo -n "$5" | perl -MURI::Escape -lne 'print uri_escape($_)'` - for BOCASERVER in `echo $BOCASERVERS | cut -d';'`; do - echo "$BOCASERVER: time-out - this will automatically retry soon, you should not worry" + for BOCASERVER in `echo $BOCASERVERS | tr ';' ' '`; do echo "BOCASERVER=$BOCASERVER" > $temp - echo "user=$user" >> $temp - echo "pass=$pass" >> $temp - echo "name=${nom}" >> $temp - echo -n "data=" >> $temp - uuencode -m zzzzzzzzzz < "$5" | grep -v "begin-base64.*zzzzzzzzzz" | perl -MURI::Escape -lne 'print uri_escape($_)' >> $temp - echo "" >> $temp + echo "user=$1" >> $temp + echo "pass=$2" >> $temp + echo "problem=$3" >> $temp + echo "language=$4" >> $temp + echo "name=`basename $5`" >> $temp + uniq=`sha256sum "$5" | cut -f1 -d' '` + echo "uniq=$uniq" >> $temp + echo -en "data=\"" >> $temp + uuencode -m zzzzzzzzzz < "$5" | grep -v "begin-base64.*zzzzzzzzzz" >> $temp + echo -e "\"" >> $temp $runaux $temp if [ "$?" == "2" ]; then echo "$BOCASERVER: time-out - this will automatically retry soon, you should not worry" - $runroot $temp + $runroot "$BOCASERVER" "$1" "$2" "$3" "$4" "`basename $5`" "$5" fi - rm $temp + [ -f "$temp" ] && rm -f $temp done else echo "file $1 not found/readable" diff --git a/tools/boca-submit-run-aux b/tools/boca-submit-run-aux index a9ff432..1be0945 100755 --- a/tools/boca-submit-run-aux +++ b/tools/boca-submit-run-aux @@ -5,6 +5,10 @@ if [ "$BOCASERVER" == "" -o "$user" == "" -o "$pass" == "" -o "$data" == "" -o " echo "parameters missing in file $1" exit 1 fi +if [ "$problem" == "" -o "$language" == "" ]; then + echo "parameters missing in file $1" + exit 1 +fi for i in uuencode wget tr perl sha256sum cut; do p=`which $i` @@ -17,49 +21,64 @@ for i in uuencode wget tr perl sha256sum cut; do done temp=/tmp/.temp.`date +%s%N`.txt -md=`wget -t 2 -T 7 -S http://$BOCASERVER/boca/index.php -O /dev/null --save-cookies /tmp/.cookie.txt --keep-session-cookies 2>&1 | grep PHPSESS | tail -n1` +md=`wget -t 2 -T 5 -S http://$BOCASERVER/boca/index.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=`echo -n $pass | sha256sum - | cut -f1 -d' '` res=`echo -n "${res}${md}" | sha256sum - | cut -f1 -d' '` - wget -t 2 -T 7 "http://$BOCASERVER/boca/index.php?name=${user}&password=${res}" --load-cookies /tmp/.cookie.txt --keep-session-cookies --save-cookies /tmp/.cookie.txt -O $temp 2>/dev/null >/dev/null + wget -t 2 -T 5 "http://$BOCASERVER/boca/index.php?name=${user}&password=${res}" --load-cookies ${temp}.cookie.txt --keep-session-cookies --save-cookies ${temp}.cookie.txt -O $temp 2>/dev/null >/dev/null grep -qi incorrect $temp if [ $? == 0 ]; then echo "$BOCASERVER: User or password incorrect" rm -f $temp - rm -f /tmp/.cookie.txt + rm -f ${temp}.cookie.txt exit 3 else - echo -n "name=${nom}" > $temp + echo -n "name=`echo $name | perl -MURI::Escape -lne 'print uri_escape($_)'`" > $temp if [ "$uniq" != "" ]; then echo -n "&pastcode=$uniq" >> $temp if [ "$code" != "" ]; then echo -n "&pasthash=$code" >> $temp - if [ "$dateerr" != "" ]; then - echo -n "&pastabs=${dateerr}" - let "dateerr = `date +%s` - $dateerr" - echo -n "&pastval=${dateerr}" + fi + if [ "$dateerr" != "" ]; then + echo -n "&pastabs=${dateerr}" >> $temp + let "dateerr = `date +%s` - $dateerr" + echo -n "&pastval=${dateerr}" >> $temp + if [ -r /root/submissions/code ]; then + code=`cat /root/submissions/code` + res=`echo -n "${code}${uniq}${dateerr}" | sha256sum - | cut -f1 -d' '` + echo -n "&pastvalhash=${res}" >> $temp fi fi fi - - echo -n "&data=" >> $temp - uuencode -m zzzzzzzzzz < $1 | grep -v "begin-base64.*zzzzzzzzzz" | perl -MURI::Escape -lne 'print uri_escape($_)' >> $temp - wget -t 2 -T 7 "http://$BOCASERVER/boca/team/run.php" --load-cookies /tmp/.cookie.txt --keep-session-cookies -O /dev/null --post-file=$temp >${temp}.out 2>/dev/null + echo -n "&problem=`echo $problem | perl -MURI::Escape -lne 'print uri_escape($_)'`" >> $temp + echo -n "&language=`echo $language | perl -MURI::Escape -lne 'print uri_escape($_)'`" >> $temp + echo -n "&data=`echo $data | tr -d ' ' | perl -MURI::Escape -lne 'print uri_escape($_)'`" >> $temp + wget -t 2 -T 5 "http://$BOCASERVER/boca/team/run.php" --load-cookies ${temp}.cookie.txt --keep-session-cookies -O ${temp}.out --post-file=$temp >/dev/null 2>/dev/null res=`tail -n1 ${temp}.out` echo $res | grep -q "RESULT:" if [ "$?" == "0" ]; then - echo "$BOCASERVER : run $uniq dateerr $dateerr : $res" - rm -f "$1" + if [ "$uniq" == "" ]; then + echo "$BOCASERVER : $res" + else + echo "$BOCASERVER : run $uniq dateerr $dateerr : $res" + fi else - echo "$BOCASERVER : run $uniq dateerr $dateerr : error to upload the run, will NOT try again, check details" + if [ "$uniq" == "" ]; then + echo "$BOCASERVER : error to upload the run, will NOT try again, check details" + else + echo "$BOCASERVER : run $uniq dateerr $dateerr : error to upload the run, will NOT try again, check details:" + cat ${temp}.out + fi + rm -f ${temp}.out + exit 4 fi rm -f ${temp}.out fi - rm -f $temp - rm -f /tmp/.cookie.txt + [ -f "$temp" ] && rm -f "$temp" + rm -f ${temp}.cookie.txt else exit 2 fi diff --git a/tools/boca-submit-run-cron b/tools/boca-submit-run-cron index 83f5b41..64d55ee 100755 --- a/tools/boca-submit-run-cron +++ b/tools/boca-submit-run-cron @@ -15,6 +15,14 @@ if [ -d /root/submissions ]; then for i in `ls /root/submissions/*.bocarun`; do if [ "$i" != "/root/submissions/placeholder.bocarun" ]; then $runaux "$i" + res=$? + if [ "$res" == "2" ]; then + echo "$i: time-out - this will automatically retry soon" + fi + if [ "$res" == "0" ]; then + mv "$i" "${i}.processed" + fi fi done fi + diff --git a/tools/boca-submit-run-root b/tools/boca-submit-run-root index a6d205a..4cc2231 100755 --- a/tools/boca-submit-run-root +++ b/tools/boca-submit-run-root @@ -5,18 +5,26 @@ if [ "`id -u`" != "0" ]; then exit 1 fi -fnam=`echo "$1" | tr -cd '[[:alnum:]]._-/'` -if [ "$fnam" != "" -a -r "$fnam" ]; then +if [ "$7" != "" ]; then mkdir -p /root/submissions chown root /root/submissions chmod 700 /root/submissions nom=/root/submissions/`date +%s%N`.bocarun.tmp - cat "$fnam" | tr -cd '[[:alnum:]]._+-/= ' > "$nom" - - echo "dateerr=`date +%s`" >> "$nom" - uniq=`date +%sN`-`sha256sum "$1"` - uniq=`echo $uniq | sha256sum - | cut -f1 -d' '` + echo "BOCASERVER=`echo $1 | tr -cd '[[:alnum:]]._+-/'`" > "$nom" + echo "user=`echo $2 | tr -cd '[[:alnum:]]._+-/'`" >> "$nom" + echo "pass=`echo $3 | tr -cd '[[:alnum:]]._+-/'`" >> "$nom" + echo "problem=`echo $4 | tr -cd '[[:alnum:]]._+-/'`" >> "$nom" + echo "language=`echo $5 | tr -cd '[[:alnum:]]._+-/'`" >> "$nom" + echo "name=`echo $6 | tr -cd '[[:alnum:]]._+-/'`" >> "$nom" + echo -en "data=\"" >> "$nom" + uuencode -m zzzzzzzzzz < `echo "$7" | tr -cd '[[:alnum:]]._+-/'` | grep -v "begin-base64.*zzzzzzzzzz" >> "$nom" + echo "\"" >> "$nom" + dateerr=`date +%s` + echo "dateerr=$dateerr" >> "$nom" +# uniq=`date +%sN`-`sha256sum "$7"` +# uniq=`echo $uniq | sha256sum - | cut -f1 -d' '` + uniq=`sha256sum "$7" | cut -f1 -d' '` code=`cat /root/submissions/code` res=`echo -n "${code}${uniq}${dateerr}" | sha256sum - | cut -f1 -d' '` echo "uniq=$uniq" >> "$nom" diff --git a/tools/etc/icpc/bocaserver.sh b/tools/etc/icpc/bocaserver.sh deleted file mode 100755 index 8bb6c2c..0000000 --- a/tools/etc/icpc/bocaserver.sh +++ /dev/null @@ -1 +0,0 @@ -BOCASERVER=127.0.0.1 diff --git a/tools/etc/icpc/installboca.sh b/tools/etc/icpc/installboca.sh index 28eb0c7..88c266f 100755 --- a/tools/etc/icpc/installboca.sh +++ b/tools/etc/icpc/installboca.sh @@ -128,15 +128,42 @@ chmod -R g+rx,u+rwx boca-$bocaver/ chmod 600 boca-$bocaver/src/private/*.php [ -f boca-$bocaver.$di/src/private/remotescores/otherservers ] && cp -f boca-$bocaver.$di/src/private/remotescores/otherservers boca-$bocaver/src/private/remotescores/otherservers if [ "$OK" == "y" ]; then - cp -f $conffile boca-$bocaver/src/private/conf.php + cp -f $conffile boca-$bocaver/src/private/conf.php + [ -f boca-$bocaver.$di/src/private/run-using-command.config ] && cp -f boca-$bocaver.$di/src/private/run-using-command.config boca-$bocaver/src/private/run-using-command.config fi chmod 700 boca-$bocaver/tools/*.sh -chmod 755 boca-$bocaver/tools/boca-submit-run* -chmod 700 boca-$bocaver/tools/boca-submit-run-cron -chown root.root boca-$bocaver/tools/boca-submit-run-root -chmod 4555 boca-$bocaver/tools/boca-submit-run-root -echo "*/2 * * * * * root `pwd`/boca-$bocaver/tools/boca-submit-run-cron" > /etc/cron.d/boca +if [ -f boca-$bocaver.$di/src/private/run-past.config ]; then + cp -f boca-$bocaver.$di/src/private/run-past.config boca-$bocaver/src/private/run-past.config +else + echo "`date +%sN`-sha256sum-`date +%sN`" | sha256sum - | cut -d' ' -f1 > boca-$bocaver/src/private/run-past.config +fi +chmod 550 boca-$bocaver/src/private/run-past.config +chown www-data.www-data boca-$bocaver/src/private/run-past.config + +cp boca-$bocaver/tools/boca-submit-run* /usr/bin/ +chmod 755 /usr/bin/boca-submit-run* +chmod 700 /usr/bin/boca-submit-run-cron + +cat > /tmp/boca-submit-run-root-wrapper.c <<EOF +#include<stdlib.h> +#include<stdio.h> +#include<sys/types.h> +#include<unistd.h> +char str[10000]; +int main(int argc, char **argv) { + if(argc != 8) return 1; + sprintf(str,"/usr/bin/boca-submit-run-root %1000s %1000s %1000s %1000s %1000s %1000s %1000s",argv[1],argv[2],argv[3],argv[4],argv[5],argv[6],argv[7]); + setuid(0); + system(str); + return 0; +} +EOF +gcc -o /usr/bin/boca-submit-run-root-wrapper /tmp/boca-submit-run-root-wrapper.c +rm -f /tmp/boca-submit-run-root-wrapper.c +chown root.root /usr/bin/boca-submit-run-root-wrapper +chmod 4555 /usr/bin/boca-submit-run-root-wrapper +echo "*/2 * * * * root /usr/bin/boca-submit-run-cron >>/var/log/bocacron.out 2>>/var/log/bocacron.err" > /etc/cron.d/boca cat > boca-$bocaver/src/.htaccess <<EOF php_flag output_buffering on diff --git a/tools/etc/icpc/setup.sh b/tools/etc/icpc/setup.sh index da5a334..5d8838f 100755 --- a/tools/etc/icpc/setup.sh +++ b/tools/etc/icpc/setup.sh @@ -15,7 +15,8 @@ If this is supposed to be the server, then leave it empty\nIf there are multiple fi FIRSTBOCA=`echo $IP | cut -d';' -f1` echo "BOCASERVER=$FIRSTBOCA" > /etc/icpc/bocaserver.sh - if [ "`echo $IP | cut -d';' -f2-`" != "" ]; then + echo $IP | grep -q ';' + if [ "$?" == "0" ]; then echo "BOCASERVERS=`echo $IP | cut -d';' -f2-`" >> /etc/icpc/bocaserver.sh fi echo "$FIRSTBOCA boca boca" >> /etc/hosts diff --git a/tools/etc/icpc/update.sh.tmp b/tools/etc/icpc/update.sh.tmp deleted file mode 100644 index 63a3858..0000000 --- a/tools/etc/icpc/update.sh.tmp +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash -if [ "`id -u`" != "0" ]; then - echo "Script must run as root" -fi - -echo "===================================================" -echo "=================== checking for updates ==========" -echo "===================================================" - -wget -O /tmp/.boca.tmp "http://www.ime.usp.br/~cassio/boca/update.date.txt" -if [ $? != 0 ]; then - echo "ERROR DOWNLOADING UPDATE" - exit 1 -fi -di=`cat /tmp/.boca.tmp` -lastu=0 -if [ -r /etc/icpc/.lastupdate ]; then - lastu=`cat /etc/icpc/.lastupdate` -fi -if [ "$di" == "$lastu" ]; then - echo "NO UPDATES AVAILABLE" - exit 0 -fi - -echo ">>>>>>>>>>" -echo ">>>>>>>>>> Downloading update release `cat /tmp/.boca.tmp`" -echo ">>>>>>>>>>" - -wget -O /tmp/.boca.tmp "http://www.ime.usp.br/~cassio/boca/update.sh" -if [ $? != 0 ]; then - echo "ERROR DOWNLOADING UPDATE" - exit 1 -fi - -echo ">>>>>>>>>>" -echo ">>>>>>>>>> Running update script" -echo ">>>>>>>>>>" -chmod 755 /tmp/.boca.tmp -/tmp/.boca.tmp -exit $? diff --git a/tools/etc/network/if-pre-up.d/boca b/tools/etc/network/if-pre-up.d/boca index 3e5eb5b..20ff38f 100644 --- a/tools/etc/network/if-pre-up.d/boca +++ b/tools/etc/network/if-pre-up.d/boca @@ -15,7 +15,7 @@ if [ "$BOCASERVER" != "" ]; then /sbin/iptables -A INPUT -s $BOCASERVER -j ACCEPT fi if [ "$BOCASERVERS" != "" ]; then - for i in `echo $BOCASERVERS | cut -d';'`; do + for i in `echo $BOCASERVERS | tr ';' ' '`; do /sbin/iptables -A INPUT -s $i -j ACCEPT done fi diff --git a/tools/install_14_04_3.sh b/tools/install_14_04_3.sh index bf5ed20..d4f180e 100755 --- a/tools/install_14_04_3.sh +++ b/tools/install_14_04_3.sh @@ -35,7 +35,6 @@ fi # find /usr/lib -name notify-osd | xargs chmod -x # killall notify-osd 2>/dev/null apt-get -y install python-software-properties 2>/dev/null -gconftool -s -t bool /apps/update-notifier/auto_launch false for i in id chown chmod cut awk tail grep cat sed mkdir rm mv sleep apt-get add-apt-repository update-alternatives; do p=`which $i` @@ -177,6 +176,8 @@ EOF cp /usr/share/applications/gnome-terminal.desktop /etc/skel/Desktop/ chmod 755 /etc/skel/Desktop/*.desktop +[ "`which gconftool`" == "" ] || gconftool -s -t bool /apps/update-notifier/auto_launch false + pass=`echo -n icpc | makepasswd --clearfrom - --crypt-md5 | cut -d'$' -f2-` pass=\$`echo $pass` id -u icpc >/dev/null 2>/dev/null diff --git a/tools/installv2.sh b/tools/installv2.sh index bf5ed20..d4f180e 100755 --- a/tools/installv2.sh +++ b/tools/installv2.sh @@ -35,7 +35,6 @@ fi # find /usr/lib -name notify-osd | xargs chmod -x # killall notify-osd 2>/dev/null apt-get -y install python-software-properties 2>/dev/null -gconftool -s -t bool /apps/update-notifier/auto_launch false for i in id chown chmod cut awk tail grep cat sed mkdir rm mv sleep apt-get add-apt-repository update-alternatives; do p=`which $i` @@ -177,6 +176,8 @@ EOF cp /usr/share/applications/gnome-terminal.desktop /etc/skel/Desktop/ chmod 755 /etc/skel/Desktop/*.desktop +[ "`which gconftool`" == "" ] || gconftool -s -t bool /apps/update-notifier/auto_launch false + pass=`echo -n icpc | makepasswd --clearfrom - --crypt-md5 | cut -d'$' -f2-` pass=\$`echo $pass` id -u icpc >/dev/null 2>/dev/null |