Пример #1
0
function handleUnexpectedShutdown()
{
    if (!my_temporary_cron_class::$sent) {
        if (OC::$CLI) {
            echo 'Unexpected error!' . PHP_EOL;
        } else {
            OC_JSON::error(array('data' => array('message' => 'Unexpected error!')));
        }
    }
}
Пример #2
0
function handleUnexpectedShutdown()
{
    // Delete lockfile
    if (!TemporaryCronClass::$keeplock && file_exists(TemporaryCronClass::$lockfile)) {
        unlink(TemporaryCronClass::$lockfile);
    }
    // Say goodbye if the app did not shutdown properly
    if (!TemporaryCronClass::$sent) {
        if (OC::$CLI) {
            echo 'Unexpected error!' . PHP_EOL;
        } else {
            OC_JSON::error(array('data' => array('message' => 'Unexpected error!')));
        }
    }
}
Пример #3
0
function index()
{
    $fileIds = OCA\Search_Lucene\Indexer::getUnindexed();
    $eventSource = new OC_EventSource();
    $eventSource->send('count', count($fileIds));
    $skippedDirs = explode(';', OCP\Config::getUserValue(OCP\User::getUser(), 'search_lucene', 'skipped_dirs', '.git;.svn;.CVS;.bzr'));
    $query = OC_DB::prepare('INSERT INTO `*PREFIX*lucene_status` VALUES (?,?)');
    foreach ($fileIds as $id) {
        $skipped = false;
        try {
            //before we start mark the file as error so we know there was a problem when the php execution dies
            $result = $query->execute(array($id, 'E'));
            $path = OC\Files\Filesystem::getPath($id);
            $eventSource->send('indexing', $path);
            //clean jobs for indexed file
            $param = json_encode(array('path' => $path, 'user' => OCP\User::getUser()));
            $cleanjobquery = OC_DB::prepare('DELETE FROM `*PREFIX*queuedtasks` WHERE `app`=? AND `parameters`=?');
            $cleanjobquery->execute(array('search_lucene', $param));
            foreach ($skippedDirs as $skippedDir) {
                if (strpos($path, '/' . $skippedDir . '/') !== false || strrpos($path, '/' . $skippedDir) === strlen($path) - (strlen($skippedDir) + 1)) {
                    $result = $query->execute(array($id, 'S'));
                    $skipped = true;
                    break;
                }
            }
            if (!$skipped) {
                if (OCA\Search_Lucene\Indexer::indexFile($path, OCP\User::getUser())) {
                    $result = $query->execute(array($id, 'I'));
                }
            }
            if (!$result) {
                OC_JSON::error(array('message' => 'Could not index file.'));
                $eventSource->send('error', $path);
            }
        } catch (PDOException $e) {
            //sqlite might report database locked errors when stock filescan is in progress
            //this also catches db locked exception that might come up when using sqlite
            \OCP\Util::writeLog('search_lucene', $e->getMessage() . ' Trace:\\n' . $e->getTraceAsString(), \OCP\Util::ERROR);
            OC_JSON::error(array('message' => 'Could not index file.'));
            $eventSource->send('error', $e->getMessage());
            //try to mark the file as new to let it reindex
            $query->execute(array($id, 'N'));
            // Add UI to trigger rescan of files with status 'E'rror?
        }
    }
    $eventSource->send('done', '');
    $eventSource->close();
}
Пример #4
0
function index()
{
    if (isset($_GET['fileid'])) {
        $fileIds = array($_GET['fileid']);
    } else {
        $fileIds = OCA\Search_Lucene\Indexer::getUnindexed();
    }
    $eventSource = new OC_EventSource();
    $eventSource->send('count', count($fileIds));
    $skippedDirs = explode(';', OCP\Config::getUserValue(OCP\User::getUser(), 'search_lucene', 'skipped_dirs', '.git;.svn;.CVS;.bzr'));
    foreach ($fileIds as $id) {
        $skipped = false;
        $fileStatus = OCA\Search_Lucene\Status::fromFileId($id);
        try {
            //before we start mark the file as error so we know there was a problem when the php execution dies
            $fileStatus->markError();
            $path = OC\Files\Filesystem::getPath($id);
            $eventSource->send('indexing', $path);
            foreach ($skippedDirs as $skippedDir) {
                if (strpos($path, '/' . $skippedDir . '/') !== false || strrpos($path, '/' . $skippedDir) === strlen($path) - (strlen($skippedDir) + 1)) {
                    $result = $fileStatus->markSkipped();
                    $skipped = true;
                    break;
                }
            }
            if (!$skipped) {
                if (OCA\Search_Lucene\Indexer::indexFile($path, OCP\User::getUser())) {
                    $result = $fileStatus->markIndexed();
                }
            }
            if (!$result) {
                OC_JSON::error(array('message' => 'Could not index file.'));
                $eventSource->send('error', $path);
            }
        } catch (Exception $e) {
            //sqlite might report database locked errors when stock filescan is in progress
            //this also catches db locked exception that might come up when using sqlite
            \OCP\Util::writeLog('search_lucene', $e->getMessage() . ' Trace:\\n' . $e->getTraceAsString(), \OCP\Util::ERROR);
            OC_JSON::error(array('message' => 'Could not index file.'));
            $eventSource->send('error', $e->getMessage());
            //try to mark the file as new to let it reindex
            $fileStatus->markNew();
            // Add UI to trigger rescan of files with status 'E'rror?
        }
    }
    $eventSource->send('done', '');
    $eventSource->close();
}
/**
* ownCloud - bookmarks plugin
*
* @author Arthur Schiwon
* @copyright 2011 Arthur Schiwon blizzz@arthur-schiwon.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 Lesser General Public 
* License along with this library.  If not, see <http://www.gnu.org/licenses/>.
* 
*/
//no apps or filesystem
$RUNTIME_NOSETUPFS = true;
// Check if we are a user
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('bookmarks');
$id = $_POST['id'];
if (!OC_Bookmarks_Bookmarks::deleteUrl($id)) {
    OC_JSON::error();
    exit;
}
OCP\JSON::success();
Пример #6
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'))));
         }
     }
 }
Пример #7
0
 * 2012 Frank Karlitschek frank@owncloud.org
 * 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."))));
Пример #8
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))));
}
Пример #9
0
 /**
  * @brief Send json error msg
  * @param array $data The data to use
  */
 public static function error($data = array())
 {
     return \OC_JSON::error($data);
 }
Пример #10
0
                }
            }
        } 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);
            }
            if ($param === 'rcNoCronRefresh') {
                OCP\Config::setAppValue('roundcube', 'rcNoCronRefresh', 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;
}
OCP\JSON::success(array('data' => array('message' => $l->t('Application settings successfully stored.'))));
return true;
Пример #11
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."))));
}
Пример #12
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')));
    }
}
Пример #13
0
/**
 * ownCloud - RainLoop mail plugin
 *
 * @author RainLoop Team
 * @copyright 2015 RainLoop Team
 *
 * https://github.com/RainLoop/rainloop-webmail/tree/master/build/owncloud
 */
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('rainloop');
OCP\JSON::callCheck();
$sEmail = '';
$sLogin = '';
if (isset($_POST['appname'], $_POST['rainloop-password'], $_POST['rainloop-email']) && 'rainloop' === $_POST['appname']) {
    $sUser = OCP\User::getUser();
    $sPostEmail = $_POST['rainloop-email'];
    OCP\Config::setUserValue($sUser, 'rainloop', 'rainloop-email', $sPostEmail);
    $sPass = $_POST['rainloop-password'];
    if ('******' !== $sPass && '' !== $sPass) {
        include_once OC_App::getAppPath('rainloop') . '/lib/RainLoopHelper.php';
        OCP\Config::setUserValue($sUser, 'rainloop', 'rainloop-password', OC_RainLoop_Helper::encodePassword($sPass, md5($sPostEmail)));
    }
    $sEmail = OCP\Config::getUserValue($sUser, 'rainloop', 'rainloop-email', '');
} else {
    sleep(1);
    OC_JSON::error(array('Message' => 'Invalid argument(s)', 'Email' => $sEmail));
    return false;
}
sleep(1);
OCP\JSON::success(array('Message' => 'Saved successfully', 'Email' => $sEmail));
return true;
Пример #14
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();
     }
 }
Пример #15
0
<?php

OC_JSON::checkAdminUser();
OCP\JSON::callCheck();
OC_JSON::setContentTypeHeader();
$appid = OC_App::enable($_POST['appid']);
if ($appid !== false) {
    OC_JSON::success(array('data' => array('appid' => $appid)));
} else {
    $l = OC_L10N::get('settings');
    OC_JSON::error(array("data" => array("message" => $l->t("Could not enable app. "))));
}
<?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"))));
}
Пример #17
0
 * later.
 * See the COPYING-README file.
 */
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('gallery');
session_write_close();
list($owner, $img) = explode('/', $_GET['file'], 2);
if ($owner !== OC_User::getUser()) {
    \OC\Files\Filesystem::initMountPoints($owner);
    $parts = explode('/', $img, 3);
    if (count($parts) === 3) {
        list($shareId, , $img) = $parts;
    } else {
        $shareId = $parts[0];
        $img = '';
    }
    if (OCP\Share::getItemSharedWith('gallery', $shareId)) {
        $ownerView = new \OC\Files\View('/' . $owner . '/files');
        $sharedGallery = $ownerView->getPath($shareId);
        if ($img) {
            $img = $sharedGallery . '/' . $img;
        } else {
            $img = $sharedGallery;
        }
    } else {
        OC_JSON::error('no such file');
        die;
    }
}
$image = new \OCA\Gallery\AlbumThumbnail('/' . $img, $owner);
$image->show();
        exit;
    }
}
$files = $_FILES['files'];
$dir = $_POST['dir'];
$dir .= '/';
$error = '';
$totalSize = 0;
foreach ($files['size'] as $size) {
    $totalSize += $size;
}
if ($totalSize > OC_Filesystem::free_space('/')) {
    OC_JSON::error(array("data" => array("message" => "Not enough space available")));
    exit;
}
$result = array();
if (strpos($dir, '..') === false) {
    $fileCount = count($files['name']);
    for ($i = 0; $i < $fileCount; $i++) {
        $target = stripslashes($dir) . $files['name'][$i];
        if (OC_Filesystem::fromUploadedFile($files['tmp_name'][$i], $target)) {
            $result[] = array("status" => "success", 'mime' => OC_Filesystem::getMimeType($target), 'size' => OC_Filesystem::filesize($target), 'name' => $files['name'][$i]);
        }
    }
    OC_JSON::encodedPrint($result);
    exit;
} else {
    $error = 'invalid dir';
}
OC_JSON::error(array('data' => array('error' => $error, "file" => $fileName)));
<?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}")));
}
Пример #20
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"))));
}
Пример #21
0
<?php

// Check if we are a user
OCP\JSON::checkLoggedIn();
OCP\JSON::callCheck();
OCP\JSON::checkAppEnabled('bookmarks');
$l = new OC_l10n('bookmarks');
if (empty($_FILES)) {
    OCP\Util::writeLog('bookmarks', "No file provided for import", \OCP\Util::WARN);
    $error[] = $l->t('No file provided for import');
} elseif (isset($_FILES['bm_import'])) {
    $file = $_FILES['bm_import']['tmp_name'];
    if ($_FILES['bm_import']['type'] == 'text/html') {
        $error = OC_Bookmarks_Bookmarks::importFile($file);
        if (empty($errors)) {
            OCP\JSON::success();
            //force charset as not set by OC_JSON
            header('Content-Type: application/json; charset=utf-8');
            exit;
        }
    } else {
        $error[] = $l->t('Unsupported file type for import');
    }
}
OC_JSON::error(array('data' => $error));
//force charset as not set by OC_JSON
header('Content-Type: application/json; charset=utf-8');
exit;
Пример #22
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())));
}
Пример #23
0
 *
 * 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::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
<?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"))));
}
Пример #25
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_Util::checkAdminUser();
OCP\JSON::callCheck();
$action = isset($_POST['action']) ? $_POST['action'] : $_GET['action'];
if (isset($_POST['app']) || isset($_GET['app'])) {
    $app = OC_App::cleanAppId(isset($_POST['app']) ? (string) $_POST['app'] : (string) $_GET['app']);
}
// An admin should not be able to add remote and public services
// on its own. This should only be possible programmatically.
// This change is due the fact that an admin may not be expected
// to execute arbitrary code in every environment.
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':
Пример #26
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)));
Пример #27
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)));
}
Пример #28
0
// Init owncloud
require_once '../../lib/base.php';
OC_JSON::checkAdminUser();
OCP\JSON::callCheck();
$success = true;
$error = "add user to";
$action = "add";
$username = $_POST["username"];
$group = htmlentities($_POST["group"]);
if (!OC_Group::groupExists($group)) {
    OC_Group::createGroup($group);
}
// Toggle group
if (OC_Group::inGroup($username, $group)) {
    $action = "remove";
    $error = "remove user from";
    $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" => "Unable to {$error} group {$group}")));
}
Пример #29
0
            $result = $mailNotification->sendLinkShareMail($to_address, $file, $link, $expiration);
            if (empty($result)) {
                \OCP\JSON::success();
            } else {
                $l = \OC::$server->getL10N('core');
                OCP\JSON::error(array('data' => array('message' => $l->t("Couldn't send mail to following users: %s ", implode(', ', $result)))));
            }
            break;
    }
} else {
    if (isset($_GET['fetch'])) {
        switch ($_GET['fetch']) {
            case 'getItemsSharedStatuses':
                if (isset($_GET['itemType'])) {
                    $return = OCP\Share::getItemsShared((string) $_GET['itemType'], OCP\Share::FORMAT_STATUSES);
                    is_array($return) ? OC_JSON::success(array('data' => $return)) : OC_JSON::error();
                }
                break;
            case 'getItem':
                if (isset($_GET['itemType']) && isset($_GET['itemSource']) && isset($_GET['checkReshare']) && isset($_GET['checkShares'])) {
                    if ($_GET['checkReshare'] == 'true') {
                        $reshare = OCP\Share::getItemSharedWithBySource((string) $_GET['itemType'], (string) $_GET['itemSource'], OCP\Share::FORMAT_NONE, null, true);
                    } else {
                        $reshare = false;
                    }
                    if ($_GET['checkShares'] == 'true') {
                        $shares = OCP\Share::getItemShared((string) $_GET['itemType'], (string) $_GET['itemSource'], OCP\Share::FORMAT_NONE, null, true);
                    } else {
                        $shares = false;
                    }
                    OC_JSON::success(array('data' => array('reshare' => $reshare, 'shares' => $shares)));
Пример #30
0
 public static function saveUserSettings($appName, $ocUser, $rcUser, $rcPassword)
 {
     $l = new OC_L10N('roundcube');
     if (isset($appName) && $appName == "roundcube") {
         $result = self::cryptEmailIdentity($ocUser, $rcUser, $rcPassword, true);
         OCP\Util::writeLog('roundcube', 'OC_RoundCube_App.class.php->saveUserSettings(): Starting saving new users data for ' . $ocUser . ' as roundcube user ' . $rcUser, OCP\Util::DEBUG);
         if ($result) {
             // update login credentials
             $rcMaildir = OCP\Config::getAppValue('roundcube', 'maildir', '');
             $rcHost = OCP\Config::getAppValue('roundcube', 'rcHost', '');
             $rcPort = OCP\Config::getAppValue('roundcube', 'rcPort', '');
             if ($rcHost == '') {
                 $rc_host = OCP\Util::getServerHost();
             }
             // login again
             if (self::login($rcHost, $rcPort, $rcMaildir, $rcUser, $rcPassword)) {
                 OCP\Util::writeLog('roundcube', 'OC_RoundCube_App.class.php->saveUserSettings(): Saved user settings successfull.', OCP\Util::DEBUG);
                 OCP\JSON::success(array('data' => array('message' => $l->t('Email-user credentials successfully stored. Please login again to OwnCloud for applying the new settings.'))));
                 return true;
             } else {
                 OCP\Util::writeLog('roundcube', 'OC_RoundCube_App.class.php->saveUserSettings(): Login errors', OCP\Util::DEBUG);
                 OC_JSON::error(array("data" => array("message" => $l->t("Unable to login into roundcube. There are login errors."))));
                 return false;
             }
         } else {
             OCP\Util::writeLog('roundcube', 'OC_RoundCube_App.class.php->saveUserSettings(): Unable to save email credentials.', OCP\Util::DEBUG);
             OC_JSON::error(array("data" => array("message" => $l->t("Unable to store email credentials in the data-base."))));
             return false;
         }
     } else {
         OCP\Util::writeLog('roundcube', 'OC_RoundCube_App.class.php->saveUserSettings(): Not for roundcube app.', OCP\Util::DEBUG);
         OC_JSON::error(array("data" => array("message" => $l->t("Not submitted for us."))));
         return false;
     }
 }