Fossil SCM

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.

drh 2014-11-28 15:05 UTC admin-logging
Commit 5e0514a607f0fc5ed57099a42832cf953be5591e
1 file changed +34 -23
+34 -23
--- src/db.c
+++ src/db.c
@@ -2204,10 +2204,11 @@
22042204
const char *def; /* Default value */
22052205
};
22062206
#endif /* INTERFACE */
22072207
struct stControlSettings const ctrlSettings[] = {
22082208
{ "access-log", 0, 0, 0, 0, "off" },
2209
+ { "admin-log", 0, 0, 0, 0, "off" },
22092210
{ "allow-symlinks", 0, 0, 1, 0, "off" },
22102211
{ "auto-captcha", "autocaptcha", 0, 0, 0, "on" },
22112212
{ "auto-hyperlink", 0, 0, 0, 0, "on", },
22122213
{ "auto-shun", 0, 0, 0, 0, "on" },
22132214
{ "autosync", 0, 0, 0, 0, "on" },
@@ -2284,10 +2285,13 @@
22842285
** The "unset" command clears a property setting.
22852286
**
22862287
**
22872288
** access-log If enabled, record successful and failed login attempts
22882289
** in the "accesslog" table. Default: off
2290
+**
2291
+** admin-log If enabled, record configuration changes in the
2292
+** "admin_log" table. Default: off
22892293
**
22902294
** allow-symlinks If enabled, don't follow symlinks, and instead treat
22912295
** (versionable) them as symlinks on Unix. Has no effect on Windows
22922296
** (existing links in repository created on Unix become
22932297
** plain-text files with link destination path inside).
@@ -2660,52 +2664,59 @@
26602664
"%s WITHOUT ROWID;\n"
26612665
"INSERT INTO \"%w\" SELECT * FROM \"x_%w\";\n"
26622666
"DROP TABLE \"x_%w\";\n",
26632667
zTName, zTName, blob_sql_text(&newSql), zTName, zTName, zTName
26642668
);
2665
- fossil_print("Converting table %s of %s to WITHOUT ROWID.\n", zTName, g.argv[i]);
2669
+ fossil_print("Converting table %s of %s to WITHOUT ROWID.\n",
2670
+ zTName, g.argv[i]);
26662671
blob_reset(&newSql);
26672672
}
26682673
blob_append_sql(&allSql, "COMMIT;\n");
26692674
db_finalize(&q);
26702675
if( dryRun ){
26712676
fossil_print("SQL that would have been evaluated:\n");
2672
- fossil_print("-------------------------------------------------------------\n");
2677
+ fossil_print("%.78c\n", '-');
26732678
fossil_print("%s", blob_sql_text(&allSql));
26742679
}else{
26752680
db_multi_exec("%s", blob_sql_text(&allSql));
26762681
}
26772682
blob_reset(&allSql);
26782683
db_close(1);
26792684
}
26802685
}
26812686
2682
-
2683
-void admin_log(const char *zFormat, ...){
2687
+/*
2688
+** Make sure the adminlog table exists. Create it if it does not
2689
+*/
2690
+void create_admin_log_table(void){
26842691
static int once = 0;
2685
- char * zUserName = g.userUid>0
2686
- ? db_text(0, "select login from user where uid=%d", g.userUid)
2687
- : 0;
2692
+ if( once ) return;
2693
+ once = 1;
2694
+ db_multi_exec(
2695
+ "CREATE TABLE IF NOT EXISTS \"%w\".admin_log(\n"
2696
+ " id INTEGER PRIMARY KEY,\n"
2697
+ " time FLOAT, -- Seconds since 1970\n"
2698
+ " page TEXT, -- path of page\n"
2699
+ " who TEXT, -- User who made the change\n "
2700
+ " what TEXT -- What changed\n"
2701
+ ")", db_name("repository")
2702
+ );
2703
+}
2704
+
2705
+/*
2706
+** Write a message into the admin_event table, if admin logging is
2707
+** enabled
2708
+*/
2709
+void admin_log(const char *zFormat, ...){
26882710
Blob what = empty_blob;
26892711
va_list ap;
26902712
int rc;
2691
- if(!once){
2692
- once = 1;
2693
- rc = db_multi_exec("CREATE TABLE IF NOT EXISTS aevent("
2694
- "id INTEGER PRIMARY KEY, "
2695
- "time FLOAT /* Julian time */, "
2696
- "page TEXT /* path of page */,"
2697
- "who TEXT /* user name */, "
2698
- "what TEXT /* descr. of event. */ "
2699
- ")");
2700
- fossil_trace("created aevent. rc=%d\n", rc);
2701
- }
2713
+ if( !db_get_boolean("admin-log", 0) ) return;
2714
+ create_admin_log_table();
27022715
va_start(ap,zFormat);
27032716
blob_vappendf( &what, zFormat, ap );
27042717
va_end(ap);
2705
- fossil_trace("what==%B rc=%d\n", &what, rc);
2706
- db_multi_exec("INSERT INTO aevent(id,time,page,who,what) VALUES("
2707
- "NULL, cast(strftime('%%J') AS FLOAT), %Q, %Q, %B"
2708
- ")", g.zPath, zUserName, &what);
2709
- fossil_free(zUserName);
2718
+ db_multi_exec("INSERT INTO admin_log(time,page,who,what)"
2719
+ " VALUES(now(), %Q, %Q, %B)",
2720
+ g.zPath, g.zLogin, &what);
27102721
blob_reset(&what);
27112722
}
27122723
--- src/db.c
+++ src/db.c
@@ -2204,10 +2204,11 @@
2204 const char *def; /* Default value */
2205 };
2206 #endif /* INTERFACE */
2207 struct stControlSettings const ctrlSettings[] = {
2208 { "access-log", 0, 0, 0, 0, "off" },
 
2209 { "allow-symlinks", 0, 0, 1, 0, "off" },
2210 { "auto-captcha", "autocaptcha", 0, 0, 0, "on" },
2211 { "auto-hyperlink", 0, 0, 0, 0, "on", },
2212 { "auto-shun", 0, 0, 0, 0, "on" },
2213 { "autosync", 0, 0, 0, 0, "on" },
@@ -2284,10 +2285,13 @@
2284 ** The "unset" command clears a property setting.
2285 **
2286 **
2287 ** access-log If enabled, record successful and failed login attempts
2288 ** in the "accesslog" table. Default: off
 
 
 
2289 **
2290 ** allow-symlinks If enabled, don't follow symlinks, and instead treat
2291 ** (versionable) them as symlinks on Unix. Has no effect on Windows
2292 ** (existing links in repository created on Unix become
2293 ** plain-text files with link destination path inside).
@@ -2660,52 +2664,59 @@
2660 "%s WITHOUT ROWID;\n"
2661 "INSERT INTO \"%w\" SELECT * FROM \"x_%w\";\n"
2662 "DROP TABLE \"x_%w\";\n",
2663 zTName, zTName, blob_sql_text(&newSql), zTName, zTName, zTName
2664 );
2665 fossil_print("Converting table %s of %s to WITHOUT ROWID.\n", zTName, g.argv[i]);
 
2666 blob_reset(&newSql);
2667 }
2668 blob_append_sql(&allSql, "COMMIT;\n");
2669 db_finalize(&q);
2670 if( dryRun ){
2671 fossil_print("SQL that would have been evaluated:\n");
2672 fossil_print("-------------------------------------------------------------\n");
2673 fossil_print("%s", blob_sql_text(&allSql));
2674 }else{
2675 db_multi_exec("%s", blob_sql_text(&allSql));
2676 }
2677 blob_reset(&allSql);
2678 db_close(1);
2679 }
2680 }
2681
2682
2683 void admin_log(const char *zFormat, ...){
 
 
2684 static int once = 0;
2685 char * zUserName = g.userUid>0
2686 ? db_text(0, "select login from user where uid=%d", g.userUid)
2687 : 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2688 Blob what = empty_blob;
2689 va_list ap;
2690 int rc;
2691 if(!once){
2692 once = 1;
2693 rc = db_multi_exec("CREATE TABLE IF NOT EXISTS aevent("
2694 "id INTEGER PRIMARY KEY, "
2695 "time FLOAT /* Julian time */, "
2696 "page TEXT /* path of page */,"
2697 "who TEXT /* user name */, "
2698 "what TEXT /* descr. of event. */ "
2699 ")");
2700 fossil_trace("created aevent. rc=%d\n", rc);
2701 }
2702 va_start(ap,zFormat);
2703 blob_vappendf( &what, zFormat, ap );
2704 va_end(ap);
2705 fossil_trace("what==%B rc=%d\n", &what, rc);
2706 db_multi_exec("INSERT INTO aevent(id,time,page,who,what) VALUES("
2707 "NULL, cast(strftime('%%J') AS FLOAT), %Q, %Q, %B"
2708 ")", g.zPath, zUserName, &what);
2709 fossil_free(zUserName);
2710 blob_reset(&what);
2711 }
2712
--- src/db.c
+++ src/db.c
@@ -2204,10 +2204,11 @@
2204 const char *def; /* Default value */
2205 };
2206 #endif /* INTERFACE */
2207 struct stControlSettings const ctrlSettings[] = {
2208 { "access-log", 0, 0, 0, 0, "off" },
2209 { "admin-log", 0, 0, 0, 0, "off" },
2210 { "allow-symlinks", 0, 0, 1, 0, "off" },
2211 { "auto-captcha", "autocaptcha", 0, 0, 0, "on" },
2212 { "auto-hyperlink", 0, 0, 0, 0, "on", },
2213 { "auto-shun", 0, 0, 0, 0, "on" },
2214 { "autosync", 0, 0, 0, 0, "on" },
@@ -2284,10 +2285,13 @@
2285 ** The "unset" command clears a property setting.
2286 **
2287 **
2288 ** access-log If enabled, record successful and failed login attempts
2289 ** in the "accesslog" table. Default: off
2290 **
2291 ** admin-log If enabled, record configuration changes in the
2292 ** "admin_log" table. Default: off
2293 **
2294 ** allow-symlinks If enabled, don't follow symlinks, and instead treat
2295 ** (versionable) them as symlinks on Unix. Has no effect on Windows
2296 ** (existing links in repository created on Unix become
2297 ** plain-text files with link destination path inside).
@@ -2660,52 +2664,59 @@
2664 "%s WITHOUT ROWID;\n"
2665 "INSERT INTO \"%w\" SELECT * FROM \"x_%w\";\n"
2666 "DROP TABLE \"x_%w\";\n",
2667 zTName, zTName, blob_sql_text(&newSql), zTName, zTName, zTName
2668 );
2669 fossil_print("Converting table %s of %s to WITHOUT ROWID.\n",
2670 zTName, g.argv[i]);
2671 blob_reset(&newSql);
2672 }
2673 blob_append_sql(&allSql, "COMMIT;\n");
2674 db_finalize(&q);
2675 if( dryRun ){
2676 fossil_print("SQL that would have been evaluated:\n");
2677 fossil_print("%.78c\n", '-');
2678 fossil_print("%s", blob_sql_text(&allSql));
2679 }else{
2680 db_multi_exec("%s", blob_sql_text(&allSql));
2681 }
2682 blob_reset(&allSql);
2683 db_close(1);
2684 }
2685 }
2686
2687 /*
2688 ** Make sure the adminlog table exists. Create it if it does not
2689 */
2690 void create_admin_log_table(void){
2691 static int once = 0;
2692 if( once ) return;
2693 once = 1;
2694 db_multi_exec(
2695 "CREATE TABLE IF NOT EXISTS \"%w\".admin_log(\n"
2696 " id INTEGER PRIMARY KEY,\n"
2697 " time FLOAT, -- Seconds since 1970\n"
2698 " page TEXT, -- path of page\n"
2699 " who TEXT, -- User who made the change\n "
2700 " what TEXT -- What changed\n"
2701 ")", db_name("repository")
2702 );
2703 }
2704
2705 /*
2706 ** Write a message into the admin_event table, if admin logging is
2707 ** enabled
2708 */
2709 void admin_log(const char *zFormat, ...){
2710 Blob what = empty_blob;
2711 va_list ap;
2712 int rc;
2713 if( !db_get_boolean("admin-log", 0) ) return;
2714 create_admin_log_table();
 
 
 
 
 
 
 
 
 
2715 va_start(ap,zFormat);
2716 blob_vappendf( &what, zFormat, ap );
2717 va_end(ap);
2718 db_multi_exec("INSERT INTO admin_log(time,page,who,what)"
2719 " VALUES(now(), %Q, %Q, %B)",
2720 g.zPath, g.zLogin, &what);
 
 
2721 blob_reset(&what);
2722 }
2723

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button