From 57ae38dec50346c404fe5ea293fe23d8d6397520 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 11 Feb 2016 20:27:41 +0100 Subject: [PATCH] add scripts for fetching report by email --- process/CMakeLists.txt | 2 +- process/checkpasswd.py | 28 ++++++++++++++++++++++++ process/sendreport.sh | 48 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100755 process/checkpasswd.py create mode 100755 process/sendreport.sh diff --git a/process/CMakeLists.txt b/process/CMakeLists.txt index 5a6fa92e0..58384b1f6 100644 --- a/process/CMakeLists.txt +++ b/process/CMakeLists.txt @@ -1,6 +1,6 @@ install(PROGRAMS create-orders backup-eressea run-turn send-zip-report 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 FILES_MATCHING PATTERN "*.cron") diff --git a/process/checkpasswd.py b/process/checkpasswd.py new file mode 100755 index 000000000..2aa51a109 --- /dev/null +++ b/process/checkpasswd.py @@ -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) + diff --git a/process/sendreport.sh b/process/sendreport.sh new file mode 100755 index 000000000..003026f4a --- /dev/null +++ b/process/sendreport.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +## this script takes a backup of a turn. +## usage: backup.sh + +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