chiark / gitweb /
mon/tripemon.in: Add per-peer key selection and mobile options.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 24 May 2014 13:00:03 +0000 (14:00 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 20 Jul 2014 00:42:31 +0000 (01:42 +0100)
mon/tripemon.in

index 63d2567..2462fff 100644 (file)
@@ -1065,48 +1065,66 @@ class AddPeerDialog (MyDialog):
                                ValidatingEntry(numericvalidate(0, 65535),
                                                '4070',
                                                5))
-    me.c_keepalive = G.CheckButton('Keepalives')
     me.l_tunnel = table.labelled('Tunnel', combo_box_text(),
                                  newlinep = True, width = 3)
     me.tuns = conn.tunnels()
     for t in me.tuns:
       me.l_tunnel.append_text(t)
     me.l_tunnel.set_active(0)
+
+    def tickybox_sensitivity(tickybox, target):
+      tickybox.connect('toggled',
+                       lambda t: target.set_sensitive (t.get_active()))
+
+    me.c_keepalive = G.CheckButton('Keepalives')
     table.pack(me.c_keepalive, newlinep = True, xopt = G.FILL)
-    me.c_keepalive.connect('toggled',
-                           lambda t: me.e_keepalive.set_sensitive\
-                                      (t.get_active()))
     me.e_keepalive = ValidatingEntry(r'^\d+[hms]?$', '', 5)
     me.e_keepalive.set_sensitive(False)
+    tickybox_sensitivity(me.c_keepalive, me.e_keepalive)
     table.pack(me.e_keepalive, width = 3)
+
+    me.c_mobile = G.CheckButton('Mobile')
+    table.pack(me.c_mobile, newlinep = True, width = 4, xopt = G.FILL)
+
+    me.c_peerkey = G.CheckButton('Peer key tag')
+    table.pack(me.c_peerkey, newlinep = True, xopt = G.FILL)
+    me.e_peerkey = ValidatingEntry(r'^[^.:\s]+$', '', 16)
+    me.e_peerkey.set_sensitive(False)
+    tickybox_sensitivity(me.c_peerkey, me.e_peerkey)
+    table.pack(me.e_peerkey, width = 3)
+
+    me.c_privkey = G.CheckButton('Private key tag')
+    table.pack(me.c_privkey, newlinep = True, xopt = G.FILL)
+    me.e_privkey = ValidatingEntry(r'^[^.:\s]+$', '', 16)
+    me.e_privkey.set_sensitive(False)
+    tickybox_sensitivity(me.c_privkey, me.e_privkey)
+    table.pack(me.e_privkey, width = 3)
+
     me.show_all()
 
   def ok(me):
     """Handle an OK press: create the peer."""
     try:
-      if me.c_keepalive.get_active():
-        ka = me.e_keepalive.get_text()
-      else:
-        ka = None
       t = me.l_tunnel.get_active()
-      if t == 0:
-        tun = None
-      else:
-        tun = me.tuns[t]
-        me._addpeer(me.e_name.get_text(),
-                    me.e_addr.get_text(),
-                    me.e_port.get_text(),
-                    ka,
-                    tun)
+      me._addpeer(me.e_name.get_text(),
+                  me.e_addr.get_text(),
+                  me.e_port.get_text(),
+                  keepalive = (me.c_keepalive.get_active() and
+                               me.e_keepalive.get_text() or None),
+                  tunnel = t and me.tuns[t] or None,
+                  key = (me.c_peerkey.get_active() and
+                         me.e_peerkey.get_text() or None),
+                  priv = (me.c_privkey.get_active() and
+                          me.e_privkey.get_text() or None))
     except ValidationError:
       GDK.beep()
       return
 
   @incr
-  def _addpeer(me, name, addr, port, keepalive, tunnel):
+  def _addpeer(me, *args, **kw):
     """Coroutine function: actually do the ADD command."""
     try:
-      conn.add(name, addr, port, keepalive = keepalive, tunnel = tunnel)
+      conn.add(*args, **kw)
       me.destroy()
     except T.TripeError, exc:
       T.defer(moanbox, ' '.join(exc))