Index: controlies/trunk/applications/controlies/controllers/hosts.py
===================================================================
--- controlies/trunk/applications/controlies/controllers/hosts.py	(revision 203)
+++ controlies/trunk/applications/controlies/controllers/hosts.py	(revision 204)
@@ -8,7 +8,7 @@
 @service.json    
 def getThinclientGroups():
     l=conecta()
-    h = Hosts (l,"","","","","")
+    h = Hosts (l,"","","","")
     response = h.getThinclientGroups()
     l.close()
     return dict(response=response)
@@ -17,7 +17,7 @@
 @service.json
 def getHostData():
     l=conecta()
-    h = Hosts(l,request.vars['cn'],"","",request.vars['group'],request.vars['type'])
+    h = Hosts(l,request.vars['cn'],"","",request.vars['type_host'])
     response = h.getHostData()    
     l.close()
     return dict(response=response)
@@ -26,7 +26,7 @@
 @auth.requires_login()
 def list_ltspservers():
     l=conecta()
-    h = Hosts (l,"","","","","")
+    h = Hosts (l,"","","","")
     response = h.getLTSPServers()
     l.close()
     return response    
@@ -36,7 +36,7 @@
 @auth.requires_login()
 def list():
     l=conecta()
-    h = Hosts (l,"","","","","")
+    h = Hosts (l,"","","","")
     a=request.vars
     response = h.list(a)    
     l.close()
@@ -47,9 +47,9 @@
 def modify():
     l=conecta()
     ip=''
-    if request.vars['type']!='thinclient':ip=request.vars['ip']
-    h = Hosts(l,request.vars['name'],ip,request.vars['mac'],request.vars['group'],request.vars['type'])
-    response=h.process(request.vars['action']  )
+    if request.vars['type_host']!='thinclient':ip=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)
    
@@ -57,7 +57,7 @@
 @auth.requires_login()    
 def delete():
     l=conecta()
-    h = Hosts(l,request.vars['cn'],"","",request.vars['group'],request.vars['type'])
+    h = Hosts(l,request.vars['cn'],"","",request.vars['type_host'])
     response=h.process(request.vars['action']  )
     l.close()
     return dict(response=response)
Index: controlies/trunk/applications/controlies/modules/Utils/ValidationUtils.py
===================================================================
--- controlies/trunk/applications/controlies/modules/Utils/ValidationUtils.py	(nonexistent)
+++ controlies/trunk/applications/controlies/modules/Utils/ValidationUtils.py	(revision 204)
@@ -0,0 +1,38 @@
+##############################################################################
+# -*- coding: utf-8 -*-
+# Project:     ControlIES
+# Module:    ValidationUtils.py
+# Purpose:     Utils of validation
+# Language:    Python 2.5
+# Date:        3-Oct-2011.
+# Ver:         3-Oct-2011.
+# Author:	Manuel Mora Gordillo
+# Copyright:    2011 - Manuel Mora Gordillo <manuito @no-spam@ gmail.com>
+#
+# ControlIES is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+# ControlIES is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+# You should have received a copy of the GNU General Public License
+# along with ControlIES. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+def validIP(address):
+    parts = address.split(".")
+    if len(parts) != 4:
+        return False
+    for item in parts:
+        if not 0 <= int(item) <= 255:
+            return False
+    return True
+
+def validMAC(address):
+    import re
+    if re.match("[0-9a-f]{2}([-:][0-9a-f]{2}){5}$", address.lower()):
+        return True
+    return False
Index: controlies/trunk/applications/controlies/modules/Hosts.py
===================================================================
--- controlies/trunk/applications/controlies/modules/Hosts.py	(revision 203)
+++ controlies/trunk/applications/controlies/modules/Hosts.py	(revision 204)
@@ -29,6 +29,7 @@
 import time
 from math import ceil
 from operator import itemgetter
+from Utils import ValidationUtils
 
 class Hosts(object):
 
@@ -35,13 +36,12 @@
     def __init__(self):
         pass
     
-    def __init__(self,ldap,name,ip,mac,group,type):
+    def __init__(self,ldap,name,ip,mac,type_host):
         self.ldap = ldap
         self.name = name
         self.ip = ip
         self.mac = mac
-        self.group = group 
-        self.type = type
+        self.type_host = type_host
     
     def getName (self):
         return self.mac 
@@ -49,25 +49,31 @@
     def validation(self,action):
 
         if action == "add":
-            if self.type == "none":
-                return "type"
+            if self.type_host == "none":
+                return "type_host"
         
         if self.name == "":
             return "name"
             
-        if self.type <> 'thinclient':
+        if self.type_host <> 'thinclient':
             if self.ip == "":
                 return "ip"
 
+        if not ValidationUtils.validIP(self.ip):
+            return "ip"
+
         if self.mac == "":
             return "mac"
-            
-        if self.type =="thinclient":
+
+        if not ValidationUtils.validMAC(self.mac):
+            return "mac"
+                        
+        if self.type_host =="thinclient":
             if self.group == "":
                 return "group"
 
-        if self.type == "":
-            return "type"
+        if self.type_host == "":
+            return "type_host"
         
         if action == "add":
             if self.existsHostname():
@@ -74,7 +80,7 @@
                 return "hostAlreadyExists"
         
             # thinclients no requieren ip, la cogen dinamicamente en el aula
-            if self.type <> "thinclient":
+            if self.type_host <> "thinclient":
                 if self.existsIP():
                     return "ipAlreadyExists"
             #controlar overflow en nodos        
@@ -94,6 +100,7 @@
         return "OK"     
         
     def process(self,action):
+
         if action == "add":
             val = self.validation(action)
             
@@ -121,12 +128,7 @@
             return response 
             
     def list(self,args):
-        
-        #from Plugins.LdapConnection import LdapConnection
-
-        #l = LdapConnection("172.23.36.5",'cn=admin,ou=People,dc=instituto,dc=extremadura,dc=es',"Sta1987teleco")
-        #l.connect()
-        
+                
         # grid parameters
         limit = int(args['rows'])
         page = int(args['page'])
@@ -144,10 +146,10 @@
             reverseSort = True
         
         #Distinguimos entre hosts ltsp, workstations y portatiles
-        type = args['type']
+        type_host = args['type_host']
         
                         
-        if type == "ltsp":
+        if type_host == "ltsp":
             # Obtengo todos los elementos del nodo hosts
             #search = l.search("ou=hosts","cn=*",["cn","ipHostNumber","macAddress"])
             #filter = self.buildFilter(args)        
@@ -186,7 +188,7 @@
             result = sorted(rows, key=itemgetter(sortBy), reverse=reverseSort)
             return { "page":page, "total":totalPages, "records":len(rows), "rows":result[start:finish]  }       
                 
-        elif type == "thinclient":
+        elif type_host == "thinclient":
             search = self.ldap.search("cn=THINCLIENTS,cn=DHCP Config","cn=*",["cn","dhcpHWAddress"])
             filter="(|(dhcpOption=*subnet*)(dhcpOption=*log*))"
             
@@ -213,7 +215,7 @@
             result = sorted(rows, key=itemgetter(sortBy), reverse=reverseSort)
             return { "page":page, "total":totalPages, "records":len(rows), "rows":result[start:finish] }                    
         
-        elif type == "workstation":
+        elif type_host == "workstation":
             # 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"])                 
@@ -259,7 +261,7 @@
             return { "page":page, "total":totalPages, "records":len(rows), "rows":result[start:finish] }        
 
     def add(self):
-        if self.type=="thinclient":
+        if self.type_host=="thinclient":
             attr = [
             ('objectclass', ['top','dhcpHost']),
             ('cn', [self.name] ),
@@ -282,7 +284,7 @@
         return "OK"
 
     def delete(self):
-        if self.type=="thinclient":
+        if self.type_host=="thinclient":
             self.ldap.delete('cn='+ self.name +',cn=' +self.group +',cn=THINCLIENTS,cn=DHCP Config')
 
         return "OK"     
@@ -292,7 +294,7 @@
         NetworkUtils.startup(self.mac)
         
     def groupOverflow(self,overflow):
-        if self.type == 'thinclient':
+        if self.type_host == 'thinclient':
             search = self.ldap.search("cn=" + self.group +",cn=THINCLIENTS,cn=DHCP Config","cn=*",["cn"])
             if len(search)-2 >= overflow:
                 return True
@@ -301,7 +303,7 @@
             
     def existsHostname(self):
         
-        if self.type == 'thinclient':
+        if self.type_host == 'thinclient':
             result = self.ldap.search("cn=THINCLIENTS,cn=DHCP Config","cn="+self.name,["cn"])
         else:
             result = self.ldap.search("ou=hosts","cn="+self.name,["cn"])
@@ -313,7 +315,7 @@
         
     def existsMAC(self):
         # Compruebo con las macs de la rama hosts
-        if self.type == 'thinclient':
+        if self.type_host == 'thinclient':
             result = self.ldap.search("cn=THINCLIENTS,cn=DHCP Config","dhcpHWAddress=*",["dhcpHWAddress"])
             for i in range (0, len(result) - 1):
                 if result [i][0][1]['dhcpHWAddress'][0].replace ("ethernet ", "") == self.mac:
Index: controlies/trunk/applications/controlies/views/layout_form_hosts.html
===================================================================
--- controlies/trunk/applications/controlies/views/layout_form_hosts.html	(revision 203)
+++ controlies/trunk/applications/controlies/views/layout_form_hosts.html	(revision 204)
@@ -76,8 +76,8 @@
 <form id="form_data" onSubmit="return send();">
     <input type="hidden" id="action" name="action"/>
 {{block form_table}}    
-   <input type="hidden" id="type" name="type" value="ltsp"/>
-    <p><span id="nameTag">Nombre del equipo:</span><br><input type="text" id="name" name="name" onChange="searchUsername();"/></p>
+   <input type="hidden" id="type_host" name="type_host" value="ltsp"/>
+    <p><span id="nameTag">Nombre del equipo:</span><br><input type="text" id="name" name="name" maxlength="20" onChange="searchUsername();"/></p>
     <p><span id="ipTag">Ip</span><br><input type="text" id="ip" name="ip"/></p> 
     <p><span id="macTag">MAC</span><br><input type="text" id="mac" name="mac"/></p>
 
Index: controlies/trunk/applications/controlies/views/layout_hosts.html
===================================================================
--- controlies/trunk/applications/controlies/views/layout_hosts.html	(revision 203)
+++ controlies/trunk/applications/controlies/views/layout_hosts.html	(revision 204)
@@ -46,7 +46,7 @@
                 {name:'macAddress',index:'macAddress', width:60, align:"center"}
             ], 
 
-            postData:{type:'ltsp'}, 
+            postData:{type_host:'ltsp'}, 
             caption:"Servidores de Aula (LTSP)",
 {{end}} 
             rowNum:25,
@@ -165,7 +165,7 @@
                     jQuery("#form_data #group").attr("readonly","true");
                     jQuery("#form_data #group").css("background-color","#DDD");
 {{block edit2_form}}                       
-                    jQuery.post('call/json/getHostData',{ cn: hid,group:group,type:'ltsp' }, function(result) {
+                    jQuery.post('call/json/getHostData',{ cn: hid,group:group,type_host:'ltsp' }, function(result) {
                         jQuery("#form_data #name").val(result.response['cn']);
                         jQuery("#form_data #ip").val(result.response['ip']);                        
                         jQuery("#form_data #mac").val(result.response['mac']);                           
@@ -231,7 +231,7 @@
             buttons: {
                 "Borrar": function() {
 {{block delete_host}}                
-                    jQuery.post("call/json/delete",{cn:cn,action:'delete',group:grupo,type:'ltsp'}, function(data){
+                    jQuery.post("call/json/delete",{cn:cn,action:'delete',group:grupo,type_host:'ltsp'}, function(data){
 {{end}}                    
                         jQuery("#dialog-confirm").dialog( "close" );
                         jQuery("#list").trigger("reloadGrid");
