Example #1
0
 /**
  * @return string
  */
 private static function getBoundary()
 {
     if (empty(self::$multipartBoundary)) {
         self::$multipartBoundary = md5(mt_rand());
     }
     return self::$multipartBoundary;
 }
Example #2
0
 /**
  *  Add file change to the notification queue in the database 
  * trigger on file/folder change/upload
  * @param $path Path of the modified file. 
  * @return void 
  */
 public static function queue_fileChange_notification($path)
 {
     $fileInfo = OC_Files::getFileInfo($path['path']);
     $timestamp = time();
     //TODO timestamp nust be a constant.
     self::db_insert_upload(OCP\User::getUser(), $timestamp, $fileInfo['fileid']);
 }
Example #3
0
 /**
  * @brief offer single file for download
  * 
  * @param string $path full path to file
  * @param int $id file id
  */
 public static function serveFile($path, $id)
 {
     \OCP\User::checkLoggedIn();
     \OC::$server->getSession()->close();
     Bookshelf::add($id);
     $dirName = dirname($path);
     $fileName = basename($path);
     \OC_Files::get($dirName, array($fileName), $_SERVER['REQUEST_METHOD'] == 'HEAD');
 }
Example #4
0
 /**
  * scan a folder for music
  * @param OC_EventSource eventSource (optional)
  * @return int the number of songs found
  */
 public static function scanCollection($eventSource = null)
 {
     $music = OC_Files::searchByMime('audio');
     $ogg = OC_Files::searchByMime('application/ogg');
     $music = array_merge($music, $ogg);
     $eventSource->send('count', count($music));
     $songs = 0;
     foreach ($music as $file) {
         self::scanFile($file);
         $songs++;
         if ($eventSource) {
             $eventSource->send('scanned', array('file' => $file, 'count' => $songs));
         }
     }
     if ($eventSource) {
         $eventSource->send('done', $songs);
     }
     return $songs;
 }
Example #5
0
 /**
  * @dataProvider setUploadLimitWriteProvider
  */
 public function testSetUploadLimitWrite($htaccessWritable, $userIniWritable, $setSize, $expectedSize, $htaccessStr, $userIniStr)
 {
     $files = $this->getUploadLimitTestFiles();
     chmod($files['.htaccess'], $htaccessWritable ? 0644 : 0444);
     chmod($files['.user.ini'], $userIniWritable ? 0644 : 0444);
     $htaccessSize = filesize($files['.htaccess']);
     $userIniSize = filesize($files['.user.ini']);
     $htaccessSizeMod = 2 * (strlen($htaccessStr) - strlen(self::UPLOAD_LIMIT_DEFAULT_STR));
     $userIniSizeMod = 2 * (strlen($userIniStr) - strlen(self::UPLOAD_LIMIT_DEFAULT_STR));
     $this->assertEquals($expectedSize, \OC_Files::setUploadLimit($setSize, $files));
     // check file contents
     $htaccess = file_get_contents($files['.htaccess']);
     $this->assertEquals(1, preg_match('/php_value upload_max_filesize ' . $htaccessStr . '/', $htaccess));
     $this->assertEquals(1, preg_match('/php_value post_max_size ' . $htaccessStr . '/', $htaccess));
     $this->assertEquals($htaccessSize + $htaccessSizeMod, filesize($files['.htaccess']));
     $userIni = file_get_contents($files['.user.ini']);
     $this->assertEquals(1, preg_match('/upload_max_filesize=' . $userIniStr . '/', $userIni));
     $this->assertEquals(1, preg_match('/post_max_size=' . $userIniStr . '/', $userIni));
     $this->assertEquals($userIniSize + $userIniSizeMod, filesize($files['.user.ini']));
 }
Example #6
0
<?php

/**
* ownCloud - ajax frontend
*
* @author Robin Appelman
* @copyright 2010 Robin Appelman icewind1991@gmail.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library.  If not, see <http://www.gnu.org/licenses/>.
*
*/
// only need filesystem apps
$RUNTIME_APPTYPES = array('filesystem');
// Init owncloud
// Check if we are a user
OCP\User::checkLoggedIn();
$files = $_GET["files"];
$dir = $_GET["dir"];
OC_Files::get($dir, $files, $_SERVER['REQUEST_METHOD'] == 'HEAD' ? true : false);
Example #7
0
 /**
  * @brief Share an item with a user, group, or via private link
  * @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 int CRUDS permissions
  * @return bool Returns true on success or false on failure
  */
 public static function shareItem($itemType, $itemSource, $shareType, $shareWith, $permissions)
 {
     $uidOwner = \OC_User::getUser();
     $sharingPolicy = \OC_Appconfig::getValue('core', 'shareapi_share_policy', 'global');
     // Verify share type and sharing conditions are met
     if ($shareType === self::SHARE_TYPE_USER) {
         if ($shareWith == $uidOwner) {
             $message = 'Sharing ' . $itemSource . ' failed, because the user ' . $shareWith . ' is the item owner';
             \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR);
             throw new \Exception($message);
         }
         if (!\OC_User::userExists($shareWith)) {
             $message = 'Sharing ' . $itemSource . ' failed, because the user ' . $shareWith . ' does not exist';
             \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR);
             throw new \Exception($message);
         }
         if ($sharingPolicy == 'groups_only') {
             $inGroup = array_intersect(\OC_Group::getUserGroups($uidOwner), \OC_Group::getUserGroups($shareWith));
             if (empty($inGroup)) {
                 $message = 'Sharing ' . $itemSource . ' failed, because the user ' . $shareWith . ' is not a member of any groups that ' . $uidOwner . ' is a member of';
                 \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR);
                 throw new \Exception($message);
             }
         }
         // Check if the item source is already shared with the user, either from the same owner or a different user
         if ($checkExists = self::getItems($itemType, $itemSource, self::$shareTypeUserAndGroups, $shareWith, null, self::FORMAT_NONE, null, 1, true, true)) {
             // Only allow the same share to occur again if it is the same owner and is not a user share, this use case is for increasing permissions for a specific user
             if ($checkExists['uid_owner'] != $uidOwner || $checkExists['share_type'] == $shareType) {
                 $message = 'Sharing ' . $itemSource . ' failed, because this item is already shared with ' . $shareWith;
                 \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR);
                 throw new \Exception($message);
             }
         }
     } else {
         if ($shareType === self::SHARE_TYPE_GROUP) {
             if (!\OC_Group::groupExists($shareWith)) {
                 $message = 'Sharing ' . $itemSource . ' failed, because the group ' . $shareWith . ' does not exist';
                 \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR);
                 throw new \Exception($message);
             }
             if ($sharingPolicy == 'groups_only' && !\OC_Group::inGroup($uidOwner, $shareWith)) {
                 $message = 'Sharing ' . $itemSource . ' failed, because ' . $uidOwner . ' is not a member of the group ' . $shareWith;
                 \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR);
                 throw new \Exception($message);
             }
             // Check if the item source is already shared with the group, either from the same owner or a different user
             // The check for each user in the group is done inside the put() function
             if ($checkExists = self::getItems($itemType, $itemSource, self::SHARE_TYPE_GROUP, $shareWith, null, self::FORMAT_NONE, null, 1, true, true)) {
                 // Only allow the same share to occur again if it is the same owner and is not a group share, this use case is for increasing permissions for a specific user
                 if ($checkExists['uid_owner'] != $uidOwner || $checkExists['share_type'] == $shareType) {
                     $message = 'Sharing ' . $itemSource . ' failed, because this item is already shared with ' . $shareWith;
                     \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR);
                     throw new \Exception($message);
                 }
             }
             // Convert share with into an array with the keys group and users
             $group = $shareWith;
             $shareWith = array();
             $shareWith['group'] = $group;
             $shareWith['users'] = array_diff(\OC_Group::usersInGroup($group), array($uidOwner));
         } else {
             if ($shareType === self::SHARE_TYPE_LINK) {
                 if (\OC_Appconfig::getValue('core', 'shareapi_allow_links', 'yes') == 'yes') {
                     if ($checkExists = self::getItems($itemType, $itemSource, self::SHARE_TYPE_LINK, null, $uidOwner, self::FORMAT_NONE, null, 1)) {
                         // If password is set delete the old link
                         if (isset($shareWith)) {
                             self::delete($checkExists['id']);
                         } else {
                             $message = 'Sharing ' . $itemSource . ' failed, because this item is already shared with a link';
                             \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR);
                             throw new \Exception($message);
                         }
                     }
                     // Generate hash of password - same method as user passwords
                     if (isset($shareWith)) {
                         $forcePortable = CRYPT_BLOWFISH != 1;
                         $hasher = new \PasswordHash(8, $forcePortable);
                         $shareWith = $hasher->HashPassword($shareWith . \OC_Config::getValue('passwordsalt', ''));
                     }
                     return self::put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions);
                 }
                 $message = 'Sharing ' . $itemSource . ' failed, because sharing with links is not allowed';
                 \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR);
                 throw new \Exception($message);
                 return false;
                 // 		} else if ($shareType === self::SHARE_TYPE_CONTACT) {
                 // 			if (!\OC_App::isEnabled('contacts')) {
                 // 				$message = 'Sharing '.$itemSource.' failed, because the contacts app is not enabled';
                 // 				\OC_Log::write('OCP\Share', $message, \OC_Log::ERROR);
                 // 				return false;
                 // 			}
                 // 			$vcard = \OC_Contacts_App::getContactVCard($shareWith);
                 // 			if (!isset($vcard)) {
                 // 				$message = 'Sharing '.$itemSource.' failed, because the contact does not exist';
                 // 				\OC_Log::write('OCP\Share', $message, \OC_Log::ERROR);
                 // 				throw new \Exception($message);
                 // 			}
                 // 			$details = \OC_Contacts_VCard::structureContact($vcard);
                 // 			// TODO Add ownCloud user to contacts vcard
                 // 			if (!isset($details['EMAIL'])) {
                 // 				$message = 'Sharing '.$itemSource.' failed, because no email address is associated with the contact';
                 // 				\OC_Log::write('OCP\Share', $message, \OC_Log::ERROR);
                 // 				throw new \Exception($message);
                 // 			}
                 // 			return self::shareItem($itemType, $itemSource, self::SHARE_TYPE_EMAIL, $details['EMAIL'], $permissions);
             } else {
                 // Future share types need to include their own conditions
                 $message = 'Share type ' . $shareType . ' is not valid for ' . $itemSource;
                 \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR);
                 throw new \Exception($message);
             }
         }
     }
     // If the item is a folder, scan through the folder looking for equivalent item types
     if ($itemType == 'folder') {
         $parentFolder = self::put('folder', $itemSource, $shareType, $shareWith, $uidOwner, $permissions, true);
         if ($parentFolder && ($files = \OC_Files::getDirectoryContent($itemSource))) {
             for ($i = 0; $i < count($files); $i++) {
                 $name = substr($files[$i]['name'], strpos($files[$i]['name'], $itemSource) - strlen($itemSource));
                 if ($files[$i]['mimetype'] == 'httpd/unix-directory' && ($children = \OC_Files::getDirectoryContent($name, '/'))) {
                     // Continue scanning into child folders
                     array_push($files, $children);
                 } else {
                     // Check file extension for an equivalent item type to convert to
                     $extension = strtolower(substr($itemSource, strrpos($itemSource, '.') + 1));
                     foreach (self::$backends as $type => $backend) {
                         if (isset($backend->dependsOn) && $backend->dependsOn == 'file' && isset($backend->supportedFileExtensions) && in_array($extension, $backend->supportedFileExtensions)) {
                             $itemType = $type;
                             break;
                         }
                     }
                     // Pass on to put() to check if this item should be converted, the item won't be inserted into the database unless it can be converted
                     self::put($itemType, $name, $shareType, $shareWith, $uidOwner, $permissions, $parentFolder);
                 }
             }
             return true;
         }
         return false;
     } else {
         // Put the item into the database
         return self::put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions);
     }
 }
Example #8
0
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library.  If not, see <http://www.gnu.org/licenses/>.
*
*/
OCP\User::checkAdminUser();
$htaccessWorking = getenv('htaccessWorking') == 'true';
$upload_max_filesize = OCP\Util::computerFileSize(ini_get('upload_max_filesize'));
$post_max_size = OCP\Util::computerFileSize(ini_get('post_max_size'));
$maxUploadFilesize = OCP\Util::humanFileSize(min($upload_max_filesize, $post_max_size));
if ($_POST && OC_Util::isCallRegistered()) {
    if (isset($_POST['maxUploadSize'])) {
        if (($setMaxSize = OC_Files::setUploadLimit(OCP\Util::computerFileSize($_POST['maxUploadSize']))) !== false) {
            $maxUploadFilesize = OCP\Util::humanFileSize($setMaxSize);
        }
    }
}
OCP\App::setActiveNavigationEntry("files_administration");
$htaccessWritable = is_writable(OC::$SERVERROOT . '/.htaccess');
$tmpl = new OCP\Template('files', 'admin');
/* 
* extended version
* + only users with permission can delete files(in the files app only)
* + file type restriction
*/
$filetyprestriction = \OC_Appconfig::getValue('core', 'filetyperes_enabled', 'no');
$allowed_types = \OC_Appconfig::getValue('core', 'allowed_filetypes', '');
$deleteGroupsList = \OC_Appconfig::getValue('core', 'delete', '');
Example #9
0
$ts = new \OC\Pictures\TileStack(array(), '');
$root_images = array();
foreach ($files as $file) {
    $filename = $root . $file['name'];
    if ($file['type'] == 'file') {
        $root_images[] = $filename;
    } else {
        // it is a dir, look for images in subdirs. We keep trying till
        // we find some images or there are no subdirs anymore to check.
        $name = $file['name'];
        $second_level_images = array();
        $dirs_to_check = array($filename);
        while (!empty($dirs_to_check)) {
            // get next subdir to check
            $subdir = array_pop($dirs_to_check);
            $subdir_files = \OC_Files::getDirectoryContent($subdir, 'image');
            foreach ($subdir_files as $file) {
                if ($file['type'] == 'file') {
                    $second_level_images[] = $subdir . '/' . $file['name'];
                } else {
                    $dirs_to_check[] = $subdir . '/' . $file['name'];
                }
            }
            if (count($second_level_images) != 0) {
                // if we collected images for this directory
                $tl->addTile(new \OC\Pictures\TileStack($second_level_images, $name));
                break;
            }
        }
    }
}
Example #10
0
<?php

// only need filesystem apps
$RUNTIME_APPTYPES = array('filesystem');
// Init owncloud
require_once 'lib/template.php';
OCP\JSON::checkLoggedIn();
// Load the files
$dir = isset($_GET['dir']) ? $_GET['dir'] : '';
$mimetype = isset($_GET['mimetype']) ? $_GET['mimetype'] : '';
// make filelist
$files = array();
foreach (OC_Files::getdirectorycontent($dir, $mimetype) as $i) {
    $i["date"] = OCP\Util::formatDate($i["mtime"]);
    $i['mimetype_icon'] = $i['type'] == 'dir' ? \mimetype_icon('dir') : \mimetype_icon($i['mimetype']);
    $files[] = $i;
}
OCP\JSON::success(array('data' => $files));
<?php

// Init owncloud
require_once '../../lib/base.php';
OC_JSON::checkLoggedIn();
// Get data
$dir = $_GET["dir"];
$file = $_GET["file"];
$target = $_GET["target"];
if (OC_Files::move($dir, $file, $target, $file)) {
    OC_JSON::success(array("data" => array("dir" => $dir, "files" => $file)));
} else {
    OC_JSON::error(array("data" => array("message" => "Could move {$file}")));
}
    OCP\JSON::error(array("data" => array("message" => "Invalid Filename")));
    exit;
}
if ($source) {
    if (substr($source, 0, 8) != 'https://' and substr($source, 0, 7) != 'http://') {
        OCP\JSON::error(array("data" => array("message" => "Not a valid source")));
        exit;
    }
    $sourceStream = fopen($source, 'rb');
    $target = $dir . '/' . $filename;
    $result = OC_Filesystem::file_put_contents($target, $sourceStream);
    if ($result) {
        $mime = OC_Filesystem::getMimetype($target);
        OCP\JSON::success(array("data" => array('mime' => $mime)));
        exit;
    } else {
        OCP\JSON::error(array("data" => array("message" => "Error while downloading " . $source . ' to ' . $target)));
        exit;
    }
} else {
    if ($content) {
        if (OC_Filesystem::file_put_contents($dir . '/' . $filename, $content)) {
            OCP\JSON::success(array("data" => array('content' => $content)));
            exit;
        }
    } elseif (OC_Files::newFile($dir, $filename, 'file')) {
        OCP\JSON::success(array("data" => array('content' => $content)));
        exit;
    }
}
OCP\JSON::error(array("data" => array("message" => "Error when creating the file")));
Example #13
0
$RUNTIME_APPTYPES = array('filesystem');
// Init owncloud
OCP\JSON::checkLoggedIn();
// Load the files
$dir = isset($_GET['dir']) ? $_GET['dir'] : '';
$doBreadcrumb = isset($_GET['breadcrumb']) ? true : false;
$data = array();
// Make breadcrumb
if ($doBreadcrumb) {
    $breadcrumb = array();
    $pathtohere = "/";
    foreach (explode("/", $dir) as $i) {
        if ($i != "") {
            $pathtohere .= "{$i}/";
            $breadcrumb[] = array("dir" => $pathtohere, "name" => $i);
        }
    }
    $breadcrumbNav = new OCP\Template("files", "part.breadcrumb", "");
    $breadcrumbNav->assign("breadcrumb", $breadcrumb);
    $data['breadcrumb'] = $breadcrumbNav->fetchPage();
}
// make filelist
$files = array();
foreach (OC_Files::getdirectorycontent($dir) as $i) {
    $i["date"] = OCP\Util::formatDate($i["mtime"]);
    $files[] = $i;
}
$list = new OCP\Template("files", "part.list", "");
$list->assign("files", $files, false);
$data = array('files' => $list->fetchPage());
OCP\JSON::success(array('data' => $data));
<?php

/**
* ownCloud - ajax frontend
*
* @author Robin Appelman
* @copyright 2010 Robin Appelman icewind1991@gmail.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library.  If not, see <http://www.gnu.org/licenses/>.
*
*/
// Init owncloud
require_once '../../lib/base.php';
// Check if we are a user
OC_Util::checkLoggedIn();
$files = $_GET["files"];
$dir = $_GET["dir"];
OC_Files::get($dir, $files);
Example #15
0
 /**
  * Returns an array with all the child nodes
  *
  * @return Sabre_DAV_INode[]
  */
 public function getChildren()
 {
     $folder_content = OC_Files::getDirectoryContent($this->path);
     $paths = array();
     foreach ($folder_content as $info) {
         $paths[] = $this->path . '/' . $info['name'];
     }
     $properties = array_fill_keys($paths, array());
     if (count($paths) > 0) {
         $placeholders = join(',', array_fill(0, count($paths), '?'));
         $query = OC_DB::prepare('SELECT * FROM `*PREFIX*properties` WHERE `userid` = ?' . ' AND `propertypath` IN (' . $placeholders . ')');
         array_unshift($paths, OC_User::getUser());
         // prepend userid
         $result = $query->execute($paths);
         while ($row = $result->fetchRow()) {
             $propertypath = $row['propertypath'];
             $propertyname = $row['propertyname'];
             $propertyvalue = $row['propertyvalue'];
             $properties[$propertypath][$propertyname] = $propertyvalue;
         }
     }
     $nodes = array();
     foreach ($folder_content as $info) {
         $node = $this->getChild($info['name'], $info);
         $node->setPropertyCache($properties[$this->path . '/' . $info['name']]);
         $nodes[] = $node;
     }
     return $nodes;
 }
 OC_Util::setupFS($user);
 $source = substr($source, strlen("/" . $user . "/files"));
 $subPath = isset($_GET['path']) ? $_GET['path'] : '';
 $root = $source;
 $source .= $subPath;
 if (!OC_Filesystem::file_exists($source)) {
     header("HTTP/1.0 404 Not Found");
     $tmpl = new OC_Template("", "404", "guest");
     $tmpl->assign("file", $subPath);
     $tmpl->printPage();
     exit;
 }
 if (OC_Filesystem::is_dir($source)) {
     $files = array();
     $rootLength = strlen($root);
     foreach (OC_Files::getdirectorycontent($source) as $i) {
         $i['date'] = OC_Util::formatDate($i['mtime']);
         if ($i['type'] == 'file') {
             $fileinfo = pathinfo($i['name']);
             $i['basename'] = $fileinfo['filename'];
             $i['extention'] = isset($fileinfo['extension']) ? '.' . $fileinfo['extension'] : '';
         }
         $i['directory'] = substr($i['directory'], $rootLength);
         if ($i['directory'] == "/") {
             $i['directory'] = "";
         }
         $files[] = $i;
     }
     // Make breadcrumb
     $breadcrumb = array();
     $pathtohere = "";
Example #17
0
 * You should have received a copy of the GNU Affero General Public License, version 3,
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */
// Check if we are a user
OCP\User::checkLoggedIn();
\OC::$server->getSession()->close();
$files = isset($_GET['files']) ? (string) $_GET['files'] : '';
$dir = isset($_GET['dir']) ? (string) $_GET['dir'] : '';
$files_list = json_decode($files);
// in case we get only a single file
if (!is_array($files_list)) {
    $files_list = array($files);
}
/**
 * this sets a cookie to be able to recognize the start of the download
 * the content must not be longer than 32 characters and must only contain
 * alphanumeric characters
 */
if (isset($_GET['downloadStartSecret']) && !isset($_GET['downloadStartSecret'][32]) && preg_match('!^[a-zA-Z0-9]+$!', $_GET['downloadStartSecret']) === 1) {
    setcookie('ocDownloadStarted', $_GET['downloadStartSecret'], time() + 20, '/');
}
$server_params = array('head' => \OC::$server->getRequest()->getMethod() == 'HEAD');
/**
 * Http range requests support
 */
if (isset($_SERVER['HTTP_RANGE'])) {
    $server_params['range'] = \OC::$server->getRequest()->getHeader('Range');
}
OC_Files::get($dir, $files_list, $server_params);
<?php

// Init owncloud
require_once '../../lib/base.php';
OC_JSON::checkLoggedIn();
// Get the params
$dir = isset($_GET['dir']) ? $_GET['dir'] : '';
$foldername = isset($_GET['foldername']) ? $_GET['foldername'] : '';
if ($foldername == '') {
    OC_JSON::error(array("data" => array("message" => "Empty Foldername")));
    exit;
}
if (defined("DEBUG") && DEBUG) {
    error_log('try to create ' . $foldername . ' in ' . $dir);
}
if (OC_Files::newFile($dir, $foldername, 'dir')) {
    OC_JSON::success(array("data" => array()));
    exit;
}
OC_JSON::error(array("data" => array("message" => "Error when creating the folder")));
Example #19
0
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.  If not, see <http://www.gnu.org/licenses/>.
*
*/
OCP\User::checkLoggedIn();
OCP\App::checkAppEnabled('facefinder');
OCP\App::setActiveNavigationEntry('facefinder');
OCP\Util::addStyle('facefinder', 'styles');
OCP\Util::addScript('facefinder', 'new_1');
if (!OCP\App::isEnabled('files_imageviewer')) {
    OCP\Template::printUserPage('facefinder', 'no-image-app');
    exit;
}
$root = !empty($_GET['root']) ? $_GET['root'] : '/';
$files = \OC_Files::getDirectoryContent($root, 'image');
$tl = new \OC\Pictures\TilesLine();
$ts = new \OC\Pictures\TileStack(array(), '');
$tmpl = new OCP\Template('facefinder', 'index', 'user');
$tmpl->assign('root', $root, false);
$tmpl->assign('tl', $tl, false);
$tmpl->printPage();
Example #20
0
 /**
  * Returns an array with all the child nodes
  *
  * @return Sabre_DAV_INode[]
  */
 public function getChildren()
 {
     $folder_content = OC_Files::getDirectoryContent($this->path);
     $paths = array();
     foreach ($folder_content as $info) {
         $paths[] = $this->path . '/' . $info['name'];
     }
     $properties = array_fill_keys($paths, array());
     if (count($paths) > 0) {
         //
         // the number of arguments within IN conditions are limited in most databases
         // we chunk $paths into arrays of 200 items each to meet this criteria
         //
         $chunks = array_chunk($paths, 200, false);
         foreach ($chunks as $pack) {
             $placeholders = join(',', array_fill(0, count($pack), '?'));
             $query = OC_DB::prepare('SELECT * FROM `*PREFIX*properties` WHERE `userid` = ?' . ' AND `propertypath` IN (' . $placeholders . ')');
             array_unshift($pack, OC_User::getUser());
             // prepend userid
             $result = $query->execute($pack);
             while ($row = $result->fetchRow()) {
                 $propertypath = $row['propertypath'];
                 $propertyname = $row['propertyname'];
                 $propertyvalue = $row['propertyvalue'];
                 $properties[$propertypath][$propertyname] = $propertyvalue;
             }
         }
     }
     $nodes = array();
     foreach ($folder_content as $info) {
         $node = $this->getChild($info['name'], $info);
         $node->setPropertyCache($properties[$this->path . '/' . $info['name']]);
         $nodes[] = $node;
     }
     return $nodes;
 }
Example #21
0
         OC_Files::get("", $path, $_SERVER['REQUEST_METHOD'] == 'HEAD' ? true : false);
     }
 } else {
     OCP\Util::addStyle('files_sharing', 'public');
     OCP\Util::addScript('files_sharing', 'public');
     OCP\Util::addScript('files', 'fileactions');
     $tmpl = new OCP\Template('files_sharing', 'public', 'base');
     $tmpl->assign('owner', $uidOwner);
     // Show file list
     if (OC_Filesystem::is_dir($path)) {
         OCP\Util::addStyle('files', 'files');
         OCP\Util::addScript('files', 'files');
         OCP\Util::addScript('files', 'filelist');
         $files = array();
         $rootLength = strlen($baseDir) + 1;
         foreach (OC_Files::getDirectoryContent($path) as $i) {
             $i['date'] = OCP\Util::formatDate($i['mtime']);
             if ($i['type'] == 'file') {
                 $fileinfo = pathinfo($i['name']);
                 $i['basename'] = $fileinfo['filename'];
                 $i['extension'] = isset($fileinfo['extension']) ? '.' . $fileinfo['extension'] : '';
             }
             $i['directory'] = '/' . substr('/' . $uidOwner . '/files' . $i['directory'], $rootLength);
             if ($i['directory'] == '/') {
                 $i['directory'] = '';
             }
             $i['permissions'] = OCP\Share::PERMISSION_READ;
             $files[] = $i;
         }
         // Make breadcrumb
         $breadcrumb = array();
Example #22
0
 /**
  * Returns an array of ['filename' => 'SHA512-hash-of-file'] for all files found
  * in the iterator.
  *
  * @param \RecursiveIteratorIterator $iterator
  * @param string $path
  * @return array Array of hashes.
  */
 private function generateHashes(\RecursiveIteratorIterator $iterator, $path)
 {
     $hashes = [];
     $copiedWebserverSettingFiles = false;
     $tmpFolder = '';
     $baseDirectoryLength = strlen($path);
     foreach ($iterator as $filename => $data) {
         /** @var \DirectoryIterator $data */
         if ($data->isDir()) {
             continue;
         }
         $relativeFileName = substr($filename, $baseDirectoryLength);
         $relativeFileName = ltrim($relativeFileName, '/');
         // Exclude signature.json files in the appinfo and root folder
         if ($relativeFileName === 'appinfo/signature.json') {
             continue;
         }
         // Exclude signature.json files in the appinfo and core folder
         if ($relativeFileName === 'core/signature.json') {
             continue;
         }
         // The .user.ini and the .htaccess file of ownCloud can contain some
         // custom modifications such as for example the maximum upload size
         // to ensure that this will not lead to false positives this will
         // copy the file to a temporary folder and reset it to the default
         // values.
         if ($filename === $this->environmentHelper->getServerRoot() . '/.htaccess' || $filename === $this->environmentHelper->getServerRoot() . '/.user.ini') {
             if (!$copiedWebserverSettingFiles) {
                 $tmpFolder = rtrim($this->tempManager->getTemporaryFolder(), '/');
                 copy($this->environmentHelper->getServerRoot() . '/.htaccess', $tmpFolder . '/.htaccess');
                 copy($this->environmentHelper->getServerRoot() . '/.user.ini', $tmpFolder . '/.user.ini');
                 \OC_Files::setUploadLimit(\OCP\Util::computerFileSize('513MB'), ['.htaccess' => $tmpFolder . '/.htaccess', '.user.ini' => $tmpFolder . '/.user.ini']);
             }
         }
         // The .user.ini file can contain custom modifications to the file size
         // as well.
         if ($filename === $this->environmentHelper->getServerRoot() . '/.user.ini') {
             $fileContent = file_get_contents($tmpFolder . '/.user.ini');
             $hashes[$relativeFileName] = hash('sha512', $fileContent);
             continue;
         }
         // The .htaccess file in the root folder of ownCloud can contain
         // custom content after the installation due to the fact that dynamic
         // content is written into it at installation time as well. This
         // includes for example the 404 and 403 instructions.
         // Thus we ignore everything below the first occurrence of
         // "#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####" and have the
         // hash generated based on this.
         if ($filename === $this->environmentHelper->getServerRoot() . '/.htaccess') {
             $fileContent = file_get_contents($tmpFolder . '/.htaccess');
             $explodedArray = explode('#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####', $fileContent);
             if (count($explodedArray) === 2) {
                 $hashes[$relativeFileName] = hash('sha512', $explodedArray[0]);
                 continue;
             }
         }
         $hashes[$relativeFileName] = hash_file('sha512', $filename);
     }
     return $hashes;
 }
Example #23
0
//echo json_encode('WP is here !');
//
//echo $baseuri;
$RUNTIME_APPTYPES = array('filesystem', 'authentication', 'share');
//
OC_App::loadApps($RUNTIME_APPTYPES);
$normalize_path = str_replace('\\', '/', OC_APP::getAppPath('user_wordpress'));
$path_array = explode('/', $normalize_path);
array_pop($path_array);
$app_folder = array_pop($path_array);
require_once $app_folder . '/lib/autoauth.php';
//require_once('apps/user_wordpress/lib/autoauth.php');
if (isset($_REQUEST['share_link'])) {
    if (OC_App::isEnabled('files_sharing')) {
        $file_path = urldecode(substr(implode('/', array_slice($vars, 5)), 0, -11));
        $file_infos = OC_Files::getFileInfo($file_path);
        $token = '';
        // is the file allready shared ?
        $shares = OCP\Share::getItemShared('file', $file_infos['id'], OCP\Share::FORMAT_NONE, null, true);
        foreach ($shares as $share) {
            if ($share['path'] == $file_infos['path']) {
                $token = $share['token'];
            }
        }
        // if not, let's share the file
        if (empty($token)) {
            $token = OCP\Share::shareItem('file', $file_infos['id'], 3, NULL, 1);
        }
        // return token
        echo trim($token);
    }
 /**
  * @NoAdminRequired
  * @NoCSRFRequired
  * @SSOCORS
  */
 public function download($dir = null, $file = null)
 {
     \OC::$server->getSession()->close();
     $exists = \OC\Files\Filesystem::file_exists($dir . "/" . $file);
     if (!$exists) {
         return new NotFoundResponse();
     }
     $files_list = json_decode($file);
     // in case we get only a single file
     if (!is_array($files_list)) {
         $files_list = array($file);
     }
     \OC_Files::get($dir, $files_list, $_SERVER['REQUEST_METHOD'] == 'HEAD');
 }
Example #25
0
* @author Robin Appelman
* @copyright 2010 Robin Appelman icewind1991@gmail.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library.  If not, see <http://www.gnu.org/licenses/>.
*
*/
// only need filesystem apps
$RUNTIME_APPTYPES = array('filesystem');
// Init owncloud
// Check if we are a user
OCP\User::checkLoggedIn();
$files = $_GET["files"];
$dir = $_GET["dir"];
$files_list = json_decode($files);
// in case we get only a single file
if (!is_array($files_list)) {
    $files_list = array($files);
}
OC_Files::get($dir, $files_list, $_SERVER['REQUEST_METHOD'] == 'HEAD');
<?php

// Init owncloud
require_once '../../lib/base.php';
OC_JSON::checkLoggedIn();
// Get data
$dir = $_GET["dir"];
$files = isset($_GET["file"]) ? $_GET["file"] : $_GET["files"];
$files = explode(';', $files);
$filesWithError = '';
$success = true;
//Now delete
foreach ($files as $file) {
    if (!OC_Files::delete($dir, $file)) {
        $filesWithError .= $file . "\n";
        $success = false;
    }
}
if ($success) {
    OC_JSON::success(array("data" => array("dir" => $dir, "files" => $files)));
} else {
    OC_JSON::error(array("data" => array("message" => "Could not delete:\n" . $filesWithError)));
}
Example #27
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')) {
    OCP\JSON::success(array("data" => array()));
    exit;
}
OCP\JSON::error(array("data" => array("message" => "Error when creating the folder")));
Example #28
0
<?php

// Init owncloud
OCP\JSON::checkLoggedIn();
OCP\JSON::callCheck();
// Get data
$dir = stripslashes($_GET["dir"]);
$file = stripslashes($_GET["file"]);
$newname = stripslashes($_GET["newname"]);
// Delete
if (OC_Files::move($dir, $file, $dir, $newname)) {
    OCP\JSON::success(array("data" => array("dir" => $dir, "file" => $file, "newname" => $newname)));
} else {
    OCP\JSON::error(array("data" => array("message" => "Unable to rename file")));
}
Example #29
0
 public static function zipAddDir($dir, $zip, $internalDir = '')
 {
     $dirname = basename($dir);
     $zip->addEmptyDir($internalDir . $dirname);
     $internalDir .= $dirname .= '/';
     $files = OC_Files::getdirectorycontent($dir);
     foreach ($files as $file) {
         $filename = $file['name'];
         $file = $dir . '/' . $filename;
         if (OC_Filesystem::is_file($file)) {
             $tmpFile = OC_Filesystem::toTmpFile($file);
             OC_Files::$tmpFiles[] = $tmpFile;
             $zip->addFile($tmpFile, $internalDir . $filename);
         } elseif (OC_Filesystem::is_dir($file)) {
             self::zipAddDir($file, $zip, $internalDir);
         }
     }
 }
Example #30
0
                    $song['album'] = OC_MEDIA_COLLECTION::getAlbumName($song['song_album']);
                    OCP\JSON::encodedPrint($song);
                }
            }
            break;
        case 'play':
            @ob_end_clean();
            $ftype = OC_Filesystem::getMimeType($arguments['path']);
            if (substr($ftype, 0, 5) != 'audio' and $ftype != 'application/ogg') {
                echo 'Not an audio file';
                exit;
            }
            $songId = OC_MEDIA_COLLECTION::getSongByPath($arguments['path']);
            OC_MEDIA_COLLECTION::registerPlay($songId);
            header('Content-Type:' . $ftype);
            OCP\Response::enableCaching(3600 * 24);
            // 24 hour
            header('Accept-Ranges: bytes');
            header('Content-Length: ' . OC_Filesystem::filesize($arguments['path']));
            $mtime = OC_Filesystem::filemtime($arguments['path']);
            OCP\Response::setLastModifiedHeader($mtime);
            OC_Filesystem::readfile($arguments['path']);
            exit;
        case 'find_music':
            $music = OC_Files::searchByMime('audio');
            $ogg = OC_Files::searchByMime('application/ogg');
            $music = array_merge($music, $ogg);
            OCP\JSON::encodedPrint($music);
            exit;
    }
}