예제 #1
0
 public function __construct($global = false)
 {
     $this->prefix = OC_Util::getInstanceId() . '/';
     if (!$global) {
         $this->prefix .= OC_User::getUser() . '/';
     }
 }
예제 #2
0
파일: office.php 프로젝트: loulancn/core
 /**
  * {@inheritDoc}
  */
 public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview)
 {
     $this->initCmd();
     if (is_null($this->cmd)) {
         return false;
     }
     $absPath = $fileview->toTmpFile($path);
     $tmpDir = \OC::$server->getTempManager()->getTempBaseDir();
     $defaultParameters = ' -env:UserInstallation=file://' . escapeshellarg($tmpDir . '/owncloud-' . \OC_Util::getInstanceId() . '/') . ' --headless --nologo --nofirststartwizard --invisible --norestore --convert-to pdf --outdir ';
     $clParameters = \OCP\Config::getSystemValue('preview_office_cl_parameters', $defaultParameters);
     $exec = $this->cmd . $clParameters . escapeshellarg($tmpDir) . ' ' . escapeshellarg($absPath);
     shell_exec($exec);
     //create imagick object from pdf
     $pdfPreview = null;
     try {
         list($dirname, , , $filename) = array_values(pathinfo($absPath));
         $pdfPreview = $dirname . '/' . $filename . '.pdf';
         $pdf = new \imagick($pdfPreview . '[0]');
         $pdf->setImageFormat('jpg');
     } catch (\Exception $e) {
         unlink($absPath);
         unlink($pdfPreview);
         \OCP\Util::writeLog('core', $e->getmessage(), \OCP\Util::ERROR);
         return false;
     }
     $image = new \OC_Image();
     $image->loadFromData($pdf);
     unlink($absPath);
     unlink($pdfPreview);
     if ($image->valid()) {
         $image->scaleDownToFit($maxX, $maxY);
         return $image;
     }
     return false;
 }
예제 #3
0
 public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview)
 {
     $this->initCmd();
     if (is_null($this->cmd)) {
         return false;
     }
     $absPath = $fileview->toTmpFile($path);
     $tmpDir = get_temp_dir();
     $defaultParameters = ' -env:UserInstallation=file://' . escapeshellarg($tmpDir . '/owncloud-' . \OC_Util::getInstanceId() . '/') . ' --headless --nologo --nofirststartwizard --invisible --norestore -convert-to pdf -outdir ';
     $clParameters = \OCP\Config::getSystemValue('preview_office_cl_parameters', $defaultParameters);
     $exec = $this->cmd . $clParameters . escapeshellarg($tmpDir) . ' ' . escapeshellarg($absPath);
     shell_exec($exec);
     //create imagick object from pdf
     try {
         $pdf = new \imagick($absPath . '.pdf' . '[0]');
         $pdf->setImageFormat('jpg');
     } catch (\Exception $e) {
         unlink($absPath);
         unlink($absPath . '.pdf');
         \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR);
         return false;
     }
     $image = new \OC_Image();
     $image->loadFromData($pdf);
     unlink($absPath);
     unlink($absPath . '.pdf');
     return $image->valid() ? $image : false;
 }
예제 #4
0
 protected static function getCacheDir()
 {
     $cache_dir = get_temp_dir() . '/owncloud-' . \OC_Util::getInstanceId() . '/';
     if (!is_dir($cache_dir)) {
         mkdir($cache_dir);
     }
     return $cache_dir;
 }
예제 #5
0
 /**
  * convert via openOffice hosted on the same server
  * @param string $input
  * @param string $targetFilter
  * @param string $targetExtension
  * @return string
  */
 protected static function convertLocal($input, $targetFilter, $targetExtension)
 {
     $infile = \OCP\Files::tmpFile();
     $outdir = \OCP\Files::tmpFolder();
     $cmd = Helper::findOpenOffice();
     $params = ' --headless --convert-to ' . $targetFilter . ' --outdir ' . escapeshellarg($outdir) . ' --writer ' . escapeshellarg($infile) . ' -env:UserInstallation=file://' . escapeshellarg(get_temp_dir() . '/owncloud-' . \OC_Util::getInstanceId() . '/');
     file_put_contents($infile, $input);
     shell_exec($cmd . $params);
     $output = file_get_contents($outdir . '/' . basename($infile) . '.' . $targetExtension);
     return $output;
 }
예제 #6
0
 public static function testConversion()
 {
     $targetFilter = 'odt:writer8';
     $targetExtension = 'odt';
     $input = file_get_contents(dirname(__DIR__) . self::TEST_DOC_PATH);
     $infile = \OC::$server->getTempManager()->getTemporaryFile();
     $outdir = \OC::$server->getTempManager()->getTemporaryFolder();
     $outfile = $outdir . '/' . basename($infile) . '.' . $targetExtension;
     $cmd = Helper::findOpenOffice();
     $params = ' --headless --convert-to ' . escapeshellarg($targetFilter) . ' --outdir ' . escapeshellarg($outdir) . ' --writer ' . escapeshellarg($infile) . ' -env:UserInstallation=file://' . escapeshellarg(get_temp_dir() . '/owncloud-' . \OC_Util::getInstanceId() . '/') . ' 2>&1';
     file_put_contents($infile, $input);
     $result = shell_exec($cmd . $params);
     $exists = file_exists($outfile);
     if (!$exists) {
         Helper::warnLog('Conversion test failed. Raw output:' . $result);
         return false;
     } else {
         unlink($outfile);
     }
     return true;
 }
예제 #7
0
파일: server.php 프로젝트: Combustible/core
 function __construct()
 {
     $this->registerService('ContactsManager', function ($c) {
         return new ContactsManager();
     });
     $this->registerService('Request', function ($c) {
         if (isset($c['urlParams'])) {
             $urlParams = $c['urlParams'];
         } else {
             $urlParams = array();
         }
         if (\OC::$server->getSession()->exists('requesttoken')) {
             $requestToken = \OC::$server->getSession()->get('requesttoken');
         } else {
             $requestToken = false;
         }
         if (defined('PHPUNIT_RUN') && PHPUNIT_RUN && in_array('fakeinput', stream_get_wrappers())) {
             $stream = 'fakeinput://data';
         } else {
             $stream = 'php://input';
         }
         return new Request(array('get' => $_GET, 'post' => $_POST, 'files' => $_FILES, 'server' => $_SERVER, 'env' => $_ENV, 'cookies' => $_COOKIE, 'method' => isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : null, 'urlParams' => $urlParams, 'requesttoken' => $requestToken), $stream);
     });
     $this->registerService('PreviewManager', function ($c) {
         return new PreviewManager();
     });
     $this->registerService('TagManager', function ($c) {
         $user = \OC_User::getUser();
         return new TagManager($user);
     });
     $this->registerService('RootFolder', function ($c) {
         // TODO: get user and user manager from container as well
         $user = \OC_User::getUser();
         /** @var $c SimpleContainer */
         $userManager = $c->query('UserManager');
         $user = $userManager->get($user);
         $manager = \OC\Files\Filesystem::getMountManager();
         $view = new View();
         return new Root($manager, $view, $user);
     });
     $this->registerService('UserManager', function ($c) {
         /**
          * @var SimpleContainer $c
          * @var \OC\AllConfig $config
          */
         $config = $c->query('AllConfig');
         return new \OC\User\Manager($config);
     });
     $this->registerService('GroupManager', function ($c) {
         /**
          * @var SimpleContainer $c
          * @var \OC\User\Manager $userManager
          */
         $userManager = $c->query('UserManager');
         return new \OC\Group\Manager($userManager);
     });
     $this->registerService('UserSession', function ($c) {
         /**
          * @var SimpleContainer $c
          * @var \OC\User\Manager $manager
          */
         $manager = $c->query('UserManager');
         $userSession = new \OC\User\Session($manager, new \OC\Session\Memory(''));
         $userSession->listen('\\OC\\User', 'preCreateUser', function ($uid, $password) {
             \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
         });
         $userSession->listen('\\OC\\User', 'postCreateUser', function ($user, $password) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
         });
         $userSession->listen('\\OC\\User', 'preDelete', function ($user) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
         });
         $userSession->listen('\\OC\\User', 'postDelete', function ($user) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
         });
         $userSession->listen('\\OC\\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
         });
         $userSession->listen('\\OC\\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
         });
         $userSession->listen('\\OC\\User', 'preLogin', function ($uid, $password) {
             \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
         });
         $userSession->listen('\\OC\\User', 'postLogin', function ($user, $password) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
         });
         $userSession->listen('\\OC\\User', 'logout', function () {
             \OC_Hook::emit('OC_User', 'logout', array());
         });
         return $userSession;
     });
     $this->registerService('NavigationManager', function ($c) {
         return new \OC\NavigationManager();
     });
     $this->registerService('AllConfig', function ($c) {
         return new \OC\AllConfig();
     });
     $this->registerService('AppConfig', function ($c) {
         return new \OC\AppConfig(\OC_DB::getConnection());
     });
     $this->registerService('L10NFactory', function ($c) {
         return new \OC\L10N\Factory();
     });
     $this->registerService('URLGenerator', function ($c) {
         /** @var $c SimpleContainer */
         $config = $c->query('AllConfig');
         return new \OC\URLGenerator($config);
     });
     $this->registerService('AppHelper', function ($c) {
         return new \OC\AppHelper();
     });
     $this->registerService('UserCache', function ($c) {
         return new UserCache();
     });
     $this->registerService('MemCacheFactory', function ($c) {
         $instanceId = \OC_Util::getInstanceId();
         return new \OC\Memcache\Factory($instanceId);
     });
     $this->registerService('ActivityManager', function ($c) {
         return new ActivityManager();
     });
     $this->registerService('AvatarManager', function ($c) {
         return new AvatarManager();
     });
     $this->registerService('Logger', function ($c) {
         /** @var $c SimpleContainer */
         $logClass = $c->query('AllConfig')->getSystemValue('log_type', 'owncloud');
         $logger = 'OC_Log_' . ucfirst($logClass);
         call_user_func(array($logger, 'init'));
         return new Log($logger);
     });
     $this->registerService('JobList', function ($c) {
         /**
          * @var Server $c
          */
         $config = $c->getConfig();
         return new \OC\BackgroundJob\JobList($c->getDatabaseConnection(), $config);
     });
     $this->registerService('Router', function ($c) {
         /**
          * @var Server $c
          */
         $cacheFactory = $c->getMemCacheFactory();
         if ($cacheFactory->isAvailable()) {
             $router = new \OC\Route\CachingRouter($cacheFactory->create('route'));
         } else {
             $router = new \OC\Route\Router();
         }
         return $router;
     });
     $this->registerService('Search', function ($c) {
         return new Search();
     });
     $this->registerService('SecureRandom', function ($c) {
         return new SecureRandom();
     });
     $this->registerService('Crypto', function ($c) {
         return new Crypto(\OC::$server->getConfig(), \OC::$server->getSecureRandom());
     });
     $this->registerService('Db', function ($c) {
         return new Db();
     });
 }
예제 #8
0
 function testGetInstanceIdGeneratesValidId()
 {
     \OC::$server->getConfig()->deleteSystemValue('instanceid');
     $instanceId = OC_Util::getInstanceId();
     $this->assertStringStartsWith('oc', $instanceId);
     $matchesRegex = preg_match('/^[a-z0-9]+$/', $instanceId);
     $this->assertSame(1, $matchesRegex);
 }
예제 #9
0
 /**
  * @param string $webRoot
  */
 public function __construct($webRoot)
 {
     parent::__construct();
     $this->webRoot = $webRoot;
     $this->registerService('ContactsManager', function ($c) {
         return new ContactsManager();
     });
     $this->registerService('PreviewManager', function (Server $c) {
         return new PreviewManager($c->getConfig());
     });
     $this->registerService('EncryptionManager', function (Server $c) {
         $view = new View();
         $util = new Encryption\Util($view, $c->getUserManager(), $c->getGroupManager(), $c->getConfig());
         return new Encryption\Manager($c->getConfig(), $c->getLogger(), $c->getL10N('core'), new View(), $util);
     });
     $this->registerService('EncryptionFileHelper', function (Server $c) {
         $util = new Encryption\Util(new View(), $c->getUserManager(), $c->getGroupManager(), $c->getConfig());
         return new Encryption\File($util);
     });
     $this->registerService('EncryptionKeyStorage', function (Server $c) {
         $view = new View();
         $util = new Encryption\Util($view, $c->getUserManager(), $c->getGroupManager(), $c->getConfig());
         return new Encryption\Keys\Storage($view, $util);
     });
     $this->registerService('TagMapper', function (Server $c) {
         return new TagMapper($c->getDatabaseConnection());
     });
     $this->registerService('TagManager', function (Server $c) {
         $tagMapper = $c->query('TagMapper');
         return new TagManager($tagMapper, $c->getUserSession());
     });
     $this->registerService('SystemTagManager', function (Server $c) {
         return new SystemTag\SystemTagManager($c->getDatabaseConnection());
     });
     $this->registerService('SystemTagObjectMapper', function (Server $c) {
         return new SystemTag\SystemTagObjectMapper($c->getDatabaseConnection(), $c->getSystemTagManager());
     });
     $this->registerService('RootFolder', function (Server $c) {
         // TODO: get user and user manager from container as well
         $user = \OC_User::getUser();
         /** @var $c SimpleContainer */
         $userManager = $c->query('UserManager');
         $user = $userManager->get($user);
         $manager = \OC\Files\Filesystem::getMountManager();
         $view = new View();
         $root = new Root($manager, $view, $user);
         $connector = new HookConnector($root, $view);
         $connector->viewToNode();
         return $root;
     });
     $this->registerService('UserManager', function (Server $c) {
         $config = $c->getConfig();
         return new \OC\User\Manager($config);
     });
     $this->registerService('GroupManager', function (Server $c) {
         $groupManager = new \OC\Group\Manager($this->getUserManager());
         $groupManager->listen('\\OC\\Group', 'preCreate', function ($gid) {
             \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
         });
         $groupManager->listen('\\OC\\Group', 'postCreate', function (\OC\Group\Group $gid) {
             \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
         });
         $groupManager->listen('\\OC\\Group', 'preDelete', function (\OC\Group\Group $group) {
             \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
         });
         $groupManager->listen('\\OC\\Group', 'postDelete', function (\OC\Group\Group $group) {
             \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
         });
         $groupManager->listen('\\OC\\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
             \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
         });
         $groupManager->listen('\\OC\\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
             \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
             //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
             \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
         });
         return $groupManager;
     });
     $this->registerService('UserSession', function (Server $c) {
         $manager = $c->getUserManager();
         $session = new \OC\Session\Memory('');
         $userSession = new \OC\User\Session($manager, $session);
         $userSession->listen('\\OC\\User', 'preCreateUser', function ($uid, $password) {
             \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
         });
         $userSession->listen('\\OC\\User', 'postCreateUser', function ($user, $password) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
         });
         $userSession->listen('\\OC\\User', 'preDelete', function ($user) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
         });
         $userSession->listen('\\OC\\User', 'postDelete', function ($user) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
         });
         $userSession->listen('\\OC\\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
         });
         $userSession->listen('\\OC\\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
         });
         $userSession->listen('\\OC\\User', 'preLogin', function ($uid, $password) {
             \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
         });
         $userSession->listen('\\OC\\User', 'postLogin', function ($user, $password) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
         });
         $userSession->listen('\\OC\\User', 'logout', function () {
             \OC_Hook::emit('OC_User', 'logout', array());
         });
         return $userSession;
     });
     $this->registerService('NavigationManager', function ($c) {
         return new \OC\NavigationManager();
     });
     $this->registerService('AllConfig', function (Server $c) {
         return new \OC\AllConfig($c->getSystemConfig());
     });
     $this->registerService('SystemConfig', function ($c) {
         return new \OC\SystemConfig();
     });
     $this->registerService('AppConfig', function ($c) {
         return new \OC\AppConfig(\OC_DB::getConnection());
     });
     $this->registerService('L10NFactory', function ($c) {
         return new \OC\L10N\Factory();
     });
     $this->registerService('URLGenerator', function (Server $c) {
         $config = $c->getConfig();
         $cacheFactory = $c->getMemCacheFactory();
         return new \OC\URLGenerator($config, $cacheFactory);
     });
     $this->registerService('AppHelper', function ($c) {
         return new \OC\AppHelper();
     });
     $this->registerService('UserCache', function ($c) {
         return new Cache\File();
     });
     $this->registerService('MemCacheFactory', function (Server $c) {
         $config = $c->getConfig();
         if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
             $v = \OC_App::getAppVersions();
             $v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php'));
             $version = implode(',', $v);
             $instanceId = \OC_Util::getInstanceId();
             $path = \OC::$SERVERROOT;
             $prefix = md5($instanceId . '-' . $version . '-' . $path);
             return new \OC\Memcache\Factory($prefix, $c->getLogger(), $config->getSystemValue('memcache.local', null), $config->getSystemValue('memcache.distributed', null), $config->getSystemValue('memcache.locking', null));
         }
         return new \OC\Memcache\Factory('', $c->getLogger(), '\\OC\\Memcache\\ArrayCache', '\\OC\\Memcache\\ArrayCache', '\\OC\\Memcache\\ArrayCache');
     });
     $this->registerService('ActivityManager', function (Server $c) {
         return new ActivityManager($c->getRequest(), $c->getUserSession(), $c->getConfig());
     });
     $this->registerService('AvatarManager', function (Server $c) {
         return new AvatarManager($c->getUserManager(), $c->getRootFolder(), $c->getL10N('lib'));
     });
     $this->registerService('Logger', function (Server $c) {
         $logClass = $c->query('AllConfig')->getSystemValue('log_type', 'owncloud');
         $logger = 'OC_Log_' . ucfirst($logClass);
         call_user_func(array($logger, 'init'));
         return new Log($logger);
     });
     $this->registerService('JobList', function (Server $c) {
         $config = $c->getConfig();
         return new \OC\BackgroundJob\JobList($c->getDatabaseConnection(), $config);
     });
     $this->registerService('Router', function (Server $c) {
         $cacheFactory = $c->getMemCacheFactory();
         $logger = $c->getLogger();
         if ($cacheFactory->isAvailable()) {
             $router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger);
         } else {
             $router = new \OC\Route\Router($logger);
         }
         return $router;
     });
     $this->registerService('Search', function ($c) {
         return new Search();
     });
     $this->registerService('SecureRandom', function ($c) {
         return new SecureRandom();
     });
     $this->registerService('Crypto', function (Server $c) {
         return new Crypto($c->getConfig(), $c->getSecureRandom());
     });
     $this->registerService('Hasher', function (Server $c) {
         return new Hasher($c->getConfig());
     });
     $this->registerService('DatabaseConnection', function (Server $c) {
         $factory = new \OC\DB\ConnectionFactory();
         $systemConfig = $c->getSystemConfig();
         $type = $systemConfig->getValue('dbtype', 'sqlite');
         if (!$factory->isValidType($type)) {
             throw new \OC\DatabaseException('Invalid database type');
         }
         $connectionParams = $factory->createConnectionParams($systemConfig);
         $connection = $factory->getConnection($type, $connectionParams);
         $connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
         return $connection;
     });
     $this->registerService('Db', function (Server $c) {
         return new Db($c->getDatabaseConnection());
     });
     $this->registerService('HTTPHelper', function (Server $c) {
         $config = $c->getConfig();
         return new HTTPHelper($config, $c->getHTTPClientService());
     });
     $this->registerService('HttpClientService', function (Server $c) {
         $user = \OC_User::getUser();
         $uid = $user ? $user : null;
         return new ClientService($c->getConfig(), new \OC\Security\CertificateManager($uid, new View(), $c->getConfig()));
     });
     $this->registerService('EventLogger', function (Server $c) {
         if ($c->getSystemConfig()->getValue('debug', false)) {
             return new EventLogger();
         } else {
             return new NullEventLogger();
         }
     });
     $this->registerService('QueryLogger', function (Server $c) {
         if ($c->getSystemConfig()->getValue('debug', false)) {
             return new QueryLogger();
         } else {
             return new NullQueryLogger();
         }
     });
     $this->registerService('TempManager', function (Server $c) {
         return new TempManager($c->getLogger(), $c->getConfig());
     });
     $this->registerService('AppManager', function (Server $c) {
         return new \OC\App\AppManager($c->getUserSession(), $c->getAppConfig(), $c->getGroupManager(), $c->getMemCacheFactory());
     });
     $this->registerService('DateTimeZone', function (Server $c) {
         return new DateTimeZone($c->getConfig(), $c->getSession());
     });
     $this->registerService('DateTimeFormatter', function (Server $c) {
         $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
         return new DateTimeFormatter($c->getDateTimeZone()->getTimeZone(), $c->getL10N('lib', $language));
     });
     $this->registerService('MountConfigManager', function () {
         $loader = \OC\Files\Filesystem::getLoader();
         return new \OC\Files\Config\MountProviderCollection($loader);
     });
     $this->registerService('IniWrapper', function ($c) {
         return new IniGetWrapper();
     });
     $this->registerService('AsyncCommandBus', function (Server $c) {
         $jobList = $c->getJobList();
         return new AsyncBus($jobList);
     });
     $this->registerService('TrustedDomainHelper', function ($c) {
         return new TrustedDomainHelper($this->getConfig());
     });
     $this->registerService('IntegrityCodeChecker', function (Server $c) {
         // IConfig and IAppManager requires a working database. This code
         // might however be called when ownCloud is not yet setup.
         if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
             $config = $c->getConfig();
             $appManager = $c->getAppManager();
         } else {
             $config = null;
             $appManager = null;
         }
         return new Checker(new EnvironmentHelper(), new FileAccessHelper(), new AppLocator(), $config, $c->getMemCacheFactory(), $appManager);
     });
     $this->registerService('Request', function ($c) {
         if (isset($this['urlParams'])) {
             $urlParams = $this['urlParams'];
         } else {
             $urlParams = [];
         }
         if ($this->getSession()->exists('requesttoken')) {
             $requestToken = $this->getSession()->get('requesttoken');
         } else {
             $requestToken = false;
         }
         if (defined('PHPUNIT_RUN') && PHPUNIT_RUN && in_array('fakeinput', stream_get_wrappers())) {
             $stream = 'fakeinput://data';
         } else {
             $stream = 'php://input';
         }
         return new Request(['get' => $_GET, 'post' => $_POST, 'files' => $_FILES, 'server' => $_SERVER, 'env' => $_ENV, 'cookies' => $_COOKIE, 'method' => isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : null, 'urlParams' => $urlParams, 'requesttoken' => $requestToken], $this->getSecureRandom(), $this->getConfig(), $stream);
     });
     $this->registerService('Mailer', function (Server $c) {
         return new Mailer($c->getConfig(), $c->getLogger(), new \OC_Defaults());
     });
     $this->registerService('OcsClient', function (Server $c) {
         return new OCSClient($this->getHTTPClientService(), $this->getConfig(), $this->getLogger());
     });
     $this->registerService('LockingProvider', function (Server $c) {
         if ($c->getConfig()->getSystemValue('filelocking.enabled', true) or defined('PHPUNIT_RUN') && PHPUNIT_RUN) {
             /** @var \OC\Memcache\Factory $memcacheFactory */
             $memcacheFactory = $c->getMemCacheFactory();
             $memcache = $memcacheFactory->createLocking('lock');
             if (!$memcache instanceof \OC\Memcache\NullCache) {
                 return new MemcacheLockingProvider($memcache);
             }
             return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory());
         }
         return new NoopLockingProvider();
     });
     $this->registerService('MountManager', function () {
         return new \OC\Files\Mount\Manager();
     });
     $this->registerService('MimeTypeDetector', function (Server $c) {
         return new \OC\Files\Type\Detection($c->getURLGenerator(), \OC::$SERVERROOT . '/config/', \OC::$SERVERROOT . '/resources/config/');
     });
     $this->registerService('MimeTypeLoader', function (Server $c) {
         return new \OC\Files\Type\Loader($c->getDatabaseConnection());
     });
     $this->registerService('NotificationManager', function () {
         return new Manager();
     });
     $this->registerService('CapabilitiesManager', function (Server $c) {
         $manager = new \OC\CapabilitiesManager();
         $manager->registerCapability(function () use($c) {
             return new \OC\OCS\CoreCapabilities($c->getConfig());
         });
         return $manager;
     });
     $this->registerService('CommentsManager', function (Server $c) {
         $config = $c->getConfig();
         $factoryClass = $config->getSystemValue('comments.managerFactory', '\\OC\\Comments\\ManagerFactory');
         /** @var \OCP\Comments\ICommentsManagerFactory $factory */
         $factory = new $factoryClass();
         return $factory->getManager();
     });
     $this->registerService('EventDispatcher', function () {
         return new EventDispatcher();
     });
     $this->registerService('CryptoWrapper', function (Server $c) {
         // FIXME: Instantiiated here due to cyclic dependency
         $request = new Request(['get' => $_GET, 'post' => $_POST, 'files' => $_FILES, 'server' => $_SERVER, 'env' => $_ENV, 'cookies' => $_COOKIE, 'method' => isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : null], new SecureRandom(), $c->getConfig());
         return new CryptoWrapper($c->getConfig(), $c->getCrypto(), $c->getSecureRandom(), $request);
     });
 }
예제 #10
0
 function testGetInstanceIdGeneratesValidId()
 {
     OC_Config::deleteKey('instanceid');
     $this->assertStringStartsWith('oc', OC_Util::getInstanceId());
 }
예제 #11
0
파일: node.php 프로젝트: evanjt/core
 /**
  * @return string|null
  */
 public function getFileId()
 {
     if ($this->info->getId()) {
         $instanceId = \OC_Util::getInstanceId();
         $id = sprintf('%08d', $this->info->getId());
         return $id . $instanceId;
     }
     return null;
 }
예제 #12
0
파일: base.php 프로젝트: krsvital/core
 public static function initSession()
 {
     // prevents javascript from accessing php session cookies
     ini_set('session.cookie_httponly', true);
     // set the cookie path to the ownCloud directory
     $cookie_path = OC::$WEBROOT ?: '/';
     ini_set('session.cookie_path', $cookie_path);
     // Let the session name be changed in the initSession Hook
     $sessionName = OC_Util::getInstanceId();
     try {
         // Allow session apps to create a custom session object
         $useCustomSession = false;
         $session = self::$server->getSession();
         OC_Hook::emit('OC', 'initSession', array('session' => &$session, 'sessionName' => &$sessionName, 'useCustomSession' => &$useCustomSession));
         if (!$useCustomSession) {
             // set the session name to the instance id - which is unique
             $session = new \OC\Session\Internal($sessionName);
         }
         $cryptoWrapper = \OC::$server->getSessionCryptoWrapper();
         $session = $cryptoWrapper->wrapSession($session);
         self::$server->setSession($session);
         // if session cant be started break with http 500 error
     } catch (Exception $e) {
         \OCP\Util::logException('base', $e);
         //show the user a detailed error page
         OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR);
         OC_Template::printExceptionErrorPage($e);
     }
     $sessionLifeTime = self::getSessionLifeTime();
     // regenerate session id periodically to avoid session fixation
     /**
      * @var \OCP\ISession $session
      */
     $session = self::$server->getSession();
     if (!$session->exists('SID_CREATED')) {
         $session->set('SID_CREATED', time());
     } else {
         if (time() - $session->get('SID_CREATED') > $sessionLifeTime / 2) {
             session_regenerate_id(true);
             $session->set('SID_CREATED', time());
         }
     }
     // session timeout
     if ($session->exists('LAST_ACTIVITY') && time() - $session->get('LAST_ACTIVITY') > $sessionLifeTime) {
         if (isset($_COOKIE[session_name()])) {
             setcookie(session_name(), '', time() - 42000, $cookie_path);
         }
         session_unset();
         session_destroy();
         session_start();
     }
     $session->set('LAST_ACTIVITY', time());
 }
예제 #13
0
 /**
  * @param string $webRoot
  */
 public function __construct($webRoot)
 {
     $this->webRoot = $webRoot;
     $this->registerService('ContactsManager', function ($c) {
         return new ContactsManager();
     });
     $this->registerService('PreviewManager', function (Server $c) {
         return new PreviewManager($c->getConfig());
     });
     $this->registerService('EncryptionManager', function (Server $c) {
         return new Encryption\Manager($c->getConfig(), $c->getLogger(), $c->getL10N('core'));
     });
     $this->registerService('EncryptionFileHelper', function (Server $c) {
         $util = new \OC\Encryption\Util(new \OC\Files\View(), $c->getUserManager(), $c->getGroupManager(), $c->getConfig());
         return new Encryption\File($util);
     });
     $this->registerService('EncryptionKeyStorage', function (Server $c) {
         $view = new \OC\Files\View();
         $util = new \OC\Encryption\Util($view, $c->getUserManager(), $c->getGroupManager(), $c->getConfig());
         return new Encryption\Keys\Storage($view, $util);
     });
     $this->registerService('TagMapper', function (Server $c) {
         return new TagMapper($c->getDatabaseConnection());
     });
     $this->registerService('TagManager', function (Server $c) {
         $tagMapper = $c->query('TagMapper');
         return new TagManager($tagMapper, $c->getUserSession());
     });
     $this->registerService('RootFolder', function (Server $c) {
         // TODO: get user and user manager from container as well
         $user = \OC_User::getUser();
         /** @var $c SimpleContainer */
         $userManager = $c->query('UserManager');
         $user = $userManager->get($user);
         $manager = \OC\Files\Filesystem::getMountManager();
         $view = new View();
         return new Root($manager, $view, $user);
     });
     $this->registerService('UserManager', function (Server $c) {
         $config = $c->getConfig();
         return new \OC\User\Manager($config);
     });
     $this->registerService('GroupManager', function (Server $c) {
         $groupManager = new \OC\Group\Manager($this->getUserManager());
         $groupManager->listen('\\OC\\Group', 'preCreate', function ($gid) {
             \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
         });
         $groupManager->listen('\\OC\\Group', 'postCreate', function (\OC\Group\Group $gid) {
             \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
         });
         $groupManager->listen('\\OC\\Group', 'preDelete', function (\OC\Group\Group $group) {
             \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
         });
         $groupManager->listen('\\OC\\Group', 'postDelete', function (\OC\Group\Group $group) {
             \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
         });
         $groupManager->listen('\\OC\\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
             \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
         });
         $groupManager->listen('\\OC\\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
             \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
         });
         return $groupManager;
     });
     $this->registerService('UserSession', function (Server $c) {
         $manager = $c->getUserManager();
         $userSession = new \OC\User\Session($manager, new \OC\Session\Memory(''));
         $userSession->listen('\\OC\\User', 'preCreateUser', function ($uid, $password) {
             \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
         });
         $userSession->listen('\\OC\\User', 'postCreateUser', function ($user, $password) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
         });
         $userSession->listen('\\OC\\User', 'preDelete', function ($user) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
         });
         $userSession->listen('\\OC\\User', 'postDelete', function ($user) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
         });
         $userSession->listen('\\OC\\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
         });
         $userSession->listen('\\OC\\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
         });
         $userSession->listen('\\OC\\User', 'preLogin', function ($uid, $password) {
             \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
         });
         $userSession->listen('\\OC\\User', 'postLogin', function ($user, $password) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
         });
         $userSession->listen('\\OC\\User', 'logout', function () {
             \OC_Hook::emit('OC_User', 'logout', array());
         });
         return $userSession;
     });
     $this->registerService('NavigationManager', function ($c) {
         return new \OC\NavigationManager();
     });
     $this->registerService('AllConfig', function (Server $c) {
         return new \OC\AllConfig($c->getSystemConfig());
     });
     $this->registerService('SystemConfig', function ($c) {
         return new \OC\SystemConfig();
     });
     $this->registerService('AppConfig', function ($c) {
         return new \OC\AppConfig(\OC_DB::getConnection());
     });
     $this->registerService('L10NFactory', function ($c) {
         return new \OC\L10N\Factory();
     });
     $this->registerService('URLGenerator', function (Server $c) {
         $config = $c->getConfig();
         $cacheFactory = $c->getMemCacheFactory();
         return new \OC\URLGenerator($config, $cacheFactory);
     });
     $this->registerService('AppHelper', function ($c) {
         return new \OC\AppHelper();
     });
     $this->registerService('UserCache', function ($c) {
         return new Cache\File();
     });
     $this->registerService('MemCacheFactory', function (Server $c) {
         $config = $c->getConfig();
         if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
             $v = \OC_App::getAppVersions();
             $v['core'] = implode('.', \OC_Util::getVersion());
             $version = implode(',', $v);
             $instanceId = \OC_Util::getInstanceId();
             $path = \OC::$SERVERROOT;
             $prefix = md5($instanceId . '-' . $version . '-' . $path);
             return new \OC\Memcache\Factory($prefix, $config->getSystemValue('memcache.local', null), $config->getSystemValue('memcache.distributed', null), $config->getSystemValue('memcache.locking', null));
         }
         return new \OC\Memcache\Factory('', new ArrayCache(), new ArrayCache(), new ArrayCache());
     });
     $this->registerService('ActivityManager', function (Server $c) {
         return new ActivityManager($c->getRequest(), $c->getUserSession(), $c->getConfig());
     });
     $this->registerService('AvatarManager', function ($c) {
         return new AvatarManager();
     });
     $this->registerService('Logger', function (Server $c) {
         $logClass = $c->query('AllConfig')->getSystemValue('log_type', 'owncloud');
         $logger = 'OC_Log_' . ucfirst($logClass);
         call_user_func(array($logger, 'init'));
         return new Log($logger);
     });
     $this->registerService('JobList', function (Server $c) {
         $config = $c->getConfig();
         return new \OC\BackgroundJob\JobList($c->getDatabaseConnection(), $config);
     });
     $this->registerService('Router', function (Server $c) {
         $cacheFactory = $c->getMemCacheFactory();
         if ($cacheFactory->isAvailable()) {
             $router = new \OC\Route\CachingRouter($cacheFactory->create('route'));
         } else {
             $router = new \OC\Route\Router();
         }
         return $router;
     });
     $this->registerService('Search', function ($c) {
         return new Search();
     });
     $this->registerService('SecureRandom', function ($c) {
         return new SecureRandom();
     });
     $this->registerService('Crypto', function (Server $c) {
         return new Crypto($c->getConfig(), $c->getSecureRandom());
     });
     $this->registerService('Hasher', function (Server $c) {
         return new Hasher($c->getConfig());
     });
     $this->registerService('DatabaseConnection', function (Server $c) {
         $factory = new \OC\DB\ConnectionFactory();
         $systemConfig = $c->getSystemConfig();
         $type = $systemConfig->getValue('dbtype', 'sqlite');
         if (!$factory->isValidType($type)) {
             throw new \OC\DatabaseException('Invalid database type');
         }
         $connectionParams = $factory->createConnectionParams($systemConfig);
         $connection = $factory->getConnection($type, $connectionParams);
         $connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
         return $connection;
     });
     $this->registerService('Db', function (Server $c) {
         return new Db($c->getDatabaseConnection());
     });
     $this->registerService('HTTPHelper', function (Server $c) {
         $config = $c->getConfig();
         return new HTTPHelper($config, $c->getHTTPClientService());
     });
     $this->registerService('HttpClientService', function (Server $c) {
         $user = \OC_User::getUser();
         $uid = $user ? $user : null;
         return new ClientService($c->getConfig(), new \OC\Security\CertificateManager($uid, new \OC\Files\View()));
     });
     $this->registerService('EventLogger', function (Server $c) {
         if (defined('DEBUG') and DEBUG) {
             return new EventLogger();
         } else {
             return new NullEventLogger();
         }
     });
     $this->registerService('QueryLogger', function ($c) {
         if (defined('DEBUG') and DEBUG) {
             return new QueryLogger();
         } else {
             return new NullQueryLogger();
         }
     });
     $this->registerService('TempManager', function (Server $c) {
         return new TempManager(get_temp_dir(), $c->getLogger());
     });
     $this->registerService('AppManager', function (Server $c) {
         return new \OC\App\AppManager($c->getUserSession(), $c->getAppConfig(), $c->getGroupManager(), $c->getMemCacheFactory());
     });
     $this->registerService('DateTimeZone', function (Server $c) {
         return new DateTimeZone($c->getConfig(), $c->getSession());
     });
     $this->registerService('DateTimeFormatter', function (Server $c) {
         $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
         return new DateTimeFormatter($c->getDateTimeZone()->getTimeZone(), $c->getL10N('lib', $language));
     });
     $this->registerService('MountConfigManager', function () {
         $loader = \OC\Files\Filesystem::getLoader();
         return new \OC\Files\Config\MountProviderCollection($loader);
     });
     $this->registerService('IniWrapper', function ($c) {
         return new IniGetWrapper();
     });
     $this->registerService('AsyncCommandBus', function (Server $c) {
         $jobList = $c->getJobList();
         return new AsyncBus($jobList);
     });
     $this->registerService('TrustedDomainHelper', function ($c) {
         return new TrustedDomainHelper($this->getConfig());
     });
     $this->registerService('Request', function ($c) {
         if (isset($this['urlParams'])) {
             $urlParams = $this['urlParams'];
         } else {
             $urlParams = [];
         }
         if ($this->getSession()->exists('requesttoken')) {
             $requestToken = $this->getSession()->get('requesttoken');
         } else {
             $requestToken = false;
         }
         if (defined('PHPUNIT_RUN') && PHPUNIT_RUN && in_array('fakeinput', stream_get_wrappers())) {
             $stream = 'fakeinput://data';
         } else {
             $stream = 'php://input';
         }
         return new Request(['get' => $_GET, 'post' => $_POST, 'files' => $_FILES, 'server' => $_SERVER, 'env' => $_ENV, 'cookies' => $_COOKIE, 'method' => isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : null, 'urlParams' => $urlParams, 'requesttoken' => $requestToken], $this->getSecureRandom(), $this->getConfig(), $stream);
     });
     $this->registerService('Mailer', function (Server $c) {
         return new Mailer($c->getConfig(), $c->getLogger(), new \OC_Defaults());
     });
     $this->registerService('OcsClient', function (Server $c) {
         return new OCSClient($this->getHTTPClientService(), $this->getConfig(), $this->getLogger());
     });
     $this->registerService('LockingProvider', function (Server $c) {
         if ($c->getConfig()->getSystemValue('filelocking.enabled', false) or defined('PHPUNIT_RUN') && PHPUNIT_RUN) {
             /** @var \OC\Memcache\Factory $memcacheFactory */
             $memcacheFactory = $c->getMemCacheFactory();
             $memcache = $memcacheFactory->createLocking('lock');
             if (!$memcache instanceof \OC\Memcache\NullCache) {
                 return new MemcacheLockingProvider($memcache);
             }
             throw new HintException('File locking is enabled but the locking cache class was not found', 'Please check the "memcache.locking" setting and make sure the matching PHP module is installed and enabled');
         }
         return new NoopLockingProvider();
     });
 }
예제 #14
0
 public static function initSession()
 {
     // prevents javascript from accessing php session cookies
     ini_set('session.cookie_httponly', '1;');
     // set the cookie path to the ownCloud directory
     $cookie_path = OC::$WEBROOT ?: '/';
     ini_set('session.cookie_path', $cookie_path);
     //set the session object to a dummy session so code relying on the session existing still works
     self::$session = new \OC\Session\Memory('');
     try {
         // set the session name to the instance id - which is unique
         self::$session = new \OC\Session\Internal(OC_Util::getInstanceId());
         // if session cant be started break with http 500 error
     } catch (Exception $e) {
         //show the user a detailed error page
         OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR);
         OC_Template::printExceptionErrorPage($e);
     }
     $sessionLifeTime = self::getSessionLifeTime();
     // regenerate session id periodically to avoid session fixation
     if (!self::$session->exists('SID_CREATED')) {
         self::$session->set('SID_CREATED', time());
     } else {
         if (time() - self::$session->get('SID_CREATED') > $sessionLifeTime / 2) {
             session_regenerate_id(true);
             self::$session->set('SID_CREATED', time());
         }
     }
     // session timeout
     if (self::$session->exists('LAST_ACTIVITY') && time() - self::$session->get('LAST_ACTIVITY') > $sessionLifeTime) {
         if (isset($_COOKIE[session_name()])) {
             setcookie(session_name(), '', time() - 42000, $cookie_path);
         }
         session_unset();
         session_destroy();
         session_start();
     }
     self::$session->set('LAST_ACTIVITY', time());
 }
예제 #15
0
 public static function initSession()
 {
     // prevents javascript from accessing php session cookies
     ini_set('session.cookie_httponly', '1;');
     // set the session name to the instance id - which is unique
     session_name(OC_Util::getInstanceId());
     // if session cant be started break with http 500 error
     if (session_start() === false) {
         OC_Log::write('core', 'Session could not be initialized', OC_Log::ERROR);
         header('HTTP/1.1 500 Internal Server Error');
         OC_Util::addStyle("styles");
         $error = 'Session could not be initialized. Please contact your ';
         $error .= 'system administrator';
         $tmpl = new OC_Template('', 'error', 'guest');
         $tmpl->assign('errors', array(1 => array('error' => $error)));
         $tmpl->printPage();
         exit;
     }
     $sessionLifeTime = self::getSessionLifeTime();
     // regenerate session id periodically to avoid session fixation
     if (!isset($_SESSION['SID_CREATED'])) {
         $_SESSION['SID_CREATED'] = time();
     } else {
         if (time() - $_SESSION['SID_CREATED'] > $sessionLifeTime / 2) {
             session_regenerate_id(true);
             $_SESSION['SID_CREATED'] = time();
         }
     }
     // session timeout
     if (isset($_SESSION['LAST_ACTIVITY']) && time() - $_SESSION['LAST_ACTIVITY'] > $sessionLifeTime) {
         if (isset($_COOKIE[session_name()])) {
             setcookie(session_name(), '', time() - 42000, '/');
         }
         session_unset();
         session_destroy();
         session_start();
     }
     $_SESSION['LAST_ACTIVITY'] = time();
 }
예제 #16
0
 /**
  * @param string $prefix
  */
 public function __construct($prefix = '')
 {
     $this->prefix = \OC_Util::getInstanceId() . '/' . $prefix;
 }
예제 #17
0
 protected function getCacheDir()
 {
     return get_temp_dir() . '/owncloud-' . \OC_Util::getInstanceId() . '/';
 }
예제 #18
0
 /**
  * @param string $webRoot
  */
 function __construct($webRoot)
 {
     $this->webRoot = $webRoot;
     $this->registerService('ContactsManager', function ($c) {
         return new ContactsManager();
     });
     $this->registerService('Request', function (Server $c) {
         if (isset($c['urlParams'])) {
             $urlParams = $c['urlParams'];
         } else {
             $urlParams = array();
         }
         if ($c->getSession()->exists('requesttoken')) {
             $requestToken = $c->getSession()->get('requesttoken');
         } else {
             $requestToken = false;
         }
         if (defined('PHPUNIT_RUN') && PHPUNIT_RUN && in_array('fakeinput', stream_get_wrappers())) {
             $stream = 'fakeinput://data';
         } else {
             $stream = 'php://input';
         }
         return new Request(array('get' => $_GET, 'post' => $_POST, 'files' => $_FILES, 'server' => $_SERVER, 'env' => $_ENV, 'cookies' => $_COOKIE, 'method' => isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : null, 'urlParams' => $urlParams, 'requesttoken' => $requestToken), $stream);
     });
     $this->registerService('PreviewManager', function ($c) {
         return new PreviewManager();
     });
     $this->registerService('TagMapper', function (Server $c) {
         return new TagMapper($c->getDb());
     });
     $this->registerService('TagManager', function (Server $c) {
         $tagMapper = $c->query('TagMapper');
         return new TagManager($tagMapper, $c->getUserSession());
     });
     $this->registerService('RootFolder', function (Server $c) {
         // TODO: get user and user manager from container as well
         $user = \OC_User::getUser();
         /** @var $c SimpleContainer */
         $userManager = $c->query('UserManager');
         $user = $userManager->get($user);
         $manager = \OC\Files\Filesystem::getMountManager();
         $view = new View();
         return new Root($manager, $view, $user);
     });
     $this->registerService('UserManager', function (Server $c) {
         $config = $c->getConfig();
         return new \OC\User\Manager($config);
     });
     $this->registerService('GroupManager', function (Server $c) {
         $groupManager = new \OC\Group\Manager($this->getUserManager());
         $groupManager->listen('\\OC\\Group', 'preCreate', function ($gid) {
             \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
         });
         $groupManager->listen('\\OC\\Group', 'postCreate', function (\OC\Group\Group $gid) {
             \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
         });
         $groupManager->listen('\\OC\\Group', 'preDelete', function (\OC\Group\Group $group) {
             \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
         });
         $groupManager->listen('\\OC\\Group', 'postDelete', function (\OC\Group\Group $group) {
             \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
         });
         $groupManager->listen('\\OC\\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
             \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
         });
         $groupManager->listen('\\OC\\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
             \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
         });
         return $groupManager;
     });
     $this->registerService('UserSession', function (Server $c) {
         $manager = $c->getUserManager();
         $userSession = new \OC\User\Session($manager, new \OC\Session\Memory(''));
         $userSession->listen('\\OC\\User', 'preCreateUser', function ($uid, $password) {
             \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
         });
         $userSession->listen('\\OC\\User', 'postCreateUser', function ($user, $password) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
         });
         $userSession->listen('\\OC\\User', 'preDelete', function ($user) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
         });
         $userSession->listen('\\OC\\User', 'postDelete', function ($user) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
         });
         $userSession->listen('\\OC\\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
         });
         $userSession->listen('\\OC\\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
         });
         $userSession->listen('\\OC\\User', 'preLogin', function ($uid, $password) {
             \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
         });
         $userSession->listen('\\OC\\User', 'postLogin', function ($user, $password) {
             /** @var $user \OC\User\User */
             \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
         });
         $userSession->listen('\\OC\\User', 'logout', function () {
             \OC_Hook::emit('OC_User', 'logout', array());
         });
         return $userSession;
     });
     $this->registerService('NavigationManager', function ($c) {
         return new \OC\NavigationManager();
     });
     $this->registerService('AllConfig', function (Server $c) {
         return new \OC\AllConfig($c->getSystemConfig());
     });
     $this->registerService('SystemConfig', function ($c) {
         return new \OC\SystemConfig();
     });
     $this->registerService('AppConfig', function ($c) {
         return new \OC\AppConfig(\OC_DB::getConnection());
     });
     $this->registerService('L10NFactory', function ($c) {
         return new \OC\L10N\Factory();
     });
     $this->registerService('URLGenerator', function (Server $c) {
         $config = $c->getConfig();
         return new \OC\URLGenerator($config);
     });
     $this->registerService('AppHelper', function ($c) {
         return new \OC\AppHelper();
     });
     $this->registerService('UserCache', function ($c) {
         return new UserCache();
     });
     $this->registerService('MemCacheFactory', function ($c) {
         $instanceId = \OC_Util::getInstanceId();
         return new \OC\Memcache\Factory($instanceId);
     });
     $this->registerService('RedisSession', function (Server $c) {
         return new \OC\Session\redisSession($c->getSystemConfig()->getValue('redis'));
     });
     $this->registerService('ActivityManager', function ($c) {
         return new ActivityManager();
     });
     $this->registerService('AvatarManager', function ($c) {
         return new AvatarManager();
     });
     $this->registerService('Logger', function (Server $c) {
         $logClass = $c->query('AllConfig')->getSystemValue('log_type', 'owncloud');
         $logger = 'OC_Log_' . ucfirst($logClass);
         call_user_func(array($logger, 'init'));
         return new Log($logger);
     });
     $this->registerService('JobList', function (Server $c) {
         $config = $c->getConfig();
         return new \OC\BackgroundJob\JobList($c->getDatabaseConnection(), $config);
     });
     $this->registerService('Router', function (Server $c) {
         $cacheFactory = $c->getMemCacheFactory();
         if ($cacheFactory->isAvailable()) {
             $router = new \OC\Route\CachingRouter($cacheFactory->create('route'));
         } else {
             $router = new \OC\Route\Router();
         }
         return $router;
     });
     $this->registerService('Search', function ($c) {
         return new Search();
     });
     $this->registerService('SecureRandom', function ($c) {
         return new SecureRandom();
     });
     $this->registerService('Crypto', function (Server $c) {
         return new Crypto($c->getConfig(), $c->getSecureRandom());
     });
     $this->registerService('Hasher', function (Server $c) {
         return new Hasher($c->getConfig());
     });
     $this->registerService('DatabaseConnection', function (Server $c) {
         $factory = new \OC\DB\ConnectionFactory();
         $systemConfig = $c->getSystemConfig();
         $type = $systemConfig->getValue('dbtype', 'sqlite');
         if (!$factory->isValidType($type)) {
             throw new \OC\DatabaseException('Invalid database type');
         }
         $connectionParams = $factory->createConnectionParams($systemConfig);
         $connection = $factory->getConnection($type, $connectionParams);
         $connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
         return $connection;
     });
     $this->registerService('Db', function (Server $c) {
         return new Db($c->getDatabaseConnection());
     });
     $this->registerService('HTTPHelper', function (Server $c) {
         $config = $c->getConfig();
         $user = $c->getUserSession()->getUser();
         $uid = $user ? $user->getUID() : null;
         return new HTTPHelper($config, new \OC\Security\CertificateManager($uid, new \OC\Files\View()));
     });
     $this->registerService('EventLogger', function (Server $c) {
         if (defined('DEBUG') and DEBUG) {
             return new EventLogger();
         } else {
             return new NullEventLogger();
         }
     });
     $this->registerService('QueryLogger', function ($c) {
         if (defined('DEBUG') and DEBUG) {
             return new QueryLogger();
         } else {
             return new NullQueryLogger();
         }
     });
     $this->registerService('TempManager', function (Server $c) {
         return new TempManager(get_temp_dir(), $c->getLogger());
     });
     $this->registerService('AppManager', function (Server $c) {
         $userSession = $c->getUserSession();
         $appConfig = $c->getAppConfig();
         $groupManager = $c->getGroupManager();
         return new \OC\App\AppManager($userSession, $appConfig, $groupManager);
     });
     $this->registerService('DateTimeZone', function (Server $c) {
         return new DateTimeZone($c->getConfig(), $c->getSession());
     });
     $this->registerService('DateTimeFormatter', function (Server $c) {
         $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
         return new DateTimeFormatter($c->getDateTimeZone()->getTimeZone(), $c->getL10N('lib', $language));
     });
     $this->registerService('MountConfigManager', function () {
         $loader = \OC\Files\Filesystem::getLoader();
         return new \OC\Files\Config\MountProviderCollection($loader);
     });
     $this->registerService('IniWrapper', function ($c) {
         return new IniGetWrapper();
     });
 }
예제 #19
0
파일: util.php 프로젝트: kebenxiaoming/core
 function testGetInstanceIdGeneratesValidId()
 {
     OC_Config::deleteKey('instanceid');
     $instanceId = OC_Util::getInstanceId();
     $this->assertStringStartsWith('oc', $instanceId);
     $matchesRegex = preg_match('/^[a-z0-9]+$/', $instanceId);
     $this->assertSame(1, $matchesRegex);
 }
예제 #20
0
파일: node.php 프로젝트: hjimmy/owncloud
 /**
  * @return mixed
  */
 public function getFileId()
 {
     $this->getFileinfoCache();
     if (isset($this->fileinfo_cache['fileid'])) {
         $instanceId = OC_Util::getInstanceId();
         $id = sprintf('%08d', $this->fileinfo_cache['fileid']);
         return $id . $instanceId;
     }
     return null;
 }