コード例 #1
0
ファイル: util.php プロジェクト: droiter/openwrt-on-android
 /**
  * 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 !== \OC\Files\SPACE_UNLIMITED) {
                         return new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => $quota, 'root' => 'files'));
                     }
                 }
             }
             return $storage;
         });
         $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);
         //trigger creation of user home and /files folder
         \OC::$server->getUserFolder($user);
         OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $userDir));
     }
     return true;
 }
コード例 #2
0
ファイル: update.php プロジェクト: WYSAC/oregon-owncloud
/**
 * update script for the removal of the logical "Shared" folder, we create physical "Shared" folder and
 * update the users file_target so that it doesn't make any difference for the user
 * @note parameters are just for testing, please ignore them
 */
function removeSharedFolder($mkdirs = true, $chunkSize = 99)
{
    $query = OCP\DB::prepare('SELECT * FROM `*PREFIX*share`');
    $result = $query->execute();
    $view = new \OC\Files\View('/');
    $users = array();
    $shares = array();
    //we need to set up user backends
    OC_User::useBackend(new OC_User_Database());
    OC_Group::useBackend(new OC_Group_Database());
    OC_App::loadApps(array('authentication'));
    //we need to set up user backends, otherwise creating the shares will fail with "because user does not exist"
    while ($row = $result->fetchRow()) {
        //collect all user shares
        if ((int) $row['share_type'] === 0 && ($row['item_type'] === 'file' || $row['item_type'] === 'folder')) {
            $users[] = $row['share_with'];
            $shares[$row['id']] = $row['file_target'];
        } else {
            if ((int) $row['share_type'] === 1 && ($row['item_type'] === 'file' || $row['item_type'] === 'folder')) {
                //collect all group shares
                $users = array_merge($users, \OC_group::usersInGroup($row['share_with']));
                $shares[$row['id']] = $row['file_target'];
            } else {
                if ((int) $row['share_type'] === 2) {
                    $shares[$row['id']] = $row['file_target'];
                }
            }
        }
    }
    $unique_users = array_unique($users);
    if (!empty($unique_users) && !empty($shares)) {
        // create folder Shared for each user
        if ($mkdirs) {
            foreach ($unique_users as $user) {
                \OC\Files\Filesystem::initMountPoints($user);
                if (!$view->file_exists('/' . $user . '/files/Shared')) {
                    $view->mkdir('/' . $user . '/files/Shared');
                }
            }
        }
        $chunkedShareList = array_chunk($shares, $chunkSize, true);
        $connection = \OC_DB::getConnection();
        foreach ($chunkedShareList as $subList) {
            $statement = "UPDATE `*PREFIX*share` SET `file_target` = CASE `id` ";
            //update share table
            $ids = implode(',', array_keys($subList));
            foreach ($subList as $id => $target) {
                $statement .= "WHEN " . $connection->quote($id, \PDO::PARAM_INT) . " THEN " . $connection->quote('/Shared' . $target, \PDO::PARAM_STR);
            }
            $statement .= ' END WHERE `id` IN (' . $ids . ')';
            $query = OCP\DB::prepare($statement);
            $query->execute(array());
        }
        // set config to keep the Shared folder as the default location for new shares
        \OCA\Files_Sharing\Helper::setShareFolder('/Shared');
    }
}
コード例 #3
0
ファイル: util.php プロジェクト: omusico/isle-web-framework
 /**
  * @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;
 }
コード例 #4
0
 /**
  * prepares everything for the test run. Includes loading ownCloud and
  * the LDAP backend, as well as getting information about toxiproxy.
  * Also creates an instance of the LDAP class, the testee
  *
  * @throws Exception
  */
 public function setUp()
 {
     require_once __DIR__ . '/../../../../lib/base.php';
     \OC_App::loadApps('user_ldap');
     $ch = $this->getCurl();
     $proxyInfoJson = curl_exec($ch);
     $this->checkCurlResult($ch, $proxyInfoJson);
     $proxyInfo = json_decode($proxyInfoJson, true);
     $this->originalProxyState = $proxyInfo['enabled'];
     $this->ldapHost = 'ldap://' . $proxyInfo['listen'];
     // contains port as well
     $this->ldap = new LDAP();
 }
コード例 #5
0
ファイル: scan.php プロジェクト: CDN-Sparks/owncloud
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     \OC_App::loadApps('authentication');
     if ($input->getOption('all')) {
         $users = $this->userManager->search('');
     } else {
         $users = $input->getArgument('user_id');
     }
     foreach ($users as $user) {
         if (is_object($user)) {
             $user = $user->getUID();
         }
         $this->scanFiles($user, $output);
     }
 }
コード例 #6
0
ファイル: util.php プロジェクト: ryanshoover/core
 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_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, $user);
         $quotaProxy = new OC_FileProxy_Quota();
         $fileOperationProxy = new OC_FileProxy_FileOperations();
         OC_FileProxy::register($quotaProxy);
         OC_FileProxy::register($fileOperationProxy);
         // Load personal mount config
         self::loadUserMountPoints($user);
         OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $user_dir));
     }
 }
コード例 #7
0
ファイル: base.php プロジェクト: GitHubUser4234/core
 /**
  * Handle the request
  */
 public static function handleRequest()
 {
     \OC::$server->getEventLogger()->start('handle_request', 'Handle request');
     $systemConfig = \OC::$server->getSystemConfig();
     // load all the classpaths from the enabled apps so they are available
     // in the routing files of each app
     OC::loadAppClassPaths();
     // Check if ownCloud is installed or in maintenance (update) mode
     if (!$systemConfig->getValue('installed', false)) {
         \OC::$server->getSession()->clear();
         $setupHelper = new OC\Setup(\OC::$server->getConfig(), \OC::$server->getIniWrapper(), \OC::$server->getL10N('lib'), new \OC_Defaults(), \OC::$server->getLogger(), \OC::$server->getSecureRandom());
         $controller = new OC\Core\Controller\SetupController($setupHelper);
         $controller->run($_POST);
         exit;
     }
     $request = \OC::$server->getRequest();
     // Check if requested URL matches 'index.php/occ'
     $isOccControllerRequested = preg_match('|/index\\.php$|', $request->getScriptName()) === 1 && strpos($request->getPathInfo(), '/occ/') === 0;
     $requestPath = $request->getRawPathInfo();
     if (substr($requestPath, -3) !== '.js') {
         // we need these files during the upgrade
         self::checkMaintenanceMode($request);
         $needUpgrade = self::checkUpgrade(!$isOccControllerRequested);
     }
     // emergency app disabling
     if ($requestPath === '/disableapp' && $request->getMethod() === 'POST' && (string) $request->getParam('appid') !== '') {
         \OCP\JSON::callCheck();
         \OCP\JSON::checkAdminUser();
         $appId = (string) $request->getParam('appid');
         $appId = \OC_App::cleanAppId($appId);
         \OC_App::disable($appId);
         \OC_JSON::success();
         exit;
     }
     try {
         // Always load authentication apps
         OC_App::loadApps(['authentication']);
     } catch (\OC\NeedsUpdateException $e) {
         if ($isOccControllerRequested && $needUpgrade) {
             OC::$server->getRouter()->match(\OC::$server->getRequest()->getRawPathInfo());
             return;
         }
         throw $e;
     }
     // Load minimum set of apps
     if (!self::checkUpgrade(false) && !$systemConfig->getValue('maintenance', false)) {
         // For logged-in users: Load everything
         if (OC_User::isLoggedIn()) {
             OC_App::loadApps();
         } else {
             // For guests: Load only filesystem and logging
             OC_App::loadApps(array('filesystem', 'logging'));
             self::handleLogin($request);
         }
     }
     if (!self::$CLI) {
         try {
             if (!$systemConfig->getValue('maintenance', false) && !self::checkUpgrade(false)) {
                 OC_App::loadApps(array('filesystem', 'logging'));
                 OC_App::loadApps();
             }
             self::checkSingleUserMode();
             OC_Util::setupFS();
             OC::$server->getRouter()->match(\OC::$server->getRequest()->getRawPathInfo());
             return;
         } catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) {
             //header('HTTP/1.0 404 Not Found');
         } catch (Symfony\Component\Routing\Exception\MethodNotAllowedException $e) {
             OC_Response::setStatus(405);
             return;
         }
     }
     // Handle WebDAV
     if ($_SERVER['REQUEST_METHOD'] == 'PROPFIND') {
         // not allowed any more to prevent people
         // mounting this root directly.
         // Users need to mount remote.php/webdav instead.
         header('HTTP/1.1 405 Method Not Allowed');
         header('Status: 405 Method Not Allowed');
         return;
     }
     // Someone is logged in
     if (OC_User::isLoggedIn()) {
         OC_App::loadApps();
         OC_User::setupBackends();
         OC_Util::setupFS();
         // FIXME
         // Redirect to default application
         OC_Util::redirectToDefaultPage();
     } else {
         // Not handled and not logged in
         header('Location: ' . \OC::$server->getURLGenerator()->linkToRouteAbsolute('core.login.showLoginForm'));
     }
 }
コード例 #8
0
ファイル: base.php プロジェクト: pinoniq/core
 /**
  * Tries to login a user using the formbased authentication
  * @return bool|void
  */
 protected static function tryFormLogin()
 {
     if (!isset($_POST["user"]) || !isset($_POST['password'])) {
         return false;
     }
     OC_JSON::callCheck();
     OC_App::loadApps();
     //setup extra user backends
     OC_User::setupBackends();
     if (OC_User::login($_POST["user"], $_POST["password"])) {
         // setting up the time zone
         if (isset($_POST['timezone-offset'])) {
             self::$server->getSession()->set('timezone', $_POST['timezone-offset']);
         }
         $userid = OC_User::getUser();
         self::cleanupLoginTokens($userid);
         if (!empty($_POST["remember_login"])) {
             if (defined("DEBUG") && DEBUG) {
                 OC_Log::write('core', 'Setting remember login to cookie', OC_Log::DEBUG);
             }
             $token = \OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate(32);
             OC_Preferences::setValue($userid, 'login_token', $token, time());
             OC_User::setMagicInCookie($userid, $token);
         } else {
             OC_User::unsetMagicInCookie();
         }
         OC_Util::redirectToDefaultPage();
         exit;
     }
     return true;
 }
コード例 #9
0
 public static function init()
 {
     // register autoloader
     spl_autoload_register(array('OC', 'autoload'));
     setlocale(LC_ALL, 'en_US.UTF-8');
     // set some stuff
     //ob_start();
     error_reporting(E_ALL | E_STRICT);
     if (defined('DEBUG') && DEBUG) {
         ini_set('display_errors', 1);
     }
     date_default_timezone_set('UTC');
     ini_set('arg_separator.output', '&');
     // try to switch magic quotes off.
     if (function_exists('set_magic_quotes_runtime')) {
         @set_magic_quotes_runtime(false);
     }
     //try to configure php to enable big file uploads.
     //this doesn´t work always depending on the webserver and php configuration.
     //Let´s try to overwrite some defaults anyways
     //try to set the maximum execution time to 60min
     @set_time_limit(3600);
     @ini_set('max_execution_time', 3600);
     @ini_set('max_input_time', 3600);
     //try to set the maximum filesize to 10G
     @ini_set('upload_max_filesize', '10G');
     @ini_set('post_max_size', '10G');
     @ini_set('file_uploads', '50');
     //try to set the session lifetime to 60min
     @ini_set('gc_maxlifetime', '3600');
     //set http auth headers for apache+php-cgi work around
     if (isset($_SERVER['HTTP_AUTHORIZATION']) && preg_match('/Basic\\s+(.*)$/i', $_SERVER['HTTP_AUTHORIZATION'], $matches)) {
         list($name, $password) = explode(':', base64_decode($matches[1]));
         $_SERVER['PHP_AUTH_USER'] = strip_tags($name);
         $_SERVER['PHP_AUTH_PW'] = strip_tags($password);
     }
     //set http auth headers for apache+php-cgi work around if variable gets renamed by apache
     if (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION']) && preg_match('/Basic\\s+(.*)$/i', $_SERVER['REDIRECT_HTTP_AUTHORIZATION'], $matches)) {
         list($name, $password) = explode(':', base64_decode($matches[1]));
         $_SERVER['PHP_AUTH_USER'] = strip_tags($name);
         $_SERVER['PHP_AUTH_PW'] = strip_tags($password);
     }
     self::initPaths();
     // register the stream wrappers
     require_once 'streamwrappers.php';
     stream_wrapper_register("fakedir", "OC_FakeDirStream");
     stream_wrapper_register('static', 'OC_StaticStreamWrapper');
     stream_wrapper_register('close', 'OC_CloseStreamWrapper');
     self::checkInstalled();
     self::checkSSL();
     // CSRF protection
     if (isset($_SERVER['HTTP_REFERER'])) {
         $referer = $_SERVER['HTTP_REFERER'];
     } else {
         $referer = '';
     }
     $refererhost = parse_url($referer);
     if (isset($refererhost['host'])) {
         $refererhost = $refererhost['host'];
     } else {
         $refererhost = '';
     }
     $server = OC_Helper::serverHost();
     $serverhost = explode(':', $server);
     $serverhost = $serverhost['0'];
     if ($_SERVER['REQUEST_METHOD'] == 'POST' and $refererhost != $serverhost) {
         $url = OC_Helper::serverProtocol() . '://' . $server . OC::$WEBROOT . '/index.php';
         header("Location: {$url}");
         exit;
     }
     self::initSession();
     self::initTemplateEngine();
     self::checkUpgrade();
     $errors = OC_Util::checkServer();
     if (count($errors) > 0) {
         OC_Template::printGuestPage('', 'error', array('errors' => $errors));
         exit;
     }
     // TODO: we should get rid of this one, too
     // WARNING: to make everything even more confusing,
     //   DATADIRECTORY is a var that changes and DATADIRECTORY_ROOT
     //   stays the same, but is set by "datadirectory".
     //   Any questions?
     OC::$CONFIG_DATADIRECTORY = OC_Config::getValue("datadirectory", OC::$SERVERROOT . "/data");
     // User and Groups
     if (!OC_Config::getValue("installed", false)) {
         $_SESSION['user_id'] = '';
     }
     OC_User::useBackend(OC_Config::getValue("userbackend", "database"));
     OC_Group::useBackend(new OC_Group_Database());
     // Set up file system unless forbidden
     global $RUNTIME_NOSETUPFS;
     if (!$RUNTIME_NOSETUPFS) {
         OC_Util::setupFS();
     }
     // Load Apps
     // This includes plugins for users and filesystems as well
     global $RUNTIME_NOAPPS;
     global $RUNTIME_APPTYPES;
     if (!$RUNTIME_NOAPPS) {
         if ($RUNTIME_APPTYPES) {
             OC_App::loadApps($RUNTIME_APPTYPES);
         } else {
             OC_App::loadApps();
         }
     }
     // Check for blacklisted files
     OC_Hook::connect('OC_Filesystem', 'write', 'OC_Filesystem', 'isBlacklisted');
     //make sure temporary files are cleaned up
     register_shutdown_function(array('OC_Helper', 'cleanTmp'));
     //parse the given parameters
     self::$REQUESTEDAPP = isset($_GET['app']) && trim($_GET['app']) != '' && !is_null($_GET['app']) ? str_replace(array('\\0', '/', '\\', '..'), '', strip_tags($_GET['app'])) : OC_Config::getValue('defaultapp', 'files');
     if (substr_count(self::$REQUESTEDAPP, '?') != 0) {
         $app = substr(self::$REQUESTEDAPP, 0, strpos(self::$REQUESTEDAPP, '?'));
         $param = substr(self::$REQUESTEDAPP, strpos(self::$REQUESTEDAPP, '?') + 1);
         parse_str($param, $get);
         $_GET = array_merge($_GET, $get);
         self::$REQUESTEDAPP = $app;
         $_GET['app'] = $app;
     }
     self::$REQUESTEDFILE = isset($_GET['getfile']) ? $_GET['getfile'] : null;
     if (substr_count(self::$REQUESTEDFILE, '?') != 0) {
         $file = substr(self::$REQUESTEDFILE, 0, strpos(self::$REQUESTEDFILE, '?'));
         $param = substr(self::$REQUESTEDFILE, strpos(self::$REQUESTEDFILE, '?') + 1);
         parse_str($param, $get);
         $_GET = array_merge($_GET, $get);
         self::$REQUESTEDFILE = $file;
         $_GET['getfile'] = $file;
     }
     if (!is_null(self::$REQUESTEDFILE)) {
         $subdir = OC::$APPSROOT . '/apps/' . self::$REQUESTEDAPP . '/' . self::$REQUESTEDFILE;
         $parent = OC::$APPSROOT . '/apps/' . self::$REQUESTEDAPP;
         if (!OC_Helper::issubdirectory($subdir, $parent)) {
             self::$REQUESTEDFILE = null;
             header('HTTP/1.0 404 Not Found');
             exit;
         }
     }
 }
コード例 #10
0
ファイル: base.php プロジェクト: krsvital/core
 /**
  * Tries to login a user using the form based authentication
  * @return bool|void
  */
 protected static function tryFormLogin()
 {
     if (!isset($_POST["user"]) || !isset($_POST['password'])) {
         return false;
     }
     if (!OC_Util::isCallRegistered()) {
         return false;
     }
     OC_App::loadApps();
     //setup extra user backends
     OC_User::setupBackends();
     if (OC_User::login((string) $_POST["user"], (string) $_POST["password"])) {
         $userId = OC_User::getUser();
         // setting up the time zone
         if (isset($_POST['timezone-offset'])) {
             self::$server->getSession()->set('timezone', (string) $_POST['timezone-offset']);
             self::$server->getConfig()->setUserValue($userId, 'core', 'timezone', (string) $_POST['timezone']);
         }
         self::cleanupLoginTokens($userId);
         if (!empty($_POST["remember_login"])) {
             $config = self::$server->getConfig();
             if ($config->getSystemValue('debug', false)) {
                 self::$server->getLogger()->debug('Setting remember login to cookie', array('app' => 'core'));
             }
             $token = \OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate(32);
             $config->setUserValue($userId, 'login_token', $token, time());
             OC_User::setMagicInCookie($userId, $token);
         } else {
             OC_User::unsetMagicInCookie();
         }
         OC_Util::redirectToDefaultPage();
         exit;
     }
     return true;
 }
コード例 #11
0
ファイル: user.php プロジェクト: TechArea/core
 /**
  * Verify with Apache whether user is authenticated.
  *
  * @return boolean|null
  *          true: authenticated
  *          false: not authenticated
  *          null: not handled / no backend available
  */
 public static function handleApacheAuth()
 {
     $backend = self::findFirstActiveUsedBackend();
     if ($backend) {
         OC_App::loadApps();
         //setup extra user backends
         self::setupBackends();
         self::unsetMagicInCookie();
         return self::loginWithApache($backend);
     }
     return null;
 }
コード例 #12
0
ファイル: report.php プロジェクト: hjimmy/owncloud
 private function countUsers()
 {
     \OC_App::loadApps(array('authentication'));
     $userManager = \OC::$server->getUserManager();
     return $userManager->countUsers();
 }
コード例 #13
0
ファイル: base.php プロジェクト: CDN-Sparks/owncloud
 protected static function tryBasicAuthLogin()
 {
     if (!isset($_SERVER["PHP_AUTH_USER"]) || !isset($_SERVER["PHP_AUTH_PW"])) {
         return false;
     }
     OC_App::loadApps(array('authentication'));
     if (OC_User::login($_SERVER["PHP_AUTH_USER"], $_SERVER["PHP_AUTH_PW"])) {
         //OC_Log::write('core',"Logged in with HTTP Authentication", OC_Log::DEBUG);
         OC_User::unsetMagicInCookie();
         $_REQUEST['redirect_url'] = OC_Request::requestUri();
         OC_Util::redirectToDefaultPage();
     }
     return true;
 }
コード例 #14
0
ファイル: updater.php プロジェクト: hjimmy/owncloud
 /**
  * runs the update actions in maintenance mode, does not upgrade the source files
  */
 public function upgrade()
 {
     \OC_DB::enableCaching(false);
     \OC_Config::setValue('maintenance', true);
     $installedVersion = \OC_Config::getValue('version', '0.0.0');
     $currentVersion = implode('.', \OC_Util::getVersion());
     if ($this->log) {
         $this->log->debug('starting upgrade from ' . $installedVersion . ' to ' . $currentVersion, array('app' => 'core'));
     }
     $this->emit('\\OC\\Updater', 'maintenanceStart');
     // create empty file in data dir, so we can later find
     // out that this is indeed an ownCloud data directory
     // (in case it didn't exist before)
     file_put_contents(\OC_Config::getValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', '');
     /*
      * START CONFIG CHANGES FOR OLDER VERSIONS
      */
     if (!\OC::$CLI && version_compare($installedVersion, '6.00.4', '<')) {
         // Add the trusted_domains config if it is not existant
         // This is added to prevent host header poisoning
         \OC_Config::setValue('trusted_domains', \OC_Config::getValue('trusted_domains', array(\OC_Request::serverHost())));
     }
     /*
      * STOP CONFIG CHANGES FOR OLDER VERSIONS
      */
     try {
         \OC_DB::updateDbFromStructure(\OC::$SERVERROOT . '/db_structure.xml');
         $this->emit('\\OC\\Updater', 'dbUpgrade');
         // do a file cache upgrade for users with files
         // this can take loooooooooooooooooooooooong
         $this->upgradeFileCache();
     } catch (\Exception $exception) {
         $this->emit('\\OC\\Updater', 'failure', array($exception->getMessage()));
     }
     \OC_Config::setValue('version', implode('.', \OC_Util::getVersion()));
     \OC_App::checkAppsRequirements();
     // load all apps to also upgrade enabled apps
     \OC_App::loadApps();
     $repair = new Repair();
     $repair->run();
     //Invalidate update feed
     \OC_Appconfig::setValue('core', 'lastupdatedat', 0);
     \OC_Config::setValue('maintenance', false);
     $this->emit('\\OC\\Updater', 'maintenanceEnd');
 }
コード例 #15
0
ファイル: base.php プロジェクト: CDN-Sparks/owncloud
 protected static function tryBasicAuthLogin()
 {
     if (!isset($_SERVER["PHP_AUTH_USER"]) || !isset($_SERVER["PHP_AUTH_PW"])) {
         return false;
     }
     OC_App::loadApps(array('authentication'));
     if (OC_User::login($_SERVER["PHP_AUTH_USER"], $_SERVER["PHP_AUTH_PW"])) {
         //OC_Log::write('core',"Logged in with HTTP Authentication", OC_Log::DEBUG);
         OC_User::unsetMagicInCookie();
         $_SERVER['HTTP_REQUESTTOKEN'] = OC_Util::callRegister();
     }
     return true;
 }
コード例 #16
0
ファイル: user.php プロジェクト: noci2012/owncloud
 /**
  * @brief Check if the user is logged in
  * @returns true/false
  *
  * Checks if the user is logged in
  */
 public static function isLoggedIn()
 {
     static $is_login_checked = null;
     if (!is_null($is_login_checked)) {
         return $is_login_checked;
     }
     if (isset($_SESSION['user_id']) and $_SESSION['user_id']) {
         OC_App::loadApps(array('authentication'));
         if (self::userExists($_SESSION['user_id'])) {
             return $is_login_checked = true;
         }
     }
     return $is_login_checked = false;
 }
コード例 #17
0
ファイル: updater.php プロジェクト: olucao/owncloud-core
 /**
  * runs the update actions in maintenance mode, does not upgrade the source files
  * except the main .htaccess file
  *
  * @param string $currentVersion current version to upgrade to
  * @param string $installedVersion previous version from which to upgrade from
  *
  * @return bool true if the operation succeeded, false otherwise
  */
 private function doUpgrade($currentVersion, $installedVersion)
 {
     // Update htaccess files for apache hosts
     if (isset($_SERVER['SERVER_SOFTWARE']) && strstr($_SERVER['SERVER_SOFTWARE'], 'Apache')) {
         \OC_Setup::updateHtaccess();
     }
     // create empty file in data dir, so we can later find
     // out that this is indeed an ownCloud data directory
     // (in case it didn't exist before)
     file_put_contents(\OC_Config::getValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', '');
     /*
      * START CONFIG CHANGES FOR OLDER VERSIONS
      */
     if (!\OC::$CLI && version_compare($installedVersion, '6.90.1', '<')) {
         // Add the trusted_domains config if it is not existant
         // This is added to prevent host header poisoning
         \OC_Config::setValue('trusted_domains', \OC_Config::getValue('trusted_domains', array(\OC_Request::serverHost())));
     }
     /*
      * STOP CONFIG CHANGES FOR OLDER VERSIONS
      */
     // pre-upgrade repairs
     $repair = new \OC\Repair(\OC\Repair::getBeforeUpgradeRepairSteps());
     $repair->run();
     // simulate DB upgrade
     if ($this->simulateStepEnabled) {
         // simulate core DB upgrade
         \OC_DB::simulateUpdateDbFromStructure(\OC::$SERVERROOT . '/db_structure.xml');
         // simulate apps DB upgrade
         $version = \OC_Util::getVersion();
         $apps = \OC_App::getEnabledApps();
         foreach ($apps as $appId) {
             $info = \OC_App::getAppInfo($appId);
             if (\OC_App::isAppCompatible($version, $info) && \OC_App::shouldUpgrade($appId)) {
                 if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/database.xml')) {
                     \OC_DB::simulateUpdateDbFromStructure(\OC_App::getAppPath($appId) . '/appinfo/database.xml');
                 }
             }
         }
         $this->emit('\\OC\\Updater', 'dbSimulateUpgrade');
     }
     // upgrade from OC6 to OC7
     // TODO removed it again for OC8
     $sharePolicy = \OC_Appconfig::getValue('core', 'shareapi_share_policy', 'global');
     if ($sharePolicy === 'groups_only') {
         \OC_Appconfig::setValue('core', 'shareapi_only_share_with_group_members', 'yes');
     }
     if ($this->updateStepEnabled) {
         // do the real upgrade
         \OC_DB::updateDbFromStructure(\OC::$SERVERROOT . '/db_structure.xml');
         $this->emit('\\OC\\Updater', 'dbUpgrade');
         // TODO: why not do this at the end ?
         \OC_Config::setValue('version', implode('.', \OC_Util::getVersion()));
         $disabledApps = \OC_App::checkAppsRequirements();
         if (!empty($disabledApps)) {
             $this->emit('\\OC\\Updater', 'disabledApps', array($disabledApps));
         }
         // load all apps to also upgrade enabled apps
         \OC_App::loadApps();
         // post-upgrade repairs
         $repair = new \OC\Repair(\OC\Repair::getRepairSteps());
         $repair->run();
         //Invalidate update feed
         \OC_Appconfig::setValue('core', 'lastupdatedat', 0);
     }
 }
コード例 #18
0
ファイル: router.php プロジェクト: droiter/openwrt-on-android
 /**
  * Find the route matching $url
  *
  * @param string $url The url to find
  * @throws \Exception
  * @return void
  */
 public function match($url)
 {
     if (substr($url, 0, 6) === '/apps/') {
         // empty string / 'apps' / $app / rest of the route
         list(, , $app, ) = explode('/', $url, 4);
         $app = \OC_App::cleanAppId($app);
         \OC::$REQUESTEDAPP = $app;
         $this->loadRoutes($app);
     } else {
         if (substr($url, 0, 6) === '/core/' or substr($url, 0, 10) === '/settings/') {
             \OC::$REQUESTEDAPP = $url;
             if (!\OC_Config::getValue('maintenance', false) && !\OCP\Util::needUpgrade()) {
                 \OC_App::loadApps();
             }
             $this->loadRoutes('core');
         } else {
             $this->loadRoutes();
         }
     }
     $matcher = new UrlMatcher($this->root, $this->context);
     $parameters = $matcher->match($url);
     if (isset($parameters['action'])) {
         $action = $parameters['action'];
         if (!is_callable($action)) {
             var_dump($action);
             throw new \Exception('not a callable action');
         }
         unset($parameters['action']);
         call_user_func($action, $parameters);
     } elseif (isset($parameters['file'])) {
         include $parameters['file'];
     } else {
         throw new \Exception('no action available');
     }
 }
コード例 #19
0
ファイル: util.php プロジェクト: Angelos0/core
 /**
  * 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;
     }
     \OC::$server->getEventLogger()->start('setup_fs', 'Setup filesystem');
     // 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;
     }
     \OC\Files\Filesystem::initMountManager();
     \OC\Files\Filesystem::addStorageWrapper('mount_options', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) {
         if ($storage->instanceOfStorage('\\OC\\Files\\Storage\\Common')) {
             /** @var \OC\Files\Storage\Common $storage */
             $storage->setMountOptions($mount->getOptions());
         }
         return $storage;
     });
     // install storage availability wrapper, before most other wrappers
     \OC\Files\Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, $storage) {
         if (!$storage->isLocal()) {
             return new \OC\Files\Storage\Wrapper\Availability(['storage' => $storage]);
         }
         return $storage;
     });
     \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')) {
             /** @var \OC\Files\Storage\Home $storage */
             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;
     });
     OC_Hook::emit('OC_Filesystem', 'preSetup', array('user' => $user));
     //check if we are using an object storage
     $objectStore = \OC::$server->getSystemConfig()->getValue('objectstore', null);
     if (isset($objectStore)) {
         self::initObjectStoreRootFS($objectStore);
     } else {
         self::initLocalStorageRootFS();
     }
     if ($user != '' && !OCP\User::userExists($user)) {
         \OC::$server->getEventLogger()->end('setup_fs');
         return false;
     }
     //if we aren't logged in, there is no use to set up the filesystem
     if ($user != "") {
         $userDir = '/' . $user . '/files';
         //jail the user into his "home" directory
         \OC\Files\Filesystem::init($user, $userDir);
         OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $userDir));
     }
     \OC::$server->getEventLogger()->end('setup_fs');
     return true;
 }
コード例 #20
0
 public static function changeUserPassword($args)
 {
     // Check if we are an user
     \OC_JSON::callCheck();
     \OC_JSON::checkLoggedIn();
     // Manually load apps to ensure hooks work correctly (workaround for issue 1503)
     \OC_App::loadApps();
     if (isset($_POST['username'])) {
         $username = $_POST['username'];
     } else {
         $l = new \OC_L10n('settings');
         \OC_JSON::error(array('data' => array('message' => $l->t('No user supplied'))));
         exit;
     }
     $password = isset($_POST['password']) ? $_POST['password'] : null;
     $recoveryPassword = isset($_POST['recoveryPassword']) ? $_POST['recoveryPassword'] : null;
     if (\OC_User::isAdminUser(\OC_User::getUser())) {
         $userstatus = 'admin';
     } elseif (\OC_SubAdmin::isUserAccessible(\OC_User::getUser(), $username)) {
         $userstatus = 'subadmin';
     } else {
         $l = new \OC_L10n('settings');
         \OC_JSON::error(array('data' => array('message' => $l->t('Authentication error'))));
         exit;
     }
     if (\OC_App::isEnabled('files_encryption')) {
         //handle the recovery case
         $util = new \OCA\Encryption\Util(new \OC_FilesystemView('/'), $username);
         $recoveryAdminEnabled = \OC_Appconfig::getValue('files_encryption', 'recoveryAdminEnabled');
         $validRecoveryPassword = false;
         $recoveryPasswordSupported = false;
         if ($recoveryAdminEnabled) {
             $validRecoveryPassword = $util->checkRecoveryPassword($recoveryPassword);
             $recoveryEnabledForUser = $util->recoveryEnabledForUser();
         }
         if ($recoveryEnabledForUser && $recoveryPassword === '') {
             $l = new \OC_L10n('settings');
             \OC_JSON::error(array('data' => array('message' => $l->t('Please provide an admin recovery password, otherwise all user data will be lost'))));
         } elseif ($recoveryEnabledForUser && !$validRecoveryPassword) {
             $l = new \OC_L10n('settings');
             \OC_JSON::error(array('data' => array('message' => $l->t('Wrong admin recovery password. Please check the password and try again.'))));
         } else {
             // now we know that everything is fine regarding the recovery password, let's try to change the password
             $result = \OC_User::setPassword($username, $password, $recoveryPassword);
             if (!$result && $recoveryPasswordSupported) {
                 $l = new \OC_L10n('settings');
                 \OC_JSON::error(array("data" => array("message" => $l->t("Back-end doesn't support password change, but the users encryption key was successfully updated."))));
             } elseif (!$result && !$recoveryPasswordSupported) {
                 $l = new \OC_L10n('settings');
                 \OC_JSON::error(array("data" => array("message" => $l->t("Unable to change password"))));
             } else {
                 \OC_JSON::success(array("data" => array("username" => $username)));
             }
         }
     } else {
         // if encryption is disabled, proceed
         if (!is_null($password) && \OC_User::setPassword($username, $password)) {
             \OC_JSON::success(array('data' => array('username' => $username)));
         } else {
             $l = new \OC_L10n('settings');
             \OC_JSON::error(array('data' => array('message' => $l->t('Unable to change password'))));
         }
     }
 }
コード例 #21
0
ファイル: update.php プロジェクト: CDN-Sparks/owncloud
                    $shareWith = $row['uid_shared_with'];
                }
            }
            OC_User::setUserId($row['uid_owner']);
            //we need to setup the filesystem for the user, otherwise OC_FileSystem::getRoot will fail and break
            OC_Util::setupFS($row['uid_owner']);
            try {
                OCP\Share::shareItem($itemType, $itemSource, $shareType, $shareWith, $permissions);
            } catch (Exception $e) {
                $update_error = true;
                OCP\Util::writeLog('files_sharing', 'Upgrade Routine: Skipping sharing "' . $row['source'] . '" to "' . $shareWith . '" (error is "' . $e->getMessage() . '")', OCP\Util::WARN);
            }
            OC_Util::tearDownFS();
        }
    }
    OC_User::setUserId(null);
    if ($update_error) {
        OCP\Util::writeLog('files_sharing', 'There were some problems upgrading the sharing of files', OCP\Util::ERROR);
    }
    // NOTE: Let's drop the table after more testing
    // 	$query = OCP\DB::prepare('DROP TABLE `*PREFIX*sharing`');
    // 	$query->execute();
}
if (version_compare($installedVersion, '0.3.3', '<')) {
    OC_User::useBackend(new OC_User_Database());
    OC_App::loadApps(array('authentication'));
    $users = OC_User::getUsers();
    foreach ($users as $user) {
        //		OC_FileCache::delete('Shared', '/'.$user.'/files/');
    }
}
コード例 #22
0
ファイル: cron.php プロジェクト: Romua1d/core
    if (!TemporaryCronClass::$sent) {
        if (OC::$CLI) {
            echo 'Unexpected error!' . PHP_EOL;
        } else {
            OC_JSON::error(array('data' => array('message' => 'Unexpected error!')));
        }
    }
}
try {
    require_once 'lib/base.php';
    if (\OCP\Util::needUpgrade()) {
        \OCP\Util::writeLog('cron', 'Update required, skipping cron', \OCP\Util::DEBUG);
        exit;
    }
    // load all apps to get all api routes properly setup
    OC_App::loadApps();
    \OC::$server->getSession()->close();
    // initialize a dummy memory session
    \OC::$server->setSession(new \OC\Session\Memory(''));
    $logger = \OC_Log::$object;
    // Don't do anything if ownCloud has not been installed
    if (!OC_Config::getValue('installed', false)) {
        exit(0);
    }
    // Handle unexpected errors
    register_shutdown_function('handleUnexpectedShutdown');
    \OC::$server->getTempManager()->cleanOld();
    // Exit if background jobs are disabled!
    $appmode = OC_BackgroundJob::getExecutionType();
    if ($appmode == 'none') {
        TemporaryCronClass::$sent = true;
コード例 #23
0
ファイル: user.php プロジェクト: CDN-Sparks/owncloud
 /**
  * @brief Check if the user is logged in
  * @returns true/false
  *
  * Checks if the user is logged in
  */
 public static function isLoggedIn()
 {
     if (isset($_SESSION['user_id']) and $_SESSION['user_id']) {
         OC_App::loadApps(array('authentication'));
         self::setupBackends();
         if (self::userExists($_SESSION['user_id'])) {
             return true;
         }
     }
     return false;
 }
コード例 #24
0
 /**
  * runs the update actions in maintenance mode, does not upgrade the source files
  */
 public function upgrade()
 {
     \OC_DB::enableCaching(false);
     \OC_Config::setValue('maintenance', true);
     $installedVersion = \OC_Config::getValue('version', '0.0.0');
     $currentVersion = implode('.', \OC_Util::getVersion());
     if ($this->log) {
         $this->log->debug('starting upgrade from ' . $installedVersion . ' to ' . $currentVersion, array('app' => 'core'));
     }
     $this->emit('\\OC\\Updater', 'maintenanceStart');
     try {
         \OC_DB::updateDbFromStructure(\OC::$SERVERROOT . '/db_structure.xml');
         $this->emit('\\OC\\Updater', 'dbUpgrade');
         // do a file cache upgrade for users with files
         // this can take loooooooooooooooooooooooong
         $this->upgradeFileCache();
     } catch (\Exception $exception) {
         $this->emit('\\OC\\Updater', 'failure', array($exception->getMessage()));
     }
     \OC_Config::setValue('version', implode('.', \OC_Util::getVersion()));
     \OC_App::checkAppsRequirements();
     // load all apps to also upgrade enabled apps
     \OC_App::loadApps();
     $repair = new Repair();
     $repair->run();
     \OC_Config::setValue('maintenance', false);
     $this->emit('\\OC\\Updater', 'maintenanceEnd');
 }
コード例 #25
0
ファイル: public.php プロジェクト: evanjt/core
        $service = $request->getParam('service', '');
    } else {
        $pathInfo = trim($pathInfo, '/');
        list($service) = explode('/', $pathInfo);
    }
    $file = OCP\CONFIG::getAppValue('core', 'public_' . strip_tags($service));
    if (is_null($file)) {
        header('HTTP/1.0 404 Not Found');
        exit;
    }
    $parts = explode('/', $file, 2);
    $app = $parts[0];
    // Load all required applications
    \OC::$REQUESTEDAPP = $app;
    OC_App::loadApps(array('authentication'));
    OC_App::loadApps(array('filesystem', 'logging'));
    if (!\OC::$server->getAppManager()->isInstalled($app)) {
        throw new Exception('App not installed: ' . $app);
    }
    OC_App::loadApp($app);
    OC_User::setIncognitoMode(true);
    $baseuri = OC::$WEBROOT . '/public.php/' . $service . '/';
    require_once OC_App::getAppPath($app) . '/' . $parts[1];
} catch (\OC\ServiceUnavailableException $ex) {
    //show the user a detailed error page
    OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE);
    \OCP\Util::writeLog('remote', $ex->getMessage(), \OCP\Util::FATAL);
    OC_Template::printExceptionErrorPage($ex);
} catch (Exception $ex) {
    //show the user a detailed error page
    OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR);
コード例 #26
0
ファイル: webdav.php プロジェクト: blablubli/owncloudapps
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library.  If not, see <http://www.gnu.org/licenses/>.
*
*/
OC_App::loadApps(array('filesystem', 'authentication'));
OCP\App::checkAppEnabled('remoteStorage');
require_once 'lib_remoteStorage.php';
require_once 'BearerAuth.php';
require_once 'oauth_ro_auth.php';
ini_set('default_charset', 'UTF-8');
#ini_set('error_reporting', '');
@ob_clean();
//allow use as remote storage for other websites
if (isset($_SERVER['HTTP_ORIGIN'])) {
    header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
    header('Access-Control-Max-Age: 3600');
    header('Access-Control-Allow-Methods: OPTIONS, GET, PUT, DELETE, PROPFIND');
    header('Access-Control-Allow-Headers: Authorization, Content-Type');
} else {
    header('Access-Control-Allow-Origin: *');
コード例 #27
0
ファイル: remote.php プロジェクト: noci2012/owncloud
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
// only need filesystem apps
$RUNTIME_APPTYPES = array('filesystem', 'authentication');
OC_App::loadApps($RUNTIME_APPTYPES);
// Backends
$authBackend = new OC_Connector_Sabre_Auth();
$lockBackend = new OC_Connector_Sabre_Locks();
// Create ownCloud Dir
$publicDir = new OC_Connector_Sabre_Directory('');
// Fire up server
$server = new Sabre_DAV_Server($publicDir);
$server->setBaseUri($baseuri);
// Load plugins
$server->addPlugin(new Sabre_DAV_Auth_Plugin($authBackend, 'ownCloud'));
$server->addPlugin(new Sabre_DAV_Locks_Plugin($lockBackend));
$server->addPlugin(new Sabre_DAV_Browser_Plugin(false));
// Show something in the Browser, but no upload
// And off we go!
$server->exec();
 public static function init()
 {
     // register autoloader
     spl_autoload_register(array('OC', 'autoload'));
     // set some stuff
     //ob_start();
     error_reporting(E_ALL | E_STRICT);
     date_default_timezone_set('Europe/Berlin');
     ini_set('arg_separator.output', '&amp;');
     // calculate the documentroot
     OC::$DOCUMENTROOT = realpath($_SERVER['DOCUMENT_ROOT']);
     OC::$SERVERROOT = str_replace("\\", '/', substr(__FILE__, 0, -13));
     OC::$SUBURI = substr(realpath($_SERVER["SCRIPT_FILENAME"]), strlen(OC::$SERVERROOT));
     $scriptName = $_SERVER["SCRIPT_NAME"];
     if (substr($scriptName, -1) == '/') {
         $scriptName .= 'index.php';
     }
     OC::$WEBROOT = substr($scriptName, 0, strlen($scriptName) - strlen(OC::$SUBURI));
     if (OC::$WEBROOT != '' and OC::$WEBROOT[0] !== '/') {
         OC::$WEBROOT = '/' . OC::$WEBROOT;
     }
     // set the right include path
     set_include_path(OC::$SERVERROOT . '/lib' . PATH_SEPARATOR . OC::$SERVERROOT . '/config' . PATH_SEPARATOR . OC::$SERVERROOT . '/3rdparty' . PATH_SEPARATOR . get_include_path() . PATH_SEPARATOR . OC::$SERVERROOT);
     // redirect to https site if configured
     if (OC_Config::getValue("forcessl", false)) {
         ini_set("session.cookie_secure", "on");
         if (!isset($_SERVER['HTTPS']) or $_SERVER['HTTPS'] != 'on') {
             $url = "https://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
             header("Location: {$url}");
             exit;
         }
     }
     ini_set('session.cookie_httponly', '1;');
     session_start();
     // Add the stuff we need always
     OC_Util::addScript("jquery-1.6.4.min");
     OC_Util::addScript("jquery-ui-1.8.14.custom.min");
     OC_Util::addScript("jquery-showpassword");
     OC_Util::addScript("jquery.infieldlabel.min");
     OC_Util::addScript("jquery-tipsy");
     OC_Util::addScript("js");
     //OC_Util::addScript( "multiselect" );
     OC_Util::addScript('search', 'result');
     OC_Util::addStyle("styles");
     OC_Util::addStyle("multiselect");
     OC_Util::addStyle("jquery-ui-1.8.14.custom");
     OC_Util::addStyle("jquery-tipsy");
     $errors = OC_Util::checkServer();
     if (count($errors) > 0) {
         OC_Template::printGuestPage('', 'error', array('errors' => $errors));
         exit;
     }
     // TODO: we should get rid of this one, too
     // WARNING: to make everything even more confusing,
     //   DATADIRECTORY is a var that changes and DATADIRECTORY_ROOT
     //   stays the same, but is set by "datadirectory".
     //   Any questions?
     OC::$CONFIG_DATADIRECTORY = OC_Config::getValue("datadirectory", OC::$SERVERROOT . "/data");
     // User and Groups
     if (!OC_Config::getValue("installed", false)) {
         $_SESSION['user_id'] = '';
     }
     OC_User::useBackend(OC_Config::getValue("userbackend", "database"));
     OC_Group::setBackend(OC_Config::getValue("groupbackend", "database"));
     // Load Apps
     // This includes plugins for users and filesystems as well
     global $RUNTIME_NOAPPS;
     if (!$RUNTIME_NOAPPS) {
         OC_App::loadApps();
     }
     // Was in required file ... put it here
     OC_Filesystem::registerStorageType('local', 'OC_Filestorage_Local', array('datadir' => 'string'));
     // Set up file system unless forbidden
     global $RUNTIME_NOSETUPFS;
     if (!$RUNTIME_NOSETUPFS) {
         OC_Util::setupFS();
     }
     // Last part: connect some hooks
     OC_HOOK::connect('OC_User', 'post_createUser', 'OC_Connector_Sabre_Principal', 'addPrincipal');
     OC_HOOK::connect('OC_User', 'post_deleteUser', 'OC_Connector_Sabre_Principal', 'deletePrincipal');
 }
コード例 #29
0
ファイル: Router.php プロジェクト: stweil/owncloud-core
 /**
  * Find the route matching $url
  *
  * @param string $url The url to find
  * @throws \Exception
  * @return void
  */
 public function match($url)
 {
     if (substr($url, 0, 6) === '/apps/') {
         // empty string / 'apps' / $app / rest of the route
         list(, , $app, ) = explode('/', $url, 4);
         $app = \OC_App::cleanAppId($app);
         \OC::$REQUESTEDAPP = $app;
         $this->loadRoutes($app);
     } else {
         if (substr($url, 0, 6) === '/core/' or substr($url, 0, 10) === '/settings/') {
             \OC::$REQUESTEDAPP = $url;
             if (!\OC::$server->getConfig()->getSystemValue('maintenance', false) && !Util::needUpgrade()) {
                 \OC_App::loadApps();
             }
             $this->loadRoutes('core');
         } else {
             $this->loadRoutes();
         }
     }
     $matcher = new UrlMatcher($this->root, $this->context);
     try {
         $parameters = $matcher->match($url);
     } catch (ResourceNotFoundException $e) {
         if (substr($url, -1) !== '/') {
             // We allow links to apps/files? for backwards compatibility reasons
             // However, since Symfony does not allow empty route names, the route
             // we need to match is '/', so we need to append the '/' here.
             try {
                 $parameters = $matcher->match($url . '/');
             } catch (ResourceNotFoundException $newException) {
                 // If we still didn't match a route, we throw the original exception
                 throw $e;
             }
         } else {
             throw $e;
         }
     }
     \OC::$server->getEventLogger()->start('run_route', 'Run route');
     if (isset($parameters['action'])) {
         $action = $parameters['action'];
         if (!is_callable($action)) {
             throw new \Exception('not a callable action');
         }
         unset($parameters['action']);
         call_user_func($action, $parameters);
     } elseif (isset($parameters['file'])) {
         include $parameters['file'];
     } else {
         throw new \Exception('no action available');
     }
     \OC::$server->getEventLogger()->end('run_route');
 }
コード例 #30
0
ファイル: user.php プロジェクト: hjimmy/owncloud
 /**
  * @brief Check if the user is logged in
  * @returns bool
  *
  * Checks if the user is logged in
  */
 public static function isLoggedIn()
 {
     if (\OC::$session->get('user_id') && self::$incognitoMode === false) {
         OC_App::loadApps(array('authentication'));
         self::setupBackends();
         return self::userExists(\OC::$session->get('user_id'));
     }
     return false;
 }