Index: /tools/node-editor
===================================================================
--- /tools/node-editor	(revision 11514)
+++ /tools/node-editor	(revision 11515)
@@ -12,4 +12,12 @@
 import readline
 import sys
+import pyproj
+
+
+def latlon2rd(lon, lat):
+  p1 = pyproj.Proj(proj='latlon',datum='WGS84')
+  p2 = pyproj.Proj(init='EPSG:28992')
+  RDx, RDy = pyproj.transform(p1,p2, lon, lat)
+  return (int(RDx), int(RDy))
 
 
@@ -17,4 +25,7 @@
 
 DEBUG =  "-g" in sys.argv
+
+# Global variable, because this is dirty code.
+datadump = None
 
 def rlprompt(prompt, prefill=''):
@@ -40,5 +51,5 @@
   while True:
     try:
-      prefill = rlinput(prompt, prefill)
+      prefill = rlinput(prompt, str(prefill))
       return float(prefill)
     except ValueError:
@@ -78,4 +89,5 @@
   datadump['latitude'] =  rlinput_float("Latitude", datadump['latitude'])
   datadump['longitude'] = rlinput_float("Longitude", datadump['longitude'])
+  (datadump['rdnap_x'], datadump['rdnap_y']) = latlon2rd(datadump['longitude'], datadump['latitude'])
   datadump['autogen_item'] =  datadump['nodetype'] + datadump['nodename']
  
@@ -83,24 +95,56 @@
   master_network = getrange.get_ranges(False, 24, 1)[0]
   master_ip = getrange.showaddr(master_network + 1)
-  datadump['master_ip'] = master_ip
-
-  def new_access_point():
-    ifname = rlinput("Interface name", "ath0")
-    datadump['iface_' + ifname] = {
-      'ip' : rlinput(" - IP", master_ip + "/26"),
-      'dhcp' : rlinput(" - DHCP range", "10-60"),
-      'ssid' : rlinput(" - SSID", "ap-WirelessLeiden-" + datadump['nodename']),
-      'mode' : 'ap',
-      'type' : '11b',
-      'comment' : rlinput(" - Comment", "Omni voor de Buurt"),
-      'sdesc': rlinput(" - Short Description", "2buurt"),
-      'channel' : rlprompt(" - Channel", "10"),
-      'status' : 'up', 
-    }
-
+  datadump['masterip'] = master_ip
+
+  if os.path.exists(datadump['autogen_item']):
+    print "Warning Node does already exists, overwriting!"
+
+
+  # Secret global state variable
   newNode.if_nr = 0
+  def next_ifnr():
+    if_nr = newNode.if_nr
+    newNode.if_nr = newNode.if_nr + 1
+    return if_nr
+
+  def new_access_point(link_type='wireless'):
+    if link_type == 'wireless':
+      ifname = rlinput("Interface name", "ath0")
+      datadump['iface_' + ifname] = {
+        'ip' : rlinput(" - IP", master_ip + "/26"),
+        'dhcp' : rlinput(" - DHCP range", "10-60"),
+        'ssid' : rlinput(" - SSID", "ap-WirelessLeiden-" + datadump['nodename']),
+        'mode' : 'ap',
+        'type' : '11b',
+        'comment' : rlinput(" - Comment", "Omni voor de Buurt"),
+        'sdesc': rlinput(" - Short Description", "2buurt"),
+        'channel' : rlprompt(" - Channel", "10"),
+        'status' : 'up', 
+      }
+    elif link_type == 'wired':
+      if_nr = next_ifnr()
+      ifname = rlinput("Interface name", "vr%i" % if_nr)
+      netmask = int(rlinput_float("Netmask", 24))
+      print "Generating the Master IP range..."
+      link_network = getrange.get_ranges(False, netmask, 1, use_history=True)[0]
+      datadump['iface_' + ifname] = {
+        'ip' : rlinput(" - IP", gformat.showaddr(link_network + 1) + "/" + str(netmask)),
+        'dhcp' : rlinput(" - DHCP range", "10-60"),
+        'ssid' : rlinput(" - SSID", "ap-WirelessLeiden-" + datadump['nodename'] + '-' + ifname),
+        'comment' : rlinput(" - Comment", "Omni voor de Buurt"),
+        'type' : 'eth',
+        'sdesc': rlinput(" - Short Description", "2buurt"),
+        'channel' : rlprompt(" - Channel", "10"),
+        'status' : 'up', 
+        'mode': "ap",
+        'bridge_type': rlinput(' - Bridge Type', 'NanoStation5M'),
+        'ns_ip': rlinput(" - NS IP", getrange.showaddr(link_network + 2) + "/" + str(netmask)),
+        'ns_mac': rlinput(" - NS MAC", "00:27:22:"),
+      }
+
   def new_interlink(link_type='wireless', link_mode='station'):
-    ifname = rlinput("Interface name", "vr%i" % newNode.if_nr)
-    newNode.if_nr = newNode.if_nr + 1
+    if_nr = next_ifnr()
+    remote_datadump = None
+    ifname = rlinput("Interface name", "vr%i" % if_nr)
     netmask = 28
     if link_mode == 'station':
@@ -122,13 +166,13 @@
         else:
           print ''
-      iface = rlinput_choices("Remote interface", if_choices)
-      ifdump = remote_datadump['iface_%s' % iface]
+      remote_ifname = rlinput_choices("Remote interface", if_choices)
+      remote_ifdump = remote_datadump['iface_%s' % remote_ifname]
 
       #make_alias = rlprompt("Create Alias", "no") == "yes"
-      link_network = gformat.network(ifdump['ip'])
+      link_network = gformat.network(remote_ifdump['ip'])
     elif link_mode == 'master':
-      remote = rlinput("Interlink is planned for (remote host)", 'Unused%s' % newNode.if_nr)
+      remote = rlinput("Interlink is planned for (remote host)", 'Unused%s' % if_nr)
       print "Generating the Interlink IP range..."
-      link_network = getrange.get_ranges(True, netmask, 1)[0]
+      link_network = getrange.get_ranges(True, netmask, 1, use_history=True)[0]
 
     print "Using Network %s/%s" % (gformat.showaddr(link_network), netmask) 
@@ -161,9 +205,12 @@
       elif link_mode == 'station':
         datadump['iface_%s' % ifname].update({
-          'ssid': rlinput(" - SSID", ifdump['ssid']),
+          'ssid': rlinput(" - SSID", remote_ifdump['ssid']),
           'ip': rlinput(" - IP", getrange.showaddr(link_network + 3) + "/" + str(netmask)),
           'ns_ip': rlinput(" - NS IP", getrange.showaddr(link_network + 4) + "/" + str(netmask)),
           'mode': "station-wds",
         })
+        remote_datadump['iface_' + remote_ifname]['comment'] = 'Link naar %s' % datadump['nodename']
+        remote_datadump['iface_' + remote_ifname]['sdesc'] = '2%s' % datadump['nodename']
+
     elif link_type == 'wired':
       if link_mode == 'master':
@@ -175,33 +222,51 @@
           'ip': rlinput(" - IP", getrange.showaddr(link_network + 2) + "/" + str(netmask)),
         })
+        remote_datadump['iface_' + remote_ifname]['comment'] = 'Link naar %s' % datadump['nodename']
+        remote_datadump['iface_' + remote_ifname]['sdesc'] = '2%s' % datadump['nodename']
+
+    if remote_datadump:
+      # Alter remote side of interfaces
+      gformat.store_yaml(remote_datadump)
+    
 
   def printMenu(): 
     print '''\
 ==========================================
- Create Interfaces
-  
-  1) New Accesspoint (ath0)
-  2) New Wired Interlink (station)
-  3) New Wired Interlink (master)
-  4) New Wireless Interlink (station)
-  5) New Wireless Interlink (master)
+Create new Interface:
+  === Public Access Points ===
+  1) Accesspoint (ath0)
+  2) Accesspoint with Bridge/Switch (vr0)
+
+  === Wireless Interlinks ===
+  3) Wireless Bridge (master)
+  4) Wireless Bridge (station)
+
+  === Multiple Nodes at location ===
+  5) Ethernet Cross-connect (master)
+  6) Ethernet Cross-connect (station)
+
+  === When finished adding links ===
   9) Finish and Save
 ==========================================
   '''
 
-  choice = 5
-  while choice != 9:
+  choice = ''
+  while True:
     printMenu()
     choice = int(rlprompt("Choice", choice))
     if choice == 1:
-      new_access_point()
+      new_access_point('wireless')
     elif choice == 2:
-      new_interlink('wired', 'station')
+      new_access_point('wired')
     elif choice == 3:
       new_interlink('wired', 'master')
     elif choice == 4:
-      new_interlink('wireless', 'station')
+      new_interlink('wired', 'station')
     elif choice == 5:
       new_interlink('wireless', 'master')
+    elif choice == 6:
+      new_interlink('wireless', 'station')
+    elif choice == 9:
+      break
     else:
       print "Invalid choice!"
@@ -209,7 +274,9 @@
   # Output final result
   print datadump
-
-  #os.mkdir(datadump['autogen_item'])
-  #gformat.store_yaml(datadump)
+  if not os.path.exists(datadump['autogen_item']):
+    os.mkdir(datadump['autogen_item'])
+  gformat.store_yaml(datadump)
+
+  print "Please check changes and commit result"
   
 
