Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.
/mnet/ -> lib.php (source)

Differences Between: [Versions 310 and 400] [Versions 311 and 400] [Versions 39 and 400] [Versions 400 and 401] [Versions 400 and 402] [Versions 400 and 403]

Library functions for mnet

Author: Donal McMullan donal@catalyst.net.nz
License: http://www.gnu.org/copyleft/gpl.html GNU Public License
Version: 0.0.1
File Size: 936 lines (34 kb)
Included or required:0 times
Referenced: 6 times
Includes or requires: 0 files

Defines 20 functions


Functions that are not part of a class:

mnet_get_hostname_from_uri($uri = null)   X-Ref
Strip extraneous detail from a URL or URI and return the hostname

return: string        Just the hostname
param: string  $uri  The URI of a file on the remote computer, optionally

mnet_get_public_key($uri, $application=null)   X-Ref
Get the remote machine's SSL Cert

return: string           A PEM formatted SSL Certificate.
param: string  $uri     The URI of a file on the remote computer, including

mnet_set_public_key($uri, $key = null)   X-Ref
Store a URI's public key in a static variable, or retrieve the key for a URI

return: mixed         A public key OR true/false.
param: string  $uri  The URI of a file on the remote computer, including its
param: mixed   $key  A public key to store in the array OR null. If the key

mnet_sign_message($message, $privatekey = null)   X-Ref
Sign a message and return it in an XML-Signature document

This function can sign any content, but it was written to provide a system of
signing XML-RPC request and response messages. The message will be base64
encoded, so it does not need to be text.

We compute the SHA1 digest of the message.
We compute a signature on that digest with our private key.
We link to the public key that can be used to verify our signature.
We base64 the message data.
We identify our wwwroot - this must match our certificate's CN

The XML-RPC document will be parceled inside an XML-SIG document, which holds
the base64_encoded XML as an object, the SHA1 digest of that document, and a
signature of that document using the local private key. This signature will
uniquely identify the RPC document as having come from this server.

See the {@Link http://www.w3.org/TR/xmldsig-core/ XML-DSig spec} at the W3c
site

return: string                         An XML-DSig document
param: string   $message              The data you want to sign
param: resource $privatekey           The private key to sign the response with

mnet_encrypt_message($message, $remote_certificate)   X-Ref
Encrypt a message and return it in an XML-Encrypted document

This function can encrypt any content, but it was written to provide a system
of encrypting XML-RPC request and response messages. The message will be
base64 encoded, so it does not need to be text - binary data should work.

We compute the SHA1 digest of the message.
We compute a signature on that digest with our private key.
We link to the public key that can be used to verify our signature.
We base64 the message data.
We identify our wwwroot - this must match our certificate's CN

The XML-RPC document will be parceled inside an XML-SIG document, which holds
the base64_encoded XML as an object, the SHA1 digest of that document, and a
signature of that document using the local private key. This signature will
uniquely identify the RPC document as having come from this server.

See the {@Link http://www.w3.org/TR/xmlenc-core/ XML-ENC spec} at the W3c
site

return: string                         An XML-ENC document
param: string   $message              The data you want to sign
param: string   $remote_certificate   Peer's certificate in PEM format

mnet_get_keypair()   X-Ref
Get your SSL keys from the database, or create them (if they don't exist yet)

Get your SSL keys from the database, or (if they don't exist yet) call
mnet_generate_keypair to create them

return: string              The signature over that text
param: string  $string     The text you want to sign

mnet_generate_keypair($dn = null, $days=28)   X-Ref
Generate public/private keys and store in the config table

Use the distinguished name provided to create a CSR, and then sign that CSR
with the same credentials. Store the keypair you create in the config table.
If a distinguished name is not provided, create one using the fullname of
'the course with ID 1' as your organization name, and your hostname (as
detailed in $CFG->wwwroot).

return: string      The signature over that text
param: array  $dn  The distinguished name of the server

mnet_update_sso_access_control($username, $mnet_host_id, $accessctrl)   X-Ref
No description

mnet_get_peer_host($mnethostid)   X-Ref
No description

mnet_sso_apply_indirection($jumpurl, $url)   X-Ref
Inline function to modify a url string so that mnet users are requested to
log in at their mnet identity provider (if they are not already logged in)
before ultimately being directed to the original url.

return: string the url the remote user should be supplied with.
param: string $jumpurl the url which user should initially be directed to.
param: array $url array with 2 elements

mnet_get_app_jumppath($applicationid)   X-Ref
No description

mnet_debug($debugdata, $debuglevel=1)   X-Ref
Output debug information about mnet.  this will go to the <b>error_log</b>.

param: mixed $debugdata this can be a string, or array or object.
param: int   $debuglevel optional , defaults to 1. bump up for very noisy debug info

mnet_profile_field_options()   X-Ref
Return an array of information about all moodle's profile fields
which ones are optional, which ones are forced.
This is used as the basis of providing lists of profile fields to the administrator
to pick which fields to import/export over MNET

return: array(forced => array, optional => array)

mnet_get_hosts($withdeleted = false)   X-Ref
Returns information about MNet peers

return: array
param: bool $withdeleted should the deleted peers be returned too

mnet_get_service_info(mnet_peer $mnet_peer, $fulldata=true)   X-Ref
return an array information about services enabled for the given peer.
in two modes, fulldata or very basic data.

return: array  If $fulldata is false, an array is returned like:
param: mnet_peer $mnet_peer the peer to get information abut
param: boolean   $fulldata whether to just return which services are published/subscribed, or more information (defaults to full)

mnet_fields_to_send(mnet_peer $peer)   X-Ref
return an array of the profile fields to send
with user information to the given mnet host.

return: array (like 'username', 'firstname', etc)
param: mnet_peer $peer the peer to send the information to

mnet_fields_to_import(mnet_peer $peer)   X-Ref
return an array of the profile fields to import
from the given host, when creating/updating user accounts

return: array (like 'username', 'firstname', etc)
param: mnet_peer $peer the peer we're getting the information from

_mnet_field_helper(mnet_peer $peer, $key)   X-Ref
helper for {@see mnet_fields_to_import} and {@mnet_fields_to_send}

return: array (like 'username', 'firstname', etc)
param: mnet_peer $peer the peer object
param: string    $key 'import' or 'export'

mnet_strip_user($user, $fields)   X-Ref
given a user object (or array) and a list of allowed fields,
strip out all the fields that should not be included.
This can be used both for outgoing data and incoming data.

return: mixed array or object, depending what type of $user object was passed (datatype is respected)
param: mixed $user array or object representing a database record
param: array $fields an array of allowed fields (usually from mnet_fields_to_{send,import}

mnet_get_deprecation_notice()   X-Ref
Return the deprecation notice of the Mnet.

return: \core\output\notification