Index: controlies/trunk/applications/controlies/controllers/hosts.py
===================================================================
--- controlies/trunk/applications/controlies/controllers/hosts.py	(revision 223)
+++ controlies/trunk/applications/controlies/controllers/hosts.py	(revision 224)
@@ -37,7 +37,8 @@
 @auth.requires_login()
 def modify():
     l=conecta()
-    h = Hosts(l,request.vars['name'],request.vars['ip'],request.vars['mac'],request.vars['type_host'])
+    ip = "172."+request.vars['subrange']+"."+request.vars['range']+"."+request.vars['ip']    
+    h = Hosts(l,request.vars['name'],ip,request.vars['mac'],request.vars['type_host'])
     response=h.process(request.vars['action'])
     l.close()
     return dict(response=response)
Index: controlies/trunk/applications/controlies/modules/Utils/LdapUtils.py
===================================================================
--- controlies/trunk/applications/controlies/modules/Utils/LdapUtils.py	(revision 223)
+++ controlies/trunk/applications/controlies/modules/Utils/LdapUtils.py	(revision 224)
@@ -55,14 +55,19 @@
 
 def getAllRanges(ldap):
 	myRange = []
-	my_search = ldap.search("dc=23,dc=172,dc=in-addr,dc=arpa,ou=hosts","dc=*",["dc"])
+	mySubRange = []	
+			
+	my_search = ldap.search("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=",""))
-		
+			
+		if len(address) == 8:
+			mySubRange.append(address[0].replace("dc=",""))
+
 	myRange.sort()
-	return myRange
+	return { "ranges":myRange, "subrange":mySubRange }
 
 # 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 223)
+++ controlies/trunk/applications/controlies/modules/Hosts.py	(revision 224)
@@ -131,96 +131,57 @@
         # reverse Sort
         reverseSort = False
         if args['sord'] == "asc":
-            reverseSort = True
-        
-        #Distinguimos entre hosts ltsp, workstations y portatiles
-        type_host = args['type_host']
-        
-                        
-        if type_host == "ltsp-server-hosts":
-            # Obtengo todos los elementos del nodo hosts
-            #search = l.search("ou=hosts","cn=*",["cn","ipHostNumber","macAddress"])
-            #filter = self.buildFilter(args)        
-            hostnames = self.getListTriplets()
-            hostnames_data = {}
-            
-            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]}						
+            reverseSort = True        
+                                
+        hostnames = self.getListTriplets()
+        hostnames_data = {}
+		
+        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 = 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 k, v in hostnames_data.iteritems():
-                row = {
-                    "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)
+        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 k, v in hostnames_data.iteritems():
+            try:
+				host = v["host"]
+            except:
+				pass
 
-            if len(rows) > 0:
-                totalPages = ceil( len(rows) / int(limit) )
-            else:
-                totalPages = 0
-            if page > totalPages:
-                page = totalPages
+            try:
+				ip = v["ip"]
+            except:
+				pass
 
-            result = sorted(rows, key=itemgetter(sortBy), reverse=reverseSort)
-            return { "page":page, "total":totalPages, "records":len(rows), "rows":result[start:finish]  }       
-        
-        elif type_host == "workstation-hosts":
-            # Obtengo todos los elementos del nodo hosts
-            #search = l.search("ou=hosts","cn=*",["cn","ipHostNumber","macAddress"])
-            search = self.ldap.search("ou=hosts","cn=*",["cn","ipHostNumber","macAddress"])                 
-            # triplets que contiene los nombres de las workstations
-            #triplets = l.search("ou=Netgroup","cn=workstation-hosts",["nisNetgroupTriple"])
-            triplets = self.ldap.search("ou=Netgroup","cn=workstation-hosts",["nisNetgroupTriple"])
-            triplets = triplets [0][0][1]["nisNetgroupTriple"]
-            hostnames=list()
-            
-            # obtengo lista de nombres de los hosts workstation
-            for node in triplets:
-                name = node.replace(",-,-)","").replace("(","")
-                hostnames.append(name)
-                
-            # Ahora tengo que quedarme con los elementos de search que estan en hostnames
-            resultado=list()
-            for element in search:
-                if element[0][1]["cn"][0] in hostnames:
-                    resultado.append(element)
-            
-            search = resultado 
+            try:
+				mac = v["mac"]
+            except:
+				pass
+				
+            row = {
+				"id":host, 
+				"cell":[host, ip, mac],
+				"cn":host,
+				"ipHostNumber":ip,
+				"macAddress":mac
+			}
+            rows.append(row)
 
-            rows = []
-            for i in search:
-                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]
-                }                       
-                #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:
+            totalPages = 0
+        if page > totalPages:
+            page = totalPages
 
-            if len(rows) > 0:
-                totalPages = ceil( len(rows) / int(limit) )
-            else:
-                totalPages = 0
-            if page > totalPages:
-                page = totalPages                   
+        result = sorted(rows, key=itemgetter(sortBy), reverse=reverseSort)
+        return { "page":page, "total":totalPages, "records":len(rows), "rows":result[start:finish]  }       
 
-            result = sorted(rows, key=itemgetter(sortBy), reverse=reverseSort)
-            return { "page":page, "total":totalPages, "records":len(rows), "rows":result[start:finish] }        
-
     def add(self):
         # Hosts
         """attr = [
@@ -241,6 +202,16 @@
         ]
         self.ldap.add("dc="+self.name+",dc="+self.domainname+",ou=Hosts", attr)
 
+        # Hosts->arpa->in-addr->172
+        ip = self.ip.split(".")
+        attr = [
+        ('objectclass', ['top','dNSDomain2','domainRelatedObject']),
+        ('associatedDomain', [ip[3]+"."+ip[2]+"."+ip[1]+"."+ip[0]+".in-addr.arpa"]),
+        ('dc', [ip[3]]), 
+        ('pTRRecord', [self.name+"."+self.domainname])
+        ]
+        self.ldap.add("dc="+ip[3]+",dc="+ip[2]+",dc="+ip[1]+",dc="+ip[0]+",dc=in-addr,dc=arpa,ou=Hosts", attr)
+
 		# DHCP Config
         attr = [
         ('objectclass', ['top','dhcpHost']),
@@ -278,9 +249,14 @@
         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")
+
+        myIP = self.getIP()
+        if myIP != "":
+            ip = myIP.split(".")
+            self.ldap.delete("dc="+ip[3]+",dc="+ip[2]+",dc="+ip[1]+",dc="+ip[0]+",dc=in-addr,dc=arpa,ou=Hosts")
             
         # Netgroup            
         triplets = self.getTriplets()
@@ -381,7 +357,11 @@
 
     def getIP(self):
         search = self.ldap.search("dc="+self.domainname+",ou=hosts","dc="+self.name,["dc","aRecord"])
-        ip = search[0][0][1]["aRecord"][0]    
+        ip=""
+        try:
+            ip = search[0][0][1]["aRecord"][0]
+        except:
+            pass
         return ip
 
     def getMAC(self):
Index: controlies/trunk/applications/controlies/views/layout_form_hosts.html
===================================================================
--- controlies/trunk/applications/controlies/views/layout_form_hosts.html	(revision 223)
+++ controlies/trunk/applications/controlies/views/layout_form_hosts.html	(revision 224)
@@ -6,7 +6,19 @@
           
         $("#cancelButton")
             .button({ icons: { primary: "ui-icon-close"}})
-            .click( function(){ $('#dialog-form').dialog('close'); });    
+            .click( function(){ $('#dialog-form').dialog('close'); });   
+
+        jQuery.post('call/json/getallranges', {}, function(result) {
+			$("#subrange").append(new Option(result.response["subrange"], result.response["subrange"]));
+			
+			for(i=0;i<result.response["ranges"].length;i++){
+				$("#range").append(new Option(result.response["ranges"][i], result.response["ranges"][i]));
+			}
+			for(i=1;i<256;i++){
+				$("#ip").append(new Option(i, i));
+			}
+		});
+
     });
 
     function restartStyle(){
@@ -76,7 +88,7 @@
     <input type="hidden" id="action" name="action"/>
     <input type="hidden" id="type_host" name="type_host"/>
     <p><span id="nameTag">Nombre del equipo:</span><br><input type="text" id="name" name="name" maxlength="20"/></p>
-    <p><span id="ipTag">Ip</span><br><input type="text" id="ip" name="ip" maxlength="15"/></p> 
+    <p><span id="ipTag">Ip</span><br>172.<select id="subrange" name="subrange"></select>.<select id="range" name="range"></select>.<select id="ip" name="ip"></select></p> 
     <p><span id="macTag">MAC</span><br><input type="text" id="mac" name="mac" maxlength="17"/></p>
 
     <div id="message" style="text-align:center; font-weight:bold; color:red; padding:3px; "></div>
Index: controlies/trunk/applications/controlies/views/layout_hosts.html
===================================================================
--- controlies/trunk/applications/controlies/views/layout_hosts.html	(revision 223)
+++ controlies/trunk/applications/controlies/views/layout_hosts.html	(revision 224)
@@ -121,11 +121,15 @@
 			jQuery("#form_data #name").css("background-color","#DDD");                   
 			jQuery.post('call/json/getHostData',{ cn:hid,type_host:type_host }, function(result) {
 				
-				jQuery("#form_data #name").val(result.response['cn']);
-				jQuery("#form_data #ip").val(result.response['ip']);                        
+				jQuery("#form_data #name").val(result.response['cn']);               
 				jQuery("#form_data #mac").val(result.response['mac']);                           
 				jQuery("#form_data #type_host").val(type_host);
 				
+				var ip = result.response['ip'].split(".");
+				jQuery("#form_data #subrange").val(ip[1]);
+				jQuery("#form_data #range").val(ip[2]);				
+				jQuery("#form_data #ip").val(ip[3]);								
+				
 				x = (jQuery(window).width()-300)/2;
 				y = (jQuery(window).height()-500)/2;
 				
@@ -144,10 +148,6 @@
 
 
     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() {
