add scripts for fetching report by email

This commit is contained in:
Enno Rehling 2016-02-11 20:27:41 +01:00
parent b18f048e1e
commit 57ae38dec5
3 changed files with 77 additions and 1 deletions

View File

@ -1,6 +1,6 @@
install(PROGRAMS create-orders backup-eressea run-turn send-zip-report install(PROGRAMS create-orders backup-eressea run-turn send-zip-report
send-bz2-report compress.py compress.sh epasswd.py orders-process send-bz2-report compress.py compress.sh epasswd.py orders-process
orders-accept DESTINATION bin) checkpasswd.py sendreport.sh orders-accept DESTINATION bin)
install(DIRECTORY cron/ DESTINATION bin USE_SOURCE_PERMISSIONS install(DIRECTORY cron/ DESTINATION bin USE_SOURCE_PERMISSIONS
FILES_MATCHING PATTERN "*.cron") FILES_MATCHING PATTERN "*.cron")

28
process/checkpasswd.py Executable file
View File

@ -0,0 +1,28 @@
#!/usr/bin/env python
import sys, re
if len(sys.argv)<4:
sys.exit(-2)
passfile=sys.argv[1]
myfaction=sys.argv[2]
mypasswd=sys.argv[3]
if mypasswd[0]=='"':
mypasswd=mypasswd[1:len(mypasswd)-1]
try:
infile = open(passfile, "r")
except:
print "failed to open " + passfile
sys.exit(-1)
for line in infile.readlines():
match = line.split(":")
if match!=None:
faction, passwd, override = match[0:3]
if faction==myfaction:
if passwd==mypasswd or override==mypasswd:
sys.exit(0)
sys.exit(-1)

48
process/sendreport.sh Executable file
View File

@ -0,0 +1,48 @@
#!/bin/bash
## this script takes a backup of a turn.
## usage: backup.sh <turn>
if [ -z $ERESSEA ]; then
echo "You have to define the \$ERESSEA environment variable to run $0"
exit -2
fi
source $HOME/bin/functions.sh
source $HOME/etc/eressea.conf
GAME=$1
EMAIL=$2
FACTION=$3
PASSWD=$4
echo "$GAME $EMAIL $FACTION $PASSWD" >> /tmp/report.log
function reply() {
echo $@ | mutt -s "Reportnachforderung Partei ${FACTION}" $EMAIL
abort $@
}
LOCKFILE=$ERESSEA/.report.lock
[ -e $LOCKFILE ] && reply "lockfile exists. wait for mail delivery to finish."
REPLYTO='accounts@eressea.de'
echo `date`:report:$GAME:$EMAIL:$FACTION:$PASSWD >> $ERESSEA/request.log
cd $ERESSEA
checkpasswd.py game-$GAME/passwd $FACTION $PASSWD || reply "Das Passwort fuer die Partei $FACTION ist ungueltig"
cd $ERESSEA/game-$GAME/reports
if [ ! -e ${FACTION}.sh ]; then
echo "Der Report für Partei $FACTION kann wegen technischer Probleme leider nicht nachgefordert werden: No such file ${FACTION}.sh" \
| mutt -s "Reportnachforderung Partei ${FACTION}" $EMAIL
exit
fi
source ${FACTION}.sh $EMAIL || reply "Unbekannte Partei $FACTION"
if [ -e $ERESSEA/game-$GAME/eressea.db ]; then
SQL="select email from faction f left join faction_data fd on fd.faction_id=f.id where f.game_id=$GAME AND fd.code='$FACTION' and fd.turn=(select max(turn) from faction_data fx where fx.faction_id=f.id)"
OWNER=$(sqlite3 $ERESSEA/game-$GAME/eressea.db "$SQL")
echo "Der Report Deiner Partei wurde an ${EMAIL} gesandt." \
| mutt -s "Reportnachforderung Partei ${FACTION}" $OWNER
fi