blob: a9c05b717d42f5313bd97efea460d7d9ba936b97 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
#!/bin/bash
#//////////////////////////////////////////////////////////////////////////////////////////
#//BOCA Online Contest Administrator. Copyright (c) 2003- Cassio Polpo de Campos.
#//It may be distributed under the terms of the Q Public License version 1.0. A copy of the
#//license can be found with this software or at http://www.opensource.org/licenses/qtpl.php
#//
#//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
#//INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
#//PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER
#//OR HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR
#//CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
#//PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
#//OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#///////////////////////////////////////////////////////////////////////////////////////////
# last updated 26/oct/2011 by cassio@ime.usp.br
for i in id chown chmod md5sum wget tr cut awk tail head grep cat sed sleep; do
p=`which $i`
if [ -x "$p" ]; then
echo -n ""
else
echo command "$i" not found
exit 1
fi
done
if [ "`id -u`" != "0" ]; then
echo "Script must run as root"
fi
privatedir=/var/www/boca/private
if [ ! -d $privatedir ]; then
echo "Could not find directory $privatedir"
exit 1
fi
httpbocadir=boca
tempdir=/tmp
others=/var/www/boca/private/otherservers
secs=120
apacheuser=
[ -r /etc/icpc/apacheuser ] && apacheuser=`cat /etc/icpc/apacheuser | sed 's/ \t\n//g'`
[ "$apacheuser" == "" ] && apacheuser=www-data
id -u $apacheuser > /dev/null 2>/dev/null
[ $? != 0 ] && echo "User $apacheuser not found -- error to set permissions with chown/chmod"
#hash="shasum -a 256 -"
hash="md5sum -"
#rm -f $privatedir/score_*.dat
#rm -f $privatedir/thissitescore.dat
chown $apacheuser.root $privatedir/score_*.dat
chown $apacheuser.root $privatedir/thissitescore.dat
BOCASERVER=
[ -x /etc/icpc/bocaserver.sh ] && . /etc/icpc/bocaserver.sh
LOCALSERVER=$BOCASERVER
if [ "$LOCALSERVER" == "" -o "$LOCALSERVER" == "0/0" ]; then
LOCALSERVER=http://127.0.0.1/$httpbocadir
else
LOCALSERVER=http://$LOCALSERVER/$httpbocadir
fi
if [ ! -r $others ]; then
echo "External server list in $others not found"
exit 1
fi
echo "Starting loop to get scores from servers defined in $others"
while /bin/true; do
echo "Getting scores..."
qtd=1
for BOCASERVER in `grep -v "^[ \t]*\#" $others | awk '{ print $1; }'`; do
if [ "$BOCASERVER" == "" ]; then
continue
fi
echo $BOCASERVER | grep -q "http"
[ $? == 0 ] || BOCASERVER=http://$BOCASERVER/boca
user=`grep -v "^[ \t]*\#" $others | head -n$qtd | tail -n1 | awk '{ print $2; }'`
[ "$user" == "" ] && user=score
pass=`grep -v "^[ \t]*\#" $others | head -n$qtd | tail -n1 | awk '{ print $2; }'`
[ "$pass" == "" ] && pass=score
let "qtd = $qtd + 1"
wget -t3 -T3 "$LOCALSERVER/scoretable.php?clock=1" -O $tempdir/.temp.txt 2>/dev/null >/dev/null
if [ $? != 0 ]; then
echo "Error getting contest clock from $LOCALSERVER"
else
tempo=`cat $tempdir/.temp.txt`
echo -n "Asking server $BOCASERVER at time $tempo. Authenticating with user '$user'..."
md=`wget -t3 -T3 -S $BOCASERVER/index.php -O /dev/null --save-cookies $tempdir/.cookie.txt --keep-session-cookies 2>&1 | grep PHPSESS | tail -n1 | cut -f2 -d'=' | cut -f1 -d';'`
res=`echo -n $pass | $hash | cut -f1 -d' '`
res=`echo -n "${res}${md}" | $hash | cut -f1 -d' '`
echo -n "sending password..."
wget -t3 -T3 "$BOCASERVER/index.php?name=${user}&password=${res}" --load-cookies $tempdir/.cookie.txt --keep-session-cookies --save-cookies $tempdir/.cookie.txt -O $tempdir/.temp.txt 2>/dev/null >/dev/null
grep -qi incorrect $tempdir/.temp.txt
if [ $? != 0 ]; then
fname=`echo $BOCASERVER | tr './:' '_'`
echo "downloading scoretable..."
wget -t3 -T3 "$BOCASERVER/scoretable.php?remote=$tempo" --load-cookies $tempdir/.cookie.txt --keep-session-cookies --save-cookies $tempdir/.cookie.txt -O $privatedir/score_${fname}.tmp 2>$tempdir/.bocascore.tmp >$tempdir/.bocascore.tmp
if [ $? == 0 ]; then
chown $apacheuser.root $privatedir/score_$fname.tmp
chmod 660 $privatedir/score_$fname.tmp
mv $privatedir/score_$fname.tmp $privatedir/score_$fname.dat
echo "Score downloaded successfully into $privatedir/score_$fname.dat"
else
echo "Error getting scoretable from $BOCASERVER: `cat $tempdir/.bocascore.tmp`"
fi
else
echo "Error authenticating to server $BOCASERVER"
fi
fi
rm -f $tempdir/.temp.txt
rm -f $tempdir/.cookie.txt
done
echo -n "Waiting $secs secs..."
sleep $secs
echo ""
done
|