| 1 | /* |
|---|
| 2 | FILE |
|---|
| 3 | $Id$ |
|---|
| 4 | (Built initially by unixservice.com mysqlRAD2) |
|---|
| 5 | PURPOSE |
|---|
| 6 | Non schema-dependent table and application table related functions. |
|---|
| 7 | AUTHOR |
|---|
| 8 | (C) 2001-2010 Unixservice, LLC. |
|---|
| 9 | |
|---|
| 10 | */ |
|---|
| 11 | |
|---|
| 12 | void tConfigNavList(void); |
|---|
| 13 | unsigned htmlConfigContext(void); |
|---|
| 14 | unsigned LocalImportConfigJob(unsigned uConfig); |
|---|
| 15 | |
|---|
| 16 | //file scoped var |
|---|
| 17 | static unsigned uDatacenter=0; |
|---|
| 18 | static char cuDatacenterPullDown[256]={""}; |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | void ExtProcesstConfigVars(pentry entries[], int x) |
|---|
| 22 | { |
|---|
| 23 | register int i; |
|---|
| 24 | for(i=0;i<x;i++) |
|---|
| 25 | { |
|---|
| 26 | if(!strcmp(entries[i].name,"uDatacenter")) |
|---|
| 27 | sscanf(entries[i].val,"%u",&uDatacenter); |
|---|
| 28 | else if(!strcmp(entries[i].name,"cuDatacenterPullDown")) |
|---|
| 29 | { |
|---|
| 30 | sprintf(cuDatacenterPullDown,"%.255s",entries[i].val); |
|---|
| 31 | uDatacenter=ReadPullDown("tDatacenter","cLabel",cuDatacenterPullDown); |
|---|
| 32 | } |
|---|
| 33 | } |
|---|
| 34 | }//void ExtProcesstConfigVars(pentry entries[], int x) |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | void ExttConfigCommands(pentry entries[], int x) |
|---|
| 38 | { |
|---|
| 39 | |
|---|
| 40 | if(!strcmp(gcFunction,"tConfigTools")) |
|---|
| 41 | { |
|---|
| 42 | MYSQL_RES *res; |
|---|
| 43 | time_t uActualModDate= -1; |
|---|
| 44 | |
|---|
| 45 | if(!strcmp(gcCommand,LANG_NB_NEW)) |
|---|
| 46 | { |
|---|
| 47 | if(guPermLevel>=10) |
|---|
| 48 | { |
|---|
| 49 | ProcesstConfigVars(entries,x); |
|---|
| 50 | guMode=2000; |
|---|
| 51 | tConfig(LANG_NB_CONFIRMNEW); |
|---|
| 52 | } |
|---|
| 53 | } |
|---|
| 54 | else if(!strcmp(gcCommand,LANG_NB_CONFIRMNEW)) |
|---|
| 55 | { |
|---|
| 56 | if(guPermLevel>=10) |
|---|
| 57 | { |
|---|
| 58 | ProcesstConfigVars(entries,x); |
|---|
| 59 | |
|---|
| 60 | guMode=2000; |
|---|
| 61 | //Check entries here |
|---|
| 62 | if(strlen(cLabel)<3) |
|---|
| 63 | tConfig("<blink>Error</blink>: cLabel too short!"); |
|---|
| 64 | sprintf(gcQuery,"SELECT uConfig FROM tConfig WHERE cLabel='%s'", |
|---|
| 65 | cLabel); |
|---|
| 66 | mysql_query(&gMysql,gcQuery); |
|---|
| 67 | if(mysql_errno(&gMysql)) |
|---|
| 68 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 69 | res=mysql_store_result(&gMysql); |
|---|
| 70 | if(mysql_num_rows(res)) |
|---|
| 71 | { |
|---|
| 72 | mysql_free_result(res); |
|---|
| 73 | tConfig("<blink>Error</blink>: tConfig.cLabel is already used!"); |
|---|
| 74 | } |
|---|
| 75 | guMode=0; |
|---|
| 76 | |
|---|
| 77 | uConfig=0; |
|---|
| 78 | uCreatedBy=guLoginClient; |
|---|
| 79 | uOwner=guCompany; |
|---|
| 80 | uModBy=0;//Never modified |
|---|
| 81 | uModDate=0;//Never modified |
|---|
| 82 | NewtConfig(1); |
|---|
| 83 | if(!uConfig) |
|---|
| 84 | tConfig("<blink>Error</blink>: New tConfig entry was not created!"); |
|---|
| 85 | |
|---|
| 86 | sprintf(gcQuery,"INSERT INTO tProperty SET uKey=%u,uType="PROP_CONFIG |
|---|
| 87 | ",cName='cDatacenter',cValue='All Datacenters',uOwner=%u,uCreatedBy=%u" |
|---|
| 88 | ",uCreatedDate=UNIX_TIMESTAMP(NOW())" |
|---|
| 89 | ,uConfig,guCompany,guLoginClient); |
|---|
| 90 | mysql_query(&gMysql,gcQuery); |
|---|
| 91 | if(mysql_errno(&gMysql)) |
|---|
| 92 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 93 | tConfig("New config created"); |
|---|
| 94 | } |
|---|
| 95 | } |
|---|
| 96 | else if(!strcmp(gcCommand,LANG_NB_DELETE)) |
|---|
| 97 | { |
|---|
| 98 | ProcesstConfigVars(entries,x); |
|---|
| 99 | if(uAllowDel(uOwner,uCreatedBy)) |
|---|
| 100 | { |
|---|
| 101 | guMode=0; |
|---|
| 102 | sprintf(gcQuery,"SELECT uConfig FROM tContainer WHERE uConfig=%u",uConfig); |
|---|
| 103 | mysql_query(&gMysql,gcQuery); |
|---|
| 104 | if(mysql_errno(&gMysql)) |
|---|
| 105 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 106 | res=mysql_store_result(&gMysql); |
|---|
| 107 | if(mysql_num_rows(res)) |
|---|
| 108 | { |
|---|
| 109 | mysql_free_result(res); |
|---|
| 110 | tConfig("<blink>Error</blink>: Can't delete a config used by a container!"); |
|---|
| 111 | } |
|---|
| 112 | guMode=2001; |
|---|
| 113 | tConfig(LANG_NB_CONFIRMDEL); |
|---|
| 114 | } |
|---|
| 115 | } |
|---|
| 116 | else if(!strcmp(gcCommand,LANG_NB_CONFIRMDEL)) |
|---|
| 117 | { |
|---|
| 118 | ProcesstConfigVars(entries,x); |
|---|
| 119 | if(uAllowDel(uOwner,uCreatedBy)) |
|---|
| 120 | { |
|---|
| 121 | guMode=2001; |
|---|
| 122 | sscanf(ForeignKey("tConfig","uModDate",uConfig),"%lu",&uActualModDate); |
|---|
| 123 | if(uModDate!=uActualModDate) |
|---|
| 124 | tConfig("<blink>Error</blink>: This record was modified. Reload it."); |
|---|
| 125 | sprintf(gcQuery,"SELECT uConfig FROM tContainer WHERE uConfig=%u",uConfig); |
|---|
| 126 | mysql_query(&gMysql,gcQuery); |
|---|
| 127 | if(mysql_errno(&gMysql)) |
|---|
| 128 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 129 | res=mysql_store_result(&gMysql); |
|---|
| 130 | if(mysql_num_rows(res)) |
|---|
| 131 | { |
|---|
| 132 | mysql_free_result(res); |
|---|
| 133 | tConfig("<blink>Error</blink>: Can't delete a config used by a container!"); |
|---|
| 134 | } |
|---|
| 135 | guMode=5; |
|---|
| 136 | DeletetConfig(); |
|---|
| 137 | } |
|---|
| 138 | } |
|---|
| 139 | else if(!strcmp(gcCommand,LANG_NB_MODIFY)) |
|---|
| 140 | { |
|---|
| 141 | ProcesstConfigVars(entries,x); |
|---|
| 142 | if(uAllowMod(uOwner,uCreatedBy)) |
|---|
| 143 | { |
|---|
| 144 | guMode=2002; |
|---|
| 145 | tConfig(LANG_NB_CONFIRMMOD); |
|---|
| 146 | } |
|---|
| 147 | } |
|---|
| 148 | else if(!strcmp(gcCommand,LANG_NB_CONFIRMMOD)) |
|---|
| 149 | { |
|---|
| 150 | ProcesstConfigVars(entries,x); |
|---|
| 151 | if(uAllowMod(uOwner,uCreatedBy)) |
|---|
| 152 | { |
|---|
| 153 | guMode=2002; |
|---|
| 154 | //Check entries here |
|---|
| 155 | sscanf(ForeignKey("tConfig","uModDate",uConfig),"%lu",&uActualModDate); |
|---|
| 156 | if(uModDate!=uActualModDate) |
|---|
| 157 | tConfig("<blink>Error</blink>: This record was modified. Reload it."); |
|---|
| 158 | if(strlen(cLabel)<3) |
|---|
| 159 | tConfig("<blink>Error</blink>: cLabel too short!"); |
|---|
| 160 | sprintf(gcQuery,"SELECT uConfig FROM tContainer WHERE uConfig=%u",uConfig); |
|---|
| 161 | mysql_query(&gMysql,gcQuery); |
|---|
| 162 | if(mysql_errno(&gMysql)) |
|---|
| 163 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 164 | res=mysql_store_result(&gMysql); |
|---|
| 165 | if(mysql_num_rows(res)) |
|---|
| 166 | { |
|---|
| 167 | mysql_free_result(res); |
|---|
| 168 | tConfig("<blink>Error</blink>: Can't modify a config used by a container!"); |
|---|
| 169 | } |
|---|
| 170 | guMode=0; |
|---|
| 171 | |
|---|
| 172 | uModBy=guLoginClient; |
|---|
| 173 | ModtConfig(); |
|---|
| 174 | } |
|---|
| 175 | } |
|---|
| 176 | else if(!strcmp(gcCommand,"Local Import")) |
|---|
| 177 | { |
|---|
| 178 | if(guPermLevel>=10) |
|---|
| 179 | { |
|---|
| 180 | ProcesstConfigVars(entries,x); |
|---|
| 181 | guMode=6; |
|---|
| 182 | if(uConfig<1) |
|---|
| 183 | tConfig("<blink>Error</blink>: Unexpected uConfig<1 error!"); |
|---|
| 184 | sscanf(ForeignKey("tConfig","uModDate",uConfig),"%lu",&uActualModDate); |
|---|
| 185 | if(uModDate!=uActualModDate) |
|---|
| 186 | tConfig("<blink>Error</blink>: This record was modified. Reload it."); |
|---|
| 187 | sprintf(gcQuery,"SELECT uConfig FROM tContainer WHERE uConfig=%u", |
|---|
| 188 | uConfig); |
|---|
| 189 | mysql_query(&gMysql,gcQuery); |
|---|
| 190 | if(mysql_errno(&gMysql)) |
|---|
| 191 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 192 | res=mysql_store_result(&gMysql); |
|---|
| 193 | if(mysql_num_rows(res)) |
|---|
| 194 | { |
|---|
| 195 | mysql_free_result(res); |
|---|
| 196 | tConfig("<blink>Error</blink>: Can't import a config already in use!"); |
|---|
| 197 | } |
|---|
| 198 | if(strlen(cLabel)<3) |
|---|
| 199 | tConfig("<blink>Error</blink>: cLabel too short!"); |
|---|
| 200 | |
|---|
| 201 | if(LocalImportConfigJob(uConfig)) |
|---|
| 202 | tConfig("Local Import job created"); |
|---|
| 203 | else |
|---|
| 204 | tConfig("<blink>Error</blink>: LocalImportTemplateJob() failed!"); |
|---|
| 205 | } |
|---|
| 206 | } |
|---|
| 207 | else if(!strcmp(gcCommand,"Enable")) |
|---|
| 208 | { |
|---|
| 209 | ProcesstConfigVars(entries,x); |
|---|
| 210 | if(uAllowMod(uOwner,uCreatedBy)) |
|---|
| 211 | { |
|---|
| 212 | guMode=6; |
|---|
| 213 | sscanf(ForeignKey("tConfig","uModDate",uConfig),"%lu",&uActualModDate); |
|---|
| 214 | if(uModDate!=uActualModDate) |
|---|
| 215 | tConfig("<blink>Error</blink>: This record was modified. Reload it."); |
|---|
| 216 | if(!uDatacenter) |
|---|
| 217 | sprintf(gcQuery,"INSERT tProperty SET cName='cDatacenter',cValue='All Datacenters'," |
|---|
| 218 | "uType=%u,uKey=%u,uOwner=%u,uCreatedBy=%u,uCreatedDate=UNIX_TIMESTAMP(NOW())", |
|---|
| 219 | uPROP_CONFIG,uConfig,uOwner,guLoginClient); |
|---|
| 220 | else |
|---|
| 221 | sprintf(gcQuery,"INSERT tProperty SET cName='cDatacenter',cValue='%s'," |
|---|
| 222 | "uType=%u,uKey=%u,uOwner=%u,uCreatedBy=%u,uCreatedDate=UNIX_TIMESTAMP(NOW())", |
|---|
| 223 | ForeignKey("tDatacenter","cLabel",uDatacenter), |
|---|
| 224 | uPROP_CONFIG,uConfig,uOwner,guLoginClient); |
|---|
| 225 | mysql_query(&gMysql,gcQuery); |
|---|
| 226 | if(mysql_errno(&gMysql)) |
|---|
| 227 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 228 | } |
|---|
| 229 | else |
|---|
| 230 | { |
|---|
| 231 | tConfig("<blink>Error</blink>: Enable not allowed!"); |
|---|
| 232 | } |
|---|
| 233 | } |
|---|
| 234 | else if(!strcmp(gcCommand,"Disable")) |
|---|
| 235 | { |
|---|
| 236 | ProcesstConfigVars(entries,x); |
|---|
| 237 | if(uAllowMod(uOwner,uCreatedBy)) |
|---|
| 238 | { |
|---|
| 239 | guMode=6; |
|---|
| 240 | sscanf(ForeignKey("tConfig","uModDate",uConfig),"%lu",&uActualModDate); |
|---|
| 241 | if(uModDate!=uActualModDate) |
|---|
| 242 | tConfig("<blink>Error</blink>: This record was modified. Reload it."); |
|---|
| 243 | if(!uDatacenter) |
|---|
| 244 | sprintf(gcQuery,"DELETE FROM tProperty WHERE cName='cDatacenter' AND cValue='All Datacenters'" |
|---|
| 245 | " AND uType=%u AND uKey=%u AND (uOwner=%u OR uCreatedBy=%u)", |
|---|
| 246 | uPROP_CONFIG,uConfig,uOwner,guLoginClient); |
|---|
| 247 | else |
|---|
| 248 | sprintf(gcQuery,"DELETE FROM tProperty WHERE cName='cDatacenter' AND cValue='%s'" |
|---|
| 249 | " AND uType=%u AND uKey=%u AND (uOwner=%u OR uCreatedBy=%u)", |
|---|
| 250 | ForeignKey("tDatacenter","cLabel",uDatacenter), |
|---|
| 251 | uPROP_CONFIG,uConfig,uOwner,guLoginClient); |
|---|
| 252 | mysql_query(&gMysql,gcQuery); |
|---|
| 253 | if(mysql_errno(&gMysql)) |
|---|
| 254 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 255 | } |
|---|
| 256 | else |
|---|
| 257 | { |
|---|
| 258 | tConfig("<blink>Error</blink>: Disable not allowed!"); |
|---|
| 259 | } |
|---|
| 260 | } |
|---|
| 261 | } |
|---|
| 262 | |
|---|
| 263 | }//void ExttConfigCommands(pentry entries[], int x) |
|---|
| 264 | |
|---|
| 265 | |
|---|
| 266 | void ExttConfigButtons(void) |
|---|
| 267 | { |
|---|
| 268 | unsigned uNum=0; |
|---|
| 269 | |
|---|
| 270 | OpenFieldSet("tConfig Aux Panel",100); |
|---|
| 271 | switch(guMode) |
|---|
| 272 | { |
|---|
| 273 | case 2000: |
|---|
| 274 | printf("<p><u>Enter/mod data</u><br>"); |
|---|
| 275 | printf(LANG_NBB_CONFIRMNEW); |
|---|
| 276 | break; |
|---|
| 277 | |
|---|
| 278 | case 2001: |
|---|
| 279 | printf("<p><u>Think twice</u><br>"); |
|---|
| 280 | printf(LANG_NBB_CONFIRMDEL); |
|---|
| 281 | break; |
|---|
| 282 | |
|---|
| 283 | case 2002: |
|---|
| 284 | printf("<p><u>Review changes</u><br>"); |
|---|
| 285 | printf(LANG_NBB_CONFIRMMOD); |
|---|
| 286 | break; |
|---|
| 287 | |
|---|
| 288 | default: |
|---|
| 289 | //ve-dns2.conf-sample |
|---|
| 290 | printf("<u>Table Tips</u><br>"); |
|---|
| 291 | printf("Make sure that the cLabel entries (new or modified) have a corresponding " |
|---|
| 292 | "/etc/vz/conf//ve-<cLabel>.conf-sample file on all unxsVZ controlled " |
|---|
| 293 | "nodes. Please note the 32 character limitation." |
|---|
| 294 | "<p><u>Automated way to install an external config file</u><br>" |
|---|
| 295 | "1-. Transfer ve-<unused tConfig.cLabel>.conf-sample to a node with a local " |
|---|
| 296 | "unxsVZ webmin and place in /etc/vz/conf/.<br>" |
|---|
| 297 | "2-. Run a [Local Import] job, after adding the new tConfig.cLabel.<br>"); |
|---|
| 298 | printf("<p><u>Record Context Info</u><br>"); |
|---|
| 299 | uNum=htmlConfigContext(); |
|---|
| 300 | tConfigNavList(); |
|---|
| 301 | |
|---|
| 302 | if(uConfig>0 && uNum==0) |
|---|
| 303 | { |
|---|
| 304 | printf("<p><u>Extended table actions</u><br>"); |
|---|
| 305 | printf("<input class=largeButton title='Submit a job for the local import of the currently selected " |
|---|
| 306 | "config' type=submit name=gcCommand value='Local Import'>"); |
|---|
| 307 | } |
|---|
| 308 | } |
|---|
| 309 | CloseFieldSet(); |
|---|
| 310 | |
|---|
| 311 | }//void ExttConfigButtons(void) |
|---|
| 312 | |
|---|
| 313 | |
|---|
| 314 | void ExttConfigAuxTable(void) |
|---|
| 315 | { |
|---|
| 316 | if(!uConfig || guMode==2000 )//uMODE_NEW |
|---|
| 317 | return; |
|---|
| 318 | |
|---|
| 319 | MYSQL_RES *res; |
|---|
| 320 | MYSQL_ROW field; |
|---|
| 321 | |
|---|
| 322 | sprintf(gcQuery,"tConfig %s Property Panel",cLabel); |
|---|
| 323 | OpenFieldSet(gcQuery,100); |
|---|
| 324 | sprintf(gcQuery,"SELECT uProperty,cName,cValue FROM tProperty WHERE uKey=%u AND uType="PROP_CONFIG |
|---|
| 325 | " ORDER BY cName",uConfig); |
|---|
| 326 | |
|---|
| 327 | mysql_query(&gMysql,gcQuery); |
|---|
| 328 | if(mysql_errno(&gMysql)) |
|---|
| 329 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 330 | |
|---|
| 331 | res=mysql_store_result(&gMysql); |
|---|
| 332 | printf("<table cols=2>"); |
|---|
| 333 | if(mysql_num_rows(res)) |
|---|
| 334 | { |
|---|
| 335 | while((field=mysql_fetch_row(res))) |
|---|
| 336 | { |
|---|
| 337 | printf("<tr>\n"); |
|---|
| 338 | printf("<td width=200 valign=top><a class=darkLink href=unxsVZ.cgi?" |
|---|
| 339 | "gcFunction=tProperty&uProperty=%s&cReturn=tConfig_%u>" |
|---|
| 340 | "%s</a></td><td>%s</td>\n", |
|---|
| 341 | field[0],uConfig,field[1],field[2]); |
|---|
| 342 | printf("</tr>\n"); |
|---|
| 343 | } |
|---|
| 344 | } |
|---|
| 345 | |
|---|
| 346 | //Simple interface to add to tConfiguration table |
|---|
| 347 | if(uAllowMod(uOwner,uCreatedBy)) |
|---|
| 348 | { |
|---|
| 349 | printf("<tr>"); |
|---|
| 350 | printf("<td width=200 valign=top><input type=submit class=largeButton" |
|---|
| 351 | " title='Enable for one or more datacenters; for new container creation'" |
|---|
| 352 | " name=gcCommand value='Enable'><p>"); |
|---|
| 353 | printf("<input type=submit class=largeButton" |
|---|
| 354 | " title='Disable for one or more datacenters; for new container creation'" |
|---|
| 355 | " name=gcCommand value='Disable'</td>"); |
|---|
| 356 | printf("<td valign=top> Select a datacenter or none (---) for all "); |
|---|
| 357 | tTablePullDown("tDatacenter;cuDatacenterPullDown","cLabel","cLabel",uDatacenter,1); |
|---|
| 358 | printf("</td>"); |
|---|
| 359 | printf("</tr>\n"); |
|---|
| 360 | } |
|---|
| 361 | |
|---|
| 362 | printf("</table>"); |
|---|
| 363 | |
|---|
| 364 | CloseFieldSet(); |
|---|
| 365 | |
|---|
| 366 | }//void ExttConfigAuxTable(void) |
|---|
| 367 | |
|---|
| 368 | |
|---|
| 369 | void ExttConfigGetHook(entry gentries[], int x) |
|---|
| 370 | { |
|---|
| 371 | register int i; |
|---|
| 372 | |
|---|
| 373 | for(i=0;i<x;i++) |
|---|
| 374 | { |
|---|
| 375 | if(!strcmp(gentries[i].name,"uConfig")) |
|---|
| 376 | { |
|---|
| 377 | sscanf(gentries[i].val,"%u",&uConfig); |
|---|
| 378 | guMode=6; |
|---|
| 379 | } |
|---|
| 380 | } |
|---|
| 381 | tConfig(""); |
|---|
| 382 | |
|---|
| 383 | }//void ExttConfigGetHook(entry gentries[], int x) |
|---|
| 384 | |
|---|
| 385 | |
|---|
| 386 | void ExttConfigSelect(void) |
|---|
| 387 | { |
|---|
| 388 | ExtSelect("tConfig",VAR_LIST_tConfig); |
|---|
| 389 | |
|---|
| 390 | }//void ExttConfigSelect(void) |
|---|
| 391 | |
|---|
| 392 | |
|---|
| 393 | void ExttConfigSelectRow(void) |
|---|
| 394 | { |
|---|
| 395 | ExtSelectRow("tConfig",VAR_LIST_tConfig,uConfig); |
|---|
| 396 | |
|---|
| 397 | }//void ExttConfigSelectRow(void) |
|---|
| 398 | |
|---|
| 399 | |
|---|
| 400 | void ExttConfigListSelect(void) |
|---|
| 401 | { |
|---|
| 402 | char cCat[512]; |
|---|
| 403 | |
|---|
| 404 | ExtListSelect("tConfig",VAR_LIST_tConfig); |
|---|
| 405 | |
|---|
| 406 | //Changes here must be reflected below in ExttConfigListFilter() |
|---|
| 407 | if(!strcmp(gcFilter,"uConfig")) |
|---|
| 408 | { |
|---|
| 409 | sscanf(gcCommand,"%u",&uConfig); |
|---|
| 410 | if(guPermLevel<10) |
|---|
| 411 | strcat(gcQuery," AND "); |
|---|
| 412 | else |
|---|
| 413 | strcat(gcQuery," WHERE "); |
|---|
| 414 | sprintf(cCat,"tConfig.uConfig=%u ORDER BY uConfig",uConfig); |
|---|
| 415 | strcat(gcQuery,cCat); |
|---|
| 416 | } |
|---|
| 417 | else if(1) |
|---|
| 418 | { |
|---|
| 419 | //None NO FILTER |
|---|
| 420 | strcpy(gcFilter,"None"); |
|---|
| 421 | strcat(gcQuery," ORDER BY uConfig"); |
|---|
| 422 | } |
|---|
| 423 | |
|---|
| 424 | }//void ExttConfigListSelect(void) |
|---|
| 425 | |
|---|
| 426 | |
|---|
| 427 | void ExttConfigListFilter(void) |
|---|
| 428 | { |
|---|
| 429 | //Filter |
|---|
| 430 | printf(" Filter on "); |
|---|
| 431 | printf("<select name=gcFilter>"); |
|---|
| 432 | if(strcmp(gcFilter,"uConfig")) |
|---|
| 433 | printf("<option>uConfig</option>"); |
|---|
| 434 | else |
|---|
| 435 | printf("<option selected>uConfig</option>"); |
|---|
| 436 | if(strcmp(gcFilter,"None")) |
|---|
| 437 | printf("<option>None</option>"); |
|---|
| 438 | else |
|---|
| 439 | printf("<option selected>None</option>"); |
|---|
| 440 | printf("</select>"); |
|---|
| 441 | |
|---|
| 442 | }//void ExttConfigListFilter(void) |
|---|
| 443 | |
|---|
| 444 | |
|---|
| 445 | void ExttConfigNavBar(void) |
|---|
| 446 | { |
|---|
| 447 | printf(LANG_NBB_SKIPFIRST); |
|---|
| 448 | printf(LANG_NBB_SKIPBACK); |
|---|
| 449 | printf(LANG_NBB_SEARCH); |
|---|
| 450 | |
|---|
| 451 | if(guPermLevel>=10 && !guListMode) |
|---|
| 452 | printf(LANG_NBB_NEW); |
|---|
| 453 | |
|---|
| 454 | if(uAllowMod(uOwner,uCreatedBy)) |
|---|
| 455 | printf(LANG_NBB_MODIFY); |
|---|
| 456 | |
|---|
| 457 | if(uAllowDel(uOwner,uCreatedBy)) |
|---|
| 458 | printf(LANG_NBB_DELETE); |
|---|
| 459 | |
|---|
| 460 | if(uOwner) |
|---|
| 461 | printf(LANG_NBB_LIST); |
|---|
| 462 | |
|---|
| 463 | printf(LANG_NBB_SKIPNEXT); |
|---|
| 464 | printf(LANG_NBB_SKIPLAST); |
|---|
| 465 | printf(" \n"); |
|---|
| 466 | |
|---|
| 467 | }//void ExttConfigNavBar(void) |
|---|
| 468 | |
|---|
| 469 | |
|---|
| 470 | void tConfigNavList(void) |
|---|
| 471 | { |
|---|
| 472 | MYSQL_RES *res; |
|---|
| 473 | MYSQL_ROW field; |
|---|
| 474 | |
|---|
| 475 | ExtSelect("tConfig","tConfig.uConfig,tConfig.cLabel"); |
|---|
| 476 | |
|---|
| 477 | mysql_query(&gMysql,gcQuery); |
|---|
| 478 | if(mysql_errno(&gMysql)) |
|---|
| 479 | { |
|---|
| 480 | printf("<p><u>tConfigNavList</u><br>\n"); |
|---|
| 481 | printf("%s",mysql_error(&gMysql)); |
|---|
| 482 | return; |
|---|
| 483 | } |
|---|
| 484 | |
|---|
| 485 | res=mysql_store_result(&gMysql); |
|---|
| 486 | if(mysql_num_rows(res)) |
|---|
| 487 | { |
|---|
| 488 | printf("<p><u>tConfigNavList</u><br>\n"); |
|---|
| 489 | |
|---|
| 490 | while((field=mysql_fetch_row(res))) |
|---|
| 491 | printf("<a class=darkLink href=unxsVZ.cgi?gcFunction=tConfig&" |
|---|
| 492 | "uConfig=%s>%s</a><br>\n",field[0],field[1]); |
|---|
| 493 | } |
|---|
| 494 | mysql_free_result(res); |
|---|
| 495 | |
|---|
| 496 | }//void tConfigNavList(void) |
|---|
| 497 | |
|---|
| 498 | |
|---|
| 499 | unsigned htmlConfigContext(void) |
|---|
| 500 | { |
|---|
| 501 | unsigned uRows=0; |
|---|
| 502 | MYSQL_RES *res; |
|---|
| 503 | |
|---|
| 504 | sprintf(gcQuery,"SELECT uConfig FROM tContainer WHERE uConfig=%u",uConfig); |
|---|
| 505 | mysql_query(&gMysql,gcQuery); |
|---|
| 506 | if(mysql_errno(&gMysql)) |
|---|
| 507 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 508 | res=mysql_store_result(&gMysql); |
|---|
| 509 | uRows=mysql_num_rows(res); |
|---|
| 510 | printf("Used by %u containers.",uRows); |
|---|
| 511 | mysql_free_result(res); |
|---|
| 512 | |
|---|
| 513 | return(uRows); |
|---|
| 514 | |
|---|
| 515 | }//unsigned htmlConfigContext(void) |
|---|
| 516 | |
|---|
| 517 | |
|---|
| 518 | unsigned LocalImportConfigJob(unsigned uConfig) |
|---|
| 519 | { |
|---|
| 520 | MYSQL_RES *res; |
|---|
| 521 | MYSQL_ROW field; |
|---|
| 522 | unsigned uCount=0; |
|---|
| 523 | unsigned uNode=0; |
|---|
| 524 | unsigned uDatacenter=0; |
|---|
| 525 | char cHostname[100]; |
|---|
| 526 | |
|---|
| 527 | if(gethostname(cHostname,99)!=0) |
|---|
| 528 | return(0); |
|---|
| 529 | |
|---|
| 530 | sprintf(gcQuery,"SELECT uNode,uDatacenter FROM tNode WHERE cLabel='%.99s'",cHostname); |
|---|
| 531 | mysql_query(&gMysql,gcQuery); |
|---|
| 532 | if(mysql_errno(&gMysql)) |
|---|
| 533 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 534 | res=mysql_store_result(&gMysql); |
|---|
| 535 | if((field=mysql_fetch_row(res))) |
|---|
| 536 | { |
|---|
| 537 | sscanf(field[0],"%u",&uNode); |
|---|
| 538 | sscanf(field[1],"%u",&uDatacenter); |
|---|
| 539 | } |
|---|
| 540 | mysql_free_result(res); |
|---|
| 541 | |
|---|
| 542 | if(!uNode || !uDatacenter || !uConfig) |
|---|
| 543 | return(0); |
|---|
| 544 | |
|---|
| 545 | sprintf(gcQuery,"INSERT INTO tJob SET cLabel='LocalImportConfigJob(%u)',cJobName='LocalImportConfigJob'" |
|---|
| 546 | ",uDatacenter=%u,uNode=%u,uContainer=0" |
|---|
| 547 | ",uJobDate=UNIX_TIMESTAMP(NOW())" |
|---|
| 548 | ",uJobStatus=1" |
|---|
| 549 | ",cJobData='uConfig=%u;'" |
|---|
| 550 | ",uOwner=%u,uCreatedBy=%u,uCreatedDate=UNIX_TIMESTAMP(NOW())", |
|---|
| 551 | uConfig, |
|---|
| 552 | uDatacenter,uNode,uConfig, |
|---|
| 553 | uOwner,guLoginClient); |
|---|
| 554 | mysql_query(&gMysql,gcQuery); |
|---|
| 555 | if(mysql_errno(&gMysql)) |
|---|
| 556 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 557 | uCount=mysql_insert_id(&gMysql); |
|---|
| 558 | unxsVZLog(uConfig,"tConfig","LocalConfigImport"); |
|---|
| 559 | return(uCount); |
|---|
| 560 | |
|---|
| 561 | }//unsigned LocalImportConfigJob(...) |
|---|