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