Revisión 69
Añadido por Manu Mora Gordillo hace alrededor de 14 años
controlies/Plugins/Groups.py | ||
---|---|---|
def __init__(self):
|
||
pass
|
||
|
||
def __init__(self,ldap,name,gidNumber):
|
||
def __init__(self,ldap,type,name):
|
||
self.ldap = ldap
|
||
self.type = type
|
||
self.name = name
|
||
self.gidNumber = gidNumber
|
||
|
||
def validation(self):
|
||
def validation(self,action):
|
||
|
||
if action == "add":
|
||
if self.type == "none":
|
||
return "type"
|
||
|
||
if self.name == "":
|
||
return "name"
|
||
|
||
if self.gidNumber == "":
|
||
return "gidNumber"
|
||
|
||
return "OK"
|
||
|
||
def process(self,action):
|
||
if action == "add":
|
||
val = self.validation()
|
||
val = self.validation(action)
|
||
|
||
if val != "OK":
|
||
return val
|
||
... | ... | |
return response
|
||
|
||
if action == "modify":
|
||
val = self.validation()
|
||
val = self.validation(action)
|
||
|
||
if val != "OK":
|
||
return val
|
||
else:
|
||
response = self.modify()
|
||
return response
|
||
|
||
if action == "delete":
|
||
response = self.delete()
|
||
return response
|
||
|
||
if action == "list":
|
||
response = self.list();
|
||
return response
|
||
return response
|
||
|
||
def list(self,args):
|
||
|
||
... | ... | |
|
||
if searchType == typeRow or searchType=="none":
|
||
row = {
|
||
"id":i[0][0],
|
||
"id":i[0][1]["cn"][0],
|
||
"cell":[typeRow, i[0][1]["cn"][0], i[0][1]["gidNumber"][0]],
|
||
"type": typeRow,
|
||
"cn": i[0][1]["cn"][0],
|
||
... | ... | |
|
||
|
||
def add(self):
|
||
record = [
|
||
('objectclass', ['person','organizationalperson','inetorgperson']),
|
||
('uid', ['francis']),
|
||
maxID = str(self.getMaxID())
|
||
|
||
attr = [
|
||
('objectclass', ['top','posixGroup','lisGroup','lisAclGroup']),
|
||
#('objectclass', ['top','posixGroup','lisGroup']),
|
||
('grouptype', [self.type] ),
|
||
('gidnumber', [maxID] ),
|
||
('cn', [self.name] ),
|
||
('sn', ['Bacon'] ),
|
||
('userpassword', [self.password]),
|
||
('ou', ['users'])
|
||
('description', [self.name+' department group']),
|
||
('memberuid', ['manuprofe']),
|
||
('member', ['uid=manuprofe,ou=People,dc=instituto,dc=extremadura,dc=es'])
|
||
]
|
||
try:
|
||
self.ldap.add("cn=Groups", record)
|
||
except ldap.ALREADY_EXISTS:
|
||
return "fail"
|
||
|
||
self.ldap.add("cn="+self.name+",ou=Group", attr)
|
||
|
||
return "OK"
|
||
|
||
... | ... | |
(ldap.MOD_ADD, 'description', 'Author of New Organon'),
|
||
(ldap.MOD_ADD, 'description', 'British empiricist')
|
||
]
|
||
self.ldap.modify_s('uid='+ uid +',cn=Groups', mod_attrs)
|
||
self.ldap.modify_s('uid='+ uid +',ou=Group', mod_attrs)
|
||
|
||
def delete(self,uid):
|
||
self.ldap.delete('uid='+ uid +',cn=Groups')
|
||
def delete(self):
|
||
self.ldap.delete('cn='+ self.name +',ou=Group')
|
||
|
||
|
||
def getMaxID(self): # find the maximum ID
|
||
result = self.ldap.search("ou=Group","cn=*",["gidNumber"])
|
||
numbers = []
|
||
for i in result:
|
||
numbers.append(int(i[0][1]['gidNumber'][0]))
|
||
|
||
result = self.ldap.search("ou=People","uid=*",["gidNumber","uidNumber"])
|
||
for i in result:
|
||
numbers.append(int(i[0][1]['gidNumber'][0]))
|
||
numbers.append(int(i[0][1]['uidNumber'][0]))
|
||
|
||
numbers.sort()
|
||
|
||
maxID = 1
|
||
if len(numbers) > 0:
|
||
maxID = numbers[len(numbers)-1] + 1
|
||
|
||
return maxID
|
controlies/Plugins/Users.py | ||
---|---|---|
else:
|
||
response = self.modify()
|
||
return response
|
||
|
||
if action == "delete":
|
||
response = self.delete()
|
||
return response
|
||
|
||
|
||
def list(self,args):
|
||
... | ... | |
|
||
self.ldap.add("uid="+self.user+",ou=People", attr)
|
||
|
||
|
||
# Add private group
|
||
attr = [
|
||
('objectclass', ['top','posixGroup','lisGroup']),
|
controlies/www/index.html | ||
---|---|---|
<div id="tabs-1">
|
||
<img src="img/unlock.png" style="float:right;"/>
|
||
<form id="form_authentication" onSubmit="return authentication();">
|
||
<p><span id="hostTag">LDAP</span><br><input type="text" id="host" name="host" value="172.23.36.5"></p>
|
||
<p><span id="hostTag">LDAP</span><br><input type="text" id="host" name="host" value="172.23.36.8"></p>
|
||
<p><span id="userTag">Nombre</span><br><input type="text" id="user" name="user" value="admin"></p>
|
||
<p><span id="passwordTag">Contraseña</span><br><input type="password" id="password" name="password"></p><br>
|
||
<div id="message" style="text-align:center; font-weight:bold; color:red; "></div>
|
controlies/www/groups/form.html | ||
---|---|---|
|
||
restartStyle();
|
||
|
||
$.post('users', $("#form_data").serialize(), function(data) {
|
||
$.post('groups', $("#form_data").serialize(), function(data) {
|
||
var result = $.parseJSON(data);
|
||
|
||
switch(result.response){
|
||
case "OK":{
|
||
$('#message').html("Operación realizada correctamente").css("color","green").effect("highlight", {"color":"yellow"}, 1000);
|
||
setTimeout("$('#dialog-form').dialog('close')",1000);
|
||
$("#list").trigger("reloadGrid");
|
||
break;
|
||
}
|
||
case "fail":{
|
||
$('#message').html("Se produjo un error").effect("highlight", {"color":"yellow"}, 1000);
|
||
break;
|
||
}
|
||
case "distinctPassword":{
|
||
$('#password2Tag').css("color","red");
|
||
$('#password2').effect("highlight", {"color":"yellow"}, 1000).focus();
|
||
$('#message').html("La repetición no coincide").effect("highlight", {"color":"yellow"}, 1000);
|
||
break;
|
||
}
|
||
default:{
|
||
$('#'+result.response+"Tag").css("color","red");
|
||
$('#'+result.response).effect("highlight", {"color":"yellow"}, 1000).focus();
|
||
... | ... | |
|
||
<form id="form_data" onSubmit="return send();">
|
||
<input type="hidden" id="action" name="action"/>
|
||
<input type="hidden" id="id" name="id"/>
|
||
<p><span id="nameTag">Nombre y Apellidos</span><br><input type="text" id="name" name="name"/></p>
|
||
<p><span id="nifTag">NIF</span><br><input type="text" id="nif" name="nif"/></p>
|
||
<p><span id="passwordTag">Contraseña</span><br><input type="text" id="password" name="password"/></p>
|
||
<p><span id="password2Tag">Repita Contraseña</span><br><input type="text" id="password2" name="password2"/></p>
|
||
<p><span id="typeTag">Tipo Grupo</span><br>
|
||
<select type="text" id="type" name="type">
|
||
<option value="none">Seleccione...</option>
|
||
<option value="school_department">Departamento</option>
|
||
<option value="school_classroom">Curso</option>
|
||
</select>
|
||
</p>
|
||
<p><span id="nameTag">Nombre </span><br><input type="text" id="name" name="name"/></p>
|
||
<div id="message" style="text-align:center; font-weight:bold; color:red; padding:3px; "></div>
|
||
<div style="text-align:center;"><button id="saveButton" type="submit" style="width:100px;">Guardar</button> <button type="button" id="cancelButton" style="width:100px;">Cancelar</button></div>
|
||
</form>
|
controlies/www/groups/index.html | ||
---|---|---|
datatype: "json",
|
||
colNames:['Tipo Grupo','Nombre','ID Grupo'],
|
||
colModel:[
|
||
{name:'type',index:'type', width:60, align:"center", stype:'select', editoptions:{value:":Todo;Departamento:Departamentos;Aula:Aulas"}},
|
||
{name:'type',index:'type', width:60, align:"center", stype:'select', editoptions:{value:":Todo;Departamento:Departamentos;Curso:Cursos"}},
|
||
{name:'cn',index:'cn', width:80, align:"center"},
|
||
{name:'gidNumber',index:'gidNumber', width:60, align:"center"}
|
||
],
|
||
... | ... | |
caption: "Insertar",
|
||
buttonicon :'ui-icon-plus',
|
||
onClickButton : function (){
|
||
handleRecord('add','Añadir Usuario');
|
||
addRecord();
|
||
}
|
||
});
|
||
$("#list").jqGrid('navButtonAdd','#pager',{
|
||
caption: "Modificar",
|
||
buttonicon :'ui-icon-pencil',
|
||
onClickButton : function (){
|
||
handleRecord('modify','Modificar Usuario');
|
||
modifyRecord();
|
||
}
|
||
});
|
||
$("#list").jqGrid('navButtonAdd','#pager',{
|
||
... | ... | |
return id;
|
||
}
|
||
|
||
function handleRecord(action,title){
|
||
var id;
|
||
function addRecord(){
|
||
|
||
$("#dialog-form").html("");
|
||
$("#dialog-form").load("groups/form.html", function() {
|
||
$("#form_data #action").val("add");
|
||
$("#form_data #messageForm").html("Todos los campos son obligatorios");
|
||
});
|
||
|
||
x = ($(window).width()-250)/2;
|
||
y = ($(window).height()-400)/2;
|
||
|
||
$("#dialog-form").dialog({
|
||
resizable: false,
|
||
position: top,
|
||
modal: true,
|
||
title: "Añadir Grupo"
|
||
}).dialog('option', 'position', [x, y]);
|
||
}
|
||
|
||
function modifyRecord(){
|
||
var uid;
|
||
|
||
if(action=="modify"){
|
||
var id = rowSelected();
|
||
if(id==false)
|
||
return false;
|
||
}
|
||
var uid = rowSelected();
|
||
if(uid==false)
|
||
return false;
|
||
|
||
$("#dialog-form").html("");
|
||
$("#dialog-form").load("groups/form.html", function() {
|
||
|
||
getAllGroups();
|
||
|
||
$("#form_data #action").val("modify");
|
||
$("#form_data #user").attr("readonly","true");
|
||
$("#form_data #user").css("background-color","#DDD");
|
||
$("#form_data #messageForm").html("Todos los campos son obligatorios");
|
||
|
||
$.post('users', 'action=getUserData&user='+uid, function(data) {
|
||
var result = $.parseJSON(data);
|
||
|
||
if(result.response['type']=="teacher")
|
||
var textType = "Profesor";
|
||
else
|
||
var textType = "Alumno";
|
||
|
||
var dep = Array(result.response['groups']['departments']);
|
||
|
||
$("#form_data #type").replaceWith(textType+"<input type='hidden' id='type' name='type' value='"+result.response['type']+"'/>");
|
||
$("#form_data #name").val(result.response['name']);
|
||
$("#form_data #nif").val(result.response['nif']);
|
||
$("#form_data #user").val(result.response['user']);
|
||
$("#form_data #surname").val(result.response['surname']);
|
||
|
||
$.each(result.response['groups']['departments'], function(i, l){
|
||
$('#form_data input:checkbox[value='+l+']').attr('checked', true);
|
||
});
|
||
|
||
$.each(result.response['groups']['classrooms'], function(i, l){
|
||
$('#form_data input:checkbox[value='+l+']').attr('checked', true);
|
||
});
|
||
});
|
||
});
|
||
|
||
x = ($(window).width()-300)/2;
|
||
y = ($(window).height()-500)/2;
|
||
|
||
$("#dialog-form").dialog({
|
||
resizable: false,
|
||
modal: true,
|
||
title: title,
|
||
open: function(event, ui) {
|
||
$("#dialog-form").html("");
|
||
$("#dialog-form").load("users/form.html", function() {
|
||
$("#form_data #action").val(action);
|
||
$("#form_data #id").val(id);
|
||
});
|
||
}
|
||
});
|
||
width: 300,
|
||
title: "Modificar Grupo"
|
||
}).dialog('option', 'position', [x, y]);
|
||
}
|
||
|
||
function deleteRecord(){
|
||
|
||
var id = rowSelected();
|
||
if(id==false)
|
||
return false;
|
||
|
||
|
||
$( "#dialog-confirm" ).dialog({
|
||
resizable: false,
|
||
height:160,
|
||
... | ... | |
modal: true,
|
||
buttons: {
|
||
"Borrar": function() {
|
||
$.post("users","idUser="+id+"&action=delete", function(data){
|
||
$( this ).dialog( "close" );
|
||
$.post("groups","name="+id+"&action=delete", function(data){
|
||
$("#dialog-confirm").dialog( "close" );
|
||
$("#list").trigger("reloadGrid");
|
||
});
|
||
},
|
||
"Cancelar": function() {
|
||
$( this ).dialog( "close" );
|
||
$(this).dialog( "close" );
|
||
}
|
||
}
|
||
}).dialog('open');
|
controlies/MainLoop.py | ||
---|---|---|
g = Groups(l,"","")
|
||
response = g.list(request.args)
|
||
return json.dumps(response)
|
||
|
||
elif request.args['action'][0] == "getAllGroups":
|
||
g = Groups(l,"","")
|
||
response = g.getAllGroups()
|
||
return json.dumps(response)
|
||
|
||
elif request.args['action'][0] == "delete":
|
||
g = Groups(l,"",request.args['name'][0])
|
||
response = g.delete()
|
||
return json.dumps({"response" : response})
|
||
|
||
else:
|
||
g = Groups(l,request.args['name'][0],request.args['gid'][0])
|
||
g = Groups(l,request.args['type'][0],request.args['name'][0])
|
||
response = g.process(request.args['action'][0])
|
||
return json.dumps({"response" : response})
|
||
|
Exportar a: Unified diff
Inserta y borra grupos