Fossil SCM
Add a primitive display of the access-log history.
Commit
f274222ea7adff9944e29da4e14c534e59abdd92
Parent
6fdf52980316e49…
2 files changed
+2
+45
+2
| --- src/setup.c | ||
| +++ src/setup.c | ||
| @@ -84,10 +84,12 @@ | ||
| 84 | 84 | "Change the logo image for the server"); |
| 85 | 85 | setup_menu_entry("Shunned", "shun", |
| 86 | 86 | "Show artifacts that are shunned by this repository"); |
| 87 | 87 | setup_menu_entry("Log", "rcvfromlist", |
| 88 | 88 | "A record of received artifacts and their sources"); |
| 89 | + setup_menu_entry("User-Log", "access_log", | |
| 90 | + "A record of login attempts"); | |
| 89 | 91 | setup_menu_entry("Stats", "stat", |
| 90 | 92 | "Display repository statistics"); |
| 91 | 93 | @ </table> |
| 92 | 94 | |
| 93 | 95 | style_footer(); |
| 94 | 96 |
| --- src/setup.c | |
| +++ src/setup.c | |
| @@ -84,10 +84,12 @@ | |
| 84 | "Change the logo image for the server"); |
| 85 | setup_menu_entry("Shunned", "shun", |
| 86 | "Show artifacts that are shunned by this repository"); |
| 87 | setup_menu_entry("Log", "rcvfromlist", |
| 88 | "A record of received artifacts and their sources"); |
| 89 | setup_menu_entry("Stats", "stat", |
| 90 | "Display repository statistics"); |
| 91 | @ </table> |
| 92 | |
| 93 | style_footer(); |
| 94 |
| --- src/setup.c | |
| +++ src/setup.c | |
| @@ -84,10 +84,12 @@ | |
| 84 | "Change the logo image for the server"); |
| 85 | setup_menu_entry("Shunned", "shun", |
| 86 | "Show artifacts that are shunned by this repository"); |
| 87 | setup_menu_entry("Log", "rcvfromlist", |
| 88 | "A record of received artifacts and their sources"); |
| 89 | setup_menu_entry("User-Log", "access_log", |
| 90 | "A record of login attempts"); |
| 91 | setup_menu_entry("Stats", "stat", |
| 92 | "Display repository statistics"); |
| 93 | @ </table> |
| 94 | |
| 95 | style_footer(); |
| 96 |
+45
| --- src/user.c | ||
| +++ src/user.c | ||
| @@ -385,5 +385,50 @@ | ||
| 385 | 385 | db_multi_exec( |
| 386 | 386 | "UPDATE user SET pw=sha1_shared_secret(pw,login)" |
| 387 | 387 | " WHERE length(pw)>0 AND length(pw)!=40" |
| 388 | 388 | ); |
| 389 | 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 | +} | |
| 390 | 435 |
| --- src/user.c | |
| +++ src/user.c | |
| @@ -385,5 +385,50 @@ | |
| 385 | db_multi_exec( |
| 386 | "UPDATE user SET pw=sha1_shared_secret(pw,login)" |
| 387 | " WHERE length(pw)>0 AND length(pw)!=40" |
| 388 | ); |
| 389 | } |
| 390 |
| --- src/user.c | |
| +++ src/user.c | |
| @@ -385,5 +385,50 @@ | |
| 385 | db_multi_exec( |
| 386 | "UPDATE user SET pw=sha1_shared_secret(pw,login)" |
| 387 | " WHERE length(pw)>0 AND length(pw)!=40" |
| 388 | ); |
| 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 |