Skip to content
GitLab
Explore
Sign in
Commits on Source (2)
Fix bugs so the program actually runs
· ac7c4d77
Imran Hussain
authored
Mar 12, 2019
ac7c4d77
Add the ability to mark a cohort from a specific year for deletion
· 4859cccc
Imran Hussain
authored
Mar 12, 2019
4859cccc
Hide whitespace changes
Inline
Side-by-side
sucsam.py
View file @
4859cccc
debugmode
=
1
debugmode
=
0
import
os
import
pwd
...
...
@@ -11,6 +11,7 @@ import smtplib
from
email.mime.multipart
import
MIMEMultipart
from
email.mime.text
import
MIMEText
import
ldap
import
subprocess
def
correctPaidUntilStr
():
...
...
@@ -257,29 +258,30 @@ def deleteUser(peopleList):
subprocess
.
call
([
'
sudo
'
,
'
mkdir
'
,
"
-m
"
,
"
700
"
,
basedir
])
for
person
in
peopleList
:
# get all their info from the db
cur
=
DBconn
.
cursor
()
cur
.
execute
(
"
SELECT * from members WHERE username=%(user)s
"
,{
"
user
"
:
person
[
0
]
})
cur
.
execute
(
"
SELECT * from members WHERE username=%(user)s
"
,{
"
user
"
:
person
})
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
]:
if
str
(
person
)
!=
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
]
))
userLDAPinfo
=
ldapconn
.
search_s
(
ldap_base
,
ldap
.
SCOPE_SUBTREE
,
"
uid=
"
+
str
(
person
))
# 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
]:
if
str
(
person
)
!=
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
]
)
username
=
str
(
person
)
persondir
=
basedir
+
"
/
"
+
username
# make the dir to store their stuff
...
...
@@ -331,17 +333,17 @@ def deleteUser(peopleList):
# /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
'
,
"
members
"
,
str
(
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
subprocess
.
call
([
'
sudo
'
,
'
/usr/lib/mailman/bin/remove_members
'
,
"
users
"
,
str
(
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
]})
cur
.
execute
(
"
DELETE FROM doorcards WHERE uid=%(uid)s
"
,{
"
uid
"
:
str
(
userDBinfo
[
0
][
0
]
)
})
# delete from members table
cur
.
execute
(
"
DELETE FROM members WHERE username=%(user)s
"
,{
"
user
"
:
person
[
0
]
})
cur
.
execute
(
"
DELETE FROM members WHERE username=%(user)s
"
,{
"
user
"
:
username
})
# 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
()
...
...
@@ -353,7 +355,7 @@ def deleteUser(peopleList):
# them
emailDeletedUser
(
userDBinfo
)
# logs@
emailAdminDeleteUser
(
person
[
0
]
)
emailAdminDeleteUser
(
person
)
# remove the entry from the list
peopleList
.
remove
(
person
)
...
...
@@ -403,6 +405,7 @@ def deleteMenu(deleteArray):
print
(
"
2. Add/delete users from delete list
"
)
print
(
"
3. Auto populate list of users to be deleted
"
)
print
(
"
3.1 Just add student accounts
"
)
print
(
"
3.2 Just add student accounts from a specific year
"
)
print
(
"
3.5 Just add accounts marked as
'
delete
'
in the DB
"
)
print
(
"
9. Do the delete
"
)
print
(
"
0. Go back to main menu
"
)
...
...
@@ -449,6 +452,16 @@ def deleteMenu(deleteArray):
deleteArray
.
append
(
student
[
0
])
print
(
"
No students look like the need deleting.
"
)
deleteMenu
(
deleteArray
)
elif
option
==
"
3.2
"
:
year
=
input
(
"
Please enter the year you wish to target:
"
)
if
len
(
studentsBad
)
>
0
:
targetedPeople
=
[]
for
student
in
studentsBad
:
paidyeararray
=
student
[
1
].
split
(
'
'
)
if
year
==
paidyeararray
[
1
]:
targetedPeople
.
append
(
student
[
0
])
print
(
"
Adding
"
+
student
[
0
]
+
"
to the list because the DB says:
"
+
str
(
student
[
1
]))
deleteMenu
(
targetedPeople
)
elif
option
==
"
3.5
"
:
if
len
(
studentsBad
)
>
0
:
for
student
in
studentsBad
:
...
...