* @return Returns true if backend is registered or false if error
*/
public static function registerBackend($itemType, $class, $collectionOf = null, $supportedFileExtensions = null) {
- if (!isset(self::$backendTypes[$itemType])) {
- self::$backendTypes[$itemType] = array('class' => $class, 'collectionOf' => $collectionOf, 'supportedFileExtensions' => $supportedFileExtensions);
- if(count(self::$backendTypes) === 1) {
- \OC_Util::addScript('core', 'share');
- \OC_Util::addStyle('core', 'share');
+ if (self::isEnabled()) {
+ if (!isset(self::$backendTypes[$itemType])) {
+ self::$backendTypes[$itemType] = array('class' => $class, 'collectionOf' => $collectionOf, 'supportedFileExtensions' => $supportedFileExtensions);
+ if(count(self::$backendTypes) === 1) {
+ \OC_Util::addScript('core', 'share');
+ \OC_Util::addStyle('core', 'share');
+ }
+ return true;
}
+ \OC_Log::write('OCP\Share', 'Sharing backend '.$class.' not registered, '.self::$backendTypes[$itemType]['class'].' is already registered for '.$itemType, \OC_Log::WARN);
+ }
+ return false;
+ }
+
+ /**
+ * @brief Check if the Share API is enabled
+ * @return Returns true if enabled or false
+ *
+ * The Share API is enabled by default if not configured
+ *
+ */
+ public static function isEnabled() {
+ if (\OC_Appconfig::getValue('core', 'shareapi_enabled', 'yes') == 'yes') {
return true;
}
- \OC_Log::write('OCP\Share', 'Sharing backend '.$class.' not registered, '.self::$backendTypes[$itemType]['class'].' is already registered for '.$itemType, \OC_Log::WARN);
return false;
}
\OC_Log::write('OCP\Share', $message, \OC_Log::ERROR);
throw new \Exception($message);
}
- $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);
+ if (\OC_Appconfig::getValue('core', 'shareapi_share_policy', 'global') == '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)) {
$shareWith['group'] = $group;
$shareWith['users'] = array_diff(\OC_Group::usersInGroup($group), array($uidOwner));
} else if ($shareType === self::SHARE_TYPE_LINK) {
- // 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', ''));
+ if (\OC_Appconfig::getValue('core', 'shareapi_allow_links', 'yes') == 'yes') {
+ // 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);
}
- 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';
*
*/
private static function getItems($itemType, $item = null, $shareType = null, $shareWith = null, $uidOwner = null, $format = self::FORMAT_NONE, $parameters = null, $limit = -1, $includeCollections = false, $itemShareWithBySource = false) {
+ if (!self::isEnabled()) {
+ if ($limit == 1 || (isset($uidOwner) && isset($item))) {
+ return false;
+ } else {
+ return array();
+ }
+ }
$backend = self::getBackend($itemType);
// Get filesystem root to add it to the file target and remove from the file source, match file_source with the file cache
if ($itemType == 'file' || $itemType == 'folder') {
<label for="backgroundjobs_cron" title="<?php echo $l->t("use systems cron service"); ?>">Cron</label><br />
</fieldset>
+<fieldset class="personalblock" id="shareAPI">
+ <legend><strong><?php echo $l->t('Share API');?></strong></legend>
+ <table class="shareAPI nostyle">
+ <tr>
+ <td id="enable">
+ <input type="checkbox" name="shareapi_enabled" id="shareAPIEnabled" value="1" <?php if ($_['shareAPIEnabled'] == 'yes') echo 'checked="checked"'; ?> />
+ <label for="shareAPIEnabled"><?php echo $l->t('Enable Share API');?></label><br />
+ <em><?php echo $l->t('Allow apps to use the Share API'); ?></em>
+ </td>
+ <td <?php if ($_['shareAPIEnabled'] == 'no') echo 'style="display:none"';?>>
+ <input type="checkbox" name="shareapi_allow_links" id="allowLinks" value="1" <?php if ($_['allowLinks'] == 'yes') echo 'checked="checked"'; ?> />
+ <label for="allowLinks"><?php echo $l->t('Allow links');?></label><br />
+ <em><?php echo $l->t('Allow users to share items to the public with links'); ?></em>
+ </td>
+ <td <?php if ($_['shareAPIEnabled'] == 'no') echo 'style="display:none"';?>>
+ <input type="checkbox" name="shareapi_allow_resharing" id="allowResharing" value="1" <?php if ($_['allowResharing'] == 'yes') echo 'checked="checked"'; ?> />
+ <label for="allowResharing"><?php echo $l->t('Allow resharing');?></label><br />
+ <em><?php echo $l->t('Allow users to share items shared with them again'); ?></em>
+ <td <?php if ($_['shareAPIEnabled'] == 'no') echo 'style="display:none"';?>>
+ <input type="radio" name="shareapi_share_policy" id="sharePolicyGlobal" value="global" <?php if ($_['sharePolicy'] == 'global') echo 'checked="checked"'; ?> />
+ <label for="sharePolicyGlobal"><?php echo $l->t('Allow users to share with anyone'); ?></label><br />
+ <input type="radio" name="shareapi_share_policy" id="sharePolicyGroupsOnly" value="groups_only" <?php if ($_['sharePolicy'] == 'groups_only') echo 'checked="checked"'; ?> />
+ <label for="sharePolicyGroupsOnly"><?php echo $l->t('Allow users to only share with users in their groups');?></label><br />
+ </td>
+ </tr>
+ </table>
+</fieldset>
+
<fieldset class="personalblock">
<legend><strong><?php echo $l->t('Log');?></strong></legend>
Log level: <select name='loglevel' id='loglevel'>