| 1 | /* |
|---|
| 2 | FILE |
|---|
| 3 | $Id$ |
|---|
| 4 | PURPOSE |
|---|
| 5 | Non-schema dependent tconfiguration.c expansion. |
|---|
| 6 | AUTHOR/LEGAL |
|---|
| 7 | (C) 2001-2010 Gary Wallis for Unixservice, LLC. |
|---|
| 8 | GPL License applies, see www.fsf.org for details |
|---|
| 9 | See LICENSE file in this distribution |
|---|
| 10 | */ |
|---|
| 11 | |
|---|
| 12 | void tConfigurationNavList(void); |
|---|
| 13 | unsigned CreateConfigurationFileJob(unsigned uConfiguration,unsigned uDatacenter,unsigned uNode,unsigned uContainer); |
|---|
| 14 | void htmlGlossaryLink(char *cLabel); |
|---|
| 15 | |
|---|
| 16 | void ExtProcesstConfigurationVars(pentry entries[], int x) |
|---|
| 17 | { |
|---|
| 18 | /* |
|---|
| 19 | register int i; |
|---|
| 20 | for(i=0;i<x;i++) |
|---|
| 21 | { |
|---|
| 22 | } |
|---|
| 23 | */ |
|---|
| 24 | }//void ExtProcesstConfigurationVars(pentry entries[], int x) |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | void ExttConfigurationCommands(pentry entries[], int x) |
|---|
| 28 | { |
|---|
| 29 | if(!strcmp(gcFunction,"tConfigurationTools")) |
|---|
| 30 | { |
|---|
| 31 | time_t uActualModDate; |
|---|
| 32 | |
|---|
| 33 | if(!strcmp(gcCommand,LANG_NB_NEW)) |
|---|
| 34 | { |
|---|
| 35 | if(guPermLevel>=10) |
|---|
| 36 | { |
|---|
| 37 | ProcesstConfigurationVars(entries,x); |
|---|
| 38 | guMode=2000; |
|---|
| 39 | tConfiguration(LANG_NB_CONFIRMNEW); |
|---|
| 40 | } |
|---|
| 41 | } |
|---|
| 42 | else if(!strcmp(gcCommand,LANG_NB_CONFIRMNEW)) |
|---|
| 43 | { |
|---|
| 44 | if(guPermLevel>=10) |
|---|
| 45 | { |
|---|
| 46 | ProcesstConfigurationVars(entries,x); |
|---|
| 47 | |
|---|
| 48 | guMode=2000; |
|---|
| 49 | //Check entries here |
|---|
| 50 | guMode=0; |
|---|
| 51 | |
|---|
| 52 | uConfiguration=0; |
|---|
| 53 | uCreatedBy=guLoginClient; |
|---|
| 54 | uOwner=guCompany; |
|---|
| 55 | uModBy=0;//Never modified |
|---|
| 56 | uModDate=0;//Never modified |
|---|
| 57 | NewtConfiguration(0); |
|---|
| 58 | } |
|---|
| 59 | } |
|---|
| 60 | else if(!strcmp(gcCommand,LANG_NB_DELETE)) |
|---|
| 61 | { |
|---|
| 62 | ProcesstConfigurationVars(entries,x); |
|---|
| 63 | if(uAllowDel(uOwner,uCreatedBy)) |
|---|
| 64 | { |
|---|
| 65 | guMode=2001; |
|---|
| 66 | tConfiguration("Make sure this is the record you would like to delete"); |
|---|
| 67 | } |
|---|
| 68 | } |
|---|
| 69 | else if(!strcmp(gcCommand,LANG_NB_CONFIRMDEL)) |
|---|
| 70 | { |
|---|
| 71 | ProcesstConfigurationVars(entries,x); |
|---|
| 72 | if(uAllowDel(uOwner,uCreatedBy)) |
|---|
| 73 | { |
|---|
| 74 | guMode=5; |
|---|
| 75 | DeletetConfiguration(); |
|---|
| 76 | } |
|---|
| 77 | } |
|---|
| 78 | else if(!strcmp(gcCommand,LANG_NB_MODIFY)) |
|---|
| 79 | { |
|---|
| 80 | ProcesstConfigurationVars(entries,x); |
|---|
| 81 | if(uAllowMod(uOwner,uCreatedBy)) |
|---|
| 82 | { |
|---|
| 83 | guMode=2002; |
|---|
| 84 | tConfiguration(LANG_NB_CONFIRMMOD); |
|---|
| 85 | } |
|---|
| 86 | } |
|---|
| 87 | else if(!strcmp(gcCommand,LANG_NB_CONFIRMMOD)) |
|---|
| 88 | { |
|---|
| 89 | ProcesstConfigurationVars(entries,x); |
|---|
| 90 | if(uAllowMod(uOwner,uCreatedBy)) |
|---|
| 91 | { |
|---|
| 92 | guMode=2002; |
|---|
| 93 | //Check entries here |
|---|
| 94 | guMode=0; |
|---|
| 95 | |
|---|
| 96 | uModBy=guLoginClient; |
|---|
| 97 | ModtConfiguration(); |
|---|
| 98 | } |
|---|
| 99 | } |
|---|
| 100 | else if(!strcmp(gcCommand,"Create File Job")) |
|---|
| 101 | { |
|---|
| 102 | ProcesstConfigurationVars(entries,x); |
|---|
| 103 | if(uAllowDel(uOwner,uCreatedBy) && guPermLevel>11 && guLoginClient==1) |
|---|
| 104 | { |
|---|
| 105 | unsigned uCount=0; |
|---|
| 106 | |
|---|
| 107 | if(uConfiguration==0) |
|---|
| 108 | tConfiguration("<blink>Error</blink>: uConfiguration==0!"); |
|---|
| 109 | |
|---|
| 110 | if(uDatacenter==0 && uNode!=0) |
|---|
| 111 | tConfiguration("<blink>Error</blink>: uDatacenter==0!"); |
|---|
| 112 | |
|---|
| 113 | |
|---|
| 114 | sscanf(ForeignKey("tConfiguration","uModDate",uConfiguration),"%lu",&uActualModDate); |
|---|
| 115 | |
|---|
| 116 | if(uModDate==uActualModDate) |
|---|
| 117 | { |
|---|
| 118 | uCount=CreateConfigurationFileJob(uConfiguration,uDatacenter, |
|---|
| 119 | uNode,uContainer); |
|---|
| 120 | if(uCount) |
|---|
| 121 | tConfiguration("CreateConfigurationFileJob() Done"); |
|---|
| 122 | else |
|---|
| 123 | tConfiguration("<blink>Error</blink>: No jobs created! Too specific?"); |
|---|
| 124 | } |
|---|
| 125 | else |
|---|
| 126 | { |
|---|
| 127 | tConfiguration("This record was modified. Reload it."); |
|---|
| 128 | } |
|---|
| 129 | } |
|---|
| 130 | } |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | }//void ExttConfigurationCommands(pentry entries[], int x) |
|---|
| 134 | |
|---|
| 135 | |
|---|
| 136 | void ExttConfigurationButtons(void) |
|---|
| 137 | { |
|---|
| 138 | |
|---|
| 139 | OpenFieldSet("tConfiguration Aux Panel",100); |
|---|
| 140 | switch(guMode) |
|---|
| 141 | { |
|---|
| 142 | case 2000: |
|---|
| 143 | printf("<p><u>Enter required data</u><br>"); |
|---|
| 144 | printf(LANG_NBB_CONFIRMNEW); |
|---|
| 145 | break; |
|---|
| 146 | |
|---|
| 147 | case 2001: |
|---|
| 148 | printf("<p>"); |
|---|
| 149 | printf(LANG_NBB_CONFIRMDEL); |
|---|
| 150 | break; |
|---|
| 151 | |
|---|
| 152 | case 2002: |
|---|
| 153 | printf("<p><u>Review record data</u><br>"); |
|---|
| 154 | printf(LANG_NBB_CONFIRMMOD); |
|---|
| 155 | break; |
|---|
| 156 | |
|---|
| 157 | default: |
|---|
| 158 | printf("<u>Table Tips</u><br>"); |
|---|
| 159 | printf("This table is used for configuration settings used by the " |
|---|
| 160 | "system that are of a more general nature than tProperty values. " |
|---|
| 161 | "Like tProperty if a tConfiguration.cLabel has an entry in tGlossary " |
|---|
| 162 | "then a link will be provided.<p>\n"); |
|---|
| 163 | tConfigurationNavList(); |
|---|
| 164 | printf("<p>"); |
|---|
| 165 | htmlGlossaryLink(cLabel); |
|---|
| 166 | |
|---|
| 167 | } |
|---|
| 168 | CloseFieldSet(); |
|---|
| 169 | |
|---|
| 170 | |
|---|
| 171 | |
|---|
| 172 | }//void ExttConfigurationButtons(void) |
|---|
| 173 | |
|---|
| 174 | |
|---|
| 175 | void ExttConfigurationAuxTable(void) |
|---|
| 176 | { |
|---|
| 177 | |
|---|
| 178 | }//void ExttConfigurationAuxTable(void) |
|---|
| 179 | |
|---|
| 180 | |
|---|
| 181 | void ExttConfigurationGetHook(entry gentries[], int x) |
|---|
| 182 | { |
|---|
| 183 | register int i; |
|---|
| 184 | |
|---|
| 185 | for(i=0;i<x;i++) |
|---|
| 186 | { |
|---|
| 187 | if(!strcmp(gentries[i].name,"uConfiguration")) |
|---|
| 188 | { |
|---|
| 189 | sscanf(gentries[i].val,"%u",&uConfiguration); |
|---|
| 190 | guMode=6; |
|---|
| 191 | } |
|---|
| 192 | } |
|---|
| 193 | tConfiguration(""); |
|---|
| 194 | |
|---|
| 195 | }//void ExttConfigurationGetHook(entry gentries[], int x) |
|---|
| 196 | |
|---|
| 197 | |
|---|
| 198 | void ExttConfigurationSelect(void) |
|---|
| 199 | { |
|---|
| 200 | if(guPermLevel>9) |
|---|
| 201 | ExtSelectPublic("tConfiguration",VAR_LIST_tConfiguration); |
|---|
| 202 | else |
|---|
| 203 | ExtSelect("tConfiguration",VAR_LIST_tConfiguration); |
|---|
| 204 | |
|---|
| 205 | }//void ExttConfigurationSelect(void) |
|---|
| 206 | |
|---|
| 207 | |
|---|
| 208 | void ExttConfigurationSelectRow(void) |
|---|
| 209 | { |
|---|
| 210 | if(guPermLevel>9) |
|---|
| 211 | ExtSelectRowPublic("tConfiguration",VAR_LIST_tConfiguration,uConfiguration); |
|---|
| 212 | else |
|---|
| 213 | ExtSelectRow("tConfiguration",VAR_LIST_tConfiguration,uConfiguration); |
|---|
| 214 | |
|---|
| 215 | }//void ExttConfigurationSelectRow(void) |
|---|
| 216 | |
|---|
| 217 | |
|---|
| 218 | void ExttConfigurationListSelect(void) |
|---|
| 219 | { |
|---|
| 220 | char cCat[512]; |
|---|
| 221 | |
|---|
| 222 | ExtListSelect("tConfiguration",VAR_LIST_tConfiguration); |
|---|
| 223 | |
|---|
| 224 | //Changes here must be reflected below in ExttConfigurationListFilter() |
|---|
| 225 | if(!strcmp(gcFilter,"uConfiguration")) |
|---|
| 226 | { |
|---|
| 227 | sscanf(gcCommand,"%u",&uConfiguration); |
|---|
| 228 | if(guPermLevel<10) |
|---|
| 229 | strcat(gcQuery," AND "); |
|---|
| 230 | else |
|---|
| 231 | strcat(gcQuery," WHERE "); |
|---|
| 232 | sprintf(cCat,"tConfiguration.uConfiguration=%u ORDER BY uConfiguration",uConfiguration); |
|---|
| 233 | strcat(gcQuery,cCat); |
|---|
| 234 | } |
|---|
| 235 | else if(1) |
|---|
| 236 | { |
|---|
| 237 | //None NO FILTER |
|---|
| 238 | strcpy(gcFilter,"None"); |
|---|
| 239 | strcat(gcQuery," ORDER BY uConfiguration"); |
|---|
| 240 | } |
|---|
| 241 | |
|---|
| 242 | }//void ExttConfigurationListSelect(void) |
|---|
| 243 | |
|---|
| 244 | |
|---|
| 245 | void ExttConfigurationListFilter(void) |
|---|
| 246 | { |
|---|
| 247 | //Filter |
|---|
| 248 | printf(" Filter on "); |
|---|
| 249 | printf("<select name=gcFilter>"); |
|---|
| 250 | if(strcmp(gcFilter,"uConfiguration")) |
|---|
| 251 | printf("<option>uConfiguration</option>"); |
|---|
| 252 | else |
|---|
| 253 | printf("<option selected>uConfiguration</option>"); |
|---|
| 254 | if(strcmp(gcFilter,"None")) |
|---|
| 255 | printf("<option>None</option>"); |
|---|
| 256 | else |
|---|
| 257 | printf("<option selected>None</option>"); |
|---|
| 258 | printf("</select>"); |
|---|
| 259 | |
|---|
| 260 | }//void ExttConfigurationListFilter(void) |
|---|
| 261 | |
|---|
| 262 | |
|---|
| 263 | void ExttConfigurationNavBar(void) |
|---|
| 264 | { |
|---|
| 265 | if(uOwner) GetClientOwner(uOwner,&guReseller); |
|---|
| 266 | |
|---|
| 267 | printf(LANG_NBB_SKIPFIRST); |
|---|
| 268 | printf(LANG_NBB_SKIPBACK); |
|---|
| 269 | printf(LANG_NBB_SEARCH); |
|---|
| 270 | |
|---|
| 271 | if(guPermLevel>=10) |
|---|
| 272 | printf(LANG_NBB_NEW); |
|---|
| 273 | |
|---|
| 274 | if(uAllowMod(uOwner,uCreatedBy)) |
|---|
| 275 | printf(LANG_NBB_MODIFY); |
|---|
| 276 | |
|---|
| 277 | if(uAllowDel(uOwner,uCreatedBy)) |
|---|
| 278 | printf(LANG_NBB_DELETE); |
|---|
| 279 | |
|---|
| 280 | if(uOwner) |
|---|
| 281 | printf(LANG_NBB_LIST); |
|---|
| 282 | |
|---|
| 283 | printf(LANG_NBB_SKIPNEXT); |
|---|
| 284 | printf(LANG_NBB_SKIPLAST); |
|---|
| 285 | |
|---|
| 286 | }//void ExttConfigurationNavBar(void) |
|---|
| 287 | |
|---|
| 288 | |
|---|
| 289 | void tConfigurationNavList(void) |
|---|
| 290 | { |
|---|
| 291 | MYSQL_RES *res; |
|---|
| 292 | MYSQL_ROW field; |
|---|
| 293 | |
|---|
| 294 | sprintf(gcQuery,"SELECT tConfiguration.uConfiguration,tConfiguration.cLabel," |
|---|
| 295 | " IFNULL(tDatacenter.cLabel,'AllDatacenters'),IFNULL(tNode.cLabel,'AllNodes')" |
|---|
| 296 | " FROM tConfiguration" |
|---|
| 297 | " LEFT JOIN tDatacenter ON tConfiguration.uDatacenter=tDatacenter.uDatacenter" |
|---|
| 298 | " LEFT JOIN tNode ON tConfiguration.uNode=tNode.uNode" |
|---|
| 299 | " ORDER BY tConfiguration.cLabel,tConfiguration.uDatacenter,tConfiguration.uNode"); |
|---|
| 300 | mysql_query(&gMysql,gcQuery); |
|---|
| 301 | if(mysql_errno(&gMysql)) |
|---|
| 302 | { |
|---|
| 303 | printf("<p><u>tConfigurationNavList</u><br>\n"); |
|---|
| 304 | printf("%s",mysql_error(&gMysql)); |
|---|
| 305 | return; |
|---|
| 306 | } |
|---|
| 307 | |
|---|
| 308 | res=mysql_store_result(&gMysql); |
|---|
| 309 | if(mysql_num_rows(res)) |
|---|
| 310 | { |
|---|
| 311 | printf("<p><u>tConfigurationNavList</u><br>\n"); |
|---|
| 312 | |
|---|
| 313 | while((field=mysql_fetch_row(res))) |
|---|
| 314 | printf("<a class=darkLink href=unxsVZ.cgi?gcFunction=tConfiguration&" |
|---|
| 315 | "uConfiguration=%s>%s/%s/%s</a><br>\n",field[0],field[1],field[2],field[3]); |
|---|
| 316 | } |
|---|
| 317 | mysql_free_result(res); |
|---|
| 318 | |
|---|
| 319 | }//void tConfigurationNavList(void) |
|---|
| 320 | |
|---|
| 321 | |
|---|
| 322 | unsigned CreateConfigurationFileJob(unsigned uConfiguration,unsigned uDatacenter,unsigned uNode,unsigned uContainer) |
|---|
| 323 | { |
|---|
| 324 | unsigned uCount=0; |
|---|
| 325 | MYSQL_RES *res; |
|---|
| 326 | MYSQL_ROW field; |
|---|
| 327 | |
|---|
| 328 | //All datacenters and all nodes, but no uContainers |
|---|
| 329 | if(uDatacenter==0 && uNode==0 && uContainer==0) |
|---|
| 330 | sprintf(gcQuery,"SELECT tNode.uDatacenter,tNode.uNode,0 FROM tNode"); |
|---|
| 331 | //Single selected datacenter and every node of that datacenter, but no uContainers |
|---|
| 332 | else if(uDatacenter!=0 && uNode==0 && uContainer==0) |
|---|
| 333 | sprintf(gcQuery,"SELECT tNode.uDatacenter,tNode.uNode,0 FROM tNode WHERE" |
|---|
| 334 | " tNode.uDatacenter=%u",uDatacenter); |
|---|
| 335 | //Single selected datacenter node, no container |
|---|
| 336 | else if(uDatacenter!=0 && uNode!=0 && uContainer==0) |
|---|
| 337 | sprintf(gcQuery,"SELECT tNode.uDatacenter,tNode.uNode,0 FROM tNode WHERE" |
|---|
| 338 | " tNode.uDatacenter=%u AND tNode.uNode=%u",uDatacenter,uNode); |
|---|
| 339 | |
|---|
| 340 | //Single containers |
|---|
| 341 | //Completely specified container. No migration ever happened. Seems useless to me now. |
|---|
| 342 | else if(uDatacenter!=0 && uNode!=0 && uContainer!=0) |
|---|
| 343 | sprintf(gcQuery,"SELECT tNode.uDatacenter,tNode.uNode,tContainer.uContainer FROM tNode,tContainer WHERE" |
|---|
| 344 | " tNode.uNode=tContainer.uNode AND tNode.uDatacenter=%u AND tNode.uNode=%u" |
|---|
| 345 | " AND tContainer.uContainer=%u",uDatacenter,uNode,uContainer); |
|---|
| 346 | //Find the datacenter and the node for a given container |
|---|
| 347 | else if(uDatacenter==0 && uNode==0 && uContainer!=0) |
|---|
| 348 | sprintf(gcQuery,"SELECT tNode.uDatacenter,tNode.uNode,tContainer.uContainer FROM tNode,tContainer WHERE" |
|---|
| 349 | " tNode.uNode=tContainer.uNode" |
|---|
| 350 | " AND tContainer.uContainer=%u",uContainer); |
|---|
| 351 | //Find the datacenter for a given container of a specified node |
|---|
| 352 | else if(uDatacenter==0 && uNode!=0 && uContainer!=0) |
|---|
| 353 | sprintf(gcQuery,"SELECT tNode.uDatacenter,tNode.uNode,tContainer.uContainer FROM tNode,tContainer WHERE" |
|---|
| 354 | " tNode.uNode=tContainer.uNode AND tNode.uNode=%u" |
|---|
| 355 | " AND tContainer.uContainer=%u",uNode,uContainer); |
|---|
| 356 | else if(1) |
|---|
| 357 | htmlPlainTextError("Unexpected CreateConfigurationFileJob() uDatacenter,uNode and uContainer combination"); |
|---|
| 358 | |
|---|
| 359 | mysql_query(&gMysql,gcQuery); |
|---|
| 360 | if(mysql_errno(&gMysql)) |
|---|
| 361 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 362 | res=mysql_store_result(&gMysql); |
|---|
| 363 | while((field=mysql_fetch_row(res))) |
|---|
| 364 | { |
|---|
| 365 | sprintf(gcQuery,"INSERT INTO tJob SET cLabel='CreateConfigurationFileJob()',cJobName='InstallConfigFile'" |
|---|
| 366 | ",uDatacenter=%s,uNode=%s,uContainer=%s" |
|---|
| 367 | ",cJobData='uConfiguration=%u;',uJobDate=UNIX_TIMESTAMP(NOW())+60" |
|---|
| 368 | ",uJobStatus=1" |
|---|
| 369 | ",uOwner=%u,uCreatedBy=%u,uCreatedDate=UNIX_TIMESTAMP(NOW())", |
|---|
| 370 | field[0],field[1],field[2], |
|---|
| 371 | uConfiguration,guLoginClient,guLoginClient); |
|---|
| 372 | mysql_query(&gMysql,gcQuery); |
|---|
| 373 | if(mysql_errno(&gMysql)) |
|---|
| 374 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 375 | uCount++; |
|---|
| 376 | } |
|---|
| 377 | mysql_free_result(res); |
|---|
| 378 | |
|---|
| 379 | return(uCount); |
|---|
| 380 | |
|---|
| 381 | }//unsigned CreateConfigurationFileJob() |
|---|