Fossil SCM

Convert the g.isHuman variable into g.isRobot.

drh 2025-08-15 23:46 robot-restrict-simplified
Commit 6422bca15da624f38fe20cdf1b4f09bab958bb316f58deacfeefa7d72743c50d
--- src/browse.c
+++ src/browse.c
@@ -1162,11 +1162,10 @@
11621162
int showId = PB("showid");
11631163
Stmt q1, q2;
11641164
double baseTime;
11651165
login_check_credentials();
11661166
if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
1167
- if( exclude_spiders(0) ) return;
11681167
zName = P("name");
11691168
if( zName==0 ) zName = "tip";
11701169
rid = symbolic_name_to_rid(zName, "ci");
11711170
if( rid==0 ){
11721171
fossil_fatal("not a valid check-in: %s", zName);
11731172
--- src/browse.c
+++ src/browse.c
@@ -1162,11 +1162,10 @@
1162 int showId = PB("showid");
1163 Stmt q1, q2;
1164 double baseTime;
1165 login_check_credentials();
1166 if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
1167 if( exclude_spiders(0) ) return;
1168 zName = P("name");
1169 if( zName==0 ) zName = "tip";
1170 rid = symbolic_name_to_rid(zName, "ci");
1171 if( rid==0 ){
1172 fossil_fatal("not a valid check-in: %s", zName);
1173
--- src/browse.c
+++ src/browse.c
@@ -1162,11 +1162,10 @@
1162 int showId = PB("showid");
1163 Stmt q1, q2;
1164 double baseTime;
1165 login_check_credentials();
1166 if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
 
1167 zName = P("name");
1168 if( zName==0 ) zName = "tip";
1169 rid = symbolic_name_to_rid(zName, "ci");
1170 if( rid==0 ){
1171 fossil_fatal("not a valid check-in: %s", zName);
1172
+4 -8
--- src/captcha.c
+++ src/captcha.c
@@ -744,11 +744,11 @@
744744
(void)exclude_spiders(1);
745745
@ <hr><p>The captcha is shown above. Add a name=HEX query parameter
746746
@ to see how HEX would be rendered in the current captcha font.
747747
@ <h2>Debug/Testing Values:</h2>
748748
@ <ul>
749
- @ <li> g.isHuman = %d(g.isHuman)
749
+ @ <li> g.isRobot = %d(g.isRobot)
750750
@ <li> g.zLogin = %h(g.zLogin)
751751
@ <li> login_cookie_welformed() = %d(login_cookie_wellformed())
752752
@ <li> captcha_is_correct(1) = %d(captcha_is_correct(1)).
753753
@ </ul>
754754
style_finish_page();
@@ -776,27 +776,23 @@
776776
** If the bTest argument is non-zero, then show the captcha regardless of
777777
** how the agent identifies. This is used for testing only.
778778
*/
779779
int exclude_spiders(int bTest){
780780
if( !bTest ){
781
- if( g.isHuman ) return 0; /* This user has already proven human */
782781
if( g.zLogin!=0 ) return 0; /* Logged in. Consider them human */
783782
if( login_cookie_wellformed() ){
784783
/* Logged into another member of the login group */
785784
return 0;
786785
}
787786
}
788787
789788
/* This appears to be a spider. Offer the captcha */
790789
style_set_current_feature("captcha");
791
- style_header("I think you are a robot");
790
+ style_header("Captcha");
792791
style_submenu_enable(0);
793792
@ <form method='POST' action='%R/ityaar'>
794
- @ <p>You seem like a robot.
795
- @
796
- @ <p>If you are human, you can prove that by solving the captcha below,
797
- @ after which you will be allowed to proceed.
793
+ @ <h2>Prove that you are human:
798794
if( bTest ){
799795
@ <input type="hidden" name="istest" value="1">
800796
}
801797
captcha_generate(3);
802798
@ </form>
@@ -830,11 +826,11 @@
830826
}
831827
cgi_append_header("X-Robot: 0\r\n");
832828
}
833829
login_redirect_to_g();
834830
}else{
835
- g.isHuman = 0;
831
+ g.isRobot = 1;
836832
(void)exclude_spiders(bTest);
837833
if( bTest ){
838834
@ <hr><p>Wrong code. Try again
839835
style_finish_page();
840836
}
841837
--- src/captcha.c
+++ src/captcha.c
@@ -744,11 +744,11 @@
744 (void)exclude_spiders(1);
745 @ <hr><p>The captcha is shown above. Add a name=HEX query parameter
746 @ to see how HEX would be rendered in the current captcha font.
747 @ <h2>Debug/Testing Values:</h2>
748 @ <ul>
749 @ <li> g.isHuman = %d(g.isHuman)
750 @ <li> g.zLogin = %h(g.zLogin)
751 @ <li> login_cookie_welformed() = %d(login_cookie_wellformed())
752 @ <li> captcha_is_correct(1) = %d(captcha_is_correct(1)).
753 @ </ul>
754 style_finish_page();
@@ -776,27 +776,23 @@
776 ** If the bTest argument is non-zero, then show the captcha regardless of
777 ** how the agent identifies. This is used for testing only.
778 */
779 int exclude_spiders(int bTest){
780 if( !bTest ){
781 if( g.isHuman ) return 0; /* This user has already proven human */
782 if( g.zLogin!=0 ) return 0; /* Logged in. Consider them human */
783 if( login_cookie_wellformed() ){
784 /* Logged into another member of the login group */
785 return 0;
786 }
787 }
788
789 /* This appears to be a spider. Offer the captcha */
790 style_set_current_feature("captcha");
791 style_header("I think you are a robot");
792 style_submenu_enable(0);
793 @ <form method='POST' action='%R/ityaar'>
794 @ <p>You seem like a robot.
795 @
796 @ <p>If you are human, you can prove that by solving the captcha below,
797 @ after which you will be allowed to proceed.
798 if( bTest ){
799 @ <input type="hidden" name="istest" value="1">
800 }
801 captcha_generate(3);
802 @ </form>
@@ -830,11 +826,11 @@
830 }
831 cgi_append_header("X-Robot: 0\r\n");
832 }
833 login_redirect_to_g();
834 }else{
835 g.isHuman = 0;
836 (void)exclude_spiders(bTest);
837 if( bTest ){
838 @ <hr><p>Wrong code. Try again
839 style_finish_page();
840 }
841
--- src/captcha.c
+++ src/captcha.c
@@ -744,11 +744,11 @@
744 (void)exclude_spiders(1);
745 @ <hr><p>The captcha is shown above. Add a name=HEX query parameter
746 @ to see how HEX would be rendered in the current captcha font.
747 @ <h2>Debug/Testing Values:</h2>
748 @ <ul>
749 @ <li> g.isRobot = %d(g.isRobot)
750 @ <li> g.zLogin = %h(g.zLogin)
751 @ <li> login_cookie_welformed() = %d(login_cookie_wellformed())
752 @ <li> captcha_is_correct(1) = %d(captcha_is_correct(1)).
753 @ </ul>
754 style_finish_page();
@@ -776,27 +776,23 @@
776 ** If the bTest argument is non-zero, then show the captcha regardless of
777 ** how the agent identifies. This is used for testing only.
778 */
779 int exclude_spiders(int bTest){
780 if( !bTest ){
 
781 if( g.zLogin!=0 ) return 0; /* Logged in. Consider them human */
782 if( login_cookie_wellformed() ){
783 /* Logged into another member of the login group */
784 return 0;
785 }
786 }
787
788 /* This appears to be a spider. Offer the captcha */
789 style_set_current_feature("captcha");
790 style_header("Captcha");
791 style_submenu_enable(0);
792 @ <form method='POST' action='%R/ityaar'>
793 @ <h2>Prove that you are human:
 
 
 
794 if( bTest ){
795 @ <input type="hidden" name="istest" value="1">
796 }
797 captcha_generate(3);
798 @ </form>
@@ -830,11 +826,11 @@
826 }
827 cgi_append_header("X-Robot: 0\r\n");
828 }
829 login_redirect_to_g();
830 }else{
831 g.isRobot = 1;
832 (void)exclude_spiders(bTest);
833 if( bTest ){
834 @ <hr><p>Wrong code. Try again
835 style_finish_page();
836 }
837
+2 -3
--- src/info.c
+++ src/info.c
@@ -2416,15 +2416,15 @@
24162416
object_description(rid, objdescFlags, 0, &downloadName);
24172417
style_submenu_element("Download", "%R/raw/%s?at=%T",
24182418
zUuid, file_tail(blob_str(&downloadName)));
24192419
@ <hr>
24202420
content_get(rid, &content);
2421
- if( !g.isHuman ){
2421
+ if( blob_size(&content)>100000 ){
24222422
/* Prevent robots from running hexdump on megabyte-sized source files
24232423
** and there by eating up lots of CPU time and bandwidth. There is
24242424
** no good reason for a robot to need a hexdump. */
2425
- @ <p>A hex dump of this file is not available.
2425
+ @ <p>A hex dump of this file is not available because it is too large.
24262426
@ Please download the raw binary file and generate a hex dump yourself.</p>
24272427
}else{
24282428
@ <blockquote><pre>
24292429
hexdump(&content);
24302430
@ </pre></blockquote>
@@ -2702,11 +2702,10 @@
27022702
HQuery url;
27032703
char *zCIUuid = 0;
27042704
int isSymbolicCI = 0; /* ci= exists and is a symbolic name, not a hash */
27052705
int isBranchCI = 0; /* ci= refers to a branch name */
27062706
char *zHeader = 0;
2707
- int iCost;
27082707
27092708
login_check_credentials();
27102709
if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
27112710
cgi_check_for_malice();
27122711
style_set_current_feature("artifact");
27132712
--- src/info.c
+++ src/info.c
@@ -2416,15 +2416,15 @@
2416 object_description(rid, objdescFlags, 0, &downloadName);
2417 style_submenu_element("Download", "%R/raw/%s?at=%T",
2418 zUuid, file_tail(blob_str(&downloadName)));
2419 @ <hr>
2420 content_get(rid, &content);
2421 if( !g.isHuman ){
2422 /* Prevent robots from running hexdump on megabyte-sized source files
2423 ** and there by eating up lots of CPU time and bandwidth. There is
2424 ** no good reason for a robot to need a hexdump. */
2425 @ <p>A hex dump of this file is not available.
2426 @ Please download the raw binary file and generate a hex dump yourself.</p>
2427 }else{
2428 @ <blockquote><pre>
2429 hexdump(&content);
2430 @ </pre></blockquote>
@@ -2702,11 +2702,10 @@
2702 HQuery url;
2703 char *zCIUuid = 0;
2704 int isSymbolicCI = 0; /* ci= exists and is a symbolic name, not a hash */
2705 int isBranchCI = 0; /* ci= refers to a branch name */
2706 char *zHeader = 0;
2707 int iCost;
2708
2709 login_check_credentials();
2710 if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
2711 cgi_check_for_malice();
2712 style_set_current_feature("artifact");
2713
--- src/info.c
+++ src/info.c
@@ -2416,15 +2416,15 @@
2416 object_description(rid, objdescFlags, 0, &downloadName);
2417 style_submenu_element("Download", "%R/raw/%s?at=%T",
2418 zUuid, file_tail(blob_str(&downloadName)));
2419 @ <hr>
2420 content_get(rid, &content);
2421 if( blob_size(&content)>100000 ){
2422 /* Prevent robots from running hexdump on megabyte-sized source files
2423 ** and there by eating up lots of CPU time and bandwidth. There is
2424 ** no good reason for a robot to need a hexdump. */
2425 @ <p>A hex dump of this file is not available because it is too large.
2426 @ Please download the raw binary file and generate a hex dump yourself.</p>
2427 }else{
2428 @ <blockquote><pre>
2429 hexdump(&content);
2430 @ </pre></blockquote>
@@ -2702,11 +2702,10 @@
2702 HQuery url;
2703 char *zCIUuid = 0;
2704 int isSymbolicCI = 0; /* ci= exists and is a symbolic name, not a hash */
2705 int isBranchCI = 0; /* ci= refers to a branch name */
2706 char *zHeader = 0;
 
2707
2708 login_check_credentials();
2709 if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
2710 cgi_check_for_malice();
2711 style_set_current_feature("artifact");
2712
+6 -6
--- src/login.c
+++ src/login.c
@@ -1341,11 +1341,11 @@
13411341
**
13421342
** g.userUid Database USER.UID value. Might be -1 for "nobody"
13431343
** g.zLogin Database USER.LOGIN value. NULL for user "nobody"
13441344
** g.perm Permissions granted to this user
13451345
** g.anon Permissions that would be available to anonymous
1346
-** g.isHuman True if the user is human, not a spider or robot
1346
+** g.isRobot True if the client is known to be a spider or robot
13471347
** g.perm Populated based on user account's capabilities
13481348
**
13491349
*/
13501350
void login_check_credentials(void){
13511351
int uid = 0; /* User id */
@@ -1382,11 +1382,11 @@
13821382
uid = db_int(0, "SELECT uid FROM user WHERE cap LIKE '%%s%%'");
13831383
}
13841384
g.zLogin = db_text("?", "SELECT login FROM user WHERE uid=%d", uid);
13851385
zCap = "sxy";
13861386
g.noPswd = 1;
1387
- g.isHuman = 1;
1387
+ g.isRobot = 0;
13881388
zSeed = db_text("??", "SELECT uid||quote(login)||quote(pw)||quote(cookie)"
13891389
" FROM user WHERE uid=%d", uid);
13901390
login_create_csrf_secret(zSeed);
13911391
fossil_free(zSeed);
13921392
}
@@ -1559,15 +1559,15 @@
15591559
g.userUid = uid;
15601560
if( fossil_strcmp(g.zLogin,"nobody")==0 ){
15611561
g.zLogin = 0;
15621562
}
15631563
if( PB("isrobot") ){
1564
- g.isHuman = 0;
1564
+ g.isRobot = 1;
15651565
}else if( g.zLogin==0 ){
1566
- g.isHuman = isHuman(P("HTTP_USER_AGENT"));
1566
+ g.isRobot = !isHuman(P("HTTP_USER_AGENT"));
15671567
}else{
1568
- g.isHuman = 1;
1568
+ g.isRobot = 0;
15691569
}
15701570
15711571
/* Set the capabilities */
15721572
login_replace_capabilities(zCap, 0);
15731573
@@ -1577,11 +1577,11 @@
15771577
** enabled for this repository and make appropriate adjustments to the
15781578
** permission flags if it is. This should be done before the permissions
15791579
** are (potentially) copied to the anonymous permission set; otherwise,
15801580
** those will be out-of-sync.
15811581
*/
1582
- if( zCap[0] && !g.perm.Hyperlink && g.isHuman ){
1582
+ if( zCap[0] && !g.perm.Hyperlink && !g.isRobot ){
15831583
int autoLink = db_get_int("auto-hyperlink",1);
15841584
if( autoLink==1 ){
15851585
g.jsHref = 1;
15861586
g.perm.Hyperlink = 1;
15871587
}else if( autoLink==2 ){
15881588
--- src/login.c
+++ src/login.c
@@ -1341,11 +1341,11 @@
1341 **
1342 ** g.userUid Database USER.UID value. Might be -1 for "nobody"
1343 ** g.zLogin Database USER.LOGIN value. NULL for user "nobody"
1344 ** g.perm Permissions granted to this user
1345 ** g.anon Permissions that would be available to anonymous
1346 ** g.isHuman True if the user is human, not a spider or robot
1347 ** g.perm Populated based on user account's capabilities
1348 **
1349 */
1350 void login_check_credentials(void){
1351 int uid = 0; /* User id */
@@ -1382,11 +1382,11 @@
1382 uid = db_int(0, "SELECT uid FROM user WHERE cap LIKE '%%s%%'");
1383 }
1384 g.zLogin = db_text("?", "SELECT login FROM user WHERE uid=%d", uid);
1385 zCap = "sxy";
1386 g.noPswd = 1;
1387 g.isHuman = 1;
1388 zSeed = db_text("??", "SELECT uid||quote(login)||quote(pw)||quote(cookie)"
1389 " FROM user WHERE uid=%d", uid);
1390 login_create_csrf_secret(zSeed);
1391 fossil_free(zSeed);
1392 }
@@ -1559,15 +1559,15 @@
1559 g.userUid = uid;
1560 if( fossil_strcmp(g.zLogin,"nobody")==0 ){
1561 g.zLogin = 0;
1562 }
1563 if( PB("isrobot") ){
1564 g.isHuman = 0;
1565 }else if( g.zLogin==0 ){
1566 g.isHuman = isHuman(P("HTTP_USER_AGENT"));
1567 }else{
1568 g.isHuman = 1;
1569 }
1570
1571 /* Set the capabilities */
1572 login_replace_capabilities(zCap, 0);
1573
@@ -1577,11 +1577,11 @@
1577 ** enabled for this repository and make appropriate adjustments to the
1578 ** permission flags if it is. This should be done before the permissions
1579 ** are (potentially) copied to the anonymous permission set; otherwise,
1580 ** those will be out-of-sync.
1581 */
1582 if( zCap[0] && !g.perm.Hyperlink && g.isHuman ){
1583 int autoLink = db_get_int("auto-hyperlink",1);
1584 if( autoLink==1 ){
1585 g.jsHref = 1;
1586 g.perm.Hyperlink = 1;
1587 }else if( autoLink==2 ){
1588
--- src/login.c
+++ src/login.c
@@ -1341,11 +1341,11 @@
1341 **
1342 ** g.userUid Database USER.UID value. Might be -1 for "nobody"
1343 ** g.zLogin Database USER.LOGIN value. NULL for user "nobody"
1344 ** g.perm Permissions granted to this user
1345 ** g.anon Permissions that would be available to anonymous
1346 ** g.isRobot True if the client is known to be a spider or robot
1347 ** g.perm Populated based on user account's capabilities
1348 **
1349 */
1350 void login_check_credentials(void){
1351 int uid = 0; /* User id */
@@ -1382,11 +1382,11 @@
1382 uid = db_int(0, "SELECT uid FROM user WHERE cap LIKE '%%s%%'");
1383 }
1384 g.zLogin = db_text("?", "SELECT login FROM user WHERE uid=%d", uid);
1385 zCap = "sxy";
1386 g.noPswd = 1;
1387 g.isRobot = 0;
1388 zSeed = db_text("??", "SELECT uid||quote(login)||quote(pw)||quote(cookie)"
1389 " FROM user WHERE uid=%d", uid);
1390 login_create_csrf_secret(zSeed);
1391 fossil_free(zSeed);
1392 }
@@ -1559,15 +1559,15 @@
1559 g.userUid = uid;
1560 if( fossil_strcmp(g.zLogin,"nobody")==0 ){
1561 g.zLogin = 0;
1562 }
1563 if( PB("isrobot") ){
1564 g.isRobot = 1;
1565 }else if( g.zLogin==0 ){
1566 g.isRobot = !isHuman(P("HTTP_USER_AGENT"));
1567 }else{
1568 g.isRobot = 0;
1569 }
1570
1571 /* Set the capabilities */
1572 login_replace_capabilities(zCap, 0);
1573
@@ -1577,11 +1577,11 @@
1577 ** enabled for this repository and make appropriate adjustments to the
1578 ** permission flags if it is. This should be done before the permissions
1579 ** are (potentially) copied to the anonymous permission set; otherwise,
1580 ** those will be out-of-sync.
1581 */
1582 if( zCap[0] && !g.perm.Hyperlink && !g.isRobot ){
1583 int autoLink = db_get_int("auto-hyperlink",1);
1584 if( autoLink==1 ){
1585 g.jsHref = 1;
1586 g.perm.Hyperlink = 1;
1587 }else if( autoLink==2 ){
1588
+2 -1
--- src/main.c
+++ src/main.c
@@ -233,11 +233,12 @@
233233
* applicable when using SEE on Windows or Linux. */
234234
#endif
235235
int useLocalauth; /* No login required if from 127.0.0.1 */
236236
int noPswd; /* Logged in without password (on 127.0.0.1) */
237237
int userUid; /* Integer user id */
238
- int isHuman; /* True if access by a human, not a spider or bot */
238
+ int isRobot; /* True if the client is definitely a robot. False
239
+ ** negatives are common for this flag */
239240
int comFmtFlags; /* Zero or more "COMMENT_PRINT_*" bit flags, should be
240241
** accessed through get_comment_format(). */
241242
const char *zSockName; /* Name of the unix-domain socket file */
242243
const char *zSockMode; /* File permissions for unix-domain socket */
243244
const char *zSockOwner; /* Owner, or owner:group for unix-domain socket */
244245
--- src/main.c
+++ src/main.c
@@ -233,11 +233,12 @@
233 * applicable when using SEE on Windows or Linux. */
234 #endif
235 int useLocalauth; /* No login required if from 127.0.0.1 */
236 int noPswd; /* Logged in without password (on 127.0.0.1) */
237 int userUid; /* Integer user id */
238 int isHuman; /* True if access by a human, not a spider or bot */
 
239 int comFmtFlags; /* Zero or more "COMMENT_PRINT_*" bit flags, should be
240 ** accessed through get_comment_format(). */
241 const char *zSockName; /* Name of the unix-domain socket file */
242 const char *zSockMode; /* File permissions for unix-domain socket */
243 const char *zSockOwner; /* Owner, or owner:group for unix-domain socket */
244
--- src/main.c
+++ src/main.c
@@ -233,11 +233,12 @@
233 * applicable when using SEE on Windows or Linux. */
234 #endif
235 int useLocalauth; /* No login required if from 127.0.0.1 */
236 int noPswd; /* Logged in without password (on 127.0.0.1) */
237 int userUid; /* Integer user id */
238 int isRobot; /* True if the client is definitely a robot. False
239 ** negatives are common for this flag */
240 int comFmtFlags; /* Zero or more "COMMENT_PRINT_*" bit flags, should be
241 ** accessed through get_comment_format(). */
242 const char *zSockName; /* Name of the unix-domain socket file */
243 const char *zSockMode; /* File permissions for unix-domain socket */
244 const char *zSockOwner; /* Owner, or owner:group for unix-domain socket */
245
+1 -1
--- src/style.c
+++ src/style.c
@@ -1487,11 +1487,11 @@
14871487
@ g.zHttpsURL = %h(g.zHttpsURL)<br>
14881488
@ g.zTop = %h(g.zTop)<br>
14891489
@ g.zPath = %h(g.zPath)<br>
14901490
@ g.userUid = %d(g.userUid)<br>
14911491
@ g.zLogin = %h(g.zLogin)<br>
1492
- @ g.isHuman = %d(g.isHuman)<br>
1492
+ @ g.isRobot = %d(g.isRobot)<br>
14931493
@ g.jsHref = %d(g.jsHref)<br>
14941494
if( g.zLocalRoot ){
14951495
@ g.zLocalRoot = %h(g.zLocalRoot)<br>
14961496
}else{
14971497
@ g.zLocalRoot = <i>none</i><br>
14981498
--- src/style.c
+++ src/style.c
@@ -1487,11 +1487,11 @@
1487 @ g.zHttpsURL = %h(g.zHttpsURL)<br>
1488 @ g.zTop = %h(g.zTop)<br>
1489 @ g.zPath = %h(g.zPath)<br>
1490 @ g.userUid = %d(g.userUid)<br>
1491 @ g.zLogin = %h(g.zLogin)<br>
1492 @ g.isHuman = %d(g.isHuman)<br>
1493 @ g.jsHref = %d(g.jsHref)<br>
1494 if( g.zLocalRoot ){
1495 @ g.zLocalRoot = %h(g.zLocalRoot)<br>
1496 }else{
1497 @ g.zLocalRoot = <i>none</i><br>
1498
--- src/style.c
+++ src/style.c
@@ -1487,11 +1487,11 @@
1487 @ g.zHttpsURL = %h(g.zHttpsURL)<br>
1488 @ g.zTop = %h(g.zTop)<br>
1489 @ g.zPath = %h(g.zPath)<br>
1490 @ g.userUid = %d(g.userUid)<br>
1491 @ g.zLogin = %h(g.zLogin)<br>
1492 @ g.isRobot = %d(g.isRobot)<br>
1493 @ g.jsHref = %d(g.jsHref)<br>
1494 if( g.zLocalRoot ){
1495 @ g.zLocalRoot = %h(g.zLocalRoot)<br>
1496 }else{
1497 @ g.zLocalRoot = <i>none</i><br>
1498

Keyboard Shortcuts

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