Monday, April 9, 2012

ACL Extraction thru lotus script

Sub Initialize
On Error GoTo ErrorHandler
    Dim session As New NotesSession   
   
    Set curDB=session.Currentdatabase
   
    Set LogDoc=curDB.CreateDocument
    LogDoc.Form="LogForm"   
    LogDoc.Server=curdb.Server
    LogDoc.StartTime=Now
    Set ActivityLogRTItem = New NotesRichTextItem( LogDoc, "Rtxtlogactivity" )
    Call ActivityLogRTItem.AppendText( Now+ ": "&"Agent Started")
    Call ActivityLogRTItem.AddNewLine( 1)
   
    Set profilevw=curDB.Getview("Profile")
    Set profiledoc=profilevw.Getfirstdocument()
    n=1
    While Not profiledoc Is Nothing
        Set personDB=session.Getdatabase(profiledoc.mailserver(0), profiledoc.folder(0)+"\"+profiledoc.mailfile(0))
        Set caldoc=personDB.GetProfileDocument("CalendarProfile")
        Set persondoc = curDB.CreateDocument
       
        persondoc.Form="PersonInfo"
        persondoc.txt_mailfile=profiledoc.folder(0)+"\"+profiledoc.mailfile(0)
        persondoc.txt_mailowner=caldoc.Owner(0)
       
        'ACL
        Dim Acl As NotesACL
        Dim Aclentry As NotesACLEntry
        Set Acl=personDB.Acl
        Set Aclentry=Acl.Getfirstentry()
        Dim ctr As Long
        Dim ctr1 As Long
        Dim ctr2 As Long
        Dim ctr3 As Long
        Dim ctr4 As Long
        Dim ctr5 As Long
        Dim ctr6 As Long
       
        ctr=0
        ctr1=0
        ctr2=0
        ctr3=0
        ctr4=0
        ctr5=0
        ctr6=0
       
       
        Dim acleditor As Variant
        ReDim acleditor(0)
       
        Dim aclmanager As Variant
        ReDim aclmanager(0)
       
        Dim acldesigner As Variant
        ReDim acldesigner(0)
       
        Dim aclauthor As Variant
        ReDim aclauthor(0)
       
        Dim aclreader As Variant
        ReDim aclreader(0)
       
        Dim acldepositor As Variant
        ReDim acldepositor(0)
       
        Dim aclnoaccess As Variant
        ReDim aclnoaccess(0)
       
        While Not Aclentry Is Nothing
           
           
            If (Aclentry.Level = ACLLEVEL_EDITOR) Then
                If (ctr<>0) Then
                    ReDim Preserve acleditor(UBound (acleditor)+1)
                End If
                acleditor(ctr)=Aclentry.name
                ctr=ctr+1
            ElseIf (Aclentry.Level = ACLLEVEL_MANAGER) Then
                If (ctr1<>0) Then
                    ReDim Preserve aclmanager(UBound (aclmanager)+1)
                End If
                aclmanager(ctr1)=Aclentry.name
                ctr1=ctr1+1
               
            ElseIf (Aclentry.Level = ACLLEVEL_DESIGNER) Then
                If (ctr2<>0) Then
                    ReDim Preserve acldesigner(UBound (acldesigner)+1)
                End If
                acldesigner(ctr2)=Aclentry.name
                ctr2=ctr2+1
               
            ElseIf (Aclentry.Level = ACLLEVEL_AUTHOR) Then
                If (ctr3<>0) Then
                    ReDim Preserve aclauthor(UBound (aclauthor)+1)
                End If
                aclauthor(ctr3)=Aclentry.name
                ctr3=ctr3+1
               
            ElseIf (Aclentry.Level = ACLLEVEL_READER) Then
                If (ctr4<>0) Then
                    ReDim Preserve aclreader(UBound (aclreader)+1)
                End If
                aclreader(ctr4)=Aclentry.name
                ctr4=ctr4+1
               
               
            ElseIf (Aclentry.Level = ACLLEVEL_DEPOSITOR) Then
                If (ctr5<>0) Then
                    ReDim Preserve acldepositor(UBound (acldepositor)+1)
                End If
                acldepositor(ctr5)=Aclentry.name
                ctr5=ctr5+1
               
               
            ElseIf (Aclentry.Level = ACLLEVEL_NOACCESS) Then
                If (ctr6<>0) Then
                    ReDim Preserve aclnoaccess(UBound (aclnoaccess)+1)
                End If
                aclnoaccess(ctr6)=Aclentry.name
                ctr6=ctr6+1

            End If
           
           

            Set Aclentry = acl.GetNextEntry( Aclentry )
           
        Wend
       
        persondoc.txt_manager=aclmanager
        persondoc.txt_designer=acldesigner
        persondoc.txt_editor=acleditor
        persondoc.txt_author=aclauthor
        persondoc.txt_reader=aclreader
        persondoc.txt_depositor=acldepositor
        persondoc.txt_noaccess=aclnoaccess
       
        Call persondoc.Save(True,False)   
        Print "count :" & n    & "for :" & profiledoc.mailfile(0)
        Set profiledoc=profilevw.Getnextdocument(profiledoc)
        n=n+1
    Wend
   
    Dim vc As NotesViewEntryCollection
    Set vc=profilevw.Allentries
    Call vc.Stampall("flag","Yes")
    MsgBox "Completed"
   
    Exit Sub
   
ErrorHandler:
    Call ActivityLogRTItem.AppendText( Now+ ": "&" Error in  :" +profiledoc.mailfile(0))
    Call ActivityLogRTItem.AppendText( Now+ ": Error " & Err() & ": " & Error() & "error line:" & CStr(Erl()))
    Call ActivityLogRTItem.AddNewLine( 1)
    Call LogDoc.Save(True,False)
    Resume Next
    'Exit sub
End Sub

No comments:

Post a Comment