Skip to content
GitLab
Explore
Sign in
Commits on Source (2)
fix a bug and add a deletion completion message
· 5a4d53a7
Imran Hussain
authored
Mar 10, 2019
5a4d53a7
Add some sanity checks to the delete function
· 13acae44
Imran Hussain
authored
Mar 10, 2019
13acae44
Hide whitespace changes
Inline
Side-by-side
sucsam.py
View file @
13acae44
...
...
@@ -262,10 +262,22 @@ def deleteUser(peopleList):
cur
.
execute
(
"
SELECT * from members WHERE username=%(user)s
"
,{
"
user
"
:
person
[
0
]})
userDBinfo
=
cur
.
fetchall
()
cur
.
close
()
# fail safe, if the DB username we just got isn't the one we are
# messing with, die
if
str
(
person
[
0
])
!=
userDBinfo
[
0
][
1
]:
print
(
"
Something went wrong getting info from DB, quitting! NO CHNAGES MADE
"
)
sys
.
exit
(
9
)
# get all their info from the ldap
userLDAPinfo
=
ldapconn
.
search_s
(
ldap_base
,
ldap
.
SCOPE_SUBTREE
,
"
uid=
"
+
str
(
person
[
0
]))
# fail safe, if the ldap username we just got isn't the one we
# are messing with, die
if
str
(
person
[
0
])
!=
userLDAPinfo
[
0
][
1
][
"
uid
"
][
0
]:
print
(
"
Something went wrong getting info from LDAP, quitting! NO CHNAGES MADE
"
)
sys
.
exit
(
9
)
# declare some easy to use vars
username
=
str
(
person
[
0
])
persondir
=
basedir
+
"
/
"
+
username
...
...
@@ -281,12 +293,23 @@ def deleteUser(peopleList):
ldapbackupfile
=
open
(
"
./ldap-ldif
"
,
"
w
"
)
subprocess
.
call
([
"
sudo
"
,
"
ldapsearch
"
,
"
-x
"
,
"
-D
"
,
ldap_manager
,
"
-y
"
,
ldap_manager_pass
,
"
-L
"
,
"
(uid=
"
+
username
+
"
)
"
],
stdout
=
ldapbackupfile
)
ldapbackupfile
.
close
()
# sanity check we have a legit backup
if
"
# numEntries: 1
"
not
in
open
(
"
./ldap-ldif
"
).
read
():
print
(
"
Something went wrong getting a backup LDAP entry, quitting! NO CHNAGES MADE
"
)
sys
.
exit
(
9
)
else
:
print
(
"
LDAP Backup made!
"
)
subprocess
.
call
([
'
sudo
'
,
'
mv
'
,
"
-f
"
,
"
./ldap-ldif
"
,
persondir
+
"
/ldap-ldif
"
])
# delete them from ldap
# ldapconn.delete_s(ldap_base,ldap.SCOPE_SUBTREE,"uid="+str(person[0]))
# sudo ldapdelete -D "cn=Manager,dc=sucs,dc=org" -y /etc/ldap.secret "uid=imran,ou=people,dc=sucs,dc=org"
subprocess
.
call
([
"
sudo
"
,
"
ldapdelete
"
,
"
-D
"
,
ldap_manager
,
"
-y
"
,
ldap_manager_pass
,
userLDAPinfo
[
0
][
0
]])
rc
=
subprocess
.
call
([
"
sudo
"
,
"
ldapdelete
"
,
"
-D
"
,
ldap_manager
,
"
-y
"
,
ldap_manager_pass
,
userLDAPinfo
[
0
][
0
]])
# sanity check ldap delete happened
if
int
(
rc
)
!=
0
:
print
(
"
Something went wrong deleting the LDAP entry, quitting! NO CHNAGES MADE
"
)
sys
.
exit
(
9
)
# move their homedir to the deleted folder
subprocess
.
call
([
'
sudo
'
,
'
mv
'
,
"
-f
"
,
userLDAPinfo
[
0
][
1
][
"
homeDirectory
"
][
0
],
persondir
+
"
/homedir
"
])
...
...
@@ -325,6 +348,8 @@ def deleteUser(peopleList):
cur
.
close
()
# notify people
# us
print
(
username
+
"
was successfully deleted on
"
+
str
(
datetime
.
datetime
.
now
().
strftime
(
"
%Y-%m-%d %H:%M:%S
"
)))
# them
emailDeletedUser
(
userDBinfo
)
# logs@
...
...
@@ -424,7 +449,7 @@ def deleteMenu(deleteArray):
print
(
"
Adding
"
+
str
(
soc
[
0
])
+
"
to the list because the DB says:
"
+
str
(
soc
[
1
]))
deleteArray
.
append
(
soc
[
0
])
for
ass
in
associatesBad
:
if
ass
==
"
delete
"
:
if
ass
[
1
]
==
"
delete
"
:
print
(
"
Adding
"
+
str
(
ass
[
0
])
+
"
to the list because the DB says:
"
+
str
(
ass
[
1
]))
deleteArray
.
append
(
ass
[
0
])
deleteMenu
(
deleteArray
)
...
...