move orders-accept configuration to eressea.ini

install lunit, too
This commit is contained in:
Enno Rehling 2017-01-20 08:32:31 +01:00
parent 5b78578939
commit d7dd281a6a
3 changed files with 61 additions and 54 deletions

View File

@ -23,4 +23,5 @@ add_subdirectory (src eressea)
install(DIRECTORY res conf DESTINATION ${CMAKE_INSTALL_PREFIX} FILES_MATCHING PATTERN "*.xml")
install(DIRECTORY res conf DESTINATION ${CMAKE_INSTALL_PREFIX} FILES_MATCHING PATTERN "*.json")
install(DIRECTORY scripts DESTINATION ${CMAKE_INSTALL_PREFIX} FILES_MATCHING PATTERN "*.lua")
install(DIRECTORY lunit DESTINATION ${CMAKE_INSTALL_PREFIX} FILES_MATCHING PATTERN "*.lua")
install(DIRECTORY share DESTINATION ${CMAKE_INSTALL_PREFIX})

View File

@ -1,3 +1,6 @@
[game]
email = Eressea Server <eressea-server@kn-bremen.de>
name = Eressea
[eressea]
base = .

View File

@ -3,22 +3,50 @@
from email.Utils import parseaddr
from email.Parser import Parser
from os import mkdir, rename, stat, utime, unlink, symlink
from os.path import exists
import os
import os.path
import ConfigParser
from re import compile, IGNORECASE
from stat import ST_MTIME
from string import upper, split, replace
import logging
from sys import argv, stdin, exit
import sys
from sys import stdin
from time import ctime, sleep, time
from socket import gethostname
from rfc822 import parsedate_tz, mktime_tz
LOG_FILENAME='/home/eressea/log/orders.log'
if 'ERESSEA' in os.environ:
dir = os.environ['ERESSEA']
elif 'HOME' in os.environ:
dir = os.path.join(os.environ['HOME'], '/eressea')
else: # WTF? No HOME?
dir = "/home/eressea/eressea"
if not os.path.isdir(dir):
print "please set the ERESSEA environment variable to the install path"
sys.exit(1)
rootdir = dir
try:
game = int(sys.argv[1])
except:
game = sys.argv[1]
gamedir = os.path.join(rootdir, "game-%d" % (game, ))
frommail = 'Eressea Server <eressea-server@eressea.kn-bremen.de>'
gamename = 'Eressea'
inifile = os.path.join(gamedir, 'eressea.ini')
if not os.path.exists(inifile):
print "no such file: " . inifile
else:
config = ConfigParser.ConfigParser()
config.read(inifile)
if config.has_option('game', 'email'):
frommail = config.get('game', 'email')
if config.has_option('game', 'name'):
gamename = config.get('game', 'name')
config = None
prefix = 'turn-'
hostname = gethostname()
# base directory for all your games:
rootdir = "/home/eressea"
orderbase = "orders.dir"
sendmail = True
# maximum number of reports per sender:
@ -28,36 +56,21 @@ writeheaders = True
# reject all html email?
rejecthtml = True
games = [
{
"from" : "Eressea Server <eressea-server@eressea.kn-bremen.de>",
"prefix" : "Eressea"
},
{
"from" : "Eressea Server <eressea-server@eressea.kn-bremen.de>",
"prefix": "E3"
},
{
"from" : "Eressea Server <eressea-server@eressea.kn-bremen.de>",
"prefix": "E4"
},
]
def unlock_file(filename):
try:
unlink(filename+".lock")
os.unlink(filename+".lock")
except:
print "could not unlock %s.lock, file not found" % filename
def lock_file(filename):
i = 0
wait = 1
if not exists(filename):
if not os.path.exists(filename):
file=open(filename, "w")
file.close()
while True:
try:
symlink(filename, filename+".lock")
os.symlink(filename, filename+".lock")
return
except:
i = i+1
@ -74,17 +87,17 @@ messages = {
"software and re-send the orders.",
"multipart-de" :
"FEHLER: Die von dir eingeschickte Mail enthält keinen " \
"FEHLER: Die von dir eingeschickte Mail enth<EFBFBD>lt keinen " \
"Text. Evtl. hast Du den Zug als HTML oder als anderweitig " \
"ungültig formatierte Mail ingeschickt. Wir können ihn " \
"deshalb nicht berücksichtigen. Schicke den Zug nochmals " \
"ung<EFBFBD>ltig formatierte Mail ingeschickt. Wir k<>nnen ihn " \
"deshalb nicht ber<EFBFBD>cksichtigen. Schicke den Zug nochmals " \
"als reinen Text ohne Formatierungen ein.",
"maildate-de":
"Es erreichte uns bereits ein Zug mit einem späteren " \
"Es erreichte uns bereits ein Zug mit einem sp<EFBFBD>teren " \
"Absendedatum (%s > %s). Entweder ist deine " \
"Systemzeit verstellt, oder ein Zug hat einen anderen Zug von " \
"dir auf dem Transportweg überholt. Entscheidend für die " \
"dir auf dem Transportweg <EFBFBD>berholt. Entscheidend f<>r die " \
"Auswertungsreihenfolge ist das Absendedatum, d.h. der Date:-Header " \
"deiner Mail.",
@ -173,8 +186,8 @@ def available_file(dirname, basename):
ver = 0
maxdate = 0
filename = "%s/%s,%s,%d" % (dirname, basename, hostname, ver)
while exists(filename):
maxdate = max(stat(filename)[ST_MTIME], maxdate)
while os.path.exists(filename):
maxdate = max(os.stat(filename)[ST_MTIME], maxdate)
ver = ver + 1
filename = "%s/%s,%s,%d" % (dirname, basename, hostname, ver)
if ver >= maxfiles:
@ -234,7 +247,7 @@ def copy_orders(message, filename, sender):
from os.path import split
dirname, basename = split(filename)
dirname = dirname + '/headers'
if not exists(dirname): mkdir(dirname)
if not os.path.exists(dirname): os.mkdir(dirname)
outfile = open(dirname + '/' + basename, "w")
for name, value in message.items():
outfile.write(name + ": " + value + "\n")
@ -265,16 +278,14 @@ def copy_orders(message, filename, sender):
# create a file, containing:
# game=0 locale=de file=/path/to/filename email=rcpt@domain.to
def accept(game, locale, stream, extend=None):
global rootdir, orderbase
global rootdir, orderbase, gamedir, gamename, frommail
if extend is not None:
orderbase = orderbase + ".pre-" + extend
gamename = games[game-2]["prefix"]
gamedir = rootdir+"/eressea/game-%d" % (game, )
savedir = gamedir+"/"+orderbase
savedir = os.path.join(gamedir, orderbase)
# check if it's one of the pre-sent orders.
# create the save-directories if they don't exist
if not exists(gamedir): mkdir(gamedir)
if not exists(savedir): mkdir(savedir)
if not os.path.exists(gamedir): os.mkdir(gamedir)
if not os.path.exists(savedir): os.mkdir(savedir)
# parse message
message = Parser().parse(stream)
sender = get_sender(message)
@ -298,7 +309,7 @@ def accept(game, locale, stream, extend=None):
maildate = message.get("Date")
if maildate != None:
turndate = mktime_tz(parsedate_tz(maildate))
utime(filename, (turndate, turndate))
os.utime(filename, (turndate, turndate))
logger.debug("mail date is '%s' (%d)" % (maildate, turndate))
if turndate < maxdate:
logger.warning("inconsistent message date " + sender)
@ -313,9 +324,9 @@ def accept(game, locale, stream, extend=None):
warning = " (" + messages["error-" + locale] + ")"
msg = msg + formatpar(messages["multipart-" + locale], 76, 2) + "\n"
logger.warning("rejected - no text/plain in orders from " + sender)
unlink(filename)
os.unlink(filename)
savedir = savedir + "/rejected"
if not exists(savedir): mkdir(savedir)
if not os.path.exists(savedir): os.mkdir(savedir)
lock_file(gamedir + "/orders.queue")
maxdate, filename = available_file(savedir, prefix + sender)
store_message(message, filename)
@ -323,7 +334,6 @@ def accept(game, locale, stream, extend=None):
fail = True
if sendmail and warning is not None:
frommail = games[key]["from"]
subject = gamename + " " + messages["subject-"+locale] + warning
mail = "Subject: %s\nFrom: %s\nTo: %s\n\n" % (subject, frommail, sender) + msg
from smtplib import SMTP
@ -347,22 +357,15 @@ def accept(game, locale, stream, extend=None):
return 0
# the main body of the script:
LOG_FILENAME=os.path.join(rootdir, 'log/orders.log')
logging.basicConfig(level=logging.DEBUG, filename=LOG_FILENAME)
logger = logging
delay=None # TODO: parse the turn delay
try:
game = int(argv[1])
except:
game = argv[1]
if game[:3]=='e3a':
game = 3
elif game[:7]=='eressea':
game = 2
locale = argv[2]
locale = sys.argv[2]
infile = stdin
if len(argv)>3:
infile = open(argv[3], "r")
if len(sys.argv)>3:
infile = open(sys.argv[3], "r")
retval = accept(game, locale, infile, delay)
if infile!=stdin:
infile.close()
exit(retval)
sys.exit(retval)