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

MNet "register all hosts" not working - and remove remaining each() use

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • 3.11.6
    • 3.9.11, 3.10.8, 3.11.4, 4.0
    • MNet
    • MOODLE_310_STABLE, MOODLE_311_STABLE, MOODLE_39_STABLE, MOODLE_400_STABLE
    • MOODLE_311_STABLE
    • Hide

      Requisites

      1. To have php with the php-xmlrpc extension enabled.
      2. To be able to edit php files to add some debugging information.
      3. It's enough to test this with php74, though it's ideal to test it also with php80.

      Configuration

      1. Install a moodle site
      2. In Admin -> Advanced features, enable "Networking" (On) and save changes.
      3. Navigate to http://YOURSITE/admin/mnet/index.php.
      4. Verify that you see a publick key (a long text with BEGIN CERTIFICATE... END CERTIFICATE).
      5. Click on "Delete this key" and confirm (clicking on "yes).
      6. *Verify that you're back to the page where the public key is shown and that the key has a "Valid until" being around 28 days (aprox) in the future.
      7. Copy the public key to some document (we'll use it later for some verifications).
      8. Navigate to http://YOURSITE/admin/mnet/peers.php
      9. Verify that "Register all hosts is currently" is currently OFF.
      10. Edit the mnet/xmlrpc/serverlib.php file. In the mnet_keyswap() function add this line:

        @@ -532,6 +532,7 @@ function mnet_keyswap($function, $params) {
                 $mnet_peer = new mnet_peer();
                 list($wwwroot, $pubkey, $application) = $params;
                 $keyok = $mnet_peer->bootstrap($wwwroot, $pubkey, $application);
        +        error_log('KEYOK: ' . (int)$keyok);
                 if ($keyok) {
                     $mnet_peer->commit();
                 }
        

      11. Open a terminal to inspect the web server error logs, it should be something like:

        tail -f /path/to/your/web/server/error_log
        

      12. Download the data.xml file attached to this issue.

      Tests with "enable all hosts" disabled.

      1. Execute:

        curl -X POST -d @data.xml http://YOURSITE/mnet/xmlrpc/server.php
        

      2. Verify that some XML is returned and it looks like this:

        <methodResponse>
        <params>
         <param>
          <value>
           <string>-----BEGIN CERTIFICATE-----&#10;
                LONG-PUB-KEY-GOES HERE
        -----END CERTIFICATE-----&#10;</string>
          </value>
         </param>
        </params>
        </methodResponse>
        

      3. Verify that the pub key matches the pub key saved in step 7 of configuration (to verify that the first 20-30 chars are the same is enough).
      4. Verify that no KEYOK line has been printed in logs.
      5. Go to http://YOURSITE/admin/mnet/peers.php
      6. Verify that there isn't any site in the list apart from the "all hosts" one.

      Tests with "enable all hosts" enabled.

      1. Go to http://YOURSITE/admin/mnet/peers.php
      2. Clink on the "Turn it on" button.
      3. Verify that "Register all hosts is currently" is currently ON.
      4. Execute:

        curl -X POST -d @data.xml http://YOURSITE/mnet/xmlrpc/server.php
        

      5. Verify that some XML is returned and it looks like this:

        <methodResponse>
        <params>
         <param>
          <value>
           <string>-----BEGIN CERTIFICATE-----&#10;
                LONG-PUB-KEY-GOES HERE
        -----END CERTIFICATE-----&#10;</string>
          </value>
         </param>
        </params>
        </methodResponse>
        

      6. Verify that the pub key matches the pub key saved in step 7 of configuration (to verify that the first 20-30 chars are the same is enough).
      7. Verify that KEYOK: 1 line has been printed in logs.
      8. Verify, if your site has debugging enabled, that there is also a "cURL request" error printed in logs. That's normal, because the testing site has tried to access to http://127.0.0.1/~stronk7/integration that obviously doesn't exist in your testing environment. It's not important, because it's only used to fetch the site name.
      9. Go to http://YOURSITE/admin/mnet/peers.php
      10. Verify that there is a new site added, with URL and name http://127.0.0.1/~stronk7/integration
      Show
      Requisites To have php with the php-xmlrpc extension enabled. To be able to edit php files to add some debugging information. It's enough to test this with php74, though it's ideal to test it also with php80. Configuration Install a moodle site In Admin -> Advanced features, enable "Networking" (On) and save changes. Navigate to http://YOURSITE/admin/mnet/index.php . Verify that you see a publick key (a long text with BEGIN CERTIFICATE... END CERTIFICATE). Click on "Delete this key" and confirm (clicking on "yes). *Verify that you're back to the page where the public key is shown and that the key has a "Valid until" being around 28 days (aprox) in the future. Copy the public key to some document (we'll use it later for some verifications). Navigate to http://YOURSITE/admin/mnet/peers.php Verify that "Register all hosts is currently" is currently OFF. Edit the mnet/xmlrpc/serverlib.php file. In the mnet_keyswap() function add this line: @@ -532,6 +532,7 @@ function mnet_keyswap($function, $params) { $mnet_peer = new mnet_peer(); list($wwwroot, $pubkey, $application) = $params; $keyok = $mnet_peer->bootstrap($wwwroot, $pubkey, $application); + error_log('KEYOK: ' . (int)$keyok); if ($keyok) { $mnet_peer->commit(); } Open a terminal to inspect the web server error logs, it should be something like: tail -f /path/to/your/web/server/error_log Download the data.xml file attached to this issue. Tests with "enable all hosts" disabled. Execute: curl -X POST -d @data.xml http://YOURSITE/mnet/xmlrpc/server.php Verify that some XML is returned and it looks like this: <methodResponse> <params> <param> <value> <string>-----BEGIN CERTIFICATE-----&#10; LONG-PUB-KEY-GOES HERE -----END CERTIFICATE-----&#10;</string> </value> </param> </params> </methodResponse> Verify that the pub key matches the pub key saved in step 7 of configuration (to verify that the first 20-30 chars are the same is enough). Verify that no KEYOK line has been printed in logs. Go to http://YOURSITE/admin/mnet/peers.php Verify that there isn't any site in the list apart from the "all hosts" one. Tests with "enable all hosts" enabled. Go to http://YOURSITE/admin/mnet/peers.php Clink on the "Turn it on" button. Verify that "Register all hosts is currently" is currently ON. Execute: curl -X POST -d @data.xml http://YOURSITE/mnet/xmlrpc/server.php Verify that some XML is returned and it looks like this: <methodResponse> <params> <param> <value> <string>-----BEGIN CERTIFICATE-----&#10; LONG-PUB-KEY-GOES HERE -----END CERTIFICATE-----&#10;</string> </value> </param> </params> </methodResponse> Verify that the pub key matches the pub key saved in step 7 of configuration (to verify that the first 20-30 chars are the same is enough). Verify that KEYOK: 1 line has been printed in logs. Verify , if your site has debugging enabled, that there is also a "cURL request" error printed in logs. That's normal, because the testing site has tried to access to http://127.0.0.1/~stronk7/integration that obviously doesn't exist in your testing environment. It's not important, because it's only used to fetch the site name. Go to http://YOURSITE/admin/mnet/peers.php Verify that there is a new site added, with URL and name http://127.0.0.1/~stronk7/integration

      This is part of the php80 epic (MDL-70745) because it was discovered when looking for not working stuff with that new version.

      Looking for each() uses in codebase (that was deprecated in php72 and has been removed in php80) only one real use was found, so far:

      $ ag '\beach\(' --php
      mnet/xmlrpc/serverlib.php
      533:        @list($wwwroot, $pubkey, $application) = each($params);
      ...
      

      (there is another in a lib/tcpdf/tcpdf.php comment, but it doesn't matter)

      The point about that line is that is, simply, plain wrong, and it never has worked. $params is an array with 3 elements, non-associative, with values being caller wwwroot, caller pubkey and caller application type. And the use of each() there, simply makes no sense. You can see it in action @ https://3v4l.org/tMK3aj

      So the proposal, is to just change that bogus line by:

      list($wwwroot, $pubkey, $application) = $params;

      And done!

      But then, when testing the results... it was discovered that, also... when a moodle site is set in "promiscuous mode" (that means that it registers all callers as mnet peers automatically, instead of having to create them manually)... it's not working at all either. And tracing that down... it's because the mnet_peer::bootstrap() method, that returns true on success (if the caller is correct) or false on failure (if the caller url, pubkey, application aren't good) is missing a return true; at the end of the method, when everything has been verified.

      Hence, we need to, also, add that missing return. That way, the server in promiscuous mode will, automatically, add the caller to its list of peers.

      So, summary, with the changes here (2 lines of code), we solve 3 problems:

      • php80 compatibility, removing the only remaining each() use in codebase.
      • fix a mnet old bug (> 10y) where the parameters were being handled incorrectly.
      • make promiscuous mode to work as expected, it never has worked ok with current code.

        1. data.xml
          2 kB
        2. MDL-73514_master_disabled_1.png
          MDL-73514_master_disabled_1.png
          330 kB
        3. MDL-73514_master_disabled_2.png
          MDL-73514_master_disabled_2.png
          192 kB
        4. MDL-73514_master_disabled_3.png
          MDL-73514_master_disabled_3.png
          100 kB
        5. MDL-73514_master_enabled_1.png
          MDL-73514_master_enabled_1.png
          102 kB
        6. MDL-73514_master_enabled_2.png
          MDL-73514_master_enabled_2.png
          330 kB
        7. MDL-73514_master_enabled_3.png
          MDL-73514_master_enabled_3.png
          230 kB
        8. MDL-73514_master_enabled_4.png
          MDL-73514_master_enabled_4.png
          107 kB
        9. MDL-73514_v311_disabled_1.png
          MDL-73514_v311_disabled_1.png
          332 kB
        10. MDL-73514_v311_disabled_2.png
          MDL-73514_v311_disabled_2.png
          136 kB
        11. MDL-73514_v311_disabled_3.png
          MDL-73514_v311_disabled_3.png
          104 kB
        12. MDL-73514_v311_enabled_1.png
          MDL-73514_v311_enabled_1.png
          105 kB
        13. MDL-73514_v311_enabled_2.png
          MDL-73514_v311_enabled_2.png
          333 kB
        14. MDL-73514_v311_enabled_3.png
          MDL-73514_v311_enabled_3.png
          171 kB
        15. MDL-73514_v311_enabled_4.png
          MDL-73514_v311_enabled_4.png
          111 kB

            stronk7 Eloy Lafuente (stronk7)
            stronk7 Eloy Lafuente (stronk7)
            Nobody Nobody
            Victor Déniz Falcón Victor Déniz Falcón
            Angelia Dela Cruz Angelia Dela Cruz
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 6 hours, 1 minute
                6h 1m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.