Esempio n. 1
0
 public static function getDisplayNames($args)
 {
     \OC_JSON::checkLoggedIn();
     \OC_JSON::callCheck();
     $users = $_GET['users'];
     $result = array();
     $userManager = \OC::$server->getUserManager();
     foreach ($users as $user) {
         $userObject = $userManager->get($user);
         if (is_object($userObject)) {
             $result[$user] = $userObject->getDisplayName();
         } else {
             $result[$user] = $user;
         }
     }
     \OC_JSON::success(array('users' => $result));
 }
Esempio n. 2
0
 /**
  * Send a mail to test the settings
  */
 public static function sendTestMail()
 {
     \OC_Util::checkAdminUser();
     \OCP\JSON::callCheck();
     $l = \OC::$server->getL10N('settings');
     $email = \OC_Preferences::getValue(\OC_User::getUser(), 'settings', 'email', '');
     if (!empty($email)) {
         $defaults = new \OC_Defaults();
         try {
             \OC_Mail::send($email, \OC_User::getDisplayName(), $l->t('test email settings'), $l->t('If you received this email, the settings seem to be correct.'), \OCP\Util::getDefaultEmailAddress('no-reply'), $defaults->getName());
         } catch (\Exception $e) {
             $message = $l->t('A problem occurred while sending the e-mail. Please revisit your settings.');
             \OC_JSON::error(array("data" => array("message" => $message)));
             exit;
         }
         \OC_JSON::success(array("data" => array("message" => $l->t("Email sent"))));
     } else {
         $message = $l->t('You need to set your user email before being able to send test emails.');
         \OC_JSON::error(array("data" => array("message" => $message)));
     }
 }
Esempio n. 3
0
            if (OC_SubAdmin::isGroupAccessible(OC_User::getUser(), $group)) {
                $groups[] = $group;
            }
        }
        if (count($groups) == 0) {
            $groups = OC_SubAdmin::getSubAdminsGroups(OC_User::getUser());
        }
    } else {
        $groups = OC_SubAdmin::getSubAdminsGroups(OC_User::getUser());
    }
}
$username = $_POST["username"];
$password = $_POST["password"];
// Does the group exist?
if (in_array($username, OC_User::getUsers())) {
    OC_JSON::error(array("data" => array("message" => "User already exists")));
    exit;
}
// Return Success story
try {
    OC_User::createUser($username, $password);
    foreach ($groups as $i) {
        if (!OC_Group::groupExists($i)) {
            OC_Group::createGroup($i);
        }
        OC_Group::addToGroup($username, $i);
    }
    OC_JSON::success(array("data" => array("username" => $username, "groups" => implode(", ", OC_Group::getUserGroups($username)))));
} catch (Exception $exception) {
    OC_JSON::error(array("data" => array("message" => $exception->getMessage())));
}
Esempio n. 4
0
OCP\JSON::callCheck();
OC_JSON::checkLoggedIn();
$l = \OC::$server->getL10N('settings');
$username = isset($_POST["username"]) ? $_POST["username"] : OC_User::getUser();
$displayName = (string) $_POST["displayName"];
$userstatus = null;
if (OC_User::isAdminUser(OC_User::getUser())) {
    $userstatus = 'admin';
}
$isUserAccessible = false;
$subadminUserObject = \OC::$server->getUserManager()->get(\OC_User::getUser());
$targetUserObject = \OC::$server->getUserManager()->get($username);
if ($subadminUserObject !== null && $targetUserObject !== null) {
    $isUserAccessible = \OC::$server->getGroupManager()->getSubAdmin()->isUserAccessible($subadminUserObject, $targetUserObject);
}
if ($isUserAccessible) {
    $userstatus = 'subadmin';
}
if ($username === OC_User::getUser() && OC_User::canUserChangeDisplayName($username)) {
    $userstatus = 'changeOwnDisplayName';
}
if (is_null($userstatus)) {
    OC_JSON::error(array("data" => array("message" => $l->t("Authentication error"))));
    exit;
}
// Return Success story
if (OC_User::setDisplayName($username, $displayName)) {
    OC_JSON::success(array("data" => array("message" => $l->t('Your full name has been changed.'), "username" => $username, 'displayName' => $displayName)));
} else {
    OC_JSON::error(array("data" => array("message" => $l->t("Unable to change full name"), 'displayName' => OC_User::getDisplayName($username))));
}
Esempio n. 5
0
OCP\JSON::checkAdminUser();
OCP\JSON::callCheck();
if (!array_key_exists('appid', $_POST)) {
    OCP\JSON::error(array('message' => 'No AppId given!'));
    return;
}
$appId = (string) $_POST['appid'];
if (!is_numeric($appId)) {
    $appId = \OC::$server->getAppConfig()->getValue($appId, 'ocsid', null);
    if ($appId === null) {
        OCP\JSON::error(array('message' => 'No OCS-ID found for app!'));
        exit;
    }
}
$appId = OC_App::cleanAppId($appId);
$config = \OC::$server->getConfig();
$config->setSystemValue('maintenance', true);
try {
    $result = OC_Installer::updateAppByOCSId($appId);
    $config->setSystemValue('maintenance', false);
} catch (Exception $ex) {
    $config->setSystemValue('maintenance', false);
    OC_JSON::error(array("data" => array("message" => $ex->getMessage())));
    return;
}
if ($result !== false) {
    OC_JSON::success(array('data' => array('appid' => $appId)));
} else {
    $l = \OC::$server->getL10N('settings');
    OC_JSON::error(array("data" => array("message" => $l->t("Couldn't update app."))));
}
<?php

/**
* ownCloud - ajax frontend
*
* @author Jakob Sack
* @copyright 2011 Jakob Sack kde@jakobsack.de
*
* 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/>.
*
*/
$app = isset($_POST["app"]) ? $_POST["app"] : "";
$app = OC_App::cleanAppId($app);
$l = OC_L10N::get($app);
OC_JSON::success(array('data' => $l->getTranslations(), 'plural_form' => $l->getPluralFormString()));
Esempio n. 7
0
 * This file is licensed under the Affero General Public License version 3 or later.
 * See the COPYING-README file.
 */
OCP\JSON::checkAppEnabled('external');
OCP\User::checkAdminUser();
OCP\JSON::callCheck();
$sites = array();
for ($i = 0; $i < sizeof($_POST['site_name']); $i++) {
    if (!empty($_POST['site_name'][$i]) && !empty($_POST['site_url'][$i])) {
        array_push($sites, array(strip_tags($_POST['site_name'][$i]), strip_tags($_POST['site_url'][$i])));
    }
}
$l = OC_L10N::get('external');
foreach ($sites as $site) {
    if (strpos($site[1], 'https://') === 0) {
        continue;
    }
    if (strpos($site[1], 'http://') === 0) {
        continue;
    }
    OC_JSON::error(array("data" => array("message" => $l->t('Please enter valid urls - they have to start with either http:// or https://'))));
    return;
}
if (sizeof($sites) == 0) {
    $appConfig = \OC::$server->getAppConfig();
    $appConfig->deleteKey('external', 'sites');
} else {
    OCP\Config::setAppValue('external', 'sites', json_encode($sites));
}
OC_JSON::success(array("data" => array("message" => $l->t("External sites saved."))));
Esempio n. 8
0
* @author  Victor Dubiniuk
* Copyright (c) 2012 Victor Dubiniuk <*****@*****.**>
* Copyright (c) 2012 Thomas Tanghus <*****@*****.**>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
OCP\JSON::callCheck();
$id = intval($_POST['id']);
$aid = intval($_POST['aid']);
$isaddressbook = isset($_POST['isaddressbook']) ? true : false;
// Ownership checking
try {
    OCA\Contacts\Addressbook::find($id);
    // is owner access check
} catch (Exception $e) {
    OCP\JSON::error(array('data' => array('message' => $e->getMessage())));
    exit;
}
try {
    OCA\Contacts\VCard::moveToAddressBook($aid, $id, $isaddressbook);
} catch (Exception $e) {
    $msg = $e->getMessage();
    OCP\Util::writeLog('contacts', 'Error moving contacts "' . implode(',', $id) . '" to addressbook "' . $aid . '"' . $msg, OCP\Util::ERROR);
    OC_JSON::error(array('data' => array('message' => $msg)));
    exit;
}
OC_JSON::success(array('data' => array('ids' => $id)));
Esempio n. 9
0
 /**
  * @brief Send json success msg
  * @param array $data The data to use
  */
 public static function success($data = array())
 {
     return \OC_JSON::success($data);
 }
*/
//no apps or filesystem
$RUNTIME_NOSETUPFS = true;
require_once '../../../lib/base.php';
// Check if we are a user
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('bookmarks');
$CONFIG_DBTYPE = OC_Config::getValue("dbtype", "sqlite");
if ($CONFIG_DBTYPE == 'sqlite' or $CONFIG_DBTYPE == 'sqlite3') {
    $_ut = "strftime('%s','now')";
} else {
    $_ut = "UNIX_TIMESTAMP()";
}
//FIXME: Detect when user adds a known URL
$query = OC_DB::prepare("\n\tINSERT INTO *PREFIX*bookmarks\n\t(url, title, user_id, public, added, lastmodified)\n\tVALUES (?, ?, ?, 0, {$_ut}, {$_ut})\n\t");
$params = array(htmlspecialchars_decode($_GET["url"]), htmlspecialchars_decode($_GET["title"]), OC_User::getUser());
$query->execute($params);
$b_id = OC_DB::insertid();
if ($b_id !== false) {
    $query = OC_DB::prepare("\n\t\tINSERT INTO *PREFIX*bookmarks_tags\n\t\t(bookmark_id, tag)\n\t\tVALUES (?, ?)\n\t\t");
    $tags = explode(' ', urldecode($_GET["tags"]));
    foreach ($tags as $tag) {
        if (empty($tag)) {
            //avoid saving blankspaces
            continue;
        }
        $params = array($b_id, trim($tag));
        $query->execute($params);
    }
    OC_JSON::success(array('data' => $b_id));
}
Esempio n. 11
0
<?php

/**
 * Copyright (c) 2012, Robin Appelman <*****@*****.**>
 * This file is licensed under the Affero General Public License version 3 or later.
 * See the COPYING-README file.
 */
OC_JSON::checkAdminUser();
$count = isset($_GET['count']) ? $_GET['count'] : 50;
$offset = isset($_GET['offset']) ? $_GET['offset'] : 0;
$entries = OC_Log_Owncloud::getEntries($count, $offset);
OC_JSON::success(array("data" => OC_Util::sanitizeHTML($entries), "remain" => count(OC_Log_Owncloud::getEntries(1, $offset + $offset)) != 0 ? true : false));
<?php

// Init owncloud
require_once '../../lib/base.php';
OC_JSON::checkLoggedIn();
$l = new OC_L10N('core');
// Get data
if (isset($_POST['email'])) {
    $email = trim($_POST['email']);
    OC_Preferences::setValue(OC_User::getUser(), 'settings', 'email', $email);
    OC_JSON::success(array("data" => array("message" => $l->t("email Changed"))));
} else {
    OC_JSON::error(array("data" => array("message" => $l->t("Invalid request"))));
}
Esempio n. 13
0
 * @author Lukas Reschke <*****@*****.**>
 * @author Robin Appelman <*****@*****.**>
 * @author Thomas Müller <*****@*****.**>
 *
 * @copyright Copyright (c) 2015, ownCloud, Inc.
 * @license AGPL-3.0
 *
 * This code is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * This program 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, version 3,
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */
OC_JSON::checkAdminUser();
OCP\JSON::callCheck();
$groups = isset($_POST['groups']) ? (array) $_POST['groups'] : null;
try {
    $app = OC_App::cleanAppId((string) $_POST['appid']);
    OC_App::enable($app, $groups);
    OC_JSON::success(['data' => ['update_required' => \OC_App::shouldUpgrade($app)]]);
} catch (Exception $e) {
    \OCP\Util::writeLog('core', $e->getMessage(), \OCP\Util::ERROR);
    OC_JSON::error(array("data" => array("message" => $e->getMessage())));
}
Esempio n. 14
0
<?php

OC_JSON::callCheck();
OC_JSON::checkSubAdminUser();
$userCount = 0;
$currentUser = \OC::$server->getUserSession()->getUser()->getUID();
if (!OC_User::isAdminUser($currentUser)) {
    $groups = OC_SubAdmin::getSubAdminsGroups($currentUser);
    foreach ($groups as $group) {
        $userCount += count(OC_Group::usersInGroup($group));
    }
} else {
    $userCountArray = \OC::$server->getUserManager()->countUsers();
    if (!empty($userCountArray)) {
        foreach ($userCountArray as $classname => $usercount) {
            $userCount += $usercount;
        }
    }
}
OC_JSON::success(array('count' => $userCount));
 */
// Init owncloud
require_once '../../../lib/base.php';
$id = $_GET['id'];
$l10n = new OC_L10N('contacts');
// Check if we are a user
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
$card = OC_Contacts_VCard::find($id);
if ($card === false) {
    OC_JSON::error(array('data' => array('message' => $l10n->t('Contact could not be found.'))));
    exit;
}
$addressbook = OC_Contacts_Addressbook::find($card['addressbookid']);
if ($addressbook === false || $addressbook['userid'] != OC_USER::getUser()) {
    OC_JSON::error(array('data' => array('message' => $l10n->t('This is not your contact.'))));
    exit;
}
$vcard = OC_Contacts_VCard::parse($card['carddata']);
// Check if the card is valid
if (is_null($vcard)) {
    OC_JSON::error(array('data' => array('message' => $l10n->t('vCard could not be read.'))));
    exit;
}
$details = OC_Contacts_VCard::structureContact($vcard);
$tmpl = new OC_Template('contacts', 'part.details');
$tmpl->assign('details', $details);
$tmpl->assign('id', $id);
$page = $tmpl->fetchPage();
OC_JSON::success(array('data' => array('id' => $id, 'page' => $page)));
Esempio n. 16
0
<?php

// Init owncloud
require_once '../../lib/base.php';
OC_JSON::checkAdminUser();
OCP\JSON::callCheck();
$name = $_POST["groupname"];
// Return Success story
if (OC_Group::deleteGroup($name)) {
    OC_JSON::success(array("data" => array("groupname" => $name)));
} else {
    OC_JSON::error(array("data" => array("message" => $l->t("Unable to delete group"))));
}
Esempio n. 17
0
    exit;
}
if (!OC_User::isAdminUser(OC_User::getUser()) && (!OC_SubAdmin::isUserAccessible(OC_User::getUser(), $username) || !OC_SubAdmin::isGroupAccessible(OC_User::getUser(), $group))) {
    $l = OC_L10N::get('core');
    OC_JSON::error(array('data' => array('message' => $l->t('Authentication error'))));
    exit;
}
if (!OC_Group::groupExists($group)) {
    OC_Group::createGroup($group);
}
$l = OC_L10N::get('settings');
$error = $l->t("Unable to add user to group %s", $group);
$action = "add";
// Toggle group
if (OC_Group::inGroup($username, $group)) {
    $action = "remove";
    $error = $l->t("Unable to remove user from group %s", $group);
    $success = OC_Group::removeFromGroup($username, $group);
    $usersInGroup = OC_Group::usersInGroup($group);
    if (count($usersInGroup) == 0) {
        OC_Group::deleteGroup($group);
    }
} else {
    $success = OC_Group::addToGroup($username, $group);
}
// Return Success story
if ($success) {
    OC_JSON::success(array("data" => array("username" => $username, "action" => $action, "groupname" => $group)));
} else {
    OC_JSON::error(array("data" => array("message" => $error)));
}
Esempio n. 18
0
 /**
  * Handle the request
  */
 public static function handleRequest()
 {
     \OC::$server->getEventLogger()->start('handle_request', 'Handle request');
     $systemConfig = \OC::$server->getSystemConfig();
     // load all the classpaths from the enabled apps so they are available
     // in the routing files of each app
     OC::loadAppClassPaths();
     // Check if ownCloud is installed or in maintenance (update) mode
     if (!$systemConfig->getValue('installed', false)) {
         \OC::$server->getSession()->clear();
         $setupHelper = new OC\Setup(\OC::$server->getConfig(), \OC::$server->getIniWrapper(), \OC::$server->getL10N('lib'), new \OC_Defaults(), \OC::$server->getLogger(), \OC::$server->getSecureRandom());
         $controller = new OC\Core\Controller\SetupController($setupHelper);
         $controller->run($_POST);
         exit;
     }
     $request = \OC::$server->getRequest();
     // Check if requested URL matches 'index.php/occ'
     $isOccControllerRequested = preg_match('|/index\\.php$|', $request->getScriptName()) === 1 && strpos($request->getPathInfo(), '/occ/') === 0;
     $requestPath = $request->getRawPathInfo();
     if (substr($requestPath, -3) !== '.js') {
         // we need these files during the upgrade
         self::checkMaintenanceMode($request);
         $needUpgrade = self::checkUpgrade(!$isOccControllerRequested);
     }
     // emergency app disabling
     if ($requestPath === '/disableapp' && $request->getMethod() === 'POST' && (string) $request->getParam('appid') !== '') {
         \OCP\JSON::callCheck();
         \OCP\JSON::checkAdminUser();
         $appId = (string) $request->getParam('appid');
         $appId = \OC_App::cleanAppId($appId);
         \OC_App::disable($appId);
         \OC_JSON::success();
         exit;
     }
     try {
         // Always load authentication apps
         OC_App::loadApps(['authentication']);
     } catch (\OC\NeedsUpdateException $e) {
         if ($isOccControllerRequested && $needUpgrade) {
             OC::$server->getRouter()->match(\OC::$server->getRequest()->getRawPathInfo());
             return;
         }
         throw $e;
     }
     // Load minimum set of apps
     if (!self::checkUpgrade(false) && !$systemConfig->getValue('maintenance', false)) {
         // For logged-in users: Load everything
         if (OC_User::isLoggedIn()) {
             OC_App::loadApps();
         } else {
             // For guests: Load only filesystem and logging
             OC_App::loadApps(array('filesystem', 'logging'));
             self::handleLogin($request);
         }
     }
     if (!self::$CLI) {
         try {
             if (!$systemConfig->getValue('maintenance', false) && !self::checkUpgrade(false)) {
                 OC_App::loadApps(array('filesystem', 'logging'));
                 OC_App::loadApps();
             }
             self::checkSingleUserMode();
             OC_Util::setupFS();
             OC::$server->getRouter()->match(\OC::$server->getRequest()->getRawPathInfo());
             return;
         } catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) {
             //header('HTTP/1.0 404 Not Found');
         } catch (Symfony\Component\Routing\Exception\MethodNotAllowedException $e) {
             OC_Response::setStatus(405);
             return;
         }
     }
     // Handle WebDAV
     if ($_SERVER['REQUEST_METHOD'] == 'PROPFIND') {
         // not allowed any more to prevent people
         // mounting this root directly.
         // Users need to mount remote.php/webdav instead.
         header('HTTP/1.1 405 Method Not Allowed');
         header('Status: 405 Method Not Allowed');
         return;
     }
     // Someone is logged in
     if (OC_User::isLoggedIn()) {
         OC_App::loadApps();
         OC_User::setupBackends();
         OC_Util::setupFS();
         // FIXME
         // Redirect to default application
         OC_Util::redirectToDefaultPage();
     } else {
         // Not handled and not logged in
         header('Location: ' . \OC::$server->getURLGenerator()->linkToRouteAbsolute('core.login.showLoginForm'));
     }
 }
Esempio n. 19
0
 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'))));
         }
     }
 }
Esempio n. 20
0
                    } else {
                        OCP\Config::setAppValue('roundcube', $param, $_POST[$param]);
                    }
                }
            }
        } else {
            if ($param === 'removeHeaderNav') {
                OCP\Config::setAppValue('roundcube', 'removeHeaderNav', false);
            }
            if ($param === 'removeControlNav') {
                OCP\Config::setAppValue('roundcube', 'removeControlNav', false);
            }
            if ($param === 'autoLogin') {
                OCP\Config::setAppValue('roundcube', 'autoLogin', false);
            }
            if ($param === 'enableDebug') {
                OCP\Config::setAppValue('roundcube', 'enableDebug', false);
            }
        }
    }
    // update login status
    $username = OCP\User::getUser();
    $params = array("uid" => $username);
    $loginHelper = new OC_RoundCube_AuthHelper();
    $loginHelper->login($params);
} else {
    OC_JSON::error(array("data" => array("message" => $l->t("Not submitted for us."))));
    return false;
}
OC_JSON::success(array('data' => array('message' => $l->t('Application settings successfully stored.'))));
return true;
<?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}")));
}
Esempio n. 22
0
}
$users = array();
$userManager = \OC_User::getManager();
if (OC_User::isAdminUser(OC_User::getUser())) {
    if ($gid !== false) {
        $batch = OC_Group::displayNamesInGroup($gid, $pattern, $limit, $offset);
    } else {
        $batch = OC_User::getDisplayNames($pattern, $limit, $offset);
    }
    foreach ($batch as $uid => $displayname) {
        $user = $userManager->get($uid);
        $users[] = array('name' => $uid, 'displayname' => $displayname, 'groups' => join(', ', OC_Group::getUserGroups($uid)), 'subadmin' => join(', ', OC_SubAdmin::getSubAdminsGroups($uid)), 'quota' => OC_Preferences::getValue($uid, 'files', 'quota', 'default'), 'storageLocation' => $user->getHome(), 'lastLogin' => $user->getLastLogin());
    }
} else {
    $groups = OC_SubAdmin::getSubAdminsGroups(OC_User::getUser());
    if ($gid !== false && in_array($gid, $groups)) {
        $groups = array($gid);
    } elseif ($gid !== false) {
        //don't you try to investigate loops you must not know about
        $groups = array();
    }
    $batch = OC_Group::usersInGroups($groups, $pattern, $limit, $offset);
    foreach ($batch as $uid) {
        $user = $userManager->get($uid);
        // Only add the groups, this user is a subadmin of
        $userGroups = array_intersect(OC_Group::getUserGroups($uid), OC_SubAdmin::getSubAdminsGroups(OC_User::getUser()));
        $users[] = array('name' => $uid, 'displayname' => $user->getDisplayName(), 'groups' => join(', ', $userGroups), 'quota' => OC_Preferences::getValue($uid, 'files', 'quota', 'default'), 'storageLocation' => $user->getHome(), 'lastLogin' => $user->getLastLogin());
    }
}
OC_JSON::success(array('data' => $users));
Esempio n. 23
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/>
 *
 */
OC_JSON::checkSubAdminUser();
OCP\JSON::callCheck();
$username = isset($_POST["username"]) ? (string) $_POST["username"] : '';
if ($username === '' && !OC_User::isAdminUser(OC_User::getUser()) || !OC_User::isAdminUser(OC_User::getUser()) && !OC_SubAdmin::isUserAccessible(OC_User::getUser(), $username)) {
    $l = \OC::$server->getL10N('core');
    OC_JSON::error(array('data' => array('message' => $l->t('Authentication error'))));
    exit;
}
//make sure the quota is in the expected format
$quota = (string) $_POST["quota"];
if ($quota !== 'none' and $quota !== 'default') {
    $quota = OC_Helper::computerFileSize($quota);
    $quota = OC_Helper::humanFileSize($quota);
}
// Return Success story
if ($username) {
    \OC::$server->getConfig()->setUserValue($username, 'files', 'quota', $quota);
} else {
    //set the default quota when no username is specified
    if ($quota === 'default') {
        //'default' as default quota makes no sense
        $quota = 'none';
    }
    OC_Appconfig::setValue('files', 'default_quota', $quota);
}
OC_JSON::success(array("data" => array("username" => $username, 'quota' => $quota)));
<?php

// Init owncloud
require_once '../../lib/base.php';
OC_JSON::checkLoggedIn();
$l = OC_L10N::get('core');
// Get data
if (isset($_POST['email']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
    $email = trim($_POST['email']);
    OC_Preferences::setValue(OC_User::getUser(), 'settings', 'email', $email);
    OC_JSON::success(array("data" => array("message" => $l->t("Email saved"))));
} else {
    OC_JSON::error(array("data" => array("message" => $l->t("Invalid email"))));
}
Esempio n. 25
0
if ($app === 'core' && isset($_POST['key']) && (substr((string) $_POST['key'], 0, 7) === 'remote_' || substr((string) $_POST['key'], 0, 7) === 'public_')) {
    OC_JSON::error(array('data' => array('message' => 'Unexpected error!')));
    return;
}
$result = false;
$appConfig = \OC::$server->getAppConfig();
switch ($action) {
    case 'getValue':
        $result = $appConfig->getValue($app, (string) $_GET['key'], (string) $_GET['defaultValue']);
        break;
    case 'setValue':
        $result = $appConfig->setValue($app, (string) $_POST['key'], (string) $_POST['value']);
        break;
    case 'getApps':
        $result = $appConfig->getApps();
        break;
    case 'getKeys':
        $result = $appConfig->getKeys($app);
        break;
    case 'hasKey':
        $result = $appConfig->hasKey($app, (string) $_GET['key']);
        break;
    case 'deleteKey':
        $result = $appConfig->deleteKey($app, (string) $_POST['key']);
        break;
    case 'deleteApp':
        $result = $appConfig->deleteApp($app);
        break;
}
OC_JSON::success(array('data' => $result));
Esempio n. 26
0
 * 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/>.
 *
 */
OC_JSON::callCheck();
OC_JSON::checkSubAdminUser();
if (isset($_GET['pattern']) && !empty($_GET['pattern'])) {
    $pattern = $_GET['pattern'];
} else {
    $pattern = '';
}
if (isset($_GET['filterGroups']) && !empty($_GET['filterGroups'])) {
    $filterGroups = intval($_GET['filterGroups']) === 1;
} else {
    $filterGroups = false;
}
$groupPattern = $filterGroups ? $pattern : '';
$groups = array();
$adminGroups = array();
$groupManager = \OC_Group::getManager();
$isAdmin = OC_User::isAdminUser(OC_User::getUser());
//we pass isAdmin as true, because OC_SubAdmin has no search feature,
//groups will be filtered out later
$groupsInfo = new \OC\Group\MetaData(OC_User::getUser(), true, $groupManager);
$groupsInfo->setSorting($groupsInfo::SORT_USERCOUNT);
list($adminGroups, $groups) = $groupsInfo->get($groupPattern, $pattern);
OC_JSON::success(array('data' => array('adminGroups' => $adminGroups, 'groups' => $groups)));
Esempio n. 27
0
        $jobList = \OC::$server->getJobList();
        $jobs = $jobList->getAll();
        foreach ($jobs as $job) {
            $job->execute($jobList, $logger);
        }
    } else {
        // We call cron.php from some website
        if ($appmode == 'cron') {
            // Cron is cron :-P
            OC_JSON::error(array('data' => array('message' => 'Backgroundjobs are using system cron!')));
        } else {
            // Work and success :-)
            $jobList = \OC::$server->getJobList();
            $job = $jobList->getNext();
            if ($job != null) {
                $job->execute($jobList, $logger);
                $jobList->setLastJob($job);
            }
            OC_JSON::success();
        }
    }
    // done!
    TemporaryCronClass::$sent = true;
    // Log the successful cron execution
    if (\OC::$server->getConfig()->getSystemValue('cron_log', true)) {
        \OC::$server->getAppConfig()->setValue('core', 'lastcron', time());
    }
    exit;
} catch (Exception $ex) {
    \OCP\Util::writeLog('cron', $ex->getMessage(), \OCP\Util::FATAL);
}
Esempio n. 28
0
 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();
     }
 }
Esempio n. 29
0
                            }
                        }
                    }
                    $count = 0;
                    // enable l10n support
                    $l = \OC::$server->getL10N('core');
                    foreach ($groups as $group) {
                        if ($count < 15) {
                            if (!isset($_GET['itemShares']) || !isset($_GET['itemShares'][OCP\Share::SHARE_TYPE_GROUP]) || !is_array((string) $_GET['itemShares'][OCP\Share::SHARE_TYPE_GROUP]) || !in_array($group, (string) $_GET['itemShares'][OCP\Share::SHARE_TYPE_GROUP])) {
                                $shareWith[] = array('label' => $group, 'value' => array('shareType' => OCP\Share::SHARE_TYPE_GROUP, 'shareWith' => $group));
                                $count++;
                            }
                        } else {
                            break;
                        }
                    }
                    // allow user to add unknown remote addresses for server-to-server share
                    $backend = \OCP\Share::getBackend((string) $_GET['itemType']);
                    if ($backend->isShareTypeAllowed(\OCP\Share::SHARE_TYPE_REMOTE)) {
                        if (substr_count((string) $_GET['search'], '@') === 1) {
                            $shareWith[] = array('label' => (string) $_GET['search'], 'value' => array('shareType' => \OCP\Share::SHARE_TYPE_REMOTE, 'shareWith' => (string) $_GET['search']));
                        }
                    }
                    $sorter = new \OC\Share\SearchResultSorter((string) $_GET['search'], 'label', new \OC\Log());
                    usort($shareWith, array($sorter, 'sort'));
                    OC_JSON::success(array('data' => $shareWith));
                }
                break;
        }
    }
}
Esempio n. 30
0
    $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 === '') {
        OC_JSON::error(array('data' => array('message' => 'Please provide a admin recovery password, otherwise all user data will be lost')));
    } elseif ($recoveryEnabledForUser && !$validRecoveryPassword) {
        OC_JSON::error(array('data' => array('message' => '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) {
            OC_JSON::error(array("data" => array("message" => "Back-end doesn't support password change, but the users encryption key was successfully updated.")));
        } elseif (!$result && !$recoveryPasswordSupported) {
            OC_JSON::error(array("data" => array("message" => "Unable to change password")));
        } else {
            OC_JSON::success(array("data" => array("username" => $username)));
        }
    }
} else {
    // if user changes his own password or 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' => 'Unable to change password')));
    }
}