Index: /trunk/exodus/models.py
===================================================================
--- /trunk/exodus/models.py	(revision 6315)
+++ /trunk/exodus/models.py	(revision 6317)
@@ -109,8 +109,12 @@
 		return "Alias %s" % (self.iface)
 
+#
+# XXX: Needs rethinking, dhcp[start|stop] could be removed if whole publicAP is
+# going to be activated as DHCP range, or only number of fixed clients needs to
+# be defined, all other could be calculated on the fly if needed
 class PublicAP(models.Model):
-    iface = models.ForeignKey(Interface)
+    iface = models.ForeignKey(Interface,related_name='ap')
     ip = models.IPAddressField(unique=True)
-    netmask = models.IntegerField(default=30)
+    netmask = models.IntegerField(default=28)
     dhcpstart = models.IPAddressField()
     dhcpstop = models.IPAddressField()
Index: /trunk/exodus/templates/addomni.html
===================================================================
--- /trunk/exodus/templates/addomni.html	(revision 6315)
+++ /trunk/exodus/templates/addomni.html	(revision 6317)
@@ -2,5 +2,5 @@
 
 {% block content %}
-<h1>Add an Omni</h1>
+<h1>Add an public access point</h1>
 
 <form method="post" action=".">
Index: /trunk/exodus/templates/exodus-template.html
===================================================================
--- /trunk/exodus/templates/exodus-template.html	(revision 6315)
+++ /trunk/exodus/templates/exodus-template.html	(revision 6317)
@@ -17,7 +17,4 @@
 	  &nbsp;&nbsp;<A class="menu" href="{% url exodus.views.addLocation %}">Add Location</a><br>
 	  &nbsp;&nbsp;<A class="menu" href="{% url exodus.views.addNode %}">Add Node</a><br>
-	  &nbsp;&nbsp;<A class="menu" href="{% url exodus.views.addInterface %}">Add Interface</a><br>
-	  &nbsp;&nbsp;<A class="menu" href="{% url exodus.views.addPublicAP %}">Add PublicAP</a><br>
-	  &nbsp;<p>
 	</td>
 	<td valign="top" class="right">
Index: /trunk/exodus/templates/node-detail.html
===================================================================
--- /trunk/exodus/templates/node-detail.html	(revision 6315)
+++ /trunk/exodus/templates/node-detail.html	(revision 6317)
@@ -17,10 +17,10 @@
 
 <h2>Interfaces</h2>
-<a href="{% url exodus.views.addInterface %}?node={{ object.name }}">Add new interface</a>
+<a href="{% url exodus.views.addInterface %}?node={{ object.name }}">Add new interface</a><p />
 
 {% for nic in object.interface_set.all %}
-	<p>
 	<div style="border:1px solid #000000;">
 	<h3>iface: {{ nic.iface }} </h3>
+	<a href="{% url exodus.views.addPublicAP %}?iface={{ nic }}">Add new public access point</a><p />
 	type: {{ nic.type }} <br>
 	description: {{ nic.shortdesc }} <br>
@@ -35,4 +35,5 @@
 	{% endifnotequal %}
 	<a href="{% url exodus.views.editInterface nic %}">EDIT</a>
+	<a href="{% url exodus.views.delInterface nic %}">DELETE</a>
 	</div>
 
@@ -51,9 +52,10 @@
 	{% endfor %}
 	
-	
-	{% for omni in nic.omni.all %}
-		<ul>
-		<li>DHCP {{ omni.dhcpstart }}-{{ omni.dhcpstop }}</li>
-		{% for dhcp in omni.dhcpstatic.all %}
+	<ul>
+	{% for accessPoint in nic.ap.all %}
+		<div style="border:1px solid #000000;">
+		<p />
+		<li>Public Access Point: {{ accessPoint.ip}}/{{accessPoint.netmask }}
+		{% for dhcp in accessPoint.dhcpstatic.all %}
 			<ul>
 			    <li>Hostname: {{ dhcp.hostname }} </li>
@@ -61,6 +63,9 @@
 			</ul>
 		{% endfor %}
-		</ul>
+        </li>
+		<p />
+		</div>
 	{% endfor %}
+	</ul>
 {% endfor %}
 
Index: /trunk/exodus/views.py
===================================================================
--- /trunk/exodus/views.py	(revision 6315)
+++ /trunk/exodus/views.py	(revision 6317)
@@ -11,5 +11,5 @@
 
 from exodus.models import *
-from exodus.wllogic import freeMasterIP, newSSIDName, addInterlinkIP, freeInterlinkIP
+from exodus.wllogic import freeMasterIP, newSSIDName, addInterlinkIP, freeInterlinkIP, freePublicAPIP
 
 class AddLocationForm(forms.ModelForm):
@@ -203,5 +203,5 @@
 	class Meta:
 		model = PublicAP
-		exclude = ('shortdesc', 'desc')
+		exclude = ('shortdesc', 'desc', 'ip', 'dhcpstart', 'dhcpstop')
 
 def addPublicAP(request):
@@ -210,9 +210,22 @@
 		if form.is_valid():
 			instance = form.save(commit=False)
+			# Find IP range inside interface range with disired size/subnet
+			instance.ip = freePublicAPIP(instance.iface, instance.netmask)
+			instance.dhcpstart = 1
+			instance.dhcpstop = 2
+			# If wireless generate ssid name
 			instance.ssid = newSSIDName(instance.iface.node, instance.iface, 'omni')
 			instance.save()
-			return HttpResponseRedirect(reverse('nodelist'))
-	else:
-		form = addPublicAPForm()
+			nodeName = instance.iface.node
+			return HttpResponseRedirect(reverse('node-detail', args=[nodeName]))
+	else:
+		#XXX: Link, master interfaces only
+		if 'iface' in request.GET:
+			nodeName, interfaceName = request.GET['iface'].split(':')
+			newPublicAP = PublicAP()
+			newPublicAP.iface = Interface.objects.get(iface=interfaceName, node=nodename2id(nodeName))
+			form = addPublicAPForm(instance=newPublicAP)
+		else:
+			form = addPublicAPForm()
 	return render_to_response('addomni.html', {'form': form })
 
Index: /trunk/exodus/wllogic.py
===================================================================
--- /trunk/exodus/wllogic.py	(revision 6315)
+++ /trunk/exodus/wllogic.py	(revision 6317)
@@ -1,5 +1,5 @@
 # (c) Roland van Laar
 
-from exodus.models import Node, Interface
+from exodus.models import Node, Interface, PublicAP
 
 def newSSIDName(node, nic, desc):
@@ -66,4 +66,34 @@
 	return showaddr(i)
 
+#
+# XXX: Needs merging with freeInterlinkIP as interface could have both AP, interlink difined on one link
+def freePublicAPIP(masterLink, netmask):
+	taken = {}
+
+	for interface in Interface.objects.filter(link=masterLink):
+		#Grr, needs all interfaces which are master requires a bit of a hack
+		addr = network(interface.ip, interface.netmask)
+		addrMax = broadcast(interface.ip, interface.netmask)
+		while addr < addrMax:
+			taken[addr] = 1
+			addr = addr + 1
+
+	for accessPoint in PublicAP.objects.filter(iface=masterLink):
+		#Grr, needs all interfaces which are master requires a bit of a hack
+		addr = network(accessPoint.ip, accessPoint.netmask)
+		addrMax = broadcast(accessPoint.ip, accessPoint.netmask)
+		while addr < addrMax:
+			taken[addr] = 1
+			addr = addr + 1
+
+	#Should be dynamic based on the number of hosts in here
+	size = netmask
+	numaddrs = 1 << (32 - size)
+	i = network(masterLink.ip,masterLink.netmask)
+	while taken.has_key(i):
+		i = i + numaddrs
+	
+	return showaddr(i)
+
 def freeInterlinkIP(masterLink):
 	taken = {}
