PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/zarafa-7.0.8/php-webclient-ajax/zarafa.php

#
PHP | 248 lines | 118 code | 37 blank | 93 comment | 22 complexity | e24fbaab2dd17e503107245718a071a9 MD5 | raw file
  1. <?php
  2. /*
  3. * Copyright 2005 - 2012 Zarafa B.V.
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License, version 3,
  7. * as published by the Free Software Foundation with the following additional
  8. * term according to sec. 7:
  9. *
  10. * According to sec. 7 of the GNU Affero General Public License, version
  11. * 3, the terms of the AGPL are supplemented with the following terms:
  12. *
  13. * "Zarafa" is a registered trademark of Zarafa B.V. The licensing of
  14. * the Program under the AGPL does not imply a trademark license.
  15. * Therefore any rights, title and interest in our trademarks remain
  16. * entirely with us.
  17. *
  18. * However, if you propagate an unmodified version of the Program you are
  19. * allowed to use the term "Zarafa" to indicate that you distribute the
  20. * Program. Furthermore you may use our trademarks where it is necessary
  21. * to indicate the intended purpose of a product or service provided you
  22. * use it in accordance with honest practices in industrial or commercial
  23. * matters. If you want to propagate modified versions of the Program
  24. * under the name "Zarafa" or "Zarafa Server", you may only do so if you
  25. * have a written permission by Zarafa B.V. (to acquire a permission
  26. * please contact Zarafa at trademark@zarafa.com).
  27. *
  28. * The interactive user interface of the software displays an attribution
  29. * notice containing the term "Zarafa" and/or the logo of Zarafa.
  30. * Interactive user interfaces of unmodified and modified versions must
  31. * display Appropriate Legal Notices according to sec. 5 of the GNU
  32. * Affero General Public License, version 3, when you propagate
  33. * unmodified or modified versions of the Program. In accordance with
  34. * sec. 7 b) of the GNU Affero General Public License, version 3, these
  35. * Appropriate Legal Notices must retain the logo of Zarafa or display
  36. * the words "Initial Development by Zarafa" if the display of the logo
  37. * is not reasonably feasible for technical reasons. The use of the logo
  38. * of Zarafa in Legal Notices is allowed for unmodified and modified
  39. * versions of the software.
  40. *
  41. * This program is distributed in the hope that it will be useful,
  42. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  43. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  44. * GNU Affero General Public License for more details.
  45. *
  46. * You should have received a copy of the GNU Affero General Public License
  47. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  48. *
  49. */
  50. ?>
  51. <?php
  52. /**
  53. * This file is the dispatcher of the whole application, every request for data enters
  54. * here. XML is received and send to the client.
  55. */
  56. // Include files
  57. include("config.php");
  58. include("defaults.php");
  59. include("server/util.php");
  60. require("server/PEAR/JSON.php");
  61. require("mapi/mapi.util.php");
  62. require("mapi/mapicode.php");
  63. require("mapi/mapidefs.php");
  64. require("mapi/mapitags.php");
  65. require("mapi/mapiguid.php");
  66. require("server/core/class.conversion.php");
  67. require("server/core/class.mapisession.php");
  68. include("server/core/constants.php");
  69. include("server/core/class.state.php");
  70. include("server/core/class.request.php");
  71. include("server/modules/class.module.php");
  72. include("server/modules/class.listmodule.php");
  73. include("server/modules/class.itemmodule.php");
  74. include("server/core/class.operations.php");
  75. include("server/core/class.properties.php");
  76. include("server/core/class.tablecolumns.php");
  77. include("server/core/class.bus.php");
  78. include("server/core/class.settings.php");
  79. include("server/core/class.language.php");
  80. include("server/core/class.pluginmanager.php");
  81. include("server/core/class.plugin.php");
  82. ob_start();
  83. setlocale(LC_CTYPE, "en_US.UTF-8");
  84. // Set timezone
  85. if(function_exists("date_default_timezone_set")) {
  86. if(defined('TIMEZONE') && TIMEZONE) {
  87. date_default_timezone_set(TIMEZONE);
  88. } else if(!ini_get('date.timezone')) {
  89. date_default_timezone_set('Europe/London');
  90. }
  91. }
  92. // Get the available modules
  93. $GLOBALS["availableModules"] = getAvailableModules();
  94. // Callback function for unserialize
  95. // Module objects of the previous request are stored in the session. With this
  96. // function they are restored to PHP objects.
  97. ini_set("unserialize_callback_func", "sessionModuleLoader");
  98. // Start session
  99. session_name(COOKIE_NAME);
  100. session_start();
  101. // Create global mapi object. This object is used in many other files
  102. $GLOBALS["mapisession"] = new MAPISession();
  103. // Logon, the username and password are set in the "index.php" file. So whenever
  104. // an user enters this file, the username and password whould be set in the $_SESSION
  105. // variable
  106. if (isset($_SESSION["username"]) && isset($_SESSION["password"])) {
  107. $sslcert_file = defined('SSLCERT_FILE') ? SSLCERT_FILE : null;
  108. $sslcert_pass = defined('SSLCERT_PASS') ? SSLCERT_PASS : null;
  109. $hresult = $GLOBALS["mapisession"]->logon($_SESSION["username"], $_SESSION["password"], DEFAULT_SERVER, $sslcert_file, $sslcert_pass);
  110. }else{
  111. $hresult = MAPI_E_UNCONFIGURED;
  112. }
  113. if(isset($_SESSION["lang"])) {
  114. $session_lang = $_SESSION["lang"];
  115. }else{
  116. $session_lang = LANG;
  117. }
  118. // Close the session now, so we're not blocking other clients
  119. session_write_close();
  120. // Set headers for XML
  121. header("Content-Type: text/xml; charset=utf-8");
  122. header("Expires: ".gmdate( "D, d M Y H:i:s")."GMT");
  123. header("Last-Modified: ".gmdate( "D, d M Y H:i:s")."GMT");
  124. header("Cache-Control: no-cache, must-revalidate");
  125. header("Pragma: no-cache");
  126. header("X-Zarafa: ".phpversion("mapi").(defined("SVN") ? "-".SVN:""));
  127. // Check is the user is authenticated
  128. if ($GLOBALS["mapisession"]->isLoggedOn()) {
  129. // Authenticated
  130. // Execute request
  131. // Instantiate Plugin Manager
  132. $GLOBALS['PluginManager'] = new PluginManager();
  133. $GLOBALS['PluginManager']->detectPlugins();
  134. $GLOBALS['PluginManager']->initPlugins();
  135. // Get the available plugin modules
  136. $GLOBALS["availablePluginModules"] = $GLOBALS['PluginManager']->getAvailablePluginModules();
  137. // Create global operations object
  138. $GLOBALS["operations"] = new Operations();
  139. // Create global properties object
  140. $GLOBALS["properties"] = new Properties();
  141. // Create global tablecolumns object
  142. $GLOBALS["TableColumns"] = new TableColumns();
  143. // Create global settings object
  144. $GLOBALS["settings"] = new Settings();
  145. // Create global language object
  146. $GLOBALS["language"] = new Language();
  147. // Set the correct language
  148. $GLOBALS["language"]->setLanguage($session_lang);
  149. // Get the state information for this subsystem
  150. if(isset($_GET["subsystem"]))
  151. $subsystem = $_GET["subsystem"];
  152. else
  153. $subsystem = "anonymous"; // Currently should never happen
  154. $state = new State($subsystem);
  155. // Lock the state of this subsystem
  156. $state->open();
  157. // Get the bus object for this subsystem
  158. $bus = $state->read("bus");
  159. if(!$bus)
  160. // Create global bus object
  161. $bus = new Bus();
  162. // Make bus global
  163. $GLOBALS["bus"] = $bus;
  164. // Reset any spurious information in the bus state
  165. $GLOBALS["bus"]->reset();
  166. // Create new request object
  167. $request = new Request();
  168. // Get the XML from the client
  169. $xml = readXML();
  170. if (function_exists("dump_xml")) dump_xml($xml,"in"); // debugging
  171. // Get Attachment data from state and put it into the $_SESSION
  172. $attachment_state = new State('attachments');
  173. $attachment_state->open();
  174. $_SESSION['files'] = $attachment_state->read("files");
  175. $_SESSION['deleteattachment'] = $attachment_state->read("deleteattachment");
  176. $checksum = md5(serialize($_SESSION['files']) . serialize($_SESSION['deleteattachment']));
  177. $attachment_state->close();
  178. // Execute the request
  179. $xml = $request->execute($xml);
  180. // Get Attachment data from $_SESSION and put it into the state, but only if something has changed
  181. if(md5(serialize($_SESSION['files']) . serialize($_SESSION['deleteattachment'])) != $checksum) {
  182. $attachment_state = new State('attachments');
  183. $attachment_state->open();
  184. $attachment_state->write("files", $_SESSION['files']);
  185. $attachment_state->write("deleteattachment", $_SESSION['deleteattachment']);
  186. $attachment_state->close();
  187. }
  188. // Prevent the SESSION data to be stored elsewhere
  189. unset($_SESSION['files'], $_SESSION['deleteattachment']);
  190. if (function_exists("dump_xml")) dump_xml($xml,"out"); // debugging
  191. // Check if we can use gzip compression
  192. if ((!defined("DEBUG_GZIP")||DEBUG_GZIP) && $GLOBALS["settings"]->get("global/use_gzip","true")=="true" && function_exists("gzencode") && isset($_SERVER["HTTP_ACCEPT_ENCODING"]) && strpos($_SERVER["HTTP_ACCEPT_ENCODING"], "gzip")!==false){
  193. // Set the correct header and compress the XML
  194. header("Content-Encoding: gzip");
  195. echo gzencode($xml);
  196. }else {
  197. echo $xml;
  198. }
  199. // Reset the BUS before saving to state information
  200. $GLOBALS["bus"]->reset();
  201. if(isset($GLOBALS["bus"]))
  202. $state->write("bus", $GLOBALS["bus"]);
  203. // You can skip this as well because the lock is freed after the PHP script ends
  204. // anyway.
  205. $state->close();
  206. } else {
  207. echo "<zarafa>\n";
  208. echo "\t<error logon=\"false\" mapi=\"".get_mapi_error_name($hresult)."\">Logon failed</error>\n";
  209. echo "</zarafa>";
  210. }
  211. ?>