Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Added basic /admin_log page, added settings change logging through onoff_attribute(). |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | admin-logging |
| Files: | files | file ages | folders |
| SHA1: |
8f1fc455819bddb82817503b6aae72e0 |
| User & Date: | stephan 2014-11-28 17:38:32.834 |
Context
|
2014-11-30
| ||
| 13:27 | merged in trunk. ... (check-in: 1526dd4c7e user: stephan tags: admin-logging) | |
|
2014-11-28
| ||
| 17:38 | Added basic /admin_log page, added settings change logging through onoff_attribute(). ... (check-in: 8f1fc45581 user: stephan tags: admin-logging) | |
| 15:05 | Change the name of the admin-log table to "admin_log". Only write to it if the "admin-log" setting is enabled (off by default). Make sure the admin_log table is created in the repository and not in the local or config databases. ... (check-in: 5e0514a607 user: drh tags: admin-logging) | |
Changes
Changes to src/db.c.
| ︙ | ︙ | |||
2690 2691 2692 2693 2694 2695 2696 |
void create_admin_log_table(void){
static int once = 0;
if( once ) return;
once = 1;
db_multi_exec(
"CREATE TABLE IF NOT EXISTS \"%w\".admin_log(\n"
" id INTEGER PRIMARY KEY,\n"
| | | < | > > > > > | 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 |
void create_admin_log_table(void){
static int once = 0;
if( once ) return;
once = 1;
db_multi_exec(
"CREATE TABLE IF NOT EXISTS \"%w\".admin_log(\n"
" id INTEGER PRIMARY KEY,\n"
" time INTEGER, -- Seconds since 1970\n"
" page TEXT, -- path of page\n"
" who TEXT, -- User who made the change\n "
" what TEXT -- What changed\n"
")", db_name("repository")
);
}
/*
** Write a message into the admin_event table, if admin logging is
** enabled via the admin-log configuration option.
*/
void admin_log(const char *zFormat, ...){
Blob what = empty_blob;
va_list ap;
if( !db_get_boolean("admin-log", 0) ){
/* Potential leak here (on %z params) but
the alternative is to let blob_vappendf()
do it below. */
return;
}
create_admin_log_table();
va_start(ap,zFormat);
blob_vappendf( &what, zFormat, ap );
va_end(ap);
db_multi_exec("INSERT INTO admin_log(time,page,who,what)"
" VALUES(now(), %Q, %Q, %B)",
g.zPath, g.zLogin, &what);
|
| ︙ | ︙ |
Changes to src/setup.c.
| ︙ | ︙ | |||
107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
"Change the logo and background images for the server");
setup_menu_entry("Shunned", "shun",
"Show artifacts that are shunned by this repository");
setup_menu_entry("Log", "rcvfromlist",
"A record of received artifacts and their sources");
setup_menu_entry("User-Log", "access_log",
"A record of login attempts");
setup_menu_entry("Stats", "stat",
"Display repository statistics");
setup_menu_entry("SQL", "admin_sql",
"Enter raw SQL commands");
setup_menu_entry("TH1", "admin_th1",
"Enter raw TH1 commands");
@ </table>
| > > | 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
"Change the logo and background images for the server");
setup_menu_entry("Shunned", "shun",
"Show artifacts that are shunned by this repository");
setup_menu_entry("Log", "rcvfromlist",
"A record of received artifacts and their sources");
setup_menu_entry("User-Log", "access_log",
"A record of login attempts");
setup_menu_entry("Admin-Log", "admin_log",
"View the admin_log entries");
setup_menu_entry("Stats", "stat",
"Display repository statistics");
setup_menu_entry("SQL", "admin_sql",
"Enter raw SQL commands");
setup_menu_entry("TH1", "admin_th1",
"Enter raw TH1 commands");
@ </table>
|
| ︙ | ︙ | |||
380 381 382 383 384 385 386 |
}
login_verify_csrf_secret();
db_multi_exec(
"REPLACE INTO user(uid,login,info,pw,cap,mtime) "
"VALUES(nullif(%d,0),%Q,%Q,%Q,%Q,now())",
uid, zLogin, P("info"), zPw, zCap
);
| | > | 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 |
}
login_verify_csrf_secret();
db_multi_exec(
"REPLACE INTO user(uid,login,info,pw,cap,mtime) "
"VALUES(nullif(%d,0),%Q,%Q,%Q,%Q,now())",
uid, zLogin, P("info"), zPw, zCap
);
admin_log( "Updated user [%q] with capabilities [%q].",
zLogin, zCap );
if( atoi(PD("all","0"))>0 ){
Blob sql;
char *zErr = 0;
blob_zero(&sql);
if( zOldLogin==0 ){
blob_appendf(&sql,
"INSERT INTO user(login)"
|
| ︙ | ︙ | |||
406 407 408 409 410 411 412 |
" mtime=now()"
" WHERE login=%Q;",
zLogin, P("pw"), zLogin, P("info"), zCap,
zOldLogin
);
login_group_sql(blob_str(&sql), "<li> ", " </li>\n", &zErr);
blob_reset(&sql);
| | > > | 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 |
" mtime=now()"
" WHERE login=%Q;",
zLogin, P("pw"), zLogin, P("info"), zCap,
zOldLogin
);
login_group_sql(blob_str(&sql), "<li> ", " </li>\n", &zErr);
blob_reset(&sql);
admin_log( "Updated user [%q] in all login groups "
"with capabilities [%q].",
zLogin, zCap );
if( zErr ){
style_header("User Change Error");
admin_log( "Error updating user '%q': %s'.", zLogin, zErr );
@ <span class="loginError">%s(zErr)</span>
@
@ <p><a href="setup_uedit?id=%d(uid)">[Bummer]</a></p>
style_footer();
|
| ︙ | ︙ | |||
863 864 865 866 867 868 869 870 871 872 873 874 875 876 |
zQ = "off";
}
if( zQ ){
int iQ = fossil_strcmp(zQ,"on")==0 || atoi(zQ);
if( iQ!=iVal ){
login_verify_csrf_secret();
db_set(zVar, iQ ? "1" : "0", 0);
iVal = iQ;
}
}
@ <input type="checkbox" name="%s(zQParm)"
if( iVal ){
@ checked="checked"
}
| > > | 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 |
zQ = "off";
}
if( zQ ){
int iQ = fossil_strcmp(zQ,"on")==0 || atoi(zQ);
if( iQ!=iVal ){
login_verify_csrf_secret();
db_set(zVar, iQ ? "1" : "0", 0);
admin_log("Set option [%q] to [%q].",
zVar, iQ ? "on" : "off");
iVal = iQ;
}
}
@ <input type="checkbox" name="%s(zQParm)"
if( iVal ){
@ checked="checked"
}
|
| ︙ | ︙ | |||
2024 2025 2026 2027 2028 2029 2030 |
@ <pre class="th1result">%h(zR)</pre>
}else{
@ <pre class="th1error">%h(zR)</pre>
}
}
style_footer();
}
| > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 |
@ <pre class="th1result">%h(zR)</pre>
}else{
@ <pre class="th1error">%h(zR)</pre>
}
}
style_footer();
}
/*
** WEBPAGE: admin_log
**
*/
void page_admin_log(){
Stmt stLog = empty_Stmt;
Blob qLog = empty_blob;
int limit;
int fLogEnabled;
int counter = 0;
login_check_credentials();
if( !g.perm.Setup && !g.perm.Admin ){
login_needed();
}
style_header("Admin Log");
create_admin_log_table();
limit = atoi(PD("n","20"));
fLogEnabled = db_get_boolean("admin-log", 0);
@ Admin logging is %s(fLogEnabled?"on":"off").
blob_append_sql(&qLog,
"SELECT datetime(time,'unixepoch'), who, page, what "
"FROM admin_log "
"ORDER BY time DESC ");
if(limit>0){
@ %d(limit) Most recent entries:
blob_append_sql(&qLog, "LIMIT %d", limit);
}
db_prepare(&stLog, "%s", blob_sql_text(&qLog));
blob_reset(&qLog);
@ <table id="adminLogTable" class="adminLogTable" width="100%%">
@ <thead>
@ <th>Time</th>
@ <th>User</th>
@ <th>Page</th>
@ <th width="60%%">Message</th>
@ </thead><tbody>
while( SQLITE_ROW == db_step(&stLog) ){
char const * zTime = db_column_text(&stLog, 0);
char const * zUser = db_column_text(&stLog, 1);
char const * zPage = db_column_text(&stLog, 2);
char const * zMessage = db_column_text(&stLog, 3);
@ <tr class="row%d(counter++%2)">
@ <td class="adminTime">%s(zTime)</td>
@ <td>%s(zUser)</td>
@ <td>%s(zPage)</td>
@ <td>%s(zMessage)</td>
@ </tr>
}
@ </tbody></table>
style_footer();
}
|
Changes to src/style.c.
| ︙ | ︙ | |||
1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 |
{ "#usetupEditCapability",
"format for capabilities string, mentioned on the user edit page",
@ font-weight: bold;
},
{ "#canvas", "timeline graph node colors",
@ color: black;
@ background-color: white;
},
{ 0,
0,
0
}
};
| > > > > > > > > > > | 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 |
{ "#usetupEditCapability",
"format for capabilities string, mentioned on the user edit page",
@ font-weight: bold;
},
{ "#canvas", "timeline graph node colors",
@ color: black;
@ background-color: white;
},
{ "table.adminLogTable",
"Class for the /admin_log table",
@ text-align: left
},
{ ".adminLogTable .adminTime",
"Class for the /admin_log table",
@ text-align: left
@ vertical-align: top;
@ white-space: nowrap;
},
{ 0,
0,
0
}
};
|
| ︙ | ︙ |