Skip to content

Commit 46d5972

Browse files
committed
save
1 parent 50ce0a4 commit 46d5972

File tree

9 files changed

+135
-1
lines changed

9 files changed

+135
-1
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,7 @@ cython_debug/
159159
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
160160
# and can be added to the global gitignore or merged into this file. For a more nuclear
161161
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
162-
#.idea/
162+
.idea/
163+
.DS_Store
164+
/src/.ssh
165+
src/etc/config.conf

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
paramiko>=3.4.1
2+
Jinja2>=3.1.4

src/bin/changepwd.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import sys
2+
sys.path.insert(0, '../lib')
3+
import ad_utils as ad
4+
import backend_utils as u
5+
6+
entity=u.readjsoninput()
7+
config=u.read_config('../etc/config.conf')
8+
ad.set_config(config)
9+
ad.__DEBUG__=1
10+
if u.is_backend_concerned(entity):
11+
ad.ad_exec_script(entity,'changepassword.template',entity['payload']['uid']+ " '"+ entity['payload']['oldPassword'] + "' '"+ entity['payload']['newPassword'] +"'")
12+
else:
13+
u.returcode(0,"not concerned")

src/bin/resetpwd.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import sys
2+
sys.path.insert(0, '../lib')
3+
import ad_utils as ad
4+
import backend_utils as u
5+
6+
entity=u.readjsoninput()
7+
config=u.read_config('../etc/config.conf')
8+
ad.set_config(config)
9+
ad.__DEBUG__=1
10+
if u.is_backend_concerned(entity):
11+
ad.ad_exec_script(entity,'resetpassword.template',entity['payload']['uid']+ " '"+ entity['payload']['newPassword']) +"'"
12+
else:
13+
u.returcode(0,"not concerned")

src/bin/upsertidentity.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import sys
2+
sys.path.insert(0, '../lib')
3+
import ad_utils as ad
4+
import backend_utils as u
5+
6+
entity=u.readjsoninput()
7+
config=u.read_config('../etc/config.conf')
8+
ad.set_config(config)
9+
if u.is_backend_concerned(entity):
10+
ad.ad_exec_script(entity,'upsertidentity.template')
11+
else:
12+
u.returcode(0,"not concerned")

src/etc/config.conf.exemple

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
host=ad.mydomain.com
2+
user=administrator
3+
base=dc=mydomain,dc=com
4+
userbase=ou=peoples,dc=mydomain,dc=com
5+
rdnattribute=uid
6+
branchForEtd=ou=Etudiants
7+
branchForAdm=ou=Administratifs
8+
branchForEsn=ou=Enseignants
9+
branchAttr=supannTypeEntiteAffectation
10+
backendFor=adm,etd,esn
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
param (
2+
[string]$user,
3+
[string]$oldp,
4+
[string]$newp
5+
)
6+
try{
7+
Set-ADUser -Identity $user -CannotChangePassword $false
8+
Set-ADAccountPassword -Identity $user -OldPassword (ConvertTo-SecureString -AsPlainText $oldp -Force) -NewPassword (ConvertTo-SecureString -AsPlainText $newp -Force)
9+
Set-ADUser -Identity $user -CannotChangePassword $true
10+
}catch{
11+
Write-Host $_
12+
exit 1
13+
}
14+
Set-ADUser -Identity $user -CannotChangePassword $true
15+
WriteHost "Password changed"
16+
Exit 0
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
param (
2+
[string]$user,
3+
[string]$newp
4+
)
5+
try{
6+
Set-ADUser -Identity $user -CannotChangePassword $false -Enabled $true
7+
Set-ADAccountPassword -Identity $user -NewPassword (ConvertTo-SecureString -AsPlainText $newp -Force) -Reset
8+
Set-ADUser -Identity $user -CannotChangePassword $true
9+
}catch{
10+
Write-Host $_
11+
exit 1
12+
}
13+
Set-ADUser -Identity $user -CannotChangePassword $true
14+
Exit 0
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
2+
try{
3+
$tab=Get-ADUser -Filter 'employeeNumber -eq "{{ e.employeeNumber }}" -and employeeType -eq "{{ e.employeeType }}"' -Properties "DistinguishedName"
4+
if ($tab["DistinguishedName"] -ne "{{ dn }}"){
5+
try{
6+
$dn=$tab["DistinguishedName"]
7+
move-adObject "$dn" -targetpath "{{ path }}"
8+
}catch{
9+
Write-Host $_
10+
exit 1
11+
}
12+
}
13+
$UserExists = $true
14+
}
15+
catch [Microsoft.ActiveDirectory.Management.ADIdentityResolutionException] {
16+
$UserExists = $false
17+
}
18+
if ($UserExists -eq $false){
19+
$np = @{
20+
Path="{{ path }}"
21+
EmployeeNumber="{{ e.employeeNumber }}"
22+
Name="{{ e.cn }}"
23+
DisplayName="{{ e.displayName }}"
24+
GivenName="{{ e.givenName }}"
25+
Surname="{{ e.sn }}"
26+
SamAccountName="{{ e.uid }}"
27+
EmailAddress="{{ e.mail }}"
28+
UserPrincipalName = "{{ e.uid }}" + '@' + "{{ domain }}"
29+
Enabled=$false
30+
CannotChangePassword=$true
31+
ChangePasswordAtLogon = $false
32+
}
33+
try{
34+
new-adUser @np -OtherAttributes @{ 'EmployeeType' = '{{ e.employeeType }}' }
35+
Write-Host "Identity created"
36+
}catch{
37+
Write-Host $_
38+
exit 1
39+
}
40+
}else{
41+
try{
42+
$dn=$tab["DistinguishedName"]
43+
$UserPrincipalName = "{{ e.uid }}" + '@' + "{{ domain }}"
44+
set-adUser -Identity "$dn" -SamAccountName "{{ e.uid }}" -DisplayName "{{e.displayName}}" -GivenName "{{ e.givenName }}" -EmailAddress "{{ e.mail }}" -UserPrincipalName "$UserPrincipalName"
45+
Write-Host "Identity modified"
46+
}catch{
47+
Write-Host $_
48+
exit 1
49+
}
50+
}
51+
exit 0

0 commit comments

Comments
 (0)