squirrelmail_rpc.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <?php
  2. /**
  3. * squirrelmail_rpc.php
  4. *
  5. * This file contains the entry point to the "SquirrelMail API" -- the
  6. * remote procedure call request receiver.
  7. *
  8. * @copyright &copy; 1999-2007 The SquirrelMail Project Team
  9. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  10. * @version $Id$
  11. * @package squirrelmail
  12. * @since 1.5.2
  13. *
  14. */
  15. /** This is the squirrelmail_rpc page */
  16. define('PAGE_NAME', 'squirrelmail_rpc');
  17. //FIXME: If we decide to route ALL requests, even normal page
  18. // requests through this file, need to change page requests
  19. // to something like this
  20. //http://example.org/squirrelmail/src/squirrelmail_rpc.php?page=read_body&passed_id=47633...
  21. // This file would then add ".php" to the "page" variable
  22. // and pass the request on to that page by simply require()ing
  23. // that page and exiting.
  24. // Does this present problems, security or otherwise? What
  25. // problems are created by the fact that the page request
  26. // is always the same thing (some parts of the code and some
  27. // plugins switch functionality based on $PHP_SELF and other
  28. // $_SERVER variables that look for specific page names -- those
  29. // can be fixed by looking at the "page" GET argument, but what
  30. // other issues are created)? What about plugins? How would
  31. // they work in this scheme? Would they be a lot more difficult
  32. // to develop?
  33. //NOTE: It is not entirely clear if doing the above is even desirable.
  34. // Initial conversations on the squirrelmail-devel list were
  35. // inconclusive. On one hand, doing so would give us one master
  36. // file that handles any and all incoming requests, no matter
  37. // where they came from or what format/type they are. On the
  38. // other, keeping page requests out of this file keeps this file
  39. // lean and specific to one technology: our RPC interface.
  40. /**
  41. * Include the SquirrelMail initialization file.
  42. */
  43. //FIXME: init.php assumes it is being called by a browser, so some error
  44. // conditions are handled by immediately calling error_box() or
  45. // otherwise trying to push something to the browser, which should
  46. // be avoided at all costs. This is also pervasive in the whole
  47. // core and must be cleaned up entirely before this can be a very
  48. // functional RPC interface
  49. require('../include/init.php');
  50. /**
  51. * Get RPC Action (can be in either GET or POST)
  52. *
  53. */
  54. if (!sqGetGlobalVar('rpc_action', $rpc_action, SQ_FORM)) {
  55. //FIXME: establish error codes (using 99 in the interim)
  56. sm_rpc_return_error(99, _("No RPC action given"));
  57. }
  58. /**
  59. * No matter what our response is, the headers
  60. * will not change.
  61. *
  62. */
  63. $oTemplate->header('Content-Type: text/xml');
  64. $oTemplate->header('Content-Type: application/xml'); // required by IE
  65. //FIXME: which anti-cache headers do we want to use?
  66. $oTemplate->header('Cache-Control: no-cache');
  67. // $oTemplate->header("Expires: Sat, 1 Jan 2000 00:00:00 GMT");
  68. // $oTemplate->header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
  69. // $oTemplate->header("Cache-Control: no-cache, must-revalidate");
  70. // $oTemplate->header("Pragma: no-cache");
  71. /**
  72. * Allow plugins to add their own RPC action
  73. * or modify behavior of SM core RPC actions...
  74. *
  75. * A plugin that handles a custom RPC action must
  76. * return TRUE to the hook so that it knows that
  77. * the action was handled and was not an unknown
  78. * action. If the action was not handled, the plugin
  79. * should return FALSE to the hook.
  80. *
  81. * Developer note: the $rpc_action parameter is passed
  82. * in an array in case we can think of more parameters
  83. * to add in the future.
  84. *
  85. */
  86. $temp = array(&$rpc_action);
  87. $handled_by_plugin = boolean_hook_function('squirrelmail_rpc', $temp, 1);
  88. /**
  89. * Go take care of each RPC action (unless plugin already did)
  90. *
  91. */
  92. if (!$handled_by_plugin) switch (strtolower($rpc_action)) {
  93. /**
  94. * Delete Messages
  95. *
  96. */
  97. case 'delete_messages':
  98. require_once(SM_PATH . 'functions/mailbox_display.php');
  99. require_once(SM_PATH . 'functions/imap.php');
  100. if (!sqGetGlobalVar('delete_ids', $delete_ids, SQ_FORM)) {
  101. sm_rpc_return_error(99, _("No deletion ID given"));
  102. }
  103. $delete_ids = explode(',', $delete_ids);
  104. if (!sqGetGlobalVar('mailbox', $mailbox, SQ_FORM)) {
  105. sm_rpc_return_error(99, _("No mailbox given"));
  106. }
  107. if (sqGetGlobalVar('startMessage', $startMessage, SQ_INORDER, 1)) {
  108. $startMessage = (int) $startMessage;
  109. }
  110. sqGetGlobalVar('what', $what, SQ_FORM, 0);
  111. if (sqGetGlobalVar('account', $iAccount, SQ_GET, 0)) {
  112. $iAccount = (int) $iAccount;
  113. }
  114. //FIXME: need to grab the bypass trash variable here too! probably other vars...
  115. /* FIXME: --- The following code was just experimental/proof-of-concept; the rest
  116. of the implementation of this functionality still needs to be done "for real"
  117. $oImapMessage = new IMAP_Message(0, $mailbox, $startMessage, $what, $iAccount);
  118. foreach ($delete_ids as $id) {
  119. $oImapMessage->setUid($id);
  120. //FIXME: establish constants for $hide values (the 3 below indicates not to show errors, but to return any error string)
  121. $result = $oImapMessage->deleteMessage(3);
  122. if ($result !== TRUE) {
  123. sm_rpc_return_error(99, $result);
  124. }
  125. }
  126. --- */
  127. sm_rpc_return_success();
  128. //FIXME: Just for testing the line above can be changed to something like this:
  129. //sm_rpc_return_success(0, 'Hooray! Message(s) deleted. Refresh your message list and make sure.');
  130. break;
  131. /**
  132. * Default: error out
  133. *
  134. */
  135. default:
  136. sm_rpc_return_error(99, _("RPC action not understood"));
  137. break;
  138. }
  139. /**
  140. * Returns an error message to the RPC caller and exits
  141. *
  142. * NOTE that this function exits and will never return
  143. *
  144. * @param int $error_code The error code for the current error condition
  145. * @param string $error_text Any error message associated with the error
  146. * condition (OPTIONAL; default empty string)
  147. *
  148. */
  149. function sm_rpc_return_error($error_code, $error_text='') {
  150. global $oTemplate;
  151. $oTemplate->assign('error_code', $error_code);
  152. $oTemplate->assign('error_text', $error_text);
  153. $oTemplate->display('rpc_response_error.tpl');
  154. exit;
  155. }
  156. /**
  157. * Returns a standard success result to the RPC caller and exits
  158. *
  159. * NOTE that this function exits and will never return
  160. *
  161. * @param int $result_code The result code (OPTIONAL; default 0)
  162. * @param string $result_text Any result message (OPTIONAL; default
  163. * empty string)
  164. *
  165. */
  166. function sm_rpc_return_success($result_code=0, $result_text='') {
  167. global $oTemplate;
  168. $oTemplate->assign('result_code', $result_code);
  169. $oTemplate->assign('result_text', $result_text);
  170. $oTemplate->display('rpc_response_success.tpl');
  171. exit;
  172. }