Beispiel #1
0
 /**
  * @return string
  * @since 8.1.0
  */
 public function render()
 {
     $r = new \OC_OCS_Result($this->data, $this->statuscode, $this->message);
     $r->setTotalItems($this->itemscount);
     $r->setItemsPerPage($this->itemsperpage);
     return \OC_API::renderResult($this->format, $r->getMeta(), $r->getData());
 }
Beispiel #2
0
 /**
  * @dataProvider dataProviderTestMergeResponses
  *
  * Test the merging of multiple responses
  * @param $statusCode1
  * @param $statusCode2
  * @param $succeeded
  */
 public function testMultipleMergeResponses($shipped1, $statusCode1, $shipped2, $statusCode2, $succeeded)
 {
     // Tests that app responses are merged correctly
     // Setup some data arrays
     $data1 = array('users' => array('tom' => array('key' => 'value'), 'frank' => array('key' => 'value')));
     $data2 = array('users' => array('tom' => array('key' => 'newvalue'), 'jan' => array('key' => 'value')));
     // Two shipped success results
     $result = OC_API::mergeResponses(array($this->buildResponse($shipped1, $data1, $statusCode1, "message1"), $this->buildResponse($shipped2, $data2, $statusCode2, "message2")));
     $this->checkResult($result, $succeeded);
     $resultData = $result->getData();
     $resultMeta = $result->getMeta();
     $resultStatusCode = $result->getStatusCode();
     $this->assertArrayHasKey('jan', $resultData['users']);
     // check if the returned status message matches the selected status code
     if ($resultStatusCode === 997) {
         $this->assertEquals('message1', $resultMeta['message']);
     } elseif ($resultStatusCode === 998) {
         $this->assertEquals('message2', $resultMeta['message']);
     } elseif ($resultStatusCode === 100) {
         $this->assertEquals(null, $resultMeta['message']);
     }
 }
Beispiel #3
0
 /**
  * Based on the requested format the response content type is set
  */
 public static function setContentType()
 {
     $format = \OC_API::requestedFormat();
     if ($format === 'xml') {
         header('Content-type: text/xml; charset=UTF-8');
         return;
     }
     if ($format === 'json') {
         header('Content-Type: application/json; charset=utf-8');
         return;
     }
     header('Content-Type: application/octet-stream; charset=utf-8');
 }
Beispiel #4
0
<?php

/**
 * ownCloud - External Storage Routes
 *
 * @author Vincent Petry
 * @copyright 2014 Vincent Petry <*****@*****.**>
 *
 * 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_API::register('get', '/apps/files_external/api/v1/mounts', array('\\OCA\\Files\\External\\Api', 'getUserMounts'), 'files_external');
Beispiel #5
0
<?php

/** @var $this \OCP\Route\IRouter */
$this->create('core_ajax_public_preview', '/publicpreview')->action(function () {
    require_once __DIR__ . '/../ajax/publicpreview.php';
});
$this->create('files_sharing_ajax_list', 'ajax/list.php')->actionInclude('files_sharing/ajax/list.php');
$this->create('sharing_external_shareinfo', '/shareinfo')->actionInclude('files_sharing/ajax/shareinfo.php');
$this->create('sharing_external_add', '/external')->actionInclude('files_sharing/ajax/external.php');
$this->create('sharing_external_test_remote', '/testremote')->actionInclude('files_sharing/ajax/testremote.php');
// OCS API
//TODO: SET: mail notification, waiting for PR #4689 to be accepted
OC_API::register('get', '/apps/files_sharing/api/v1/shares', array('\\OCA\\Files\\Share\\Api', 'getAllShares'), 'files_sharing');
OC_API::register('post', '/apps/files_sharing/api/v1/shares', array('\\OCA\\Files\\Share\\Api', 'createShare'), 'files_sharing');
OC_API::register('get', '/apps/files_sharing/api/v1/shares/{id}', array('\\OCA\\Files\\Share\\Api', 'getShare'), 'files_sharing');
OC_API::register('put', '/apps/files_sharing/api/v1/shares/{id}', array('\\OCA\\Files\\Share\\Api', 'updateShare'), 'files_sharing');
OC_API::register('delete', '/apps/files_sharing/api/v1/shares/{id}', array('\\OCA\\Files\\Share\\Api', 'deleteShare'), 'files_sharing');
Beispiel #6
0
 *
 * You should have received a copy of the GNU Affero General Public License, version 3,
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */
require_once '../lib/base.php';
if (\OCP\Util::needUpgrade() || \OC::$server->getSystemConfig()->getValue('maintenance', false) || \OC::$server->getSystemConfig()->getValue('singleuser', false)) {
    // since the behavior of apps or remotes are unpredictable during
    // an upgrade, return a 503 directly
    OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE);
    $response = new OC_OCS_Result(null, OC_Response::STATUS_SERVICE_UNAVAILABLE, 'Service unavailable');
    OC_API::respond($response, OC_API::requestedFormat());
    exit;
}
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
try {
    // load all apps to get all api routes properly setup
    OC_App::loadApps();
    // force language as given in the http request
    \OC_L10N::setLanguageFromRequest();
    OC::$server->getRouter()->match('/ocs' . \OC::$server->getRequest()->getRawPathInfo());
} catch (ResourceNotFoundException $e) {
    OC_API::setContentType();
    OC_OCS::notFound();
} catch (MethodNotAllowedException $e) {
    OC_API::setContentType();
    OC_Response::setStatus(405);
} catch (\OC\OCS\Exception $ex) {
    OC_API::respond($ex->getResult(), OC_API::requestedFormat());
}
Beispiel #7
0
<?php

/** @var $this \OCP\Route\IRouter */
$this->create('core_ajax_trashbin_preview', 'ajax/preview.php')->actionInclude('files_trashbin/ajax/preview.php');
$this->create('files_trashbin_ajax_delete', 'ajax/delete.php')->actionInclude('files_trashbin/ajax/delete.php');
$this->create('files_trashbin_ajax_isEmpty', 'ajax/isEmpty.php')->actionInclude('files_trashbin/ajax/isEmpty.php');
$this->create('files_trashbin_ajax_list', 'ajax/list.php')->actionInclude('files_trashbin/ajax/list.php');
$this->create('files_trashbin_ajax_undelete', 'ajax/undelete.php')->actionInclude('files_trashbin/ajax/undelete.php');
// Register with the capabilities API
\OC_API::register('get', '/cloud/capabilities', array('OCA\\Files_Trashbin\\Capabilities', 'getCapabilities'), 'files_trashbin', \OC_API::USER_AUTH);
Beispiel #8
0
 /**
  * registers an api call
  * @param string $method the http method
  * @param string $url the url to match
  * @param callable $action the function to run
  * @param string $app the id of the app registering the call
  * @param int $authLevel the level of authentication required for the call (See OC_API constants)
  * @param array $defaults
  * @param array $requirements
  */
 public static function register($method, $url, $action, $app, $authLevel = OC_API::USER_AUTH, $defaults = array(), $requirements = array())
 {
     \OC_API::register($method, $url, $action, $app, $authLevel, $defaults, $requirements);
 }
Beispiel #9
0
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License, version 3,
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */
namespace OCA\Files_Sharing\AppInfo;

use OCA\Files_Sharing\Application;
$application = new Application();
$application->registerRoutes($this, ['resources' => ['ExternalShares' => ['url' => '/api/externalShares']]]);
/** @var $this \OCP\Route\IRouter */
$this->create('core_ajax_public_preview', '/publicpreview')->action(function () {
    require_once __DIR__ . '/../ajax/publicpreview.php';
});
$this->create('files_sharing_ajax_list', 'ajax/list.php')->actionInclude('files_sharing/ajax/list.php');
$this->create('files_sharing_ajax_publicpreview', 'ajax/publicpreview.php')->actionInclude('files_sharing/ajax/publicpreview.php');
$this->create('sharing_external_shareinfo', '/shareinfo')->actionInclude('files_sharing/ajax/shareinfo.php');
$this->create('sharing_external_add', '/external')->actionInclude('files_sharing/ajax/external.php');
$this->create('sharing_external_test_remote', '/testremote')->actionInclude('files_sharing/ajax/testremote.php');
// OCS API
//TODO: SET: mail notification, waiting for PR #4689 to be accepted
\OC_API::register('get', '/apps/files_sharing/api/v1/shares', array('\\OCA\\Files_Sharing\\API\\Local', 'getAllShares'), 'files_sharing');
\OC_API::register('post', '/apps/files_sharing/api/v1/shares', array('\\OCA\\Files_Sharing\\API\\Local', 'createShare'), 'files_sharing');
\OC_API::register('get', '/apps/files_sharing/api/v1/shares/{id}', array('\\OCA\\Files_Sharing\\API\\Local', 'getShare'), 'files_sharing');
\OC_API::register('put', '/apps/files_sharing/api/v1/shares/{id}', array('\\OCA\\Files_Sharing\\API\\Local', 'updateShare'), 'files_sharing');
\OC_API::register('delete', '/apps/files_sharing/api/v1/shares/{id}', array('\\OCA\\Files_Sharing\\API\\Local', 'deleteShare'), 'files_sharing');
// Register with the capabilities API
\OC_API::register('get', '/cloud/capabilities', array('OCA\\Files_Sharing\\Capabilities', 'getCapabilities'), 'files_sharing', \OC_API::USER_AUTH);
Beispiel #10
0
<?php

/**
 * Copyright (c) 2013, Tom Needham <*****@*****.**>
 * This file is licensed under the Affero General Public License version 3 or later.
 * See the COPYING-README file.
 */
// Register with the capabilities API
OC_API::register('get', '/cloud/capabilities', array('OCA\\Encryption\\Capabilities', 'getCapabilities'), 'files_encryption', OC_API::USER_AUTH);
Beispiel #11
0
 /**
  * Called when a not existing OCS endpoint has been called
  */
 public static function notFound()
 {
     $format = \OC::$server->getRequest()->getParam('format', 'xml');
     $txt = 'Invalid query, please check the syntax. API specifications are here:' . ' http://www.freedesktop.org/wiki/Specifications/open-collaboration-services. DEBUG OUTPUT:' . "\n";
     OC_API::respond(new OC_OCS_Result(null, API::RESPOND_UNKNOWN_ERROR, $txt), $format);
 }
Beispiel #12
0
 /**
  * http basic auth
  * @return string|false (username, or false on failure)
  */
 private static function loginUser()
 {
     // basic auth
     $authUser = isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : '';
     $authPw = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : '';
     $return = OC_User::login($authUser, $authPw);
     if ($return === true) {
         self::$logoutRequired = true;
         // initialize the user's filesystem
         \OC_Util::setUpFS(\OC_User::getUser());
         return $authUser;
     }
     // reuse existing login
     $loggedIn = OC_User::isLoggedIn();
     $ocsApiRequest = isset($_SERVER['HTTP_OCS_APIREQUEST']) ? $_SERVER['HTTP_OCS_APIREQUEST'] === 'true' : false;
     if ($loggedIn === true && $ocsApiRequest) {
         // initialize the user's filesystem
         \OC_Util::setUpFS(\OC_User::getUser());
         return OC_User::getUser();
     }
     return false;
 }
Beispiel #13
0
<?php

/**
 * Copyright (c) 2012, Tom Needham <*****@*****.**>
 * This file is licensed under the Affero General Public License version 3 or later.
 * See the COPYING-README file.
 */
// Config
OC_API::register('get', '/config', array('OC_OCS_Config', 'apiConfig'), 'core', OC_API::GUEST_AUTH);
// Person
OC_API::register('post', '/person/check', array('OC_OCS_Person', 'check'), 'core', OC_API::GUEST_AUTH);
// Privatedata
OC_API::register('get', '/privatedata/getattribute', array('OC_OCS_Privatedata', 'get'), 'core', OC_API::USER_AUTH, array('app' => '', 'key' => ''));
OC_API::register('get', '/privatedata/getattribute/{app}', array('OC_OCS_Privatedata', 'get'), 'core', OC_API::USER_AUTH, array('key' => ''));
OC_API::register('get', '/privatedata/getattribute/{app}/{key}', array('OC_OCS_Privatedata', 'get'), 'core', OC_API::USER_AUTH);
OC_API::register('post', '/privatedata/setattribute/{app}/{key}', array('OC_OCS_Privatedata', 'set'), 'core', OC_API::USER_AUTH);
OC_API::register('post', '/privatedata/deleteattribute/{app}/{key}', array('OC_OCS_Privatedata', 'delete'), 'core', OC_API::USER_AUTH);
// cloud
OC_API::register('get', '/cloud/capabilities', array('OC_OCS_Cloud', 'getCapabilities'), 'core', OC_API::USER_AUTH);
OC_API::register('get', '/cloud/users/{userid}', array('OC_OCS_Cloud', 'getUser'), 'core', OC_API::USER_AUTH);
OC_API::register('get', '/cloud/user', array('OC_OCS_Cloud', 'getCurrentUser'), 'core', OC_API::USER_AUTH);
Beispiel #14
0
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License, version 3,
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */
// Config
OC_API::register('get', '/config', array('OC_OCS_Config', 'apiConfig'), 'core', OC_API::GUEST_AUTH);
// Person
OC_API::register('post', '/person/check', array('OC_OCS_Person', 'check'), 'core', OC_API::GUEST_AUTH);
// Privatedata
OC_API::register('get', '/privatedata/getattribute', array('OC_OCS_Privatedata', 'get'), 'core', OC_API::USER_AUTH, array('app' => '', 'key' => ''));
OC_API::register('get', '/privatedata/getattribute/{app}', array('OC_OCS_Privatedata', 'get'), 'core', OC_API::USER_AUTH, array('key' => ''));
OC_API::register('get', '/privatedata/getattribute/{app}/{key}', array('OC_OCS_Privatedata', 'get'), 'core', OC_API::USER_AUTH);
OC_API::register('post', '/privatedata/setattribute/{app}/{key}', array('OC_OCS_Privatedata', 'set'), 'core', OC_API::USER_AUTH);
OC_API::register('post', '/privatedata/deleteattribute/{app}/{key}', array('OC_OCS_Privatedata', 'delete'), 'core', OC_API::USER_AUTH);
// cloud
OC_API::register('get', '/cloud/capabilities', array('OC_OCS_Cloud', 'getCapabilities'), 'core', OC_API::USER_AUTH);
OC_API::register('get', '/cloud/users/{userid}', array('OC_OCS_Cloud', 'getUser'), 'core', OC_API::USER_AUTH);
OC_API::register('get', '/cloud/user', array('OC_OCS_Cloud', 'getCurrentUser'), 'core', OC_API::USER_AUTH);
// Server-to-Server Sharing
$s2s = new \OCA\Files_Sharing\API\Server2Server();
OC_API::register('post', '/cloud/shares', array($s2s, 'createShare'), 'files_sharing', OC_API::GUEST_AUTH);
OC_API::register('post', '/cloud/shares/{id}/accept', array($s2s, 'acceptShare'), 'files_sharing', OC_API::GUEST_AUTH);
OC_API::register('post', '/cloud/shares/{id}/decline', array($s2s, 'declineShare'), 'files_sharing', OC_API::GUEST_AUTH);
OC_API::register('post', '/cloud/shares/{id}/unshare', array($s2s, 'unshare'), 'files_sharing', OC_API::GUEST_AUTH);
Beispiel #15
0
 public static function notFound()
 {
     $format = OC_API::requestedFormat();
     $txt = 'Invalid query, please check the syntax. API specifications are here:' . ' http://www.freedesktop.org/wiki/Specifications/open-collaboration-services. DEBUG OUTPUT:' . "\n";
     $txt .= OC_OCS::getDebugOutput();
     OC_API::respond(new OC_OCS_Result(null, API::RESPOND_UNKNOWN_ERROR, $txt), $format);
 }
Beispiel #16
0
 /**
  * @dataProvider providesStatusCodes
  */
 public function testStatusCodeMapper($expected, $sc)
 {
     $result = OC_API::mapStatusCodes($sc);
     $this->assertEquals($expected, $result);
 }
Beispiel #17
0
<?php

/**
 * Copyright (c) 2012, Tom Needham <*****@*****.**>
 * This file is licensed under the Affero General Public License version 3 or later.
 * See the COPYING-README file.
 */
// Config
OC_API::register('get', '/config', array('OC_OCS_Config', 'apiConfig'), 'core', OC_API::GUEST_AUTH);
// Person
OC_API::register('post', '/person/check', array('OC_OCS_Person', 'check'), 'core', OC_API::GUEST_AUTH);
// Activity
OC_API::register('get', '/activity', array('OC_OCS_Activity', 'activityGet'), 'core', OC_API::USER_AUTH);
// Privatedata
OC_API::register('get', '/privatedata/getattribute', array('OC_OCS_Privatedata', 'get'), 'core', OC_API::USER_AUTH, array('app' => '', 'key' => ''));
OC_API::register('get', '/privatedata/getattribute/{app}', array('OC_OCS_Privatedata', 'get'), 'core', OC_API::USER_AUTH, array('key' => ''));
OC_API::register('get', '/privatedata/getattribute/{app}/{key}', array('OC_OCS_Privatedata', 'get'), 'core', OC_API::USER_AUTH);
OC_API::register('post', '/privatedata/setattribute/{app}/{key}', array('OC_OCS_Privatedata', 'set'), 'core', OC_API::USER_AUTH);
OC_API::register('post', '/privatedata/deleteattribute/{app}/{key}', array('OC_OCS_Privatedata', 'delete'), 'core', OC_API::USER_AUTH);
// cloud
OC_API::register('get', '/cloud/capabilities', array('OC_OCS_Cloud', 'getCapabilities'), 'core', OC_API::USER_AUTH);
Beispiel #18
0
<?php

namespace OCA\Files_Sharing\AppInfo;

use OCA\Files_Sharing\Application;
$application = new Application();
$application->registerRoutes($this, ['resources' => ['ExternalShares' => ['url' => '/api/externalShares']]]);
/** @var $this \OCP\Route\IRouter */
$this->create('core_ajax_public_preview', '/publicpreview')->action(function () {
    require_once __DIR__ . '/../ajax/publicpreview.php';
});
$this->create('files_sharing_ajax_list', 'ajax/list.php')->actionInclude('files_sharing/ajax/list.php');
$this->create('files_sharing_ajax_publicpreview', 'ajax/publicpreview.php')->actionInclude('files_sharing/ajax/publicpreview.php');
$this->create('sharing_external_shareinfo', '/shareinfo')->actionInclude('files_sharing/ajax/shareinfo.php');
$this->create('sharing_external_add', '/external')->actionInclude('files_sharing/ajax/external.php');
$this->create('sharing_external_test_remote', '/testremote')->actionInclude('files_sharing/ajax/testremote.php');
// OCS API
//TODO: SET: mail notification, waiting for PR #4689 to be accepted
\OC_API::register('get', '/apps/files_sharing/api/v1/shares', array('\\OCA\\Files_Sharing\\API\\Local', 'getAllShares'), 'files_sharing');
\OC_API::register('post', '/apps/files_sharing/api/v1/shares', array('\\OCA\\Files_Sharing\\API\\Local', 'createShare'), 'files_sharing');
\OC_API::register('get', '/apps/files_sharing/api/v1/shares/{id}', array('\\OCA\\Files_Sharing\\API\\Local', 'getShare'), 'files_sharing');
\OC_API::register('put', '/apps/files_sharing/api/v1/shares/{id}', array('\\OCA\\Files_Sharing\\API\\Local', 'updateShare'), 'files_sharing');
\OC_API::register('delete', '/apps/files_sharing/api/v1/shares/{id}', array('\\OCA\\Files_Sharing\\API\\Local', 'deleteShare'), 'files_sharing');
Beispiel #19
0
* ownCloud
*
* @author Frank Karlitschek
* @copyright 2012 Frank Karlitschek frank@owncloud.org
*
* 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/>.
*
*/
require_once '../lib/base.php';
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
try {
    OC::getRouter()->match('/ocs' . OC_Request::getRawPathInfo());
} catch (ResourceNotFoundException $e) {
    OC_API::setContentType();
    OC_OCS::notFound();
} catch (MethodNotAllowedException $e) {
    OC_API::setContentType();
    OC_Response::setStatus(405);
}
Beispiel #20
0
<?php

/**
 * ownCloud - Activity App
 *
 * @author Frank Karlitschek
 * @copyright 2013 Frank Karlitschek frank@owncloud.org
 *
 * 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/>.
 *
 */
/** @var $this OC\Route\Router */
$this->create('activity.index', '')->actionInclude('activity/index.php');
$this->create('activity.ajax.fetch', 'ajax/fetch.php')->actionInclude('activity/ajax/fetch.php');
$this->create('activity.ajax.rssfeed', 'ajax/rssfeed.php')->actionInclude('activity/ajax/rssfeed.php');
$this->create('activity.ajax.settings', 'ajax/settings.php')->actionInclude('activity/ajax/settings.php');
$this->create('activity.rss', 'rss.php')->actionInclude('activity/rss.php');
// Register an OCS API call
OC_API::register('get', '/cloud/activity', array('OCA\\Activity\\Api', 'get'), 'activity');
Beispiel #21
0
<?php

/**
 * Copyright (c) 2013, Tom Needham <*****@*****.**>
 * This file is licensed under the Affero General Public License version 3 or later.
 * See the COPYING-README file.
 */
/** @var $this \OCP\Route\IRouter */
$this->create('core_ajax_versions_preview', '/preview')->action(function () {
    require_once __DIR__ . '/../ajax/preview.php';
});
// Register with the capabilities API
OC_API::register('get', '/cloud/capabilities', array('OCA\\Files_Versions\\Capabilities', 'getCapabilities'), 'files_versions', OC_API::USER_AUTH);
Beispiel #22
0
 /**
  * http basic auth
  * @return string|false (username, or false on failure)
  */
 private static function loginUser()
 {
     if (self::$isLoggedIn === true) {
         return \OC_User::getUser();
     }
     // reuse existing login
     $loggedIn = OC_User::isLoggedIn();
     if ($loggedIn === true) {
         $ocsApiRequest = isset($_SERVER['HTTP_OCS_APIREQUEST']) ? $_SERVER['HTTP_OCS_APIREQUEST'] === 'true' : false;
         if ($ocsApiRequest) {
             // initialize the user's filesystem
             \OC_Util::setUpFS(\OC_User::getUser());
             self::$isLoggedIn = true;
             return OC_User::getUser();
         }
         return false;
     }
     // basic auth - because OC_User::login will create a new session we shall only try to login
     // if user and pass are set
     if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
         $authUser = $_SERVER['PHP_AUTH_USER'];
         $authPw = $_SERVER['PHP_AUTH_PW'];
         try {
             $return = OC_User::login($authUser, $authPw);
         } catch (\OC\User\LoginException $e) {
             return false;
         }
         if ($return === true) {
             self::$logoutRequired = true;
             // initialize the user's filesystem
             \OC_Util::setUpFS(\OC_User::getUser());
             self::$isLoggedIn = true;
             /**
              * Add DAV authenticated. This should in an ideal world not be
              * necessary but the iOS App reads cookies from anywhere instead
              * only the DAV endpoint.
              * This makes sure that the cookies will be valid for the whole scope
              * @see https://github.com/owncloud/core/issues/22893
              */
             \OC::$server->getSession()->set(\OCA\DAV\Connector\Sabre\Auth::DAV_AUTHENTICATED, \OC::$server->getUserSession()->getUser()->getUID());
             return \OC_User::getUser();
         }
     }
     return false;
 }
Beispiel #23
0
 /**
  * http basic auth
  * @return string|false (username, or false on failure)
  */
 private static function loginUser()
 {
     if (self::$isLoggedIn === true) {
         return \OC_User::getUser();
     }
     // reuse existing login
     $loggedIn = OC_User::isLoggedIn();
     if ($loggedIn === true) {
         $ocsApiRequest = isset($_SERVER['HTTP_OCS_APIREQUEST']) ? $_SERVER['HTTP_OCS_APIREQUEST'] === 'true' : false;
         if ($ocsApiRequest) {
             // initialize the user's filesystem
             \OC_Util::setUpFS(\OC_User::getUser());
             self::$isLoggedIn = true;
             return OC_User::getUser();
         }
         return false;
     }
     // basic auth - because OC_User::login will create a new session we shall only try to login
     // if user and pass are set
     if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
         $authUser = $_SERVER['PHP_AUTH_USER'];
         $authPw = $_SERVER['PHP_AUTH_PW'];
         $return = OC_User::login($authUser, $authPw);
         if ($return === true) {
             self::$logoutRequired = true;
             // initialize the user's filesystem
             \OC_Util::setUpFS(\OC_User::getUser());
             self::$isLoggedIn = true;
             return \OC_User::getUser();
         }
     }
     return false;
 }
Beispiel #24
0
 /**
  * http basic auth
  * @return string|false (username, or false on failure)
  */
 private static function loginUser()
 {
     if (self::$isLoggedIn === true) {
         return \OC_User::getUser();
     }
     // reuse existing login
     $loggedIn = \OC::$server->getUserSession()->isLoggedIn();
     if ($loggedIn === true) {
         if (\OC::$server->getTwoFactorAuthManager()->needsSecondFactor()) {
             // Do not allow access to OCS until the 2FA challenge was solved successfully
             return false;
         }
         $ocsApiRequest = isset($_SERVER['HTTP_OCS_APIREQUEST']) ? $_SERVER['HTTP_OCS_APIREQUEST'] === 'true' : false;
         if ($ocsApiRequest) {
             // initialize the user's filesystem
             \OC_Util::setupFS(\OC_User::getUser());
             self::$isLoggedIn = true;
             return OC_User::getUser();
         }
         return false;
     }
     // basic auth - because OC_User::login will create a new session we shall only try to login
     // if user and pass are set
     $userSession = \OC::$server->getUserSession();
     $request = \OC::$server->getRequest();
     try {
         $loginSuccess = $userSession->tryTokenLogin($request);
         if (!$loginSuccess) {
             $loginSuccess = $userSession->tryBasicAuthLogin($request);
         }
     } catch (\OC\User\LoginException $e) {
         return false;
     }
     if ($loginSuccess === true) {
         self::$logoutRequired = true;
         // initialize the user's filesystem
         \OC_Util::setupFS(\OC_User::getUser());
         self::$isLoggedIn = true;
         return \OC_User::getUser();
     }
     return false;
 }