Fossil SCM
Automatically enable hyperlinks for user agents that appear to be human.
Commit
e059e5a24de1a0070f8ea746a25bf306e0e3c80f
Parent
313ba5c64f2102f…
1 file changed
+22
+22
| --- src/login.c | ||
| +++ src/login.c | ||
| @@ -197,10 +197,29 @@ | ||
| 197 | 197 | "INSERT INTO accesslog(uname,ipaddr,success,mtime)" |
| 198 | 198 | "VALUES(%Q,%Q,%d,julianday('now'));", |
| 199 | 199 | zUsername, zIpAddr, bSuccess |
| 200 | 200 | ); |
| 201 | 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 | +} | |
| 202 | 221 | |
| 203 | 222 | /* |
| 204 | 223 | ** SQL function for constant time comparison of two values. |
| 205 | 224 | ** Sets result to 0 if two values are equal. |
| 206 | 225 | */ |
| @@ -727,10 +746,13 @@ | ||
| 727 | 746 | } |
| 728 | 747 | |
| 729 | 748 | /* Set the capabilities */ |
| 730 | 749 | login_set_capabilities(zCap, 0); |
| 731 | 750 | login_set_anon_nobody_capabilities(); |
| 751 | + if( zCap[0] && !g.perm.History && isHuman() ){ | |
| 752 | + g.perm.History = 1; | |
| 753 | + } | |
| 732 | 754 | } |
| 733 | 755 | |
| 734 | 756 | /* |
| 735 | 757 | ** Memory of settings |
| 736 | 758 | */ |
| 737 | 759 |
| --- 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 |