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 |
#include <vcl.h>
|
27 |
#pragma hdrstop
|
28 |
|
29 |
#include "ExUsrMg0.h"
|
30 |
#include "ExUsrMg1.h"
|
31 |
#include "ExUsrMg2.h"
|
32 |
#include "ExUsrMg3.h"
|
33 |
#include "ExUsrMg4.h"
|
34 |
#pragma link "stnet"
|
35 |
//---------------------------------------------------------------------------
|
36 |
#pragma package(smart_init)
|
37 |
#pragma resource "*.dfm"
|
38 |
TMainForm *MainForm;
|
39 |
//---------------------------------------------------------------------------
|
40 |
__fastcall TMainForm::TMainForm(TComponent* Owner)
|
41 |
: TForm(Owner)
|
42 |
{
|
43 |
}
|
44 |
//---------------------------------------------------------------------------
|
45 |
void __fastcall TMainForm::SelectServer1Click(TObject *Sender)
|
46 |
{
|
47 |
String SelectedServer;
|
48 |
if (InputQuery("Server name", "Select the server name to use", SelectedServer)) {
|
49 |
CS = StNetwork->Server[SelectedServer];
|
50 |
|
51 |
if (CS) {
|
52 |
|
53 |
// load the users into the listview
|
54 |
ListView1->Items->Clear();
|
55 |
UL = CS->Users;
|
56 |
for (int i=0;i<UL->Count;i++) {
|
57 |
TStNetUserItem* U = (TStNetUserItem*)UL->Objects[i];
|
58 |
if ((U->ItemType == nitLocalUser) || (U->ItemType == nitGlobalUser)) {
|
59 |
TListItem* LI = ListView1->Items->Add();
|
60 |
LI->Caption = U->Name;
|
61 |
LI->SubItems->Add(U->FullName);
|
62 |
LI->SubItems->Add(U->Comment);
|
63 |
}
|
64 |
}
|
65 |
|
66 |
// load the groups into the listview
|
67 |
ListView2->Items->Clear();
|
68 |
GL = CS->Groups;
|
69 |
for (int i=0;i<GL->Count;i++) {
|
70 |
TStNetGroupItem* G = (TStNetGroupItem*)GL->Objects[i];
|
71 |
if ((G->ItemType == nitLocalGroup) || (G->ItemType == nitGlobalGroup)) {
|
72 |
TListItem* LI = ListView2->Items->Add();
|
73 |
LI->Caption = G->Name;
|
74 |
LI->SubItems->Add(G->Comment);
|
75 |
}
|
76 |
}
|
77 |
|
78 |
// check for GloableGroup creation on domain controllers
|
79 |
if (CS->ServerType.Contains(nsvtDomainCtrl) || CS->ServerType.Contains(nsvtDomainBackupCtrl))
|
80 |
NewGlobalGroup1->Enabled = true;
|
81 |
else
|
82 |
NewGlobalGroup1->Enabled = false;
|
83 |
}
|
84 |
}
|
85 |
}
|
86 |
//---------------------------------------------------------------------------
|
87 |
void __fastcall TMainForm::About1Click(TObject *Sender)
|
88 |
{
|
89 |
String AdditionalText = "An network example program from the TurboPower SysTools Library";
|
90 |
String Caption = MainForm->Caption;
|
91 |
Application->MessageBox(AdditionalText.c_str(), Caption.c_str(), MB_OK | MB_ICONINFORMATION);
|
92 |
}
|
93 |
//---------------------------------------------------------------------------
|
94 |
void __fastcall TMainForm::Properties1Click(TObject *Sender)
|
95 |
{
|
96 |
TListItem* LI;
|
97 |
// Are we dealing with a user or group?
|
98 |
if (ListView1->Focused() && ListView1->SelCount > 0) {
|
99 |
LI = ListView1->Selected;
|
100 |
|
101 |
TUserPropertiesForm* UPF = new TUserPropertiesForm(this);
|
102 |
UPF->U = (TStNetUserItem*)UL->Objects[UL->IndexOf(LI->Caption)];
|
103 |
if (UPF->ShowModal() == mrOk) {
|
104 |
// update the data
|
105 |
UPF->U->Name = UPF->UserNameEdit->Text;
|
106 |
UPF->U->FullName = UPF->FullNameEdit->Text;
|
107 |
UPF->U->Comment = UPF->CommentEdit->Text;
|
108 |
|
109 |
if ((UPF->Password1Edit->Text != "NO PASSWORD CHANGE"))
|
110 |
UPF->U->Password = UPF->Password1Edit->Text;
|
111 |
|
112 |
LI->Caption = UPF->U->Name;
|
113 |
LI->SubItems->Strings[0] = UPF->U->FullName;
|
114 |
LI->SubItems->Strings[1] = UPF->U->Comment;
|
115 |
}
|
116 |
delete UPF;
|
117 |
} else if (ListView2->Focused() && ListView2->SelCount > 0) {
|
118 |
LI = ListView2->Selected;
|
119 |
TGroupPropertiesForm* GPF = new TGroupPropertiesForm(this);
|
120 |
GPF->G = (TStNetGroupItem*)GL->Objects[GL->IndexOf(LI->Caption)];
|
121 |
if (GPF->ShowModal()) {
|
122 |
// update the data
|
123 |
GPF->G->Name = GPF->GroupNameEdit->Text;
|
124 |
GPF->G->Comment = GPF->CommentEdit->Text;
|
125 |
|
126 |
LI->Caption = GPF->G->Name;
|
127 |
LI->SubItems->Strings[0] = GPF->G->Comment;
|
128 |
}
|
129 |
delete GPF;
|
130 |
}
|
131 |
}
|
132 |
//---------------------------------------------------------------------------
|
133 |
void __fastcall TMainForm::Delete1Click(TObject *Sender)
|
134 |
{
|
135 |
TListItem* LI;
|
136 |
// Are we dealing with a user or group?
|
137 |
if (ListView1->Focused() && ListView1->SelCount > 0) {
|
138 |
LI = ListView1->Selected;
|
139 |
TStNetUserItem* U = (TStNetUserItem*)UL->Objects[UL->IndexOf(LI->Caption)];
|
140 |
|
141 |
if (MessageDlg("Are you sure you want to delete the user - [" + U->Name + "]?",
|
142 |
mtConfirmation, TMsgDlgButtons() << mbYes << mbNo, 0) == mrYes) {
|
143 |
U->Delete();
|
144 |
LI->Delete();
|
145 |
}
|
146 |
} else if (ListView2->Focused() && ListView2->SelCount > 0) {
|
147 |
LI = ListView2->Selected;
|
148 |
TStNetGroupItem* G = (TStNetGroupItem*)GL->Objects[GL->IndexOf(LI->Caption)];
|
149 |
if (MessageDlg("Are you sure you want to delete the group - [" + G->Name + "]?",
|
150 |
mtConfirmation, TMsgDlgButtons() << mbYes << mbNo, 0) == mrYes) {
|
151 |
G->Delete();
|
152 |
LI->Delete();
|
153 |
}
|
154 |
}
|
155 |
}
|
156 |
//---------------------------------------------------------------------------
|
157 |
void __fastcall TMainForm::ListViewKeyDown(TObject *Sender, WORD &Key,
|
158 |
TShiftState Shift)
|
159 |
{
|
160 |
if (Key == VK_RETURN) {
|
161 |
Properties1Click(Sender);
|
162 |
}
|
163 |
}
|
164 |
//---------------------------------------------------------------------------
|
165 |
void __fastcall TMainForm::NewUser1Click(TObject *Sender)
|
166 |
{
|
167 |
if (!CS)
|
168 |
return;
|
169 |
// Create a new user
|
170 |
TNewUserForm* NU = new TNewUserForm(this);
|
171 |
NU->Caption = CS->Name + " - New User Account";
|
172 |
if (NU->ShowModal() == mrOk) {
|
173 |
TStNetUserItem* U = CS->AddUser(NU->UserNameEdit->Text, NU->Password1Edit->Text, true);
|
174 |
U->FullName = NU->FullNameEdit->Text;
|
175 |
U->Comment = NU->CommentEdit->Text;
|
176 |
|
177 |
TListItem* LI = ListView1->Items->Add();
|
178 |
LI->Caption = U->Name;
|
179 |
LI->SubItems->Add(U->FullName);
|
180 |
LI->SubItems->Add(U->Comment);
|
181 |
|
182 |
UL = CS->Users;
|
183 |
}
|
184 |
delete NU;
|
185 |
}
|
186 |
//---------------------------------------------------------------------------
|
187 |
void __fastcall TMainForm::NewGlobalGroup1Click(TObject *Sender)
|
188 |
{
|
189 |
if (!CS)
|
190 |
return;
|
191 |
// Create a new global group
|
192 |
TNewGroupForm* NG = new TNewGroupForm(this);
|
193 |
NG->Caption = CS->Name + " - New Global Group";
|
194 |
if (NG->ShowModal() == mrOk) {
|
195 |
TStNetGroupItem* G = CS->AddGroup(NG->GroupNameEdit->Text, NG->CommentEdit->Text, true);
|
196 |
|
197 |
TListItem* LI = ListView2->Items->Add();
|
198 |
LI->Caption = G->Name;
|
199 |
LI->SubItems->Add(G->Comment);
|
200 |
|
201 |
GL = CS->Groups;
|
202 |
}
|
203 |
delete NG;
|
204 |
}
|
205 |
//---------------------------------------------------------------------------
|
206 |
void __fastcall TMainForm::NewLocalGroup1Click(TObject *Sender)
|
207 |
{
|
208 |
if (!CS)
|
209 |
return;
|
210 |
// create a new local group
|
211 |
TNewGroupForm* NG = new TNewGroupForm(this);
|
212 |
NG->Caption = CS->Name + " - New Local Group";
|
213 |
if (NG->ShowModal() == mrOk) {
|
214 |
TStNetGroupItem* G = CS->AddGroup(NG->GroupNameEdit->Text, NG->CommentEdit->Text, false);
|
215 |
|
216 |
TListItem* LI = ListView2->Items->Add();
|
217 |
LI->Caption = G->Name;
|
218 |
LI->SubItems->Add(G->Comment);
|
219 |
|
220 |
GL = CS->Groups;
|
221 |
}
|
222 |
delete NG;
|
223 |
}
|
224 |
//---------------------------------------------------------------------------
|
225 |
void __fastcall TMainForm::Exit1Click(TObject *Sender)
|
226 |
{
|
227 |
Close();
|
228 |
}
|
229 |
//---------------------------------------------------------------------------
|