Moodle APIs
3.8
Moodle 3.8.6 (Build: 20201109)
|
Classes | |
class | mnet_peer |
class | mnet_xmlrpc_client |
Class representing an XMLRPC request against a remote machine. More... | |
Functions | |
discard_data ($parser, $data) | |
Discard the next chunk of character data. More... | |
encrypted_to ($keyresource) | |
end_element ($parser, $name) | |
Switch the character-data handler to ignore the next chunk of data. More... | |
free_resource () | |
Destroy the parser and free up any related resource. | |
initialise () | |
Set default element handlers and initialise properties to empty. More... | |
mnet_debug ($debugdata, $debuglevel=1) | |
Output debug information about mnet. More... | |
mnet_encrypt_message ($message, $remote_certificate) | |
Encrypt a message and return it in an XML-Encrypted document. More... | |
mnet_encxml_parser () | |
Old syntax of class constructor. More... | |
mnet_fields_to_import (mnet_peer $peer) | |
return an array of the profile fields to import from the given host, when creating/updating user accounts More... | |
mnet_fields_to_send (mnet_peer $peer) | |
return an array of the profile fields to send with user information to the given mnet host. More... | |
mnet_generate_keypair ($dn=null, $days=28) | |
Generate public/private keys and store in the config table. More... | |
mnet_get_app_jumppath ($applicationid) | |
mnet_get_hostname_from_uri ($uri=null) | |
Strip extraneous detail from a URL or URI and return the hostname. More... | |
mnet_get_hosts ($withdeleted=false) | |
Returns information about MNet peers. More... | |
mnet_get_keypair () | |
Get your SSL keys from the database, or create them (if they don't exist yet) More... | |
mnet_get_peer_host ($mnethostid) | |
mnet_get_public_key ($uri, $application=null) | |
Get the remote machine's SSL Cert. More... | |
mnet_get_service_info (mnet_peer $mnet_peer, $fulldata=true) | |
return an array information about services enabled for the given peer. More... | |
mnet_profile_field_options () | |
Return an array of information about all moodle's profile fields which ones are optional, which ones are forced. More... | |
mnet_set_public_key ($uri, $key=null) | |
Store a URI's public key in a static variable, or retrieve the key for a URI. More... | |
mnet_sign_message ($message, $privatekey=null) | |
Sign a message and return it in an XML-Signature document. More... | |
mnet_sso_apply_indirection ($jumpurl, $url) | |
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. More... | |
mnet_strip_user ($user, $fields) | |
given a user object (or array) and a list of allowed fields, strip out all the fields that should not be included. More... | |
mnet_update_sso_access_control ($username, $mnet_host_id, $accessctrl) | |
object_to_call ($object) | |
parse ($data) | |
Parse a block of XML text. More... | |
parse_cipher ($parser, $data) | |
Add the next chunk of character data to the cipher string for that tag. More... | |
parse_digest ($parser, $data) | |
Add the next chunk of character data to the digest string. More... | |
parse_fault ($parser, $data) | |
parse_object ($parser, $data) | |
Add the next chunk of character data to the data_object string. More... | |
parse_signature ($parser, $data) | |
Add the next chunk of character data to the signature string. More... | |
parse_timestamp ($parser, $data) | |
Add the next chunk of character data to the remote_timestamp string. More... | |
parse_wwwroot ($parser, $data) | |
Add the next chunk of character data to the remote_wwwroot string. More... | |
plaintext_is_ok () | |
refresh_key () | |
set_pushkey () | |
signature_verified () | |
start_element ($parser, $name, $attrs) | |
Set the character-data handler to the right function for each element. More... | |
static_location ($location) | |
was_encrypted () | |
was_signed () | |
Variables | |
$pushkey = false | |
$request_was_encrypted = false | |
$request_was_signed = false | |
$signatureok = false | |
$static_location = false | |
$useprivatekey = '' | |
*author Donal McMullan donal catalyst net nz *version *license | http |
*author Donal McMullan donal catalyst net nz *version *license | http |
*author Donal McMullan donal catalyst net nz *version *license | http |
*author Donal McMullan donal catalyst net nz *version *license | http |
*author Donal McMullan donal catalyst net nz *version *license | http |
const | RPC_FORBIDDENFUNCTION 4 |
const | RPC_FORBIDDENMETHOD 6 |
const | RPC_NOSUCHCLASS 2 |
const | RPC_NOSUCHFILE 1 |
const | RPC_NOSUCHFUNCTION 3 |
const | RPC_NOSUCHMETHOD 5 |
const | RPC_OK 0 |
CONSTANTS ///////////////////////////////////////////////////////////. | |
discard_data | ( | $parser, | |
$data | |||
) |
Discard the next chunk of character data.
This is used for tags that we're not interested in.
mixed | $parser | The XML parser |
string | $data | The content of the current tag (1024 byte chunk) |
bool | True |
end_element | ( | $parser, | |
$name | |||
) |
Switch the character-data handler to ignore the next chunk of data.
mixed | $parser | The XML parser |
string | $name | The name of the tag, e.g. method_call |
bool | True |
initialise | ( | ) |
Set default element handlers and initialise properties to empty.
bool | True |
mnet_debug | ( | $debugdata, | |
$debuglevel = 1 |
|||
) |
Output debug information about mnet.
this will go to the error_log.
mixed | $debugdata | this can be a string, or array or object. |
int | $debuglevel | optional , defaults to 1. bump up for very noisy debug info |
mnet_encrypt_message | ( | $message, | |
$remote_certificate | |||
) |
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
string | $message | The data you want to sign |
string | $remote_certificate | Peer's certificate in PEM format |
string | An XML-ENC document |
mnet_encxml_parser | ( | ) |
mnet_fields_to_import | ( | mnet_peer | $peer | ) |
return an array of the profile fields to import from the given host, when creating/updating user accounts
mnet_peer | $peer | the peer we're getting the information from |
array | (like 'username', 'firstname', etc) |
mnet_fields_to_send | ( | mnet_peer | $peer | ) |
return an array of the profile fields to send with user information to the given mnet host.
mnet_peer | $peer | the peer to send the information to |
array | (like 'username', 'firstname', etc) |
mnet_generate_keypair | ( | $dn = null , |
|
$days = 28 |
|||
) |
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).
array | $dn | The distinguished name of the server |
string | The signature over that text |
mnet_get_hostname_from_uri | ( | $uri = null | ) |
Strip extraneous detail from a URL or URI and return the hostname.
string | $uri | The URI of a file on the remote computer, optionally including its http:// prefix like http://www.example.com/index.html |
string | Just the hostname |
mnet_get_hosts | ( | $withdeleted = false | ) |
Returns information about MNet peers.
bool | $withdeleted | should the deleted peers be returned too |
array |
mnet_get_keypair | ( | ) |
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
string | $string | The text you want to sign |
string | The signature over that text |
mnet_get_public_key | ( | $uri, | |
$application = null |
|||
) |
mnet_get_service_info | ( | mnet_peer | $mnet_peer, |
$fulldata = true |
|||
) |
return an array information about services enabled for the given peer.
in two modes, fulldata or very basic data.
mnet_peer | $mnet_peer | the peer to get information abut |
boolean | $fulldata | whether to just return which services are published/subscribed, or more information (defaults to full) |
array | If $fulldata is false, an array is returned like: publish => array( serviceid => boolean, serviceid => boolean, ), subscribe => array( serviceid => boolean, serviceid => boolean, ) If $fulldata is true, an array is returned like: servicename => array( apiversion => array( name => string offer => boolean apiversion => int plugintype => string pluginname => string hostsubscribes => boolean hostpublishes => boolean ), ) |
mnet_profile_field_options | ( | ) |
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
array(forced | => array, optional => array) |
mnet_set_public_key | ( | $uri, | |
$key = null |
|||
) |
Store a URI's public key in a static variable, or retrieve the key for a URI.
string | $uri | The URI of a file on the remote computer, including its https:// prefix |
mixed | $key | A public key to store in the array OR null. If the key is null, the function will return the previously stored key for the supplied URI, should it exist. |
mixed | A public key OR true/false. |
mnet_sign_message | ( | $message, | |
$privatekey = null |
|||
) |
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
string | $message | The data you want to sign |
resource | $privatekey | The private key to sign the response with |
string | An XML-DSig document |
mnet_sso_apply_indirection | ( | $jumpurl, | |
$url | |||
) |
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.
string | $jumpurl | the url which user should initially be directed to. This is a URL associated with a moodle networking peer when it is fulfiling a role as an identity provider (IDP). Different urls for different peers, the jumpurl is formed partly from the IDP's webroot, and partly from a predefined local path within that webwroot. The result of the user hitting this jump url is that they will be asked to login (at their identity provider (if they aren't already)), mnet will prepare the necessary authentication information, then redirect them back to somewhere at the content provider(CP) moodle (this moodle) |
array | $url | array with 2 elements 0 - context the url was taken from, possibly just the url, possibly href="url" 1 - the destination url |
string | the url the remote user should be supplied with. |
mnet_strip_user | ( | $user, | |
$fields | |||
) |
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.
mixed | $user | array or object representing a database record |
array | $fields | an array of allowed fields (usually from mnet_fields_to_{send,import} |
mixed | array or object, depending what type of $user object was passed (datatype is respected) |
parse | ( | $data | ) |
Parse a block of XML text.
The XML Text will be an XML-RPC request which is wrapped in an XML doc with a signature from the sender. This envelope may be encrypted and delivered within another XML envelope with a symmetric key. The parser should first decrypt this XML, and then place the XML-RPC request into the data_object property, and the signature into the signature property.
See the W3C's * and @javalink http://www.w3.org/TR/2001/PR-xmldsig-core-20010820/ XML-Signature Syntax and Processing guidelines for more detail on the XML.
--—XML-Envelope------------------------------— | | | Symmetric-key-----------------------— | | |_____________________________________| | | | | Encrypted data----------------------— | | | | | | | -XML-Envelope---------------— | | | | | | | | | | | –Signature----------— | | | | | | |______________________| | | | | | | | | | | | | –Signed-Payload-----— | | | | | | | | | | | | | | | XML-RPC Request | | | | | | | |______________________| | | | | | | | | | | | |_____________________________| | | | |_____________________________________| | | | |________________________________________________|
string | $data | The XML that you want to parse |
bool | True on success - false on failure |
parse_cipher | ( | $parser, | |
$data | |||
) |
Add the next chunk of character data to the cipher string for that tag.
The XML parser calls the character-data handler with 1024-character chunks of data. This means that the handler may be called several times for a single tag, so we use the concatenate operator (.) to build the tag content into a string. We should not encounter more than one of each tag type, except for the cipher tag. We will often see two of those. We prevent the content of these two tags being concatenated together by counting each tag, and using its 'number' as the key to an array of ciphers.
mixed | $parser | The XML parser |
string | $data | The content of the current tag (1024 byte chunk) |
bool | True |
parse_digest | ( | $parser, | |
$data | |||
) |
Add the next chunk of character data to the digest string.
mixed | $parser | The XML parser |
string | $data | The content of the current tag (1024 byte chunk) |
bool | True |
parse_object | ( | $parser, | |
$data | |||
) |
Add the next chunk of character data to the data_object string.
mixed | $parser | The XML parser |
string | $data | The content of the current tag (1024 byte chunk) |
bool | True |
parse_signature | ( | $parser, | |
$data | |||
) |
Add the next chunk of character data to the signature string.
mixed | $parser | The XML parser |
string | $data | The content of the current tag (1024 byte chunk) |
bool | True |
parse_timestamp | ( | $parser, | |
$data | |||
) |
Add the next chunk of character data to the remote_timestamp string.
mixed | $parser | The XML parser |
string | $data | The content of the current tag (1024 byte chunk) |
bool | True |
parse_wwwroot | ( | $parser, | |
$data | |||
) |
Add the next chunk of character data to the remote_wwwroot string.
mixed | $parser | The XML parser |
string | $data | The content of the current tag (1024 byte chunk) |
bool | True |
start_element | ( | $parser, | |
$name, | |||
$attrs | |||
) |
Set the character-data handler to the right function for each element.
For each tag (element) name, this function switches the character-data handler to the function that handles that element. Note that character data is referred to the handler in blocks of 1024 bytes.
mixed | $parser | The XML parser |
string | $name | The name of the tag, e.g. method_call |
array | $attrs | The tag's attributes (if any exist). |
bool | True |