| | @@ -391,24 +391,24 @@ |
| 391 | 391 | for(i=0; zAgent[i]; i++){ |
| 392 | 392 | if( prefix_match("bot", zAgent+i) ) return 0; |
| 393 | 393 | if( prefix_match("spider", zAgent+i) ) return 0; |
| 394 | 394 | if( prefix_match("crawl", zAgent+i) ) return 0; |
| 395 | 395 | /* If a URI appears in the User-Agent, it is probably a bot */ |
| 396 | | - if( memcmp("http", zAgent+i,4)==0 ) return 0; |
| 396 | + if( strncmp("http", zAgent+i,4)==0 ) return 0; |
| 397 | 397 | } |
| 398 | | - if( memcmp(zAgent, "Mozilla/", 8)==0 ){ |
| 398 | + if( strncmp(zAgent, "Mozilla/", 8)==0 ){ |
| 399 | 399 | if( atoi(&zAgent[8])<4 ) return 0; /* Many bots advertise as Mozilla/3 */ |
| 400 | 400 | if( strglob("*Firefox/[1-9]*", zAgent) ) return 1; |
| 401 | 401 | if( strglob("*Chrome/[1-9]*", zAgent) ) return 1; |
| 402 | 402 | if( strglob("*(compatible;?MSIE?[1789]*", zAgent) ) return 1; |
| 403 | 403 | if( strglob("*AppleWebKit/[1-9]*(KHTML*", zAgent) ) return 1; |
| 404 | 404 | return 0; |
| 405 | 405 | } |
| 406 | | - if( memcmp(zAgent, "Opera/", 6)==0 ) return 1; |
| 407 | | - if( memcmp(zAgent, "Safari/", 7)==0 ) return 1; |
| 408 | | - if( memcmp(zAgent, "Lynx/", 5)==0 ) return 1; |
| 409 | | - if( memcmp(zAgent, "NetSurf/", 8)==0 ) return 1; |
| 406 | + if( strncmp(zAgent, "Opera/", 6)==0 ) return 1; |
| 407 | + if( strncmp(zAgent, "Safari/", 7)==0 ) return 1; |
| 408 | + if( strncmp(zAgent, "Lynx/", 5)==0 ) return 1; |
| 409 | + if( strncmp(zAgent, "NetSurf/", 8)==0 ) return 1; |
| 410 | 410 | return 0; |
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | /* |
| 414 | 414 | ** COMMAND: test-ishuman |
| | @@ -598,11 +598,11 @@ |
| 598 | 598 | @ </table> |
| 599 | 599 | @ <script type="text/JavaScript"> |
| 600 | 600 | @ gebi('u').focus() |
| 601 | 601 | @ function chngAction(form){ |
| 602 | 602 | if( g.sslNotAvailable==0 |
| 603 | | - && memcmp(g.zBaseURL,"https:",6)!=0 |
| 603 | + && strncmp(g.zBaseURL,"https:",6)!=0 |
| 604 | 604 | && db_get_boolean("https-login",0) |
| 605 | 605 | ){ |
| 606 | 606 | char *zSSL = mprintf("https:%s", &g.zBaseURL[5]); |
| 607 | 607 | @ if( form.u.value!="anonymous" ){ |
| 608 | 608 | @ form.action = "%h(zSSL)/login"; |
| | @@ -763,14 +763,17 @@ |
| 763 | 763 | } |
| 764 | 764 | |
| 765 | 765 | /* |
| 766 | 766 | ** This routine examines the login cookie to see if it exists and |
| 767 | 767 | ** is valid. If the login cookie checks out, it then sets global |
| 768 | | -** variables appropriately. Global variables set include g.userUid |
| 769 | | -** and g.zLogin and the g.perm family of permission booleans. |
| 768 | +** variables appropriately. |
| 770 | 769 | ** |
| 771 | | -** If the |
| 770 | +** g.userUid Database USER.UID value. Might be -1 for "nobody" |
| 771 | +** g.zLogin Database USER.LOGIN value. NULL for user "nobody" |
| 772 | +** g.perm Permissions granted to this user |
| 773 | +** g.isHuman True if the user is human, not a spider or robot |
| 774 | +** |
| 772 | 775 | */ |
| 773 | 776 | void login_check_credentials(void){ |
| 774 | 777 | int uid = 0; /* User id */ |
| 775 | 778 | const char *zCookie; /* Text of the login cookie */ |
| 776 | 779 | const char *zIpAddr; /* Raw IP address of the requestor */ |
| | @@ -799,10 +802,11 @@ |
| 799 | 802 | ){ |
| 800 | 803 | uid = db_int(0, "SELECT uid FROM user WHERE cap LIKE '%%s%%'"); |
| 801 | 804 | g.zLogin = db_text("?", "SELECT login FROM user WHERE uid=%d", uid); |
| 802 | 805 | zCap = "sx"; |
| 803 | 806 | g.noPswd = 1; |
| 807 | + g.isHuman = 1; |
| 804 | 808 | sqlite3_snprintf(sizeof(g.zCsrfToken), g.zCsrfToken, "localhost"); |
| 805 | 809 | } |
| 806 | 810 | |
| 807 | 811 | /* Check the login cookie to see if it matches a known valid user. |
| 808 | 812 | */ |
| | @@ -907,10 +911,11 @@ |
| 907 | 911 | */ |
| 908 | 912 | g.userUid = uid; |
| 909 | 913 | if( fossil_strcmp(g.zLogin,"nobody")==0 ){ |
| 910 | 914 | g.zLogin = 0; |
| 911 | 915 | } |
| 916 | + g.isHuman = g.zLogin==0 ? isHuman(P("HTTP_USER_AGENT")) : 1; |
| 912 | 917 | |
| 913 | 918 | /* Set the capabilities */ |
| 914 | 919 | login_replace_capabilities(zCap, 0); |
| 915 | 920 | login_set_anon_nobody_capabilities(); |
| 916 | 921 | |
| | @@ -918,13 +923,14 @@ |
| 918 | 923 | ** who do not have the "h" permission as long as their UserAgent string |
| 919 | 924 | ** makes it appear that they are human. Check to see if auto-hyperlink is |
| 920 | 925 | ** enabled for this repository and make appropriate adjustments to the |
| 921 | 926 | ** permission flags if it is. |
| 922 | 927 | */ |
| 923 | | - if( zCap[0] && !g.perm.Hyperlink |
| 928 | + if( zCap[0] |
| 929 | + && !g.perm.Hyperlink |
| 930 | + && g.isHuman |
| 924 | 931 | && db_get_boolean("auto-hyperlink",1) |
| 925 | | - && isHuman(P("HTTP_USER_AGENT")) |
| 926 | 932 | ){ |
| 927 | 933 | g.perm.Hyperlink = 1; |
| 928 | 934 | g.javascriptHyperlink = 1; |
| 929 | 935 | } |
| 930 | 936 | |
| 931 | 937 | |