| 1 | /* |
|---|
| 2 | FILE |
|---|
| 3 | tIP source code of unxsVZ.cgi |
|---|
| 4 | Built by mysqlRAD2.cgi (C) Gary Wallis 2001-2007 |
|---|
| 5 | $Id$ |
|---|
| 6 | PURPOSE |
|---|
| 7 | Schema dependent RAD generated file. |
|---|
| 8 | Program app functionality in tipfunc.h while |
|---|
| 9 | RAD is still to be used. |
|---|
| 10 | AUTHOR/LEGAL |
|---|
| 11 | (C) 2001-2010 Gary Wallis for Unixservice, LLC. |
|---|
| 12 | GPLv2 license applies. See LICENSE file included. |
|---|
| 13 | */ |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | #include "mysqlrad.h" |
|---|
| 17 | |
|---|
| 18 | //Table Variables |
|---|
| 19 | //Table Variables |
|---|
| 20 | //uIP: Primary Key |
|---|
| 21 | static unsigned uIP=0; |
|---|
| 22 | //cLabel: Short label |
|---|
| 23 | static char cLabel[33]={""}; |
|---|
| 24 | //uAvailable: IP is available for use |
|---|
| 25 | static unsigned uAvailable=0; |
|---|
| 26 | static char cYesNouAvailable[32]={""}; |
|---|
| 27 | //uOwner: Record owner |
|---|
| 28 | static unsigned uOwner=0; |
|---|
| 29 | //uCreatedBy: uClient for last insert |
|---|
| 30 | static unsigned uCreatedBy=0; |
|---|
| 31 | //uCreatedDate: Unix seconds date last insert |
|---|
| 32 | static time_t uCreatedDate=0; |
|---|
| 33 | //uModBy: uClient for last update |
|---|
| 34 | static unsigned uModBy=0; |
|---|
| 35 | //uModDate: Unix seconds date last update |
|---|
| 36 | static time_t uModDate=0; |
|---|
| 37 | //uDatacenter: Belongs to this Datacenter |
|---|
| 38 | static unsigned uDatacenter=0; |
|---|
| 39 | static char cuDatacenterPullDown[256]={""}; |
|---|
| 40 | |
|---|
| 41 | //cComment |
|---|
| 42 | static char *cComment={""}; |
|---|
| 43 | |
|---|
| 44 | //Extensions for searching |
|---|
| 45 | static char cIPv4Search[16]={""}; |
|---|
| 46 | static unsigned uAvailableSearch=0; |
|---|
| 47 | static char cYesNouAvailableSearch[8]={""}; |
|---|
| 48 | static unsigned uNodeSearch=0; |
|---|
| 49 | static char cuNodeSearchPullDown[256]={""}; |
|---|
| 50 | static unsigned uNodeSearchNot=0; |
|---|
| 51 | static unsigned uIPv4Exclude=0; |
|---|
| 52 | static unsigned uOwnerSearch=0; |
|---|
| 53 | static unsigned uDatacenterSearch=0; |
|---|
| 54 | static char cuDatacenterSearchPullDown[256]={""}; |
|---|
| 55 | int ReadYesNoPullDownTriState(const char *cLabel); |
|---|
| 56 | void YesNoPullDownTriState(char *cFieldName, unsigned uSelect, unsigned uMode); |
|---|
| 57 | |
|---|
| 58 | #define VAR_LIST_tIP "tIP.uIP,tIP.cLabel,tIP.uAvailable,tIP.uOwner,tIP.uCreatedBy,tIP.uCreatedDate,tIP.uModBy,tIP.uModDate,tIP.uDatacenter,tIP.cComment" |
|---|
| 59 | |
|---|
| 60 | //Local only |
|---|
| 61 | void tIPSearchSet(unsigned uStep); |
|---|
| 62 | void Insert_tIP(void); |
|---|
| 63 | void Update_tIP(char *cRowid); |
|---|
| 64 | void ProcesstIPListVars(pentry entries[], int x); |
|---|
| 65 | |
|---|
| 66 | //In tIPfunc.h file included below |
|---|
| 67 | void ExtProcesstIPVars(pentry entries[], int x); |
|---|
| 68 | void ExttIPCommands(pentry entries[], int x); |
|---|
| 69 | void ExttIPButtons(void); |
|---|
| 70 | void ExttIPNavBar(void); |
|---|
| 71 | void ExttIPGetHook(entry gentries[], int x); |
|---|
| 72 | void ExttIPSelect(void); |
|---|
| 73 | void ExttIPSelectRow(void); |
|---|
| 74 | void ExttIPListSelect(void); |
|---|
| 75 | void ExttIPListFilter(void); |
|---|
| 76 | void ExttIPAuxTable(void); |
|---|
| 77 | |
|---|
| 78 | #include "tipfunc.h" |
|---|
| 79 | |
|---|
| 80 | //Table Variables Assignment Function |
|---|
| 81 | void ProcesstIPVars(pentry entries[], int x) |
|---|
| 82 | { |
|---|
| 83 | register int i; |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | for(i=0;i<x;i++) |
|---|
| 87 | { |
|---|
| 88 | if(!strcmp(entries[i].name,"uIP")) |
|---|
| 89 | sscanf(entries[i].val,"%u",&uIP); |
|---|
| 90 | else if(!strcmp(entries[i].name,"cLabel")) |
|---|
| 91 | sprintf(cLabel,"%.32s",entries[i].val); |
|---|
| 92 | else if(!strcmp(entries[i].name,"uAvailable")) |
|---|
| 93 | sscanf(entries[i].val,"%u",&uAvailable); |
|---|
| 94 | else if(!strcmp(entries[i].name,"cYesNouAvailable")) |
|---|
| 95 | { |
|---|
| 96 | sprintf(cYesNouAvailable,"%.31s",entries[i].val); |
|---|
| 97 | uAvailable=ReadYesNoPullDown(cYesNouAvailable); |
|---|
| 98 | } |
|---|
| 99 | else if(!strcmp(entries[i].name,"uOwner")) |
|---|
| 100 | sscanf(entries[i].val,"%u",&uOwner); |
|---|
| 101 | else if(!strcmp(entries[i].name,"uCreatedBy")) |
|---|
| 102 | sscanf(entries[i].val,"%u",&uCreatedBy); |
|---|
| 103 | else if(!strcmp(entries[i].name,"uCreatedDate")) |
|---|
| 104 | sscanf(entries[i].val,"%lu",&uCreatedDate); |
|---|
| 105 | else if(!strcmp(entries[i].name,"uModBy")) |
|---|
| 106 | sscanf(entries[i].val,"%u",&uModBy); |
|---|
| 107 | else if(!strcmp(entries[i].name,"uModDate")) |
|---|
| 108 | sscanf(entries[i].val,"%lu",&uModDate); |
|---|
| 109 | else if(!strcmp(entries[i].name,"uDatacenter")) |
|---|
| 110 | sscanf(entries[i].val,"%u",&uDatacenter); |
|---|
| 111 | else if(!strcmp(entries[i].name,"cComment")) |
|---|
| 112 | cComment=entries[i].val; |
|---|
| 113 | else if(!strcmp(entries[i].name,"cuDatacenterPullDown")) |
|---|
| 114 | { |
|---|
| 115 | sprintf(cuDatacenterPullDown,"%.255s",entries[i].val); |
|---|
| 116 | uDatacenter=ReadPullDown("tDatacenter","cLabel",cuDatacenterPullDown); |
|---|
| 117 | } |
|---|
| 118 | else if(!strcmp(entries[i].name,"uOwnerSearch")) |
|---|
| 119 | sscanf(entries[i].val,"%u",&uOwnerSearch); |
|---|
| 120 | else if(!strcmp(entries[i].name,"cForClientPullDown")) |
|---|
| 121 | { |
|---|
| 122 | sprintf(cForClientPullDown,"%.255s",entries[i].val); |
|---|
| 123 | uOwnerSearch=ReadPullDown("tClient","cLabel",cForClientPullDown); |
|---|
| 124 | } |
|---|
| 125 | else if(!strcmp(entries[i].name,"uDatacenterSearch")) |
|---|
| 126 | sscanf(entries[i].val,"%u",&uDatacenterSearch); |
|---|
| 127 | else if(!strcmp(entries[i].name,"cuDatacenterSearchPullDown")) |
|---|
| 128 | { |
|---|
| 129 | sprintf(cuDatacenterSearchPullDown,"%.255s",entries[i].val); |
|---|
| 130 | uDatacenterSearch=ReadPullDown("tDatacenter","cLabel",cuDatacenterSearchPullDown); |
|---|
| 131 | } |
|---|
| 132 | else if(!strcmp(entries[i].name,"uNodeSearch")) |
|---|
| 133 | sscanf(entries[i].val,"%u",&uNodeSearch); |
|---|
| 134 | else if(!strcmp(entries[i].name,"cuNodeSearchPullDown")) |
|---|
| 135 | { |
|---|
| 136 | sprintf(cuNodeSearchPullDown,"%.255s",entries[i].val); |
|---|
| 137 | uNodeSearch=ReadPullDown("tNode","cLabel",cuNodeSearchPullDown); |
|---|
| 138 | } |
|---|
| 139 | else if(!strcmp(entries[i].name,"cIPv4Search")) |
|---|
| 140 | sprintf(cIPv4Search,"%.15s",entries[i].val); |
|---|
| 141 | else if(!strcmp(entries[i].name,"cYesNouAvailableSearch")) |
|---|
| 142 | { |
|---|
| 143 | sprintf(cYesNouAvailableSearch,"%.8s",entries[i].val); |
|---|
| 144 | uAvailableSearch=ReadYesNoPullDownTriState(cYesNouAvailableSearch); |
|---|
| 145 | } |
|---|
| 146 | else if(!strcmp(entries[i].name,"uNodeSearchNotNoCA")) |
|---|
| 147 | uNodeSearchNot=1; |
|---|
| 148 | else if(!strcmp(entries[i].name,"uIPv4ExcludeNoCA")) |
|---|
| 149 | uIPv4Exclude=1; |
|---|
| 150 | |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | //After so we can overwrite form data if needed. |
|---|
| 154 | ExtProcesstIPVars(entries,x); |
|---|
| 155 | |
|---|
| 156 | }//ProcesstIPVars() |
|---|
| 157 | |
|---|
| 158 | |
|---|
| 159 | void ProcesstIPListVars(pentry entries[], int x) |
|---|
| 160 | { |
|---|
| 161 | register int i; |
|---|
| 162 | |
|---|
| 163 | for(i=0;i<x;i++) |
|---|
| 164 | { |
|---|
| 165 | if(!strncmp(entries[i].name,"ED",2)) |
|---|
| 166 | { |
|---|
| 167 | sscanf(entries[i].name+2,"%u",&uIP); |
|---|
| 168 | guMode=2002; |
|---|
| 169 | tIP(""); |
|---|
| 170 | } |
|---|
| 171 | } |
|---|
| 172 | }//void ProcesstIPListVars(pentry entries[], int x) |
|---|
| 173 | |
|---|
| 174 | |
|---|
| 175 | int tIPCommands(pentry entries[], int x) |
|---|
| 176 | { |
|---|
| 177 | ProcessControlVars(entries,x); |
|---|
| 178 | |
|---|
| 179 | ExttIPCommands(entries,x); |
|---|
| 180 | |
|---|
| 181 | if(!strcmp(gcFunction,"tIPTools")) |
|---|
| 182 | { |
|---|
| 183 | if(!strcmp(gcFind,LANG_NB_LIST)) |
|---|
| 184 | { |
|---|
| 185 | tIPList(); |
|---|
| 186 | } |
|---|
| 187 | |
|---|
| 188 | //Default |
|---|
| 189 | ProcesstIPVars(entries,x); |
|---|
| 190 | tIP(""); |
|---|
| 191 | } |
|---|
| 192 | else if(!strcmp(gcFunction,"tIPList")) |
|---|
| 193 | { |
|---|
| 194 | ProcessControlVars(entries,x); |
|---|
| 195 | ProcesstIPListVars(entries,x); |
|---|
| 196 | tIPList(); |
|---|
| 197 | } |
|---|
| 198 | |
|---|
| 199 | return(0); |
|---|
| 200 | |
|---|
| 201 | }//tIPCommands() |
|---|
| 202 | |
|---|
| 203 | |
|---|
| 204 | void tIP(const char *cResult) |
|---|
| 205 | { |
|---|
| 206 | MYSQL_RES *res; |
|---|
| 207 | MYSQL_RES *res2; |
|---|
| 208 | MYSQL_ROW field; |
|---|
| 209 | |
|---|
| 210 | //Internal skip reloading |
|---|
| 211 | if(!cResult[0]) |
|---|
| 212 | { |
|---|
| 213 | if(guMode) |
|---|
| 214 | ExttIPSelectRow(); |
|---|
| 215 | else |
|---|
| 216 | ExttIPSelect(); |
|---|
| 217 | |
|---|
| 218 | mysql_query(&gMysql,gcQuery); |
|---|
| 219 | if(mysql_errno(&gMysql)) |
|---|
| 220 | { |
|---|
| 221 | if(strstr(mysql_error(&gMysql)," doesn't exist")) |
|---|
| 222 | { |
|---|
| 223 | CreatetIP(); |
|---|
| 224 | unxsVZ("New tIP table created"); |
|---|
| 225 | } |
|---|
| 226 | else |
|---|
| 227 | { |
|---|
| 228 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 229 | } |
|---|
| 230 | } |
|---|
| 231 | |
|---|
| 232 | res=mysql_store_result(&gMysql); |
|---|
| 233 | if((guI=mysql_num_rows(res))) |
|---|
| 234 | { |
|---|
| 235 | if(guMode==6) |
|---|
| 236 | { |
|---|
| 237 | sprintf(gcQuery,"SELECT _rowid FROM tIP WHERE uIP=%u" |
|---|
| 238 | ,uIP); |
|---|
| 239 | MYSQL_RUN_STORE(res2); |
|---|
| 240 | field=mysql_fetch_row(res2); |
|---|
| 241 | sscanf(field[0],"%lu",&gluRowid); |
|---|
| 242 | gluRowid++; |
|---|
| 243 | } |
|---|
| 244 | PageMachine("",0,""); |
|---|
| 245 | if(!guMode) mysql_data_seek(res,gluRowid-1); |
|---|
| 246 | field=mysql_fetch_row(res); |
|---|
| 247 | sscanf(field[0],"%u",&uIP); |
|---|
| 248 | sprintf(cLabel,"%.32s",field[1]); |
|---|
| 249 | sscanf(field[2],"%u",&uAvailable); |
|---|
| 250 | sscanf(field[3],"%u",&uOwner); |
|---|
| 251 | sscanf(field[4],"%u",&uCreatedBy); |
|---|
| 252 | sscanf(field[5],"%lu",&uCreatedDate); |
|---|
| 253 | sscanf(field[6],"%u",&uModBy); |
|---|
| 254 | sscanf(field[7],"%lu",&uModDate); |
|---|
| 255 | sscanf(field[8],"%u",&uDatacenter); |
|---|
| 256 | cComment=field[9]; |
|---|
| 257 | |
|---|
| 258 | } |
|---|
| 259 | |
|---|
| 260 | }//Internal Skip |
|---|
| 261 | |
|---|
| 262 | Header_ism3(":: IPs used and reserved for use",2);//checkbox js = 2 |
|---|
| 263 | printf("<table width=100%% cellspacing=0 cellpadding=0>\n"); |
|---|
| 264 | printf("<tr><td colspan=2 align=right valign=center>"); |
|---|
| 265 | |
|---|
| 266 | |
|---|
| 267 | printf("<input type=hidden name=gcFunction value=tIPTools>"); |
|---|
| 268 | printf("<input type=hidden name=gluRowid value=%lu>",gluRowid); |
|---|
| 269 | if(guI) |
|---|
| 270 | { |
|---|
| 271 | if(guMode==6) |
|---|
| 272 | //printf(" Found"); |
|---|
| 273 | printf(LANG_NBR_FOUND); |
|---|
| 274 | else if(guMode==5) |
|---|
| 275 | //printf(" Modified"); |
|---|
| 276 | printf(LANG_NBR_MODIFIED); |
|---|
| 277 | else if(guMode==4) |
|---|
| 278 | //printf(" New"); |
|---|
| 279 | printf(LANG_NBR_NEW); |
|---|
| 280 | printf(LANG_NBRF_SHOWING,gluRowid,guI); |
|---|
| 281 | } |
|---|
| 282 | else |
|---|
| 283 | { |
|---|
| 284 | if(!cResult[0]) |
|---|
| 285 | //printf(" No records found"); |
|---|
| 286 | printf(LANG_NBR_NORECS); |
|---|
| 287 | } |
|---|
| 288 | if(cResult[0]) printf("%s",cResult); |
|---|
| 289 | printf("</td></tr>"); |
|---|
| 290 | printf("<tr><td valign=top width=25%%>"); |
|---|
| 291 | |
|---|
| 292 | ExttIPButtons(); |
|---|
| 293 | |
|---|
| 294 | printf("</td><td valign=top>"); |
|---|
| 295 | // |
|---|
| 296 | OpenFieldSet("tIP Record Data",100); |
|---|
| 297 | |
|---|
| 298 | //Custom right panel for creating search sets |
|---|
| 299 | if(guMode==12001) |
|---|
| 300 | tIPSearchSet(1); |
|---|
| 301 | else if(guMode==12002) |
|---|
| 302 | tIPSearchSet(2); |
|---|
| 303 | else if(guMode==2000 || guMode==2002) |
|---|
| 304 | tIPInput(1); |
|---|
| 305 | else if(1) |
|---|
| 306 | tIPInput(0); |
|---|
| 307 | |
|---|
| 308 | // |
|---|
| 309 | CloseFieldSet(); |
|---|
| 310 | |
|---|
| 311 | //Bottom table |
|---|
| 312 | printf("<tr><td colspan=2>"); |
|---|
| 313 | ExttIPAuxTable(); |
|---|
| 314 | |
|---|
| 315 | Footer_ism3(); |
|---|
| 316 | |
|---|
| 317 | }//end of tIP(); |
|---|
| 318 | |
|---|
| 319 | |
|---|
| 320 | void tIPSearchSet(unsigned uStep) |
|---|
| 321 | { |
|---|
| 322 | OpenRow("<u>Set search parameters</u>","black"); |
|---|
| 323 | |
|---|
| 324 | OpenRow("IPv4 pattern","black"); |
|---|
| 325 | printf("<input title='SQL search pattern %% and _ allowed' type=text name=cIPv4Search" |
|---|
| 326 | " value=\"%s\" size=40 maxlength=15 >",cIPv4Search); |
|---|
| 327 | printf("<input title='Exclude 10/8, 172.16/12 and 192.168/16 IPs' type=checkbox name=uIPv4ExcludeNoCA "); |
|---|
| 328 | if(uIPv4Exclude) |
|---|
| 329 | printf(" checked"); |
|---|
| 330 | printf("> Exclude RFC1918 IPs"); |
|---|
| 331 | |
|---|
| 332 | OpenRow("Datacenter","black"); |
|---|
| 333 | tTablePullDown("tDatacenter;cuDatacenterSearchPullDown","cLabel","cLabel",uDatacenterSearch,1); |
|---|
| 334 | |
|---|
| 335 | OpenRow("Node","black"); |
|---|
| 336 | tTablePullDown("tNode;cuNodeSearchPullDown","cLabel","cLabel",uNodeSearch,1); |
|---|
| 337 | printf("<input title='Logical NOT of selected node if any. Including default any node (no node)' type=checkbox name=uNodeSearchNotNoCA "); |
|---|
| 338 | if(uNodeSearchNot) |
|---|
| 339 | printf(" checked"); |
|---|
| 340 | printf("> Not"); |
|---|
| 341 | |
|---|
| 342 | OpenRow("Owner","black"); |
|---|
| 343 | tTablePullDownResellers(uOwnerSearch,0); |
|---|
| 344 | |
|---|
| 345 | OpenRow("Available","black"); |
|---|
| 346 | YesNoPullDownTriState("uAvailableSearch",uAvailableSearch,1); |
|---|
| 347 | |
|---|
| 348 | if(uStep==1) |
|---|
| 349 | { |
|---|
| 350 | ; |
|---|
| 351 | } |
|---|
| 352 | else if(uStep==2) |
|---|
| 353 | { |
|---|
| 354 | ; |
|---|
| 355 | } |
|---|
| 356 | |
|---|
| 357 | }//void tIPSearchSet(unsigned uStep) |
|---|
| 358 | |
|---|
| 359 | |
|---|
| 360 | void tIPInput(unsigned uMode) |
|---|
| 361 | { |
|---|
| 362 | |
|---|
| 363 | //uIP |
|---|
| 364 | OpenRow(LANG_FL_tIP_uIP,"black"); |
|---|
| 365 | printf("<input title='%s' type=text name=uIP value=%u size=16 maxlength=10 " |
|---|
| 366 | ,LANG_FT_tIP_uIP,uIP); |
|---|
| 367 | if(guPermLevel>=20 && uMode) |
|---|
| 368 | { |
|---|
| 369 | printf("></td></tr>\n"); |
|---|
| 370 | } |
|---|
| 371 | else |
|---|
| 372 | { |
|---|
| 373 | printf("disabled></td></tr>\n"); |
|---|
| 374 | printf("<input type=hidden name=uIP value=%u >\n",uIP); |
|---|
| 375 | } |
|---|
| 376 | //cLabel |
|---|
| 377 | OpenRow(LANG_FL_tIP_cLabel,"black"); |
|---|
| 378 | printf("<input title='%s' type=text name=cLabel value=\"%s\" size=40 maxlength=32 " |
|---|
| 379 | ,LANG_FT_tIP_cLabel,EncodeDoubleQuotes(cLabel)); |
|---|
| 380 | if(guPermLevel>=0 && uMode) |
|---|
| 381 | { |
|---|
| 382 | printf("></td></tr>\n"); |
|---|
| 383 | } |
|---|
| 384 | else |
|---|
| 385 | { |
|---|
| 386 | printf("disabled></td></tr>\n"); |
|---|
| 387 | printf("<input type=hidden name=cLabel value=\"%s\">\n",EncodeDoubleQuotes(cLabel)); |
|---|
| 388 | } |
|---|
| 389 | //uAvailable |
|---|
| 390 | OpenRow(LANG_FL_tIP_uAvailable,"black"); |
|---|
| 391 | if(guPermLevel>=10 && uMode) |
|---|
| 392 | YesNoPullDown("uAvailable",uAvailable,1); |
|---|
| 393 | else |
|---|
| 394 | YesNoPullDown("uAvailable",uAvailable,0); |
|---|
| 395 | //uDatacenter |
|---|
| 396 | OpenRow(LANG_FL_tContainer_uDatacenter,"black"); |
|---|
| 397 | if(guPermLevel>=7 && uMode) |
|---|
| 398 | tTablePullDownOwner("tDatacenter;cuDatacenterPullDown","cLabel","cLabel",uDatacenter,1); |
|---|
| 399 | else |
|---|
| 400 | tTablePullDownOwner("tDatacenter;cuDatacenterPullDown","cLabel","cLabel",uDatacenter,0); |
|---|
| 401 | //cComment |
|---|
| 402 | OpenRow("cComment","black"); |
|---|
| 403 | printf("<textarea title='Additional information about IP use' cols=80 wrap=hard rows=4 name=cComment "); |
|---|
| 404 | if(guPermLevel>=7 && uMode) |
|---|
| 405 | { |
|---|
| 406 | printf(">%s</textarea></td></tr>\n",TransformAngleBrackets(cComment)); |
|---|
| 407 | } |
|---|
| 408 | else |
|---|
| 409 | { |
|---|
| 410 | printf("disabled>%s</textarea></td></tr>\n",TransformAngleBrackets(cComment)); |
|---|
| 411 | printf("<input type=hidden name=cComment value=\"%s\" >\n",EncodeDoubleQuotes(cComment)); |
|---|
| 412 | } |
|---|
| 413 | //uOwner |
|---|
| 414 | OpenRow(LANG_FL_tIP_uOwner,"black"); |
|---|
| 415 | if(guPermLevel>=20 && uMode) |
|---|
| 416 | { |
|---|
| 417 | printf("%s<input type=hidden name=uOwner value=%u >\n",ForeignKey("tClient","cLabel",uOwner),uOwner); |
|---|
| 418 | } |
|---|
| 419 | else |
|---|
| 420 | { |
|---|
| 421 | printf("%s<input type=hidden name=uOwner value=%u >\n",ForeignKey("tClient","cLabel",uOwner),uOwner); |
|---|
| 422 | } |
|---|
| 423 | //uCreatedBy |
|---|
| 424 | OpenRow(LANG_FL_tIP_uCreatedBy,"black"); |
|---|
| 425 | if(guPermLevel>=20 && uMode) |
|---|
| 426 | { |
|---|
| 427 | printf("%s<input type=hidden name=uCreatedBy value=%u >\n",ForeignKey("tClient","cLabel",uCreatedBy),uCreatedBy); |
|---|
| 428 | } |
|---|
| 429 | else |
|---|
| 430 | { |
|---|
| 431 | printf("%s<input type=hidden name=uCreatedBy value=%u >\n",ForeignKey("tClient","cLabel",uCreatedBy),uCreatedBy); |
|---|
| 432 | } |
|---|
| 433 | //uCreatedDate |
|---|
| 434 | OpenRow(LANG_FL_tIP_uCreatedDate,"black"); |
|---|
| 435 | if(uCreatedDate) |
|---|
| 436 | printf("%s\n\n",ctime(&uCreatedDate)); |
|---|
| 437 | else |
|---|
| 438 | printf("---\n\n"); |
|---|
| 439 | printf("<input type=hidden name=uCreatedDate value=%lu >\n",uCreatedDate); |
|---|
| 440 | //uModBy |
|---|
| 441 | OpenRow(LANG_FL_tIP_uModBy,"black"); |
|---|
| 442 | if(guPermLevel>=20 && uMode) |
|---|
| 443 | { |
|---|
| 444 | printf("%s<input type=hidden name=uModBy value=%u >\n",ForeignKey("tClient","cLabel",uModBy),uModBy); |
|---|
| 445 | } |
|---|
| 446 | else |
|---|
| 447 | { |
|---|
| 448 | printf("%s<input type=hidden name=uModBy value=%u >\n",ForeignKey("tClient","cLabel",uModBy),uModBy); |
|---|
| 449 | } |
|---|
| 450 | //uModDate |
|---|
| 451 | OpenRow(LANG_FL_tIP_uModDate,"black"); |
|---|
| 452 | if(uModDate) |
|---|
| 453 | printf("%s\n\n",ctime(&uModDate)); |
|---|
| 454 | else |
|---|
| 455 | printf("---\n\n"); |
|---|
| 456 | printf("<input type=hidden name=uModDate value=%lu >\n",uModDate); |
|---|
| 457 | printf("</tr>\n"); |
|---|
| 458 | |
|---|
| 459 | |
|---|
| 460 | |
|---|
| 461 | }//void tIPInput(unsigned uMode) |
|---|
| 462 | |
|---|
| 463 | |
|---|
| 464 | void NewtIP(unsigned uMode) |
|---|
| 465 | { |
|---|
| 466 | MYSQL_RES *res; |
|---|
| 467 | |
|---|
| 468 | sprintf(gcQuery,"SELECT uIP FROM tIP WHERE uIP=%u",uIP); |
|---|
| 469 | MYSQL_RUN_STORE(res); |
|---|
| 470 | if(mysql_num_rows(res)) |
|---|
| 471 | //tIP("<blink>Record already exists"); |
|---|
| 472 | tIP(LANG_NBR_RECEXISTS); |
|---|
| 473 | |
|---|
| 474 | //insert query |
|---|
| 475 | Insert_tIP(); |
|---|
| 476 | if(mysql_errno(&gMysql)) htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 477 | //sprintf(gcQuery,"New record %u added"); |
|---|
| 478 | uIP=mysql_insert_id(&gMysql); |
|---|
| 479 | uCreatedDate=luGetCreatedDate("tIP",uIP); |
|---|
| 480 | unxsVZLog(uIP,"tIP","New"); |
|---|
| 481 | |
|---|
| 482 | if(!uMode) |
|---|
| 483 | { |
|---|
| 484 | sprintf(gcQuery,LANG_NBR_NEWRECADDED,uIP); |
|---|
| 485 | tIP(gcQuery); |
|---|
| 486 | } |
|---|
| 487 | |
|---|
| 488 | }//NewtIP(unsigned uMode) |
|---|
| 489 | |
|---|
| 490 | |
|---|
| 491 | void DeletetIP(void) |
|---|
| 492 | { |
|---|
| 493 | sprintf(gcQuery,"DELETE FROM tIP WHERE uIP=%u AND ( uOwner=%u OR %u>9 )",uIP,guLoginClient,guPermLevel); |
|---|
| 494 | MYSQL_RUN; |
|---|
| 495 | //tIP("Record Deleted"); |
|---|
| 496 | if(mysql_affected_rows(&gMysql)>0) |
|---|
| 497 | { |
|---|
| 498 | unxsVZLog(uIP,"tIP","Del"); |
|---|
| 499 | tIP(LANG_NBR_RECDELETED); |
|---|
| 500 | } |
|---|
| 501 | else |
|---|
| 502 | { |
|---|
| 503 | unxsVZLog(uIP,"tIP","DelError"); |
|---|
| 504 | tIP(LANG_NBR_RECNOTDELETED); |
|---|
| 505 | } |
|---|
| 506 | |
|---|
| 507 | }//void DeletetIP(void) |
|---|
| 508 | |
|---|
| 509 | |
|---|
| 510 | void Insert_tIP(void) |
|---|
| 511 | { |
|---|
| 512 | sprintf(gcQuery,"INSERT INTO tIP SET uIP=%u,cLabel='%s',uAvailable=%u,uOwner=%u,uCreatedBy=%u," |
|---|
| 513 | "uCreatedDate=UNIX_TIMESTAMP(NOW()),uDatacenter=%u,cComment='%s'", |
|---|
| 514 | uIP |
|---|
| 515 | ,TextAreaSave(cLabel) |
|---|
| 516 | ,uAvailable |
|---|
| 517 | ,uOwner |
|---|
| 518 | ,uCreatedBy |
|---|
| 519 | ,uDatacenter |
|---|
| 520 | ,cComment); |
|---|
| 521 | MYSQL_RUN; |
|---|
| 522 | |
|---|
| 523 | }//void Insert_tIP(void) |
|---|
| 524 | |
|---|
| 525 | |
|---|
| 526 | void Update_tIP(char *cRowid) |
|---|
| 527 | { |
|---|
| 528 | sprintf(gcQuery,"UPDATE tIP SET uIP=%u,cLabel='%s',uAvailable=%u,uModBy=%u," |
|---|
| 529 | "uModDate=UNIX_TIMESTAMP(NOW()),uDatacenter=%u,cComment='%s' WHERE _rowid=%s", |
|---|
| 530 | uIP |
|---|
| 531 | ,TextAreaSave(cLabel) |
|---|
| 532 | ,uAvailable |
|---|
| 533 | ,uModBy |
|---|
| 534 | ,uDatacenter |
|---|
| 535 | ,cComment |
|---|
| 536 | ,cRowid); |
|---|
| 537 | MYSQL_RUN; |
|---|
| 538 | |
|---|
| 539 | }//void Update_tIP(void) |
|---|
| 540 | |
|---|
| 541 | |
|---|
| 542 | void ModtIP(void) |
|---|
| 543 | { |
|---|
| 544 | register int i=0; |
|---|
| 545 | MYSQL_RES *res; |
|---|
| 546 | MYSQL_ROW field; |
|---|
| 547 | unsigned uPreModDate=0; |
|---|
| 548 | |
|---|
| 549 | //Mod select gcQuery |
|---|
| 550 | if(guPermLevel<10) |
|---|
| 551 | sprintf(gcQuery,"SELECT tIP.uIP,tIP.uModDate FROM tIP,tClient WHERE tIP.uIP=%u" |
|---|
| 552 | " AND tIP.uOwner=tClient.uClient AND (tClient.uOwner=%u OR tClient.uClient=%u)" |
|---|
| 553 | ,uIP,guLoginClient,guLoginClient); |
|---|
| 554 | else |
|---|
| 555 | sprintf(gcQuery,"SELECT uIP,uModDate FROM tIP WHERE uIP=%u",uIP); |
|---|
| 556 | MYSQL_RUN_STORE(res); |
|---|
| 557 | i=mysql_num_rows(res); |
|---|
| 558 | |
|---|
| 559 | //if(i<1) tIP("<blink>Record does not exist"); |
|---|
| 560 | if(i<1) tIP(LANG_NBR_RECNOTEXIST); |
|---|
| 561 | //if(i>1) tIP("<blink>Multiple rows!"); |
|---|
| 562 | if(i>1) tIP(LANG_NBR_MULTRECS); |
|---|
| 563 | |
|---|
| 564 | field=mysql_fetch_row(res); |
|---|
| 565 | sscanf(field[1],"%u",&uPreModDate); |
|---|
| 566 | if(uPreModDate!=uModDate) tIP(LANG_NBR_EXTMOD); |
|---|
| 567 | |
|---|
| 568 | Update_tIP(field[0]); |
|---|
| 569 | if(mysql_errno(&gMysql)) htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 570 | //sprintf(query,"record %s modified",field[0]); |
|---|
| 571 | sprintf(gcQuery,LANG_NBRF_REC_MODIFIED,field[0]); |
|---|
| 572 | uModDate=luGetModDate("tIP",uIP); |
|---|
| 573 | unxsVZLog(uIP,"tIP","Mod"); |
|---|
| 574 | tIP(gcQuery); |
|---|
| 575 | |
|---|
| 576 | }//ModtIP(void) |
|---|
| 577 | |
|---|
| 578 | |
|---|
| 579 | void tIPList(void) |
|---|
| 580 | { |
|---|
| 581 | MYSQL_RES *res; |
|---|
| 582 | MYSQL_ROW field; |
|---|
| 583 | |
|---|
| 584 | ExttIPListSelect(); |
|---|
| 585 | |
|---|
| 586 | MYSQL_RUN_STORE(res); |
|---|
| 587 | guI=mysql_num_rows(res); |
|---|
| 588 | |
|---|
| 589 | PageMachine("tIPList",1,"");//1 is auto header list guMode. Opens table! |
|---|
| 590 | |
|---|
| 591 | //Filter select drop down |
|---|
| 592 | ExttIPListFilter(); |
|---|
| 593 | |
|---|
| 594 | printf("<input type=text size=16 name=gcCommand maxlength=98 value=\"%s\" >",gcCommand); |
|---|
| 595 | |
|---|
| 596 | printf("</table>\n"); |
|---|
| 597 | |
|---|
| 598 | printf("<table bgcolor=#9BC1B3 border=0 width=100%%>\n"); |
|---|
| 599 | printf("<tr bgcolor=black>" |
|---|
| 600 | "<td><font face=arial,helvetica color=white>uIP" |
|---|
| 601 | "<td><font face=arial,helvetica color=white>cLabel" |
|---|
| 602 | "<td><font face=arial,helvetica color=white>uAvailable" |
|---|
| 603 | "<td><font face=arial,helvetica color=white>uDatacenter" |
|---|
| 604 | "<td><font face=arial,helvetica color=white>cComment" |
|---|
| 605 | "<td><font face=arial,helvetica color=white>uOwner" |
|---|
| 606 | "<td><font face=arial,helvetica color=white>uCreatedBy" |
|---|
| 607 | "<td><font face=arial,helvetica color=white>uCreatedDate" |
|---|
| 608 | "<td><font face=arial,helvetica color=white>uModBy" |
|---|
| 609 | "<td><font face=arial,helvetica color=white>uModDate</tr>"); |
|---|
| 610 | |
|---|
| 611 | |
|---|
| 612 | |
|---|
| 613 | mysql_data_seek(res,guStart-1); |
|---|
| 614 | |
|---|
| 615 | for(guN=0;guN<(guEnd-guStart+1);guN++) |
|---|
| 616 | { |
|---|
| 617 | field=mysql_fetch_row(res); |
|---|
| 618 | if(!field) |
|---|
| 619 | { |
|---|
| 620 | printf("<tr><td><font face=arial,helvetica>End of data</table>"); |
|---|
| 621 | Footer_ism3(); |
|---|
| 622 | } |
|---|
| 623 | if(guN % 2) |
|---|
| 624 | printf("<tr bgcolor=#BBE1D3>"); |
|---|
| 625 | else |
|---|
| 626 | printf("<tr>"); |
|---|
| 627 | long unsigned luYesNo2=strtoul(field[2],NULL,10); |
|---|
| 628 | char cBuf2[4]; |
|---|
| 629 | if(luYesNo2) |
|---|
| 630 | sprintf(cBuf2,"Yes"); |
|---|
| 631 | else |
|---|
| 632 | sprintf(cBuf2,"No"); |
|---|
| 633 | time_t luTime5=strtoul(field[5],NULL,10); |
|---|
| 634 | char cBuf5[32]; |
|---|
| 635 | if(luTime5) |
|---|
| 636 | ctime_r(&luTime5,cBuf5); |
|---|
| 637 | else |
|---|
| 638 | sprintf(cBuf5,"---"); |
|---|
| 639 | time_t luTime7=strtoul(field[7],NULL,10); |
|---|
| 640 | char cBuf7[32]; |
|---|
| 641 | if(luTime7) |
|---|
| 642 | ctime_r(&luTime7,cBuf7); |
|---|
| 643 | else |
|---|
| 644 | sprintf(cBuf7,"---"); |
|---|
| 645 | printf("<td><input type=submit name=ED%s value=Edit> %s<td>%s<td>%s<td>%s<td>%s<td>%s<td>%s<td>%s<td>%s<td>%s</tr>" |
|---|
| 646 | ,field[0] |
|---|
| 647 | ,field[0] |
|---|
| 648 | ,field[1] |
|---|
| 649 | ,cBuf2 |
|---|
| 650 | ,ForeignKey("tDatacenter","cLabel",strtoul(field[8],NULL,10)) |
|---|
| 651 | ,field[9] |
|---|
| 652 | ,ForeignKey("tClient","cLabel",strtoul(field[3],NULL,10)) |
|---|
| 653 | ,ForeignKey("tClient","cLabel",strtoul(field[4],NULL,10)) |
|---|
| 654 | ,cBuf5 |
|---|
| 655 | ,ForeignKey("tClient","cLabel",strtoul(field[6],NULL,10)) |
|---|
| 656 | ,cBuf7); |
|---|
| 657 | } |
|---|
| 658 | |
|---|
| 659 | printf("</table></form>\n"); |
|---|
| 660 | Footer_ism3(); |
|---|
| 661 | |
|---|
| 662 | }//tIPList() |
|---|
| 663 | |
|---|
| 664 | |
|---|
| 665 | void CreatetIP(void) |
|---|
| 666 | { |
|---|
| 667 | sprintf(gcQuery,"CREATE TABLE IF NOT EXISTS tIP ( " |
|---|
| 668 | "uIP INT UNSIGNED PRIMARY KEY AUTO_INCREMENT," |
|---|
| 669 | "cLabel VARCHAR(32) NOT NULL DEFAULT ''," |
|---|
| 670 | "cComment VARCHAR(255) NOT NULL DEFAULT ''," |
|---|
| 671 | "uOwner INT UNSIGNED NOT NULL DEFAULT 0,INDEX (uOwner)," |
|---|
| 672 | "uCreatedBy INT UNSIGNED NOT NULL DEFAULT 0," |
|---|
| 673 | "uCreatedDate INT UNSIGNED NOT NULL DEFAULT 0," |
|---|
| 674 | "uModBy INT UNSIGNED NOT NULL DEFAULT 0," |
|---|
| 675 | "uModDate INT UNSIGNED NOT NULL DEFAULT 0," |
|---|
| 676 | "uAvailable INT UNSIGNED NOT NULL DEFAULT 0," |
|---|
| 677 | "uDatacenter INT UNSIGNED NOT NULL DEFAULT 0 )"); |
|---|
| 678 | mysql_query(&gMysql,gcQuery); |
|---|
| 679 | if(mysql_errno(&gMysql)) |
|---|
| 680 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 681 | }//CreatetIP() |
|---|
| 682 | |
|---|