/** * Creates an absolute url for remote use. * @param string $service id * @return string the url * @since 4.0.0 */ public static function linkToRemote($service) { return \OC_Helper::linkToRemote($service); }
// Check for autosetup: $autosetup_file = OC::$SERVERROOT . "/config/autoconfig.php"; if (file_exists($autosetup_file)) { OC_Log::write('core', 'Autoconfig file found, setting up owncloud...', OC_Log::INFO); include $autosetup_file; $_POST['install'] = 'true'; $_POST = array_merge($_POST, $AUTOCONFIG); unlink($autosetup_file); } OC_Util::addScript('setup'); require_once 'setup.php'; exit; } // Handle WebDAV if ($_SERVER['REQUEST_METHOD'] == 'PROPFIND') { header('location: ' . OC_Helper::linkToRemote('webdav')); exit; } elseif (!OC_User::isLoggedIn() && substr(OC::$REQUESTEDFILE, -3) == 'css') { OC_App::loadApps(); OC::loadfile(); } elseif (OC_User::isLoggedIn()) { OC_App::loadApps(); if (isset($_GET["logout"]) and $_GET["logout"]) { OC_User::logout(); header("Location: " . OC::$WEBROOT . '/'); exit; } else { if (is_null(OC::$REQUESTEDFILE)) { OC::loadapp(); } else { OC::loadfile();
/** * test if webDAV is working properly * * @return bool * @description * The basic assumption is that if the server returns 401/Not Authenticated for an unauthenticated PROPFIND * the web server it self is setup properly. * * Why not an authenticated PROPFIND and other verbs? * - We don't have the password available * - We have no idea about other auth methods implemented (e.g. OAuth with Bearer header) * */ public static function isWebDAVWorking() { if (!function_exists('curl_init')) { return true; } if (!\OC_Config::getValue("check_for_working_webdav", true)) { return true; } $settings = array('baseUri' => OC_Helper::linkToRemote('webdav')); $client = new \OC_DAVClient($settings); $client->setRequestTimeout(10); // for this self test we don't care if the ssl certificate is self signed and the peer cannot be verified. $client->setVerifyPeer(false); // also don't care if the host can't be verified $client->setVerifyHost(0); $return = true; try { // test PROPFIND $client->propfind('', array('{DAV:}resourcetype')); } catch (\Sabre\DAV\Exception\NotAuthenticated $e) { $return = true; } catch (\Exception $e) { OC_Log::write('core', 'isWebDAVWorking: NO - Reason: ' . $e->getMessage() . ' (' . get_class($e) . ')', OC_Log::WARN); $return = false; } return $return; }
/** * @small * test linkToRemote URL construction */ public function testLinkToRemote() { \OC::$WEBROOT = ''; $result = \OC_Helper::linkToRemote('webdav'); $this->assertEquals('http://localhost/remote.php/webdav/', $result); $result = \OC_Helper::linkToRemote('webdav', false); $this->assertEquals('http://localhost/remote.php/webdav', $result); \OC::$WEBROOT = '/owncloud'; $result = \OC_Helper::linkToRemote('webdav'); $this->assertEquals('http://localhost/owncloud/remote.php/webdav/', $result); $result = \OC_Helper::linkToRemote('webdav', false); $this->assertEquals('http://localhost/owncloud/remote.php/webdav', $result); }
/** * @brief Handle the request */ public static function handleRequest() { // 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 (!OC_Config::getValue('installed', false)) { require_once 'core/setup.php'; exit; } $request = OC_Request::getPathInfo(); if (substr($request, -3) !== '.js') { // we need these files during the upgrade self::checkMaintenanceMode(); self::checkUpgrade(); } if (!self::$CLI) { try { if (!OC_Config::getValue('maintenance', false)) { OC_App::loadApps(); } OC::getRouter()->match(OC_Request::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; } } $app = OC::$REQUESTEDAPP; $file = OC::$REQUESTEDFILE; $param = array('app' => $app, 'file' => $file); // Handle app css files if (substr($file, -3) == 'css') { self::loadCSSFile($param); return; } // Handle redirect URL for logged in users if (isset($_REQUEST['redirect_url']) && OC_User::isLoggedIn()) { $location = OC_Helper::makeURLAbsolute(urldecode($_REQUEST['redirect_url'])); // Deny the redirect if the URL contains a @ // This prevents unvalidated redirects like ?redirect_url=:user@domain.com if (strpos($location, '@') === FALSE) { header('Location: ' . $location); return; } } // Handle WebDAV if ($_SERVER['REQUEST_METHOD'] == 'PROPFIND') { header('location: ' . OC_Helper::linkToRemote('webdav')); return; } // Someone is logged in : if (OC_User::isLoggedIn()) { OC_App::loadApps(); OC_User::setupBackends(); if (isset($_GET["logout"]) and $_GET["logout"]) { if (isset($_COOKIE['oc_token'])) { OC_Preferences::deleteKey(OC_User::getUser(), 'login_token', $_COOKIE['oc_token']); } OC_User::logout(); header("Location: " . OC::$WEBROOT . '/'); } else { if (is_null($file)) { $param['file'] = 'index.php'; } $file_ext = substr($param['file'], -3); if ($file_ext != 'php' || !self::loadAppScriptFile($param)) { header('HTTP/1.0 404 Not Found'); } } return; } // Not handled and not logged in self::handleLogin(); }
} ?> </ul> <div id="app-settings"> <div id="app-settings-header"> <button class="settings-button" data-apps-slide-toggle="#app-settings-content"> <span class="hidden-visually"><?php p($l->t('Settings')); ?> </span> </button> </div> <div id="app-settings-content"> <h2> <label for="webdavurl"><?php p($l->t('WebDAV')); ?> </label> </h2> <input id="webdavurl" type="text" readonly="readonly" value="<?php p(OC_Helper::linkToRemote('webdav')); ?> " /> <em><?php print_unescaped($l->t('Use this address to <a href="%s" target="_blank">access your Files via WebDAV</a>', array(link_to_docs('user-webdav')))); ?> </em> </div> </div> </div>
?> </select> <a href="https://www.transifex.net/projects/p/owncloud/team/<?php echo $_['languages'][0]['code']; ?> /" target="_blank"><em><?php echo $l->t('Help translate'); ?> </em></a> </fieldset> </form> <p class="personalblock"> <strong>WebDAV</strong> <code><?php echo OC_Helper::linkToRemote('webdav'); ?> </code><br /> <em><?php echo $l->t('use this address to connect to your ownCloud in your file manager'); ?> </em> </p> <?php foreach ($_['forms'] as $form) { echo $form; } ?>
public function __construct($renderas) { // Decide which page we show if ($renderas == 'user') { parent::__construct('core', 'layout.user'); $this->assign('searchurl', OC_Helper::linkTo('search', 'index.php'), false); if (array_search(OC_APP::getCurrentApp(), array('settings', 'admin', 'help')) !== false) { $this->assign('bodyid', 'body-settings', false); } else { $this->assign('bodyid', 'body-user', false); } // Add navigation entry $navigation = OC_App::getNavigation(); $this->assign('navigation', $navigation, false); $this->assign('settingsnavigation', OC_App::getSettingsNavigation(), false); foreach ($navigation as $entry) { if ($entry['active']) { $this->assign('application', $entry['name'], false); break; } } } else { if ($renderas == 'guest') { parent::__construct('core', 'layout.guest'); } else { parent::__construct('core', 'layout.base'); } } $apps_paths = array(); foreach (OC_App::getEnabledApps() as $app) { $apps_paths[$app] = OC_App::getAppWebPath($app); } $this->assign('apps_paths', str_replace('\\/', '/', json_encode($apps_paths)), false); // Ugly unescape slashes waiting for better solution if (OC_Config::getValue('installed', false) && !OC_AppConfig::getValue('core', 'remote_core.css', false)) { OC_AppConfig::setValue('core', 'remote_core.css', '/core/minimizer.php'); OC_AppConfig::setValue('core', 'remote_core.js', '/core/minimizer.php'); } // Add the js files $jsfiles = self::findJavascriptFiles(OC_Util::$scripts); $this->assign('jsfiles', array(), false); if (!empty(OC_Util::$core_scripts)) { $this->append('jsfiles', OC_Helper::linkToRemote('core.js', false)); } foreach ($jsfiles as $info) { $root = $info[0]; $web = $info[1]; $file = $info[2]; $this->append('jsfiles', $web . '/' . $file); } // Add the css files $cssfiles = self::findStylesheetFiles(OC_Util::$styles); $this->assign('cssfiles', array()); if (!empty(OC_Util::$core_styles)) { $this->append('cssfiles', OC_Helper::linkToRemote('core.css', false)); } foreach ($cssfiles as $info) { $root = $info[0]; $web = $info[1]; $file = $info[2]; $paths = explode('/', $file); $in_root = false; foreach (OC::$APPSROOTS as $app_root) { if ($root == $app_root['path']) { $in_root = true; break; } } if ($in_root) { $app = $paths[0]; unset($paths[0]); $path = implode('/', $paths); $this->append('cssfiles', OC_Helper::linkTo($app, $path)); } else { $this->append('cssfiles', $web . '/' . $file); } } }
/** * @brief Handle the request */ public static function handleRequest() { if (!OC_Config::getValue('installed', false)) { // Check for autosetup: $autosetup_file = OC::$SERVERROOT . "/config/autoconfig.php"; if (file_exists($autosetup_file)) { OC_Log::write('core', 'Autoconfig file found, setting up owncloud...', OC_Log::INFO); include $autosetup_file; $_POST['install'] = 'true'; $_POST = array_merge($_POST, $AUTOCONFIG); unlink($autosetup_file); } OC_Util::addScript('setup'); require_once 'setup.php'; exit; } // Handle WebDAV if ($_SERVER['REQUEST_METHOD'] == 'PROPFIND') { header('location: ' . OC_Helper::linkToRemote('webdav')); return; } // Handle app css files if (substr(OC::$REQUESTEDFILE, -3) == 'css') { self::loadCSSFile(); return; } // Someone is logged in : if (OC_User::isLoggedIn()) { OC_App::loadApps(); OC_User::setupBackends(); if (isset($_GET["logout"]) and $_GET["logout"]) { OC_User::logout(); header("Location: " . OC::$WEBROOT . '/'); } else { $app = OC::$REQUESTEDAPP; $file = OC::$REQUESTEDFILE; if (is_null($file)) { $file = 'index.php'; } $file_ext = substr($file, -3); if ($file_ext != 'php' || !self::loadAppScriptFile($app, $file)) { header('HTTP/1.0 404 Not Found'); } } return; } // Not handled and not logged in self::handleLogin(); }
?> </em> </a> <?php } ?> </fieldset> </form> <fieldset class="personalblock"> <h2><?php p($l->t('WebDAV')); ?> </h2> <code><?php print_unescaped(OC_Helper::linkToRemote('webdav')); ?> </code><br /> <em><?php print_unescaped($l->t('Use this address to <a href="%s" target="_blank">access your Files via WebDAV</a>', array(link_to_docs('user-webdav')))); ?> </em> </fieldset> <?php foreach ($_['forms'] as $form) { print_unescaped($form); } ?> <?php
/** * we test if webDAV is working properly * * The basic assumption is that if the server returns 401/Not Authenticated for an unauthenticated PROPFIND * the web server it self is setup properly. * * Why not an authenticated PROFIND and other verbs? * - We don't have the password available * - We have no idea about other auth methods implemented (e.g. OAuth with Bearer header) * */ public static function isWebDAVWorking() { if (!function_exists('curl_init')) { return true; } $settings = array('baseUri' => OC_Helper::linkToRemote('webdav')); // save the old timeout so that we can restore it later $old_timeout = ini_get("default_socket_timeout"); // use a 5 sec timeout for the check. Should be enough for local requests. ini_set("default_socket_timeout", 5); $client = new \Sabre_DAV_Client($settings); // for this self test we don't care if the ssl certificate is self signed and the peer cannot be verified. $client->setVerifyPeer(false); $return = true; try { // test PROPFIND $client->propfind('', array('{DAV:}resourcetype')); } catch (\Sabre_DAV_Exception_NotAuthenticated $e) { $return = true; } catch (\Exception $e) { OC_Log::write('core', 'isWebDAVWorking: NO - Reason: ' . $e, OC_Log::WARN); $return = false; } // restore the original timeout ini_set("default_socket_timeout", $old_timeout); return $return; }
/** * @brief Handle the request */ public static function handleRequest() { if (!OC_Config::getValue('installed', false)) { require_once 'core/setup.php'; exit; } // Handle WebDAV if ($_SERVER['REQUEST_METHOD'] == 'PROPFIND') { header('location: ' . OC_Helper::linkToRemote('webdav')); return; } try { OC_App::loadApps(); OC::getRouter()->match(OC_Request::getPathInfo()); 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; } $app = OC::$REQUESTEDAPP; $file = OC::$REQUESTEDFILE; $param = array('app' => $app, 'file' => $file); // Handle app css files if (substr($file, -3) == 'css') { self::loadCSSFile($param); return; } // Someone is logged in : if (OC_User::isLoggedIn()) { OC_App::loadApps(); OC_User::setupBackends(); if (isset($_GET["logout"]) and $_GET["logout"]) { OC_Preferences::deleteKey(OC_User::getUser(), 'login_token', $_COOKIE['oc_token']); OC_User::logout(); header("Location: " . OC::$WEBROOT . '/'); } else { if (is_null($file)) { $param['file'] = 'index.php'; } $file_ext = substr($param['file'], -3); if ($file_ext != 'php' || !self::loadAppScriptFile($param)) { header('HTTP/1.0 404 Not Found'); } } return; } // Not handled and not logged in self::handleLogin(); }