forked from Freifunk-Potsdam/ffp-monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfffeed.wsgi
47 lines (40 loc) · 1.32 KB
/
fffeed.wsgi
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
#!/usr/bin/env python3
import sys
sys.stdout = sys.stderr
import atexit
import gzip
import hashlib
import cherrypy
from cherrypy import HTTPError
from cherrypy._cperror import HTTPRedirect
from cherrypy.lib.static import serve_fileobj, serve_file
import logging
import os
import time
logger=logging.getLogger("Root")
if cherrypy.__version__.startswith('3.0') and cherrypy.engine.state == 0:
cherrypy.engine.start(blocking=False)
atexit.register(cherrypy.engine.stop)
class Root():
@cherrypy.expose
@cherrypy.tools.allow(methods=['POST'])
def feed(self,f):
ip = self.getip()
if type(f) is cherrypy._cpreqbody.Part and f.file:
data = f.file.read()
try:
data = gzip.decompress(data)
except OSError:
pass
h = hashlib.md5(data).hexdigest()
out = open(os.path.join("/var/ffdata","%s_%d_%s.xml" % (ip,time.time(),h)),"wb")
out.write(data)
out.close()
return "success"
raise HTTPError("400 No file")
def getip(self):
if "X-Forwarded-For" in cherrypy.request.headers:
return cherrypy.request.headers["X-Forwarded-For"]
else:
return cherrypy.request.remote.ip
application = cherrypy.Application( Root() , script_name=None, config=None)