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