[5595] | 1 | <?php |
---|
| 2 | include_once("http_request.class.php"); |
---|
| 3 | |
---|
| 4 | $public_functions = array( |
---|
| 5 | "Expresso.login", |
---|
| 6 | "Expresso.logout", |
---|
| 7 | "Mail.getUserFolders", |
---|
| 8 | "Mail.getUserMessages" |
---|
| 9 | ); |
---|
| 10 | |
---|
| 11 | $GLOBALS['phpgw_info'] = array( |
---|
| 12 | 'flags' => array( |
---|
| 13 | 'currentapp' => 'login', |
---|
| 14 | 'noheader' => True, |
---|
| 15 | 'disable_Template_class' => True, |
---|
| 16 | 'public_functions' => $public_functions |
---|
| 17 | ) |
---|
| 18 | ); |
---|
| 19 | |
---|
| 20 | include_once('../header.inc.php'); |
---|
| 21 | |
---|
| 22 | // NO COOKIES!!!! |
---|
| 23 | unset($_COOKIE); |
---|
| 24 | switch ($_SERVER['REQUEST_METHOD']) { |
---|
| 25 | case 'GET': |
---|
| 26 | case 'POST': |
---|
| 27 | execute($_REQUEST); |
---|
| 28 | break; |
---|
| 29 | |
---|
| 30 | default: |
---|
| 31 | exit(); |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | function execute($request){ |
---|
| 35 | if(empty($request)) { |
---|
| 36 | $request = array(); |
---|
| 37 | $http_request = new http_request(); |
---|
| 38 | $content_type = $http_request->header('Content-Type'); |
---|
| 39 | $accept = $http_request->header('Accept'); |
---|
| 40 | $content = $http_request->body(); |
---|
| 41 | |
---|
| 42 | if (($content_type == 'application/x-www-form-urlencoded') |
---|
| 43 | && ($accept == 'application/json') && $content != null) { |
---|
| 44 | |
---|
| 45 | $req_obj = json_decode($content); |
---|
| 46 | $request['params'] = (array)$req_obj->params; |
---|
| 47 | $request['method'] = $req_obj->method; |
---|
| 48 | $request ['format'] = "json-rpc"; |
---|
| 49 | $request['id'] = $req_obj->id; |
---|
| 50 | } |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | list($params, $method, $format, $id) = array_values($request); |
---|
| 54 | |
---|
| 55 | if(verifyMethod($method)){ |
---|
| 56 | $method = explode(".", $method); |
---|
| 57 | include_once("./".$format."/".$method[0].".php"); |
---|
| 58 | $obj = new $method[0]($id); |
---|
| 59 | $response = $obj->$method[1]($params); |
---|
| 60 | } |
---|
| 61 | else{ |
---|
| 62 | $response = array( |
---|
| 63 | 'result' => null, |
---|
| 64 | 'error' => "Available Resources: ". implode(", ", $GLOBALS['phpgw_info']['flags']['public_functions']), |
---|
| 65 | 'id' => $id |
---|
| 66 | ); |
---|
| 67 | } |
---|
| 68 | dispatch($response, $format); |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | function verifyMethod($method) { |
---|
| 72 | if(array_search( $method, $GLOBALS['phpgw_info']['flags']['public_functions']) !== FALSE){ |
---|
| 73 | return true; |
---|
| 74 | } |
---|
| 75 | else { |
---|
| 76 | return false; |
---|
| 77 | } |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | function dispatch($response, $format){ |
---|
| 81 | $e_response = false; |
---|
| 82 | switch($format){ |
---|
| 83 | case 'json-rpc': |
---|
| 84 | $e_response = @json_encode($response); |
---|
| 85 | break; |
---|
| 86 | case 'xml-rpc': |
---|
| 87 | $e_response = @xmlrpc_encode($response); |
---|
| 88 | break; |
---|
| 89 | default: |
---|
| 90 | $e_response = false; |
---|
| 91 | break; |
---|
| 92 | } |
---|
| 93 | echo $e_response; |
---|
| 94 | } |
---|