1 |
(* ***** BEGIN LICENSE BLOCK *****
|
2 |
* Version: MPL 1.1
|
3 |
*
|
4 |
* The contents of this file are subject to the Mozilla Public License Version
|
5 |
* 1.1 (the "License"); you may not use this file except in compliance with
|
6 |
* the License. You may obtain a copy of the License at
|
7 |
* http://www.mozilla.org/MPL/
|
8 |
*
|
9 |
* Software distributed under the License is distributed on an "AS IS" basis,
|
10 |
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
11 |
* for the specific language governing rights and limitations under the
|
12 |
* License.
|
13 |
*
|
14 |
* The Original Code is TurboPower SysTools
|
15 |
*
|
16 |
* The Initial Developer of the Original Code is
|
17 |
* TurboPower Software
|
18 |
*
|
19 |
* Portions created by the Initial Developer are Copyright (C) 1996-2002
|
20 |
* the Initial Developer. All Rights Reserved.
|
21 |
*
|
22 |
* Contributor(s):
|
23 |
*
|
24 |
* ***** END LICENSE BLOCK ***** *)
|
25 |
|
26 |
unit EXUSRMG0;
|
27 |
|
28 |
interface
|
29 |
|
30 |
uses
|
31 |
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
|
32 |
Menus, ComCtrls, ExtCtrls,
|
33 |
|
34 |
StNet;
|
35 |
|
36 |
type
|
37 |
TMainForm = class(TForm)
|
38 |
MainMenu1: TMainMenu;
|
39 |
User1: TMenuItem;
|
40 |
About1: TMenuItem;
|
41 |
NewUser1: TMenuItem;
|
42 |
NewGlobalGroup1: TMenuItem;
|
43 |
N1: TMenuItem;
|
44 |
Delete1: TMenuItem;
|
45 |
Properties1: TMenuItem;
|
46 |
N2: TMenuItem;
|
47 |
SelectServer1: TMenuItem;
|
48 |
N3: TMenuItem;
|
49 |
Exit1: TMenuItem;
|
50 |
NewLocalGroup1: TMenuItem;
|
51 |
Panel1: TPanel;
|
52 |
Splitter1: TSplitter;
|
53 |
Panel2: TPanel;
|
54 |
ListView1: TListView;
|
55 |
ListView2: TListView;
|
56 |
procedure SelectServer1Click(Sender: TObject);
|
57 |
procedure About1Click(Sender: TObject);
|
58 |
procedure Properties1Click(Sender: TObject);
|
59 |
procedure Delete1Click(Sender: TObject);
|
60 |
procedure ListViewKeyDown(Sender: TObject; var Key: Word;
|
61 |
Shift: TShiftState);
|
62 |
procedure NewUser1Click(Sender: TObject);
|
63 |
procedure NewGlobalGroup1Click(Sender: TObject);
|
64 |
procedure NewLocalGroup1Click(Sender: TObject);
|
65 |
procedure Exit1Click(Sender: TObject);
|
66 |
private
|
67 |
{ Private declarations }
|
68 |
public
|
69 |
{ Public declarations }
|
70 |
CS : TStNetServerItem;
|
71 |
UL : TStringList;
|
72 |
GL : TStringList;
|
73 |
end;
|
74 |
|
75 |
var
|
76 |
MainForm: TMainForm;
|
77 |
|
78 |
implementation
|
79 |
|
80 |
{$R *.DFM}
|
81 |
|
82 |
uses EXUSRMG1, EXUSRMG2, EXUSRMG3, EXUSRMG4;
|
83 |
|
84 |
procedure TMainForm.SelectServer1Click(Sender: TObject);
|
85 |
var
|
86 |
SelectedServer : string;
|
87 |
I : Integer;
|
88 |
U : TStNetUserItem;
|
89 |
G : TStNetGroupItem;
|
90 |
LI : TListItem;
|
91 |
begin
|
92 |
if InputQuery('Server name', 'Select the server name to use', SelectedServer) then begin
|
93 |
CS := StNetwork.Server[SelectedServer];
|
94 |
|
95 |
if CS <> nil then begin
|
96 |
|
97 |
{ load the users into the listview }
|
98 |
ListView1.Items.Clear;
|
99 |
UL := CS.Users;
|
100 |
for I := 0 to UL.Count-1 do begin
|
101 |
U := TStNetUserItem(UL.Objects[I]);
|
102 |
if (U.ItemType = nitLocalUser) or (U.ItemType = nitGlobalUser) then begin
|
103 |
LI := ListView1.Items.Add;
|
104 |
LI.Caption := U.Name;
|
105 |
LI.SubItems.Add(U.FullName);
|
106 |
LI.SubItems.Add(U.Comment);
|
107 |
end;
|
108 |
end;
|
109 |
|
110 |
{ load the groups into the listview }
|
111 |
ListView2.Items.Clear;
|
112 |
GL := CS.Groups;
|
113 |
for I := 0 to GL.Count-1 do begin
|
114 |
G := TStNetGroupItem(GL.Objects[I]);
|
115 |
if (G.ItemType = nitLocalGroup) or (G.ItemType = nitGlobalGroup) then begin
|
116 |
LI := ListView2.Items.Add;
|
117 |
LI.Caption := G.Name;
|
118 |
LI.SubItems.Add(G.Comment);
|
119 |
end;
|
120 |
end;
|
121 |
|
122 |
{ check for GloableGroup creation on domain controllers }
|
123 |
if (nsvtDomainCtrl in CS.ServerType) or (nsvtDomainBackupCtrl in CS.ServerType) then
|
124 |
NewGlobalGroup1.Enabled := True
|
125 |
else
|
126 |
NewGlobalGroup1.Enabled := False;
|
127 |
end;
|
128 |
end;
|
129 |
end;
|
130 |
|
131 |
procedure TMainForm.About1Click(Sender: TObject);
|
132 |
var
|
133 |
AdditionalText, Caption : string;
|
134 |
begin
|
135 |
AdditionalText := 'An network example program from the TurboPower SysTools Library';
|
136 |
Caption := MainForm.Caption;
|
137 |
|
138 |
Application.MessageBox(PChar(AdditionalText), PChar(Caption),
|
139 |
MB_OK or MB_ICONINFORMATION);
|
140 |
end;
|
141 |
|
142 |
procedure TMainForm.Properties1Click(Sender: TObject);
|
143 |
var
|
144 |
LI : TListItem;
|
145 |
UPF : TUserPropertiesForm;
|
146 |
GPF : TGroupPropertiesForm;
|
147 |
begin
|
148 |
{ Are we dealing with a user or group? }
|
149 |
if (ListView1.Focused) and (ListView1.SelCount > 0) then begin
|
150 |
LI := ListView1.Selected;
|
151 |
|
152 |
UPF := TUserPropertiesForm.Create(Self);
|
153 |
UPF.U := TStNetUserItem(UL.Objects[UL.IndexOf(LI.Caption)]);
|
154 |
case UPF.ShowModal of
|
155 |
mrOK :
|
156 |
begin
|
157 |
{ update the data }
|
158 |
UPF.U.Name := UPF.UserNameEdit.Text;
|
159 |
UPF.U.FullName := UPF.FullNameEdit.Text;
|
160 |
UPF.U.Comment := UPF.CommentEdit.Text;
|
161 |
|
162 |
if (UPF.Password1Edit.Text <> 'NO PASSWORD CHANGE') then
|
163 |
UPF.U.Password := UPF.Password1Edit.Text;
|
164 |
|
165 |
LI.Caption := UPF.U.Name;
|
166 |
LI.SubItems.Strings[0] := UPF.U.FullName;
|
167 |
LI.SubItems.Strings[1] := UPF.U.Comment;
|
168 |
end;
|
169 |
|
170 |
mrCancel : ;
|
171 |
end;
|
172 |
UPF.Free;
|
173 |
end else if (ListView2.Focused) and (ListView2.SelCount > 0) then begin
|
174 |
LI := ListView2.Selected;
|
175 |
GPF := TGroupPropertiesForm.Create(Self);
|
176 |
GPF.G := TStNetGroupItem(GL.Objects[GL.IndexOf(LI.Caption)]);
|
177 |
case GPF.ShowModal of
|
178 |
mrOK :
|
179 |
begin
|
180 |
{ update the data }
|
181 |
GPF.G.Name := GPF.GroupNameEdit.Text;
|
182 |
GPF.G.Comment := GPF.CommentEdit.Text;
|
183 |
|
184 |
LI.Caption := GPF.G.Name;
|
185 |
LI.SubItems.Strings[0] := GPF.G.Comment;
|
186 |
end;
|
187 |
|
188 |
mrCancel : ;
|
189 |
end;
|
190 |
GPF.Free;
|
191 |
end;
|
192 |
end;
|
193 |
|
194 |
procedure TMainForm.Delete1Click(Sender: TObject);
|
195 |
var
|
196 |
LI : TListItem;
|
197 |
U : TStNetUserItem;
|
198 |
G : TStNetGroupItem;
|
199 |
begin
|
200 |
{ Are we dealing with a user or group? }
|
201 |
if (ListView1.Focused) and (ListView1.SelCount > 0) then begin
|
202 |
LI := ListView1.Selected;
|
203 |
U := TStNetUserItem(UL.Objects[UL.IndexOf(LI.Caption)]);
|
204 |
|
205 |
if MessageDlg('Are you sure you want to delete the user - [' + U.Name + ']?',
|
206 |
mtConfirmation, [mbYes, mbNo], 0) = mrYes then begin
|
207 |
U.Delete;
|
208 |
LI.Delete;
|
209 |
end;
|
210 |
end else if (ListView2.Focused) and (ListView2.SelCount > 0) then begin
|
211 |
LI := ListView2.Selected;
|
212 |
G := TStNetGroupItem(GL.Objects[GL.IndexOf(LI.Caption)]);
|
213 |
if MessageDlg('Are you sure you want to delete the group - [' + G.Name + ']?',
|
214 |
mtConfirmation, [mbYes, mbNo], 0) = mrYes then begin
|
215 |
G.Delete;
|
216 |
LI.Delete;
|
217 |
end;
|
218 |
end;
|
219 |
end;
|
220 |
|
221 |
procedure TMainForm.ListViewKeyDown(Sender: TObject; var Key: Word;
|
222 |
Shift: TShiftState);
|
223 |
begin
|
224 |
if Key = VK_RETURN then begin
|
225 |
Properties1Click(Sender);
|
226 |
end;
|
227 |
end;
|
228 |
|
229 |
procedure TMainForm.NewUser1Click(Sender: TObject);
|
230 |
var
|
231 |
NU : TNewUserForm;
|
232 |
U : TStNetUserItem;
|
233 |
LI : TListItem;
|
234 |
begin
|
235 |
if CS = nil then
|
236 |
Exit;
|
237 |
{ Create a new user }
|
238 |
NU := TNewUserForm.Create(Self);
|
239 |
NU.Caption := Format(NU.Caption, [CS.Name]);
|
240 |
case NU.ShowModal of
|
241 |
mrOK :
|
242 |
begin
|
243 |
U := CS.AddUser(NU.UserNameEdit.Text, NU.Password1Edit.Text, True);
|
244 |
U.FullName := NU.FullNameEdit.Text;
|
245 |
U.Comment := NU.CommentEdit.Text;
|
246 |
|
247 |
LI := ListView1.Items.Add;
|
248 |
LI.Caption := U.Name;
|
249 |
LI.SubItems.Add(U.FullName);
|
250 |
LI.SubItems.Add(U.Comment);
|
251 |
|
252 |
U.Free; {!!.01}
|
253 |
UL := CS.Users;
|
254 |
end;
|
255 |
mrCancel : ;
|
256 |
end;
|
257 |
NU.Free;
|
258 |
end;
|
259 |
|
260 |
procedure TMainForm.NewGlobalGroup1Click(Sender: TObject);
|
261 |
var
|
262 |
NG : TNewGroupForm;
|
263 |
G : TStNetGroupItem;
|
264 |
LI : TLIstItem;
|
265 |
begin
|
266 |
if CS = nil then
|
267 |
Exit;
|
268 |
{ Create a new global group }
|
269 |
NG := TNewGroupForm.Create(Self);
|
270 |
NG.Caption := Format(NG.Caption, [CS.Name, 'global']);
|
271 |
case NG.ShowModal of
|
272 |
mrOK :
|
273 |
begin
|
274 |
G := CS.AddGroup(NG.GroupNameEdit.Text, NG.CommentEdit.Text, True);
|
275 |
|
276 |
LI := ListView2.Items.Add;
|
277 |
LI.Caption := G.Name;
|
278 |
LI.SubItems.Add(G.Comment);
|
279 |
|
280 |
G.Free; {!!.01}
|
281 |
GL := CS.Groups;
|
282 |
end;
|
283 |
mrCancel : ;
|
284 |
end;
|
285 |
NG.Free;
|
286 |
end;
|
287 |
|
288 |
procedure TMainForm.NewLocalGroup1Click(Sender: TObject);
|
289 |
var
|
290 |
NG : TNewGroupForm;
|
291 |
G : TStNetGroupItem;
|
292 |
LI : TLIstItem;
|
293 |
begin
|
294 |
if CS = nil then
|
295 |
Exit;
|
296 |
{ create a new local group }
|
297 |
NG := TNewGroupForm.Create(Self);
|
298 |
NG.Caption := Format(NG.Caption, [CS.Name, 'local']);
|
299 |
case NG.ShowModal of
|
300 |
mrOK :
|
301 |
begin
|
302 |
G := CS.AddGroup(NG.GroupNameEdit.Text, NG.CommentEdit.Text, False);
|
303 |
|
304 |
LI := ListView2.Items.Add;
|
305 |
LI.Caption := G.Name;
|
306 |
LI.SubItems.Add(G.Comment);
|
307 |
|
308 |
G.Free; {!!.01}
|
309 |
GL := CS.Groups;
|
310 |
end;
|
311 |
mrCancel : ;
|
312 |
end;
|
313 |
NG.Free;
|
314 |
end;
|
315 |
|
316 |
procedure TMainForm.Exit1Click(Sender: TObject);
|
317 |
begin
|
318 |
Close;
|
319 |
end;
|
320 |
|
321 |
end.
|