Exemplo n.º 1
0
 /**
  * Describe a service and all its methods
  * @param $data An object containing 'label' and 'data' keys
  */
 public function describeService($data)
 {
     $className = $data['label'];
     //Sanitize path
     //$path = str_replace('..', '', $data['data']);
     $methodTable = MethodTable::create($this->servicePath . ($data['data'] ? DIRECTORY_SEPARATOR . $data['data'] : '') . $className . '.php', NULL, $classComment);
     return array($methodTable, $classComment);
 }
Exemplo n.º 2
0
 /**
  * Describe a service and all its methods
  * @param $data An object containing 'label' and 'data' keys
  */
 function describeService($data)
 {
     $className = $data['label'];
     //Sanitize path
     $path = str_replace('..', '', $data['data']);
     //Generate the method table from this info
     $this->_path = dirname(dirname(realpath(__FILE__))) . DIRECTORY_SEPARATOR;
     $methodTable = MethodTable::create($this->_path . $path . $className . '.php', NULL, $classComment);
     return array($methodTable, $classComment);
 }
Exemplo n.º 3
0
	/**
	 * Returns a mapped object where all commands are documented.
	 */
	public function commands(){
		
		$dir = AMFPHP_ROOTPATH . "services/";
		
		$services = self::listServices($dir);
		$commnads = array();
		
		foreach($services as $bundle){
			
			$methodTable = MethodTable::create($dir . $bundle . '.php', NULL, $classComment);
			
			foreach($methodTable as $name => $command){
				$name = $bundle . "." . $name;
				$commnads[$name] = $command;	
			}
		}
		
		return $commnads;
	}
Exemplo n.º 4
0
/**
 * Parse a file to find out what functions/methods exist in it, and add entries
 * for the remote-call-enabled functions to the database.
 *
 * The path to a file, e.g. auth/mnet/auth.php can be thought of as
 * type/parentname/docname
 *
 * @param  string   $type           mod, auth or enrol
 * @param  string   $parentname     Implementation of type, e.g. 'mnet' in the
 *                                  case of auth/mnet/auth.php
 * @return bool                     True on success, else false
 */
function mnet_get_functions($type, $parentname)
{
    global $CFG;
    $dataobject = new stdClass();
    $docname = $type . '.php';
    $publishes = array();
    if ('mod' == $type) {
        $docname = 'rpclib.php';
        $relname = '/mod/' . $parentname . '/' . $docname;
        $filename = $CFG->dirroot . $relname;
        if (file_exists($filename)) {
            include_once $filename;
        }
        $mnet_publishes = $parentname . '_mnet_publishes';
        if (function_exists($mnet_publishes)) {
            (array) ($publishes = $mnet_publishes());
        }
    } elseif ('local' == $type) {
        $docname = 'rpclib.php';
        $relname = '/local/' . $parentname . '/' . $docname;
        $filename = $CFG->dirroot . $relname;
        if (file_exists($filename)) {
            include_once $filename;
        }
        $mnet_publishes = $parentname . '_mnet_publishes';
        if (function_exists($mnet_publishes)) {
            (array) ($publishes = $mnet_publishes());
        }
    } else {
        // auth or enrol
        $relname = '/' . $type . '/' . $parentname . '/' . $docname;
        $filename = $CFG->dirroot . $relname;
        if (file_exists($filename)) {
            include_once $filename;
        }
        $class = $type . ($type == 'enrol' ? 'ment' : '') . '_plugin_' . $parentname;
        if (class_exists($class)) {
            $object = new $class();
            if (method_exists($object, 'mnet_publishes')) {
                (array) ($publishes = $object->mnet_publishes());
            }
        }
    }
    $methodServiceArray = array();
    foreach ($publishes as $service) {
        if (is_array($service['methods'])) {
            foreach ($service['methods'] as $methodname) {
                $methodServiceArray[$methodname][] = $service;
            }
        }
    }
    // Disable functions that don't exist (any more) in the source
    // Should these be deleted? What about their permissions records?
    $rpcrecords = get_records_select('mnet_rpc', ' parent=\'' . $parentname . '\' AND parent_type=\'' . $type . '\' ', 'function_name ASC ');
    if (!empty($rpcrecords)) {
        foreach ($rpcrecords as $rpc) {
            if (!array_key_exists($rpc->function_name, $methodServiceArray)) {
                $rpc->enabled = 0;
                update_record('mnet_rpc', $rpc);
            }
        }
    }
    if (!file_exists($filename)) {
        return false;
    }
    if (extension_loaded('tokenizer')) {
        include_once "{$CFG->dirroot}/{$CFG->admin}/mnet/MethodTable.php";
        $functions = (array) MethodTable::create($filename, false);
    }
    foreach ($methodServiceArray as $method => $servicearray) {
        if (!empty($functions[$method])) {
            $details = $functions[$method];
            $profile = $details['arguments'];
            if (!isset($details['returns'])) {
                array_unshift($profile, array('type' => 'void', 'description' => 'No return value'));
            } else {
                array_unshift($profile, $details['returns']);
            }
            $dataobject->profile = serialize($profile);
            $dataobject->help = addslashes($details['description']);
        } else {
            $dataobject->profile = serialize(array(array('type' => 'void', 'description' => 'No return value')));
            $dataobject->help = '';
        }
        $dataobject->function_name = $method;
        $dataobject->xmlrpc_path = $type . '/' . $parentname . '/' . $docname . '/' . $method;
        $dataobject->parent_type = $type;
        $dataobject->parent = $parentname;
        $dataobject->enabled = '0';
        if ($record_exists = get_record('mnet_rpc', 'xmlrpc_path', $dataobject->xmlrpc_path)) {
            $dataobject->id = $record_exists->id;
            $dataobject->enabled = $record_exists->enabled;
            update_record('mnet_rpc', $dataobject);
        } else {
            $dataobject->id = insert_record('mnet_rpc', $dataobject, true);
        }
        foreach ($servicearray as $service) {
            $serviceobj = get_record('mnet_service', 'name', $service['name']);
            if (false == $serviceobj) {
                $serviceobj = new stdClass();
                $serviceobj->name = $service['name'];
                $serviceobj->apiversion = $service['apiversion'];
                $serviceobj->offer = 1;
                $serviceobj->id = insert_record('mnet_service', $serviceobj, true);
            }
            if (false == get_record('mnet_service2rpc', 'rpcid', $dataobject->id, 'serviceid', $serviceobj->id)) {
                $obj = new stdClass();
                $obj->rpcid = $dataobject->id;
                $obj->serviceid = $serviceobj->id;
                insert_record('mnet_service2rpc', $obj, true);
            }
        }
    }
    return true;
}
Exemplo n.º 5
0
 /**
  * Prints out the headers and footers of the method testing page and
  * either prints a form (through _printForm) for the user to enter arguments or, if arguments
  * are provided, prints the result of the method (through printResult).
  */
 function testMethod($name)
 {
     if (isset($this->_classConstruct->methodTable[$name]['arguments'])) {
         return $this->_classConstruct->methodTable[$name]['arguments'];
     } else {
         require_once AMFPHP_BASE . 'util/MethodTable.php';
         $mt = MethodTable::create(substr($_GET['class'], strrpos('/' . $_GET['class'], '/')) . '.php');
         return $mt[$name]['arguments'];
     }
 }
Exemplo n.º 6
0
<?php

include_once "config.inc.php";
define("AMFPHP_BASE", $cfg['AmfphpPath'] . 'amf-core/');
include_once AMFPHP_BASE . "util/Compat.php";
error_reporting(E_ALL ^ E_NOTICE);
if (!is_dir($cfg['ServicesPath'])) {
    print "FATAL ERROR - Invalid ServicesPath<BR><BR>See right pane.";
    exit;
}
include_once $cfg['AmfphpPath'] . "/amf-core/util/MethodTable.php";
ob_start();
chdir($cfg['ServicesPath']);
@(include_once $cfg['ServicesPath'] . $_GET['class'] . ".php");
ob_end_clean();
$methodTable = MethodTable::create($cfg['ServicesPath'] . $_GET['class'] . ".php");
$className = substr($_GET['class'], strrpos('/', $_GET['class']));
if ($methodTable === false) {
    exit;
} else {
    if ($_GET['action'] == 'save') {
        $loc = $cfg['ServicesPath'] . $_GET['class'] . '.methodTable.php';
        $bytes = file_put_contents($loc, "<" . "?php \n" . MethodTable::showCode($methodTable) . "\n?" . ">");
        if ($bytes == 0) {
            $feedback = "<p class='error'>Error writing file, are permissions set correctly?</p>";
        } else {
            $feedback = "<p class='feedback'>Write file succesful</p>";
        }
    }
}
?>