aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/ajax
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2014-03-21 14:05:08 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2014-03-21 14:05:08 +0100
commit6ff96b34ad0462ad05c34633ccd08236b93bf195 (patch)
tree1acd7eb869d512b5a3fc9502961a98591ea20cfa /apps/files/ajax
parente139f7c863d5971a6386070148496cb0f70ad04e (diff)
parent37af74efb3e3511b2d6eacef67dc90f22a685bd3 (diff)
downloadnextcloud-server-6ff96b34ad0462ad05c34633ccd08236b93bf195.tar.gz
nextcloud-server-6ff96b34ad0462ad05c34633ccd08236b93bf195.zip
Merge branch 'master' into load-apps-proper-master
Conflicts: apps/files/ajax/rawlist.php cron.php ocs/v1.php
Diffstat (limited to 'apps/files/ajax')
-rw-r--r--apps/files/ajax/delete.php20
-rw-r--r--apps/files/ajax/download.php1
-rw-r--r--apps/files/ajax/getstoragestats.php1
-rw-r--r--apps/files/ajax/list.php6
-rw-r--r--apps/files/ajax/mimeicon.php1
-rw-r--r--apps/files/ajax/move.php6
-rw-r--r--apps/files/ajax/newfile.php17
-rw-r--r--apps/files/ajax/newfolder.php5
-rw-r--r--apps/files/ajax/rawlist.php59
-rw-r--r--apps/files/ajax/rename.php1
-rw-r--r--apps/files/ajax/scan.php2
-rw-r--r--apps/files/ajax/upgrade.php44
-rw-r--r--apps/files/ajax/upload.php19
13 files changed, 85 insertions, 97 deletions
diff --git a/apps/files/ajax/delete.php b/apps/files/ajax/delete.php
index c69f5a8860c..f6aa4f0c90e 100644
--- a/apps/files/ajax/delete.php
+++ b/apps/files/ajax/delete.php
@@ -1,16 +1,28 @@
<?php
-// Init owncloud
-
-
OCP\JSON::checkLoggedIn();
OCP\JSON::callCheck();
+\OC::$session->close();
+
// Get data
$dir = stripslashes($_POST["dir"]);
$files = isset($_POST["file"]) ? $_POST["file"] : $_POST["files"];
+$allFiles = isset($_POST["allfiles"]) ? $_POST["allfiles"] : false;
+if ($allFiles === 'true') {
+ $allFiles = true;
+}
-$files = json_decode($files);
+// delete all files in dir ?
+if ($allFiles) {
+ $files = array();
+ $fileList = \OC\Files\Filesystem::getDirectoryContent($dir);
+ foreach ($fileList as $fileInfo) {
+ $files[] = $fileInfo['name'];
+ }
+} else {
+ $files = json_decode($files);
+}
$filesWithError = '';
$success = true;
diff --git a/apps/files/ajax/download.php b/apps/files/ajax/download.php
index 58037cb0c87..4b4a7f8948d 100644
--- a/apps/files/ajax/download.php
+++ b/apps/files/ajax/download.php
@@ -23,6 +23,7 @@
// Check if we are a user
OCP\User::checkLoggedIn();
+\OC::$session->close();
$files = $_GET["files"];
$dir = $_GET["dir"];
diff --git a/apps/files/ajax/getstoragestats.php b/apps/files/ajax/getstoragestats.php
index 69a26ed8eb3..dd8af39bada 100644
--- a/apps/files/ajax/getstoragestats.php
+++ b/apps/files/ajax/getstoragestats.php
@@ -7,6 +7,7 @@ if (isset($_GET['dir'])) {
}
OCP\JSON::checkLoggedIn();
+\OC::$session->close();
// send back json
OCP\JSON::success(array('data' => \OCA\Files\Helper::buildFileStorageStatistics($dir)));
diff --git a/apps/files/ajax/list.php b/apps/files/ajax/list.php
index 3617cd426cc..3bb35579d5f 100644
--- a/apps/files/ajax/list.php
+++ b/apps/files/ajax/list.php
@@ -1,11 +1,13 @@
<?php
OCP\JSON::checkLoggedIn();
+\OC::$session->close();
// Load the files
$dir = isset( $_GET['dir'] ) ? $_GET['dir'] : '';
$dir = \OC\Files\Filesystem::normalizePath($dir);
-if (!\OC\Files\Filesystem::is_dir($dir . '/')) {
+$dirInfo = \OC\Files\Filesystem::getFileInfo($dir);
+if (!$dirInfo->getType() === 'dir') {
header("HTTP/1.0 404 Not Found");
exit();
}
@@ -14,7 +16,7 @@ $doBreadcrumb = isset($_GET['breadcrumb']);
$data = array();
$baseUrl = OCP\Util::linkTo('files', 'index.php') . '?dir=';
-$permissions = \OCA\Files\Helper::getDirPermissions($dir);
+$permissions = $dirInfo->getPermissions();
// Make breadcrumb
if($doBreadcrumb) {
diff --git a/apps/files/ajax/mimeicon.php b/apps/files/ajax/mimeicon.php
index dbb8b60112a..6557ff941ac 100644
--- a/apps/files/ajax/mimeicon.php
+++ b/apps/files/ajax/mimeicon.php
@@ -1,3 +1,4 @@
<?php
+\OC::$session->close();
print OC_Helper::mimetypeIcon($_GET['mime']);
diff --git a/apps/files/ajax/move.php b/apps/files/ajax/move.php
index 93063e52eb0..0a8dbc24a65 100644
--- a/apps/files/ajax/move.php
+++ b/apps/files/ajax/move.php
@@ -1,10 +1,8 @@
<?php
-// Init owncloud
-
-
OCP\JSON::checkLoggedIn();
OCP\JSON::callCheck();
+\OC::$session->close();
// Get data
$dir = stripslashes($_POST["dir"]);
@@ -18,7 +16,7 @@ if(\OC\Files\Filesystem::file_exists($target . '/' . $file)) {
exit;
}
-if ($dir != '' || $file != 'Shared') {
+if ($target != '' || strtolower($file) != 'shared') {
$targetFile = \OC\Files\Filesystem::normalizePath($target . '/' . $file);
$sourceFile = \OC\Files\Filesystem::normalizePath($dir . '/' . $file);
if(\OC\Files\Filesystem::rename($sourceFile, $targetFile)) {
diff --git a/apps/files/ajax/newfile.php b/apps/files/ajax/newfile.php
index 1853098c507..1234cf11394 100644
--- a/apps/files/ajax/newfile.php
+++ b/apps/files/ajax/newfile.php
@@ -7,7 +7,8 @@ if(!OC_User::isLoggedIn()) {
exit;
}
-session_write_close();
+\OC::$session->close();
+
// Get the params
$dir = isset( $_REQUEST['dir'] ) ? '/'.trim($_REQUEST['dir'], '/\\') : '';
$filename = isset( $_REQUEST['filename'] ) ? trim($_REQUEST['filename'], '/\\') : '';
@@ -50,16 +51,22 @@ $l10n = \OC_L10n::get('files');
$result = array(
'success' => false,
'data' => NULL
- );
+);
+$trimmedFileName = trim($filename);
-if(trim($filename) === '') {
+if($trimmedFileName === '') {
$result['data'] = array('message' => (string)$l10n->t('File name cannot be empty.'));
OCP\JSON::error($result);
exit();
}
+if($trimmedFileName === '.' || $trimmedFileName === '..') {
+ $result['data'] = array('message' => (string)$l10n->t('"%s" is an invalid file name.', $trimmedFileName));
+ OCP\JSON::error($result);
+ exit();
+}
-if(strpos($filename, '/') !== false) {
- $result['data'] = array('message' => (string)$l10n->t('File name must not contain "/". Please choose a different name.'));
+if(!OCP\Util::isValidFileName($filename)) {
+ $result['data'] = array('message' => (string)$l10n->t("Invalid name, '\\', '/', '<', '>', ':', '\"', '|', '?' and '*' are not allowed."));
OCP\JSON::error($result);
exit();
}
diff --git a/apps/files/ajax/newfolder.php b/apps/files/ajax/newfolder.php
index 4cfcae3090d..032447460f3 100644
--- a/apps/files/ajax/newfolder.php
+++ b/apps/files/ajax/newfolder.php
@@ -5,6 +5,7 @@
OCP\JSON::checkLoggedIn();
OCP\JSON::callCheck();
+\OC::$session->close();
// Get the params
$dir = isset( $_POST['dir'] ) ? stripslashes($_POST['dir']) : '';
@@ -23,8 +24,8 @@ if(trim($foldername) === '') {
exit();
}
-if(strpos($foldername, '/') !== false) {
- $result['data'] = array('message' => $l10n->t('Folder name must not contain "/". Please choose a different name.'));
+if(!OCP\Util::isValidFileName($foldername)) {
+ $result['data'] = array('message' => (string)$l10n->t("Invalid name, '\\', '/', '<', '>', ':', '\"', '|', '?' and '*' are not allowed."));
OCP\JSON::error($result);
exit();
}
diff --git a/apps/files/ajax/rawlist.php b/apps/files/ajax/rawlist.php
index fb34e518fa2..f18bbffb74a 100644
--- a/apps/files/ajax/rawlist.php
+++ b/apps/files/ajax/rawlist.php
@@ -1,9 +1,10 @@
<?php
OCP\JSON::checkLoggedIn();
+\OC::$session->close();
// Load the files
-$dir = isset( $_GET['dir'] ) ? $_GET['dir'] : '';
+$dir = isset($_GET['dir']) ? $_GET['dir'] : '';
$mimetypes = isset($_GET['mimetypes']) ? json_decode($_GET['mimetypes'], true) : '';
// Clean up duplicates from array and deal with non-array requests
@@ -15,43 +16,39 @@ if (is_array($mimetypes)) {
// make filelist
$files = array();
+/**
+ * @var \OCP\Files\FileInfo[] $files
+ */
// If a type other than directory is requested first load them.
-if($mimetypes && !in_array('httpd/unix-directory', $mimetypes)) {
- foreach( \OC\Files\Filesystem::getDirectoryContent( $dir, 'httpd/unix-directory' ) as $file ) {
- $file['directory'] = $dir;
- $file['isPreviewAvailable'] = \OC::$server->getPreviewManager()->isMimeSupported($file['mimetype']);
- $file["date"] = OCP\Util::formatDate($file["mtime"]);
- $file['mimetype_icon'] = \OCA\Files\Helper::determineIcon($file);
- $files[] = $file;
- }
+if ($mimetypes && !in_array('httpd/unix-directory', $mimetypes)) {
+ $files = array_merge($files, \OC\Files\Filesystem::getDirectoryContent($dir, 'httpd/unix-directory'));
}
if (is_array($mimetypes) && count($mimetypes)) {
foreach ($mimetypes as $mimetype) {
- foreach( \OC\Files\Filesystem::getDirectoryContent( $dir, $mimetype ) as $file ) {
- $file['directory'] = $dir;
- $file['isPreviewAvailable'] = \OC::$server->getPreviewManager()->isMimeSupported($file['mimetype']);
- $file["date"] = OCP\Util::formatDate($file["mtime"]);
- $file['mimetype_icon'] = \OCA\Files\Helper::determineIcon($file);
- $files[] = $file;
- }
+ $files = array_merge($files, \OC\Files\Filesystem::getDirectoryContent($dir, $mimetype));
}
} else {
- foreach( \OC\Files\Filesystem::getDirectoryContent( $dir ) as $file ) {
- $file['directory'] = $dir;
- $file['isPreviewAvailable'] = \OC::$server->getPreviewManager()->isMimeSupported($file['mimetype']);
- $file["date"] = OCP\Util::formatDate($file["mtime"]);
- $file['mimetype_icon'] = \OCA\Files\Helper::determineIcon($file);
- $files[] = $file;
- }
+ $files = array_merge($files, \OC\Files\Filesystem::getDirectoryContent($dir));
}
-
// Sort by name
-usort($files, function ($a, $b) {
- if ($a['name'] === $b['name']) {
- return 0;
- }
- return ($a['name'] < $b['name']) ? -1 : 1;
-});
+usort($files, array('\OCA\Files\Helper', 'fileCmp'));
+
+$result = array();
+foreach ($files as $file) {
+ $fileData = array();
+ $fileData['directory'] = $dir;
+ $fileData['name'] = $file->getName();
+ $fileData['type'] = $file->getType();
+ $fileData['path'] = $file['path'];
+ $fileData['id'] = $file->getId();
+ $fileData['size'] = $file->getSize();
+ $fileData['mtime'] = $file->getMtime();
+ $fileData['mimetype'] = $file->getMimetype();
+ $fileData['isPreviewAvailable'] = \OC::$server->getPreviewManager()->isMimeSupported($file->getMimetype());
+ $fileData["date"] = OCP\Util::formatDate($file->getMtime());
+ $fileData['mimetype_icon'] = \OCA\Files\Helper::determineIcon($file);
+ $result[] = $fileData;
+}
-OC_JSON::success(array('data' => $files));
+OC_JSON::success(array('data' => $result));
diff --git a/apps/files/ajax/rename.php b/apps/files/ajax/rename.php
index 5b07c306af8..fa3ddace63d 100644
--- a/apps/files/ajax/rename.php
+++ b/apps/files/ajax/rename.php
@@ -23,6 +23,7 @@
OCP\JSON::checkLoggedIn();
OCP\JSON::callCheck();
+\OC::$session->close();
$files = new \OCA\Files\App(
\OC\Files\Filesystem::getView(),
diff --git a/apps/files/ajax/scan.php b/apps/files/ajax/scan.php
index 5b32b6db9b7..d5d88483801 100644
--- a/apps/files/ajax/scan.php
+++ b/apps/files/ajax/scan.php
@@ -1,6 +1,6 @@
<?php
set_time_limit(0); //scanning can take ages
-session_write_close();
+\OC::$session->close();
$force = (isset($_GET['force']) and ($_GET['force'] === 'true'));
$dir = isset($_GET['dir']) ? $_GET['dir'] : '';
diff --git a/apps/files/ajax/upgrade.php b/apps/files/ajax/upgrade.php
deleted file mode 100644
index 7237b02c0b0..00000000000
--- a/apps/files/ajax/upgrade.php
+++ /dev/null
@@ -1,44 +0,0 @@
-<?php
-set_time_limit(0); //scanning can take ages
-session_write_close();
-
-$user = OC_User::getUser();
-$eventSource = new OC_EventSource();
-$listener = new UpgradeListener($eventSource);
-$legacy = new \OC\Files\Cache\Legacy($user);
-
-if ($legacy->hasItems()) {
- OC_Hook::connect('\OC\Files\Cache\Upgrade', 'migrate_path', $listener, 'upgradePath');
-
- OC_DB::beginTransaction();
- $upgrade = new \OC\Files\Cache\Upgrade($legacy);
- $count = $legacy->getCount();
- $eventSource->send('total', $count);
- $upgrade->upgradePath('/' . $user . '/files');
- OC_DB::commit();
-}
-\OC\Files\Cache\Upgrade::upgradeDone($user);
-$eventSource->send('done', true);
-$eventSource->close();
-
-class UpgradeListener {
- /**
- * @var OC_EventSource $eventSource
- */
- private $eventSource;
-
- private $count = 0;
- private $lastSend = 0;
-
- public function __construct($eventSource) {
- $this->eventSource = $eventSource;
- }
-
- public function upgradePath($path) {
- $this->count++;
- if ($this->count > ($this->lastSend + 5)) {
- $this->lastSend = $this->count;
- $this->eventSource->send('count', $this->count);
- }
- }
-}
diff --git a/apps/files/ajax/upload.php b/apps/files/ajax/upload.php
index 8f6c42d6620..37c600e91da 100644
--- a/apps/files/ajax/upload.php
+++ b/apps/files/ajax/upload.php
@@ -22,6 +22,7 @@ if (empty($_POST['dirToken'])) {
} else {
// return only read permissions for public upload
$allowedPermissions = OCP\PERMISSION_READ;
+ $public_directory = !empty($_POST['subdir']) ? $_POST['subdir'] : '/';
$linkItem = OCP\Share::getShareByToken($_POST['dirToken']);
if ($linkItem === false) {
@@ -45,7 +46,7 @@ if (empty($_POST['dirToken'])) {
$dir = sprintf(
"/%s/%s",
$path,
- isset($_POST['subdir']) ? $_POST['subdir'] : ''
+ $public_directory
);
if (!$dir || empty($dir) || $dir === false) {
@@ -57,6 +58,7 @@ if (empty($_POST['dirToken'])) {
OCP\JSON::callCheck();
+\OC::$session->close();
// get array with current storage stats (e.g. max file size)
@@ -112,7 +114,14 @@ if (strpos($dir, '..') === false) {
} else {
$target = \OC\Files\Filesystem::normalizePath(stripslashes($dir).'/'.$files['name'][$i]);
}
-
+
+ $directory = \OC\Files\Filesystem::normalizePath(stripslashes($dir));
+ if (isset($public_directory)) {
+ // If we are uploading from the public app,
+ // we want to send the relative path in the ajax request.
+ $directory = $public_directory;
+ }
+
if ( ! \OC\Files\Filesystem::file_exists($target)
|| (isset($_POST['resolution']) && $_POST['resolution']==='replace')
) {
@@ -139,7 +148,8 @@ if (strpos($dir, '..') === false) {
'originalname' => $files['tmp_name'][$i],
'uploadMaxFilesize' => $maxUploadFileSize,
'maxHumanFilesize' => $maxHumanFileSize,
- 'permissions' => $meta['permissions'] & $allowedPermissions
+ 'permissions' => $meta['permissions'] & $allowedPermissions,
+ 'directory' => $directory,
);
}
@@ -166,7 +176,8 @@ if (strpos($dir, '..') === false) {
'originalname' => $files['tmp_name'][$i],
'uploadMaxFilesize' => $maxUploadFileSize,
'maxHumanFilesize' => $maxHumanFileSize,
- 'permissions' => $meta['permissions'] & $allowedPermissions
+ 'permissions' => $meta['permissions'] & $allowedPermissions,
+ 'directory' => $directory,
);
}
}