| 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/LEGAL |
|---|
| 8 | (C) 2001-2010 Gary Wallis. |
|---|
| 9 | GPLv2 license applies. See LICENSE file included. |
|---|
| 10 | */ |
|---|
| 11 | |
|---|
| 12 | #include <openisp/ucidr.h> |
|---|
| 13 | |
|---|
| 14 | void tIPReport(void); |
|---|
| 15 | void tIPNavList(unsigned uAvailable); |
|---|
| 16 | void tIPUsedButAvailableNavList(void); |
|---|
| 17 | void tIPUsedButAvailableFix(void); |
|---|
| 18 | |
|---|
| 19 | //uForClient: Create for, on 'New; |
|---|
| 20 | static unsigned uForClient=0; |
|---|
| 21 | static char cForClientPullDown[256]={""}; |
|---|
| 22 | static char cIPRange[32]={""}; |
|---|
| 23 | static char cSearch[32]={""}; |
|---|
| 24 | |
|---|
| 25 | void AddIPRange(char *cIPRange); |
|---|
| 26 | void DelIPRange(char *cIPRange); |
|---|
| 27 | |
|---|
| 28 | //extern |
|---|
| 29 | unsigned uGetSearchGroup(const char *gcUser); |
|---|
| 30 | |
|---|
| 31 | void ExtProcesstIPVars(pentry entries[], int x) |
|---|
| 32 | { |
|---|
| 33 | register int i; |
|---|
| 34 | for(i=0;i<x;i++) |
|---|
| 35 | { |
|---|
| 36 | if(!strcmp(entries[i].name,"cIPRange")) |
|---|
| 37 | sprintf(cIPRange,"%.31s",entries[i].val); |
|---|
| 38 | else if(!strcmp(entries[i].name,"cForClientPullDown")) |
|---|
| 39 | { |
|---|
| 40 | sprintf(cForClientPullDown,"%.255s",entries[i].val); |
|---|
| 41 | uForClient=ReadPullDown("tClient","cLabel",cForClientPullDown); |
|---|
| 42 | } |
|---|
| 43 | else if(!strcmp(entries[i].name,"cSearch")) |
|---|
| 44 | { |
|---|
| 45 | sprintf(cSearch,"%.31s",TextAreaSave(entries[i].val)); |
|---|
| 46 | } |
|---|
| 47 | } |
|---|
| 48 | }//void ExtProcesstIPVars(pentry entries[], int x) |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | void ExttIPCommands(pentry entries[], int x) |
|---|
| 52 | { |
|---|
| 53 | |
|---|
| 54 | if(!strcmp(gcFunction,"tIPTools")) |
|---|
| 55 | { |
|---|
| 56 | MYSQL_RES *res; |
|---|
| 57 | |
|---|
| 58 | if(!strncmp(gcCommand,"Set ",4) || !strncmp(gcCommand,"Group ",6) || !strncmp(gcCommand,"Delete Checked",14)) |
|---|
| 59 | { |
|---|
| 60 | ProcesstIPVars(entries,x); |
|---|
| 61 | guMode=12002; |
|---|
| 62 | tIP(gcCommand); |
|---|
| 63 | } |
|---|
| 64 | else if(!strcmp(gcCommand,"Reload Search Set")) |
|---|
| 65 | { |
|---|
| 66 | if(guPermLevel>=9) |
|---|
| 67 | { |
|---|
| 68 | ProcesstIPVars(entries,x); |
|---|
| 69 | guMode=12002; |
|---|
| 70 | tIP("Search set reloaded"); |
|---|
| 71 | } |
|---|
| 72 | else |
|---|
| 73 | { |
|---|
| 74 | tIP("<blink>Error:</blink> Denied by permissions settings"); |
|---|
| 75 | } |
|---|
| 76 | } |
|---|
| 77 | else if(!strcmp(gcCommand,"Remove from Search Set")) |
|---|
| 78 | { |
|---|
| 79 | if(guPermLevel>=9) |
|---|
| 80 | { |
|---|
| 81 | ProcesstIPVars(entries,x); |
|---|
| 82 | guMode=12002; |
|---|
| 83 | char cQuerySection[256]; |
|---|
| 84 | unsigned uLink=0; |
|---|
| 85 | unsigned uGroup=0; |
|---|
| 86 | |
|---|
| 87 | if(cIPv4Search[0]==0 && uDatacenterSearch==0 && uNodeSearch==0 && uNodeSearchNot==0 && uAvailableSearch==0 |
|---|
| 88 | && uOwnerSearch==0 && uIPv4Exclude==0) |
|---|
| 89 | tIP("You must specify at least one search parameter"); |
|---|
| 90 | |
|---|
| 91 | if((uGroup=uGetSearchGroup(gcUser))==0) |
|---|
| 92 | tIP("No search set exists. Please create one first."); |
|---|
| 93 | |
|---|
| 94 | //Initial query section |
|---|
| 95 | sprintf(gcQuery,"DELETE FROM tGroupGlue WHERE uGroup=%u AND uIP IN" |
|---|
| 96 | " (SELECT uIP FROM tIP WHERE",uGroup); |
|---|
| 97 | |
|---|
| 98 | if(cIPv4Search[0]) |
|---|
| 99 | { |
|---|
| 100 | sprintf(cQuerySection," uIP IN (SELECT uIP FROM tIP WHERE cLabel LIKE '%s%%')",cIPv4Search); |
|---|
| 101 | strcat(gcQuery,cQuerySection); |
|---|
| 102 | uLink=1; |
|---|
| 103 | } |
|---|
| 104 | else |
|---|
| 105 | { |
|---|
| 106 | uLink=0; |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | if(uDatacenterSearch) |
|---|
| 110 | { |
|---|
| 111 | if(uLink) |
|---|
| 112 | strcat(gcQuery," AND"); |
|---|
| 113 | sprintf(cQuerySection," uDatacenter=%u",uDatacenterSearch); |
|---|
| 114 | strcat(gcQuery,cQuerySection); |
|---|
| 115 | uLink=1; |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | if(uNodeSearch || uNodeSearchNot) |
|---|
| 119 | { |
|---|
| 120 | if(uLink) |
|---|
| 121 | strcat(gcQuery," AND"); |
|---|
| 122 | if(uNodeSearchNot && uNodeSearch ) |
|---|
| 123 | sprintf(cQuerySection," uIP IN (SELECT uIPv4 FROM tContainer WHERE uNode!=%u)",uNodeSearch); |
|---|
| 124 | else if(uNodeSearch) |
|---|
| 125 | sprintf(cQuerySection," uIP IN (SELECT uIPv4 FROM tContainer WHERE uNode=%u)",uNodeSearch); |
|---|
| 126 | else |
|---|
| 127 | sprintf(cQuerySection," uIP IN" |
|---|
| 128 | " (SELECT uIP FROM tIP LEFT JOIN tContainer ON tContainer.uIPv4=tIP.uIP" |
|---|
| 129 | " WHERE tContainer.cLabel IS NULL)"); |
|---|
| 130 | strcat(gcQuery,cQuerySection); |
|---|
| 131 | uLink=1; |
|---|
| 132 | } |
|---|
| 133 | |
|---|
| 134 | //YesNo tristate |
|---|
| 135 | if(uAvailableSearch) |
|---|
| 136 | { |
|---|
| 137 | if(uLink) |
|---|
| 138 | strcat(gcQuery," AND"); |
|---|
| 139 | if(uAvailableSearch==2)//Tri state Yes |
|---|
| 140 | sprintf(cQuerySection," uAvailable>0"); |
|---|
| 141 | else |
|---|
| 142 | sprintf(cQuerySection," uAvailable=0"); |
|---|
| 143 | strcat(gcQuery,cQuerySection); |
|---|
| 144 | uLink=1; |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | if(uOwnerSearch) |
|---|
| 148 | { |
|---|
| 149 | if(uLink) |
|---|
| 150 | strcat(gcQuery," AND"); |
|---|
| 151 | sprintf(cQuerySection," uOwner=%u",uOwnerSearch); |
|---|
| 152 | strcat(gcQuery,cQuerySection); |
|---|
| 153 | uLink=1; |
|---|
| 154 | } |
|---|
| 155 | |
|---|
| 156 | if(uIPv4Exclude) |
|---|
| 157 | { |
|---|
| 158 | if(uLink) |
|---|
| 159 | strcat(gcQuery," AND"); |
|---|
| 160 | sprintf(cQuerySection," cLabel NOT LIKE '10.%%.%%.%%' AND" |
|---|
| 161 | " cLabel NOT LIKE '172.16.%%.%%' AND" //This is only the first class C of the /12 |
|---|
| 162 | " cLabel NOT LIKE '192.168.%%.%%'"); |
|---|
| 163 | strcat(gcQuery,cQuerySection); |
|---|
| 164 | uLink=1; |
|---|
| 165 | } |
|---|
| 166 | |
|---|
| 167 | strcat(gcQuery,")"); |
|---|
| 168 | //debug only |
|---|
| 169 | //tIP(gcQuery); |
|---|
| 170 | |
|---|
| 171 | mysql_query(&gMysql,gcQuery); |
|---|
| 172 | if(mysql_errno(&gMysql)) |
|---|
| 173 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 174 | unsigned uNumber=0; |
|---|
| 175 | if((uNumber=mysql_affected_rows(&gMysql))>0) |
|---|
| 176 | { |
|---|
| 177 | sprintf(gcQuery,"%u tIP records were removed from your search set",uNumber); |
|---|
| 178 | tIP(gcQuery); |
|---|
| 179 | } |
|---|
| 180 | else |
|---|
| 181 | { |
|---|
| 182 | tIP("No records were removed from your search set"); |
|---|
| 183 | } |
|---|
| 184 | } |
|---|
| 185 | else |
|---|
| 186 | { |
|---|
| 187 | tIP("<blink>Error:</blink> Denied by permissions settings"); |
|---|
| 188 | } |
|---|
| 189 | } |
|---|
| 190 | else if(!strcmp(gcCommand,"Add to Search Set") || !strcmp(gcCommand,"Create Search Set")) |
|---|
| 191 | { |
|---|
| 192 | if(guPermLevel>=9) |
|---|
| 193 | { |
|---|
| 194 | ProcesstIPVars(entries,x); |
|---|
| 195 | guMode=12002; |
|---|
| 196 | char cQuerySection[256]; |
|---|
| 197 | unsigned uLink=0; |
|---|
| 198 | unsigned uGroup=0; |
|---|
| 199 | |
|---|
| 200 | if(cIPv4Search[0]==0 && uDatacenterSearch==0 && uNodeSearch==0 && uNodeSearchNot==0 && uAvailableSearch==0 |
|---|
| 201 | && uOwnerSearch==0 && uIPv4Exclude==0) |
|---|
| 202 | tIP("You must specify at least one search parameter"); |
|---|
| 203 | |
|---|
| 204 | if((uGroup=uGetSearchGroup(gcUser))==0) |
|---|
| 205 | { |
|---|
| 206 | sprintf(gcQuery,"INSERT INTO tGroup SET cLabel='%s',uGroupType=2"//2 is search group |
|---|
| 207 | ",uOwner=%u,uCreatedBy=%u,uCreatedDate=UNIX_TIMESTAMP(NOW())", |
|---|
| 208 | gcUser,guCompany,guLoginClient);//2=search set type TODO |
|---|
| 209 | mysql_query(&gMysql,gcQuery); |
|---|
| 210 | if(mysql_errno(&gMysql)) |
|---|
| 211 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 212 | if((uGroup=mysql_insert_id(&gMysql))==0) |
|---|
| 213 | tIP("An error ocurred when attempting to create your search set"); |
|---|
| 214 | } |
|---|
| 215 | else |
|---|
| 216 | { |
|---|
| 217 | if(!strcmp(gcCommand,"Create Search Set")) |
|---|
| 218 | { |
|---|
| 219 | sprintf(gcQuery,"DELETE FROM tGroupGlue WHERE uGroup=%u",uGroup); |
|---|
| 220 | mysql_query(&gMysql,gcQuery); |
|---|
| 221 | if(mysql_errno(&gMysql)) |
|---|
| 222 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 223 | } |
|---|
| 224 | } |
|---|
| 225 | |
|---|
| 226 | //Initial query section |
|---|
| 227 | sprintf(gcQuery,"INSERT INTO tGroupGlue (uGroup,uIP)" |
|---|
| 228 | " SELECT %u,uIP FROM tIP WHERE",uGroup); |
|---|
| 229 | |
|---|
| 230 | //Build AND query section |
|---|
| 231 | |
|---|
| 232 | if(cIPv4Search[0]) |
|---|
| 233 | { |
|---|
| 234 | sprintf(cQuerySection," uIP IN (SELECT uIP FROM tIP WHERE cLabel LIKE '%s%%')",cIPv4Search); |
|---|
| 235 | strcat(gcQuery,cQuerySection); |
|---|
| 236 | uLink=1; |
|---|
| 237 | } |
|---|
| 238 | else |
|---|
| 239 | { |
|---|
| 240 | uLink=0; |
|---|
| 241 | } |
|---|
| 242 | |
|---|
| 243 | if(uDatacenterSearch) |
|---|
| 244 | { |
|---|
| 245 | if(uLink) |
|---|
| 246 | strcat(gcQuery," AND"); |
|---|
| 247 | sprintf(cQuerySection," uDatacenter=%u",uDatacenterSearch); |
|---|
| 248 | strcat(gcQuery,cQuerySection); |
|---|
| 249 | uLink=1; |
|---|
| 250 | } |
|---|
| 251 | |
|---|
| 252 | if(uNodeSearch || uNodeSearchNot) |
|---|
| 253 | { |
|---|
| 254 | if(uLink) |
|---|
| 255 | strcat(gcQuery," AND"); |
|---|
| 256 | if(uNodeSearchNot && uNodeSearch ) |
|---|
| 257 | sprintf(cQuerySection," uIP IN (SELECT uIPv4 FROM tContainer WHERE uNode!=%u)",uNodeSearch); |
|---|
| 258 | else if(uNodeSearch) |
|---|
| 259 | sprintf(cQuerySection," uIP IN (SELECT uIPv4 FROM tContainer WHERE uNode=%u)",uNodeSearch); |
|---|
| 260 | else |
|---|
| 261 | sprintf(cQuerySection," uIP IN" |
|---|
| 262 | " (SELECT uIP FROM tIP LEFT JOIN tContainer ON tContainer.uIPv4=tIP.uIP" |
|---|
| 263 | " WHERE tContainer.cLabel IS NULL)"); |
|---|
| 264 | strcat(gcQuery,cQuerySection); |
|---|
| 265 | uLink=1; |
|---|
| 266 | } |
|---|
| 267 | |
|---|
| 268 | //YesNo tristate |
|---|
| 269 | if(uAvailableSearch) |
|---|
| 270 | { |
|---|
| 271 | if(uLink) |
|---|
| 272 | strcat(gcQuery," AND"); |
|---|
| 273 | if(uAvailableSearch==2)//Tri state Yes |
|---|
| 274 | sprintf(cQuerySection," uAvailable>0"); |
|---|
| 275 | else |
|---|
| 276 | sprintf(cQuerySection," uAvailable=0"); |
|---|
| 277 | strcat(gcQuery,cQuerySection); |
|---|
| 278 | uLink=1; |
|---|
| 279 | } |
|---|
| 280 | |
|---|
| 281 | if(uOwnerSearch) |
|---|
| 282 | { |
|---|
| 283 | if(uLink) |
|---|
| 284 | strcat(gcQuery," AND"); |
|---|
| 285 | sprintf(cQuerySection," uOwner=%u",uOwnerSearch); |
|---|
| 286 | strcat(gcQuery,cQuerySection); |
|---|
| 287 | uLink=1; |
|---|
| 288 | } |
|---|
| 289 | |
|---|
| 290 | if(uIPv4Exclude) |
|---|
| 291 | { |
|---|
| 292 | if(uLink) |
|---|
| 293 | strcat(gcQuery," AND"); |
|---|
| 294 | sprintf(cQuerySection," cLabel NOT LIKE '10.%%.%%.%%' AND" |
|---|
| 295 | " cLabel NOT LIKE '172.16.%%.%%' AND" //This is only the first class C of the /12 |
|---|
| 296 | " cLabel NOT LIKE '192.168.%%.%%'"); |
|---|
| 297 | strcat(gcQuery,cQuerySection); |
|---|
| 298 | uLink=1; |
|---|
| 299 | } |
|---|
| 300 | |
|---|
| 301 | //debug only |
|---|
| 302 | //tIP(gcQuery); |
|---|
| 303 | |
|---|
| 304 | mysql_query(&gMysql,gcQuery); |
|---|
| 305 | if(mysql_errno(&gMysql)) |
|---|
| 306 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 307 | unsigned uNumber=0; |
|---|
| 308 | if((uNumber=mysql_affected_rows(&gMysql))>0) |
|---|
| 309 | { |
|---|
| 310 | sprintf(gcQuery,"%u tIP records were added to your search set",uNumber); |
|---|
| 311 | tIP(gcQuery); |
|---|
| 312 | } |
|---|
| 313 | else |
|---|
| 314 | { |
|---|
| 315 | tIP("No records were added to your search set. Filter returned 0 records"); |
|---|
| 316 | } |
|---|
| 317 | } |
|---|
| 318 | else |
|---|
| 319 | { |
|---|
| 320 | tIP("<blink>Error:</blink> Denied by permissions settings"); |
|---|
| 321 | } |
|---|
| 322 | } |
|---|
| 323 | else if(!strcmp(gcCommand,"Search Set Operations")) |
|---|
| 324 | { |
|---|
| 325 | if(guPermLevel>=9) |
|---|
| 326 | { |
|---|
| 327 | guMode=12001; |
|---|
| 328 | tIP("Search Set Operations"); |
|---|
| 329 | } |
|---|
| 330 | else |
|---|
| 331 | { |
|---|
| 332 | tIP("<blink>Error:</blink> Denied by permissions settings"); |
|---|
| 333 | } |
|---|
| 334 | } |
|---|
| 335 | else if(!strcmp(gcCommand,LANG_NB_NEW)) |
|---|
| 336 | { |
|---|
| 337 | if(guPermLevel>=10) |
|---|
| 338 | { |
|---|
| 339 | ProcesstIPVars(entries,x); |
|---|
| 340 | guMode=2000; |
|---|
| 341 | tIP(LANG_NB_CONFIRMNEW); |
|---|
| 342 | } |
|---|
| 343 | else |
|---|
| 344 | { |
|---|
| 345 | tIP("Not allowed by permissions settings"); |
|---|
| 346 | } |
|---|
| 347 | } |
|---|
| 348 | else if(!strcmp(gcCommand,LANG_NB_CONFIRMNEW)) |
|---|
| 349 | { |
|---|
| 350 | if(guPermLevel>=10) |
|---|
| 351 | { |
|---|
| 352 | ProcesstIPVars(entries,x); |
|---|
| 353 | |
|---|
| 354 | guMode=2000; |
|---|
| 355 | //Check entries here |
|---|
| 356 | //1.2.3.4 min |
|---|
| 357 | if(strlen(cLabel)<7) |
|---|
| 358 | tIP("cLabel too short"); |
|---|
| 359 | if(!uDatacenter) |
|---|
| 360 | tIP("Must specify a uDatacenter"); |
|---|
| 361 | guMode=0; |
|---|
| 362 | |
|---|
| 363 | uIP=0; |
|---|
| 364 | uCreatedBy=guLoginClient; |
|---|
| 365 | if(uForClient) guCompany=uForClient; |
|---|
| 366 | uOwner=guCompany; |
|---|
| 367 | uModBy=0;//Never modified |
|---|
| 368 | uModDate=0;//Never modified |
|---|
| 369 | NewtIP(0); |
|---|
| 370 | } |
|---|
| 371 | else |
|---|
| 372 | { |
|---|
| 373 | tIP("Not allowed by permissions settings"); |
|---|
| 374 | } |
|---|
| 375 | } |
|---|
| 376 | else if(!strcmp(gcCommand,LANG_NB_DELETE)) |
|---|
| 377 | { |
|---|
| 378 | ProcesstIPVars(entries,x); |
|---|
| 379 | if((uAllowDel(uOwner,uCreatedBy) && uAvailable) || guPermLevel>=11) |
|---|
| 380 | { |
|---|
| 381 | guMode=0; |
|---|
| 382 | sprintf(gcQuery,"SELECT uIPv4 FROM tContainer WHERE uIPv4=%u",uIP); |
|---|
| 383 | mysql_query(&gMysql,gcQuery); |
|---|
| 384 | if(mysql_errno(&gMysql)) |
|---|
| 385 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 386 | res=mysql_store_result(&gMysql); |
|---|
| 387 | if(mysql_num_rows(res)) |
|---|
| 388 | { |
|---|
| 389 | mysql_free_result(res); |
|---|
| 390 | tIP("Can't delete an IP in use"); |
|---|
| 391 | } |
|---|
| 392 | guMode=2001; |
|---|
| 393 | tIP(LANG_NB_CONFIRMDEL); |
|---|
| 394 | } |
|---|
| 395 | else |
|---|
| 396 | { |
|---|
| 397 | tIP("Not allowed by permissions settings"); |
|---|
| 398 | } |
|---|
| 399 | } |
|---|
| 400 | else if(!strcmp(gcCommand,LANG_NB_CONFIRMDEL)) |
|---|
| 401 | { |
|---|
| 402 | ProcesstIPVars(entries,x); |
|---|
| 403 | if((uAllowDel(uOwner,uCreatedBy) && uAvailable) || guPermLevel>=11) |
|---|
| 404 | { |
|---|
| 405 | guMode=5; |
|---|
| 406 | if(cIPRange[0]) |
|---|
| 407 | { |
|---|
| 408 | if(uForClient) guCompany=uForClient; |
|---|
| 409 | DelIPRange(cIPRange); |
|---|
| 410 | } |
|---|
| 411 | else |
|---|
| 412 | { |
|---|
| 413 | sprintf(gcQuery,"SELECT uIPv4 FROM tContainer WHERE uIPv4=%u",uIP); |
|---|
| 414 | mysql_query(&gMysql,gcQuery); |
|---|
| 415 | if(mysql_errno(&gMysql)) |
|---|
| 416 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 417 | res=mysql_store_result(&gMysql); |
|---|
| 418 | if(mysql_num_rows(res)) |
|---|
| 419 | { |
|---|
| 420 | mysql_free_result(res); |
|---|
| 421 | guMode=2001; |
|---|
| 422 | tIP("Can't delete an IP in use"); |
|---|
| 423 | } |
|---|
| 424 | DeletetIP(); |
|---|
| 425 | } |
|---|
| 426 | } |
|---|
| 427 | else |
|---|
| 428 | { |
|---|
| 429 | tIP("Not allowed by permissions settings"); |
|---|
| 430 | } |
|---|
| 431 | } |
|---|
| 432 | else if(!strcmp(gcCommand,LANG_NB_MODIFY)) |
|---|
| 433 | { |
|---|
| 434 | ProcesstIPVars(entries,x); |
|---|
| 435 | if((uAllowMod(uOwner,uCreatedBy) && uAvailable) || guPermLevel>=11) |
|---|
| 436 | { |
|---|
| 437 | guMode=0; |
|---|
| 438 | sprintf(gcQuery,"SELECT uIPv4 FROM tContainer WHERE uIPv4=%u",uIP); |
|---|
| 439 | mysql_query(&gMysql,gcQuery); |
|---|
| 440 | if(mysql_errno(&gMysql)) |
|---|
| 441 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 442 | res=mysql_store_result(&gMysql); |
|---|
| 443 | if(mysql_num_rows(res)) |
|---|
| 444 | { |
|---|
| 445 | mysql_free_result(res); |
|---|
| 446 | tIP("Can't modify an IP in use"); |
|---|
| 447 | } |
|---|
| 448 | guMode=2002; |
|---|
| 449 | tIP(LANG_NB_CONFIRMMOD); |
|---|
| 450 | } |
|---|
| 451 | else |
|---|
| 452 | { |
|---|
| 453 | tIP("Not allowed by permissions settings"); |
|---|
| 454 | } |
|---|
| 455 | } |
|---|
| 456 | else if(!strcmp(gcCommand,LANG_NB_CONFIRMMOD)) |
|---|
| 457 | { |
|---|
| 458 | ProcesstIPVars(entries,x); |
|---|
| 459 | if((uAllowMod(uOwner,uCreatedBy)) || guPermLevel>=11) |
|---|
| 460 | { |
|---|
| 461 | guMode=2002; |
|---|
| 462 | sprintf(gcQuery,"SELECT uIPv4 FROM tContainer WHERE uIPv4=%u",uIP); |
|---|
| 463 | mysql_query(&gMysql,gcQuery); |
|---|
| 464 | if(mysql_errno(&gMysql)) |
|---|
| 465 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 466 | res=mysql_store_result(&gMysql); |
|---|
| 467 | if(mysql_num_rows(res)) |
|---|
| 468 | { |
|---|
| 469 | mysql_free_result(res); |
|---|
| 470 | tIP("Can't modify an IP in use"); |
|---|
| 471 | } |
|---|
| 472 | if(strlen(cLabel)<7) |
|---|
| 473 | tIP("cLabel too short"); |
|---|
| 474 | if(!uDatacenter) |
|---|
| 475 | tIP("Must specify a uDatacenter"); |
|---|
| 476 | guMode=0; |
|---|
| 477 | |
|---|
| 478 | if(uForClient) |
|---|
| 479 | { |
|---|
| 480 | guCompany=uForClient; |
|---|
| 481 | if(!cIPRange[0]) |
|---|
| 482 | { |
|---|
| 483 | uOwner=guCompany; |
|---|
| 484 | sprintf(gcQuery,"UPDATE tIP SET uOwner=%u WHERE uAvailable=1 AND uIP=%u", |
|---|
| 485 | guCompany,uIP); |
|---|
| 486 | mysql_query(&gMysql,gcQuery); |
|---|
| 487 | if(mysql_errno(&gMysql)) |
|---|
| 488 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 489 | } |
|---|
| 490 | } |
|---|
| 491 | if(cIPRange[0]) |
|---|
| 492 | AddIPRange(cIPRange); |
|---|
| 493 | uModBy=guLoginClient; |
|---|
| 494 | ModtIP(); |
|---|
| 495 | } |
|---|
| 496 | else |
|---|
| 497 | { |
|---|
| 498 | tIP("Not allowed by permissions settings"); |
|---|
| 499 | } |
|---|
| 500 | } |
|---|
| 501 | else if(!strcmp(gcCommand,"Fix")) |
|---|
| 502 | { |
|---|
| 503 | ProcesstIPVars(entries,x); |
|---|
| 504 | if((uAllowMod(uOwner,uCreatedBy)) || guPermLevel>=11) |
|---|
| 505 | { |
|---|
| 506 | tIPUsedButAvailableFix(); |
|---|
| 507 | } |
|---|
| 508 | else |
|---|
| 509 | { |
|---|
| 510 | tIP("Not allowed by permissions settings"); |
|---|
| 511 | } |
|---|
| 512 | } |
|---|
| 513 | } |
|---|
| 514 | |
|---|
| 515 | }//void ExttIPCommands(pentry entries[], int x) |
|---|
| 516 | |
|---|
| 517 | |
|---|
| 518 | void ExttIPButtons(void) |
|---|
| 519 | { |
|---|
| 520 | OpenFieldSet("tIP Aux Panel",100); |
|---|
| 521 | switch(guMode) |
|---|
| 522 | { |
|---|
| 523 | case 12001: |
|---|
| 524 | case 12002: |
|---|
| 525 | printf("<u>Create or refine your user search set</u><br>"); |
|---|
| 526 | printf("In the right panel you can select your search criteria. When refining you do not need" |
|---|
| 527 | " to reuse your initial search critieria. Your search set is persistent even across unxsVZ sessions.<p>"); |
|---|
| 528 | printf("<input type=submit class=largeButton title='Create an initial or replace an existing search set'" |
|---|
| 529 | " name=gcCommand value='Create Search Set'>"); |
|---|
| 530 | printf("<input type=submit class=largeButton title='Add the results to your current search set. Do not add the same search" |
|---|
| 531 | " over and over again it will not result in any change but may slow down processing.'" |
|---|
| 532 | " name=gcCommand value='Add to Search Set'>"); |
|---|
| 533 | printf("<p><input type=submit class=largeButton title='Apply the right panel filter to refine your existing search set" |
|---|
| 534 | " by removing set elements that match the filter settings.'" |
|---|
| 535 | " name=gcCommand value='Remove from Search Set'>\n"); |
|---|
| 536 | printf("<p><input type=submit class=largeButton title='Reload current search set. Good for checking for any new status updates'" |
|---|
| 537 | " name=gcCommand value='Reload Search Set'>"); |
|---|
| 538 | printf("<input type=submit class=largeButton title='Return to main tContainer tab page'" |
|---|
| 539 | " name=gcCommand value='Cancel'>"); |
|---|
| 540 | printf("<p><u>Set Operation Options</u>"); |
|---|
| 541 | |
|---|
| 542 | break; |
|---|
| 543 | |
|---|
| 544 | case 2000: |
|---|
| 545 | printf("<p><u>Enter/mod data</u><br>"); |
|---|
| 546 | tTablePullDownResellers(uForClient,1); |
|---|
| 547 | if(cSearch[0]) |
|---|
| 548 | printf("<input type=hidden name=cSearch value='%s'>",cSearch); |
|---|
| 549 | printf(LANG_NBB_CONFIRMNEW); |
|---|
| 550 | break; |
|---|
| 551 | |
|---|
| 552 | case 2001: |
|---|
| 553 | printf("<p><u>Think twice</u>"); |
|---|
| 554 | printf("<p>Here you can delete a single record or optionally a complete block of IPs." |
|---|
| 555 | " In the later case you specify a uOwner company to limit the deletion."); |
|---|
| 556 | printf("<p>cIPRange<br>\n"); |
|---|
| 557 | printf("<input title='Optionally enter CIDR IP Range (ex. 10.0.0.1/27) for available mass deletion'" |
|---|
| 558 | " type=text name=cIPRange><p>\n"); |
|---|
| 559 | tTablePullDownResellers(uForClient,1); |
|---|
| 560 | if(cSearch[0]) |
|---|
| 561 | printf("<input type=hidden name=cSearch value='%s'>",cSearch); |
|---|
| 562 | printf(LANG_NBB_CONFIRMDEL); |
|---|
| 563 | break; |
|---|
| 564 | |
|---|
| 565 | case 2002: |
|---|
| 566 | printf("<p><u>Review changes</u><br>"); |
|---|
| 567 | printf("Change a single record or optionally add a block of available IPs. In all cases you must" |
|---|
| 568 | " specify a uDatacenter and optionally a new company (uOwner) if your" |
|---|
| 569 | " permissions allow.<br>"); |
|---|
| 570 | printf("<p>cIPRange<br>\n"); |
|---|
| 571 | printf("<input title='Optionally enter CIDR IP Range (ex. 10.0.0.1/27) for available mass addition'" |
|---|
| 572 | " type=text name=cIPRange value='%s'><p>\n",cIPRange); |
|---|
| 573 | tTablePullDownResellers(uForClient,1); |
|---|
| 574 | if(cSearch[0]) |
|---|
| 575 | printf("<input type=hidden name=cSearch value='%s'>",cSearch); |
|---|
| 576 | printf(LANG_NBB_CONFIRMMOD); |
|---|
| 577 | break; |
|---|
| 578 | |
|---|
| 579 | default: |
|---|
| 580 | printf("<p><u>Table Tips</u><br>"); |
|---|
| 581 | printf("IPs used and available for container and new hardware node" |
|---|
| 582 | " deployment are tracked and maintained here.<p>You can add available IPs <i>en masse</i>" |
|---|
| 583 | " via the cIPRange at the [Modify] stage. For example 192.168.0.1/28 would add 16 IPs" |
|---|
| 584 | " starting at 192.168.0.1 and ending at 192.168.0.16." |
|---|
| 585 | " To add an initial range use [New], then [Modify], enter new CIDR range." |
|---|
| 586 | "<p>You can also delete available IPs <i>en masse</i> via the cIPRange at the [Delete]" |
|---|
| 587 | " stage."); |
|---|
| 588 | printf("<p><input type=submit class=largeButton title='Open user search set page. There you can create search sets and operate" |
|---|
| 589 | " on selected containers of the loaded container set.'" |
|---|
| 590 | " name=gcCommand value='Search Set Operations'>\n"); |
|---|
| 591 | |
|---|
| 592 | printf("<p><u>Filter by cLabel</u><br>"); |
|---|
| 593 | printf("<input title='Enter cLabel start or MySQL LIKE pattern (%% or _ allowed)' type=text" |
|---|
| 594 | " name=cSearch value='%s'>",cSearch); |
|---|
| 595 | tIPNavList(0); |
|---|
| 596 | } |
|---|
| 597 | CloseFieldSet(); |
|---|
| 598 | |
|---|
| 599 | }//void ExttIPButtons(void) |
|---|
| 600 | |
|---|
| 601 | |
|---|
| 602 | void ExttIPAuxTable(void) |
|---|
| 603 | { |
|---|
| 604 | MYSQL_RES *res; |
|---|
| 605 | MYSQL_ROW field; |
|---|
| 606 | unsigned uGroup=0; |
|---|
| 607 | unsigned uNumRows=0; |
|---|
| 608 | |
|---|
| 609 | switch(guMode) |
|---|
| 610 | { |
|---|
| 611 | case 12001: |
|---|
| 612 | case 12002: |
|---|
| 613 | //Set operation buttons |
|---|
| 614 | OpenFieldSet("Set Operations",100); |
|---|
| 615 | printf("<input title='Delete checked containers from your search set. They will still be visible but will" |
|---|
| 616 | " marked deleted and will not be used in any subsequent set operation'" |
|---|
| 617 | " type=submit class=largeButton name=gcCommand value='Delete Checked'>\n"); |
|---|
| 618 | printf(" <input title='Deletes IPs not in use by containers.'" |
|---|
| 619 | " type=submit class=largeButton" |
|---|
| 620 | " name=gcCommand value='Group Delete'>\n"); |
|---|
| 621 | printf(" <input title='Updates IPs to uAvailable=1 for IPs not in use by containers.'" |
|---|
| 622 | " type=submit class=largeButton" |
|---|
| 623 | " name=gcCommand value='Group Make Available'>\n"); |
|---|
| 624 | CloseFieldSet(); |
|---|
| 625 | |
|---|
| 626 | sprintf(gcQuery,"Search Set Contents"); |
|---|
| 627 | OpenFieldSet(gcQuery,100); |
|---|
| 628 | uGroup=uGetSearchGroup(gcUser); |
|---|
| 629 | sprintf(gcQuery,"SELECT" |
|---|
| 630 | " tIP.uIP," |
|---|
| 631 | " tIP.cLabel," |
|---|
| 632 | " IF(tIP.uAvailable>0,'Yes','No')," |
|---|
| 633 | " IFNULL(tDatacenter.cLabel,'')," |
|---|
| 634 | " IFNULL(tNode.cLabel,'')," |
|---|
| 635 | " IFNULL(tContainer.cHostname,'')," |
|---|
| 636 | " tClient.cLabel," |
|---|
| 637 | " FROM_UNIXTIME(tIP.uModDate,'%%a %%b %%d %%T %%Y')," |
|---|
| 638 | " tIP.cComment" |
|---|
| 639 | " FROM tIP" |
|---|
| 640 | " LEFT JOIN tContainer ON tContainer.uIPv4=tIP.uIP" |
|---|
| 641 | " LEFT JOIN tDatacenter ON tIP.uDatacenter=tDatacenter.uDatacenter" |
|---|
| 642 | " LEFT JOIN tNode ON tContainer.uNode=tNode.uNode" |
|---|
| 643 | " LEFT JOIN tClient ON tIP.uOwner=tClient.uClient" |
|---|
| 644 | " WHERE uIP IN (SELECT uIP FROM tGroupGlue WHERE uGroup=%u)",uGroup); |
|---|
| 645 | mysql_query(&gMysql,gcQuery); |
|---|
| 646 | if(mysql_errno(&gMysql)) |
|---|
| 647 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 648 | res=mysql_store_result(&gMysql); |
|---|
| 649 | if((uNumRows=mysql_num_rows(res))) |
|---|
| 650 | { |
|---|
| 651 | char cResult[100]={""}; |
|---|
| 652 | char cCtLabel[100]={""}; |
|---|
| 653 | |
|---|
| 654 | printf("<table>"); |
|---|
| 655 | printf("<tr>"); |
|---|
| 656 | printf("<td><u>cLabel</u></td>" |
|---|
| 657 | "<td><u>Available</u></td>" |
|---|
| 658 | "<td><u>Datacenter</u></td>" |
|---|
| 659 | "<td><u>Node</u></td>" |
|---|
| 660 | "<td><u>Hostname</u></td>" |
|---|
| 661 | "<td><u>Owner</u></td>" |
|---|
| 662 | "<td><u>ModifiedDate</u></td>" |
|---|
| 663 | "<td><u>Comment</u></td>" |
|---|
| 664 | "<td><u>Set operation result</u></td></tr>"); |
|---|
| 665 | //Reset margin start |
|---|
| 666 | while((field=mysql_fetch_row(res))) |
|---|
| 667 | { |
|---|
| 668 | if(guMode==12002) |
|---|
| 669 | { |
|---|
| 670 | register int i; |
|---|
| 671 | unsigned uCtIP=0; |
|---|
| 672 | |
|---|
| 673 | cResult[0]=0; |
|---|
| 674 | sscanf(field[0],"%u",&uCtIP); |
|---|
| 675 | sprintf(cCtLabel,"Ct%u",uCtIP); |
|---|
| 676 | for(i=0;i<x;i++) |
|---|
| 677 | { |
|---|
| 678 | //insider xss protection |
|---|
| 679 | if(guPermLevel<10) |
|---|
| 680 | continue; |
|---|
| 681 | |
|---|
| 682 | if(!strcmp(entries[i].name,cCtLabel)) |
|---|
| 683 | { |
|---|
| 684 | if(!strcmp(gcCommand,"Delete Checked")) |
|---|
| 685 | { |
|---|
| 686 | sprintf(gcQuery,"DELETE FROM tGroupGlue WHERE uGroup=%u AND uIP=%u",uGroup,uCtIP); |
|---|
| 687 | mysql_query(&gMysql,gcQuery); |
|---|
| 688 | if(mysql_errno(&gMysql)) |
|---|
| 689 | { |
|---|
| 690 | sprintf(cResult,mysql_error(&gMysql)); |
|---|
| 691 | break; |
|---|
| 692 | } |
|---|
| 693 | if(mysql_affected_rows(&gMysql)>0) |
|---|
| 694 | sprintf(cResult,"Deleted from set"); |
|---|
| 695 | else |
|---|
| 696 | sprintf(cResult,"Unexpected non deletion"); |
|---|
| 697 | break; |
|---|
| 698 | }//Delete Checked |
|---|
| 699 | |
|---|
| 700 | //Group Delete |
|---|
| 701 | else if(!strcmp(gcCommand,"Group Delete")) |
|---|
| 702 | { |
|---|
| 703 | MYSQL_RES *res; |
|---|
| 704 | |
|---|
| 705 | sprintf(gcQuery,"DELETE FROM tGroupGlue WHERE uGroup=%u AND uIP=%u",uGroup,uCtIP); |
|---|
| 706 | mysql_query(&gMysql,gcQuery); |
|---|
| 707 | if(mysql_errno(&gMysql)) |
|---|
| 708 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 709 | |
|---|
| 710 | sprintf(gcQuery,"SELECT uIPv4 FROM tContainer WHERE uIPv4=%u",uCtIP); |
|---|
| 711 | mysql_query(&gMysql,gcQuery); |
|---|
| 712 | if(mysql_errno(&gMysql)) |
|---|
| 713 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 714 | res=mysql_store_result(&gMysql); |
|---|
| 715 | if(mysql_num_rows(res)>0) |
|---|
| 716 | { |
|---|
| 717 | sprintf(cResult,"IP in use"); |
|---|
| 718 | break; |
|---|
| 719 | } |
|---|
| 720 | |
|---|
| 721 | sprintf(gcQuery,"DELETE FROM tIP WHERE uIP=%u",uCtIP); |
|---|
| 722 | mysql_query(&gMysql,gcQuery); |
|---|
| 723 | if(mysql_errno(&gMysql)) |
|---|
| 724 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 725 | if(mysql_affected_rows(&gMysql)>0) |
|---|
| 726 | sprintf(cResult,"group delete done"); |
|---|
| 727 | else |
|---|
| 728 | cResult[0]=0; |
|---|
| 729 | break; |
|---|
| 730 | }//Group Delete |
|---|
| 731 | |
|---|
| 732 | |
|---|
| 733 | //Group Make Available |
|---|
| 734 | else if(!strcmp(gcCommand,"Group Make Available")) |
|---|
| 735 | { |
|---|
| 736 | MYSQL_RES *res; |
|---|
| 737 | |
|---|
| 738 | sprintf(gcQuery,"SELECT uIPv4 FROM tContainer WHERE uIPv4=%u",uCtIP); |
|---|
| 739 | mysql_query(&gMysql,gcQuery); |
|---|
| 740 | if(mysql_errno(&gMysql)) |
|---|
| 741 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 742 | res=mysql_store_result(&gMysql); |
|---|
| 743 | if(mysql_num_rows(res)>0) |
|---|
| 744 | { |
|---|
| 745 | sprintf(cResult,"IP in use"); |
|---|
| 746 | break; |
|---|
| 747 | } |
|---|
| 748 | |
|---|
| 749 | sprintf(gcQuery,"UPDATE tIP SET uAvailable=1 WHERE uIP=%u AND uAvailable=0",uCtIP); |
|---|
| 750 | mysql_query(&gMysql,gcQuery); |
|---|
| 751 | if(mysql_errno(&gMysql)) |
|---|
| 752 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 753 | if(mysql_affected_rows(&gMysql)>0) |
|---|
| 754 | sprintf(cResult,"make available done"); |
|---|
| 755 | else |
|---|
| 756 | cResult[0]=0; |
|---|
| 757 | break; |
|---|
| 758 | }//Group Make Available |
|---|
| 759 | |
|---|
| 760 | else if(1) |
|---|
| 761 | { |
|---|
| 762 | sprintf(cResult,"Unexpected gcCommand=%.64s",gcCommand); |
|---|
| 763 | break; |
|---|
| 764 | } |
|---|
| 765 | }//end if Ct block |
|---|
| 766 | }//end for() |
|---|
| 767 | } |
|---|
| 768 | |
|---|
| 769 | printf("<tr>"); |
|---|
| 770 | printf("<td width=200 valign=top>" |
|---|
| 771 | "<input type=checkbox name=Ct%s >" //0 |
|---|
| 772 | "<a class=darkLink href=unxsVZ.cgi?gcFunction=tIP&uIP=%s>%s</a>" //0 and 1 |
|---|
| 773 | "</td>" |
|---|
| 774 | "<td>%s</td>" //2 |
|---|
| 775 | "<td>%s</td>" //3 |
|---|
| 776 | "<td>%s</td>" //4 |
|---|
| 777 | "<td>%s</td>" //5 |
|---|
| 778 | "<td>%s</td>" //6 |
|---|
| 779 | "<td>%s</td>" //7 |
|---|
| 780 | "<td>%s</td>" //8 |
|---|
| 781 | "<td>%s</td>\n", //cResult |
|---|
| 782 | field[0],field[0],field[1],field[2],field[3],field[4],field[5],field[6],field[7],field[8],cResult); |
|---|
| 783 | printf("</tr>"); |
|---|
| 784 | |
|---|
| 785 | }//while() |
|---|
| 786 | //Reset margin end |
|---|
| 787 | |
|---|
| 788 | printf("<tr><td><input type=checkbox name=all onClick='checkAll(document.formMain,this)'>" |
|---|
| 789 | "Check all %u IPs</td></tr>\n",uNumRows); |
|---|
| 790 | printf("</table>"); |
|---|
| 791 | |
|---|
| 792 | }//If results |
|---|
| 793 | mysql_free_result(res); |
|---|
| 794 | CloseFieldSet(); |
|---|
| 795 | break; |
|---|
| 796 | |
|---|
| 797 | default: |
|---|
| 798 | ; |
|---|
| 799 | |
|---|
| 800 | }//switch(guMode) |
|---|
| 801 | |
|---|
| 802 | }//void ExttContainerAuxTable(void) |
|---|
| 803 | |
|---|
| 804 | |
|---|
| 805 | |
|---|
| 806 | void ExttIPGetHook(entry gentries[], int x) |
|---|
| 807 | { |
|---|
| 808 | register int i; |
|---|
| 809 | |
|---|
| 810 | for(i=0;i<x;i++) |
|---|
| 811 | { |
|---|
| 812 | if(!strcmp(gentries[i].name,"uIP")) |
|---|
| 813 | { |
|---|
| 814 | sscanf(gentries[i].val,"%u",&uIP); |
|---|
| 815 | guMode=6; |
|---|
| 816 | } |
|---|
| 817 | else if(!strcmp(gentries[i].name,"cSearch")) |
|---|
| 818 | { |
|---|
| 819 | sprintf(cSearch,"%.31s",gentries[i].val); |
|---|
| 820 | } |
|---|
| 821 | } |
|---|
| 822 | tIP(""); |
|---|
| 823 | |
|---|
| 824 | }//void ExttIPGetHook(entry gentries[], int x) |
|---|
| 825 | |
|---|
| 826 | |
|---|
| 827 | void ExttIPSelect(void) |
|---|
| 828 | { |
|---|
| 829 | if(cSearch[0]) |
|---|
| 830 | ExtSelectSearchPublic("tIP",VAR_LIST_tIP,"cLabel",cSearch); |
|---|
| 831 | else |
|---|
| 832 | ExtSelectPublic("tIP",VAR_LIST_tIP); |
|---|
| 833 | |
|---|
| 834 | }//void ExttIPSelect(void) |
|---|
| 835 | |
|---|
| 836 | |
|---|
| 837 | void ExttIPSelectRow(void) |
|---|
| 838 | { |
|---|
| 839 | ExtSelectRowPublic("tIP",VAR_LIST_tIP,uIP); |
|---|
| 840 | |
|---|
| 841 | }//void ExttIPSelectRow(void) |
|---|
| 842 | |
|---|
| 843 | |
|---|
| 844 | void ExttIPListSelect(void) |
|---|
| 845 | { |
|---|
| 846 | char cCat[512]; |
|---|
| 847 | |
|---|
| 848 | ExtListSelectPublic("tIP",VAR_LIST_tIP); |
|---|
| 849 | |
|---|
| 850 | //Changes here must be reflected below in ExttIPListFilter() |
|---|
| 851 | if(!strcmp(gcFilter,"uIP")) |
|---|
| 852 | { |
|---|
| 853 | sscanf(gcCommand,"%u",&uIP); |
|---|
| 854 | sprintf(cCat," WHERE tIP.uIP=%u ORDER BY uIP",uIP); |
|---|
| 855 | strcat(gcQuery,cCat); |
|---|
| 856 | } |
|---|
| 857 | else if(1) |
|---|
| 858 | { |
|---|
| 859 | //None NO FILTER |
|---|
| 860 | strcpy(gcFilter,"None"); |
|---|
| 861 | strcat(gcQuery," ORDER BY uIP"); |
|---|
| 862 | } |
|---|
| 863 | |
|---|
| 864 | }//void ExttIPListSelect(void) |
|---|
| 865 | |
|---|
| 866 | |
|---|
| 867 | void ExttIPListFilter(void) |
|---|
| 868 | { |
|---|
| 869 | //Filter |
|---|
| 870 | printf(" Filter on "); |
|---|
| 871 | printf("<select name=gcFilter>"); |
|---|
| 872 | if(strcmp(gcFilter,"uIP")) |
|---|
| 873 | printf("<option>uIP</option>"); |
|---|
| 874 | else |
|---|
| 875 | printf("<option selected>uIP</option>"); |
|---|
| 876 | if(strcmp(gcFilter,"None")) |
|---|
| 877 | printf("<option>None</option>"); |
|---|
| 878 | else |
|---|
| 879 | printf("<option selected>None</option>"); |
|---|
| 880 | printf("</select>"); |
|---|
| 881 | |
|---|
| 882 | }//void ExttIPListFilter(void) |
|---|
| 883 | |
|---|
| 884 | |
|---|
| 885 | void ExttIPNavBar(void) |
|---|
| 886 | { |
|---|
| 887 | printf(LANG_NBB_SKIPFIRST); |
|---|
| 888 | printf(LANG_NBB_SKIPBACK); |
|---|
| 889 | printf(LANG_NBB_SEARCH); |
|---|
| 890 | |
|---|
| 891 | if(guPermLevel>=10 && !guListMode) |
|---|
| 892 | printf(LANG_NBB_NEW); |
|---|
| 893 | |
|---|
| 894 | if((uAllowMod(uOwner,uCreatedBy) && uAvailable) || guPermLevel>=11) |
|---|
| 895 | printf(LANG_NBB_MODIFY); |
|---|
| 896 | |
|---|
| 897 | if((uAllowMod(uOwner,uCreatedBy) && uAvailable) || guPermLevel>=11) |
|---|
| 898 | printf(LANG_NBB_DELETE); |
|---|
| 899 | |
|---|
| 900 | if(uOwner) |
|---|
| 901 | printf(LANG_NBB_LIST); |
|---|
| 902 | |
|---|
| 903 | printf(LANG_NBB_SKIPNEXT); |
|---|
| 904 | printf(LANG_NBB_SKIPLAST); |
|---|
| 905 | printf(" \n"); |
|---|
| 906 | |
|---|
| 907 | }//void ExttIPNavBar(void) |
|---|
| 908 | |
|---|
| 909 | |
|---|
| 910 | void tIPNavList(unsigned uAvailable) |
|---|
| 911 | { |
|---|
| 912 | MYSQL_RES *res; |
|---|
| 913 | MYSQL_ROW field; |
|---|
| 914 | unsigned uNumRows=0; |
|---|
| 915 | unsigned uMySQLNumRows=0; |
|---|
| 916 | #define uLIMIT 32 |
|---|
| 917 | |
|---|
| 918 | if(guPermLevel>11) |
|---|
| 919 | { |
|---|
| 920 | if(cSearch[0]) |
|---|
| 921 | sprintf(gcQuery,"SELECT tIP.uIP,tIP.cLabel,tContainer.cLabel,tContainer.uContainer FROM" |
|---|
| 922 | " tIP LEFT JOIN tContainer ON tContainer.uIPv4=tIP.uIP WHERE tIP.uAvailable=%u" |
|---|
| 923 | " AND tIP.cLabel LIKE '%s%%' ORDER BY tIP.cLabel",uAvailable,cSearch); |
|---|
| 924 | else |
|---|
| 925 | sprintf(gcQuery,"SELECT tIP.uIP,tIP.cLabel,tContainer.cLabel,tContainer.uContainer FROM" |
|---|
| 926 | " tIP LEFT JOIN tContainer ON tContainer.uIPv4=tIP.uIP WHERE" |
|---|
| 927 | " tIP.uAvailable=%u ORDER BY tIP.cLabel",uAvailable); |
|---|
| 928 | } |
|---|
| 929 | else |
|---|
| 930 | { |
|---|
| 931 | if(cSearch[0]) |
|---|
| 932 | sprintf(gcQuery,"SELECT tIP.uIP,tIP.cLabel,tContainer.cLabel,tContainer.uContainer FROM" |
|---|
| 933 | " tIP LEFT JOIN tContainer ON tContainer.uIPv4=tIP.uIP WHERE" |
|---|
| 934 | " tIP.uAvailable=%u AND tIP.cLabel LIKE '%s%%' AND" |
|---|
| 935 | " tIP.uOwner=%u ORDER BY tIP.cLabel",uAvailable,cSearch,guCompany); |
|---|
| 936 | else |
|---|
| 937 | sprintf(gcQuery,"SELECT tIP.uIP,tIP.cLabel,tContainer.cLabel,tContainer.uContainer FROM" |
|---|
| 938 | " tIP LEFT JOIN tContainer ON tContainer.uIPv4=tIP.uIP WHERE" |
|---|
| 939 | " tIP.uAvailable=%u AND tIP.uOwner=%u ORDER BY tIP.cLabel", |
|---|
| 940 | uAvailable,guCompany); |
|---|
| 941 | } |
|---|
| 942 | |
|---|
| 943 | mysql_query(&gMysql,gcQuery); |
|---|
| 944 | if(mysql_errno(&gMysql)) |
|---|
| 945 | { |
|---|
| 946 | printf("<p><u>tIPNavList</u><br>\n"); |
|---|
| 947 | printf("%s",mysql_error(&gMysql)); |
|---|
| 948 | return; |
|---|
| 949 | } |
|---|
| 950 | |
|---|
| 951 | res=mysql_store_result(&gMysql); |
|---|
| 952 | if((uMySQLNumRows=mysql_num_rows(res))) |
|---|
| 953 | { |
|---|
| 954 | if(uAvailable) |
|---|
| 955 | printf("<p><u>Available tIPNavList(%u)</u><br>\n",uMySQLNumRows); |
|---|
| 956 | else |
|---|
| 957 | printf("<p><u>Used tIPNavList(%u)</u><br>\n",uMySQLNumRows); |
|---|
| 958 | |
|---|
| 959 | |
|---|
| 960 | while((field=mysql_fetch_row(res))) |
|---|
| 961 | { |
|---|
| 962 | |
|---|
| 963 | if(cSearch[0]) |
|---|
| 964 | if(field[2]!=NULL) |
|---|
| 965 | printf("<a class=darkLink href=unxsVZ.cgi?gcFunction=tIP&uIP=%s&cSearch=%s>%s</a>" |
|---|
| 966 | " (<a class=darkLink href=unxsVZ.cgi?gcFunction=tContainer&uContainer=%s>%s" |
|---|
| 967 | "</a>)<br>\n", |
|---|
| 968 | field[0],cURLEncode(cSearch),field[1],field[3],field[2]); |
|---|
| 969 | else |
|---|
| 970 | printf("<a class=darkLink href=unxsVZ.cgi?gcFunction=tIP&uIP=%s&cSearch=%s>%s" |
|---|
| 971 | "</a><br>\n",field[0],cURLEncode(cSearch),field[1]); |
|---|
| 972 | else |
|---|
| 973 | if(field[2]!=NULL) |
|---|
| 974 | printf("<a class=darkLink href=unxsVZ.cgi?gcFunction=tIP&uIP=%s>%s</a>" |
|---|
| 975 | " (<a class=darkLink href=unxsVZ.cgi?gcFunction=tContainer&uContainer=%s>%s" |
|---|
| 976 | "</a>)<br>\n",field[0],field[1],field[3],field[2]); |
|---|
| 977 | else |
|---|
| 978 | printf("<a class=darkLink href=unxsVZ.cgi?gcFunction=tIP&uIP=%s>%s</a><br>\n", |
|---|
| 979 | field[0],field[1]); |
|---|
| 980 | if(++uNumRows>uLIMIT) |
|---|
| 981 | { |
|---|
| 982 | printf("(Only %u IPs shown use search/filters to shorten list.)<br>\n",uLIMIT); |
|---|
| 983 | break; |
|---|
| 984 | } |
|---|
| 985 | } |
|---|
| 986 | } |
|---|
| 987 | mysql_free_result(res); |
|---|
| 988 | |
|---|
| 989 | }//void tIPNavList(unsigned uAvailable) |
|---|
| 990 | |
|---|
| 991 | |
|---|
| 992 | void tIPReport(void) |
|---|
| 993 | { |
|---|
| 994 | MYSQL_RES *res; |
|---|
| 995 | MYSQL_ROW field; |
|---|
| 996 | |
|---|
| 997 | sprintf(gcQuery,"SELECT uContainer,cHostname FROM tContainer WHERE uIPv4=%u",uIP); |
|---|
| 998 | mysql_query(&gMysql,gcQuery); |
|---|
| 999 | if(mysql_errno(&gMysql)) |
|---|
| 1000 | { |
|---|
| 1001 | printf("<p><u>tIPReport</u><br>\n"); |
|---|
| 1002 | printf("%s",mysql_error(&gMysql)); |
|---|
| 1003 | return; |
|---|
| 1004 | } |
|---|
| 1005 | res=mysql_store_result(&gMysql); |
|---|
| 1006 | if(mysql_num_rows(res)) |
|---|
| 1007 | { |
|---|
| 1008 | printf("<p><u>tIPReport tContainer</u><br>\n"); |
|---|
| 1009 | |
|---|
| 1010 | |
|---|
| 1011 | while((field=mysql_fetch_row(res))) |
|---|
| 1012 | { |
|---|
| 1013 | printf("<a class=darkLink href=unxsVZ.cgi?gcFunction=tContainer" |
|---|
| 1014 | "&uContainer=%s>%s used by %s</a><br>\n",field[0],cLabel,field[1]); |
|---|
| 1015 | } |
|---|
| 1016 | } |
|---|
| 1017 | mysql_free_result(res); |
|---|
| 1018 | |
|---|
| 1019 | sprintf(gcQuery,"SELECT tProperty.uKey,tContainer.cLabel FROM tProperty,tContainer" |
|---|
| 1020 | " WHERE tProperty.uType=3 AND tProperty.cValue='%s'" |
|---|
| 1021 | " AND tProperty.uKey=tContainer.uContainer",cLabel); |
|---|
| 1022 | mysql_query(&gMysql,gcQuery); |
|---|
| 1023 | if(mysql_errno(&gMysql)) |
|---|
| 1024 | { |
|---|
| 1025 | printf("<p><u>tIPReport</u><br>\n"); |
|---|
| 1026 | printf("%s",mysql_error(&gMysql)); |
|---|
| 1027 | return; |
|---|
| 1028 | } |
|---|
| 1029 | res=mysql_store_result(&gMysql); |
|---|
| 1030 | if(mysql_num_rows(res)) |
|---|
| 1031 | { |
|---|
| 1032 | printf("<p><u>tIPReport tContainer Extra IPs</u><br>\n"); |
|---|
| 1033 | |
|---|
| 1034 | |
|---|
| 1035 | while((field=mysql_fetch_row(res))) |
|---|
| 1036 | { |
|---|
| 1037 | printf("<a class=darkLink href=unxsVZ.cgi?gcFunction=tContainer" |
|---|
| 1038 | "&uContainer=%s>%s used by %s</a><br>\n",field[0],cLabel,field[1]); |
|---|
| 1039 | } |
|---|
| 1040 | } |
|---|
| 1041 | mysql_free_result(res); |
|---|
| 1042 | |
|---|
| 1043 | sprintf(gcQuery,"SELECT tProperty.uKey,tNode.cLabel FROM tProperty,tNode" |
|---|
| 1044 | " WHERE tProperty.uType=2 AND tProperty.cValue='%s'" |
|---|
| 1045 | " AND tProperty.uKey=tNode.uNode",cLabel); |
|---|
| 1046 | mysql_query(&gMysql,gcQuery); |
|---|
| 1047 | if(mysql_errno(&gMysql)) |
|---|
| 1048 | { |
|---|
| 1049 | printf("<p><u>tIPReport</u><br>\n"); |
|---|
| 1050 | printf("%s",mysql_error(&gMysql)); |
|---|
| 1051 | return; |
|---|
| 1052 | } |
|---|
| 1053 | res=mysql_store_result(&gMysql); |
|---|
| 1054 | if(mysql_num_rows(res)) |
|---|
| 1055 | { |
|---|
| 1056 | printf("<p><u>tIPReport tNode</u><br>\n"); |
|---|
| 1057 | |
|---|
| 1058 | |
|---|
| 1059 | while((field=mysql_fetch_row(res))) |
|---|
| 1060 | { |
|---|
| 1061 | printf("<a class=darkLink href=unxsVZ.cgi?gcFunction=tNode" |
|---|
| 1062 | "&uNode=%s>%s used by %s</a><br>\n",field[0],cLabel,field[1]); |
|---|
| 1063 | } |
|---|
| 1064 | } |
|---|
| 1065 | mysql_free_result(res); |
|---|
| 1066 | |
|---|
| 1067 | }//void tIPReport(void) |
|---|
| 1068 | |
|---|
| 1069 | |
|---|
| 1070 | void AddIPRange(char *cIPRange) |
|---|
| 1071 | { |
|---|
| 1072 | char *cIPs[2048];//Warning max 4 class C's or /22 |
|---|
| 1073 | unsigned uCIDR4Mask=0; |
|---|
| 1074 | unsigned uCIDR4IP=0; |
|---|
| 1075 | register int i,uSkip=0; |
|---|
| 1076 | MYSQL_RES *res; |
|---|
| 1077 | |
|---|
| 1078 | if(!uInCIDR4Format(cIPRange,&uCIDR4IP,&uCIDR4Mask)) |
|---|
| 1079 | tIP("<blink>Error:</blink> cIPRange is not in standard CIDR format!"); |
|---|
| 1080 | if(uCIDR4Mask<22) |
|---|
| 1081 | tIP("<blink>Error:</blink> cIPRange is limited to 4 class C's or /22!"); |
|---|
| 1082 | uCIDR4IP=ExpandCIDR4(cIPRange,&cIPs[0]); |
|---|
| 1083 | for(i=0;i<uCIDR4IP;i++) |
|---|
| 1084 | { |
|---|
| 1085 | sprintf(gcQuery,"SELECT uIP FROM tIP WHERE cLabel='%s'",cIPs[i]); |
|---|
| 1086 | mysql_query(&gMysql,gcQuery); |
|---|
| 1087 | if(mysql_errno(&gMysql)) |
|---|
| 1088 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 1089 | res=mysql_store_result(&gMysql); |
|---|
| 1090 | if(mysql_num_rows(res)) |
|---|
| 1091 | { |
|---|
| 1092 | mysql_free_result(res); |
|---|
| 1093 | uSkip++; |
|---|
| 1094 | continue; |
|---|
| 1095 | } |
|---|
| 1096 | mysql_free_result(res); |
|---|
| 1097 | |
|---|
| 1098 | sprintf(gcQuery,"INSERT INTO tIP SET cLabel='%s',uOwner=%u,uCreatedBy=%u,uAvailable=1" |
|---|
| 1099 | ",uCreatedDate=UNIX_TIMESTAMP(NOW()),uDatacenter=%u", |
|---|
| 1100 | cIPs[i],guCompany,guLoginClient,uDatacenter); |
|---|
| 1101 | mysql_query(&gMysql,gcQuery); |
|---|
| 1102 | if(mysql_errno(&gMysql)) |
|---|
| 1103 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 1104 | free(cIPs[i]); |
|---|
| 1105 | } |
|---|
| 1106 | unxsVZLog(mysql_insert_id(&gMysql),"tIP","NewRange"); |
|---|
| 1107 | if(!uSkip) |
|---|
| 1108 | tIP("Complete cIPRange added"); |
|---|
| 1109 | else if(uSkip==i) |
|---|
| 1110 | tIP("<blink>Warning:</blink> cIPRange already exists no IPs added"); |
|---|
| 1111 | else if(1) |
|---|
| 1112 | tIP("<blink>Note:</blink> Partial cIPRange added. At least one already existed"); |
|---|
| 1113 | |
|---|
| 1114 | }//void AddIPRange(char *cIPRange) |
|---|
| 1115 | |
|---|
| 1116 | |
|---|
| 1117 | void DelIPRange(char *cIPRange) |
|---|
| 1118 | { |
|---|
| 1119 | char *cIPs[2048];//Warning max 4 class C's or /22 |
|---|
| 1120 | unsigned uCIDR4Mask=0; |
|---|
| 1121 | unsigned uCIDR4IP=0; |
|---|
| 1122 | register int i,uSkip=0; |
|---|
| 1123 | |
|---|
| 1124 | if(!uInCIDR4Format(cIPRange,&uCIDR4IP,&uCIDR4Mask)) |
|---|
| 1125 | tIP("<blink>Error:</blink> cIPRange is not in standard CIDR format!"); |
|---|
| 1126 | if(uCIDR4Mask<22) |
|---|
| 1127 | tIP("<blink>Error:</blink> cIPRange is limited to 4 class C's or /22!"); |
|---|
| 1128 | uCIDR4IP=ExpandCIDR4(cIPRange,&cIPs[0]); |
|---|
| 1129 | for(i=0;i<uCIDR4IP;i++) |
|---|
| 1130 | { |
|---|
| 1131 | if(guCompany==1) |
|---|
| 1132 | sprintf(gcQuery,"DELETE FROM tIP WHERE cLabel='%s' AND uAvailable=1",cIPs[i]); |
|---|
| 1133 | else |
|---|
| 1134 | sprintf(gcQuery,"DELETE FROM tIP WHERE cLabel='%s' AND uAvailable=1 AND uOwner=%u", |
|---|
| 1135 | cIPs[i],guCompany); |
|---|
| 1136 | mysql_query(&gMysql,gcQuery); |
|---|
| 1137 | if(mysql_errno(&gMysql)) |
|---|
| 1138 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 1139 | if(mysql_affected_rows(&gMysql)==1) |
|---|
| 1140 | uSkip++; |
|---|
| 1141 | free(cIPs[i]); |
|---|
| 1142 | } |
|---|
| 1143 | unxsVZLog(uIP,"tIP","DelRange"); |
|---|
| 1144 | if(!uSkip) |
|---|
| 1145 | tIP("<blink>Warning:</blink> cIPRange of available IPs controlled by you did not exist!"); |
|---|
| 1146 | else if(uSkip==i) |
|---|
| 1147 | tIP("Complete cIPRange deleted"); |
|---|
| 1148 | else if(1) |
|---|
| 1149 | tIP("<blink>Note:</blink> Partial cIPRange deleted. At least one available IP controlled by you did not exist"); |
|---|
| 1150 | |
|---|
| 1151 | }//void DelIPRange(char *cIPRange) |
|---|
| 1152 | |
|---|
| 1153 | |
|---|
| 1154 | void tIPUsedButAvailableNavList(void) |
|---|
| 1155 | { |
|---|
| 1156 | MYSQL_RES *res; |
|---|
| 1157 | MYSQL_ROW field; |
|---|
| 1158 | unsigned uNumRows=0; |
|---|
| 1159 | unsigned uMySQLNumRows=0; |
|---|
| 1160 | #define uUBALIMIT 64 |
|---|
| 1161 | |
|---|
| 1162 | if(guPermLevel>11) |
|---|
| 1163 | { |
|---|
| 1164 | if(cSearch[0]) |
|---|
| 1165 | sprintf(gcQuery,"SELECT tIP.uIP,tIP.cLabel,tContainer.cLabel,tContainer.uContainer FROM" |
|---|
| 1166 | " tIP,tContainer WHERE tContainer.uIPv4=tIP.uIP AND tIP.uAvailable=1" |
|---|
| 1167 | " AND tIP.cLabel LIKE '%s%%' ORDER BY tIP.cLabel",cSearch); |
|---|
| 1168 | else |
|---|
| 1169 | sprintf(gcQuery,"SELECT tIP.uIP,tIP.cLabel,tContainer.cLabel,tContainer.uContainer FROM" |
|---|
| 1170 | " tIP,tContainer WHERE tContainer.uIPv4=tIP.uIP AND" |
|---|
| 1171 | " tIP.uAvailable=1 ORDER BY tIP.cLabel"); |
|---|
| 1172 | } |
|---|
| 1173 | else |
|---|
| 1174 | { |
|---|
| 1175 | if(cSearch[0]) |
|---|
| 1176 | sprintf(gcQuery,"SELECT tIP.uIP,tIP.cLabel,tContainer.cLabel,tContainer.uContainer FROM" |
|---|
| 1177 | " tIP,tContainer WHERE tContainer.uIPv4=tIP.uIP AND" |
|---|
| 1178 | " tIP.uAvailable=1 AND tIP.cLabel LIKE '%s%%' AND" |
|---|
| 1179 | " tIP.uOwner=%u ORDER BY tIP.cLabel",cSearch,guCompany); |
|---|
| 1180 | else |
|---|
| 1181 | sprintf(gcQuery,"SELECT tIP.uIP,tIP.cLabel,tContainer.cLabel,tContainer.uContainer FROM" |
|---|
| 1182 | " tIP,tContainer WHERE tContainer.uIPv4=tIP.uIP AND" |
|---|
| 1183 | " tIP.uAvailable=1 AND tIP.uOwner=%u ORDER BY tIP.cLabel",guCompany); |
|---|
| 1184 | } |
|---|
| 1185 | |
|---|
| 1186 | mysql_query(&gMysql,gcQuery); |
|---|
| 1187 | if(mysql_errno(&gMysql)) |
|---|
| 1188 | { |
|---|
| 1189 | printf("<p><u>tIPUsedButAvailableNavList</u><br>\n"); |
|---|
| 1190 | printf("%s",mysql_error(&gMysql)); |
|---|
| 1191 | return; |
|---|
| 1192 | } |
|---|
| 1193 | |
|---|
| 1194 | res=mysql_store_result(&gMysql); |
|---|
| 1195 | if((uMySQLNumRows=mysql_num_rows(res))) |
|---|
| 1196 | { |
|---|
| 1197 | printf("<p><u>tIPUsedButAvailableNavList(%u)</u><br>\n",uMySQLNumRows); |
|---|
| 1198 | |
|---|
| 1199 | while((field=mysql_fetch_row(res))) |
|---|
| 1200 | { |
|---|
| 1201 | |
|---|
| 1202 | if(cSearch[0]) |
|---|
| 1203 | printf("<a class=darkLink href=unxsVZ.cgi?gcFunction=tIP&uIP=%s&cSearch=%s>%s</a>" |
|---|
| 1204 | " (<a class=darkLink href=unxsVZ.cgi?gcFunction=tContainer&uContainer=%s>%s" |
|---|
| 1205 | "</a>)<br>\n", |
|---|
| 1206 | field[0],cURLEncode(cSearch),field[1],field[3],field[2]); |
|---|
| 1207 | else |
|---|
| 1208 | printf("<a class=darkLink href=unxsVZ.cgi?gcFunction=tIP&uIP=%s>%s</a>" |
|---|
| 1209 | " (<a class=darkLink href=unxsVZ.cgi?gcFunction=tContainer&uContainer=%s>%s" |
|---|
| 1210 | "</a>)<br>\n",field[0],field[1],field[3],field[2]); |
|---|
| 1211 | if(++uNumRows>uLIMIT) |
|---|
| 1212 | { |
|---|
| 1213 | printf("(Only %u IPs shown use search/filters to shorten list.)<br>\n",uLIMIT); |
|---|
| 1214 | break; |
|---|
| 1215 | } |
|---|
| 1216 | } |
|---|
| 1217 | |
|---|
| 1218 | printf("<input type=submit class=lwarnButton name=gcCommand value=Fix" |
|---|
| 1219 | " title='Change all the tIPUsedButAvailableNavList IPs to not available'><br>\n"); |
|---|
| 1220 | } |
|---|
| 1221 | mysql_free_result(res); |
|---|
| 1222 | |
|---|
| 1223 | }//void tIPUsedButAvailableNavList() |
|---|
| 1224 | |
|---|
| 1225 | |
|---|
| 1226 | void tIPUsedButAvailableFix(void) |
|---|
| 1227 | { |
|---|
| 1228 | MYSQL_RES *res; |
|---|
| 1229 | MYSQL_ROW field; |
|---|
| 1230 | |
|---|
| 1231 | if(guPermLevel>11) |
|---|
| 1232 | { |
|---|
| 1233 | if(cSearch[0]) |
|---|
| 1234 | sprintf(gcQuery,"SELECT tIP.uIP FROM" |
|---|
| 1235 | " tIP,tContainer WHERE tContainer.uIPv4=tIP.uIP AND tIP.uAvailable=1" |
|---|
| 1236 | " AND tIP.cLabel LIKE '%s%%' ORDER BY tIP.cLabel",cSearch); |
|---|
| 1237 | else |
|---|
| 1238 | sprintf(gcQuery,"SELECT tIP.uIP FROM" |
|---|
| 1239 | " tIP,tContainer WHERE tContainer.uIPv4=tIP.uIP AND" |
|---|
| 1240 | " tIP.uAvailable=1 ORDER BY tIP.cLabel"); |
|---|
| 1241 | } |
|---|
| 1242 | else |
|---|
| 1243 | { |
|---|
| 1244 | if(cSearch[0]) |
|---|
| 1245 | sprintf(gcQuery,"SELECT tIP.uIP FROM" |
|---|
| 1246 | " tIP,tContainer WHERE tContainer.uIPv4=tIP.uIP AND" |
|---|
| 1247 | " tIP.uAvailable=1 AND tIP.cLabel LIKE '%s%%' AND" |
|---|
| 1248 | " tIP.uOwner=%u ORDER BY tIP.cLabel",cSearch,guCompany); |
|---|
| 1249 | else |
|---|
| 1250 | sprintf(gcQuery,"SELECT tIP.uIP FROM" |
|---|
| 1251 | " tIP,tContainer WHERE tContainer.uIPv4=tIP.uIP AND" |
|---|
| 1252 | " tIP.uAvailable=1 AND tIP.uOwner=%u ORDER BY tIP.cLabel",guCompany); |
|---|
| 1253 | } |
|---|
| 1254 | |
|---|
| 1255 | mysql_query(&gMysql,gcQuery); |
|---|
| 1256 | if(mysql_errno(&gMysql)) |
|---|
| 1257 | tIP(mysql_error(&gMysql)); |
|---|
| 1258 | |
|---|
| 1259 | res=mysql_store_result(&gMysql); |
|---|
| 1260 | if(mysql_num_rows(res)>0) |
|---|
| 1261 | { |
|---|
| 1262 | while((field=mysql_fetch_row(res))) |
|---|
| 1263 | { |
|---|
| 1264 | sprintf(gcQuery,"UPDATE tIP SET uAvailable=0 WHERE uIP=%s",field[0]); |
|---|
| 1265 | mysql_query(&gMysql,gcQuery); |
|---|
| 1266 | if(mysql_errno(&gMysql)) |
|---|
| 1267 | tIP(mysql_error(&gMysql)); |
|---|
| 1268 | } |
|---|
| 1269 | } |
|---|
| 1270 | mysql_free_result(res); |
|---|
| 1271 | |
|---|
| 1272 | }//void tIPUsedButAvailableFix() |
|---|
| 1273 | |
|---|