Fossil SCM
Improvements to the access log. The display is still primitive.
Commit
e3b3c5cfbb65b2727d9550d0725c1c9728cdc1b2
Parent
f274222ea7adff9…
2 files changed
+1
-1
+38
-15
+1
-1
| --- src/login.c | ||
| +++ src/login.c | ||
| @@ -213,11 +213,11 @@ | ||
| 213 | 213 | sha1sum_blob(&b, &b); |
| 214 | 214 | zCookie = sqlite3_mprintf("anon/%s/%s", zNow, blob_buffer(&b)); |
| 215 | 215 | blob_reset(&b); |
| 216 | 216 | free(zNow); |
| 217 | 217 | cgi_set_cookie(zCookieName, zCookie, 0, 6*3600); |
| 218 | - record_login_attempt("anonyous", zIpAddr, 1); | |
| 218 | + record_login_attempt("anonymous", zIpAddr, 1); | |
| 219 | 219 | redirect_to_g(); |
| 220 | 220 | } |
| 221 | 221 | if( zUsername!=0 && zPasswd!=0 && zPasswd[0]!=0 ){ |
| 222 | 222 | zSha1Pw = sha1_shared_secret(zPasswd, zUsername); |
| 223 | 223 | uid = db_int(0, |
| 224 | 224 |
| --- src/login.c | |
| +++ src/login.c | |
| @@ -213,11 +213,11 @@ | |
| 213 | sha1sum_blob(&b, &b); |
| 214 | zCookie = sqlite3_mprintf("anon/%s/%s", zNow, blob_buffer(&b)); |
| 215 | blob_reset(&b); |
| 216 | free(zNow); |
| 217 | cgi_set_cookie(zCookieName, zCookie, 0, 6*3600); |
| 218 | record_login_attempt("anonyous", zIpAddr, 1); |
| 219 | redirect_to_g(); |
| 220 | } |
| 221 | if( zUsername!=0 && zPasswd!=0 && zPasswd[0]!=0 ){ |
| 222 | zSha1Pw = sha1_shared_secret(zPasswd, zUsername); |
| 223 | uid = db_int(0, |
| 224 |
| --- src/login.c | |
| +++ src/login.c | |
| @@ -213,11 +213,11 @@ | |
| 213 | sha1sum_blob(&b, &b); |
| 214 | zCookie = sqlite3_mprintf("anon/%s/%s", zNow, blob_buffer(&b)); |
| 215 | blob_reset(&b); |
| 216 | free(zNow); |
| 217 | cgi_set_cookie(zCookieName, zCookie, 0, 6*3600); |
| 218 | record_login_attempt("anonymous", zIpAddr, 1); |
| 219 | redirect_to_g(); |
| 220 | } |
| 221 | if( zUsername!=0 && zPasswd!=0 && zPasswd[0]!=0 ){ |
| 222 | zSha1Pw = sha1_shared_secret(zPasswd, zUsername); |
| 223 | uid = db_int(0, |
| 224 |
+38
-15
| --- src/user.c | ||
| +++ src/user.c | ||
| @@ -389,46 +389,69 @@ | ||
| 389 | 389 | } |
| 390 | 390 | |
| 391 | 391 | /* |
| 392 | 392 | ** WEBPAGE: access_log |
| 393 | 393 | ** |
| 394 | -** s Success only | |
| 395 | -** f Failures only | |
| 394 | +** y=N 1: success only. 2: failure only. 3: both | |
| 396 | 395 | ** n=N Number of entries to show |
| 397 | 396 | ** o=N Skip this many entries |
| 398 | 397 | */ |
| 399 | 398 | void access_log_page(void){ |
| 400 | - int bSuccessOnly = P("s")!=0; | |
| 401 | - int bFailOnly = P("f")!=0; | |
| 399 | + int y = atoi(PD("y","3")); | |
| 402 | 400 | int n = atoi(PD("n","50")); |
| 403 | 401 | int skip = atoi(PD("o","0")); |
| 402 | + const char *zNow; | |
| 403 | + Blob sql; | |
| 404 | 404 | Stmt q; |
| 405 | + int cnt = 0; | |
| 405 | 406 | |
| 406 | 407 | login_check_credentials(); |
| 407 | 408 | if( !g.okAdmin ){ login_needed(); return; } |
| 408 | 409 | |
| 409 | 410 | style_header("Access Log"); |
| 410 | - db_prepare(&q, | |
| 411 | - "SELECT uname, ipaddr, datetime(mtime), success" | |
| 412 | - " FROM accesslog ORDER BY mtime DESC" | |
| 413 | - " LIMIT %d OFFSET %d", n, skip); | |
| 414 | - @ <table border="1" cellpadding="5"> | |
| 415 | - @ <tr><th>Date</th><th>User</th><th>IP Address</th><th>Success?</th></tr> | |
| 411 | + blob_zero(&sql); | |
| 412 | + blob_append(&sql, | |
| 413 | + "SELECT uname, ipaddr, datetime(mtime, 'localtime'), success" | |
| 414 | + " FROM accesslog", -1 | |
| 415 | + ); | |
| 416 | + if( y==1 ){ | |
| 417 | + blob_append(&sql, " WHERE success", -1); | |
| 418 | + }else if( y==2 ){ | |
| 419 | + blob_append(&sql, " WHERE NOT success", -1); | |
| 420 | + } | |
| 421 | + blob_appendf(&sql," ORDER BY mtime DESC LIMIT %d OFFSET %d", n+1, skip); | |
| 422 | + if( skip ){ | |
| 423 | + style_submenu_element("Newer", "Newer entries", | |
| 424 | + "%s/access_log?o=%d&n=%d&y=%d", g.zTop, skip>=n ? skip-n : 0, | |
| 425 | + n, y); | |
| 426 | + } | |
| 427 | + db_prepare(&q, blob_str(&sql)); | |
| 428 | + zNow = db_text(0, "SELECT datetime('now','localtime');"); | |
| 429 | + @ <center><table border="1" cellpadding="5"> | |
| 430 | + @ <tr><th width="33%%">Date</th><th width="34%%">User</th> | |
| 431 | + @ <th width="33%%">IP Address</th></tr> | |
| 416 | 432 | while( db_step(&q)==SQLITE_ROW ){ |
| 417 | 433 | const char *zName = db_column_text(&q, 0); |
| 418 | 434 | const char *zIP = db_column_text(&q, 1); |
| 419 | 435 | const char *zDate = db_column_text(&q, 2); |
| 420 | 436 | int bSuccess = db_column_int(&q, 3); |
| 421 | - if( bSuccessOnly && bSuccess==0 ) continue; | |
| 422 | - if( bFailOnly && bSuccess!=0 ) continue; | |
| 437 | + cnt++; | |
| 438 | + if( cnt>n ){ | |
| 439 | + style_submenu_element("Older", "Older entries", | |
| 440 | + "%s/access_log?o=%d&n=%d&y=%d", g.zTop, skip+n, n, y); | |
| 441 | + break; | |
| 442 | + } | |
| 423 | 443 | if( bSuccess ){ |
| 424 | 444 | @ <tr> |
| 425 | 445 | }else{ |
| 426 | 446 | @ <tr bgcolor="#ffacc0"> |
| 427 | 447 | } |
| 428 | - @ <td>%s(zDate)</td><td>%h(zName)</td><td>%h(zIP)</td> | |
| 429 | - @ <td>%s(bSuccess?"yes":"no")</td></tr> | |
| 448 | + @ <td>%s(zDate)</td><td>%h(zName)</td><td>%h(zIP)</td></tr> | |
| 449 | + } | |
| 450 | + if( skip>0 || cnt>n ){ | |
| 451 | + style_submenu_element("All", "All entries", | |
| 452 | + "%s/access_log?n=10000000", g.zTop); | |
| 430 | 453 | } |
| 431 | - @ </table> | |
| 454 | + @ </table></center> | |
| 432 | 455 | db_finalize(&q); |
| 433 | 456 | style_footer(); |
| 434 | 457 | } |
| 435 | 458 |
| --- src/user.c | |
| +++ src/user.c | |
| @@ -389,46 +389,69 @@ | |
| 389 | } |
| 390 | |
| 391 | /* |
| 392 | ** WEBPAGE: access_log |
| 393 | ** |
| 394 | ** s Success only |
| 395 | ** f Failures only |
| 396 | ** n=N Number of entries to show |
| 397 | ** o=N Skip this many entries |
| 398 | */ |
| 399 | void access_log_page(void){ |
| 400 | int bSuccessOnly = P("s")!=0; |
| 401 | int bFailOnly = P("f")!=0; |
| 402 | int n = atoi(PD("n","50")); |
| 403 | int skip = atoi(PD("o","0")); |
| 404 | Stmt q; |
| 405 | |
| 406 | login_check_credentials(); |
| 407 | if( !g.okAdmin ){ login_needed(); return; } |
| 408 | |
| 409 | style_header("Access Log"); |
| 410 | db_prepare(&q, |
| 411 | "SELECT uname, ipaddr, datetime(mtime), success" |
| 412 | " FROM accesslog ORDER BY mtime DESC" |
| 413 | " LIMIT %d OFFSET %d", n, skip); |
| 414 | @ <table border="1" cellpadding="5"> |
| 415 | @ <tr><th>Date</th><th>User</th><th>IP Address</th><th>Success?</th></tr> |
| 416 | while( db_step(&q)==SQLITE_ROW ){ |
| 417 | const char *zName = db_column_text(&q, 0); |
| 418 | const char *zIP = db_column_text(&q, 1); |
| 419 | const char *zDate = db_column_text(&q, 2); |
| 420 | int bSuccess = db_column_int(&q, 3); |
| 421 | if( bSuccessOnly && bSuccess==0 ) continue; |
| 422 | if( bFailOnly && bSuccess!=0 ) continue; |
| 423 | if( bSuccess ){ |
| 424 | @ <tr> |
| 425 | }else{ |
| 426 | @ <tr bgcolor="#ffacc0"> |
| 427 | } |
| 428 | @ <td>%s(zDate)</td><td>%h(zName)</td><td>%h(zIP)</td> |
| 429 | @ <td>%s(bSuccess?"yes":"no")</td></tr> |
| 430 | } |
| 431 | @ </table> |
| 432 | db_finalize(&q); |
| 433 | style_footer(); |
| 434 | } |
| 435 |
| --- src/user.c | |
| +++ src/user.c | |
| @@ -389,46 +389,69 @@ | |
| 389 | } |
| 390 | |
| 391 | /* |
| 392 | ** WEBPAGE: access_log |
| 393 | ** |
| 394 | ** y=N 1: success only. 2: failure only. 3: both |
| 395 | ** n=N Number of entries to show |
| 396 | ** o=N Skip this many entries |
| 397 | */ |
| 398 | void access_log_page(void){ |
| 399 | int y = atoi(PD("y","3")); |
| 400 | int n = atoi(PD("n","50")); |
| 401 | int skip = atoi(PD("o","0")); |
| 402 | const char *zNow; |
| 403 | Blob sql; |
| 404 | Stmt q; |
| 405 | int cnt = 0; |
| 406 | |
| 407 | login_check_credentials(); |
| 408 | if( !g.okAdmin ){ login_needed(); return; } |
| 409 | |
| 410 | style_header("Access Log"); |
| 411 | blob_zero(&sql); |
| 412 | blob_append(&sql, |
| 413 | "SELECT uname, ipaddr, datetime(mtime, 'localtime'), success" |
| 414 | " FROM accesslog", -1 |
| 415 | ); |
| 416 | if( y==1 ){ |
| 417 | blob_append(&sql, " WHERE success", -1); |
| 418 | }else if( y==2 ){ |
| 419 | blob_append(&sql, " WHERE NOT success", -1); |
| 420 | } |
| 421 | blob_appendf(&sql," ORDER BY mtime DESC LIMIT %d OFFSET %d", n+1, skip); |
| 422 | if( skip ){ |
| 423 | style_submenu_element("Newer", "Newer entries", |
| 424 | "%s/access_log?o=%d&n=%d&y=%d", g.zTop, skip>=n ? skip-n : 0, |
| 425 | n, y); |
| 426 | } |
| 427 | db_prepare(&q, blob_str(&sql)); |
| 428 | zNow = db_text(0, "SELECT datetime('now','localtime');"); |
| 429 | @ <center><table border="1" cellpadding="5"> |
| 430 | @ <tr><th width="33%%">Date</th><th width="34%%">User</th> |
| 431 | @ <th width="33%%">IP Address</th></tr> |
| 432 | while( db_step(&q)==SQLITE_ROW ){ |
| 433 | const char *zName = db_column_text(&q, 0); |
| 434 | const char *zIP = db_column_text(&q, 1); |
| 435 | const char *zDate = db_column_text(&q, 2); |
| 436 | int bSuccess = db_column_int(&q, 3); |
| 437 | cnt++; |
| 438 | if( cnt>n ){ |
| 439 | style_submenu_element("Older", "Older entries", |
| 440 | "%s/access_log?o=%d&n=%d&y=%d", g.zTop, skip+n, n, y); |
| 441 | break; |
| 442 | } |
| 443 | if( bSuccess ){ |
| 444 | @ <tr> |
| 445 | }else{ |
| 446 | @ <tr bgcolor="#ffacc0"> |
| 447 | } |
| 448 | @ <td>%s(zDate)</td><td>%h(zName)</td><td>%h(zIP)</td></tr> |
| 449 | } |
| 450 | if( skip>0 || cnt>n ){ |
| 451 | style_submenu_element("All", "All entries", |
| 452 | "%s/access_log?n=10000000", g.zTop); |
| 453 | } |
| 454 | @ </table></center> |
| 455 | db_finalize(&q); |
| 456 | style_footer(); |
| 457 | } |
| 458 |