| 1 | /* |
|---|
| 2 | FILE |
|---|
| 3 | $Id$ |
|---|
| 4 | (Built initially by unixservice.com mysqlRAD2) |
|---|
| 5 | PURPOSE |
|---|
| 6 | Non schema-dependent table and application table related functions. |
|---|
| 7 | AUTHOR |
|---|
| 8 | (C) 2001-2007 Gary Wallis. |
|---|
| 9 | |
|---|
| 10 | */ |
|---|
| 11 | |
|---|
| 12 | static unsigned uMonth=0; |
|---|
| 13 | static char cuMonthPullDown[33]={""}; |
|---|
| 14 | |
|---|
| 15 | void LogMonthSummary(void); |
|---|
| 16 | |
|---|
| 17 | void ExtProcesstLogMonthVars(pentry entries[], int x) |
|---|
| 18 | { |
|---|
| 19 | register int i; |
|---|
| 20 | for(i=0;i<x;i++) |
|---|
| 21 | { |
|---|
| 22 | if(!strcmp(entries[i].name,"cuMonthPullDown")) |
|---|
| 23 | { |
|---|
| 24 | //escape_shell_cmd used to stop cross site SQL injection |
|---|
| 25 | //of a valid user :( yikes! |
|---|
| 26 | escape_shell_cmd(entries[i].val); |
|---|
| 27 | strcpy(cuMonthPullDown,entries[i].val); |
|---|
| 28 | uMonth=ReadPullDown("tMonth","cLabel",cuMonthPullDown); |
|---|
| 29 | } |
|---|
| 30 | } |
|---|
| 31 | }//void ExtProcesstLogMonthVars(pentry entries[], int x) |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | void ExttLogMonthCommands(pentry entries[], int x) |
|---|
| 35 | { |
|---|
| 36 | |
|---|
| 37 | if(!strcmp(gcFunction,"tLogMonthTools")) |
|---|
| 38 | { |
|---|
| 39 | if(!strcmp(gcCommand,"Load")) |
|---|
| 40 | { |
|---|
| 41 | ExtProcesstLogMonthVars(entries,x); |
|---|
| 42 | if(!uMonth) |
|---|
| 43 | htmlPlainTextError("Must specify valid month table"); |
|---|
| 44 | |
|---|
| 45 | sprintf(gcQuery,"DELETE FROM tLogMonth"); |
|---|
| 46 | mysql_query(&gMysql,gcQuery); |
|---|
| 47 | if(mysql_errno(&gMysql)) |
|---|
| 48 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 49 | |
|---|
| 50 | sprintf(gcQuery,"INSERT DELAYED tLogMonth (uLog,cLabel,uLogType,cHash,uPermLevel,uLoginClient,cLogin,cHost,uTablePK,cTableName,uOwner,uCreatedBy,uCreatedDate,uModBy,uModDate) SELECT uLog,cLabel,uLogType,cHash,uPermLevel,uLoginClient,cLogin,cHost,uTablePK,cTableName,uOwner,uCreatedBy,uCreatedDate,uModBy,uModDate FROM %s",cuMonthPullDown); |
|---|
| 51 | mysql_query(&gMysql,gcQuery); |
|---|
| 52 | if(mysql_errno(&gMysql)) |
|---|
| 53 | htmlPlainTextError(mysql_error(&gMysql)); |
|---|
| 54 | |
|---|
| 55 | } |
|---|
| 56 | else if(!strcmp(gcCommand,"Top OP Stats Report")) |
|---|
| 57 | { |
|---|
| 58 | MYSQL_RES *res; |
|---|
| 59 | MYSQL_ROW field; |
|---|
| 60 | char *cTabs; |
|---|
| 61 | |
|---|
| 62 | ExtProcesstLogMonthVars(entries,x); |
|---|
| 63 | if(!uMonth) |
|---|
| 64 | htmlPlainTextError("Must select archived table!"); |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | printf("Content-type: text/plain\n\n"); |
|---|
| 68 | printf("tLogMonth.Report(%s) start.\n",cuMonthPullDown); |
|---|
| 69 | |
|---|
| 70 | printf("\nNew OPs: Top 20 by login\n\n"); |
|---|
| 71 | sprintf(gcQuery,"SELECT cLogin,COUNT(uLog) AS CountLog FROM %s WHERE cLabel='New' GROUP BY cLogin ORDER BY CountLog DESC LIMIT 20",cuMonthPullDown); |
|---|
| 72 | mysql_query(&gMysql,gcQuery); |
|---|
| 73 | if(mysql_errno(&gMysql)) |
|---|
| 74 | { |
|---|
| 75 | printf("mysql_error: %s\n",mysql_error(&gMysql)); |
|---|
| 76 | exit(0); |
|---|
| 77 | } |
|---|
| 78 | res=mysql_store_result(&gMysql); |
|---|
| 79 | while((field=mysql_fetch_row(res))) |
|---|
| 80 | { |
|---|
| 81 | if(strlen(field[0])>7) |
|---|
| 82 | cTabs="\t\t\t\t\t"; |
|---|
| 83 | else |
|---|
| 84 | cTabs="\t\t\t\t\t\t"; |
|---|
| 85 | printf("%s%s%s\n",field[0],cTabs,field[1]); |
|---|
| 86 | } |
|---|
| 87 | mysql_free_result(res); |
|---|
| 88 | |
|---|
| 89 | printf("\nMod OPs: Top 20 by login\n\n"); |
|---|
| 90 | sprintf(gcQuery,"SELECT cLogin,COUNT(uLog) AS CountLog FROM %s WHERE cLabel='Mod' GROUP BY cLogin ORDER BY CountLog DESC LIMIT 20",cuMonthPullDown); |
|---|
| 91 | mysql_query(&gMysql,gcQuery); |
|---|
| 92 | if(mysql_errno(&gMysql)) |
|---|
| 93 | { |
|---|
| 94 | printf("mysql_error: %s\n",mysql_error(&gMysql)); |
|---|
| 95 | exit(0); |
|---|
| 96 | } |
|---|
| 97 | res=mysql_store_result(&gMysql); |
|---|
| 98 | while((field=mysql_fetch_row(res))) |
|---|
| 99 | { |
|---|
| 100 | if(strlen(field[0])>7) |
|---|
| 101 | cTabs="\t\t\t\t\t"; |
|---|
| 102 | else |
|---|
| 103 | cTabs="\t\t\t\t\t\t"; |
|---|
| 104 | printf("%s%s%s\n",field[0],cTabs,field[1]); |
|---|
| 105 | } |
|---|
| 106 | mysql_free_result(res); |
|---|
| 107 | |
|---|
| 108 | printf("\nDel OPs: Top 20 by login\n\n"); |
|---|
| 109 | sprintf(gcQuery,"SELECT cLogin,COUNT(uLog) AS CountLog FROM %s WHERE cLabel='Del' GROUP BY cLogin ORDER BY CountLog DESC LIMIT 20",cuMonthPullDown); |
|---|
| 110 | mysql_query(&gMysql,gcQuery); |
|---|
| 111 | if(mysql_errno(&gMysql)) |
|---|
| 112 | { |
|---|
| 113 | printf("mysql_error: %s\n",mysql_error(&gMysql)); |
|---|
| 114 | exit(0); |
|---|
| 115 | } |
|---|
| 116 | res=mysql_store_result(&gMysql); |
|---|
| 117 | while((field=mysql_fetch_row(res))) |
|---|
| 118 | { |
|---|
| 119 | if(strlen(field[0])>7) |
|---|
| 120 | cTabs="\t\t\t\t\t"; |
|---|
| 121 | else |
|---|
| 122 | cTabs="\t\t\t\t\t\t"; |
|---|
| 123 | printf("%s%s%s\n",field[0],cTabs,field[1]); |
|---|
| 124 | } |
|---|
| 125 | mysql_free_result(res); |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | printf("\ntLogMonth.Report() end.\n"); |
|---|
| 129 | exit(0); |
|---|
| 130 | } |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | }//void ExttLogMonthCommands(pentry entries[], int x) |
|---|
| 134 | |
|---|
| 135 | |
|---|
| 136 | void ExttLogMonthButtons(void) |
|---|
| 137 | { |
|---|
| 138 | OpenFieldSet("tLogMonth Aux Panel",100); |
|---|
| 139 | |
|---|
| 140 | printf("<u>Table Tips</u><br>"); |
|---|
| 141 | printf("This table is used to load command line archived read only tLog data one month at a time. You can then search and/or run reports on this historical data. Some simple reports do not require loading, just selecting the archive table below.<p>"); |
|---|
| 142 | |
|---|
| 143 | printf("<u>Archive Tools</u><br>"); |
|---|
| 144 | tTablePullDown("tMonth;cuMonthPullDown","cLabel","cLabel",uMonth,1); |
|---|
| 145 | printf("<p><input class=lalertButton title='Load selected month data' type=submit name=gcCommand value='Load'><p>"); |
|---|
| 146 | printf("<p><input class=largeButton title='Simple example must select archive above' type=submit name=gcCommand value='Top OP Stats Report'><p>"); |
|---|
| 147 | |
|---|
| 148 | if(uLog && cLabel[0] && strcmp(cLabel,"Del") && guPermLevel>10 |
|---|
| 149 | && uTablePK[0] && cTableName[0]) |
|---|
| 150 | LogMonthSummary(); |
|---|
| 151 | |
|---|
| 152 | CloseFieldSet(); |
|---|
| 153 | |
|---|
| 154 | }//void ExttLogMonthButtons(void) |
|---|
| 155 | |
|---|
| 156 | |
|---|
| 157 | void ExttLogMonthAuxTable(void) |
|---|
| 158 | { |
|---|
| 159 | |
|---|
| 160 | }//void ExttLogMonthAuxTable(void) |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | void ExttLogMonthGetHook(entry gentries[], int x) |
|---|
| 164 | { |
|---|
| 165 | register int i; |
|---|
| 166 | |
|---|
| 167 | for(i=0;i<x;i++) |
|---|
| 168 | { |
|---|
| 169 | if(!strcmp(gentries[i].name,"uLog")) |
|---|
| 170 | { |
|---|
| 171 | sscanf(gentries[i].val,"%u",&uLog); |
|---|
| 172 | guMode=6; |
|---|
| 173 | } |
|---|
| 174 | } |
|---|
| 175 | tLogMonth(""); |
|---|
| 176 | |
|---|
| 177 | }//void ExttLogMonthGetHook(entry gentries[], int x) |
|---|
| 178 | |
|---|
| 179 | |
|---|
| 180 | void ExttLogMonthSelect(void) |
|---|
| 181 | { |
|---|
| 182 | ExtSelect("tLogMonth",VAR_LIST_tLogMonth); |
|---|
| 183 | |
|---|
| 184 | }//void ExttLogMonthSelect(void) |
|---|
| 185 | |
|---|
| 186 | |
|---|
| 187 | void ExttLogMonthSelectRow(void) |
|---|
| 188 | { |
|---|
| 189 | ExtSelectRow("tLogMonth",VAR_LIST_tLogMonth,uLog); |
|---|
| 190 | |
|---|
| 191 | }//void ExttLogMonthSelectRow(void) |
|---|
| 192 | |
|---|
| 193 | |
|---|
| 194 | void ExttLogMonthListSelect(void) |
|---|
| 195 | { |
|---|
| 196 | char cCat[512]; |
|---|
| 197 | |
|---|
| 198 | ExtListSelect("tLogMonth",VAR_LIST_tLogMonth); |
|---|
| 199 | |
|---|
| 200 | //Changes here must be reflected below in ExttLogMonthListFilter() |
|---|
| 201 | if(!strcmp(gcFilter,"uLog")) |
|---|
| 202 | { |
|---|
| 203 | sscanf(gcCommand,"%u",&uLog); |
|---|
| 204 | strcat(gcQuery," WHERE "); |
|---|
| 205 | sprintf(cCat,"tLogMonth.uLog=%u ORDER BY uLog",uLog); |
|---|
| 206 | strcat(gcQuery,cCat); |
|---|
| 207 | } |
|---|
| 208 | else if(!strcmp(gcFilter,"cLabel")) |
|---|
| 209 | { |
|---|
| 210 | strcat(gcQuery," WHERE "); |
|---|
| 211 | sprintf(cCat,"tLogMonth.cLabel='%s' ORDER BY uLog",gcCommand); |
|---|
| 212 | strcat(gcQuery,cCat); |
|---|
| 213 | } |
|---|
| 214 | else if(!strcmp(gcFilter,"uLogType")) |
|---|
| 215 | { |
|---|
| 216 | sscanf(gcCommand,"%u",&uLogType); |
|---|
| 217 | strcat(gcQuery," WHERE "); |
|---|
| 218 | sprintf(cCat,"tLogMonth.uLogType=%u ORDER BY uLog",uLog); |
|---|
| 219 | strcat(gcQuery,cCat); |
|---|
| 220 | } |
|---|
| 221 | else if(!strcmp(gcFilter,"uLoginClient")) |
|---|
| 222 | { |
|---|
| 223 | sscanf(gcCommand,"%u",&uLoginClient); |
|---|
| 224 | strcat(gcQuery," WHERE "); |
|---|
| 225 | sprintf(cCat,"tLogMonth.uLoginClient=%u ORDER BY uLog",uLoginClient); |
|---|
| 226 | strcat(gcQuery,cCat); |
|---|
| 227 | } |
|---|
| 228 | else if(!strcmp(gcFilter,"cLogin")) |
|---|
| 229 | { |
|---|
| 230 | strcat(gcQuery," WHERE "); |
|---|
| 231 | sprintf(cCat,"tLogMonth.cLogin LIKE '%s' ORDER BY cLogin,uLog",gcCommand); |
|---|
| 232 | strcat(gcQuery,cCat); |
|---|
| 233 | } |
|---|
| 234 | else if(!strcmp(gcFilter,"cHost")) |
|---|
| 235 | { |
|---|
| 236 | strcat(gcQuery," WHERE "); |
|---|
| 237 | sprintf(cCat,"tLogMonth.cHost LIKE '%s' ORDER BY cHost,uLog",gcCommand); |
|---|
| 238 | strcat(gcQuery,cCat); |
|---|
| 239 | } |
|---|
| 240 | else if(!strcmp(gcFilter,"uTablePK")) |
|---|
| 241 | { |
|---|
| 242 | strcat(gcQuery," WHERE "); |
|---|
| 243 | sprintf(cCat,"tLogMonth.uTablePK=%s ORDER BY cTableName,uTablePK,uLog",gcCommand); |
|---|
| 244 | strcat(gcQuery,cCat); |
|---|
| 245 | } |
|---|
| 246 | else if(!strcmp(gcFilter,"uZone")) |
|---|
| 247 | { |
|---|
| 248 | unsigned uZone=0; |
|---|
| 249 | |
|---|
| 250 | sscanf(gcCommand,"%u",&uZone); |
|---|
| 251 | sprintf(cCat,",tResource WHERE tLogMonth.uTablePK=tResource.uResource AND cTableName='tResource' AND tResource.uZone=%u",uZone); |
|---|
| 252 | strcat(gcQuery,cCat); |
|---|
| 253 | } |
|---|
| 254 | else if(1) |
|---|
| 255 | { |
|---|
| 256 | //None NO FILTER |
|---|
| 257 | strcpy(gcFilter,"None"); |
|---|
| 258 | strcat(gcQuery," ORDER BY uLog"); |
|---|
| 259 | } |
|---|
| 260 | |
|---|
| 261 | }//void ExttLogMonthListSelect(void) |
|---|
| 262 | |
|---|
| 263 | |
|---|
| 264 | void ExttLogMonthListFilter(void) |
|---|
| 265 | { |
|---|
| 266 | //Filter |
|---|
| 267 | printf(" Filter on "); |
|---|
| 268 | printf("<select name=gcFilter>"); |
|---|
| 269 | if(strcmp(gcFilter,"uLog")) |
|---|
| 270 | printf("<option>uLog</option>"); |
|---|
| 271 | else |
|---|
| 272 | printf("<option selected>uLog</option>"); |
|---|
| 273 | if(strcmp(gcFilter,"cLabel")) |
|---|
| 274 | printf("<option>cLabel</option>"); |
|---|
| 275 | else |
|---|
| 276 | printf("<option selected>cLabel</option>"); |
|---|
| 277 | if(strcmp(gcFilter,"uLogType")) |
|---|
| 278 | printf("<option>uLogType</option>"); |
|---|
| 279 | else |
|---|
| 280 | printf("<option selected>uLogType</option>"); |
|---|
| 281 | if(strcmp(gcFilter,"uLoginClient")) |
|---|
| 282 | printf("<option>uLoginClient</option>"); |
|---|
| 283 | else |
|---|
| 284 | printf("<option selected>uLoginClient</option>"); |
|---|
| 285 | if(strcmp(gcFilter,"cLogin")) |
|---|
| 286 | printf("<option>cLogin</option>"); |
|---|
| 287 | else |
|---|
| 288 | printf("<option selected>cLogin</option>"); |
|---|
| 289 | if(strcmp(gcFilter,"cHost")) |
|---|
| 290 | printf("<option>cHost</option>"); |
|---|
| 291 | else |
|---|
| 292 | printf("<option selected>cHost</option>"); |
|---|
| 293 | if(strcmp(gcFilter,"uTablePK")) |
|---|
| 294 | printf("<option>uTablePK</option>"); |
|---|
| 295 | else |
|---|
| 296 | printf("<option selected>uTablePK</option>"); |
|---|
| 297 | if(strcmp(gcFilter,"uZone")) |
|---|
| 298 | printf("<option>uZone</option>"); |
|---|
| 299 | else |
|---|
| 300 | printf("<option selected>uZone</option>"); |
|---|
| 301 | if(strcmp(gcFilter,"None")) |
|---|
| 302 | printf("<option>None</option>"); |
|---|
| 303 | else |
|---|
| 304 | printf("<option selected>None</option>"); |
|---|
| 305 | printf("</select>"); |
|---|
| 306 | |
|---|
| 307 | }//void ExttLogMonthListFilter(void) |
|---|
| 308 | |
|---|
| 309 | |
|---|
| 310 | void ExttLogMonthNavBar(void) |
|---|
| 311 | { |
|---|
| 312 | printf(LANG_NBB_SKIPFIRST); |
|---|
| 313 | printf(LANG_NBB_SKIPBACK); |
|---|
| 314 | printf(LANG_NBB_SEARCH); |
|---|
| 315 | |
|---|
| 316 | if(guPermLevel>9) |
|---|
| 317 | printf(LANG_NBB_LIST); |
|---|
| 318 | |
|---|
| 319 | printf(LANG_NBB_SKIPNEXT); |
|---|
| 320 | printf(LANG_NBB_SKIPLAST); |
|---|
| 321 | printf(" \n"); |
|---|
| 322 | |
|---|
| 323 | }//void ExttLogMonthNavBar(void) |
|---|
| 324 | |
|---|
| 325 | |
|---|
| 326 | |
|---|
| 327 | void LogMonthSummary(void) |
|---|
| 328 | { |
|---|
| 329 | unsigned uTPK=0; |
|---|
| 330 | |
|---|
| 331 | sscanf(uTablePK,"%u",&uTPK); |
|---|
| 332 | |
|---|
| 333 | printf("<u>LogMonthSummary</u><br>\n"); |
|---|
| 334 | if(!strcmp(cTableName,"tZone")) |
|---|
| 335 | { |
|---|
| 336 | printf("tZone<blockquote>\n"); |
|---|
| 337 | printf("%s<br>\n",ForeignKey("tZone","cZone",uTPK)); |
|---|
| 338 | printf("</blockquote>\n"); |
|---|
| 339 | } |
|---|
| 340 | else if(!strcmp(cTableName,"tResource")) |
|---|
| 341 | { |
|---|
| 342 | unsigned uZone=0; |
|---|
| 343 | unsigned uRRType=0; |
|---|
| 344 | |
|---|
| 345 | sscanf(ForeignKey("tResource","uZone",uTPK),"%u",&uZone); |
|---|
| 346 | sscanf(ForeignKey("tResource","uRRType",uTPK),"%u",&uRRType); |
|---|
| 347 | |
|---|
| 348 | printf("<a class=darkLink title='Jump to tResource entry' href=unxsVZ.cgi?gcFunction=tResource&uResource=%u>tResource</a><blockquote>\n",uTPK); |
|---|
| 349 | printf("cZone=%s<br>\n",ForeignKey("tZone","cZone",uZone)); |
|---|
| 350 | printf("cName=%s<br>\n",ForeignKey("tResource","cName",uTPK)); |
|---|
| 351 | printf("RRType=%s<br>\n",ForeignKey("tRRType","cLabel",uRRType)); |
|---|
| 352 | printf("cParam1=%.32s<br>\n",ForeignKey("tResource","cParam1",uTPK)); |
|---|
| 353 | printf("cParam2=%s<br>\n",ForeignKey("tResource","cParam2",uTPK)); |
|---|
| 354 | printf("cComment=%s<br>\n",ForeignKey("tResource","cComment",uTPK)); |
|---|
| 355 | printf("Contact=%s<br></blockquote>\n", |
|---|
| 356 | ForeignKey("tClient","cLabel",uLoginClient)); |
|---|
| 357 | } |
|---|
| 358 | else if(1) |
|---|
| 359 | { |
|---|
| 360 | printf("No summary available for %s\n",cTableName); |
|---|
| 361 | } |
|---|
| 362 | }//void LogMonthSummary(void); |
|---|
| 363 | |
|---|