-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAD-AddPhoto.py
45 lines (39 loc) · 1.07 KB
/
AD-AddPhoto.py
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
import sys
from PIL import Image
import os
import io
#arguments
#full name admin AD ([email protected])
admin_login = str(sys.argv[1])
#password admin AD
admin_pass = str(sys.argv[2])
#user login for change foto
user_login = str(sys.argv[3])
#path for foto.jpg
foto = str(sys.argv[4])
image = Image.open(foto)
#thumbnail photo
image.thumbnail(size=(96,96))
#image.thumbnail(size=(300,300))
#jpg to OctetString
buf = io.BytesIO()
image.save(buf,'jpeg')
img = buf.getvalue()
#bytes to OctetString !!!
bimg = [img]
img_size = len(img)
if img_size > 102400 :
print("Big size of picture: ",foto ,img_size ," > 100 kB")
sys.exit(1)
###work to AD
from ms_active_directory import ADDomain
domain = ADDomain(domain='domain.local',site='domain.local',ldap_servers_or_uris=['dc1.domain.local','dc2.domain.local'])
try:
#create connect
session = domain.create_session_as_user(admin_login, admin_pass)
#save foto to AD
success = session.overwrite_attribute_for_user(user_login,'thumbnailPhoto',bimg)
print(success)
except Exception as e:
#print(type(e))
print(e.args)