-
Notifications
You must be signed in to change notification settings - Fork 2
/
gestion-ldap-desde-bash.sh
175 lines (157 loc) · 5.14 KB
/
gestion-ldap-desde-bash.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
##################################################################
############## DISCLAIMER ##############
# #
# Este script ha sido creado por @Angelocho #
# #
############## DISCLAIMER ##############
##################################################################
#!/usr/bin/env bash
op=0
org=0
cont=$(ldapsearch -x -LLL -b dc=bocalandro,dc=local "(objectClass=person)" | grep "uidNumber" | wc -l)
function faltas(){
cont2=$(expr $cont + 1001)
userPassword={SSHA}k4LG1STOQfpYpuQj2DFmI5doZGHmWRU0
cont2=$(expr $cont2 + 1 )
alta=`yad --form --field=Nombre --field=Apellido --field=Telefono --field=Correo`
nom=`echo ${alta} | cut -f1 -d"|"`
ape=`echo ${alta} | cut -f2 -d"|"`
tel=`echo ${alta} | cut -f3 -d"|"`
cor=`echo ${alta} | cut -f4 -d"|"`
echo "${nom} ${ape} ${tel} ${cor}"
if [[ "${nom}" == "" ]] | [[ "${ape}" == "" ]] | [[ "${tel}" == "" ]] | [[ "${cor}" == "" ]];
then
echo "Faltan parametros"
else
echo "dn: cn=${nom},dc=bocalandro,dc=local" >> dominio.ldif
echo "objectClass: person" >> dominio.ldif
echo "objectClass: organizationalPerson" >> dominio.ldif
echo "objectClass: inetOrgPerson" >> dominio.ldif
echo "objectClass: posixAccount" >> dominio.ldif
echo "objectClass: shadowAccount" >> dominio.ldif
echo "homeDirectory: /home/${nom}" >> dominio.ldif
echo "loginShell: /bin/bash" >> dominio.ldif
echo "sn: ${ape}" >> dominio.ldif
echo "uid: ${nom}">> dominio.ldif
echo "uidNumber: ${cont2}" >> dominio.ldif
echo "gidNumber: ${cont2}" >> dominio.ldif
echo "mobile: ${tel}" >> dominio.ldif
echo "mail: ${cor}" >> dominio.ldif
echo "userPassword: ${userPassword}" >> dominio.ldif
echo -e "\n" >> dominio.ldif
ldapadd -x -D cn=admin,dc=bocalandro,dc=local -W -f dominio.ldif
bien=`echo $?`
if [ ${bien} != 0 ]
then
echo "Algo ha ido mal en la adicion del usuario en el dominio"
else
echo "Todo genial !"
fi
fi
}
function fbajas(){
baja=`yad --form --field=Nombre`
nom=`echo ${baja} | cut -f1 -d"|"`
existe=`ldapsearch -x -b dc=bocalandro,dc=local -LLL "(objectClass=inetOrgPerson)" | grep ${nom}`
comp=`echo $?`
if [[ ${comp} != 0 ]]
then
echo "Usuario no existente"
else
read -p "¿Es este el usuario que desea borrar (s/n)? " resp
if [[ ${resp} == 's' ]]
then
echo "dn=${nom},dc=bocalandro,dc=local" >> borrar.ldif
ldapdelete -x -D cn=admin,dc=bocalandro,dc=local -W -f borrar.ldif
bien=`echo $?`
if [ ${bien} != 0 ]
then
echo "Algo ha ido mal al intentar borrar (en esta demo solo se permiten borrar usuarios que esten en la raiz)"
fi
fi
fi
}
function fconsultas(){
echo "consulta"
OIFS=$IFS
IFS=#
telefono=$(yad --form --title="Dame el telefono" --width=300 --height=300 --center --separator="#" \
--field=telefono )
while read nom ou tel cor
do
if [ "${tel}" == "${telefono}" ]
then
n="${n}${nom}"
a="${a}${ape}"
t="${t}${tel}"
c="${c}${cor}"
yad --list --title="Resultado consulta" --width=400 --height=300 --center \
--column=NOMBRE --column=OU --column=TELEFONO --column=EMAIL \
"${n}" "${a}" "${t}" "${c}"
fi
done < ./dominio.txt
IFS=$OIFS
}
function flistados(){
echo "listado"
# OIFS=$IFS
# IFS=#
# n=""
# a=""
# t=""
# c=""
# f=""
# while read nom ape tel cor fn
# do
# n="${n}${nom}""\n"
# a="${a}${ape}""\n"
# t="${t}${tel}""\n"
# c="${c}${cor}""\n"
# f="${f}${fn}""\n"
#cadena="${cadena}${nom}\t${ape}\t${tel}\t${cor}\t${fn}\n"
#done < ./agenda.txt
#yad --info --title="CONTENIDO AGENDA" --text="${cadena}"
#yad --list --title="Contenido agenda" --width=400 --height=300 --center \
#--column=NOMBRE --column=APELLIDO --column=TELEFONO --column=EMAIL --column="F.NACIMIENTO" \
#"${n}" "${a}" "${t}" "${c}" "${f}"
# IFS=$OIFS
}
function fmodificaciones(){
echo "Modificar contenido de la agenda"
# nombre=`yad --entry --title="Dime el nombre" --test="NOMBRE" --center `
#OIFS=$IFS
#IFS=#
#while read nom ape tel cor fn
#do
# if [ "${nom}" == "${nombre}" ]
# then
# n="${n}${nom}"
# a="${a}${ape}"
# t="${t}${tel}"
# c="${c}${cor}"
# f="${f}${fn}"
# registro=$(yad --form --title="MODIFICAR REGISTRO REGISTRO" --width=300 --height=300 --center \
# --field=NOMBRE:RO --field=APELLIDO:RO --field=TELEFONO --field=EMAIL --field="FECHA NACIMIENTO":DT \
# ${nom} ${ape} ${tel} ${cor} ${fn})
# echo ${registro} | tr "|" "#" > ./temp.txt
# else
# echo ${nom}"#"${ape}"#"${tel}"#"${cor}"#"${fn}"#" >> temp.txt
# rm agenda.txt
# mv temp.txt agenda.txt
# fi
#done < ./agenda.txt
#IFS=$OIFS
}
while [ $op -ne 6 ]
do
op=$(yad --list --title="Agenda" --width=200 --height=400 --center \
--column="" --column="" 1 "ALTA DE UN USUARIO" 2 "BAJAS" 3 "CONSULTAS" 4 "LISTADOS" 5 "MODIFICACIONES" 6 "SALIR")
op=$(echo $op | cut -f1 -d"|")
case $op in
1) faltas;;
2) fbajas;;
3) fconsultas;;
4) flistados;;
5) fmodificaciones
esac
done