Ejemplo n.º 1
0
 /**
  * @brief Can be set up
  * @param string $user
  * @return boolean
  * @description configure the initial filesystem based on the configuration
  */
 public static function setupFS($user = '')
 {
     //setting up the filesystem twice can only lead to trouble
     if (self::$fsSetup) {
         return false;
     }
     // If we are not forced to load a specific user we load the one that is logged in
     if ($user == "" && OC_User::isLoggedIn()) {
         $user = OC_User::getUser();
     }
     // load all filesystem apps before, so no setup-hook gets lost
     if (!isset($RUNTIME_NOAPPS) || !$RUNTIME_NOAPPS) {
         OC_App::loadApps(array('filesystem'));
     }
     // the filesystem will finish when $user is not empty,
     // mark fs setup here to avoid doing the setup from loading
     // OC_Filesystem
     if ($user != '') {
         self::$fsSetup = true;
     }
     $configDataDirectory = OC_Config::getValue("datadirectory", OC::$SERVERROOT . "/data");
     //first set up the local "root" storage
     \OC\Files\Filesystem::initMounts();
     if (!self::$rootMounted) {
         \OC\Files\Filesystem::mount('\\OC\\Files\\Storage\\Local', array('datadir' => $configDataDirectory), '/');
         self::$rootMounted = true;
     }
     //if we aren't logged in, there is no use to set up the filesystem
     if ($user != "") {
         \OC\Files\Filesystem::addStorageWrapper(function ($mountPoint, $storage) {
             // set up quota for home storages, even for other users
             // which can happen when using sharing
             if ($storage instanceof \OC\Files\Storage\Home) {
                 $user = $storage->getUser()->getUID();
                 $quota = OC_Util::getUserQuota($user);
                 if ($quota !== \OC\Files\SPACE_UNLIMITED) {
                     return new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => $quota));
                 }
             }
             return $storage;
         });
         $userDir = '/' . $user . '/files';
         $userRoot = OC_User::getHome($user);
         $userDirectory = $userRoot . '/files';
         if (!is_dir($userDirectory)) {
             mkdir($userDirectory, 0755, true);
             OC_Util::copySkeleton($userDirectory);
         }
         //jail the user into his "home" directory
         \OC\Files\Filesystem::init($user, $userDir);
         $fileOperationProxy = new OC_FileProxy_FileOperations();
         OC_FileProxy::register($fileOperationProxy);
         OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $userDir));
     }
     return true;
 }
Ejemplo n.º 2
0
 /**
  * @brief Get the source file path for a shared file
  * @param string Shared target file path
  * @return Returns source file path or false if not found
  */
 private function getSourcePath($target)
 {
     $file = $this->getFile($target);
     if (isset($file['path'])) {
         $uid = substr($file['path'], 1, strpos($file['path'], '/', 1) - 1);
         OC_Filesystem::mount('OC_Filestorage_Local', array('datadir' => OC_User::getHome($uid)), $uid);
         return $file['path'];
     }
     return false;
 }
Ejemplo n.º 3
0
 public static function setupFS($user = '')
 {
     // configure the initial filesystem based on the configuration
     if (self::$fsSetup) {
         //setting up the filesystem twice can only lead to trouble
         return false;
     }
     // If we are not forced to load a specific user we load the one that is logged in
     if ($user == "" && OC_User::isLoggedIn()) {
         $user = OC_User::getUser();
     }
     // the filesystem will finish when $user is not empty,
     // mark fs setup here to avoid doing the setup from loading
     // OC_Filesystem
     if ($user != '') {
         self::$fsSetup = true;
     }
     $CONFIG_DATADIRECTORY = OC_Config::getValue("datadirectory", OC::$SERVERROOT . "/data");
     //first set up the local "root" storage
     if (!self::$rootMounted) {
         OC_Filesystem::mount('OC_Filestorage_Local', array('datadir' => $CONFIG_DATADIRECTORY), '/');
         self::$rootMounted = true;
     }
     if ($user != "") {
         //if we aren't logged in, there is no use to set up the filesystem
         $user_dir = '/' . $user . '/files';
         $user_root = OC_User::getHome($user);
         $userdirectory = $user_root . '/files';
         if (!is_dir($userdirectory)) {
             mkdir($userdirectory, 0755, true);
         }
         //jail the user into his "home" directory
         OC_Filesystem::mount('OC_Filestorage_Local', array('datadir' => $user_root), $user);
         OC_Filesystem::init($user_dir);
         $quotaProxy = new OC_FileProxy_Quota();
         OC_FileProxy::register($quotaProxy);
         // Load personal mount config
         if (is_file($user_root . '/mount.php')) {
             $mountConfig = (include $user_root . '/mount.php');
             if (isset($mountConfig['user'][$user])) {
                 foreach ($mountConfig['user'][$user] as $mountPoint => $options) {
                     OC_Filesystem::mount($options['class'], $options['options'], $mountPoint);
                 }
             }
             $mtime = filemtime($user_root . '/mount.php');
             $previousMTime = OC_Preferences::getValue($user, 'files', 'mountconfigmtime', 0);
             if ($mtime > $previousMTime) {
                 //mount config has changed, filecache needs to be updated
                 OC_FileCache::triggerUpdate($user);
                 OC_Preferences::setValue($user, 'files', 'mountconfigmtime', $mtime);
             }
         }
         OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $user_dir));
     }
 }
Ejemplo n.º 4
0
 /**
  * Delete thumb from filesystem if exists
  * @param string $thumbPath
  */
 private static function deleteThumb($thumbPath)
 {
     // Get full thumbnail path
     $fileInfo = pathinfo($thumbPath);
     $user = \OCP\USER::getUser();
     $previewDir = \OC_User::getHome($user) . '/oclife/previews/' . $user;
     $fullThumbPath = $previewDir . $fileInfo['dirname'] . '/' . $fileInfo['filename'] . '.png';
     // If thumbnail exists remove it
     if (file_exists($fullThumbPath)) {
         unlink($fullThumbPath);
     }
 }
 public function checkPassword($uid, $password)
 {
     $this->_user[$uid] = \GO::session()->login($uid, $password, false);
     if (!$this->_user[$uid]) {
         return false;
     } else {
         //workaround bug in ownCloud
         $cache = \OC_User::getHome($uid) . '/cache';
         if (!is_dir($cache)) {
             mkdir($cache, 0755, true);
         }
         //make sure ownCloud folder exists in Group-Office
         $folder = new \GO\Base\Fs\Folder(\GO::config()->file_storage_path . 'users/' . $uid . $this->_groupoffice_mount);
         $folder->create();
         return $uid;
     }
 }
Ejemplo n.º 6
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;
 }
Ejemplo n.º 7
0
 public static function setupFS($user = '')
 {
     // configure the initial filesystem based on the configuration
     if (self::$fsSetup) {
         //setting up the filesystem twice can only lead to trouble
         return false;
     }
     // If we are not forced to load a specific user we load the one that is logged in
     if ($user == "" && OC_User::isLoggedIn()) {
         $user = OC_User::getUser();
     }
     // load all filesystem apps before, so no setup-hook gets lost
     if (!isset($RUNTIME_NOAPPS) || !$RUNTIME_NOAPPS) {
         OC_App::loadApps(array('filesystem'));
     }
     // the filesystem will finish when $user is not empty,
     // mark fs setup here to avoid doing the setup from loading
     // OC_Filesystem
     if ($user != '') {
         self::$fsSetup = true;
     }
     $CONFIG_DATADIRECTORY = OC_Config::getValue("datadirectory", OC::$SERVERROOT . "/data");
     //first set up the local "root" storage
     if (!self::$rootMounted) {
         \OC\Files\Filesystem::mount('\\OC\\Files\\Storage\\Local', array('datadir' => $CONFIG_DATADIRECTORY), '/');
         self::$rootMounted = true;
     }
     if ($user != "") {
         //if we aren't logged in, there is no use to set up the filesystem
         $user_dir = '/' . $user . '/files';
         $user_root = OC_User::getHome($user);
         $userdirectory = $user_root . '/files';
         if (!is_dir($userdirectory)) {
             mkdir($userdirectory, 0755, true);
         }
         //jail the user into his "home" directory
         \OC\Files\Filesystem::init($user, $user_dir);
         $quotaProxy = new OC_FileProxy_Quota();
         $fileOperationProxy = new OC_FileProxy_FileOperations();
         OC_FileProxy::register($quotaProxy);
         OC_FileProxy::register($fileOperationProxy);
         OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $user_dir));
     }
     return true;
 }
Ejemplo n.º 8
0
 public function __construct($imagePath, $user = null, $square = false)
 {
     if (!Filesystem::isValidPath($imagePath)) {
         return;
     }
     if (is_null($user)) {
         $this->view = Filesystem::getView();
         $this->user = \OCP\USER::getUser();
     } else {
         $this->view = new View('/' . $user . '/files');
         $this->user = $user;
     }
     $galleryDir = \OC_User::getHome($this->user) . '/gallery/' . $this->user . '/';
     $this->path = $galleryDir . $imagePath . '.png';
     if (!file_exists($this->path)) {
         self::create($imagePath, $square);
     }
 }
Ejemplo n.º 9
0
 function setUp()
 {
     // set content for encrypting / decrypting in tests
     $this->dataLong = file_get_contents(__DIR__ . '/../lib/crypt.php');
     $this->dataShort = 'hats';
     $this->dataUrl = __DIR__ . '/../lib/crypt.php';
     $this->legacyData = __DIR__ . '/legacy-text.txt';
     $this->legacyEncryptedData = __DIR__ . '/legacy-encrypted-text.txt';
     $this->randomKey = Encryption\Crypt::generateKey();
     $keypair = Encryption\Crypt::createKeypair();
     $this->genPublicKey = $keypair['publicKey'];
     $this->genPrivateKey = $keypair['privateKey'];
     $this->view = new \OC\Files\View('/');
     \Test_Encryption_Util::loginHelper(Test_Encryption_Keymanager::TEST_USER);
     $this->userId = \Test_Encryption_Keymanager::TEST_USER;
     $this->pass = \Test_Encryption_Keymanager::TEST_USER;
     $userHome = \OC_User::getHome($this->userId);
     $this->dataDir = str_replace('/' . $this->userId, '', $userHome);
 }
Ejemplo n.º 10
0
 /**
  * @param array $params
  * @throws \Exception
  */
 public function __construct($params)
 {
     $this->statCache = new ArrayCache();
     if (isset($params['host']) && isset($params['user']) && isset($params['password'])) {
         $host = $params['host'];
         //remove leading http[s], will be generated in createBaseUri()
         if (substr($host, 0, 8) == "https://") {
             $host = substr($host, 8);
         } else {
             if (substr($host, 0, 7) == "http://") {
                 $host = substr($host, 7);
             }
         }
         $this->host = $host;
         $this->user = $params['user'];
         $this->password = $params['password'];
         if (isset($params['secure'])) {
             if (is_string($params['secure'])) {
                 $this->secure = $params['secure'] === 'true';
             } else {
                 $this->secure = (bool) $params['secure'];
             }
         } else {
             $this->secure = false;
         }
         if ($this->secure === true) {
             $certPath = \OC_User::getHome(\OC_User::getUser()) . '/files_external/rootcerts.crt';
             if (file_exists($certPath)) {
                 $this->certPath = $certPath;
             }
         }
         $this->root = isset($params['root']) ? $params['root'] : '/';
         if (!$this->root || $this->root[0] != '/') {
             $this->root = '/' . $this->root;
         }
         if (substr($this->root, -1, 1) != '/') {
             $this->root .= '/';
         }
     } else {
         throw new \Exception('Invalid webdav storage configuration');
     }
 }
Ejemplo n.º 11
0
 public static function loadUserMountPoints($user)
 {
     $user_dir = '/' . $user . '/files';
     $user_root = OC_User::getHome($user);
     $userdirectory = $user_root . '/files';
     if (is_file($user_root . '/mount.php')) {
         $mountConfig = (include $user_root . '/mount.php');
         if (isset($mountConfig['user'][$user])) {
             foreach ($mountConfig['user'][$user] as $mountPoint => $options) {
                 OC_Filesystem::mount($options['class'], $options['options'], $mountPoint);
             }
         }
         $mtime = filemtime($user_root . '/mount.php');
         $previousMTime = OC_Preferences::getValue($user, 'files', 'mountconfigmtime', 0);
         if ($mtime > $previousMTime) {
             //mount config has changed, filecache needs to be updated
             OC_FileCache::triggerUpdate($user);
             OC_Preferences::setValue($user, 'files', 'mountconfigmtime', $mtime);
         }
     }
 }
Ejemplo n.º 12
0
 function setUp()
 {
     // set content for encrypting / decrypting in tests
     $this->dataLong = file_get_contents(__DIR__ . '/../lib/crypt.php');
     $this->dataShort = 'hats';
     $this->dataUrl = __DIR__ . '/../lib/crypt.php';
     $this->legacyData = __DIR__ . '/legacy-text.txt';
     $this->legacyEncryptedData = __DIR__ . '/legacy-encrypted-text.txt';
     $this->randomKey = Encryption\Crypt::generateKey();
     $keypair = Encryption\Crypt::createKeypair();
     $this->genPublicKey = $keypair['publicKey'];
     $this->genPrivateKey = $keypair['privateKey'];
     $this->view = new \OC_FilesystemView('/');
     \OC_User::setUserId(\Test_Encryption_Keymanager::TEST_USER);
     $this->userId = \Test_Encryption_Keymanager::TEST_USER;
     $this->pass = \Test_Encryption_Keymanager::TEST_USER;
     $userHome = \OC_User::getHome($this->userId);
     $this->dataDir = str_replace('/' . $this->userId, '', $userHome);
     // remember files_trashbin state
     $this->stateFilesTrashbin = OC_App::isEnabled('files_trashbin');
     // we don't want to tests with app files_trashbin enabled
     \OC_App::disable('files_trashbin');
 }
Ejemplo n.º 13
0
 /**
  * opens or creates the users lucene index
  * 
  * stores the index in <datadirectory>/<user>/lucene_index
  * 
  * @author Jörn Dreyer <*****@*****.**>
  *
  * @return Zend_Search_Lucene_Interface 
  */
 public static function openOrCreate($user = null)
 {
     if ($user == null) {
         $user = User::getUser();
     }
     try {
         \Zend_Search_Lucene_Analysis_Analyzer::setDefault(new \Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive());
         //let lucene search for numbers as well as words
         // Create index
         //$ocFilesystemView = OC_App::getStorage('search_lucene'); // encrypt the index on logout, decrypt on login
         $indexUrl = \OC_User::getHome($user) . '/lucene_index';
         if (file_exists($indexUrl)) {
             $index = \Zend_Search_Lucene::open($indexUrl);
         } else {
             $index = \Zend_Search_Lucene::create($indexUrl);
             //todo index all user files
         }
     } catch (Exception $e) {
         Util::writeLog('search_lucene', $e->getMessage() . ' Trace:\\n' . $e->getTraceAsString(), Util::ERROR);
         return null;
     }
     return $index;
 }
Ejemplo n.º 14
0
 public static function av_scan($path)
 {
     $path = $path[\OC\Files\Filesystem::signal_param_path];
     if ($path != '') {
         $files_view = \OCP\Files::getStorage("files");
         if ($files_view->file_exists($path)) {
             $root = OC_User::getHome(OC_User::getUser()) . '/files';
             $file = $root . $path;
             $result = self::clamav_scan($file);
             switch ($result) {
                 case CLAMAV_SCANRESULT_UNCHECKED:
                     //TODO: Show warning to the user: The file can not be checked
                     break;
                 case CLAMAV_SCANRESULT_INFECTED:
                     //remove file
                     $files_view->unlink($path);
                     OCP\JSON::error(array("data" => array("message" => "Virus detected! Can't upload the file.")));
                     $email = OC_Preferences::getValue(OC_User::getUser(), 'settings', 'email', '');
                     \OCP\Util::writeLog('files_antivirus', 'Email: ' . $email, \OCP\Util::DEBUG);
                     if (!empty($email)) {
                         $tmpl = new OC_Template('files_antivirus', 'notification');
                         $tmpl->assign('file', $path);
                         $tmpl->assign('host', OCP\Util::getServerHost());
                         $tmpl->assign('user', OC_User::getUser());
                         $msg = $tmpl->fetchPage();
                         $from = OCP\Util::getDefaultEmailAddress('security-noreply');
                         OCP\Util::sendMail($email, OC_User::getUser(), 'Malware detected', $msg, $from, 'ownCloud', 1);
                     }
                     exit;
                     break;
                 case CLAMAV_SCANRESULT_CLEAN:
                     //do nothing
                     break;
             }
         }
     }
 }
Ejemplo n.º 15
0
 /**
  * Write the mount points to the config file
  *
  * @param string|null $user If not null, personal for $user, otherwise system
  * @param array $data Mount points
  */
 public static function writeData($user, $data)
 {
     if (isset($user)) {
         $file = OC_User::getHome($user) . '/mount.json';
     } else {
         $datadir = \OC_Config::getValue('datadirectory', \OC::$SERVERROOT . '/data/');
         $file = \OC_Config::getValue('mount_file', $datadir . '/mount.json');
     }
     foreach ($data as &$applicables) {
         foreach ($applicables as &$mountPoints) {
             foreach ($mountPoints as &$options) {
                 self::addStorageId($options);
             }
         }
     }
     $content = json_encode($data, JSON_PRETTY_PRINT);
     @file_put_contents($file, $content);
     @chmod($file, 0640);
 }
Ejemplo n.º 16
0
 /**
  * creates certificate bundle
  */
 public static function createCertificateBundle()
 {
     $path = OC_User::getHome(OC_User::getUser()) . '/files_external';
     $certs = OC_Mount_Config::getCertificates();
     $fh_certs = fopen($path . "/rootcerts.crt", 'w');
     foreach ($certs as $cert) {
         $file = $path . '/uploads/' . $cert;
         $fh = fopen($file, "r");
         $data = fread($fh, filesize($file));
         fclose($fh);
         if (strpos($data, 'BEGIN CERTIFICATE')) {
             fwrite($fh_certs, $data);
             fwrite($fh_certs, "\r\n");
         }
     }
     fclose($fh_certs);
     return true;
 }
Ejemplo n.º 17
0
 /**
  * return path to file which reflects one visible in browser
  *
  * @param string $path
  * @return string
  */
 public static function getLocalPath($path)
 {
     $datadir = \OC_User::getHome(\OC_User::getUser()) . '/files';
     $newpath = $path;
     if (strncmp($newpath, $datadir, strlen($datadir)) == 0) {
         $newpath = substr($path, strlen($datadir));
     }
     return $newpath;
 }
Ejemplo n.º 18
0
 public static function removeHook($params)
 {
     $path = $params['path'];
     $user = \OCP\User::getUser();
     $galleryDir = \OC_User::getHome($user) . '/gallery/';
     $thumbPath = $galleryDir . $path;
     if (is_dir($thumbPath)) {
         if (file_exists($thumbPath . '.png')) {
             unlink($thumbPath . '.png');
         }
     } else {
         if (file_exists($thumbPath)) {
             unlink($thumbPath);
         }
         if (strrpos($path, '.')) {
             $extension = substr($path, strrpos($path, '.') + 1);
             $image = substr($path, 0, strrpos($path, '.'));
         } else {
             $extension = '';
             $image = $path;
         }
         $squareThumbPath = $galleryDir . $image . '.square.' . $extension;
         if (file_exists($squareThumbPath)) {
             unlink($squareThumbPath);
         }
     }
     $parent = dirname($path);
     if ($parent !== DIRECTORY_SEPARATOR and $parent !== '' and $parent !== $path) {
         self::removeHook(array('path' => $parent));
     }
 }
Ejemplo n.º 19
0
OCP\JSON::checkLoggedIn();
// Revert parameters from ajax
$filePath = filter_input(INPUT_GET, 'filePath', FILTER_SANITIZE_STRING);
if (substr($filePath, -1) === '/') {
    $previewPath = __DIR__ . '/img/multiImage.png';
} else {
    // Get current user
    $user = \OCP\User::getUser();
    // Build user's view path
    $viewPath = '/' . $user . '/files';
    // Build the placeholder's path - Image to show in case we don't have the thumbnail
    $placeHolderPath = __DIR__ . '/img/noImage.png';
    // Build thumb path
    if (isset($filePath)) {
        $filePathInfo = pathinfo($filePath);
        $previewPath = \OC_User::getHome($user) . '/oclife/thumbnails/' . $user;
        $previewDir = $previewPath . ($filePathInfo['dirname'] === '.' ? '' : $filePathInfo['dirname']);
        // OC7 FIX
        $thumbPath = $previewDir . '/' . $filePathInfo['filename'] . '.png';
        // Check and eventually prepare preview directory
        if (!is_dir($previewDir)) {
            mkdir($previewDir, 0755, true);
        }
        // If preview exist check if it's newer than the file, regenate it otherwise
        if (file_exists($thumbPath)) {
            $thumbMTime = filemtime($thumbPath);
            $fileInfo = \OC\Files\Filesystem::getFileInfo($filePath);
            if ($thumbMTime < $fileInfo['mtime']) {
                unlink($thumbPath);
            }
        }
Ejemplo n.º 20
0
 /**
  * Write the mount points to the config file
  * @param bool Personal or system config file
  * @param array Mount points
  */
 private static function writeData($isPersonal, $data)
 {
     if ($isPersonal) {
         $file = OC_User::getHome(OCP\User::getUser()) . '/mount.php';
     } else {
         $file = OC::$SERVERROOT . '/config/mount.php';
     }
     $content = "<?php return array (\n";
     if (isset($data[self::MOUNT_TYPE_GROUP])) {
         $content .= "\t'group' => array (\n";
         foreach ($data[self::MOUNT_TYPE_GROUP] as $group => $mounts) {
             $content .= "\t\t'" . $group . "' => array (\n";
             foreach ($mounts as $mountPoint => $mount) {
                 $content .= "\t\t\t'" . $mountPoint . "' => " . str_replace("\n", '', var_export($mount, true)) . ",\n";
             }
             $content .= "\t\t),\n";
         }
         $content .= "\t),\n";
     }
     if (isset($data[self::MOUNT_TYPE_USER])) {
         $content .= "\t'user' => array (\n";
         foreach ($data[self::MOUNT_TYPE_USER] as $user => $mounts) {
             $content .= "\t\t'" . $user . "' => array (\n";
             foreach ($mounts as $mountPoint => $mount) {
                 $content .= "\t\t\t'" . $mountPoint . "' => " . str_replace("\n", '', var_export($mount, true)) . ",\n";
             }
             $content .= "\t\t),\n";
         }
         $content .= "\t),\n";
     }
     $content .= ");\n?>";
     @file_put_contents($file, $content);
 }
Ejemplo n.º 21
0
 protected function setUp()
 {
     parent::setUp();
     OC_Mount_Config::registerBackend('Test_Mount_Config_Dummy_Storage', array('backend' => 'dummy', 'priority' => 150, 'configuration' => array()));
     OC_Mount_Config::registerBackend('Test_Mount_Config_Storage_No_Personal', array('backend' => 'dummy no personal', 'priority' => 150, 'configuration' => array()));
     \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::createGroup(self::TEST_GROUP1B);
     \OC_Group::addToGroup(self::TEST_USER1, self::TEST_GROUP1);
     \OC_Group::addToGroup(self::TEST_USER1, self::TEST_GROUP1B);
     \OC_Group::createGroup(self::TEST_GROUP2);
     \OC_Group::createGroup(self::TEST_GROUP2B);
     \OC_Group::addToGroup(self::TEST_USER2, self::TEST_GROUP2);
     \OC_Group::addToGroup(self::TEST_USER2, self::TEST_GROUP2B);
     \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', '');
     OCP\Config::setAppValue('files_external', 'user_mounting_backends', 'Test_Mount_Config_Dummy_Storage');
     OC_Mount_Config::$skipTest = true;
     Test_Mount_Config_Hook_Test::setupHooks();
 }
Ejemplo n.º 22
0
 /**
  * Delete the user
  *
  * @return bool
  */
 public function delete()
 {
     if ($this->emitter) {
         $this->emitter->emit('\\OC\\User', 'preDelete', array($this));
     }
     $result = $this->backend->deleteUser($this->uid);
     if ($result) {
         // FIXME: Feels like an hack - suggestions?
         // We have to delete the user from all groups
         foreach (\OC_Group::getUserGroups($this->uid) as $i) {
             \OC_Group::removeFromGroup($this->uid, $i);
         }
         // Delete the user's keys in preferences
         \OC::$server->getConfig()->deleteAllUserValues($this->uid);
         // Delete user files in /data/
         \OC_Helper::rmdirr(\OC_User::getHome($this->uid));
         // Delete the users entry in the storage table
         \OC\Files\Cache\Storage::remove('home::' . $this->uid);
         \OC::$server->getCommentsManager()->deleteReferencesOfActor('users', $this->uid);
         \OC::$server->getCommentsManager()->deleteReadMarksFromUser($this);
     }
     if ($this->emitter) {
         $this->emitter->emit('\\OC\\User', 'postDelete', array($this));
     }
     return !($result === false);
 }
Ejemplo n.º 23
0
 /**
  * Write the mount points to the config file
  * @param bool Personal or system config file
  * @param array Mount points
  */
 private static function writeData($isPersonal, $data)
 {
     if ($isPersonal) {
         $file = OC_User::getHome(OCP\User::getUser()) . '/mount.json';
     } else {
         $datadir = \OC_Config::getValue("datadirectory", \OC::$SERVERROOT . "/data");
         $file = $datadir . '/mount.json';
     }
     $content = json_encode($data);
     @file_put_contents($file, $content);
 }
Ejemplo n.º 24
0
 /**
  * Can be set up
  *
  * @param string $user
  * @return boolean
  * @description configure the initial filesystem based on the configuration
  */
 public static function setupFS($user = '')
 {
     //setting up the filesystem twice can only lead to trouble
     if (self::$fsSetup) {
         return false;
     }
     // If we are not forced to load a specific user we load the one that is logged in
     if ($user == "" && OC_User::isLoggedIn()) {
         $user = OC_User::getUser();
     }
     // load all filesystem apps before, so no setup-hook gets lost
     OC_App::loadApps(array('filesystem'));
     // the filesystem will finish when $user is not empty,
     // mark fs setup here to avoid doing the setup from loading
     // OC_Filesystem
     if ($user != '') {
         self::$fsSetup = true;
     }
     //check if we are using an object storage
     $objectStore = OC_Config::getValue('objectstore');
     if (isset($objectStore)) {
         self::initObjectStoreRootFS($objectStore);
     } else {
         self::initLocalStorageRootFS();
     }
     if ($user != '' && !OCP\User::userExists($user)) {
         return false;
     }
     //if we aren't logged in, there is no use to set up the filesystem
     if ($user != "") {
         \OC\Files\Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) {
             // set up quota for home storages, even for other users
             // which can happen when using sharing
             /**
              * @var \OC\Files\Storage\Storage $storage
              */
             if ($storage->instanceOfStorage('\\OC\\Files\\Storage\\Home') || $storage->instanceOfStorage('\\OC\\Files\\ObjectStore\\HomeObjectStoreStorage')) {
                 if (is_object($storage->getUser())) {
                     $user = $storage->getUser()->getUID();
                     $quota = OC_Util::getUserQuota($user);
                     if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) {
                         return new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => $quota, 'root' => 'files'));
                     }
                 }
             }
             return $storage;
         });
         // copy skeleton for local storage only
         if (!isset($objectStore)) {
             $userRoot = OC_User::getHome($user);
             $userDirectory = $userRoot . '/files';
             if (!is_dir($userDirectory)) {
                 mkdir($userDirectory, 0755, true);
                 OC_Util::copySkeleton($userDirectory);
             }
         }
         $userDir = '/' . $user . '/files';
         //jail the user into his "home" directory
         \OC\Files\Filesystem::init($user, $userDir);
         $fileOperationProxy = new OC_FileProxy_FileOperations();
         OC_FileProxy::register($fileOperationProxy);
         OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $userDir));
     }
     return true;
 }
Ejemplo n.º 25
0
 public function getShareInfo()
 {
     $remote = $this->getRemote();
     $token = $this->getToken();
     $password = $this->getPassword();
     $url = $remote . '/index.php/apps/files_sharing/shareinfo?t=' . $token;
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array('password' => $password)));
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
     $path = \OC_User::getHome(\OC_User::getUser()) . '/files_external/rootcerts.crt';
     if (is_readable($path)) {
         curl_setopt($ch, CURLOPT_CAINFO, $path);
     }
     $result = curl_exec($ch);
     $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     $errorMessage = curl_error($ch);
     curl_close($ch);
     if (!empty($errorMessage)) {
         throw new \Exception($errorMessage);
     }
     switch ($status) {
         case 401:
         case 403:
             throw new ForbiddenException();
         case 404:
             throw new NotFoundException();
         case 500:
             throw new \Exception();
     }
     return json_decode($result, true);
 }
Ejemplo n.º 26
0
                $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"];
// Return Success story
try {
    // check whether the user's files home exists
    $userDirectory = OC_User::getHome($username) . '/files/';
    $homeExists = file_exists($userDirectory);
    if (!OC_User::createUser($username, $password)) {
        OC_JSON::error(array('data' => array('message' => 'User creation failed for ' . $username)));
        exit;
    }
    foreach ($groups as $i) {
        if (!OC_Group::groupExists($i)) {
            OC_Group::createGroup($i);
        }
        OC_Group::addToGroup($username, $i);
    }
    OC_JSON::success(array("data" => array("homeExists" => $homeExists, "username" => $username, "groups" => OC_Group::getUserGroups($username))));
} catch (Exception $exception) {
    OC_JSON::error(array("data" => array("message" => $exception->getMessage())));
}
Ejemplo n.º 27
0
 function testMountSharesOtherUser()
 {
     $folderInfo = $this->view->getFileInfo($this->folder);
     $fileInfo = $this->view->getFileInfo($this->filename);
     $rootView = new \OC\Files\View('');
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     // share 2 different files with 2 different users
     \OCP\Share::shareItem('folder', $folderInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
     \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER3, 31);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $this->assertTrue($rootView->file_exists('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/' . $this->folder));
     OC_Hook::emit('OC_Filesystem', 'setup', array('user' => self::TEST_FILES_SHARING_API_USER3, 'user_dir' => \OC_User::getHome(self::TEST_FILES_SHARING_API_USER3)));
     $this->assertTrue($rootView->file_exists('/' . self::TEST_FILES_SHARING_API_USER3 . '/files/' . $this->filename));
     // make sure we didn't double setup shares for user 2 or mounted the shares for user 3 in user's 2 home
     $this->assertFalse($rootView->file_exists('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/' . $this->folder . ' (2)'));
     $this->assertFalse($rootView->file_exists('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/' . $this->filename));
     //cleanup
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     $this->view->unlink($this->folder);
 }
Ejemplo n.º 28
0
 /**
  * exports a user, or owncloud instance
  * @param string $uid user id of user to export if export type is user, defaults to current
  * @param string $type type of export, defualts to user
  * @param string $path path to zip output folder
  * @return string on error, path to zip on success
  */
 public static function export($uid = null, $type = 'user', $path = null)
 {
     $datadir = OC_Config::getValue('datadirectory');
     // Validate export type
     $types = array('user', 'instance', 'system', 'userfiles');
     if (!in_array($type, $types)) {
         OC_Log::write('migration', 'Invalid export type', OC_Log::ERROR);
         return json_encode(array('success' => false));
     }
     self::$exporttype = $type;
     // Userid?
     if (self::$exporttype == 'user') {
         // Check user exists
         self::$uid = is_null($uid) ? OC_User::getUser() : $uid;
         if (!OC_User::userExists(self::$uid)) {
             return json_encode(array('success' => false));
         }
     }
     // Calculate zipname
     if (self::$exporttype == 'user') {
         $zipname = 'oc_export_' . self::$uid . '_' . date("y-m-d_H-i-s") . '.zip';
     } else {
         $zipname = 'oc_export_' . self::$exporttype . '_' . date("y-m-d_H-i-s") . '.zip';
     }
     // Calculate path
     if (self::$exporttype == 'user') {
         self::$zippath = $datadir . '/' . self::$uid . '/' . $zipname;
     } else {
         if (!is_null($path)) {
             // Validate custom path
             if (!file_exists($path) || !is_writeable($path)) {
                 OC_Log::write('migration', 'Path supplied is invalid.', OC_Log::ERROR);
                 return json_encode(array('success' => false));
             }
             self::$zippath = $path . $zipname;
         } else {
             // Default path
             self::$zippath = get_temp_dir() . '/' . $zipname;
         }
     }
     // Create the zip object
     if (!self::createZip()) {
         return json_encode(array('success' => false));
     }
     // Do the export
     self::findProviders();
     $exportdata = array();
     switch (self::$exporttype) {
         case 'user':
             // Connect to the db
             self::$dbpath = $datadir . '/' . self::$uid . '/migration.db';
             if (!self::connectDB()) {
                 return json_encode(array('success' => false));
             }
             self::$content = new OC_Migration_Content(self::$zip, self::$migration_database);
             // Export the app info
             $exportdata = self::exportAppData();
             // Add the data dir to the zip
             self::$content->addDir(OC_User::getHome(self::$uid), true, '/');
             break;
         case 'instance':
             self::$content = new OC_Migration_Content(self::$zip);
             // Creates a zip that is compatable with the import function
             $dbfile = tempnam(get_temp_dir(), "owncloud_export_data_");
             OC_DB::getDbStructure($dbfile, 'MDB2_SCHEMA_DUMP_ALL');
             // Now add in *dbname* and *dbprefix*
             $dbexport = file_get_contents($dbfile);
             $dbnamestring = "<database>\n\n <name>" . OC_Config::getValue("dbname", "owncloud");
             $dbtableprefixstring = "<table>\n\n  <name>" . OC_Config::getValue("dbtableprefix", "oc_");
             $dbexport = str_replace($dbnamestring, "<database>\n\n <name>*dbname*", $dbexport);
             $dbexport = str_replace($dbtableprefixstring, "<table>\n\n  <name>*dbprefix*", $dbexport);
             // Add the export to the zip
             self::$content->addFromString($dbexport, "dbexport.xml");
             // Add user data
             foreach (OC_User::getUsers() as $user) {
                 self::$content->addDir(OC_User::getHome($user), true, "/userdata/");
             }
             break;
         case 'userfiles':
             self::$content = new OC_Migration_Content(self::$zip);
             // Creates a zip with all of the users files
             foreach (OC_User::getUsers() as $user) {
                 self::$content->addDir(OC_User::getHome($user), true, "/");
             }
             break;
         case 'system':
             self::$content = new OC_Migration_Content(self::$zip);
             // Creates a zip with the owncloud system files
             self::$content->addDir(OC::$SERVERROOT . '/', false, '/');
             foreach (array(".git", "3rdparty", "apps", "core", "files", "l10n", "lib", "ocs", "search", "settings", "tests") as $dir) {
                 self::$content->addDir(OC::$SERVERROOT . '/' . $dir, true, "/");
             }
             break;
     }
     if (!($info = self::getExportInfo($exportdata))) {
         return json_encode(array('success' => false));
     }
     // Add the export info json to the export zip
     self::$content->addFromString($info, 'export_info.json');
     if (!self::$content->finish()) {
         return json_encode(array('success' => false));
     }
     return json_encode(array('success' => true, 'data' => self::$zippath));
 }
Ejemplo n.º 29
0
 /**
  * Write the mount points to the config file
  * @param string|null $user If not null, personal for $user, otherwise system
  * @param array $data Mount points
  */
 private static function writeData($user, $data)
 {
     if (isset($user)) {
         $file = OC_User::getHome($user) . '/mount.json';
     } else {
         $datadir = \OC_Config::getValue('datadirectory', \OC::$SERVERROOT . '/data/');
         $file = \OC_Config::getValue('mount_file', $datadir . '/mount.json');
     }
     $options = 0;
     if (defined('JSON_PRETTY_PRINT')) {
         // only for PHP >= 5.4
         $options = JSON_PRETTY_PRINT;
     }
     $content = json_encode($data, $options);
     @file_put_contents($file, $content);
     @chmod($file, 0640);
 }
Ejemplo n.º 30
0
 /**
  * @brief delete a user
  * @param string $uid The username of the user to delete
  * @return bool
  *
  * Deletes a user
  */
 public static function deleteUser($uid)
 {
     $user = self::getManager()->get($uid);
     if ($user) {
         $result = $user->delete();
         // if delete was successful we clean-up the rest
         if ($result) {
             // We have to delete the user from all groups
             foreach (OC_Group::getUserGroups($uid) as $i) {
                 OC_Group::removeFromGroup($uid, $i);
             }
             // Delete the user's keys in preferences
             OC_Preferences::deleteUser($uid);
             // Delete user files in /data/
             $home = \OC_User::getHome($uid);
             OC_Helper::rmdirr($home);
             // Delete the users entry in the storage table
             \OC\Files\Cache\Storage::remove('home::' . $uid);
             \OC\Files\Cache\Storage::remove('local::' . $home . '/');
             // Remove it from the Cache
             self::getManager()->delete($uid);
         }
         return true;
     } else {
         return false;
     }
 }