Exemple #1
0
 /**
  * get all files and folders in a folder
  * @param string path
  * @param string root (optional)
  * @return array
  *
  * returns an array of assiciative arrays with the following keys:
  * - path
  * - name
  * - size
  * - mtime
  * - ctime
  * - mimetype
  * - encrypted
  * - versioned
  */
 public static function getFolderContent($path, $root = false, $mimetype_filter = '')
 {
     if ($root === false) {
         $root = OC_Filesystem::getRoot();
     }
     $parent = OC_FileCache::getId($path, $root);
     if ($parent == -1) {
         return array();
     }
     $query = OC_DB::prepare('SELECT `id`,`path`,`name`,`ctime`,`mtime`,`mimetype`,`size`,`encrypted`,`versioned`,`writable` FROM `*PREFIX*fscache` WHERE `parent`=? AND (`mimetype` LIKE ? OR `mimetype` = ?)');
     $result = $query->execute(array($parent, $mimetype_filter . '%', 'httpd/unix-directory'))->fetchAll();
     if (is_array($result)) {
         return $result;
     } else {
         OC_Log::write('files', 'getFolderContent(): file not found in cache (' . $path . ')', OC_Log::DEBUG);
         return false;
     }
 }
Exemple #2
0
 /**
  * @brief Generate a unique target for the item
  * @param string Item type
  * @param string Item source
  * @param int SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK
  * @param string User or group the item is being shared with
  * @param string The suggested target originating from a reshare (optional)
  * @param int The id of the parent group share (optional)
  * @return string Item target
  */
 private static function generateTarget($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $suggestedTarget = null, $groupParent = null)
 {
     $backend = self::getBackend($itemType);
     if ($shareType == self::SHARE_TYPE_LINK) {
         if (isset($suggestedTarget)) {
             return $suggestedTarget;
         }
         return $backend->generateTarget($itemSource, false);
     } else {
         if ($itemType == 'file' || $itemType == 'folder') {
             $column = 'file_target';
             $columnSource = 'file_source';
         } else {
             $column = 'item_target';
             $columnSource = 'item_source';
         }
         if ($shareType == self::SHARE_TYPE_USER) {
             // Share with is a user, so set share type to user and groups
             $shareType = self::$shareTypeUserAndGroups;
             $userAndGroups = array_merge(array($shareWith), \OC_Group::getUserGroups($shareWith));
         } else {
             $userAndGroups = false;
         }
         $exclude = null;
         // Backend has 3 opportunities to generate a unique target
         for ($i = 0; $i < 2; $i++) {
             // Check if suggested target exists first
             if ($i == 0 && isset($suggestedTarget)) {
                 $target = $suggestedTarget;
             } else {
                 if ($shareType == self::SHARE_TYPE_GROUP) {
                     $target = $backend->generateTarget($itemSource, false, $exclude);
                 } else {
                     $target = $backend->generateTarget($itemSource, $shareWith, $exclude);
                 }
                 if (is_array($exclude) && in_array($target, $exclude)) {
                     break;
                 }
             }
             // Check if target already exists
             $checkTarget = self::getItems($itemType, $target, $shareType, $shareWith);
             if (!empty($checkTarget)) {
                 foreach ($checkTarget as $item) {
                     // Skip item if it is the group parent row
                     if (isset($groupParent) && $item['id'] == $groupParent) {
                         if (count($checkTarget) == 1) {
                             return $target;
                         } else {
                             continue;
                         }
                     }
                     if ($item['uid_owner'] == $uidOwner) {
                         if ($itemType == 'file' || $itemType == 'folder') {
                             if ($item['file_source'] == \OC_FileCache::getId($itemSource)) {
                                 return $target;
                             }
                         } else {
                             if ($item['item_source'] == $itemSource) {
                                 return $target;
                             }
                         }
                     }
                 }
                 if (!isset($exclude)) {
                     $exclude = array();
                 }
                 // Find similar targets to improve backend's chances to generate a unqiue target
                 if ($userAndGroups) {
                     if ($column == 'file_target') {
                         $checkTargets = \OC_DB::prepare('SELECT `' . $column . '` FROM `*PREFIX*share` WHERE `item_type` IN (\'file\', \'folder\') AND `share_type` IN (?,?,?) AND `share_with` IN (\'' . implode('\',\'', $userAndGroups) . '\')');
                         $result = $checkTargets->execute(array(self::SHARE_TYPE_USER, self::SHARE_TYPE_GROUP, self::$shareTypeGroupUserUnique));
                     } else {
                         $checkTargets = \OC_DB::prepare('SELECT `' . $column . '` FROM `*PREFIX*share` WHERE `item_type` = ? AND `share_type` IN (?,?,?) AND `share_with` IN (\'' . implode('\',\'', $userAndGroups) . '\')');
                         $result = $checkTargets->execute(array($itemType, self::SHARE_TYPE_USER, self::SHARE_TYPE_GROUP, self::$shareTypeGroupUserUnique));
                     }
                 } else {
                     if ($column == 'file_target') {
                         $checkTargets = \OC_DB::prepare('SELECT `' . $column . '` FROM `*PREFIX*share` WHERE `item_type` IN (\'file\', \'folder\') AND `share_type` = ? AND `share_with` = ?');
                         $result = $checkTargets->execute(array(self::SHARE_TYPE_GROUP, $shareWith));
                     } else {
                         $checkTargets = \OC_DB::prepare('SELECT `' . $column . '` FROM `*PREFIX*share` WHERE `item_type` = ? AND `share_type` = ? AND `share_with` = ?');
                         $result = $checkTargets->execute(array($itemType, self::SHARE_TYPE_GROUP, $shareWith));
                     }
                 }
                 while ($row = $result->fetchRow()) {
                     $exclude[] = $row[$column];
                 }
             } else {
                 return $target;
             }
         }
     }
     $message = 'Sharing backend registered for ' . $itemType . ' did not generate a unique target for ' . $itemSource;
     \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR);
     throw new \Exception($message);
 }
Exemple #3
0
        exit;
    }
}
$files = $_FILES['files'];
$dir = $_POST['dir'];
$error = '';
$totalSize = 0;
foreach ($files['size'] as $size) {
    $totalSize += $size;
}
if ($totalSize > OC_Filesystem::free_space('/')) {
    OCP\JSON::error(array("data" => array("message" => "Not enough space available")));
    exit;
}
$result = array();
if (strpos($dir, '..') === false) {
    $fileCount = count($files['name']);
    for ($i = 0; $i < $fileCount; $i++) {
        $target = OCP\Files::buildNotExistingFileName(stripslashes($dir), $files['name'][$i]);
        if (is_uploaded_file($files['tmp_name'][$i]) and OC_Filesystem::fromTmpFile($files['tmp_name'][$i], $target)) {
            $meta = OC_FileCache::get($target);
            $id = OC_FileCache::getId($target);
            $result[] = array("status" => "success", 'mime' => $meta['mimetype'], 'size' => $meta['size'], 'id' => $id, 'name' => basename($target));
        }
    }
    OCP\JSON::encodedPrint($result);
    exit;
} else {
    $error = 'invalid dir';
}
OCP\JSON::error(array('data' => array('error' => $error, "file" => $fileName)));
Exemple #4
0
    $ctx = stream_context_create(null, array('notification' => 'progress'));
    $sourceStream = fopen($source, 'rb', false, $ctx);
    $target = $dir . '/' . $filename;
    $result = OC_Filesystem::file_put_contents($target, $sourceStream);
    if ($result) {
        $target = OC_Filesystem::normalizePath($target);
        $meta = OC_FileCache::get($target);
        $mime = $meta['mimetype'];
        $id = OC_FileCache::getId($target);
        $eventSource->send('success', array('mime' => $mime, 'size' => OC_Filesystem::filesize($target), 'id' => $id));
    } else {
        $eventSource->send('error', "Error while downloading " . $source . ' to ' . $target);
    }
    $eventSource->close();
    exit;
} else {
    if ($content) {
        if (OC_Filesystem::file_put_contents($dir . '/' . $filename, $content)) {
            $meta = OC_FileCache::get($dir . '/' . $filename);
            $id = OC_FileCache::getId($dir . '/' . $filename);
            OCP\JSON::success(array("data" => array('content' => $content, 'id' => $id)));
            exit;
        }
    } elseif (OC_Files::newFile($dir, $filename, 'file')) {
        $meta = OC_FileCache::get($dir . '/' . $filename);
        $id = OC_FileCache::getId($dir . '/' . $filename);
        OCP\JSON::success(array("data" => array('content' => $content, 'id' => $id)));
        exit;
    }
}
OCP\JSON::error(array("data" => array("message" => "Error when creating the file")));
Exemple #5
0
<?php

$installedVersion = OCP\Config::getAppValue('files_sharing', 'installed_version');
if (version_compare($installedVersion, '0.3', '<')) {
    $update_error = false;
    $query = OCP\DB::prepare('SELECT * FROM `*PREFIX*sharing`');
    $result = $query->execute();
    $groupShares = array();
    //we need to set up user backends, otherwise creating the shares will fail with "because user does not exist"
    OC_User::useBackend(new OC_User_Database());
    OC_Group::useBackend(new OC_Group_Database());
    OC_App::loadApps(array('authentication'));
    while ($row = $result->fetchRow()) {
        $itemSource = OC_FileCache::getId($row['source'], '');
        if ($itemSource != -1) {
            $file = OC_FileCache::get($row['source'], '');
            if ($file['mimetype'] == 'httpd/unix-directory') {
                $itemType = 'folder';
            } else {
                $itemType = 'file';
            }
            if ($row['permissions'] == 0) {
                $permissions = OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_SHARE;
            } else {
                $permissions = OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_UPDATE | OCP\Share::PERMISSION_SHARE;
                if ($itemType == 'folder') {
                    $permissions |= OCP\Share::PERMISSION_CREATE;
                }
            }
            $pos = strrpos($row['uid_shared_with'], '@');
            if ($pos !== false && OC_Group::groupExists(substr($row['uid_shared_with'], $pos + 1))) {
Exemple #6
0
<?php

// Init owncloud
OCP\JSON::checkLoggedIn();
OCP\JSON::callCheck();
// Get the params
$dir = isset($_POST['dir']) ? stripslashes($_POST['dir']) : '';
$foldername = isset($_POST['foldername']) ? stripslashes($_POST['foldername']) : '';
if (trim($foldername) == '') {
    OCP\JSON::error(array("data" => array("message" => "Empty Foldername")));
    exit;
}
if (strpos($foldername, '/') !== false) {
    OCP\JSON::error(array("data" => array("message" => "Invalid Foldername")));
    exit;
}
if (OC_Files::newFile($dir, stripslashes($foldername), 'dir')) {
    if ($dir != '/') {
        $path = $dir . '/' . $foldername;
    } else {
        $path = '/' . $foldername;
    }
    $id = OC_FileCache::getId($path);
    OCP\JSON::success(array("data" => array('id' => $id)));
    exit;
}
OCP\JSON::error(array("data" => array("message" => "Error when creating the folder")));