Fossil SCM
Make sure the accesslog table exists before attempting to use it. Ticket [7b55fd2958d8d]
Commit
c7de5f7b6ec924569b92d6a3d441adc099d9a86a
Parent
448dc5adf75e5ea…
2 files changed
+16
-7
+1
+16
-7
| --- src/login.c | ||
| +++ src/login.c | ||
| @@ -114,10 +114,24 @@ | ||
| 114 | 114 | if( fossil_stricmp(zPw, zPassword)!=0 ) return 0; |
| 115 | 115 | uid = db_int(0, "SELECT uid FROM user WHERE login='anonymous'" |
| 116 | 116 | " AND length(pw)>0 AND length(cap)>0"); |
| 117 | 117 | return uid; |
| 118 | 118 | } |
| 119 | + | |
| 120 | +/* | |
| 121 | +** Make sure the accesslog table exists. Create it if it does not | |
| 122 | +*/ | |
| 123 | +void create_accesslog_table(void){ | |
| 124 | + db_multi_exec( | |
| 125 | + "CREATE TABLE IF NOT EXISTS %s.accesslog(" | |
| 126 | + " uname TEXT," | |
| 127 | + " ipaddr TEXT," | |
| 128 | + " success BOOLEAN," | |
| 129 | + " mtime TIMESTAMP" | |
| 130 | + ");", db_name("repository") | |
| 131 | + ); | |
| 132 | +} | |
| 119 | 133 | |
| 120 | 134 | /* |
| 121 | 135 | ** Make a record of a login attempt, if login record keeping is enabled. |
| 122 | 136 | */ |
| 123 | 137 | static void record_login_attempt( |
| @@ -124,20 +138,15 @@ | ||
| 124 | 138 | const char *zUsername, /* Name of user logging in */ |
| 125 | 139 | const char *zIpAddr, /* IP address from which they logged in */ |
| 126 | 140 | int bSuccess /* True if the attempt was a success */ |
| 127 | 141 | ){ |
| 128 | 142 | if( !db_get_boolean("access-log", 0) ) return; |
| 143 | + create_accesslog_table(); | |
| 129 | 144 | db_multi_exec( |
| 130 | - "CREATE TABLE IF NOT EXISTS %s.accesslog(" | |
| 131 | - " uname TEXT," | |
| 132 | - " ipaddr TEXT," | |
| 133 | - " success BOOLEAN," | |
| 134 | - " mtime TIMESTAMP" | |
| 135 | - ");" | |
| 136 | 145 | "INSERT INTO accesslog(uname,ipaddr,success,mtime)" |
| 137 | 146 | "VALUES(%Q,%Q,%d,julianday('now'));", |
| 138 | - db_name("repository"), zUsername, zIpAddr, bSuccess | |
| 147 | + zUsername, zIpAddr, bSuccess | |
| 139 | 148 | ); |
| 140 | 149 | } |
| 141 | 150 | |
| 142 | 151 | /* |
| 143 | 152 | ** WEBPAGE: login |
| 144 | 153 |
| --- src/login.c | |
| +++ src/login.c | |
| @@ -114,10 +114,24 @@ | |
| 114 | if( fossil_stricmp(zPw, zPassword)!=0 ) return 0; |
| 115 | uid = db_int(0, "SELECT uid FROM user WHERE login='anonymous'" |
| 116 | " AND length(pw)>0 AND length(cap)>0"); |
| 117 | return uid; |
| 118 | } |
| 119 | |
| 120 | /* |
| 121 | ** Make a record of a login attempt, if login record keeping is enabled. |
| 122 | */ |
| 123 | static void record_login_attempt( |
| @@ -124,20 +138,15 @@ | |
| 124 | const char *zUsername, /* Name of user logging in */ |
| 125 | const char *zIpAddr, /* IP address from which they logged in */ |
| 126 | int bSuccess /* True if the attempt was a success */ |
| 127 | ){ |
| 128 | if( !db_get_boolean("access-log", 0) ) return; |
| 129 | db_multi_exec( |
| 130 | "CREATE TABLE IF NOT EXISTS %s.accesslog(" |
| 131 | " uname TEXT," |
| 132 | " ipaddr TEXT," |
| 133 | " success BOOLEAN," |
| 134 | " mtime TIMESTAMP" |
| 135 | ");" |
| 136 | "INSERT INTO accesslog(uname,ipaddr,success,mtime)" |
| 137 | "VALUES(%Q,%Q,%d,julianday('now'));", |
| 138 | db_name("repository"), zUsername, zIpAddr, bSuccess |
| 139 | ); |
| 140 | } |
| 141 | |
| 142 | /* |
| 143 | ** WEBPAGE: login |
| 144 |
| --- src/login.c | |
| +++ src/login.c | |
| @@ -114,10 +114,24 @@ | |
| 114 | if( fossil_stricmp(zPw, zPassword)!=0 ) return 0; |
| 115 | uid = db_int(0, "SELECT uid FROM user WHERE login='anonymous'" |
| 116 | " AND length(pw)>0 AND length(cap)>0"); |
| 117 | return uid; |
| 118 | } |
| 119 | |
| 120 | /* |
| 121 | ** Make sure the accesslog table exists. Create it if it does not |
| 122 | */ |
| 123 | void create_accesslog_table(void){ |
| 124 | db_multi_exec( |
| 125 | "CREATE TABLE IF NOT EXISTS %s.accesslog(" |
| 126 | " uname TEXT," |
| 127 | " ipaddr TEXT," |
| 128 | " success BOOLEAN," |
| 129 | " mtime TIMESTAMP" |
| 130 | ");", db_name("repository") |
| 131 | ); |
| 132 | } |
| 133 | |
| 134 | /* |
| 135 | ** Make a record of a login attempt, if login record keeping is enabled. |
| 136 | */ |
| 137 | static void record_login_attempt( |
| @@ -124,20 +138,15 @@ | |
| 138 | const char *zUsername, /* Name of user logging in */ |
| 139 | const char *zIpAddr, /* IP address from which they logged in */ |
| 140 | int bSuccess /* True if the attempt was a success */ |
| 141 | ){ |
| 142 | if( !db_get_boolean("access-log", 0) ) return; |
| 143 | create_accesslog_table(); |
| 144 | db_multi_exec( |
| 145 | "INSERT INTO accesslog(uname,ipaddr,success,mtime)" |
| 146 | "VALUES(%Q,%Q,%d,julianday('now'));", |
| 147 | zUsername, zIpAddr, bSuccess |
| 148 | ); |
| 149 | } |
| 150 | |
| 151 | /* |
| 152 | ** WEBPAGE: login |
| 153 |
+1
| --- src/user.c | ||
| +++ src/user.c | ||
| @@ -404,10 +404,11 @@ | ||
| 404 | 404 | int cnt = 0; |
| 405 | 405 | int rc; |
| 406 | 406 | |
| 407 | 407 | login_check_credentials(); |
| 408 | 408 | if( !g.okAdmin ){ login_needed(); return; } |
| 409 | + create_accesslog_table(); | |
| 409 | 410 | |
| 410 | 411 | if( P("delall") && P("delallbtn") ){ |
| 411 | 412 | db_multi_exec("DELETE FROM accesslog"); |
| 412 | 413 | cgi_redirectf("%s/access_log?y=%d&n=%d&o=%o", g.zTop, y, n, skip); |
| 413 | 414 | return; |
| 414 | 415 |
| --- src/user.c | |
| +++ src/user.c | |
| @@ -404,10 +404,11 @@ | |
| 404 | int cnt = 0; |
| 405 | int rc; |
| 406 | |
| 407 | login_check_credentials(); |
| 408 | if( !g.okAdmin ){ login_needed(); return; } |
| 409 | |
| 410 | if( P("delall") && P("delallbtn") ){ |
| 411 | db_multi_exec("DELETE FROM accesslog"); |
| 412 | cgi_redirectf("%s/access_log?y=%d&n=%d&o=%o", g.zTop, y, n, skip); |
| 413 | return; |
| 414 |
| --- src/user.c | |
| +++ src/user.c | |
| @@ -404,10 +404,11 @@ | |
| 404 | int cnt = 0; |
| 405 | int rc; |
| 406 | |
| 407 | login_check_credentials(); |
| 408 | if( !g.okAdmin ){ login_needed(); return; } |
| 409 | create_accesslog_table(); |
| 410 | |
| 411 | if( P("delall") && P("delallbtn") ){ |
| 412 | db_multi_exec("DELETE FROM accesslog"); |
| 413 | cgi_redirectf("%s/access_log?y=%d&n=%d&o=%o", g.zTop, y, n, skip); |
| 414 | return; |
| 415 |