-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathavsync.py
97 lines (79 loc) · 3.18 KB
/
avsync.py
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
import lindenip
import logging
import cgi
import os
from google.appengine.api import urlfetch
from google.appengine.api import memcache
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
import relations
relationtypes = ['owns', 'secowns']#valid relation types. For the sake of consistency
#let's keep only active verbs in this list
from model import AppSettings
import model
sharedpass = AppSettings.get_or_insert("sharedpass", value="sharedpassword").value
cmdurl = AppSettings.get_or_insert("cmdurl", value="http://yourcmdapp.appspot.com").value
def AlarmUrl():
theurl=memcache.get('alarmurl')
if theurl is None:
alarm = AppSettings.get_by_key_name("alarmurl")
if alarm is None:
return ''
else:
memcache.set('alarmurl', alarm.value)
return alarm.value
else:
return theurl
def RequestName(key):
URL = "%s/Key2Name/" % AlarmUrl()
logging.info('Key request send for %s to URL %s' % (key, URL))
rpc = urlfetch.create_rpc()
message = key
# send the request to an SL object
urlfetch.make_fetch_call(rpc, URL, payload=message, method="POST")
class SetName(webapp.RequestHandler):
def post(self):
#check that we're coming from an LL ip
if not lindenip.inrange(os.environ['REMOTE_ADDR']):
self.error(403)
elif not self.request.headers['X-SecondLife-Owner-Key'] in model.adminkeys:
self.error(403)
else:
lines = self.request.body.split('\n')
params = {}
for line in lines:
params[line.split('=')[0]] = line.split('=')[1]
logging.info('Info receided from SL, now storing %s with key %s' % (params['name'], params['key']))
relations.update_av(params['key'], params['name'])
class GetName2Key(webapp.RequestHandler):
def get(self):
if (self.request.headers['sharedpass'] == sharedpass):
key = cgi.escape(self.request.get('key'))
logging.info('Key2name request for %s' % (key))
name = relations.key2name(key)
if name:
logging.info('Resolved as %s' % (name))
self.response.out.write(name)
self.response.set_status(200)#accepted
else:
logging.warning('Could not be resolved! Sending request now to inworld item.')
RequestName(key)
self.response.out.write('')
self.response.set_status(202)#accepted
else:
self.error(403)
logging.error('wrong shared password expecting %s received %s ip address' % (sharedpass,self.request.headers['sharedpass'],os.environ['REMOTE_ADDR']))
class MainPage(webapp.RequestHandler):
def get(self):
self.response.out.write('hello world')
application = webapp.WSGIApplication(
[
(r'/.*?/getname',GetName2Key),
(r'/.*?/setname',SetName),
('/.*', MainPage)
],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()