118 db.mapper(Host, db.dhcp_hosts, properties=dict( |
118 db.mapper(Host, db.dhcp_hosts, properties=dict( |
119 #id = db.dhcp_hosts.c.rowid, |
119 #id = db.dhcp_hosts.c.rowid, |
120 #state = db.dhcp_hosts.c., |
120 #state = db.dhcp_hosts.c., |
121 )) |
121 )) |
122 |
122 |
|
123 |
|
124 |
|
125 |
123 class BaseHandler (web.Handler) : |
126 class BaseHandler (web.Handler) : |
124 HOST_ATTRS = { |
127 HOST_ATTRS = { |
125 'id': Host.id, |
128 'id': Host.id, |
126 'net': Host.gw, |
129 'net': Host.gw, |
127 'ip': Host.ip, |
130 'ip': Host.ip, |
252 render_cell('ip', host.ip, filter=True), |
255 render_cell('ip', host.ip, filter=True), |
253 render_cell('mac', host.mac, filter=True, htmlvalue=host.render_mac()), |
256 render_cell('mac', host.mac, filter=True, htmlvalue=host.render_mac()), |
254 render_cell('name', host.name, htmlvalue=host.render_name()), |
257 render_cell('name', host.name, htmlvalue=host.render_name()), |
255 render_cell('gw', host.gw), |
258 render_cell('gw', host.gw), |
256 |
259 |
257 html.td(host.when()), |
260 html.td(host.seen()), |
258 html.td(class_=host.state_class(), title=host.state_title())(host.state), |
261 html.td(class_=host.state_class(), title=host.state_title())(host.state), |
259 ) for i, host in enumerate(hosts) |
262 ) for i, host in enumerate(hosts) |
260 ), |
263 ), |
261 html.tfoot( |
264 html.tfoot( |
262 html.tr( |
265 html.tr( |
463 class RealtimeHandler (web.Handler) : |
466 class RealtimeHandler (web.Handler) : |
464 TITLE = "Pseudo-Realtime hosts.." |
467 TITLE = "Pseudo-Realtime hosts.." |
465 JS = ( |
468 JS = ( |
466 #"/static/jquery/jquery.js", |
469 #"/static/jquery/jquery.js", |
467 'http://code.jquery.com/jquery-1.8.2.js', |
470 'http://code.jquery.com/jquery-1.8.2.js', |
|
471 '/static/js/spin.js', |
468 '/static/hosts.js', |
472 '/static/hosts.js', |
469 ) |
473 ) |
470 |
474 |
471 def process (self) : |
475 def process (self) : |
472 hosts = self.db.query(Host).order_by(Host.last_seen.desc()) |
476 hosts = self.db.query(Host).order_by(Host.last_seen.desc()) |
504 |
519 |
505 def render (self) : |
520 def render (self) : |
506 params = dict( |
521 params = dict( |
507 url = self.url(), |
522 url = self.url(), |
508 t = dt2ts(self.t), |
523 t = dt2ts(self.t), |
|
524 host = self.url(ItemHandler, id='0'), |
509 ) |
525 ) |
510 params = json.dumps(params) |
526 params = json.dumps(params) |
511 |
527 |
512 return ( |
528 COLUMNS = ( |
513 html.input(type='submit', id='refresh', value="Refresh", _selfclosing=False), |
529 '#', 'IP', 'MAC', 'Hostname', 'Network', 'Seen', 'State' |
514 html.ul(id='hosts')( |
530 ) |
515 html.li(id=host.id)("{host.ip} / {host.mac}".format(host=host)) for host in self.hosts |
531 |
|
532 return html.div(id='wrapper')( |
|
533 html.input(type='submit', id='refresh', value="Refresh"), |
|
534 html.table(id='hosts')( |
|
535 html.thead( |
|
536 html.tr( |
|
537 html.th(title) for title in COLUMNS |
|
538 ), |
|
539 ), |
|
540 html.tbody( |
|
541 html.tr(id=host.id)( |
|
542 html.td(html.a(href=self.url(ItemHandler, id=host.id))('#')), |
|
543 ( |
|
544 html.td(value) for value in ( |
|
545 host.ip, host.mac, host.name, host.gw, host.seen(), |
|
546 ) |
|
547 ), |
|
548 html.td(class_=host.state_class())(host.state), |
|
549 ) for host in self.hosts |
|
550 ) |
516 ), |
551 ), |
517 html.script(type='text/javascript')(""" |
552 html.script(type='text/javascript')(""" |
518 $(document).ready(hosts_realtime({params})); |
553 $(document).ready(hosts_realtime({params})); |
519 """.format(params=params) |
554 """.format(params=params) |
520 ) |
555 ) |