PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/worktable/cf_ajaxplorer_content.php

https://github.com/umbecr/camilaframework
PHP | 228 lines | 159 code | 13 blank | 56 comment | 63 complexity | 3297769d83f9a11184d70fd60781b20e MD5 | raw file
  1. <?php
  2. /* This File is part of Camila PHP Framework
  3. Copyright (C) 2006-2010 Umberto Bresciani
  4. Camila PHP Framework is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. Camila PHP Framework is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with Camila PHP Framework; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
  15. require('../camila/header.php');
  16. /**
  17. * Copyright 2007-2009 Charles du Jeu
  18. * This file is part of AjaXplorer.
  19. * The latest code can be found at http://www.ajaxplorer.info/
  20. *
  21. * This program is published under the LGPL Gnu Lesser General Public License.
  22. * You should have received a copy of the license along with AjaXplorer.
  23. *
  24. * The main conditions are as follow :
  25. * You must conspicuously and appropriately publish on each copy distributed
  26. * an appropriate copyright notice and disclaimer of warranty and keep intact
  27. * all the notices that refer to this License and to the absence of any warranty;
  28. * and give any other recipients of the Program a copy of the GNU Lesser General
  29. * Public License along with the Program.
  30. *
  31. * If you modify your copy or copies of the library or any portion of it, you may
  32. * distribute the resulting library provided you do so under the GNU Lesser
  33. * General Public License. However, programs that link to the library may be
  34. * licensed under terms of your choice, so long as the library itself can be changed.
  35. * Any translation of the GNU Lesser General Public License must be accompanied by the
  36. * GNU Lesser General Public License.
  37. *
  38. * If you copy or distribute the program, you must accompany it with the complete
  39. * corresponding machine-readable source code or with a written offer, valid for at
  40. * least three years, to furnish the complete corresponding machine-readable source code.
  41. *
  42. * Any of the above conditions can be waived if you get permission from the copyright holder.
  43. * AjaXplorer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  44. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  45. *
  46. * Description : main script called by any Ajax query. Will dispatch the actions on the plugins.
  47. */
  48. include_once(CAMILA_VAR_ROOTDIR . "/ajaxplorer/conf/base.conf.php");
  49. require_once(CAMILA_LIB_DIR . "ajaxplorer/server/classes/class.AJXP_Utils.php");
  50. require_once(CAMILA_LIB_DIR . "ajaxplorer/server/classes/class.SystemTextEncoding.php");
  51. require_once(CAMILA_LIB_DIR . "ajaxplorer/server/classes/class.Repository.php");
  52. require_once(CAMILA_LIB_DIR . "ajaxplorer/server/classes/class.AJXP_Exception.php");
  53. require_once(CAMILA_LIB_DIR . "ajaxplorer/server/classes/class.AJXP_Plugin.php");
  54. require_once(CAMILA_LIB_DIR . "ajaxplorer/server/classes/class.AJXP_PluginsService.php");
  55. require_once(CAMILA_LIB_DIR . "ajaxplorer/server/classes/class.AbstractAccessDriver.php");
  56. require_once(CAMILA_LIB_DIR . "ajaxplorer/server/classes/class.ConfService.php");
  57. require_once(CAMILA_LIB_DIR . "ajaxplorer/server/classes/class.AuthService.php");
  58. require_once(CAMILA_LIB_DIR . "ajaxplorer/server/classes/class.UserSelection.php");
  59. require_once(CAMILA_LIB_DIR . "ajaxplorer/server/classes/class.HTMLWriter.php");
  60. require_once(CAMILA_LIB_DIR . "ajaxplorer/server/classes/class.AJXP_XMLWriter.php");
  61. require_once(CAMILA_LIB_DIR . "ajaxplorer/server/classes/class.RecycleBinManager.php");
  62. if(isSet($_GET["ajxp_sessid"]))
  63. {
  64. // Don't overwrite cookie
  65. if (!isSet($_COOKIE["AjaXplorer"]))
  66. $_COOKIE["AjaXplorer"] = $_GET["ajxp_sessid"];
  67. }
  68. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  69. header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
  70. header("Cache-Control: no-cache, must-revalidate");
  71. header("Pragma: no-cache");
  72. require_once(CAMILA_LIB_DIR . "ajaxplorer/server/classes/class.AJXP_Logger.php");
  73. set_error_handler(array("AJXP_XMLWriter", "catchError"), E_ALL & ~E_NOTICE );
  74. set_exception_handler(array("AJXP_XMLWriter", "catchException"));
  75. $pServ = AJXP_PluginsService::getInstance();
  76. $pServ->loadPluginsRegistry(INSTALL_PATH."/plugins", CAMILA_VAR_ROOTDIR . "/ajaxplorer/conf");
  77. ConfService::init(CAMILA_VAR_ROOTDIR . "/ajaxplorer/conf/conf.php");
  78. $confStorageDriver = ConfService::getConfStorageImpl();
  79. require_once($confStorageDriver->getUserClassFileName());
  80. session_name("AjaXplorer");
  81. session_start();
  82. if(isSet($_GET["tmp_repository_id"])){
  83. ConfService::switchRootDir($_GET["tmp_repository_id"], true);
  84. }
  85. if(AuthService::usersEnabled())
  86. {
  87. $rememberLogin = "";
  88. $rememberPass = "";
  89. if(isset($_GET["get_action"]) && $_GET["get_action"] == "get_seed"){
  90. HTMLWriter::charsetHeader("text/plain");
  91. print AuthService::generateSeed();
  92. exit(0);
  93. }
  94. if(isSet($_GET["get_action"]) && $_GET["get_action"] == "logout")
  95. {
  96. AuthService::disconnect();
  97. $loggingResult = 2;
  98. }
  99. if(isSet($_GET["get_action"]) && $_GET["get_action"] == "back")
  100. {
  101. AJXP_XMLWriter::header("url");
  102. echo AuthService::getLogoutAddress(false);
  103. AJXP_XMLWriter::close("url");
  104. exit(1);
  105. }
  106. if(isSet($_GET["get_action"]) && $_GET["get_action"] == "login")
  107. {
  108. $userId = (isSet($_GET["userid"])?$_GET["userid"]:null);
  109. $userPass = (isSet($_GET["password"])?$_GET["password"]:null);
  110. $rememberMe = ((isSet($_GET["remember_me"]) && $_GET["remember_me"] == "on")?true:false);
  111. $cookieLogin = (isSet($_GET["cookie_login"])?true:false);
  112. $loggingResult = AuthService::logUser($userId, $userPass, false, $cookieLogin, $_GET["login_seed"]);
  113. if($rememberMe && $loggingResult == 1){
  114. $rememberLogin = $userId;
  115. $loggedUser = AuthService::getLoggedUser();
  116. $rememberPass = $loggedUser->getCookieString();
  117. }
  118. }
  119. else
  120. {
  121. AuthService::logUser(null, null);
  122. }
  123. // Check that current user can access current repository, try to switch otherwise.
  124. $loggedUser = AuthService::getLoggedUser();
  125. if($loggedUser != null)
  126. {
  127. if(isSet($_SESSION["PENDING_REPOSITORY_ID"]) && isSet($_SESSION["PENDING_FOLDER"])){
  128. $loggedUser->setArrayPref("history", "last_repository", $_SESSION["PENDING_REPOSITORY_ID"]);
  129. $loggedUser->setArrayPref("history", $_SESSION["PENDING_REPOSITORY_ID"], $_SESSION["PENDING_FOLDER"]);
  130. $loggedUser->save();
  131. unset($_SESSION["PENDING_REPOSITORY_ID"]);
  132. unset($_SESSION["PENDING_FOLDER"]);
  133. }
  134. $currentRepoId = ConfService::getCurrentRootDirIndex();
  135. $lastRepoId = $loggedUser->getArrayPref("history", "last_repository");
  136. $defaultRepoId = AuthService::getDefaultRootId();
  137. if($lastRepoId != "" && $lastRepoId!=$currentRepoId && !isSet($_GET["tmp_repository_id"]) && $loggedUser->canSwitchTo($lastRepoId)){
  138. ConfService::switchRootDir($lastRepoId);
  139. }else if(!$loggedUser->canSwitchTo($currentRepoId)){
  140. ConfService::switchRootDir($defaultRepoId);
  141. }
  142. }
  143. if($loggedUser == null)
  144. {
  145. $requireAuth = true;
  146. }
  147. if(isset($loggingResult))
  148. {
  149. AJXP_XMLWriter::header();
  150. AJXP_XMLWriter::loggingResult($loggingResult, $rememberLogin, $rememberPass);
  151. AJXP_XMLWriter::close();
  152. exit(1);
  153. }
  154. }else{
  155. if(isSet($_GET["get_action"]) && $_GET["get_action"] == "logged_user")
  156. {
  157. AJXP_XMLWriter::header();
  158. print("<user id=\"shared\">");
  159. print("<active_repo id=\"".ConfService::getCurrentRootDirIndex()."\" write=\"1\" read=\"1\"/>");
  160. print(AJXP_XMLWriter::writeRepositoriesData(null));
  161. print("</user>");
  162. AJXP_XMLWriter::close();
  163. exit(1);
  164. }
  165. }
  166. //Set language
  167. $loggedUser = AuthService::getLoggedUser();
  168. if($loggedUser != null && $loggedUser->getPref("lang") != "") ConfService::setLanguage($loggedUser->getPref("lang"));
  169. else if(isSet($_COOKIE["AJXP_lang"])) ConfService::setLanguage($_COOKIE["AJXP_lang"]);
  170. $mess = ConfService::getMessages();
  171. $action = "";
  172. if(isSet($_GET["action"]) || isSet($_GET["get_action"])) $action = (isset($_GET["get_action"])?$_GET["get_action"]:$_GET["action"]);
  173. else if(isSet($_POST["action"]) || isSet($_POST["get_action"])) $action = (isset($_POST["get_action"])?$_POST["get_action"]:$_POST["action"]);
  174. //------------------------------------------------------------
  175. // SPECIAL HANDLING FOR FANCY UPLOADER RIGHTS FOR THIS ACTION
  176. //------------------------------------------------------------
  177. if(AuthService::usersEnabled())
  178. {
  179. $loggedUser = AuthService::getLoggedUser();
  180. if($action == "upload" && ($loggedUser == null || !$loggedUser->canWrite(ConfService::getCurrentRootDirIndex()."")) && isSet($_FILES['Filedata']))
  181. {
  182. header('HTTP/1.0 ' . '410 Not authorized');
  183. die('Error 410 Not authorized!');
  184. }
  185. }
  186. // THIS FIRST DRIVERS DO NOT NEED ID CHECK
  187. $ajxpDriver = AJXP_PluginsService::findPlugin("gui", "ajax");
  188. $ajxpDriver->init(ConfService::getRepository());
  189. $authDriver = ConfService::getAuthDriverImpl();
  190. // DRIVERS BELOW NEED IDENTIFICATION CHECK
  191. if(!AuthService::usersEnabled() || ALLOW_GUEST_BROWSING || AuthService::getLoggedUser()!=null){
  192. $confDriver = ConfService::getConfStorageImpl();
  193. $Driver = ConfService::loadRepositoryDriver();
  194. }
  195. ConfService::initActivePlugins();
  196. require_once(INSTALL_PATH."/server/classes/class.AJXP_Controller.php");
  197. $xmlResult = AJXP_Controller::findActionAndApply($action, array_merge($_GET, $_POST), $_FILES);
  198. if($xmlResult !== false && $xmlResult != ""){
  199. AJXP_XMLWriter::header();
  200. print($xmlResult);
  201. AJXP_XMLWriter::close();
  202. exit(1);
  203. }
  204. if(isset($requireAuth))
  205. {
  206. AJXP_XMLWriter::header();
  207. AJXP_XMLWriter::requireAuth();
  208. AJXP_XMLWriter::close();
  209. exit(1);
  210. }
  211. session_write_close();
  212. ?>