[?]   dans   mode   trier par   

[<] Sujet : [AS] Script_modifiant_les_accès_d'un_utilisate ur
De : Yves PETRONIN <anonyme@...>
Date : 2010-04-20 17:51:53

Si cela peut être utile.....


--SCRIPT

(*********************************************************************** 
**************************)
(* Script d'interdiction/autorisation d'accès d'un utilisateur.
*Version: 0.9.0
* Compatibilité: Mac OS X. 10.4 Versions plus récentes non testées.  
Privilèges d'administrateur requis
*
* Auteur: Y Petronin
*
* Fichier:
* Fichiers/Dossiers annexes:
* Libs: non
* Osaxen: non
* Outils Unix: oui
* Apps:
*
* Description:
*
* * Utilisation: ...Lancer le script... *
* Historique: *
* 0.9.0
* 2010-01-19 Version alpha *
**)

(* Product properties *)

property pMyName : "Script limitation accès ordinateur" (* default  
name *)
property version : "0.9.0"


--User properties

property pUserName : missing value
property pauthorized : missing value
property prestricted : missing value


on init()
	set pUserName to SelectUser()
	set pauthorized to ";ShadowHash;"
	set prestricted to ";DisabledUser;"
end init


on run
	main()
end run


on GetLoginStatus(pUserName)
	try
		set readLoginstatus to "dscl . -read /users/" & pUserName & " " &  
"AuthenticationAuthority" & " " & " | tail -1 | awk  '{print ($2)'}"
		set loginStatus to do shell script readLoginstatus
		return loginStatus as string
	on error
		return ""
	end try
end GetLoginStatus



on main()
	try
		init()
		LockUnlockUser()
	end try
end main


on LockUnlockUser()
	if GetLoginStatus(pUserName) is pauthorized then
		set dlg to "L 'utilisateur" & " " & pUserName & " est actuellement  
autorisé. Voulez vous modifier ses droits d'accès ?"
		dlgUser(dlg)
		set DesactiveUser to "sudo dscl . -change /users/" & pUserName & "  
" & "AuthenticationAuthority" & " " & """ & pauthorized & "" " &  
""" & prestricted & """
		try
			do shell script DesactiveUser with administrator privileges
			if GetLoginStatus(pUserName) is prestricted then
				set dlg to "L 'utilisateur" & " " & pUserName & " a été bloqué !"
				dlgUser(dlg)
			else
				set dlg to "Opération non effectuée ! Un problème est apparu !"
				dlgUser(dlg)
			end if
		end try
	else
		
		set dlg to "L 'utilisateur" & " " & pUserName & " est actuellement  
bloqué. Voulez vous modifier ses droit d'accès ?"
		dlgUser(dlg)
		set ActiveUser to "sudo dscl . -change /users/" & pUserName & " " &  
"AuthenticationAuthority" & " " & """ & prestricted & """ & " " &  
""" & pauthorized & """
		try
			do shell script ActiveUser with administrator privileges
			if GetLoginStatus(pUserName) is pauthorized then
				set dlg to "L 'utilisateur" & " " & pUserName & " est à nouveau  
autorisé !"
				dlgUser(dlg)
			else
				set dlg to "Opération non effectuée ! Un problème est apparu !"
				dlgUser(dlg)
			end if
		end try
	end if
	
end LockUnlockUser



on dlgUser(G)
	activate
	set bs to {"ANNULER", "OK"}
	display dialog G buttons bs default button 2 with icon 1 giving up  
after 8
	set {b, u} to {button returned, gave up} of result
	if u then set b to bs's item 1
	if b is bs's item 1 then error number -128 (* ¡localization! *)
end dlgUser



on SelectUser()
	try
		set l to ListUsers() as list
		set dlg to choose from list l with prompt "Veuillez entrer le nom  
de l'utilisateur dont l'accès est à modifier:" cancel button name  
"ANNULER" OK button name "OK" without multiple selections allowed and  
empty selection allowed
		if the result is false then
			error number -128
		else
			return result as text
		end if
	end try
end SelectUser


on ListUsers()
	try
		tell application "System Events" to set NameCurrentUser to (name of  
(current user)) as string
		set cmd to "ls /Users/"
		set a to do shell script cmd
		set Long_List to words of a as list
		set Short_List to {}
		repeat with x in Long_List
			if contents of x is not in {NameCurrentUser, "Shared"} then set  
end of Short_List to contents of x
		end repeat
		return Short_List
	end try
end ListUsers

--SCRIPT
_______________________________________________
Applescript_fr mailing list
anonyme@...
http://listes.patpro.net/mailman/listinfo/applescript_fr

Apple, AppleScript, AppleScript Studio, AppleTalk, AppleWorks, ColorSync, Finder, HyperCard, iBook, iLife, iMac, iWork, Keynote, Mac, Macintosh, Mac OS, Pages, Panther, PowerBook, Power Mac, Power Macintosh, QuickTime, Safari, Tiger, Xcode sont des marques déposées par Apple Computer, Inc., enregistrées aux Etats-Unis et dans les autres pays. Liste officielle