base.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Frank Karlitschek
  6. * @copyright 2012 Frank Karlitschek frank@owncloud.org
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * Class that is a namespace for all global OC variables
  24. * No, we can not put this class in its own file because it is used by
  25. * OC_autoload!
  26. */
  27. class OC{
  28. /**
  29. * Assoziative array for autoloading. classname => filename
  30. */
  31. public static $CLASSPATH = array();
  32. /**
  33. * The installation path for owncloud on the server (e.g. /srv/http/owncloud)
  34. */
  35. public static $SERVERROOT = '';
  36. /**
  37. * the current request path relative to the owncloud root (e.g. files/index.php)
  38. */
  39. private static $SUBURI = '';
  40. /**
  41. * the owncloud root path for http requests (e.g. owncloud/)
  42. */
  43. public static $WEBROOT = '';
  44. /**
  45. * The installation path of the 3rdparty folder on the server (e.g. /srv/http/owncloud/3rdparty)
  46. */
  47. public static $THIRDPARTYROOT = '';
  48. /**
  49. * the root path of the 3rdparty folder for http requests (e.g. owncloud/3rdparty)
  50. */
  51. public static $THIRDPARTYWEBROOT = '';
  52. /**
  53. * The installation path array of the apps folder on the server (e.g. /srv/http/owncloud) 'path' and web path in 'url'
  54. */
  55. public static $APPSROOTS = array();
  56. /*
  57. * requested app
  58. */
  59. public static $REQUESTEDAPP = '';
  60. /*
  61. * requested file of app
  62. */
  63. public static $REQUESTEDFILE = '';
  64. /**
  65. * check if owncloud runs in cli mode
  66. */
  67. public static $CLI = false;
  68. /**
  69. * SPL autoload
  70. */
  71. public static function autoload($className){
  72. if(array_key_exists($className, OC::$CLASSPATH)) {
  73. /** @TODO: Remove this when necessary
  74. Remove "apps/" from inclusion path for smooth migration to mutli app dir
  75. */
  76. $path = preg_replace('/apps\//', '', OC::$CLASSPATH[$className]);
  77. require_once $path;
  78. }
  79. elseif(strpos($className, 'OC_')===0) {
  80. $path = strtolower(str_replace('_', '/', substr($className,3)) . '.php');
  81. }
  82. elseif(strpos($className, 'OCP\\')===0) {
  83. $path = 'public/'.strtolower(str_replace('\\',' /',s ubstr($className,3)) . '.php');
  84. }
  85. elseif(strpos($className, 'OCA\\')===0) {
  86. $path = 'apps/'.strtolower(str_replace('\\', '/', substr($className,3)) . '.php');
  87. }
  88. elseif(strpos($className, 'Sabre_')===0) {
  89. $path = str_replace('_', '/', $className) . '.php';
  90. }
  91. elseif(strpos($className,'Test_')===0) {
  92. $path = 'tests/lib/'.strtolower(str_replace('_', '/', substr($className,5 )) . '.php');
  93. }else{
  94. return false;
  95. }
  96. if($fullPath = stream_resolve_include_path($path)) {
  97. require_once $path;
  98. }
  99. return false;
  100. }
  101. public static function initPaths(){
  102. // calculate the root directories
  103. OC::$SERVERROOT=str_replace("\\", '/', substr(__FILE__, 0, -13));
  104. OC::$SUBURI= str_replace("\\", "/", substr(realpath($_SERVER["SCRIPT_FILENAME"]), strlen(OC::$SERVERROOT)));
  105. $scriptName=$_SERVER["SCRIPT_NAME"];
  106. if(substr($scriptName, -1)=='/') {
  107. $scriptName.='index.php';
  108. //make sure suburi follows the same rules as scriptName
  109. if(substr(OC::$SUBURI, -9)!='index.php') {
  110. if(substr(OC::$SUBURI,-1)!='/' {
  111. OC::$SUBURI=OC::$SUBURI.'/';
  112. }
  113. OC::$SUBURI=OC::$SUBURI.'index.php';
  114. }
  115. }
  116. OC::$WEBROOT=substr($scriptName, 0, strlen($scriptName)-strlen(OC::$SUBURI));
  117. if(OC::$WEBROOT!='' and OC::$WEBROOT[0]!=='/') {
  118. OC::$WEBROOT='/'.OC::$WEBROOT;
  119. }
  120. // ensure we can find OC_Config
  121. set_include_path(
  122. OC::$SERVERROOT.'/lib'.PATH_SEPARATOR.
  123. get_include_path()
  124. );
  125. // search the 3rdparty folder
  126. if(OC_Config::getValue('3rdpartyroot', '')<>'' and OC_Config::getValue('3rdpartyurl', '')<>'') {
  127. OC::$THIRDPARTYROOT=OC_Config::getValue('3rdpartyroot', '');
  128. OC::$THIRDPARTYWEBROOT=OC_Config::getValue('3rdpartyurl', '');
  129. }elseif(file_exists(OC::$SERVERROOT.'/3rdparty')) {
  130. OC::$THIRDPARTYROOT=OC::$SERVERROOT;
  131. OC::$THIRDPARTYWEBROOT=OC::$WEBROOT;
  132. }elseif(file_exists(OC::$SERVERROOT.'/../3rdparty')) {
  133. OC::$THIRDPARTYWEBROOT=rtrim(dirname(OC::$WEBROOT), '/');
  134. OC::$THIRDPARTYROOT=rtrim(dirname(OC::$SERVERROOT), '/');
  135. }else{
  136. echo("3rdparty directory not found! Please put the ownCloud 3rdparty folder in the ownCloud folder or the folder above. You can also configure the location in the config.php file.");
  137. exit;
  138. }
  139. // search the apps folder
  140. $config_paths = OC_Config::getValue('apps_paths', array());
  141. if(! empty($config_paths)) {
  142. foreach($config_paths as $paths) {
  143. if( isset($paths['url']) && isset($paths['path'])) {
  144. $paths['url'] = rtrim($paths['url'], '/');
  145. $paths['path'] = rtrim($paths['path'], '/');
  146. OC::$APPSROOTS[] = $paths;
  147. }
  148. }
  149. }elseif(file_exists(OC::$SERVERROOT.'/apps')) {
  150. OC::$APPSROOTS[] = array('path'=> OC::$SERVERROOT.'/apps', 'url' => '/apps', 'writable' => true);
  151. }elseif(file_exists(OC::$SERVERROOT.'/../apps')) {
  152. OC::$APPSROOTS[] = array('path'=> rtrim(dirname(OC::$SERVERROOT), '/').'/apps', 'url' => '/apps', 'writable' => true);
  153. }
  154. if(empty(OC::$APPSROOTS)) {
  155. echo("apps directory not found! Please put the ownCloud apps folder in the ownCloud folder or the folder above. You can also configure the location in the config.php file.");
  156. exit;
  157. }
  158. $paths = array();
  159. foreach( OC::$APPSROOTS as $path)
  160. $paths[] = $path['path'];
  161. // set the right include path
  162. set_include_path(
  163. OC::$SERVERROOT.'/lib'.PATH_SEPARATOR.
  164. OC::$SERVERROOT.'/config'.PATH_SEPARATOR.
  165. OC::$THIRDPARTYROOT.'/3rdparty'.PATH_SEPARATOR.
  166. implode($paths,PATH_SEPARATOR).PATH_SEPARATOR.
  167. get_include_path().PATH_SEPARATOR.
  168. OC::$SERVERROOT
  169. );
  170. }
  171. public static function checkInstalled() {
  172. // Redirect to installer if not installed
  173. if (!OC_Config::getValue('installed', false) && OC::$SUBURI != '/index.php') {
  174. if(!OC::$CLI) {
  175. $url = 'http://'.$_SERVER['SERVER_NAME'].OC::$WEBROOT.'/index.php';
  176. header("Location: $url");
  177. }
  178. exit();
  179. }
  180. }
  181. public static function checkSSL() {
  182. // redirect to https site if configured
  183. if( OC_Config::getValue( "forcessl", false )) {
  184. ini_set("session.cookie_secure", "on");
  185. if(OC_Request::serverProtocol()<>'https' and !OC::$CLI) {
  186. $url = "https://". OC_Request::serverHost() . $_SERVER['REQUEST_URI'];
  187. header("Location: $url");
  188. exit();
  189. }
  190. }
  191. }
  192. public static function checkUpgrade() {
  193. if(OC_Config::getValue('installed', false)) {
  194. $installedVersion=OC_Config::getValue('version', '0.0.0');
  195. $currentVersion=implode('.', OC_Util::getVersion());
  196. if (version_compare($currentVersion, $installedVersion, '>')) {
  197. OC_Log::write('core', 'starting upgrade from '.$installedVersion.' to '.$currentVersion, OC_Log::DEBUG);
  198. $result=OC_DB::updateDbFromStructure(OC::$SERVERROOT.'/db_structure.xml');
  199. if(!$result) {
  200. echo 'Error while upgrading the database';
  201. die();
  202. }
  203. if(file_exists(OC::$SERVERROOT."/config/config.php") and !is_writable(OC::$SERVERROOT."/config/config.php")) {
  204. $tmpl = new OC_Template( '', 'error', 'guest' );
  205. $tmpl->assign('errors', array(1=>array('error'=>"Can't write into config directory 'config'",'hint'=>"You can usually fix this by giving the webserver user write access to the config directory in owncloud")));
  206. $tmpl->printPage();
  207. exit;
  208. }
  209. OC_Config::setValue('version', implode('.', OC_Util::getVersion()));
  210. OC_App::checkAppsRequirements();
  211. // load all apps to also upgrade enabled apps
  212. OC_App::loadApps();
  213. }
  214. }
  215. }
  216. public static function initTemplateEngine() {
  217. // Add the stuff we need always
  218. OC_Util::addScript( "jquery-1.7.2.min" );
  219. OC_Util::addScript( "jquery-ui-1.8.16.custom.min" );
  220. OC_Util::addScript( "jquery-showpassword" );
  221. OC_Util::addScript( "jquery.infieldlabel.min" );
  222. OC_Util::addScript( "jquery-tipsy" );
  223. OC_Util::addScript( "oc-dialogs" );
  224. OC_Util::addScript( "js" );
  225. OC_Util::addScript( "eventsource" );
  226. OC_Util::addScript( "config" );
  227. //OC_Util::addScript( "multiselect" );
  228. OC_Util::addScript('search', 'result');
  229. if( OC_Config::getValue( 'installed', false )){
  230. if( OC_Appconfig::getValue( 'core', 'backgroundjobs_mode', 'ajax' ) == 'ajax' ) {
  231. OC_Util::addScript( 'backgroundjobs' );
  232. }
  233. }
  234. OC_Util::addStyle( "styles" );
  235. OC_Util::addStyle( "multiselect" );
  236. OC_Util::addStyle( "jquery-ui-1.8.16.custom" );
  237. OC_Util::addStyle( "jquery-tipsy" );
  238. }
  239. public static function initSession() {
  240. ini_set('session.cookie_httponly', '1;');
  241. session_start();
  242. }
  243. public static function init(){
  244. // register autoloader
  245. spl_autoload_register(array('OC','autoload'));
  246. setlocale(LC_ALL, 'en_US.UTF-8');
  247. // set some stuff
  248. //ob_start();
  249. error_reporting(E_ALL | E_STRICT);
  250. if (defined('DEBUG') && DEBUG) {
  251. ini_set('display_errors', 1);
  252. }
  253. self::$CLI=(php_sapi_name() == 'cli');
  254. date_default_timezone_set('UTC');
  255. ini_set('arg_separator.output', '&amp;');
  256. // try to switch magic quotes off.
  257. if(function_exists('set_magic_quotes_runtime')) {
  258. @set_magic_quotes_runtime(false);
  259. }
  260. //try to configure php to enable big file uploads.
  261. //this doesn´t work always depending on the webserver and php configuration.
  262. //Let´s try to overwrite some defaults anyways
  263. //try to set the maximum execution time to 60min
  264. @set_time_limit(3600);
  265. @ini_set('max_execution_time', 3600);
  266. @ini_set('max_input_time', 3600);
  267. //try to set the maximum filesize to 10G
  268. @ini_set('upload_max_filesize', '10G');
  269. @ini_set('post_max_size', '10G');
  270. @ini_set('file_uploads', '50');
  271. //try to set the session lifetime to 60min
  272. @ini_set('gc_maxlifetime', '3600');
  273. //set http auth headers for apache+php-cgi work around
  274. if (isset($_SERVER['HTTP_AUTHORIZATION']) && preg_match('/Basic\s+(.*)$/i', $_SERVER['HTTP_AUTHORIZATION'], $matches)) {
  275. list($name, $password) = explode(':', base64_decode($matches[1]));
  276. $_SERVER['PHP_AUTH_USER'] = strip_tags($name);
  277. $_SERVER['PHP_AUTH_PW'] = strip_tags($password);
  278. }
  279. //set http auth headers for apache+php-cgi work around if variable gets renamed by apache
  280. if (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION']) && preg_match('/Basic\s+(.*)$/i', $_SERVER['REDIRECT_HTTP_AUTHORIZATION'], $matches)) {
  281. list($name, $password) = explode(':', base64_decode($matches[1]));
  282. $_SERVER['PHP_AUTH_USER'] = strip_tags($name);
  283. $_SERVER['PHP_AUTH_PW'] = strip_tags($password);
  284. }
  285. self::initPaths();
  286. // set debug mode if an xdebug session is active
  287. if (!defined('DEBUG') || !DEBUG) {
  288. if(isset($_COOKIE['XDEBUG_SESSION'])) {
  289. define('DEBUG',true);
  290. }
  291. }
  292. // register the stream wrappers
  293. require_once 'streamwrappers.php';
  294. stream_wrapper_register("fakedir", "OC_FakeDirStream");
  295. stream_wrapper_register('static', 'OC_StaticStreamWrapper');
  296. stream_wrapper_register('close', 'OC_CloseStreamWrapper');
  297. self::checkInstalled();
  298. self::checkSSL();
  299. self::initSession();
  300. self::initTemplateEngine();
  301. self::checkUpgrade();
  302. $errors=OC_Util::checkServer();
  303. if(count($errors)>0) {
  304. OC_Template::printGuestPage('', 'error', array('errors' => $errors));
  305. exit;
  306. }
  307. // User and Groups
  308. if( !OC_Config::getValue( "installed", false )) {
  309. $_SESSION['user_id'] = '';
  310. }
  311. OC_User::useBackend(new OC_User_Database());
  312. OC_Group::useBackend(new OC_Group_Database());
  313. // Load Apps
  314. // This includes plugins for users and filesystems as well
  315. global $RUNTIME_NOAPPS;
  316. global $RUNTIME_APPTYPES;
  317. if(!$RUNTIME_NOAPPS ) {
  318. if($RUNTIME_APPTYPES) {
  319. OC_App::loadApps($RUNTIME_APPTYPES);
  320. }else{
  321. OC_App::loadApps();
  322. }
  323. }
  324. //setup extra user backends
  325. OC_User::setupBackends();
  326. // register cache cleanup jobs
  327. OC_BackgroundJob_RegularTask::register('OC_Cache_FileGlobal', 'gc');
  328. OC_Hook::connect('OC_User', 'post_login', 'OC_Cache_File', 'loginListener');
  329. // Check for blacklisted files
  330. OC_Hook::connect('OC_Filesystem','write', 'OC_Filesystem', 'isBlacklisted');
  331. OC_Hook::connect('OC_Filesystem', 'rename', 'OC_Filesystem', 'isBlacklisted');
  332. //make sure temporary files are cleaned up
  333. register_shutdown_function(array('OC_Helper','cleanTmp'));
  334. //parse the given parameters
  335. 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'));
  336. if(substr_count(self::$REQUESTEDAPP, '?') != 0) {
  337. $app = substr(self::$REQUESTEDAPP, 0, strpos(self::$REQUESTEDAPP, '?'));
  338. $param = substr($_GET['app'], strpos($_GET['app'], '?') + 1);
  339. parse_str($param, $get);
  340. $_GET = array_merge($_GET, $get);
  341. self::$REQUESTEDAPP = $app;
  342. $_GET['app'] = $app;
  343. }
  344. self::$REQUESTEDFILE = (isset($_GET['getfile'])?$_GET['getfile']:null);
  345. if(substr_count(self::$REQUESTEDFILE, '?') != 0) {
  346. $file = substr(self::$REQUESTEDFILE, 0, strpos(self::$REQUESTEDFILE, '?'));
  347. $param = substr(self::$REQUESTEDFILE, strpos(self::$REQUESTEDFILE, '?') + 1);
  348. parse_str($param, $get);
  349. $_GET = array_merge($_GET, $get);
  350. self::$REQUESTEDFILE = $file;
  351. $_GET['getfile'] = $file;
  352. }
  353. if(!is_null(self::$REQUESTEDFILE)) {
  354. $subdir = OC_App::getAppPath(OC::$REQUESTEDAPP) . '/' . self::$REQUESTEDFILE;
  355. $parent = OC_App::getAppPath(OC::$REQUESTEDAPP);
  356. if(!OC_Helper::issubdirectory($subdir, $parent)) {
  357. self::$REQUESTEDFILE = null;
  358. header('HTTP/1.0 404 Not Found');
  359. exit;
  360. }
  361. }
  362. }
  363. /**
  364. * @brief Handle the request
  365. */
  366. public static function handleRequest() {
  367. if (!OC_Config::getValue('installed', false)) {
  368. // Check for autosetup:
  369. $autosetup_file = OC::$SERVERROOT."/config/autoconfig.php";
  370. if( file_exists( $autosetup_file )) {
  371. OC_Log::write('core', 'Autoconfig file found, setting up owncloud...', OC_Log::INFO);
  372. include $autosetup_file;
  373. $_POST['install'] = 'true';
  374. $_POST = array_merge ($_POST, $AUTOCONFIG);
  375. unlink($autosetup_file);
  376. }
  377. OC_Util::addScript('setup');
  378. require_once 'setup.php';
  379. exit();
  380. }
  381. // Handle WebDAV
  382. if($_SERVER['REQUEST_METHOD']=='PROPFIND') {
  383. header('location: '.OC_Helper::linkToRemote('webdav'));
  384. return;
  385. }
  386. // Handle app css files
  387. if(substr(OC::$REQUESTEDFILE, -3) == 'css') {
  388. self::loadCSSFile();
  389. return;
  390. }
  391. // Someone is logged in :
  392. if(OC_User::isLoggedIn()) {
  393. OC_App::loadApps();
  394. OC_User::setupBackends();
  395. if(isset($_GET["logout"]) and ($_GET["logout"])) {
  396. OC_User::logout();
  397. header("Location: ".OC::$WEBROOT.'/');
  398. }else{
  399. $app = OC::$REQUESTEDAPP;
  400. $file = OC::$REQUESTEDFILE;
  401. if(is_null($file)) {
  402. $file = 'index.php';
  403. }
  404. $file_ext = substr($file, -3);
  405. if ($file_ext != 'php'|| !self::loadAppScriptFile($app, $file)) {
  406. header('HTTP/1.0 404 Not Found');
  407. }
  408. }
  409. return;
  410. }
  411. // Not handled and not logged in
  412. self::handleLogin();
  413. }
  414. protected static function loadAppScriptFile($app, $file) {
  415. $app_path = OC_App::getAppPath($app);
  416. $file = $app_path . '/' . $file;
  417. unset($app, $app_path);
  418. if (file_exists($file)) {
  419. require_once $file;
  420. return true;
  421. }
  422. return false;
  423. }
  424. protected static function loadCSSFile() {
  425. $app = OC::$REQUESTEDAPP;
  426. $file = OC::$REQUESTEDFILE;
  427. $app_path = OC_App::getAppPath($app);
  428. if (file_exists($app_path . '/' . $file)) {
  429. $app_web_path = OC_App::getAppWebPath($app);
  430. $filepath = $app_web_path . '/' . $file;
  431. $minimizer = new OC_Minimizer_CSS();
  432. $info = array($app_path, $app_web_path, $file);
  433. $minimizer->output(array($info), $filepath);
  434. }
  435. }
  436. protected static function handleLogin() {
  437. OC_App::loadApps(array('prelogin'));
  438. $error = false;
  439. // remember was checked after last login
  440. if (OC::tryRememberLogin()) {
  441. // nothing more to do
  442. // Someone wants to log in :
  443. } elseif (OC::tryFormLogin()) {
  444. $error = true;
  445. // The user is already authenticated using Apaches AuthType Basic... very usable in combination with LDAP
  446. } elseif (OC::tryBasicAuthLogin()) {
  447. $error = true;
  448. }
  449. OC_Util::displayLoginPage($error);
  450. }
  451. protected static function tryRememberLogin() {
  452. if(!isset($_COOKIE["oc_remember_login"])
  453. || !isset($_COOKIE["oc_token"])
  454. || !isset($_COOKIE["oc_username"])
  455. || !$_COOKIE["oc_remember_login"])
  456. {
  457. return false;
  458. }
  459. OC_App::loadApps(array('authentication'));
  460. if(defined("DEBUG") && DEBUG) {
  461. OC_Log::write('core', 'Trying to login from cookie', OC_Log::DEBUG);
  462. }
  463. // confirm credentials in cookie
  464. if(isset($_COOKIE['oc_token']) && OC_User::userExists($_COOKIE['oc_username']) &&
  465. OC_Preferences::getValue($_COOKIE['oc_username'], "login", "token") === $_COOKIE['oc_token'])
  466. {
  467. OC_User::setUserId($_COOKIE['oc_username']);
  468. OC_Util::redirectToDefaultPage();
  469. }
  470. else {
  471. OC_User::unsetMagicInCookie();
  472. }
  473. return true;
  474. }
  475. protected static function tryFormLogin() {
  476. if(!isset($_POST["user"])
  477. || !isset($_POST['password'])
  478. || !isset($_SESSION['sectoken'])
  479. || !isset($_POST['sectoken'])
  480. || ($_SESSION['sectoken']!=$_POST['sectoken']) ) {
  481. return false;
  482. }
  483. OC_App::loadApps();
  484. //setup extra user backends
  485. OC_User::setupBackends();
  486. if(OC_User::login($_POST["user"], $_POST["password"])) {
  487. if(!empty($_POST["remember_login"])) {
  488. if(defined("DEBUG") && DEBUG) {
  489. OC_Log::write('core', 'Setting remember login to cookie', OC_Log::DEBUG);
  490. }
  491. $token = md5($_POST["user"].time().$_POST['password']);
  492. OC_Preferences::setValue($_POST['user'], 'login', 'token', $token);
  493. OC_User::setMagicInCookie($_POST["user"], $token);
  494. }
  495. else {
  496. OC_User::unsetMagicInCookie();
  497. }
  498. OC_Util::redirectToDefaultPage();
  499. }
  500. return true;
  501. }
  502. protected static function tryBasicAuthLogin() {
  503. if (!isset($_SERVER["PHP_AUTH_USER"])
  504. || !isset($_SERVER["PHP_AUTH_PW"])){
  505. return false;
  506. }
  507. OC_App::loadApps(array('authentication'));
  508. if (OC_User::login($_SERVER["PHP_AUTH_USER"],$_SERVER["PHP_AUTH_PW"])) {
  509. //OC_Log::write('core',"Logged in with HTTP Authentication",OC_Log::DEBUG);
  510. OC_User::unsetMagicInCookie();
  511. $_REQUEST['redirect_url'] = (isset($_SERVER['REQUEST_URI'])?$_SERVER['REQUEST_URI']:'');
  512. OC_Util::redirectToDefaultPage();
  513. }
  514. return true;
  515. }
  516. }
  517. // define runtime variables - unless this already has been done
  518. if( !isset( $RUNTIME_NOAPPS )) {
  519. $RUNTIME_NOAPPS = false;
  520. }
  521. if(!function_exists('get_temp_dir')) {
  522. function get_temp_dir() {
  523. if( $temp=ini_get('upload_tmp_dir') ) return $temp;
  524. if( $temp=getenv('TMP') ) return $temp;
  525. if( $temp=getenv('TEMP') ) return $temp;
  526. if( $temp=getenv('TMPDIR') ) return $temp;
  527. $temp=tempnam(__FILE__, '');
  528. if (file_exists($temp)) {
  529. unlink($temp);
  530. return dirname($temp);
  531. }
  532. if( $temp=sys_get_temp_dir()) return $temp;
  533. return null;
  534. }
  535. }
  536. OC::init();