function catchError($code, $message, $fichier, $ligne, $context)
 {
     if (error_reporting() == 0) {
         return;
     }
     $message = "{$code} : {$message} in {$fichier} (l.{$ligne})";
     AJXP_Logger::logAction("error", array("message" => $message));
     AJXP_XMLWriter::header();
     AJXP_XMLWriter::sendMessage(null, $message, true);
     AJXP_XMLWriter::close();
     exit(1);
 }
 public function switchAction($action, $httpVars, $filesVars)
 {
     if (!isset($this->actions[$action])) {
         return false;
     }
     $repository = ConfService::getRepository();
     if (!$repository->detectStreamWrapper(true)) {
         return false;
     }
     if (!isset($this->pluginConf)) {
         $this->pluginConf = array("GENERATE_THUMBNAIL" => false);
     }
     $streamData = $repository->streamData;
     $destStreamURL = $streamData["protocol"] . "://" . $repository->getId();
     if ($action == "preview_data_proxy") {
         $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
         if (isset($httpVars["get_thumb"]) && $this->pluginConf["GENERATE_THUMBNAIL"]) {
             require_once INSTALL_PATH . "/plugins/editor.diaporama/PThumb.lib.php";
             $pThumb = new PThumb($this->pluginConf["THUMBNAIL_QUALITY"]);
             if (!$pThumb->isError()) {
                 $pThumb->remote_wrapper = $streamData["classname"];
                 $pThumb->use_cache = $this->pluginConf["USE_THUMBNAIL_CACHE"];
                 $pThumb->cache_dir = $this->pluginConf["THUMBNAIL_CACHE_DIR"];
                 $pThumb->fit_thumbnail($destStreamURL . $file, 200);
                 if ($pThumb->isError()) {
                     print_r($pThumb->error_array);
                     AJXP_Logger::logAction("error", $pThumb->error_array);
                 }
                 //exit(0);
             } else {
                 print_r($pThumb->error_array);
                 AJXP_Logger::logAction("error", $pThumb->error_array);
             }
         } else {
             $filesize = filesize($destStreamURL . $file);
             $fp = fopen($destStreamURL . $file, "r");
             header("Content-Type: " . AJXP_Utils::getImageMimeType(basename($file)) . "; name=\"" . basename($file) . "\"");
             header("Content-Length: " . $filesize);
             header('Cache-Control: public');
             $class = $streamData["classname"];
             $stream = fopen("php://output", "a");
             call_user_func(array($streamData["classname"], "copyFileInStream"), $destStreamURL . $file, $stream);
             fflush($stream);
             fclose($stream);
             //exit(1);
         }
     }
 }
 /**
  * Opens the stream
  * Diff with parent class : do not "securePath", as it removes double slash
  *
  * @param String $path Maybe in the form "ajxp.fs://repositoryId/pathToFile" 
  * @param String $mode
  * @param unknown_type $options
  * @param unknown_type $opened_path
  * @return unknown
  */
 public function stream_open($path, $mode, $options, &$context)
 {
     try {
         $this->realPath = $this->initPath($path, "file");
     } catch (Exception $e) {
         AJXP_Logger::logAction("error", array("message" => "Error while opening stream {$path}"));
         return false;
     }
     if ($this->realPath == -1) {
         $this->fp = -1;
         return true;
     } else {
         $this->fp = fopen($this->realPath, $mode, $options);
         return $this->fp !== false;
     }
 }
 public function postProcess($action, $httpVars, $params)
 {
     $url = $params["ob_output"];
     if (!isset($this->pluginConf["BITLY_USER"]) || !isset($this->pluginConf["BITLY_APIKEY"])) {
         print $url;
         AJXP_Logger::logAction("error", "Bitly Shortener : you must drop the conf.shorten.bitly.inc file inside conf.php and set the login/api key!");
         return;
     }
     $bitly_login = $this->pluginConf["BITLY_USER"];
     $bitly_api = $this->pluginConf["BITLY_APIKEY"];
     $format = 'json';
     $version = '2.0.1';
     $bitly = 'http://api.bit.ly/shorten?version=' . $version . '&longUrl=' . urlencode($url) . '&login='******'&apiKey=' . $bitly_api . '&format=' . $format;
     $response = AJXP_Utils::getRemoteContent($bitly);
     $json = json_decode($response, true);
     if (isset($json['results'][$url]['shortUrl'])) {
         print $json['results'][$url]['shortUrl'];
         $this->updateMetaShort($httpVars["file"], $json['results'][$url]['shortUrl']);
     } else {
         print $url;
     }
 }
 /**
  *
  * @param AJXP_Node $ajxpNode
  */
 public function extractMeta(&$ajxpNode)
 {
     //if(isSet($_SESSION["SVN_COMMAND_RUNNING"]) && $_SESSION["SVN_COMMAND_RUNNING"] === true) return ;
     $realDir = dirname($ajxpNode->getRealFile());
     if (SvnManager::$svnListDir == $realDir) {
         $entries = SvnManager::$svnListCache;
     } else {
         try {
             SvnManager::$svnListDir = $realDir;
             $entries = $this->svnListNode($realDir);
             SvnManager::$svnListCache = $entries;
         } catch (Exception $e) {
             AJXP_Logger::logAction("Error", array($e->getMessage()));
         }
     }
     $fileId = SystemTextEncoding::toUTF8(basename($ajxpNode->getUrl()));
     if (isset($entries[$fileId])) {
         $ajxpNode->mergeMetadata($entries[$fileId]);
     }
 }
 function storeFileToCopy($fileData)
 {
     $user = AuthService::getLoggedUser();
     $files = $user->getTemporaryData("tmp_upload");
     $files[] = $fileData;
     AJXP_Logger::debug("Storing data", $fileData);
     $user->saveTemporaryData("tmp_upload", $files);
     if (strpos($_SERVER["HTTP_USER_AGENT"], "ajaxplorer-ios-client") !== false || strpos($_SERVER["HTTP_USER_AGENT"], "Apache-HttpClient") !== false) {
         AJXP_Logger::logAction("Up from " . $_SERVER["HTTP_USER_AGENT"] . " - direct triger of next to remote");
         $this->uploadActions("next_to_remote", array(), array());
     }
 }
Beispiel #7
0
 public function deleteSelection($actionName, &$httpVars, $filesVars)
 {
     $init = $this->initDirAndSelection($httpVars, array(), true);
     if (isset($init["RECYCLE"]) && isset($init["RECYCLE"]["action"]) && $init["RECYCLE"]["action"] != "delete") {
         $httpVars["dest"] = SystemTextEncoding::fromUTF8($init["RECYCLE"]["dest"]);
         $this->copyOrMoveSelection("move", $httpVars, $filesVars);
         $userSelection = $init["ORIGINAL_SELECTION"];
         $files = $userSelection->getFiles();
         if ($actionName == "delete") {
             foreach ($files as $file) {
                 RecycleBinManager::fileToRecycle($file);
             }
         } else {
             if ($actionName == "restore") {
                 foreach ($files as $file) {
                     RecycleBinManager::deleteFromRecycle($file);
                 }
             }
         }
         $this->commitChanges($actionName, array("dir" => RecycleBinManager::getRelativeRecycle()), $filesVars);
         return;
     }
     foreach ($init["SELECTION"] as $selectedFile) {
         $res = ExecSvnCmd('svn delete', $selectedFile, '--force');
     }
     $this->commitMessageParams = "[" . implode(",", $init["SELECTION"]) . "]";
     $this->commitChanges($actionName, $httpVars, $filesVars);
     AJXP_Logger::logAction("Delete (svn delegate)", array("files" => $init["SELECTION"]));
     AJXP_XMLWriter::header();
     AJXP_XMLWriter::sendMessage("The selected files/folders have been deleted (by SVN)", null);
     AJXP_XMLWriter::reloadDataNode();
     AJXP_XMLWriter::close();
 }
 protected function parseSpecificContributions(&$contribNode)
 {
     parent::parseSpecificContributions($contribNode);
     if (isset($this->actions["public_url"]) && (!is_dir(PUBLIC_DOWNLOAD_FOLDER) || !is_writable(PUBLIC_DOWNLOAD_FOLDER))) {
         AJXP_Logger::logAction("Disabling Public links, PUBLIC_DOWNLOAD_FOLDER is not writeable!", array("folder" => PUBLIC_DOWNLOAD_FOLDER, "is_dir" => is_dir(PUBLIC_DOWNLOAD_FOLDER), "is_writeable" => is_writable(PUBLIC_DOWNLOAD_FOLDER)));
         unset($this->actions["public_url"]);
         $actionXpath = new DOMXPath($contribNode->ownerDocument);
         $publicUrlNodeList = $actionXpath->query('action[@name="public_url"]', $contribNode);
         $publicUrlNode = $publicUrlNodeList->item(0);
         $contribNode->removeChild($publicUrlNode);
     }
     if ($this->detectStreamWrapper() !== false) {
         $this->actions["cross_copy"] = array();
     }
 }
 function deleteUser($userId)
 {
     $authDriver = ConfService::getAuthDriverImpl();
     $confDriver = ConfService::getConfStorageImpl();
     $authDriver->deleteUser($userId);
     AJXP_User::deleteUser($userId);
     AJXP_Logger::logAction("Delete User", array("user_id" => $userId));
     return true;
 }
 function checkPassword($login, $pass, $seed)
 {
     //AJXP_Logger::logAction('auth.ldap:ldapAuthDriver::checkPassword');
     $ret = ldap_search($this->ldapconn, $this->ldapDN, "uid=" . $login);
     $entries = ldap_get_entries($this->ldapconn, $ret);
     //error_log(print_r($entries, true));
     if ($entries['count'] > 0) {
         //AJXP_Logger::logAction('auth.ldap:Found user!');
         //error_log(print_r($entries[0]["dn"], true));
         if (@ldap_bind($this->ldapconn, $entries[0]["dn"], $pass)) {
             AJXP_Logger::logAction('Ldap Password Check:Got user ' . $entries[0]["cn"][0]);
             return true;
         }
         return false;
     } else {
         AJXP_Logger::logAction("Ldap Password Check:No user {$user_id} found");
         return false;
     }
 }
Beispiel #11
0
 function deleteRepository($repoId)
 {
     $confStorage = ConfService::getConfStorageImpl();
     $res = $confStorage->deleteRepository($repoId);
     if ($res == -1) {
         return $res;
     }
     global $G_DEFAULT_REPOSITORIES, $G_REPOSITORIES;
     AJXP_Logger::logAction("Delete Repository", array("repo_id" => $repoId));
     $G_REPOSITORIES = ConfService::initRepositoriesList($G_DEFAULT_REPOSITORIES);
 }
 function switchAction($action, $httpVars, $fileVars)
 {
     if (!isset($this->actions[$action])) {
         return;
     }
     $xmlBuffer = "";
     foreach ($httpVars as $getName => $getValue) {
         ${$getName} = AJXP_Utils::securePath($getValue);
     }
     if (isset($dir) && $action != "upload") {
         $dir = SystemTextEncoding::fromUTF8($dir);
     }
     $mess = ConfService::getMessages();
     switch ($action) {
         //------------------------------------
         //	SWITCH THE ROOT REPOSITORY
         //------------------------------------
         case "switch_repository":
             if (!isset($repository_id)) {
                 break;
             }
             $dirList = ConfService::getRootDirsList();
             if (!isset($dirList[$repository_id])) {
                 $errorMessage = "Trying to switch to an unkown repository!";
                 break;
             }
             ConfService::switchRootDir($repository_id);
             // Load try to init the driver now, to trigger an exception
             // if it's not loading right.
             ConfService::loadRepositoryDriver();
             if (AuthService::usersEnabled() && AuthService::getLoggedUser() != null) {
                 $user = AuthService::getLoggedUser();
                 $activeRepId = ConfService::getCurrentRootDirIndex();
                 $user->setArrayPref("history", "last_repository", $activeRepId);
                 $user->save();
             }
             //$logMessage = "Successfully Switched!";
             AJXP_Logger::logAction("Switch Repository", array("rep. id" => $repository_id));
             break;
             //------------------------------------
             //	BOOKMARK BAR
             //------------------------------------
         //------------------------------------
         //	BOOKMARK BAR
         //------------------------------------
         case "get_bookmarks":
             $bmUser = null;
             if (AuthService::usersEnabled() && AuthService::getLoggedUser() != null) {
                 $bmUser = AuthService::getLoggedUser();
             } else {
                 if (!AuthService::usersEnabled()) {
                     $confStorage = ConfService::getConfStorageImpl();
                     $bmUser = $confStorage->createUserObject("shared");
                 }
             }
             if ($bmUser == null) {
                 exit(1);
             }
             if (isset($_GET["bm_action"]) && isset($_GET["bm_path"])) {
                 if ($_GET["bm_action"] == "add_bookmark") {
                     $title = "";
                     if (isset($_GET["bm_title"])) {
                         $title = $_GET["bm_title"];
                     }
                     if ($title == "" && $_GET["bm_path"] == "/") {
                         $title = ConfService::getCurrentRootDirDisplay();
                     }
                     $bmUser->addBookMark(SystemTextEncoding::magicDequote($_GET["bm_path"]), SystemTextEncoding::magicDequote($title));
                 } else {
                     if ($_GET["bm_action"] == "delete_bookmark") {
                         $bmUser->removeBookmark($_GET["bm_path"]);
                     } else {
                         if ($_GET["bm_action"] == "rename_bookmark" && isset($_GET["bm_title"])) {
                             $bmUser->renameBookmark($_GET["bm_path"], $_GET["bm_title"]);
                         }
                     }
                 }
             }
             if (AuthService::usersEnabled() && AuthService::getLoggedUser() != null) {
                 $bmUser->save();
                 AuthService::updateUser($bmUser);
             } else {
                 if (!AuthService::usersEnabled()) {
                     $bmUser->save();
                 }
             }
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::writeBookmarks($bmUser->getBookmarks());
             AJXP_XMLWriter::close();
             exit(1);
             break;
             //------------------------------------
             //	SAVE USER PREFERENCE
             //------------------------------------
         //------------------------------------
         //	SAVE USER PREFERENCE
         //------------------------------------
         case "save_user_pref":
             $userObject = AuthService::getLoggedUser();
             $i = 0;
             while (isset($_GET["pref_name_" . $i]) && isset($_GET["pref_value_" . $i])) {
                 $prefName = AJXP_Utils::sanitize($_GET["pref_name_" . $i], AJXP_SANITIZE_ALPHANUM);
                 $prefValue = AJXP_Utils::sanitize(SystemTextEncoding::magicDequote($_GET["pref_value_" . $i]));
                 if ($prefName == "password") {
                     continue;
                 }
                 if ($prefName != "pending_folder" && ($userObject == null || $userObject->getId() == "guest")) {
                     $i++;
                     continue;
                 }
                 $userObject->setPref($prefName, $prefValue);
                 $userObject->save();
                 AuthService::updateUser($userObject);
                 //setcookie("AJXP_$prefName", $prefValue);
                 $i++;
             }
             header("Content-Type:text/plain");
             print "SUCCESS";
             exit(1);
             break;
         default:
             break;
     }
     if (isset($logMessage) || isset($errorMessage)) {
         $xmlBuffer .= AJXP_XMLWriter::sendMessage(isset($logMessage) ? $logMessage : null, isset($errorMessage) ? $errorMessage : null, false);
     }
     if (isset($requireAuth)) {
         $xmlBuffer .= AJXP_XMLWriter::requireAuth(false);
     }
     return $xmlBuffer;
 }
 public function generateJpegsCallback($masterFile, $targetFile)
 {
     $unoconv = false;
     if (isset($this->pluginConf["UNOCONV"]) && !empty($this->pluginConf["UNOCONV"])) {
         $unoconv = $this->pluginConf["UNOCONV"];
         $officeExt = array('xls', 'xlsx', 'ods', 'doc', 'docx', 'odt', 'ppt', 'pptx', 'odp', 'rtf');
     }
     $extension = pathinfo($masterFile, PATHINFO_EXTENSION);
     $node = new AJXP_Node($masterFile);
     $masterFile = $node->getRealFile();
     if (DIRECTORY_SEPARATOR == "\\") {
         $masterFile = str_replace("/", "\\", $masterFile);
     }
     $wrappers = stream_get_wrappers();
     $wrappers_re = '(' . join('|', $wrappers) . ')';
     $isStream = preg_match("!^{$wrappers_re}://!", $targetFile) === 1;
     if ($isStream) {
         $backToStreamTarget = $targetFile;
         $targetFile = tempnam(AJXP_Utils::getAjxpTmpDir(), "imagick_") . ".pdf";
     }
     $workingDir = dirname($targetFile);
     $out = array();
     $return = 0;
     $tmpFileThumb = str_replace(".{$extension}", ".jpg", $targetFile);
     if (DIRECTORY_SEPARATOR == "\\") {
         $tmpFileThumb = str_replace("/", "\\", $tmpFileThumb);
     }
     if (!$this->extractAll) {
         //register_shutdown_function("unlink", $tmpFileThumb);
     } else {
         @set_time_limit(90);
     }
     chdir($workingDir);
     if ($unoconv !== false && in_array($extension, $officeExt)) {
         $unoDoc = str_replace(".jpg", "_unoconv.pdf", $tmpFileThumb);
         if (!is_file($tmpFileThumb)) {
             // Create PDF Version now
             $unoconv = "HOME=/tmp " . $this->pluginConf["UNOCONV"] . " --stdout -f pdf " . escapeshellarg($masterFile) . " > " . escapeshellarg(basename($unoDoc));
             exec($unoconv, $out, $return);
         }
         if (is_file($unoDoc)) {
             $masterFile = basename($unoDoc);
         }
     }
     if ($this->onTheFly) {
         $pageNumber = strrchr($targetFile, "-");
         $pageNumber = str_replace(array(".jpg", "-"), "", $pageNumber);
         $pageLimit = "[" . $pageNumber . "]";
         $this->extractAll = true;
     } else {
         if (!$this->useOnTheFly) {
             $pageLimit = $this->extractAll ? "" : "[0]";
         } else {
             $pageLimit = "[0]";
             if ($this->extractAll) {
                 $tmpFileThumb = str_replace(".jpg", "-0.jpg", $tmpFileThumb);
             }
         }
     }
     $params = $this->extractAll ? "-quality " . $this->pluginConf["IM_VIEWER_QUALITY"] : "-resize 250 -quality " . $this->pluginConf["IM_THUMB_QUALITY"] . (isset($this->pluginConf["IM_CUSTOM_OPTIONS"]) ? " " . $this->pluginConf["IM_CUSTOM_OPTIONS"] : "");
     $cmd = $this->pluginConf["IMAGE_MAGICK_CONVERT"] . " " . escapeshellarg($masterFile . $pageLimit) . " " . $params . " " . escapeshellarg($tmpFileThumb);
     AJXP_Logger::logAction("IMagick Command : {$cmd}");
     session_write_close();
     // Be sure to give the hand back
     exec($cmd, $out, $return);
     if (is_array($out) && count($out)) {
         throw new AJXP_Exception(implode("\n", $out));
     }
     if (!$this->extractAll) {
         rename($tmpFileThumb, $targetFile);
         if ($isStream) {
             AJXP_Logger::debug("Copy preview file to remote", $backToStreamTarget);
             copy($targetFile, $backToStreamTarget);
             unlink($targetFile);
         }
     } else {
         if ($isStream) {
             if (is_file(str_replace(".{$extension}", "", $targetFile))) {
                 $targetFile = str_replace(".{$extension}", "", $targetFile);
             }
             if (is_file($targetFile)) {
                 AJXP_Logger::debug("Copy preview file to remote", $backToStreamTarget);
                 copy($targetFile, $backToStreamTarget);
                 unlink($targetFile);
             }
             AJXP_Logger::debug("Searching for ", str_replace(".jpg", "-0.jpg", $tmpFileThumb));
             $i = 0;
             while (file_exists(str_replace(".jpg", "-{$i}.jpg", $tmpFileThumb))) {
                 $page = str_replace(".jpg", "-{$i}.jpg", $tmpFileThumb);
                 $remote_page = str_replace(".{$extension}", "-{$i}.jpg", $backToStreamTarget);
                 AJXP_Logger::debug("Copy preview file to remote", $remote_page);
                 copy($page, $remote_page);
                 unlink($page);
                 $i++;
             }
         }
     }
     return true;
 }
 static function catchError($code, $message, $fichier, $ligne, $context)
 {
     if (error_reporting() == 0) {
         return;
     }
     if (ConfService::getConf("SERVER_DEBUG")) {
         $message = "{$message} in {$fichier} (l.{$ligne})";
     }
     AJXP_Logger::logAction("error", array("message" => $message));
     AJXP_XMLWriter::header();
     AJXP_XMLWriter::sendMessage(null, SystemTextEncoding::toUTF8($message), true);
     AJXP_XMLWriter::close();
     exit(1);
 }
 function checkPassword($login, $pass, $seed)
 {
     if (empty($pass)) {
         return false;
     }
     $entries = $this->getUserEntries($login);
     if ($entries['count'] > 0) {
         if (@ldap_bind($this->ldapconn, $entries[0]["dn"], $pass)) {
             AJXP_Logger::logAction('Ldap Password Check:Got user ' . $entries[0]["cn"][0]);
             return true;
         }
         return false;
     } else {
         AJXP_Logger::logAction("Ldap Password Check:No user {$login} found");
         return false;
     }
 }
 public function postProcess2($action, $httpVars, $params)
 {
     AJXP_Logger::logAction("2post_" . $action, $httpVars);
     print $params["ob_output"];
     return "postProc2";
 }
 /**
  * Save Temporary Data.
  * Implementation uses serialised files because of the overhead incurred with a full db implementation.
  * 
  * @param $key String key of data to save.
  * @param $value Value to save
  * @return null (AJXP_Utils::saveSerialFile() returns nothing)
  */
 function saveTemporaryData($key, $value)
 {
     $dirPath = $this->storage->getOption("USERS_DIRPATH");
     if ($dirPath == "") {
         $dirPath = AJXP_INSTALL_PATH . "/data/users";
         AJXP_Logger::logAction("setTemporaryData", array("Warning" => "The conf.sql driver is missing a mandatory option USERS_DIRPATH!"));
     }
     return AJXP_Utils::saveSerialFile($dirPath . "/" . $this->getId() . "-temp-" . $key . ".ser", $value);
 }
 public function deleteRepositoryInst($repoId)
 {
     $confStorage = self::getConfStorageImpl();
     $res = $confStorage->deleteRepository($repoId);
     if ($res == -1) {
         return $res;
     }
     AJXP_Logger::logAction("Delete Repository", array("repo_id" => $repoId));
     $this->configs["REPOSITORIES"] = self::initRepositoriesList($this->configs["DEFAULT_REPOSITORIES"]);
 }
 function switchAction($action, $httpVars, $fileVars)
 {
     if (!isset($this->actions[$action])) {
         return;
     }
     $xmlBuffer = "";
     foreach ($httpVars as $getName => $getValue) {
         ${$getName} = Utils::securePath($getValue);
     }
     if (isset($dir) && $action != "upload") {
         $dir = SystemTextEncoding::fromUTF8($dir);
     }
     $mess = ConfService::getMessages();
     switch ($action) {
         //------------------------------------
         //	SWITCH THE ROOT REPOSITORY
         //------------------------------------
         case "switch_root_dir":
             if (!isset($root_dir_index)) {
                 break;
             }
             $dirList = ConfService::getRootDirsList();
             if (!isset($dirList[$root_dir_index])) {
                 $errorMessage = "Trying to switch to an unkown folder!";
                 break;
             }
             ConfService::switchRootDir($root_dir_index);
             $logMessage = "Successfully Switched!";
             AJXP_Logger::logAction("Switch Repository", array("rep. id" => $root_dir_index));
             break;
             //------------------------------------
             //	GET AN HTML TEMPLATE
             //------------------------------------
         //------------------------------------
         //	GET AN HTML TEMPLATE
         //------------------------------------
         case "get_template":
             header("Content-type:text/html; charset:UTF-8");
             if (isset($template_name) && is_file(CLIENT_RESOURCES_FOLDER . "/html/" . $template_name)) {
                 if ($template_name == "gui_tpl.html") {
                     include CLIENT_RESOURCES_FOLDER . "/html/usertemplate_top.html";
                 }
                 include CLIENT_RESOURCES_FOLDER . "/html/" . $template_name;
                 if ($template_name == "gui_tpl.html") {
                     include CLIENT_RESOURCES_FOLDER . "/html/usertemplate_bottom.html";
                 }
             }
             exit(0);
             break;
             //------------------------------------
             //	GET I18N MESSAGES
             //------------------------------------
         //------------------------------------
         //	GET I18N MESSAGES
         //------------------------------------
         case "get_i18n_messages":
             header("Content-type:text/javascript");
             HTMLWriter::writeI18nMessagesClass(ConfService::getMessages());
             exit(0);
             break;
             //------------------------------------
             //	BOOKMARK BAR
             //------------------------------------
         //------------------------------------
         //	BOOKMARK BAR
         //------------------------------------
         case "get_bookmarks":
             $bmUser = null;
             if (AuthService::usersEnabled() && AuthService::getLoggedUser() != null) {
                 $bmUser = AuthService::getLoggedUser();
             } else {
                 if (!AuthService::usersEnabled()) {
                     $confStorage = ConfService::getConfStorageImpl();
                     $bmUser = $confStorage->createUserObject("shared");
                 }
             }
             if ($bmUser == null) {
                 exit(1);
             }
             if (isset($_GET["bm_action"]) && isset($_GET["bm_path"])) {
                 if ($_GET["bm_action"] == "add_bookmark") {
                     $title = "";
                     if (isset($_GET["title"])) {
                         $title = $_GET["title"];
                     }
                     if ($title == "" && $_GET["bm_path"] == "/") {
                         $title = ConfService::getCurrentRootDirDisplay();
                     }
                     $bmUser->addBookMark($_GET["bm_path"], $title);
                 } else {
                     if ($_GET["bm_action"] == "delete_bookmark") {
                         $bmUser->removeBookmark($_GET["bm_path"]);
                     } else {
                         if ($_GET["bm_action"] == "rename_bookmark" && isset($_GET["bm_title"])) {
                             $bmUser->renameBookmark($_GET["bm_path"], $_GET["bm_title"]);
                         }
                     }
                 }
             }
             if (AuthService::usersEnabled() && AuthService::getLoggedUser() != null) {
                 $bmUser->save();
                 AuthService::updateUser($bmUser);
             } else {
                 if (!AuthService::usersEnabled()) {
                     $bmUser->save();
                 }
             }
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::writeBookmarks($bmUser->getBookmarks());
             AJXP_XMLWriter::close();
             exit(1);
             break;
             //------------------------------------
             //	SAVE USER PREFERENCE
             //------------------------------------
         //------------------------------------
         //	SAVE USER PREFERENCE
         //------------------------------------
         case "save_user_pref":
             $userObject = AuthService::getLoggedUser();
             if ($userObject == null) {
                 exit(1);
             }
             $i = 0;
             while (isset($_GET["pref_name_" . $i]) && isset($_GET["pref_value_" . $i])) {
                 $prefName = $_GET["pref_name_" . $i];
                 $prefValue = $_GET["pref_value_" . $i];
                 if ($prefName != "password") {
                     $userObject->setPref($prefName, $prefValue);
                     $userObject->save();
                     AuthService::updateUser($userObject);
                     setcookie("AJXP_{$prefName}", $prefValue);
                 } else {
                     if (isset($_GET["crt"]) && AuthService::checkPassword($userObject->getId(), $_GET["crt"], false, $_GET["pass_seed"])) {
                         AuthService::updatePassword($userObject->getId(), $prefValue);
                     } else {
                         //$errorMessage = "Wrong password!";
                         header("Content-Type:text/plain");
                         print "PASS_ERROR";
                         exit(1);
                     }
                 }
                 $i++;
             }
             header("Content-Type:text/plain");
             print "SUCCESS";
             exit(1);
             break;
             //------------------------------------
             //	DISPLAY DOC
             //------------------------------------
         //------------------------------------
         //	DISPLAY DOC
         //------------------------------------
         case "display_doc":
             header("Content-type:text/html; charset:UTF-8");
             echo HTMLWriter::getDocFile(htmlentities($_GET["doc_file"]));
             exit(1);
             break;
         default:
             break;
     }
     if (isset($logMessage) || isset($errorMessage)) {
         $xmlBuffer .= AJXP_XMLWriter::sendMessage(isset($logMessage) ? $logMessage : null, isset($errorMessage) ? $errorMessage : null, false);
     }
     if (isset($requireAuth)) {
         $xmlBuffer .= AJXP_XMLWriter::requireAuth(false);
     }
     if (isset($reload_current_node) && $reload_current_node == "true") {
         $xmlBuffer .= AJXP_XMLWriter::reloadCurrentNode(false);
     }
     if (isset($reload_dest_node) && $reload_dest_node != "") {
         $xmlBuffer .= AJXP_XMLWriter::reloadNode($reload_dest_node, false);
     }
     if (isset($reload_file_list)) {
         $xmlBuffer .= AJXP_XMLWriter::reloadFileList($reload_file_list, false);
     }
     return $xmlBuffer;
 }
 function execQuery($sql = '')
 {
     $output = '';
     if ($sql != '') {
         //$sql=mysql_real_escape_string($sql);
         $result = @mysql_query(stripslashes($sql));
         if ($result) {
             AJXP_Logger::logAction("exec", array($sql));
             return $result;
         } else {
             return new AJXP_Exception($sql . ":" . mysql_error());
         }
     } else {
         return new AJXP_Exception('Empty Query');
     }
 }
 function switchAction($action, $httpVars, $fileVars)
 {
     if (!isset($this->actions[$action])) {
         return;
     }
     $xmlBuffer = "";
     foreach ($httpVars as $getName => $getValue) {
         ${$getName} = Utils::securePath(SystemTextEncoding::magicDequote($getValue));
     }
     $selection = new UserSelection();
     $selection->initFromHttpVars($httpVars);
     if (isset($dir) && $action != "upload") {
         $safeDir = $dir;
         $dir = SystemTextEncoding::fromUTF8($dir);
     }
     if (isset($dest)) {
         $dest = SystemTextEncoding::fromUTF8($dest);
     }
     $mess = ConfService::getMessages();
     $recycleBinOption = $this->repository->getOption("RECYCLE_BIN");
     // FILTER ACTION FOR DELETE
     if ($recycleBinOption != "" && $action == "delete" && $dir != "/" . $recycleBinOption) {
         $action = "move";
         $dest = "/" . $recycleBinOption;
         $dest_node = "AJAXPLORER_RECYCLE_NODE";
     }
     // FILTER ACTION FOR RESTORE
     if ($recycleBinOption != "" && $action == "restore" && $dir == "/" . $recycleBinOption) {
         $originalRep = RecycleBinManager::getFileOrigin($selection->getUniqueFile());
         if ($originalRep != "") {
             $action = "move";
             $dest = $originalRep;
         }
     }
     switch ($action) {
         //------------------------------------
         //	DOWNLOAD, IMAGE & MP3 PROXYS
         //------------------------------------
         case "download":
             AJXP_Logger::logAction("Download", array("files" => $selection));
             $zip = false;
             if ($selection->isUnique()) {
                 if (is_dir($this->getPath() . "/" . $selection->getUniqueFile())) {
                     $zip = true;
                     $dir .= "/" . basename($selection->getUniqueFile());
                 }
             } else {
                 $zip = true;
             }
             if ($zip) {
                 // Make a temp zip and send it as download
                 $this->downFile($this->makeName($selection->getFiles()), "force-download", "archive.zip");
             } else {
                 $this->downFile($this->makeName($selection->getUniqueFile()), "force-download", $selection->getUniqueFile());
             }
             exit(0);
             break;
         case "image_proxy":
             $this->downFile($this->makeName($file), "image", $file);
             exit(0);
             break;
         case "mp3_proxy":
             $this->downFile($this->makeName($file), "mp3", $file);
             exit(0);
             break;
             //------------------------------------
             //	ONLINE EDIT
             //------------------------------------
         //------------------------------------
         //	ONLINE EDIT
         //------------------------------------
         case "edit":
             if (isset($save) && $save == 1) {
                 AJXP_Logger::logAction("Online Edition", array("file" => SystemTextEncoding::fromUTF8($file)));
                 $code = stripslashes($code);
                 $code = str_replace("&lt;", "<", $code);
                 $this->SSHOperation->setRemoteContent($this->makeName($file), $code);
                 echo $mess[115];
             } else {
                 $this->sendFile($this->SSHOperation->getRemoteContent($this->makeName($file)), "plain", $file);
             }
             exit(0);
             break;
             //------------------------------------
             //	COPY / MOVE
             //------------------------------------
         //------------------------------------
         //	COPY / MOVE
         //------------------------------------
         case "copy":
         case "move":
             if ($selection->isEmpty()) {
                 $errorMessage = $mess[113];
                 break;
             }
             $result = "";
             if ($action == "move") {
                 $result = $this->SSHOperation->moveFile($this->makeName($selection->getFiles()), $this->makeName($dest));
             } else {
                 $result = $this->SSHOperation->copyFile($this->makeName($selection->getFiles()), $this->makeName($dest));
             }
             $mess = ConfService::getMessages();
             if (strlen($result)) {
                 $errorMessage = $mess[114];
             } else {
                 foreach ($selection->getFiles() as $files) {
                     $logMessage .= $mess[34] . " " . SystemTextEncoding::toUTF8(basename($file)) . " " . $mess[$action == "move" ? 74 : 73] . " " . SystemTextEncoding::toUTF8($dest) . "\n";
                 }
                 AJXP_Logger::logAction($action == "move" ? "Move" : "Copy", array("files" => $selection, "destination" => $dest));
             }
             $reload_current_node = true;
             if (isset($dest_node)) {
                 $reload_dest_node = $dest_node;
             }
             $reload_file_list = true;
             break;
             //------------------------------------
             //  CHANGE FILE PERMISSION
             //------------------------------------
         //------------------------------------
         //  CHANGE FILE PERMISSION
         //------------------------------------
         case "chmod":
             $messtmp = "";
             $changedFiles = array();
             $value = "0" . decoct(octdec(ltrim($chmod_value, "0")));
             // On error, the command will fail
             $result = $this->SSHOperation->chmodFile($this->makeName($selection->getFiles()), $chmod_value);
             $mess = ConfService::getMessages();
             if (strlen($result)) {
                 $errorMessage = $mess[114];
             } else {
                 $logMessage = "Successfully changed permission to " . $chmod_value . " for " . count($selection->getFiles()) . " files or folders";
                 AJXP_Logger::logAction("Chmod", array("dir" => $dir, "filesCount" => count($selection->getFiles())));
                 $reload_file_list = $dir;
             }
             break;
             //------------------------------------
             //	SUPPRIMER / DELETE
             //------------------------------------
         //------------------------------------
         //	SUPPRIMER / DELETE
         //------------------------------------
         case "delete":
             if ($selection->isEmpty()) {
                 $errorMessage = $mess[113];
                 break;
             }
             $logMessages = array();
             $result = $this->SSHOperation->deleteFile($this->makeName($selection->getFiles()));
             if (strlen($result)) {
                 $mess = ConfService::getMessages();
                 $errorMessage = $mess[120];
             } else {
                 $mess = ConfService::getMessages();
                 foreach ($selection->getFiles() as $file) {
                     $logMessages[] = "{$mess['34']} " . SystemTextEncoding::toUTF8($file) . " {$mess['44']}.";
                 }
                 $logMessage = join("\n", $logMessages);
             }
             AJXP_Logger::logAction("Delete", array("files" => $selection));
             $reload_current_node = true;
             $reload_file_list = true;
             break;
             //------------------------------------
             //	RENOMMER / RENAME
             //------------------------------------
         //------------------------------------
         //	RENOMMER / RENAME
         //------------------------------------
         case "rename":
             $filename_new = $dir . "/" . $filename_new;
             $error = $this->SSHOperation->moveFile($this->makeName($file), $this->makeName($filename_new));
             if ($error != null) {
                 $errorMessage = $error;
                 break;
             }
             $logMessage = SystemTextEncoding::toUTF8($file) . " {$mess['41']} " . SystemTextEncoding::toUTF8($filename_new);
             $reload_current_node = true;
             $reload_file_list = basename($filename_new);
             AJXP_Logger::logAction("Rename", array("original" => $file, "new" => $filename_new));
             break;
             //------------------------------------
             //	CREER UN REPERTOIRE / CREATE DIR
             //------------------------------------
         //------------------------------------
         //	CREER UN REPERTOIRE / CREATE DIR
         //------------------------------------
         case "mkdir":
             $messtmp = "";
             $dirname = Utils::processFileName($dirname);
             $error = $this->SSHOperation->createRemoteDirectory($this->makeName($dir . "/" . $dirname));
             if (isset($error)) {
                 $errorMessage = $error;
                 break;
             }
             $reload_file_list = $dirname;
             $messtmp .= "{$mess['38']} " . SystemTextEncoding::toUTF8($dirname) . " {$mess['39']} ";
             if ($dir == "") {
                 $messtmp .= "/";
             } else {
                 $messtmp .= SystemTextEncoding::toUTF8($dir);
             }
             $logMessage = $messtmp;
             $reload_current_node = true;
             AJXP_Logger::logAction("Create Dir", array("dir" => $dir . "/" . $dirname));
             break;
             //------------------------------------
             //	CREER UN FICHIER / CREATE FILE
             //------------------------------------
         //------------------------------------
         //	CREER UN FICHIER / CREATE FILE
         //------------------------------------
         case "mkfile":
             $messtmp = "";
             $filename = Utils::processFileName($filename);
             $error = $this->SSHOperation->setRemoteContent($this->makeName($dir . "/" . $filename), "");
             if (isset($error)) {
                 $errorMessage = $error;
                 break;
             }
             $messtmp .= "{$mess['34']} " . SystemTextEncoding::toUTF8($filename) . " {$mess['39']} ";
             if ($dir == "") {
                 $messtmp .= "/";
             } else {
                 $messtmp .= SystemTextEncoding::toUTF8($dir);
             }
             $logMessage = $messtmp;
             $reload_file_list = $filename;
             AJXP_Logger::logAction("Create File", array("file" => $dir . "/" . $filename));
             break;
             //------------------------------------
             //	UPLOAD
             //------------------------------------
         //------------------------------------
         //	UPLOAD
         //------------------------------------
         case "upload":
             $fancyLoader = false;
             if (isset($fileVars["Filedata"])) {
                 $fancyLoader = true;
                 if ($dir != "") {
                     $dir = "/" . base64_decode($dir);
                 }
             }
             if ($dir != "") {
                 $rep_source = "/{$dir}";
             } else {
                 $rep_source = "";
             }
             $destination = $rep_source;
             $logMessage = "";
             //$fancyLoader = false;
             foreach ($fileVars as $boxName => $boxData) {
                 if ($boxName != "Filedata" && substr($boxName, 0, 9) != "userfile_") {
                     continue;
                 }
                 if ($boxName == "Filedata") {
                     $fancyLoader = true;
                 }
                 $err = Utils::parseFileDataErrors($boxData, $fancyLoader);
                 if ($err != null) {
                     $errorMessage = $err;
                     break;
                 }
                 $userfile_name = $boxData["name"];
                 $userfile_name = Utils::processFileName($userfile_name);
                 if (!$this->SSHOperation->uploadFile($boxData["tmp_name"], $this->makeName($destination . "/" . $userfile_name))) {
                     $errorMessage = ($fancyLoader ? "411 " : "") . "{$mess['33']} " . $userfile_name;
                     break;
                 }
                 $logMessage .= "{$mess['34']} " . SystemTextEncoding::toUTF8($userfile_name) . " {$mess['35']} {$dir}";
                 AJXP_Logger::logAction("Upload File", array("file" => $dir . "/" . $userfile_name));
             }
             if ($fancyLoader) {
                 if (isset($errorMessage)) {
                     header('HTTP/1.0 ' . $errorMessage);
                     die('Error ' . $errorMessage);
                 } else {
                     header('HTTP/1.0 200 OK');
                     die("200 OK");
                 }
             } else {
                 print "<html><script language=\"javascript\">\n";
                 if (isset($errorMessage)) {
                     print "\n if(parent.ajaxplorer.actionBar.multi_selector)parent.ajaxplorer.actionBar.multi_selector.submitNext('" . str_replace("'", "\\'", $errorMessage) . "');";
                 } else {
                     print "\n if(parent.ajaxplorer.actionBar.multi_selector)parent.ajaxplorer.actionBar.multi_selector.submitNext();";
                 }
                 print "</script></html>";
             }
             exit;
             break;
             //------------------------------------
             // Public URL
             //------------------------------------
         //------------------------------------
         // Public URL
         //------------------------------------
         case "public_url":
             $file = SystemTextEncoding::fromUTF8($file);
             $url = $this->makePubliclet($file, $password, $expiration);
             header("Content-type:text/plain");
             echo $url;
             exit(1);
             break;
             //------------------------------------
             //	XML LISTING
             //------------------------------------
         //------------------------------------
         //	XML LISTING
         //------------------------------------
         case "ls":
             if (!isset($dir) || $dir == "/") {
                 $dir = "";
             }
             $searchMode = $fileListMode = $completeMode = false;
             if (isset($mode)) {
                 if ($mode == "search") {
                     $searchMode = true;
                 } else {
                     if ($mode == "file_list") {
                         $fileListMode = true;
                     } else {
                         if ($mode == "complete") {
                             $completeMode = true;
                         }
                     }
                 }
             }
             $nom_rep = $dir;
             AJXP_Exception::errorToXml($nom_rep);
             $result = $this->SSHOperation->listFilesIn($nom_rep);
             AJXP_XMLWriter::header();
             foreach ($result as $file) {
                 $attributes = "";
                 $fileName = SystemTextEncoding::toUTF8($file["name"]);
                 $icon = Utils::mimetype($fileName, "image", $file["isDir"] == 1);
                 if ($searchMode) {
                     if ($file["isDir"] == 0) {
                         $attributes = "is_file=\"true\" icon=\"" . SystemTextEncoding::toUTF8($icon) . "\"";
                     }
                 } else {
                     if ($fileListMode) {
                         $atts = array();
                         $atts[] = "is_file=\"" . (1 - $file["isDir"]) . "\"";
                         $atts[] = "is_image=\"" . Utils::is_image($fileName) . "\"";
                         $atts[] = "mimestring=\"" . Utils::mimetype($fileName, "type", $file["isDir"] == 1) . "\"";
                         $atts[] = "ajxp_modiftime=\"" . $this->dateModif($file["time"]) . "\"";
                         $atts[] = "filesize=\"" . Utils::roundSize($file["size"]) . "\"";
                         $atts[] = "bytesize=\"" . $file["size"] . "\"";
                         $atts[] = "filename=\"" . str_replace("&", "&amp;", $dir . "/" . $fileName) . "\"";
                         $atts[] = "icon=\"" . ($file["isDir"] == 1 ? "folder.png" : SystemTextEncoding::toUTF8($icon)) . "\"";
                         $attributes = join(" ", $atts);
                     } else {
                         if ($file["isDir"] == 1) {
                             $link = SERVER_ACCESS . "?dir=" . $dir . "/" . $fileName;
                             $link = urlencode($link);
                             $folderBaseName = str_replace("&", "&amp;", $fileName);
                             $folderFullName = "{$dir}/" . $folderBaseName;
                             $parentFolderName = $dir;
                             if (!$completeMode) {
                                 $icon = CLIENT_RESOURCES_FOLDER . "/images/foldericon.png";
                                 $openicon = CLIENT_RESOURCES_FOLDER . "/images/openfoldericon.png";
                                 if (preg_match("/\\.zip\$/", $file["name"])) {
                                     $icon = $openicon = CLIENT_RESOURCES_FOLDER . "/images/crystal/actions/16/accessories-archiver.png";
                                 }
                                 $attributes = "icon=\"{$icon}\"  openicon=\"{$openicon}\" filename=\"" . $folderFullName . "\" src=\"{$link}\"";
                             }
                         }
                     }
                 }
                 if (strlen($attributes) > 0) {
                     print "<tree text=\"" . str_replace("&", "&amp;", SystemTextEncoding::toUTF8($this->SSHOperation->unescapeFileName($file["name"]))) . "\" {$attributes}>";
                     print "</tree>";
                 }
             }
             AJXP_XMLWriter::close();
             exit(1);
             break;
     }
     if (isset($logMessage) || isset($errorMessage)) {
         $xmlBuffer .= AJXP_XMLWriter::sendMessage(isset($logMessage) ? $logMessage : null, isset($errorMessage) ? $errorMessage : null, false);
     }
     if (isset($requireAuth)) {
         $xmlBuffer .= AJXP_XMLWriter::requireAuth(false);
     }
     if (isset($reload_current_node) && $reload_current_node == "true") {
         $xmlBuffer .= AJXP_XMLWriter::reloadCurrentNode(false);
     }
     if (isset($reload_dest_node) && $reload_dest_node != "") {
         $xmlBuffer .= AJXP_XMLWriter::reloadNode($reload_dest_node, false);
     }
     if (isset($reload_file_list)) {
         $xmlBuffer .= AJXP_XMLWriter::reloadFileList($reload_file_list, false);
     }
     return $xmlBuffer;
 }
 function switchAction($action, $httpVars, $fileVars)
 {
     if (!isset($this->actions[$action])) {
         return;
     }
     $xmlBuffer = "";
     foreach ($httpVars as $getName => $getValue) {
         ${$getName} = AJXP_Utils::securePath($getValue);
     }
     if (isset($dir) && $action != "upload") {
         $dir = SystemTextEncoding::fromUTF8($dir);
     }
     $mess = ConfService::getMessages();
     switch ($action) {
         //------------------------------------
         //	SWITCH THE ROOT REPOSITORY
         //------------------------------------
         case "switch_repository":
             if (!isset($repository_id)) {
                 break;
             }
             $dirList = ConfService::getRepositoriesList();
             /** @var $repository_id string */
             if (!isset($dirList[$repository_id])) {
                 $errorMessage = "Trying to switch to an unkown repository!";
                 break;
             }
             ConfService::switchRootDir($repository_id);
             // Load try to init the driver now, to trigger an exception
             // if it's not loading right.
             ConfService::loadRepositoryDriver();
             if (AuthService::usersEnabled() && AuthService::getLoggedUser() != null) {
                 $user = AuthService::getLoggedUser();
                 $activeRepId = ConfService::getCurrentRootDirIndex();
                 $user->setArrayPref("history", "last_repository", $activeRepId);
                 $user->save("user");
             }
             //$logMessage = "Successfully Switched!";
             AJXP_Logger::logAction("Switch Repository", array("rep. id" => $repository_id));
             break;
             //------------------------------------
             //	BOOKMARK BAR
             //------------------------------------
         //------------------------------------
         //	BOOKMARK BAR
         //------------------------------------
         case "get_bookmarks":
             $bmUser = null;
             if (AuthService::usersEnabled() && AuthService::getLoggedUser() != null) {
                 $bmUser = AuthService::getLoggedUser();
             } else {
                 if (!AuthService::usersEnabled()) {
                     $confStorage = ConfService::getConfStorageImpl();
                     $bmUser = $confStorage->createUserObject("shared");
                 }
             }
             if ($bmUser == null) {
                 exit(1);
             }
             if (isset($httpVars["bm_action"]) && isset($httpVars["bm_path"])) {
                 if ($httpVars["bm_action"] == "add_bookmark") {
                     $title = "";
                     if (isset($httpVars["bm_title"])) {
                         $title = $httpVars["bm_title"];
                     }
                     if ($title == "" && $httpVars["bm_path"] == "/") {
                         $title = ConfService::getCurrentRootDirDisplay();
                     }
                     $bmUser->addBookMark(SystemTextEncoding::magicDequote($httpVars["bm_path"]), SystemTextEncoding::magicDequote($title));
                 } else {
                     if ($httpVars["bm_action"] == "delete_bookmark") {
                         $bmUser->removeBookmark($httpVars["bm_path"]);
                     } else {
                         if ($httpVars["bm_action"] == "rename_bookmark" && isset($httpVars["bm_title"])) {
                             $bmUser->renameBookmark($httpVars["bm_path"], $httpVars["bm_title"]);
                         }
                     }
                 }
             }
             if (AuthService::usersEnabled() && AuthService::getLoggedUser() != null) {
                 $bmUser->save("user");
                 AuthService::updateUser($bmUser);
             } else {
                 if (!AuthService::usersEnabled()) {
                     $bmUser->save("user");
                 }
             }
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::writeBookmarks($bmUser->getBookmarks());
             AJXP_XMLWriter::close();
             exit(1);
             break;
             //------------------------------------
             //	SAVE USER PREFERENCE
             //------------------------------------
         //------------------------------------
         //	SAVE USER PREFERENCE
         //------------------------------------
         case "save_user_pref":
             $userObject = AuthService::getLoggedUser();
             $i = 0;
             while (isset($httpVars["pref_name_" . $i]) && isset($httpVars["pref_value_" . $i])) {
                 $prefName = AJXP_Utils::sanitize($httpVars["pref_name_" . $i], AJXP_SANITIZE_ALPHANUM);
                 $prefValue = AJXP_Utils::sanitize(SystemTextEncoding::magicDequote($httpVars["pref_value_" . $i]));
                 if ($prefName == "password") {
                     continue;
                 }
                 if ($prefName != "pending_folder" && $userObject == null) {
                     $i++;
                     continue;
                 }
                 $userObject->setPref($prefName, $prefValue);
                 $userObject->save("user");
                 AuthService::updateUser($userObject);
                 //setcookie("AJXP_$prefName", $prefValue);
                 $i++;
             }
             header("Content-Type:text/plain");
             print "SUCCESS";
             exit(1);
             break;
             //------------------------------------
             // WEBDAV PREFERENCES
             //------------------------------------
         //------------------------------------
         // WEBDAV PREFERENCES
         //------------------------------------
         case "webdav_preferences":
             $userObject = AuthService::getLoggedUser();
             $webdavActive = false;
             $passSet = false;
             // Detect http/https and host
             if (ConfService::getCoreConf("WEBDAV_BASEHOST") != "") {
                 $baseURL = ConfService::getCoreConf("WEBDAV_BASEHOST");
             } else {
                 $baseURL = AJXP_Utils::detectServerURL();
             }
             $webdavBaseUrl = $baseURL . ConfService::getCoreConf("WEBDAV_BASEURI") . "/";
             if (isset($httpVars["activate"]) || isset($httpVars["webdav_pass"])) {
                 $davData = $userObject->getPref("AJXP_WEBDAV_DATA");
                 if (!empty($httpVars["activate"])) {
                     $activate = $httpVars["activate"] == "true" ? true : false;
                     if (empty($davData)) {
                         $davData = array();
                     }
                     $davData["ACTIVE"] = $activate;
                 }
                 if (!empty($httpVars["webdav_pass"])) {
                     $password = $httpVars["webdav_pass"];
                     if (function_exists('mcrypt_encrypt')) {
                         $user = $userObject->getId();
                         $secret = defined("AJXP_SECRET_KEY") ? AJXP_SAFE_SECRET_KEY : "CDAFx¨op#";
                         $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND);
                         $password = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($user . $secret), $password, MCRYPT_MODE_ECB, $iv));
                     }
                     $davData["PASS"] = $password;
                 }
                 $userObject->setPref("AJXP_WEBDAV_DATA", $davData);
                 $userObject->save("user");
             }
             $davData = $userObject->getPref("AJXP_WEBDAV_DATA");
             if (!empty($davData)) {
                 $webdavActive = isset($davData["ACTIVE"]) && $davData["ACTIVE"] === true;
                 $passSet = isset($davData["PASS"]);
             }
             $repoList = ConfService::getRepositoriesList();
             $davRepos = array();
             $loggedUser = AuthService::getLoggedUser();
             foreach ($repoList as $repoIndex => $repoObject) {
                 $accessType = $repoObject->getAccessType();
                 $driver = AJXP_PluginsService::getInstance()->getPluginByTypeName("access", $accessType);
                 if (is_a($driver, "AjxpWebdavProvider") && ($loggedUser->canRead($repoIndex) || $loggedUser->canWrite($repoIndex))) {
                     $davRepos[$repoIndex] = $webdavBaseUrl . "" . ($repoObject->getSlug() == null ? $repoObject->getId() : $repoObject->getSlug());
                 }
             }
             $prefs = array("webdav_active" => $webdavActive, "password_set" => $passSet, "webdav_base_url" => $webdavBaseUrl, "webdav_repositories" => $davRepos);
             HTMLWriter::charsetHeader("application/json");
             print json_encode($prefs);
             break;
         case "get_user_template_logo":
             $tplId = $httpVars["template_id"];
             $iconFormat = $httpVars["icon_format"];
             $repo = ConfService::getRepositoryById($tplId);
             $logo = $repo->getOption("TPL_ICON_" . strtoupper($iconFormat));
             if (isset($logo) && is_file(AJXP_DATA_PATH . "/plugins/core.conf/tpl_logos/" . $logo)) {
                 header("Content-Type: " . AJXP_Utils::getImageMimeType($logo) . "; name=\"" . $logo . "\"");
                 header("Content-Length: " . filesize(AJXP_DATA_PATH . "/plugins/core.conf/tpl_logos/" . $logo));
                 header('Pragma:');
                 header('Cache-Control: public');
                 header("Last-Modified: " . gmdate("D, d M Y H:i:s", time() - 10000) . " GMT");
                 header("Expires: " . gmdate("D, d M Y H:i:s", time() + 5 * 24 * 3600) . " GMT");
                 readfile(AJXP_DATA_PATH . "/plugins/core.conf/tpl_logos/" . $logo);
             } else {
                 $logo = "default_template_logo-" . ($iconFormat == "small" ? 16 : 22) . ".png";
                 header("Content-Type: " . AJXP_Utils::getImageMimeType($logo) . "; name=\"" . $logo . "\"");
                 header("Content-Length: " . filesize(AJXP_INSTALL_PATH . "/" . AJXP_PLUGINS_FOLDER . "/core.conf/" . $logo));
                 header('Pragma:');
                 header('Cache-Control: public');
                 header("Last-Modified: " . gmdate("D, d M Y H:i:s", time() - 10000) . " GMT");
                 header("Expires: " . gmdate("D, d M Y H:i:s", time() + 5 * 24 * 3600) . " GMT");
                 readfile(AJXP_INSTALL_PATH . "/" . AJXP_PLUGINS_FOLDER . "/core.conf/" . $logo);
             }
             break;
         case "get_user_templates_definition":
             AJXP_XMLWriter::header("repository_templates");
             $repositories = ConfService::getRepositoriesList();
             $pServ = AJXP_PluginsService::getInstance();
             foreach ($repositories as $repo) {
                 if (!$repo->isTemplate) {
                     continue;
                 }
                 if (!$repo->getOption("TPL_USER_CAN_CREATE")) {
                     continue;
                 }
                 $repoId = $repo->getUniqueId();
                 $repoLabel = $repo->getDisplay();
                 $repoType = $repo->getAccessType();
                 print "<template repository_id=\"{$repoId}\" repository_label=\"{$repoLabel}\" repository_type=\"{$repoType}\">";
                 $driverPlug = $pServ->getPluginByTypeName("access", $repoType);
                 $params = $driverPlug->getManifestRawContent("//param", "node");
                 $tplDefined = $repo->getOptionsDefined();
                 $defaultLabel = '';
                 foreach ($params as $paramNode) {
                     $name = $paramNode->getAttribute("name");
                     if (strpos($name, "TPL_") === 0) {
                         if ($name == "TPL_DEFAULT_LABEL") {
                             $defaultLabel = str_replace("AJXP_USER", AuthService::getLoggedUser()->getId(), $repo->getOption($name));
                         }
                         continue;
                     }
                     if (in_array($paramNode->getAttribute("name"), $tplDefined)) {
                         continue;
                     }
                     if ($paramNode->getAttribute('no_templates') == 'true') {
                         continue;
                     }
                     print AJXP_XMLWriter::replaceAjxpXmlKeywords($paramNode->ownerDocument->saveXML($paramNode));
                 }
                 // ADD LABEL
                 echo '<param name="DISPLAY" type="string" label="' . $mess[359] . '" description="' . $mess[429] . '" mandatory="true" default="' . $defaultLabel . '"/>';
                 print "</template>";
             }
             AJXP_XMLWriter::close("repository_templates");
             break;
         case "user_create_repository":
             $tplId = $httpVars["template_id"];
             $tplRepo = ConfService::getRepositoryById($tplId);
             $options = array();
             self::parseParameters($httpVars, $options);
             $newRep = $tplRepo->createTemplateChild(AJXP_Utils::sanitize($httpVars["DISPLAY"]), $options, null, AuthService::getLoggedUser()->getId());
             $res = ConfService::addRepository($newRep);
             AJXP_XMLWriter::header();
             if ($res == -1) {
                 AJXP_XMLWriter::sendMessage(null, $mess[426]);
             } else {
                 $loggedUser = AuthService::getLoggedUser();
                 // Make sure we do not overwrite otherwise loaded rights.
                 $loggedUser->load();
                 $loggedUser->setRight($newRep->getUniqueId(), "rw");
                 $loggedUser->save("superuser");
                 AuthService::updateUser($loggedUser);
                 AJXP_XMLWriter::sendMessage($mess[425], null);
                 AJXP_XMLWriter::reloadDataNode("", $newRep->getUniqueId());
                 AJXP_XMLWriter::reloadRepositoryList();
             }
             AJXP_XMLWriter::close();
             break;
         case "user_delete_repository":
             $repoId = $httpVars["repository_id"];
             $repository = ConfService::getRepositoryById($repoId);
             if (!$repository->getUniqueUser() || $repository->getUniqueUser() != AuthService::getLoggedUser()->getId()) {
                 throw new Exception("You are not allowed to perform this operation!");
             }
             $res = ConfService::deleteRepository($repoId);
             AJXP_XMLWriter::header();
             if ($res == -1) {
                 AJXP_XMLWriter::sendMessage(null, $mess[427]);
             } else {
                 $loggedUser = AuthService::getLoggedUser();
                 // Make sure we do not override remotely set rights
                 $loggedUser->load();
                 $loggedUser->removeRights($repoId);
                 $loggedUser->save("superuser");
                 AuthService::updateUser($loggedUser);
                 AJXP_XMLWriter::sendMessage($mess[428], null);
                 AJXP_XMLWriter::reloadRepositoryList();
             }
             AJXP_XMLWriter::close();
             break;
         default:
             break;
     }
     if (isset($logMessage) || isset($errorMessage)) {
         $xmlBuffer .= AJXP_XMLWriter::sendMessage(isset($logMessage) ? $logMessage : null, isset($errorMessage) ? $errorMessage : null, false);
     }
     if (isset($requireAuth)) {
         $xmlBuffer .= AJXP_XMLWriter::requireAuth(false);
     }
     return $xmlBuffer;
 }
 protected function parseSpecificContributions(&$contribNode)
 {
     parent::parseSpecificContributions($contribNode);
     if (isset($this->actions["public_url"])) {
         $disableSharing = false;
         if (!is_dir(PUBLIC_DOWNLOAD_FOLDER) || !is_writable(PUBLIC_DOWNLOAD_FOLDER)) {
             AJXP_Logger::logAction("Disabling Public links, PUBLIC_DOWNLOAD_FOLDER is not writeable!", array("folder" => PUBLIC_DOWNLOAD_FOLDER, "is_dir" => is_dir(PUBLIC_DOWNLOAD_FOLDER), "is_writeable" => is_writable(PUBLIC_DOWNLOAD_FOLDER)));
             $disableSharing = true;
         } else {
             if (AuthService::usersEnabled()) {
                 $loggedUser = AuthService::getLoggedUser();
                 /*
                 // Should be disabled by AJXP_Controller directly
                 $currentRepo = ConfService::getRepository();
                 if($currentRepo != null){
                 	$rights = $loggedUser->getSpecificActionsRights($currentRepo->getId());
                 	if(isSet($rights["public_url"]) && $rights["public_url"] === false){
                 		$disableSharing = true;
                 	}
                 }
                 */
                 if ($loggedUser->getId() == "guest" || $loggedUser == "shared") {
                     $disableSharing = true;
                 }
             } else {
                 $disableSharing = true;
             }
         }
         if ($disableSharing) {
             unset($this->actions["public_url"]);
             $actionXpath = new DOMXPath($contribNode->ownerDocument);
             $publicUrlNodeList = $actionXpath->query('action[@name="public_url"]', $contribNode);
             $publicUrlNode = $publicUrlNodeList->item(0);
             $contribNode->removeChild($publicUrlNode);
         }
     }
     if ($this->detectStreamWrapper() !== false) {
         $this->actions["cross_copy"] = array();
     }
 }
    function listPlugins($dir, $root = NULL)
    {
        $dir = "/{$dir}";
        AJXP_Logger::logAction("Listing plugins");
        // make sure that the logger is started!
        $pServ = AJXP_PluginsService::getInstance();
        $activePlugins = $pServ->getActivePlugins();
        $types = $pServ->getDetectedPlugins();
        $uniqTypes = array("core");
        if ($dir == "/plugins") {
            AJXP_XMLWriter::sendFilesListComponentConfig('<columns switchGridMode="filelist" template_name="ajxp_conf.plugins_folder">
			<column messageId="ajxp_conf.101" attributeName="ajxp_label" sortType="String"/>
			</columns>');
            ksort($types);
            foreach ($types as $t => $tPlugs) {
                if (in_array($t, $uniqTypes)) {
                    continue;
                }
                $meta = array("icon" => "folder_development.png", "plugin_id" => $t);
                AJXP_XMLWriter::renderNode("/{$root}/plugins/" . $t, ucfirst($t), false, $meta);
            }
        } else {
            if ($dir == "/core") {
                AJXP_XMLWriter::sendFilesListComponentConfig('<columns switchGridMode="filelist" switchDisplayMode="list"  template_name="ajxp_conf.plugins">
			<column messageId="ajxp_conf.101" attributeName="ajxp_label" sortType="String"/>
			<column messageId="ajxp_conf.102" attributeName="plugin_id" sortType="String"/>
			<column messageId="ajxp_conf.103" attributeName="plugin_description" sortType="String"/>
			</columns>');
                $mess = ConfService::getMessages();
                foreach ($uniqTypes as $type) {
                    if (!isset($types[$type])) {
                        continue;
                    }
                    foreach ($types[$type] as $pId => $pObject) {
                        $meta = array("icon" => $type == "core" ? "preferences_desktop.png" : "preferences_plugin.png", "ajxp_mime" => "ajxp_plugin", "plugin_id" => $pObject->getId(), "plugin_description" => $pObject->getManifestDescription());
                        if ($type == "core") {
                            if ($pObject->getId() == "core.ajaxplorer") {
                                $label = "AjaXplorer Core";
                            } else {
                                $label = sprintf($mess["ajxp_conf.100"], $pObject->getName());
                            }
                        } else {
                            if ($activePlugins[$pObject->getId()] !== true) {
                                continue;
                            }
                            $label = $pObject->getManifestLabel();
                        }
                        AJXP_XMLWriter::renderNode("/{$root}/plugins/" . $pObject->getId(), $label, true, $meta);
                    }
                }
            } else {
                $split = explode("/", $dir);
                if (empty($split[0])) {
                    array_shift($split);
                }
                $type = $split[1];
                AJXP_XMLWriter::sendFilesListComponentConfig('<columns switchGridMode="filelist" switchDisplayMode="full" template_name="ajxp_conf.plugin_detail">
			<column messageId="ajxp_conf.101" attributeName="ajxp_label" sortType="String" defaultWidth="10%"/>
			<column messageId="ajxp_conf.102" attributeName="plugin_id" sortType="String" defaultWidth="10%"/>
			<column messageId="ajxp_conf.103" attributeName="plugin_description" sortType="String" defaultWidth="60%"/>
			<column messageId="ajxp_conf.104" attributeName="enabled" sortType="String" defaultWidth="10%"/>
			<column messageId="ajxp_conf.105" attributeName="can_active" sortType="String" defaultWidth="10%"/>
			</columns>');
                $mess = ConfService::getMessages();
                foreach ($types[$type] as $pId => $pObject) {
                    $errors = "OK";
                    try {
                        $pObject->performChecks();
                    } catch (Exception $e) {
                        $errors = "ERROR : " . $e->getMessage();
                    }
                    $meta = array("icon" => "preferences_plugin.png", "ajxp_mime" => "ajxp_plugin", "can_active" => $errors, "enabled" => $pObject->isEnabled() ? $mess[440] : $mess[441], "plugin_id" => $pObject->getId(), "plugin_description" => $pObject->getManifestDescription());
                    AJXP_XMLWriter::renderNode("/{$root}/plugins/" . $pObject->getId(), $pObject->getManifestLabel(), true, $meta);
                }
            }
        }
    }
 /**
  * Delete a user in the auth driver impl
  * @static
  * @param $userId
  * @return bool
  */
 static function deleteUser($userId)
 {
     $userId = AuthService::filterUserSensitivity($userId);
     AJXP_Controller::applyHook("user.before_delete", array($userId));
     $authDriver = ConfService::getAuthDriverImpl();
     $authDriver->deleteUser($userId);
     $subUsers = array();
     AJXP_User::deleteUser($userId, $subUsers);
     foreach ($subUsers as $deletedUser) {
         $authDriver->deleteUser($deletedUser);
     }
     AJXP_Controller::applyHook("user.after_delete", array($userId));
     AJXP_Logger::logAction("Delete User", array("user_id" => $userId, "sub_user" => implode(",", $subUsers)));
     return true;
 }
 function switchAction($action, $httpVars, $fileVars)
 {
     if (!isset($this->actions[$action])) {
         return;
     }
     parent::accessPreprocess($action, $httpVars, $fileVars);
     $selection = new UserSelection();
     $dir = $httpVars["dir"] or "";
     $dir = AJXP_Utils::securePath($dir);
     if ($action != "upload") {
         $dir = SystemTextEncoding::fromPostedFileName($dir);
     }
     $selection->initFromHttpVars($httpVars);
     $mess = ConfService::getMessages();
     $newArgs = RecycleBinManager::filterActions($action, $selection, $dir);
     if (isset($newArgs["action"])) {
         $action = $newArgs["action"];
     }
     if (isset($newArgs["dest"])) {
         $httpVars["dest"] = SystemTextEncoding::toUTF8($newArgs["dest"]);
     }
     //Re-encode!
     // FILTER DIR PAGINATION ANCHOR
     $page = null;
     if (isset($dir) && strstr($dir, "#") !== false) {
         $parts = explode("#", $dir);
         $dir = $parts[0];
         $page = $parts[1];
     }
     $pendingSelection = "";
     $logMessage = null;
     $reloadContextNode = false;
     switch ($action) {
         //------------------------------------
         //	DOWNLOAD
         //------------------------------------
         case "download":
             AJXP_Logger::logAction("Download", array("files" => $selection));
             @set_error_handler(array("HTMLWriter", "javascriptErrorHandler"), E_ALL & ~E_NOTICE);
             @register_shutdown_function("restore_error_handler");
             $zip = false;
             if ($selection->isUnique()) {
                 if (is_dir($this->urlBase . $selection->getUniqueFile())) {
                     $zip = true;
                     $base = basename($selection->getUniqueFile());
                     $dir .= "/" . dirname($selection->getUniqueFile());
                 }
             } else {
                 $zip = true;
             }
             if ($zip) {
                 // Make a temp zip and send it as download
                 $loggedUser = AuthService::getLoggedUser();
                 $file = USERS_DIR . "/" . ($loggedUser ? $loggedUser->getId() : "shared") . "/" . time() . "tmpDownload.zip";
                 $zipFile = $this->makeZip($selection->getFiles(), $file, $dir);
                 if (!$zipFile) {
                     throw new AJXP_Exception("Error while compressing");
                 }
                 register_shutdown_function("unlink", $file);
                 $localName = ($base == "" ? "Files" : $base) . ".zip";
                 $this->readFile($file, "force-download", $localName, false, false, true);
             } else {
                 $this->readFile($this->urlBase . $selection->getUniqueFile(), "force-download");
             }
             exit(0);
             break;
         case "compress":
             // Make a temp zip and send it as download
             $loggedUser = AuthService::getLoggedUser();
             if (isset($httpVars["archive_name"])) {
                 $localName = AJXP_Utils::decodeSecureMagic($httpVars["archive_name"]);
             } else {
                 $localName = (basename($dir) == "" ? "Files" : basename($dir)) . ".zip";
             }
             $file = USERS_DIR . "/" . ($loggedUser ? $loggedUser->getId() : "shared") . "/" . time() . "tmpCompression.zip";
             $zipFile = $this->makeZip($selection->getFiles(), $file, $dir);
             if (!$zipFile) {
                 throw new AJXP_Exception("Error while compressing file {$localName}");
             }
             register_shutdown_function("unlink", $file);
             copy($file, $this->urlBase . $dir . "/" . str_replace(".zip", ".tmp", $localName));
             @rename($this->urlBase . $dir . "/" . str_replace(".zip", ".tmp", $localName), $this->urlBase . $dir . "/" . $localName);
             $reloadContextNode = true;
             $pendingSelection = $localName;
             break;
         case "stat":
             clearstatcache();
             $stat = @stat($this->urlBase . AJXP_Utils::decodeSecureMagic($httpVars["file"]));
             header("Content-type:application/json");
             if (!$stat) {
                 print '{}';
             } else {
                 print json_encode($stat);
             }
             exit(1);
             break;
             //------------------------------------
             //	ONLINE EDIT
             //------------------------------------
         //------------------------------------
         //	ONLINE EDIT
         //------------------------------------
         case "get_content":
             $this->readFile($this->urlBase . AJXP_Utils::decodeSecureMagic($httpVars["file"]), "plain");
             exit(0);
             break;
         case "put_content":
             if (!isset($httpVars["content"])) {
                 break;
             }
             // Reload "code" variable directly from POST array, do not "securePath"...
             $code = $httpVars["content"];
             $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
             AJXP_Logger::logAction("Online Edition", array("file" => $file));
             if (isset($httpVars["encode"]) && $httpVars["encode"] == "base64") {
                 $code = base64_decode($code);
             } else {
                 $code = stripslashes($code);
                 $code = str_replace("&lt;", "<", $code);
             }
             $fileName = $this->urlBase . $file;
             if (!is_file($fileName) || !is_writable($fileName)) {
                 header("Content-Type:text/plain");
                 print !is_writable($fileName) ? "1001" : "1002";
                 exit(1);
             }
             $fp = fopen($fileName, "w");
             fputs($fp, $code);
             fclose($fp);
             header("Content-Type:text/plain");
             print $mess[115];
             exit(0);
             break;
             //------------------------------------
             //	COPY / MOVE
             //------------------------------------
         //------------------------------------
         //	COPY / MOVE
         //------------------------------------
         case "copy":
         case "move":
             if ($selection->isEmpty()) {
                 throw new AJXP_Exception("", 113);
             }
             $success = $error = array();
             $dest = AJXP_Utils::decodeSecureMagic($httpVars["dest"]);
             if ($selection->inZip()) {
                 // Set action to copy anycase (cannot move from the zip).
                 $action = "copy";
             }
             $this->copyOrMove($dest, $selection->getFiles(), $error, $success, $action == "move" ? true : false);
             if (count($error)) {
                 throw new AJXP_Exception(join("\n", $error));
             } else {
                 $logMessage = join("\n", $success);
                 AJXP_Logger::logAction($action == "move" ? "Move" : "Copy", array("files" => $selection, "destination" => $dest));
             }
             $reloadContextNode = true;
             $reloadDataNode = $dest;
             break;
             //------------------------------------
             //	SUPPRIMER / DELETE
             //------------------------------------
         //------------------------------------
         //	SUPPRIMER / DELETE
         //------------------------------------
         case "delete":
             if ($selection->isEmpty()) {
                 throw new AJXP_Exception("", 113);
             }
             $logMessages = array();
             $errorMessage = $this->delete($selection->getFiles(), $logMessages);
             if (count($logMessages)) {
                 $logMessage = join("\n", $logMessages);
             }
             if ($errorMessage) {
                 throw new AJXP_Exception($errorMessage);
             }
             AJXP_Logger::logAction("Delete", array("files" => $selection));
             $reloadContextNode = true;
             break;
             //------------------------------------
             //	RENOMMER / RENAME
             //------------------------------------
         //------------------------------------
         //	RENOMMER / RENAME
         //------------------------------------
         case "rename":
             $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
             $filename_new = AJXP_Utils::decodeSecureMagic($httpVars["filename_new"]);
             $this->rename($file, $filename_new);
             $logMessage = SystemTextEncoding::toUTF8($file) . " {$mess['41']} " . SystemTextEncoding::toUTF8($filename_new);
             $reloadContextNode = true;
             $pendingSelection = $filename_new;
             AJXP_Logger::logAction("Rename", array("original" => $file, "new" => $filename_new));
             break;
             //------------------------------------
             //	CREER UN REPERTOIRE / CREATE DIR
             //------------------------------------
         //------------------------------------
         //	CREER UN REPERTOIRE / CREATE DIR
         //------------------------------------
         case "mkdir":
             $messtmp = "";
             $dirname = AJXP_Utils::processFileName(SystemTextEncoding::fromUTF8($httpVars["dirname"]));
             $error = $this->mkDir($dir, $dirname);
             if (isset($error)) {
                 throw new AJXP_Exception($error);
             }
             $messtmp .= "{$mess['38']} " . SystemTextEncoding::toUTF8($dirname) . " {$mess['39']} ";
             if ($dir == "") {
                 $messtmp .= "/";
             } else {
                 $messtmp .= SystemTextEncoding::toUTF8($dir);
             }
             $logMessage = $messtmp;
             $pendingSelection = $dirname;
             $reloadContextNode = true;
             AJXP_Logger::logAction("Create Dir", array("dir" => $dir . "/" . $dirname));
             break;
             //------------------------------------
             //	CREER UN FICHIER / CREATE FILE
             //------------------------------------
         //------------------------------------
         //	CREER UN FICHIER / CREATE FILE
         //------------------------------------
         case "mkfile":
             $messtmp = "";
             $filename = AJXP_Utils::processFileName(SystemTextEncoding::fromUTF8($httpVars["filename"]));
             $error = $this->createEmptyFile($dir, $filename);
             if (isset($error)) {
                 throw new AJXP_Exception($error);
             }
             $messtmp .= "{$mess['34']} " . SystemTextEncoding::toUTF8($filename) . " {$mess['39']} ";
             if ($dir == "") {
                 $messtmp .= "/";
             } else {
                 $messtmp .= SystemTextEncoding::toUTF8($dir);
             }
             $logMessage = $messtmp;
             $reloadContextNode = true;
             $pendingSelection = $dir . "/" . $filename;
             AJXP_Logger::logAction("Create File", array("file" => $dir . "/" . $filename));
             break;
             //------------------------------------
             //	CHANGE FILE PERMISSION
             //------------------------------------
         //------------------------------------
         //	CHANGE FILE PERMISSION
         //------------------------------------
         case "chmod":
             $messtmp = "";
             $files = $selection->getFiles();
             $changedFiles = array();
             $chmod_value = $httpVars["chmod_value"];
             $recursive = $httpVars["recursive"];
             $recur_apply_to = $httpVars["recur_apply_to"];
             foreach ($files as $fileName) {
                 $error = $this->chmod($fileName, $chmod_value, $recursive == "on", $recursive == "on" ? $recur_apply_to : "both", $changedFiles);
             }
             if (isset($error)) {
                 throw new AJXP_Exception($error);
             }
             //$messtmp.="$mess[34] ".SystemTextEncoding::toUTF8($filename)." $mess[39] ";
             $logMessage = "Successfully changed permission to " . $chmod_value . " for " . count($changedFiles) . " files or folders";
             $reloadContextNode = true;
             AJXP_Logger::logAction("Chmod", array("dir" => $dir, "filesCount" => count($changedFiles)));
             break;
             //------------------------------------
             //	UPLOAD
             //------------------------------------
         //------------------------------------
         //	UPLOAD
         //------------------------------------
         case "upload":
             AJXP_Logger::debug("Upload Files Data", $fileVars);
             $destination = $this->urlBase . SystemTextEncoding::fromPostedFileName($dir);
             AJXP_Logger::debug("Upload inside", array("destination" => $destination));
             if (!$this->isWriteable($destination)) {
                 $errorCode = 412;
                 $errorMessage = "{$mess['38']} " . SystemTextEncoding::toUTF8($dir) . " {$mess['99']}.";
                 AJXP_Logger::debug("Upload error 412", array("destination" => $destination));
                 return array("ERROR" => array("CODE" => $errorCode, "MESSAGE" => $errorMessage));
             }
             foreach ($fileVars as $boxName => $boxData) {
                 if (substr($boxName, 0, 9) != "userfile_") {
                     continue;
                 }
                 $err = AJXP_Utils::parseFileDataErrors($boxData);
                 if ($err != null) {
                     $errorCode = $err[0];
                     $errorMessage = $err[1];
                     break;
                 }
                 $userfile_name = $boxData["name"];
                 $userfile_name = AJXP_Utils::processFileName($userfile_name);
                 if (isset($httpVars["auto_rename"])) {
                     $userfile_name = self::autoRenameForDest($destination, $userfile_name);
                 }
                 if (isset($boxData["input_upload"])) {
                     try {
                         AJXP_Logger::debug("Begining reading INPUT stream");
                         $input = fopen("php://input", "r");
                         $output = fopen("{$destination}/" . $userfile_name, "w");
                         $sizeRead = 0;
                         while ($sizeRead < intval($boxData["size"])) {
                             $chunk = fread($input, 4096);
                             $sizeRead += strlen($chunk);
                             fwrite($output, $chunk, strlen($chunk));
                         }
                         fclose($input);
                         fclose($output);
                         AJXP_Logger::debug("End reading INPUT stream");
                     } catch (Exception $e) {
                         $errorCode = 411;
                         $errorMessage = $e->getMessage();
                         break;
                     }
                 } else {
                     if (!move_uploaded_file($boxData["tmp_name"], "{$destination}/" . $userfile_name)) {
                         $errorCode = 411;
                         $errorMessage = "{$mess['33']} " . $userfile_name;
                         break;
                     }
                 }
                 $this->changeMode($destination . "/" . $userfile_name);
                 $logMessage .= "{$mess['34']} " . SystemTextEncoding::toUTF8($userfile_name) . " {$mess['35']} {$dir}";
                 AJXP_Logger::logAction("Upload File", array("file" => SystemTextEncoding::fromUTF8($dir) . "/" . $userfile_name));
             }
             if (isset($errorMessage)) {
                 AJXP_Logger::debug("Return error {$errorCode} {$errorMessage}");
                 return array("ERROR" => array("CODE" => $errorCode, "MESSAGE" => $errorMessage));
             } else {
                 AJXP_Logger::debug("Return success");
                 return array("SUCCESS" => true);
             }
             return;
             break;
             //------------------------------------
             // Public URL
             //------------------------------------
         //------------------------------------
         // Public URL
         //------------------------------------
         case "public_url":
             $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
             $url = $this->makePubliclet($file, $httpVars["password"], $httpVars["expiration"]);
             header("Content-type:text/plain");
             echo $url;
             exit(1);
             break;
             //------------------------------------
             //	XML LISTING
             //------------------------------------
         //------------------------------------
         //	XML LISTING
         //------------------------------------
         case "ls":
             if (!isset($dir) || $dir == "/") {
                 $dir = "";
             }
             $lsOptions = $this->parseLsOptions(isset($httpVars["options"]) ? $httpVars["options"] : "a");
             $startTime = microtime();
             $dir = AJXP_Utils::securePath(SystemTextEncoding::magicDequote($dir));
             $path = $this->urlBase . ($dir != "" ? "/" . $dir : "");
             $threshold = $this->repository->getOption("PAGINATION_THRESHOLD");
             if (!isset($threshold) || intval($threshold) == 0) {
                 $threshold = 500;
             }
             $limitPerPage = $this->repository->getOption("PAGINATION_NUMBER");
             if (!isset($limitPerPage) || intval($limitPerPage) == 0) {
                 $limitPerPage = 200;
             }
             $countFiles = $this->countFiles($path, !$lsOptions["f"]);
             if ($countFiles > $threshold) {
                 $offset = 0;
                 $crtPage = 1;
                 if (isset($page)) {
                     $offset = (intval($page) - 1) * $limitPerPage;
                     $crtPage = $page;
                 }
                 $totalPages = floor($countFiles / $limitPerPage) + 1;
             } else {
                 $offset = $limitPerPage = 0;
             }
             $metaData = array();
             $crtLabel = AJXP_Utils::xmlEntities(basename($dir), true);
             if (RecycleBinManager::recycleEnabled()) {
                 if (RecycleBinManager::currentLocationIsRecycle($dir)) {
                     $metaData["ajxp_mime"] = "ajxp_recycle";
                     $crtLabel = AJXP_Utils::xmlEntities($mess[122]);
                 } else {
                     if ($dir == "") {
                         $metaData["repo_has_recycle"] = "true";
                     }
                 }
             }
             AJXP_XMLWriter::renderHeaderNode(AJXP_Utils::xmlEntities($dir, true), $crtLabel, false, $metaData);
             if (isset($totalPages) && isset($crtPage)) {
                 AJXP_XMLWriter::renderPaginationData($countFiles, $crtPage, $totalPages);
                 if (!$lsOptions["f"]) {
                     AJXP_XMLWriter::close();
                     exit(1);
                 }
             }
             $cursor = 0;
             $handle = opendir($path);
             if (!$handle) {
                 throw new AJXP_Exception("Cannot open dir " . $path);
             }
             $fullList = array("d" => array(), "z" => array(), "f" => array());
             while (strlen($nodeName = readdir($handle)) > 0) {
                 if ($nodeName == "." || $nodeName == "..") {
                     continue;
                 }
                 $isLeaf = is_file($path . "/" . $nodeName) || AJXP_Utils::isBrowsableArchive($nodeName);
                 if (!$this->filterNodeName($path, $nodeName, $isLeaf, $lsOptions)) {
                     continue;
                 }
                 if (RecycleBinManager::recycleEnabled() && $dir == "" && "/" . $nodeName == RecycleBinManager::getRecyclePath()) {
                     continue;
                 }
                 $nodeType = "d";
                 if ($isLeaf) {
                     if (AJXP_Utils::isBrowsableArchive($nodeName)) {
                         if ($lsOptions["f"] && $lsOptions["z"]) {
                             // See archives as files
                             $nodeType = "f";
                         } else {
                             $nodeType = "z";
                         }
                     } else {
                         $nodeType = "f";
                     }
                 }
                 if ($offset > 0 && $cursor < $offset) {
                     $cursor++;
                     continue;
                 }
                 if ($limitPerPage > 0 && $cursor - $offset >= $limitPerPage) {
                     break;
                 }
                 $metaData = array();
                 $currentFile = $path . "/" . $nodeName;
                 $metaData["is_file"] = $isLeaf ? "1" : "0";
                 $metaData["filename"] = AJXP_Utils::xmlEntities(SystemTextEncoding::toUTF8($dir . "/" . $nodeName));
                 $metaData["icon"] = AJXP_Utils::mimetype($nodeName, "image", !$isLeaf);
                 if ($metaData["icon"] == "folder.png") {
                     $metaData["openicon"] = "folder_open.png";
                 }
                 if (!is_file($currentFile) || AJXP_Utils::isBrowsableArchive($nodeName)) {
                     $link = SystemTextEncoding::toUTF8(SERVER_ACCESS . "?get_action=ls&options=dz&dir=" . $dir . "/" . $nodeName);
                     $link = urlencode($link);
                     $metaData["src"] = $link;
                 }
                 if ($lsOptions["l"]) {
                     $metaData["file_group"] = @filegroup($currentFile) || "unknown";
                     $metaData["file_owner"] = @fileowner($currentFile) || "unknown";
                     $fPerms = @fileperms($currentFile);
                     if ($fPerms !== false) {
                         $fPerms = substr(decoct($fPerms), $isLeaf ? 2 : 1);
                     } else {
                         $fPerms = '0000';
                     }
                     $metaData["file_perms"] = $fPerms;
                     $metaData["mimestring"] = AJXP_Utils::mimetype($currentFile, "type", !$isLeaf);
                     $datemodif = $this->date_modif($currentFile);
                     $metaData["ajxp_modiftime"] = $datemodif ? $datemodif : "0";
                     $metaData["bytesize"] = 0;
                     if ($isLeaf) {
                         $metaData["bytesize"] = filesize($currentFile);
                     }
                     $metaData["filesize"] = AJXP_Utils::roundSize($metaData["bytesize"]);
                     if (AJXP_Utils::isBrowsableArchive($nodeName)) {
                         $metaData["ajxp_mime"] = "ajxp_browsable_archive";
                     }
                     $realFile = null;
                     // A reference to the real file.
                     AJXP_Controller::applyHook("ls.metadata", array($currentFile, &$metaData, $this->wrapperClassName, &$realFile));
                 }
                 $attributes = "";
                 foreach ($metaData as $key => $value) {
                     $attributes .= "{$key}=\"{$value}\" ";
                 }
                 $renderNodeData = array(AJXP_Utils::xmlEntities($dir . "/" . $nodeName, true), AJXP_Utils::xmlEntities($nodeName, true), $isLeaf, $metaData);
                 $fullList[$nodeType][$nodeName] = $renderNodeData;
                 $cursor++;
             }
             foreach ($fullList as $key => $list) {
                 uksort($list, 'strnatcasecmp');
                 $fullList[$key] = $list;
             }
             $allNodes = array_merge($fullList["d"], $fullList["z"], $fullList["f"]);
             array_map(array("AJXP_XMLWriter", "renderNodeArray"), $fullList["d"]);
             array_map(array("AJXP_XMLWriter", "renderNodeArray"), $fullList["z"]);
             array_map(array("AJXP_XMLWriter", "renderNodeArray"), $fullList["f"]);
             // ADD RECYCLE BIN TO THE LIST
             if ($dir == "" && RecycleBinManager::recycleEnabled()) {
                 $recycleBinOption = RecycleBinManager::getRelativeRecycle();
                 if (file_exists($this->urlBase . $recycleBinOption)) {
                     $recycleIcon = $this->countFiles($this->urlBase . $recycleBinOption, false, true) > 0 ? "trashcan_full.png" : "trashcan.png";
                     AJXP_XMLWriter::renderNode($recycleBinOption, AJXP_Utils::xmlEntities($mess[122]), false, array("ajxp_modiftime" => $this->date_modif($this->urlBase . $recycleBinOption), "mimestring" => AJXP_Utils::xmlEntities($mess[122]), "icon" => "{$recycleIcon}", "filesize" => "-", "ajxp_mime" => "ajxp_recycle"));
                 }
             }
             AJXP_Logger::debug("LS Time : " . intval((microtime() - $startTime) * 1000) . "ms");
             AJXP_XMLWriter::close();
             return;
             break;
     }
     $xmlBuffer = "";
     if (isset($logMessage) || isset($errorMessage)) {
         $xmlBuffer .= AJXP_XMLWriter::sendMessage(isset($logMessage) ? $logMessage : null, isset($errorMessage) ? $errorMessage : null, false);
     }
     if ($reloadContextNode) {
         if (!isset($pendingSelection)) {
             $pendingSelection = "";
         }
         $xmlBuffer .= AJXP_XMLWriter::reloadDataNode("", $pendingSelection, false);
     }
     if (isset($reloadDataNode)) {
         $xmlBuffer .= AJXP_XMLWriter::reloadDataNode($reloadDataNode, "", false);
     }
     return $xmlBuffer;
 }
 public function checkPassword($login, $pass, $seed)
 {
     if (!extension_loaded('radius')) {
         AJXP_Logger::logAction("RADIUS: php radius extension is missing, please install it.");
         return false;
     }
     $res = radius_auth_open();
     $this->prepareRequest($res, $login, $pass, $seed);
     $req = radius_send_request($res);
     if (!$req) {
         AJXP_Logger::debug(__CLASS__, __FUNCTION__, "RADIUS: Could not send request (" . radius_strerror($res) . ")");
         return false;
     }
     switch ($req) {
         case RADIUS_ACCESS_ACCEPT:
             AJXP_Logger::debug(__CLASS__, __FUNCTION__, "RADIUS: authentication for user \"" . $login . "\" successful");
             radius_close($res);
             return true;
         case RADIUS_ACCESS_REJECT:
             AJXP_Logger::logAction("RADIUS: authentication for user \"" . $login . "\" failed");
             break;
         default:
             AJXP_Logger::debug(__CLASS__, __FUNCTION__, "RADIUS: unknwon return value " . $req);
             break;
     }
     radius_close($res);
     return false;
 }
Beispiel #28
0
 static function deleteUser($userId)
 {
     $authDriver = ConfService::getAuthDriverImpl();
     $confDriver = ConfService::getConfStorageImpl();
     $authDriver->deleteUser($userId);
     AJXP_User::deleteUser($userId);
     $users = $authDriver->listUsers();
     $subUsers = "";
     foreach (array_keys($users) as $id) {
         $object = $confDriver->createUserObject($id);
         if ($object->hasParent() && $object->getParent() == $userId) {
             $subUsers .= $id . ",";
             $authDriver->deleteUser($id);
             AJXP_User::deleteUser($id);
         }
     }
     AJXP_Logger::logAction("Delete User", array("user_id" => $userId, "sub_user" => $subUsers));
     return true;
 }
 function switchAction($action, $httpVars, $fileVars)
 {
     if (!isset($this->actions[$action])) {
         return;
     }
     $xmlBuffer = "";
     foreach ($httpVars as $getName => $getValue) {
         ${$getName} = Utils::securePath(SystemTextEncoding::magicDequote($getValue));
     }
     $selection = new UserSelection();
     $selection->initFromHttpVars($httpVars);
     if (isset($dir) && $action != "upload") {
         $safeDir = $dir;
         $dir = SystemTextEncoding::fromUTF8($dir);
     }
     if (isset($dest)) {
         $dest = SystemTextEncoding::fromUTF8($dest);
     }
     $mess = ConfService::getMessages();
     $newArgs = RecycleBinManager::filterActions($action, $selection, $dir);
     foreach ($newArgs as $argName => $argValue) {
         ${$argName} = $argValue;
     }
     // FILTER DIR PAGINATION ANCHOR
     if (isset($dir) && strstr($dir, "#") !== false) {
         $parts = explode("#", $dir);
         $dir = $parts[0];
         $page = $parts[1];
     }
     switch ($action) {
         //------------------------------------
         //	DOWNLOAD, IMAGE & MP3 PROXYS
         //------------------------------------
         case "download":
             AJXP_Logger::logAction("Download", array("files" => $selection));
             set_error_handler(array("HTMLWriter", "javascriptErrorHandler"), E_ALL & ~E_NOTICE);
             register_shutdown_function("restore_error_handler");
             if ($selection->inZip) {
                 $tmpDir = dirname($selection->getZipPath()) . "/.tmpExtractDownload";
                 $delDir = $this->getPath() . "/" . $tmpDir;
                 @mkdir($delDir);
                 register_shutdown_function(array($this, "deldir"), $delDir);
                 $this->convertSelectionToTmpFiles($tmpDir, $selection);
             }
             $zip = false;
             if ($selection->isUnique()) {
                 if (is_dir($this->getPath() . "/" . $selection->getUniqueFile())) {
                     $zip = true;
                     $dir .= "/" . basename($selection->getUniqueFile());
                 }
             } else {
                 $zip = true;
             }
             if ($zip) {
                 // Make a temp zip and send it as download
                 $loggedUser = AuthService::getLoggedUser();
                 $file = USERS_DIR . "/" . ($loggedUser ? $loggedUser->getId() : "shared") . "/" . time() . "tmpDownload.zip";
                 $zipFile = $this->makeZip($selection->getFiles(), $file, $dir);
                 if (!$zipFile) {
                     AJXP_Exception::errorToXml("Error while compressing");
                 }
                 register_shutdown_function("unlink", $file);
                 $localName = (basename($dir) == "" ? "Files" : basename($dir)) . ".zip";
                 $this->readFile($file, "force-download", $localName, false, false);
             } else {
                 $this->readFile($this->getPath() . "/" . $selection->getUniqueFile(), "force-download");
             }
             exit(0);
             break;
         case "compress":
             // Make a temp zip and send it as download
             if (isset($archive_name)) {
                 $localName = SystemTextEncoding::fromUTF8($archive_name);
             } else {
                 $localName = (basename($dir) == "" ? "Files" : basename($dir)) . ".zip";
             }
             $file = $this->getPath() . "/" . $dir . "/" . $localName;
             $zipFile = $this->makeZip($selection->getFiles(), $file, $dir);
             if (!$zipFile) {
                 AJXP_Exception::errorToXml("Error while compressing file {$localName}");
             }
             $reload_current_node = true;
             $reload_file_list = $localName;
             break;
         case "image_proxy":
             if ($split = UserSelection::detectZip(SystemTextEncoding::fromUTF8($file))) {
                 require_once "server/classes/pclzip.lib.php";
                 $zip = new PclZip($this->getPath() . $split[0]);
                 $data = $zip->extract(PCLZIP_OPT_BY_NAME, substr($split[1], 1), PCLZIP_OPT_EXTRACT_AS_STRING);
                 header("Content-Type: " . Utils::getImageMimeType(basename($split[1])) . "; name=\"" . basename($split[1]) . "\"");
                 header("Content-Length: " . strlen($data[0]["content"]));
                 header('Cache-Control: public');
                 print $data[0]["content"];
             } else {
                 if (isset($get_thumb) && $get_thumb == "true" && $this->driverConf["GENERATE_THUMBNAIL"]) {
                     require_once "server/classes/PThumb.lib.php";
                     $pThumb = new PThumb($this->driverConf["THUMBNAIL_QUALITY"]);
                     if (!$pThumb->isError()) {
                         $pThumb->use_cache = $this->driverConf["USE_THUMBNAIL_CACHE"];
                         $pThumb->cache_dir = $this->driverConf["THUMBNAIL_CACHE_DIR"];
                         $pThumb->fit_thumbnail($this->getPath() . "/" . SystemTextEncoding::fromUTF8($file), 200);
                         if ($pThumb->isError()) {
                             print_r($pThumb->error_array);
                         }
                         exit(0);
                     }
                 }
                 $this->readFile($this->getPath() . "/" . SystemTextEncoding::fromUTF8($file), "image");
             }
             exit(0);
             break;
         case "mp3_proxy":
             if ($split = UserSelection::detectZip(SystemTextEncoding::fromUTF8($file))) {
                 require_once "server/classes/pclzip.lib.php";
                 $zip = new PclZip($this->getPath() . $split[0]);
                 $data = $zip->extract(PCLZIP_OPT_BY_NAME, substr($split[1], 1), PCLZIP_OPT_EXTRACT_AS_STRING);
                 header("Content-Type: audio/mp3; name=\"" . basename($split[1]) . "\"");
                 header("Content-Length: " . strlen($data[0]["content"]));
                 print $data[0]["content"];
             } else {
                 $this->readFile($this->getPath() . "/" . SystemTextEncoding::fromUTF8($file), "mp3");
             }
             exit(0);
             break;
             //------------------------------------
             //	ONLINE EDIT
             //------------------------------------
         //------------------------------------
         //	ONLINE EDIT
         //------------------------------------
         case "edit":
             if (isset($save) && $save == 1 && isset($code)) {
                 // Reload "code" variable directly from POST array, do not "securePath"...
                 $code = $_POST["code"];
                 AJXP_Logger::logAction("Online Edition", array("file" => SystemTextEncoding::fromUTF8($file)));
                 $code = stripslashes($code);
                 $code = str_replace("&lt;", "<", $code);
                 $fileName = $this->getPath() . SystemTextEncoding::fromUTF8("/{$file}");
                 if (!is_file($fileName) || !is_writable($fileName)) {
                     header("Content-Type:text/plain");
                     print !is_writable($fileName) ? "1001" : "1002";
                     exit(1);
                 }
                 $fp = fopen($fileName, "w");
                 fputs($fp, $code);
                 fclose($fp);
                 header("Content-Type:text/plain");
                 print $mess[115];
             } else {
                 $this->readFile($this->getPath() . "/" . SystemTextEncoding::fromUTF8($file), "plain");
             }
             exit(0);
             break;
             //------------------------------------
             //	COPY / MOVE
             //------------------------------------
         //------------------------------------
         //	COPY / MOVE
         //------------------------------------
         case "copy":
         case "move":
             if ($selection->isEmpty()) {
                 $errorMessage = $mess[113];
                 break;
             }
             if ($selection->inZip()) {
                 $tmpDir = dirname($selection->getZipPath()) . "/.tmpExtractDownload";
                 @mkdir($this->getPath() . "/" . $tmpDir);
                 $this->convertSelectionToTmpFiles($tmpDir, $selection);
                 if (is_dir($tmpDir)) {
                     $this->deldir($this->getPath() . "/" . $tmpDir);
                 }
             }
             $success = $error = array();
             $this->copyOrMove($dest, $selection->getFiles(), $error, $success, $action == "move" ? true : false);
             if (count($error)) {
                 $errorMessage = join("\n", $error);
             } else {
                 $logMessage = join("\n", $success);
                 AJXP_Logger::logAction($action == "move" ? "Move" : "Copy", array("files" => $selection, "destination" => $dest));
             }
             $reload_current_node = true;
             if (isset($dest_node)) {
                 $reload_dest_node = $dest_node;
             }
             $reload_file_list = true;
             break;
             //------------------------------------
             //	SUPPRIMER / DELETE
             //------------------------------------
         //------------------------------------
         //	SUPPRIMER / DELETE
         //------------------------------------
         case "delete":
             if ($selection->isEmpty()) {
                 $errorMessage = $mess[113];
                 break;
             }
             $logMessages = array();
             $errorMessage = $this->delete($selection->getFiles(), $logMessages);
             if (count($logMessages)) {
                 $logMessage = join("\n", $logMessages);
             }
             AJXP_Logger::logAction("Delete", array("files" => $selection));
             $reload_current_node = true;
             $reload_file_list = true;
             break;
             //------------------------------------
             //	RENOMMER / RENAME
             //------------------------------------
         //------------------------------------
         //	RENOMMER / RENAME
         //------------------------------------
         case "rename":
             $file = SystemTextEncoding::fromUTF8($file);
             $filename_new = SystemTextEncoding::fromUTF8($filename_new);
             $error = $this->rename($file, $filename_new);
             if ($error != null) {
                 $errorMessage = $error;
                 break;
             }
             $logMessage = SystemTextEncoding::toUTF8($file) . " {$mess['41']} " . SystemTextEncoding::toUTF8($filename_new);
             $reload_current_node = true;
             $reload_file_list = basename($filename_new);
             AJXP_Logger::logAction("Rename", array("original" => $file, "new" => $filename_new));
             break;
             //------------------------------------
             //	CREER UN REPERTOIRE / CREATE DIR
             //------------------------------------
         //------------------------------------
         //	CREER UN REPERTOIRE / CREATE DIR
         //------------------------------------
         case "mkdir":
             $messtmp = "";
             $dirname = Utils::processFileName(SystemTextEncoding::fromUTF8($dirname));
             $error = $this->mkDir($dir, $dirname);
             if (isset($error)) {
                 $errorMessage = $error;
                 break;
             }
             $reload_file_list = $dirname;
             $messtmp .= "{$mess['38']} " . SystemTextEncoding::toUTF8($dirname) . " {$mess['39']} ";
             if ($dir == "") {
                 $messtmp .= "/";
             } else {
                 $messtmp .= SystemTextEncoding::toUTF8($dir);
             }
             $logMessage = $messtmp;
             $reload_current_node = true;
             AJXP_Logger::logAction("Create Dir", array("dir" => $dir . "/" . $dirname));
             break;
             //------------------------------------
             //	CREER UN FICHIER / CREATE FILE
             //------------------------------------
         //------------------------------------
         //	CREER UN FICHIER / CREATE FILE
         //------------------------------------
         case "mkfile":
             $messtmp = "";
             $filename = Utils::processFileName(SystemTextEncoding::fromUTF8($filename));
             $error = $this->createEmptyFile($dir, $filename);
             if (isset($error)) {
                 $errorMessage = $error;
                 break;
             }
             $messtmp .= "{$mess['34']} " . SystemTextEncoding::toUTF8($filename) . " {$mess['39']} ";
             if ($dir == "") {
                 $messtmp .= "/";
             } else {
                 $messtmp .= SystemTextEncoding::toUTF8($dir);
             }
             $logMessage = $messtmp;
             $reload_file_list = $filename;
             AJXP_Logger::logAction("Create File", array("file" => $dir . "/" . $filename));
             break;
             //------------------------------------
             //	CHANGE FILE PERMISSION
             //------------------------------------
         //------------------------------------
         //	CHANGE FILE PERMISSION
         //------------------------------------
         case "chmod":
             $messtmp = "";
             $files = $selection->getFiles();
             $changedFiles = array();
             foreach ($files as $fileName) {
                 $error = $this->chmod($this->getPath() . $fileName, $chmod_value, $recursive == "on", $recursive == "on" ? $recur_apply_to : "both", $changedFiles);
             }
             if (isset($error)) {
                 $errorMessage = $error;
                 break;
             }
             //$messtmp.="$mess[34] ".SystemTextEncoding::toUTF8($filename)." $mess[39] ";
             $logMessage = "Successfully changed permission to " . $chmod_value . " for " . count($changedFiles) . " files or folders";
             $reload_file_list = $dir;
             AJXP_Logger::logAction("Chmod", array("dir" => $dir, "filesCount" => count($changedFiles)));
             break;
             //------------------------------------
             //	UPLOAD
             //------------------------------------
         //------------------------------------
         //	UPLOAD
         //------------------------------------
         case "upload":
             $fancyLoader = false;
             if (isset($fileVars["Filedata"])) {
                 $fancyLoader = true;
                 if ($dir != "") {
                     $dir = "/" . base64_decode($dir);
                 }
             }
             if ($dir != "") {
                 $rep_source = "/{$dir}";
             } else {
                 $rep_source = "";
             }
             $destination = SystemTextEncoding::fromUTF8($this->getPath() . $rep_source);
             if (!$this->isWriteable($destination)) {
                 global $_GET;
                 $errorMessage = "{$mess['38']} " . SystemTextEncoding::toUTF8($dir) . " {$mess['99']}.";
                 if ($fancyLoader || isset($_GET["ajxp_sessid"])) {
                     header('HTTP/1.0 412 ' . $errorMessage);
                     die('Error 412 ' . $errorMessage);
                 } else {
                     print "\n if(parent.ajaxplorer.actionBar.multi_selector)parent.ajaxplorer.actionBar.multi_selector.submitNext('" . str_replace("'", "\\'", $errorMessage) . "');";
                     break;
                 }
             }
             $logMessage = "";
             foreach ($fileVars as $boxName => $boxData) {
                 if ($boxName != "Filedata" && substr($boxName, 0, 9) != "userfile_") {
                     continue;
                 }
                 if ($boxName == "Filedata") {
                     $fancyLoader = true;
                 }
                 $err = Utils::parseFileDataErrors($boxData, $fancyLoader);
                 if ($err != null) {
                     $errorMessage = $err;
                     break;
                 }
                 $userfile_name = $boxData["name"];
                 if ($fancyLoader) {
                     $userfile_name = SystemTextEncoding::fromUTF8($userfile_name);
                 }
                 $userfile_name = Utils::processFileName($userfile_name);
                 if (isset($auto_rename)) {
                     $userfile_name = fsDriver::autoRenameForDest($destination, $userfile_name);
                 }
                 if (!move_uploaded_file($boxData["tmp_name"], "{$destination}/" . $userfile_name)) {
                     $errorMessage = ($fancyLoader ? "411 " : "") . "{$mess['33']} " . $userfile_name;
                     break;
                 }
                 $this->changeMode($destination . "/" . $userfile_name);
                 $logMessage .= "{$mess['34']} " . SystemTextEncoding::toUTF8($userfile_name) . " {$mess['35']} {$dir}";
                 AJXP_Logger::logAction("Upload File", array("file" => SystemTextEncoding::fromUTF8($dir) . "/" . $userfile_name));
             }
             if ($fancyLoader) {
                 if (isset($errorMessage)) {
                     header('HTTP/1.0 ' . $errorMessage);
                     die('Error ' . $errorMessage);
                 } else {
                     header('HTTP/1.0 200 OK');
                     die("200 OK");
                 }
             } else {
                 print "<html><script language=\"javascript\">\n";
                 if (isset($errorMessage)) {
                     print "\n if(parent.ajaxplorer.actionBar.multi_selector)parent.ajaxplorer.actionBar.multi_selector.submitNext('" . str_replace("'", "\\'", $errorMessage) . "');";
                 } else {
                     print "\n if(parent.ajaxplorer.actionBar.multi_selector)parent.ajaxplorer.actionBar.multi_selector.submitNext();";
                 }
                 print "</script></html>";
             }
             exit;
             break;
             //------------------------------------
             // Public URL
             //------------------------------------
         //------------------------------------
         // Public URL
         //------------------------------------
         case "public_url":
             $file = SystemTextEncoding::fromUTF8($file);
             $url = $this->makePubliclet($file, $password, $expiration);
             header("Content-type:text/plain");
             echo $url;
             exit(1);
             break;
             //------------------------------------
             //	XML LISTING
             //------------------------------------
         //------------------------------------
         //	XML LISTING
         //------------------------------------
         case "ls":
             if (!isset($dir) || $dir == "/") {
                 $dir = "";
             }
             $searchMode = $fileListMode = $completeMode = false;
             if (isset($mode)) {
                 if ($mode == "search") {
                     $searchMode = true;
                 } else {
                     if ($mode == "file_list") {
                         $fileListMode = true;
                     } else {
                         if ($mode == "complete") {
                             $completeMode = true;
                         }
                     }
                 }
             }
             if (isset($skipZip) && $skipZip == "true") {
                 $skipZip = true;
             } else {
                 $skipZip = false;
             }
             if ($test = UserSelection::detectZip($dir)) {
                 $liste = array();
                 $zip = $this->zipListing($test[0], $test[1], $liste);
                 AJXP_XMLWriter::header();
                 $tmpDir = $this->getPath() . dirname($test[0]) . ".tmpZipExtract";
                 foreach ($liste as $zipEntry) {
                     $atts = array();
                     if (!$fileListMode && !$zipEntry["folder"]) {
                         continue;
                     }
                     $atts[] = "is_file=\"" . ($zipEntry["folder"] ? "false" : "true") . "\"";
                     $atts[] = "text=\"" . Utils::xmlEntities(basename(SystemTextEncoding::toUTF8($zipEntry["stored_filename"]))) . "\"";
                     $atts[] = "filename=\"" . Utils::xmlEntities(SystemTextEncoding::toUTF8($zipEntry["filename"])) . "\"";
                     if ($fileListMode) {
                         $atts[] = "filesize=\"" . Utils::roundSize($zipEntry["size"]) . "\"";
                         $atts[] = "bytesize=\"" . $zipEntry["size"] . "\"";
                         $atts[] = "ajxp_modiftime=\"" . $zipEntry["mtime"] . "\"";
                         $atts[] = "mimestring=\"" . Utils::mimetype($zipEntry["stored_filename"], "mime", $zipEntry["folder"]) . "\"";
                         $atts[] = "icon=\"" . Utils::mimetype($zipEntry["stored_filename"], "image", $zipEntry["folder"]) . "\"";
                         $is_image = Utils::is_image(basename($zipEntry["stored_filename"]));
                         $atts[] = "is_image=\"" . $is_image . "\"";
                         if ($is_image) {
                             if (!is_dir($tmpDir)) {
                                 mkdir($tmpDir);
                             }
                             $currentFile = $tmpDir . "/" . basename($zipEntry["stored_filename"]);
                             $data = $zip->extract(PCLZIP_OPT_BY_NAME, $zipEntry["stored_filename"], PCLZIP_OPT_REMOVE_ALL_PATH, PCLZIP_OPT_PATH, $tmpDir);
                             list($width, $height, $type, $attr) = @getimagesize($currentFile);
                             $atts[] = "image_type=\"" . image_type_to_mime_type($type) . "\"";
                             $atts[] = "image_width=\"{$width}\"";
                             $atts[] = "image_height=\"{$height}\"";
                             unlink($currentFile);
                         }
                     } else {
                         $atts[] = "icon=\"client/images/foldericon.png\"";
                         $atts[] = "openicon=\"client/images/foldericon.png\"";
                         $atts[] = "src=\"content.php?dir=" . urlencode(SystemTextEncoding::toUTF8($zipEntry["filename"])) . "\"";
                     }
                     print "<tree " . join(" ", $atts) . "/>";
                 }
                 if (is_dir($tmpDir)) {
                     rmdir($tmpDir);
                 }
                 AJXP_XMLWriter::close();
                 exit(0);
             }
             $nom_rep = $this->initName($dir);
             AJXP_Exception::errorToXml($nom_rep);
             $threshold = $this->repository->getOption("PAGINATION_THRESHOLD");
             if (!isset($threshold) || intval($threshold) == 0) {
                 $threshold = 500;
             }
             $limitPerPage = $this->repository->getOption("PAGINATION_NUMBER");
             if (!isset($limitPerPage) || intval($limitPerPage) == 0) {
                 $limitPerPage = 200;
             }
             if ($fileListMode) {
                 $countFiles = $this->countFiles($nom_rep);
                 if ($countFiles > $threshold) {
                     $offset = 0;
                     $crtPage = 1;
                     if (isset($page)) {
                         $offset = (intval($page) - 1) * $limitPerPage;
                         $crtPage = $page;
                     }
                     $totalPages = floor($countFiles / $limitPerPage) + 1;
                     $reps = $this->listing($nom_rep, false, $offset, $limitPerPage);
                 } else {
                     $reps = $this->listing($nom_rep, $searchMode);
                 }
             } else {
                 $countFolders = $this->countFiles($nom_rep, true);
                 if ($countFolders > $threshold) {
                     AJXP_XMLWriter::header();
                     $icon = CLIENT_RESOURCES_FOLDER . "/images/foldericon.png";
                     $openicon = CLIENT_RESOURCES_FOLDER . "/images/openfoldericon.png";
                     $attributes = "icon=\"{$icon}\"  openicon=\"{$openicon}\"";
                     print "<tree text=\"{$mess['306']} ({$countFolders})...\" {$attributes}></tree>";
                     AJXP_XMLWriter::close();
                     exit(1);
                 }
                 $reps = $this->listing($nom_rep, !$searchMode);
             }
             //$reps = $result[0];
             AJXP_XMLWriter::header();
             if (isset($totalPages) && isset($crtPage)) {
                 //print '<columns switchDisplayMode="list" switchGridMode="filelist"/>';
                 print '<pagination count="' . $countFiles . '" total="' . $totalPages . '" current="' . $crtPage . '"/>';
             }
             foreach ($reps as $repIndex => $repName) {
                 if (preg_match("/\\.zip\$/", $repName) && $skipZip) {
                     continue;
                 }
                 $attributes = "";
                 if ($searchMode) {
                     if (is_file($nom_rep . "/" . $repIndex)) {
                         $attributes = "is_file=\"true\" icon=\"{$repName}\"";
                         $repName = $repIndex;
                     }
                 } else {
                     if ($fileListMode) {
                         $currentFile = $nom_rep . "/" . $repIndex;
                         $atts = array();
                         $atts[] = "is_file=\"" . (is_file($currentFile) ? "1" : "0") . "\"";
                         $atts[] = "is_image=\"" . Utils::is_image($currentFile) . "\"";
                         $fGroup = @filegroup($currentFile) || "unknown";
                         $atts[] = "file_group=\"" . $fGroup . "\"";
                         $fOwner = @fileowner($currentFile) || "unknown";
                         $atts[] = "file_owner=\"" . $fOwner . "\"";
                         $fPerms = @fileperms($currentFile);
                         if ($fPerms !== false) {
                             $fPerms = substr(decoct($fPerms), is_file($currentFile) ? 2 : 1);
                         } else {
                             $fPerms = '0000';
                         }
                         $atts[] = "file_perms=\"" . $fPerms . "\"";
                         if (Utils::is_image($currentFile)) {
                             list($width, $height, $type, $attr) = @getimagesize($currentFile);
                             $atts[] = "image_type=\"" . image_type_to_mime_type($type) . "\"";
                             $atts[] = "image_width=\"{$width}\"";
                             $atts[] = "image_height=\"{$height}\"";
                         }
                         $atts[] = "mimestring=\"" . Utils::mimetype($currentFile, "type", is_dir($currentFile)) . "\"";
                         $datemodif = $this->date_modif($currentFile);
                         $atts[] = "ajxp_modiftime=\"" . ($datemodif ? $datemodif : "0") . "\"";
                         $bytesize = @filesize($currentFile) or 0;
                         if ($bytesize < 0) {
                             $bytesize = sprintf("%u", $bytesize);
                         }
                         $atts[] = "filesize=\"" . Utils::roundSize($bytesize) . "\"";
                         $atts[] = "bytesize=\"" . $bytesize . "\"";
                         $atts[] = "filename=\"" . Utils::xmlEntities(SystemTextEncoding::toUTF8($dir . "/" . $repIndex)) . "\"";
                         $atts[] = "icon=\"" . (is_file($currentFile) ? SystemTextEncoding::toUTF8($repName) : (is_dir($currentFile) ? "folder.png" : "mime-empty.png")) . "\"";
                         $attributes = join(" ", $atts);
                         $repName = $repIndex;
                     } else {
                         $folderBaseName = Utils::xmlEntities($repName);
                         $link = SystemTextEncoding::toUTF8(SERVER_ACCESS . "?dir=" . $dir . "/" . $folderBaseName);
                         $link = urlencode($link);
                         $folderFullName = Utils::xmlEntities($dir) . "/" . $folderBaseName;
                         $parentFolderName = $dir;
                         if (!$completeMode) {
                             $icon = CLIENT_RESOURCES_FOLDER . "/images/foldericon.png";
                             $openicon = CLIENT_RESOURCES_FOLDER . "/images/openfoldericon.png";
                             if (preg_match("/\\.zip\$/", $repName)) {
                                 $icon = $openicon = CLIENT_RESOURCES_FOLDER . "/images/crystal/actions/16/accessories-archiver.png";
                             }
                             $attributes = "icon=\"{$icon}\"  openicon=\"{$openicon}\" filename=\"" . SystemTextEncoding::toUTF8($folderFullName) . "\" src=\"{$link}\"";
                         }
                     }
                 }
                 print "<tree text=\"" . Utils::xmlEntities(SystemTextEncoding::toUTF8($repName)) . "\" {$attributes}>";
                 print "</tree>";
             }
             // ADD RECYCLE BIN TO THE LIST
             if ($nom_rep == $this->repository->getOption("PATH") && RecycleBinManager::recycleEnabled() && !$completeMode && !$skipZip) {
                 $recycleBinOption = $this->repository->getOption("RECYCLE_BIN");
                 if (is_dir($this->repository->getOption("PATH") . "/" . $recycleBinOption)) {
                     $recycleIcon = $this->countFiles($this->repository->getOption("PATH") . "/" . $recycleBinOption, false, true) > 0 ? "trashcan_full.png" : "trashcan.png";
                     if ($fileListMode) {
                         print "<tree text=\"" . Utils::xmlEntities($mess[122]) . "\" filesize=\"-\" is_file=\"0\" is_recycle=\"1\" mimestring=\"Trashcan\" ajxp_modiftime=\"" . $this->date_modif($this->repository->getOption("PATH") . "/" . $recycleBinOption) . "\" filename=\"/" . $recycleBinOption . "\" icon=\"{$recycleIcon}\"></tree>";
                     } else {
                         print "<tree text=\"{$mess['122']}\" is_recycle=\"true\" icon=\"" . CLIENT_RESOURCES_FOLDER . "/images/crystal/mimes/16/{$recycleIcon}\"  openIcon=\"" . CLIENT_RESOURCES_FOLDER . "/images/crystal/mimes/16/{$recycleIcon}\" filename=\"/" . $recycleBinOption . "\"/>";
                     }
                 }
             }
             AJXP_XMLWriter::close();
             exit(1);
             break;
     }
     if (isset($logMessage) || isset($errorMessage)) {
         $xmlBuffer .= AJXP_XMLWriter::sendMessage(isset($logMessage) ? $logMessage : null, isset($errorMessage) ? $errorMessage : null, false);
     }
     if (isset($requireAuth)) {
         $xmlBuffer .= AJXP_XMLWriter::requireAuth(false);
     }
     if (isset($reload_current_node) && $reload_current_node == "true") {
         $xmlBuffer .= AJXP_XMLWriter::reloadCurrentNode(false);
     }
     if (isset($reload_dest_node) && $reload_dest_node != "") {
         $xmlBuffer .= AJXP_XMLWriter::reloadNode($reload_dest_node, false);
     }
     if (isset($reload_file_list)) {
         $xmlBuffer .= AJXP_XMLWriter::reloadFileList($reload_file_list, false);
     }
     return $xmlBuffer;
 }
 function switchAction($action, $httpVars, $fileVars)
 {
     if (!isset($this->actions[$action])) {
         return;
     }
     $xmlBuffer = "";
     foreach ($httpVars as $getName => $getValue) {
         ${$getName} = Utils::securePath(SystemTextEncoding::magicDequote($getValue));
     }
     $selection = new UserSelection();
     $selection->initFromHttpVars($httpVars);
     if (isset($dir) && $action != "upload") {
         $safeDir = $dir;
         $dir = SystemTextEncoding::fromUTF8($dir);
     }
     if (isset($dest)) {
         $dest = SystemTextEncoding::fromUTF8($dest);
     }
     $mess = ConfService::getMessages();
     if (class_exists("RecycleBinManager")) {
         $newArgs = RecycleBinManager::filterActions($action, $selection, $dir);
         foreach ($newArgs as $argName => $argValue) {
             ${$argName} = $argValue;
         }
     }
     switch ($action) {
         //------------------------------------
         //	DOWNLOAD, IMAGE & MP3 PROXYS
         //------------------------------------
         case "download":
         case "image_proxy":
         case "mp3_proxy":
             AJXP_Logger::logAction("Download", array("files" => $selection));
             $this->sendRemoteFile($selection->files[0], $action == "download");
             exit(0);
             break;
             //------------------------------------
             //	ONLINE EDIT
             //------------------------------------
         //------------------------------------
         //	ONLINE EDIT
         //------------------------------------
         case "edit":
             $file_name = basename($file);
             $this->ftp_get_contents($file);
             if (isset($save) && $save == 1 && isset($code)) {
                 // Reload "code" variable directly from POST array, do not "securePath"...
                 $code = $_POST["code"];
                 AJXP_Logger::logAction("Online Edition", array("file" => SystemTextEncoding::fromUTF8($file_name)));
                 $code = stripslashes($code);
                 $code = str_replace("&lt;", "<", $code);
                 $fp = fopen("files/" . SystemTextEncoding::fromUTF8("{$file_name}"), "w");
                 fputs($fp, $code);
                 fclose($fp);
                 echo $mess[115];
                 ftp_put($this->connect, $this->secureFtpPath($this->getPath() . $file), "files/" . SystemTextEncoding::fromUTF8($file_name), FTP_BINARY);
                 $this->ftpRemoveFileTmp("files/" . SystemTextEncoding::fromUTF8("{$file_name}"));
                 $reload_current_node = true;
             } else {
                 $this->readFile("files/" . SystemTextEncoding::fromUTF8($file_name), "plain");
             }
             exit(0);
             break;
             //------------------------------------
             //	COPY / MOVE
             //------------------------------------
         //------------------------------------
         //	COPY / MOVE
         //------------------------------------
         case "copy":
         case "move":
             if ($selection->isEmpty()) {
                 $errorMessage = $mess[113];
                 break;
             }
             $this->copyOrMove($dest, $selection->getFiles(), $error, $success, $action == "move" ? true : false);
             if (count($error)) {
                 $errorMessage = join("\n", $error);
             } else {
                 $logMessage = join("\n", $success);
             }
             $reload_current_node = true;
             if (isset($dest_node)) {
                 $reload_dest_node = $dest_node;
             }
             $reload_file_list = true;
             break;
             //------------------------------------
             //	SUPPRIMER / DELETE
             //------------------------------------
         //------------------------------------
         //	SUPPRIMER / DELETE
         //------------------------------------
         case "delete":
             if ($selection->isEmpty()) {
                 $errorMessage = $mess[113];
                 break;
             }
             $logMessages = array();
             $errorMessage = $this->delete($selection->getFiles(), $logMessages, $dir);
             if (count($logMessages)) {
                 $logMessage = join("\n", $logMessages);
             }
             AJXP_Logger::logAction("Delete", array("files" => $selection));
             $reload_current_node = true;
             $reload_file_list = true;
             break;
             //------------------------------------
             //	RENOMMER / RENAME
             //------------------------------------
         //------------------------------------
         //	RENOMMER / RENAME
         //------------------------------------
         case "rename":
             $file = SystemTextEncoding::fromUTF8($file);
             $filename_new = SystemTextEncoding::fromUTF8($filename_new);
             $error = $this->rename($file, $filename_new);
             if ($error != null) {
                 $errorMessage = $error;
                 break;
             }
             $logMessage = SystemTextEncoding::toUTF8($file) . " {$mess['41']} " . SystemTextEncoding::toUTF8($filename_new);
             $reload_current_node = true;
             $reload_file_list = basename($filename_new);
             AJXP_Logger::logAction("Rename", array("original" => $file, "new" => $filename_new));
             break;
             //------------------------------------
             //	CREER UN REPERTOIRE / CREATE DIR
             //------------------------------------
         //------------------------------------
         //	CREER UN REPERTOIRE / CREATE DIR
         //------------------------------------
         case "mkdir":
             $messtmp = "";
             $dirname = Utils::processFileName(SystemTextEncoding::fromUTF8($dirname));
             $error = $this->mkDir($dir, $dirname);
             if (isset($error)) {
                 $errorMessage = $error;
                 break;
             }
             $reload_file_list = $dirname;
             $messtmp .= "{$mess['38']} " . SystemTextEncoding::toUTF8($dirname) . " {$mess['39']} ";
             if ($dir == "") {
                 $messtmp .= "/";
             } else {
                 $messtmp .= SystemTextEncoding::toUTF8($dir);
             }
             $logMessage = $messtmp;
             $reload_current_node = true;
             AJXP_Logger::logAction("Create Dir", array("dir" => $dir . "/" . $dirname));
             break;
             //------------------------------------
             //	CREER UN FICHIER / CREATE FILE
             //------------------------------------
         //------------------------------------
         //	CREER UN FICHIER / CREATE FILE
         //------------------------------------
         case "mkfile":
             $messtmp = "";
             $filename = Utils::processFileName(SystemTextEncoding::fromUTF8($filename));
             $error = $this->createEmptyFile($dir, $filename);
             if (isset($error)) {
                 $errorMessage = $error;
                 break;
             }
             $messtmp .= "{$mess['34']} " . SystemTextEncoding::toUTF8($filename) . " {$mess['39']} ";
             if ($dir == "") {
                 $messtmp .= "/";
             } else {
                 $messtmp .= SystemTextEncoding::toUTF8($dir);
             }
             $logMessage = $messtmp;
             $reload_file_list = $filename;
             AJXP_Logger::logAction("Create File", array("file" => $dir . "/" . $filename));
             break;
             //------------------------------------
             //	CHANGE FILE PERMISSION
             //------------------------------------
         //------------------------------------
         //	CHANGE FILE PERMISSION
         //------------------------------------
         case "chmod":
             $files = $selection->getFiles();
             if (@ftp_chmod($this->connect, $chmod_value, $this->getPath() . $files[0]) === false) {
                 $error = "Error chmod";
             }
             if (isset($error)) {
                 $errorMessage = $error;
                 break;
             }
             $logMessage = "Successfully changed permission to " . $chmod_value . " for " . $files[0];
             $reload_file_list = $dir;
             AJXP_Logger::logAction("Chmod", array("dir" => $dir, "file" => $files[0]));
             break;
             //------------------------------------
             //	UPLOAD
             //------------------------------------
         //------------------------------------
         //	UPLOAD
         //------------------------------------
         case "upload":
             break;
             //------------------------------------
             // Public URL
             //------------------------------------
         //------------------------------------
         // Public URL
         //------------------------------------
         case "public_url":
             $file = SystemTextEncoding::fromUTF8($file);
             $url = $this->makePubliclet($file, $password, $expiration);
             header("Content-type:text/plain");
             echo $url;
             exit(1);
             break;
             //------------------------------------
             //	XML LISTING
             //------------------------------------
         //------------------------------------
         //	XML LISTING
         //------------------------------------
         case "ls":
             if (!isset($dir) || $dir == "/") {
                 $dir = "";
             }
             $searchMode = $fileListMode = $completeMode = false;
             if (isset($mode)) {
                 if ($mode == "search") {
                     $searchMode = true;
                 } else {
                     if ($mode == "file_list") {
                         $fileListMode = true;
                     } else {
                         if ($mode == "complete") {
                             $completeMode = true;
                         }
                     }
                 }
             }
             if (isset($skipZip) && $skipZip == "true") {
                 $skipZip = true;
             } else {
                 $skipZip = false;
             }
             if ($test = UserSelection::detectZip($dir)) {
                 $liste = array();
                 $zip = $this->zipListing($test[0], $test[1], $liste);
                 AJXP_XMLWriter::header();
                 $tmpDir = $this->getPath() . dirname($test[0]) . ".tmpZipExtract";
                 foreach ($liste as $zipEntry) {
                     $atts = array();
                     if (!$fileListMode && !$zipEntry["folder"]) {
                         continue;
                     }
                     $atts[] = "is_file=\"" . ($zipEntry["folder"] ? "false" : "true") . "\"";
                     $atts[] = "text=\"" . str_replace("&", "&amp;", basename(SystemTextEncoding::toUTF8($zipEntry["stored_filename"]))) . "\"";
                     $atts[] = "filename=\"" . str_replace("&", "&amp;", SystemTextEncoding::toUTF8($zipEntry["filename"])) . "\"";
                     if ($fileListMode) {
                         $atts[] = "filesize=\"" . Utils::roundSize($zipEntry["size"]) . "\"";
                         $atts[] = "bytesize=\"" . $zipEntry["size"] . "\"";
                         $atts[] = "ajxp_modiftime=\"" . $zipEntry["mtime"] . "\"";
                         $atts[] = "mimestring=\"" . Utils::mimetype($zipEntry["stored_filename"], "mime", $zipEntry["folder"]) . "\"";
                         $atts[] = "icon=\"" . Utils::mimetype($zipEntry["stored_filename"], "image", $zipEntry["folder"]) . "\"";
                         $is_image = Utils::is_image(basename($zipEntry["stored_filename"]));
                         $atts[] = "is_image=\"" . $is_image . "\"";
                         if ($is_image) {
                             if (!is_dir($tmpDir)) {
                                 mkdir($tmpDir);
                             }
                             $currentFile = $tmpDir . "/" . basename($zipEntry["stored_filename"]);
                             $data = $zip->extract(PCLZIP_OPT_BY_NAME, $zipEntry["stored_filename"], PCLZIP_OPT_REMOVE_ALL_PATH, PCLZIP_OPT_PATH, $tmpDir);
                             list($width, $height, $type, $attr) = @getimagesize($currentFile);
                             $atts[] = "image_type=\"" . image_type_to_mime_type($type) . "\"";
                             $atts[] = "image_width=\"{$width}\"";
                             $atts[] = "image_height=\"{$height}\"";
                             unlink($currentFile);
                         }
                     } else {
                         $atts[] = "icon=\"client/images/foldericon.png\"";
                         $atts[] = "openicon=\"client/images/foldericon.png\"";
                         $atts[] = "src=\"content.php?dir=" . urlencode(SystemTextEncoding::toUTF8($zipEntry["filename"])) . "\"";
                     }
                     print "<tree " . join(" ", $atts) . "/>";
                     if (is_dir($tmpDir)) {
                         rmdir($tmpDir);
                     }
                 }
                 AJXP_XMLWriter::close();
                 exit(0);
             }
             $nom_rep = $this->initName($dir);
             AJXP_Exception::errorToXml($nom_rep);
             $result = $this->listing($nom_rep, !($searchMode || $fileListMode));
             $this->fileListData = $result[0];
             $reps = $result[0];
             AJXP_XMLWriter::header();
             if (!is_array($reps)) {
                 AJXP_XMLWriter::close();
                 exit(1);
             }
             foreach ($reps as $repIndex => $repName) {
                 if (is_string($repName) && (preg_match("/\\.zip\$/", $repName) && $skipZip)) {
                     continue;
                 }
                 $attributes = "";
                 if ($searchMode) {
                     if (is_file($nom_rep . "/" . $repIndex)) {
                         $attributes = "is_file=\"true\" icon=\"{$repName}\"";
                         $repName = $repIndex;
                     }
                 } else {
                     if ($fileListMode) {
                         $currentFile = $nom_rep . "/" . $repName['name'];
                         $atts = array();
                         $atts[] = "is_file=\"" . ($repName['isDir'] ? "0" : "1") . "\"";
                         $atts[] = "is_image=\"" . Utils::is_image($currentFile) . "\"";
                         $atts[] = "file_group=\"" . $repName['group'] . "\"";
                         $atts[] = "file_owner=\"" . $repName['owner'] . "\"";
                         $atts[] = "file_perms=\"" . $repName['chmod1'] . "\"";
                         if (Utils::is_image($currentFile)) {
                             list($width, $height, $type, $attr) = $this->getimagesize($currentFile);
                             $atts[] = "image_type=\"" . image_type_to_mime_type($type) . "\"";
                             $atts[] = "image_width=\"{$width}\"";
                             $atts[] = "image_height=\"{$height}\"";
                         }
                         $atts[] = "mimestring=\"" . $repName['type'] . "\"";
                         $datemodif = $repName['modifTime'];
                         $atts[] = "ajxp_modiftime=\"" . ($datemodif ? $datemodif : "0") . "\"";
                         $bytesize = $repName['size'] or 0;
                         if ($bytesize < 0) {
                             $bytesize = sprintf("%u", $bytesize);
                         }
                         $atts[] = "filesize=\"" . Utils::roundSize($bytesize) . "\"";
                         $atts[] = "bytesize=\"" . $bytesize . "\"";
                         $atts[] = "filename=\"" . str_replace("&", "&amp;", SystemTextEncoding::toUTF8($dir . "/" . $repIndex)) . "\"";
                         $atts[] = "icon=\"" . $repName['icon'] . "\"";
                         $attributes = join(" ", $atts);
                         $repName = $repIndex;
                     } else {
                         //Menu treeview repertoire
                         $folderBaseName = str_replace("&", "&amp;", $repName['name']);
                         $link = SystemTextEncoding::toUTF8(SERVER_ACCESS . "?dir=" . $dir . "/" . $folderBaseName);
                         $link = urlencode($link);
                         $folderFullName = str_replace("&", "&amp;", $dir) . "/" . $folderBaseName;
                         $parentFolderName = $dir;
                         $repName = $repIndex;
                         if (!$completeMode) {
                             $icon = CLIENT_RESOURCES_FOLDER . "/images/foldericon.png";
                             $openicon = CLIENT_RESOURCES_FOLDER . "/images/openfoldericon.png";
                             if (preg_match("/\\.zip\$/", $repName)) {
                                 $icon = $openicon = CLIENT_RESOURCES_FOLDER . "/images/crystal/actions/16/accessories-archiver.png";
                             }
                             $attributes = "icon=\"{$icon}\"  openicon=\"{$openicon}\" filename=\"" . SystemTextEncoding::toUTF8($folderFullName) . "\" src=\"{$link}\"";
                         }
                     }
                 }
                 print "<tree text=\"" . str_replace("&", "&amp;", SystemTextEncoding::toUTF8($repName)) . "\" {$attributes}>";
                 print "</tree>";
             }
             // ADD RECYCLE BIN TO THE LIST
             if ($nom_rep == $this->repository->getOption("PATH") && RecycleBinManager::recycleEnabled() && !$completeMode && !$skipZip) {
                 $recycleBinOption = $this->repository->getOption("RECYCLE_BIN");
                 if ($fileListMode) {
                     print "<tree text=\"" . Utils::xmlEntities($mess[122]) . "\" filesize=\"-\" is_file=\"0\" is_recycle=\"1\" mimestring=\"Trashcan\" ajxp_modiftime=\"\" filename=\"/" . $recycleBinOption . "\" icon=\"trashcan.png\"></tree>";
                 } else {
                     print "<tree text=\"{$mess['122']}\" is_recycle=\"true\" icon=\"" . CLIENT_RESOURCES_FOLDER . "/images/crystal/mimes/16/trashcan.png\"  openIcon=\"" . CLIENT_RESOURCES_FOLDER . "/images/crystal/mimes/16/trashcan.png\" filename=\"/" . $recycleBinOption . "\"/>";
                 }
             }
             AJXP_XMLWriter::close();
             exit(1);
             break;
     }
     if (isset($logMessage) || isset($errorMessage)) {
         $xmlBuffer .= AJXP_XMLWriter::sendMessage(isset($logMessage) ? $logMessage : null, isset($errorMessage) ? $errorMessage : null, false);
     }
     if (isset($requireAuth)) {
         $xmlBuffer .= AJXP_XMLWriter::requireAuth(false);
     }
     if (isset($reload_current_node) && $reload_current_node == "true") {
         $xmlBuffer .= AJXP_XMLWriter::reloadCurrentNode(false);
     }
     if (isset($reload_dest_node) && $reload_dest_node != "") {
         $xmlBuffer .= AJXP_XMLWriter::reloadNode($reload_dest_node, false);
     }
     if (isset($reload_file_list)) {
         $xmlBuffer .= AJXP_XMLWriter::reloadFileList($reload_file_list, false);
     }
     return $xmlBuffer;
 }