pvl/verkko/dhcp.py
changeset 178 f9f5e669bace
child 184 eef756d892e9
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pvl/verkko/dhcp.py	Sat Jan 26 17:52:40 2013 +0200
@@ -0,0 +1,72 @@
+# encoding: utf-8
+import pvl.web
+import pvl.verkko.web
+
+from pvl.web import html, urls
+from pvl.verkko import hosts
+
+import logging; log = logging.getLogger('pvl.verkko.dhcp')
+
+class Index (pvl.verkko.web.DatabaseHandler) :
+    TITLE = u"Päivölä Verkko"
+
+    CSS = pvl.verkko.web.DatabaseHandler.CSS + (
+            '/static/dhcp/forms.css',
+    )
+
+    def render_link (self, title, **opts) :
+        return html.a(href=self.url(hosts.ListHandler, **opts))(title)
+
+    def render_links (self, attr, titlevalues) :
+        return html.ul(
+                html.li(
+                    self.render_link(title, **{attr: value})
+                ) for title, value in titlevalues
+        )
+
+    def render (self) :
+        return (
+            html.h2("Interval"),
+            self.render_links('seen', (
+                        ("Hour",    '1h'),
+                        ("Day",     '1d'),
+                        #("Month",   '30d'),
+                        #("Year",    '365d'),
+            )),
+            html.h2("State"),
+            self.render_links('state', (
+                        ("Valid",       ('DHCPACK', 'DHCPRELEASE')),
+                        ("Incomplete",  ('DHCPDISCOVER', 'DHCPOFFER', 'DHCPREQUEST')),
+                        ("Invalid",     ('DHCPNAK', )),
+            )),
+
+            html.h2("IP/MAC"),
+            html.form(action=self.url(hosts.ListHandler), method='get')(
+                html.fieldset(
+                    html.ul(
+                        html.li(
+                            html.label(for_='ip')("IP"),
+                            html.input(type='text', name='ip'),
+                        ),
+
+                        html.li(
+                            html.label(for_='mac')("MAC"),
+                            html.input(type='text', name='mac'),
+                        ),
+
+                        html.li(
+                            html.input(type='submit', value="Search"),
+                        ),
+                    )
+                )
+            ),
+        )
+
+class Application (pvl.verkko.web.Application) :
+    URLS = urls.Map((
+        urls.rule('/',                       Index),
+        urls.rule('/hosts/',                 hosts.ListHandler),
+        urls.rule('/hosts/<int:id>',         hosts.ItemHandler),
+        urls.rule('/hosts/realtime',         hosts.RealtimeHandler),
+    ))
+