-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtnameserverfunc.h
426 lines (361 loc) · 11.8 KB
/
tnameserverfunc.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
/*
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 tNameserverNavList(void);
//file scoped var
static unsigned uDatacenter=0;
static char cuDatacenterPullDown[256]={""};
void ExtProcesstNameserverVars(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 ExtProcesstNameserverVars(pentry entries[], int x)
void ExttNameserverCommands(pentry entries[], int x)
{
if(!strcmp(gcFunction,"tNameserverTools"))
{
MYSQL_RES *res;
if(!strcmp(gcCommand,LANG_NB_NEW))
{
if(guPermLevel>=10)
{
ProcesstNameserverVars(entries,x);
guMode=2000;
tNameserver(LANG_NB_CONFIRMNEW);
}
}
else if(!strcmp(gcCommand,LANG_NB_CONFIRMNEW))
{
if(guPermLevel>=10)
{
ProcesstNameserverVars(entries,x);
guMode=2000;
//Check entries here
if(strlen(cLabel)<3)
tNameserver("<blink>Error</blink>: cLabel too short!");
sprintf(gcQuery,"SELECT uNameserver FROM tNameserver 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);
tNameserver("<blink>Error</blink>: Nameserver cLabel in use!");
}
guMode=0;
uNameserver=0;
uCreatedBy=guLoginClient;
uOwner=guCompany;
uModBy=0;//Never modified
uModDate=0;//Never modified
NewtNameserver(1);
if(!uNameserver)
tNameserver("<blink>Error</blink>: New tNameserver entry was not created!");
sprintf(gcQuery,"INSERT INTO tProperty SET uKey=%u,uType="PROP_NAMESERVER
",cName='cDatacenter',cValue='All Datacenters',uOwner=%u,uCreatedBy=%u"
",uCreatedDate=UNIX_TIMESTAMP(NOW())"
,uNameserver,guCompany,guLoginClient);
mysql_query(&gMysql,gcQuery);
if(mysql_errno(&gMysql))
htmlPlainTextError(mysql_error(&gMysql));
tNameserver("New nameserver created");
}
}
else if(!strcmp(gcCommand,LANG_NB_DELETE))
{
ProcesstNameserverVars(entries,x);
if(uAllowDel(uOwner,uCreatedBy))
{
guMode=0;
sprintf(gcQuery,"SELECT uNameserver FROM tContainer WHERE uNameserver=%u",
uNameserver);
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);
tNameserver("<blink>Error</blink>: Can't delete a nameserver used by a container!");
}
guMode=2001;
tNameserver(LANG_NB_CONFIRMDEL);
}
}
else if(!strcmp(gcCommand,LANG_NB_CONFIRMDEL))
{
ProcesstNameserverVars(entries,x);
if(uAllowDel(uOwner,uCreatedBy))
{
guMode=5;
sprintf(gcQuery,"SELECT uNameserver FROM tContainer WHERE uNameserver=%u",
uNameserver);
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);
tNameserver("<blink>Error</blink>: Can't delete a nameserver used by a container!");
}
DeletetNameserver();
}
}
else if(!strcmp(gcCommand,LANG_NB_MODIFY))
{
ProcesstNameserverVars(entries,x);
if(uAllowMod(uOwner,uCreatedBy))
{
guMode=2002;
tNameserver(LANG_NB_CONFIRMMOD);
}
}
else if(!strcmp(gcCommand,LANG_NB_CONFIRMMOD))
{
ProcesstNameserverVars(entries,x);
if(uAllowMod(uOwner,uCreatedBy))
{
guMode=2002;
//Check entries here
if(strlen(cLabel)<3)
tNameserver("<blink>Error</blink>: cLabel too short!");
guMode=0;
uModBy=guLoginClient;
ModtNameserver();
}
}
else if(!strcmp(gcCommand,"Enable"))
{
ProcesstNameserverVars(entries,x);
if(uAllowMod(uOwner,uCreatedBy))
{
guMode=6;
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_NAMESERVER,uNameserver,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_NAMESERVER,uNameserver,uOwner,guLoginClient);
mysql_query(&gMysql,gcQuery);
if(mysql_errno(&gMysql))
htmlPlainTextError(mysql_error(&gMysql));
}
else
{
tNameserver("<blink>Error</blink>: Enable not allowed!");
}
}
else if(!strcmp(gcCommand,"Disable"))
{
ProcesstNameserverVars(entries,x);
if(uAllowMod(uOwner,uCreatedBy))
{
guMode=6;
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_NAMESERVER,uNameserver,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_NAMESERVER,uNameserver,uOwner,guLoginClient);
mysql_query(&gMysql,gcQuery);
if(mysql_errno(&gMysql))
htmlPlainTextError(mysql_error(&gMysql));
}
else
{
tNameserver("<blink>Error</blink>: Disable not allowed!");
}
}
}
}//void ExttNameserverCommands(pentry entries[], int x)
void ExttNameserverButtons(void)
{
OpenFieldSet("tNameserver 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:
printf("<u>Table Tips (%s)</u><br>",cGitVersion);
printf("<p><u>Record Context Info</u><br>");
tNameserverNavList();
}
CloseFieldSet();
}//void ExttNameserverButtons(void)
void ExttNameserverAuxTable(void)
{
if(!uNameserver || guMode==2000 )//uMODE_NEW
return;
MYSQL_RES *res;
MYSQL_ROW field;
sprintf(gcQuery,"tNameserver %s Property Panel",cLabel);
OpenFieldSet(gcQuery,100);
sprintf(gcQuery,"SELECT uProperty,cName,cValue FROM tProperty WHERE uKey=%u AND uType="PROP_NAMESERVER
" ORDER BY cName",uNameserver);
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=tNameserver_%u>"
"%s</a></td><td>%s</td>\n",
field[0],uNameserver,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 ExttNameserverAuxTable(void)
void ExttNameserverGetHook(entry gentries[], int x)
{
register int i;
for(i=0;i<x;i++)
{
if(!strcmp(gentries[i].name,"uNameserver"))
{
sscanf(gentries[i].val,"%u",&uNameserver);
guMode=6;
}
}
tNameserver("");
}//void ExttNameserverGetHook(entry gentries[], int x)
void ExttNameserverSelect(void)
{
ExtSelect("tNameserver",VAR_LIST_tNameserver);
}//void ExttNameserverSelect(void)
void ExttNameserverSelectRow(void)
{
ExtSelectRow("tNameserver",VAR_LIST_tNameserver,uNameserver);
}//void ExttNameserverSelectRow(void)
void ExttNameserverListSelect(void)
{
char cCat[512];
ExtListSelect("tNameserver",VAR_LIST_tNameserver);
//Changes here must be reflected below in ExttNameserverListFilter()
if(!strcmp(gcFilter,"uNameserver"))
{
sscanf(gcCommand,"%u",&uNameserver);
if(guLoginClient==1 && guPermLevel>11)
strcat(gcQuery," WHERE ");
else
strcat(gcQuery," AND ");
sprintf(cCat,"tNameserver.uNameserver=%u ORDER BY uNameserver",uNameserver);
strcat(gcQuery,cCat);
}
else if(1)
{
//None NO FILTER
strcpy(gcFilter,"None");
strcat(gcQuery," ORDER BY uNameserver");
}
}//void ExttNameserverListSelect(void)
void ExttNameserverListFilter(void)
{
//Filter
printf(" Filter on ");
printf("<select name=gcFilter>");
if(strcmp(gcFilter,"uNameserver"))
printf("<option>uNameserver</option>");
else
printf("<option selected>uNameserver</option>");
if(strcmp(gcFilter,"None"))
printf("<option>None</option>");
else
printf("<option selected>None</option>");
printf("</select>");
}//void ExttNameserverListFilter(void)
void ExttNameserverNavBar(void)
{
if(uOwner) GetClientOwner(uOwner,&guReseller);
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 ExttNameserverNavBar(void)
void tNameserverNavList(void)
{
MYSQL_RES *res;
MYSQL_ROW field;
ExtSelect("tNameserver","tNameserver.uNameserver,tNameserver.cLabel");
mysql_query(&gMysql,gcQuery);
if(mysql_errno(&gMysql))
{
printf("<p><u>tNameserverNavList</u><br>\n");
printf("%s",mysql_error(&gMysql));
return;
}
res=mysql_store_result(&gMysql);
if(mysql_num_rows(res))
{
printf("<p><u>tNameserverNavList</u><br>\n");
while((field=mysql_fetch_row(res)))
printf("<a class=darkLink href=unxsVZ.cgi?gcFunction=tNameserver&"
"uNameserver=%s>%s</a><br>\n",field[0],field[1]);
}
mysql_free_result(res);
}//void tNameserverNavList(void)