Skip to content
GitLab
Explore
Sign in
Commits on Source (3)
Fix some bugs by getting rid of some of the magic numbers
· 2aa492c8
Imran Hussain
authored
Mar 10, 2019
2aa492c8
Delete func now removes people from the mailing lists
· bdcdca45
Imran Hussain
authored
Mar 10, 2019
bdcdca45
Delete function now complete! (feature parity of php scripts)
· 08b447be
Imran Hussain
authored
Mar 10, 2019
08b447be
Hide whitespace changes
Inline
Side-by-side
sucsam.py
View file @
08b447be
...
...
@@ -171,7 +171,8 @@ def listUsers():
def
deleteUser
(
peopleList
):
#get fs ready
directory
=
"
/home/deleted
"
basedir
=
"
/home/deleted
"
mboxdir
=
"
/var/mail/
"
subprocess
.
call
([
'
sudo
'
,
'
mkdir
'
,
"
-m
"
,
"
700
"
,
directory
])
for
person
in
peopleList
:
...
...
@@ -184,18 +185,22 @@ def deleteUser(peopleList):
#get all their info from the ldap
userLDAPinfo
=
ldapconn
.
search_s
(
ldap_base
,
ldap
.
SCOPE_SUBTREE
,
"
uid=
"
+
str
(
person
[
0
]))
#declare some easy to use vars
username
=
str
(
person
[
0
])
persondir
=
basedir
+
"
/
"
+
username
#make the dir to store their stuff
subprocess
.
call
([
"
sudo
"
,
"
mkdir
"
,
directory
+
"
/
"
+
str
(
person
[
0
])
])
subprocess
.
call
([
"
sudo
"
,
"
mkdir
"
,
person
dir
])
#kill all their procs
subprocess
.
call
([
"
sudo
"
,
"
pkill
"
,
"
-u
"
,
str
(
person
[
0
])
])
subprocess
.
call
([
"
sudo
"
,
"
pkill
"
,
"
-u
"
,
username
])
#backup their ldap entry
#sudo ldapsearch -x -D "cn=Manager,dc=sucs,dc=org" -y /etc/ldap.secret "(uid=imranh)"
ldapbackupfile
=
open
(
"
./ldap-ldif
"
,
"
w
"
)
subprocess
.
call
([
"
sudo
"
,
"
ldapsearch
"
,
"
-x
"
,
"
-D
"
,
ldap_manager
,
"
-y
"
,
ldap_manager_pass
,
"
-L
"
,
"
(uid=
"
+
str
(
person
[
0
])
+
"
)
"
],
stdout
=
ldapbackupfile
)
subprocess
.
call
([
"
sudo
"
,
"
ldapsearch
"
,
"
-x
"
,
"
-D
"
,
ldap_manager
,
"
-y
"
,
ldap_manager_pass
,
"
-L
"
,
"
(uid=
"
+
username
+
"
)
"
],
stdout
=
ldapbackupfile
)
ldapbackupfile
.
close
()
subprocess
.
call
([
'
sudo
'
,
'
mv
'
,
"
-f
"
,
"
./ldap-ldif
"
,
directory
+
"
/
"
+
str
(
person
[
0
])
+
"
ldap-ldif
"
])
subprocess
.
call
([
'
sudo
'
,
'
mv
'
,
"
-f
"
,
"
./ldap-ldif
"
,
person
dir
+
"
/
ldap-ldif
"
])
#delete them from ldap
#ldapconn.delete_s(ldap_base,ldap.SCOPE_SUBTREE,"uid="+str(person[0]))
...
...
@@ -203,20 +208,36 @@ def deleteUser(peopleList):
subprocess
.
call
([
"
sudo
"
,
"
ldapdelete
"
,
"
-D
"
,
ldap_manager
,
"
-y
"
,
ldap_manager_pass
,
userLDAPinfo
[
0
][
0
]])
#move their homedir to the deleted folder
subprocess
.
call
([
'
sudo
'
,
'
mv
'
,
"
-f
"
,
userLDAPinfo
[
0
][
1
][
"
homeDirectory
"
][
0
],
directory
+
"
/
"
+
str
(
person
[
0
])
+
"
/homedir
"
])
subprocess
.
call
([
'
sudo
'
,
'
mv
'
,
"
-f
"
,
userLDAPinfo
[
0
][
1
][
"
homeDirectory
"
][
0
],
person
dir
+
"
/homedir
"
])
#move their mail to the deleted folder
subprocess
.
call
([
'
sudo
'
,
'
mv
'
,
"
-f
"
,
"
/var/mail
"
+
"
/
"
+
str
(
person
[
0
]),
directory
+
"
/
"
+
str
(
person
[
0
])
+
"
/mbox
"
])
subprocess
.
call
([
'
sudo
'
,
'
mv
'
,
"
-f
"
,
mboxdir
+
username
,
person
dir
+
"
/mbox
"
])
#remove them from the printer
#pkusers --delete imranh
subprocess
.
call
([
'
sudo
'
,
'
pkusers
'
,
"
--delete
"
,
str
(
person
[
0
])
])
subprocess
.
call
([
'
sudo
'
,
'
pkusers
'
,
"
--delete
"
,
username
])
#remove from mailing lists
#/usr/lib/mailman/bin/remove_members imranh@sucs.org members
#/usr/lib/mailman/bin/remove_members imranh@sucs.org users
#/usr/lib/mailman/bin/remove_members members imranh@sucs.org
#/usr/lib/mailman/bin/remove_members users imranh@sucs.org
subprocess
.
call
([
'
sudo
'
,
'
/usr/lib/mailman/bin/remove_members
'
,
"
members
"
,
userLDAPinfo
[
0
][
1
][
"
mail
"
][
0
]])
#sucs email
subprocess
.
call
([
'
sudo
'
,
'
/usr/lib/mailman/bin/remove_members
'
,
"
members
"
,
userDBinfo
[
0
][
3
]])
#main email
subprocess
.
call
([
'
sudo
'
,
'
/usr/lib/mailman/bin/remove_members
'
,
"
members
"
,
userDBinfo
[
0
][
6
]
+
"
@swan.ac.uk
"
])
# iss email
subprocess
.
call
([
'
sudo
'
,
'
/usr/lib/mailman/bin/remove_members
'
,
"
users
"
,
userLDAPinfo
[
0
][
1
][
"
mail
"
][
0
]])
#sucs email
subprocess
.
call
([
'
sudo
'
,
'
/usr/lib/mailman/bin/remove_members
'
,
"
users
"
,
userDBinfo
[
0
][
3
]])
#main email
subprocess
.
call
([
'
sudo
'
,
'
/usr/lib/mailman/bin/remove_members
'
,
"
users
"
,
userDBinfo
[
0
][
6
]
+
"
@swan.ac.uk
"
])
# iss email
#time to delete them from the db :(
cur
=
DBconn
.
cursor
()
#delete from doorcards first
cur
.
execute
(
"
DELETE FROM doorcards WHERE uid=%(uid)s
"
,{
"
uid
"
:
userDBinfo
[
0
][
0
]})
#delete from members table
cur
.
execute
(
"
DELETE FROM members WHERE username=%(user)s
"
,{
"
user
"
:
person
[
0
]})
#add their some details to the oldmembers table
cur
.
execute
(
"
INSERT into oldmembers (username,realname) VALUES (%(user)s,%(realname)s)
"
,{
"
user
"
:
username
,
"
realname
"
:
userDBinfo
[
0
][
2
]})
DBconn
.
commit
()
cur
.
close
()
def
reminderMenu
():
print
(
""
)
...
...