public static function renameDocument($args) { $fileId = intval(@$args['file_id']); $name = @$_POST['name']; $file = new File($fileId); $l = new \OC_L10n('documents'); if (isset($name) && $file->getPermissions() & \OCP\PERMISSION_UPDATE) { if ($file->renameTo($name)) { // TODO: propagate to other clients \OCP\JSON::success(); return; } } \OCP\JSON::error(array('message' => $l->t('You don\'t have permission to rename this document'))); }
case STREAM_NOTIFY_PROGRESS: if ($bytes_transferred > 0) { if (!isset($filesize)) { } else { $progress = (int) ($bytes_transferred / $filesize * 100); if ($progress > $lastsize) { //limit the number or messages send $eventSource->send('progress', $progress); } $lastsize = $progress; } } break; } } $l10n = \OC_L10n::get('files'); $result = array('success' => false, 'data' => NULL); if (trim($filename) === '') { $result['data'] = array('message' => $l10n->t('File name cannot be empty.')); OCP\JSON::error($result); exit; } if (strpos($filename, '/') !== false) { $result['data'] = array('message' => $l10n->t('File name must not contain "/". Please choose a different name.')); OCP\JSON::error($result); exit; } //TODO why is stripslashes used on foldername in newfolder.php but not here? $target = $dir . '/' . $filename; if (\OC\Files\Filesystem::file_exists($target)) { $result['data'] = array('message' => $l10n->t('The name %s is already used in the folder %s. Please choose a different name.', array($filename, $dir)));
public static function changeUserPassword($args) { // Check if we are an user \OC_JSON::callCheck(); \OC_JSON::checkLoggedIn(); $l = new \OC_L10n('settings'); if (isset($_POST['username'])) { $username = $_POST['username']; } else { \OC_JSON::error(array('data' => array('message' => $l->t('No user supplied')))); exit; } $password = isset($_POST['password']) ? $_POST['password'] : null; $recoveryPassword = isset($_POST['recoveryPassword']) ? $_POST['recoveryPassword'] : null; $isUserAccessible = false; $currentUserObject = \OC::$server->getUserSession()->getUser(); $targetUserObject = \OC::$server->getUserManager()->get($username); if ($currentUserObject !== null && $targetUserObject !== null) { $isUserAccessible = \OC::$server->getGroupManager()->getSubAdmin()->isUserAccessible($currentUserObject, $targetUserObject); } if (\OC_User::isAdminUser(\OC_User::getUser())) { $userstatus = 'admin'; } elseif ($isUserAccessible) { $userstatus = 'subadmin'; } else { \OC_JSON::error(array('data' => array('message' => $l->t('Authentication error')))); exit; } if (\OC_App::isEnabled('encryption')) { //handle the recovery case $crypt = new \OCA\Encryption\Crypto\Crypt(\OC::$server->getLogger(), \OC::$server->getUserSession(), \OC::$server->getConfig(), \OC::$server->getL10N('encryption')); $keyStorage = \OC::$server->getEncryptionKeyStorage(); $util = new \OCA\Encryption\Util(new \OC\Files\View(), $crypt, \OC::$server->getLogger(), \OC::$server->getUserSession(), \OC::$server->getConfig(), \OC::$server->getUserManager()); $keyManager = new \OCA\Encryption\KeyManager($keyStorage, $crypt, \OC::$server->getConfig(), \OC::$server->getUserSession(), new \OCA\Encryption\Session(\OC::$server->getSession()), \OC::$server->getLogger(), $util); $recovery = new \OCA\Encryption\Recovery(\OC::$server->getUserSession(), $crypt, \OC::$server->getSecureRandom(), $keyManager, \OC::$server->getConfig(), $keyStorage, \OC::$server->getEncryptionFilesHelper(), new \OC\Files\View()); $recoveryAdminEnabled = $recovery->isRecoveryKeyEnabled(); $validRecoveryPassword = false; $recoveryEnabledForUser = false; if ($recoveryAdminEnabled) { $validRecoveryPassword = $keyManager->checkRecoveryPassword($recoveryPassword); $recoveryEnabledForUser = $recovery->isRecoveryEnabledForUser($username); } if ($recoveryEnabledForUser && $recoveryPassword === '') { \OC_JSON::error(array('data' => array('message' => $l->t('Please provide an admin recovery password, otherwise all user data will be lost')))); } elseif ($recoveryEnabledForUser && !$validRecoveryPassword) { \OC_JSON::error(array('data' => array('message' => $l->t('Wrong admin recovery password. Please check the password and try again.')))); } else { // now we know that everything is fine regarding the recovery password, let's try to change the password $result = \OC_User::setPassword($username, $password, $recoveryPassword); if (!$result && $recoveryEnabledForUser) { \OC_JSON::error(array("data" => array("message" => $l->t("Backend doesn't support password change, but the user's encryption key was successfully updated.")))); } elseif (!$result && !$recoveryEnabledForUser) { \OC_JSON::error(array("data" => array("message" => $l->t("Unable to change password")))); } else { \OC_JSON::success(array("data" => array("username" => $username))); } } } else { // if encryption is disabled, proceed if (!is_null($password) && \OC_User::setPassword($username, $password)) { \OC_JSON::success(array('data' => array('username' => $username))); } else { \OC_JSON::error(array('data' => array('message' => $l->t('Unable to change password')))); } } }
public static function unFavorite($args) { $tagger = self::getTagger($args['type']); if (!$tagger->removeFromFavorites($args['id'])) { $l = new \OC_L10n('core'); \OC_JSON::error(array('message' => $l->t('Error unfavoriting'))); } else { \OC_JSON::success(); } }
public static function changeUserPassword($args) { // Check if we are an user \OC_JSON::callCheck(); \OC_JSON::checkLoggedIn(); // Manually load apps to ensure hooks work correctly (workaround for issue 1503) \OC_App::loadApps(); if (isset($_POST['username'])) { $username = $_POST['username']; } else { $l = new \OC_L10n('settings'); \OC_JSON::error(array('data' => array('message' => $l->t('No user supplied')))); exit; } $password = isset($_POST['password']) ? $_POST['password'] : null; $recoveryPassword = isset($_POST['recoveryPassword']) ? $_POST['recoveryPassword'] : null; if (\OC_User::isAdminUser(\OC_User::getUser())) { $userstatus = 'admin'; } elseif (\OC_SubAdmin::isUserAccessible(\OC_User::getUser(), $username)) { $userstatus = 'subadmin'; } else { $l = new \OC_L10n('settings'); \OC_JSON::error(array('data' => array('message' => $l->t('Authentication error')))); exit; } if (\OC_App::isEnabled('files_encryption')) { //handle the recovery case $util = new \OCA\Encryption\Util(new \OC_FilesystemView('/'), $username); $recoveryAdminEnabled = \OC_Appconfig::getValue('files_encryption', 'recoveryAdminEnabled'); $validRecoveryPassword = false; $recoveryPasswordSupported = false; if ($recoveryAdminEnabled) { $validRecoveryPassword = $util->checkRecoveryPassword($recoveryPassword); $recoveryEnabledForUser = $util->recoveryEnabledForUser(); } if ($recoveryEnabledForUser && $recoveryPassword === '') { $l = new \OC_L10n('settings'); \OC_JSON::error(array('data' => array('message' => $l->t('Please provide an admin recovery password, otherwise all user data will be lost')))); } elseif ($recoveryEnabledForUser && !$validRecoveryPassword) { $l = new \OC_L10n('settings'); \OC_JSON::error(array('data' => array('message' => $l->t('Wrong admin recovery password. Please check the password and try again.')))); } else { // now we know that everything is fine regarding the recovery password, let's try to change the password $result = \OC_User::setPassword($username, $password, $recoveryPassword); if (!$result && $recoveryPasswordSupported) { $l = new \OC_L10n('settings'); \OC_JSON::error(array("data" => array("message" => $l->t("Back-end doesn't support password change, but the users encryption key was successfully updated.")))); } elseif (!$result && !$recoveryPasswordSupported) { $l = new \OC_L10n('settings'); \OC_JSON::error(array("data" => array("message" => $l->t("Unable to change password")))); } else { \OC_JSON::success(array("data" => array("username" => $username))); } } } else { // if encryption is disabled, proceed if (!is_null($password) && \OC_User::setPassword($username, $password)) { \OC_JSON::success(array('data' => array('username' => $username))); } else { $l = new \OC_L10n('settings'); \OC_JSON::error(array('data' => array('message' => $l->t('Unable to change password')))); } } }
public static function postCroppedAvatar($args) { \OC_JSON::checkLoggedIn(); \OC_JSON::callCheck(); $user = \OC_User::getUser(); if (isset($_POST['crop'])) { $crop = $_POST['crop']; } else { $l = new \OC_L10n('core'); \OC_JSON::error(array("data" => array("message" => $l->t("No crop data provided")))); return; } $tmpavatar = \OC_Cache::get('tmpavatar'); if (is_null($tmpavatar)) { $l = new \OC_L10n('core'); \OC_JSON::error(array("data" => array("message" => $l->t("No temporary profile picture available, try again")))); return; } $image = new \OC_Image($tmpavatar); $image->crop($crop['x'], $crop['y'], $crop['w'], $crop['h']); try { $avatar = new \OC_Avatar($user); $avatar->set($image->data()); // Clean up \OC_Cache::remove('tmpavatar'); \OC_JSON::success(); } catch (\Exception $e) { \OC_JSON::error(array("data" => array("message" => $e->getMessage()))); } }
* 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/>. * */ /** * @file appinfo/app.php * @brief Basic registration of app inside ownCloud * @author Christian Reiner */ $l = new OC_L10n('imprint'); OCP\App::registerAdmin('imprint', 'settings'); OCP\Util::addStyle('imprint', 'imprint'); // workaround for OC-4.x's chaotoc header layout if (5 > @reset(OCP\Util::getVersion())) { OCP\Util::addStyle('imprint', 'imprint-oc4'); } // backwards compatibility for OC5's global p() functions $ocVersion = implode('.', OCP\Util::getVersion()); if (version_compare($ocVersion, '4.93', '<')) { if (!function_exists('p')) { function p($string) { print OCP\Util::sanitizeHTML($string); } }
/** * ownCloud - Core * * @author Morris Jobke * @copyright 2013 Morris Jobke morris.jobke@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/>. * */ OCP\JSON::checkLoggedIn(); OCP\JSON::callCheck(); \OC::$session->close(); $files = new \OCA\Files\App(\OC\Files\Filesystem::getView(), \OC_L10n::get('files')); $result = $files->rename($_GET["dir"], $_GET["file"], $_GET["newname"]); if ($result['success'] === true) { OCP\JSON::success(array('data' => $result['data'])); } else { OCP\JSON::error(array('data' => $result['data'])); }