Fossil SCM

Make sure the accesslog table exists before attempting to use it. Ticket [7b55fd2958d8d]

drh 2011-03-16 02:38 trunk
Commit c7de5f7b6ec924569b92d6a3d441adc099d9a86a
2 files changed +16 -7 +1
+16 -7
--- src/login.c
+++ src/login.c
@@ -114,10 +114,24 @@
114114
if( fossil_stricmp(zPw, zPassword)!=0 ) return 0;
115115
uid = db_int(0, "SELECT uid FROM user WHERE login='anonymous'"
116116
" AND length(pw)>0 AND length(cap)>0");
117117
return uid;
118118
}
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
+}
119133
120134
/*
121135
** Make a record of a login attempt, if login record keeping is enabled.
122136
*/
123137
static void record_login_attempt(
@@ -124,20 +138,15 @@
124138
const char *zUsername, /* Name of user logging in */
125139
const char *zIpAddr, /* IP address from which they logged in */
126140
int bSuccess /* True if the attempt was a success */
127141
){
128142
if( !db_get_boolean("access-log", 0) ) return;
143
+ create_accesslog_table();
129144
db_multi_exec(
130
- "CREATE TABLE IF NOT EXISTS %s.accesslog("
131
- " uname TEXT,"
132
- " ipaddr TEXT,"
133
- " success BOOLEAN,"
134
- " mtime TIMESTAMP"
135
- ");"
136145
"INSERT INTO accesslog(uname,ipaddr,success,mtime)"
137146
"VALUES(%Q,%Q,%d,julianday('now'));",
138
- db_name("repository"), zUsername, zIpAddr, bSuccess
147
+ zUsername, zIpAddr, bSuccess
139148
);
140149
}
141150
142151
/*
143152
** WEBPAGE: login
144153
--- 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 @@
404404
int cnt = 0;
405405
int rc;
406406
407407
login_check_credentials();
408408
if( !g.okAdmin ){ login_needed(); return; }
409
+ create_accesslog_table();
409410
410411
if( P("delall") && P("delallbtn") ){
411412
db_multi_exec("DELETE FROM accesslog");
412413
cgi_redirectf("%s/access_log?y=%d&n=%d&o=%o", g.zTop, y, n, skip);
413414
return;
414415
--- 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

Keyboard Shortcuts

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