-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtnodefunc.h
2091 lines (1899 loc) · 67.7 KB
/
tnodefunc.h
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
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
FILE
tnodefunc.h
PURPOSE
tNode aux functions.
AUTHOR/LEGAL
(C) 2001-2017 Gary Wallis for Unixservice, LLC. GPLv2 license applies.
*/
static unsigned uClone=0;
static unsigned uTargetNode=0;
static char cuTargetNodePullDown[256]={""};
static unsigned uWizIPv4=0;
static char cuWizIPv4PullDown[32]={""};
static char cSearch[32]={""};
static unsigned uTargetDatacenter=0;
static char cuTargetDatacenterPullDown[256]={""};
static unsigned uCloneStop=WARM_CLONE;
static unsigned uSyncPeriod=0;
//ModuleFunctionProtos()
void CopyProperties(unsigned uOldNode,unsigned uNewNode,unsigned uType);
void DelProperties(unsigned uNode,unsigned uType);
void tNodeNavList(unsigned uDataCenter);
void tContainerNavList(unsigned uNode, char *cSearch);//tcontainerfunc.h
void htmlGroups(unsigned uNode, unsigned uContainer);
unsigned FailoverCloneContainer(unsigned uDatacenter, unsigned uNode, unsigned uContainer, unsigned uSource,
unsigned uSourceNode, unsigned uSourceDatacenter, unsigned uIPv4, unsigned uStatus,
char *cLabel, char *cHostname,unsigned uOwner,unsigned uDebug);
unsigned CloneNode(unsigned uSourceNode,unsigned uTargetNode,unsigned uWizIPv4,const char *cuWizIPv4PullDown,
unsigned uSyncPeriod,unsigned uCloneStop,unsigned uTargetDatacenter);
void SetNodeProp(char const *cName,char const *cValue,unsigned uNode);
unsigned ConnectToOptionalUBCDb(unsigned uDatacenter,unsigned uPrivate);
void tNodeHealth(void);
//external
//tcontainerfunc.h
void htmlHealth(unsigned uElement,unsigned uDatacenter,unsigned uType);
//void htmlNodeHealth(unsigned uNode);
char *cRatioColor(float *fRatio);
void SetContainerStatus(unsigned uContainer,unsigned uStatus);
unsigned FailoverToJob(unsigned uDatacenter, unsigned uNode, unsigned uContainer,unsigned uOwner,unsigned uLoginClient,unsigned uDebug);
unsigned FailoverFromJob(unsigned uDatacenter,unsigned uNode,unsigned uContainer,
unsigned uIPv4,char *cLabel,char *cHostname,unsigned uSource,
unsigned uStatus,unsigned uFailToJob,unsigned uOwner,unsigned uLoginClient,unsigned uDebug);
//tcontainer.c
void tTablePullDownAvail(const char *cTableName, const char *cFieldName,
const char *cOrderby, unsigned uSelector, unsigned uMode);
//tclientfunc.h
static unsigned uForClient=0;
static char cForClientPullDown[256]={"---"};
void ExtProcesstNodeVars(pentry entries[], int x)
{
register int i;
for(i=0;i<x;i++)
{
if(!strcmp(entries[i].name,"cSearch"))
sprintf(cSearch,"%.31s",TextAreaSave(entries[i].val));
else if(!strcmp(entries[i].name,"cForClientPullDown"))
{
strcpy(cForClientPullDown,entries[i].val);
uForClient=ReadPullDown(TCLIENT,"cLabel",cForClientPullDown);
}
else if(!strcmp(entries[i].name,"uClone"))
uClone=1;
else if(!strcmp(entries[i].name,"cuTargetNodePullDown"))
{
sprintf(cuTargetNodePullDown,"%.255s",entries[i].val);
uTargetNode=ReadPullDown("tNode","cLabel",cuTargetNodePullDown);
}
else if(!strcmp(entries[i].name,"cuWizIPv4PullDown"))
{
sprintf(cuWizIPv4PullDown,"%.31s",entries[i].val);
uWizIPv4=ReadPullDown("tIP","cLabel",cuWizIPv4PullDown);
}
else if(!strcmp(entries[i].name,"cuTargetDatacenterPullDown"))
{
sprintf(cuTargetDatacenterPullDown,"%.255s",entries[i].val);
uTargetDatacenter=ReadPullDown("tDatacenter","cLabel",cuTargetDatacenterPullDown);
}
else if(!strcmp(entries[i].name,"uCloneStop"))
sscanf(entries[i].val,"%u",&uCloneStop);
else if(!strcmp(entries[i].name,"uSyncPeriod"))
sscanf(entries[i].val,"%u",&uSyncPeriod);
else if(!strcmp(entries[i].name,"cVendor"))
sprintf(cVendor,"%.32s",TextAreaSave(entries[i].val));
else if(!strcmp(entries[i].name,"cIPMIIPv4"))
sprintf(cIPMIIPv4,"%.32s",TextAreaSave(entries[i].val));
else if(!strcmp(entries[i].name,"cIPMIPasswd"))
sprintf(cIPMIPasswd,"%.32s",TextAreaSave(entries[i].val));
else if(!strcmp(entries[i].name,"cPurchaseOrder"))
sprintf(cPurchaseOrder,"%.64s",TextAreaSave(entries[i].val));
else if(!strcmp(entries[i].name,"cMACeth0"))
sprintf(cMACeth0,"%.32s",TextAreaSave(entries[i].val));
else if(!strcmp(entries[i].name,"cMACeth1"))
sprintf(cMACeth1,"%.32s",TextAreaSave(entries[i].val));
else if(!strcmp(entries[i].name,"cOtherName"))
sprintf(cOtherName,"%.32s",TextAreaSave(entries[i].val));
else if(!strcmp(entries[i].name,"cProcCPUInfo"))
sprintf(cProcCPUInfo,"%.32s",TextAreaSave(entries[i].val));
else if(!strcmp(entries[i].name,"uMaxCloneContainers"))
{
sscanf(entries[i].val,"%u",&uMaxCloneContainers);
sprintf(cuMaxCloneContainers,"%u",uMaxCloneContainers);
}
else if(!strcmp(entries[i].name,"uMaxContainers"))
{
sscanf(entries[i].val,"%u",&uMaxContainers);
sprintf(cuMaxContainers,"%u",uMaxContainers);
}
else if(!strcmp(entries[i].name,"cNewContainerMode"))
sprintf(cNewContainerMode,"%.32s",TextAreaSave(entries[i].val));
else if(!strcmp(entries[i].name,"luInstalledRam"))
{
sscanf(entries[i].val,"%lu",&luInstalledRam);
sprintf(cluInstalledRam,"%lu",luInstalledRam);
}
else if(!strcmp(entries[i].name,"luInstalledDiskSpace"))
{
sscanf(entries[i].val,"%lu",&luInstalledDiskSpace);
sprintf(cluInstalledDiskSpace,"%lu",luInstalledDiskSpace);
}
}
}//void ExtProcesstNodeVars(pentry entries[], int x)
void ExttNodeCommands(pentry entries[], int x)
{
if(!strcmp(gcFunction,"tNodeTools"))
{
MYSQL_RES *res;
time_t uActualModDate= -1;
if(!strcmp(gcCommand,LANG_NB_NEW))
{
if(guPermLevel>=9)
{
ProcesstNodeVars(entries,x);
guMode=2000;
tNode(LANG_NB_CONFIRMNEW);
}
}
else if(!strcmp(gcCommand,LANG_NB_CONFIRMNEW))
{
if(guPermLevel>=9)
{
ProcesstNodeVars(entries,x);
unsigned uOldNode=uNode;
guMode=2000;
//Check entries here
if(strlen(cLabel)<3)
tNode("<strong>Error</strong>: Must supply valid cLabel. Min 3 chars!");
if(!uDatacenter)
tNode("<strong>Error</strong>: Must supply valid uDatacenter!");
sprintf(gcQuery,"SELECT uNode FROM tNode WHERE cLabel='%s'",
cLabel);
mysql_query(&gMysql,gcQuery);
if(mysql_errno(&gMysql))
htmlPlainTextError(mysql_error(&gMysql));
res=mysql_store_result(&gMysql);
if(mysql_num_rows(res))
{
mysql_free_result(res);
tNode("<strong>Error</strong>: Node cLabel is used!");
}
guMode=0;
if(!uForClient)
uOwner=guCompany;
else
uOwner=uForClient;
uNode=0;
uCreatedBy=guLoginClient;
uStatus=1;//Initially active
uModBy=0;//Never modified
uModDate=0;//Never modified
NewtNode(1);//Come back here uNode should be set
if(!uNode)
tNode("<strong>Error</strong>: New node was not created!");
sprintf(gcQuery,"INSERT INTO tProperty SET uKey=%u,uType=2"
",cName='Name',cValue='%s',uOwner=%u,uCreatedBy=%u"
",uCreatedDate=UNIX_TIMESTAMP(NOW())"
,uNode,cLabel,guCompany,guLoginClient);
mysql_query(&gMysql,gcQuery);
if(mysql_errno(&gMysql))
htmlPlainTextError(mysql_error(&gMysql));
if(uNode && uClone && uOldNode)
{
CopyProperties(uOldNode,uNode,2);
tNode("New node created and properties copied");
}
tNode("New node created");
}
}
else if(!strcmp(gcCommand,LANG_NB_DELETE))
{
ProcesstNodeVars(entries,x);
if(uAllowDel(uOwner,uCreatedBy))
{
guMode=0;
sprintf(gcQuery,"SELECT uNode FROM tContainer WHERE uNode=%u",
uNode);
mysql_query(&gMysql,gcQuery);
if(mysql_errno(&gMysql))
htmlPlainTextError(mysql_error(&gMysql));
res=mysql_store_result(&gMysql);
if(mysql_num_rows(res))
{
mysql_free_result(res);
tNode("<strong>Error</strong>: Can't delete a node"
" used by a container!");
}
guMode=2001;
tNode(LANG_NB_CONFIRMDEL);
}
else
tNode("<strong>Error</strong>: Denied by permissions settings");
}
else if(!strcmp(gcCommand,LANG_NB_CONFIRMDEL))
{
ProcesstNodeVars(entries,x);
if(uAllowDel(uOwner,uCreatedBy))
{
guMode=5;
sscanf(ForeignKey("tNode","uModDate",uNode),"%lu",&uActualModDate);
if(uModDate!=uActualModDate)
tNode("<strong>Error</strong>: This record was modified. Reload it.");
sprintf(gcQuery,"SELECT uNode FROM tContainer WHERE uNode=%u",
uNode);
mysql_query(&gMysql,gcQuery);
if(mysql_errno(&gMysql))
htmlPlainTextError(mysql_error(&gMysql));
res=mysql_store_result(&gMysql);
if(mysql_num_rows(res))
{
mysql_free_result(res);
tNode("<strong>Error</strong>: Can't delete a node"
" used by a container!");
}
guMode=0;
DelProperties(uNode,2);
DeletetNode();
}
else
tNode("<strong>Error</strong>: Denied by permissions settings");
}
else if(!strcmp(gcCommand,LANG_NB_MODIFY))
{
ProcesstNodeVars(entries,x);
if(uAllowMod(uOwner,uCreatedBy))
{
guMode=2002;
tNode(LANG_NB_CONFIRMMOD);
}
else
tNode("<strong>Error</strong>: Denied by permissions settings");
}
else if(!strcmp(gcCommand,LANG_NB_CONFIRMMOD))
{
ProcesstNodeVars(entries,x);
if(uAllowMod(uOwner,uCreatedBy))
{
guMode=2002;
sscanf(ForeignKey("tNode","uModDate",uNode),"%lu",&uActualModDate);
if(uModDate!=uActualModDate)
tNode("<strong>Error</strong>: This record was modified. Reload it.");
if(strlen(cLabel)<3)
tNode("<strong>Error</strong>: Must supply valid cLabel. Min 3 chars!");
if(!uDatacenter)
tNode("<strong>Error</strong>: Must supply valid uDatacenter!");
guMode=0;
if(uForClient)
{
sprintf(gcQuery,"UPDATE tNode SET uOwner=%u WHERE uNode=%u",
uForClient,uNode);
mysql_query(&gMysql,gcQuery);
if(mysql_errno(&gMysql))
htmlPlainTextError(mysql_error(&gMysql));
uOwner=uForClient;
}
uModBy=guLoginClient;
ModtNode();
}
else
tNode("<strong>Error</strong>: Denied by permissions settings");
}
else if(!strcmp(gcCommand,"Node Offline"))
{
ProcesstNodeVars(entries,x);
if(uStatus==1 && uAllowMod(uOwner,uCreatedBy) && guPermLevel>11)
{
guMode=0;
sscanf(ForeignKey("tNode","uModDate",uNode),"%lu",&uActualModDate);
if(uModDate!=uActualModDate)
tNode("<strong>Error</strong>: This record was modified. Reload it.");
sprintf(gcQuery,"UPDATE tNode SET uStatus=%u WHERE uNode=%u",
uOFFLINE,uNode);
mysql_query(&gMysql,gcQuery);
if(mysql_errno(&gMysql))
htmlPlainTextError(mysql_error(&gMysql));
uStatus=uOFFLINE;
ModtNode();
}
else if(uAllowMod(uOwner,uCreatedBy))
{
tNode("<strong>Error</strong>: Denied by node status");
}
else
{
tNode("<strong>Error</strong>: Denied by permissions settings");
}
}
else if(!strcmp(gcCommand,"Node Online"))
{
ProcesstNodeVars(entries,x);
if(uStatus==uOFFLINE && uAllowMod(uOwner,uCreatedBy) && guPermLevel>11)
{
guMode=0;
sscanf(ForeignKey("tNode","uModDate",uNode),"%lu",&uActualModDate);
if(uModDate!=uActualModDate)
tNode("<strong>Error</strong>: This record was modified. Reload it.");
sprintf(gcQuery,"UPDATE tNode SET uStatus=%u WHERE uNode=%u",
uACTIVE,uNode);
mysql_query(&gMysql,gcQuery);
if(mysql_errno(&gMysql))
htmlPlainTextError(mysql_error(&gMysql));
uStatus=uACTIVE;
ModtNode();
}
else if(uAllowMod(uOwner,uCreatedBy))
{
tNode("<strong>Error</strong>: Denied by node status");
}
else
{
tNode("<strong>Error</strong>: Denied by permissions settings");
}
}
else if(!strcmp(gcCommand,"Node Container Report"))
{
ProcesstNodeVars(entries,x);
if(uStatus==1 && uAllowMod(uOwner,uCreatedBy))
{
guMode=0;
sscanf(ForeignKey("tNode","uModDate",uNode),"%lu",&uActualModDate);
if(uModDate!=uActualModDate)
tNode("<strong>Error</strong>: This record was modified. Reload it.");
guMode=9001;
tNode("");
}
else if(uAllowMod(uOwner,uCreatedBy))
{
tNode("<strong>Error</strong>: Denied by node status");
}
else
{
tNode("<strong>Error</strong>: Denied by permissions settings");
}
}
else if(!strcmp(gcCommand,"Hardware Information"))
{
ProcesstNodeVars(entries,x);
if(uAllowMod(uOwner,uCreatedBy) || guPermLevel>=6)
{
guMode=10000;
tNode("Hardware inventory information");
}
else
{
tNode("<strong>Error</strong>: Denied by permissions settings");
}
}
else if(!strcmp(gcCommand,"Save Hardware Information"))
{
ProcesstNodeVars(entries,x);
if(uAllowMod(uOwner,uCreatedBy) || guPermLevel>=6)
{
guMode=10000;
//check
if(!uNode)
tNode("uNode not specified");
if(!cVendor[0])
tNode("cVendor not specified");
if(!cIPMIPasswd[0])
tNode("cIPMIPasswd not specified");
if(!cIPMIIPv4[0])
tNode("cIPMIIPv4 not specified");
if(!cPurchaseOrder[0])
tNode("cPurchaseOrder not specified");
if(!cProcCPUInfo[0])
tNode("cProcCPUInfo not specified");
if(!cMACeth0[0])
tNode("cMACeth0 not specified");
if(!cMACeth1[0])
tNode("cMACeth1 not specified");
if(!cluInstalledDiskSpace[0])
tNode("cluInstalledDiskSpace not specified");
if(!cluInstalledRam[0])
tNode("cluInstalledRam not specified");
if(!cuMaxContainers[0])
tNode("cuMaxContainers not specified");
if(!cNewContainerMode[0])
tNode("cNewContainerMode not specified");
SetNodeProp("cVendor",cVendor,uNode);
SetNodeProp("cIPMIPasswd",cIPMIPasswd,uNode);
SetNodeProp("cIPMIIPv4",cIPMIIPv4,uNode);
SetNodeProp("cPurchaseOrder",cPurchaseOrder,uNode);
SetNodeProp("cProcCPUInfo",cProcCPUInfo,uNode);
SetNodeProp("cMACeth0",cMACeth0,uNode);
SetNodeProp("cMACeth1",cMACeth1,uNode);
SetNodeProp("cOtherName",cOtherName,uNode);
SetNodeProp("luInstalledDiskSpace",cluInstalledDiskSpace,uNode);
SetNodeProp("luInstalledRam",cluInstalledRam,uNode);
SetNodeProp("MaxCloneContainers",cuMaxCloneContainers,uNode);
SetNodeProp("MaxContainers",cuMaxContainers,uNode);
SetNodeProp("NewContainerMode",cNewContainerMode,uNode);
guMode=10001;
tNode("Hardware inventory information saved");
}
else
{
tNode("<strong>Error</strong>: Denied by permissions settings");
}
}
else if(!strcmp(gcCommand,"Clone Node Wizard"))
{
ProcesstNodeVars(entries,x);
if(uStatus==1 && uAllowMod(uOwner,uCreatedBy))
{
guMode=0;
sscanf(ForeignKey("tNode","uModDate",uNode),"%lu",&uActualModDate);
if(uModDate!=uActualModDate)
tNode("<strong>Error</strong>: This record was modified. Reload it.");
guMode=7001;
tNode("Select datacenter");
}
else if(uAllowMod(uOwner,uCreatedBy))
{
tNode("<strong>Error</strong>: Denied by node status");
}
else
{
tNode("<strong>Error</strong>: Denied by permissions settings");
}
}
else if(!strcmp(gcCommand,"Select Clone Datacenter"))
{
ProcesstNodeVars(entries,x);
if(uStatus==1 && uAllowMod(uOwner,uCreatedBy))
{
guMode=0;
sscanf(ForeignKey("tNode","uModDate",uNode),"%lu",&uActualModDate);
if(uModDate!=uActualModDate)
tNode("<strong>Error</strong>: This record was modified. Reload it.");
guMode=7001;
if(!uTargetDatacenter)
tNode("<strong>Error:</strong> You must select a datacenter");
guMode=7002;
tNode("Select node, uIPv4 and more");
}
else if(uAllowMod(uOwner,uCreatedBy))
{
tNode("<strong>Error</strong>: Denied by node status");
}
else
{
tNode("<strong>Error</strong>: Denied by permissions settings");
}
}
else if(!strcmp(gcCommand,"Confirm Node Clone"))
{
ProcesstNodeVars(entries,x);
if(uStatus==1 && uAllowMod(uOwner,uCreatedBy))
{
char cTargetNodeIPv4[32]={""};
unsigned uRetVal=0;
unsigned uIPv4Datacenter=0;
guMode=0;
sscanf(ForeignKey("tNode","uModDate",uNode),"%lu",&uActualModDate);
if(uModDate!=uActualModDate)
tNode("<strong>Error</strong>: This record was modified. Reload it.");
guMode=7002;
//tNode("Function not available. Try again later");
if(!uWizIPv4)
tNode("<strong>Error</strong>: You must select a start IP!");
if(uTargetNode==0)
tNode("<strong>Error</strong>: Please select a valid target node!");
if(uTargetNode==uNode)
tNode("<strong>Error</strong>: Can't clone to same node!");
GetNodeProp(uTargetNode,"cIPv4",cTargetNodeIPv4);
if(!cTargetNodeIPv4[0])
tNode("<strong>Error</strong>: Your target node is"
" missing it's cIPv4 property!");
if(uCloneStop>COLD_CLONE || uCloneStop<HOT_CLONE)
tNode("<strong>Error:</strong> Unexpected initial state");
sscanf(ForeignKey("tIP","uDatacenter",uWizIPv4),"%u",&uIPv4Datacenter);
if(uTargetDatacenter!=uIPv4Datacenter)
tNode("<strong>Error:</strong> The specified target uIPv4 does not "
"belong to the specified uDatacenter.");
if(!uDatacenter || !uTargetDatacenter )
tNode("<strong>Error:</strong> Unexpected problem with missing source node"
" settings!");
if(uSyncPeriod>86400*30 || (uSyncPeriod && uSyncPeriod<300))
tNode("<strong>Error:</strong> Clone uSyncPeriod seconds out of range:"
" Max 30 days, min 5 minutes or 0 off.");
guMode=0;
uRetVal=CloneNode(uNode,uTargetNode,uWizIPv4,cuWizIPv4PullDown,uSyncPeriod,uCloneStop,
uTargetDatacenter);
if(uRetVal==5)
tNode("<strong>Operation not completed</strong>: Not enough IPs are available");
else if(uRetVal==2)
tNode("<strong>Error</strong>: Unexpected CommonCloneContainer() error! Check tJob");
else if(uRetVal)
tNode("<strong>Error</strong>: Unexpected CloneNode() error! Check tJob");
else if(!uRetVal)
tNode("Clone node container jobs created");
}
}
else if(!strcmp(gcCommand,"Failover Node Wizard"))
{
ProcesstNodeVars(entries,x);
if(uStatus==1 && uAllowMod(uOwner,uCreatedBy))
{
guMode=0;
sscanf(ForeignKey("tNode","uModDate",uNode),"%lu",&uActualModDate);
if(uModDate!=uActualModDate)
tNode("<strong>Error</strong>: This record was modified. Reload it.");
guMode=8001;
tNode("Candiate failover jobs listed below, double check.");
}
else
{
tNode("<strong>Error</strong>: Denied by permissions settings");
}
}
else if(!strcmp(gcCommand,"Confirm Node Failover"))
{
ProcesstNodeVars(entries,x);
if(uStatus==1 && uAllowMod(uOwner,uCreatedBy))
{
guMode=0;
sscanf(ForeignKey("tNode","uModDate",uNode),"%lu",&uActualModDate);
if(uModDate!=uActualModDate)
tNode("<strong>Error</strong>: This record was modified. Reload it.");
guMode=8002;
tNode("For failover jobs created see clone panel below");
}
}
}
}//void ExttNodeCommands(pentry entries[], int x)
void ExttNodeButtons(void)
{
switch(guMode)
{
//Hardware Information
case 10000:
case 10001:
OpenFieldSet("tNode Hardware Panel",100);
if(cLabel[0] && uNode)
printf("Back to tNode <a href=unxsVZ.cgi?gcFunction=tNode"
"&uNode=%u>%s</a><br>\n",uNode,cLabel);
printf("<p><u>Hardare Inventory Operations</u><br>");
printf("<p><input title='Commit hardware data database'"
" type=submit class=largeButton"
" name=gcCommand value='Save Hardware Information'>\n");
printf("<br><input type=submit class=largeButton title='Hardware inventory information and data entry for selected node.'"
" name=gcCommand value='Hardware Information'>");
break;
case 9001:
OpenFieldSet("tNode Aux Panel",100);
printf("<p><u>Node Container Report</u><br>");
printf("See bottom panel.");
break;
case 7001:
OpenFieldSet("tNode Aux Panel",100);
printf("<p><u>Node Clone Wizard (Step 1/2)</u><br>");
printf("Here you will select the datacenter. If it is oversubscribed or not"
" configured for use, or otherwise unavailable you will have to select another.");
printf("<p>Select datacenter<br>");
tTablePullDown("tDatacenter;cuTargetDatacenterPullDown","cLabel","cLabel",uTargetDatacenter,1);
printf("<p><input title='Step one of remote clone wizard'"
" type=submit class=largeButton"
" name=gcCommand value='Select Clone Datacenter'>\n");
break;
case 7002:
OpenFieldSet("tNode Aux Panel",100);
printf("<p><u>Node Clone Wizard (Step 2/2)</u><br>");
printf("Here you will select the hardware node target. If the selected node is"
" oversubscribed, not available, or scheduled for maintenance. You will"
" be informed at the next step.\n<p>\n"
"You must also select a start uIPv4 for the cloned containers, and set the initial"
" state of the clone."
" Usually clones should be kept stopped to conserve resources and facilitate rsync."
" Use the checkbox to change this default behavior."
" Any mount/umount files of the source container will NOT be used"
" by the new cloned container. This issue will be left for manual"
" or automated failover to the cloned container.<p>If you wish to"
" keep the source and clone container sync'd you can specify a non zero"
" value via the 'cuSyncPeriod' entry below.");
printf("<p>Selected datacenter<br>");
tTablePullDown("tDatacenter;cuTargetDatacenterPullDown","cLabel","cLabel",uTargetDatacenter,0);
printf("<p>Select target node<br>");
tTablePullDownDatacenter("tNode;cuTargetNodePullDown","cLabel","cLabel",uTargetNode,1,
cuTargetNodePullDown,0,uTargetDatacenter,0);//0 does not use tProperty, uses uDatacenter
printf("<p>Select start uIPv4<br>");
tTablePullDownOwnerAvailDatacenter("tIP;cuWizIPv4PullDown","cLabel","cLabel",uWizIPv4,1,
uTargetDatacenter,uOwner);
printf("<p>Select clone state<br>");
printf("<input type=radio name=uCloneStop value=%u",WARM_CLONE);
if(uCloneStop==WARM_CLONE)
printf(" checked");
printf("> Stopped/Warm");
printf("<input type=radio name=uCloneStop value=%u",COLD_CLONE);
if(uCloneStop==COLD_CLONE)
printf(" checked");
printf("> Initial Setup/Cold");
printf("<input type=radio name=uCloneStop value=%u",HOT_CLONE);
if(uCloneStop==HOT_CLONE)
printf(" checked");
printf("> Active/Hot");
printf("<p>cuSyncPeriod<br>");
printf("<input title='Keep clone in sync every cuSyncPeriod seconds"
". You can change this at any time via the property panel.'"
" type=text size=10 maxlength=7"
" name=uSyncPeriod value='%u'>\n",uSyncPeriod);
printf("<p>Optional primary group change<br>");
printf("<p><input title='Create a clone job for the current container'"
" type=submit class=largeButton"
" name=gcCommand value='Confirm Node Clone'>\n");
break;
case 8001:
OpenFieldSet("tNode Aux Panel",100);
printf("<p><u>Failover Node Wizard</u><br>");
printf("The current node should be down (or offline.)"
" Other nodes should have \"-clone\" (uSource!=0) containers that have been kept updated."
" The candidate containers are presented below for your approval.<p>");
printf("<p><input title='Create failover jobs for all the current node`s master containers"
" and for other node`s corresponding clone container`s'"
" type=submit class=lwarnButton"
" name=gcCommand value='Confirm Node Failover'>\n");
break;
case 8002:
OpenFieldSet("tNode Aux Panel",100);
printf("<p><u>Failover Node Wizard</u><br>");
printf("Failover jobs have been attempted to be created see panel below for results."
" See <a href=unxsVZ.cgi?gcFunction=tJob>tJob</a> for details.<p>");
break;
case 2000:
OpenFieldSet("tNode Aux Panel",100);
printf("<p><u>Enter/mod data</u><br>");
printf(LANG_NBB_CONFIRMNEW);
if(uNode)
printf("<p><input title='Copies all properties'"
" type=checkbox name=uClone checked> Copy properties from property panel below.\n");
if(guPermLevel>11)
tTablePullDownResellers(uForClient,1);
break;
case 2001:
OpenFieldSet("tNode Aux Panel",100);
printf("<p><u>Think twice</u><br>");
printf(LANG_NBB_CONFIRMDEL);
break;
case 2002:
OpenFieldSet("tNode Aux Panel",100);
printf("<p><u>Review changes</u><br>");
printf(LANG_NBB_CONFIRMMOD);
if(guPermLevel>11)
{
printf("<p>To change the record owner, just...");
tTablePullDownResellers(guCompany,1);
}
break;
default:
OpenFieldSet("tNode Aux Panel",100);
printf("<u>Table Tips (%s)</u><br>",cGitVersion);
printf("Hardware nodes are defined here. Hardware nodes host containers, and allow"
" for the autonomic migration to other nodes that may be better suited"
" at specific points in time to accomplish QoS or other system admin"
" created policies herein. uVeth='Yes' container traffic is not included"
"in the node graphs at this time.");
if(uNode && uStatus==1)
printf("<br><input type=submit class=largeButton title='Hardware inventory information and data entry for selected node.'"
" name=gcCommand value='Hardware Information'>");
printf("<p><u>Record Context Info</u><br>");
if(uDatacenter && uNode)
{
printf("Node belongs to ");
printf("<a class=darkLink href=unxsVZ.cgi?gcFunction=tDatacenter&uDatacenter=%u>%s</a>",
uDatacenter,ForeignKey("tDatacenter","cLabel",uDatacenter));
htmlGroups(uNode,0);
}
printf("<p><u>Node Container Search</u><br>");
printf("<input title='Enter pattern then click on node link. Use [Search], enter cLabel start or MySQL LIKE pattern"
" (%% or _ allowed) to show a navgation list with containers that match pattern for a given node.'"
" type=text name=cSearch value='%s'>",cSearch);
tNodeNavList(0);
tContainerNavList(uNode,cSearch);
if(uNode)
{
tNodeHealth();
//htmlHealth(uNode,uDatacenter,2);
//hide health if node selected via get
//if(guMode!=6)
// htmlNodeHealth(uNode);
printf("<p><input type=submit class=largeButton title='Display node container"
" report'"
" name=gcCommand value='Node Container Report'><br>");
printf("<p><input type=submit class=lwarnButton title='Clone all containers on this clone to another node.'"
" name=gcCommand value='Clone Node Wizard'><br>");
printf("<input type=submit class=lwarnButton title='Failover to this node`s clone containers"
" the master containers`s of down node.'"
" name=gcCommand value='Failover Node Wizard'><br>");
if(guPermLevel>11 && uStatus!=uOFFLINE)
printf("<input type=submit class=lwarnButton title='Change node status to offline.'"
" name=gcCommand value='Node Offline'><br>");
else if(guPermLevel>11 && uStatus==uOFFLINE)
printf("<input type=submit class=lwarnButton title='Change node status to online.'"
" name=gcCommand value='Node Online'><br>");
}
}
CloseFieldSet();
}//void ExttNodeButtons(void)
//UBC work required
void ExttNodeAuxTable(void)
{
MYSQL_RES *res;
MYSQL_ROW field;
switch(guMode)
{
//Node Container Report
case 9001:
{
//UBC support
char cLogfile[64]={"/tmp/unxsvzlog"};
if(gLfp==NULL)
{
if( (gLfp=fopen(cLogfile,"a"))==NULL)
tContainer("Could not open logfile");
}
if(uDatacenter && ConnectToOptionalUBCDb(uDatacenter,0))
{
printf("<p>ConnectToOptionalUBCDb() error<p>");
return;
}
if(strcmp(gcUBCDBIP0,DBIP0) || strcmp(gcUBCDBIP1,DBIP1))
gMysqlUBC=gMysql;
sprintf(gcQuery,"Distributed UBC %s Property Panel",cLabel);
sprintf(gcQuery,"Non clone %s Containers",cLabel);
OpenFieldSet(gcQuery,100);
printf("<table>");
printf("<tr>"
//"<td><u>select</u></td>"
"<td><u>master label</u></td>"
"<td><u>master hostname</u></td>"
"<td><u>template</u></td>"
"<td><u>status</u></td>"
"<td><u>clone label</u></td>"
"<td><u>clone hostname</u></td>"
"<td><u>seconds since rsync</u></td>"
"</tr>");
sprintf(gcQuery,"SELECT tContainer.uContainer,tContainer.cLabel,tContainer.cHostname,"
"tContainer.uNode,tContainer.uDatacenter,tOSTemplate.cLabel,tStatus.cLabel"
" FROM tContainer,tOSTemplate,tStatus"
" WHERE tContainer.uNode=%u"
" AND tContainer.uOSTemplate=tOSTemplate.uOSTemplate"
" AND tContainer.uStatus=tStatus.uStatus"
" AND tContainer.uSource=0"
" ORDER BY tContainer.cLabel",uNode);
mysql_query(&gMysql,gcQuery);
if(mysql_errno(&gMysql))
htmlPlainTextError(mysql_error(&gMysql));
res=mysql_store_result(&gMysql);
if(mysql_num_rows(res))
{
MYSQL_RES *res2;
MYSQL_ROW field2;
long unsigned luTotalDiskSpace=0;
long unsigned luDiskSpace;
while((field=mysql_fetch_row(res)))
{
printf( "<tr>"
//"<td><input type=checkbox name=CNW%s</td>"
"<td>"
"<a class=darkLink href=unxsVZ.cgi?gcFunction=tContainer&uContainer=%s>%s</a>"
"</td>"
"<td>%s</td>"
"<td>%s</td>"
"<td>%s</td>",
//field[0],
field[0],field[1],field[2],field[5],field[6]);
sprintf(gcQuery,"SELECT uContainer,cLabel,cHostname,(UNIX_TIMESTAMP(NOW())-uBackupDate),"
"uDatacenter,uNode,uIPv4,uStatus,uOwner"
" FROM tContainer WHERE uSource=%s",field[0]);
mysql_query(&gMysql,gcQuery);
if(mysql_errno(&gMysql))
htmlPlainTextError(mysql_error(&gMysql));
res2=mysql_store_result(&gMysql);
if((field2=mysql_fetch_row(res2)))
{
printf("<td><a class=darkLink href=unxsVZ.cgi?"
"gcFunction=tContainer&uContainer=%s>"
"%s</a></td><td>%s</td><td>%s</td>",
field2[0],field2[1],field2[2],field2[3]);
}
else
{
printf("<td>---</a></td><td>---</td><td>---</td>");
}
mysql_free_result(res2);
printf("</tr>\n");
sprintf(gcQuery,"SELECT cValue FROM tProperty"
" WHERE cName='1k-blocks.luUsage' AND uType=3 AND uKey=%s",field[0]);
mysql_query(&gMysqlUBC,gcQuery);
if(mysql_errno(&gMysqlUBC))
htmlPlainTextError(mysql_error(&gMysqlUBC));
res2=mysql_store_result(&gMysqlUBC);
if((field2=mysql_fetch_row(res2)))
{
luDiskSpace=0;
sscanf(field2[0],"%lu",&luDiskSpace);
luTotalDiskSpace+=luDiskSpace;
}
mysql_free_result(res2);
}
printf("<tr><td>Total disk space used: %lu</td></tr>",luTotalDiskSpace);
}
printf("</table>");
CloseFieldSet();
}
break;
//Hardware Information
case 10000:
case 10001:
sprintf(gcQuery,"Hardware Inventory %s",ForeignKey("tDatacenter","cLabel",uDatacenter));
OpenFieldSet(gcQuery,100);
printf("<table>");
printf("<tr>"
"<td width=100><u>Node</u></td>"
"<td width=200><u>cName</u></td>"
"<td width=400><u>cValue</u></td>"
"</tr>");
sprintf(gcQuery,"SELECT tNode.cLabel,tProperty.cName,tProperty.cValue,tNode.uNode,tProperty.uProperty"
" FROM tNode,tProperty"
" WHERE tProperty.uKey=tNode.uNode AND tProperty.uType=2"
" AND tNode.uStatus=1"
" AND tNode.uDatacenter=%u"
//" AND tProperty.cName='cIPMIIPv4'"
" AND ("
" tProperty.cName LIKE 'c%%' OR tProperty.cName LIKE 'Max%%'"
" OR tProperty.cName LIKE 'luInstalled%%'"
" OR tProperty.cName='Name'"
" OR tProperty.cName='NewContainerMode'"
" OR tProperty.cName LIKE 'Max%%Containers'"
")"
" AND tNode.cLabel!='appliance'"
" ORDER BY tNode.uNode,tProperty.cName",uDatacenter);
mysql_query(&gMysql,gcQuery);
if(mysql_errno(&gMysql))
htmlPlainTextError(mysql_error(&gMysql));
res=mysql_store_result(&gMysql);
if(mysql_num_rows(res))
{
char cPrevLabel[32]={""};
char cLabel[32]={""};
while((field=mysql_fetch_row(res)))
{
sprintf(cLabel,"%.31s",field[0]);
if(strcmp(cPrevLabel,field[0]))
sprintf(cPrevLabel,"%.31s",field[0]);
else
cLabel[0]=0;
printf("<tr>"
"<td><a class=darkLink href=unxsVZ.cgi?gcFunction=tNode&uNode=%s&uHardware>%s</a></td>"
"<td><a class=darkLink href=unxsVZ.cgi?gcFunction=tProperty&uProperty=%s>%s</a></td>"
"<td><a class=darkLink href=unxsVZ.cgi?gcFunction=tProperty&uProperty=%s>%s</a></td>"
"</tr>",field[3],cLabel,field[4],field[1],field[4],field[2]);
}
}
mysql_free_result(res);
printf("</table>");
CloseFieldSet();
break;
case 8001:
case 8002:
sprintf(gcQuery,"%s Clone Panel",cLabel);
OpenFieldSet(gcQuery,100);
printf("<table>");
printf("<tr>"
"<td><u>master label</u></td>"
"<td><u>master hostname</u></td>"
"<td><u>clone label</u></td>"
"<td><u>clone hostname</u></td>"
"<td><u>seconds since rsync</u></td>"
"<td><u>job created</u></td>"
"</tr>");
sprintf(gcQuery,"SELECT uContainer,cLabel,cHostname,uNode,uDatacenter FROM tContainer WHERE"
" uNode=%u AND uSource=0 AND uStatus=%u ORDER BY cLabel",uNode,uACTIVE);
mysql_query(&gMysql,gcQuery);
if(mysql_errno(&gMysql))
htmlPlainTextError(mysql_error(&gMysql));
res=mysql_store_result(&gMysql);
if(mysql_num_rows(res))
{
MYSQL_RES *res2;
MYSQL_ROW field2;
while((field=mysql_fetch_row(res)))
{
printf("<tr>");
printf("<td><a class=darkLink href=unxsVZ.cgi?"
"gcFunction=tContainer&uContainer=%s>"
"%s</a></td><td>%s</td>",
field[0],field[1],field[2]);
sprintf(gcQuery,"SELECT uContainer,cLabel,cHostname,(UNIX_TIMESTAMP(NOW())-uBackupDate),"
"uDatacenter,uNode,uIPv4,uStatus,uOwner"
" FROM tContainer WHERE uSource=%s",field[0]);
mysql_query(&gMysql,gcQuery);
if(mysql_errno(&gMysql))
htmlPlainTextError(mysql_error(&gMysql));
res2=mysql_store_result(&gMysql);
if((field2=mysql_fetch_row(res2)))
{
printf("<td><a class=darkLink href=unxsVZ.cgi?"
"gcFunction=tContainer&uContainer=%s>"
"%s</a></td><td>%s</td><td>%s</td>",
field2[0],field2[1],field2[2],field2[3]);
if(guMode==8002)
{
unsigned uRetVal=0;
unsigned uDatacenter=0;
unsigned uNode=0;
unsigned uContainer=0;
unsigned uIPv4=0;
unsigned uStatus=0;
unsigned uSource=0;
unsigned uSourceNode=0;
unsigned uSourceDatacenter=0;