-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinforma_frontend.py
executable file
·219 lines (189 loc) · 6.67 KB
/
informa_frontend.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
import os, json, re, tornado.web, requests
from sys import exit, argv
from time import sleep
from user_agents import parse as ua_parse
from lib.Frontend.unveillance_frontend import UnveillanceFrontend
from lib.Frontend.lib.Core.vars import Result
from v2.v2j3m import *
from conf import INFORMA_BASE_DIR, INFORMA_CONF_ROOT, DEBUG, WEB_TITLE, buildServerURL
class InformaFrontend(UnveillanceFrontend):
def __init__(self):
UnveillanceFrontend.__init__(self)
self.reserved_routes.extend(["ictd", "commit", "leaflet", "submissions", "v2j3mview"])
self.routes.extend([
(r"/ictd/", self.ICTDHandler),
(r"/commit/", self.DriveHandler),
(r"/submissions/", self.SubmissionShortcutHandler),
(r"/leaflet/(.*)", self.LeafletHandler),
(r"/j3mheader/(.*)", J3MHeaderHandler),
(r"/lightMeter/(.*)", LightMeterHandler),
(r"/pressureHPAOrMBAR/(.*)", pressureHPAOrMBARHandler),
(r"/pressureAltitude/(.*)", pressureAltitudeHandler),
(r"/GPSBearing/(.*)", GPSBearingHandler),
(r"/GPSCoords/(.*)", GPSCoordsHandler),
(r"/GPSAccuracy/(.*)", GPSAccuracyHandler),
(r"/GPSData/(.*)", GPSDataHandler),
(r"/Accelerometer/(.*)", AccelerometerHandler),
(r"/DocumentWrapper/(.*)", DocumentWrapperHandler),
(r"/PitchRollAzimuth/(.*)", PitchRollAzimuthHandler),
(r"/VisibleWifiNetworks/(.*)", VisibleWifiNetworksHandler),
(r"/AppendedUserData/(.*)", AppendedUserDataHandler),
(r"/SubmitViaURL/(.*)", SubmitViaURLHandler),
(r"/j3mretrieve/(.*)", J3MRetrieveHandler)])
self.default_on_loads.extend([
'/web/js/lib/md5.js',
'/web/js/lib/sammy.js',
'/web/js/lib/crossfilter.min.js',
'/web/js/lib/d3.min.js',
'/web/js/lib/visualsearch.js',
'/web/js/lib/jquery.ui.js',
'/web/js/lib/jquery.ui.core.js',
'/web/js/lib/jquery.ui.position.js',
'/web/js/lib/jquery.ui.widget.js',
'/web/js/lib/jquery.ui.menu.js',
'/web/js/lib/jquery.ui.autocomplete.js',
'/web/js/viz/uv_viz.js',
'/web/js/models/ic_notifier.js',
'/web/js/informacam.js'
])
self.on_loads.update({
'submission' : [
'/leaflet/leaflet.js',
# '/web/js/viz/uv_indented_tree.js',
'/web/js/viz/ic_main.js',
'/web/js/viz/ic_progress_notifer.js',
'/web/js/viz/ic_document_source.js',
'/web/js/viz/ic_document_wrapper.js',
'/web/js/viz/ic_appended_userdata.js',
'/web/js/viz/ic_j3m_header.js',
# '/web/js/viz/ic_timeseries_graph.js',
# '/web/js/viz/ic_timeseries_chart.js',
'/web/js/viz/ic_timeseries_map.js',
'/web/js/viz/ic_linechart_multiview.js',
'/web/js/models/unveillance_document.js',
'/web/js/models/ic_j3m.js',
# '/web/js/models/ic_image.js',
# '/web/js/models/ic_submission.js',
'/web/js/modules/ic_submission.js',
'/web/js/ic_tsv_export.js',
'/web/css/ic_viz.css'
],
'source' : [
'/web/js/models/unveillance_document.js',
'/web/js/models/ic_source.js',
'/web/js/modules/ic_source.js'
],
'main' : [
'/web/js/lib/dropzone.js',
'/web/js/models/ic_search.js',
'/web/js/models/unveillance_dropzone.js',
'/web/js/models/ic_document_browser.js',
'/web/js/modules/main.js'],
'search' :[
'/web/js/models/ic_search.js',
'/web/js/models/ic_document_browser.js',
'/web/js/models/ic_j3m.js',
'/web/js/ic_tsv_export.js',
'/web/js/modules/ic_search.js',
'/web/css/ic_viz.css'
],
'unveil' : [
'/web/js/modules/uv_unveil.js',
'/web/js/models/unveillance_task_pipe.js',
'/web/js/modules/ic_unveil.js'
],
'landing' : [
'/web/css/tabs.css',
'/web/js/lib/dropzone.js',
'/web/js/models/ic2_search.js',
'/web/js/models/unveillance_dropzone.js',
'/web/js/models/ic_dropzone.js',
'/web/js/models/ic_document_browser.js',
'/web/js/modules/ic2_search.js',
'/web/js/modules/ic_landing.js'
],
'simple' : [
'/web/js/lib/dropzone.js',
'/web/js/models/unveillance_dropzone.js'
]
})
self.on_loads_by_status[1].extend([
'/web/js/modules/ic_login.js',
'/web/js/models/unveillance_user.js'
])
self.on_loads_by_status[2].extend([
'/web/js/models/unveillance_user.js',
'/web/js/modules/ic_logout.js',
'/web/js/models/ic_user.js'
])
self.on_loads_by_status[3].extend([
'/web/js/models/unveillance_user.js',
'/web/js/modules/ic_logout.js',
'/web/js/models/ic_user.js',
'/web/js/models/ic_user_admin.js'
])
self.restricted_routes_by_status[0].extend([
'unveil', 'reindex', 'cluster'])
self.get_page_load_extras.update({
'body_classes' : self.get_browser_from_user_agent
})
with open(os.path.join(INFORMA_CONF_ROOT, "informacam.init.json"), 'rb') as IV:
init_vars = json.loads(IV.read())['web']
self.init_vars.update(init_vars)
tmpl_root = os.path.join(INFORMA_BASE_DIR, "web", "layout", "tmpl")
self.INDEX_HEADER = os.path.join(tmpl_root, "header.html")
self.INDEX_FOOTER = os.path.join(tmpl_root, "footer.html")
self.MODULE_HEADER = self.INDEX_HEADER
self.MODULE_FOOTER = self.INDEX_FOOTER
self.WEB_TITLE = WEB_TITLE
"""
Custom page load extras
"""
def get_browser_from_user_agent(self, request):
try:
user_agent = ua_parse(request.headers['User-Agent']).browser
return ("%s_%s" % (user_agent.family, user_agent.version_string)).lower().replace(" ", "_").replace(".", "_")
except Exception as e:
if DEBUG:
print e, type(e)
print "could not get User-Agent"
return ""
"""
Custom handlers
"""
class LeafletHandler(tornado.web.RequestHandler):
@tornado.web.asynchronous
def get(self, uri):
r = requests.get("http://cdn.leafletjs.com/leaflet-0.7.3/%s" % uri)
self.finish(r.content)
class ICTDHandler(tornado.web.RequestHandler):
@tornado.web.asynchronous
def get(self):
self.finish("ICTD GOES HERE")
class DriveHandler(tornado.web.RequestHandler):
@tornado.web.asynchronous
def get(self):
endpoint = "/"
res = self.application.routeRequest(Result(), "open_drive_file", self)
if DEBUG: print res.emit()
if res.result == 200 and hasattr(res, "data"):
endpoint += "#collection=%s" % json.dumps(res.data)
self.redirect(endpoint)
class SubmissionShortcutHandler(tornado.web.RequestHandler):
@tornado.web.asynchronous
def get(self):
endpoint = "/"
# depending on the query params, we might want to look up a submission by
# public_hash, _id, or other publicly-available params TBD
self.redirect(endpoint)
if __name__ == "__main__":
informa_frontend = InformaFrontend()
if len(argv) != 2: exit("Usage: informa_frontend.py [-start, -stop, -restart]")
if argv[1] == "-start" or argv[1] == "-firstuse":
informa_frontend.startup()
elif argv[1] == "-stop":
informa_frontend.shutdown()
elif argv[1] == "-restart":
informa_frontend.shutdown()
sleep(5)
informa_frontend.startup()