blob: e1b000bd72e9de84ef038db0d5632a3e908e1f6b [file] [log] [blame]
Steve McIntyre2454bf02015-09-23 18:33:02 +01001#! /usr/bin/python
2
3# Copyright 2015 Linaro Limited
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software
17# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18# MA 02110-1301, USA.
19#
20# Visualisation module for VLANd. Fork a trivial webserver
21# implementation on an extra, and generate a simple set of pages and
22# graphics on demand.
23#
24
25import os, sys, logging, time, datetime, re
26from multiprocessing import Process
27from BaseHTTPServer import BaseHTTPRequestHandler
28from BaseHTTPServer import HTTPServer
29import urlparse
Steve McIntyre57a9d0a2015-10-28 18:22:31 +000030import cStringIO
Steve McIntyre2454bf02015-09-23 18:33:02 +010031
32if __name__ == '__main__':
33 vlandpath = os.path.abspath(os.path.normpath(os.path.dirname(sys.argv[0])))
34 sys.path.insert(0, vlandpath)
35 sys.path.insert(0, "%s/.." % vlandpath)
36
37from errors import InputError
38from db.db import VlanDB
39from config.config import VlanConfig
40from graphics import Graphics,Switch
41from util import VlanUtil
42class VlandHTTPServer(HTTPServer):
43 """ Trivial wrapper for HTTPServer so we can include our own state. """
44 def __init__(self, server_address, handler, state):
45 HTTPServer.__init__(self, server_address, handler)
46 self.state = state
47
Steve McIntyre57a9d0a2015-10-28 18:22:31 +000048class GraphicsCache(object):
49 """ Cache for graphics state, to avoid having to recalculate every
50 query too many times. """
51 last_update = None
Steve McIntyre57a9d0a2015-10-28 18:22:31 +000052 graphics = {}
53
54 def __init__(self):
55 # Pick an epoch older than any sensible use
56 self.last_update = datetime.datetime(2000, 01, 01)
57
Steve McIntyre2454bf02015-09-23 18:33:02 +010058class Visualisation(object):
59 """ Code and config for the visualisation graphics module. """
60
61 state = None
62 p = None
63
64 # Fork a new process for the visualisation webserver
65 def __init__(self, state):
66 self.state = state
67 self.p = Process(target=self.visloop, args=())
68 self.p.start()
69
70 # The main loop for the visualisation webserver
71 def visloop(self):
Steve McIntyre57a9d0a2015-10-28 18:22:31 +000072 self.state.cache = GraphicsCache()
Steve McIntyre2454bf02015-09-23 18:33:02 +010073 self.state.db = VlanDB(db_name=self.state.config.database.dbname,
Steve McIntyreea343aa2015-10-23 17:46:17 +010074 username=self.state.config.database.username,
75 readonly=True)
Steve McIntyre2454bf02015-09-23 18:33:02 +010076
77 loglevel = VlanUtil().set_logging_level(self.state.config.logging.level)
78
79 # Should we log to stderr?
80 if self.state.config.logging.filename is None:
81 logging.basicConfig(level = loglevel,
82 format = '%(asctime)s %(levelname)-8s %(message)s')
83 else:
84 logging.basicConfig(level = loglevel,
85 format = '%(asctime)s %(levelname)-8s VIS %(message)s',
86 datefmt = '%Y-%m-%d %H:%M:%S %Z',
87 filename = self.state.config.logging.filename,
88 filemode = 'a')
89 logging.info('%s visualisation starting up', self.state.banner)
90
Steve McIntyre86916e42015-09-28 02:39:32 +010091 server = VlandHTTPServer(('', self.state.config.visualisation.port),
Steve McIntyre2454bf02015-09-23 18:33:02 +010092 GetHandler, self.state)
93 server.serve_forever()
94
95 # Kill the webserver
96 def shutdown(self):
97 self.p.terminate()
98
99class GetHandler(BaseHTTPRequestHandler):
100 """ Methods to generate and serve the pages """
101
102 parsed_path = None
103
104 # Trivial top-level page. Link to images for each of the VLANs we
105 # know about.
106 def send_index(self):
107 self.send_response(200)
108 self.wfile.write('Content-type: text/html\r\n')
109 self.end_headers()
Steve McIntyreb0aa4602015-10-08 15:33:28 +0100110 config = self.server.state.config.visualisation
Steve McIntyre57a9d0a2015-10-28 18:22:31 +0000111 cache = self.server.state.cache
112 db = self.server.state.db
113 switches = db.all_switches()
114 vlans = db.all_vlans()
115 vlan_tags = {}
116
117 for vlan in vlans:
118 vlan_tags[vlan.vlan_id] = vlan.tag
119
120 if cache.last_update < self.server.state.db.get_last_modified_time():
121 logging.debug('Cache is out of date')
122 # Fill the cache with all the information we need:
123 # * the graphics themselves
124 # * the data to match each graphic, so we can generate imagemap/tooltips
125 cache.graphics = {}
126 if len(switches) > 0:
127 for vlan in vlans:
128 cache.graphics[vlan.vlan_id] = self.generate_graphic(vlan.vlan_id)
129 cache.last_update = datetime.datetime.utcnow()
130
Steve McIntyre2454bf02015-09-23 18:33:02 +0100131 page = []
Steve McIntyrede1ee972015-10-28 18:23:05 +0000132 page.append('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">')
Steve McIntyre2454bf02015-09-23 18:33:02 +0100133 page.append('<html>')
134 page.append('<head>')
Steve McIntyrede1ee972015-10-28 18:23:05 +0000135 page.append('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">')
Steve McIntyre2454bf02015-09-23 18:33:02 +0100136 page.append('<TITLE>VLANd visualisation</TITLE>')
Steve McIntyreb74ea6b2015-09-24 20:45:31 +0100137 page.append('<link rel="stylesheet" type="text/css" href="style.css">')
Steve McIntyreb0aa4602015-10-08 15:33:28 +0100138 if config.refresh and config.refresh > 0:
139 page.append('<meta http-equiv="refresh" content="%d">' % config.refresh)
Steve McIntyre2454bf02015-09-23 18:33:02 +0100140 page.append('</HEAD>')
141 page.append('<body>')
Steve McIntyrebfef5062015-10-30 18:28:32 +0000142
143 # Generate left-hand menu with links to each VLAN diagram
Steve McIntyreb74ea6b2015-09-24 20:45:31 +0100144 page.append('<div class="menu">')
145 if len(switches) > 0:
146 page.append('<h2>Menu</h2>')
147 page.append('<p>VLANs: %d</p>' % len(vlans))
148 page.append('<ul>')
149 for vlan in vlans:
Steve McIntyredef26862015-10-29 17:35:10 +0000150 page.append('<li><a href="./#vlan%d">VLAN ID %d, Tag %d<br>(%s)</a>' % (vlan.vlan_id, vlan.vlan_id, vlan.tag, vlan.name))
Steve McIntyreb74ea6b2015-09-24 20:45:31 +0100151 page.append('</ul>')
152 page.append('<div class="date"><p>Current time: %s</p>' % datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S UTC"))
153 page.append('<p>version %s</p>' % self.server.state.version)
154 page.append('</div>')
155 page.append('</div>')
156
Steve McIntyrebfef5062015-10-30 18:28:32 +0000157 # Now the main content area with the graphics
Steve McIntyreb74ea6b2015-09-24 20:45:31 +0100158 page.append('<div class="content">')
159 page.append('<h1>VLANd visualisation</h1>')
160
Steve McIntyrebfef5062015-10-30 18:28:32 +0000161 # Bail early if we have nothing to show!
Steve McIntyre2454bf02015-09-23 18:33:02 +0100162 if len(switches) == 0:
163 page.append('<p>No switches found in the database, nothing to show...</p>')
Steve McIntyrebfef5062015-10-30 18:28:32 +0000164 page.append('</div>')
165 page.append('</body>')
166 self.wfile.write('\r\n'.join(page))
167 return
Steve McIntyre2454bf02015-09-23 18:33:02 +0100168
Steve McIntyrebfef5062015-10-30 18:28:32 +0000169 # Trivial javascript helpers for tooltip control
170 page.append('<SCRIPT LANGUAGE="javascript">')
171 page.append('function popup(v,p) {')
172 page.append('a=v.toString();')
173 page.append('b=p.toString();')
174 page.append('id="port".concat("",a).concat(".",b);')
175 page.append('document.getElementById(id).style.visibility="visible";')
176 page.append('}')
177 page.append('function popdown(v,p) {')
178 page.append('a=v.toString();')
179 page.append('b=p.toString();')
180 page.append('id="port".concat("",a).concat(".",b);')
181 page.append('document.getElementById(id).style.visibility="hidden";')
182 page.append('}')
183 page.append('</SCRIPT>')
184
185 # For each VLAN, add a graphic
186 for vlan in vlans:
187 this_image = cache.graphics[vlan.vlan_id]
188 page.append('<a name="vlan%d"></a>' % vlan.vlan_id)
189 page.append('<h3>VLAN ID %d, Tag %d, name %s</h3>' % (vlan.vlan_id, vlan.tag, vlan.name))
190
191 # Link to an image we generate from our data
192 page.append('<p><img src="images/vlan/%d.png" ' % vlan.vlan_id)
193 page.append('width="%d" height="%d" ' % ( this_image['image']['width'], this_image['image']['height']))
194 page.append('alt="VLAN %d diagram" usemap="#MAPVLAN%d">' % (vlan.vlan_id,vlan.vlan_id))
195
196 # Generate an imagemap describing all the ports, with
197 # javascript hooks to pop up/down a tooltip box based on
198 # later data.
199 page.append('<map name="MAPVLAN%d">' % vlan.vlan_id)
200 for switch in this_image['ports'].keys():
201 for portnum in this_image['ports'][switch].keys():
202 this_port = this_image['ports'][switch][portnum]
203 port = this_port['db']
204 ((ulx,uly),(lrx,lry),upper) = this_port['location']
205 page.append('<area shape="rect" ')
206 page.append('coords="%d,%d,%d,%d" ' % (ulx,uly,lrx,lry))
207 page.append('onMouseOver="popup(%d,%d)" onMouseOut="popdown(%d,%d)">' % (vlan.vlan_id, port.port_id, vlan.vlan_id, port.port_id))
208 page.append('</map></p>')
209 page.append('<hr>')
210 page.append('</div>') # End of normal content, all the VLAN graphics shown
211
212 # Now generate the tooltip boxes for the ports. Each is
213 # fully-formed but invisible, ready for our javascript helper
214 # to pop visible on demand.
215 for vlan in vlans:
216 this_image = cache.graphics[vlan.vlan_id]
217 for switch in this_image['ports'].keys():
218 for portnum in this_image['ports'][switch].keys():
219 this_port = this_image['ports'][switch][portnum]
220 port = this_port['db']
221 page.append('<div class="port" id="port%d.%d">' % (vlan.vlan_id, port.port_id))
222 page.append('Port ID: %d Port number: %d<br>' % (port.port_id, port.number))
223 if port.is_locked:
224 page.append('Locked<br>')
225 if port.is_trunk:
226 page.append('Trunk')
227 if port.trunk_id != -1:
228 page.append(' (Trunk ID %d)' % port.trunk_id)
229 page.append('<br>')
230 else:
231 page.append('Current VLAN ID: %d (Tag %d)<br>' % (port.current_vlan_id, vlan_tags[port.current_vlan_id]))
232 page.append('Base VLAN ID: %d (Tag %d)<br>' % (port.base_vlan_id, vlan_tags[port.base_vlan_id]))
233 page.append('</div>')
234
Steve McIntyre2454bf02015-09-23 18:33:02 +0100235 page.append('</body>')
236 self.wfile.write('\r\n'.join(page))
237
Steve McIntyre57a9d0a2015-10-28 18:22:31 +0000238 # Simple-ish style sheet
Steve McIntyre2454bf02015-09-23 18:33:02 +0100239 def send_style(self):
240 self.send_response(200)
241 self.wfile.write('Content-type: text/css\r\n')
242 self.end_headers()
Steve McIntyre57a9d0a2015-10-28 18:22:31 +0000243 cache = self.server.state.cache
Steve McIntyreb74ea6b2015-09-24 20:45:31 +0100244 page = []
Steve McIntyre57a9d0a2015-10-28 18:22:31 +0000245 page.append('body {')
246 page.append(' background: white;')
247 page.append(' color: black;')
248 page.append(' font-size: 12pt;')
249 page.append('}')
250 page.append('')
251 page.append('.menu {')
252 page.append(' position:fixed;')
253 page.append(' float:left;')
254 page.append(' font-family: arial, Helvetica, sans-serif;')
255 page.append(' width:20%;')
256 page.append(' height:100%;')
257 page.append(' font-size: 10pt;')
258 page.append(' padding-top: 10px;')
259 page.append('}')
260 page.append('')
261 page.append('.content {')
262 page.append(' position:relative;')
263 page.append(' padding-top: 10px;')
Steve McIntyree8f39df2015-10-28 18:36:39 +0000264 page.append(' width: 80%;')
Steve McIntyre57a9d0a2015-10-28 18:22:31 +0000265 page.append(' max-width:80%;')
266 page.append(' margin-left: 21%;')
267 page.append(' margin-top: 50px;')
268 page.append(' height:100%;')
269 page.append('}')
270 page.append('')
Steve McIntyre8179f612015-10-30 18:24:20 +0000271 page.append('h1,h2,h3 {')
Steve McIntyre57a9d0a2015-10-28 18:22:31 +0000272 page.append(' font-family: arial, Helvetica, sans-serif;')
273 page.append(' padding-right:3pt;')
274 page.append(' padding-top:2pt;')
275 page.append(' padding-bottom:2pt;')
276 page.append(' margin-top:8pt;')
277 page.append(' margin-bottom:8pt;')
278 page.append(' border-style:none;')
279 page.append(' border-width:thin;')
280 page.append('}')
281 page.append('A:link { text-decoration: none; }')
282 page.append('A:visited { text-decoration: none}')
283 page.append('h1 { font-size: 18pt; }')
284 page.append('h2 { font-size: 14pt; }')
285 page.append('h3 { font-size: 12pt; }')
Steve McIntyre57a9d0a2015-10-28 18:22:31 +0000286 page.append('dl,ul { margin-top: 1pt; text-indent: 0 }')
287 page.append('ol { margin-top: 1pt; text-indent: 0 }')
Steve McIntyre57a9d0a2015-10-28 18:22:31 +0000288 page.append('div.date { font-size: 8pt; }')
289 page.append('div.sig { font-size: 8pt; }')
Steve McIntyrebfef5062015-10-30 18:28:32 +0000290 page.append('div.port {')
Steve McIntyre57a9d0a2015-10-28 18:22:31 +0000291 page.append(' display: block;')
292 page.append(' position: fixed;')
Steve McIntyrebfef5062015-10-30 18:28:32 +0000293 page.append(' left: 0px;')
Steve McIntyre57a9d0a2015-10-28 18:22:31 +0000294 page.append(' bottom: 0px;')
295 page.append(' z-index: 99;')
296 page.append(' background: #FFFF00;')
Steve McIntyrebfef5062015-10-30 18:28:32 +0000297 page.append(' border-style: solid;')
298 page.append(' border-width: 3pt;')
Steve McIntyre57a9d0a2015-10-28 18:22:31 +0000299 page.append(' border-color: #3B3B3B;')
Steve McIntyrebfef5062015-10-30 18:28:32 +0000300 page.append(' margin: 1;')
Steve McIntyre57a9d0a2015-10-28 18:22:31 +0000301 page.append(' padding: 5px;')
302 page.append(' font-size: 10pt;')
303 page.append(' font-family: Courier,monotype;')
Steve McIntyrebfef5062015-10-30 18:28:32 +0000304 page.append(' visibility: hidden;')
Steve McIntyre57a9d0a2015-10-28 18:22:31 +0000305 page.append('}')
Steve McIntyreb74ea6b2015-09-24 20:45:31 +0100306 self.wfile.write('\r\n'.join(page))
Steve McIntyre2454bf02015-09-23 18:33:02 +0100307
Steve McIntyree8f39df2015-10-28 18:36:39 +0000308 # Generate a PNG showing the layout of switches/port/trunks for a
309 # specific VLAN
Steve McIntyre2454bf02015-09-23 18:33:02 +0100310 def send_graphic(self):
311 vlan_id = 0
312 vlan_re = re.compile(r'^/images/vlan/(\d+).png$')
313 match = vlan_re.match(self.parsed_path.path)
314 if match:
Steve McIntyre57a9d0a2015-10-28 18:22:31 +0000315 vlan_id = int(match.group(1))
316 cache = self.server.state.cache
317
Steve McIntyredef26862015-10-29 17:35:10 +0000318 # Do we have a graphic for this VLAN ID?
Steve McIntyre57a9d0a2015-10-28 18:22:31 +0000319 if not vlan_id in cache.graphics.keys():
320 logging.debug('asked for vlan_id %s', vlan_id)
321 logging.debug(cache.graphics.keys())
Steve McIntyre2454bf02015-09-23 18:33:02 +0100322 self.send_response(404)
Steve McIntyre4f584a72015-09-28 02:28:56 +0100323 self.wfile.write('Content-type: text/plain\r\n')
Steve McIntyre2454bf02015-09-23 18:33:02 +0100324 self.end_headers()
Steve McIntyre4f584a72015-09-28 02:28:56 +0100325 self.wfile.write('404 Not Found\r\n')
Steve McIntyre0f561cd2015-10-28 18:05:20 +0000326 self.wfile.write('%s' % self.parsed_path.path)
Steve McIntyre4f584a72015-09-28 02:28:56 +0100327 logging.error('VLAN graphic not found - asked for %s', self.parsed_path.path)
Steve McIntyre2454bf02015-09-23 18:33:02 +0100328 return
329
Steve McIntyre57a9d0a2015-10-28 18:22:31 +0000330 # Yes - just send it from the cache
331 self.send_response(200)
332 self.wfile.write('Content-type: image/png\r\n')
333 self.end_headers()
334 self.wfile.write(cache.graphics[vlan_id]['image']['png'].getvalue())
335 return
336
337 # Generate a PNG showing the layout of switches/port/trunks for a
338 # specific VLAN, and return that PNG along with geometry details
339 def generate_graphic(self, vlan_id):
340 db = self.server.state.db
341 vlan = db.get_vlan_by_id(vlan_id)
342 # We've been asked for a VLAN that doesn't exist
343 if vlan is None:
344 return None
345
346 data = {}
347 data['image'] = {}
348 data['ports'] = {}
349
Steve McIntyre2454bf02015-09-23 18:33:02 +0100350 gim = Graphics()
351
Steve McIntyre2454bf02015-09-23 18:33:02 +0100352 # Pick fonts. TODO: Make these configurable?
353 gim.set_font(['/usr/share/fonts/truetype/inconsolata/Inconsolata.otf',
354 '/usr/share/fonts/truetype/freefont/FreeMono.ttf'])
355 try:
356 gim.font
357 # If we can't get the font we need, fail
358 except NameError:
359 self.send_response(500)
Steve McIntyre4f584a72015-09-28 02:28:56 +0100360 self.wfile.write('Content-type: text/plain\r\n')
Steve McIntyre2454bf02015-09-23 18:33:02 +0100361 self.end_headers()
Steve McIntyre4f584a72015-09-28 02:28:56 +0100362 self.wfile.write('500 Internal Server Error\r\n')
363 logging.error('Unable to generate graphic, no fonts found - asked for %s',
364 self.parsed_path.path)
Steve McIntyre2454bf02015-09-23 18:33:02 +0100365 return
366
367 switch = {}
368 size_x = {}
369 size_y = {}
370
371 switches = db.all_switches()
372
373 # Need to set gaps big enough for the number of trunks, at least.
374 trunks = db.all_trunks()
375 y_gap = max(20, 15 * len(trunks))
376 x_gap = max(20, 15 * len(trunks))
377
378 x = 0
379 y = y_gap
380
381 # Work out how much space we need for the switches
382 for i in range(0, len(switches)):
383 ports = db.get_ports_by_switch(switches[i].switch_id)
384 switch[i] = Switch(gim, len(ports), switches[i].name)
385 (size_x[i], size_y[i]) = switch[i].get_dimensions()
386 x = max(x, size_x[i])
387 y += size_y[i] + y_gap
388
389 # Add space for the legend and the label
390 label = "VLAN %d - %s" % (vlan.tag, vlan.name)
391 (legend_width, legend_height) = gim.get_legend_dimensions()
392 (label_width, label_height) = gim.get_label_size(label, gim.label_font_size)
393 x = max(x, legend_width + 2*x_gap + label_width)
394 x = x_gap + x + x_gap
395 y = y + max(legend_height + y_gap, label_height)
396
397 # Create a canvas of the right size
398 gim.create_canvas(x, y)
399
400 # Draw the switches and ports in it
401 curr_y = y_gap
402 for i in range(0, len(switches)):
403 switch[i].draw_switch(gim, x_gap, curr_y)
404 ports = db.get_ports_by_switch(switches[i].switch_id)
Steve McIntyre57a9d0a2015-10-28 18:22:31 +0000405 data['ports'][i] = {}
Steve McIntyre2454bf02015-09-23 18:33:02 +0100406 for port_id in ports:
407 port = db.get_port_by_id(port_id)
Steve McIntyre57a9d0a2015-10-28 18:22:31 +0000408 port_location = switch[i].get_port_location(port.number)
409 data['ports'][i][port.number] = {}
410 data['ports'][i][port.number]['db'] = port
411 data['ports'][i][port.number]['location'] = port_location
Steve McIntyre2454bf02015-09-23 18:33:02 +0100412 if port.is_locked:
413 switch[i].draw_port(gim, port.number, 'locked')
414 elif port.is_trunk:
415 switch[i].draw_port(gim, port.number, 'trunk')
416 elif port.current_vlan_id == int(vlan_id):
417 switch[i].draw_port(gim, port.number, 'VLAN')
418 else:
419 switch[i].draw_port(gim, port.number, 'normal')
420 curr_y += size_y[i] + y_gap
421
422 # Now add the trunks
423 for i in range(0, len(trunks)):
424 ports = db.get_ports_by_trunk(trunks[i].trunk_id)
425 port1 = db.get_port_by_id(ports[0])
426 port2 = db.get_port_by_id(ports[1])
427 for s in range(0, len(switches)):
428 if switches[s].switch_id == port1.switch_id:
429 switch1 = s
430 if switches[s].switch_id == port2.switch_id:
431 switch2 = s
432 gim.draw_trunk(i,
433 switch[switch1].get_port_location(port1.number),
434 switch[switch2].get_port_location(port2.number),
435 gim.port_pallette['trunk']['trace'])
436
437 # And the legend and label
438 gim.draw_legend(x_gap, curr_y)
439 gim.draw_label(x - label_width - 2*x_gap, curr_y, label, int(x_gap / 2))
440
Steve McIntyre57a9d0a2015-10-28 18:22:31 +0000441 # All done - push the image file into the cache for this vlan
442 data['image']['png'] = cStringIO.StringIO()
443 gim.im.writePng(data['image']['png'])
444 data['image']['width'] = x
445 data['image']['height'] = y
446 return data
Steve McIntyre2454bf02015-09-23 18:33:02 +0100447
448 # Implement an HTTP GET handler for the HTTPServer instance
449 def do_GET(self):
450 # Compare the URL path to any of the names we recognise and
451 # call the right generator function if we get a match
452 self.parsed_path = urlparse.urlparse(self.path)
453 for url in self.functionMap:
454 match = re.match(url['re'], self.parsed_path.path)
455 if match:
456 return url['fn'](self)
457
458 # Fall-through for any files we don't recognise
459 self.send_response(404)
Steve McIntyre4f584a72015-09-28 02:28:56 +0100460 self.wfile.write('Content-type: text/plain\r\n')
Steve McIntyre2454bf02015-09-23 18:33:02 +0100461 self.end_headers()
462 self.wfile.write('404 Not Found')
Steve McIntyre0f561cd2015-10-28 18:05:20 +0000463 self.wfile.write('%s' % self.parsed_path.path)
Steve McIntyre4f584a72015-09-28 02:28:56 +0100464 logging.error('File not supported - asked for %s', self.parsed_path.path)
Steve McIntyre2454bf02015-09-23 18:33:02 +0100465 return
466
467 # Override the BaseHTTPRequestHandler log_message() method so we
468 # can log requests properly
Steve McIntyre9ff96bf2015-09-23 18:54:53 +0100469 def log_message(self, fmt, *args):
Steve McIntyre2454bf02015-09-23 18:33:02 +0100470 """Log an arbitrary message. """
Steve McIntyre9ff96bf2015-09-23 18:54:53 +0100471 logging.info('%s %s', self.client_address[0], fmt%args)
Steve McIntyre2454bf02015-09-23 18:33:02 +0100472
473 functionMap = (
Steve McIntyre9ff96bf2015-09-23 18:54:53 +0100474 {'re': r'^/$', 'fn': send_index},
475 {'re': r'^/style.css$', 'fn': send_style},
476 {'re': r'^/images/vlan/(\d+).png$', 'fn': send_graphic}
Steve McIntyre2454bf02015-09-23 18:33:02 +0100477 )