Fossil SCM

Automatically enable hyperlinks for user agents that appear to be human.

drh 2011-10-26 14:00 trunk
Commit e059e5a24de1a0070f8ea746a25bf306e0e3c80f
1 file changed +22
+22
--- src/login.c
+++ src/login.c
@@ -197,10 +197,29 @@
197197
"INSERT INTO accesslog(uname,ipaddr,success,mtime)"
198198
"VALUES(%Q,%Q,%d,julianday('now'));",
199199
zUsername, zIpAddr, bSuccess
200200
);
201201
}
202
+
203
+/*
204
+** Look at the HTTP_USER_AGENT parameter and try to determine if the user agent
205
+** is a manually operated browser or a bot. When in doubt, assume a bot. Return
206
+** true if we believe the agent is a real person.
207
+*/
208
+static int isHuman(void){
209
+ const char *zAgent = P("HTTP_USER_AGENT");
210
+ int i;
211
+ if( zAgent==0 ) return 0;
212
+ for(i=0; zAgent[i]; i++){
213
+ if( zAgent[i]=='b' && memcmp(&zAgent[i],"bot",3)==0 ) return 0;
214
+ if( zAgent[i]=='s' && memcmp(&zAgent[i],"spider",6)==0 ) return 0;
215
+ }
216
+ if( memcmp(zAgent, "Mozilla/", 8)==0 ) return 1;
217
+ if( memcmp(zAgent, "Opera/", 6)==0 ) return 1;
218
+ if( memcmp(zAgent, "Safari/", 7)==0 ) return 1;
219
+ return 0;
220
+}
202221
203222
/*
204223
** SQL function for constant time comparison of two values.
205224
** Sets result to 0 if two values are equal.
206225
*/
@@ -727,10 +746,13 @@
727746
}
728747
729748
/* Set the capabilities */
730749
login_set_capabilities(zCap, 0);
731750
login_set_anon_nobody_capabilities();
751
+ if( zCap[0] && !g.perm.History && isHuman() ){
752
+ g.perm.History = 1;
753
+ }
732754
}
733755
734756
/*
735757
** Memory of settings
736758
*/
737759
--- src/login.c
+++ src/login.c
@@ -197,10 +197,29 @@
197 "INSERT INTO accesslog(uname,ipaddr,success,mtime)"
198 "VALUES(%Q,%Q,%d,julianday('now'));",
199 zUsername, zIpAddr, bSuccess
200 );
201 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202
203 /*
204 ** SQL function for constant time comparison of two values.
205 ** Sets result to 0 if two values are equal.
206 */
@@ -727,10 +746,13 @@
727 }
728
729 /* Set the capabilities */
730 login_set_capabilities(zCap, 0);
731 login_set_anon_nobody_capabilities();
 
 
 
732 }
733
734 /*
735 ** Memory of settings
736 */
737
--- src/login.c
+++ src/login.c
@@ -197,10 +197,29 @@
197 "INSERT INTO accesslog(uname,ipaddr,success,mtime)"
198 "VALUES(%Q,%Q,%d,julianday('now'));",
199 zUsername, zIpAddr, bSuccess
200 );
201 }
202
203 /*
204 ** Look at the HTTP_USER_AGENT parameter and try to determine if the user agent
205 ** is a manually operated browser or a bot. When in doubt, assume a bot. Return
206 ** true if we believe the agent is a real person.
207 */
208 static int isHuman(void){
209 const char *zAgent = P("HTTP_USER_AGENT");
210 int i;
211 if( zAgent==0 ) return 0;
212 for(i=0; zAgent[i]; i++){
213 if( zAgent[i]=='b' && memcmp(&zAgent[i],"bot",3)==0 ) return 0;
214 if( zAgent[i]=='s' && memcmp(&zAgent[i],"spider",6)==0 ) return 0;
215 }
216 if( memcmp(zAgent, "Mozilla/", 8)==0 ) return 1;
217 if( memcmp(zAgent, "Opera/", 6)==0 ) return 1;
218 if( memcmp(zAgent, "Safari/", 7)==0 ) return 1;
219 return 0;
220 }
221
222 /*
223 ** SQL function for constant time comparison of two values.
224 ** Sets result to 0 if two values are equal.
225 */
@@ -727,10 +746,13 @@
746 }
747
748 /* Set the capabilities */
749 login_set_capabilities(zCap, 0);
750 login_set_anon_nobody_capabilities();
751 if( zCap[0] && !g.perm.History && isHuman() ){
752 g.perm.History = 1;
753 }
754 }
755
756 /*
757 ** Memory of settings
758 */
759

Keyboard Shortcuts

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