Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-66166

Improve the moodlebot user agent and expose a function for plugins to use

    XMLWordPrintable

Details

    • MOODLE_38_STABLE
    • MOODLE_38_STABLE
    • Hide

      Verify the raw api

      The best practice for bots is to include a "+ prefixed url back to the calling domain" as User agent substring.

      1. To verify that this has been implemented correctly in this patch, run this command:

        $ php -r "define('CLI_SCRIPT', true); require_once('config.php'); print \core_useragent::get_moodlebot_useragent().PHP_EOL;"
        

        1. The output should be similar to this:

          MoodleBot/3.8 (+http://moodle.local)
          

      h3 Verify with a call from Moodle out
      Verify this is being used by curl() test using a 3rd party service which just echo's headers:

      1. Run the following command:

        php -r "define('CLI_SCRIPT', true); require_once('config.php'); require_once('lib/filelib.php'); print_object(json_decode(download_file_content('https://postman-echo.com/get')));"
        

        1. The output should be similar to:

          stdClass Object
          (
              [args] => stdClass Object
                  (
                  )
           
              [headers] => stdClass Object
                  (
                      [x-forwarded-proto] => https
                      [host] => postman-echo.com
                      [accept] => */*
                      [accept-charset] => ISO-8859-1,utf-8;q=0.7,*;q=0.7
                      [accept-encoding] => deflate, gzip, br
                      [user-agent] => MoodleBot/3.8 (+http://boysenberry.local/im)
                      [x-forwarded-port] => 443
                  )
           
              [url] => https://postman-echo.com/get
          )
          

          Note the MoodleBot in the user-agent section which should contain your own wwwroot

      Show
      Verify the raw api The best practice for bots is to include a "+ prefixed url back to the calling domain" as User agent substring. To verify that this has been implemented correctly in this patch, run this command: $ php -r "define('CLI_SCRIPT', true); require_once('config.php'); print \core_useragent::get_moodlebot_useragent().PHP_EOL;" The output should be similar to this: MoodleBot/3.8 (+http://moodle.local) h3 Verify with a call from Moodle out Verify this is being used by curl() test using a 3rd party service which just echo's headers: Run the following command: php -r "define('CLI_SCRIPT', true); require_once('config.php'); require_once('lib/filelib.php'); print_object(json_decode(download_file_content('https://postman-echo.com/get')));" The output should be similar to: stdClass Object ( [args] => stdClass Object ( )   [headers] => stdClass Object ( [x-forwarded-proto] => https [host] => postman-echo.com [accept] => */* [accept-charset] => ISO-8859-1,utf-8;q=0.7,*;q=0.7 [accept-encoding] => deflate, gzip, br [user-agent] => MoodleBot/3.8 (+http://boysenberry.local/im) [x-forwarded-port] => 443 )   [url] => https://postman-echo.com/get ) Note the MoodleBot in the user-agent section which should contain your own wwwroot

    Description

      I just want a way to expose and reuse the moodlebot UA string instead of it being hardcoded here:

      https://github.com/moodle/moodle/blob/master/lib/filelib.php#L3105

      it should also recognize itself here:

      https://github.com/moodle/moodle/blob/master/lib/classes/useragent.php#L217

       

       

      Attachments

        Activity

          People

            brendanheywood Brendan Heywood
            brendanheywood Brendan Heywood
            Alexander Bias Alexander Bias
            Andrew Lyons Andrew Lyons
            Jennifer Bauzon Jennifer Bauzon
            Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Sara Arjona (@sarjona)
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              18/Nov/19

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 hour, 10 minutes
                1h 10m