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.
Commit
5e0514a607f0fc5ed57099a42832cf953be5591e
Parent
ee666c46fb7d1f3…
1 file changed
+34
-23
M
src/db.c
+34
-23
| --- src/db.c | ||
| +++ src/db.c | ||
| @@ -2204,10 +2204,11 @@ | ||
| 2204 | 2204 | const char *def; /* Default value */ |
| 2205 | 2205 | }; |
| 2206 | 2206 | #endif /* INTERFACE */ |
| 2207 | 2207 | struct stControlSettings const ctrlSettings[] = { |
| 2208 | 2208 | { "access-log", 0, 0, 0, 0, "off" }, |
| 2209 | + { "admin-log", 0, 0, 0, 0, "off" }, | |
| 2209 | 2210 | { "allow-symlinks", 0, 0, 1, 0, "off" }, |
| 2210 | 2211 | { "auto-captcha", "autocaptcha", 0, 0, 0, "on" }, |
| 2211 | 2212 | { "auto-hyperlink", 0, 0, 0, 0, "on", }, |
| 2212 | 2213 | { "auto-shun", 0, 0, 0, 0, "on" }, |
| 2213 | 2214 | { "autosync", 0, 0, 0, 0, "on" }, |
| @@ -2284,10 +2285,13 @@ | ||
| 2284 | 2285 | ** The "unset" command clears a property setting. |
| 2285 | 2286 | ** |
| 2286 | 2287 | ** |
| 2287 | 2288 | ** access-log If enabled, record successful and failed login attempts |
| 2288 | 2289 | ** in the "accesslog" table. Default: off |
| 2290 | +** | |
| 2291 | +** admin-log If enabled, record configuration changes in the | |
| 2292 | +** "admin_log" table. Default: off | |
| 2289 | 2293 | ** |
| 2290 | 2294 | ** allow-symlinks If enabled, don't follow symlinks, and instead treat |
| 2291 | 2295 | ** (versionable) them as symlinks on Unix. Has no effect on Windows |
| 2292 | 2296 | ** (existing links in repository created on Unix become |
| 2293 | 2297 | ** plain-text files with link destination path inside). |
| @@ -2660,52 +2664,59 @@ | ||
| 2660 | 2664 | "%s WITHOUT ROWID;\n" |
| 2661 | 2665 | "INSERT INTO \"%w\" SELECT * FROM \"x_%w\";\n" |
| 2662 | 2666 | "DROP TABLE \"x_%w\";\n", |
| 2663 | 2667 | zTName, zTName, blob_sql_text(&newSql), zTName, zTName, zTName |
| 2664 | 2668 | ); |
| 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]); | |
| 2666 | 2671 | blob_reset(&newSql); |
| 2667 | 2672 | } |
| 2668 | 2673 | blob_append_sql(&allSql, "COMMIT;\n"); |
| 2669 | 2674 | db_finalize(&q); |
| 2670 | 2675 | if( dryRun ){ |
| 2671 | 2676 | fossil_print("SQL that would have been evaluated:\n"); |
| 2672 | - fossil_print("-------------------------------------------------------------\n"); | |
| 2677 | + fossil_print("%.78c\n", '-'); | |
| 2673 | 2678 | fossil_print("%s", blob_sql_text(&allSql)); |
| 2674 | 2679 | }else{ |
| 2675 | 2680 | db_multi_exec("%s", blob_sql_text(&allSql)); |
| 2676 | 2681 | } |
| 2677 | 2682 | blob_reset(&allSql); |
| 2678 | 2683 | db_close(1); |
| 2679 | 2684 | } |
| 2680 | 2685 | } |
| 2681 | 2686 | |
| 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){ | |
| 2684 | 2691 | 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, ...){ | |
| 2688 | 2710 | Blob what = empty_blob; |
| 2689 | 2711 | va_list ap; |
| 2690 | 2712 | 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(); | |
| 2702 | 2715 | va_start(ap,zFormat); |
| 2703 | 2716 | blob_vappendf( &what, zFormat, ap ); |
| 2704 | 2717 | 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); | |
| 2710 | 2721 | blob_reset(&what); |
| 2711 | 2722 | } |
| 2712 | 2723 |
| --- 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 |