Changeset 39000


Ignore:
Timestamp:
2024-05-07T14:46:46+12:00 (2 weeks ago)
Author:
kjdon
Message:

the usecookies option has been renamed to usecookiesForUID to better reflect what it means. A new option usecookiesForE is added. If this is set to true (the default), then the e arg will be saved as a cookie, instead of being set into the various compressedoptions macros (which will now be empty). nzdl.org is getting hammered by bots, and one theory is that the e arg changes everytime so looks like a new page when its not.

Location:
main/trunk/greenstone2/runtime-src/src/recpt
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/runtime-src/src/recpt/cgiwrapper.cpp

    r30373 r39000  
    388388       << "  from the command line as it would be when run from your\n"
    389389       << "  web server.\n";
    390   if (configinfo.usecookies)
    391     cout << "cookies are enabled\n";
     390  if (configinfo.usecookiesForUID)
     391    cout << "UID will be saved as a cookie\n";
    392392  else
    393     cout << "cookies are disabled\n";
     393    cout << "UID not saved as a cookie\n";
     394  if (configinfo.usecookiesForE)
     395    cout << "The e arg will be saved as a cookie\n";
     396  else
     397    cout << "The e arg is not saved as a cookie - set usecookiesForE to true to use cookies for e \n";
    394398  if (configinfo.logcgiargs)
    395399    cout << "logging is enabled\n";
  • main/trunk/greenstone2/runtime-src/src/recpt/receptionist.cpp

    r31980 r39000  
    6363  macrofiles.erase(macrofiles.begin(), macrofiles.end());
    6464  saveconf.clear();
    65   usecookies = false;
     65  usecookiesForUID = false;
     66  usecookiesForE = true;
    6667  logcgiargs = false;
    6768  LogDateFormat = LocalTime;
     
    251252    }
    252253    else if (key == "saveconf") configinfo.saveconf = cfgline[0];
    253     else if (key == "usecookies") configinfo.usecookies = (cfgline[0] == "true");
     254    // keep usecookies here for backwards compatibility
     255    else if (key == "usecookies" || key == "usecookiesForUID") configinfo.usecookiesForUID = (cfgline[0] == "true");
     256    else if (key == "usecookiesForE") configinfo.usecookiesForE = (cfgline[0] == "true");
    254257    else if (key == "logcgiargs") configinfo.logcgiargs = (cfgline[0] == "true");
    255258    else if (key == "maintainer") configinfo.maintainer = cfgline[0];
     
    594597  args.clear();
    595598  split_cgi_args (argsinfo, argstr, args);
    596  
     599
     600  // get e cookie
     601  if (configinfo.usecookiesForE) get_named_cookie(args["e"], "GSDL_E", fcgienv);
    597602  // expand the compressed argument (if there was one)
    598603  if (!expand_save_args (argsinfo, configinfo.saveconf, args, logout)) return false;
     
    605610 
    606611  // get the cookie
    607   if (configinfo.usecookies) get_cookie(args["z"], fcgienv);
     612  if (configinfo.usecookiesForUID) get_uid_cookie(args["z"], fcgienv);
    608613 
    609614  // if we're changing languages, set the encoding to the default for the new language
     
    672677
    673678
     679// Returns true if cookie exists, false if not
     680bool receptionist::get_named_cookie (text_t &cookie, text_t cookie_name, text_tmap &fcgienv)
     681{
     682 
     683  // See if we can get the cookies
     684  text_t cookiestring = gsdl_getenv ("HTTP_COOKIE", fcgienv);
     685  if (cookiestring.empty()) return false;
     686    // This should really be handled by the findword function...
     687 
     688    // Check if the cookie contains 'cookie_name'
     689  text_t cid = cookie_name+"=";
     690  text_t::iterator cid_start = findword(cookiestring.begin(), cookiestring.end(), cid);
     691  if (cid_start != cookiestring.end())
     692  {
     693    // Yes, so extract its value
     694    cookie = substr(cid_start + cid.size(), findchar(cid_start + cid.size(), cookiestring.end(), ';'));
     695    return true;
     696  }
     697  return false;
     698}
     699
    674700// Returns true if cookie already existed, false if it was generated
    675 bool receptionist::get_cookie (text_t &cookie, text_tmap &fcgienv)
     701bool receptionist::get_uid_cookie (text_t &cookie, text_tmap &fcgienv)
    676702{
    677703  // See if we can get the GSDL_UID cookie
    678   text_t cookiestring = gsdl_getenv ("HTTP_COOKIE", fcgienv);
    679   if (!cookiestring.empty()) // This should really be handled by the findword function...
    680   {
    681     // Check if the cookie contains GSDL_UID
    682     text_t gsdl_uid = "GSDL_UID=";
    683     text_t::iterator gsdl_uid_start = findword(cookiestring.begin(), cookiestring.end(), gsdl_uid);
    684     if (gsdl_uid_start != cookiestring.end())
    685     {
    686       // Yes, so extract its value
    687       cookie = substr(gsdl_uid_start + gsdl_uid.size(), findchar(gsdl_uid_start + gsdl_uid.size(), cookiestring.end(), ';'));
    688       return true;
    689     }
    690   }
    691 
     704  bool found = get_named_cookie(cookie, "GSDL_UID", fcgienv);
     705  if (found) return true;
    692706  // Generate a new key "[host]-[epoch time]", e.g. test.com-1256764496
    693707  cookie.clear();
     
    706720
    707721// Same as above but just tests if cookie exists
    708 bool receptionist::get_cookie (text_tmap &fcgienv)
     722bool receptionist::has_uid_cookie (text_tmap &fcgienv)
    709723{
    710724  text_t cookie_jar = "";
    711   return get_cookie(cookie_jar, fcgienv);
     725  return get_named_cookie(cookie_jar, "GSDL_UID", fcgienv);
     726
    712727}
    713728
     
    957972
    958973    // add cookie if required
    959     if (configinfo.usecookies && !get_cookie(fcgienv))
     974    if (configinfo.usecookiesForUID && !has_uid_cookie(fcgienv))
    960975      response_data += "\nSet-Cookie: GSDL_UID=" + args["z"]
    961976    + "; expires=Fri, 25-Dec-2037 00:00:00 GMT";
     977    if (configinfo.usecookiesForE) {
     978      // set the GSDL_E cookie
     979      response_data += "\nSet-Cookie: GSDL_E=" + get_compressed_arg (args, logout)
     980    + "; expires=Fri, 25-Dec-2037 00:00:00 GMT";
     981    }
     982       
    962983  }
    963984}
     
    14761497
    14771498
    1478   text_t compressedoptions = get_compressed_arg(args, logout);
     1499  text_t compressedoptions = "";
     1500  if (!configinfo.usecookiesForE) {
     1501    compressedoptions = get_compressed_arg(args, logout);
     1502  }
    14791503  disp.setmacro ("compressedoptions", displayclass::defaultpackage, dm_safe(compressedoptions));
    14801504  //disp.setmacro ("compressedoptionsUrlsafe", displayclass::defaultpackage, encodeForURL(dm_safe(compressedoptions))); // seems to be unnecessary after testing e=hack or e=hack<collect>... or e=...<collect>hack in a live server
     
    14981522  // the old version was dm_safed, so make a dm safe version in case we need it
    14991523  disp.setmacro ("decodedcompressedoptionsAttrDmsafe", displayclass::defaultpackage, encodeForHTMLAttr(dm_safe(dmacrovalue)));
     1524
    15001525
    15011526#if defined (__WIN32__)
  • main/trunk/greenstone2/runtime-src/src/recpt/receptionist.h

    r19109 r39000  
    8888   text_tset macrofiles;
    8989   text_t saveconf;
    90    bool usecookies;  // true if we want cookies set
     90   bool usecookiesForUID;  // true if we want to save user id as a cookie
     91  bool usecookiesForE; // true if want to save the e arg as a cookie instead of passing it round as an arg
    9192   bool logcgiargs;  // true if we want to log cgi arguments
    9293   
     
    143144                ostream &logout);
    144145   
    145    bool get_cookie (text_t &cookie, text_tmap &fcgienv);
    146    bool get_cookie (text_tmap &fcgienv);
    147    
     146   bool get_uid_cookie (text_t &cookie, text_tmap &fcgienv);
     147   bool has_uid_cookie (text_tmap &fcgienv);
     148  bool get_named_cookie (text_t &cookie, const text_t cookie_name, text_tmap &fcgienv);
     149 
    148150   // get the default encoding for the given language - if it fails for any
    149151   // reason, return ""
  • main/trunk/greenstone2/runtime-src/src/recpt/statusaction.cpp

    r28911 r39000  
    171171      << "\"</td></tr>\n";
    172172
    173   // usecookies
    174   textout << outconvert << "<tr valign=top><th>usecookies</th><td>\"";
    175   if (rcinfo.usecookies) textout << outconvert << "true";
     173  // usecookiesForUID
     174  textout << outconvert << "<tr valign=top><th>usecookiesForUID</th><td>\"";
     175  if (rcinfo.usecookiesForUID) textout << outconvert << "true";
     176  else textout << outconvert << "false";
     177  textout << outconvert << "\"</td></tr>\n";
     178  // usecookiesForE
     179  textout << outconvert << "<tr valign=top><th>usecookiesForE</th><td>\"";
     180  if (rcinfo.usecookiesForE) textout << outconvert << "true";
    176181  else textout << outconvert << "false";
    177182  textout << outconvert << "\"</td></tr>\n";
Note: See TracChangeset for help on using the changeset viewer.