Blame view

sources/remote.php 1.47 KB
03e52840d   Kload   Init
1
  <?php
03e52840d   Kload   Init
2

31b7f2792   Kload   Upgrade to ownclo...
3
  try {
31b7f2792   Kload   Upgrade to ownclo...
4
  	require_once 'lib/base.php';
6d9380f96   Cédric Dupont   Update sources OC...
5
6
7
8
9
10
11
12
  
  	if (\OCP\Util::needUpgrade()) {
  		// since the behavior of apps or remotes are unpredictable during
  		// an upgrade, return a 503 directly
  		OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE);
  		OC_Template::printErrorPage('Service unavailable');
  		exit;
  	}
31b7f2792   Kload   Upgrade to ownclo...
13
14
15
16
17
18
19
20
21
  	$path_info = OC_Request::getPathInfo();
  	if ($path_info === false || $path_info === '') {
  		OC_Response::setStatus(OC_Response::STATUS_NOT_FOUND);
  		exit;
  	}
  	if (!$pos = strpos($path_info, '/', 1)) {
  		$pos = strlen($path_info);
  	}
  	$service=substr($path_info, 1, $pos-1);
6d9380f96   Cédric Dupont   Update sources OC...
22
  	$file = \OC::$server->getAppConfig()->getValue('core', 'remote_' . $service);
31b7f2792   Kload   Upgrade to ownclo...
23
24
25
26
27
28
29
  
  	if(is_null($file)) {
  		OC_Response::setStatus(OC_Response::STATUS_NOT_FOUND);
  		exit;
  	}
  
  	$file=ltrim($file, '/');
03e52840d   Kload   Init
30

31b7f2792   Kload   Upgrade to ownclo...
31
32
  	$parts=explode('/', $file, 2);
  	$app=$parts[0];
6d9380f96   Cédric Dupont   Update sources OC...
33
34
35
36
37
  
  	// Load all required applications
  	\OC::$REQUESTEDAPP = $app;
  	OC_App::loadApps(array('authentication'));
  	OC_App::loadApps(array('filesystem', 'logging'));
31b7f2792   Kload   Upgrade to ownclo...
38
39
40
41
42
43
44
  	switch ($app) {
  		case 'core':
  			$file =  OC::$SERVERROOT .'/'. $file;
  			break;
  		default:
  			OC_Util::checkAppEnabled($app);
  			OC_App::loadApp($app);
6d9380f96   Cédric Dupont   Update sources OC...
45
  			$file = OC_App::getAppPath($app) .'/'. $parts[1];
31b7f2792   Kload   Upgrade to ownclo...
46
47
48
49
  			break;
  	}
  	$baseuri = OC::$WEBROOT . '/remote.php/'.$service.'/';
  	require_once $file;
03e52840d   Kload   Init
50

31b7f2792   Kload   Upgrade to ownclo...
51
52
53
54
  } catch (Exception $ex) {
  	OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR);
  	\OCP\Util::writeLog('remote', $ex->getMessage(), \OCP\Util::FATAL);
  	OC_Template::printExceptionErrorPage($ex);
03e52840d   Kload   Init
55
  }