Ejemplo n.º 1
0
 public function rpc($cdata)
 {
     $classes = $this->_api->getClasses();
     D::v($this->_api);
     try {
         if (!isset($classes[$cdata->action])) {
             $good = FALSE;
             foreach ($classes as $classCheck => $cconfCheck) {
                 if (is_array($cconfCheck) && $cconfCheck['serverName'] == $cdata->action) {
                     $class = $classCheck;
                     $good = TRUE;
                 }
             }
             if (!$good) {
                 throw new Exception('Call to undefined class: ' . $cdata->action);
             }
         } else {
             $class = $cdata->action;
         }
         $method = $cdata->method;
         $cconf = $classes[$class];
         $mconf = null;
         $classPath = isset($cconf['fullPath']) ? $cconf['fullPath'] : $this->_api->getClassPath($class, $cconf);
         require_once $class . '.inc';
         $parsedAPI = $this->_api->getParsedAPI();
         if (!empty($parsedAPI) && isset($parsedAPI['actions'][$class])) {
             foreach ($parsedAPI['actions'][$class] as $m) {
                 if ($m['name'] === $method) {
                     $mconf = $m;
                     $serverMethod = isset($m['serverMethod']) ? $m['serverMethod'] : $method;
                 }
             }
         } else {
             // do some very simple reflection on the class to check if the method is allowed
             $rClass = new ReflectionClass($cconf['prefix'] . $class);
             if (!$rClass->hasMethod($method)) {
                 $rMethods = $rClass->getMethods();
                 foreach ($rMethods as $rMethod) {
                     $doc = $rMethod->getDocComment();
                     if ($rMethod->isPublic() && strlen($doc) > 0 && !!preg_match('/' . $this->_remoteAttribute . '/', $doc) && !!preg_match('/' . $this->_nameAttribute . ' ([w]+)/', $doc, $matches) && $method === $matches[1]) {
                         $serverMethod = $rMethod->getName();
                         $mconf = array('name' => $method, 'len' => $rMethod->getNumberOfRequiredParameters());
                         if (!!preg_match('/' . $this->_api->getFormAttribute() . '/', $doc)) {
                             $mconf['formHandler'] = true;
                         }
                     }
                 }
                 if (!$serverMethod) {
                     throw new Exception("Call to undefined method: {$method} on class {$class}");
                 }
             } else {
                 $rMethod = $rClass->getMethod($method);
                 $doc = $rMethod->getDocComment();
                 if ($rMethod->isPublic() && strlen($doc) > 0) {
                     if (!!preg_match('/' . $this->_api->getRemoteAttribute() . '/', $doc)) {
                         $serverMethod = $method;
                         $mconf = array('name' => $method, 'len' => $rMethod->getNumberOfRequiredParameters());
                         if (!!preg_match('/' . $this->_api->getFormAttribute() . '/', $doc)) {
                             $mconf['formHandler'] = true;
                         }
                     }
                 }
             }
         }
         if (!isset($mconf)) {
             throw new Exception("Call to undefined or unallowed method: {$method} on class {$class}");
         }
         if ($this->isForm && (!isset($mconf['formHandler']) || $mconf['formHandler'] !== true)) {
             throw new Exception("Called method {$method} on class {$class} is not a form handler");
         }
         $params = isset($cdata->data) && is_array($cdata->data) ? $cdata->data : array();
         if (count($params) < $mconf['len']) {
             throw new Exception("Not enough required params specified for method: {$method} on class {$class}");
         }
         if ($cconf['serverName']) {
             $action = $cconf['serverName'];
         } else {
             $action = $class;
         }
         $response = array('type' => 'rpc', 'tid' => $cdata->tid, 'action' => $action, 'method' => $method);
         $className = $cconf['prefix'] . $class;
         $instance = new $className();
         $response['result'] = call_user_func_array(array($instance, $serverMethod), $params);
     } catch (Exception $e) {
         $response = array('type' => 'exception', 'tid' => $cdata->tid, 'message' => $e->getMessage(), 'where' => $e->getTraceAsString());
     }
     return $response;
 }
Ejemplo n.º 2
0
$configFile = 'common/config.inc';
include_once "./alib/alib.inc";
global $debug, $config;
addIncludePath('./alib');
addIncludePath('./common');
addIncludePath('./php', TRUE);
include_once '../alib/iuser.inc';
include_once './common/functions.inc';
include_once './common/login.inc';
include_once './common/smartObjectDefs.inc';
// Connect to the db:
if (!is_object($db)) {
    $db = new idb($config->mainDB);
}
D::log('db');
D::v($db);
$login = new $config->loginModule();
if ($login->loggedIn || $config->allowNonLoggedIn) {
    global $user, $broker;
    $broker = new broker();
} elseif (stristr($_SERVER['REQUEST_URI'], 'api')) {
    $api = new publicAPI();
} else {
    $template = new template($config->loginTemplate);
    $template->set('title', $config->defaultTitle);
    $template->set('appName', $config->appName);
    $template->set('extLocation', $config->extLocation);
    $template->set('self', $config->self);
    if ($login->error && $login->error != 'Not logged in and not trying to log in.') {
        $template->set('badLogin', TRUE);
        $template->set('loginError', $login->error);