forked from ibv/LDAP-Admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOu.pas
146 lines (128 loc) · 3.67 KB
/
Ou.pas
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
{ LDAPAdmin - Ou.pas
* Copyright (C) 2003 Tihomir Karlovic
*
* Author: Tihomir Karlovic
*
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This file is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
}
unit Ou;
{$IFDEF FPC}
{$MODE Delphi}
{$ENDIF}
interface
uses
{$IFnDEF FPC}
Windows,
{$ELSE}
LCLIntf, LCLType, LMessages,
{$ENDIF}
Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, LDAPClasses, Constant;
type
TOuDlg = class(TForm)
NameLabel: TLabel;
ou: TEdit;
GroupBox1: TGroupBox;
Label18: TLabel;
Label19: TLabel;
Label24: TLabel;
Label31: TLabel;
postalAddress: TMemo;
st: TEdit;
postalCode: TEdit;
l: TEdit;
Label1: TLabel;
description: TEdit;
OKBtn: TButton;
CancelBtn: TButton;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormDestroy(Sender: TObject);
private
Entry: TLDAPEntry;
ParentDn: string;
procedure Save;
public
constructor Create(AOwner: TComponent; dn: string; Session: TLDAPSession; Mode: TEditMode); reintroduce;
end;
var
OuDlg: TOuDlg;
implementation
uses {$ifdef mswindows}WinLDAP,{$else} LinLDAP,{$endif} Misc;
{$R *.dfm}
procedure TOuDlg.Save;
var
C: Integer;
Component: TComponent;
s: string;
begin
if ou.Text = '' then
raise Exception.Create(Format(stReqNoEmpty, [cName]));
if esNew in Entry.State then
begin
Entry.dn := 'ou=' + EncodeLdapString(ou.Text) + ',' + ParentDn;
with Entry.AttributesByName['objectclass'] do
begin
AddValue('top');
AddValue('organizationalUnit');
end;
Entry.AttributesByName['ou'].AddValue(ou.Text);
end;
for C := 0 to GroupBox1.ControlCount - 1 do
begin
Component := GroupBox1.Controls[c];
if (Component is TCustomEdit) and (TCustomEdit(Component).Modified) then
begin
if Component is TMemo then
s := FormatMemoOutput(TMemo(Component).Text)
else
s := TEdit(Component).Text;
Entry.AttributesByName[Component.Name].AsString := s;
end;
end;
Entry.Write;
end;
constructor TOuDlg.Create(AOwner: TComponent; dn: string; Session: TLDAPSession; Mode: TEditMode);
var
C: Integer;
begin
inherited Create(AOwner);
ParentDn := dn;
Entry := TLDAPEntry.Create(Session, dn);
if Mode = EM_MODIFY then
begin
ou.Enabled := False;
ou.text := GetNameFromDn(dn);
Caption := Format(cPropertiesOf, [ou.Text]);
Entry.Read;
for C := 0 to ComponentCount - 1 do
begin
if Components[C] is TEdit then with TEdit(Components[C]) do
Text := Entry.AttributesByName[Name].AsString;
end;
postalAddress.Text := FormatMemoInput(Entry.AttributesByName['postalAddress'].AsString);
end;
end;
procedure TOuDlg.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if ModalResult = mrOK then
Save;
Action := caFree;
end;
procedure TOuDlg.FormDestroy(Sender: TObject);
begin
Entry.Free;
end;
end.