Index: controlies/trunk/applications/controlies/controllers/hosts.py
===================================================================
--- controlies/trunk/applications/controlies/controllers/hosts.py	(revision 222)
+++ controlies/trunk/applications/controlies/controllers/hosts.py	(revision 223)
@@ -51,6 +51,14 @@
     l.close()
     return dict(response=response)
 
+@service.json
+@auth.requires_login()    
+def getallranges():
+    from Utils import LdapUtils
+    l=conecta()
+    myRanges = LdapUtils.getAllRanges(l)
+    return dict(response=myRanges)
+    
 #necesaria estas funciones en el controlador para poder cargar las vistas correspondientes:    
 def ltspservers():
     return dict()
Index: controlies/trunk/applications/controlies/modules/Utils/LdapUtils.py
===================================================================
--- controlies/trunk/applications/controlies/modules/Utils/LdapUtils.py	(revision 222)
+++ controlies/trunk/applications/controlies/modules/Utils/LdapUtils.py	(revision 223)
@@ -53,6 +53,16 @@
 	
 	return { "departments":departments, "classrooms":classrooms }
 
+def getAllRanges(ldap):
+	myRange = []
+	my_search = ldap.search("dc=23,dc=172,dc=in-addr,dc=arpa,ou=hosts","dc=*",["dc"])
+	for s in my_search:
+		address = s[0][0].split(",")
+		if len(address) == 9:
+			myRange.append(address[0].replace("dc=",""))
+		
+	myRange.sort()
+	return myRange
 
 # Get the max ID of the groups and users
 def getMaxID(ldap): 
Index: controlies/trunk/applications/controlies/modules/Hosts.py
===================================================================
--- controlies/trunk/applications/controlies/modules/Hosts.py	(revision 222)
+++ controlies/trunk/applications/controlies/modules/Hosts.py	(revision 223)
@@ -116,8 +116,7 @@
             response = self.list();
             return response               
             
-    def list(self,args):
-        self.getIPRanges()        
+    def list(self,args):    
         # grid parameters
         limit = int(args['rows'])
         page = int(args['page'])
@@ -142,31 +141,31 @@
             # Obtengo todos los elementos del nodo hosts
             #search = l.search("ou=hosts","cn=*",["cn","ipHostNumber","macAddress"])
             #filter = self.buildFilter(args)        
-            search = self.ldap.search("ou=hosts","cn=*",["cn","ipHostNumber","macAddress"])     
-
-            # triplets que contiene los nombres de los ltsp-servers
-            hostnames = self.getLTSPServers()
+            hostnames = self.getListTriplets()
+            hostnames_data = {}
             
-            # Ahora tengo que quedarme con los elementos de search que estan en hostnames: los que son ltsp
-            resultado=list()
-            for element in search:
-                if element[0][1]["cn"][0] in hostnames:
-                    resultado.append(element)
+            search = self.ldap.search("cn=INTERNAL,cn=DHCP Config","cn=*",["cn","dhcpHWAddress"])     
+            for s in search:
+                if s[0][1]['cn'][0] in hostnames:
+					hostnames_data[s[0][1]['cn'][0]] = {"mac" : s[0][1]['dhcpHWAddress'][0].replace("ethernet ",""), "host":s[0][1]['cn'][0]}						
 
-            search = resultado 
-
+            search = self.ldap.search("dc="+self.domainname+",ou=hosts","dc=*",["dc","aRecord"])
+            for s in search:
+                if s[0][1]['dc'][0] in hostnames:
+					hostnames_data[s[0][1]['dc'][0]]["ip"] = s[0][1]['aRecord'][0]
+				
             rows = []
-            for i in search:
+            for k, v in hostnames_data.iteritems():
                 row = {
-                    "id":i[0][1]["cn"][0], 
-                    "cell":[i[0][1]["cn"][0], i[0][1]["ipHostNumber"][0],i[0][1]["macAddress"]],
-                    "cn":i[0][1]["cn"][0],
-                    "ipHostNumber":i[0][1]["ipHostNumber"][0],
-                    "macAddress":i[0][1]["macAddress"][0]
+                    "id":v["host"], 
+                    "cell":[v["host"], v["ip"],v["mac"]],
+                    "cn":v["host"],
+                    "ipHostNumber":v["ip"],
+                    "macAddress":v["mac"]
                 }
                 #row = { "cn":i[0][0], "cell":[i[0][1]["cn"][0], i[0][1]["ipHostNumber"][0],i[0][1]["macAddress"]]}
                 rows.append(row)
-                
+
             if len(rows) > 0:
                 totalPages = ceil( len(rows) / int(limit) )
             else:
@@ -224,7 +223,7 @@
 
     def add(self):
         # Hosts
-        attr = [
+        """attr = [
         ('objectclass', ['top','organizationalRole','domainRelatedObject','ipHost','ieee802Device']),
         ('associatedDomain', [self.domainname]),
         ('cn', [self.name]),
@@ -231,7 +230,7 @@
         ('macAddress', [self.mac]), 
         ('ipHostNumber', [self.ip])
         ]
-        self.ldap.add("cn="+self.name+",ou=Hosts", attr)
+        self.ldap.add("cn="+self.name+",ou=Hosts", attr)"""
 
         # Hosts->domain
         attr = [
@@ -255,7 +254,6 @@
         triplets = self.getTriplets()
         triplets.append('('+self.name+',-,-)')
         triplets.sort()
-		
         attr = [(ldap.MOD_REPLACE, 'nisNetgroupTriple', triplets )]
         self.ldap.modify("cn="+self.type_host+",ou=Netgroup", attr)
             
@@ -263,11 +261,11 @@
         
     def modify(self):
         # Hosts
-        attr = [
+        """attr = [
         (ldap.MOD_REPLACE, 'ipHostNumber', [self.ip] ),
         (ldap.MOD_REPLACE, 'macAddress', [self.mac])
         ]
-        self.ldap.modify("cn="+self.name+",ou=Hosts", attr)
+        self.ldap.modify("cn="+self.name+",ou=Hosts", attr)"""
 
         # Hosts->domain
         attr = [(ldap.MOD_REPLACE, 'aRecord', [self.ip] )]
@@ -280,7 +278,7 @@
         return "OK"
 
     def delete(self):
-        self.ldap.delete("cn="+self.name+",ou=Hosts")
+        """self.ldap.delete("cn="+self.name+",ou=Hosts")"""
         self.ldap.delete("dc="+self.name+",dc="+self.domainname+",ou=Hosts")
         self.ldap.delete("cn="+self.name+",cn=group1,cn=INTERNAL,cn=DHCP Config")
             
@@ -299,19 +297,21 @@
         NetworkUtils.startup(self.mac)
     
     def existsHostname(self):
-        result = self.ldap.search("ou=hosts","cn="+self.name,["cn"])
-        
-        if len(result) > 0:
+        if self.name in self.getListTriplets():
             return True
         
         return False
         
     def existsMAC(self):
-        result = self.ldap.search("ou=hosts","macAddress="+self.mac,["macAddress"])
+        search = self.ldap.search("cn=INTERNAL,cn=DHCP Config","cn=*",["cn","dhcpHWAddress"])
+        
+        for s in search:
+			try:
+				if s[0][1]["dhcpHWAddress"][0].replace("ethernet ","") == self.mac:
+					return True
+			except:
+				pass
 
-        if len(result) > 0:
-            return True
-        
         return False
 
 
@@ -330,15 +330,13 @@
         return False
 
     def equalMAC(self):
-        result = self.ldap.search("ou=hosts","cn="+self.name,["macAddress"])
-        if result[0][0][1]['macAddress'][0] == self.mac:
+        if self.getMAC() == self.mac:
             return True
         
         return False
 
-    def equalIP(self):
-        result = self.ldap.search("ou=hosts","cn="+self.name,["ipHostNumber"])
-        if result[0][0][1]['ipHostNumber'][0] == self.ip:
+    def equalIP(self):                
+        if self.getIP() == self.ip:
             return True
         
         return False
@@ -362,29 +360,35 @@
         triplets = self.ldap.search("ou=Netgroup","cn="+self.type_host+"",["nisNetgroupTriple"])
         triplets = triplets [0][0][1]["nisNetgroupTriple"]
         return triplets
+
+    def getListTriplets(self):
+        hostnames = []		
+        triplets = self.ldap.search("ou=Netgroup","cn="+self.type_host+"",["nisNetgroupTriple"])
+        triplets = triplets [0][0][1]["nisNetgroupTriple"]
+        
+        for t in triplets:
+            hostnames.append(t.replace("(","").replace(",-,-)",""))
+        return hostnames
             
-    def getHostData(self):       
-        result = self.ldap.search("ou=hosts","cn="+self.name,["cn","ipHostNumber","macAddress"])
+    def getHostData(self):
 
         dataHost = {
             "cn":self.name,
-            "mac":result[0][0][1]["macAddress"][0],
-            "ip":result[0][0][1]["ipHostNumber"][0]
+            "mac":self.getMAC(),
+            "ip":self.getIP()
         }
-        return dataHost     
-        
-    def getLTSPServers (self):
-        triplets = self.ldap.search("ou=Netgroup","cn="+self.type_host+"",["nisNetgroupTriple"])
-        triplets = triplets [0][0][1]["nisNetgroupTriple"]
-        hostnames=list()
-            
-        for node in triplets:
-            name = node.replace(",-,-)","").replace("(","")
-            hostnames.append(name)
-        hostnames.sort()
-        return hostnames
+        return dataHost             
 
+    def getIP(self):
+        search = self.ldap.search("dc="+self.domainname+",ou=hosts","dc="+self.name,["dc","aRecord"])
+        ip = search[0][0][1]["aRecord"][0]    
+        return ip
 
+    def getMAC(self):
+        search = self.ldap.search("cn=INTERNAL,cn=DHCP Config","cn="+self.name,["cn","dhcpHWAddress"])
+        mac = search[0][0][1]["dhcpHWAddress"][0].replace("ethernet ","")        
+        return mac
+
     def getLTSPStatus (self):
         from Utils.avahiClient import avahiClient
         import threading
@@ -403,13 +407,6 @@
         a.kill()"""
         return names
 
-    def getIPRanges(self):
-        ranges = self.ldap.search("dc=23,dc=172,dc=in-addr,dc=arpa,ou=hosts","dc=*",["dc"])
-        #print ranges
-        for r in ranges:
-			print ranges[2]
-        return True
-
 #   def wakeup(self):
 #       from twisted.internet.task import LoopingCall
 #       from twisted.internet import defer
Index: controlies/trunk/applications/controlies/views/layout_form_hosts.html
===================================================================
--- controlies/trunk/applications/controlies/views/layout_form_hosts.html	(revision 222)
+++ controlies/trunk/applications/controlies/views/layout_form_hosts.html	(revision 223)
@@ -6,7 +6,7 @@
           
         $("#cancelButton")
             .button({ icons: { primary: "ui-icon-close"}})
-            .click( function(){ $('#dialog-form').dialog('close'); });            
+            .click( function(){ $('#dialog-form').dialog('close'); });    
     });
 
     function restartStyle(){
@@ -83,3 +83,7 @@
     <div style="text-align:center;"><button id="saveButton" type="submit" style="width:100px;">Guardar</button>&nbsp;&nbsp;<button type="button" id="cancelButton" style="width:100px;">Cancelar</button></div>
     <p style="padding-top:10px; text-align:center; font-size:10px;" id="messageForm"></p>       
 </form>
+
+<script language="javascript">
+
+</script>
Index: controlies/trunk/applications/controlies/views/layout_hosts.html
===================================================================
--- controlies/trunk/applications/controlies/views/layout_hosts.html	(revision 222)
+++ controlies/trunk/applications/controlies/views/layout_hosts.html	(revision 223)
@@ -144,6 +144,10 @@
 
 
     function addRecord(){
+
+        jQuery.post('call/json/getallranges', {cn:"hola"}, function(result) {
+			alert("hola");
+		});
     
         jQuery("#dialog-form").html("");
         jQuery("#dialog-form").load("form_ltspserver.html", function() {
