Active Directoryを使用した1C 8.2データベースのリストの管理

読者の皆様、ご挨拶!

伝統的に、あまり蹴らないようにお願いします。なぜなら、 これは私の最初の投稿です。



そのため、約6か月前、タスクはドメインのユーザーからの1Cデータベースのリスト(そのうち20以上が既に離婚している)の管理を自動化することでした。

これは、便宜上だけでなく、プロジェクトのフレームワーク内でも行われ、「ロールベースのアクセスモデル」が導入されました。 つまり、このモデルの意味は、ドメイン内の各ユーザーが特定のグループ(位置に応じて名前が付けられている)のメンバーであり、情報ベースのリストを含む事前定義された特権セットを持っているということです。



なぜなら Active Directoryドメインがある場合、グループポリシーを使用してタスクを完了するのが論理的です。

グーグルはかなりの数の実装(および有料の実装)を作成しましたが、それらのすべては、ほとんどの場合、データベースのリスト(ibases.v8i)を含む事前生成ファイルになりました。 したかったのは:

a)インフォベースに接続するための設定を一元管理します(SQLデータベースを備えたクライアントサーバーバージョンがあります)。

b)ユーザーの「ロール」に従って、ユーザーが利用できる情報ベースのリストを一元管理します。



その結果、私たちの会社で6か月以上働いているソリューションについてお話します。





それでは始めましょう。



ステップ1



1C 8.2はibases.v8iファイルに情報ベースのリストを保存します。このようなファイルは各ユーザーのプロファイルに存在します。 このファイルの形式と動作原理はここここで詳しく説明さいるので、 ここでこれを繰り返す理由はありません。

また、ibases.v8iファイルと同じディレクトリに1CEStart.cfgファイルがあります。このファイルの機能は、特定の情報ベースに接続するためのパラメーターを含む個々の* .v8iファイルへのパスを含むことができることです。

起動時に、1Cは1CEStart.cfgに登録されたファイルから情報ベースへの接続のパラメーターを取得し、それらをibases.v8iに配置します。 この機能を使用します。

最初に、各インフォベースのv8iファイルを作成します。

このようなファイルを作成する最も簡単な方法は、リスト内の目的のデータベースを右クリックし、「ファイルへのリンクを保存」オプションを選択することです。

画像

ただし、このように作成されたv8iファイルには、不要な「余分な」行が含まれていることに注意してください。 通常の操作では、次のもののみを残すだけで十分です。



[%NAME% ] Connect=Srvr="%server%";Ref="%base%"; ClientConnectionSpeed=Normal App=Auto WA=1 Version=8.2
      
      





次に、これらのファイルをローカルネットワークユーザーの公開場所に配置し、「読み取り」権限を付与する必要があります。 面倒なことはせず、ドメインコントローラーのNETLOGONフォルダーに配置しました。 これにはいくつかの理由があります。ドメインコントローラー間のディレクトリレプリケーションとフォールトトレランス(3つのコントローラーがあり、そのうちの少なくとも1つがいつでも利用可能であるため)。



ステップ2



特定のADグループのユーザーのメンバーシップに基づいてインフォベースのリストを管理するため、1Cデータベースに応じて必要な数のセキュリティグループを作成します。

画像



プレフィックス「1C_82」は必須であり、さらにその理由は明らかです。



ここで、新しく作成された各セキュリティグループの[メモ]フィールドで、対応するv8iファイルへのパスを指定します。

画像



これはグループで終わりました。



ステップ3



ユーザーがログオンするたびに次のvbsスクリプトを実行するグ​​ループポリシーを作成します。



VBSコード
 On Error Resume Next Const PROPERTY_NOT_FOUND = &h8000500D Dim sGroupNames Dim sGroupDNs Dim aGroupNames Dim aGroupDNs Dim aMemof Dim oUser Dim tgdn Dim fso Dim V8iConfigFile Dim dir Const ForReading = 1, ForWriting = 2, ForAppending = 8 '   Set fso = CreateObject("Scripting.FileSystemObject") Set WshShell = WScript.CreateObject("Wscript.Shell") strSysVarTEMP = WshShell.ExpandEnvironmentStrings("%TEMP%") Set oScriptLog = fso.OpenTextFile(strSysVarTEMP + "\_dbconn.log",ForWriting,True) oScriptLog.Write "" strToLog = CStr(Date())+" "+CStr(Time()) + " - " + "Start..." oScriptLog.WriteLine(strToLog) ',  1  Set objFSO = CreateObject("Scripting.FileSystemObject") If Not (objFSO.FolderExists("C:\Program Files\1cv82") Or objFSO.FolderExists("C:\Program Files (x86)\1cv82")) Then strToLog = CStr(Date())+" "+CStr(Time()) + " - " + "1C 8.2 not installed... Quit..." oScriptLog.WriteLine(strToLog) WScript.quit End If '         ' APPDATA = WshShell.ExpandEnvironmentStrings("%APPDATA%") v8i = APPDATA + "\1C\1CEStart\ibases.v8i" If fso.FileExists(v8i) Then fso.DeleteFile(v8i) Set V8iConfigFile = fso.CreateTextFile(v8i ,True) strToLog = CStr(Date())+" "+CStr(Time()) + " - " + "  v8i   " oScriptLog.WriteLine(strToLog) '    (1  ),       Else Set dir = fso.CreateFolder(APPDATA + "\1C") Set dir = fso.CreateFolder(dir + "\1CEStart") Set V8iConfigFile = fso.CreateTextFile(v8i ,True) strToLog = CStr(Date())+" "+CStr(Time()) + " - " + "  v8i" oScriptLog.WriteLine(strToLog) End if ' ' Initialise strings. We make the assumption that every account is a member of two system groups ' sGroupNames = "Authenticated Users(S),Everyone(S)" ' ' Enter the DN for the user account here Set objSysInfo = CreateObject("ADSystemInfo") strUserName = objSysInfo.UserName strToLog = CStr(Date())+" "+CStr(Time()) + " - " + "Logged user DN: "+strUserName oScriptLog.WriteLine(strToLog) '     Set oUser = GetObject("LDAP://" + strUserName) If Err.Number <> 0 Then strToLog = CStr(Date())+" "+CStr(Time()) + " - " + "There is an error retrieving the account. Please check your distinguished name syntax assigned to the oUser object." oScriptLog.WriteLine(strToLog) WScript.quit End If ' ' Determine the DN of the primary group ' We make an assumption that every user account is a member of a primary group ' iPgid = oUser.Get("primaryGroupID") sGroupDNs = primgroup(iPgid) tgdn = sGroupDNs ' ' Call a subroutine to extract the group name and scope ' Add the result to the accumulated group name String ' Call Getmemof(tgdn) ' ' Check the direct group membership for the User account ' aMemOf = oUser.GetEx("memberOf") If Err.Number <> PROPERTY_NOT_FOUND Then ' ' Call a recursive subroutine to retrieve all indirect group memberships ' Err.clear For Each GroupDN in aMemof Call AddGroups(GroupDN) Call Getmemof(GroupDN) Next End If aGroupNames = Split(sGroupNames,",") aGroupDNs = Split(sGroupDNs,":") '  ,    1C_82 For Each strGroupDN in aGroupDNs if StrComp(Mid(strGroupDN,1,8), "CN=1C_82", vbTextCompare) = 0 Then strToLog = CStr(Date())+" "+CStr(Time()) + " - " + "User is member of: " + strGroupDN oScriptLog.WriteLine(strToLog) Set objGroup = GetObject("LDAP://" & strGroupDN) If Err.Number <> 0 Then strToLog = CStr(Date())+" "+CStr(Time()) + " - " + "There is an error retrieving the group. Please check your distinguished name syntax assigned to the objGroup object: " + strGroupDN oScriptLog.WriteLine(strToLog) WScript.quit End If strInfo = objGroup.Get("info") strToLog = CStr(Date())+" "+CStr(Time()) + " - " + "Group " + strGroupDN +" info field: " + strInfo oScriptLog.WriteLine(strToLog) strAllInfo = strAllInfo & ":" & strInfo End If Next aInfoStrings = Split(strAllInfo,":") Call WriteDBSettings() Sub WriteDBSettings() '   v8i   1CEStart.cfg strSysVarAPPDATA = WshShell.ExpandEnvironmentStrings("%APPDATA%") strDBConfigFilePath = strSysVarAPPDATA + "\1C\1CEStart\1CEStart.cfg" strToLog = CStr(Date())+" "+CStr(Time()) + " - " + "1C Config file is: " + strDBConfigFilePath oScriptLog.WriteLine(strToLog) If (fso.FileExists(strDBConfigFilePath)) Then Set objDBConfigFile = fso.OpenTextFile(strDBConfigFilePath,ForWriting,True) objDBConfigFile.Write "" For each strInfo in aInfoStrings objDBConfigFile.WriteLine("CommonInfoBases=" + strInfo) strToLog = CStr(Date())+" "+CStr(Time()) + " - " + "Add Line: " + "CommonInfoBases=" + strInfo oScriptLog.WriteLine(strToLog) next '  0,      objDBConfigFile.WriteLine("UseHWLicenses=1") strToLog = CStr(Date())+" "+CStr(Time()) + " - " + "Add Line: " + "UseHWLicenses=1" oScriptLog.WriteLine(strToLog) strToLog = CStr(Date())+" "+CStr(Time()) + " - " + "Ready" oScriptLog.WriteLine(strToLog) objDBConfigFile.Close Else Set fso = CreateObject("Scripting.FileSystemObject") Set WshShell = WScript.CreateObject("Wscript.Shell") Set objDBConfigFile = fso.OpenTextFile(strDBConfigFilePath,ForWriting,True) objDBConfigFile.Write "" For each strInfo in aInfoStrings objDBConfigFile.WriteLine("CommonInfoBases=" + strInfo) strToLog = CStr(Date())+" "+CStr(Time()) + " - " + "Add Line: " + "CommonInfoBases=" + strInfo oScriptLog.WriteLine(strToLog) next strToLog = CStr(Date())+" "+CStr(Time()) + " - " + "1C Config file" + strDBConfigFilePath + " Not Exist! Create!" oScriptLog.WriteLine(strToLog) WScript.Quit End If End Sub '************************************************************************************************* ' End of mainline code '************************************************************************************************* Function primgroup(groupid) ' This function accepts a primary group id ' It binds to the local domain and returns the DN of the primary group ' David Zemdegs 6 May 2008 ' Dim oRootDSE,oConn,oCmd,oRset Dim ADDomain,srchdmn ' Bind to loca domain Set oRootDSE = GetObject("LDAP://RootDSE") ADDomain = oRootDSE.Get("defaultNamingContext") srchdmn = "<LDAP://" & ADDomain & ">" ' ' Initialise AD search and obtain the recordset of groups ' Set oConn = CreateObject("ADODB.Connection") oConn.Open "Provider=ADsDSOObject;" Set oCmd = CreateObject("ADODB.Command") oCmd.ActiveConnection = oConn oCmd.CommandText = srchdmn & ";(objectCategory=Group);" & _ "distinguishedName,primaryGroupToken;subtree" Set oRset = oCmd.Execute ' ' Loop through the recordset and find the matching primary group token ' When found retrieve the DN and exit the loop ' Do Until oRset.EOF If oRset.Fields("primaryGroupToken") = groupid Then primgroup = oRset.Fields("distinguishedName") Exit Do End If oRset.MoveNext Loop ' ' Close and tidy up objects ' oConn.Close Set oRootDSE = Nothing Set oConn = Nothing Set oCmd = Nothing Set oRset = Nothing End Function Sub Getmemof(sDN) ' ' This is recursive subroutine that calls itself for memberof Property ' David Zemdegs 6 May 2008 ' On Error Resume Next Dim oGrp Dim aGrpMemOf Dim sGrpDN Set oGrp = GetObject("LDAP://" & sDN) aGrpMemOf = oGrp.GetEx("memberOf") If Err.Number <> PROPERTY_NOT_FOUND Then ' ' Call a recursive subroutine to retrieve all indirect group memberships ' Err.clear For Each sGrpDN in aGrpMemOf Call AddGroups(sGrpDN) Call Getmemof(sGrpDN) Next End If Err.clear Set oGrp = Nothing End Sub Sub AddGroups(sGdn) ' ' This subroutine accepts a disguished name ' It extracts the RDN as the group name and determines the group scope ' This is then appended to the group name String ' It also appends the DN to the DN String ' Const SCOPE_GLOBAL = &h2 Const SCOPE_LOCAL = &h4 Const SCOPE_UNIVERSAL = &h8 Dim SNewgrp ' ' Retrieve the group name ' iComma = InStr(1,sGdn,",") sGrpName = Mid(sGdn,4,iComma-4) ' ' Add the results to the group name String ' Check that the group doesnt already exist in the list ' sNewgrp = sGrpName If InStr(1,sGroupNames,SNewgrp,1) = 0 Then sGroupNames = sGroupNames & "," & SNewgrp End If ' ' Add the Groups DN to the string if not duplicate ' If InStr(1,sGroupDNs,sGdn,1) = 0 Then sGroupDNs = sGroupDNs & ":" & sGdn End If End Sub
      
      







スクリプトのロジックは次のとおりです。

1. 1Cがインストールされているかどうかを確認し、インストールされていない場合、スクリプトは終了します。

2. ibases.v8iファイルが存在するかどうかを確認し、空に上書きします(存在しない場合は作成します)。

3.ユーザーがメンバーになっているADからすべてのグループを取得します。

4. 1C_82で始まるものを除くすべてをドロップします。

5.「Notes」属性の値を取得します。

6.この属性の値をファイル1CEStart.cfgに書き込みます

途中で、ログが書き込まれます。

Windows 7の場合-C:\ユーザー\ユーザー名\ appdata \ローカル\一時\ _dbconn.log

Windows XPの場合-C:\ Documents and Settings \ username \ Local Settings \ Temp \ _dbconn.log



ステップ4



グループポリシーを必要なOUまたはドメイン全体に「ハング」させます。 スクリプトが無差別に適用されないように(すべてのユーザーが1Cで作業するわけではない)、ステップ2で作成したグループのみをグループポリシーセキュリティフィルターに追加したため、スクリプトは含まれるユーザーに対してのみ機能することに注意してくださいこれらのグループの少なくとも1つで:

画像



ステップ5



役割ベースのアクセスモデルで提供される1Cグループにユーザーのグループ(読み取り位置)を含めます(ただし、1人のユーザーでも可能ですが、例外があります)。 再起動後、ユーザーは自分の位置に個別の情報ベースのリストを取得します。

まあ、それがすべてです。

ちなみに、変更を適用するには、ユーザーはログインする必要がありません。たとえば、スクリプトを電子メールで送信するなど、便利な方法でユーザーにこのスクリプトを実行させるだけです。



ご清聴ありがとうございました。この記事が誰かを助けてくれたらとても嬉しいです。



All Articles