forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestclient.php
144 lines (122 loc) · 5.92 KB
/
testclient.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php // $Id$
/**
* A service browser for remote Moodles
*
* This script 'remotely' executes the reflection methods on a remote Moodle,
* and publishes the details of the available services
*
* @author Donal McMullan [email protected]
* @version 0.0.1
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package mnet
*/
require_once(dirname(dirname(__FILE__)) . '/config.php');
require_once $CFG->dirroot.'/mnet/xmlrpc/client.php';
if ($CFG->mnet_dispatcher_mode === 'off') {
print_error('mnetdisabled', 'mnet');
}
// Site admins only, thanks.
require_login();
$context = get_context_instance(CONTEXT_SYSTEM);
require_capability('moodle/site:config', $context);
error_reporting(E_ALL);
// Some HTML sugar
echo '<?xml version="1.0" encoding="utf-8"?>';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head><title>Moodle MNET Test Client</title></head><body>
<H1>Hosts</H1>
<?php
$hosts = $DB->get_records('mnet_host');
foreach ($hosts as $id => $host) {
// Skip the 'all hosts' option
if(empty($host->wwwroot)) continue;
// Skip localhost
if($host->wwwroot == $CFG->wwwroot) continue;
// Skip non-moodle non-mahara hosts
if($host->applicationid != 1 && $host->applicationid != 2) continue; //TODO: get rid of magic numbers.
echo '<p><a href="testclient.php?hostid='.$host->id.'">'.$host->wwwroot."</a></p>\n";
}
if (!empty($_GET['hostid']) && array_key_exists($_GET['hostid'], $hosts)) {
$host = $hosts[$_GET['hostid']];
$mnet_peer = new mnet_peer();
$mnet_peer->set_wwwroot($host->wwwroot);
$mnet_request = new mnet_xmlrpc_client();
// Tell it the path to the method that we want to execute
$mnet_request->set_method('system/listServices');
$mnet_request->send($mnet_peer);
$services = $mnet_request->response;
$yesno = array('No', 'Yes');
$servicenames = array();
echo '<hr /><br /><h3>Services available on host: '.$host->wwwroot .'</h3><table><tr valign="top"><th> Service ID </th><th> Service </th><th> Version </th><th> They Publish </th><th> They Subscribe </th><th></th></tr>';
foreach ($services as $id => $service) {
$sql = 'select c.id, c.parent_type, c.parent from {mnet_service2rpc} a, {mnet_service} b, {mnet_rpc} c where a.serviceid = b.id and b.name=? and c.id = a.rpcid ';
echo '<tr valign="top">
<td>'.$service['name'].'</td>';
if ($detail = $DB->get_record_sql($sql, array($service['name']))) {
$service['humanname'] = get_string($service['name'].'_name', $detail->parent_type.'_'.$detail->parent);
echo '<td>'.$service['humanname'].'</td>';
} else {
$service['humanname'] = $service['name'];
echo '<td> unknown </td>';
}
echo '
<td>'.$service['apiversion'].'</td>
<td>'.$yesno[$service['publish']].'</td>
<td>'.$yesno[$service['subscribe']].'</td>
<td><a href="testclient.php?hostid='.$host->id.'&service='.$service['name'].'">List methods</a></td>
</tr>'."\n";
$servicenames[$service['name']] = $service;
}
echo '</table>';
if (isset($_GET['service']) && array_key_exists($_GET['service'], $servicenames)) {
$service = $servicenames[$_GET['service']];
// Tell it the path to the method that we want to execute
$mnet_request->set_method('system/listMethods');
$mnet_request->add_param($service['name'], 'string');
$mnet_request->send($mnet_peer);
$methods = $mnet_request->response;
echo '<hr /><br /><h3>Methods in the '.$service['humanname'] .' service</h3><table><th>Method</th><th colspan="2">Options</th>';
foreach ($methods as $id => $method) {
echo '<tr><td>'.$method.'</td><td> <a href="testclient.php?hostid='.$host->id.'&service='.$service['name'].'&method='.$id.'&show=sig">Inspect</a></td></tr>'."\n";
}
echo '</table>';
} else {
// Tell it the path to the method that we want to execute
$mnet_request->set_method('system/listMethods');
$mnet_request->send($mnet_peer);
$methods = $mnet_request->response;
echo '<hr /><br /><h3>Methods '.$host->wwwroot .'</h3><table><th>Method</th><th colspan="2">Options</th>';
foreach ($methods as $id => $method) {
echo '<tr><td>'.$method.'</td><td> <a href="testclient.php?hostid='.$host->id.'&method='.$id.'&show=sig">Inspect</a></td></tr>'."\n";
}
echo '</table>';
}
if (isset($_GET['method']) && array_key_exists($_GET['method'], $methods)) {
$method = $methods[$_GET['method']];
$mnet_request = new mnet_xmlrpc_client();
// Tell it the path to the method that we want to execute
$mnet_request->set_method('system/methodSignature');
$mnet_request->add_param($method, 'string');
$mnet_request->send($mnet_peer);
$signature = $mnet_request->response;
echo '<hr /><br /><h3>Method signature for '.$method.':</h3><table border="1"><th>Position</th><th>Type</th><th>Description</th>';
$params = array_pop($signature);
foreach ($params as $pos => $details) {
echo '<tr><td>'.$pos.'</td><td>'.$details['type'].'</td><td>'.$details['description'].'</td></tr>';
}
echo '</table>';
// Tell it the path to the method that we want to execute
$mnet_request->set_method('system/methodHelp');
$mnet_request->add_param($method, 'string');
$mnet_request->send($mnet_peer);
$help = $mnet_request->response;
echo '<hr /><br /><h3>Help details from docblock for '.$method.':</h3>';
echo(str_replace('\n', '<br />',$help));
echo '</pre>';
}
}
?>
</body>
</html>