forked from bigmacd/trapreceiver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrActions.cpp
More file actions
531 lines (451 loc) · 13.1 KB
/
TrActions.cpp
File metadata and controls
531 lines (451 loc) · 13.1 KB
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
#include "stdafx.h"
#include "TrapRcvr.h"
#include "TrActions.h"
#include "TrActionAdd.h"
#include "Registry.h"
IMPLEMENT_DYNCREATE(TrActions, CPropertyPage)
TrActions::TrActions() : CPropertyPage(TrActions::IDD)
{
//{{AFX_DATA_INIT(TrActions)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
TrActions::~TrActions()
{
}
void TrActions::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(TrActions)
DDX_Control(pDX, IDC_LIST, mList);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(TrActions, CPropertyPage)
//{{AFX_MSG_MAP(TrActions)
ON_NOTIFY(NM_DBLCLK, IDC_LIST, OnDblclkList)
ON_BN_CLICKED(IDC_BUTTONADD, OnButtonadd)
ON_BN_CLICKED(IDC_BUTTONDELETE, OnButtondelete)
ON_BN_CLICKED(IDC_BUTTONMODIFY, OnButtonmodify)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// TrActions message handlers
void TrActions::OnDblclkList(NMHDR* pNMHDR, LRESULT* pResult)
{
UINT nFlags;
CPoint point;
BOOL b = ::GetCursorPos( &point );
mList.ScreenToClient( &point );
int currentIndex = mList.HitTest(point, &nFlags);
if (currentIndex >= 0)
DoModify(currentIndex);
*pResult = 0;
SetFocus();
}
void TrActions::OnButtonadd()
{
TrActionAdd dlg;
int result = dlg.DoModal();
if (result == IDOK)
{
BOOL partOfGroup = dlg.mPartOfGroup;
int col = 0;
LV_ITEM lv;
lv.iItem = mList.GetItemCount();
lv.mask = LVIF_TEXT;
lv.iSubItem = col++;
lv.pszText = dlg.mName.GetBuffer(0);
mList.InsertItem(&lv);
lv.mask = LVIF_TEXT;
lv.iSubItem = col++;
lv.pszText = dlg.mWatchText.GetBuffer(0);
// mList.InsertItem(&lv);
mList.SetItem(&lv);
mList.SetItemData(lv.iItem, dlg.mWatch);
lv.mask = LVIF_TEXT;
lv.iSubItem = col++;
lv.pszText = dlg.mValue.GetBuffer(0);
mList.SetItem(&lv);
if (!partOfGroup) {
// bools
int bools = dlg.mBools;
lv.mask = LVIF_TEXT;
lv.iSubItem = col++;
CString sPort;
sPort.Format("%d", bools);
lv.pszText = sPort.GetBuffer(0);
mList.SetItem(&lv);
lv.mask = LVIF_TEXT;
lv.iSubItem = col++;
lv.pszText = dlg.mExecuteProgram.GetBuffer(0);
mList.SetItem(&lv);
lv.mask = LVIF_TEXT;
lv.iSubItem = col++;
lv.pszText = dlg.mExecuteArgs.GetBuffer(0);
mList.SetItem(&lv);
BOOL itd = dlg.mIncludeTrapData;
lv.mask = LVIF_TEXT;
lv.iSubItem = col++;
CString iTD;
iTD.Format("%d", itd);
lv.pszText = iTD.GetBuffer(0);
mList.SetItem(&lv);
lv.mask = LVIF_TEXT;
lv.iSubItem = col++;
lv.pszText = dlg.mEmailDest.GetBuffer(0);
mList.SetItem(&lv);
iTD.Format("%d", dlg.mSoundPlayDuration);
lv.mask = LVIF_TEXT;
lv.iSubItem = col++;
lv.pszText = iTD.GetBuffer(0);
mList.SetItem(&lv);
lv.mask = LVIF_TEXT;
lv.iSubItem = col++;
lv.pszText = dlg.mSoundFile.GetBuffer(0);
mList.SetItem(&lv);
lv.mask = LVIF_TEXT;
lv.iSubItem = col++;
lv.pszText = dlg.mExploderDest.GetBuffer(0);
mList.SetItem(&lv);
}
if (partOfGroup)
col += 8; // makes up for all those col++ above
BOOL pog = dlg.mPartOfGroup;
lv.mask = LVIF_TEXT;
lv.iSubItem = col++;
CString pOG;
pOG.Format("%d", pog);
lv.pszText = pOG.GetBuffer(0);
mList.SetItem(&lv);
int rd = dlg.mRequireDesktop;
lv.mask = LVIF_TEXT;
lv.iSubItem = col++;
CString iTD;
iTD.Format("%d", rd);
lv.pszText = iTD.GetBuffer(0);
mList.SetItem(&lv);
SetModified(TRUE);
}
SetFocus();
}
void TrActions::OnButtondelete()
{
int currentIndex = GetCurrentIndex();
if (currentIndex >= 0)
{
mList.DeleteItem(currentIndex);
SetModified(TRUE);
}
SetFocus();
}
void TrActions::OnButtonmodify()
{
int currentIndex = GetCurrentIndex();
if (currentIndex >= 0)
DoModify(currentIndex);
SetFocus();
}
BOOL
TrActions::OnInitDialog()
{
CPropertyPage::OnInitDialog();
RECT rect;
mList.GetClientRect(&rect);
// int width = (rect.right / 2);
int width = (rect.right / 3);
int col = 0;
mList.InsertColumn(col++, "Name", LVCFMT_CENTER, width);
mList.InsertColumn(col++, "Watch", LVCFMT_CENTER, width);
mList.InsertColumn(col++, "Value", LVCFMT_CENTER, width);
mList.InsertColumn(col++, "Bools", LVCFMT_CENTER, 0);
mList.InsertColumn(col++, "Execute", LVCFMT_CENTER, 0);
mList.InsertColumn(col++, "Args", LVCFMT_CENTER, 0);
mList.InsertColumn(col++, "td", LVCFMT_CENTER, 0);
mList.InsertColumn(col++, "emaildests", LVCFMT_CENTER, 0);
mList.InsertColumn(col++, "soundDuration", LVCFMT_CENTER, 0);
mList.InsertColumn(col++, "soundFile", LVCFMT_CENTER, 0);
mList.InsertColumn(col++, "exploderdests", LVCFMT_CENTER, 0);
mList.InsertColumn(col++, "partofgroup", LVCFMT_CENTER, 0);
mList.InsertColumn(col++, "requireDesktop", LVCFMT_CENTER, 0);
Registry registry("Actions");
int count = (int)registry.getCount();
LV_ITEM lv;
CString data;
try
{
for (int listLength = 0; listLength < count; listLength++)
{
registry.ReOpen(listLength);
lv.iItem = listLength;
data = registry.name();
col = 0;
lv.mask = LVIF_TEXT;
lv.iSubItem = col++;
lv.pszText = data.GetBuffer(0);
mList.InsertItem(&lv);
int w = registry.watch();
lv.mask = LVIF_TEXT;
lv.iSubItem = col++;
switch (w)
{
case COMMUNITY:
data = "Community";
break;
case GENERIC:
data = "Generic Type";
break;
case SENDERIP:
data = "Sender IP";
break;
case SENDEROID:
data = "Sender OID";
break;
case SPECIFIC:
data = "Specific Type";
break;
case VARBINDOID:
data = "Varbind OID";
break;
case VARBINDVALUE:
data = "Varbind Value";
break;
}
lv.pszText = data.GetBuffer(0);
//mList.InsertItem(&lv);
mList.SetItem(&lv);
mList.SetItemData(listLength, w);
data = registry.value();
lv.mask = LVIF_TEXT;
lv.iSubItem = col++;
lv.pszText = data.GetBuffer(0);
mList.SetItem(&lv);
data.Format("%d", registry.bools());
lv.mask = LVIF_TEXT;
lv.iSubItem = col++;
lv.pszText = data.GetBuffer(0);
mList.SetItem(&lv);
data = registry.executable();
lv.mask = LVIF_TEXT;
lv.iSubItem = col++;
lv.pszText = data.GetBuffer(0);
mList.SetItem(&lv);
data = registry.arguments();
lv.mask = LVIF_TEXT;
lv.iSubItem = col++;
lv.pszText = data.GetBuffer(0);
mList.SetItem(&lv);
data.Format("%d", registry.includeTrapData());
lv.mask = LVIF_TEXT;
lv.iSubItem = col++;
lv.pszText = data.GetBuffer(0);
mList.SetItem(&lv);
data = registry.emailRecipients();
lv.mask = LVIF_TEXT;
lv.iSubItem = col++;
lv.pszText = data.GetBuffer(0);
mList.SetItem(&lv);
data.Format("%d", registry.soundPlayDuration());
lv.mask = LVIF_TEXT;
lv.iSubItem = col++;
lv.pszText = data.GetBuffer(0);
mList.SetItem(&lv);
data = registry.soundFile();
lv.mask = LVIF_TEXT;
lv.iSubItem = col++;
lv.pszText = data.GetBuffer(0);
mList.SetItem(&lv);
data = registry.exploderDestinations();
lv.mask = LVIF_TEXT;
lv.iSubItem = col++;
lv.pszText = data.GetBuffer(0);
mList.SetItem(&lv);
data.Format("%d", registry.partOfGroup());
lv.mask = LVIF_TEXT;
lv.iSubItem = col++;
lv.pszText = data.GetBuffer(0);
mList.SetItem(&lv);
int runfrom = 1; // default all to gui
try { runfrom = registry.runFrom(); } catch (...) { registry.runFrom(runfrom); }
data.Format("%d", runfrom);
lv.mask = LVIF_TEXT;
lv.iSubItem = col++;
lv.pszText = data.GetBuffer(0);
mList.SetItem(&lv);
}
}
catch(...)
{
}
return TRUE;
}
int
TrActions::GetCurrentIndex()
{
int count = mList.GetItemCount();
int x;
for (x = 0; x < count; x++)
{
if (mList.GetItemState(x, LVIS_SELECTED) == LVIS_SELECTED)
break;
}
if (x == count)
return -1;
else
return x;
}
void
TrActions::DoModify(int currentIndex)
{
// get the item data
int index = 0; // !! must be zero when adding groups
CString name = mList.GetItemText(currentIndex, index++);
int watch = mList.GetItemData(currentIndex); index++;
CString value = mList.GetItemText(currentIndex, index++);
CString bools = mList.GetItemText(currentIndex, index++);
CString execute = mList.GetItemText(currentIndex, index++);
CString args = mList.GetItemText(currentIndex, index++);
CString iTD = mList.GetItemText(currentIndex, index++);
CString emailDests = mList.GetItemText(currentIndex, index++);
int soundPlayDuration = atoi(mList.GetItemText(currentIndex, index++));
CString soundFile = mList.GetItemText(currentIndex, index++);
CString exploderDests = mList.GetItemText(currentIndex, index++);
BOOL partOfGroup = (BOOL)atoi(mList.GetItemText(currentIndex, index++));
int requireDesktop = atoi(mList.GetItemText(currentIndex, index++));
// pass it to the dlg
TrActionAdd dlg(name,
watch,
value,
atoi(bools.GetBuffer(0)),
execute,
args,
(BOOL)atoi(iTD.GetBuffer(0)),
emailDests,
exploderDests,
soundPlayDuration,
soundFile,
partOfGroup,
requireDesktop);
int result = dlg.DoModal();
if (result == IDOK)
{
index = 0;
LV_ITEM lv;
lv.iItem = currentIndex;
lv.mask = LVIF_TEXT;
lv.iSubItem = index++;
lv.pszText = dlg.mName.GetBuffer(0);
mList.SetItem(&lv);
lv.mask = LVIF_TEXT;
lv.iSubItem = index++;
lv.pszText = dlg.mWatchText.GetBuffer(0);
mList.SetItem(&lv);
mList.SetItemData(currentIndex, dlg.mWatch);
lv.mask = LVIF_TEXT;
lv.iSubItem = index++;
lv.pszText = dlg.mValue.GetBuffer(0);
mList.SetItem(&lv);
// bools
int bools = dlg.mBools;
lv.mask = LVIF_TEXT;
lv.iSubItem = index++;
CString sPort;
sPort.Format("%d", bools);
lv.pszText = sPort.GetBuffer(0);
mList.SetItem(&lv);
lv.mask = LVIF_TEXT;
lv.iSubItem = index++;
lv.pszText = dlg.mExecuteProgram.GetBuffer(0);
mList.SetItem(&lv);
lv.mask = LVIF_TEXT;
lv.iSubItem = index++;
lv.pszText = dlg.mExecuteArgs.GetBuffer(0);
mList.SetItem(&lv);
BOOL itd = dlg.mIncludeTrapData;
lv.mask = LVIF_TEXT;
lv.iSubItem = index++;
CString iTD;
iTD.Format("%d", itd);
lv.pszText = iTD.GetBuffer(0);
mList.SetItem(&lv);
lv.mask = LVIF_TEXT;
lv.iSubItem = index++;
lv.pszText = dlg.mEmailDest.GetBuffer(0);
mList.SetItem(&lv);
iTD.Format("%d", dlg.mSoundPlayDuration);
lv.mask = LVIF_TEXT;
lv.iSubItem = index++;
lv.pszText = iTD.GetBuffer(0);
mList.SetItem(&lv);
lv.mask = LVIF_TEXT;
lv.iSubItem = index++;
lv.pszText = dlg.mSoundFile.GetBuffer(0);
mList.SetItem(&lv);
lv.mask = LVIF_TEXT;
lv.iSubItem = index++;
lv.pszText = dlg.mExploderDest.GetBuffer(0);
mList.SetItem(&lv);
BOOL pog = dlg.mPartOfGroup;
lv.mask = LVIF_TEXT;
lv.iSubItem = index++;
CString pOG;
pOG.Format("%d", pog);
lv.pszText = pOG.GetBuffer(0);
mList.SetItem(&lv);
int rd = dlg.mRequireDesktop;
lv.mask = LVIF_TEXT;
lv.iSubItem = index++;
iTD.Format("%d", rd);
lv.pszText = iTD.GetBuffer(0);
mList.SetItem(&lv);
SetModified(TRUE);
}
}
BOOL TrActions::OnApply()
{
try
{
Registry registry("Actions");
unsigned long count = registry.getCount();
// for (unsigned long x = 0; x < count; x++)
// registry.deleteAction(x);
registry.deleteActions();
int listCount = mList.GetItemCount();
for (int regX = 0; regX < listCount; regX++)
{
//int index = 1;
int index = 0; // !! needs to be 0 for groups
CString name = mList.GetItemText(regX, index++);
int watch = mList.GetItemData(regX); index++;
CString value = mList.GetItemText(regX, index++);
CString bools = mList.GetItemText(regX, index++);
CString exe = mList.GetItemText(regX, index++);
CString args = mList.GetItemText(regX, index++);
CString iTD = mList.GetItemText(regX, index++);
CString emailDests = mList.GetItemText(regX, index++);
int soundDuration = atoi(mList.GetItemText(regX, index++));
CString soundFile = mList.GetItemText(regX, index++);
CString exploderDests = mList.GetItemText(regX, index++);
BOOL partOfGroup = (BOOL)atoi(mList.GetItemText(regX, index++));
int requireDesktop = atoi(mList.GetItemText(regX, index++));
// change for groups in 7.47
// registry.insertAction(watch,
registry.insertAction(name,
watch,
value,
atoi(bools.GetBuffer(0)),
exe,
args,
atoi(iTD.GetBuffer(0)),
emailDests,
exploderDests,
soundDuration,
soundFile,
partOfGroup,
requireDesktop);
}
}
catch(...)
{
}
return CPropertyPage::OnApply();
}