Example #1
0
 public function setUp()
 {
     OC_User::clearBackends();
     OC_User::useBackend('dummy');
     $this->user1 = uniqid('user1_');
     $this->user2 = uniqid('user2_');
     $this->user3 = uniqid('user3_');
     $this->user4 = uniqid('user4_');
     OC_User::createUser($this->user1, 'pass');
     OC_User::createUser($this->user2, 'pass');
     OC_User::createUser($this->user3, 'pass');
     OC_User::createUser($this->user4, 'pass');
     OC_User::setUserId($this->user1);
     OC_Group::clearBackends();
     OC_Group::useBackend(new OC_Group_Dummy());
     $this->group1 = uniqid('group_');
     $this->group2 = uniqid('group_');
     OC_Group::createGroup($this->group1);
     OC_Group::createGroup($this->group2);
     OC_Group::addToGroup($this->user1, $this->group1);
     OC_Group::addToGroup($this->user2, $this->group1);
     OC_Group::addToGroup($this->user3, $this->group1);
     OC_Group::addToGroup($this->user2, $this->group2);
     OC_Group::addToGroup($this->user4, $this->group2);
     OCP\Share::registerBackend('test', 'Test_Share_Backend');
     OC_Hook::clear('OCP\\Share');
     OC::registerShareHooks();
     $this->resharing = OC_Appconfig::getValue('core', 'shareapi_allow_resharing', 'yes');
     OC_Appconfig::setValue('core', 'shareapi_allow_resharing', 'yes');
     // 20 Minutes in the past, 20 minutes in the future.
     $now = time();
     $dateFormat = 'Y-m-d H:i:s';
     $this->dateInPast = date($dateFormat, $now - 20 * 60);
     $this->dateInFuture = date($dateFormat, $now + 20 * 60);
 }
Example #2
0
 public static function setUpBeforeClass()
 {
     // reset backend
     \OC_User::clearBackends();
     \OC_User::useBackend('database');
     // enable resharing
     \OC_Appconfig::setValue('core', 'shareapi_allow_resharing', 'yes');
     // clear share hooks
     \OC_Hook::clear('OCP\\Share');
     \OC::registerShareHooks();
     \OCP\Util::connectHook('OC_Filesystem', 'setup', '\\OC\\Files\\Storage\\Shared', 'setup');
     // Sharing related hooks
     \OCA\Encryption\Helper::registerShareHooks();
     // Filesystem related hooks
     \OCA\Encryption\Helper::registerFilesystemHooks();
     // clear and register hooks
     \OC_FileProxy::clearProxies();
     \OC_FileProxy::register(new OCA\Encryption\Proxy());
     // create users
     \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1, true);
     \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, true);
     \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3, true);
     \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4, true);
     // create group and assign users
     \OC_Group::createGroup(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_GROUP1);
     \OC_Group::addToGroup(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_GROUP1);
     \OC_Group::addToGroup(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_GROUP1);
 }
Example #3
0
 public function setUp()
 {
     OC_User::clearBackends();
     OC_User::useBackend('dummy');
     $this->user1 = uniqid('user1_');
     $this->user2 = uniqid('user2_');
     $this->user3 = uniqid('user3_');
     $this->user4 = uniqid('user4_');
     OC_User::createUser($this->user1, 'pass');
     OC_User::createUser($this->user2, 'pass');
     OC_User::createUser($this->user3, 'pass');
     OC_User::createUser($this->user4, 'pass');
     OC_User::setUserId($this->user1);
     OC_Group::clearBackends();
     OC_Group::useBackend(new OC_Group_Dummy());
     $this->group1 = uniqid('group_');
     $this->group2 = uniqid('group_');
     OC_Group::createGroup($this->group1);
     OC_Group::createGroup($this->group2);
     OC_Group::addToGroup($this->user1, $this->group1);
     OC_Group::addToGroup($this->user2, $this->group1);
     OC_Group::addToGroup($this->user3, $this->group1);
     OC_Group::addToGroup($this->user2, $this->group2);
     OC_Group::addToGroup($this->user4, $this->group2);
     OCP\Share::registerBackend('test', 'Test_Share_Backend');
     OC_Hook::clear('OCP\\Share');
     OC::registerShareHooks();
 }
Example #4
0
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     // reset backend
     \OC_User::clearBackends();
     \OC_User::useBackend('database');
     // enable resharing
     \OC::$server->getAppConfig()->setValue('core', 'shareapi_allow_resharing', 'yes');
     // clear share hooks
     \OC_Hook::clear('OCP\\Share');
     // register share hooks
     \OC::registerShareHooks();
     \OCA\Files_Sharing\Helper::registerHooks();
     // Sharing related hooks
     \OCA\Encryption\Helper::registerShareHooks();
     // Filesystem related hooks
     \OCA\Encryption\Helper::registerFilesystemHooks();
     // clear and register hooks
     \OC_FileProxy::clearProxies();
     \OC_FileProxy::register(new OCA\Files\Share\Proxy());
     \OC_FileProxy::register(new OCA\Encryption\Proxy());
     // create users
     self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1, true);
     self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, true);
     self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3, true);
     self::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4, true);
     // create group and assign users
     \OC_Group::createGroup(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_GROUP1);
     \OC_Group::addToGroup(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_GROUP1);
     \OC_Group::addToGroup(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_GROUP1);
 }
Example #5
0
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     // create test user
     self::loginHelper(self::TEST_ENCRYPTION_UTIL_USER1, true);
     self::loginHelper(self::TEST_ENCRYPTION_UTIL_USER2, true);
     self::loginHelper(self::TEST_ENCRYPTION_UTIL_LEGACY_USER, true);
     // create groups
     \OC_Group::createGroup(self::TEST_ENCRYPTION_UTIL_GROUP1);
     \OC_Group::createGroup(self::TEST_ENCRYPTION_UTIL_GROUP2);
     // add user 1 to group1
     \OC_Group::addToGroup(self::TEST_ENCRYPTION_UTIL_USER1, self::TEST_ENCRYPTION_UTIL_GROUP1);
 }
Example #6
0
 public static function setUpBeforeClass()
 {
     // reset backend
     \OC_User::clearBackends();
     \OC_User::useBackend('database');
     self::setupHooks();
     // create test user
     \Test_Encryption_Util::loginHelper(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER1, true);
     \Test_Encryption_Util::loginHelper(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER2, true);
     \Test_Encryption_Util::loginHelper(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_LEGACY_USER, true);
     // create groups
     \OC_Group::createGroup(self::TEST_ENCRYPTION_UTIL_GROUP1);
     \OC_Group::createGroup(self::TEST_ENCRYPTION_UTIL_GROUP2);
     // add user 1 to group1
     \OC_Group::addToGroup(self::TEST_ENCRYPTION_UTIL_USER1, self::TEST_ENCRYPTION_UTIL_GROUP1);
 }
Example #7
0
 public function setUp()
 {
     \OC_User::createUser(self::TEST_USER1, self::TEST_USER1);
     \OC_User::createUser(self::TEST_USER2, self::TEST_USER2);
     \OC_Group::createGroup(self::TEST_GROUP1);
     \OC_Group::addToGroup(self::TEST_USER1, self::TEST_GROUP1);
     \OC_Group::createGroup(self::TEST_GROUP2);
     \OC_Group::addToGroup(self::TEST_USER2, self::TEST_GROUP2);
     \OC_User::setUserId(self::TEST_USER1);
     $this->userHome = \OC_User::getHome(self::TEST_USER1);
     mkdir($this->userHome);
     $this->dataDir = \OC_Config::getValue('datadirectory', \OC::$SERVERROOT . '/data/');
     $this->oldAllowedBackends = OCP\Config::getAppValue('files_external', 'user_mounting_backends', '');
     $this->allBackends = OC_Mount_Config::getBackends();
     OCP\Config::setAppValue('files_external', 'user_mounting_backends', implode(',', array_keys($this->allBackends)));
     OC_Mount_Config::$skipTest = true;
 }
Example #8
0
 /**
  * creates a new group
  */
 public static function addGroup($parameters)
 {
     // Validate name
     $groupid = isset($_POST['groupid']) ? $_POST['groupid'] : '';
     if (preg_match('/[^a-zA-Z0-9 _\\.@\\-]/', $groupid) || empty($groupid)) {
         return 101;
     }
     // Check if it exists
     if (OC_Group::groupExists($groupid)) {
         return 102;
     }
     if (OC_Group::createGroup($groupid)) {
         return 100;
     } else {
         return 103;
     }
 }
Example #9
0
 protected function setUp()
 {
     parent::setUp();
     \OC_User::clearBackends();
     \OC_User::useBackend('dummy');
     $this->user1 = $this->getUniqueID('user1_');
     $this->user2 = $this->getUniqueID('user2_');
     $this->user3 = $this->getUniqueID('user3_');
     $this->user4 = $this->getUniqueID('user4_');
     $this->user5 = $this->getUniqueID('user5_');
     $this->user6 = $this->getUniqueID('user6_');
     $this->groupAndUser = $this->getUniqueID('groupAndUser_');
     \OC::$server->getUserManager()->createUser($this->user1, 'pass');
     \OC::$server->getUserManager()->createUser($this->user2, 'pass');
     \OC::$server->getUserManager()->createUser($this->user3, 'pass');
     \OC::$server->getUserManager()->createUser($this->user4, 'pass');
     \OC::$server->getUserManager()->createUser($this->user5, 'pass');
     \OC::$server->getUserManager()->createUser($this->user6, 'pass');
     // no group
     \OC::$server->getUserManager()->createUser($this->groupAndUser, 'pass');
     \OC_User::setUserId($this->user1);
     \OC_Group::clearBackends();
     \OC_Group::useBackend(new \Test\Util\Group\Dummy());
     $this->group1 = $this->getUniqueID('group1_');
     $this->group2 = $this->getUniqueID('group2_');
     \OC_Group::createGroup($this->group1);
     \OC_Group::createGroup($this->group2);
     \OC_Group::createGroup($this->groupAndUser);
     \OC_Group::addToGroup($this->user1, $this->group1);
     \OC_Group::addToGroup($this->user2, $this->group1);
     \OC_Group::addToGroup($this->user3, $this->group1);
     \OC_Group::addToGroup($this->user2, $this->group2);
     \OC_Group::addToGroup($this->user4, $this->group2);
     \OC_Group::addToGroup($this->user2, $this->groupAndUser);
     \OC_Group::addToGroup($this->user3, $this->groupAndUser);
     \OCP\Share::registerBackend('test', 'Test\\Share\\Backend');
     \OC_Hook::clear('OCP\\Share');
     \OC::registerShareHooks();
     $this->resharing = \OC::$server->getAppConfig()->getValue('core', 'shareapi_allow_resharing', 'yes');
     \OC::$server->getAppConfig()->setValue('core', 'shareapi_allow_resharing', 'yes');
     // 20 Minutes in the past, 20 minutes in the future.
     $now = time();
     $dateFormat = 'Y-m-d H:i:s';
     $this->dateInPast = date($dateFormat, $now - 20 * 60);
     $this->dateInFuture = date($dateFormat, $now + 20 * 60);
 }
Example #10
0
 function testUnshareFromSelf()
 {
     \OC_Group::createGroup('testGroup');
     \OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup');
     \OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup');
     $fileinfo = $this->view->getFileInfo($this->filename);
     $pathinfo = pathinfo($this->filename);
     $duplicate = '/' . $pathinfo['filename'] . ' (2).' . $pathinfo['extension'];
     $result = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Files_Sharing::TEST_FILES_SHARING_API_USER2, 31);
     $this->assertTrue($result);
     $result = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, 'testGroup', 31);
     $this->assertTrue($result);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
     $this->assertTrue(\OC\Files\Filesystem::file_exists($duplicate));
     self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
     $this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
     $this->assertFalse(\OC\Files\Filesystem::file_exists($duplicate));
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     \OC\Files\Filesystem::unlink($this->filename);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $this->assertFalse(\OC\Files\Filesystem::file_exists($this->filename));
     $this->assertTrue(\OC\Files\Filesystem::file_exists($duplicate));
     // for user3 nothing should change
     self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
     $this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
     $this->assertFalse(\OC\Files\Filesystem::file_exists($duplicate));
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     \OC\Files\Filesystem::unlink($duplicate);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $this->assertFalse(\OC\Files\Filesystem::file_exists($this->filename));
     $this->assertFalse(\OC\Files\Filesystem::file_exists($duplicate));
     // for user3 nothing should change
     self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
     $this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
     $this->assertFalse(\OC\Files\Filesystem::file_exists($duplicate));
     //cleanup
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     \OCP\Share::unshare('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, 'testGroup');
     \OCP\Share::unshare('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2);
     \OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup');
     \OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup');
     \OC_Group::deleteGroup('testGroup');
 }
Example #11
0
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     // enable resharing
     \OC::$server->getAppConfig()->setValue('core', 'shareapi_allow_resharing', 'yes');
     // register share hooks
     \OC::registerShareHooks();
     \OCA\Files_Sharing\Helper::registerHooks();
     // clear and register hooks
     \OC_FileProxy::register(new \OCA\Files\Share\Proxy());
     // create users
     self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1, true);
     self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER2, true);
     self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER3, true);
     self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER4, true);
     // create group and assign users
     \OC_Group::createGroup(self::TEST_ENCRYPTION_SHARE_GROUP1);
     \OC_Group::addToGroup(self::TEST_ENCRYPTION_SHARE_USER3, self::TEST_ENCRYPTION_SHARE_GROUP1);
     \OC_Group::addToGroup(self::TEST_ENCRYPTION_SHARE_USER4, self::TEST_ENCRYPTION_SHARE_GROUP1);
 }
Example #12
0
 public static function setUpBeforeClass()
 {
     // reset backend
     \OC_User::clearBackends();
     \OC_User::useBackend('database');
     // Filesystem related hooks
     \OCA\Encryption\Helper::registerFilesystemHooks();
     // clear and register hooks
     \OC_FileProxy::clearProxies();
     \OC_FileProxy::register(new OCA\Encryption\Proxy());
     // create test user
     \Test_Encryption_Util::loginHelper(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER1, true);
     \Test_Encryption_Util::loginHelper(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER2, true);
     \Test_Encryption_Util::loginHelper(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_LEGACY_USER, true);
     // create groups
     \OC_Group::createGroup(self::TEST_ENCRYPTION_UTIL_GROUP1);
     \OC_Group::createGroup(self::TEST_ENCRYPTION_UTIL_GROUP2);
     // add user 1 to group1
     \OC_Group::addToGroup(self::TEST_ENCRYPTION_UTIL_USER1, self::TEST_ENCRYPTION_UTIL_GROUP1);
 }
Example #13
0
 public function testUnshareFromSelf()
 {
     \OC_Group::createGroup('testGroup');
     \OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup');
     \OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup');
     $share1 = $this->share(\OCP\Share::SHARE_TYPE_USER, $this->filename, self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2, \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE);
     $share2 = $this->share(\OCP\Share::SHARE_TYPE_GROUP, $this->filename, self::TEST_FILES_SHARING_API_USER1, 'testGroup', \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
     self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
     $this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     \OC\Files\Filesystem::unlink($this->filename);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     // both group share and user share should be gone
     $this->assertFalse(\OC\Files\Filesystem::file_exists($this->filename));
     // for user3 nothing should change
     self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
     $this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
     $this->shareManager->deleteShare($share1);
     $this->shareManager->deleteShare($share2);
 }
Example #14
0
 public function testGetSubAdminsOfGroup()
 {
     $user1 = $this->generateUsers();
     $user2 = $this->generateUsers();
     self::loginAsUser($user1);
     \OC_Group::addToGroup($user1, 'admin');
     $group1 = $this->getUniqueID();
     \OC_Group::createGroup($group1);
     \OC_SubAdmin::createSubAdmin($user2, $group1);
     $result = \OCA\provisioning_api\Groups::getSubAdminsOfGroup(array('groupid' => $group1));
     $this->assertInstanceOf('OC_OCS_Result', $result);
     $this->assertTrue($result->succeeded());
     $data = $result->getData();
     $this->assertEquals($user2, reset($data));
     \OC_Group::deleteGroup($group1);
     $user1 = $this->generateUsers();
     self::loginAsUser($user1);
     \OC_Group::addToGroup($user1, 'admin');
     $result = \OCA\provisioning_api\Groups::getSubAdminsOfGroup(array('groupid' => $this->getUniqueID()));
     $this->assertInstanceOf('OC_OCS_Result', $result);
     $this->assertFalse($result->succeeded());
     $this->assertEquals(101, $result->getStatusCode());
 }
Example #15
0
 public function testUnshareFromSelf()
 {
     \OC_Group::createGroup('testGroup');
     \OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup');
     \OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup');
     $fileinfo = $this->view->getFileInfo($this->filename);
     $result = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Files_Sharing::TEST_FILES_SHARING_API_USER2, 31);
     $this->assertTrue($result);
     $result = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, 'testGroup', 31);
     $this->assertTrue($result);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
     self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
     $this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     \OC\Files\Filesystem::unlink($this->filename);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     // both group share and user share should be gone
     $this->assertFalse(\OC\Files\Filesystem::file_exists($this->filename));
     // for user3 nothing should change
     self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
     $this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
 }
<?php

// Init owncloud
require_once '../../lib/base.php';
// Check if we are a user
if (!OC_User::isLoggedIn() || !OC_Group::inGroup(OC_User::getUser(), 'admin')) {
    OC_JSON::error(array("data" => array("message" => "Authentication error")));
    exit;
}
$groupname = $_POST["groupname"];
// Does the group exist?
if (in_array($groupname, OC_Group::getGroups())) {
    OC_JSON::error(array("data" => array("message" => "Group already exists")));
    exit;
}
// Return Success story
if (OC_Group::createGroup($groupname)) {
    OC_JSON::success(array("data" => array("groupname" => $groupname)));
} else {
    OC_JSON::error(array("data" => array("message" => "Unable to add group")));
}
Example #17
0
 /**
  * @param $options
  * @return array
  */
 public static function install($options)
 {
     $l = self::getTrans();
     $error = array();
     $dbType = $options['dbtype'];
     if (empty($options['adminlogin'])) {
         $error[] = $l->t('Set an admin username.');
     }
     if (empty($options['adminpass'])) {
         $error[] = $l->t('Set an admin password.');
     }
     if (empty($options['directory'])) {
         $options['directory'] = OC::$SERVERROOT . "/data";
     }
     if (!isset(self::$dbSetupClasses[$dbType])) {
         $dbType = 'sqlite';
     }
     $username = htmlspecialchars_decode($options['adminlogin']);
     $password = htmlspecialchars_decode($options['adminpass']);
     $dataDir = htmlspecialchars_decode($options['directory']);
     $class = self::$dbSetupClasses[$dbType];
     /** @var \OC\Setup\AbstractDatabase $dbSetup */
     $dbSetup = new $class(self::getTrans(), 'db_structure.xml');
     $error = array_merge($error, $dbSetup->validate($options));
     // validate the data directory
     if (!is_dir($dataDir) and !mkdir($dataDir) or !is_writable($dataDir)) {
         $error[] = $l->t("Can't create or write into the data directory %s", array($dataDir));
     }
     if (count($error) != 0) {
         return $error;
     }
     //no errors, good
     if (isset($options['trusted_domains']) && is_array($options['trusted_domains'])) {
         $trustedDomains = $options['trusted_domains'];
     } else {
         $trustedDomains = array(OC_Request::serverHost());
     }
     if (OC_Util::runningOnWindows()) {
         $dataDir = rtrim(realpath($dataDir), '\\');
     }
     //use sqlite3 when available, otherwise sqlite2 will be used.
     if ($dbType == 'sqlite' and class_exists('SQLite3')) {
         $dbType = 'sqlite3';
     }
     //generate a random salt that is used to salt the local user passwords
     $salt = \OC::$server->getSecureRandom()->getLowStrengthGenerator()->generate(30);
     \OC::$server->getConfig()->setSystemValue('passwordsalt', $salt);
     // generate a secret
     $secret = \OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate(48);
     \OC::$server->getConfig()->setSystemValue('secret', $secret);
     //write the config file
     \OC::$server->getConfig()->setSystemValue('trusted_domains', $trustedDomains);
     \OC::$server->getConfig()->setSystemValue('datadirectory', $dataDir);
     \OC::$server->getConfig()->setSystemValue('overwrite.cli.url', \OC_Request::serverProtocol() . '://' . \OC_Request::serverHost() . OC::$WEBROOT);
     \OC::$server->getConfig()->setSystemValue('dbtype', $dbType);
     \OC::$server->getConfig()->setSystemValue('version', implode('.', OC_Util::getVersion()));
     try {
         $dbSetup->initialize($options);
         $dbSetup->setupDatabase($username);
     } catch (DatabaseSetupException $e) {
         $error[] = array('error' => $e->getMessage(), 'hint' => $e->getHint());
         return $error;
     } catch (Exception $e) {
         $error[] = array('error' => 'Error while trying to create admin user: '******'hint' => '');
         return $error;
     }
     //create the user and group
     try {
         OC_User::createUser($username, $password);
     } catch (Exception $exception) {
         $error[] = $exception->getMessage();
     }
     if (count($error) == 0) {
         $appConfig = \OC::$server->getAppConfig();
         $appConfig->setValue('core', 'installedat', microtime(true));
         $appConfig->setValue('core', 'lastupdatedat', microtime(true));
         OC_Group::createGroup('admin');
         OC_Group::addToGroup($username, 'admin');
         OC_User::login($username, $password);
         //guess what this does
         OC_Installer::installShippedApps();
         // create empty file in data dir, so we can later find
         // out that this is indeed an ownCloud data directory
         file_put_contents(OC_Config::getValue('datadirectory', OC::$SERVERROOT . '/data') . '/.ocdata', '');
         // Update htaccess files for apache hosts
         if (isset($_SERVER['SERVER_SOFTWARE']) && strstr($_SERVER['SERVER_SOFTWARE'], 'Apache')) {
             self::updateHtaccess();
             self::protectDataDirectory();
         }
         //and we are done
         OC_Config::setValue('installed', true);
     }
     return $error;
 }
Example #18
0
/**
* Gets an array of groups and will try to add the group to OC and then add the user to the groups.
* 
*/
function update_groups($uid, $groups, $protected_groups = array(), $just_created = false)
{
    if (!$just_created) {
        $old_groups = OC_Group::getUserGroups($uid);
        foreach ($old_groups as $group) {
            if (!in_array($group, $protected_groups) && !in_array($group, $groups)) {
                \OC_Group::removeFromGroup($uid, $group);
                \OCP\Util::writeLog('cas', 'Removed "' . $uid . '" from the group "' . $group . '"', \OCP\Util::DEBUG);
            }
        }
    }
    foreach ($groups as $group) {
        if (preg_match('/[^a-zA-Z0-9 _\\.@\\-]/', $group)) {
            \OCP\Util::writeLog('cas', 'Invalid group "' . $group . '", allowed chars "a-zA-Z0-9" and "_.@-" ', \OCP\Util::DEBUG);
        } else {
            if (!\OC_Group::inGroup($uid, $group)) {
                if (!OC_Group::groupExists($group)) {
                    \OC_Group::createGroup($group);
                    \OCP\Util::writeLog('cas', 'New group created: ' . $group, \OCP\Util::DEBUG);
                }
                \OC_Group::addToGroup($uid, $group);
                \OCP\Util::writeLog('cas', 'Added "' . $uid . '" to the group "' . $group . '"', \OCP\Util::DEBUG);
            }
        }
    }
}
Example #19
0
 public static function install($options)
 {
     $l = self::getTrans();
     $error = array();
     $dbtype = $options['dbtype'];
     if (empty($options['adminlogin'])) {
         $error[] = $l->t('Set an admin username.');
     }
     if (empty($options['adminpass'])) {
         $error[] = $l->t('Set an admin password.');
     }
     if (empty($options['directory'])) {
         $options['directory'] = OC::$SERVERROOT . "/data";
     }
     if (!isset(self::$dbSetupClasses[$dbtype])) {
         $dbtype = 'sqlite';
     }
     $class = self::$dbSetupClasses[$dbtype];
     $dbSetup = new $class(self::getTrans(), 'db_structure.xml');
     $error = array_merge($error, $dbSetup->validate($options));
     if (count($error) != 0) {
         return $error;
     }
     //no errors, good
     $username = htmlspecialchars_decode($options['adminlogin']);
     $password = htmlspecialchars_decode($options['adminpass']);
     $datadir = htmlspecialchars_decode($options['directory']);
     if (isset($options['trusted_domains']) && is_array($options['trusted_domains'])) {
         $trustedDomains = $options['trusted_domains'];
     } else {
         $trustedDomains = array(OC_Request::serverHost());
     }
     if (OC_Util::runningOnWindows()) {
         $datadir = rtrim(realpath($datadir), '\\');
     }
     //use sqlite3 when available, otherise sqlite2 will be used.
     if ($dbtype == 'sqlite' and class_exists('SQLite3')) {
         $dbtype = 'sqlite3';
     }
     //generate a random salt that is used to salt the local user passwords
     $salt = OC_Util::generateRandomBytes(30);
     OC_Config::setValue('passwordsalt', $salt);
     //write the config file
     OC_Config::setValue('trusted_domains', $trustedDomains);
     OC_Config::setValue('datadirectory', $datadir);
     OC_Config::setValue('dbtype', $dbtype);
     OC_Config::setValue('version', implode('.', OC_Util::getVersion()));
     try {
         $dbSetup->initialize($options);
         $dbSetup->setupDatabase($username);
     } catch (DatabaseSetupException $e) {
         $error[] = array('error' => $e->getMessage(), 'hint' => $e->getHint());
         return $error;
     } catch (Exception $e) {
         $error[] = array('error' => 'Error while trying to create admin user: '******'hint' => '');
         return $error;
     }
     //create the user and group
     try {
         OC_User::createUser($username, $password);
     } catch (Exception $exception) {
         $error[] = $exception->getMessage();
     }
     if (count($error) == 0) {
         OC_Appconfig::setValue('core', 'installedat', microtime(true));
         OC_Appconfig::setValue('core', 'lastupdatedat', microtime(true));
         OC_AppConfig::setValue('core', 'remote_core.css', '/core/minimizer.php');
         OC_AppConfig::setValue('core', 'remote_core.js', '/core/minimizer.php');
         OC_Group::createGroup('admin');
         OC_Group::addToGroup($username, 'admin');
         OC_User::login($username, $password);
         //guess what this does
         OC_Installer::installShippedApps();
         // create empty file in data dir, so we can later find
         // out that this is indeed an ownCloud data directory
         file_put_contents(OC_Config::getValue('datadirectory', OC::$SERVERROOT . '/data') . '/.ocdata', '');
         //create htaccess files for apache hosts
         if (isset($_SERVER['SERVER_SOFTWARE']) && strstr($_SERVER['SERVER_SOFTWARE'], 'Apache')) {
             self::createHtaccess();
         }
         //and we are done
         OC_Config::setValue('installed', true);
     }
     return $error;
 }
Example #20
0
 public static function install($options)
 {
     $error = array();
     $dbtype = $options['dbtype'];
     if (empty($options['adminlogin'])) {
         $error[] = 'Set an admin username.';
     }
     if (empty($options['adminpass'])) {
         $error[] = 'Set an admin password.';
     }
     if (empty($options['directory'])) {
         $error[] = 'Specify a data folder.';
     }
     if ($dbtype == 'mysql' or $dbtype == 'pgsql') {
         //mysql and postgresql needs more config options
         if ($dbtype == 'mysql') {
             $dbprettyname = 'MySQL';
         } else {
             $dbprettyname = 'PostgreSQL';
         }
         if (empty($options['dbuser'])) {
             $error[] = "{$dbprettyname} enter the database username.";
         }
         if (empty($options['dbname'])) {
             $error[] = "{$dbprettyname} enter the database name.";
         }
         if (empty($options['dbhost'])) {
             $error[] = "{$dbprettyname} set the database host.";
         }
     }
     if (count($error) == 0) {
         //no errors, good
         $username = htmlspecialchars_decode($options['adminlogin']);
         $password = htmlspecialchars_decode($options['adminpass']);
         $datadir = htmlspecialchars_decode($options['directory']);
         //use sqlite3 when available, otherise sqlite2 will be used.
         if ($dbtype == 'sqlite' and class_exists('SQLite3')) {
             $dbtype = 'sqlite3';
         }
         //generate a random salt that is used to salt the local user passwords
         $salt = OC_Util::generate_random_bytes(30);
         OC_Config::setValue('passwordsalt', $salt);
         //write the config file
         OC_Config::setValue('datadirectory', $datadir);
         OC_Config::setValue('dbtype', $dbtype);
         OC_Config::setValue('version', implode('.', OC_Util::getVersion()));
         if ($dbtype == 'mysql') {
             $dbuser = $options['dbuser'];
             $dbpass = $options['dbpass'];
             $dbname = $options['dbname'];
             $dbhost = $options['dbhost'];
             $dbtableprefix = isset($options['dbtableprefix']) ? $options['dbtableprefix'] : 'oc_';
             OC_Config::setValue('dbname', $dbname);
             OC_Config::setValue('dbhost', $dbhost);
             OC_Config::setValue('dbtableprefix', $dbtableprefix);
             //check if the database user has admin right
             $connection = @mysql_connect($dbhost, $dbuser, $dbpass);
             if (!$connection) {
                 $error[] = array('error' => 'MySQL username and/or password not valid', 'hint' => 'You need to enter either an existing account or the administrator.');
                 return $error;
             } else {
                 $oldUser = OC_Config::getValue('dbuser', false);
                 $oldPassword = OC_Config::getValue('dbpassword', false);
                 $query = "SELECT user FROM mysql.user WHERE user='******'";
                 //this should be enough to check for admin rights in mysql
                 if (mysql_query($query, $connection)) {
                     //use the admin login data for the new database user
                     //add prefix to the mysql user name to prevent collissions
                     $dbusername = substr('oc_' . $username, 0, 16);
                     if ($dbusername != $oldUser) {
                         //hash the password so we don't need to store the admin config in the config file
                         $dbpassword = md5(time() . $password);
                         self::createDBUser($dbusername, $dbpassword, $connection);
                         OC_Config::setValue('dbuser', $dbusername);
                         OC_Config::setValue('dbpassword', $dbpassword);
                     }
                     //create the database
                     self::createDatabase($dbname, $dbusername, $connection);
                 } else {
                     if ($dbuser != $oldUser) {
                         OC_Config::setValue('dbuser', $dbuser);
                         OC_Config::setValue('dbpassword', $dbpass);
                     }
                     //create the database
                     self::createDatabase($dbname, $dbuser, $connection);
                 }
                 //fill the database if needed
                 $query = "select count(*) from information_schema.tables where table_schema='{$dbname}' AND table_name = '{$dbtableprefix}users';";
                 $result = mysql_query($query, $connection);
                 if ($result) {
                     $row = mysql_fetch_row($result);
                 }
                 if (!$result or $row[0] == 0) {
                     OC_DB::createDbFromStructure('db_structure.xml');
                 }
                 mysql_close($connection);
             }
         } elseif ($dbtype == 'pgsql') {
             $dbuser = $options['dbuser'];
             $dbpass = $options['dbpass'];
             $dbname = $options['dbname'];
             $dbhost = $options['dbhost'];
             $dbtableprefix = isset($options['dbtableprefix']) ? $options['dbtableprefix'] : 'oc_';
             OC_CONFIG::setValue('dbname', $dbname);
             OC_CONFIG::setValue('dbhost', $dbhost);
             OC_CONFIG::setValue('dbtableprefix', $dbtableprefix);
             //check if the database user has admin right
             $connection_string = "host={$dbhost} dbname=postgres user={$dbuser} password={$dbpass}";
             $connection = @pg_connect($connection_string);
             if (!$connection) {
                 $error[] = array('error' => 'PostgreSQL username and/or password not valid', 'hint' => 'You need to enter either an existing account or the administrator.');
                 return $error;
             } else {
                 //check for roles creation rights in postgresql
                 $query = "SELECT 1 FROM pg_roles WHERE rolcreaterole=TRUE AND rolname='{$dbuser}'";
                 $result = pg_query($connection, $query);
                 if ($result and pg_num_rows($result) > 0) {
                     //use the admin login data for the new database user
                     //add prefix to the postgresql user name to prevent collissions
                     $dbusername = '******' . $username;
                     //create a new password so we don't need to store the admin config in the config file
                     $dbpassword = md5(time());
                     self::pg_createDBUser($dbusername, $dbpassword, $connection);
                     OC_CONFIG::setValue('dbuser', $dbusername);
                     OC_CONFIG::setValue('dbpassword', $dbpassword);
                     //create the database
                     self::pg_createDatabase($dbname, $dbusername, $connection);
                 } else {
                     OC_CONFIG::setValue('dbuser', $dbuser);
                     OC_CONFIG::setValue('dbpassword', $dbpass);
                     //create the database
                     self::pg_createDatabase($dbname, $dbuser, $connection);
                 }
                 // the connection to dbname=postgres is not needed anymore
                 pg_close($connection);
                 // connect to the ownCloud database (dbname=$dbname) an check if it needs to be filled
                 $dbuser = OC_CONFIG::getValue('dbuser');
                 $dbpass = OC_CONFIG::getValue('dbpassword');
                 $connection_string = "host={$dbhost} dbname={$dbname} user={$dbuser} password={$dbpass}";
                 $connection = @pg_connect($connection_string);
                 if (!$connection) {
                     $error[] = array('error' => 'PostgreSQL username and/or password not valid', 'hint' => 'You need to enter either an existing account or the administrator.');
                 } else {
                     $query = "select count(*) FROM pg_class WHERE relname='{$dbtableprefix}users' limit 1";
                     $result = pg_query($connection, $query);
                     if ($result) {
                         $row = pg_fetch_row($result);
                     }
                     if (!$result or $row[0] == 0) {
                         OC_DB::createDbFromStructure('db_structure.xml');
                     }
                 }
             }
         } else {
             //delete the old sqlite database first, might cause infinte loops otherwise
             if (file_exists("{$datadir}/owncloud.db")) {
                 unlink("{$datadir}/owncloud.db");
             }
             //in case of sqlite, we can always fill the database
             OC_DB::createDbFromStructure('db_structure.xml');
         }
         //create the user and group
         try {
             OC_User::createUser($username, $password);
         } catch (Exception $exception) {
             $error[] = $exception->getMessage();
         }
         if (count($error) == 0) {
             OC_Appconfig::setValue('core', 'installedat', microtime(true));
             OC_Appconfig::setValue('core', 'lastupdatedat', microtime(true));
             OC_Group::createGroup('admin');
             OC_Group::addToGroup($username, 'admin');
             OC_User::login($username, $password);
             //guess what this does
             OC_Installer::installShippedApps();
             //create htaccess files for apache hosts
             if (strstr($_SERVER['SERVER_SOFTWARE'], 'Apache')) {
                 self::createHtaccess();
             }
             //and we are done
             OC_Config::setValue('installed', true);
         }
     }
     return $error;
 }
Example #21
0
OCP\JSON::callCheck();
$success = true;
$username = $_POST["username"];
$group = $_POST["group"];
if ($username == OC_User::getUser() && $group == "admin" && OC_User::isAdminUser($username)) {
    $l = OC_L10N::get('core');
    OC_JSON::error(array('data' => array('message' => $l->t('Admins can\'t remove themself from the admin group'))));
    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);
Example #22
0
 protected function setUp()
 {
     parent::setUp();
     \OC_Group::createGroup('admin');
 }
Example #23
0
 /**
  * share file with a group if a user renames the file the filename should not change
  * for the other users
  */
 function testMoveGroupShare()
 {
     \OC_Group::createGroup('testGroup');
     \OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER1, 'testGroup');
     \OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup');
     \OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup');
     $fileinfo = $this->view->getFileInfo($this->filename);
     $result = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, "testGroup", 31);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
     \OC\Files\Filesystem::rename($this->filename, "newFileName");
     $this->assertTrue(\OC\Files\Filesystem::file_exists('newFileName'));
     $this->assertFalse(\OC\Files\Filesystem::file_exists($this->filename));
     self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
     $this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
     $this->assertFalse(\OC\Files\Filesystem::file_exists("newFileName"));
     self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
     $this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
     $this->assertFalse(\OC\Files\Filesystem::file_exists("newFileName"));
     //cleanup
     \OCP\Share::unshare('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, 'testGroup');
     \OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER1, 'testGroup');
     \OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup');
     \OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup');
 }
Example #24
0
 /**
  * @param string $user
  * @param bool $create
  * @param bool $password
  */
 protected static function loginHelper($user, $create = false, $password = false)
 {
     if ($password === false) {
         $password = $user;
     }
     if ($create) {
         \OC_User::createUser($user, $password);
         \OC_Group::createGroup('group');
         \OC_Group::addToGroup($user, 'group');
     }
     \OC_Util::tearDownFS();
     \OC::$server->getUserSession()->setUser(null);
     \OC\Files\Filesystem::tearDown();
     \OC::$server->getUserSession()->login($user, $password);
     \OC_Util::setupFS($user);
 }
Example #25
0
 /**
  * @dataProvider dataProviderForTestIsSharingDisabledForUser
  * @param array $groups existing groups
  * @param array $membership groups the user belong to
  * @param array $excludedGroups groups which should be excluded from sharing
  * @param bool $expected expected result
  */
 function testIsSharingDisabledForUser($groups, $membership, $excludedGroups, $expected)
 {
     $uid = "user1";
     \OC_User::setUserId($uid);
     \OC_User::createUser($uid, "passwd");
     foreach ($groups as $group) {
         \OC_Group::createGroup($group);
     }
     foreach ($membership as $group) {
         \OC_Group::addToGroup($uid, $group);
     }
     $appConfig = \OC::$server->getAppConfig();
     $appConfig->setValue('core', 'shareapi_exclude_groups_list', implode(',', $excludedGroups));
     $appConfig->setValue('core', 'shareapi_exclude_groups', 'yes');
     $result = \OCP\Util::isSharingDisabledForUser();
     $this->assertSame($expected, $result);
     // cleanup
     \OC_User::deleteUser($uid);
     \OC_User::setUserId('');
     foreach ($groups as $group) {
         \OC_Group::deleteGroup($group);
     }
     $appConfig->setValue('core', 'shareapi_exclude_groups_list', '');
     $appConfig->setValue('core', 'shareapi_exclude_groups', 'no');
 }
Example #26
0
 public function testMultiBackend()
 {
     $userBackend = new \Test\Util\User\Dummy();
     \OC_User::getManager()->registerBackend($userBackend);
     $backend1 = new OC_Group_Dummy();
     $backend2 = new OC_Group_Dummy();
     OC_Group::useBackend($backend1);
     OC_Group::useBackend($backend2);
     $group1 = $this->getUniqueID();
     $group2 = $this->getUniqueID();
     OC_Group::createGroup($group1);
     //groups should be added to the first registered backend
     $this->assertEquals(array($group1), $backend1->getGroups());
     $this->assertEquals(array(), $backend2->getGroups());
     $this->assertEquals(array($group1), OC_Group::getGroups());
     $this->assertTrue(OC_Group::groupExists($group1));
     $this->assertFalse(OC_Group::groupExists($group2));
     $backend1->createGroup($group2);
     $this->assertEquals(array($group1, $group2), OC_Group::getGroups());
     $this->assertTrue(OC_Group::groupExists($group1));
     $this->assertTrue(OC_Group::groupExists($group2));
     $user1 = $this->getUniqueID();
     $user2 = $this->getUniqueID();
     $userBackend->createUser($user1, '');
     $userBackend->createUser($user2, '');
     $this->assertFalse(OC_Group::inGroup($user1, $group1));
     $this->assertFalse(OC_Group::inGroup($user2, $group1));
     $this->assertTrue(OC_Group::addToGroup($user1, $group1));
     $this->assertTrue(OC_Group::inGroup($user1, $group1));
     $this->assertFalse(OC_Group::inGroup($user2, $group1));
     $this->assertFalse($backend2->inGroup($user1, $group1));
     OC_Group::addToGroup($user1, $group1);
     $this->assertEquals(array($user1), OC_Group::usersInGroup($group1));
     $this->assertEquals(array($group1), OC_Group::getUserGroups($user1));
     $this->assertEquals(array(), OC_Group::getUserGroups($user2));
     OC_Group::deleteGroup($group1);
     $this->assertEquals(array(), OC_Group::getUserGroups($user1));
     $this->assertEquals(array(), OC_Group::usersInGroup($group1));
     $this->assertFalse(OC_Group::inGroup($user1, $group1));
 }
Example #27
0
 private static function update_groups($uid, $groups, $protectedGroups = array(), $just_created = false)
 {
     if (!$just_created) {
         $old_groups = OC_Group::getUserGroups($uid);
         foreach ($old_groups as $group) {
             if (!in_array($group, $protectedGroups) && !in_array($group, $groups)) {
                 // This does not affect groups from user_group_admin
                 OC_Group::removeFromGroup($uid, $group);
                 OC_Log::write('saml', 'Removed "' . $uid . '" from the group "' . $group . '"', OC_Log::DEBUG);
             }
         }
     }
     foreach ($groups as $group) {
         if (preg_match('/[^a-zA-Z0-9 _\\.@\\-\\/]/', $group)) {
             OC_Log::write('saml', 'Invalid group "' . $group . '", allowed chars "a-zA-Z0-9" and "_.@-/" ', OC_Log::DEBUG);
         } else {
             if (!OC_Group::inGroup($uid, $group)) {
                 if (!OC_Group::groupExists($group)) {
                     if (OCP\App::isEnabled('user_group_admin')) {
                         OC_User_Group_Admin_Util::createHiddenGroup($group);
                     } else {
                         OC_Group::createGroup($group);
                     }
                     OC_Log::write('saml', 'New group created: ' . $group, OC_Log::DEBUG);
                 }
                 if (OCP\App::isEnabled('user_group_admin')) {
                     OC_User_Group_Admin_Util::addToGroup($uid, $group);
                 } else {
                     OC_Group::addToGroup($uid, $group);
                 }
                 OC_Log::write('saml', 'Added "' . $uid . '" to the group "' . $group . '"', OC_Log::DEBUG);
             }
         }
     }
 }
Example #28
0
 /**
  * If the permissions on a group share are upgraded be sure to still respect 
  * removed shares by a member of that group
  */
 function testPermissionUpgradeOnUserDeletedGroupShare()
 {
     \OC_Group::createGroup('testGroup');
     \OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER1, 'testGroup');
     \OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup');
     \OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup');
     $connection = \OC::$server->getDatabaseConnection();
     // Share item with group
     $fileinfo = $this->view->getFileInfo($this->folder);
     $share = $this->share(\OCP\Share::SHARE_TYPE_GROUP, $this->folder, self::TEST_FILES_SHARING_API_USER1, 'testGroup', \OCP\Constants::PERMISSION_READ);
     // Login as user 2 and verify the item exists
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $this->assertTrue(\OC\Files\Filesystem::file_exists($this->folder));
     $result = $this->shareManager->getShareById($share->getFullId(), self::TEST_FILES_SHARING_API_USER2);
     $this->assertNotEmpty($result);
     $this->assertEquals(\OCP\Constants::PERMISSION_READ, $result->getPermissions());
     // Delete the share
     $this->assertTrue(\OC\Files\Filesystem::rmdir($this->folder));
     $this->assertFalse(\OC\Files\Filesystem::file_exists($this->folder));
     // Verify we do not get a share
     $result = $this->shareManager->getShareById($share->getFullId(), self::TEST_FILES_SHARING_API_USER2);
     $this->assertEquals(0, $result->getPermissions());
     // Login as user 1 again and change permissions
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     $share->setPermissions(\OCP\Constants::PERMISSION_ALL);
     $share = $this->shareManager->updateShare($share);
     // Login as user 2 and verify
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $this->assertFalse(\OC\Files\Filesystem::file_exists($this->folder));
     $result = $this->shareManager->getShareById($share->getFullId(), self::TEST_FILES_SHARING_API_USER2);
     $this->assertEquals(0, $result->getPermissions());
     $this->shareManager->deleteShare($share);
     //cleanup
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     \OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER1, 'testGroup');
     \OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup');
     \OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup');
 }
Example #29
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())));
}
Example #30
0
 public function testSubAdminOfGroupAlreadySubAdmin()
 {
     $user1 = $this->generateUsers();
     $user2 = $this->generateUsers();
     self::loginAsUser($user1);
     \OC_Group::addToGroup($user1, 'admin');
     $group1 = $this->getUniqueID();
     \OC_Group::createGroup($group1);
     //Make user2 subadmin of group1
     $_POST['groupid'] = $group1;
     $result = \OCA\provisioning_api\Users::addSubAdmin(['userid' => $user2]);
     $this->assertInstanceOf('OC_OCS_Result', $result);
     $this->assertTrue($result->succeeded());
     //Make user2 subadmin of group1 again
     $_POST['groupid'] = $group1;
     $result = \OCA\provisioning_api\Users::addSubAdmin(['userid' => $user2]);
     $this->assertInstanceOf('OC_OCS_Result', $result);
     $this->assertTrue($result->succeeded());
 }