Revisión 204
Añadido por Manu Mora Gordillo hace más de 13 años
controlies/trunk/applications/controlies/controllers/hosts.py | ||
---|---|---|
@service.json
|
||
def getThinclientGroups():
|
||
l=conecta()
|
||
h = Hosts (l,"","","","","")
|
||
h = Hosts (l,"","","","")
|
||
response = h.getThinclientGroups()
|
||
l.close()
|
||
return dict(response=response)
|
||
... | ... | |
@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)
|
||
... | ... | |
@auth.requires_login()
|
||
def list_ltspservers():
|
||
l=conecta()
|
||
h = Hosts (l,"","","","","")
|
||
h = Hosts (l,"","","","")
|
||
response = h.getLTSPServers()
|
||
l.close()
|
||
return response
|
||
... | ... | |
@auth.requires_login()
|
||
def list():
|
||
l=conecta()
|
||
h = Hosts (l,"","","","","")
|
||
h = Hosts (l,"","","","")
|
||
a=request.vars
|
||
response = h.list(a)
|
||
l.close()
|
||
... | ... | |
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)
|
||
|
||
... | ... | |
@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)
|
controlies/trunk/applications/controlies/modules/Utils/ValidationUtils.py | ||
---|---|---|
##############################################################################
|
||
# -*- 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
|
controlies/trunk/applications/controlies/modules/Hosts.py | ||
---|---|---|
import time
|
||
from math import ceil
|
||
from operator import itemgetter
|
||
from Utils import ValidationUtils
|
||
|
||
class Hosts(object):
|
||
|
||
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
|
||
... | ... | |
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():
|
||
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
|
||
... | ... | |
return "OK"
|
||
|
||
def process(self,action):
|
||
|
||
if action == "add":
|
||
val = self.validation(action)
|
||
|
||
... | ... | |
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'])
|
||
... | ... | |
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)
|
||
... | ... | |
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*))"
|
||
|
||
... | ... | |
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"])
|
||
... | ... | |
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] ),
|
||
... | ... | |
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"
|
||
... | ... | |
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
|
||
... | ... | |
|
||
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"])
|
||
... | ... | |
|
||
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:
|
controlies/trunk/applications/controlies/views/layout_form_hosts.html | ||
---|---|---|
<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>
|
||
|
controlies/trunk/applications/controlies/views/layout_hosts.html | ||
---|---|---|
{name:'macAddress',index:'macAddress', width:60, align:"center"}
|
||
],
|
||
|
||
postData:{type:'ltsp'},
|
||
postData:{type_host:'ltsp'},
|
||
caption:"Servidores de Aula (LTSP)",
|
||
{{end}}
|
||
rowNum:25,
|
||
... | ... | |
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']);
|
||
... | ... | |
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");
|
Exportar a: Unified diff
Gestión de LTSP - No terminado