示例#1
0
 /**
  * Returns the rendered json
  * @return the rendered json
  */
 public function render()
 {
     parent::render();
     ob_start();
     if ($this->error) {
         \OCP\JSON::error($this->data);
     } else {
         \OCP\JSON::success($this->data);
     }
     $result = ob_get_contents();
     ob_end_clean();
     return $result;
 }
 public static function rename($args)
 {
     self::preDispatch();
     $fileId = intval(Helper::getArrayValueByKey($args, 'file_id', 0));
     $name = Helper::getArrayValueByKey($_POST, 'name');
     $view = \OC\Files\Filesystem::getView();
     $path = $view->getPath($fileId);
     if (isset($name) && $view->is_file($path) && $view->isUpdatable($path)) {
         $newPath = dirname($path) . '/' . $name;
         if ($view->rename($path, $newPath)) {
             \OCP\JSON::success();
             return;
         }
     }
     \OCP\JSON::error(array('message' => Config::getL10n()->t('You don\'t have permission to rename this document')));
 }
 /**
  * Send JSON response on successful login
  * @param String $uid
  */
 public static function postlogin_hook($uid)
 {
     if (!self::$_isPersona) {
         return;
     }
     \OCP\Util::writeLog(App::APP_ID, 'Check ambigous ', \OCP\Util::DEBUG);
     if (self::$_isAmbigous) {
         //Reply with error and logout
         \OCP\User::logout();
         \OCP\JSON::error(array('msg' => 'More than one user found'));
         exit;
     } else {
         \OCP\JSON::success(array('msg' => 'Access granted'));
         exit;
     }
 }
示例#4
0
 /**
  * Sets up the filesystem and user for public sharing
  * @param string $token string share token
  * @param string $relativePath optional path relative to the share
  * @param string $password optional password
  */
 public static function setupFromToken($token, $relativePath = null, $password = null)
 {
     \OC_User::setIncognitoMode(true);
     $linkItem = \OCP\Share::getShareByToken($token, !$password);
     if ($linkItem === false || $linkItem['item_type'] !== 'file' && $linkItem['item_type'] !== 'folder') {
         \OC_Response::setStatus(404);
         \OC_Log::write('core-preview', 'Passed token parameter is not valid', \OC_Log::DEBUG);
         exit;
     }
     if (!isset($linkItem['uid_owner']) || !isset($linkItem['file_source'])) {
         \OC_Response::setStatus(500);
         \OC_Log::write('core-preview', 'Passed token seems to be valid, but it does not contain all necessary information . ("' . $token . '")', \OC_Log::WARN);
         exit;
     }
     $rootLinkItem = \OCP\Share::resolveReShare($linkItem);
     $path = null;
     if (isset($rootLinkItem['uid_owner'])) {
         \OCP\JSON::checkUserExists($rootLinkItem['uid_owner']);
         \OC_Util::tearDownFS();
         \OC_Util::setupFS($rootLinkItem['uid_owner']);
         $path = \OC\Files\Filesystem::getPath($linkItem['file_source']);
     }
     if ($path === null) {
         \OCP\Util::writeLog('share', 'could not resolve linkItem', \OCP\Util::DEBUG);
         \OC_Response::setStatus(404);
         \OCP\JSON::error(array('success' => false));
         exit;
     }
     if (!isset($linkItem['item_type'])) {
         \OCP\Util::writeLog('share', 'No item type set for share id: ' . $linkItem['id'], \OCP\Util::ERROR);
         \OC_Response::setStatus(404);
         \OCP\JSON::error(array('success' => false));
         exit;
     }
     if (isset($linkItem['share_with'])) {
         if (!self::authenticate($linkItem, $password)) {
             \OC_Response::setStatus(403);
             \OCP\JSON::error(array('success' => false));
             exit;
         }
     }
     $basePath = $path;
     if ($relativePath !== null && \OC\Files\Filesystem::isReadable($basePath . $relativePath)) {
         $path .= \OC\Files\Filesystem::normalizePath($relativePath);
     }
     return array('linkItem' => $linkItem, 'basePath' => $basePath, 'realPath' => $path);
 }
示例#5
0
 public static function av_scan($path)
 {
     $path = $path[\OC\Files\Filesystem::signal_param_path];
     if ($path != '') {
         if (isset($_POST['dirToken'])) {
             //Public upload case
             $filesView = \OC\Files\Filesystem::getView();
         } else {
             $filesView = \OCP\Files::getStorage("files");
         }
         if (!is_object($filesView)) {
             \OCP\Util::writeLog('files_antivirus', 'Can\'t init filesystem view', \OCP\Util::WARN);
             return;
         }
         // check if path is a directory
         if ($filesView->is_dir($path)) {
             return;
         }
         // we should have a file to work with, and the file shouldn't
         // be empty
         $fileExists = $filesView->file_exists($path);
         if ($fileExists && $filesView->filesize($path) > 0) {
             $fileStatus = self::scanFile($filesView, $path);
             $result = $fileStatus->getNumericStatus();
             switch ($result) {
                 case Status::SCANRESULT_UNCHECKED:
                     //TODO: Show warning to the user: The file can not be checked
                     break;
                 case Status::SCANRESULT_INFECTED:
                     //remove file
                     $filesView->unlink($path);
                     Notification::sendMail($path);
                     $message = \OCP\Util::getL10N('files_antivirus')->t("Virus detected! Can't upload the file %s", array(basename($path)));
                     \OCP\JSON::error(array("data" => array("message" => $message)));
                     exit;
                     break;
                 case Status::SCANRESULT_CLEAN:
                     //do nothing
                     break;
             }
         }
     }
 }
示例#6
0
 public function __construct($AppName, IRequest $request, $UserId)
 {
     parent::__construct($AppName, $request);
     $this->userId = $UserId;
     $path = self::PROJECTKIT_PREFIX . DIRECTORY_SEPARATOR;
     if (isset($_GET['containerId'])) {
         $path .= self::PROJECT_PREFIX . (string) $_GET['containerId'] . DIRECTORY_SEPARATOR;
         if (isset($_GET['targetType']) && isset($_GET['targetId'])) {
             switch ($_GET['targetType']) {
                 case TargetType::TASK:
                     $path .= self::TASK_PREFIX;
                     break;
                 case TargetType::ISSUE:
                     $path .= self::ISSUE_PREFIX;
                     break;
                 default:
                     break;
             }
             $path .= (string) $_GET['targetId'] . DIRECTORY_SEPARATOR;
             $_SESSION['targetType'] = $_GET['targetType'];
         } elseif (!isset($_GET['targetType']) && !isset($_GET['targetId'])) {
             $_SESSION['targetType'] = TargetType::PROJECT;
         }
         //use session to save targetType
         $path = Filesystem::normalizePath($path);
         //Create folder for path
         if (!Filesystem::file_exists($path)) {
             try {
                 Filesystem::mkdir($path);
             } catch (\Exception $e) {
                 $result = ['success' => false, 'data' => ['message' => $e->getMessage()]];
                 \OCP\JSON::error($result);
                 exit;
             }
         }
         if (!isset($_GET['dir'])) {
             $params = array_merge($_GET, ["dir" => $path]);
             $url = $_SERVER['PHP_SELF'] . '?' . http_build_query($params);
             header('Location: ' . $url, true, 302);
             exit;
         }
     }
 }
 public static function joinAsUser($args)
 {
     $uid = self::preDispatch();
     $fileId = Helper::getArrayValueByKey($args, 'file_id');
     try {
         $view = \OC\Files\Filesystem::getView();
         $path = $view->getPath($fileId);
         if ($view->isUpdatable($path)) {
             $file = new File($fileId);
             $session = Db\Session::start($uid, $file);
             \OCP\JSON::success($session);
         } else {
             $info = $view->getFileInfo($path);
             \OCP\JSON::success(array('permissions' => $info['permissions'], 'id' => $fileId));
         }
         exit;
     } catch (\Exception $e) {
         Helper::warnLog('Starting a session failed. Reason: ' . $e->getMessage());
         \OCP\JSON::error();
         exit;
     }
 }
示例#8
0
 * Copyright (c) 2013, Sam Tuke <*****@*****.**>
 * This file is licensed under the Affero General Public License version 3 or later.
 * See the COPYING-README file.
 *
 * Script to handle admin settings for encrypted key recovery
 */
use OCA\Encryption;
\OCP\JSON::checkLoggedIn();
\OCP\JSON::checkAppEnabled('files_encryption');
\OCP\JSON::callCheck();
$l = \OC::$server->getL10N('files_encryption');
if (isset($_POST['userEnableRecovery']) && (0 == $_POST['userEnableRecovery'] || '1' === $_POST['userEnableRecovery'])) {
    $userId = \OCP\USER::getUser();
    $view = new \OC\Files\View('/');
    $util = new \OCA\Encryption\Util($view, $userId);
    // Save recovery preference to DB
    $return = $util->setRecoveryForUser($_POST['userEnableRecovery']);
    if ($_POST['userEnableRecovery'] === '1') {
        $util->addRecoveryKeys();
    } else {
        $util->removeRecoveryKeys();
    }
} else {
    $return = false;
}
// Return success or failure
if ($return) {
    \OCP\JSON::success(array('data' => array('message' => $l->t('File recovery settings updated'))));
} else {
    \OCP\JSON::error(array('data' => array('message' => $l->t('Could not update file recovery'))));
}
示例#9
0
<?php

/**
 * ownCloud - gsync plugin
 * 
 * @author Victor Dubiniuk
 * @copyright 2012-2013 Victor Dubiniuk victor.dubiniuk@gmail.com
 * 
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 */
namespace OCA_Gsync;

App::initAjaxController();
// Get data
if (isset($_POST[App::GOOGLE_CLIENT_ID])) {
    App::setClientId($_POST[App::GOOGLE_CLIENT_ID]);
} elseif (isset($_POST[App::GOOGLE_SECRET])) {
    App::setSecret($_POST[App::GOOGLE_SECRET]);
} elseif (isset($_POST[App::GOOGLE_REFRESH_TOKEN])) {
    $token = App::getRefreshToken();
    Request::revokeRefreshToken($token);
    App::setRefreshToken('');
} else {
    \OCP\JSON::error(array("data" => array("message" => App::$l10n->t("Invalid request"))));
}
\OCP\JSON::success(array("data" => array("message" => App::$l10n->t("Saved"))));
示例#10
0
<?php

OCP\JSON::checkLoggedIn();
OCP\JSON::callCheck();
$l = \OC::$server->getL10N('settings');
$util = new \OCA\Files_Encryption\Util(new \OC\Files\View(), \OC_User::getUser());
$result = $util->restoreBackup('decryptAll');
if ($result) {
    \OCP\JSON::success(array('data' => array('message' => $l->t('Backups restored successfully'))));
} else {
    \OCP\JSON::error(array('data' => array('message' => $l->t('Couldn\'t restore your encryption keys, please check your owncloud.log or ask your administrator'))));
}
示例#11
0
    $password = $_POST['password'];
}
$relativePath = null;
if (isset($_GET['dir'])) {
    $relativePath = $_GET['dir'];
}
$sortAttribute = isset($_GET['sort']) ? $_GET['sort'] : 'name';
$sortDirection = isset($_GET['sortdirection']) ? $_GET['sortdirection'] === 'desc' : false;
$data = \OCA\Files_Sharing\Helper::setupFromToken($token, $relativePath, $password);
$linkItem = $data['linkItem'];
// Load the files
$dir = $data['realPath'];
$dir = \OC\Files\Filesystem::normalizePath($dir);
if (!\OC\Files\Filesystem::is_dir($dir . '/')) {
    \OC_Response::setStatus(\OC_Response::STATUS_NOT_FOUND);
    \OCP\JSON::error(array('success' => false));
    exit;
}
$data = array();
// make filelist
$files = \OCA\Files\Helper::getFiles($dir, $sortAttribute, $sortDirection);
$formattedFiles = array();
foreach ($files as $file) {
    $entry = \OCA\Files\Helper::formatFileInfo($file);
    unset($entry['directory']);
    // for now
    $entry['permissions'] = \OCP\PERMISSION_READ;
    $formattedFiles[] = $entry;
}
$data['directory'] = $relativePath;
$data['files'] = $formattedFiles;
示例#12
0
 * This file is licensed under the Affero General Public License version 3 or later.
 * See the COPYING-README file.
 *
 * Script to handle admin settings for encrypted key recovery
 */
use OCA\Encryption;
\OCP\JSON::checkAdminUser();
\OCP\JSON::checkAppEnabled('files_encryption');
\OCP\JSON::callCheck();
$l = OC_L10N::get('files_encryption');
$return = false;
// Enable recoveryAdmin
$recoveryKeyId = \OC::$server->getAppConfig()->getValue('files_encryption', 'recoveryKeyId');
if (isset($_POST['adminEnableRecovery']) && $_POST['adminEnableRecovery'] === '1') {
    $return = \OCA\Encryption\Helper::adminEnableRecovery($recoveryKeyId, $_POST['recoveryPassword']);
    // Return success or failure
    if ($return) {
        \OCP\JSON::success(array('data' => array('message' => $l->t('Recovery key successfully enabled'))));
    } else {
        \OCP\JSON::error(array('data' => array('message' => $l->t('Could not enable recovery key. Please check your recovery key password!'))));
    }
    // Disable recoveryAdmin
} elseif (isset($_POST['adminEnableRecovery']) && '0' === $_POST['adminEnableRecovery']) {
    $return = \OCA\Encryption\Helper::adminDisableRecovery($_POST['recoveryPassword']);
    // Return success or failure
    if ($return) {
        \OCP\JSON::success(array('data' => array('message' => $l->t('Recovery key successfully disabled'))));
    } else {
        \OCP\JSON::error(array('data' => array('message' => $l->t('Could not disable recovery key. Please check your recovery key password!'))));
    }
}
示例#13
0
        } catch (\Exception $e) {
            \OCP\JSON::error(array('message' => $e->getMessage()));
            exit;
        }
        \OCP\JSON::error();
        exit;
        break;
    case 'save':
        $key = isset($_POST['cfgkey']) ? $_POST['cfgkey'] : false;
        $val = isset($_POST['cfgval']) ? $_POST['cfgval'] : null;
        if ($key === false || is_null($val)) {
            \OCP\JSON::error(array('message' => $l->t('No data specified')));
            exit;
        }
        $cfg = array($key => $val);
        $setParameters = array();
        $configuration->setConfiguration($cfg, $setParameters);
        if (!in_array($key, $setParameters)) {
            \OCP\JSON::error(array('message' => $l->t($key . ' Could not set configuration %s', $setParameters[0])));
            exit;
        }
        $configuration->saveConfiguration();
        //clear the cache on save
        $connection = new \OCA\user_ldap\lib\Connection($ldapWrapper, $prefix);
        $connection->clearCache();
        OCP\JSON::success();
        break;
    default:
        //TODO: return 4xx error
        break;
}
示例#14
0
<?php

OCP\JSON::checkLoggedIn();
OCP\JSON::callCheck();
//encryption app needs to be loaded
OC_App::loadApp('files_encryption');
// init encryption app
$params = array('uid' => \OCP\User::getUser(), 'password' => $_POST['password']);
$view = new OC\Files\View('/');
$util = new \OCA\Encryption\Util($view, \OCP\User::getUser());
$l = \OC_L10N::get('settings');
$result = $util->initEncryption($params);
if ($result !== false) {
    try {
        $successful = $util->decryptAll();
    } catch (\Exception $ex) {
        \OCP\Util::writeLog('encryption library', "Decryption finished unexpected: " . $ex->getMessage(), \OCP\Util::ERROR);
        $successful = false;
    }
    $util->closeEncryptionSession();
    if ($successful === true) {
        \OCP\JSON::success(array('data' => array('message' => $l->t('Files decrypted successfully'))));
    } else {
        \OCP\JSON::error(array('data' => array('message' => $l->t('Couldn\'t decrypt your files, please check your owncloud.log or ask your administrator'))));
    }
} else {
    \OCP\JSON::error(array('data' => array('message' => $l->t('Couldn\'t decrypt your files, check your password and try again'))));
}
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
use Arnovr\Statistics\Api\ApiConnection;
use GuzzleHttp\Exception\RequestException;
use OCA\ocUsageCharts\AppInfo\Chart;
\OCP\JSON::checkLoggedIn();
\OCP\JSON::checkAppEnabled('ocusagecharts');
\OCP\JSON::callCheck();
$l = \OCP\Util::getL10N('ocusagecharts');
$app = new Chart();
$container = $app->getContainer();
/** @var ApiConnection $apiConnection */
$apiConnection = $container->query('ContentStatisticsClientApiConnection');
$data = array('data' => array('status' => 'success'));
try {
    if ($apiConnection->testConnection()) {
        \OCP\JSON::success($data);
        exit;
    }
} catch (RequestException $exception) {
}
$data = array('data' => array('status' => 'error'));
\OCP\JSON::error($data);
示例#16
0
文件: external.php 项目: Romua1d/core
$token = $_POST['token'];
$remote = $_POST['remote'];
$owner = $_POST['owner'];
$name = $_POST['name'];
$password = $_POST['password'];
// Check for invalid name
if (!\OCP\Util::isValidFileName($name)) {
    \OCP\JSON::error(array('data' => array('message' => $l->t('The mountpoint name contains invalid characters.'))));
    exit;
}
$externalManager = new \OCA\Files_Sharing\External\Manager(\OC::$server->getDatabaseConnection(), \OC\Files\Filesystem::getMountManager(), \OC\Files\Filesystem::getLoader(), \OC::$server->getUserSession());
$name = OCP\Files::buildNotExistingFileName('/', $name);
// check for ssl cert
if (substr($remote, 0, 5) === 'https' and !OC_Util::getUrlContent($remote)) {
    \OCP\JSON::error(array('data' => array('message' => $l->t("Invalid or untrusted SSL certificate"))));
    exit;
} else {
    $mount = $externalManager->addShare($remote, $token, $password, $name, $owner);
    /**
     * @var \OCA\Files_Sharing\External\Storage $storage
     */
    $storage = $mount->getStorage();
    $result = $storage->file_exists('');
    if ($result) {
        $storage->getScanner()->scanAll();
        \OCP\JSON::success();
    } else {
        $externalManager->removeShare($mount->getMountPoint());
        \OCP\JSON::error(array('data' => array('message' => $l->t("Couldn't add remote share"))));
    }
}
示例#17
0
 /**
  * @brief checks if an event was edited and dies if it was
  * @param (object) $vevent - vevent object of the event
  * @param (int) $lastmodified - time of last modification as unix timestamp
  * @return (bool)
  */
 public static function isNotModified($vevent, $lastmodified)
 {
     $last_modified = $vevent->__get('LAST-MODIFIED');
     if ($last_modified && $lastmodified != $last_modified->getDateTime()->format('U')) {
         \OCP\JSON::error(array('modified' => true));
         exit;
     }
     return true;
 }
示例#18
0
 * @author Frank de Lange
 * @copyright 2014 Frank de Lange
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 */
namespace OCA\Files_Opds;

\OCP\JSON::callCheck();
\OCP\JSON::checkLoggedIn();
$l = new \OC_L10N('files_opds');
$opdsEnable = isset($_POST['opdsEnable']) ? $_POST['opdsEnable'] : 'false';
$rootPath = isset($_POST['rootPath']) ? $_POST['rootPath'] : '/Library';
$fileTypes = isset($_POST['fileTypes']) ? $_POST['fileTypes'] : '';
$skipList = isset($_POST['skipList']) ? $_POST['skipList'] : 'metadata.opf,cover.jpg';
$feedTitle = isset($_POST['feedTitle']) ? $_POST['feedTitle'] : $l->t("%s's Library", \OCP\User::getDisplayName());
if (!is_null($rootPath)) {
    if (\OC\Files\Filesystem::file_exists($rootPath) === false) {
        \OCP\JSON::error(array('data' => array('message' => $l->t('Directory does not exist!'))));
    } else {
        Config::set('root_path', $rootPath);
        \OCP\JSON::success(array('data' => array('message' => $l->t('Settings updated successfully.'))));
    }
    Config::set('enable', $opdsEnable);
    Config::set('file_types', $fileTypes);
    Config::set('skip_list', $skipList);
    Config::set('feed_title', $feedTitle);
    Config::set('id', Util::genUuid());
    exit;
}
exit;
示例#19
0
<?php

/**
 * ownCloud - Documents App
 *
 * @author Victor Dubiniuk
 * @copyright 2013 Victor Dubiniuk victor.dubiniuk@gmail.com
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 */
namespace OCA\Documents;

\OCP\JSON::callCheck();
\OCP\JSON::checkLoggedIn();
$l = \OC_L10N::get('documents');
$savePath = isset($_POST['savePath']) ? $_POST['savePath'] : null;
if (!is_null($savePath)) {
    if (\OC\Files\Filesystem::file_exists($savePath) === false) {
        if (!\OC\Files\Filesystem::mkdir($savePath)) {
            \OCP\JSON::error(array('data' => array('message' => $l->t('An error occurred while changing directory.'))));
        }
    }
    \OCP\Config::setUserValue(\OCP\User::getUser(), 'documents', 'save_path', $savePath);
    \OCP\JSON::success(array('data' => array('message' => $l->t('Directory saved successfully.'))));
    exit;
}
exit;
示例#20
0
    $recipientList = array('name' => array(), 'email' => array());
    $sendTo = explode(',', $recipients);
    foreach ($sendTo as $recipient) {
        if (preg_match_all($pattern, $recipient, $matches)) {
            // We have 'John Doe <*****@*****.**>'
            $recipientList['name'][] = $matches[1][0];
            $recipientList['email'][] = $matches[2][0];
        } else {
            // Name is unknown, we have  email@example.org
            $recipientList['name'][] = '';
            $recipientList['email'][] = $recipient;
        }
    }
    //We only use the first recipient atm. (OC_Mail doesn't support multiple CC)
    $nameTo = array_shift($recipientList['name']);
    $emailTo = array_shift($recipientList['email']);
    try {
        $emailFrom = \OCP\Util::getDefaultEmailAddress('noreply');
        \OCP\Util::sendMail($emailTo, $nameTo, $subject, $message, $emailFrom, $nameFrom);
    } catch (Exception $e) {
        $status = false;
    }
} else {
    $status = false;
}
if ($status) {
    \OCP\JSON::success(array());
} else {
    \OCP\JSON::error(array());
}
exit;
示例#21
0
try {
    // check if storage exists
    $storage->checkStorageAvailability();
} catch (\OCP\Files\StorageInvalidException $e) {
    // note: checkStorageAvailability will already remove the invalid share
    \OCP\Util::writeLog('files_sharing', 'Invalid remote storage: ' . get_class($e) . ': ' . $e->getMessage(), \OCP\Util::DEBUG);
    \OCP\JSON::error(array('data' => array('message' => $l->t('Could not authenticate to remote share, password might be wrong'))));
    exit;
} catch (\Exception $e) {
    \OCP\Util::writeLog('files_sharing', 'Invalid remote storage: ' . get_class($e) . ': ' . $e->getMessage(), \OCP\Util::DEBUG);
    $externalManager->removeShare($mount->getMountPoint());
    \OCP\JSON::error(array('data' => array('message' => $l->t('Storage not valid'))));
    exit;
}
$result = $storage->file_exists('');
if ($result) {
    try {
        $storage->getScanner()->scanAll();
        \OCP\JSON::success();
    } catch (\OCP\Files\StorageInvalidException $e) {
        \OCP\Util::writeLog('files_sharing', 'Invalid remote storage: ' . get_class($e) . ': ' . $e->getMessage(), \OCP\Util::DEBUG);
        \OCP\JSON::error(array('data' => array('message' => $l->t('Storage not valid'))));
    } catch (\Exception $e) {
        \OCP\Util::writeLog('files_sharing', 'Invalid remote storage: ' . get_class($e) . ': ' . $e->getMessage(), \OCP\Util::DEBUG);
        \OCP\JSON::error(array('data' => array('message' => $l->t('Couldn\'t add remote share'))));
    }
} else {
    $externalManager->removeShare($mount->getMountPoint());
    \OCP\Util::writeLog('files_sharing', 'Couldn\'t add remote share', \OCP\Util::DEBUG);
    \OCP\JSON::error(array('data' => array('message' => $l->t('Couldn\'t add remote share'))));
}
示例#22
0
<?php

/**
* ownCloud
*
* @author Oliver Gasser
* @copyright 2013 Oliver Gasser
*
*/
// Check if this file is called by admin user, otherwise send JSON error
\OCP\JSON::checkAdminUser();
// Check if valid requesttoken was sent
\OCP\JSON::callCheck();
// Load translations
$l = OC_L10N::get('mozilla_sync');
// Get inputs and set correct settings
$quota = filter_var($_POST['quota'], FILTER_VALIDATE_INT);
if ($quota === false) {
    // Send error message
    \OCP\JSON::error(array("data" => array("message" => $l->t("Invalid input"))));
} else {
    // Update settings values
    \OCA\mozilla_sync\User::setQuota($quota);
    // Send success message
    \OCP\JSON::success(array("data" => array("message" => $l->t("Quota saved"))));
}
/* vim: set ts=4 sw=4 tw=80 noet : */
示例#23
0
<?php

/**
 * ownCloud - Updater plugin
 *
 * @author Victor Dubiniuk
 * @copyright 2014 Victor Dubiniuk victor.dubiniuk@gmail.com
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 */
namespace OCA\Updater;

\OCP\JSON::checkAdminUser();
\OCP\JSON::callCheck();
set_time_limit(0);
$request = file_get_contents('php://input');
$decodedRequest = json_decode($request, true);
// Downloading new version
$packageUrl = isset($decodedRequest['url']) ? $decodedRequest['url'] : '';
$packageVersion = isset($decodedRequest['version']) ? $decodedRequest['version'] : '';
try {
    Downloader::getPackage($packageUrl, $packageVersion);
    \OCP\JSON::success();
} catch (\Exception $e) {
    App::log($e->getMessage());
    \OCP\JSON::error(array('message' => $e->getMessage()));
}
示例#24
0
<?php

/**
 * Copyright (c) 2013, Sam Tuke <*****@*****.**>
 * This file is licensed under the Affero General Public License version 3 or later.
 * See the COPYING-README file.
 *
 * @brief Script to handle admin settings for encrypted key recovery
 */
use OCA\Encryption;
\OCP\JSON::checkLoggedIn();
\OCP\JSON::checkAppEnabled('files_encryption');
\OCP\JSON::callCheck();
if (isset($_POST['userEnableRecovery']) && (0 == $_POST['userEnableRecovery'] || '1' === $_POST['userEnableRecovery'])) {
    $userId = \OCP\USER::getUser();
    $view = new \OC_FilesystemView('/');
    $util = new \OCA\Encryption\Util($view, $userId);
    // Save recovery preference to DB
    $return = $util->setRecoveryForUser($_POST['userEnableRecovery']);
    if ($_POST['userEnableRecovery'] === '1') {
        $util->addRecoveryKeys();
    } else {
        $util->removeRecoveryKeys();
    }
} else {
    $return = false;
}
// Return success or failure
$return ? \OCP\JSON::success() : \OCP\JSON::error();
    $errorMessage = $l->t('Please repeat the new recovery password');
    \OCP\JSON::error(array('data' => array('message' => $errorMessage)));
    exit;
}
if ($_POST['newPassword'] !== $_POST['confirmPassword']) {
    $errorMessage = $l->t('Repeated recovery key password does not match the provided recovery key password');
    \OCP\JSON::error(array('data' => array('message' => $errorMessage)));
    exit;
}
$view = new \OC\Files\View('/');
$util = new \OCA\Files_Encryption\Util(new \OC\Files\View('/'), \OCP\User::getUser());
$proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false;
$keyId = $util->getRecoveryKeyId();
$encryptedRecoveryKey = \OCA\Files_Encryption\Keymanager::getPrivateSystemKey($keyId);
$decryptedRecoveryKey = $encryptedRecoveryKey ? \OCA\Files_Encryption\Crypt::decryptPrivateKey($encryptedRecoveryKey, $oldPassword) : false;
if ($decryptedRecoveryKey) {
    $cipher = \OCA\Files_Encryption\Helper::getCipher();
    $encryptedKey = \OCA\Files_Encryption\Crypt::symmetricEncryptFileContent($decryptedRecoveryKey, $newPassword, $cipher);
    if ($encryptedKey) {
        \OCA\Files_Encryption\Keymanager::setPrivateSystemKey($encryptedKey, $keyId);
        $return = true;
    }
}
\OC_FileProxy::$enabled = $proxyStatus;
// success or failure
if ($return) {
    \OCP\JSON::success(array('data' => array('message' => $l->t('Password successfully changed.'))));
} else {
    \OCP\JSON::error(array('data' => array('message' => $l->t('Could not change the password. Maybe the old password was not correct.'))));
}
示例#26
0
                        $response["ops"] = array();
                        $response["head_seq"] = $currentHead;
                    }
                } else {
                    // HEADs do not match
                    $response["ops"] = $op->getOpsAfterJson($esId, $seqHead);
                    $response["head_seq"] = $currentHead;
                    $response["result"] = $hasOps ? 'conflict' : 'new_ops';
                }
                $inactiveMembers = $member->updateByTimeout($esId);
                foreach ($inactiveMembers as $inactive) {
                    $op->removeCursor($esId, $inactive);
                    $op->removeMember($esId, $inactive);
                }
            } else {
                // Error - no seq_head passed
                throw new BadRequestException();
            }
            break;
        default:
            $ex = new BadRequestException();
            $ex->setBody($request->getRawRequest());
            throw $ex;
            break;
    }
    \OCP\JSON::success($response);
} catch (BadRequestException $e) {
    header('HTTP/1.1 400: BAD REQUEST');
    \OCP\JSON::error(array('err' => 'bad request:[' . $e->getBody() . ']'));
}
exit;
示例#27
0
文件: wizard.php 项目: evanjt/core
        } catch (\Exception $e) {
            \OCP\JSON::error(array('message' => $e->getMessage()));
            exit;
        }
        \OCP\JSON::error();
        exit;
        break;
    case 'save':
        $key = isset($_POST['cfgkey']) ? $_POST['cfgkey'] : false;
        $val = isset($_POST['cfgval']) ? $_POST['cfgval'] : null;
        if ($key === false || is_null($val)) {
            \OCP\JSON::error(array('message' => $l->t('No data specified')));
            exit;
        }
        $cfg = array($key => $val);
        $setParameters = array();
        $configuration->setConfiguration($cfg, $setParameters);
        if (!in_array($key, $setParameters)) {
            \OCP\JSON::error(array('message' => $l->t($key . ' Could not set configuration %s', $setParameters[0])));
            exit;
        }
        $configuration->saveConfiguration();
        //clear the cache on save
        $connection = new \OCA\user_ldap\lib\Connection($ldapWrapper, $prefix);
        $connection->clearCache();
        OCP\JSON::success();
        break;
    default:
        \OCP\JSON::error(array('message' => $l->t('Action does not exist')));
        break;
}
示例#28
0
文件: update.php 项目: samj1912/repo
<?php

/**
 * ownCloud - Updater plugin
 *
 * @author Victor Dubiniuk
 * @copyright 2013 Victor Dubiniuk victor.dubiniuk@gmail.com
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 */
namespace OCA\Updater;

\OCP\JSON::checkAdminUser();
\OCP\JSON::callCheck();
set_time_limit(0);
$request = file_get_contents('php://input');
$decodedRequest = json_decode($request, true);
$packageUrl = isset($decodedRequest['url']) ? $decodedRequest['url'] : '';
$packageVersion = isset($decodedRequest['version']) ? $decodedRequest['version'] : '';
$backupPath = isset($decodedRequest['backupPath']) ? $decodedRequest['backupPath'] : '';
try {
    Updater::update($packageVersion, $backupPath);
    // We are done. Some cleanup
    Downloader::cleanUp($packageVersion);
    Updater::cleanUp();
    \OCP\JSON::success();
} catch (\Exception $e) {
    App::log($e->getMessage());
    \OCP\JSON::error(array('message' => (string) App::$l10n->t('Update failed.') . $e->getMessage()));
}
示例#29
0
 */
namespace OCA_Updater;

\OCP\JSON::checkAdminUser();
// Url to download package e.g. http://download.owncloud.org/releases/owncloud-4.0.5.tar.bz2
$packageUrl = 'http://owncloud.org/releases/owncloud-latest.zip';
//Package version e.g. 4.0.4
$packageVersion = '';
$updateData = \OC_Updater::check();
if (isset($updateData['version'])) {
    $packageVersion = $updateData['version'];
}
if (isset($updateData['url']) && extension_loaded('bz2')) {
    $packageUrl = $updateData['url'];
}
if (!$packageVersion) {
    \OCP\JSON::error(array('msg' => 'Version not found'));
    exit;
}
$sourcePath = Downloader::getPackage($packageUrl, $packageVersion);
if (!$sourcePath) {
    \OCP\JSON::error(array('msg' => 'Unable to fetch package'));
    exit;
}
$backupPath = Backup::createBackup();
if ($backupPath) {
    Updater::update($sourcePath, $backupPath);
    \OCP\JSON::success(array());
} else {
    \OCP\JSON::error(array('msg' => 'Failed to create backup'));
}
示例#30
0
}
if ($_POST['recoveryPassword'] !== $_POST['confirmPassword']) {
    $errorMessage = $l->t('Repeated recovery key password does not match the provided recovery key password');
    \OCP\JSON::error(array('data' => array('message' => $errorMessage)));
    exit;
}
// Enable recoveryAdmin
$recoveryKeyId = \OC::$server->getAppConfig()->getValue('files_encryption', 'recoveryKeyId');
if (isset($_POST['adminEnableRecovery']) && $_POST['adminEnableRecovery'] === '1') {
    $return = \OCA\Encryption\Helper::adminEnableRecovery($recoveryKeyId, $_POST['recoveryPassword']);
    // Return success or failure
    if ($return) {
        $successMessage = $l->t('Recovery key successfully enabled');
    } else {
        $errorMessage = $l->t('Could not disable recovery key. Please check your recovery key password!');
    }
    // Disable recoveryAdmin
} elseif (isset($_POST['adminEnableRecovery']) && '0' === $_POST['adminEnableRecovery']) {
    $return = \OCA\Encryption\Helper::adminDisableRecovery($_POST['recoveryPassword']);
    if ($return) {
        $successMessage = $l->t('Recovery key successfully disabled');
    } else {
        $errorMessage = $l->t('Could not disable recovery key. Please check your recovery key password!');
    }
}
// Return success or failure
if ($return) {
    \OCP\JSON::success(array('data' => array('message' => $successMessage)));
} else {
    \OCP\JSON::error(array('data' => array('message' => $errorMessage)));
}