-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtconfigfunc.h
573 lines (495 loc) · 16.5 KB
/
tconfigfunc.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
/*
FILE
svn ID removed
(Built initially by unixservice.com mysqlRAD2)
PURPOSE
Non schema-dependent table and application table related functions.
AUTHOR
(C) 2001-2010 Unixservice, LLC.
*/
void tConfigNavList(void);
unsigned htmlConfigContext(void);
unsigned LocalImportConfigJob(unsigned uConfig);
//file scoped var
static unsigned uDatacenter=0;
static char cuDatacenterPullDown[256]={""};
void ExtProcesstConfigVars(pentry entries[], int x)
{
register int i;
for(i=0;i<x;i++)
{
if(!strcmp(entries[i].name,"uDatacenter"))
sscanf(entries[i].val,"%u",&uDatacenter);
else if(!strcmp(entries[i].name,"cuDatacenterPullDown"))
{
sprintf(cuDatacenterPullDown,"%.255s",entries[i].val);
uDatacenter=ReadPullDown("tDatacenter","cLabel",cuDatacenterPullDown);
}
}
}//void ExtProcesstConfigVars(pentry entries[], int x)
void ExttConfigCommands(pentry entries[], int x)
{
if(!strcmp(gcFunction,"tConfigTools"))
{
MYSQL_RES *res;
time_t uActualModDate= -1;
if(!strcmp(gcCommand,LANG_NB_NEW))
{
if(guPermLevel>=10)
{
ProcesstConfigVars(entries,x);
guMode=2000;
tConfig(LANG_NB_CONFIRMNEW);
}
}
else if(!strcmp(gcCommand,LANG_NB_CONFIRMNEW))
{
if(guPermLevel>=10)
{
ProcesstConfigVars(entries,x);
guMode=2000;
//Check entries here
if(strlen(cLabel)<3)
tConfig("<strong>Error</strong>: cLabel too short!");
sprintf(gcQuery,"SELECT uConfig FROM tConfig 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);
tConfig("<strong>Error</strong>: tConfig.cLabel is already used!");
}
guMode=0;
uConfig=0;
uCreatedBy=guLoginClient;
uOwner=guCompany;
uModBy=0;//Never modified
uModDate=0;//Never modified
NewtConfig(1);
if(!uConfig)
tConfig("<strong>Error</strong>: New tConfig entry was not created!");
sprintf(gcQuery,"INSERT INTO tProperty SET uKey=%u,uType="PROP_CONFIG
",cName='cDatacenter',cValue='All Datacenters',uOwner=%u,uCreatedBy=%u"
",uCreatedDate=UNIX_TIMESTAMP(NOW())"
,uConfig,guCompany,guLoginClient);
mysql_query(&gMysql,gcQuery);
if(mysql_errno(&gMysql))
htmlPlainTextError(mysql_error(&gMysql));
tConfig("New config created");
}
}
else if(!strcmp(gcCommand,LANG_NB_DELETE))
{
ProcesstConfigVars(entries,x);
if(uAllowDel(uOwner,uCreatedBy))
{
guMode=0;
sprintf(gcQuery,"SELECT uConfig FROM tContainer WHERE uConfig=%u",uConfig);
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);
tConfig("<strong>Error</strong>: Can't delete a config used by a container!");
}
guMode=2001;
tConfig(LANG_NB_CONFIRMDEL);
}
}
else if(!strcmp(gcCommand,LANG_NB_CONFIRMDEL))
{
ProcesstConfigVars(entries,x);
if(uAllowDel(uOwner,uCreatedBy))
{
guMode=2001;
sscanf(ForeignKey("tConfig","uModDate",uConfig),"%lu",&uActualModDate);
if(uModDate!=uActualModDate)
tConfig("<strong>Error</strong>: This record was modified. Reload it.");
sprintf(gcQuery,"SELECT uConfig FROM tContainer WHERE uConfig=%u",uConfig);
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);
tConfig("<strong>Error</strong>: Can't delete a config used by a container!");
}
guMode=5;
DeletetConfig();
}
}
else if(!strcmp(gcCommand,LANG_NB_MODIFY))
{
ProcesstConfigVars(entries,x);
if(uAllowMod(uOwner,uCreatedBy))
{
guMode=2002;
tConfig(LANG_NB_CONFIRMMOD);
}
}
else if(!strcmp(gcCommand,LANG_NB_CONFIRMMOD))
{
ProcesstConfigVars(entries,x);
if(uAllowMod(uOwner,uCreatedBy))
{
guMode=2002;
//Check entries here
sscanf(ForeignKey("tConfig","uModDate",uConfig),"%lu",&uActualModDate);
if(uModDate!=uActualModDate)
tConfig("<strong>Error</strong>: This record was modified. Reload it.");
if(strlen(cLabel)<3)
tConfig("<strong>Error</strong>: cLabel too short!");
sprintf(gcQuery,"SELECT uConfig FROM tContainer WHERE uConfig=%u",uConfig);
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);
tConfig("<strong>Error</strong>: Can't modify a config used by a container!");
}
guMode=0;
uModBy=guLoginClient;
ModtConfig();
}
}
else if(!strcmp(gcCommand,"Local Import"))
{
if(guPermLevel>=10)
{
ProcesstConfigVars(entries,x);
guMode=6;
if(uConfig<1)
tConfig("<strong>Error</strong>: Unexpected uConfig<1 error!");
sscanf(ForeignKey("tConfig","uModDate",uConfig),"%lu",&uActualModDate);
if(uModDate!=uActualModDate)
tConfig("<strong>Error</strong>: This record was modified. Reload it.");
sprintf(gcQuery,"SELECT uConfig FROM tContainer WHERE uConfig=%u",
uConfig);
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);
tConfig("<strong>Error</strong>: Can't import a config already in use!");
}
if(strlen(cLabel)<3)
tConfig("<strong>Error</strong>: cLabel too short!");
if(LocalImportConfigJob(uConfig))
tConfig("Local Import job created");
else
tConfig("<strong>Error</strong>: LocalImportTemplateJob() failed!");
}
}
else if(!strcmp(gcCommand,"Enable"))
{
ProcesstConfigVars(entries,x);
if(uAllowMod(uOwner,uCreatedBy))
{
guMode=6;
sscanf(ForeignKey("tConfig","uModDate",uConfig),"%lu",&uActualModDate);
if(uModDate!=uActualModDate)
tConfig("<strong>Error</strong>: This record was modified. Reload it.");
if(!uDatacenter)
sprintf(gcQuery,"INSERT tProperty SET cName='cDatacenter',cValue='All Datacenters',"
"uType=%u,uKey=%u,uOwner=%u,uCreatedBy=%u,uCreatedDate=UNIX_TIMESTAMP(NOW())",
uPROP_CONFIG,uConfig,uOwner,guLoginClient);
else
sprintf(gcQuery,"INSERT tProperty SET cName='cDatacenter',cValue='%s',"
"uType=%u,uKey=%u,uOwner=%u,uCreatedBy=%u,uCreatedDate=UNIX_TIMESTAMP(NOW())",
ForeignKey("tDatacenter","cLabel",uDatacenter),
uPROP_CONFIG,uConfig,uOwner,guLoginClient);
mysql_query(&gMysql,gcQuery);
if(mysql_errno(&gMysql))
htmlPlainTextError(mysql_error(&gMysql));
}
else
{
tConfig("<strong>Error</strong>: Enable not allowed!");
}
}
else if(!strcmp(gcCommand,"Disable"))
{
ProcesstConfigVars(entries,x);
if(uAllowMod(uOwner,uCreatedBy))
{
guMode=6;
sscanf(ForeignKey("tConfig","uModDate",uConfig),"%lu",&uActualModDate);
if(uModDate!=uActualModDate)
tConfig("<strong>Error</strong>: This record was modified. Reload it.");
if(!uDatacenter)
sprintf(gcQuery,"DELETE FROM tProperty WHERE cName='cDatacenter' AND cValue='All Datacenters'"
" AND uType=%u AND uKey=%u AND (uOwner=%u OR uCreatedBy=%u)",
uPROP_CONFIG,uConfig,uOwner,guLoginClient);
else
sprintf(gcQuery,"DELETE FROM tProperty WHERE cName='cDatacenter' AND cValue='%s'"
" AND uType=%u AND uKey=%u AND (uOwner=%u OR uCreatedBy=%u)",
ForeignKey("tDatacenter","cLabel",uDatacenter),
uPROP_CONFIG,uConfig,uOwner,guLoginClient);
mysql_query(&gMysql,gcQuery);
if(mysql_errno(&gMysql))
htmlPlainTextError(mysql_error(&gMysql));
}
else
{
tConfig("<strong>Error</strong>: Disable not allowed!");
}
}
}
}//void ExttConfigCommands(pentry entries[], int x)
void ExttConfigButtons(void)
{
unsigned uNum=0;
OpenFieldSet("tConfig Aux Panel",100);
switch(guMode)
{
case 2000:
printf("<p><u>Enter/mod data</u><br>");
printf(LANG_NBB_CONFIRMNEW);
break;
case 2001:
printf("<p><u>Think twice</u><br>");
printf(LANG_NBB_CONFIRMDEL);
break;
case 2002:
printf("<p><u>Review changes</u><br>");
printf(LANG_NBB_CONFIRMMOD);
break;
default:
//ve-dns2.conf-sample
printf("<u>Table Tips (%s)</u><br>",cGitVersion);
printf("Make sure that the cLabel entries (new or modified) have a corresponding "
"/etc/vz/conf//ve-<cLabel>.conf-sample file on all unxsVZ controlled "
"nodes. Please note the 32 character limitation."
"<p><u>Automated way to install an external config file</u><br>"
"1-. Transfer ve-<unused tConfig.cLabel>.conf-sample to a node with a local "
"unxsVZ webmin and place in /etc/vz/conf/.<br>"
"2-. Run a [Local Import] job, after adding the new tConfig.cLabel.<br>");
printf("<p><u>Record Context Info</u><br>");
uNum=htmlConfigContext();
tConfigNavList();
if(uConfig>0 && uNum==0)
{
printf("<p><u>Extended table actions</u><br>");
printf("<input class=largeButton title='Submit a job for the local import of the currently selected "
"config' type=submit name=gcCommand value='Local Import'>");
}
}
CloseFieldSet();
}//void ExttConfigButtons(void)
void ExttConfigAuxTable(void)
{
if(!uConfig || guMode==2000 )//uMODE_NEW
return;
MYSQL_RES *res;
MYSQL_ROW field;
sprintf(gcQuery,"tConfig %s Property Panel",cLabel);
OpenFieldSet(gcQuery,100);
sprintf(gcQuery,"SELECT uProperty,cName,cValue FROM tProperty WHERE uKey=%u AND uType="PROP_CONFIG
" ORDER BY cName",uConfig);
mysql_query(&gMysql,gcQuery);
if(mysql_errno(&gMysql))
htmlPlainTextError(mysql_error(&gMysql));
res=mysql_store_result(&gMysql);
printf("<table cols=2>");
if(mysql_num_rows(res))
{
while((field=mysql_fetch_row(res)))
{
printf("<tr>\n");
printf("<td width=200 valign=top><a class=darkLink href=unxsVZ.cgi?"
"gcFunction=tProperty&uProperty=%s&cReturn=tConfig_%u>"
"%s</a></td><td>%s</td>\n",
field[0],uConfig,field[1],field[2]);
printf("</tr>\n");
}
}
//Simple interface to add to tConfiguration table
if(uAllowMod(uOwner,uCreatedBy))
{
printf("<tr>");
printf("<td width=200 valign=top><input type=submit class=largeButton"
" title='Enable for one or more datacenters; for new container creation'"
" name=gcCommand value='Enable'><p>");
printf("<input type=submit class=largeButton"
" title='Disable for one or more datacenters; for new container creation'"
" name=gcCommand value='Disable'</td>");
printf("<td valign=top> Select a datacenter or none (---) for all ");
tTablePullDown("tDatacenter;cuDatacenterPullDown","cLabel","cLabel",uDatacenter,1);
printf("</td>");
printf("</tr>\n");
}
printf("</table>");
CloseFieldSet();
}//void ExttConfigAuxTable(void)
void ExttConfigGetHook(entry gentries[], int x)
{
register int i;
for(i=0;i<x;i++)
{
if(!strcmp(gentries[i].name,"uConfig"))
{
sscanf(gentries[i].val,"%u",&uConfig);
guMode=6;
}
}
tConfig("");
}//void ExttConfigGetHook(entry gentries[], int x)
void ExttConfigSelect(void)
{
ExtSelect("tConfig",VAR_LIST_tConfig);
}//void ExttConfigSelect(void)
void ExttConfigSelectRow(void)
{
ExtSelectRow("tConfig",VAR_LIST_tConfig,uConfig);
}//void ExttConfigSelectRow(void)
void ExttConfigListSelect(void)
{
char cCat[512];
ExtListSelect("tConfig",VAR_LIST_tConfig);
//Changes here must be reflected below in ExttConfigListFilter()
if(!strcmp(gcFilter,"uConfig"))
{
sscanf(gcCommand,"%u",&uConfig);
if(guPermLevel<10)
strcat(gcQuery," AND ");
else
strcat(gcQuery," WHERE ");
sprintf(cCat,"tConfig.uConfig=%u ORDER BY uConfig",uConfig);
strcat(gcQuery,cCat);
}
else if(1)
{
//None NO FILTER
strcpy(gcFilter,"None");
strcat(gcQuery," ORDER BY uConfig");
}
}//void ExttConfigListSelect(void)
void ExttConfigListFilter(void)
{
//Filter
printf(" Filter on ");
printf("<select name=gcFilter>");
if(strcmp(gcFilter,"uConfig"))
printf("<option>uConfig</option>");
else
printf("<option selected>uConfig</option>");
if(strcmp(gcFilter,"None"))
printf("<option>None</option>");
else
printf("<option selected>None</option>");
printf("</select>");
}//void ExttConfigListFilter(void)
void ExttConfigNavBar(void)
{
printf(LANG_NBB_SKIPFIRST);
printf(LANG_NBB_SKIPBACK);
printf(LANG_NBB_SEARCH);
if(guPermLevel>=10 && !guListMode)
printf(LANG_NBB_NEW);
if(uAllowMod(uOwner,uCreatedBy))
printf(LANG_NBB_MODIFY);
if(uAllowDel(uOwner,uCreatedBy))
printf(LANG_NBB_DELETE);
if(uOwner)
printf(LANG_NBB_LIST);
printf(LANG_NBB_SKIPNEXT);
printf(LANG_NBB_SKIPLAST);
printf(" \n");
}//void ExttConfigNavBar(void)
void tConfigNavList(void)
{
MYSQL_RES *res;
MYSQL_ROW field;
MYSQL_RES *res2;
ExtSelect("tConfig","tConfig.uConfig,tConfig.cLabel");
mysql_query(&gMysql,gcQuery);
if(mysql_errno(&gMysql))
{
printf("<p><u>tConfigNavList</u><br>\n");
printf("%s",mysql_error(&gMysql));
return;
}
res=mysql_store_result(&gMysql);
if(mysql_num_rows(res))
{
printf("<p><u>tConfigNavList</u><br>\n");
while((field=mysql_fetch_row(res)))
{
printf("<a class=darkLink href=unxsVZ.cgi?gcFunction=tConfig&"
"uConfig=%s>%s</a>",field[0],field[1]);
sprintf(gcQuery,"SELECT uProperty FROM tProperty WHERE uKey=%s AND uType="PROP_CONFIG"",field[0]);
mysql_query(&gMysql,gcQuery);
if(mysql_errno(&gMysql))
printf("%s",mysql_error(&gMysql));
res2=mysql_store_result(&gMysql);
if(mysql_num_rows(res2))
printf("*");
printf("<br>\n");
mysql_free_result(res2);
}
}
mysql_free_result(res);
}//void tConfigNavList(void)
unsigned htmlConfigContext(void)
{
unsigned uRows=0;
MYSQL_RES *res;
sprintf(gcQuery,"SELECT uConfig FROM tContainer WHERE uConfig=%u",uConfig);
mysql_query(&gMysql,gcQuery);
if(mysql_errno(&gMysql))
htmlPlainTextError(mysql_error(&gMysql));
res=mysql_store_result(&gMysql);
uRows=mysql_num_rows(res);
printf("Used by %u containers.",uRows);
mysql_free_result(res);
return(uRows);
}//unsigned htmlConfigContext(void)
unsigned LocalImportConfigJob(unsigned uConfig)
{
MYSQL_RES *res;
MYSQL_ROW field;
unsigned uCount=0;
unsigned uNode=0;
unsigned uDatacenter=0;
char cHostname[100];
if(gethostname(cHostname,99)!=0)
return(0);
sprintf(gcQuery,"SELECT uNode,uDatacenter FROM tNode WHERE cLabel='%.99s'",cHostname);
mysql_query(&gMysql,gcQuery);
if(mysql_errno(&gMysql))
htmlPlainTextError(mysql_error(&gMysql));
res=mysql_store_result(&gMysql);
if((field=mysql_fetch_row(res)))
{
sscanf(field[0],"%u",&uNode);
sscanf(field[1],"%u",&uDatacenter);
}
mysql_free_result(res);
if(!uNode || !uDatacenter || !uConfig)
return(0);
sprintf(gcQuery,"INSERT INTO tJob SET cLabel='LocalImportConfigJob(%u)',cJobName='LocalImportConfigJob'"
",uDatacenter=%u,uNode=%u,uContainer=0"
",uJobDate=UNIX_TIMESTAMP(NOW())"
",uJobStatus=1"
",cJobData='uConfig=%u;'"
",uOwner=%u,uCreatedBy=%u,uCreatedDate=UNIX_TIMESTAMP(NOW())",
uConfig,
uDatacenter,uNode,uConfig,
uOwner,guLoginClient);
mysql_query(&gMysql,gcQuery);
if(mysql_errno(&gMysql))
htmlPlainTextError(mysql_error(&gMysql));
uCount=mysql_insert_id(&gMysql);
unxsVZLog(uConfig,"tConfig","LocalConfigImport");
return(uCount);
}//unsigned LocalImportConfigJob(...)